/* * All command line parameters have the syntax "-f string" or "-fstring" * OPTIONS: * -d filename - specify d:line file * -f filename - specify config file * -h hostname - specify server name * -k filename - specify k:line file * -l filename - specify log file * -n - do not fork, run in foreground * -v - print daemon version and exit * -x - set debug level, if compiled for debug logging */ static void parse_command_line(int argc, char* argv[]) { const char* options = "d:f:h:k:l:nvx:"; int opt; while ((opt = getopt(argc, argv, options)) != EOF) { switch (opt) { case 'd': if (optarg) ConfigFileEntry.dpath = optarg; break; case 'f': #ifdef CMDLINE_CONFIG if (optarg) ConfigFileEntry.configfile = optarg; #endif break; case 'k': #ifdef KPATH if (optarg) ConfigFileEntry.klinefile = optarg; #endif break; case 'h': if (optarg) strncpy_irc(me.name, optarg, HOSTLEN); break; case 'l': if (optarg) logFileName = optarg; break; case 'n': bootDaemon = 0; break; case 'v': printf("ircd %s\n\tzlib %s\n\tircd_dir: %s\n", ircd_version, #ifndef ZIP_LINKS "not used", #else zlibVersion(), #endif ConfigFileEntry.dpath); exit(0); break; /* NOT REACHED */ case 'x': #ifdef DEBUGMODE if (optarg) { debuglevel = atoi(optarg); debugmode = optarg; } #endif break; default: bad_command(); break; } } }
int main(int argc, char *argv[]) { uid_t uid, euid; sbrk0 = (char *)sbrk((size_t)0); uid = getuid(); euid = geteuid(); #ifdef CHROOTDIR ircd_res_init(); if (chdir(ROOT_PATH)!=0) { perror("chdir"); (void)fprintf(stderr,"%s: Cannot chdir: %s.\n", IRCD_PATH, ROOT_PATH); exit(5); } if (chroot(ROOT_PATH)!=0) { perror("chroot"); (void)fprintf(stderr,"%s: Cannot chroot: %s.\n", IRCD_PATH, ROOT_PATH); exit(5); } #endif /*CHROOTDIR*/ #ifdef ZIP_LINKS if (zlib_version[0] == '0') { fprintf(stderr, "zlib version 1.0 or higher required\n"); exit(1); } if (zlib_version[0] != ZLIB_VERSION[0]) { fprintf(stderr, "incompatible zlib version\n"); exit(1); } if (strcmp(zlib_version, ZLIB_VERSION) != 0) { fprintf(stderr, "warning: different zlib version\n"); } #endif myargv = argv; (void)umask(077); /* better safe than sorry --SRB */ bzero((char *)&me, sizeof(me)); make_server(&me); register_server(&me); version = make_version(); /* Generate readable version string */ /* ** All command line parameters have the syntax "-fstring" ** or "-f string" (e.g. the space is optional). String may ** be empty. Flag characters cannot be concatenated (like ** "-fxyz"), it would conflict with the form "-fstring". */ while (--argc > 0 && (*++argv)[0] == '-') { char *p = argv[0]+1; int flag = *p++; if (flag == '\0' || *p == '\0') { if (argc > 1 && argv[1][0] != '-') { p = *++argv; argc -= 1; } else { p = ""; } } switch (flag) { case 'a': bootopt |= BOOT_AUTODIE; break; case 'b': bootopt |= BOOT_BADTUNE; break; case 'c': bootopt |= BOOT_CONSOLE; break; case 'q': bootopt |= BOOT_QUICK; break; #ifdef CMDLINE_CONFIG case 'f': (void)setuid((uid_t)uid); configfile = p; break; #endif case 'h': if (*p == '\0') bad_command(); strncpyzt(me.serv->namebuf, p, sizeof(me.serv->namebuf)); break; case 'i': bootopt |= BOOT_INETD|BOOT_AUTODIE; break; case 'p': if (!strcmp(p, "strict")) bootopt |= BOOT_PROT|BOOT_STRICTPROT; else if (!strcmp(p, "on")) bootopt |= BOOT_PROT; else if (!strcmp(p, "off")) bootopt &= ~(BOOT_PROT|BOOT_STRICTPROT); else if (!strcmp(p, "standalone")) bootopt |= BOOT_STANDALONE; else bad_command(); break; case 's': bootopt |= BOOT_NOIAUTH; break; case 't': #ifdef DEBUGMODE (void)setuid((uid_t)uid); #endif bootopt |= BOOT_TTY; break; case 'T': tunefile = p; break; case 'v': (void)printf("ircd %s %s\n\tzlib %s\n\tircd.conf delimiter %c\n\t%s #%s\n", version, serveropts, #ifndef ZIP_LINKS "not used", #else zlib_version, #endif IRCDCONF_DELIMITER, creation, generation); exit(0); case 'x': #ifdef DEBUGMODE (void)setuid((uid_t)uid); debuglevel = atoi(p); debugmode = *p ? p : "0"; bootopt |= BOOT_DEBUG; break; #else (void)fprintf(stderr, "%s: DEBUGMODE must be defined for -x y\n", myargv[0]); exit(0); #endif default: bad_command(); } } if (strlen(tunefile) > 1023 || strlen(mybasename(tunefile)) > 42) { fprintf(stderr, "Too long tune filename\n"); exit(-1); } if (argc > 0) bad_command(); /* This exits out */ #ifndef IRC_UID if ((uid != euid) && !euid) { (void)fprintf(stderr, "ERROR: do not run ircd setuid root. Make it setuid a\ normal user.\n"); exit(-1); }
static int command(struct atrf_dsc *dsc, const char *arg, int doit) { const char *p; char *end; unsigned long reg, value, mask = 0xff; uint8_t got; if (!strcmp(arg, "delay")) { if (doit) usleep(DEFAULT_DELAY_MS*1000); return 1; } if (!strncmp(arg, "delay=", 6)) { value = strtoul(arg+6, &end, 0); if (!value || *end) bad_command(arg); if (doit) usleep(value*1000); return 1; } if (!strcmp(arg, "frame")) { if (doit) atrf_buf_write(dsc, "", 1); return 1; } if (!strcmp(arg, "reset")) { if (doit) atrf_reset_rf(dsc); return 1; } if (!strcmp(arg, "slp_tr")) { if (doit) atrf_slp_tr(dsc, 1, 1); return 1; } p = strchr(arg, '='); if (!p) p = strchr(arg, ':'); if (!p) p = strchr(arg, '!'); if (!p) p = strchr(arg, '/'); if (!p) return 0; reg = strtoul(arg, &end, 0); if (end != p || reg > 0xff) bad_command(arg); value = strtoul(p+1, &end, 0); if (value > 0xff) bad_command(arg); if (*end) { if (*p != ':') bad_command(arg); if (*end != '/') bad_command(arg); mask = strtoul(end+1, &end, 0); if (*end || mask > 0xff) bad_command(arg); } if (!doit) return 1; switch (*p) { case '=': atrf_reg_write(dsc, reg, value); break; case ':': got = atrf_reg_read(dsc, reg); if (end != p+1 && ((got ^ value) & mask)) { fprintf(stderr, "register 0x%02lx: got 0x%02x expected " "0x%02lx/0x%02lx\n", reg, got, value, mask); exit(1); } break; case '!': atrf_sram_write(dsc, reg, value); break; case '/': got = atrf_sram_read(dsc, reg); if (got != value) { fprintf(stderr, "got 0x%02x expected 0x%02lx\n", got, value); exit(1); } break; default: abort(); } return 1; }
int main(int argc, char *argv[]) { uid_t uid, euid; int portarg = 0, fd; #ifdef SAVE_MAXCLIENT_STATS FILE *mcsfp; #endif memset(&me, 0, sizeof(aClient)); if ((timeofday = time(NULL)) == -1) { (void) fprintf(stderr, "ERROR: Clock Failure (%d)\n", errno); exit(errno); } build_version(); Count.server = 1; /* us */ Count.oper = 0; Count.chan = 0; Count.local = 0; Count.total = 0; Count.invisi = 0; Count.unknown = 0; Count.max_loc = 0; Count.max_tot = 0; Count.today = 0; Count.weekly = 0; Count.monthly = 0; Count.yearly = 0; Count.start = NOW; Count.day = NOW; Count.week = NOW; Count.month = NOW; Count.year = NOW; #ifdef SAVE_MAXCLIENT_STATS mcsfp=fopen(DPATH "/.maxclients", "r"); if(mcsfp!=NULL) { fscanf(mcsfp, "%d %d %li %li %li %ld %ld %ld %ld", &Count.max_loc, &Count.max_tot, &Count.weekly, &Count.monthly, &Count.yearly, &Count.start, &Count.week, &Count.month, &Count.year); fclose(mcsfp); } #endif /* * this code by [email protected] * it is intended to keep the ircd from being swapped out. BSD * swapping criteria do not match the requirements of ircd */ #ifdef INITIAL_DBUFS dbuf_init(); /* set up some dbuf stuff to control paging */ #endif sbrk0 = (char *) sbrk((size_t) 0); uid = getuid(); euid = geteuid(); #ifdef PROFIL (void) monstartup(0, etext); (void) moncontrol(1); (void) signal(SIGUSR1, s_monitor); #endif myargv = argv; (void) umask(077); /* better safe than sorry --SRB */ memset((char *) &me, '\0', sizeof(me)); setup_signals(); /* * * All command line parameters have the syntax "-fstring" or "-f * string" (e.g. the space is optional). String may be empty. Flag * characters cannot be concatenated (like "-fxyz"), it would * conflict with the form "-fstring". */ while (--argc > 0 && (*++argv)[0] == '-') { char *p = argv[0] + 1; int flag = *p++; if (flag == '\0' || *p == '\0') { if (argc > 1 && argv[1][0] != '-') { p = *++argv; argc -= 1; } else p = ""; } switch (flag) { case 'a': bootopt |= BOOT_AUTODIE; break; case 'c': bootopt |= BOOT_CONSOLE; break; case 'q': bootopt |= BOOT_QUICK; break; case 'd': (void) setuid((uid_t) uid); dpath = p; break; case 'o': /* Per user local daemon... */ (void) setuid((uid_t) uid); bootopt |= BOOT_OPER; break; #ifdef CMDLINE_CONFIG case 'f': (void) setuid((uid_t) uid); configfile = p; break; # ifdef KPATH case 'k': (void) setuid((uid_t) uid); klinefile = p; break; # endif #endif case 'h': strncpyzt(me.name, p, sizeof(me.name)); break; case 'i': bootopt |= BOOT_INETD | BOOT_AUTODIE; break; case 'p': if ((portarg = atoi(p)) > 0) portnum = portarg; break; case 's': bootopt |= BOOT_STDERR; break; case 't': (void) setuid((uid_t) uid); bootopt |= BOOT_TTY; break; case 'v': (void) printf("ircd %s\n", version); exit(0); case 'x': #ifdef DEBUGMODE (void) setuid((uid_t) uid); debuglevel = atoi(p); debugmode = *p ? p : "0"; bootopt |= BOOT_DEBUG; break; #else (void) fprintf(stderr, "%s: DEBUGMODE must be defined for -x y\n", myargv[0]); exit(0); #endif default: bad_command(); break; } } if (chdir(dpath)) { perror("chdir"); exit(-1); } if ((uid != euid) && !euid) { (void) fprintf(stderr, "ERROR: do not run ircd setuid root. Make it setuid a normal user.\n"); exit(-1); } if (argc > 0) return bad_command(); /* This should exit out */ initialize_ssl(); motd = (aMotd *) NULL; helpfile = (aMotd *) NULL; motd_tm = NULL; #ifdef SHORT_MOTD shortmotd = NULL; #endif read_motd(MOTD); read_help(HELPFILE); #ifdef SHORT_MOTD read_shortmotd(SHORTMOTD); #endif clear_client_hash_table(); clear_channel_hash_table(); clear_scache_hash_table(); /* server cache name table */ clear_ip_hash_table(); /* client host ip hash table */ initlists(); initclass(); initwhowas(); initstats(); init_tree_parse(msgtab); init_send(); NOW = time(NULL); open_debugfile(); NOW = time(NULL); init_fdlist(&serv_fdlist); init_fdlist(&oper_fdlist); init_fdlist(&listen_fdlist); #ifndef NO_PRIORITY init_fdlist(&busycli_fdlist); #endif init_fdlist(&default_fdlist); { int i; for (i = MAXCONNECTIONS + 1; i > 0; i--) { default_fdlist.entry[i] = i - 1; } } if ((timeofday = time(NULL)) == -1) { #ifdef USE_SYSLOG syslog(LOG_WARNING, "Clock Failure (%d), TS can be corrupted", errno); #endif sendto_ops("Clock Failure (%d), TS can be corrupted", errno); } #ifdef WINGATE_NOTICE strcpy(ProxyMonURL, "http://"); strncpyzt((ProxyMonURL + 7), DEFAULT_PROXY_INFO_URL, (TOPICLEN + 1) - 7); strncpyzt(ProxyMonHost, MONITOR_HOST, (HOSTLEN + 1)); #endif if (portnum < 0) portnum = PORTNUM; me.port = portnum; (void) init_sys(); me.flags = FLAGS_LISTEN; #ifndef _WIN32 if (bootopt & BOOT_INETD) { me.fd = 0; local[0] = &me; me.flags = FLAGS_LISTEN; } else #endif me.fd = -1; #ifdef USE_SYSLOG # define SYSLOG_ME "ircd" openlog(SYSLOG_ME, LOG_PID | LOG_NDELAY, LOG_FACILITY); #endif if ((fd = openconf(configfile)) == -1) { Debug((DEBUG_FATAL, "Failed in reading configuration file %s", configfile)); (void) printf("Couldn't open configuration file %s\n", configfile); exit(-1); } (void) initconf(bootopt, fd); /* comstuds SEPARATE_QUOTE_KLINES_BY_DATE code */ #ifdef SEPARATE_QUOTE_KLINES_BY_DATE { struct tm *tmptr; char timebuffer[20], filename[200]; tmptr = localtime(&NOW); (void) strftime(timebuffer, 20, "%y%m%d", tmptr); ircsprintf(filename, "%s.%s", klinefile, timebuffer); if ((fd = openconf(filename)) == -1) { Debug((DEBUG_ERROR, "Failed reading kline file %s", filename)); (void) printf("Couldn't open kline file %s\n", filename); } else (void) initconf(0, fd); } #else # ifdef KPATH if ((fd = openconf(klinefile)) == -1) { Debug((DEBUG_ERROR, "Failed reading kline file %s", klinefile)); (void) printf("Couldn't open kline file %s\n", klinefile); } else (void) initconf(0, fd); # endif #endif if (!(bootopt & BOOT_INETD)) { static char star[] = "*"; aConfItem *aconf; u_long vaddr; if ((aconf = find_me()) && portarg <= 0 && aconf->port > 0) portnum = aconf->port; Debug((DEBUG_ERROR, "Port = %d", portnum)); if ((aconf->passwd[0] != '\0') && (aconf->passwd[0] != '*')) vaddr = inet_addr(aconf->passwd); else vaddr = (u_long) NULL; if (inetport(&me, star, portnum, vaddr)) { if (bootopt & BOOT_STDERR) fprintf(stderr, "Couldn't bind to primary port %d\n", portnum); #ifdef USE_SYSLOG (void) syslog(LOG_CRIT, "Couldn't bind to primary port %d\n", portnum); #endif exit(1); } } else if (inetport(&me, "*", 0, 0)) { if (bootopt & BOOT_STDERR) fprintf(stderr, "Couldn't bind to port passed from inetd\n"); #ifdef USE_SYSLOG (void) syslog(LOG_CRIT, "Couldn't bind to port passed from inetd\n"); #endif exit(1); } (void) get_my_name(&me, me.sockhost, sizeof(me.sockhost) - 1); if (me.name[0] == '\0') strncpyzt(me.name, me.sockhost, sizeof(me.name)); me.hopcount = 0; me.authfd = -1; me.confs = NULL; me.next = NULL; me.user = NULL; me.from = &me; SetMe(&me); make_server(&me); me.serv->up = me.name; me.lasttime = me.since = me.firsttime = NOW; (void) add_to_client_hash_table(me.name, &me); /* We don't want to calculate these every time they are used :) */ sprintf(REPORT_DO_DNS, REPORT_DO_DNS_, me.name); sprintf(REPORT_FIN_DNS, REPORT_FIN_DNS_, me.name); sprintf(REPORT_FIN_DNSC, REPORT_FIN_DNSC_, me.name); sprintf(REPORT_FAIL_DNS, REPORT_FAIL_DNS_, me.name); sprintf(REPORT_DO_ID, REPORT_DO_ID_, me.name); sprintf(REPORT_FIN_ID, REPORT_FIN_ID_, me.name); sprintf(REPORT_FAIL_ID, REPORT_FAIL_ID_, me.name); R_do_dns = strlen(REPORT_DO_DNS); R_fin_dns = strlen(REPORT_FIN_DNS); R_fin_dnsc = strlen(REPORT_FIN_DNSC); R_fail_dns = strlen(REPORT_FAIL_DNS); R_do_id = strlen(REPORT_DO_ID); R_fin_id = strlen(REPORT_FIN_ID); R_fail_id = strlen(REPORT_FAIL_ID); check_class(); if (bootopt & BOOT_OPER) { aClient *tmp = add_connection(&me, 0); if (!tmp) exit(1); SetMaster(tmp); } else write_pidfile(); Debug((DEBUG_NOTICE, "Server ready...")); #ifdef USE_SYSLOG syslog(LOG_NOTICE, "Server Ready"); #endif NOW = time(NULL); #ifndef NO_PRIORITY check_fdlists(); #endif if ((timeofday = time(NULL)) == -1) { #ifdef USE_SYSLOG syslog(LOG_WARNING, "Clock Failure (%d), TS can be corrupted", errno); #endif sendto_ops("Clock Failure (%d), TS can be corrupted", errno); } #ifdef DUMP_DEBUG dumpfp=fopen("dump.log", "w"); #endif io_loop(); return 0; }
int main(int argc, char *argv[]) { int portarg = 0; uid_t uid, euid; time_t delay = 0; int fd; if((timeofday = time(NULL)) == -1) { (void)fprintf(stderr,"ERROR: Clock Failure (%d)\n", errno); exit(errno); } /* * We don't want to calculate these every time they are used :) */ R_do_dns = strlen(REPORT_DO_DNS); R_fin_dns = strlen(REPORT_FIN_DNS); R_fin_dnsc = strlen(REPORT_FIN_DNSC); R_fail_dns = strlen(REPORT_FAIL_DNS); R_do_id = strlen(REPORT_DO_ID); R_fin_id = strlen(REPORT_FIN_ID); R_fail_id = strlen(REPORT_FAIL_ID); Count.server = 1; /* us */ Count.oper = 0; Count.chan = 0; Count.local = 0; Count.total = 0; Count.invisi = 0; Count.unknown = 0; Count.max_loc = 0; Count.max_tot = 0; /* this code by [email protected] */ /* it is intended to keep the ircd from being swapped out. BSD swapping criteria do not match the requirements of ircd */ #ifdef SETUID_ROOT if(plock(TXTLOCK)<0) fprintf(stderr,"could not plock...\n"); if(setuid(IRCD_UID)<0)exit(-1); /* blah.. this should be done better */ #endif #ifdef INITIAL_DBUFS dbuf_init(); /* set up some dbuf stuff to control paging */ #endif sbrk0 = (char *)sbrk((size_t)0); uid = getuid(); euid = geteuid(); #ifdef PROFIL (void)monstartup(0, etext); (void)moncontrol(1); (void)signal(SIGUSR1, s_monitor); #endif #ifdef CHROOTDIR if (chdir(dpath)) { perror("chdir"); exit(-1); } res_init(); if (chroot(DPATH)) { (void)fprintf(stderr,"ERROR: Cannot chdir/chroot\n"); exit(5); } #endif /*CHROOTDIR*/ myargv = argv; (void)umask(077); /* better safe than sorry --SRB */ bzero((char *)&me, sizeof(me)); setup_signals(); /* ** All command line parameters have the syntax "-fstring" ** or "-f string" (e.g. the space is optional). String may ** be empty. Flag characters cannot be concatenated (like ** "-fxyz"), it would conflict with the form "-fstring". */ while (--argc > 0 && (*++argv)[0] == '-') { char *p = argv[0]+1; int flag = *p++; if (flag == '\0' || *p == '\0') if (argc > 1 && argv[1][0] != '-') { p = *++argv; argc -= 1; } else p = ""; switch (flag) { case 'a': bootopt |= BOOT_AUTODIE; break; case 'c': bootopt |= BOOT_CONSOLE; break; case 'q': bootopt |= BOOT_QUICK; break; case 'd' : (void)setuid((uid_t)uid); dpath = p; break; case 'o': /* Per user local daemon... */ (void)setuid((uid_t)uid); bootopt |= BOOT_OPER; break; #ifdef CMDLINE_CONFIG case 'f': (void)setuid((uid_t)uid); configfile = p; break; #ifdef KPATH case 'k': (void)setuid((uid_t)uid); klinefile = p; break; #endif #endif case 'h': strncpyzt(me.name, p, sizeof(me.name)); break; case 'i': bootopt |= BOOT_INETD|BOOT_AUTODIE; break; case 'p': if ((portarg = atoi(p)) > 0 ) portnum = portarg; break; case 's': bootopt |= BOOT_STDERR; break; case 't': (void)setuid((uid_t)uid); bootopt |= BOOT_TTY; break; case 'v': (void)printf("ircd %s\n", version); exit(0); case 'x': #ifdef DEBUGMODE (void)setuid((uid_t)uid); debuglevel = atoi(p); debugmode = *p ? p : "0"; bootopt |= BOOT_DEBUG; break; #else (void)fprintf(stderr, "%s: DEBUGMODE must be defined for -x y\n", myargv[0]); exit(0); #endif default: bad_command(); break; } } #ifndef CHROOT if (chdir(dpath)) { perror("chdir"); exit(-1); } #endif #ifndef IRC_UID if ((uid != euid) && !euid) { (void)fprintf(stderr, "ERROR: do not run ircd setuid root. Make it setuid a\ normal user.\n"); exit(-1); }