int main(int argc, char *argv[]) { int option; char buf[MAX_MAILBOX_PATH+1]; int i, r; char *alt_config = NULL; struct incremental_record irec; if ((geteuid()) == 0 && (become_cyrus(/*is_master*/0) != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } while ((option = getopt(argc, argv, "vC:")) != EOF) { switch (option) { case 'v': verbose++; break; case 'C': /* alt config file */ alt_config = optarg; break; default: usage(argv[0]); break; } } if (optind == argc) { usage(argv[0]); } cyrus_init(alt_config, "dump", 0, CONFIG_NEED_PARTITION_DATA); mboxlist_init(0); mboxlist_open(NULL); /* Set namespace -- force standard (internal) */ if ((r = mboxname_init_namespace(&dump_namespace, 1)) != 0) { syslog(LOG_ERR, "%s", error_message(r)); fatal(error_message(r), EC_CONFIG); } irec.incruid = 0; for (i = optind; i < argc; i++) { strlcpy(buf, argv[i], sizeof(buf)); /* Translate any separators in mailboxname */ mboxname_hiersep_tointernal(&dump_namespace, buf, config_virtdomains ? strcspn(buf, "@") : 0); (*dump_namespace.mboxlist_findall)(&dump_namespace, buf, 1, 0, 0, dump_me, &irec); } mboxlist_close(); mboxlist_done(); cyrus_done(); return 0; }
int main(int argc, char **argv) { int opt, i, r; int cmd = 0; char buf[MAX_MAILBOX_PATH+1]; char *alt_config = 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:t")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 't': cmd = CMD_TIME; break; default: usage(); } } cyrus_init(alt_config, "mbtool", 0, 0); /* 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); } mboxlist_init(0); mboxlist_open(NULL); signals_set_shutdown(&shut_down); signals_add_handlers(0); if (optind == argc) { usage(); } for (i = optind; i < argc; i++) { /* Handle virtdomains and separators in mailboxname */ (*recon_namespace.mboxname_tointernal)(&recon_namespace, argv[i], NULL, buf); mboxlist_findall(&recon_namespace, buf, 1, 0, 0, do_cmd, &cmd); } mboxlist_close(); mboxlist_done(); exit(0); }
/* * run once when process is forked; * MUST NOT exit directly; must return with non-zero error code */ int service_init(int argc, char **argv, char **envp) { if (geteuid() == 0) fatal("must run as the Cyrus user", EC_USAGE); setproctitle_init(argc, argv, envp); signals_set_shutdown(&shut_down); mboxlist_init(0); mboxlist_open(NULL); return 0; }
int main(int argc, char **argv) { int opt; char *alt_config = NULL; int r = IMAP_NOTFOUND; strarray_t mboxnames = STRARRAY_INITIALIZER; const char *query = NULL; int background = 1; const char *channel = "squatter"; const char *synclogfile = NULL; int init_flags = CYRUSINIT_PERROR; int multi_folder = 0; int user_mode = 0; int compact_flags = 0; const char *fromfile = NULL; strarray_t *srctiers = NULL; const char *desttier = NULL; enum { UNKNOWN, INDEXER, INDEXFROM, SEARCH, ROLLING, SYNCLOG, START_DAEMON, STOP_DAEMON, RUN_DAEMON, COMPACT } mode = UNKNOWN; if ((geteuid()) == 0 && (become_cyrus(/*is_master*/0) != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } setbuf(stdout, NULL); while ((opt = getopt(argc, argv, "C:I:N:RAXT:S:Fc:de:f:mn:rsiavz:t:ou")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'A': compact_flags |= SEARCH_COMPACT_AUDIT; break; case 'F': compact_flags |= SEARCH_COMPACT_FILTER; break; case 'X': compact_flags |= SEARCH_COMPACT_REINDEX; break; case 'N': name_starts_from = optarg; break; case 'I': /* indexer, using specified mbox/uids in file */ if (mode != UNKNOWN && mode != INDEXFROM) usage(argv[0]); fromfile = optarg; mode = INDEXFROM; break; case 'R': /* rolling indexer */ if (mode != UNKNOWN) usage(argv[0]); mode = ROLLING; incremental_mode = 1; /* always incremental if rolling */ break; case 'S': /* sleep time in seconds */ sleepmicroseconds = (atof(optarg) * 1000000); break; case 'T': /* temporary root directory for search */ temp_root_dir = optarg; break; /* This option is deliberately undocumented, for testing only */ case 'c': /* daemon control mode */ if (mode != UNKNOWN) usage(argv[0]); if (!strcmp(optarg, "start")) mode = START_DAEMON; else if (!strcmp(optarg, "stop")) mode = STOP_DAEMON; else if (!strcmp(optarg, "run")) mode = RUN_DAEMON; else usage(argv[0]); break; case 'd': /* foreground (with -R) */ background = 0; break; /* This option is deliberately undocumented, for testing only */ case 'e': /* add a search term */ if (mode != UNKNOWN && mode != SEARCH) usage(argv[0]); query = optarg; mode = SEARCH; break; case 'f': /* alternate synclogfile used in SYNCLOG mode */ synclogfile = optarg; mode = SYNCLOG; break; /* This option is deliberately undocumented, for testing only */ case 'm': /* multi-folder in SEARCH mode */ if (mode != UNKNOWN && mode != SEARCH) usage(argv[0]); multi_folder = 1; mode = SEARCH; break; case 'n': /* sync channel name (with -R) */ channel = optarg; break; case 'o': /* copy one DB rather than compressing */ compact_flags |= SEARCH_COMPACT_COPYONE; break; case 'v': /* verbose */ verbose++; break; case 'r': /* recurse */ if (mode != UNKNOWN && mode != INDEXER) usage(argv[0]); recursive_flag = 1; mode = INDEXER; break; case 'i': /* incremental mode */ incremental_mode = 1; break; case 'a': /* use /squat annotation */ if (mode != UNKNOWN && mode != INDEXER) usage(argv[0]); annotation_flag = 1; mode = INDEXER; break; case 'z': if (mode != UNKNOWN && mode != COMPACT) usage(argv[0]); desttier = optarg; mode = COMPACT; break; case 't': if (mode != UNKNOWN && mode != COMPACT) usage(argv[0]); srctiers = strarray_split(optarg, ",", 0); mode = COMPACT; break; case 'u': user_mode = 1; break; default: usage("squatter"); } } compact_flags |= SEARCH_VERBOSE(verbose); if (mode == UNKNOWN) mode = INDEXER; /* fork and close fds if required */ if (mode == ROLLING && background) { become_daemon(); init_flags &= ~CYRUSINIT_PERROR; } if (mode == COMPACT && (!desttier || !srctiers)) { /* need both src and dest for compact */ usage("squatter"); } cyrus_init(alt_config, "squatter", init_flags, CONFIG_NEED_PARTITION_DATA); /* Set namespace -- force standard (internal) */ if ((r = mboxname_init_namespace(&squat_namespace, 1)) != 0) { fatal(error_message(r), EC_CONFIG); } annotate_init(NULL, NULL); annotatemore_open(); mboxlist_init(0); mboxlist_open(NULL); if (mode == ROLLING || mode == SYNCLOG) { signals_set_shutdown(&shut_down); signals_add_handlers(0); } switch (mode) { case UNKNOWN: break; case INDEXER: /* -r requires at least one mailbox */ if (recursive_flag && optind == argc) usage(argv[0]); expand_mboxnames(&mboxnames, argc-optind, (const char **)argv+optind, user_mode); syslog(LOG_NOTICE, "indexing mailboxes"); r = do_indexer(&mboxnames); syslog(LOG_NOTICE, "done indexing mailboxes"); break; case INDEXFROM: syslog(LOG_NOTICE, "indexing messages"); r = do_indexfrom(fromfile); syslog(LOG_NOTICE, "done indexing messages"); break; case SEARCH: if (recursive_flag && optind == argc) usage(argv[0]); expand_mboxnames(&mboxnames, argc-optind, (const char **)argv+optind, user_mode); r = do_search(query, !multi_folder, &mboxnames); break; case ROLLING: do_rolling(channel); /* never returns */ break; case SYNCLOG: r = do_synclogfile(synclogfile); break; case START_DAEMON: if (optind != argc) usage("squatter"); search_start_daemon(verbose); break; case STOP_DAEMON: if (optind != argc) usage("squatter"); search_stop_daemon(verbose); break; case RUN_DAEMON: if (optind != argc) usage("squatter"); do_run_daemon(); break; case COMPACT: if (recursive_flag && optind == argc) usage(argv[0]); expand_mboxnames(&mboxnames, argc-optind, (const char **)argv+optind, user_mode); r = do_compact(&mboxnames, srctiers, desttier, compact_flags); break; } strarray_fini(&mboxnames); shut_down(r ? EC_TEMPFAIL : 0); }
int main(int argc,char **argv) { int opt; int i; int fflag = 0; int r, code = 0; int do_report = 1; char *alt_config = NULL, *domain = 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:d:fqZ")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'q': do_report = 0; break; case 'd': domain = optarg; break; case 'f': fflag = 1; break; /* deliberately undocumented option for testing */ case 'Z': test_sync_mode = 1; break; default: usage(); } } /* always report if not fixing, otherwise we do nothing */ if (!fflag) do_report = 1; cyrus_init(alt_config, "quota", 0, CONFIG_NEED_PARTITION_DATA); /* Set namespace -- force standard (internal) */ if ((r = mboxname_init_namespace("a_namespace, 1)) != 0) { syslog(LOG_ERR, "%s", error_message(r)); fatal(error_message(r), EC_CONFIG); } if (config_getswitch(IMAPOPT_IMPROVED_MBOXLIST_SORT)) compar = bsearch_compare_mbox; else compar = strcmp; /* * Lock mailbox list to prevent mailbox creation/deletion * during work */ mboxlist_init(0); mboxlist_open(NULL); quotadb_init(0); quotadb_open(NULL); quota_changelock(); if (!r) r = buildquotalist(domain, argv+optind, argc-optind); if (!r && fflag) r = fixquotas(domain, argv+optind, argc-optind); quota_changelockrelease(); if (r) code = convert_code(r); else if (do_report) reportquota(); quotadb_close(); quotadb_done(); mboxlist_close(); mboxlist_done(); /* just for neatness */ for (i = 0; i < quota_num; i++) free(quotaroots[i].name); free(quotaroots); cyrus_done(); return code; }
int main(int argc, char **argv) { int opt; pid_t pid; char *alt_config = NULL; time_t runattime = 0; int upgrade = 0; if ((geteuid()) == 0 && (become_cyrus(/*is_master*/0) != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } while ((opt = getopt(argc, argv, "C:dt:U")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'd': /* don't fork. debugging mode */ debugmode = 1; break; case 't': /* run a single scan at this time */ runattime = atoi(optarg); break; case 'U': upgrade = 1; break; default: fprintf(stderr, "invalid argument\n"); exit(EC_USAGE); break; } } cyrus_init(alt_config, "calalarmd", 0, 0); mboxlist_init(0); mboxlist_open(NULL); quotadb_init(0); quotadb_open(NULL); annotatemore_open(); caldav_init(); mboxevent_init(); if (upgrade) { caldav_alarm_upgrade(); shut_down(0); } if (runattime) { caldav_alarm_process(runattime); shut_down(0); } signals_set_shutdown(shut_down); signals_add_handlers(0); /* fork unless we were given the -d option or we're running as a daemon */ if (debugmode == 0 && !getenv("CYRUS_ISDAEMON")) { pid = fork(); if (pid == -1) { perror("fork"); exit(1); } if (pid != 0) { /* parent */ exit(0); } } /* child */ for (;;) { struct timeval start, end; double totaltime; int tosleep; signals_poll(); gettimeofday(&start, 0); caldav_alarm_process(0); gettimeofday(&end, 0); signals_poll(); totaltime = timesub(&start, &end); tosleep = 10 - (int) (totaltime + 0.5); /* round to nearest int */ if (tosleep > 0) sleep(tosleep); } /* NOTREACHED */ shut_down(1); }
int main(int argc, char **argv) { char *path, *mpath; int rc, i, quiet = 0, stop_on_error=0, metadata=0; int opt; /* getopt() returns an int */ char *alt_config = NULL; char buf[MAX_MAILBOX_PATH+1]; if (geteuid() == 0) fatal("must run as the Cyrus user", EC_USAGE); while ((opt = getopt(argc, argv, "C:qsm")) != EOF) { switch(opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'q': quiet = 1; break; case 's': stop_on_error = 1; break; case 'm': metadata = 1; break; default: usage(); } } cyrus_init(alt_config, "mbpath", 0); if ((rc = mboxname_init_namespace(&mbpath_namespace, 1)) != 0) { fatal(error_message(rc), -1); } mboxlist_init(0); mboxlist_open(NULL); for (i = optind; i < argc; i++) { (void)memset(&path, 0, sizeof(path)); /* Translate mailboxname */ (*mbpath_namespace.mboxname_tointernal)(&mbpath_namespace, argv[i], NULL, buf); if ((rc = mboxlist_detail(buf, NULL, &path, &mpath, NULL, NULL, NULL)) == 0) { if (metadata && mpath) printf("%s\n", mpath); else printf("%s\n", path); } else { if (!quiet && (rc == IMAP_MAILBOX_NONEXISTENT)) { fprintf(stderr, "Invalid mailbox name: %s\n", argv[i]); } if (stop_on_error) { if (quiet) { fatal("", -1); } else { fatal("Error in processing mailbox. Stopping\n", -1); } } } } mboxlist_close(); mboxlist_done(); cyrus_done(); return 0; }
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; char buf[MAX_MAILBOX_PATH+1]; char *alt_config = NULL; int quotachk = 0; if ((geteuid()) == 0 && (become_cyrus() != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } /* Ensure we're up-to-date on the index file format */ assert(INDEX_HEADER_SIZE == (OFFSET_HEADER_CRC+4)); assert(INDEX_RECORD_SIZE == (OFFSET_RECORD_CRC+4)); while ((opt = getopt(argc, argv, "C:u:s:q")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'u': if(wantvalue) usage(); wantuid = 1; wantvalue = atoi(optarg); break; case 's': if(wantvalue) usage(); wantvalue = atoi(optarg); break; case 'q': quotachk = 1; break; default: usage(); } } cyrus_init(alt_config, "mbexamine", 0); /* 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); } mboxlist_init(0); mboxlist_open(NULL); signals_set_shutdown(&shut_down); signals_add_handlers(0); if (optind == argc) { strlcpy(buf, "*", sizeof(buf)); (*recon_namespace.mboxlist_findall)(&recon_namespace, buf, 1, 0, 0, quotachk ? do_quota : do_examine, NULL); } for (i = optind; i < argc; i++) { /* Handle virtdomains and separators in mailboxname */ (*recon_namespace.mboxname_tointernal)(&recon_namespace, argv[i], NULL, buf); (*recon_namespace.mboxlist_findall)(&recon_namespace, buf, 1, 0, 0, quotachk ? do_quota : do_examine, NULL); } mboxlist_close(); mboxlist_done(); exit(code); }
int main(int argc, char **argv) { int opt, i, r; char buf[MAX_MAILBOX_PATH+1]; char *alt_config = NULL; int quotachk = 0; if ((geteuid()) == 0 && (become_cyrus(/*is_master*/0) != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } while ((opt = getopt(argc, argv, "C:u:s:q")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'u': if(wantvalue) usage(); wantuid = 1; wantvalue = atoi(optarg); break; case 's': if(wantvalue) usage(); wantvalue = atoi(optarg); break; case 'q': quotachk = 1; break; default: usage(); } } cyrus_init(alt_config, "mbexamine", 0, 0); /* 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); } mboxlist_init(0); mboxlist_open(NULL); signals_set_shutdown(&shut_down); signals_add_handlers(0); if (optind == argc) { strlcpy(buf, "*", sizeof(buf)); mboxlist_findall(&recon_namespace, buf, 1, 0, 0, quotachk ? do_quota : do_examine, NULL); } for (i = optind; i < argc; i++) { /* Handle virtdomains and separators in mailboxname */ char *intname = mboxname_from_external(argv[i], &recon_namespace, NULL); mboxlist_findall(&recon_namespace, intname, 1, 0, 0, quotachk ? do_quota : do_examine, NULL); free(intname); } mboxlist_close(); mboxlist_done(); exit(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) { int opt, i, r; char buf[MAX_MAILBOX_PATH+1]; char *alt_config = NULL; int (*cb)(struct findall_data *, void *) = &do_examine; if ((geteuid()) == 0 && (become_cyrus(/*is_master*/0) != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } while ((opt = getopt(argc, argv, "C:u:s:qc")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'u': if(wantvalue) usage(); wantuid = 1; wantvalue = atoi(optarg); break; case 's': if(wantvalue) usage(); wantvalue = atoi(optarg); break; case 'q': cb = &do_quota; break; case 'c': cb = &do_compare; break; default: usage(); } } cyrus_init(alt_config, "mbexamine", 0, 0); /* Set namespace -- force standard (internal) */ if ((r = mboxname_init_namespace(&mbexamine_namespace, 1)) != 0) { syslog(LOG_ERR, "%s", error_message(r)); fatal(error_message(r), EC_CONFIG); } mboxlist_init(0); mboxlist_open(NULL); signals_set_shutdown(&shut_down); signals_add_handlers(0); if (optind == argc) { strlcpy(buf, "*", sizeof(buf)); mboxlist_findall(&mbexamine_namespace, buf, 1, 0, 0, cb, NULL); } for (i = optind; i < argc; i++) { mboxlist_findall(&mbexamine_namespace, argv[i], 1, 0, 0, cb, NULL); } mboxlist_close(); mboxlist_done(); exit(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; }
int main(int argc, char **argv) { struct mboxlist_entry *mbentry = NULL; int rc, i, quiet = 0, stop_on_error=0, metadata=0; int opt; /* getopt() returns an int */ char *alt_config = NULL; char buf[MAX_MAILBOX_PATH+1]; if ((geteuid()) == 0 && (become_cyrus() != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } while ((opt = getopt(argc, argv, "C:qsm")) != EOF) { switch(opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'q': quiet = 1; break; case 's': stop_on_error = 1; break; case 'm': metadata = 1; break; default: usage(); } } cyrus_init(alt_config, "mbpath", 0); if ((rc = mboxname_init_namespace(&mbpath_namespace, 1)) != 0) { fatal(error_message(rc), -1); } mboxlist_init(0); mboxlist_open(NULL); for (i = optind; i < argc; i++) { /* Translate mailboxname */ (*mbpath_namespace.mboxname_tointernal)(&mbpath_namespace, argv[i], NULL, buf); if ((rc = mboxlist_lookup(buf, &mbentry, NULL)) == 0) { if (mbentry->mbtype & MBTYPE_REMOTE) { printf("%s!%s\n", mbentry->server, mbentry->partition); } else if (metadata) { const char *path = mboxname_metapath(mbentry->partition, mbentry->name, 0, 0); printf("%s\n", path); } else { const char *path = mboxname_datapath(mbentry->partition, mbentry->name, 0); printf("%s\n", path); } mboxlist_entry_free(&mbentry); } else { if (!quiet && (rc == IMAP_MAILBOX_NONEXISTENT)) { fprintf(stderr, "Invalid mailbox name: %s\n", argv[i]); } if (stop_on_error) { if (quiet) { fatal("", -1); } else { fatal("Error in processing mailbox. Stopping\n", -1); } } } } mboxlist_close(); mboxlist_done(); cyrus_done(); return 0; }