int main (int argc, char *argv[]) { int option; /* getopt() returns an int */ char buf[MAX_MAILBOX_PATH+1]; char *alt_config = NULL; int r; if ((geteuid()) == 0 && (become_cyrus() != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } while ((option = getopt(argc, argv, "C:rn")) != EOF) { switch (option) { case 'C': /* alt config file */ alt_config = optarg; break; case 'r': disinfect = 1; break; case 'n': notify = 1; break; case 'h': default: usage(argv[0]); } } cyrus_init(alt_config, "cyr_virusscan", 0); if (!engine.name) { fatal("no virus scanner configured", EC_SOFTWARE); } else { if (verbose) printf("Using %s virus scanner\n", engine.name); } engine.state = engine.init(); /* Set namespace -- force standard (internal) */ if ((r = mboxname_init_namespace(&scan_namespace, 1)) != 0) { syslog(LOG_ERR, "%s", error_message(r)); fatal(error_message(r), EC_CONFIG); } mboxlist_init(0); mboxlist_open(NULL); /* open the quota db, we'll need it for expunge */ quotadb_init(0); quotadb_open(NULL); sync_log_init(); if (optind == argc) { /* do the whole partition */ strcpy(buf, "*"); (*scan_namespace.mboxlist_findall)(&scan_namespace, buf, 1, 0, 0, scan_me, NULL); } else { for (; optind < argc; optind++) { strncpy(buf, argv[optind], MAX_MAILBOX_BUFFER); /* Translate any separators in mailboxname */ mboxname_hiersep_tointernal(&scan_namespace, buf, config_virtdomains ? strcspn(buf, "@") : 0); (*scan_namespace.mboxlist_findall)(&scan_namespace, buf, 1, 0, 0, scan_me, NULL); } } if (notify) append_notifications(); sync_log_done(); quotadb_close(); quotadb_done(); mboxlist_close(); mboxlist_done(); engine.destroy(engine.state); cyrus_done(); return 0; }
int main (int argc, char *argv[]) { int option; /* getopt() returns an int */ char *alt_config = NULL; if ((geteuid()) == 0 && (become_cyrus(/*is_master*/0) != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } while ((option = getopt(argc, argv, "C:rn")) != EOF) { switch (option) { case 'C': /* alt config file */ alt_config = optarg; break; case 'r': disinfect = 1; break; case 'n': notify = 1; break; case 'h': default: usage(argv[0]); } } cyrus_init(alt_config, "cyr_virusscan", 0, CONFIG_NEED_PARTITION_DATA); if (!engine.name) { fatal("no virus scanner configured", EC_SOFTWARE); } else { if (verbose) printf("Using %s virus scanner\n", engine.name); } engine.state = engine.init(); mboxlist_init(0); mboxlist_open(NULL); /* open the quota db, we'll need it for expunge */ quotadb_init(0); quotadb_open(NULL); sync_log_init(); /* setup for mailbox event notifications */ mboxevent_init(); if (optind == argc) { /* do the whole partition */ mboxlist_findall(NULL, "*", 1, 0, 0, scan_me, NULL); } else { strarray_t *array = strarray_new(); for (; optind < argc; optind++) { strarray_append(array, argv[optind]); } mboxlist_findallmulti(NULL, array, 1, 0, 0, scan_me, NULL); strarray_free(array); } if (notify) append_notifications(); sync_log_done(); quotadb_close(); quotadb_done(); mboxlist_close(); mboxlist_done(); engine.destroy(engine.state); cyrus_done(); return 0; }