conf.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  1. /*
  2. * conf.c -- handles:
  3. *
  4. * all of the conf handling
  5. */
  6. #include "common.h"
  7. #include "conf.h"
  8. #include "shell.h"
  9. #include "binary.h"
  10. #include "debug.h"
  11. #include "chanprog.h"
  12. #include "crypt.h"
  13. #include "main.h"
  14. #include "settings.h"
  15. #include "src/mod/irc.mod/irc.h"
  16. #include "misc.h"
  17. #include "users.h"
  18. #include "misc_file.h"
  19. #include "socket.h"
  20. #include "botnet.h"
  21. #include "userrec.h"
  22. #include <errno.h>
  23. #ifdef HAVE_PATHS_H
  24. # include <paths.h>
  25. #endif /* HAVE_PATHS_H */
  26. #include <sys/types.h>
  27. #include <sys/wait.h>
  28. #include <sys/stat.h>
  29. #include <time.h>
  30. #include <sys/time.h>
  31. #include <signal.h>
  32. #ifdef HAVE_LIMITS_H
  33. # include <limits.h>
  34. #endif
  35. #ifdef CYGWIN_HACKS
  36. char cfile[DIRMAX] = "";
  37. #endif /* CYGWIN_HACKS */
  38. conf_t conf; /* global conf struct */
  39. static void
  40. tellconf()
  41. {
  42. conf_bot *bot = NULL;
  43. int i = 0;
  44. sdprintf(STR("tempdir: %s\n"), replace(tempdir, conf.homedir, "~"));
  45. sdprintf(STR("features: %d\n"), conf.features);
  46. sdprintf(STR("uid: %d\n"), conf.uid);
  47. sdprintf(STR("uname: %s\n"), conf.uname);
  48. sdprintf(STR("homedir: %s\n"), conf.homedir);
  49. sdprintf(STR("username: %s\n"), conf.username);
  50. sdprintf(STR("binpath: %s\n"), replace(conf.binpath, conf.homedir, "~"));
  51. sdprintf(STR("binname: %s\n"), conf.binname);
  52. sdprintf(STR("datadir: %s\n"), replace(conf.datadir, conf.homedir, "~"));
  53. sdprintf(STR("portmin: %d\n"), conf.portmin);
  54. sdprintf(STR("portmax: %d\n"), conf.portmax);
  55. sdprintf(STR("pscloak: %d\n"), conf.pscloak);
  56. sdprintf(STR("autocron: %d\n"), conf.autocron);
  57. sdprintf(STR("autouname: %d\n"), conf.autouname);
  58. sdprintf(STR("watcher: %d\n"), conf.watcher);
  59. sdprintf(STR("bots:\n"));
  60. for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
  61. i++;
  62. sdprintf(STR("%d: %s%s IP: %s HOST: %s IP6: %s HOST6: %s v6: %d HUB: %d PID: %d\n"), i,
  63. bot->disabled ? "/" : "",
  64. bot->nick,
  65. bot->net.ip ? bot->net.ip : "",
  66. bot->net.host ? bot->net.host : "", bot->net.ip6 ? bot->net.ip6 : "", bot->net.host6 ? bot->net.host6 : "",
  67. bot->net.v6,
  68. bot->hub,
  69. bot->pid);
  70. }
  71. if (conf.bot && ((bot = conf.bot))) {
  72. sdprintf(STR("me:\n"));
  73. sdprintf(STR("%s%s IP: %s HOST: %s IP6: %s HOST6: %s v6: %d HUB: %d PID: %d\n"),
  74. bot->disabled ? "/" : "",
  75. bot->nick,
  76. bot->net.ip ? bot->net.ip : "",
  77. bot->net.host ? bot->net.host : "", bot->net.ip6 ? bot->net.ip6 : "", bot->net.host6 ? bot->net.host6 : "",
  78. bot->net.v6,
  79. bot->hub,
  80. bot->pid);
  81. }
  82. }
  83. void spawnbot(const char *nick)
  84. {
  85. size_t size = strlen(shell_escape(nick)) + strlen(shell_escape(binname)) + 20;
  86. char *run = (char *) my_calloc(1, size);
  87. int status = 0;
  88. simple_snprintf(run, size, "%s %s", shell_escape(binname), shell_escape(nick));
  89. sdprintf("Spawning '%s': %s", nick, run);
  90. status = system(run);
  91. if (status == -1 || WEXITSTATUS(status))
  92. sdprintf("Failed to spawn '%s': %s", nick, strerror(errno));
  93. free(run);
  94. }
  95. /* spawn and kill bots accordingly
  96. * bots prefixxed with '/' will be killed auto if running.
  97. * if (updating) then we were called with -U or -u */
  98. void
  99. spawnbots(conf_bot *bots, bool rehashed)
  100. {
  101. conf_bot *bot = NULL;
  102. for (bot = bots; bot && bot->nick; bot = bot->next) {
  103. sdprintf("checking bot: %s", bot->nick);
  104. if (bot->disabled) {
  105. /* kill it if running */
  106. if (bot->pid) {
  107. kill(bot->pid, SIGKILL);
  108. bot->pid = 0;
  109. } else
  110. continue;
  111. /* if we're updating automatically, we were called with -u and are only supposed to kill non-localhubs
  112. -if updating and we find our nick, skip
  113. -if pid exists and not updating, bot is running and we have nothing more to do, skip.
  114. */
  115. } else if ((conf.bot && !egg_strcasecmp(bot->nick, conf.bot->nick) &&
  116. (updating == UPDATE_AUTO || rehashed)) || (bot->pid && !updating)) {
  117. sdprintf(STR(" ... skipping. Updating: %d, pid: %d"), updating, bot->pid);
  118. continue;
  119. } else {
  120. /* if we are updating with -u then we need to restart ALL bots */
  121. if (updating == UPDATE_AUTO && bot->pid) {
  122. kill(bot->pid, SIGHUP);
  123. continue;
  124. }
  125. spawnbot(bot->nick);
  126. }
  127. }
  128. }
  129. int
  130. conf_killbot(conf_bot *bots, const char *botnick, conf_bot *bot, int signal, bool notbotnick)
  131. {
  132. int ret = -1;
  133. if (bot) {
  134. if (bot->pid)
  135. ret = kill(bot->pid, signal);
  136. } else {
  137. for (bot = bots; bot && bot->nick; bot = bot->next) {
  138. /* kill all bots but myself if botnick==NULL, otherwise just kill botnick */
  139. if ((!conf.bot) ||
  140. (!botnick &&
  141. (conf.bot->nick && egg_strcasecmp(conf.bot->nick, bot->nick))) ||
  142. (botnick &&
  143. ((notbotnick == 0 && !egg_strcasecmp(botnick, bot->nick)) ||
  144. (notbotnick == 1 && egg_strcasecmp(botnick, bot->nick))
  145. )
  146. )
  147. ) {
  148. if (bot->pid)
  149. ret = kill(bot->pid, signal);
  150. if (botnick && !notbotnick)
  151. break;
  152. }
  153. }
  154. }
  155. return ret;
  156. }
  157. #ifndef CYGWIN_HACKS
  158. static uid_t save_euid, save_egid;
  159. static int
  160. swap_uids()
  161. {
  162. save_euid = geteuid();
  163. save_egid = getegid();
  164. return (setegid(getgid()) || seteuid(getuid()))? -1 : 0;
  165. }
  166. static int
  167. swap_uids_back()
  168. {
  169. return (setegid(save_egid) || seteuid(save_euid)) ? -1 : 0;
  170. }
  171. static int
  172. my_gettime(struct timespec *ts)
  173. {
  174. int rval;
  175. #if defined(HAVE_GETTIMEOFDAY) && (defined(HAVE_ST_MTIM) || defined(HAVE_ST_MTIMESPEC))
  176. struct timeval tv;
  177. rval = gettimeofday(&tv, NULL);
  178. ts->tv_sec = tv.tv_sec;
  179. ts->tv_nsec = tv.tv_usec * 1000;
  180. #else
  181. rval = (int)time(&ts->tv_sec);
  182. ts->tv_nsec = 0;
  183. #endif
  184. return (rval);
  185. }
  186. void
  187. confedit()
  188. {
  189. Tempfile tmpconf = Tempfile("conf");
  190. const char *editor = NULL;
  191. mode_t um;
  192. int waiter;
  193. pid_t pid, xpid;
  194. struct stat st, sn;
  195. struct timespec ts1, ts2; /* time before and after edit */
  196. bool autowrote = 0;
  197. conf_bot *oldbots = NULL;
  198. um = umask(077);
  199. autowrote = writeconf(NULL, tmpconf.f, CONF_COMMENT);
  200. fstat(tmpconf.fd, &st); /* for file modification compares */
  201. // tmpconf.my_close();
  202. umask(um);
  203. if (!can_stat(tmpconf.file))
  204. fatal(STR("Cannot stat tempfile"), 0);
  205. /* Okay, edit the file */
  206. if ((!((editor = getenv(STR("EDITOR"))) && strlen(editor)))
  207. && (!((editor = getenv(STR("VISUAL"))) && strlen(editor)))
  208. ) {
  209. editor = STR("vi");
  210. /*
  211. #if defined(DEBIAN)
  212. editor = "/usr/bin/editor";
  213. #elif defined(_PATH_VI)
  214. editor = _PATH_VI;
  215. #else
  216. editor = "/usr/ucb/vi";
  217. #endif
  218. */
  219. }
  220. signal(SIGINT, SIG_IGN);
  221. signal(SIGQUIT, SIG_IGN);
  222. signal(SIGCONT, SIG_DFL);
  223. swap_uids();
  224. my_gettime(&ts1);
  225. switch (pid = fork()) {
  226. case -1:
  227. fatal(STR("Cannot fork"), 0);
  228. case 0:
  229. {
  230. char *run = NULL;
  231. size_t size = tmpconf.len + strlen(editor) + 5;
  232. setgid(getgid());
  233. setuid(getuid());
  234. run = (char *) my_calloc(1, size);
  235. /* child */
  236. simple_snprintf(run, size, "%s %s", editor, tmpconf.file);
  237. execlp("/bin/sh", "/bin/sh", "-c", run, (char*)NULL);
  238. perror(editor);
  239. exit(1);
  240. /*NOTREACHED*/}
  241. default:
  242. /* parent */
  243. break;
  244. }
  245. /* parent */
  246. while (1) {
  247. xpid = waitpid(pid, &waiter, WUNTRACED);
  248. my_gettime(&ts2);
  249. if (xpid == -1) {
  250. fprintf(stderr, STR("waitpid() failed waiting for PID %d from \"%s\": %s\n"), pid, editor, strerror(errno));
  251. } else if (xpid != pid) {
  252. fprintf(stderr, STR("wrong PID (%d != %d) from \"%s\"\n"), xpid, pid, editor);
  253. goto fatal;
  254. } else if (WIFSTOPPED(waiter)) {
  255. /* raise(WSTOPSIG(waiter)); Not needed and breaks in job control shell */
  256. } else if (WIFEXITED(waiter) && WEXITSTATUS(waiter)) {
  257. fprintf(stderr, STR("\"%s\" exited with status %d\n"), editor, WEXITSTATUS(waiter));
  258. goto fatal;
  259. } else if (WIFSIGNALED(waiter)) {
  260. fprintf(stderr, STR("\"%s\" killed; signal %d (%score dumped)\n"), editor, WTERMSIG(waiter),
  261. # ifdef CYGWIN_HACKS
  262. 0
  263. # else
  264. WCOREDUMP(waiter)
  265. # endif
  266. /* CYGWIN_HACKS */
  267. ? "" : "no ");
  268. goto fatal;
  269. } else {
  270. break;
  271. }
  272. }
  273. signal(SIGINT, SIG_DFL);
  274. signal(SIGQUIT, SIG_DFL);
  275. swap_uids_back();
  276. if (fstat(tmpconf.fd, &sn))
  277. fatal(STR("Error reading new config file"), 0);
  278. if (!autowrote && st.st_size == sn.st_size &&
  279. mtim_getsec(st) == mtim_getsec(sn) &&
  280. mtim_getnsec(st) == mtim_getnsec(sn)) {
  281. /*
  282. * If mtime and size match but the user spent no measurable
  283. * time in the editor we can't tell if the file was changed.
  284. */
  285. #ifdef HAVE_TIMESPECSUB2
  286. timespecsub(&ts1, &ts2);
  287. #else
  288. timespecsub(&ts1, &ts2, &ts2);
  289. #endif
  290. if (timespecisset(&ts2)) {
  291. printf(STR("* Config unchanged.\n"));
  292. exit(0);
  293. }
  294. }
  295. tmpconf.my_close();
  296. oldbots = conf_bots_dup(conf.bots);
  297. free_conf();
  298. readconf((const char *) tmpconf.file, 0); /* read cleartext conf tmp into &settings */
  299. expand_tilde(&conf.binpath);
  300. expand_tilde(&conf.datadir);
  301. unlink(tmpconf.file);
  302. conf_to_bin(&conf, 0, -1);
  303. /* Now signal all of the old bots with SIGUSR1
  304. * They will auto die and determine new localhub, etc..
  305. */
  306. conf_checkpids(oldbots);
  307. conf_killbot(oldbots, NULL, NULL, SIGUSR1);
  308. /* Now spawn new bots */
  309. // spawnbots(conf.bots);
  310. exit(0);
  311. fatal:
  312. unlink(tmpconf.file);
  313. exit(1);
  314. }
  315. #endif /* !CYGWIN_HACKS */
  316. void
  317. init_conf()
  318. {
  319. // conf.bots = (conf_bot *) my_calloc(1, sizeof(conf_bot));
  320. // conf.bots->nick = NULL;
  321. // conf.bots->next = NULL;
  322. conf.bots = NULL;
  323. conf.bot = NULL;
  324. conf.localhub = NULL;
  325. conf.watcher = 0;
  326. #ifdef CYGWIN_HACKS
  327. conf.autocron = 0;
  328. #else
  329. conf.autocron = 1;
  330. #endif /* !CYGWIN_HACKS */
  331. conf.autouname = 0;
  332. #ifdef CYGWIN_HACKS
  333. if (homedir())
  334. conf.binpath = strdup(homedir());
  335. #else /* !CYGWIN_HACKS */
  336. conf.binpath = strdup(dirname(binname));
  337. #endif /* CYGWIN_HACKS */
  338. char *p = strrchr(binname, '/');
  339. p++;
  340. if (!strncmp(p, STR("wraith."), 7) && strchr(p, '-'))
  341. conf.binname = strdup(STR("wraith"));
  342. else
  343. conf.binname = strdup(p);
  344. conf.features = 0;
  345. conf.portmin = 0;
  346. conf.portmax = 0;
  347. conf.pscloak = 0;
  348. conf.uid = -1;
  349. conf.uname = NULL;
  350. conf.username = NULL;
  351. conf.homedir = NULL;
  352. conf.datadir = strdup(STR("./..."));
  353. expand_tilde(&conf.datadir);
  354. }
  355. void conf_checkpids(conf_bot *bots, bool all)
  356. {
  357. conf_bot *bot = NULL;
  358. for (bot = bots; bot && bot->nick; bot = bot->next)
  359. if (all || (!all && bot->pid == 0))
  360. bot->pid = checkpid(bot->nick, bot);
  361. }
  362. /*
  363. * Return the PID of a bot if it is running, otherwise return 0
  364. */
  365. pid_t
  366. checkpid(const char *nick, conf_bot *bot)
  367. {
  368. FILE *f = NULL;
  369. char buf[DIRMAX] = "", *tmpnick = NULL, *tmp_ptr = NULL;
  370. pid_t pid = 0;
  371. tmpnick = tmp_ptr = strdup(nick);
  372. strtolower(tmpnick);
  373. simple_snprintf(buf, sizeof buf, STR("%s/.pid.%s"), conf.datadir, tmpnick);
  374. free(tmp_ptr);
  375. if (bot && !(bot->pid_file))
  376. bot->pid_file = strdup(buf);
  377. else if (bot && egg_strcasecmp(bot->pid_file, buf))
  378. str_redup(&bot->pid_file, buf);
  379. if ((f = fopen(buf, "r"))) {
  380. char *bufp = NULL, *pids = NULL;
  381. fgets(buf, sizeof(buf), f);
  382. fclose(f);
  383. remove_crlf(buf);
  384. if (!buf[0])
  385. return 0;
  386. bufp = buf;
  387. pids = newsplit(&bufp);
  388. if (str_isdigit(pids)) {
  389. pid = atoi(pids);
  390. if (kill(pid, SIGCHLD)) //Problem killing, most likely it's just not running.
  391. pid = 0;
  392. }
  393. if (bufp[0] && pid && can_stat(bufp) && (getpid() == pid) &&
  394. !egg_strncasecmp(nick, origbotnick, HANDLEN)) {
  395. socksfile = strdup(bufp);
  396. return 0;
  397. }
  398. }
  399. return pid;
  400. }
  401. void
  402. conf_addbot(char *nick, char *ip, char *host, char *ip6)
  403. {
  404. conf_bot *bot = (conf_bot *) my_calloc(1, sizeof(conf_bot));
  405. bot->next = NULL;
  406. bot->pid_file = NULL;
  407. if (nick[0] == '/') {
  408. bot->disabled = 1;
  409. ++nick;
  410. sdprintf(STR("%s is disabled."), nick);
  411. }
  412. bot->nick = strldup(nick, HANDLEN);
  413. bot->net.ip = NULL;
  414. bot->net.host = NULL;
  415. bot->net.ip6 = NULL;
  416. bot->net.host6 = NULL;
  417. if (host && host[0] == '+') {
  418. ++host;
  419. bot->net.host6 = strdup(host);
  420. } else if (host && !strchr(".*", host[0])) {
  421. bot->net.host = strdup(host);
  422. }
  423. if (ip && !strchr(".*", ip[0])) {
  424. int aftype = is_dotted_ip(ip);
  425. if (aftype == AF_INET)
  426. bot->net.ip = strdup(ip);
  427. #ifdef USE_IPV6
  428. else if (aftype == AF_INET6)
  429. bot->net.ip6 = strdup(ip);
  430. #endif /* USE_IPV6 */
  431. else if (aftype == 0) { /* The idiot used a hostname in place of ip */
  432. if (bot->net.host)
  433. free(bot->net.host);
  434. bot->net.host = strdup(ip);
  435. }
  436. }
  437. #ifdef USE_IPV6
  438. if (ip6 && !strchr(".*", ip6[0]) && is_dotted_ip(ip6) == AF_INET6)
  439. bot->net.ip6 = strdup(ip6);
  440. if (bot->net.ip6 || bot->net.host6)
  441. bot->net.v6 = 1;
  442. #endif /* USE_IPV6 */
  443. if (userlist)
  444. bot->u = get_user_by_handle(userlist, nick);
  445. else
  446. bot->u = NULL;
  447. // bot->pid = checkpid(nick, bot);
  448. if (settings.hubs && is_hub(bot->nick))
  449. bot->hub = 1;
  450. /* not a hub
  451. AND
  452. * no bots added yet (first bot) yet, not disabled.
  453. OR
  454. * bots already listed but we dont have a localhub yet, so we're it!
  455. */
  456. if (!conf.localhub && !bot->hub && !bot->disabled) {
  457. bot->localhub = 1; /* first bot */
  458. conf.localhub = strdup(bot->nick);
  459. }
  460. list_append((struct list_type **) &(conf.bots), (struct list_type *) bot);
  461. }
  462. void
  463. free_bot(conf_bot *bot)
  464. {
  465. if (bot) {
  466. list_delete((struct list_type **) &(conf.bots), (struct list_type *) bot);
  467. free(bot->nick);
  468. free(bot->pid_file);
  469. if (bot->net.ip)
  470. free(bot->net.ip);
  471. if (bot->net.host)
  472. free(bot->net.host);
  473. if (bot->net.ip6)
  474. free(bot->net.ip6);
  475. if (bot->net.host6)
  476. free(bot->net.host6);
  477. free(bot);
  478. }
  479. }
  480. int
  481. conf_delbot(char *botn, bool kill)
  482. {
  483. conf_bot *bot = NULL;
  484. for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
  485. if (!egg_strcasecmp(bot->nick, botn)) { /* found it! */
  486. if (kill) {
  487. bot->pid = checkpid(bot->nick, bot);
  488. conf_killbot(conf.bots, NULL, bot, SIGKILL);
  489. }
  490. free_bot(bot);
  491. return 0;
  492. }
  493. }
  494. return 1;
  495. }
  496. void
  497. free_conf()
  498. {
  499. free_conf_bots(conf.bots);
  500. free_bot(conf.bot);
  501. conf.bot = NULL;
  502. if (conf.localhub)
  503. free(conf.localhub);
  504. if (conf.uname)
  505. free(conf.uname);
  506. if (conf.username)
  507. free(conf.username);
  508. if (conf.datadir)
  509. free(conf.datadir);
  510. if (conf.homedir)
  511. free(conf.homedir);
  512. if (conf.binname)
  513. free(conf.binname);
  514. if (conf.binpath)
  515. free(conf.binpath);
  516. init_conf();
  517. }
  518. void
  519. free_conf_bots(conf_bot *list)
  520. {
  521. if (list) {
  522. conf_bot *bot = NULL, *bot_n = NULL;
  523. for (bot = list; bot; bot = bot_n) {
  524. bot_n = bot->next;
  525. free_bot(bot);
  526. }
  527. list = NULL;
  528. }
  529. }
  530. void prep_homedir(bool error)
  531. {
  532. if (!conf.homedir)
  533. str_redup(&conf.homedir, homedir());
  534. if (error && (!conf.homedir || !conf.homedir[0]))
  535. werr(ERR_NOHOMEDIR);
  536. }
  537. int
  538. parseconf(bool error)
  539. {
  540. if (error && conf.uid == -1 && !conf.uname)
  541. werr(ERR_NOTINIT);
  542. if (!conf.username)
  543. str_redup(&conf.username, my_username());
  544. if (error && (!conf.username || !conf.username[0]))
  545. werr(ERR_NOUSERNAME);
  546. #ifndef CYGWIN_HACKS
  547. if (error && conf.uid != (signed) myuid) {
  548. sdprintf(STR("wrong uid, conf: %d :: %d"), conf.uid, myuid);
  549. werr(ERR_WRONGUID);
  550. } else if (!conf.uid)
  551. conf.uid = myuid;
  552. if (conf.uname && strcmp(conf.uname, my_uname()) && !conf.autouname) {
  553. baduname(conf.uname, my_uname()); /* its not auto, and its not RIGHT, bail out. */
  554. sdprintf(("wrong uname, conf: %s :: %s"), conf.uname, my_uname());
  555. if (error)
  556. werr(ERR_WRONGUNAME);
  557. } else if (conf.uname && conf.autouname) { /* if autouname, dont bother comparing, just set uname to output */
  558. str_redup(&conf.uname, my_uname());
  559. } else if (!conf.uname) { /* if not set, then just set it, wont happen again next time... */
  560. conf.uname = strdup(my_uname());
  561. }
  562. #endif /* !CYGWIN_HACKS */
  563. return 0;
  564. }
  565. int
  566. readconf(const char *fname, int bits)
  567. {
  568. FILE *f = NULL;
  569. int i = 0, enc = (bits & CONF_ENC) ? 1 : 0;
  570. char *inbuf = NULL;
  571. sdprintf(STR("readconf(%s, %d)"), fname, enc);
  572. Context;
  573. if (!(f = fopen(fname, "r")))
  574. fatal(STR("Cannot read config"), 0);
  575. free_conf_bots(conf.bots);
  576. inbuf = (char *) my_calloc(1, 201);
  577. while (fgets(inbuf, 201, f) != NULL) {
  578. char *line = NULL, *temp_ptr = NULL;
  579. remove_crlf(inbuf);
  580. if (enc)
  581. line = temp_ptr = decrypt_string(settings.salt1, inbuf);
  582. else
  583. line = inbuf;
  584. if ((line && !line[0]) || line[0] == '\n') {
  585. if (enc)
  586. free(line);
  587. continue;
  588. }
  589. i++;
  590. rmspace(line);
  591. sdprintf(STR("CONF LINE: %s"), line);
  592. // !strchr("_`|}][{*/#-+!abcdefghijklmnopqrstuvwxyzABDEFGHIJKLMNOPWRSTUVWXYZ", line[0])) {
  593. if (enc && line[0] > '~') {
  594. sdprintf(STR("line %d, char %c "), i, line[0]);
  595. fatal(STR("Bad encryption"), 0);
  596. } else { /* line is good to parse */
  597. /* - uid */
  598. if (line[0] == '-') {
  599. newsplit(&line);
  600. if (conf.uid == -1)
  601. conf.uid = atoi(line);
  602. /* + uname */
  603. } else if (line[0] == '+') {
  604. newsplit(&line);
  605. if (!conf.uname)
  606. conf.uname = strdup(line);
  607. /* ! is misc options */
  608. } else if (line[0] == '!') {
  609. char *option = NULL;
  610. /* Only newplit if they did '! option' */
  611. if (line[1] == ' ')
  612. newsplit(&line);
  613. else
  614. ++line;
  615. if (line[0])
  616. option = newsplit(&line);
  617. if (!option || !line[0])
  618. continue;
  619. if (!egg_strcasecmp(option, STR("autocron"))) { /* automatically check/create crontab? */
  620. if (egg_isdigit(line[0]))
  621. conf.autocron = atoi(line);
  622. } else if (!egg_strcasecmp(option, STR("autouname"))) { /* auto update uname contents? */
  623. if (egg_isdigit(line[0]))
  624. conf.autouname = atoi(line);
  625. } else if (!egg_strcasecmp(option, STR("username"))) { /* shell username */
  626. str_redup(&conf.username, line);
  627. } else if (!egg_strcasecmp(option, STR("homedir"))) { /* homedir */
  628. str_redup(&conf.homedir, line);
  629. } else if (!egg_strcasecmp(option, STR("datadir"))) { /* datadir */
  630. str_redup(&conf.datadir, line);
  631. } else if (!egg_strcasecmp(option, STR("binpath"))) { /* path that the binary should move to? */
  632. str_redup(&conf.binpath, line);
  633. } else if (!egg_strcasecmp(option, STR("binname"))) { /* filename of the binary? */
  634. str_redup(&conf.binname, line);
  635. } else if (!egg_strcasecmp(option, STR("portmin"))) {
  636. if (egg_isdigit(line[0]))
  637. conf.portmin = atoi(line);
  638. } else if (!egg_strcasecmp(option, STR("portmax"))) {
  639. if (egg_isdigit(line[0]))
  640. conf.portmax = atoi(line);
  641. } else if (!egg_strcasecmp(option, STR("pscloak"))) { /* should bots on this shell pscloak? */
  642. if (egg_isdigit(line[0]))
  643. conf.pscloak = atoi(line);
  644. } else if (!egg_strcasecmp(option, STR("uid"))) { /* new method uid */
  645. if (str_isdigit(line))
  646. conf.uid = atoi(line);
  647. } else if (!egg_strcasecmp(option, STR("uname"))) { /* new method uname */
  648. str_redup(&conf.uname, line);
  649. } else if (!egg_strcasecmp(option, STR("watcher"))) {
  650. if (egg_isdigit(line[0]))
  651. conf.watcher = atoi(line);
  652. } else {
  653. putlog(LOG_MISC, "*", STR("Unrecognized config option '%s'"), option);
  654. }
  655. /* read in portmin */
  656. } else if (line[0] == '>') {
  657. newsplit(&line);
  658. conf.portmin = atoi(line);
  659. } else if (line[0] == '<') {
  660. newsplit(&line);
  661. conf.portmax = atoi(line);
  662. /* now to parse nick/hosts */
  663. } else if (line[0] != '#') {
  664. char *nick = NULL, *host = NULL, *ip = NULL, *ipsix = NULL;
  665. nick = newsplit(&line);
  666. if (!nick || (nick && !nick[0]))
  667. werr(ERR_BADCONF);
  668. if (line[0])
  669. ip = newsplit(&line);
  670. if (line[0])
  671. host = newsplit(&line);
  672. if (line[0])
  673. ipsix = newsplit(&line);
  674. conf_addbot(nick, ip, host, ipsix);
  675. }
  676. }
  677. inbuf[0] = 0;
  678. if (enc)
  679. free(temp_ptr);
  680. } /* while(fgets()) */
  681. fclose(f);
  682. free(inbuf);
  683. return 0;
  684. }
  685. int
  686. writeconf(char *filename, FILE * stream, int bits)
  687. {
  688. FILE *f = NULL;
  689. conf_bot *bot = NULL;
  690. int (*my_write) (FILE *, const char *, ... ) = NULL;
  691. int autowrote = 0;
  692. if (bits & CONF_ENC)
  693. my_write = lfprintf;
  694. else if (!(bits & CONF_ENC))
  695. my_write = fprintf;
  696. #define comment(text) do { \
  697. if (bits & CONF_COMMENT) \
  698. my_write(f, STR("%s\n"), text); \
  699. } while(0)
  700. if (stream) {
  701. f = stream;
  702. } else if (filename) {
  703. if (!(f = fopen(filename, "w")))
  704. return 1;
  705. }
  706. #ifndef CYGWIN_HACKS
  707. char *p = NULL;
  708. comment("");
  709. comment("# Lines beginning with # are what the preceeding line SHOULD be");
  710. comment("# They are simply comments and are not parsed at all.\n");
  711. #define conf_com() do { \
  712. if (do_confedit == CONF_AUTO) { \
  713. comment("# Automatically updated with -C"); \
  714. autowrote = 1; \
  715. } else \
  716. comment("#The correct line follows. (Not auto due to -c)"); \
  717. } while(0)
  718. if ((bits & CONF_COMMENT) && conf.uid != (signed) myuid) {
  719. conf_com();
  720. my_write(f, STR("%s! uid %d\n"), do_confedit == CONF_AUTO ? "" : "#", myuid);
  721. my_write(f, STR("%s! uid %d\n"), do_confedit == CONF_STATIC ? "" : "#", conf.uid);
  722. } else
  723. my_write(f, STR("! uid %d\n"), conf.uid);
  724. if (!conf.uname || (conf.uname && conf.autouname && strcmp(conf.uname, my_uname()))) {
  725. autowrote = 1;
  726. if (conf.uname)
  727. comment("# autouname is ON");
  728. else
  729. comment("# Automatically updated empty uname");
  730. my_write(f, STR("! uname %s\n"), my_uname());
  731. if (conf.uname)
  732. my_write(f, STR("#! uname %s\n"), conf.uname);
  733. } else if (conf.uname && !conf.autouname && strcmp(conf.uname, my_uname())) {
  734. conf_com();
  735. my_write(f, STR("%s! uname %s\n"), do_confedit == CONF_AUTO ? "" : "#", my_uname());
  736. my_write(f, STR("%s! uname %s\n"), do_confedit == CONF_STATIC ? "" : "#", conf.uname);
  737. } else
  738. my_write(f, STR("! uname %s\n"), conf.uname);
  739. comment("");
  740. if (conf.username && my_username() && strcmp(conf.username, my_username())) {
  741. conf_com();
  742. my_write(f, STR("%s! username %s\n"), do_confedit == CONF_AUTO ? "" : "#", my_username());
  743. my_write(f, STR("%s! username %s\n"), do_confedit == CONF_STATIC ? "" : "#", conf.username);
  744. } else
  745. my_write(f, STR("! username %s\n"), conf.username ? conf.username : my_username() ? my_username() : "");
  746. if (conf.homedir && homedir(0) && strcmp(conf.homedir, homedir(0))) {
  747. conf_com();
  748. my_write(f, STR("%s! homedir %s\n"), do_confedit == CONF_AUTO ? "" : "#", homedir(0));
  749. my_write(f, STR("%s! homedir %s\n"), do_confedit == CONF_STATIC ? "" : "#", conf.homedir);
  750. } else
  751. my_write(f, STR("! homedir %s\n"), conf.homedir ? conf.homedir : homedir(0) ? homedir(0) : "");
  752. comment("\n# binpath needs to be full path unless it begins with '~', which uses 'homedir', ie, '~/'");
  753. if (homedir() && strstr(conf.binpath, homedir())) {
  754. p = replace(conf.binpath, homedir(), "~");
  755. my_write(f, STR("! binpath %s\n"), p);
  756. } else if (conf.homedir && strstr(conf.binpath, conf.homedir)) { /* Could be an older homedir */
  757. p = replace(conf.binpath, conf.homedir, "~");
  758. my_write(f, STR("! binpath %s\n"), p);
  759. } else
  760. my_write(f, STR("! binpath %s\n"), conf.binpath);
  761. comment("# binname is relative to binpath, if you change this, you'll need to manually remove the old one from crontab.");
  762. my_write(f, STR("! binname %s\n"), conf.binname);
  763. comment("");
  764. if (conf.datadir && strcmp(conf.datadir, "./...")) {
  765. comment("# datadir should be set to a static directory that is writable");
  766. if (homedir() && strstr(conf.datadir, homedir())) {
  767. p = replace(conf.datadir, homedir(), "~");
  768. my_write(f, STR("! datadir %s\n"), p);
  769. } else if (conf.homedir && strstr(conf.datadir, conf.homedir)) { /* Could be an older homedir */
  770. p = replace(conf.datadir, conf.homedir, "~");
  771. my_write(f, STR("! datadir %s\n"), p);
  772. } else
  773. my_write(f, STR("! datadir %s\n"), conf.datadir);
  774. comment("");
  775. }
  776. if (conf.portmin || conf.portmax) {
  777. comment("# portmin/max are for incoming connections (DCC) [0 for any] (These only make sense for HUBS)");
  778. my_write(f, STR("! portmin %d\n"), conf.portmin);
  779. my_write(f, STR("! portmax %d\n"), conf.portmax);
  780. comment("");
  781. }
  782. if (conf.pscloak) {
  783. comment("# Attempt to \"cloak\" the process name in `ps` for Linux?");
  784. my_write(f, STR("! pscloak %d\n"), conf.pscloak);
  785. comment("");
  786. }
  787. if (conf.autocron == 0) {
  788. comment("# Automatically add the bot to crontab?");
  789. my_write(f, STR("! autocron %d\n"), conf.autocron);
  790. comment("");
  791. }
  792. if (conf.autouname) {
  793. comment("# Automatically update 'uname' if it changes? (DANGEROUS)");
  794. my_write(f, STR("! autouname %d\n"), conf.autouname);
  795. comment("");
  796. }
  797. #ifdef NO
  798. comment("# This will spawn a child process for EACH BOT that will block ALL process hijackers.");
  799. my_write(f, STR("! watcher %d\n"), conf.watcher);
  800. comment("");
  801. #endif
  802. comment("# '|' means OR, [] means the enclosed is optional");
  803. comment("# A '+' in front of HOST means the HOST is ipv6");
  804. comment("# A '/' in front of BOT will disable that bot.");
  805. comment("#[/]BOT IP|* [+]HOST|* [IPV6-IP]");
  806. comment("#bot ip vhost");
  807. comment("#bot2 * vhost");
  808. comment("#bot3 ip");
  809. comment("#bot4 * +ipv6.vhost.com");
  810. comment("#bot5 * * ip:v6:ip:goes:here::");
  811. comment("### Hubs should have their own binary ###");
  812. #endif /* CYGWIN_HACKS */
  813. for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
  814. my_write(f, STR("%s%s %s %s%s %s\n"),
  815. bot->disabled ? "/" : "", bot->nick,
  816. bot->net.ip ? bot->net.ip : "*", bot->net.host6 ? "+" : "",
  817. bot->net.host ? bot->net.host : (bot->net.host6 ? bot->net.host6 : "*"), bot->net.ip6 ? bot->net.ip6 : "");
  818. }
  819. fflush(f);
  820. if (!stream)
  821. fclose(f);
  822. return autowrote;
  823. }
  824. void
  825. conf_bot_dup(conf_bot *dest, conf_bot *src)
  826. {
  827. if (dest && src) {
  828. dest->nick = src->nick ? strdup(src->nick) : NULL;
  829. dest->pid_file = src->pid_file ? strdup(src->pid_file) : NULL;
  830. dest->net.ip = src->net.ip ? strdup(src->net.ip) : NULL;
  831. dest->net.host = src->net.host ? strdup(src->net.host) : NULL;
  832. dest->net.ip6 = src->net.ip6 ? strdup(src->net.ip6) : NULL;
  833. dest->net.host6 = src->net.host6 ? strdup(src->net.host6) : NULL;
  834. dest->net.v6 = src->net.v6;
  835. dest->u = src->u ? src->u : NULL;
  836. dest->pid = src->pid;
  837. dest->hub = src->hub;
  838. dest->localhub = src->localhub;
  839. dest->disabled = src->disabled;
  840. dest->next = NULL;
  841. }
  842. }
  843. conf_bot *conf_bots_dup(conf_bot *src)
  844. {
  845. conf_bot *ret = NULL;
  846. if (src) {
  847. conf_bot *bot = NULL, *newbot = NULL;
  848. for (bot = src; bot && bot->nick; bot = bot->next) {
  849. newbot = (conf_bot *) my_calloc(1, sizeof(conf_bot));
  850. conf_bot_dup(newbot, bot);
  851. list_append((struct list_type **) &(ret), (struct list_type *) newbot);
  852. }
  853. }
  854. return ret;
  855. }
  856. void deluser_removed_bots(conf_bot *oldlist, conf_bot *newlist)
  857. {
  858. if (oldlist) {
  859. conf_bot *botold = NULL, *botnew = NULL;
  860. bool found = 0;
  861. struct userrec *u = NULL;
  862. for (botold = oldlist; botold && botold->nick; botold = botold->next) {
  863. found = 0;
  864. for (botnew = newlist; botnew && botnew->nick; botnew = botnew->next) {
  865. if (!egg_strcasecmp(botold->nick, botnew->nick)) {
  866. found = 1;
  867. break;
  868. }
  869. }
  870. if (!found && egg_strcasecmp(botold->nick, origbotnick)) { /* Never kill ME.. will handle it elsewhere */
  871. /* No need to kill -- they are signalled and they will die on their own now */
  872. //botold->pid = checkpid(botold->nick, botold);
  873. //conf_killbot(conf.bots, NULL, botold, SIGKILL);
  874. if ((u = get_user_by_handle(userlist, botold->nick))) {
  875. putlog(LOG_MISC, "*", STR("Removing '%s' as it has been removed from the binary config."), botold->nick);
  876. if (server_online)
  877. check_this_user(botold->nick, 1, NULL);
  878. if (deluser(botold->nick)) {
  879. /* there is likely NO conf[]
  880. if (conf.bot->hub)
  881. write_userfile(-1);
  882. */
  883. }
  884. }
  885. }
  886. }
  887. }
  888. }
  889. void
  890. fill_conf_bot(bool fatal)
  891. {
  892. if (!conf.bots || !conf.bots->nick)
  893. return;
  894. char *mynick = NULL;
  895. conf_bot *me = NULL;
  896. /* This first clause should actually be obsolete */
  897. if (!used_B && conf.bots && conf.bots->nick) {
  898. mynick = strdup(conf.bots->nick);
  899. strlcpy(origbotnick, conf.bots->nick, HANDLEN + 1);
  900. } else
  901. mynick = strldup(origbotnick, HANDLEN);
  902. sdprintf(STR("mynick: %s"), mynick);
  903. for (me = conf.bots; me && me->nick; me = me->next)
  904. if (!egg_strcasecmp(me->nick, mynick))
  905. break;
  906. if (fatal && (!me || (me->nick && egg_strcasecmp(me->nick, mynick))))
  907. werr(ERR_BADBOT);
  908. free(mynick);
  909. if (me) {
  910. if (!me->hub && me->localhub)
  911. sdprintf(STR("I am localhub!"));
  912. /* for future, we may just want to make this a pointer to ->bots if we do an emech style currentbot-> */
  913. conf.bot = (conf_bot *) my_calloc(1, sizeof(conf_bot));
  914. conf_bot_dup(conf.bot, me);
  915. }
  916. }
  917. void
  918. bin_to_conf(bool error)
  919. {
  920. /* printf("Converting binary data to conf struct\n"); */
  921. conf.features = atol(settings.features);
  922. conf.uid = atol(settings.uid);
  923. if (settings.username[0])
  924. str_redup(&conf.username, settings.username);
  925. str_redup(&conf.uname, settings.uname);
  926. str_redup(&conf.datadir, settings.datadir);
  927. if (settings.homedir[0])
  928. str_redup(&conf.homedir, settings.homedir);
  929. str_redup(&conf.binpath, settings.binpath);
  930. str_redup(&conf.binname, settings.binname);
  931. conf.portmin = atol(settings.portmin);
  932. conf.portmax = atol(settings.portmax);
  933. conf.autouname = atoi(settings.autouname);
  934. conf.autocron = atoi(settings.autocron);
  935. conf.watcher = atoi(settings.watcher);
  936. conf.pscloak = atoi(settings.pscloak);
  937. prep_homedir(error);
  938. expand_tilde(&conf.datadir);
  939. expand_tilde(&conf.binpath);
  940. /* PARSE/ADD BOTS */
  941. {
  942. char *p = NULL, *tmp = NULL, *tmpp = NULL;
  943. tmp = tmpp = strdup(settings.bots);
  944. while ((p = strchr(tmp, ','))) {
  945. char *nick = NULL, *host = NULL, *ip = NULL, *ipsix = NULL;
  946. *p++ = 0;
  947. if (!tmp[0])
  948. break;
  949. nick = newsplit(&tmp);
  950. if (!nick || (nick && !nick[0]))
  951. werr(ERR_BADCONF);
  952. if (tmp[0])
  953. ip = newsplit(&tmp);
  954. if (tmp[0])
  955. host = newsplit(&tmp);
  956. if (tmp[0])
  957. ipsix = newsplit(&tmp);
  958. conf_addbot(nick, ip, host, ipsix);
  959. tmp = p++;
  960. }
  961. free(tmpp);
  962. }
  963. char datadir[PATH_MAX] = "";
  964. realpath(conf.datadir, datadir);
  965. str_redup(&conf.datadir, datadir);
  966. if (!mkdir_p(conf.datadir) && error)
  967. werr(ERR_DATADIR);
  968. str_redup(&conf.datadir, replace(datadir, conf.binpath, "."));
  969. Tempfile::FindDir();
  970. if (clear_tmpdir)
  971. clear_tmp(); /* clear out the tmp dir, no matter if we are localhub or not */
  972. conf_checkpids(conf.bots);
  973. tellconf();
  974. }
  975. void conf_add_userlist_bots()
  976. {
  977. conf_bot *bot = NULL;
  978. struct userrec *u = NULL;
  979. struct bot_addr *bi = NULL;
  980. char tmp[81] = "", uhost[UHOSTLEN] = "";
  981. for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
  982. /* Don't auto-add hubs. */
  983. if (!bot->hub && tands > 0 && !bot->disabled) {
  984. u = get_user_by_handle(userlist, bot->nick);
  985. if (!u) {
  986. putlog(LOG_MISC, "*", STR("Adding bot '%s' as it has been added to the binary config."), bot->nick);
  987. userlist = adduser(userlist, bot->nick, "none", "-", USER_OP, 1);
  988. u = get_user_by_handle(userlist, bot->nick);
  989. egg_snprintf(tmp, sizeof(tmp), "%li [internal]", (long)now);
  990. set_user(&USERENTRY_ADDED, u, tmp);
  991. bi = (struct bot_addr *) my_calloc(1, sizeof(struct bot_addr));
  992. bi->address = (char *) my_calloc(1, 1);
  993. bi->uplink = (char *) my_calloc(1, 1);
  994. bi->telnet_port = bi->relay_port = 3333;
  995. bi->hublevel = 999;
  996. set_user(&USERENTRY_BOTADDR, u, bi);
  997. }
  998. if (bot->net.ip) {
  999. simple_snprintf(uhost, sizeof(uhost), "*!%s@%s", conf.username, bot->net.ip);
  1000. if (!user_has_host(NULL, u, uhost) && !host_conflicts(uhost))
  1001. addhost_by_handle(bot->nick, uhost);
  1002. simple_snprintf(uhost, sizeof(uhost), "*!~%s@%s", conf.username, bot->net.ip);
  1003. if (!user_has_host(NULL, u, uhost) && !host_conflicts(uhost))
  1004. addhost_by_handle(bot->nick, uhost);
  1005. }
  1006. if (bot->net.host) {
  1007. simple_snprintf(uhost, sizeof(uhost), "*!%s@%s", conf.username, bot->net.host);
  1008. if (!user_has_host(NULL, u, uhost) && !host_conflicts(uhost))
  1009. addhost_by_handle(bot->nick, uhost);
  1010. simple_snprintf(uhost, sizeof(uhost), "*!~%s@%s", conf.username, bot->net.host);
  1011. if (!user_has_host(NULL, u, uhost) && !host_conflicts(uhost))
  1012. addhost_by_handle(bot->nick, uhost);
  1013. }
  1014. if (bot->net.host6) {
  1015. simple_snprintf(uhost, sizeof(uhost), "*!%s@%s", conf.username, bot->net.host6);
  1016. if (!user_has_host(NULL, u, uhost) && !host_conflicts(uhost))
  1017. addhost_by_handle(bot->nick, uhost);
  1018. simple_snprintf(uhost, sizeof(uhost), "*!~%s@%s", conf.username, bot->net.host6);
  1019. if (!user_has_host(NULL, u, uhost) && !host_conflicts(uhost))
  1020. addhost_by_handle(bot->nick, uhost);
  1021. }
  1022. if (bot->net.ip6) {
  1023. simple_snprintf(uhost, sizeof(uhost), "*!%s@%s", conf.username, bot->net.ip6);
  1024. if (!user_has_host(NULL, u, uhost) && !host_conflicts(uhost))
  1025. addhost_by_handle(bot->nick, uhost);
  1026. simple_snprintf(uhost, sizeof(uhost), "*!~%s@%s", conf.username, bot->net.ip6);
  1027. if (!user_has_host(NULL, u, uhost) && !host_conflicts(uhost))
  1028. addhost_by_handle(bot->nick, uhost);
  1029. }
  1030. }
  1031. }
  1032. }
  1033. conf_bot *conf_getlocalhub(conf_bot *bots) {
  1034. if (!bots)
  1035. return NULL;
  1036. conf_bot *localhub = bots;
  1037. if (localhub->disabled)
  1038. while (localhub && localhub->disabled)
  1039. localhub = localhub->next;
  1040. if (!localhub) return NULL;
  1041. return !localhub->disabled ? localhub : NULL;
  1042. }
  1043. void conf_setmypid(pid_t pid) {
  1044. conf.bot->pid = pid;
  1045. conf_bot *bot = conf.bots;
  1046. if (conf.bots) {
  1047. for (; bot && egg_strcasecmp(bot->nick, conf.bot->nick); bot = bot->next)
  1048. ;
  1049. if (bot)
  1050. bot->pid = pid;
  1051. }
  1052. }