void status_init(int (*get_progress)(int *), int start) { char *cfg_threshold; if (start) { if (!status_restored_time) memset(&status, 0, sizeof(status)); status.start_time = get_time(); } status_get_progress = get_progress; if (!(timeformat = cfg_get_param(SECTION_OPTIONS, NULL, "TimeFormat"))) timeformat = "%c"; if ((cfg_threshold = cfg_get_param(SECTION_OPTIONS, NULL, "ETAthreshold"))) if ((ETAthreshold = atof(cfg_threshold)) < 0.01) ETAthreshold = 0.01; showcand = cfg_get_bool(SECTION_OPTIONS, NULL, "StatusShowCandidates", 0); clk_tck_init(); /* This makes --max-run-time disregard loading time */ timer_abort = options.max_run_time; }
static void print_info(const struct md *md) { double energy = md->potential_energy; double invariant = md->get_invariant(md); double temperature = get_temperature(md); msg("%30s %16.10lf\n", "POTENTIAL ENERGY", energy); msg("%30s %16.10lf\n", "INVARIANT", invariant); msg("%30s %16.10lf\n", "TEMPERATURE", temperature); if (cfg_get_enum(md->state->cfg, "ensemble") == ENSEMBLE_TYPE_NPT) { double pressure = get_pressure(md) / BAR_TO_AU; msg("%30s %16.10lf\n", "PRESSURE", pressure); } if (cfg_get_bool(md->state->cfg, "enable_pbc")) { double x = md->box.x * BOHR_RADIUS; double y = md->box.y * BOHR_RADIUS; double z = md->box.z * BOHR_RADIUS; msg("%30s %9.3lf %9.3lf %9.3lf\n", "PERIODIC BOX SIZE", x, y, z); } msg("\n\n"); }
int httpadmin_start(Cfg *cfg) { CfgGroup *grp; int ssl = 0; #ifdef HAVE_LIBSSL Octstr *ssl_server_cert_file; Octstr *ssl_server_key_file; #endif /* HAVE_LIBSSL */ if (httpadmin_running) return -1; grp = cfg_get_single_group(cfg, octstr_imm("core")); if (cfg_get_integer(&ha_port, grp, octstr_imm("admin-port")) == -1) panic(0, "Missing admin-port variable, cannot start HTTP admin"); ha_interface = cfg_get(grp, octstr_imm("admin-interface")); ha_password = cfg_get(grp, octstr_imm("admin-password")); if (ha_password == NULL) panic(0, "You MUST set HTTP admin-password"); ha_status_pw = cfg_get(grp, octstr_imm("status-password")); ha_allow_ip = cfg_get(grp, octstr_imm("admin-allow-ip")); ha_deny_ip = cfg_get(grp, octstr_imm("admin-deny-ip")); #ifdef HAVE_LIBSSL cfg_get_bool(&ssl, grp, octstr_imm("admin-port-ssl")); /* * check if SSL is desired for HTTP servers and then * load SSL client and SSL server public certificates * and private keys */ ssl_server_cert_file = cfg_get(grp, octstr_imm("ssl-server-cert-file")); ssl_server_key_file = cfg_get(grp, octstr_imm("ssl-server-key-file")); if (ssl_server_cert_file != NULL && ssl_server_key_file != NULL) { /* we are fine here, the following call is now in conn_config_ssl(), * so there is no reason to do this twice. use_global_server_certkey_file(ssl_server_cert_file, ssl_server_key_file); */ } else if (ssl) { panic(0, "You MUST specify cert and key files within core group for SSL-enabled HTTP servers!"); } octstr_destroy(ssl_server_cert_file); octstr_destroy(ssl_server_key_file); #endif /* HAVE_LIBSSL */ http_open_port_if(ha_port, ssl, ha_interface); if (gwthread_create(httpadmin_run, NULL) == -1) panic(0, "Failed to start a new thread for HTTP admin"); httpadmin_running = 1; return 0; }
// Compute the effective value of the root_files configuration and // return a json reference. The caller must decref the ref when done // (we may synthesize this value). Sets enforcing to indicate whether // we will only allow watches on the root_files. // The array returned by this function (if not NULL) is guaranteed to // list .watchmanconfig as its zeroth element. json_t *cfg_compute_root_files(bool *enforcing) { json_t *ref; // This is completely undocumented and will go away soon. Do not document or // use! bool ignore_watchmanconfig = cfg_get_bool(NULL, "_ignore_watchmanconfig", false); *enforcing = false; ref = cfg_get_json(NULL, "enforce_root_files"); if (ref) { if (!json_is_boolean(ref)) { w_log(W_LOG_FATAL, "Expected config value enforce_root_files to be boolean\n"); } *enforcing = json_is_true(ref); } ref = cfg_get_json(NULL, "root_files"); if (ref) { if (!is_array_of_strings(ref)) { w_log(W_LOG_FATAL, "global config root_files must be an array of strings\n"); *enforcing = false; return NULL; } prepend_watchmanconfig_to_array(ref); json_incref(ref); return ref; } // Try legacy root_restrict_files configuration ref = cfg_get_json(NULL, "root_restrict_files"); if (ref) { if (!is_array_of_strings(ref)) { w_log(W_LOG_FATAL, "deprecated global config root_restrict_files " "must be an array of strings\n"); *enforcing = false; return NULL; } if (!ignore_watchmanconfig) { prepend_watchmanconfig_to_array(ref); } json_incref(ref); *enforcing = true; return ref; } // Synthesize our conservative default value. // .watchmanconfig MUST be first if (!ignore_watchmanconfig) { return json_pack("[ssss]", ".watchmanconfig", ".hg", ".git", ".svn"); } else { return json_pack("[sss]", ".hg", ".git", ".svn"); } }
void menu_create (GtkWidget *menu, GSList *list, char *target, int check_path) { struct popup *pop; GtkWidget *tempmenu = menu, *subitem = NULL; int childcount = 0; submenu_list = g_slist_prepend (0, menu); while (list) { pop = (struct popup *) list->data; if (!g_ascii_strncasecmp (pop->name, "SUB", 3)) { childcount = 0; tempmenu = menu_quick_sub (pop->cmd, tempmenu, &subitem, XCMENU_DOLIST, -1); } else if (!g_ascii_strncasecmp (pop->name, "TOGGLE", 6)) { childcount++; menu_toggle_item (pop->name + 7, tempmenu, toggle_cb, pop->cmd, cfg_get_bool (pop->cmd)); } else if (!g_ascii_strncasecmp (pop->name, "ENDSUB", 6)) { /* empty sub menu due to no programs in PATH? */ if (check_path && childcount < 1) gtk_widget_destroy (subitem); subitem = NULL; if (tempmenu != menu) tempmenu = menu_quick_endsub (); /* If we get here and tempmenu equals menu that means we havent got any submenus to exit from */ } else if (!g_ascii_strncasecmp (pop->name, "SEP", 3)) { menu_quick_item (0, 0, tempmenu, XCMENU_SHADED, 0, 0); } else { if (!check_path || pop->cmd[0] != '!') { menu_quick_item (pop->cmd, pop->name, tempmenu, 0, target, 0); /* check if the program is in path, if not, leave it out! */ } else if (is_in_path (pop->cmd)) { childcount++; menu_quick_item (pop->cmd, pop->name, tempmenu, 0, target, 0); } } list = list->next; } /* Let's clean up the linked list from mem */ while (submenu_list) submenu_list = g_slist_remove (submenu_list, submenu_list->data); }
int idle_requested(struct fmt_main *format) { if (!cfg_get_bool(SECTION_OPTIONS, NULL, "Idle", 1)) return 0; #ifdef _OPENMP if ((format->params.flags & FMT_OMP) && omp_get_max_threads() > 1) return 0; #endif return 1; }
int smsbox_start(Cfg *cfg) { CfgGroup *grp; if (smsbox_running) return -1; debug("bb", 0, "starting smsbox connection module"); grp = cfg_get_single_group(cfg, octstr_imm("core")); if (cfg_get_integer(&smsbox_port, grp, octstr_imm("smsbox-port")) == -1) { error(0, "Missing smsbox-port variable, cannot start smsboxes"); return -1; } #ifdef HAVE_LIBSSL cfg_get_bool(&smsbox_port_ssl, grp, octstr_imm("smsbox-port-ssl")); #endif /* HAVE_LIBSSL */ if (smsbox_port_ssl) debug("bb", 0, "smsbox connection module is SSL-enabled"); if (cfg_get_integer(&smsbox_max_pending, grp, octstr_imm("smsbox-max-pending")) == -1) { smsbox_max_pending = SMSBOX_MAX_PENDING; info(0, "BOXC: 'smsbox-max-pending' not set, using default (%ld).", smsbox_max_pending); } smsbox_list = gwlist_create(); /* have a list of connections */ smsbox_list_rwlock = gw_rwlock_create(); if (!boxid) boxid = counter_create(); /* the smsbox routing specific inits */ smsbox_by_id = dict_create(10, NULL); /* and a hash directory of identified */ smsbox_by_smsc = dict_create(30, (void(*)(void *)) octstr_destroy); smsbox_by_receiver = dict_create(50, (void(*)(void *)) octstr_destroy); smsbox_by_smsc_receiver = dict_create(50, (void(*)(void *)) octstr_destroy); /* load the defined smsbox routing rules */ init_smsbox_routes(cfg); gwlist_add_producer(outgoing_sms); gwlist_add_producer(smsbox_list); smsbox_running = 1; if ((sms_dequeue_thread = gwthread_create(sms_to_smsboxes, NULL)) == -1) panic(0, "Failed to start a new thread for smsbox routing"); if (gwthread_create(smsboxc_run, &smsbox_port) == -1) panic(0, "Failed to start a new thread for smsbox connections"); return 0; }
static void john_run(void) { if (options.flags & FLG_TEST_CHK) exit_status = benchmark_all() ? 1 : 0; else if (options.flags & FLG_MAKECHR_CHK) do_makechars(&database, options.charset); else if (options.flags & FLG_CRACKING_CHK) { if (!(options.flags & FLG_STDOUT)) { status_init(NULL, 1); log_init(LOG_NAME, options.loader.activepot, options.session); john_log_format(); if (cfg_get_bool(SECTION_OPTIONS, NULL, "Idle", 1)) log_event("- Configured to use otherwise idle " "processor cycles only"); } tty_init(options.flags & FLG_STDIN_CHK); if (options.flags & FLG_SINGLE_CHK) do_single_crack(&database); else if ((options.flags & FLG_GIJOHN_CHK) && FLG_EXTERNAL_CHK) { do { do_external_crack(&database); if (!aborted_gijohn) ext_init("gijohn"); } while (crk_db->password_count && !aborted_gijohn); } else if (options.flags & FLG_WORDLIST_CHK) do_wordlist_crack(&database, options.wordlist, (options.flags & FLG_RULES) != 0); else if (options.flags & FLG_INC_CHK) do_incremental_crack(&database, options.charset); else if (options.flags & FLG_MKV_CHK) do_markov_crack(&database, options.mkv_level, options.mkv_start, options.mkv_end, options.mkv_maxlen); else if ((options.flags & FLG_EXTERNAL_CHK) && FLG_GIJOHN_CHK) do_external_crack(&database); else if (options.flags & FLG_BATCH_CHK) do_batch_crack(&database); status_print(); tty_done(); } }
static vec_t wrap(const struct md *md, const vec_t *pos) { if (!cfg_get_bool(md->state->cfg, "enable_pbc")) return *pos; vec_t sub = { md->box.x * floor(pos->x / md->box.x), md->box.y * floor(pos->y / md->box.y), md->box.z * floor(pos->z / md->box.z) }; return vec_sub(pos, &sub); }
void log_init(char *log_name, char *pot_name, char *session) { in_logger = 1; if (log_name && log.fd < 0) { if (session) log_name = path_session(session, LOG_SUFFIX); log_file_init(&log, log_name, LOG_BUFFER_SIZE); } if (pot_name && pot.fd < 0) { log_file_init(&pot, pot_name, POT_BUFFER_SIZE); cfg_beep = cfg_get_bool(SECTION_OPTIONS, NULL, "Beep", 0); } cfg_log_passwords = cfg_get_bool(SECTION_OPTIONS, NULL, "LogCrackedPasswords", 0); in_logger = 0; }
static void john_wait(void) { int waiting_for = john_child_count; log_event("Waiting for %d child%s to terminate", waiting_for, waiting_for == 1 ? "" : "ren"); log_flush(); fprintf(stderr, "Waiting for %d child%s to terminate\n", waiting_for, waiting_for == 1 ? "" : "ren"); log_flush(); /* Tell our friends there is nothing more to crack! */ if (!database.password_count && !options.reload_at_crack && cfg_get_bool(SECTION_OPTIONS, NULL, "ReloadAtDone", 0)) raise(SIGUSR2); /* * Although we may block on wait(2), we still have signal handlers and a timer * in place, so we're relaying keypresses to child processes via signals. */ while (waiting_for) { int i, status; int pid = wait(&status); if (pid == -1) { if (errno != EINTR) perror("wait"); } else for (i = 0; i < john_child_count; i++) { if (john_child_pids[i] == pid) { john_child_pids[i] = 0; waiting_for--; children_ok = children_ok && WIFEXITED(status) && !WEXITSTATUS(status); break; } } } /* Close and possibly remove our .rec file now */ rec_done((children_ok && !event_abort) ? -1 : -2); }
int idle_requested(struct fmt_main *format) { if (!cfg_get_bool(SECTION_OPTIONS, NULL, "Idle", 1)) return 0; #ifdef _OPENMP if ((format->params.flags & FMT_OMP) && omp_get_max_threads() > 1) return 0; #endif #ifdef HAVE_OPENCL if (strstr(format->params.label, "-opencl")) return 0; #endif #ifdef HAVE_CUDA if (strstr(format->params.label, "-cuda")) return 0; #endif return 1; }
int wapbox_start(Cfg *cfg) { CfgGroup *grp; if (wapbox_running) return -1; debug("bb", 0, "starting wapbox connection module"); grp = cfg_get_single_group(cfg, octstr_imm("core")); if (cfg_get_integer(&wapbox_port, grp, octstr_imm("wapbox-port")) == -1) { error(0, "Missing wapbox-port variable, cannot start WAP"); return -1; } #ifdef HAVE_LIBSSL cfg_get_bool(&wapbox_port_ssl, grp, octstr_imm("wapbox-port-ssl")); #endif /* HAVE_LIBSSL */ box_allow_ip = cfg_get(grp, octstr_imm("box-allow-ip")); if (box_allow_ip == NULL) box_allow_ip = octstr_create(""); box_deny_ip = cfg_get(grp, octstr_imm("box-deny-ip")); if (box_deny_ip == NULL) box_deny_ip = octstr_create(""); if (box_allow_ip != NULL && box_deny_ip == NULL) info(0, "Box connection allowed IPs defined without any denied..."); wapbox_list = gwlist_create(); /* have a list of connections */ gwlist_add_producer(outgoing_wdp); if (!boxid) boxid = counter_create(); if (gwthread_create(wdp_to_wapboxes, NULL) == -1) panic(0, "Failed to start a new thread for wapbox routing"); if (gwthread_create(wapboxc_run, &wapbox_port) == -1) panic(0, "Failed to start a new thread for wapbox connections"); wapbox_running = 1; return 0; }
void add_root_warnings_to_response(json_t *response, w_root_t *root) { char *str = NULL; char *full = NULL; if (!root->last_recrawl_reason && !root->warning) { return; } if (cfg_get_bool(root, "suppress_recrawl_warnings", false)) { return; } if (root->last_recrawl_reason) { ignore_result( asprintf(&str, "Recrawled this watch %d times, most recently because:\n" "%.*s\n" "To resolve, please review the information on\n" "%s#recrawl", root->recrawl_count, root->last_recrawl_reason->len, root->last_recrawl_reason->buf, cfg_get_trouble_url())); } ignore_result(asprintf( &full, "%.*s%s" // root->warning "%s\n" // str (last recrawl reason) "To clear this warning, run:\n" "`watchman watch-del %.*s ; watchman watch-project %.*s`\n", root->warning ? root->warning->len : 0, root->warning ? root->warning->buf : "", root->warning && str ? "\n" : "", // newline if we have both strings str ? str : "", root->root_path->len, root->root_path->buf, root->root_path->len, root->root_path->buf)); if (full) { set_prop(response, "warning", typed_string_to_json(full, W_STRING_MIXED)); } free(str); free(full); }
void status_init(int (*get_progress)(int *), int start) { char *cfg_threshold; if (start) { if (!status_restored_time) memset(&status, 0, sizeof(status)); status.start_time = get_time(); } status_get_progress = get_progress; if (!(timeformat = cfg_get_param(SECTION_OPTIONS, NULL, "TimeFormat"))) timeformat = "%c"; if ((cfg_threshold = cfg_get_param(SECTION_OPTIONS, NULL, "ETAthreshold"))) if ((ETAthreshold = atof(cfg_threshold)) < 0.01) ETAthreshold = 0.01; showcand = cfg_get_bool(SECTION_OPTIONS, NULL, "StatusShowCandidates", 0); clk_tck_init(); }
static void read_test_ppg_config(Octstr *name) { Cfg *cfg; CfgGroup *grp; cfg = cfg_create(name); if (cfg_read(cfg) == -1) panic(0, "Cannot read a configuration file %s, exiting", octstr_get_cstr(name)); cfg_dump(cfg); grp = cfg_get_single_group(cfg, octstr_imm("test-ppg")); cfg_get_integer(&retries, grp, octstr_imm("retries")); cfg_get_bool(&pi_ssl, grp, octstr_imm("pi-ssl")); #ifdef HAVE_LIBSSL if (pi_ssl) { ssl_client_certkey_file = cfg_get(grp, octstr_imm("ssl-client-certkey-file")); if (ssl_client_certkey_file != NULL) { use_global_client_certkey_file(ssl_client_certkey_file); } else { error(0, "cannot set up SSL without client certkey file"); exit(1); } } #endif grp = cfg_get_single_group(cfg, octstr_imm("configuration")); push_url = cfg_get(grp, octstr_imm("push-url")); pap_file = cfg_get(grp, octstr_imm("pap-file")); content_file = cfg_get(grp, octstr_imm("content-file")); if (!use_hardcoded) { username = cfg_get(grp, octstr_imm("username")); password = cfg_get(grp, octstr_imm("password")); } cfg_destroy(cfg); }
static void john_load_conf_db(void) { if (options.flags & FLG_STDOUT) { /* john.conf alternative for --internal-encoding */ if (!pers_opts.internal_enc && pers_opts.target_enc == UTF_8 && options.flags & (FLG_RULES | FLG_SINGLE_CHK | FLG_BATCH_CHK | FLG_MASK_CHK)) if (!(pers_opts.internal_enc = cp_name2id(cfg_get_param(SECTION_OPTIONS, NULL, "DefaultInternalEncoding")))) /* Deprecated alternative */ pers_opts.internal_enc = cp_name2id(cfg_get_param(SECTION_OPTIONS, NULL, "DefaultIntermediateEncoding")); } if (!pers_opts.unicode_cp) initUnicode(UNICODE_UNICODE); pers_opts.report_utf8 = cfg_get_bool(SECTION_OPTIONS, NULL, "AlwaysReportUTF8", 0); /* Unicode (UTF-16) formats may lack encoding support. We must stop the user from trying to use it because it will just result in false negatives. */ if (database.format && pers_opts.target_enc != ASCII && pers_opts.target_enc != ISO_8859_1 && database.format->params.flags & FMT_UNICODE && !(database.format->params.flags & FMT_UTF8)) { if (john_main_process) fprintf(stderr, "This format does not yet support" " other encodings than ISO-8859-1\n"); error(); } if (database.format && database.format->params.flags & FMT_UNICODE) pers_opts.store_utf8 = cfg_get_bool(SECTION_OPTIONS, NULL, "UnicodeStoreUTF8", 0); else pers_opts.store_utf8 = cfg_get_bool(SECTION_OPTIONS, NULL, "CPstoreUTF8", 0); if (!options.secure) { if (pers_opts.report_utf8 && options.loader.log_passwords) log_event("- Passwords in this logfile are " "UTF-8 encoded"); if (pers_opts.store_utf8) log_event("- Passwords will be stored UTF-8 " "encoded in .pot file"); } if (pers_opts.target_enc != pers_opts.input_enc && pers_opts.input_enc != UTF_8) { if (john_main_process) fprintf(stderr, "Target encoding can only be specified" " if input encoding is UTF-8\n"); exit(0); } if (!(options.flags & FLG_SHOW_CHK) && !options.loader.showuncracked) if (options.flags & (FLG_PASSWD | FLG_STDIN_CHK)) if (pers_opts.default_enc && john_main_process && pers_opts.input_enc != ASCII) fprintf(stderr, "Using default input encoding: %s\n", cp_id2name(pers_opts.input_enc)); if (!(options.flags & FLG_SHOW_CHK) && !options.loader.showuncracked) if (pers_opts.target_enc != pers_opts.input_enc && (!database.format || !(database.format->params.flags & FMT_UNICODE))) { log_event("- Target encoding: %s", cp_id2name(pers_opts.target_enc)); if (john_main_process) { if (pers_opts.default_target_enc) fprintf(stderr, "Using default target " "encoding: %s\n", cp_id2name(pers_opts.target_enc)); else fprintf(stderr, "Target encoding: %s\n", cp_id2name(pers_opts.target_enc)); } } if (!(options.flags & FLG_SHOW_CHK) && !options.loader.showuncracked) if (pers_opts.input_enc != pers_opts.internal_enc) { log_event("- Rules/masks using %s", cp_id2name(pers_opts.internal_enc)); if (john_main_process && (database.format->params.flags & FMT_UNICODE)) fprintf(stderr, "Rules/masks using %s\n", cp_id2name(pers_opts.internal_enc)); } }
static void john_load_conf(void) { int internal, target; if (!(options.flags & FLG_VERBOSITY)) { options.verbosity = cfg_get_int(SECTION_OPTIONS, NULL, "Verbosity"); if (options.verbosity == -1) options.verbosity = 3; if (options.verbosity < 1 || options.verbosity > 5) { if (john_main_process) fprintf(stderr, "Invalid verbosity " "level in config file, use 1-5\n"); error(); } } if (pers_opts.activepot == NULL) { if (options.secure) pers_opts.activepot = str_alloc_copy(SEC_POT_NAME); else pers_opts.activepot = str_alloc_copy(POT_NAME); } if (pers_opts.activewordlistrules == NULL) if (!(pers_opts.activewordlistrules = cfg_get_param(SECTION_OPTIONS, NULL, "BatchModeWordlistRules"))) pers_opts.activewordlistrules = str_alloc_copy(SUBSECTION_WORDLIST); if (pers_opts.activesinglerules == NULL) if (!(pers_opts.activesinglerules = cfg_get_param(SECTION_OPTIONS, NULL, "SingleRules"))) pers_opts.activesinglerules = str_alloc_copy(SUBSECTION_SINGLE); if ((options.flags & FLG_LOOPBACK_CHK) && !(options.flags & FLG_RULES)) { if ((pers_opts.activewordlistrules = cfg_get_param(SECTION_OPTIONS, NULL, "LoopbackRules"))) options.flags |= FLG_RULES; } if ((options.flags & FLG_WORDLIST_CHK) && !(options.flags & FLG_RULES)) { if ((pers_opts.activewordlistrules = cfg_get_param(SECTION_OPTIONS, NULL, "WordlistRules"))) options.flags |= FLG_RULES; } options.secure = cfg_get_bool(SECTION_OPTIONS, NULL, "SecureMode", 0); options.reload_at_crack = cfg_get_bool(SECTION_OPTIONS, NULL, "ReloadAtCrack", 1); options.reload_at_save = cfg_get_bool(SECTION_OPTIONS, NULL, "ReloadAtSave", 1); options.abort_file = cfg_get_param(SECTION_OPTIONS, NULL, "AbortFile"); options.pause_file = cfg_get_param(SECTION_OPTIONS, NULL, "PauseFile"); /* This is --crack-status. We toggle here, so if it's enabled in john.conf, we can disable it using the command line option */ if (cfg_get_bool(SECTION_OPTIONS, NULL, "CrackStatus", 0)) options.flags ^= FLG_CRKSTAT; #if HAVE_OPENCL if (cfg_get_bool(SECTION_OPTIONS, SUBSECTION_OPENCL, "ForceScalar", 0)) options.flags |= FLG_SCALAR; #endif options.loader.log_passwords = options.secure || cfg_get_bool(SECTION_OPTIONS, NULL, "LogCrackedPasswords", 0); if (!pers_opts.input_enc && !(options.flags & FLG_TEST_CHK)) { if ((options.flags & FLG_LOOPBACK_CHK) && cfg_get_bool(SECTION_OPTIONS, NULL, "UnicodeStoreUTF8", 0)) pers_opts.input_enc = cp_name2id("UTF-8"); else { pers_opts.input_enc = cp_name2id(cfg_get_param(SECTION_OPTIONS, NULL, "DefaultEncoding")); } pers_opts.default_enc = pers_opts.input_enc; } /* Pre-init in case some format's prepare() needs it */ internal = pers_opts.internal_enc; target = pers_opts.target_enc; initUnicode(UNICODE_UNICODE); pers_opts.internal_enc = internal; pers_opts.target_enc = target; pers_opts.unicode_cp = CP_UNDEF; }
static void john_omp_show_info(void) { #if HAVE_MPI if (mpi_p == 1) #endif if (database.format && database.format->params.label && (!strstr(database.format->params.label, "-opencl") && !strstr(database.format->params.label, "-cuda"))) if (!options.fork && john_omp_threads_orig > 1 && database.format && database.format != &dummy_format && !rec_restoring_now) { const char *msg = NULL; if (!(database.format->params.flags & FMT_OMP)) msg = "no OpenMP support"; else if ((database.format->params.flags & FMT_OMP_BAD)) msg = "poor OpenMP scalability"; if (msg) #if OS_FORK fprintf(stderr, "Warning: %s for this hash type, " "consider --fork=%d\n", msg, john_omp_threads_orig); #else fprintf(stderr, "Warning: %s for this hash type\n", msg); #endif } /* * Only show OpenMP info if one of the following is true: * - we have a format detected for the loaded hashes and it is OpenMP-enabled; * - we're doing --test and no format is specified (so we will test all, * including some that are presumably OpenMP-enabled); * - we're doing --test and the specified format is OpenMP-enabled. */ { int show = 0; if (database.format && (database.format->params.flags & FMT_OMP)) show = 1; else if ((options.flags & (FLG_TEST_CHK | FLG_FORMAT)) == FLG_TEST_CHK) show = 1; else if ((options.flags & FLG_TEST_CHK) && (fmt_list->params.flags & FMT_OMP)) show = 1; if (!show) return; } #if HAVE_MPI /* * If OMP_NUM_THREADS is set, we assume the user knows what * he is doing. Here's how to pass it to remote hosts: * mpirun -x OMP_NUM_THREADS=4 -np 4 -host ... */ if (mpi_p > 1) { if(getenv("OMP_NUM_THREADS") == NULL && cfg_get_bool(SECTION_OPTIONS, SUBSECTION_MPI, "MPIOMPmutex", 1)) { if(cfg_get_bool(SECTION_OPTIONS, SUBSECTION_MPI, "MPIOMPverbose", 1) && mpi_id == 0) fprintf(stderr, "MPI in use, disabling OMP " "(see doc/README.mpi)\n"); omp_set_num_threads(1); john_omp_threads_orig = 0; /* Mute later warning */ } else if(john_omp_threads_orig > 1 && cfg_get_bool(SECTION_OPTIONS, SUBSECTION_MPI, "MPIOMPverbose", 1) && mpi_id == 0) fprintf(stderr, "Note: Running both MPI and OMP" " (see doc/README.mpi)\n"); } else #endif if (options.fork) { #if OS_FORK if (john_omp_threads_new > 1) fprintf(stderr, "Will run %d OpenMP threads per process " "(%u total across %u processes)\n", john_omp_threads_new, john_omp_threads_new * options.fork, options.fork); else if (john_omp_threads_orig > 1) fputs("Warning: OpenMP was disabled due to --fork; " "a non-OpenMP build may be faster\n", stderr); #endif } else { if (john_omp_threads_new > 1) fprintf(stderr, "Will run %d OpenMP threads\n", john_omp_threads_new); } if (john_omp_threads_orig == 1) if (john_main_process) fputs("Warning: OpenMP is disabled; " "a non-OpenMP build may be faster\n", stderr); }
DICT *dict_ldap_open(const char *ldapsource, int dummy, int dict_flags) { char *myname = "dict_ldap_open"; DICT_LDAP *dict_ldap; VSTRING *url_list; char *s; char *h; char *server_host; char *domainlist; char *scope; char *attr; int tmp; if (msg_verbose) msg_info("%s: Using LDAP source %s", myname, ldapsource); dict_ldap = (DICT_LDAP *) dict_alloc(DICT_TYPE_LDAP, ldapsource, sizeof(*dict_ldap)); dict_ldap->dict.lookup = dict_ldap_lookup; dict_ldap->dict.close = dict_ldap_close; dict_ldap->dict.flags = dict_flags | DICT_FLAG_FIXED; dict_ldap->ld = NULL; dict_ldap->parser = cfg_parser_alloc(ldapsource); dict_ldap->ldapsource = mystrdup(ldapsource); server_host = cfg_get_str(dict_ldap->parser, "server_host", "localhost", 1, 0); /* * get configured value of "server_port"; default to LDAP_PORT (389) */ dict_ldap->server_port = cfg_get_int(dict_ldap->parser, "server_port", LDAP_PORT, 0, 0); /* * Define LDAP Version. */ dict_ldap->version = cfg_get_int(dict_ldap->parser, "version", 2, 2, 0); switch (dict_ldap->version) { case 2: dict_ldap->version = LDAP_VERSION2; break; case 3: dict_ldap->version = LDAP_VERSION3; break; default: msg_warn("%s: %s Unknown version %d.", myname, ldapsource, dict_ldap->version); dict_ldap->version = LDAP_VERSION2; } #if defined(LDAP_API_FEATURE_X_OPENLDAP) dict_ldap->ldap_ssl = 0; #endif url_list = vstring_alloc(32); s = server_host; while ((h = mystrtok(&s, " \t\n\r,")) != NULL) { #if defined(LDAP_API_FEATURE_X_OPENLDAP) /* * Convert (host, port) pairs to LDAP URLs */ if (ldap_is_ldap_url(h)) { LDAPURLDesc *url_desc; int rc; if ((rc = ldap_url_parse(h, &url_desc)) != 0) { msg_error("%s: error parsing URL %s: %d: %s; skipping", myname, h, rc, ldap_err2string(rc)); continue; } if (strcasecmp(url_desc->lud_scheme, "ldap") != 0 && dict_ldap->version != LDAP_VERSION3) { msg_warn("%s: URL scheme %s requires protocol version 3", myname, url_desc->lud_scheme); dict_ldap->version = LDAP_VERSION3; } if (strcasecmp(url_desc->lud_scheme, "ldaps") == 0) dict_ldap->ldap_ssl = 1; ldap_free_urldesc(url_desc); vstring_sprintf_append(url_list, " %s", h); } else { if (strrchr(h, ':')) vstring_sprintf_append(url_list, " ldap://%s", h); else vstring_sprintf_append(url_list, " ldap://%s:%d", h, dict_ldap->server_port); } #else vstring_sprintf_append(url_list, " %s", h); #endif } dict_ldap->server_host = mystrdup(VSTRING_LEN(url_list) > 0 ? vstring_str(url_list) + 1 : ""); #if defined(LDAP_API_FEATURE_X_OPENLDAP) /* * With URL scheme, clear port to normalize connection cache key */ dict_ldap->server_port = LDAP_PORT; if (msg_verbose) msg_info("%s: %s server_host URL is %s", myname, ldapsource, dict_ldap->server_host); #endif myfree(server_host); vstring_free(url_list); /* * Scope handling thanks to Carsten Hoeger of SuSE. */ scope = cfg_get_str(dict_ldap->parser, "scope", "sub", 1, 0); if (strcasecmp(scope, "one") == 0) { dict_ldap->scope = LDAP_SCOPE_ONELEVEL; } else if (strcasecmp(scope, "base") == 0) { dict_ldap->scope = LDAP_SCOPE_BASE; } else if (strcasecmp(scope, "sub") == 0) { dict_ldap->scope = LDAP_SCOPE_SUBTREE; } else { msg_warn("%s: %s: Unrecognized value %s specified for scope; using sub", myname, ldapsource, scope); dict_ldap->scope = LDAP_SCOPE_SUBTREE; } myfree(scope); dict_ldap->search_base = cfg_get_str(dict_ldap->parser, "search_base", "", 0, 0); domainlist = cfg_get_str(dict_ldap->parser, "domain", "", 0, 0); if (*domainlist) { #ifdef MATCH_FLAG_NONE dict_ldap->domain = match_list_init(MATCH_FLAG_NONE, domainlist, 1, match_string); #else dict_ldap->domain = match_list_init(domainlist, 1, match_string); #endif if (dict_ldap->domain == NULL) msg_warn("%s: domain match list creation using \"%s\" failed, will continue without it", myname, domainlist); if (msg_verbose) msg_info("%s: domain list created using \"%s\"", myname, domainlist); } else { dict_ldap->domain = NULL; } myfree(domainlist); /* * get configured value of "timeout"; default to 10 seconds * * Thanks to Manuel Guesdon for spotting that this wasn't really getting * set. */ dict_ldap->timeout = cfg_get_int(dict_ldap->parser, "timeout", 10, 0, 0); dict_ldap->query_filter = cfg_get_str(dict_ldap->parser, "query_filter", "(mailacceptinggeneralid=%s)", 0, 0); dict_ldap->result_filter = cfg_get_str(dict_ldap->parser, "result_filter", "%s", 0, 0); if (strcmp(dict_ldap->result_filter, "%s") == 0) { myfree(dict_ldap->result_filter); dict_ldap->result_filter = NULL; } attr = cfg_get_str(dict_ldap->parser, "result_attribute", "maildrop", 0, 0); dict_ldap->result_attributes = argv_split(attr, " ,\t\r\n"); dict_ldap->num_attributes = dict_ldap->result_attributes->argc; myfree(attr); attr = cfg_get_str(dict_ldap->parser, "special_result_attribute", "", 0, 0); if (*attr) { argv_split_append(dict_ldap->result_attributes, attr, " ,\t\r\n"); } myfree(attr); /* * get configured value of "bind"; default to true */ dict_ldap->bind = cfg_get_bool(dict_ldap->parser, "bind", 1); /* * get configured value of "bind_dn"; default to "" */ dict_ldap->bind_dn = cfg_get_str(dict_ldap->parser, "bind_dn", "", 0, 0); /* * get configured value of "bind_pw"; default to "" */ dict_ldap->bind_pw = cfg_get_str(dict_ldap->parser, "bind_pw", "", 0, 0); /* * get configured value of "cache"; default to false */ tmp = cfg_get_bool(dict_ldap->parser, "cache", 0); if (tmp) msg_warn("%s: %s ignoring cache", myname, ldapsource); /* * get configured value of "cache_expiry"; default to 30 seconds */ tmp = cfg_get_int(dict_ldap->parser, "cache_expiry", -1, 0, 0); if (tmp >= 0) msg_warn("%s: %s ignoring cache_expiry", myname, ldapsource); /* * get configured value of "cache_size"; default to 32k */ tmp = cfg_get_int(dict_ldap->parser, "cache_size", -1, 0, 0); if (tmp >= 0) msg_warn("%s: %s ignoring cache_size", myname, ldapsource); /* * get configured value of "recursion_limit"; default to 1000 */ dict_ldap->recursion_limit = cfg_get_int(dict_ldap->parser, "recursion_limit", 1000, 1, 0); /* * get configured value of "expansion_limit"; default to 0 */ dict_ldap->expansion_limit = cfg_get_int(dict_ldap->parser, "expansion_limit", 0, 0, 0); /* * get configured value of "size_limit"; default to expansion_limit */ dict_ldap->size_limit = cfg_get_int(dict_ldap->parser, "size_limit", dict_ldap->expansion_limit, 0, 0); /* * Alias dereferencing suggested by Mike Mattice. */ dict_ldap->dereference = cfg_get_int(dict_ldap->parser, "dereference", 0, 0, 0); if (dict_ldap->dereference < 0 || dict_ldap->dereference > 3) { msg_warn("%s: %s Unrecognized value %d specified for dereference; using 0", myname, ldapsource, dict_ldap->dereference); dict_ldap->dereference = 0; } /* Referral chasing */ dict_ldap->chase_referrals = cfg_get_bool(dict_ldap->parser, "chase_referrals", 0); #ifdef LDAP_API_FEATURE_X_OPENLDAP /* * TLS options */ /* get configured value of "start_tls"; default to no */ dict_ldap->start_tls = cfg_get_bool(dict_ldap->parser, "start_tls", 0); if (dict_ldap->start_tls && dict_ldap->version < LDAP_VERSION3) { msg_warn("%s: %s start_tls requires protocol version 3", myname, ldapsource); dict_ldap->version = LDAP_VERSION3; } /* get configured value of "tls_require_cert"; default to no */ dict_ldap->tls_require_cert = cfg_get_bool(dict_ldap->parser, "tls_require_cert", 0); /* get configured value of "tls_ca_cert_file"; default "" */ dict_ldap->tls_ca_cert_file = cfg_get_str(dict_ldap->parser, "tls_ca_cert_file", "", 0, 0); /* get configured value of "tls_ca_cert_dir"; default "" */ dict_ldap->tls_ca_cert_dir = cfg_get_str(dict_ldap->parser, "tls_ca_cert_dir", "", 0, 0); /* get configured value of "tls_cert"; default "" */ dict_ldap->tls_cert = cfg_get_str(dict_ldap->parser, "tls_cert", "", 0, 0); /* get configured value of "tls_key"; default "" */ dict_ldap->tls_key = cfg_get_str(dict_ldap->parser, "tls_key", "", 0, 0); /* get configured value of "tls_random_file"; default "" */ dict_ldap->tls_random_file = cfg_get_str(dict_ldap->parser, "tls_random_file", "", 0, 0); /* get configured value of "tls_cipher_suite"; default "" */ dict_ldap->tls_cipher_suite = cfg_get_str(dict_ldap->parser, "tls_cipher_suite", "", 0, 0); #endif /* * Debug level. */ #if defined(LDAP_OPT_DEBUG_LEVEL) && defined(LBER_OPT_LOG_PRINT_FN) dict_ldap->debuglevel = cfg_get_int(dict_ldap->parser, "debuglevel", 0, 0, 0); #endif /* * Find or allocate shared LDAP connection container. */ dict_ldap_conn_find(dict_ldap); /* * Return the new dict_ldap structure. */ return (DICT_DEBUG (&dict_ldap->dict)); }
SMSCConn *smscconn_create(CfgGroup *grp, int start_as_stopped) { SMSCConn *conn; Octstr *smsc_type; int ret; Octstr *allowed_smsc_id_regex; Octstr *denied_smsc_id_regex; Octstr *allowed_prefix_regex; Octstr *denied_prefix_regex; Octstr *preferred_prefix_regex; Octstr *tmp; if (grp == NULL) return NULL; conn = gw_malloc(sizeof(*conn)); memset(conn, 0, sizeof(*conn)); conn->why_killed = SMSCCONN_ALIVE; conn->status = SMSCCONN_CONNECTING; conn->connect_time = -1; conn->is_stopped = start_as_stopped; conn->received = counter_create(); conn->received_dlr = counter_create(); conn->sent = counter_create(); conn->sent_dlr = counter_create(); conn->failed = counter_create(); conn->flow_mutex = mutex_create(); conn->outgoing_sms_load = load_create(); /* add 60,300,-1 entries */ load_add_interval(conn->outgoing_sms_load, 60); load_add_interval(conn->outgoing_sms_load, 300); load_add_interval(conn->outgoing_sms_load, -1); conn->incoming_sms_load = load_create(); /* add 60,300,-1 entries */ load_add_interval(conn->incoming_sms_load, 60); load_add_interval(conn->incoming_sms_load, 300); load_add_interval(conn->incoming_sms_load, -1); conn->incoming_dlr_load = load_create(); /* add 60,300,-1 entries to dlr */ load_add_interval(conn->incoming_dlr_load, 60); load_add_interval(conn->incoming_dlr_load, 300); load_add_interval(conn->incoming_dlr_load, -1); conn->outgoing_dlr_load = load_create(); /* add 60,300,-1 entries to dlr */ load_add_interval(conn->outgoing_dlr_load, 60); load_add_interval(conn->outgoing_dlr_load, 300); load_add_interval(conn->outgoing_dlr_load, -1); #define GET_OPTIONAL_VAL(x, n) x = cfg_get(grp, octstr_imm(n)) #define SPLIT_OPTIONAL_VAL(x, n) \ do { \ Octstr *tmp = cfg_get(grp, octstr_imm(n)); \ if (tmp) x = octstr_split(tmp, octstr_imm(";")); \ else x = NULL; \ octstr_destroy(tmp); \ }while(0) GET_OPTIONAL_VAL(conn->id, "smsc-id"); SPLIT_OPTIONAL_VAL(conn->allowed_smsc_id, "allowed-smsc-id"); SPLIT_OPTIONAL_VAL(conn->denied_smsc_id, "denied-smsc-id"); SPLIT_OPTIONAL_VAL(conn->preferred_smsc_id, "preferred-smsc-id"); GET_OPTIONAL_VAL(conn->allowed_prefix, "allowed-prefix"); GET_OPTIONAL_VAL(conn->denied_prefix, "denied-prefix"); GET_OPTIONAL_VAL(conn->preferred_prefix, "preferred-prefix"); GET_OPTIONAL_VAL(conn->unified_prefix, "unified-prefix"); GET_OPTIONAL_VAL(conn->our_host, "our-host"); GET_OPTIONAL_VAL(conn->log_file, "log-file"); cfg_get_bool(&conn->alt_dcs, grp, octstr_imm("alt-dcs")); GET_OPTIONAL_VAL(allowed_smsc_id_regex, "allowed-smsc-id-regex"); if (allowed_smsc_id_regex != NULL) if ((conn->allowed_smsc_id_regex = gw_regex_comp(allowed_smsc_id_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(allowed_smsc_id_regex)); GET_OPTIONAL_VAL(denied_smsc_id_regex, "denied-smsc-id-regex"); if (denied_smsc_id_regex != NULL) if ((conn->denied_smsc_id_regex = gw_regex_comp(denied_smsc_id_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(denied_smsc_id_regex)); GET_OPTIONAL_VAL(allowed_prefix_regex, "allowed-prefix-regex"); if (allowed_prefix_regex != NULL) if ((conn->allowed_prefix_regex = gw_regex_comp(allowed_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(allowed_prefix_regex)); GET_OPTIONAL_VAL(denied_prefix_regex, "denied-prefix-regex"); if (denied_prefix_regex != NULL) if ((conn->denied_prefix_regex = gw_regex_comp(denied_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(denied_prefix_regex)); GET_OPTIONAL_VAL(preferred_prefix_regex, "preferred-prefix-regex"); if (preferred_prefix_regex != NULL) if ((conn->preferred_prefix_regex = gw_regex_comp(preferred_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(preferred_prefix_regex)); if ((tmp = cfg_get(grp, octstr_imm("throughput"))) != NULL) { if (octstr_parse_double(&conn->throughput, tmp, 0) == -1) conn->throughput = 0; octstr_destroy(tmp); info(0, "Set throughput to %.3f for smsc id <%s>", conn->throughput, octstr_get_cstr(conn->id)); } /* Sets the admin_id. Equals to connection id if empty */ GET_OPTIONAL_VAL(conn->admin_id, "smsc-admin-id"); if (conn->admin_id == NULL) conn->admin_id = octstr_duplicate(conn->id); /* configure the internal rerouting rules for this smsc id */ init_reroute(conn, grp); if (cfg_get_integer(&conn->log_level, grp, octstr_imm("log-level")) == -1) conn->log_level = 0; if (cfg_get_integer(&conn->max_sms_octets, grp, octstr_imm("max-sms-octets")) == -1) conn->max_sms_octets = MAX_SMS_OCTETS; if (cfg_get_bool(&conn->dead_start, grp, octstr_imm("dead-start")) == -1) conn->dead_start = 0; /* default to connect at start-up time */ /* open a smsc-id specific log-file in exlusive mode */ if (conn->log_file) conn->log_idx = log_open(octstr_get_cstr(conn->log_file), conn->log_level, GW_EXCL); #undef GET_OPTIONAL_VAL #undef SPLIT_OPTIONAL_VAL if (conn->allowed_smsc_id && conn->denied_smsc_id) warning(0, "Both 'allowed-smsc-id' and 'denied-smsc-id' set, deny-list " "automatically ignored"); if (conn->allowed_smsc_id_regex && conn->denied_smsc_id_regex) warning(0, "Both 'allowed-smsc-id_regex' and 'denied-smsc-id_regex' set, deny-regex " "automatically ignored"); if (cfg_get_integer(&conn->reconnect_delay, grp, octstr_imm("reconnect-delay")) == -1) conn->reconnect_delay = SMSCCONN_RECONNECT_DELAY; smsc_type = cfg_get(grp, octstr_imm("smsc")); if (smsc_type == NULL) { error(0, "Required field 'smsc' missing for smsc group."); smscconn_destroy(conn); octstr_destroy(smsc_type); return NULL; } if (octstr_compare(smsc_type, octstr_imm("fake")) == 0) ret = smsc_fake_create(conn, grp); else if (octstr_compare(smsc_type, octstr_imm("cimd2")) == 0) ret = smsc_cimd2_create(conn, grp); else if (octstr_compare(smsc_type, octstr_imm("emi")) == 0) ret = smsc_emi2_create(conn, grp); else if (octstr_compare(smsc_type, octstr_imm("http")) == 0) ret = smsc_http_create(conn, grp); else if (octstr_compare(smsc_type, octstr_imm("smpp")) == 0) ret = smsc_smpp_create(conn, grp); else if (octstr_compare(smsc_type, octstr_imm("at")) == 0) ret = smsc_at2_create(conn,grp); else if (octstr_compare(smsc_type, octstr_imm("cgw")) == 0) ret = smsc_cgw_create(conn,grp); else if (octstr_compare(smsc_type, octstr_imm("smasi")) == 0) ret = smsc_smasi_create(conn, grp); else if (octstr_compare(smsc_type, octstr_imm("oisd")) == 0) ret = smsc_oisd_create(conn, grp); else if (octstr_compare(smsc_type, octstr_imm("loopback")) == 0) ret = smsc_loopback_create(conn, grp); #ifdef HAVE_GSOAP else if (octstr_compare(smsc_type, octstr_imm("parlayx")) == 0) ret = smsc_soap_parlayx_create(conn, grp); #endif else ret = smsc_wrapper_create(conn, grp); octstr_destroy(smsc_type); if (ret == -1) { smscconn_destroy(conn); return NULL; } gw_assert(conn->send_msg != NULL); bb_smscconn_ready(conn); return conn; }
static void john_run(void) { if (options.flags & FLG_TEST_CHK) exit_status = benchmark_all() ? 1 : 0; else if (options.flags & FLG_MAKECHR_CHK) do_makechars(&database, options.charset); else if (options.flags & FLG_CRACKING_CHK) { int remaining = database.password_count; if (!(options.flags & FLG_STDOUT)) { status_init(NULL, 1); log_init(LOG_NAME, options.loader.activepot, options.session); john_log_format(); if (idle_requested(database.format)) log_event("- Configured to use otherwise idle " "processor cycles only"); } tty_init(options.flags & FLG_STDIN_CHK); #if defined(HAVE_MPI) && defined(_OPENMP) if (database.format->params.flags & FMT_OMP && omp_get_max_threads() > 1 && mpi_p > 1) { if(cfg_get_bool(SECTION_OPTIONS, NULL, "MPIOMPmutex", 1)) { if(cfg_get_bool(SECTION_OPTIONS, NULL, "MPIOMPverbose", 1) && mpi_id == 0) fprintf(stderr, "MPI in use, disabling OMP (see doc/README.mpi)\n"); omp_set_num_threads(1); } else if(cfg_get_bool(SECTION_OPTIONS, NULL, "MPIOMPverbose", 1) && mpi_id == 0) fprintf(stderr, "Note: Running both MPI and OMP (see doc/README.mpi)\n"); } #endif if (options.flags & FLG_SINGLE_CHK) do_single_crack(&database); else if (options.flags & FLG_WORDLIST_CHK) do_wordlist_crack(&database, options.wordlist, (options.flags & FLG_RULES) != 0); else if (options.flags & FLG_INC_CHK) do_incremental_crack(&database, options.charset); else if (options.flags & FLG_MKV_CHK) do_markov_crack(&database, options.mkv_level, options.mkv_start, options.mkv_end, options.mkv_maxlen, options.mkv_minlevel, options.mkv_minlen); else if (options.flags & FLG_EXTERNAL_CHK) do_external_crack(&database); else if (options.flags & FLG_BATCH_CHK) do_batch_crack(&database); status_print(); tty_done(); if (database.password_count < remaining) { char *might = "Warning: passwords printed above might"; char *partial = " be partial"; char *not_all = " not be all those cracked"; switch (database.options->flags & (DB_SPLIT | DB_NODUP)) { case DB_SPLIT: #ifdef HAVE_MPI if (mpi_id == 0) #endif fprintf(stderr, "%s%s\n", might, partial); break; case DB_NODUP: #ifdef HAVE_MPI if (mpi_id == 0) #endif fprintf(stderr, "%s%s\n", might, not_all); break; case (DB_SPLIT | DB_NODUP): #ifdef HAVE_MPI if (mpi_id == 0) #endif fprintf(stderr, "%s%s and%s\n", might, partial, not_all); } #ifdef HAVE_MPI if (mpi_id == 0) #endif fputs("Use the \"--show\" option to display all of " "the cracked passwords reliably\n", stderr); } } }
static void compute_hessian(struct state *state, double *hess) { size_t n_frags, n_coord; double *xyzabc, *grad_f, *grad_b; bool central = cfg_get_bool(state->cfg, "hess_central"); check_fail(efp_get_frag_count(state->efp, &n_frags)); n_coord = 6 * n_frags; xyzabc = xmalloc(n_coord * sizeof(double)); grad_f = xmalloc(n_coord * sizeof(double)); grad_b = xmalloc(n_coord * sizeof(double)); check_fail(efp_get_coordinates(state->efp, xyzabc)); if (!central) { memcpy(grad_b, state->grad, n_frags * 6 * sizeof(double)); for (size_t i = 0; i < n_frags; i++) { const double *euler = xyzabc + 6 * i + 3; double *gradptr = grad_b + 6 * i + 3; efp_torque_to_derivative(euler, gradptr, gradptr); } } for (size_t i = 0; i < n_coord; i++) { double save = xyzabc[i]; double step = i % 6 < 3 ? cfg_get_double(state->cfg, "num_step_dist") : cfg_get_double(state->cfg, "num_step_angle"); show_progress(i + 1, n_coord, "FORWARD"); xyzabc[i] = save + step; compute_gradient(state, n_frags, xyzabc, grad_f); if (central) { show_progress(i + 1, n_coord, "BACKWARD"); xyzabc[i] = save - step; compute_gradient(state, n_frags, xyzabc, grad_b); } double delta = central ? 2.0 * step : step; for (size_t j = 0; j < n_coord; j++) hess[i * n_coord + j] = (grad_f[j] - grad_b[j]) / delta; xyzabc[i] = save; } /* restore original coordinates */ check_fail(efp_set_coordinates(state->efp, EFP_COORD_TYPE_XYZABC, xyzabc)); /* reduce error by computing the average of H(i,j) and H(j,i) */ for (size_t i = 0; i < n_coord; i++) { for (size_t j = i + 1; j < n_coord; j++) { double sum = hess[i * n_coord + j] + hess[j * n_coord + i]; hess[i * n_coord + j] = 0.5 * sum; hess[j * n_coord + i] = hess[i * n_coord + j]; } } free(xyzabc); free(grad_f); free(grad_b); msg("\n\n"); }
/* * Read all reloadable configuration directives */ static void config_reload(int reload) { Cfg *cfg; CfgGroup *grp; List *groups; long map_url_max; Octstr *s; long i; long new_value; int new_bool; Octstr *http_proxy_host; Octstr *http_interface_name; long http_proxy_port; int http_proxy_ssl = 0; List *http_proxy_exceptions; Octstr *http_proxy_username; Octstr *http_proxy_password; Octstr *http_proxy_exceptions_regex; int warn_map_url = 0; /* XXX TO-DO: if(reload) implement wapbox.suspend/mutex.lock */ if (reload) debug("config_reload", 0, "Reloading configuration"); /* * NOTE: we could lstat config file and only reload if it was modified, * but as we have a include directive, we don't know every file's * timestamp at this point */ cfg = cfg_create(config_filename); if (cfg_read(cfg) == -1) { warning(0, "Couldn't %sload configuration from `%s'.", (reload ? "re" : ""), octstr_get_cstr(config_filename)); return; } grp = cfg_get_single_group(cfg, octstr_imm("core")); http_proxy_host = cfg_get(grp, octstr_imm("http-proxy-host")); http_proxy_port = -1; cfg_get_integer(&http_proxy_port, grp, octstr_imm("http-proxy-port")); #ifdef HAVE_LIBSSL cfg_get_bool(&http_proxy_ssl, grp, octstr_imm("http-proxy-ssl")); #endif /* HAVE_LIBSSL */ http_proxy_username = cfg_get(grp, octstr_imm("http-proxy-username")); http_proxy_password = cfg_get(grp, octstr_imm("http-proxy-password")); http_proxy_exceptions = cfg_get_list(grp, octstr_imm("http-proxy-exceptions")); http_proxy_exceptions_regex = cfg_get(grp, octstr_imm("http-proxy-exceptions-regex")); if (http_proxy_host != NULL && http_proxy_port > 0) { http_use_proxy(http_proxy_host, http_proxy_port, http_proxy_ssl, http_proxy_exceptions, http_proxy_username, http_proxy_password, http_proxy_exceptions_regex); } octstr_destroy(http_proxy_host); octstr_destroy(http_proxy_username); octstr_destroy(http_proxy_password); octstr_destroy(http_proxy_exceptions_regex); gwlist_destroy(http_proxy_exceptions, octstr_destroy_item); grp = cfg_get_single_group(cfg, octstr_imm("wapbox")); if (grp == NULL) { warning(0, "No 'wapbox' group in configuration."); return; } if (cfg_get_integer(&new_value, grp, octstr_imm("log-level")) != -1) { reload_int(reload, octstr_imm("log level"), &logfilelevel, &new_value); logfilelevel = new_value; log_set_log_level(new_value); } /* Configure interface name for http requests */ http_interface_name = cfg_get(grp, octstr_imm("http-interface-name")); if (http_interface_name != NULL) { http_set_interface(http_interface_name); octstr_destroy(http_interface_name); } /* * users may define 'smart-errors' to have WML decks returned with * error information instead of signaling using the HTTP reply codes */ cfg_get_bool(&new_bool, grp, octstr_imm("smart-errors")); reload_bool(reload, octstr_imm("smart error messaging"), &wsp_smart_errors, &new_bool); /* decide if our XML parser within WML compiler is strict or relaxed */ cfg_get_bool(&new_bool, grp, octstr_imm("wml-strict")); reload_bool(reload, octstr_imm("XML within WML has to be strict"), &wml_xml_strict, &new_bool); if (!wml_xml_strict) warning(0, "'wml-strict' config directive has been set to no, " "this may make you vulnerable against XML bogus input."); if (cfg_get_bool(&new_bool, grp, octstr_imm("concatenation")) == 1) reload_bool(reload, octstr_imm("concatenation"), &concatenation, &new_bool); else concatenation = 1; if (cfg_get_integer(&new_value, grp, octstr_imm("max-messages")) != -1) { max_messages = new_value; reload_int(reload, octstr_imm("max messages"), &max_messages, &new_value); } /* configure URL mappings */ map_url_max = -1; cfg_get_integer(&map_url_max, grp, octstr_imm("map-url-max")); if (map_url_max > 0) warn_map_url = 1; if (reload) { /* clear old map */ wap_map_destroy(); wap_map_user_destroy(); } if ((device_home = cfg_get(grp, octstr_imm("device-home"))) != NULL) { wap_map_url_config_device_home(octstr_get_cstr(device_home)); } if ((s = cfg_get(grp, octstr_imm("map-url"))) != NULL) { warn_map_url = 1; wap_map_url_config(octstr_get_cstr(s)); octstr_destroy(s); } debug("wap", 0, "map_url_max = %ld", map_url_max); for (i = 0; i <= map_url_max; i++) { Octstr *name; name = octstr_format("map-url-%d", i); if ((s = cfg_get(grp, name)) != NULL) wap_map_url_config(octstr_get_cstr(s)); octstr_destroy(name); } /* warn the user that he/she should use the new wap-url-map groups */ if (warn_map_url) warning(0, "'map-url' config directive and related are deprecated, " "please use wap-url-map group"); /* configure wap-url-map */ groups = cfg_get_multi_group(cfg, octstr_imm("wap-url-map")); while (groups && (grp = gwlist_extract_first(groups)) != NULL) { Octstr *name, *url, *map_url, *send_msisdn_query; Octstr *send_msisdn_header, *send_msisdn_format; int accept_cookies; name = cfg_get(grp, octstr_imm("name")); url = cfg_get(grp, octstr_imm("url")); map_url = cfg_get(grp, octstr_imm("map-url")); send_msisdn_query = cfg_get(grp, octstr_imm("send-msisdn-query")); send_msisdn_header = cfg_get(grp, octstr_imm("send-msisdn-header")); send_msisdn_format = cfg_get(grp, octstr_imm("send-msisdn-format")); accept_cookies = -1; cfg_get_bool(&accept_cookies, grp, octstr_imm("accept-cookies")); wap_map_add_url(name, url, map_url, send_msisdn_query, send_msisdn_header, send_msisdn_format, accept_cookies); info(0, "Added wap-url-map <%s> with url <%s>, map-url <%s>, " "send-msisdn-query <%s>, send-msisdn-header <%s>, " "send-msisdn-format <%s>, accept-cookies <%s>", octstr_get_cstr(name), octstr_get_cstr(url), octstr_get_cstr(map_url), octstr_get_cstr(send_msisdn_query), octstr_get_cstr(send_msisdn_header), octstr_get_cstr(send_msisdn_format), (accept_cookies ? "yes" : "no")); } gwlist_destroy(groups, NULL); /* configure wap-user-map */ groups = cfg_get_multi_group(cfg, octstr_imm("wap-user-map")); while (groups && (grp = gwlist_extract_first(groups)) != NULL) { Octstr *name, *user, *pass, *msisdn; name = cfg_get(grp, octstr_imm("name")); user = cfg_get(grp, octstr_imm("user")); pass = cfg_get(grp, octstr_imm("pass")); msisdn = cfg_get(grp, octstr_imm("msisdn")); wap_map_add_user(name, user, pass, msisdn); info(0,"Added wap-user-map <%s> with credentials <%s:%s> " "and MSISDN <%s>", octstr_get_cstr(name), octstr_get_cstr(user), octstr_get_cstr(pass), octstr_get_cstr(msisdn)); } gwlist_destroy(groups, NULL); cfg_destroy(cfg); /* XXX TO-DO: if(reload) implement wapbox.resume/mutex.unlock */ }
static Cfg *init_wapbox(Cfg *cfg) { CfgGroup *grp; Octstr *s; Octstr *logfile; int lf, m; long value; lf = m = 1; cfg_dump(cfg); /* * Extract info from the core group. */ grp = cfg_get_single_group(cfg, octstr_imm("core")); if (grp == NULL) panic(0, "No 'core' group in configuration."); if (cfg_get_integer(&bearerbox_port,grp,octstr_imm("wapbox-port")) == -1) panic(0, "No 'wapbox-port' in core group"); #ifdef HAVE_LIBSSL cfg_get_bool(&bearerbox_ssl, grp, octstr_imm("wapbox-port-ssl")); #endif /* HAVE_LIBSSL */ /* load parameters that could be later reloaded */ config_reload(0); conn_config_ssl(grp); /* * And the rest of the pull info comes from the wapbox group. */ grp = cfg_get_single_group(cfg, octstr_imm("wapbox")); if (grp == NULL) panic(0, "No 'wapbox' group in configuration."); bearerbox_host = cfg_get(grp, octstr_imm("bearerbox-host")); if (cfg_get_integer(&timer_freq, grp, octstr_imm("timer-freq")) == -1) timer_freq = DEFAULT_TIMER_FREQ; logfile = cfg_get(grp, octstr_imm("log-file")); if (logfile != NULL) { log_open(octstr_get_cstr(logfile), logfilelevel, GW_NON_EXCL); info(0, "Starting to log to file %s level %ld", octstr_get_cstr(logfile), logfilelevel); } octstr_destroy(logfile); if ((s = cfg_get(grp, octstr_imm("syslog-level"))) != NULL) { long level; Octstr *facility; if ((facility = cfg_get(grp, octstr_imm("syslog-facility"))) != NULL) { log_set_syslog_facility(octstr_get_cstr(facility)); octstr_destroy(facility); } if (octstr_compare(s, octstr_imm("none")) == 0) { log_set_syslog(NULL, 0); debug("wap", 0, "syslog parameter is none"); } else if (octstr_parse_long(&level, s, 0, 10) > 0) { log_set_syslog("wapbox", level); debug("wap", 0, "syslog parameter is %ld", level); } octstr_destroy(s); } else { log_set_syslog(NULL, 0); debug("wap", 0, "no syslog parameter"); } /* determine which timezone we use for access logging */ if ((s = cfg_get(grp, octstr_imm("access-log-time"))) != NULL) { lf = (octstr_case_compare(s, octstr_imm("gmt")) == 0) ? 0 : 1; octstr_destroy(s); } /* should predefined markers be used, ie. prefixing timestamp */ cfg_get_bool(&m, grp, octstr_imm("access-log-clean")); /* open access-log file */ if ((s = cfg_get(grp, octstr_imm("access-log"))) != NULL) { info(0, "Logging accesses to '%s'.", octstr_get_cstr(s)); alog_open(octstr_get_cstr(s), lf, m ? 0 : 1); octstr_destroy(s); } if (cfg_get_integer(&value, grp, octstr_imm("http-timeout")) == 0) http_set_client_timeout(value); /* configure the 'wtls' group */ #if (HAVE_WTLS_OPENSSL) /* Load up the necessary keys */ grp = cfg_get_single_group(cfg, octstr_imm("wtls")); if (grp != NULL) { if ((s = cfg_get(grp, octstr_imm("certificate-file"))) != NULL) { if (octstr_compare(s, octstr_imm("none")) == 0) { debug("bbox", 0, "certificate file not set"); } else { /* Load the certificate into the necessary parameter */ get_cert_from_file(s, &x509_cert); gw_assert(x509_cert != NULL); debug("bbox", 0, "certificate parameter is %s", octstr_get_cstr(s)); } octstr_destroy(s); } else panic(0, "No 'certificate-file' in wtls group"); if ((s = cfg_get(grp, octstr_imm("privatekey-file"))) != NULL) { Octstr *password; password = cfg_get(grp, octstr_imm("privatekey-password")); if (octstr_compare(s, octstr_imm("none")) == 0) { debug("bbox", 0, "privatekey-file not set"); } else { /* Load the private key into the necessary parameter */ get_privkey_from_file(s, &private_key, password); gw_assert(private_key != NULL); debug("bbox", 0, "certificate parameter is %s", octstr_get_cstr(s)); } if (password != NULL) octstr_destroy(password); octstr_destroy(s); } else panic(0, "No 'privatekey-file' in wtls group"); } #endif /* * Check if we have a 'radius-acct' proxy group and start the * corresponding thread for the proxy. */ grp = cfg_get_single_group(cfg, octstr_imm("radius-acct")); if (grp) { radius_acct_init(grp); } /* * We pass ppg configuration groups to the ppg module. */ grp = cfg_get_single_group(cfg, octstr_imm("ppg")); if (grp == NULL) { cfg_destroy(cfg); return NULL; } return cfg; }
static Cfg *init_bearerbox(Cfg *cfg) { CfgGroup *grp; Octstr *log, *val; long loglevel, store_dump_freq, value; int lf, m; #ifdef HAVE_LIBSSL Octstr *ssl_server_cert_file; Octstr *ssl_server_key_file; int ssl_enabled = 0; #endif /* HAVE_LIBSSL */ Octstr *http_proxy_host = NULL; long http_proxy_port = -1; int http_proxy_ssl = 0; List *http_proxy_exceptions = NULL; Octstr *http_proxy_username = NULL; Octstr *http_proxy_password = NULL; Octstr *http_proxy_exceptions_regex = NULL; /* defaults: use localtime and markers for access-log */ lf = m = 1; grp = cfg_get_single_group(cfg, octstr_imm("core")); log = cfg_get(grp, octstr_imm("log-file")); if (log != NULL) { if (cfg_get_integer(&loglevel, grp, octstr_imm("log-level")) == -1) loglevel = 0; log_open(octstr_get_cstr(log), loglevel, GW_NON_EXCL); octstr_destroy(log); } if ((val = cfg_get(grp, octstr_imm("syslog-level"))) != NULL) { long level; Octstr *facility; if ((facility = cfg_get(grp, octstr_imm("syslog-facility"))) != NULL) { log_set_syslog_facility(octstr_get_cstr(facility)); octstr_destroy(facility); } if (octstr_compare(val, octstr_imm("none")) == 0) { log_set_syslog(NULL, 0); } else if (octstr_parse_long(&level, val, 0, 10) > 0) { log_set_syslog("bearerbox", level); } octstr_destroy(val); } else { log_set_syslog(NULL, 0); } if (check_config(cfg) == -1) panic(0, "Cannot start with corrupted configuration"); /* determine which timezone we use for access logging */ if ((log = cfg_get(grp, octstr_imm("access-log-time"))) != NULL) { lf = (octstr_case_compare(log, octstr_imm("gmt")) == 0) ? 0 : 1; octstr_destroy(log); } /* should predefined markers be used, ie. prefixing timestamp */ cfg_get_bool(&m, grp, octstr_imm("access-log-clean")); /* custom access-log format */ if ((log = cfg_get(grp, octstr_imm("access-log-format"))) != NULL) { bb_alog_init(log); octstr_destroy(log); } /* open access-log file */ if ((log = cfg_get(grp, octstr_imm("access-log"))) != NULL) { alog_open(octstr_get_cstr(log), lf, m ? 0 : 1); octstr_destroy(log); } if (cfg_get_integer(&store_dump_freq, grp, octstr_imm("store-dump-freq")) == -1) store_dump_freq = -1; log = cfg_get(grp, octstr_imm("store-file")); /* initialize the store file */ if (log != NULL) { warning(0, "'store-file' option deprecated, please use 'store-location' and 'store-type' instead."); val = octstr_create("file"); } else { log = cfg_get(grp, octstr_imm("store-location")); val = cfg_get(grp, octstr_imm("store-type")); } if (store_init(val, log, store_dump_freq, msg_pack, msg_unpack_wrapper) == -1) panic(0, "Could not start with store init failed."); octstr_destroy(val); octstr_destroy(log); cfg_get_integer(&http_proxy_port, grp, octstr_imm("http-proxy-port")); #ifdef HAVE_LIBSSL cfg_get_bool(&http_proxy_ssl, grp, octstr_imm("http-proxy-ssl")); #endif /* HAVE_LIBSSL */ http_proxy_host = cfg_get(grp, octstr_imm("http-proxy-host")); http_proxy_username = cfg_get(grp, octstr_imm("http-proxy-username")); http_proxy_password = cfg_get(grp, octstr_imm("http-proxy-password")); http_proxy_exceptions = cfg_get_list(grp, octstr_imm("http-proxy-exceptions")); http_proxy_exceptions_regex = cfg_get(grp, octstr_imm("http-proxy-exceptions-regex")); conn_config_ssl (grp); /* * Make sure we have "ssl-server-cert-file" and "ssl-server-key-file" specified * in the core group since we need it to run SSL-enabled internal box * connections configured via "smsbox-port-ssl = yes" and "wapbox-port-ssl = yes". * Check only these, because for "admin-port-ssl" and "sendsms-port-ssl" for the * SSL-enabled HTTP servers are probed within gw/bb_http.c:httpadmin_start() */ #ifdef HAVE_LIBSSL ssl_server_cert_file = cfg_get(grp, octstr_imm("ssl-server-cert-file")); ssl_server_key_file = cfg_get(grp, octstr_imm("ssl-server-key-file")); if (ssl_server_cert_file != NULL && ssl_server_key_file != NULL) { /* we are fine, at least files are specified in the configuration */ } else { cfg_get_bool(&ssl_enabled, grp, octstr_imm("smsbox-port-ssl")); cfg_get_bool(&ssl_enabled, grp, octstr_imm("wapbox-port-ssl")); if (ssl_enabled) { panic(0, "You MUST specify cert and key files within core group for SSL-enabled inter-box connections!"); } } octstr_destroy(ssl_server_cert_file); octstr_destroy(ssl_server_key_file); #endif /* HAVE_LIBSSL */ /* if all seems to be OK by the first glimpse, real start-up */ outgoing_sms = gwlist_create(); incoming_sms = gwlist_create(); outgoing_wdp = gwlist_create(); incoming_wdp = gwlist_create(); outgoing_sms_counter = counter_create(); incoming_sms_counter = counter_create(); incoming_dlr_counter = counter_create(); outgoing_dlr_counter = counter_create(); outgoing_wdp_counter = counter_create(); incoming_wdp_counter = counter_create(); status_mutex = mutex_create(); outgoing_sms_load = load_create(); /* add 60,300,-1 entries */ load_add_interval(outgoing_sms_load, 60); load_add_interval(outgoing_sms_load, 300); load_add_interval(outgoing_sms_load, -1); incoming_sms_load = load_create(); /* add 60,300,-1 entries */ load_add_interval(incoming_sms_load, 60); load_add_interval(incoming_sms_load, 300); load_add_interval(incoming_sms_load, -1); incoming_dlr_load = load_create(); /* add 60,300,-1 entries to dlr */ load_add_interval(incoming_dlr_load, 60); load_add_interval(incoming_dlr_load, 300); load_add_interval(incoming_dlr_load, -1); outgoing_dlr_load = load_create(); /* add 60,300,-1 entries to dlr */ load_add_interval(outgoing_dlr_load, 60); load_add_interval(outgoing_dlr_load, 300); load_add_interval(outgoing_dlr_load, -1); setup_signal_handlers(); /* http-admin is REQUIRED */ httpadmin_start(cfg); if (cfg_get_integer(&max_incoming_sms_qlength, grp, octstr_imm("maximum-queue-length")) == -1) max_incoming_sms_qlength = -1; else { warning(0, "Option 'maximum-queue-length' is deprecated! Please use" " 'sms-incoming-queue-limit' instead!"); } if (max_incoming_sms_qlength == -1 && cfg_get_integer(&max_incoming_sms_qlength, grp, octstr_imm("sms-incoming-queue-limit")) == -1) max_incoming_sms_qlength = -1; if (cfg_get_integer(&max_outgoing_sms_qlength, grp, octstr_imm("sms-outgoing-queue-limit")) == -1) max_outgoing_sms_qlength = -1; if (max_outgoing_sms_qlength < 0) max_outgoing_sms_qlength = DEFAULT_OUTGOING_SMS_QLENGTH; if (cfg_get_integer(&value, grp, octstr_imm("http-timeout")) == 0) http_set_client_timeout(value); #ifndef NO_SMS { List *list; list = cfg_get_multi_group(cfg, octstr_imm("smsc")); if (list != NULL) { gwlist_destroy(list, NULL); if (start_smsc(cfg) == -1) { panic(0, "Unable to start SMSCs."); return NULL; } } } #endif #ifndef NO_WAP grp = cfg_get_single_group(cfg, octstr_imm("core")); val = cfg_get(grp, octstr_imm("wdp-interface-name")); if (val != NULL && octstr_len(val) > 0) start_udp(cfg); octstr_destroy(val); if (cfg_get_single_group(cfg, octstr_imm("wapbox")) != NULL) start_wap(cfg); #endif if (http_proxy_host != NULL && http_proxy_port > 0) { http_use_proxy(http_proxy_host, http_proxy_port, http_proxy_ssl, http_proxy_exceptions, http_proxy_username, http_proxy_password, http_proxy_exceptions_regex); } octstr_destroy(http_proxy_host); octstr_destroy(http_proxy_username); octstr_destroy(http_proxy_password); octstr_destroy(http_proxy_exceptions_regex); gwlist_destroy(http_proxy_exceptions, octstr_destroy_item); return cfg; }
int smsc_http_create(SMSCConn *conn, CfgGroup *cfg) { ConnData *conndata = NULL; Octstr *type; int ssl = 0; /* indicate if SSL-enabled server should be used */ long max_ps; if ((type = cfg_get(cfg, octstr_imm("system-type"))) == NULL) { error(0, "HTTP[%s]: 'system-type' missing in smsc 'http' record.", octstr_get_cstr(conn->id)); octstr_destroy(type); return -1; } conndata = gw_malloc(sizeof(ConnData)); /* reset conndata */ memset(conndata, 0, sizeof(ConnData)); conn->data = conndata; conndata->http_ref = NULL; conndata->data = NULL; if (cfg_get_integer(&conndata->port, cfg, octstr_imm("port")) == -1) { warning(0, "HTTP[%s]: 'port' not set in smsc 'http' group.", octstr_get_cstr(conn->id)); conndata->port = -1; } conndata->allow_ip = cfg_get(cfg, octstr_imm("connect-allow-ip")); conndata->send_url = cfg_get(cfg, octstr_imm("send-url")); conndata->username = cfg_get(cfg, octstr_imm("smsc-username")); conndata->password = cfg_get(cfg, octstr_imm("smsc-password")); conndata->system_id = cfg_get(cfg, octstr_imm("system-id")); cfg_get_bool(&conndata->no_sender, cfg, octstr_imm("no-sender")); cfg_get_bool(&conndata->no_coding, cfg, octstr_imm("no-coding")); cfg_get_bool(&conndata->no_sep, cfg, octstr_imm("no-sep")); conndata->proxy = cfg_get(cfg, octstr_imm("system-id")); cfg_get_bool(&ssl, cfg, octstr_imm("use-ssl")); conndata->dlr_url = cfg_get(cfg, octstr_imm("dlr-url")); conndata->alt_charset = cfg_get(cfg, octstr_imm("alt-charset")); if (cfg_get_integer(&max_ps, cfg, octstr_imm("max-pending-submits")) == -1 || max_ps < 1) max_ps = 10; conndata->max_pending_sends = semaphore_create(max_ps); if (conndata->port <= 0 && conndata->send_url == NULL) { error(0, "Sender and receiver disabled. Dummy SMSC not allowed."); goto error; } if (conndata->send_url == NULL) panic(0, "HTTP[%s]: Sending not allowed. No 'send-url' specified.", octstr_get_cstr(conn->id)); if (octstr_case_compare(type, octstr_imm("kannel")) == 0) { if (conndata->username == NULL || conndata->password == NULL) { error(0, "HTTP[%s]: 'username' and 'password' required for Kannel http smsc", octstr_get_cstr(conn->id)); goto error; } conndata->callbacks = &smsc_http_kannel_callback; } else if (octstr_case_compare(type, octstr_imm("brunet")) == 0) { conndata->callbacks = &smsc_http_brunet_callback; } else if (octstr_case_compare(type, octstr_imm("xidris")) == 0) { conndata->callbacks = &smsc_http_xidris_callback; } else if (octstr_case_compare(type, octstr_imm("generic")) == 0) { conndata->callbacks = &smsc_http_generic_callback; } else if (octstr_case_compare(type, octstr_imm("clickatell")) == 0) { conndata->callbacks = &smsc_http_clickatell_callback; } else if (octstr_case_compare(type, octstr_imm("wapme")) == 0) { conndata->callbacks = &smsc_http_wapme_callback; } /* * ADD NEW HTTP SMSC TYPES HERE */ else { error(0, "HTTP[%s]: system-type '%s' unknown smsc 'http' record.", octstr_get_cstr(conn->id), octstr_get_cstr(type)); goto error; } if (conndata->callbacks != NULL && conndata->callbacks->init != NULL && conndata->callbacks->init(conn, cfg)) { error(0, "HTTP[%s]: submodule '%s' init failed.", octstr_get_cstr(conn->id), octstr_get_cstr(type)); goto error; } conndata->open_sends = counter_create(); conndata->msg_to_send = gwlist_create(); gwlist_add_producer(conndata->msg_to_send); conndata->http_ref = http_caller_create(); conn->name = octstr_format("HTTP%s:%S:%d", (ssl?"S":""), type, conndata->port); if (conndata->send_url != NULL) { conn->status = SMSCCONN_ACTIVE; } else { conn->status = SMSCCONN_ACTIVE_RECV; } conn->connect_time = time(NULL); conn->shutdown = httpsmsc_shutdown; conn->queued = httpsmsc_queued; conn->send_msg = httpsmsc_send; conndata->shutdown = 0; /* start receiver thread */ if (conndata->port > 0) { if (http_open_port(conndata->port, ssl) == -1) goto error; if ((conndata->receive_thread = gwthread_create(httpsmsc_receiver, conn)) == -1) goto error; } else conndata->receive_thread = -1; /* start sender threads */ if (conndata->send_url) { if ((conndata->send_cb_thread = gwthread_create(httpsmsc_send_cb, conn)) == -1) goto error; if ((conndata->sender_thread = gwthread_create(httpsmsc_sender, conn)) == -1) goto error; } else { conndata->send_cb_thread = conndata->sender_thread = -1; } info(0, "HTTP[%s]: Initiated and ready", octstr_get_cstr(conn->id)); octstr_destroy(type); return 0; error: error(0, "HTTP[%s]: Failed to create HTTP SMSC connection", octstr_get_cstr(conn->id)); if (conndata->callbacks != NULL && conndata->callbacks->destroy != NULL) conndata->callbacks->destroy(conn); conn->data = NULL; conndata_destroy(conndata); conn->why_killed = SMSCCONN_KILLED_CANNOT_CONNECT; conn->status = SMSCCONN_DEAD; octstr_destroy(type); return -1; }
static void mysql_parse_config(DICT_MYSQL *dict_mysql, const char *mysqlcf) { const char *myname = "mysql_parse_config"; CFG_PARSER *p = dict_mysql->parser; VSTRING *buf; char *hosts; dict_mysql->username = cfg_get_str(p, "user", "", 0, 0); dict_mysql->password = cfg_get_str(p, "password", "", 0, 0); dict_mysql->dbname = cfg_get_str(p, "dbname", "", 1, 0); dict_mysql->result_format = cfg_get_str(p, "result_format", "%s", 1, 0); dict_mysql->option_file = cfg_get_str(p, "option_file", NULL, 0, 0); dict_mysql->option_group = cfg_get_str(p, "option_group", NULL, 0, 0); #if defined(MYSQL_VERSION_ID) && MYSQL_VERSION_ID >= 40000 dict_mysql->tls_key_file = cfg_get_str(p, "tls_key_file", NULL, 0, 0); dict_mysql->tls_cert_file = cfg_get_str(p, "tls_cert_file", NULL, 0, 0); dict_mysql->tls_CAfile = cfg_get_str(p, "tls_CAfile", NULL, 0, 0); dict_mysql->tls_CApath = cfg_get_str(p, "tls_CApath", NULL, 0, 0); dict_mysql->tls_ciphers = cfg_get_str(p, "tls_ciphers", NULL, 0, 0); #if MYSQL_VERSION_ID >= 50023 dict_mysql->tls_verify_cert = cfg_get_bool(p, "tls_verify_cert", -1); #endif #endif /* * XXX: The default should be non-zero for safety, but that is not * backwards compatible. */ dict_mysql->expansion_limit = cfg_get_int(dict_mysql->parser, "expansion_limit", 0, 0, 0); if ((dict_mysql->query = cfg_get_str(p, "query", NULL, 0, 0)) == 0) { /* * No query specified -- fallback to building it from components (old * style "select %s from %s where %s") */ buf = vstring_alloc(64); db_common_sql_build_query(buf, p); dict_mysql->query = vstring_export(buf); } /* * Must parse all templates before we can use db_common_expand() */ dict_mysql->ctx = 0; (void) db_common_parse(&dict_mysql->dict, &dict_mysql->ctx, dict_mysql->query, 1); (void) db_common_parse(0, &dict_mysql->ctx, dict_mysql->result_format, 0); db_common_parse_domain(p, dict_mysql->ctx); /* * Maps that use substring keys should only be used with the full input * key. */ if (db_common_dict_partial(dict_mysql->ctx)) dict_mysql->dict.flags |= DICT_FLAG_PATTERN; else dict_mysql->dict.flags |= DICT_FLAG_FIXED; if (dict_mysql->dict.flags & DICT_FLAG_FOLD_FIX) dict_mysql->dict.fold_buf = vstring_alloc(10); hosts = cfg_get_str(p, "hosts", "", 0, 0); dict_mysql->hosts = argv_split(hosts, " ,\t\r\n"); if (dict_mysql->hosts->argc == 0) { argv_add(dict_mysql->hosts, "localhost", ARGV_END); argv_terminate(dict_mysql->hosts); if (msg_verbose) msg_info("%s: %s: no hostnames specified, defaulting to '%s'", myname, mysqlcf, dict_mysql->hosts->argv[0]); } myfree(hosts); }
static void john_load(void) { struct list_entry *current; #ifndef _MSC_VER umask(077); #endif if (options.flags & FLG_EXTERNAL_CHK) ext_init(options.external, NULL); if (options.flags & FLG_MAKECHR_CHK) { options.loader.flags |= DB_CRACKED; ldr_init_database(&database, &options.loader); if (options.flags & FLG_PASSWD) { ldr_show_pot_file(&database, options.loader.activepot); database.options->flags |= DB_PLAINTEXTS; if ((current = options.passwd->head)) do { ldr_show_pw_file(&database, current->data); } while ((current = current->next)); } else { database.options->flags |= DB_PLAINTEXTS; ldr_show_pot_file(&database, options.loader.activepot); } return; } if (options.flags & FLG_STDOUT) { ldr_init_database(&database, &options.loader); database.format = &dummy_format; memset(&dummy_format, 0, sizeof(dummy_format)); dummy_format.params.plaintext_length = options.length; dummy_format.params.flags = FMT_CASE | FMT_8_BIT; } if (options.flags & FLG_PASSWD) { int total; if (options.flags & FLG_SHOW_CHK) { options.loader.flags |= DB_CRACKED; ldr_init_database(&database, &options.loader); ldr_show_pot_file(&database, options.loader.activepot); if ((current = options.passwd->head)) do { ldr_show_pw_file(&database, current->data); } while ((current = current->next)); printf("%s%d password hash%s cracked, %d left\n", database.guess_count ? "\n" : "", database.guess_count, database.guess_count != 1 ? "es" : "", database.password_count - database.guess_count); return; } if (options.flags & (FLG_SINGLE_CHK | FLG_BATCH_CHK) && status.pass <= 1) options.loader.flags |= DB_WORDS; else if (mem_saving_level) { options.loader.flags &= ~DB_LOGIN; options.loader.max_wordfile_memory = 0; } ldr_init_database(&database, &options.loader); if ((current = options.passwd->head)) do { ldr_load_pw_file(&database, current->data); } while ((current = current->next)); // Unicode (UTF-16) formats may lack UTF-8 support (initially) if (options.utf8 && database.password_count && database.format->params.flags & FMT_UNICODE && !(database.format->params.flags & FMT_UTF8)) { fprintf(stderr, "This format does not yet support UTF-8 conversion\n"); error(); } if ((options.flags & FLG_CRACKING_CHK) && database.password_count) { log_init(LOG_NAME, NULL, options.session); if (status_restored_time) log_event("Continuing an interrupted session"); else log_event("Starting a new session"); log_event("Loaded a total of %s", john_loaded_counts()); /* make sure the format is properly initialized */ fmt_init(database.format); printf("Loaded %s (%s [%s])\n", john_loaded_counts(), database.format->params.format_name, database.format->params.algorithm_name); // Tell External our max length if (options.flags & FLG_EXTERNAL_CHK) ext_init(options.external, &database); } if (database.password_count) { if (database.format->params.flags & FMT_UNICODE) options.store_utf8 = cfg_get_bool(SECTION_OPTIONS, NULL, "UnicodeStoreUTF8", 0); else options.store_utf8 = cfg_get_bool(SECTION_OPTIONS, NULL, "CPstoreUTF8", 0); } if (!options.utf8) { if (options.report_utf8 && options.log_passwords) log_event("- Passwords in this logfile are UTF-8 encoded"); if (options.store_utf8) log_event("- Passwords will be stored UTF-8 encoded in .pot file"); } total = database.password_count; ldr_load_pot_file(&database, options.loader.activepot); ldr_fix_database(&database); if (!database.password_count) { log_discard(); printf("No password hashes %s (see FAQ)\n", total ? "left to crack" : "loaded"); } else if (database.password_count < total) { log_event("Remaining %s", john_loaded_counts()); printf("Remaining %s\n", john_loaded_counts()); } if (options.regen_lost_salts) { extern void build_fake_salts_for_regen_lost(struct db_salt *); build_fake_salts_for_regen_lost(database.salts); } if ((options.flags & FLG_PWD_REQ) && !database.salts) exit(0); } }
static void init_sqlbox(Cfg *cfg) { CfgGroup *grp; Octstr *logfile; long lvl; /* some default values */ sqlbox_port_ssl = 0; bearerbox_port = BB_DEFAULT_SMSBOX_PORT; bearerbox_port_ssl = 0; logfile = NULL; lvl = 0; /* * first we take the port number in bearerbox and other values from the * core group in configuration file */ grp = cfg_get_single_group(cfg, octstr_imm("sqlbox")); if (cfg_get_integer(&bearerbox_port, grp, octstr_imm("bearerbox-port")) == -1) panic(0, "Missing or bad 'bearerbox-port' in sqlbox group"); #ifdef HAVE_LIBSSL cfg_get_bool(&bearerbox_port_ssl, grp, octstr_imm("smsbox-port-ssl")); conn_config_ssl(grp); #endif grp = cfg_get_single_group(cfg, octstr_imm("sqlbox")); if (grp == NULL) panic(0, "No 'sqlbox' group in configuration"); bearerbox_host = cfg_get( grp, octstr_imm("bearerbox-host")); if (bearerbox_host == NULL) bearerbox_host = octstr_create(BB_DEFAULT_HOST); sqlbox_id = cfg_get(grp, octstr_imm("smsbox-id")); global_sender = cfg_get(grp, octstr_imm("global-sender")); if (cfg_get_integer(&sqlbox_port, grp, octstr_imm("smsbox-port")) == -1) sqlbox_port = 13005; /* setup limit per cycle */ if (cfg_get_integer(&limit_per_cycle, grp, octstr_imm("limit-per-cycle")) == -1) limit_per_cycle = DEFAULT_LIMIT_PER_CYCLE; /* set up save parameters */ if (cfg_get_bool(&save_mo, grp, octstr_imm("save-mo")) == -1) save_mo = 1; if (cfg_get_bool(&save_mt, grp, octstr_imm("save-mt")) == -1) save_mt = 1; if (cfg_get_bool(&save_dlr, grp, octstr_imm("save-dlr")) == -1) save_dlr = 1; /* setup logfile stuff */ logfile = cfg_get(grp, octstr_imm("log-file")); cfg_get_integer(&lvl, grp, octstr_imm("log-level")); if (logfile != NULL) { info(0, "Starting to log to file %s level %ld", octstr_get_cstr(logfile), lvl); log_open(octstr_get_cstr(logfile), lvl, GW_NON_EXCL); octstr_destroy(logfile); } sql_type = sqlbox_init_sql(cfg); if (sql_type == NULL) { panic(0, "No proper SQL server defined."); } gw_sql_enter(cfg); sqlbox_status = SQL_RUNNING; }