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); }
int main(int argc, char **argv) { int opt, r; char *alt_config = NULL; int allusers = 0; const char *audit_tool = NULL; while ((opt = getopt(argc, argv, "C:A:a")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'a': allusers = 1; break; case 'A': audit_tool = optarg; break; default: usage(); } } cyrus_init(alt_config, "dav_reconstruct", 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), EX_CONFIG); } signals_set_shutdown(&shut_down); signals_add_handlers(0); sqldb_init(); /* Initialize libical */ ical_support_init(); if (allusers) { mboxlist_alluser(do_user, (void *)audit_tool); } else if (optind == argc) { usage(); } else { int i; for (i = optind; i < argc; i++) do_user(argv[i], (void *)audit_tool); } exit(code); }
/* * Run a search daemon in such a way that the natural shutdown * mechanism for Cyrus (sending a SIGTERM to the master process) * will cleanly shut down the search daemon too. For Sphinx * this currently means running a loop in a forked process whose * job it is to live in the master process' process group and thus * receive the SIGTERM that master re-sends. */ static void do_run_daemon(void) { int r; /* We start the daemon before forking. This eliminates a * race condition during slot startup by ensuring that * Sphinx is fully running before the rolling squatter * tries to use it. */ r = search_start_daemon(verbose); if (r) exit(EC_TEMPFAIL); /* tell shut_down() to shut down the searchd too */ running_daemon = 1; become_daemon(); signals_set_shutdown(&shut_down); signals_add_handlers(0); for (;;) { signals_poll(); /* will call shut_down() after SIGTERM */ poll(NULL, 0, -1); /* sleeps until signalled */ } }
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; 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) { int opt, r = 0; char *alt_config = NULL, *pub = NULL, *ver = NULL, *winfile = NULL; char prefix[2048]; enum { REBUILD, WINZONES, NONE } op = NONE; if ((geteuid()) == 0 && (become_cyrus(/*ismaster*/0) != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } while ((opt = getopt(argc, argv, "C:r:vw:")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'r': if (op == NONE) { op = REBUILD; pub = optarg; ver = strchr(optarg, ':'); if (ver) *ver++ = '\0'; else usage(); } else usage(); break; case 'v': verbose = 1; break; case 'w': if (op == NONE) { op = WINZONES; winfile = optarg; } else usage(); break; default: usage(); } } cyrus_init(alt_config, "ctl_zoneinfo", 0, 0); signals_set_shutdown(&shut_down); signals_add_handlers(0); snprintf(prefix, sizeof(prefix), "%s%s", config_dir, FNAME_ZONEINFODIR); switch (op) { case REBUILD: { struct hash_table tzentries; struct zoneinfo *info; struct txn *tid = NULL; char buf[1024]; FILE *fp; construct_hash_table(&tzentries, 500, 1); /* Add INFO record (overall lastmod and TZ DB source version) */ info = xzmalloc(sizeof(struct zoneinfo)); info->type = ZI_INFO; appendstrlist(&info->data, pub); appendstrlist(&info->data, ver); hash_insert(INFO_TZID, info, &tzentries); /* Add LEAP record (last updated and hash) */ snprintf(buf, sizeof(buf), "%s%s", prefix, FNAME_LEAPSECFILE); if (verbose) printf("Processing leap seconds file %s\n", buf); if (!(fp = fopen(buf, "r"))) { fprintf(stderr, "Could not open leap seconds file %s\n", buf); } else { struct zoneinfo *leap = xzmalloc(sizeof(struct zoneinfo)); leap->type = ZI_INFO; while(fgets(buf, sizeof(buf), fp)) { if (buf[0] == '#') { /* comment line */ if (buf[1] == '$') { /* last updated */ unsigned long last; sscanf(buf+2, "\t%lu", &last); leap->dtstamp = last - NIST_EPOCH_OFFSET; } else if (buf[1] == 'h') { /* hash */ char *p, *hash = buf+3 /* skip "#h\t" */; /* trim trailing whitespace */ for (p = hash + strlen(hash); isspace(*--p); *p = '\0'); appendstrlist(&leap->data, hash); } } } fclose(fp); hash_insert(LEAP_TZID, leap, &tzentries); info->dtstamp = leap->dtstamp; } /* Add ZONE/LINK records */ do_zonedir(prefix, &tzentries, info); zoneinfo_open(NULL); /* Store records */ hash_enumerate(&tzentries, &store_zoneinfo, &tid); zoneinfo_close(tid); free_hash_table(&tzentries, &free_zoneinfo); break; } case WINZONES: { xmlParserCtxtPtr ctxt; xmlDocPtr doc; xmlNodePtr node; struct buf tzidbuf = BUF_INITIALIZER; struct buf aliasbuf = BUF_INITIALIZER; if (verbose) printf("Processing Windows Zone file %s\n", winfile); /* Parse the XML file */ ctxt = xmlNewParserCtxt(); if (!ctxt) { fprintf(stderr, "Failed to create XML parser context\n"); break; } doc = xmlCtxtReadFile(ctxt, winfile, NULL, 0); xmlFreeParserCtxt(ctxt); if (!doc) { fprintf(stderr, "Failed to parse XML document\n"); break; } node = xmlDocGetRootElement(doc); if (!node || xmlStrcmp(node->name, BAD_CAST "supplementalData")) { fprintf(stderr, "Incorrect root node\n"); goto done; } for (node = xmlFirstElementChild(node); node && xmlStrcmp(node->name, BAD_CAST "windowsZones"); node = xmlNextElementSibling(node)); if (!node) { fprintf(stderr, "Missing windowsZones node\n"); goto done; } node = xmlFirstElementChild(node); if (!node || xmlStrcmp(node->name, BAD_CAST "mapTimezones")) { fprintf(stderr, "Missing mapTimezones node\n"); goto done; } if (chdir(prefix)) { fprintf(stderr, "chdir(%s) failed\n", prefix); goto done; } for (node = xmlFirstElementChild(node); node; node = xmlNextElementSibling(node)) { if (!xmlStrcmp(node->name, BAD_CAST "mapZone") && !xmlStrcmp(xmlGetProp(node, BAD_CAST "territory"), BAD_CAST "001")) { const char *tzid, *alias; buf_setcstr(&tzidbuf, (const char *) xmlGetProp(node, BAD_CAST "type")); buf_appendcstr(&tzidbuf, ".ics"); tzid = buf_cstring(&tzidbuf); buf_setcstr(&aliasbuf, (const char *) xmlGetProp(node, BAD_CAST "other")); buf_appendcstr(&aliasbuf, ".ics"); alias = buf_cstring(&aliasbuf); if (verbose) printf("\tLINK: %s -> %s\n", alias, tzid); if (symlink(tzid, alias)) { if (errno == EEXIST) { struct stat sbuf; if (stat(alias, &sbuf)) { fprintf(stderr, "stat(%s) failed: %s\n", alias, strerror(errno)); errno = EEXIST; } else if (sbuf.st_mode & S_IFLNK) { char link[MAX_MAILBOX_PATH+1]; int n = readlink(alias, link, MAX_MAILBOX_PATH); if (n == -1) { fprintf(stderr, "readlink(%s) failed: %s\n", alias, strerror(errno)); errno = EEXIST; } else if (n == (int) strlen(tzid) && !strncmp(tzid, link, n)) { errno = 0; } } } if (errno) { fprintf(stderr, "symlink(%s, %s) failed: %s\n", tzid, alias, strerror(errno)); } } } } done: buf_free(&aliasbuf); buf_free(&tzidbuf); xmlFreeDoc(doc); break; } case NONE: r = 2; usage(); break; } cyrus_done(); return r; }
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; 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); }