void setup(void) { configure_debug(255,0); config_read(configFile); GetDBParams(); db_connect(); auth_connect(); }
/* * * the test fixtures * */ void setup(void) { reallyquiet = 1; configure_debug(255,0); config_read(configFile); GetDBParams(); db_connect(); auth_connect(); do_add("testfailuser","testpass","md5-hash",0,0,NULL,NULL); }
void setup(void) { configure_debug(511,0); config_read(configFile); GetDBParams(); db_connect(); auth_connect(); g_mime_init(0); init_testuser1(); }
void setup(void) { configure_debug(255,0); config_read(configFile); GetDBParams(); db_connect(); if (! g_thread_supported () ) g_thread_init (NULL); auth_connect(); init_testuser1(); }
void setup(void) { config_get_file(); config_read(configFile); configure_debug(NULL,255,0); GetDBParams(); db_connect(); auth_connect(); init_testuser1(); queue_pool = mempool_open(); }
int main(int argc, char *argv[]) { int check_integrity = 0; int check_iplog = 0, check_replycache = 0; char *timespec_iplog = NULL, *timespec_replycache = NULL; int vacuum_db = 0, purge_deleted = 0, set_deleted = 0, dangling_aliases = 0, rehash = 0; int show_help = 0; int do_nothing = 1; int is_header = 0; int migrate = 0, migrate_limit = 10000; static struct option long_options[] = { { "rehash", 0, 0, 0 }, { 0, 0, 0, 0 } }; int opt_index = 0; int opt; g_mime_init(0); openlog(PNAME, LOG_PID, LOG_MAIL); setvbuf(stdout, 0, _IONBF, 0); /* get options */ opterr = 0; /* suppress error message from getopt() */ while ((opt = getopt_long(argc, argv, "-acbtl:r:pudsMm:" "i" "f:qnyvVh", long_options, &opt_index)) != -1) { /* The initial "-" of optstring allows unaccompanied * options and reports them as the optarg to opt 1 (not '1') */ switch (opt) { case 0: do_nothing = 0; if (strcmp(long_options[opt_index].name,"rehash")==0) rehash = 1; break; case 'a': /* This list should be kept up to date. */ vacuum_db = 1; purge_deleted = 1; set_deleted = 1; dangling_aliases = 1; check_integrity = 1; is_header = 1; do_nothing = 0; break; case 'c': vacuum_db = 1; do_nothing = 0; break; case 'b': is_header = 1; do_nothing = 0; break; case 'p': purge_deleted = 1; do_nothing = 0; break; case 'd': set_deleted = 1; do_nothing = 0; break; case 's': dangling_aliases = 1; do_nothing = 0; break; case 't': check_integrity = 1; do_nothing = 0; break; case 'u': /* deprecated */ break; case 'l': check_iplog = 1; do_nothing = 0; if (optarg) timespec_iplog = g_strdup(optarg); break; case 'r': check_replycache = 1; do_nothing = 0; if (optarg) timespec_replycache = g_strdup(optarg); break; case 'M': migrate = 1; do_nothing = 0; break; case 'm': if (optarg) migrate_limit = atoi(optarg); break; case 'i': qerrorf("Interactive console is not supported in this release.\n"); return 1; /* Common options */ case 'h': show_help = 1; do_nothing = 0; break; case 'n': no_to_all = 1; break; case 'y': yes_to_all = 1; break; case 'q': /* If we get q twice, be really quiet! */ if (quiet) reallyquiet = 1; if (!verbose) quiet = 1; break; case 'f': if (optarg && strlen(optarg) > 0) configFile = optarg; else { qerrorf("dbmail-util: -f requires a filename\n\n" ); return 1; } break; case 'v': verbose = 1; break; case 'V': PRINTF_THIS_IS_DBMAIL; return 1; default: printf("unrecognized option [%c]\n", optopt); show_help = 1; break; } } if (do_nothing || show_help || (no_to_all && yes_to_all)) { do_showhelp(); return 1; } /* Don't make any changes unless specifically authorized. */ if (!yes_to_all) { qprintf("Choosing dry-run mode. No changes will be made at this time.\n"); no_to_all = 1; } config_read(configFile); SetTraceLevel("DBMAIL"); GetDBParams(); qverbosef("Opening connection to database... \n"); if (db_connect() != 0) { qerrorf("Failed. An error occured. Please check log.\n"); return -1; } qverbosef("Opening connection to authentication... \n"); if (auth_connect() != 0) { qerrorf("Failed. An error occured. Please check log.\n"); return -1; } qverbosef("Ok. Connected.\n"); if (check_integrity) do_check_integrity(); if (purge_deleted) do_purge_deleted(); if (is_header) do_header_cache(); if (set_deleted) do_set_deleted(); if (dangling_aliases) do_dangling_aliases(); if (check_iplog) do_check_iplog(timespec_iplog); if (check_replycache) do_check_replycache(timespec_replycache); if (vacuum_db) do_vacuum_db(); if (rehash) do_rehash(); if (migrate) do_migrate(migrate_limit); if (!has_errors && !serious_errors) { qprintf("\nMaintenance done. No errors found.\n"); } else { qerrorf("\nMaintenance done. Errors were found"); if (serious_errors) { qerrorf(" but not fixed due to failures.\n"); qerrorf("Please check the logs for further details, " "turning up the trace level as needed.\n"); // Indicate that something went really wrong has_errors = 3; } else if (no_to_all) { qerrorf(" but not fixed.\n"); qerrorf("Run again with the '-y' option to " "repair the errors.\n"); // Indicate that the program should be run with -y has_errors = 2; } else if (yes_to_all) { qerrorf(" and fixed.\n"); qerrorf("We suggest running dbmail-util again to " "confirm that all errors were repaired.\n"); // Indicate that the program should be run again has_errors = 1; } } auth_disconnect(); db_disconnect(); config_free(); g_mime_shutdown(); return has_errors; }
int main(int argc, char *argv[]) { int opt = 0, opt_prev = 0; int show_help = 0; int result = 0, delete_after_dump = 0, recursive = 0; char *user=NULL, *mailbox=NULL, *outfile=NULL, *basedir=NULL, *search=NULL; openlog(PNAME, LOG_PID, LOG_MAIL); setvbuf(stdout, 0, _IONBF, 0); g_mime_init(0); /* get options */ opterr = 0; /* suppress error message from getopt() */ while ((opt = getopt(argc, argv, "-u:m:o:b:s:dDr" /* Major modes */ "f:qvVh" /* Common options */ )) != -1) { /* The initial "-" of optstring allows unaccompanied * options and reports them as the optarg to opt 1 (not '1') */ if (opt == 1) opt = opt_prev; opt_prev = opt; switch (opt) { /* export specific options */ case 'u': if (optarg && strlen(optarg)) user = optarg; break; case 'm': if (optarg && strlen(optarg)) mailbox = optarg; break; case 'b': if (optarg && strlen(optarg)) basedir = optarg; break; case 'o': if (optarg && strlen(optarg)) outfile = optarg; break; case 'd': delete_after_dump |= 1; break; case 'D': delete_after_dump |= 2; break; case 'r': recursive = 1; break; case 's': if (optarg && strlen(optarg)) search = optarg; else { qerrorf("dbmail-mailbox: -s requires a value\n\n"); result = 1; } break; /* Common options */ case 'f': if (optarg && strlen(optarg) > 0) configFile = optarg; else { qerrorf("dbmail-mailbox: -f requires a filename\n\n"); result = 1; } break; case 'h': show_help = 1; break; case 'q': /* If we get q twice, be really quiet! */ if (quiet) reallyquiet = 1; if (!verbose) quiet = 1; break; case 'v': if (!quiet) verbose = 1; break; case 'V': /* Show the version and return non-zero. */ PRINTF_THIS_IS_DBMAIL; result = 1; break; default: /* printf("unrecognized option [%c], continuing...\n",optopt); */ break; } /* If there's a non-negative return code, * it's time to free memory and bail out. */ if (result) goto freeall; } /* If nothing is happening, show the help text. */ if (!user || (basedir && outfile) || show_help) { do_showhelp(); result = 1; goto freeall; } /* read the config file */ if (config_read(configFile) == -1) { qerrorf("Failed. Unable to read config file %s\n", configFile); result = -1; goto freeall; } SetTraceLevel("DBMAIL"); GetDBParams(); /* open database connection */ if (db_connect() != 0) { qerrorf ("Failed. Could not connect to database (check log)\n"); result = -1; goto freeall; } /* open authentication connection */ if (auth_connect() != 0) { qerrorf("Failed. Could not connect to authentication (check log)\n"); result = -1; goto freeall; } /* Loop over all user accounts if there's a wildcard. */ if (strchr(user, '?') || strchr(user, '*')) { GList *all_users = auth_get_known_users(); GList *matching_users = match_glob_list(user, all_users); GList *users = g_list_first(matching_users); if (!users) { qerrorf("Error: no users matching [%s] were found.\n", user); g_list_destroy(all_users); result = -1; goto freeall; } while (users) { result = do_export(users->data, mailbox, basedir, outfile, search, delete_after_dump, recursive); if (!g_list_next(users)) break; users = g_list_next(users); } g_list_destroy(all_users); g_list_destroy(matching_users); } else { /* No globbing, just run with this one user. */ result = do_export(user, mailbox, basedir, outfile, search, delete_after_dump, recursive); } /* Here's where we free memory and quit. * Be sure that all of these are NULL safe! */ freeall: db_disconnect(); auth_disconnect(); config_free(); g_mime_shutdown(); if (result < 0) qerrorf("Command failed.\n"); return result; }