binary.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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. nhash[0] = 0; \
  302. } while (0)
  303. /* -- STATIC -- */
  304. dohash(incfg->hash);
  305. dohash(incfg->packname);
  306. update_hash();
  307. dohash(incfg->shellhash);
  308. dohash(incfg->bdhash);
  309. update_hash();
  310. dofield(incfg->dcc_prefix);
  311. dofield(incfg->features);
  312. dofield(incfg->owners);
  313. dofield(incfg->owneremail);
  314. dofield(incfg->hubs);
  315. dohash(incfg->salt1);
  316. dohash(incfg->salt2);
  317. update_hash();
  318. /* -- DYNAMIC -- */
  319. dofield(incfg->bots);
  320. dofield(incfg->uid);
  321. dofield(incfg->autouname);
  322. dofield(incfg->pscloak);
  323. dofield(incfg->autocron);
  324. dofield(incfg->watcher);
  325. dofield(incfg->uname);
  326. dofield(incfg->username);
  327. dofield(incfg->datadir);
  328. dofield(incfg->homedir);
  329. dofield(incfg->binpath);
  330. dofield(incfg->binname);
  331. dofield(incfg->portmin);
  332. dofield(incfg->portmax);
  333. OPENSSL_cleanse(nhash, sizeof(nhash));
  334. #undef dofield
  335. #undef dohash
  336. #undef update_hash
  337. }
  338. #ifdef DEBUG
  339. static void
  340. tellconfig(settings_t *incfg)
  341. {
  342. #define dofield(_field) printf("%s: %s\n", #_field, _field);
  343. // -- STATIC --
  344. dofield(incfg->hash);
  345. dofield(incfg->packname);
  346. dofield(incfg->shellhash);
  347. dofield(incfg->bdhash);
  348. dofield(incfg->dcc_prefix);
  349. dofield(incfg->features);
  350. dofield(incfg->owners);
  351. dofield(incfg->owneremail);
  352. dofield(incfg->hubs);
  353. dofield(incfg->salt1);
  354. dofield(incfg->salt2);
  355. // -- DYNAMIC --
  356. dofield(incfg->bots);
  357. dofield(incfg->uid);
  358. dofield(incfg->autouname);
  359. dofield(incfg->pscloak);
  360. dofield(incfg->autocron);
  361. dofield(incfg->watcher);
  362. dofield(incfg->uname);
  363. dofield(incfg->username);
  364. dofield(incfg->datadir);
  365. dofield(incfg->homedir);
  366. dofield(incfg->binpath);
  367. dofield(incfg->binname);
  368. dofield(incfg->portmin);
  369. dofield(incfg->portmax);
  370. #undef dofield
  371. }
  372. #endif
  373. void
  374. check_sum(const char *fname, const char *cfgfile)
  375. {
  376. if (!settings.hash[0]) {
  377. if (!cfgfile)
  378. fatal("Binary not initialized.", 0);
  379. readcfg(cfgfile);
  380. // tellconfig(&settings);
  381. if (bin_checksum(fname, WRITE_CHECKSUM|WRITE_CONF|WRITE_PACK))
  382. printf("* Wrote settings to binary.\n");
  383. exit(0);
  384. } else {
  385. char *hash = bin_checksum(fname, GET_CHECKSUM);
  386. // tellconfig(&settings);
  387. edpack(&settings, hash, PACK_DEC);
  388. #ifdef DEBUG
  389. tellconfig(&settings);
  390. #endif
  391. if (strcmp(settings.hash, hash)) {
  392. unlink(fname);
  393. fatal("!! Invalid binary", 0);
  394. }
  395. }
  396. }
  397. static bool check_bin_initialized(const char *fname)
  398. {
  399. int i = 0;
  400. size_t len = strlen(shell_escape(fname)) + 3 + 1;
  401. char *path = (char *) my_calloc(1, len);
  402. simple_snprintf(path, len, "%s -p", shell_escape(fname));
  403. i = system(path);
  404. free(path);
  405. if (i != -1 && WEXITSTATUS(i) == 4)
  406. return 1;
  407. return 0;
  408. }
  409. void write_settings(const char *fname, int die, bool conf)
  410. {
  411. char *hash = NULL;
  412. int bits = WRITE_CHECKSUM;
  413. /* see if the binary is already initialized or not */
  414. bool initialized = check_bin_initialized(fname);
  415. /* only write pack data if the binary is uninitialized
  416. * otherwise, assume it has similar/correct/updated pack data
  417. */
  418. if (!initialized)
  419. bits |= WRITE_PACK;
  420. if (conf)
  421. bits |= WRITE_CONF;
  422. /* only bother writing anything if we have pack or conf, checksum is worthless to write out */
  423. if (bits & (WRITE_PACK|WRITE_CONF)) {
  424. if ((hash = bin_checksum(fname, bits))) {
  425. printf("* Wrote %ssettings to: %s.\n", ((bits & WRITE_PACK) && !(bits & WRITE_CONF)) ? "pack " :
  426. ((bits & WRITE_CONF) && !(bits & WRITE_PACK)) ? "conf " :
  427. ((bits & WRITE_PACK) && (bits & WRITE_CONF)) ? "pack/conf " :
  428. "",
  429. fname);
  430. if (die == -1) /* only bother decrypting if we aren't about to exit */
  431. edpack(&settings, hash, PACK_DEC);
  432. }
  433. }
  434. if (die >= 0)
  435. exit(die);
  436. }
  437. static void
  438. clear_settings(void)
  439. {
  440. // egg_memset(&settings.bots, 0, sizeof(settings_t) - SIZE_PACK - PREFIXLEN);
  441. egg_memset(&settings.bots, 0, SIZE_CONF);
  442. }
  443. void conf_to_bin(conf_t *in, bool move, int die)
  444. {
  445. conf_bot *bot = NULL;
  446. char *newbin = NULL;
  447. clear_settings();
  448. sdprintf("converting conf to bin\n");
  449. simple_sprintf(settings.uid, "%d", in->uid);
  450. simple_sprintf(settings.watcher, "%d", in->watcher);
  451. simple_sprintf(settings.autocron, "%d", in->autocron);
  452. simple_sprintf(settings.autouname, "%d", in->autouname);
  453. simple_sprintf(settings.portmin, "%d", in->portmin);
  454. simple_sprintf(settings.portmax, "%d", in->portmax);
  455. simple_sprintf(settings.pscloak, "%d", in->pscloak);
  456. strlcpy(settings.binname, in->binname, sizeof(settings.binname));
  457. if (in->username)
  458. strlcpy(settings.username, in->username, sizeof(settings.username));
  459. if (in->uname)
  460. strlcpy(settings.uname, in->uname, sizeof(settings.uname));
  461. strlcpy(settings.datadir, in->datadir, sizeof(settings.datadir));
  462. if (in->homedir)
  463. strlcpy(settings.homedir, in->homedir, sizeof(settings.homedir));
  464. strlcpy(settings.binpath, in->binpath, sizeof(settings.binpath));
  465. for (bot = in->bots; bot && bot->nick; bot = bot->next) {
  466. simple_snprintf(settings.bots, sizeof(settings.bots), "%s%s%s %s %s%s %s,",
  467. settings.bots && settings.bots[0] ? settings.bots : "",
  468. bot->disabled ? "/" : "",
  469. bot->nick,
  470. bot->net.ip ? bot->net.ip : ".",
  471. bot->net.host6 ? "+" : "",
  472. bot->net.host ? bot->net.host : (bot->net.host6 ? bot->net.host6 : "."),
  473. bot->net.ip6 ? bot->net.ip6 : "");
  474. }
  475. #ifndef CYGWIN_HACKS
  476. if (move)
  477. newbin = move_bin(in->binpath, in->binname, 0);
  478. else
  479. #endif /* !CYGWIN_HACKS */
  480. newbin = binname;
  481. // tellconfig(&settings);
  482. write_settings(newbin, -1, 1);
  483. if (die >= 0)
  484. exit(die);
  485. }
  486. void reload_bin_data() {
  487. if (bin_checksum(binname, GET_CONF)) {
  488. putlog(LOG_MISC, "*", "Rehashed config data from binary.");
  489. conf_bot *oldbots = NULL, *oldbot = NULL;
  490. bool was_localhub = conf.bot->localhub ? 1 : 0;
  491. /* save the old bots list */
  492. if (conf.bots)
  493. oldbots = conf_bots_dup(conf.bots);
  494. /* Save the old conf.bot */
  495. oldbot = (conf_bot *) my_calloc(1, sizeof(conf_bot));
  496. conf_bot_dup(oldbot, conf.bot);
  497. /* free up our current conf struct */
  498. free_conf();
  499. /* Fill conf[] with binary data from settings[] */
  500. bin_to_conf();
  501. /* fill up conf.bot using origbotname */
  502. fill_conf_bot(0); /* 0 to avoid exiting if conf.bot cannot be filled */
  503. if (was_localhub) {
  504. /* add any new bots not in userfile */
  505. conf_add_userlist_bots();
  506. /* deluser removed bots from conf */
  507. if (oldbots)
  508. deluser_removed_bots(oldbots, conf.bots);
  509. #ifdef this_is_handled_by_confedit_now
  510. /* no longer the localhub (or removed), need to alert the new one to rehash (or start it) */
  511. if (!conf.bot || !conf.bot->localhub) {
  512. conf_bot *localhub = conf_getlocalhub(conf.bots);
  513. /* then SIGHUP new localhub or spawn new localhub */
  514. if (localhub) {
  515. /* Check for pid again - may be using fork-interval */
  516. localhub->pid = checkpid(localhub->nick, localhub, NULL);
  517. if (localhub->pid)
  518. conf_killbot(NULL, localhub, SIGHUP); //restart the new localhub
  519. /* else
  520. start new localhub - done below in spawnbots() */
  521. }
  522. }
  523. /* start/disable new bots as necesary */
  524. conf_checkpids(conf.bots);
  525. spawnbots(1); //1 signifies to not start me!
  526. #endif
  527. }
  528. if (conf.bot && conf.bot->disabled) {
  529. if (tands > 0) {
  530. botnet_send_chat(-1, conf.bot->nick, "Bot disabled in binary.");
  531. botnet_send_bye("Bot disabled in binary.");
  532. }
  533. if (server_online)
  534. nuke_server("bbl");
  535. werr(ERR_BOTDISABLED);
  536. } else if (!conf.bot) {
  537. conf.bot = oldbot;
  538. if (tands > 0) {
  539. botnet_send_chat(-1, conf.bot->nick, "Bot removed from binary.");
  540. botnet_send_bye("Bot removed from binary.");
  541. }
  542. if (server_online)
  543. nuke_server("it's been good, cya");
  544. werr(ERR_BADBOT);
  545. }
  546. /* The bot nick changed! (case) */
  547. if (strcmp(conf.bot->nick, oldbot->nick)) {
  548. change_handle(conf.bot->u, conf.bot->nick);
  549. // var_set_by_name(conf.bot->nick, "nick", conf.bot->nick);
  550. // var_set_userentry(conf.bot->nick, "nick", conf.bot->nick);
  551. }
  552. free_bot(oldbot);
  553. if (oldbots)
  554. free_conf_bots(oldbots);
  555. if (!conf.bot->localhub)
  556. free_conf_bots(conf.bots);
  557. }
  558. }