misc.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896
  1. /*
  2. * misc.c -- handles:
  3. * split() maskhost() dumplots() daysago() days() daysdur()
  4. * queueing output for the bot (msg and help)
  5. * resync buffers for sharebots
  6. * motd display and %var substitution
  7. *
  8. */
  9. #include "main.h"
  10. #include <sys/stat.h>
  11. #include <sys/types.h>
  12. #include <sys/wait.h>
  13. #include <unistd.h>
  14. #include <fcntl.h>
  15. #include "chan.h"
  16. #include "tandem.h"
  17. #include "modules.h"
  18. #include <pwd.h>
  19. #include <errno.h>
  20. #ifdef S_ANTITRACE
  21. #include <sys/ptrace.h>
  22. #include <sys/wait.h>
  23. #endif /* S_ANTITRACE */
  24. #include <net/if.h>
  25. #include <sys/ioctl.h>
  26. #include <sys/socket.h>
  27. #include <signal.h>
  28. #ifdef HAVE_UNAME
  29. # include <sys/utsname.h>
  30. #endif /* HAVE_UNAME */
  31. #include "stat.h"
  32. #include "bg.h"
  33. extern struct userrec *userlist;
  34. extern struct dcc_t *dcc;
  35. extern struct chanset_t *chanset;
  36. extern tand_t *tandbot;
  37. extern char version[], origbotname[], botname[],
  38. admin[], network[], motdfile[], ver[], botnetnick[],
  39. bannerfile[], textdir[], userfile[],
  40. *binname, pid_file[], *netpass, tempdir[];
  41. extern int backgrd, con_chan, term_z, use_stderr, dcc_total, timesync, sdebug,
  42. #ifdef HUB
  43. my_port,
  44. #endif
  45. strict_host, loading,
  46. localhub;
  47. extern time_t now;
  48. extern Tcl_Interp *interp;
  49. extern struct cfg_entry CFG_MOTD, CFG_LOGIN, CFG_BADPROCESS, CFG_PROCESSLIST,
  50. CFG_PROMISC, CFG_TRACE, CFG_HIJACK;
  51. void detected(int, char *);
  52. int shtime = 1; /* Whether or not to display the time
  53. with console output */
  54. int conmask = LOG_MODES | LOG_CMDS | LOG_MISC; /* Console mask */
  55. int debug_output = 1; /* Disply output to server to LOG_SERVEROUT */
  56. /* Expected memory usage
  57. */
  58. int expmem_misc()
  59. {
  60. int tot = 0;
  61. tot += strlen(binname) + 1;
  62. return tot;
  63. }
  64. void init_misc()
  65. {
  66. }
  67. /*
  68. * Misc functions
  69. */
  70. /* low-level stuff for other modules
  71. */
  72. /* This implementation wont overrun dst - 'max' is the max bytes that dst
  73. * can be, including the null terminator. So if 'dst' is a 128 byte buffer,
  74. * pass 128 as 'max'. The function will _always_ null-terminate 'dst'.
  75. *
  76. * Returns: The number of characters appended to 'dst'.
  77. *
  78. * Usage eg.
  79. *
  80. * char buf[128];
  81. * size_t bufsize = sizeof(buf);
  82. *
  83. * buf[0] = 0, bufsize--;
  84. *
  85. * while (blah && bufsize) {
  86. * bufsize -= egg_strcatn(buf, <some-long-string>, sizeof(buf));
  87. * }
  88. *
  89. * <Cybah>
  90. */
  91. int egg_strcatn(char *dst, const char *src, size_t max)
  92. {
  93. size_t tmpmax = 0;
  94. /* find end of 'dst' */
  95. while (*dst && max > 0) {
  96. dst++;
  97. max--;
  98. }
  99. /* Store 'max', so we can use it to workout how many characters were
  100. * written later on.
  101. */
  102. tmpmax = max;
  103. /* copy upto, but not including the null terminator */
  104. while (*src && max > 1) {
  105. *dst++ = *src++;
  106. max--;
  107. }
  108. /* null-terminate the buffer */
  109. *dst = 0;
  110. /* Don't include the terminating null in our count, as it will cumulate
  111. * in loops - causing a headache for the caller.
  112. */
  113. return tmpmax - max;
  114. }
  115. int my_strcpy(register char *a, register char *b)
  116. {
  117. register char *c = b;
  118. while (*b)
  119. *a++ = *b++;
  120. *a = *b;
  121. return b - c;
  122. }
  123. /* Split first word off of rest and put it in first
  124. */
  125. void splitc(char *first, char *rest, char divider)
  126. {
  127. char *p = strchr(rest, divider);
  128. if (p == NULL) {
  129. if (first != rest && first)
  130. first[0] = 0;
  131. return;
  132. }
  133. *p = 0;
  134. if (first != NULL)
  135. strcpy(first, rest);
  136. if (first != rest)
  137. /* In most circumstances, strcpy with src and dst being the same buffer
  138. * can produce undefined results. We're safe here, as the src is
  139. * guaranteed to be at least 2 bytes higher in memory than dest. <Cybah>
  140. */
  141. strcpy(rest, p + 1);
  142. }
  143. /* As above, but lets you specify the 'max' number of bytes (EXCLUDING the
  144. * terminating null).
  145. *
  146. * Example of use:
  147. *
  148. * char buf[HANDLEN + 1];
  149. *
  150. * splitcn(buf, input, "@", HANDLEN);
  151. *
  152. * <Cybah>
  153. */
  154. void splitcn(char *first, char *rest, char divider, size_t max)
  155. {
  156. char *p = strchr(rest, divider);
  157. if (p == NULL) {
  158. if (first != rest && first)
  159. first[0] = 0;
  160. return;
  161. }
  162. *p = 0;
  163. if (first != NULL)
  164. strncpyz(first, rest, max);
  165. if (first != rest)
  166. /* In most circumstances, strcpy with src and dst being the same buffer
  167. * can produce undefined results. We're safe here, as the src is
  168. * guaranteed to be at least 2 bytes higher in memory than dest. <Cybah>
  169. */
  170. strcpy(rest, p + 1);
  171. }
  172. char *splitnick(char **blah)
  173. {
  174. char *p = strchr(*blah, '!'), *q = *blah;
  175. if (p) {
  176. *p = 0;
  177. *blah = p + 1;
  178. return q;
  179. }
  180. return "";
  181. }
  182. char *newsplit(char **rest)
  183. {
  184. register char *o, *r;
  185. if (!rest)
  186. return *rest = "";
  187. o = *rest;
  188. while (*o == ' ')
  189. o++;
  190. r = o;
  191. while (*o && (*o != ' '))
  192. o++;
  193. if (*o)
  194. *o++ = 0;
  195. *rest = o;
  196. return r;
  197. }
  198. /* Convert "abc!user@a.b.host" into "*!user@*.b.host"
  199. * or "abc!user@1.2.3.4" into "*!user@1.2.3.*"
  200. * or "abc!user@0:0:0:0:0:ffff:1.2.3.4" into "*!user@0:0:0:0:0:ffff:1.2.3.*"
  201. * or "abc!user@3ffe:604:2:b02e:6174:7265:6964:6573" into
  202. * "*!user@3ffe:604:2:b02e:6174:7265:6964:*"
  203. */
  204. void maskhost(const char *s, char *nw)
  205. {
  206. register const char *p, *q, *e, *f;
  207. int i;
  208. *nw++ = '*';
  209. *nw++ = '!';
  210. p = (q = strchr(s, '!')) ? q + 1 : s;
  211. /* Strip of any nick, if a username is found, use last 8 chars */
  212. if ((q = strchr(p, '@'))) {
  213. int fl = 0;
  214. if ((q - p) > 9) {
  215. nw[0] = '*';
  216. p = q - 7;
  217. i = 1;
  218. } else
  219. i = 0;
  220. while (*p != '@') {
  221. if (!fl && strchr("~+-^=", *p)) {
  222. if (strict_host)
  223. nw[i] = '?';
  224. else
  225. i--;
  226. } else
  227. nw[i] = *p;
  228. fl++;
  229. p++;
  230. i++;
  231. }
  232. nw[i++] = '@';
  233. q++;
  234. } else {
  235. nw[0] = '*';
  236. nw[1] = '@';
  237. i = 2;
  238. q = s;
  239. }
  240. nw += i;
  241. e = NULL;
  242. /* Now q points to the hostname, i point to where to put the mask */
  243. if ((!(p = strchr(q, '.')) || !(e = strchr(p + 1, '.'))) && !strchr(q, ':'))
  244. /* TLD or 2 part host */
  245. strcpy(nw, q);
  246. else {
  247. if (e == NULL) { /* IPv6 address? */
  248. const char *mask_str;
  249. f = strrchr(q, ':');
  250. if (strchr(f, '.')) { /* IPv4 wrapped in an IPv6? */
  251. f = strrchr(f, '.');
  252. mask_str = ".*";
  253. } else /* ... no, true IPv6. */
  254. mask_str = ":*";
  255. strncpy(nw, q, f - q);
  256. /* No need to nw[f-q] = 0 here, as the strcpy below will
  257. * terminate the string for us.
  258. */
  259. nw += (f - q);
  260. strcpy(nw, mask_str);
  261. } else {
  262. for (f = e; *f; f++);
  263. f--;
  264. if (*f >= '0' && *f <= '9') { /* Numeric IP address */
  265. while (*f != '.')
  266. f--;
  267. strncpy(nw, q, f - q);
  268. /* No need to nw[f-q] = 0 here, as the strcpy below will
  269. * terminate the string for us.
  270. */
  271. nw += (f - q);
  272. strcpy(nw, ".*");
  273. } else { /* Normal host >= 3 parts */
  274. /* a.b.c -> *.b.c
  275. * a.b.c.d -> *.b.c.d if tld is a country (2 chars)
  276. * OR *.c.d if tld is com/edu/etc (3 chars)
  277. * a.b.c.d.e -> *.c.d.e etc
  278. */
  279. const char *x = strchr(e + 1, '.');
  280. if (!x)
  281. x = p;
  282. else if (strchr(x + 1, '.'))
  283. x = e;
  284. else if (strlen(x) == 3)
  285. x = p;
  286. else
  287. x = e;
  288. sprintf(nw, "*%s", x);
  289. }
  290. }
  291. }
  292. }
  293. /* Dump a potentially super-long string of text.
  294. */
  295. void dumplots(int idx, const char *prefix, char *data)
  296. {
  297. char *p = data, *q, *n, c;
  298. const int max_data_len = 500 - strlen(prefix);
  299. if (!*data) {
  300. dprintf(idx, "%s\n", prefix);
  301. return;
  302. }
  303. while (strlen(p) > max_data_len) {
  304. q = p + max_data_len;
  305. /* Search for embedded linefeed first */
  306. n = strchr(p, '\n');
  307. if (n && n < q) {
  308. /* Great! dump that first line then start over */
  309. *n = 0;
  310. dprintf(idx, "%s%s\n", prefix, p);
  311. *n = '\n';
  312. p = n + 1;
  313. } else {
  314. /* Search backwards for the last space */
  315. while (*q != ' ' && q != p)
  316. q--;
  317. if (q == p)
  318. q = p + max_data_len;
  319. c = *q;
  320. *q = 0;
  321. dprintf(idx, "%s%s\n", prefix, p);
  322. *q = c;
  323. p = q;
  324. if (c == ' ')
  325. p++;
  326. }
  327. }
  328. /* Last trailing bit: split by linefeeds if possible */
  329. n = strchr(p, '\n');
  330. while (n) {
  331. *n = 0;
  332. dprintf(idx, "%s%s\n", prefix, p);
  333. *n = '\n';
  334. p = n + 1;
  335. n = strchr(p, '\n');
  336. }
  337. if (*p)
  338. dprintf(idx, "%s%s\n", prefix, p); /* Last trailing bit */
  339. }
  340. /* Convert an interval (in seconds) to one of:
  341. * "19 days ago", "1 day ago", "18:12"
  342. */
  343. void daysago(time_t now, time_t then, char *out)
  344. {
  345. if (now - then > 86400) {
  346. int days = (now - then) / 86400;
  347. sprintf(out, "%d day%s ago", days, (days == 1) ? "" : "s");
  348. return;
  349. }
  350. egg_strftime(out, 6, "%H:%M", localtime(&then));
  351. }
  352. /* Convert an interval (in seconds) to one of:
  353. * "in 19 days", "in 1 day", "at 18:12"
  354. */
  355. void days(time_t now, time_t then, char *out)
  356. {
  357. if (now - then > 86400) {
  358. int days = (now - then) / 86400;
  359. sprintf(out, "in %d day%s", days, (days == 1) ? "" : "s");
  360. return;
  361. }
  362. egg_strftime(out, 9, "at %H:%M", localtime(&now));
  363. }
  364. /* Convert an interval (in seconds) to one of:
  365. * "for 19 days", "for 1 day", "for 09:10"
  366. */
  367. void daysdur(time_t now, time_t then, char *out)
  368. {
  369. char s[81];
  370. int hrs, mins;
  371. if (now - then > 86400) {
  372. int days = (now - then) / 86400;
  373. sprintf(out, "for %d day%s", days, (days == 1) ? "" : "s");
  374. return;
  375. }
  376. strcpy(out, "for ");
  377. now -= then;
  378. hrs = (int) (now / 3600);
  379. mins = (int) ((now - (hrs * 3600)) / 60);
  380. sprintf(s, "%02d:%02d", hrs, mins);
  381. strcat(out, s);
  382. }
  383. /* show l33t banner */
  384. char *wbanner() {
  385. int r;
  386. r = random();
  387. switch (r % 7) {
  388. case 0: return STR(" .__ __ .__\n__ _ ______________ |__|/ |_| |__\n\\ \\/ \\/ /\\_ __ \\__ \\ | \\ __\\ | \\\n \\ / | | \\// __ \\| || | | Y \\\n \\/\\_/ |__| (____ /__||__| |___| /\n \\/ \\/\n");
  389. case 1: return STR(" _ _ _ \n__ ___ __ __ _(_) |_| |__ \n\\ \\ /\\ / / '__/ _` | | __| '_ \\ \n \\ V V /| | | (_| | | |_| | | |\n \\_/\\_/ |_| \\__,_|_|\\__|_| |_|\n");
  390. case 2: return STR("@@@ @@@ @@@ @@@@@@@ @@@@@@ @@@ @@@@@@@ @@@ @@@\n@@@ @@@ @@@ @@@@@@@@ @@@@@@@@ @@@ @@@@@@@ @@@ @@@\n@@! @@! @@! @@! @@@ @@! @@@ @@! @@! @@! @@@\n!@! !@! !@! !@! @!@ !@! @!@ !@! !@! !@! @!@\n@!! !!@ @!@ @!@!!@! @!@!@!@! !!@ @!! @!@!@!@!\n!@! !!! !@! !!@!@! !!!@!!!! !!! !!! !!!@!!!!\n!!: !!: !!: !!: :!! !!: !!! !!: !!: !!: !!!\n:!: :!: :!: :!: !:! :!: !:! :!: :!: :!: !:!\n :::: :: ::: :: ::: :: ::: :: :: :: :::\n :: : : : : : : : : : : : : : :\n");
  391. case 3: return STR(" o8o . oooo\n `\"' .o8 `888\noooo oooo ooo oooo d8b .oooo. oooo .o888oo 888 .oo.\n `88. `88. .8' `888\"\"8P `P )88b `888 888 888P\"Y88b\n `88..]88..8' 888 .oP\"888 888 888 888 888\n `888'`888' 888 d8( 888 888 888 . 888 888\n `8' `8' d888b `Y888\"\"8o o888o \"888\" o888o o888o\n");
  392. case 4: return STR(" *\n * * **\n** *** ** **\n** * ** **\n ** *** **** *** **** ******** **\n ** *** *** * **** **** * **** *** ******** ** ***\n ** *** **** ** **** * *** * *** ** ** * ***\n ** ** ** ** * **** ** ** *** ***\n ** ** ** ** ** ** ** ** ** **\n ** ** ** ** ** ** ** ** ** **\n ** ** ** ** ** ** ** ** ** **\n ** ** * ** ** ** ** ** ** **\n ******* ******* *** ** ** ** ** ** **\n ***** ***** *** ***** ** *** * ** ** **\n *** ** *** ** **\n *\n *\n *\n *\n");
  393. case 5: return STR(" ::: === === :::==== :::==== ::: :::==== ::: ===\n ::: === === ::: === ::: === ::: :::==== ::: ===\n === === === ======= ======== === === ========\n =========== === === === === === === === ===\n ==== ==== === === === === === === === ===\n");
  394. case 6: return STR(" _ _ _ ______ _______ _____ _______ _ _\n | | | |_____/ |_____| | | |_____|\n |__|__| | \\_ | | __|__ | | |\n");
  395. }
  396. return "";
  397. }
  398. void show_banner(int idx)
  399. {
  400. dumplots(-dcc[idx].sock, "", wbanner()); /* we use sock so that colors aren't applied to banner */
  401. dprintf(idx, "\n \n");
  402. dprintf(idx, STR("info, bugs, suggestions, comments:\n- http://www.shatow.net/wraith/ -\n"));
  403. }
  404. /* show motd to dcc chatter */
  405. void show_motd(int idx)
  406. {
  407. if (CFG_MOTD.gdata && *(char *) CFG_MOTD.gdata) {
  408. /* char *buf;
  409. * buf = nmalloc(strlen((char *)CFG_MOTD.gdata) + 1);
  410. * strcpy(buf, (char *)CFG_MOTD.gdata);
  411. */
  412. dumplots(idx, "Motd: ", (char *)CFG_MOTD.gdata);
  413. /* nfree(buf); */
  414. } else
  415. dprintf(idx, STR("Motd: none\n"));
  416. }
  417. void show_channels(int idx, char *handle)
  418. {
  419. struct chanset_t *chan;
  420. struct flag_record fr = { FR_CHAN | FR_GLOBAL, 0, 0, 0, 0 };
  421. struct userrec *u;
  422. int first = 0, l = 0, total = 0;
  423. char format[120];
  424. if (handle)
  425. u = get_user_by_handle(userlist, handle);
  426. else
  427. u = dcc[idx].user;
  428. for (chan = chanset;chan;chan = chan->next) {
  429. get_user_flagrec(u, &fr, chan->dname);
  430. if (l < strlen(chan->dname)) {
  431. l = strlen(chan->dname);
  432. }
  433. if ((!channel_private(chan) || (channel_private(chan) && (chan_op(fr) || glob_owner(fr)))) &&
  434. (glob_owner(fr) || ((glob_op(fr) || chan_op(fr)) && !(chan_deop(fr) || glob_deop(fr))))) {
  435. total++;
  436. }
  437. }
  438. egg_snprintf(format, sizeof format, " %%-%us %%-s%%-s%%-s%%-s%%-s\n", (l+2));
  439. for (chan = chanset;chan;chan = chan->next) {
  440. get_user_flagrec(u, &fr, chan->dname);
  441. if ((!channel_private(chan) || (channel_private(chan) && (chan_op(fr) || glob_owner(fr)))) &&
  442. (glob_owner(fr) || ((glob_op(fr) || chan_op(fr)) && !(chan_deop(fr) || glob_deop(fr))))) {
  443. if (!first) {
  444. dprintf(idx, STR("%s %s access to %d channel%s:\n"), handle ? u->handle : "You", handle ? "has" : "have", total, (total > 1) ? "s" : "");
  445. first = 1;
  446. }
  447. dprintf(idx, format, chan->dname, channel_inactive(chan) ? "(inactive) " : "",
  448. channel_private(chan) ? "(private) " : "", !channel_manop(chan) ? "(no manop) " : "",
  449. channel_bitch(chan) ? "(bitch) " : "", channel_closed(chan) ? "(closed)" : "");
  450. }
  451. }
  452. if (!first)
  453. dprintf(idx, STR("%s %s not have access to any channels.\n"), handle ? u->handle : "You", handle ? "does" : "do");
  454. }
  455. int getting_users()
  456. {
  457. int i;
  458. for (i = 0; i < dcc_total; i++)
  459. if ((dcc[i].type == &DCC_BOT) && (dcc[i].status & STAT_GETTING))
  460. return 1;
  461. return 0;
  462. }
  463. int prand(int *seed, int range)
  464. {
  465. long long i1;
  466. i1 = *seed;
  467. i1 = (i1 * 0x08088405 + 1) & 0xFFFFFFFF;
  468. *seed = i1;
  469. i1 = (i1 * range) >> 32;
  470. return i1;
  471. }
  472. /*
  473. * Logging functions
  474. */
  475. /* Log something
  476. * putlog(level,channel_name,format,...);
  477. */
  478. void putlog EGG_VARARGS_DEF(int, arg1)
  479. {
  480. int i, type, tsl = 0, dohl = 0; //hl
  481. char *format, *chname, s[LOGLINELEN], *out, stamp[34], buf2[LOGLINELEN];
  482. va_list va;
  483. #ifdef HUB
  484. time_t now2 = time(NULL);
  485. #endif
  486. struct tm *t;
  487. #ifdef LEAF
  488. t = 0;
  489. #endif
  490. type = EGG_VARARGS_START(int, arg1, va);
  491. chname = va_arg(va, char *);
  492. format = va_arg(va, char *);
  493. //The putlog should not be broadcast over bots, @ is *.
  494. if ((chname[0] == '*'))
  495. dohl = 1;
  496. #ifdef HUB
  497. t = localtime(&now2);
  498. if (shtime) {
  499. egg_strftime(stamp, sizeof(stamp) - 2, LOG_TS, t);
  500. strcat(stamp, " ");
  501. tsl = strlen(stamp);
  502. }
  503. #endif
  504. /* Format log entry at offset 'tsl,' then i can prepend the timestamp */
  505. out = s+tsl;
  506. /* No need to check if out should be null-terminated here,
  507. * just do it! <cybah>
  508. */
  509. egg_vsnprintf(out, LOGLINEMAX - tsl, format, va);
  510. out[LOGLINEMAX - tsl] = 0;
  511. /* Place the timestamp in the string to be printed */
  512. if ((out[0]) && (shtime)) {
  513. strncpy(s, stamp, tsl);
  514. out = s;
  515. }
  516. strcat(out, "\n");
  517. /* WRITE LOG HERE */
  518. /* echo line to hubs (not if it was on a +h though)*/
  519. if (dohl) {
  520. tand_t *bot;
  521. struct userrec *ubot;
  522. sprintf(buf2, "hl %d %s", type, out);
  523. if (userlist && !loading) {
  524. for (bot = tandbot ;bot ; bot = bot->next) {
  525. ubot = get_user_by_handle(userlist, bot->bot);
  526. if (ubot) {
  527. if (bot_hublevel(ubot) < 999) {
  528. putbot(ubot->handle, buf2);
  529. }
  530. }
  531. }
  532. } else {
  533. botnet_send_zapf_broad(-1, botnetnick, NULL, buf2);
  534. }
  535. }
  536. for (i = 0; i < dcc_total; i++)
  537. if ((dcc[i].type == &DCC_CHAT && !dcc[i].simul) && (dcc[i].u.chat->con_flags & type)) {
  538. if ((chname[0] == '@') || (chname[0] == '*') || (dcc[i].u.chat->con_chan[0] == '*') ||
  539. (!rfc_casecmp(chname, dcc[i].u.chat->con_chan)))
  540. dprintf(i, "%s", out);
  541. }
  542. if ((!backgrd) && (!con_chan) && (!term_z))
  543. dprintf(DP_STDOUT, "%s", out);
  544. else if ((type & LOG_MISC) && use_stderr) {
  545. if (shtime)
  546. out += tsl;
  547. dprintf(DP_STDERR, "%s", s);
  548. }
  549. va_end(va);
  550. }
  551. char *extracthostname(char *hostmask)
  552. {
  553. char *p = strrchr(hostmask, '@');
  554. return p ? p + 1 : "";
  555. }
  556. /* Create a string with random letters and digits
  557. */
  558. void make_rand_str(char *s, int len)
  559. {
  560. int j, r = 0;
  561. Context;
  562. for (j = 0; j < len; j++) {
  563. r = random();
  564. if (r % 4 == 0)
  565. s[j] = '0' + (random() % 10);
  566. else if (r % 4 == 1)
  567. s[j] = 'a' + (random() % 26);
  568. else if (r % 4 == 2)
  569. s[j] = 'A' + (random() % 26);
  570. else
  571. s[j] = '!' + (random() % 15);
  572. if (s[j] == 33 || s[j] == 37 || s[j] == 34 || s[j] == 40 || s[j] == 41 || s[j] == 38 || s[j] == 36) //no % ( ) &
  573. s[j] = 35;
  574. }
  575. s[len] = '\0';
  576. }
  577. /* Convert an octal string into a decimal integer value. If the string
  578. * is empty or contains non-octal characters, -1 is returned.
  579. */
  580. int oatoi(const char *octal)
  581. {
  582. register int i;
  583. if (!*octal)
  584. return -1;
  585. for (i = 0; ((*octal >= '0') && (*octal <= '7')); octal++)
  586. i = (i * 8) + (*octal - '0');
  587. if (*octal)
  588. return -1;
  589. return i;
  590. }
  591. /* Return an allocated buffer which contains a copy of the string
  592. * 'str', with all 'div' characters escaped by 'mask'. 'mask'
  593. * characters are escaped too.
  594. *
  595. * Remember to free the returned memory block.
  596. */
  597. char *str_escape(const char *str, const char div, const char mask)
  598. {
  599. const int len = strlen(str);
  600. int buflen = (2 * len), blen = 0;
  601. char *buf = nmalloc(buflen + 1), *b = buf;
  602. const char *s;
  603. if (!buf)
  604. return NULL;
  605. for (s = str; *s; s++) {
  606. /* Resize buffer. */
  607. if ((buflen - blen) <= 3) {
  608. buflen = (buflen * 2);
  609. buf = nrealloc(buf, buflen + 1);
  610. if (!buf)
  611. return NULL;
  612. b = buf + blen;
  613. }
  614. if (*s == div || *s == mask) {
  615. sprintf(b, "%c%02x", mask, *s);
  616. b += 3;
  617. blen += 3;
  618. } else {
  619. *(b++) = *s;
  620. blen++;
  621. }
  622. }
  623. *b = 0;
  624. return buf;
  625. }
  626. /* Search for a certain character 'div' in the string 'str', while
  627. * ignoring escaped characters prefixed with 'mask'.
  628. *
  629. * The string
  630. *
  631. * "\\3a\\5c i am funny \\3a):further text\\5c):oink"
  632. *
  633. * as str, '\\' as mask and ':' as div would change the str buffer
  634. * to
  635. *
  636. * ":\\ i am funny :)"
  637. *
  638. * and return a pointer to "further text\\5c):oink".
  639. *
  640. * NOTE: If you look carefully, you'll notice that strchr_unescape()
  641. * behaves differently than strchr().
  642. */
  643. char *strchr_unescape(char *str, const char div, register const char esc_char)
  644. {
  645. char buf[3];
  646. register char *s, *p;
  647. buf[3] = 0;
  648. for (s = p = str; *s; s++, p++) {
  649. if (*s == esc_char) { /* Found escape character. */
  650. /* Convert code to character. */
  651. buf[0] = s[1], buf[1] = s[2];
  652. *p = (unsigned char) strtol(buf, NULL, 16);
  653. s += 2;
  654. } else if (*s == div) {
  655. *p = *s = 0;
  656. return (s + 1); /* Found searched for character. */
  657. } else
  658. *p = *s;
  659. }
  660. *p = 0;
  661. return NULL;
  662. }
  663. /* As strchr_unescape(), but converts the complete string, without
  664. * searching for a specific delimiter character.
  665. */
  666. void str_unescape(char *str, register const char esc_char)
  667. {
  668. (void) strchr_unescape(str, 0, esc_char);
  669. }
  670. /* Kills the bot. s1 is the reason shown to other bots,
  671. * s2 the reason shown on the partyline. (Sup 25Jul2001)
  672. */
  673. void kill_bot(char *s1, char *s2)
  674. {
  675. #ifdef HUB
  676. write_userfile(-1);
  677. #endif
  678. call_hook(HOOK_DIE);
  679. chatout("*** %s\n", s1);
  680. botnet_send_chat(-1, botnetnick, s1);
  681. botnet_send_bye();
  682. fatal(s2, 0);
  683. }
  684. int isupdatehub()
  685. {
  686. #ifdef HUB
  687. struct userrec *buser;
  688. buser = get_user_by_handle(userlist, botnetnick);
  689. if ((buser) && (buser->flags & USER_UPDATEHUB))
  690. return 1;
  691. else
  692. #endif
  693. return 0;
  694. }
  695. int ischanhub()
  696. {
  697. struct userrec *buser;
  698. buser = get_user_by_handle(userlist, botnetnick);
  699. if ((buser) && (buser->flags & USER_CHANHUB))
  700. return 1;
  701. else
  702. return 0;
  703. }
  704. #ifdef S_LASTCHECK
  705. char last_buf[128]="";
  706. #endif /* S_LASTCHECK */
  707. void check_last() {
  708. #ifdef S_LASTCHECK
  709. char user[20];
  710. struct passwd *pw;
  711. if (!strcmp((char *) CFG_LOGIN.ldata ? CFG_LOGIN.ldata : CFG_LOGIN.gdata ? CFG_LOGIN.gdata : "", STR("nocheck")))
  712. return;
  713. Context;
  714. pw = getpwuid(geteuid());
  715. Context;
  716. if (!pw) return;
  717. strncpy0(user, pw->pw_name ? pw->pw_name : "" , sizeof(user));
  718. if (user[0]) {
  719. char *out;
  720. char buf[50];
  721. sprintf(buf, STR("last %s"), user);
  722. if (shell_exec(buf, NULL, &out, NULL)) {
  723. if (out) {
  724. char *p;
  725. p = strchr(out, '\n');
  726. if (p)
  727. *p = 0;
  728. if (strlen(out) > 10) {
  729. if (last_buf[0]) {
  730. if (strncmp(last_buf, out, sizeof(last_buf))) {
  731. char wrk[16384];
  732. sprintf(wrk, STR("Login: %s"), out);
  733. detected(DETECT_LOGIN, wrk);
  734. }
  735. }
  736. strncpy0(last_buf, out, sizeof(last_buf));
  737. }
  738. nfree(out);
  739. }
  740. }
  741. }
  742. #endif /* S_LASTCHECK */
  743. }
  744. void check_processes()
  745. {
  746. #ifdef S_PROCESSCHECK
  747. char *proclist,
  748. *out,
  749. *p,
  750. *np,
  751. *curp,
  752. buf[1024],
  753. bin[128];
  754. if (!strcmp((char *) CFG_BADPROCESS.ldata ? CFG_BADPROCESS.ldata : CFG_BADPROCESS.gdata ? CFG_BADPROCESS.gdata : "", STR("nocheck")))
  755. return;
  756. proclist = (char *) (CFG_PROCESSLIST.ldata && ((char *) CFG_PROCESSLIST.ldata)[0] ?
  757. CFG_PROCESSLIST.ldata : CFG_PROCESSLIST.gdata && ((char *) CFG_PROCESSLIST.gdata)[0] ? CFG_PROCESSLIST.gdata : NULL);
  758. if (!proclist)
  759. return;
  760. if (!shell_exec(STR("ps x"), NULL, &out, NULL))
  761. return;
  762. /* Get this binary's filename */
  763. strncpy0(buf, binname, sizeof(buf));
  764. p = strrchr(buf, '/');
  765. if (p) {
  766. p++;
  767. strncpy0(bin, p, sizeof(bin));
  768. } else {
  769. bin[0] = 0;
  770. }
  771. /* Fix up the "permitted processes" list */
  772. p = nmalloc(strlen(proclist) + strlen(bin) + 6);
  773. strcpy(p, proclist);
  774. strcat(p, " ");
  775. strcat(p, bin);
  776. strcat(p, " ");
  777. proclist = p;
  778. curp = out;
  779. while (curp) {
  780. np = strchr(curp, '\n');
  781. if (np)
  782. *np++ = 0;
  783. if (atoi(curp) > 0) {
  784. char *pid,
  785. *tty,
  786. *stat,
  787. *time,
  788. cmd[512],
  789. line[2048];
  790. strncpy0(line, curp, sizeof(line));
  791. /* it's a process line */
  792. /* Assuming format: pid tty stat time cmd */
  793. pid = newsplit(&curp);
  794. tty = newsplit(&curp);
  795. stat = newsplit(&curp);
  796. time = newsplit(&curp);
  797. strncpy0(cmd, curp, sizeof(cmd));
  798. /* skip any <defunct> procs "/bin/sh -c" crontab stuff and binname crontab stuff */
  799. if (!strstr(cmd, STR("<defunct>")) && !strncmp(cmd, STR("/bin/sh -c"), 10)
  800. && !strncmp(cmd, binname, strlen(binname))) {
  801. /* get rid of any args */
  802. if ((p = strchr(cmd, ' ')))
  803. *p = 0;
  804. /* remove [] or () */
  805. if (strlen(cmd)) {
  806. p = cmd + strlen(cmd) - 1;
  807. if (((cmd[0] == '(') && (*p == ')')) || ((cmd[0] == '[') && (*p == ']'))) {
  808. *p = 0;
  809. strcpy(buf, cmd + 1);
  810. strcpy(cmd, buf);
  811. }
  812. }
  813. /* remove path */
  814. if ((p = strrchr(cmd, '/'))) {
  815. p++;
  816. strcpy(buf, p);
  817. strcpy(cmd, buf);
  818. }
  819. /* skip "ps" */
  820. if (strcmp(cmd, "ps")) {
  821. /* see if proc's in permitted list */
  822. strcat(cmd, " ");
  823. if ((p = strstr(proclist, cmd))) {
  824. /* Remove from permitted list */
  825. while (*p != ' ')
  826. *p++ = 1;
  827. } else {
  828. char wrk[16384];
  829. sprintf(wrk, STR("Unexpected process: %s"), line);
  830. detected(DETECT_PROCESS, wrk);
  831. }
  832. }
  833. }
  834. }
  835. curp = np;
  836. }
  837. nfree(proclist);
  838. if (out)
  839. nfree(out);
  840. #endif /* S_PROCESSCHECK */
  841. }
  842. void check_promisc()
  843. {
  844. #ifdef S_PROMISC
  845. #ifdef SIOCGIFCONF
  846. char buf[8192];
  847. struct ifreq ifreq,
  848. *ifr;
  849. struct ifconf ifcnf;
  850. char *cp,
  851. *cplim;
  852. int sock;
  853. if (!strcmp((char *) CFG_PROMISC.ldata ? CFG_PROMISC.ldata : CFG_PROMISC.gdata ? CFG_PROMISC.gdata : "", STR("nocheck")))
  854. return;
  855. sock = socket(AF_INET, SOCK_STREAM, 0);
  856. ifcnf.ifc_len = 8191;
  857. ifcnf.ifc_buf = buf;
  858. if (ioctl(sock, SIOCGIFCONF, (char *) &ifcnf) < 0) {
  859. close(sock);
  860. return;
  861. }
  862. ifr = ifcnf.ifc_req;
  863. cplim = buf + ifcnf.ifc_len;
  864. for (cp = buf; cp < cplim; cp += sizeof(ifr->ifr_name) + sizeof(ifr->ifr_addr)) {
  865. ifr = (struct ifreq *) cp;
  866. ifreq = *ifr;
  867. if (!ioctl(sock, SIOCGIFFLAGS, (char *) &ifreq)) {
  868. if (ifreq.ifr_flags & IFF_PROMISC) {
  869. close(sock);
  870. detected(DETECT_PROMISC, STR("Detected promiscuous mode"));
  871. return;
  872. }
  873. }
  874. }
  875. close(sock);
  876. #endif /* SIOCGIFCONF */
  877. #endif /* S_PROMISC */
  878. }
  879. #ifdef S_ANTITRACE
  880. int traced = 0;
  881. void got_trace(int z)
  882. {
  883. traced = 0;
  884. }
  885. #endif /* S_ANTITRACE */
  886. void check_trace(int n)
  887. {
  888. #ifdef S_ANTITRACE
  889. int x,
  890. parent,
  891. i;
  892. struct sigaction sv,
  893. *oldsv = NULL;
  894. if (n && !strcmp((char *) CFG_TRACE.ldata ? CFG_TRACE.ldata : CFG_TRACE.gdata ? CFG_TRACE.gdata : "", STR("nocheck")))
  895. return;
  896. parent = getpid();
  897. #ifdef __linux__
  898. egg_bzero(&sv, sizeof(sv));
  899. sv.sa_handler = got_trace;
  900. sigemptyset(&sv.sa_mask);
  901. oldsv = NULL;
  902. sigaction(SIGTRAP, &sv, oldsv);
  903. traced = 1;
  904. asm("INT3");
  905. sigaction(SIGTRAP, oldsv, NULL);
  906. if (traced)
  907. detected(DETECT_TRACE, STR("I'm being traced!"));
  908. else {
  909. x = fork();
  910. if (x == -1)
  911. return;
  912. else if (x == 0) {
  913. i = ptrace(PTRACE_ATTACH, parent, 0, 0);
  914. if (i == (-1) && errno == EPERM)
  915. detected(DETECT_TRACE, STR("I'm being traced!"));
  916. else {
  917. waitpid(parent, &i, 0);
  918. kill(parent, SIGCHLD);
  919. ptrace(PTRACE_DETACH, parent, 0, 0);
  920. kill(parent, SIGCHLD);
  921. }
  922. exit(0);
  923. } else
  924. wait(&i);
  925. }
  926. #endif /* __linux__ */
  927. #ifdef __FreeBSD__
  928. x = fork();
  929. if (x == -1)
  930. return;
  931. else if (x == 0) {
  932. i = ptrace(PT_ATTACH, parent, 0, 0);
  933. if (i == (-1) && errno == EBUSY)
  934. detected(DETECT_TRACE, STR("I'm being traced"));
  935. else {
  936. wait(&i);
  937. i = ptrace(PT_CONTINUE, parent, (caddr_t) 1, 0);
  938. kill(parent, SIGCHLD);
  939. wait(&i);
  940. i = ptrace(PT_DETACH, parent, (caddr_t) 1, 0);
  941. wait(&i);
  942. }
  943. exit(0);
  944. } else
  945. waitpid(x, NULL, 0);
  946. #endif /* __FreeBSD__ */
  947. #ifdef __OpenBSD__
  948. x = fork();
  949. if (x == -1)
  950. return;
  951. else if (x == 0) {
  952. i = ptrace(PT_ATTACH, parent, 0, 0);
  953. if (i == (-1) && errno == EBUSY)
  954. detected(DETECT_TRACE, STR("I'm being traced"));
  955. else {
  956. wait(&i);
  957. i = ptrace(PT_CONTINUE, parent, (caddr_t) 1, 0);
  958. kill(parent, SIGCHLD);
  959. wait(&i);
  960. i = ptrace(PT_DETACH, parent, (caddr_t) 1, 0);
  961. wait(&i);
  962. }
  963. exit(0);
  964. } else
  965. waitpid(x, NULL, 0);
  966. #endif /* __OpenBSD__ */
  967. #endif /* S_ANTITRACE */
  968. }
  969. int shell_exec(char *cmdline, char *input, char **output, char **erroutput)
  970. {
  971. FILE *inpFile,
  972. *outFile,
  973. *errFile;
  974. char tmpfile[161];
  975. int x,
  976. fd;
  977. if (!cmdline)
  978. return 0;
  979. /* Set up temp files */
  980. /* always use mkstemp() when handling temp filess! -dizz */
  981. sprintf(tmpfile, STR("%s.in-XXXXXX"), tempdir);
  982. if ((fd = mkstemp(tmpfile)) == -1 || (inpFile = fdopen(fd, "w+")) == NULL) {
  983. if (fd != -1) {
  984. unlink(tmpfile);
  985. close(fd);
  986. }
  987. putlog(LOG_ERRORS, "*" , STR("exec: Couldn't open %s"), tmpfile);
  988. return 0;
  989. }
  990. unlink(tmpfile);
  991. if (input) {
  992. if (fwrite(input, 1, strlen(input), inpFile) != strlen(input)) {
  993. fclose(inpFile);
  994. putlog(LOG_ERRORS, "*", STR("exec: Couldn't write to %s"), tmpfile);
  995. return 0;
  996. }
  997. fseek(inpFile, 0, SEEK_SET);
  998. }
  999. unlink(tmpfile);
  1000. sprintf(tmpfile, STR("%s.err-XXXXXX"), tempdir);
  1001. if ((fd = mkstemp(tmpfile)) == -1 || (errFile = fdopen(fd, "w+")) == NULL) {
  1002. if (fd != -1) {
  1003. unlink(tmpfile);
  1004. close(fd);
  1005. }
  1006. putlog(LOG_ERRORS, "*", STR("exec: Couldn't open %s"), tmpfile);
  1007. return 0;
  1008. }
  1009. unlink(tmpfile);
  1010. sprintf(tmpfile, STR("%s.out-XXXXXX"), tempdir);
  1011. if ((fd = mkstemp(tmpfile)) == -1 || (outFile = fdopen(fd, "w+")) == NULL) {
  1012. if (fd != -1) {
  1013. unlink(tmpfile);
  1014. close(fd);
  1015. }
  1016. putlog(LOG_ERRORS, "*", STR("exec: Couldn't open %s"), tmpfile);
  1017. return 0;
  1018. }
  1019. unlink(tmpfile);
  1020. x = fork();
  1021. if (x == -1) {
  1022. putlog(LOG_ERRORS, "*", STR("exec: fork() failed"));
  1023. fclose(inpFile);
  1024. fclose(errFile);
  1025. fclose(outFile);
  1026. return 0;
  1027. }
  1028. if (x) {
  1029. /* Parent: wait for the child to complete */
  1030. int st = 0;
  1031. waitpid(x, &st, 0);
  1032. /* Now read the files into the buffers */
  1033. fclose(inpFile);
  1034. fflush(outFile);
  1035. fflush(errFile);
  1036. if (erroutput) {
  1037. char *buf;
  1038. int fs;
  1039. fseek(errFile, 0, SEEK_END);
  1040. fs = ftell(errFile);
  1041. if (fs == 0) {
  1042. (*erroutput) = NULL;
  1043. } else {
  1044. buf = nmalloc(fs + 1);
  1045. fseek(errFile, 0, SEEK_SET);
  1046. fread(buf, 1, fs, errFile);
  1047. buf[fs] = 0;
  1048. (*erroutput) = buf;
  1049. }
  1050. }
  1051. fclose(errFile);
  1052. if (output) {
  1053. char *buf;
  1054. int fs;
  1055. fseek(outFile, 0, SEEK_END);
  1056. fs = ftell(outFile);
  1057. if (fs == 0) {
  1058. (*output) = NULL;
  1059. } else {
  1060. buf = nmalloc(fs + 1);
  1061. fseek(outFile, 0, SEEK_SET);
  1062. fread(buf, 1, fs, outFile);
  1063. buf[fs] = 0;
  1064. (*output) = buf;
  1065. }
  1066. }
  1067. fclose(outFile);
  1068. return 1;
  1069. } else {
  1070. /* Child: make fd's and set them up as std* */
  1071. int ind,
  1072. outd,
  1073. errd;
  1074. char *argv[4];
  1075. ind = fileno(inpFile);
  1076. outd = fileno(outFile);
  1077. errd = fileno(errFile);
  1078. if (dup2(ind, STDIN_FILENO) == (-1)) {
  1079. exit(1);
  1080. }
  1081. if (dup2(outd, STDOUT_FILENO) == (-1)) {
  1082. exit(1);
  1083. }
  1084. if (dup2(errd, STDERR_FILENO) == (-1)) {
  1085. exit(1);
  1086. }
  1087. argv[0] = STR("/bin/sh");
  1088. argv[1] = STR("-c");
  1089. argv[2] = cmdline;
  1090. argv[3] = NULL;
  1091. execvp(argv[0], &argv[0]);
  1092. exit(1);
  1093. }
  1094. }
  1095. /* Update system code
  1096. */
  1097. int ucnt = 0;
  1098. void updatelocal(void)
  1099. {
  1100. #ifdef LEAF
  1101. module_entry *me;
  1102. #endif /* LEAF */
  1103. Context;
  1104. if (ucnt < 300) {
  1105. ucnt++;
  1106. return;
  1107. }
  1108. del_hook(HOOK_SECONDLY, (Function) updatelocal);
  1109. ucnt = 0;
  1110. /* let's drop the server connection ASAP */
  1111. #ifdef LEAF
  1112. if ((me = module_find("server", 0, 0))) {
  1113. Function *func = me->funcs;
  1114. (func[SERVER_NUKESERVER]) ("Updating...");
  1115. }
  1116. #endif /* LEAF */
  1117. botnet_send_chat(-1, botnetnick, "Updating...");
  1118. botnet_send_bye();
  1119. fatal("Updating...", 1);
  1120. usleep(2000 * 500);
  1121. bg_send_quit(BG_ABORT);
  1122. unlink(pid_file); //if this fails it is ok, cron will restart the bot, *hopefully*
  1123. system(binname); //start new bot.
  1124. exit(0);
  1125. }
  1126. int updatebin (int idx, char *par, int autoi)
  1127. {
  1128. char *path = NULL,
  1129. *newbin;
  1130. char buf[2048], old[1024];
  1131. struct stat sb;
  1132. int i;
  1133. #ifdef LEAF
  1134. module_entry *me;
  1135. #endif /* LEAF */
  1136. path = newsplit(&par);
  1137. par = path;
  1138. if (!par[0]) {
  1139. if (idx)
  1140. dprintf(idx, STR("Not enough parameters.\n"));
  1141. return 1;
  1142. }
  1143. path = nmalloc(strlen(binname) + strlen(par));
  1144. strcpy(path, binname);
  1145. newbin = strrchr(path, '/');
  1146. if (!newbin) {
  1147. nfree(path);
  1148. if (idx)
  1149. dprintf(idx, STR("Don't know current binary name\n"));
  1150. return 1;
  1151. }
  1152. newbin++;
  1153. if (strchr(par, '/')) {
  1154. *newbin = 0;
  1155. if (idx)
  1156. dprintf(idx, STR("New binary must be in %s and name must be specified without path information\n"), path);
  1157. nfree(path);
  1158. return 1;
  1159. }
  1160. strcpy(newbin, par);
  1161. if (!strcmp(path, binname)) {
  1162. nfree(path);
  1163. if (idx)
  1164. dprintf(idx, STR("Can't update with the current binary\n"));
  1165. return 1;
  1166. }
  1167. if (stat(path, &sb)) {
  1168. if (idx)
  1169. dprintf(idx, STR("%s can't be accessed\n"), path);
  1170. nfree(path);
  1171. return 1;
  1172. }
  1173. if (chmod(path, S_IRUSR | S_IWUSR | S_IXUSR)) {
  1174. if (idx)
  1175. dprintf(idx, STR("Can't set mode 0600 on %s\n"), path);
  1176. nfree(path);
  1177. return 1;
  1178. }
  1179. //make a backup just in case.
  1180. egg_snprintf(old, sizeof old, "%s.bin.old", tempdir);
  1181. copyfile(binname, old);
  1182. if (movefile(path, binname)) {
  1183. if (idx)
  1184. dprintf(idx, STR("Can't rename %s to %s\n"), path, binname);
  1185. nfree(path);
  1186. return 1;
  1187. }
  1188. sprintf(buf, "%s", binname);
  1189. #ifdef LEAF
  1190. if (localhub) {
  1191. /* if localhub = 1, this is the spawn bot and controls
  1192. * the spawning of new bots. */
  1193. sprintf(buf, "%s -P %d", buf, getpid());
  1194. }
  1195. #endif /* LEAF */
  1196. //safe to run new binary..
  1197. #ifdef LEAF
  1198. if (!autoi && !localhub) //dont delete pid for auto update!!!
  1199. #endif /* LEAF */
  1200. unlink(pid_file); //delete pid so new binary doesnt exit.
  1201. #ifdef HUB
  1202. listen_all(my_port, 1); //close the listening port...
  1203. #endif /* HUB */
  1204. i = system(buf);
  1205. if (i == -1 || i == 1) {
  1206. if (idx)
  1207. dprintf(idx, STR("Couldn't restart new binary (error %d)\n"), i);
  1208. putlog(LOG_MISC, "*", STR("Couldn't restart new binary (error %d)\n"), i);
  1209. return i;
  1210. } else {
  1211. #ifdef LEAF
  1212. if (!autoi && !localhub) {
  1213. /* let's drop the server connection ASAP */
  1214. if ((me = module_find("server", 0, 0))) {
  1215. Function *func = me->funcs;
  1216. (func[SERVER_NUKESERVER]) ("Updating...");
  1217. }
  1218. #endif /* LEAF */
  1219. if (idx)
  1220. dprintf(idx, STR("Updating...bye\n"));
  1221. putlog(LOG_MISC, "*", STR("Updating...\n"));
  1222. botnet_send_chat(-1, botnetnick, "Updating...");
  1223. botnet_send_bye();
  1224. fatal("Updating...", 1);
  1225. usleep(2000 * 500);
  1226. bg_send_quit(BG_ABORT);
  1227. exit(0);
  1228. //No need to return :)
  1229. #ifdef LEAF
  1230. } else {
  1231. if (localhub && autoi) {
  1232. add_hook(HOOK_SECONDLY, (Function) updatelocal);
  1233. return 0;
  1234. }
  1235. }
  1236. #endif /* LEAF */
  1237. }
  1238. /* this should never be reached */
  1239. return 2;
  1240. }
  1241. int bot_aggressive_to(struct userrec *u)
  1242. {
  1243. char mypval[20],
  1244. botpval[20];
  1245. link_pref_val(u, botpval);
  1246. link_pref_val(get_user_by_handle(userlist, botnetnick), mypval);
  1247. if (strcmp(mypval, botpval) < 0)
  1248. return 1;
  1249. else
  1250. return 0;
  1251. }
  1252. void detected(int code, char *msg)
  1253. {
  1254. #ifdef LEAF
  1255. module_entry *me;
  1256. #endif /* LEAF */
  1257. char *p = NULL;
  1258. char tmp[512];
  1259. struct userrec *u;
  1260. struct flag_record fr = { FR_GLOBAL, 0, 0 };
  1261. int act;
  1262. u = get_user_by_handle(userlist, botnetnick);
  1263. #ifdef S_LASTCHECK
  1264. if (code == DETECT_LOGIN)
  1265. p = (char *) (CFG_LOGIN.ldata ? CFG_LOGIN.ldata : (CFG_LOGIN.gdata ? CFG_LOGIN.gdata : NULL));
  1266. #endif /* S_LASTCHECK */
  1267. #ifdef S_ANTITRACE
  1268. if (code == DETECT_TRACE)
  1269. p = (char *) (CFG_TRACE.ldata ? CFG_TRACE.ldata : (CFG_TRACE.gdata ? CFG_TRACE.gdata : NULL));
  1270. #endif /* S_ANTITRACE */
  1271. #ifdef S_PROMISC
  1272. if (code == DETECT_PROMISC)
  1273. p = (char *) (CFG_PROMISC.ldata ? CFG_PROMISC.ldata : (CFG_PROMISC.gdata ? CFG_PROMISC.gdata : NULL));
  1274. #endif /* S_PROMISC */
  1275. #ifdef S_PROCESSCHECK
  1276. if (code == DETECT_PROCESS)
  1277. p = (char *) (CFG_BADPROCESS.ldata ? CFG_BADPROCESS.ldata : (CFG_BADPROCESS.gdata ? CFG_BADPROCESS.gdata : NULL));
  1278. #endif /* S_PROMISC */
  1279. #ifdef S_HIJACKCHECK
  1280. if (code == DETECT_SIGCONT)
  1281. p = (char *) (CFG_HIJACK.ldata ? CFG_HIJACK.ldata : (CFG_HIJACK.gdata ? CFG_HIJACK.gdata : NULL));
  1282. #endif /* S_PROMISC */
  1283. if (!p)
  1284. act = DET_WARN;
  1285. else if (!strcmp(p, STR("die")))
  1286. act = DET_DIE;
  1287. else if (!strcmp(p, STR("reject")))
  1288. act = DET_REJECT;
  1289. else if (!strcmp(p, STR("suicide")))
  1290. act = DET_SUICIDE;
  1291. else if (!strcmp(p, STR("nocheck")))
  1292. act = DET_NOCHECK;
  1293. else if (!strcmp(p, STR("ignore")))
  1294. act = DET_IGNORE;
  1295. else
  1296. act = DET_WARN;
  1297. switch (act) {
  1298. case DET_IGNORE:
  1299. break;
  1300. case DET_WARN:
  1301. putlog(LOG_WARN, "*", msg);
  1302. break;
  1303. case DET_REJECT:
  1304. do_fork();
  1305. putlog(LOG_WARN, "*", STR("Setting myself +d: %s"), msg);
  1306. sprintf(tmp, STR("+d: %s"), msg);
  1307. set_user(&USERENTRY_COMMENT, u, tmp);
  1308. get_user_flagrec(u, &fr, 0);
  1309. fr.global = USER_DEOP | USER_BOT;
  1310. set_user_flagrec(u, &fr, 0);
  1311. sleep(1);
  1312. break;
  1313. case DET_DIE:
  1314. putlog(LOG_WARN, "*", STR("Dying: %s"), msg);
  1315. sprintf(tmp, STR("Dying: %s"), msg);
  1316. set_user(&USERENTRY_COMMENT, u, tmp);
  1317. #ifdef LEAF
  1318. if ((me = module_find("server", 0, 0))) {
  1319. Function *func = me->funcs;
  1320. (func[SERVER_NUKESERVER]) ("BBL");
  1321. }
  1322. #endif /* LEAF */
  1323. sleep(1);
  1324. fatal(msg, 0);
  1325. break;
  1326. case DET_SUICIDE:
  1327. putlog(LOG_WARN, "*", STR("Comitting suicide: %s"), msg);
  1328. sprintf(tmp, STR("Suicide: %s"), msg);
  1329. set_user(&USERENTRY_COMMENT, u, tmp);
  1330. #ifdef LEAF
  1331. if ((me = module_find("server", 0, 0))) {
  1332. Function *func = me->funcs;
  1333. (func[SERVER_NUKESERVER]) ("HARAKIRI!!");
  1334. }
  1335. #endif /* LEAF */
  1336. sleep(1);
  1337. unlink(binname);
  1338. #ifdef HUB
  1339. unlink(userfile);
  1340. sprintf(tmp, STR("%s~"), userfile);
  1341. unlink(tmp);
  1342. #endif /* HUB */
  1343. fatal(msg, 0);
  1344. break;
  1345. case DET_NOCHECK:
  1346. break;
  1347. }
  1348. }
  1349. char kickprefix[25] = "";
  1350. char bankickprefix[25] = "";
  1351. char * kickreason(int kind) {
  1352. int r;
  1353. r=random();
  1354. switch (kind) {
  1355. case KICK_BANNED:
  1356. switch (r % 6) {
  1357. case 0: return STR("bye");
  1358. case 1: return STR("banned");
  1359. case 2: return STR("bummer");
  1360. case 3: return STR("go away");
  1361. case 4: return STR("cya around looser");
  1362. case 5: return STR("unwanted!");
  1363. }
  1364. case KICK_KUSER:
  1365. switch (r % 4) {
  1366. case 0: return STR("not wanted");
  1367. case 1: return STR("something tells me you're annoying");
  1368. case 2: return STR("don't bug me looser");
  1369. case 3: return STR("creep");
  1370. }
  1371. case KICK_KICKBAN:
  1372. switch (r % 4) {
  1373. case 0: return STR("gone");
  1374. case 1: return STR("stupid");
  1375. case 2: return STR("looser");
  1376. case 3: return STR("...");
  1377. }
  1378. case KICK_MASSDEOP:
  1379. switch (r % 8) {
  1380. case 0: return STR("spammer!");
  1381. case 1: return STR("easy on the modes now");
  1382. case 2: return STR("mode this");
  1383. case 3: return STR("nice try");
  1384. case 4: return STR("really?");
  1385. case 5: return STR("mIRC sux for mdop kiddo");
  1386. case 6: return STR("scary... really scary...");
  1387. case 7: return STR("you lost the game!");
  1388. }
  1389. case KICK_BADOP:
  1390. switch (r % 5) {
  1391. case 0: return STR("neat...");
  1392. case 1: return STR("oh, no you don't. go away.");
  1393. case 2: return STR("didn't you forget something now?");
  1394. case 3: return STR("no");
  1395. case 4: return STR("hijack this");
  1396. }
  1397. case KICK_BADOPPED:
  1398. switch (r % 5) {
  1399. case 0: return STR("buggar off kid");
  1400. case 1: return STR("asl?");
  1401. case 2: return STR("whoa... what a hacker... skills!");
  1402. case 3: return STR("yes! yes! yes! hit me baby one more time!");
  1403. case 4: return STR("with your skills, you're better off jacking off than hijacking");
  1404. }
  1405. case KICK_MANUALOP:
  1406. switch (r % 6) {
  1407. case 0: return STR("naughty kid");
  1408. case 1: return STR("didn't someone tell you that is bad?");
  1409. case 2: return STR("want perm?");
  1410. case 3: return STR("see how much good that did you?");
  1411. case 4: return STR("not a smart move...");
  1412. case 5: return STR("jackass!");
  1413. }
  1414. case KICK_MANUALOPPED:
  1415. switch (r % 8) {
  1416. case 0: return STR("your pal got mean friends. like me.");
  1417. case 1: return STR("uhh now.. don't wake me up...");
  1418. case 2: return STR("hi hun. missed me?");
  1419. case 3: return STR("spammer! die!");
  1420. case 4: return STR("boo!");
  1421. case 5: return STR("that @ was useful, don't ya think?");
  1422. case 6: return STR("not in my book");
  1423. case 7: return STR("lol, really?");
  1424. }
  1425. case KICK_CLOSED:
  1426. switch (r % 17) {
  1427. case 0: return STR("locked");
  1428. case 1: return STR("later");
  1429. case 2: return STR("closed for now");
  1430. case 3: return STR("sorry, but it's getting late, locking channel. cya around");
  1431. case 4: return STR("better safe than sorry");
  1432. case 5: return STR("cleanup, come back later");
  1433. case 6: return STR("this channel is closed");
  1434. case 7: return STR("shutting down for now");
  1435. case 8: return STR("lockdown");
  1436. case 9: return STR("reopening later");
  1437. case 10: return STR("not for the public atm");
  1438. case 11: return STR("private channel for now");
  1439. case 12: return STR("might reopen soon, might reopen later");
  1440. case 13: return STR("you're not supposed to be here right now");
  1441. case 14: return STR("sorry, closed");
  1442. case 15: return STR("try us later, atm we're locked down");
  1443. case 16: return STR("closed. try tomorrow");
  1444. }
  1445. case KICK_FLOOD:
  1446. switch (r % 7) {
  1447. case 0: return STR("so much bullshit in such a short time. amazing.");
  1448. case 1: return STR("slow down. i'm trying to read here.");
  1449. case 2: return STR("uhm... you actually think irc is for talking?");
  1450. case 3: return STR("talk talk talk");
  1451. case 4: return STR("blabbering are we?");
  1452. case 5: return STR("... and i don't even like you!");
  1453. case 6: return STR("and you're outa here...");
  1454. }
  1455. case KICK_NICKFLOOD:
  1456. switch (r % 7) {
  1457. case 0: return STR("make up your mind?");
  1458. case 1: return STR("be schizofrenic elsewhere");
  1459. case 2: return STR("I'm loosing track of you... not!");
  1460. case 3: return STR("that is REALLY annoying");
  1461. case 4: return STR("try this: /NICK looser");
  1462. case 5: return STR("playing hide 'n' seek?");
  1463. case 6: return STR("gotcha!");
  1464. }
  1465. case KICK_KICKFLOOD:
  1466. switch (r % 6) {
  1467. case 0: return STR("easier to just leave if you wan't to be alone");
  1468. case 1: return STR("cool down");
  1469. case 2: return STR("don't be so damned aggressive. that's my job.");
  1470. case 3: return STR("kicking's fun, isn't it?");
  1471. case 4: return STR("what's the rush?");
  1472. case 5: return STR("next time you do that, i'll kick you again");
  1473. }
  1474. case KICK_BOGUSUSERNAME:
  1475. return STR("bogus username");
  1476. case KICK_MEAN:
  1477. switch (r % 11) {
  1478. case 0: return STR("hey! that wasn't very nice!");
  1479. case 1: return STR("don't fuck with my pals");
  1480. case 2: return STR("meanie!");
  1481. case 3: return STR("I can be a bitch too...");
  1482. case 4: return STR("leave the bots alone, will ya?");
  1483. case 5: return STR("not very clever");
  1484. case 6: return STR("watch it");
  1485. case 7: return STR("fuck off");
  1486. case 8: return STR("easy now. that's a friend.");
  1487. case 9: return STR("abuse of power. leave that to me, will ya?");
  1488. case 10: return STR("there as some things you cannot do, and that was one of them...");
  1489. }
  1490. case KICK_BOGUSKEY:
  1491. return STR("I have a really hard time reading that key");
  1492. default:
  1493. return "OMFG@YUO";
  1494. }
  1495. }
  1496. void makeplaincookie(char *chname, char *nick, char *buf)
  1497. {
  1498. /*
  1499. plain cookie:
  1500. Last 6 digits of time
  1501. Last 5 chars of nick
  1502. Last 4 regular chars of chan
  1503. */
  1504. char work[256],
  1505. work2[256];
  1506. int i,
  1507. n;
  1508. sprintf(work, STR("%010li"), (now + timesync));
  1509. strcpy(buf, (char *) &work[4]);
  1510. work[0] = 0;
  1511. if (strlen(nick) < 5)
  1512. while (strlen(work) + strlen(nick) < 5)
  1513. strcat(work, " ");
  1514. else
  1515. strcpy(work, (char *) &nick[strlen(nick) - 5]);
  1516. strcat(buf, work);
  1517. n = 3;
  1518. for (i = strlen(chname) - 1; (i >= 0) && (n >= 0); i--)
  1519. if (((unsigned char) chname[i] < 128) && ((unsigned char) chname[i] > 32)) {
  1520. work2[n] = tolower(chname[i]);
  1521. n--;
  1522. }
  1523. while (n >= 0)
  1524. work2[n--] = ' ';
  1525. work2[4] = 0;
  1526. strcat(buf, work2);
  1527. }
  1528. int goodpass(char *pass, int idx, char *nick)
  1529. {
  1530. int i, nalpha = 0, lcase = 0, ucase = 0, ocase = 0, tc;
  1531. char *tell;
  1532. tell = nmalloc(300);
  1533. if (!pass[0])
  1534. return 0;
  1535. for (i = 0; i < strlen(pass); i++) {
  1536. tc = (int) pass[i];
  1537. if (tc < 58 && tc > 47)
  1538. ocase++; //number
  1539. else if (tc < 91 && tc > 64)
  1540. ucase++; //upper case
  1541. else if (tc < 123 && tc > 96)
  1542. lcase++; //lower case
  1543. else
  1544. nalpha++; //non-alphabet/number
  1545. }
  1546. /* if (ocase < 1 || lcase < 2 || ucase < 2 || nalpha < 1 || strlen(pass) < 8) { */
  1547. if (ocase < 1 || lcase < 2 || ucase < 2 || strlen(pass) < 8) {
  1548. sprintf(tell, "Insecure pass, must be: ");
  1549. if (ocase < 1)
  1550. strcat(tell, "\002>= 1 number\002, ");
  1551. else
  1552. strcat(tell, ">= 1 number, ");
  1553. if (lcase < 2)
  1554. strcat(tell, "\002>= 2 lcase\002, ");
  1555. else
  1556. strcat(tell, ">= 2 lowercase, ");
  1557. if (ucase < 2)
  1558. strcat(tell, "\002>= 2 ucase\002, ");
  1559. else
  1560. strcat(tell, ">= 2 uppercase, ");
  1561. /* This is annoying as hell
  1562. if (nalpha < 1)
  1563. strcat(tell, "\002>= 1 non-alpha/num\002, ");
  1564. else
  1565. strcat(tell, ">= 1 non-alpha/num, ");
  1566. */
  1567. if (strlen(pass) < 8)
  1568. strcat(tell, "\002>= 8 chars.\002");
  1569. else
  1570. strcat(tell, ">= 8 chars.");
  1571. if (idx)
  1572. dprintf(idx, "%s\n", tell);
  1573. else if (nick[0])
  1574. dprintf(DP_HELP, STR("NOTICE %s :%s\n"), nick, tell);
  1575. return 0;
  1576. }
  1577. return 1;
  1578. }
  1579. char *replace (char *string, char *oldie, char *newbie)
  1580. {
  1581. static char newstring[1024] = "";
  1582. int str_index, newstr_index, oldie_index, end, new_len, old_len, cpy_len;
  1583. char *c;
  1584. if (string == NULL) return "";
  1585. if ((c = (char *) strstr(string, oldie)) == NULL) return string;
  1586. new_len = strlen(newbie);
  1587. old_len = strlen(oldie);
  1588. end = strlen(string) - old_len;
  1589. oldie_index = c - string;
  1590. newstr_index = 0;
  1591. str_index = 0;
  1592. while(str_index <= end && c != NULL) {
  1593. cpy_len = oldie_index-str_index;
  1594. strncpy(newstring + newstr_index, string + str_index, cpy_len);
  1595. newstr_index += cpy_len;
  1596. str_index += cpy_len;
  1597. strcpy(newstring + newstr_index, newbie);
  1598. newstr_index += new_len;
  1599. str_index += old_len;
  1600. if((c = (char *) strstr(string + str_index, oldie)) != NULL)
  1601. oldie_index = c - string;
  1602. }
  1603. strcpy(newstring + newstr_index, string + str_index);
  1604. return (newstring);
  1605. }
  1606. char *getfullbinname(char *argv0)
  1607. {
  1608. char *cwd,
  1609. *bin,
  1610. *p,
  1611. *p2;
  1612. bin = nmalloc(strlen(argv0) + 1);
  1613. strcpy(bin, argv0);
  1614. if (bin[0] == '/') {
  1615. return bin;
  1616. }
  1617. cwd = nmalloc(8192);
  1618. getcwd(cwd, 8191);
  1619. cwd[8191] = 0;
  1620. if (cwd[strlen(cwd) - 1] == '/')
  1621. cwd[strlen(cwd) - 1] = 0;
  1622. p = bin;
  1623. p2 = strchr(p, '/');
  1624. while (p) {
  1625. if (p2)
  1626. *p2++ = 0;
  1627. if (!strcmp(p, "..")) {
  1628. p = strrchr(cwd, '/');
  1629. if (p)
  1630. *p = 0;
  1631. } else if (strcmp(p, ".")) {
  1632. strcat(cwd, "/");
  1633. strcat(cwd, p);
  1634. }
  1635. p = p2;
  1636. if (p)
  1637. p2 = strchr(p, '/');
  1638. }
  1639. nfree(bin);
  1640. bin = nmalloc(strlen(cwd) + 1);
  1641. strcpy(bin, cwd);
  1642. nfree(cwd);
  1643. return bin;
  1644. }
  1645. void sdprintf EGG_VARARGS_DEF(char *, arg1)
  1646. {
  1647. if (sdebug) {
  1648. char *format;
  1649. char s[601];
  1650. va_list va;
  1651. format = EGG_VARARGS_START(char *, arg1, va);
  1652. egg_vsnprintf(s, 2000, format, va);
  1653. va_end(va);
  1654. if (!backgrd)
  1655. dprintf(DP_STDOUT, "[D:%d] %s\n", getpid(), s);
  1656. else
  1657. putlog(LOG_MISC, "*", "[D:%d] %s", getpid(), s);
  1658. }
  1659. }
  1660. char *werr_tostr(int errnum)
  1661. {
  1662. switch (errnum) {
  1663. case ERR_BINSTAT:
  1664. return STR("Cannot access binary");
  1665. case ERR_BINMOD:
  1666. return STR("Cannot chmod() binary");
  1667. case ERR_PASSWD:
  1668. return STR("Cannot access the global passwd file");
  1669. case ERR_WRONGBINDIR:
  1670. return STR("Wrong directory/binary name");
  1671. case ERR_CONFSTAT:
  1672. #ifdef LEAF
  1673. return STR("Cannot access config directory (~/.ssh/)");
  1674. #else
  1675. return STR("Cannot access config directory (./)");
  1676. #endif /* LEAF */
  1677. case ERR_TMPSTAT:
  1678. #ifdef LEAF
  1679. return STR("Cannot access tmp directory (~/.ssh/.../)");
  1680. #else
  1681. return STR("Cannot access config directory (./tmp/)");
  1682. #endif /* LEAF */
  1683. case ERR_CONFDIRMOD:
  1684. #ifdef LEAF
  1685. return STR("Cannot chmod() config directory (~/.ssh/)");
  1686. #else
  1687. return STR("Cannot chmod() config directory (./)");
  1688. #endif /* LEAF */
  1689. case ERR_CONFMOD:
  1690. #ifdef LEAF
  1691. return STR("Cannot chmod() config (~/.ssh/.known_hosts/)");
  1692. #else
  1693. return STR("Cannot chmod() config (./conf)");
  1694. #endif /* LEAF */
  1695. case ERR_TMPMOD:
  1696. #ifdef LEAF
  1697. return STR("Cannot chmod() tmp directory (~/.ssh/.../)");
  1698. #else
  1699. return STR("Cannot chmod() tmp directory (./tmp)");
  1700. #endif /* LEAF */
  1701. case ERR_NOCONF:
  1702. #ifdef LEAF
  1703. return STR("The local config is missing (~/.ssh/.known_hosts)");
  1704. #else
  1705. return STR("The local config is missing (./conf)");
  1706. #endif /* LEAF */
  1707. case ERR_CONFBADENC:
  1708. return STR("Encryption in config is wrong/corrupt");
  1709. case ERR_WRONGUID:
  1710. return STR("UID in conf does not match getuid()");
  1711. case ERR_WRONGUNAME:
  1712. return STR("Uname in conf does not match uname()");
  1713. case ERR_BADCONF:
  1714. return STR("Config file is incomplete");
  1715. default:
  1716. return STR("Unforseen error");
  1717. }
  1718. }
  1719. void werr(int errnum)
  1720. {
  1721. putlog(LOG_MISC, "*", STR("error #%d"), errnum);
  1722. sdprintf(STR("error translates to: %s"), werr_tostr(errnum));
  1723. printf(STR("(segmentation fault)\n"));
  1724. fatal("", 0);
  1725. }