binary.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * binary.c -- handles:
  3. * misc update functions
  4. * md5 hash verifying
  5. *
  6. */
  7. #include "common.h"
  8. #include "binary.h"
  9. #include "settings.h"
  10. #include "crypt.h"
  11. #include "shell.h"
  12. #include "misc.h"
  13. #include "main.h"
  14. #include "misc_file.h"
  15. #include "tandem.h"
  16. #include "botnet.h"
  17. #include "userrec.h"
  18. #include <sys/wait.h>
  19. #include <sys/types.h>
  20. #include <signal.h>
  21. settings_t settings = {
  22. "\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200",
  23. /* -- STATIC -- */
  24. "", "", "", "", "", "", "", "", "", "", "",
  25. /* -- DYNAMIC -- */
  26. "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  27. /* -- PADDING */
  28. ""
  29. };
  30. static void edpack(settings_t *, const char *, int);
  31. #define PACK_ENC 1
  32. #define PACK_DEC 2
  33. int checked_bin_buf = 0;
  34. static char *
  35. bin_checksum(const char *fname, int todo)
  36. {
  37. MD5_CTX ctx;
  38. static char hash[MD5_HASH_LENGTH + 1] = "";
  39. unsigned char md5out[MD5_HASH_LENGTH + 1] = "", buf[PREFIXLEN + 1] = "";
  40. FILE *f = NULL;
  41. size_t len = 0;
  42. MD5_Init(&ctx);
  43. checked_bin_buf++;
  44. hash[0] = 0;
  45. fixmod(fname);
  46. if (todo == GET_CHECKSUM) {
  47. if (!(f = fopen(fname, "rb")))
  48. werr(ERR_BINSTAT);
  49. while ((len = fread(buf, 1, sizeof buf - 1, f))) {
  50. if (!memcmp(buf, &settings.prefix, PREFIXLEN))
  51. break;
  52. MD5_Update(&ctx, buf, len);
  53. }
  54. fclose(f);
  55. f = NULL;
  56. MD5_Final(md5out, &ctx);
  57. strlcpy(hash, btoh(md5out, MD5_DIGEST_LENGTH), sizeof(hash));
  58. OPENSSL_cleanse(&ctx, sizeof(ctx));
  59. }
  60. if (todo == GET_CONF) {
  61. char *oldhash = strdup(settings.hash);
  62. if (!(f = fopen(fname, "rb")))
  63. werr(ERR_BINSTAT);
  64. while ((len = fread(buf, 1, sizeof buf - 1, f)))
  65. if (!memcmp(buf, &settings.prefix, PREFIXLEN))
  66. break;
  67. char *tmpbuf = (char *) my_calloc(1, SIZE_PACK);
  68. if ((len = fread(tmpbuf, 1, SIZE_PACK, f))) {
  69. edpack(&settings, oldhash, PACK_ENC);
  70. len = fread(&settings.bots, 1, SIZE_CONF, f);
  71. edpack(&settings, oldhash, PACK_DEC);
  72. } else
  73. return NULL;
  74. free(oldhash);
  75. fclose(f);
  76. return settings.hash;
  77. }
  78. if (todo & WRITE_CHECKSUM) {
  79. Tempfile *newbin = new Tempfile("bin");
  80. char *fname_bak = NULL;
  81. size_t size = 0, newpos = 0;
  82. size = strlen(fname) + 2;
  83. fname_bak = (char *) my_calloc(1, size);
  84. simple_snprintf(fname_bak, size, "%s~", fname);
  85. size = 0;
  86. if (!(f = fopen(fname, "rb")))
  87. goto fatal;
  88. fseek(f, 0, SEEK_END);
  89. size = ftell(f);
  90. fseek(f, 0, SEEK_SET);
  91. newpos = 0;
  92. while ((len = fread(buf, 1, sizeof(buf) - 1, f))) {
  93. if (fwrite(buf, 1, len, newbin->f) != len)
  94. goto fatal;
  95. newpos += len;
  96. if (!memcmp(buf, &settings.prefix, PREFIXLEN)) { /* found the settings struct! */
  97. MD5_Final(md5out, &ctx);
  98. strlcpy(hash, btoh(md5out, MD5_DIGEST_LENGTH), sizeof(hash));
  99. OPENSSL_cleanse(&ctx, sizeof(ctx));
  100. strlcpy(settings.hash, hash, 65);
  101. edpack(&settings, hash, PACK_ENC); /* encrypt the entire struct with the hash (including hash) */
  102. if (todo & WRITE_PACK) {
  103. fwrite(&settings.hash, SIZE_PACK, 1, newbin->f);
  104. sdprintf("writing pack: %d\n", SIZE_PACK);
  105. } else {
  106. char *tmpbuf = (char *) my_calloc(1, SIZE_PACK);
  107. if ((len = fread(tmpbuf, 1, SIZE_PACK, f))) {
  108. if (fwrite(tmpbuf, 1, len, newbin->f) != len) {
  109. free(tmpbuf);
  110. goto fatal;
  111. }
  112. }
  113. free(tmpbuf);
  114. }
  115. newpos += SIZE_PACK;
  116. if (todo & WRITE_CONF) {
  117. fwrite(&settings.bots, SIZE_CONF, 1, newbin->f);
  118. sdprintf("writing conf: %d\n", SIZE_CONF);
  119. } else {
  120. char *tmpbuf = (char *) my_calloc(1, SIZE_CONF);
  121. if ((len = fread(tmpbuf, 1, SIZE_CONF, f))) {
  122. if (fwrite(tmpbuf, 1, len, newbin->f) != len) {
  123. free(tmpbuf);
  124. goto fatal;
  125. }
  126. }
  127. free(tmpbuf);
  128. }
  129. newpos += SIZE_CONF;
  130. fseek(newbin->f, newpos + SIZE_PAD, SEEK_SET);
  131. newpos += SIZE_PAD;
  132. /* skip reading over the stuff we already wrote */
  133. fseek(f, newpos, SEEK_SET);
  134. } else if (!hash[0]) /* hash as long as we haven't reached the prefix */
  135. MD5_Update(&ctx, buf, len);
  136. }
  137. fclose(f);
  138. f = NULL;
  139. newbin->my_close();
  140. if (size != newpos) {
  141. delete newbin;
  142. fatal("Binary corrupted", 0);
  143. }
  144. if (movefile(fname, fname_bak)) {
  145. printf("Failed to move file (%s -> %s): %s\n", fname, fname_bak, strerror(errno));
  146. delete newbin;
  147. fatal("", 0);
  148. }
  149. if (movefile(newbin->file, fname)) {
  150. printf("Failed to move file (%s -> %s): %s\n", newbin->file, fname, strerror(errno));
  151. delete newbin;
  152. fatal("", 0);
  153. }
  154. fixmod(fname);
  155. unlink(fname_bak);
  156. delete newbin;
  157. return hash;
  158. fatal:
  159. if (f)
  160. fclose(f);
  161. delete newbin;
  162. werr(ERR_BINSTAT);
  163. }
  164. return hash;
  165. }
  166. static int
  167. features_find(const char *buffer)
  168. {
  169. if (!egg_strcasecmp(buffer, STR("no_take")))
  170. return FEATURE_NO_TAKE;
  171. else if (!egg_strcasecmp(buffer, STR("no_mdop")))
  172. return FEATURE_NO_MDOP;
  173. else if (!egg_strcasecmp(buffer, STR("beta")))
  174. return FEATURE_BETA;
  175. return 0;
  176. }
  177. static int
  178. readcfg(const char *cfgfile)
  179. {
  180. FILE *f = NULL;
  181. if ((f = fopen(cfgfile, "r")) == NULL) {
  182. printf("Error: Can't open '%s' for reading\n", cfgfile);
  183. exit(1);
  184. }
  185. char *buffer = NULL, *p = NULL;
  186. int skip = 0, line = 0, feature = 0;
  187. printf("Reading '%s' ", cfgfile);
  188. while ((!feof(f)) && ((buffer = step_thru_file(f)) != NULL)) {
  189. line++;
  190. if ((*buffer)) {
  191. if (strchr(buffer, '\n'))
  192. *(char *) strchr(buffer, '\n') = 0;
  193. if ((skipline(buffer, &skip)))
  194. continue;
  195. if (strchr(buffer, '<') || strchr(buffer, '>')) {
  196. printf(" Failed\n");
  197. printf("%s:%d: error: Look at your configuration file again...\n", cfgfile, line);
  198. // exit(1);
  199. }
  200. p = strchr(buffer, ' ');
  201. while (p && (strchr(LISTSEPERATORS, p[0])))
  202. *p++ = 0;
  203. if (p) {
  204. if (!egg_strcasecmp(buffer, "packname")) {
  205. strlcpy(settings.packname, trim(p), sizeof settings.packname);
  206. printf(".");
  207. } else if (!egg_strcasecmp(buffer, "shellhash")) {
  208. strlcpy(settings.shellhash, trim(p), sizeof settings.shellhash);
  209. printf(".");
  210. } else if (!egg_strcasecmp(buffer, "bdhash")) {
  211. strlcpy(settings.bdhash, trim(p), sizeof settings.bdhash);
  212. printf(".");
  213. } else if (!egg_strcasecmp(buffer, "dccprefix")) {
  214. strlcpy(settings.dcc_prefix, trim(p), sizeof settings.dcc_prefix);
  215. printf(".");
  216. } else if (!egg_strcasecmp(buffer, "owner")) {
  217. strcat(settings.owners, trim(p));
  218. strcat(settings.owners, ",");
  219. printf(".");
  220. } else if (!egg_strcasecmp(buffer, "owneremail")) {
  221. strcat(settings.owneremail, trim(p));
  222. strcat(settings.owneremail, ",");
  223. printf(".");
  224. } else if (!egg_strcasecmp(buffer, "hub")) {
  225. strcat(settings.hubs, trim(p));
  226. strcat(settings.hubs, ",");
  227. printf(".");
  228. } else if (!egg_strcasecmp(buffer, "salt1")) {
  229. strcat(settings.salt1, trim(p));
  230. printf(".");
  231. } else if (!egg_strcasecmp(buffer, "salt2")) {
  232. strcat(settings.salt2, trim(p));
  233. printf(".");
  234. } else {
  235. printf("%s %s\n", buffer, p);
  236. printf(",");
  237. }
  238. } else { /* SINGLE DIRECTIVES */
  239. if ((feature = features_find(buffer))) {
  240. int features = atol(settings.features);
  241. features |= feature;
  242. simple_snprintf(settings.features, sizeof(settings.features), "%d", features);
  243. printf(".");
  244. }
  245. }
  246. }
  247. buffer = NULL;
  248. }
  249. if (f)
  250. fclose(f);
  251. if (!settings.salt1[0] || !settings.salt2[0]) {
  252. /* Write salts back to the cfgfile */
  253. char salt1[SALT1LEN + 1] = "", salt2[SALT2LEN + 1] = "";
  254. printf("Creating Salts");
  255. if ((f = fopen(cfgfile, "a")) == NULL) {
  256. printf("Cannot open cfgfile for appending.. aborting\n");
  257. exit(1);
  258. }
  259. make_rand_str(salt1, SALT1LEN);
  260. make_rand_str(salt2, SALT2LEN);
  261. salt1[sizeof salt1] = salt2[sizeof salt2] = 0;
  262. fprintf(f, "SALT1 %s\n", salt1);
  263. fprintf(f, "SALT2 %s\n", salt2);
  264. fflush(f);
  265. fclose(f);
  266. }
  267. printf(" Success\n");
  268. return 1;
  269. }
  270. static void edpack(settings_t *incfg, const char *in_hash, int what)
  271. {
  272. char *tmp = NULL, *hash = (char *) in_hash, nhash[51] = "";
  273. unsigned char *(*enc_dec_string)(const char *, unsigned char *, size_t *);
  274. size_t len = 0;
  275. if (what == PACK_ENC)
  276. enc_dec_string = encrypt_binary;
  277. else
  278. enc_dec_string = decrypt_binary;
  279. #define dofield(_field) do { \
  280. if (_field) { \
  281. len = sizeof(_field) - 1; \
  282. tmp = (char *) enc_dec_string(hash, (unsigned char *) _field, &len); \
  283. if (what == PACK_ENC) \
  284. egg_memcpy(_field, tmp, len); \
  285. else \
  286. simple_snprintf(_field, sizeof(_field), "%s", tmp); \
  287. free(tmp); \
  288. } \
  289. } while (0)
  290. //FIXME: Maybe this should be done for EACH dofield(), ie, each entry changes the encryption for next line?
  291. //makes it harder to fuck with, then again, maybe current is fine?
  292. #define dohash(_field) do { \
  293. if (what == PACK_ENC) \
  294. simple_snprintf(nhash, sizeof(nhash), "%s%s", nhash[0] ? nhash : "", _field); \
  295. dofield(_field); \
  296. if (what == PACK_DEC) \
  297. simple_snprintf(nhash, sizeof(nhash), "%s%s", nhash[0] ? nhash : "", _field); \
  298. } while (0)
  299. #define update_hash() do { \
  300. hash = MD5(nhash); \
  301. OPENSSL_cleanse(nhash, sizeof(nhash)); \
  302. nhash[0] = 0; \
  303. } while (0)
  304. /* -- STATIC -- */
  305. dohash(incfg->hash);
  306. dohash(incfg->packname);
  307. update_hash();
  308. dohash(incfg->shellhash);
  309. dohash(incfg->bdhash);
  310. update_hash();
  311. dofield(incfg->dcc_prefix);
  312. dofield(incfg->features);
  313. dofield(incfg->owners);
  314. dofield(incfg->owneremail);
  315. dofield(incfg->hubs);
  316. dohash(incfg->salt1);
  317. dohash(incfg->salt2);
  318. update_hash();
  319. /* -- DYNAMIC -- */
  320. dofield(incfg->bots);
  321. dofield(incfg->uid);
  322. dofield(incfg->autouname);
  323. dofield(incfg->pscloak);
  324. dofield(incfg->autocron);
  325. dofield(incfg->watcher);
  326. dofield(incfg->uname);
  327. dofield(incfg->username);
  328. dofield(incfg->datadir);
  329. dofield(incfg->homedir);
  330. dofield(incfg->binpath);
  331. dofield(incfg->binname);
  332. dofield(incfg->portmin);
  333. dofield(incfg->portmax);
  334. OPENSSL_cleanse(nhash, sizeof(nhash));
  335. #undef dofield
  336. #undef dohash
  337. #undef update_hash
  338. }
  339. #ifdef DEBUG
  340. static void
  341. tellconfig(settings_t *incfg)
  342. {
  343. #define dofield(_field) printf("%s: %s\n", #_field, _field);
  344. // -- STATIC --
  345. dofield(incfg->hash);
  346. dofield(incfg->packname);
  347. dofield(incfg->shellhash);
  348. dofield(incfg->bdhash);
  349. dofield(incfg->dcc_prefix);
  350. dofield(incfg->features);
  351. dofield(incfg->owners);
  352. dofield(incfg->owneremail);
  353. dofield(incfg->hubs);
  354. dofield(incfg->salt1);
  355. dofield(incfg->salt2);
  356. // -- DYNAMIC --
  357. dofield(incfg->bots);
  358. dofield(incfg->uid);
  359. dofield(incfg->autouname);
  360. dofield(incfg->pscloak);
  361. dofield(incfg->autocron);
  362. dofield(incfg->watcher);
  363. dofield(incfg->uname);
  364. dofield(incfg->username);
  365. dofield(incfg->datadir);
  366. dofield(incfg->homedir);
  367. dofield(incfg->binpath);
  368. dofield(incfg->binname);
  369. dofield(incfg->portmin);
  370. dofield(incfg->portmax);
  371. #undef dofield
  372. }
  373. #endif
  374. void
  375. check_sum(const char *fname, const char *cfgfile)
  376. {
  377. if (!settings.hash[0]) {
  378. if (!cfgfile)
  379. fatal("Binary not initialized.", 0);
  380. readcfg(cfgfile);
  381. // tellconfig(&settings);
  382. if (bin_checksum(fname, WRITE_CHECKSUM|WRITE_CONF|WRITE_PACK))
  383. printf("* Wrote settings to binary.\n");
  384. exit(0);
  385. } else {
  386. char *hash = bin_checksum(fname, GET_CHECKSUM);
  387. // tellconfig(&settings);
  388. edpack(&settings, hash, PACK_DEC);
  389. #ifdef DEBUG
  390. tellconfig(&settings);
  391. #endif
  392. if (strcmp(settings.hash, hash)) {
  393. unlink(fname);
  394. fatal("!! Invalid binary", 0);
  395. }
  396. }
  397. }
  398. static bool check_bin_initialized(const char *fname)
  399. {
  400. int i = 0;
  401. size_t len = strlen(shell_escape(fname)) + 3 + 1;
  402. char *path = (char *) my_calloc(1, len);
  403. simple_snprintf(path, len, "%s -p", shell_escape(fname));
  404. i = system(path);
  405. free(path);
  406. if (i != -1 && WEXITSTATUS(i) == 4)
  407. return 1;
  408. return 0;
  409. }
  410. void write_settings(const char *fname, int die, bool conf)
  411. {
  412. char *hash = NULL;
  413. int bits = WRITE_CHECKSUM;
  414. /* see if the binary is already initialized or not */
  415. bool initialized = check_bin_initialized(fname);
  416. /* only write pack data if the binary is uninitialized
  417. * otherwise, assume it has similar/correct/updated pack data
  418. */
  419. if (!initialized)
  420. bits |= WRITE_PACK;
  421. if (conf)
  422. bits |= WRITE_CONF;
  423. /* only bother writing anything if we have pack or conf, checksum is worthless to write out */
  424. if (bits & (WRITE_PACK|WRITE_CONF)) {
  425. if ((hash = bin_checksum(fname, bits))) {
  426. printf("* Wrote %ssettings to: %s.\n", ((bits & WRITE_PACK) && !(bits & WRITE_CONF)) ? "pack " :
  427. ((bits & WRITE_CONF) && !(bits & WRITE_PACK)) ? "conf " :
  428. ((bits & WRITE_PACK) && (bits & WRITE_CONF)) ? "pack/conf " :
  429. "",
  430. fname);
  431. if (die == -1) /* only bother decrypting if we aren't about to exit */
  432. edpack(&settings, hash, PACK_DEC);
  433. }
  434. }
  435. if (die >= 0)
  436. exit(die);
  437. }
  438. static void
  439. clear_settings(void)
  440. {
  441. // egg_memset(&settings.bots, 0, sizeof(settings_t) - SIZE_PACK - PREFIXLEN);
  442. egg_memset(&settings.bots, 0, SIZE_CONF);
  443. }
  444. void conf_to_bin(conf_t *in, bool move, int die)
  445. {
  446. conf_bot *bot = NULL;
  447. char *newbin = NULL;
  448. clear_settings();
  449. sdprintf("converting conf to bin\n");
  450. simple_sprintf(settings.uid, "%d", in->uid);
  451. simple_sprintf(settings.watcher, "%d", in->watcher);
  452. simple_sprintf(settings.autocron, "%d", in->autocron);
  453. simple_sprintf(settings.autouname, "%d", in->autouname);
  454. simple_sprintf(settings.portmin, "%d", in->portmin);
  455. simple_sprintf(settings.portmax, "%d", in->portmax);
  456. simple_sprintf(settings.pscloak, "%d", in->pscloak);
  457. strlcpy(settings.binname, in->binname, sizeof(settings.binname));
  458. if (in->username)
  459. strlcpy(settings.username, in->username, sizeof(settings.username));
  460. if (in->uname)
  461. strlcpy(settings.uname, in->uname, sizeof(settings.uname));
  462. strlcpy(settings.datadir, in->datadir, sizeof(settings.datadir));
  463. if (in->homedir)
  464. strlcpy(settings.homedir, in->homedir, sizeof(settings.homedir));
  465. strlcpy(settings.binpath, in->binpath, sizeof(settings.binpath));
  466. for (bot = in->bots; bot && bot->nick; bot = bot->next) {
  467. simple_snprintf(settings.bots, sizeof(settings.bots), "%s%s%s %s %s%s %s,",
  468. settings.bots && settings.bots[0] ? settings.bots : "",
  469. bot->disabled ? "/" : "",
  470. bot->nick,
  471. bot->net.ip ? bot->net.ip : ".",
  472. bot->net.host6 ? "+" : "",
  473. bot->net.host ? bot->net.host : (bot->net.host6 ? bot->net.host6 : "."),
  474. bot->net.ip6 ? bot->net.ip6 : "");
  475. }
  476. #ifndef CYGWIN_HACKS
  477. if (move)
  478. newbin = move_bin(in->binpath, in->binname, 0);
  479. else
  480. #endif /* !CYGWIN_HACKS */
  481. newbin = binname;
  482. // tellconfig(&settings);
  483. write_settings(newbin, -1, 1);
  484. if (die >= 0)
  485. exit(die);
  486. }
  487. void reload_bin_data() {
  488. if (bin_checksum(binname, GET_CONF)) {
  489. putlog(LOG_MISC, "*", "Rehashed config data from binary.");
  490. conf_bot *oldbots = NULL, *oldbot = NULL;
  491. bool was_localhub = conf.bot->localhub ? 1 : 0;
  492. /* save the old bots list */
  493. if (conf.bots)
  494. oldbots = conf_bots_dup(conf.bots);
  495. /* Save the old conf.bot */
  496. oldbot = (conf_bot *) my_calloc(1, sizeof(conf_bot));
  497. conf_bot_dup(oldbot, conf.bot);
  498. /* free up our current conf struct */
  499. free_conf();
  500. /* Fill conf[] with binary data from settings[] */
  501. bin_to_conf();
  502. /* fill up conf.bot using origbotname */
  503. fill_conf_bot(0); /* 0 to avoid exiting if conf.bot cannot be filled */
  504. if (was_localhub) {
  505. /* add any new bots not in userfile */
  506. conf_add_userlist_bots();
  507. /* deluser removed bots from conf */
  508. if (oldbots)
  509. deluser_removed_bots(oldbots, conf.bots);
  510. #ifdef this_is_handled_by_confedit_now
  511. /* no longer the localhub (or removed), need to alert the new one to rehash (or start it) */
  512. if (!conf.bot || !conf.bot->localhub) {
  513. conf_bot *localhub = conf_getlocalhub(conf.bots);
  514. /* then SIGHUP new localhub or spawn new localhub */
  515. if (localhub) {
  516. /* Check for pid again - may be using fork-interval */
  517. localhub->pid = checkpid(localhub->nick, localhub, NULL);
  518. if (localhub->pid)
  519. conf_killbot(NULL, localhub, SIGHUP); //restart the new localhub
  520. /* else
  521. start new localhub - done below in spawnbots() */
  522. }
  523. }
  524. /* start/disable new bots as necesary */
  525. conf_checkpids(conf.bots);
  526. spawnbots(1); //1 signifies to not start me!
  527. #endif
  528. }
  529. if (conf.bot && conf.bot->disabled) {
  530. if (tands > 0) {
  531. botnet_send_chat(-1, conf.bot->nick, "Bot disabled in binary.");
  532. botnet_send_bye("Bot disabled in binary.");
  533. }
  534. if (server_online)
  535. nuke_server("bbl");
  536. werr(ERR_BOTDISABLED);
  537. } else if (!conf.bot) {
  538. conf.bot = oldbot;
  539. if (tands > 0) {
  540. botnet_send_chat(-1, conf.bot->nick, "Bot removed from binary.");
  541. botnet_send_bye("Bot removed from binary.");
  542. }
  543. if (server_online)
  544. nuke_server("it's been good, cya");
  545. werr(ERR_BADBOT);
  546. }
  547. /* The bot nick changed! (case) */
  548. if (strcmp(conf.bot->nick, oldbot->nick)) {
  549. change_handle(conf.bot->u, conf.bot->nick);
  550. // var_set_by_name(conf.bot->nick, "nick", conf.bot->nick);
  551. // var_set_userentry(conf.bot->nick, "nick", conf.bot->nick);
  552. }
  553. free_bot(oldbot);
  554. if (oldbots)
  555. free_conf_bots(oldbots);
  556. if (!conf.bot->localhub)
  557. free_conf_bots(conf.bots);
  558. }
  559. }