static void cmdloop(void) { int ret = FALSE; if (chdir("/tmp/")) { syslog(LOG_ERR, "Failed to chdir to /tmp/"); ret = TRUE; /* exit immediately */ } capabilities(sieved_out, sieved_saslconn, 0, 0, 0); /* initialize lexer */ lex_init(); while (ret != TRUE) { if (backend) { /* create a pipe from client to backend */ bitpipe(); /* pipe has been closed */ return; } ret = parser(sieved_out, sieved_in); } sync_log_done(); /* done */ shut_down(0); }
int main(int argc, char *argv[]) { extern char *optarg; int opt, r = 0; char *alt_config = NULL, *intname = NULL, *extname = NULL; struct mailbox *mailbox = NULL; int mode = MODE_UNKNOWN; unsigned numrestored = 0; time_t time_since = time(NULL); int len, secs = 0; unsigned long *uids = NULL; unsigned nuids = 0; while ((opt = getopt(argc, argv, "C:laudt:f:v")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'l': if (mode != MODE_UNKNOWN) usage(); mode = MODE_LIST; break; case 'a': if (mode != MODE_UNKNOWN) usage(); mode = MODE_ALL; break; case 't': if (mode != MODE_UNKNOWN) usage(); mode = MODE_TIME; secs = atoi(optarg); len = strlen(optarg); if ((secs > 0) && (len > 1)) { switch (optarg[len-1]) { case 'm': secs *= 60; break; case 'h': secs *= (60*60); break; case 'd': secs *= (24*60*60); break; case 'w': secs *= (7*24*60*60); break; } } time_since = time(NULL) - secs; break; case 'u': if (mode != MODE_UNKNOWN) usage(); mode = MODE_UID; break; case 'd': unsetdeleted = 1; break; case 'f': addflag = optarg; break; case 'v': verbose = 1; break; default: usage(); break; } } /* sanity check */ if (mode == MODE_UNKNOWN || (optind + (mode == MODE_UID ? 1 : 0)) >= argc) usage(); cyrus_init(alt_config, "unexpunge", 0, 0); sync_log_init(); if (addflag && addflag[0] == '\\') { syslog(LOG_ERR, "can't set a system flag"); fatal("can't set a system flag", EX_SOFTWARE); } /* Set namespace -- force standard (internal) */ if ((r = mboxname_init_namespace(&unex_namespace, 1)) != 0) { syslog(LOG_ERR, "%s", error_message(r)); fatal(error_message(r), EX_CONFIG); } /* Translate mailboxname */ intname = mboxname_from_external(argv[optind], &unex_namespace, NULL); if (mode == MODE_LIST) { list_expunged(intname); goto done; } /* Open/lock header */ r = mailbox_open_iwl(intname, &mailbox); if (r) { printf("Failed to open mailbox '%s'\n", intname); goto done; } if (mode == MODE_UID) { unsigned i; nuids = argc - ++optind; uids = (unsigned long *) xmalloc(nuids * sizeof(unsigned long)); for (i = 0; i < nuids; i++) uids[i] = strtoul(argv[optind+i], NULL, 10); /* Sort the UIDs so we can binary search */ qsort(uids, nuids, sizeof(unsigned long), compare_uid); } extname = mboxname_to_external(intname, &unex_namespace, NULL); printf("restoring %sexpunged messages in mailbox '%s'\n", mode == MODE_ALL ? "all " : "", extname); r = restore_expunged(mailbox, mode, uids, nuids, time_since, &numrestored, extname); if (!r) { printf("restored %u expunged messages\n", numrestored); syslog(LOG_NOTICE, "restored %u expunged messages in mailbox '%s'", numrestored, extname); } mailbox_close(&mailbox); done: free(intname); free(extname); sync_log_done(); cyrus_done(); exit(r); }
/* * channelp = NULL => we're not processing a channel * *channelp = NULL => we're processing the default channel * *channelp = "foo" => we're processing the channel named "foo" */ static int do_sync(sync_log_reader_t *slr, const char **channelp) { struct sync_action_list *user_list = sync_action_list_create(); struct sync_action_list *unuser_list = sync_action_list_create(); struct sync_action_list *meta_list = sync_action_list_create(); struct sync_action_list *mailbox_list = sync_action_list_create(); struct sync_action_list *unmailbox_list = sync_action_list_create(); struct sync_action_list *quota_list = sync_action_list_create(); struct sync_action_list *annot_list = sync_action_list_create(); struct sync_action_list *seen_list = sync_action_list_create(); struct sync_action_list *sub_list = sync_action_list_create(); struct sync_name_list *mboxname_list = sync_name_list_create(); const char *args[3]; struct sync_action *action; int r = 0; while (1) { r = sync_log_reader_getitem(slr, args); if (r == EOF) break; if (!strcmp(args[0], "USER")) sync_action_list_add(user_list, NULL, args[1]); else if (!strcmp(args[0], "UNUSER")) sync_action_list_add(unuser_list, NULL, args[1]); else if (!strcmp(args[0], "META")) sync_action_list_add(meta_list, NULL, args[1]); else if (!strcmp(args[0], "SIEVE")) sync_action_list_add(meta_list, NULL, args[1]); else if (!strcmp(args[0], "APPEND")) /* just a mailbox event */ sync_action_list_add(mailbox_list, args[1], NULL); else if (!strcmp(args[0], "MAILBOX")) sync_action_list_add(mailbox_list, args[1], NULL); else if (!strcmp(args[0], "UNMAILBOX")) sync_action_list_add(unmailbox_list, args[1], NULL); else if (!strcmp(args[0], "QUOTA")) sync_action_list_add(quota_list, args[1], NULL); else if (!strcmp(args[0], "ANNOTATION")) sync_action_list_add(annot_list, args[1], NULL); else if (!strcmp(args[0], "SEEN")) sync_action_list_add(seen_list, args[2], args[1]); else if (!strcmp(args[0], "SUB")) sync_action_list_add(sub_list, args[2], args[1]); else if (!strcmp(args[0], "UNSUB")) sync_action_list_add(sub_list, args[2], args[1]); else syslog(LOG_ERR, "Unknown action type: %s", args[0]); } /* Optimise out redundant clauses */ for (action = user_list->head; action; action = action->next) { /* remove per-user items */ remove_meta(action->user, meta_list); remove_meta(action->user, seen_list); remove_meta(action->user, sub_list); } /* duplicate removal for unuser - we also strip all the user events */ for (action = unuser_list->head; action; action = action->next) { /* remove per-user items */ remove_meta(action->user, meta_list); remove_meta(action->user, seen_list); remove_meta(action->user, sub_list); /* unuser trumps user */ remove_meta(action->user, user_list); } for (action = meta_list->head; action; action = action->next) { /* META action overrides any user SEEN or SUB/UNSUB action for same user */ remove_meta(action->user, seen_list); remove_meta(action->user, sub_list); } /* And then run tasks. */ /* we want to be able to defer items to the subsequent sync log */ sync_log_init(); for (action = quota_list->head; action; action = action->next) { if (!action->active) continue; r = sync_do_quota(action->name, sync_backend, flags); if (channelp && r == IMAP_MAILBOX_LOCKED) { sync_log_channel_quota(*channelp, action->name); report_verbose(" Deferred: QUOTA %s\n", action->name); } else if (r) { /* XXX - bogus handling, should be user */ sync_action_list_add(mailbox_list, action->name, NULL); report_verbose(" Promoting: QUOTA %s -> MAILBOX %s\n", action->name, action->name); } } for (action = annot_list->head; action; action = action->next) { if (!action->active) continue; /* NOTE: ANNOTATION "" is a special case - it's a server * annotation, hence the check for a character at the * start of the name */ r = sync_do_annotation(action->name, sync_backend, flags); if (!*action->name) continue; if (channelp && r == IMAP_MAILBOX_LOCKED) { sync_log_channel_annotation(*channelp, action->name); report_verbose(" Deferred: ANNOTATION %s\n", action->name); } else if (r) { /* XXX - bogus handling, should be ... er, something */ sync_action_list_add(mailbox_list, action->name, NULL); report_verbose(" Promoting: ANNOTATION %s -> MAILBOX %s\n", action->name, action->name); } } for (action = seen_list->head; action; action = action->next) { if (!action->active) continue; r = sync_do_seen(action->user, action->name, sync_backend, flags); if (channelp && r == IMAP_MAILBOX_LOCKED) { sync_log_channel_seen(*channelp, action->user, action->name); report_verbose(" Deferred: SEEN %s %s\n", action->user, action->name); } else if (r) { char *userid = mboxname_to_userid(action->name); if (userid && mboxname_isusermailbox(action->name, 1) && !strcmp(userid, action->user)) { sync_action_list_add(user_list, NULL, action->user); report_verbose(" Promoting: SEEN %s %s -> USER %s\n", action->user, action->name, action->user); } else { sync_action_list_add(meta_list, NULL, action->user); report_verbose(" Promoting: SEEN %s %s -> META %s\n", action->user, action->name, action->user); } free(userid); } } for (action = sub_list->head; action; action = action->next) { if (!action->active) continue; r = user_sub(action->user, action->name); if (channelp && r == IMAP_MAILBOX_LOCKED) { sync_log_channel_subscribe(*channelp, action->user, action->name); report_verbose(" Deferred: SUB %s %s\n", action->user, action->name); } else if (r) { sync_action_list_add(meta_list, NULL, action->user); report_verbose(" Promoting: SUB %s %s -> META %s\n", action->user, action->name, action->user); } } for (action = mailbox_list->head; action; action = action->next) { if (!action->active) continue; sync_name_list_add(mboxname_list, action->name); /* only do up to 1000 mailboxes at a time */ if (mboxname_list->count > 1000) { syslog(LOG_NOTICE, "sync_mailboxes: doing 1000"); r = do_sync_mailboxes(mboxname_list, user_list, channelp, flags); if (r) goto cleanup; r = do_restart(); if (r) goto cleanup; sync_name_list_free(&mboxname_list); mboxname_list = sync_name_list_create(); } } r = do_sync_mailboxes(mboxname_list, user_list, channelp, flags); if (r) goto cleanup; r = do_restart(); if (r) goto cleanup; for (action = unmailbox_list->head; action; action = action->next) { if (!action->active) continue; r = do_unmailbox(action->name, sync_backend, flags); if (channelp && r == IMAP_MAILBOX_LOCKED) { sync_log_channel_unmailbox(*channelp, action->name); report_verbose(" Deferred: UNMAILBOX %s\n", action->name); } else if (r) goto cleanup; } for (action = meta_list->head; action; action = action->next) { if (!action->active) continue; r = sync_do_meta(action->user, sync_backend, flags); if (channelp && r == IMAP_MAILBOX_LOCKED) { sync_log_channel_sieve(*channelp, action->user); report_verbose(" Deferred: META %s\n", action->user); } else if (r == IMAP_INVALID_USER) { goto cleanup; } else if (r) { sync_action_list_add(user_list, NULL, action->user); report_verbose(" Promoting: META %s -> USER %s\n", action->user, action->user); } } for (action = user_list->head; action; action = action->next) { if (!action->active) continue; r = sync_do_user(action->user, NULL, sync_backend, flags); if (channelp && r == IMAP_MAILBOX_LOCKED) { sync_log_channel_user(*channelp, action->user); report_verbose(" Deferred: USER %s\n", action->user); } else if (r) goto cleanup; r = do_restart(); if (r) goto cleanup; } for (action = unuser_list->head; action; action = action->next) { if (!action->active) continue; r = do_unuser(action->user); if (channelp && r == IMAP_MAILBOX_LOCKED) { sync_log_channel_unuser(*channelp, action->user); report_verbose(" Deferred: UNUSER %s\n", action->user); } else if (r) goto cleanup; } cleanup: if (r) { if (verbose) fprintf(stderr, "Error in do_sync(): bailing out! %s\n", error_message(r)); syslog(LOG_ERR, "Error in do_sync(): bailing out! %s", error_message(r)); } sync_log_done(); sync_action_list_free(&user_list); sync_action_list_free(&unuser_list); sync_action_list_free(&meta_list); sync_action_list_free(&mailbox_list); sync_action_list_free(&unmailbox_list); sync_action_list_free("a_list); sync_action_list_free(&annot_list); sync_action_list_free(&seen_list); sync_action_list_free(&sub_list); sync_name_list_free(&mboxname_list); return r; }
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 opt, i, r; int dousers = 0; int rflag = 0; int mflag = 0; int fflag = 0; int xflag = 0; char buf[MAX_MAILBOX_PATH+1]; strarray_t discovered = STRARRAY_INITIALIZER; char *alt_config = NULL; char *start_part = NULL; if ((geteuid()) == 0 && (become_cyrus(/*is_master*/0) != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } construct_hash_table(&unqid_table, 2047, 1); while ((opt = getopt(argc, argv, "C:kp:rmfsxgGqRUMoOnV:u")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'p': start_part = optarg; break; case 'r': rflag = 1; break; case 'u': dousers = 1; break; case 'm': mflag = 1; break; case 'n': reconstruct_flags &= ~RECONSTRUCT_MAKE_CHANGES; break; case 'g': fprintf(stderr, "reconstruct: deprecated option -g ignored\n"); break; case 'G': reconstruct_flags |= RECONSTRUCT_ALWAYS_PARSE; break; case 'f': fflag = 1; break; case 'x': xflag = 1; break; case 'k': fprintf(stderr, "reconstruct: deprecated option -k ignored\n"); break; case 's': reconstruct_flags &= ~RECONSTRUCT_DO_STAT; break; case 'q': reconstruct_flags |= RECONSTRUCT_QUIET; break; case 'R': reconstruct_flags |= RECONSTRUCT_GUID_REWRITE; break; case 'U': reconstruct_flags |= RECONSTRUCT_GUID_UNLINK; break; case 'o': reconstruct_flags |= RECONSTRUCT_IGNORE_ODDFILES; break; case 'O': reconstruct_flags |= RECONSTRUCT_REMOVE_ODDFILES; break; case 'M': reconstruct_flags |= RECONSTRUCT_PREFER_MBOXLIST; break; case 'V': if (!strcasecmp(optarg, "max")) setversion = MAILBOX_MINOR_VERSION; else setversion = atoi(optarg); break; default: usage(); } } cyrus_init(alt_config, "reconstruct", 0, CONFIG_NEED_PARTITION_DATA); global_sasl_init(1,0,NULL); /* Set namespace -- force standard (internal) */ if ((r = mboxname_init_namespace(&recon_namespace, 1)) != 0) { syslog(LOG_ERR, "%s", error_message(r)); fatal(error_message(r), EC_CONFIG); } sync_log_init(); if (mflag) { if (rflag || fflag || optind != argc) { cyrus_done(); usage(); } do_mboxlist(); } mboxlist_init(0); mboxlist_open(NULL); quotadb_init(0); quotadb_open(NULL); #ifdef WITH_DAV caldav_init(); carddav_init(); webdav_init(); #endif /* Deal with nonexistent mailboxes */ if (start_part) { /* We were handed a mailbox that does not exist currently */ if(optind == argc) { fprintf(stderr, "When using -p, you must specify a mailbox to attempt to reconstruct."); exit(EC_USAGE); } /* do any of the mailboxes exist in mboxlist already? */ /* Do they look like mailboxes? */ for (i = optind; i < argc; i++) { if (strchr(argv[i],'%') || strchr(argv[i],'*')) { fprintf(stderr, "Using wildcards with -p is not supported.\n"); exit(EC_USAGE); } /* Translate mailboxname */ char *intname = mboxname_from_external(argv[i], &recon_namespace, NULL); /* Does it exist */ do { r = mboxlist_lookup(intname, NULL, NULL); } while (r == IMAP_AGAIN); if (r != IMAP_MAILBOX_NONEXISTENT) { fprintf(stderr, "Mailbox %s already exists. Cannot specify -p.\n", argv[i]); exit(EC_USAGE); } free(intname); } /* None of them exist. Create them. */ for (i = optind; i < argc; i++) { /* Translate mailboxname */ char *intname = mboxname_from_external(argv[i], &recon_namespace, NULL); /* don't notify mailbox creation here */ r = mboxlist_createmailbox(intname, 0, start_part, 1, "cyrus", NULL, 0, 0, !xflag, 0, NULL); if (r) { fprintf(stderr, "could not create %s\n", argv[i]); } free(intname); } } /* Normal Operation */ if (optind == argc) { if (rflag || dousers) { fprintf(stderr, "please specify a mailbox to recurse from\n"); cyrus_done(); exit(EC_USAGE); } assert(!rflag); strlcpy(buf, "*", sizeof(buf)); mboxlist_findall(&recon_namespace, buf, 1, 0, 0, do_reconstruct, NULL); } for (i = optind; i < argc; i++) { if (dousers) { mboxlist_usermboxtree(argv[i], do_reconstruct_p, NULL, MBOXTREE_TOMBSTONES|MBOXTREE_DELETED); continue; } char *domain = NULL; /* save domain */ if (config_virtdomains) domain = strchr(argv[i], '@'); strlcpy(buf, argv[i], sizeof(buf)); /* reconstruct the first mailbox/pattern */ mboxlist_findall(&recon_namespace, buf, 1, 0, 0, do_reconstruct, fflag ? &discovered : NULL); if (rflag) { /* build a pattern for submailboxes */ char *p = strchr(buf, '@'); if (p) *p = '\0'; strlcat(buf, ".*", sizeof(buf)); /* append the domain */ if (domain) strlcat(buf, domain, sizeof(buf)); /* reconstruct the submailboxes */ mboxlist_findall(&recon_namespace, buf, 1, 0, 0, do_reconstruct, fflag ? &discovered : NULL); } } /* examine our list to see if we discovered anything */ while (discovered.count) { char *name = strarray_shift(&discovered); int r = 0; /* create p (database only) and reconstruct it */ /* partition is defined by the parent mailbox */ /* don't notify mailbox creation here */ r = mboxlist_createmailbox(name, 0, NULL, 1, "cyrus", NULL, 0, 0, !xflag, 0, NULL); if (r) { fprintf(stderr, "createmailbox %s: %s\n", name, error_message(r)); } else { mboxlist_findone(&recon_namespace, name, 1, 0, 0, do_reconstruct, &discovered); } /* may have added more things into our list */ free(name); } free_hash_table(&unqid_table, free); sync_log_done(); mboxlist_close(); mboxlist_done(); quotadb_close(); quotadb_done(); partlist_local_done(); #ifdef WITH_DAV webdav_done(); carddav_done(); caldav_done(); #endif cyrus_done(); strarray_fini(&discovered); return 0; }
int main(int argc, char *argv[]) { extern char *optarg; int opt, r = 0; char *alt_config = NULL; char buf[MAX_MAILBOX_PATH+1]; struct mailbox *mailbox = NULL; int mode = MODE_UNKNOWN; unsigned numrestored = 0; time_t time_since = time(NULL); int len, secs = 0; unsigned long *uids = NULL; unsigned nuids = 0; char *mboxname = NULL; if ((geteuid()) == 0 && (become_cyrus(/*is_master*/0) != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } while ((opt = getopt(argc, argv, "C:laudt:v")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'l': if (mode != MODE_UNKNOWN) usage(); mode = MODE_LIST; break; case 'a': if (mode != MODE_UNKNOWN) usage(); mode = MODE_ALL; break; case 't': if (mode != MODE_UNKNOWN) usage(); mode = MODE_TIME; secs = atoi(optarg); len = strlen(optarg); if ((secs > 0) && (len > 1)) { switch (optarg[len-1]) { case 'm': secs *= 60; break; case 'h': secs *= (60*60); break; case 'd': secs *= (24*60*60); break; case 'w': secs *= (7*24*60*60); break; } } time_since = time(NULL) - secs; break; case 'u': if (mode != MODE_UNKNOWN) usage(); mode = MODE_UID; break; case 'd': unsetdeleted = 1; break; case 'v': verbose = 1; break; default: usage(); break; } } /* sanity check */ if (mode == MODE_UNKNOWN || (optind + (mode == MODE_UID ? 1 : 0)) >= argc) usage(); cyrus_init(alt_config, "unexpunge", 0, 0); mboxlist_init(0); mboxlist_open(NULL); quotadb_init(0); quotadb_open(NULL); sync_log_init(); /* Set namespace -- force standard (internal) */ if ((r = mboxname_init_namespace(&unex_namespace, 1)) != 0) { syslog(LOG_ERR, "%s", error_message(r)); fatal(error_message(r), EC_CONFIG); } /* Translate mailboxname */ (*unex_namespace.mboxname_tointernal)(&unex_namespace, argv[optind], NULL, buf); if (mode == MODE_LIST) { list_expunged(buf); goto done; } /* Open/lock header */ r = mailbox_open_iwl(buf, &mailbox); if (r) { printf("Failed to open mailbox '%s'\n", buf); goto done; } if (mode == MODE_UID) { unsigned i; nuids = argc - ++optind; uids = (unsigned long *) xmalloc(nuids * sizeof(unsigned long)); for (i = 0; i < nuids; i++) uids[i] = strtoul(argv[optind+i], NULL, 10); /* Sort the UIDs so we can binary search */ qsort(uids, nuids, sizeof(unsigned long), compare_uid); } mboxname = xstrdup(mailbox->name); mboxname_hiersep_toexternal(&unex_namespace, mboxname, 0); printf("restoring %sexpunged messages in mailbox '%s'\n", mode == MODE_ALL ? "all " : "", mboxname); r = restore_expunged(mailbox, mode, uids, nuids, time_since, &numrestored, mboxname); if (!r) { printf("restored %u expunged messages\n", numrestored); syslog(LOG_NOTICE, "restored %u expunged messages in mailbox '%s'", numrestored, mboxname); } mailbox_close(&mailbox); done: sync_log_done(); quotadb_close(); quotadb_done(); mboxlist_close(); mboxlist_done(); cyrus_done(); exit(r); }
int main(int argc, char *argv[]) { char *alt_config = NULL; char cmd = '\0'; int opt; if ((geteuid()) == 0 && (become_cyrus(/*is_master*/0) != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } while ((opt = getopt(argc, argv, "C:uUvmMacqnsb")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'u': /* User */ cmd = 'u'; break; case 'U': /* UnUser */ cmd = 'U'; break; case 'v': /* sieVe */ cmd = 'v'; break; case 'm': /* Mailbox */ cmd = 'm'; break; case 'M': /* UnMailbox */ cmd = 'M'; break; case 'a': /* Append */ cmd = 'a'; break; case 'c': /* aCl */ cmd = 'c'; break; case 'q': /* Quota */ cmd = 'q'; break; case 'n': /* aNnotation */ cmd = 'n'; break; case 's': /* Seen */ cmd = 's'; break; case 'b': /* suBscription */ cmd = 'b'; break; } } /* need at least one value */ if ((argc - optind) < 1) usage(argv[0]); /* and not an empty string */ if (!argv[optind][0]) usage(argv[0]); if (cmd == 's' || cmd == 'b') { /* need a second value */ if ((argc - optind) < 2) usage(argv[0]); /* and not an empty string */ if (!argv[optind+1][0]) usage(argv[0]); } cyrus_init(alt_config, "cyr_synclog", 0, 0); sync_log_init(); switch(cmd) { case 'u': /* User */ sync_log_user(argv[optind]); break; case 'U': /* UnUser */ sync_log_unuser(argv[optind]); break; case 'v': /* sieVe */ sync_log_sieve(argv[optind]); break; case 'm': /* Mailbox */ sync_log_mailbox(argv[optind]); break; case 'M': /* UnMailbox */ sync_log_unmailbox(argv[optind]); break; case 'q': /* Quota */ sync_log_quota(argv[optind]); break; case 'n': /* aNnotation */ sync_log_annotation(argv[optind]); break; case 's': /* Seen */ sync_log_seen(argv[optind], argv[optind+1]); break; case 'b': /* suBscription */ sync_log_subscribe(argv[optind], argv[optind+1]); break; default: /* just as is! */ sync_log(argv[optind]); break; } sync_log_done(); 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; }