int init_resolver(int op) { int ret = 0; if (op & RES_INITLIST) { bzero((char *)&reinfo, sizeof(reinfo)); first = last = NULL; } if (op & RES_CALLINIT) { ret = ircd_res_init(); if (!ircd_res.nscount) { ircd_res.nscount = 1; Debug((DEBUG_DNS, "Setting nameserver to be %s", NAME_SERVER)); #ifdef INET6 /* still IPv4 */ ircd_res.nsaddr_list[0].sin_addr.s_addr = inet_pton(AF_INET, NAME_SERVER, &ircd_res.nsaddr_list[0].sin_addr.s_addr); #else ircd_res.nsaddr_list[0].sin_addr.s_addr = inet_addr(NAME_SERVER); #endif } } if (op & RES_INITSOCK) { int on = 0; #ifdef INET6 /* still IPv4 */ ret = resfd = socket(AF_INET, SOCK_DGRAM, 0); #else ret = resfd = socket(AF_INET, SOCK_DGRAM, 0); #endif (void)setsockopt(ret, SOL_SOCKET, SO_BROADCAST, &on, on); } #ifdef DEBUGMODE if (op & RES_INITDEBG) ircd_res.options |= RES_DEBUG; #endif if (op & RES_INITCACH) { bzero((char *)&cainfo, sizeof(cainfo)); bzero((char *)hashtable, sizeof(hashtable)); } if (op == 0) ret = resfd; return ret; }
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); }
int init_resolver(int op) { int ret = 0; #ifdef LRAND48 srand48(time(NULL)); #endif if (op & RES_INITLIST) { bzero((char *)&reinfo, sizeof(reinfo)); first = last = NULL; } if (op & RES_CALLINIT) { ret = ircd_res_init(); if (!ircd_res.nscount) { ircd_res.nscount = 1; #ifdef INET6 if (!inetpton(AF_INET6, "::1", &ircd_res.nsaddr_list[0].sin6_addr.s6_addr)) { bcopy(minus_one, ircd_res.nsaddr_list[0].sin6_addr.s6_addr, IN6ADDRSZ); } #else ircd_res.nsaddr_list[0].sin_addr.s_addr = inetaddr("127.0.0.1"); #endif } } if (op & RES_INITSOCK) { int on = 0; ret = resfd = socket(AFINET, SOCK_DGRAM, 0); (void) SETSOCKOPT(ret, SOL_SOCKET, SO_BROADCAST, &on, on); /* The following frame is a hack to allow resolving * in FreeBSD jail(). As it is harmless elsewhere, it is * not #ifdef-ed. * Note that currently IPv6 within jail() is not * supported by the FreeBSD. */ { struct SOCKADDR_IN res_addr; memset(&res_addr, 0, sizeof(res_addr)); res_addr.SIN_FAMILY = AFINET; #ifdef INET6 res_addr.sin6_addr = in6addr_any; #else res_addr.sin_addr.s_addr = htonl(INADDR_ANY); #endif bind(resfd, (SAP) &res_addr, sizeof(res_addr)); } } #ifdef DEBUG if (op & RES_INITDEBG); ircd_res.options |= RES_DEBUG; #endif if (op & RES_INITCACH) { bzero((char *)&cainfo, sizeof(cainfo)); bzero((char *)hashtable, sizeof(hashtable)); } if (op == 0) ret = resfd; return ret; }