users.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  1. /*
  2. * users.c -- handles:
  3. * testing and enforcing ignores
  4. * adding and removing ignores
  5. * listing ignores
  6. * auto-linking bots
  7. * sending and receiving a userfile from a bot
  8. * listing users ('.whois' and '.match')
  9. * reading the user file
  10. *
  11. * dprintf'ized, 9nov1995
  12. *
  13. */
  14. #include "main.h"
  15. #include "users.h"
  16. #include "chan.h"
  17. #include "modules.h"
  18. #include "tandem.h"
  19. char natip[121] = "";
  20. #include <netinet/in.h>
  21. #include <arpa/inet.h>
  22. extern struct dcc_t *dcc;
  23. extern struct userrec *userlist, *lastuser;
  24. extern struct chanset_t *chanset;
  25. extern int dcc_total, noshare, egg_numver;
  26. extern char botnetnick[];
  27. extern Tcl_Interp *interp;
  28. extern time_t now;
  29. char userfile[121] = ""; /* where the user records are stored */
  30. int ignore_time = 10; /* how many minutes will ignores last? */
  31. /* is this nick!user@host being ignored? */
  32. int match_ignore(char *uhost)
  33. {
  34. struct igrec *ir;
  35. for (ir = global_ign; ir; ir = ir->next)
  36. if (wild_match(ir->igmask, uhost))
  37. return 1;
  38. return 0;
  39. }
  40. int equals_ignore(char *uhost)
  41. {
  42. struct igrec *u = global_ign;
  43. for (; u; u = u->next)
  44. if (!rfc_casecmp(u->igmask, uhost)) {
  45. if (u->flags & IGREC_PERM)
  46. return 2;
  47. else
  48. return 1;
  49. }
  50. return 0;
  51. }
  52. int delignore(char *ign)
  53. {
  54. int i, j;
  55. struct igrec **u;
  56. struct igrec *t;
  57. char temp[256];
  58. i = 0;
  59. if (!strchr(ign, '!') && (j = atoi(ign))) {
  60. for (u = &global_ign, j--; *u && j; u = &((*u)->next), j--);
  61. if (*u) {
  62. strncpyz(temp, (*u)->igmask, sizeof temp);
  63. i = 1;
  64. }
  65. } else {
  66. /* find the matching host, if there is one */
  67. for (u = &global_ign; *u && !i; u = &((*u)->next))
  68. if (!rfc_casecmp(ign, (*u)->igmask)) {
  69. strncpyz(temp, ign, sizeof temp);
  70. i = 1;
  71. break;
  72. }
  73. }
  74. if (i) {
  75. if (!noshare) {
  76. char *mask = str_escape(temp, ':', '\\');
  77. if (mask) {
  78. shareout(NULL, STR("-i %s\n"), mask);
  79. nfree(mask);
  80. }
  81. }
  82. nfree((*u)->igmask);
  83. if ((*u)->msg)
  84. nfree((*u)->msg);
  85. if ((*u)->user)
  86. nfree((*u)->user);
  87. t = *u;
  88. *u = (*u)->next;
  89. nfree(t);
  90. }
  91. return i;
  92. }
  93. void addignore(char *ign, char *from, char *mnote, time_t expire_time)
  94. {
  95. struct igrec *p = NULL, *l;
  96. for (l = global_ign; l; l = l->next)
  97. if (!rfc_casecmp(l->igmask, ign)) {
  98. p = l;
  99. break;
  100. }
  101. if (p == NULL) {
  102. p = user_malloc(sizeof(struct igrec));
  103. p->next = global_ign;
  104. global_ign = p;
  105. } else {
  106. nfree(p->igmask);
  107. nfree(p->user);
  108. nfree(p->msg);
  109. }
  110. p->expire = expire_time;
  111. p->added = now;
  112. p->flags = expire_time ? 0 : IGREC_PERM;
  113. p->igmask = user_malloc(strlen(ign) + 1);
  114. strcpy(p->igmask, ign);
  115. p->user = user_malloc(strlen(from) + 1);
  116. strcpy(p->user, from);
  117. p->msg = user_malloc(strlen(mnote) + 1);
  118. strcpy(p->msg, mnote);
  119. if (!noshare) {
  120. char *mask = str_escape(ign, ':', '\\');
  121. if (mask) {
  122. shareout(NULL, STR("+i %s %lu %c %s %s\n"), mask, expire_time - now,
  123. (p->flags & IGREC_PERM) ? 'p' : '-', from, mnote);
  124. nfree(mask);
  125. }
  126. }
  127. }
  128. /* take host entry from ignore list and display it ignore-style */
  129. void display_ignore(int idx, int number, struct igrec *ignore)
  130. {
  131. char dates[81], s[41];
  132. if (ignore->added) {
  133. daysago(now, ignore->added, s);
  134. sprintf(dates, STR("Started %s"), s);
  135. } else
  136. dates[0] = 0;
  137. if (ignore->flags & IGREC_PERM)
  138. strcpy(s, STR("(perm)"));
  139. else {
  140. char s1[41];
  141. days(ignore->expire, now, s1);
  142. sprintf(s, STR("(expires %s)"), s1);
  143. }
  144. if (number >= 0)
  145. dprintf(idx, STR(" [%3d] %s %s\n"), number, ignore->igmask, s);
  146. else
  147. dprintf(idx, STR("IGNORE: %s %s\n"), ignore->igmask, s);
  148. if (ignore->msg && ignore->msg[0])
  149. dprintf(idx, STR(" %s: %s\n"), ignore->user, ignore->msg);
  150. else
  151. dprintf(idx, STR(" %s %s\n"), MODES_PLACEDBY, ignore->user);
  152. if (dates[0])
  153. dprintf(idx, STR(" %s\n"), dates);
  154. }
  155. /* list the ignores and how long they've been active */
  156. void tell_ignores(int idx, char *match)
  157. {
  158. struct igrec *u = global_ign;
  159. int k = 1;
  160. if (u == NULL) {
  161. dprintf(idx, STR("No ignores.\n"));
  162. return;
  163. }
  164. dprintf(idx, STR("%s:\n"), IGN_CURRENT);
  165. for (; u; u = u->next) {
  166. if (match[0]) {
  167. if (wild_match(match, u->igmask) ||
  168. wild_match(match, u->msg) ||
  169. wild_match(match, u->user))
  170. display_ignore(idx, k, u);
  171. k++;
  172. } else
  173. display_ignore(idx, k++, u);
  174. }
  175. }
  176. /* check for expired timed-ignores */
  177. void check_expired_ignores()
  178. {
  179. struct igrec **u = &global_ign;
  180. if (!*u)
  181. return;
  182. while (*u) {
  183. if (!((*u)->flags & IGREC_PERM) && (now >= (*u)->expire)) {
  184. putlog(LOG_MISC, "*", STR("%s %s (%s)"), IGN_NOLONGER, (*u)->igmask,
  185. MISC_EXPIRED);
  186. delignore((*u)->igmask);
  187. } else {
  188. u = &((*u)->next);
  189. }
  190. }
  191. }
  192. /* Channel mask loaded from user file. This function is
  193. * add(ban|invite|exempt)_fully merged into one. <cybah>
  194. */
  195. static void addmask_fully(struct chanset_t *chan, maskrec **m, maskrec **global,
  196. char *mask, char *from,
  197. char *note, time_t expire_time, int flags,
  198. time_t added, time_t last)
  199. {
  200. maskrec *p = user_malloc(sizeof(maskrec));
  201. maskrec **u = (chan) ? m : global;
  202. p->next = *u;
  203. *u = p;
  204. p->expire = expire_time;
  205. p->added = added;
  206. p->lastactive = last;
  207. p->flags = flags;
  208. p->mask = user_malloc(strlen(mask) + 1);
  209. strcpy(p->mask, mask);
  210. p->user = user_malloc(strlen(from) + 1);
  211. strcpy(p->user, from);
  212. p->desc = user_malloc(strlen(note) + 1);
  213. strcpy(p->desc, note);
  214. }
  215. static void restore_chanban(struct chanset_t *chan, char *host)
  216. {
  217. char *expi, *add, *last, *user, *desc;
  218. int flags = 0;
  219. expi = strchr_unescape(host, ':', '\\');
  220. if (expi) {
  221. if (*expi == '+') {
  222. flags |= MASKREC_PERM;
  223. expi++;
  224. }
  225. add = strchr(expi, ':');
  226. if (add) {
  227. if (add[-1] == '*') {
  228. flags |= MASKREC_STICKY;
  229. add[-1] = 0;
  230. } else
  231. *add = 0;
  232. add++;
  233. if (*add == '+') {
  234. last = strchr(add, ':');
  235. if (last) {
  236. *last = 0;
  237. last++;
  238. user = strchr(last, ':');
  239. if (user) {
  240. *user = 0;
  241. user++;
  242. desc = strchr(user, ':');
  243. if (desc) {
  244. *desc = 0;
  245. desc++;
  246. addmask_fully(chan, &chan->bans, &global_bans, host, user,
  247. desc, atoi(expi), flags, atoi(add), atoi(last));
  248. return;
  249. }
  250. }
  251. }
  252. } else {
  253. desc = strchr(add, ':');
  254. if (desc) {
  255. *desc = 0;
  256. desc++;
  257. addmask_fully(chan, &chan->bans, &global_bans, host, add, desc,
  258. atoi(expi), flags, now, 0);
  259. return;
  260. }
  261. }
  262. }
  263. }
  264. putlog(LOG_MISC, "*", STR("*** Malformed banline for %s."),
  265. chan ? chan->dname : STR("global_bans"));
  266. }
  267. static void restore_chanexempt(struct chanset_t *chan, char *host)
  268. {
  269. char *expi, *add, *last, *user, *desc;
  270. int flags = 0;
  271. expi = strchr_unescape(host, ':', '\\');
  272. if (expi) {
  273. if (*expi == '+') {
  274. flags |= MASKREC_PERM;
  275. expi++;
  276. }
  277. add = strchr(expi, ':');
  278. if (add) {
  279. if (add[-1] == '*') {
  280. flags |= MASKREC_STICKY;
  281. add[-1] = 0;
  282. } else
  283. *add = 0;
  284. add++;
  285. if (*add == '+') {
  286. last = strchr(add, ':');
  287. if (last) {
  288. *last = 0;
  289. last++;
  290. user = strchr(last, ':');
  291. if (user) {
  292. *user = 0;
  293. user++;
  294. desc = strchr(user, ':');
  295. if (desc) {
  296. *desc = 0;
  297. desc++;
  298. addmask_fully(chan, &chan->exempts, &global_exempts, host, user,
  299. desc, atoi(expi), flags, atoi(add), atoi(last));
  300. return;
  301. }
  302. }
  303. }
  304. } else {
  305. desc = strchr(add, ':');
  306. if (desc) {
  307. *desc = 0;
  308. desc++;
  309. addmask_fully(chan, &chan->exempts, &global_exempts, host, add,
  310. desc, atoi(expi), flags, now, 0);
  311. return;
  312. }
  313. }
  314. }
  315. }
  316. putlog(LOG_MISC, "*", STR("*** Malformed exemptline for %s."),
  317. chan ? chan->dname : STR("global_exempts"));
  318. }
  319. static void restore_chaninvite(struct chanset_t *chan, char *host)
  320. {
  321. char *expi, *add, *last, *user, *desc;
  322. int flags = 0;
  323. expi = strchr_unescape(host, ':', '\\');
  324. if (expi) {
  325. if (*expi == '+') {
  326. flags |= MASKREC_PERM;
  327. expi++;
  328. }
  329. add = strchr(expi, ':');
  330. if (add) {
  331. if (add[-1] == '*') {
  332. flags |= MASKREC_STICKY;
  333. add[-1] = 0;
  334. } else
  335. *add = 0;
  336. add++;
  337. if (*add == '+') {
  338. last = strchr(add, ':');
  339. if (last) {
  340. *last = 0;
  341. last++;
  342. user = strchr(last, ':');
  343. if (user) {
  344. *user = 0;
  345. user++;
  346. desc = strchr(user, ':');
  347. if (desc) {
  348. *desc = 0;
  349. desc++;
  350. addmask_fully(chan, &chan->invites, &global_invites, host, user,
  351. desc, atoi(expi), flags, atoi(add), atoi(last));
  352. return;
  353. }
  354. }
  355. }
  356. } else {
  357. desc = strchr(add, ':');
  358. if (desc) {
  359. *desc = 0;
  360. desc++;
  361. addmask_fully(chan, &chan->invites, &global_invites, host, add,
  362. desc, atoi(expi), flags, now, 0);
  363. return;
  364. }
  365. }
  366. }
  367. }
  368. putlog(LOG_MISC, "*", STR("*** Malformed inviteline for %s."),
  369. chan ? chan->dname : STR("global_invites"));
  370. }
  371. static void restore_ignore(char *host)
  372. {
  373. char *expi, *user, *added, *desc;
  374. int flags = 0;
  375. struct igrec *p;
  376. expi = strchr_unescape(host, ':', '\\');
  377. if (expi) {
  378. if (*expi == '+') {
  379. flags |= IGREC_PERM;
  380. expi++;
  381. }
  382. user = strchr(expi, ':');
  383. if (user) {
  384. *user = 0;
  385. user++;
  386. added = strchr(user, ':');
  387. if (added) {
  388. *added = 0;
  389. added++;
  390. desc = strchr(added, ':');
  391. if (desc) {
  392. *desc = 0;
  393. desc++;
  394. } else
  395. desc = NULL;
  396. } else {
  397. added = "0";
  398. desc = NULL;
  399. }
  400. p = user_malloc(sizeof(struct igrec));
  401. p->next = global_ign;
  402. global_ign = p;
  403. p->expire = atoi(expi);
  404. p->added = atoi(added);
  405. p->flags = flags;
  406. p->igmask = user_malloc(strlen(host) + 1);
  407. strcpy(p->igmask, host);
  408. p->user = user_malloc(strlen(user) + 1);
  409. strcpy(p->user, user);
  410. if (desc) {
  411. p->msg = user_malloc(strlen(desc) + 1);
  412. strcpy(p->msg, desc);
  413. } else
  414. p->msg = NULL;
  415. return;
  416. }
  417. }
  418. putlog(LOG_MISC, "*", STR("*** Malformed ignore line."));
  419. }
  420. void tell_user(int idx, struct userrec *u, int master)
  421. {
  422. char s[81], s1[81];
  423. char format[81];
  424. int n;
  425. time_t now2;
  426. struct chanuserrec *ch;
  427. struct chanset_t *chan;
  428. struct user_entry *ue;
  429. struct laston_info *li;
  430. struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
  431. fr.global = u->flags;
  432. fr.udef_global = u->flags_udef;
  433. build_flags(s, &fr, NULL);
  434. Tcl_SetVar(interp, "user", u->handle, 0);
  435. n = 0;
  436. if (Tcl_VarEval(interp, "notes ", "$user", NULL) == TCL_OK)
  437. n = atoi(interp->result);
  438. li = get_user(&USERENTRY_LASTON, u);
  439. if (!li || !li->laston)
  440. strcpy(s1, "never");
  441. else {
  442. now2 = now - li->laston;
  443. if (now2 > 86400)
  444. #ifdef S_UTCTIME
  445. egg_strftime(s1, 7, "%d %b", gmtime(&li->laston));
  446. #else /* !S_UTCTIME */
  447. egg_strftime(s1, 7, "%d %b", localtime(&li->laston));
  448. #endif /* S_UTCTIME */
  449. else
  450. #ifdef S_UTCTIME
  451. egg_strftime(s1, 6, "%H:%M", gmtime(&li->laston));
  452. #else /* !S_UTCTIME */
  453. egg_strftime(s1, 6, "%H:%M", localtime(&li->laston));
  454. #endif /* S_UTCTIME */
  455. }
  456. egg_snprintf(format, sizeof format, "%%-%us %%-5s%%5d %%-15s %%s (%%-10.10s)",
  457. HANDLEN);
  458. dprintf(idx, format, u->handle,
  459. get_user(&USERENTRY_PASS, u) ? "yes" : "no", n, s, s1,
  460. (li && li->lastonplace) ? li->lastonplace : "nowhere");
  461. dprintf(idx, "\n");
  462. /* channel flags? */
  463. for (ch = u->chanrec; ch; ch = ch->next) {
  464. fr.match = FR_CHAN | FR_GLOBAL;
  465. chan = findchan_by_dname(ch->channel);
  466. get_user_flagrec(dcc[idx].user, &fr, ch->channel);
  467. if (!channel_private(chan) || (channel_private(chan) && (chan_op(fr) || glob_owner(fr)))) {
  468. if (glob_op(fr) || chan_op(fr)) {
  469. if (ch->laston == 0L)
  470. strcpy(s1, "never");
  471. else {
  472. now2 = now - (ch->laston);
  473. if (now2 > 86400)
  474. #ifdef S_UTCTIME
  475. egg_strftime(s1, 7, "%d %b", gmtime(&ch->laston));
  476. #else /* !S_UTCTIME */
  477. egg_strftime(s1, 7, "%d %b", localtime(&ch->laston));
  478. #endif /* S_UTCTIME */
  479. else
  480. #ifdef S_UTCTIME
  481. egg_strftime(s1, 6, "%H:%M", gmtime(&ch->laston));
  482. #else /* !S_UTCTIME */
  483. egg_strftime(s1, 6, "%H:%M", localtime(&ch->laston));
  484. #endif /* S_UTCTIME */
  485. }
  486. fr.match = FR_CHAN;
  487. fr.chan = ch->flags;
  488. fr.udef_chan = ch->flags_udef;
  489. build_flags(s, &fr, NULL);
  490. egg_snprintf(format, sizeof format, "%%%us %%-18s %%-15s %%s\n", HANDLEN-9);
  491. dprintf(idx, format, " ", ch->channel, s, s1);
  492. if (ch->info != NULL)
  493. dprintf(idx, " INFO: %s\n", ch->info);
  494. }
  495. }
  496. }
  497. /* user-defined extra fields */
  498. for (ue = u->entries; ue; ue = ue->next)
  499. if (!ue->name && ue->type->display)
  500. ue->type->display(idx, ue, u);
  501. }
  502. /* show user by ident */
  503. void tell_user_ident(int idx, char *id, int master)
  504. {
  505. char format[81];
  506. struct userrec *u;
  507. struct flag_record user = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  508. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  509. int noax = 0;
  510. get_user_flagrec(dcc[idx].user, &user, NULL);
  511. u = get_user_by_handle(userlist, id);
  512. if (u == NULL)
  513. u = get_user_by_host(id);
  514. if (u) {
  515. get_user_flagrec(u, &fr, NULL);
  516. if (glob_master(fr) && !glob_master(user)) { u = dcc[idx].user; noax = 1; }
  517. else if (glob_owner(fr) && !glob_owner(user)) { u = dcc[idx].user; noax = 1; }
  518. else if (glob_admin(fr) && !glob_admin(user)) { u = dcc[idx].user; noax = 1; }
  519. else if (glob_bot(fr) && !glob_master(user)) { u = dcc[idx].user; noax = 1; }
  520. }
  521. if (u == NULL || noax) {
  522. dprintf(idx, "%s.\n", USERF_NOMATCH);
  523. return;
  524. }
  525. egg_snprintf(format, sizeof format, STR("%%-%us PASS NOTES FLAGS LAST\n"),
  526. HANDLEN);
  527. dprintf(idx, format, STR("HANDLE"));
  528. tell_user(idx, u, master);
  529. }
  530. /* match string:
  531. * wildcard to match nickname or hostmasks
  532. * +attr to find all with attr */
  533. void tell_users_match(int idx, char *mtch, int start, int limit,
  534. int master, char *chname)
  535. {
  536. char format[81];
  537. struct userrec *u;
  538. int fnd = 0, cnt, nomns = 0, flags = 0;
  539. struct list_type *q;
  540. struct flag_record user, pls, mns;
  541. dprintf(idx, STR("*** %s '%s':\n"), MISC_MATCHING, mtch);
  542. cnt = 0;
  543. egg_snprintf(format, sizeof format, STR("%%-%us PASS NOTES FLAGS LAST\n"),
  544. HANDLEN);
  545. dprintf(idx, format, STR("HANDLE"));
  546. if (start > 1)
  547. dprintf(idx, STR("(%s %d)\n"), MISC_SKIPPING, start - 1);
  548. if (strchr("+-&|", *mtch)) {
  549. user.match = pls.match = FR_GLOBAL | FR_BOT | FR_CHAN;
  550. break_down_flags(mtch, &pls, &mns);
  551. mns.match = pls.match ^ (FR_AND | FR_OR);
  552. if (!mns.global && !mns.udef_global && !mns.chan && !mns.udef_chan &&
  553. !mns.bot) {
  554. nomns = 1;
  555. if (!pls.global && !pls.udef_global && !pls.chan && !pls.udef_chan &&
  556. !pls.bot) {
  557. /* happy now BB you weenie :P */
  558. dprintf(idx, STR("Unknown flag specified for matching!!\n"));
  559. return;
  560. }
  561. }
  562. if (!chname || !chname[0])
  563. chname = dcc[idx].u.chat->con_chan;
  564. flags = 1;
  565. }
  566. for (u = userlist; u; u = u->next) {
  567. if (flags) {
  568. get_user_flagrec(u, &user, chname);
  569. if (flagrec_eq(&pls, &user)) {
  570. if (nomns || !flagrec_eq(&mns, &user)) {
  571. cnt++;
  572. if ((cnt <= limit) && (cnt >= start))
  573. tell_user(idx, u, master);
  574. if (cnt == limit + 1)
  575. dprintf(idx, MISC_TRUNCATED, limit);
  576. }
  577. }
  578. } else if (wild_match(mtch, u->handle)) {
  579. cnt++;
  580. if ((cnt <= limit) && (cnt >= start))
  581. tell_user(idx, u, master);
  582. if (cnt == limit + 1)
  583. dprintf(idx, MISC_TRUNCATED, limit);
  584. } else {
  585. fnd = 0;
  586. for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next) {
  587. if ((wild_match(mtch, q->extra)) && (!fnd)) {
  588. cnt++;
  589. fnd = 1;
  590. if ((cnt <= limit) && (cnt >= start)) {
  591. tell_user(idx, u, master);
  592. }
  593. if (cnt == limit + 1)
  594. dprintf(idx, MISC_TRUNCATED, limit);
  595. }
  596. }
  597. }
  598. }
  599. dprintf(idx, MISC_FOUNDMATCH, cnt, cnt == 1 ? "" : MISC_MATCH_PLURAL);
  600. }
  601. /*
  602. * tagged lines in the user file:
  603. * * OLD:
  604. * # (comment)
  605. * ; (comment)
  606. * - hostmask(s)
  607. * + email
  608. * * dcc directory
  609. * = comment
  610. * : info line
  611. * . xtra (Tcl)
  612. * ! channel-specific
  613. * !! global laston
  614. * :: channel-specific bans
  615. * NEW:
  616. * *ban global bans
  617. * *ignore global ignores
  618. * ::#chan channel bans
  619. * - entries in each
  620. * + denotes tcl command
  621. * <handle> begin user entry
  622. * --KEY INFO - info on each
  623. * NEWER:
  624. * % exemptmask(s)
  625. * @ Invitemask(s)
  626. * *exempt global exempts
  627. * *Invite global Invites
  628. * && channel-specific exempts
  629. * &&#chan channel exempts
  630. * $$ channel-specific Invites
  631. * $$#chan channel Invites
  632. */
  633. int readuserfile(char *file, struct userrec **ret)
  634. {
  635. char *p, buf[1024], lasthand[512], *attr, *pass, *code, s1[1024], *s, cbuf[1024], *temps;
  636. FILE *f;
  637. struct userrec *bu, *u = NULL;
  638. struct chanset_t *cst = NULL;
  639. int i, line = 0;
  640. char ignored[512];
  641. struct flag_record fr;
  642. struct chanuserrec *cr;
  643. bu = (*ret);
  644. ignored[0] = 0;
  645. if (bu == userlist) {
  646. clear_chanlist();
  647. lastuser = NULL;
  648. global_bans = NULL;
  649. global_ign = NULL;
  650. global_exempts = NULL;
  651. global_invites = NULL;
  652. }
  653. lasthand[0] = 0;
  654. f = fopen(file, "r");
  655. if (f == NULL)
  656. return 0;
  657. noshare = 1;
  658. /* read opening comment */
  659. s = buf;
  660. fgets(cbuf, 180, f);
  661. temps = (char *) decrypt_string(SALT1, cbuf);
  662. egg_snprintf(s, 180, temps);
  663. nfree(temps);
  664. if (s[1] < '4') {
  665. fatal(USERF_OLDFMT, 0);
  666. }
  667. if (s[1] > '4')
  668. fatal(USERF_INVALID, 0);
  669. while (!feof(f)) {
  670. s = buf;
  671. fgets(cbuf, 1024, f);
  672. temps = (char *) decrypt_string(SALT1, cbuf);
  673. egg_snprintf(s, 1024, temps);
  674. nfree(temps);
  675. if (!feof(f)) {
  676. line++;
  677. if (s[0] != '#' && s[0] != ';' && s[0]) {
  678. code = newsplit(&s);
  679. rmspace(s);
  680. if (!strcmp(code, "-")) {
  681. if (!lasthand[0])
  682. continue; /* Skip this entry. */
  683. if (u) { /* only break it down if there a real users */
  684. p = strchr(s, ',');
  685. while (p != NULL) {
  686. splitc(s1, s, ',');
  687. rmspace(s1);
  688. if (s1[0])
  689. set_user(&USERENTRY_HOSTS, u, s1);
  690. p = strchr(s, ',');
  691. }
  692. }
  693. /* channel bans are never stacked with , */
  694. if (s[0]) {
  695. if (lasthand[0] && strchr(CHANMETA, lasthand[0]) != NULL)
  696. restore_chanban(cst, s);
  697. else if (lasthand[0] == '*') {
  698. if (lasthand[1] == IGNORE_NAME[1])
  699. restore_ignore(s);
  700. #ifdef S_DCCPASS
  701. else if (lasthand[1] == CONFIG_NAME[1]) {
  702. set_cmd_pass(s, 1);
  703. }
  704. #endif /* S_DCCPASS */
  705. else
  706. restore_chanban(NULL, s);
  707. } else if (lasthand[0])
  708. set_user(&USERENTRY_HOSTS, u, s);
  709. }
  710. } else if (!strcmp(code, "%")) { /* exemptmasks */
  711. if (!lasthand[0])
  712. continue; /* Skip this entry. */
  713. if (s[0]) {
  714. if (lasthand[0] == '#' || lasthand[0] == '+')
  715. restore_chanexempt(cst,s);
  716. else if (lasthand[0] == '*')
  717. if (lasthand[1] == EXEMPT_NAME[1])
  718. restore_chanexempt(NULL, s);
  719. }
  720. } else if (!strcmp(code, "@")) { /* Invitemasks */
  721. if (!lasthand[0])
  722. continue; /* Skip this entry. */
  723. if (s[0]) {
  724. if (lasthand[0] == '#' || lasthand[0] == '+') {
  725. restore_chaninvite(cst,s);
  726. } else if (lasthand[0] == '*') {
  727. if (lasthand[1] == INVITE_NAME[1]) {
  728. restore_chaninvite(NULL, s);
  729. } else if (lasthand[1] == CONFIG_NAME[1]) {
  730. userfile_cfg_line(s);
  731. }
  732. }
  733. }
  734. } else if (!strcmp(code, "!")) {
  735. /* ! #chan laston flags [info] */
  736. char *chname, *st, *fl;
  737. if (u) {
  738. chname = newsplit(&s);
  739. st = newsplit(&s);
  740. fl = newsplit(&s);
  741. rmspace(s);
  742. fr.match = FR_CHAN;
  743. break_down_flags(fl, &fr, 0);
  744. if (findchan_by_dname(chname)) {
  745. for (cr = u->chanrec; cr; cr = cr->next)
  746. if (!rfc_casecmp(cr->channel, chname))
  747. break;
  748. if (!cr) {
  749. cr = (struct chanuserrec *)
  750. user_malloc(sizeof(struct chanuserrec));
  751. cr->next = u->chanrec;
  752. u->chanrec = cr;
  753. strncpyz(cr->channel, chname, 80);
  754. cr->laston = atoi(st);
  755. cr->flags = fr.chan;
  756. cr->flags_udef = fr.udef_chan;
  757. if (s[0]) {
  758. cr->info = (char *) user_malloc(strlen(s) + 1);
  759. strcpy(cr->info, s);
  760. } else
  761. cr->info = NULL;
  762. }
  763. }
  764. }
  765. } else if (!strcmp(code, "+")) {
  766. if (s[0] && lasthand[0] == '*' && lasthand[1] == CHANS_NAME[1]) {
  767. if (Tcl_Eval(interp, s) != TCL_OK) {
  768. putlog(LOG_MISC, "*", "Tcl error in userfile on line %d", line);
  769. putlog(LOG_MISC, "*", "%s", Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY));
  770. return 0;
  771. }
  772. }
  773. } else if (!strncmp(code, "::", 2)) {
  774. /* channel-specific bans */
  775. strcpy(lasthand, &code[2]);
  776. u = NULL;
  777. if (!findchan_by_dname(lasthand)) {
  778. strcpy(s1, lasthand);
  779. strcat(s1, " ");
  780. if (strstr(ignored, s1) == NULL) {
  781. strcat(ignored, lasthand);
  782. strcat(ignored, " ");
  783. }
  784. lasthand[0] = 0;
  785. } else {
  786. /* Remove all bans for this channel to avoid dupes */
  787. /* NOTE only remove bans for when getting a userfile
  788. * from another bot & that channel is shared */
  789. cst = findchan_by_dname(lasthand);
  790. if ((*ret == userlist) || channel_shared(cst)) {
  791. clear_masks(cst->bans);
  792. cst->bans = NULL;
  793. } else {
  794. /* otherwise ignore any bans for this channel */
  795. cst = NULL;
  796. lasthand[0] = 0;
  797. }
  798. }
  799. } else if (!strncmp(code, "&&", 2)) {
  800. /* channel-specific exempts */
  801. strcpy(lasthand, &code[2]);
  802. u = NULL;
  803. if (!findchan_by_dname(lasthand)) {
  804. strcpy(s1, lasthand);
  805. strcat(s1, " ");
  806. if (strstr(ignored, s1) == NULL) {
  807. strcat(ignored, lasthand);
  808. strcat(ignored, " ");
  809. }
  810. lasthand[0] = 0;
  811. } else {
  812. /* Remove all exempts for this channel to avoid dupes */
  813. /* NOTE only remove exempts for when getting a userfile
  814. * from another bot & that channel is shared */
  815. cst = findchan_by_dname(lasthand);
  816. if ((*ret == userlist) || channel_shared(cst)) {
  817. clear_masks(cst->exempts);
  818. cst->exempts = NULL;
  819. } else {
  820. /* otherwise ignore any exempts for this channel */
  821. cst = NULL;
  822. lasthand[0] = 0;
  823. }
  824. }
  825. } else if (!strncmp(code, "$$", 2)) {
  826. /* channel-specific invites */
  827. strcpy(lasthand, &code[2]);
  828. u = NULL;
  829. if (!findchan_by_dname(lasthand)) {
  830. strcpy(s1, lasthand);
  831. strcat(s1, " ");
  832. if (strstr(ignored, s1) == NULL) {
  833. strcat(ignored, lasthand);
  834. strcat(ignored, " ");
  835. }
  836. lasthand[0] = 0;
  837. } else {
  838. /* Remove all invites for this channel to avoid dupes */
  839. /* NOTE only remove invites for when getting a userfile
  840. * from another bot & that channel is shared */
  841. cst = findchan_by_dname(lasthand);
  842. if ((*ret == userlist) || channel_shared(cst)) {
  843. clear_masks(cst->invites);
  844. cst->invites = NULL;
  845. } else {
  846. /* otherwise ignore any invites for this channel */
  847. cst = NULL;
  848. lasthand[0] = 0;
  849. }
  850. }
  851. } else if (!strncmp(code, "--", 2)) {
  852. Context;
  853. if (u) {
  854. /* new format storage */
  855. struct user_entry *ue;
  856. int ok = 0;
  857. for (ue = u->entries; ue && !ok; ue = ue->next)
  858. if (ue->name && !egg_strcasecmp(code + 2, ue->name)) {
  859. struct list_type *list;
  860. list = user_malloc(sizeof(struct list_type));
  861. list->next = NULL;
  862. list->extra = user_malloc(strlen(s) + 1);
  863. strcpy(list->extra, s);
  864. list_append((&ue->u.list), list);
  865. ok = 1;
  866. }
  867. if (!ok) {
  868. ue = user_malloc(sizeof(struct user_entry));
  869. ue->name = user_malloc(strlen(code + 1));
  870. ue->type = NULL;
  871. strcpy(ue->name, code + 2);
  872. ue->u.list = user_malloc(sizeof(struct list_type));
  873. ue->u.list->next = NULL;
  874. ue->u.list->extra = user_malloc(strlen(s) + 1);
  875. strcpy(ue->u.list->extra, s);
  876. list_insert((&u->entries), ue);
  877. }
  878. }
  879. } else if (!rfc_casecmp(code, BAN_NAME)) {
  880. strcpy(lasthand, code);
  881. u = NULL;
  882. } else if (!rfc_casecmp(code, IGNORE_NAME)) {
  883. strcpy(lasthand, code);
  884. u = NULL;
  885. } else if (!rfc_casecmp(code, EXEMPT_NAME)) {
  886. strcpy(lasthand, code);
  887. u = NULL;
  888. } else if (!rfc_casecmp(code, INVITE_NAME)) {
  889. strcpy(lasthand, code);
  890. u = NULL;
  891. } else if (!rfc_casecmp(code, CHANS_NAME)) {
  892. strcpy(lasthand, code);
  893. u = NULL;
  894. } else if (!rfc_casecmp(code, CONFIG_NAME)) {
  895. strcpy(lasthand, code);
  896. u = NULL;
  897. } else if (code[0] == '*') {
  898. lasthand[0] = 0;
  899. u = NULL;
  900. } else {
  901. pass = newsplit(&s);
  902. attr = newsplit(&s);
  903. rmspace(s);
  904. Context;
  905. if (!attr[0] || !pass[0]) {
  906. putlog(LOG_MISC, "*", "* %s line: %d!", USERF_CORRUPT, line);
  907. lasthand[0] = 0;
  908. return 0;
  909. } else {
  910. u = get_user_by_handle(bu, code);
  911. if (u && !(u->flags & USER_UNSHARED)) {
  912. putlog(LOG_ERROR, "@", "* %s '%s'!", USERF_DUPE, code);
  913. lasthand[0] = 0;
  914. u = NULL;
  915. } else if (u) {
  916. lasthand[0] = 0;
  917. u = NULL;
  918. } else {
  919. fr.match = FR_GLOBAL;
  920. break_down_flags(attr, &fr, 0);
  921. strcpy(lasthand, code);
  922. cst = NULL;
  923. if (strlen(code) > HANDLEN)
  924. code[HANDLEN] = 0;
  925. if (strlen(pass) > 20) {
  926. putlog(LOG_MISC, "*", "* %s '%s'", USERF_BROKEPASS, code);
  927. strcpy(pass, "-");
  928. }
  929. bu = adduser(bu, code, 0, pass,
  930. sanity_check(fr.global &USER_VALID));
  931. u = get_user_by_handle(bu, code);
  932. for (i = 0; i < dcc_total; i++)
  933. if (!egg_strcasecmp(code, dcc[i].nick))
  934. dcc[i].user = u;
  935. u->flags_udef = fr.udef_global;
  936. /* if s starts with '/' it's got file info */
  937. }
  938. }
  939. }
  940. }
  941. }
  942. }
  943. fclose(f);
  944. (*ret) = bu;
  945. if (ignored[0]) {
  946. putlog(LOG_MISC, "*", "%s %s", USERF_IGNBANS, ignored);
  947. }
  948. putlog(LOG_MISC, "*", "Userfile loaded, unpacking...");
  949. for (u = bu; u; u = u->next) {
  950. struct user_entry *e;
  951. if (!(u->flags & USER_BOT) && !egg_strcasecmp (u->handle, botnetnick)) {
  952. putlog(LOG_MISC, "*", "(!) I have a user record, but without +b");
  953. /* u->flags |= USER_BOT; */
  954. }
  955. for (e = u->entries; e; e = e->next)
  956. if (e->name) {
  957. struct user_entry_type *uet = find_entry_type(e->name);
  958. if (uet) {
  959. e->type = uet;
  960. uet->unpack(u, e);
  961. nfree(e->name);
  962. e->name = NULL;
  963. }
  964. }
  965. }
  966. /* process the user data *now* */
  967. #ifdef LEAF
  968. unlink(userfile);
  969. #endif /* LEAF */
  970. noshare = 0;
  971. return 1;
  972. }
  973. /* New methodology - cycle through list 3 times
  974. * 1st time scan for +sh bots and link if none connected
  975. * 2nd time scan for +h bots
  976. * 3rd time scan for +a/+h bots */
  977. void link_pref_val(struct userrec *u, char *val)
  978. {
  979. /* val must be HANDLEN + 4 chars minimum */
  980. struct bot_addr *ba;
  981. val[0] = 'Z';
  982. val[1] = 0;
  983. if (!u)
  984. return;
  985. if (!(u->flags & USER_BOT))
  986. return;
  987. ba = get_user(&USERENTRY_BOTADDR, u);
  988. if (!ba)
  989. return;
  990. if (!ba->hublevel)
  991. return;
  992. sprintf(val, STR("%02d%s"), ba->hublevel, u->handle);
  993. }
  994. struct userrec *next_hub(struct userrec *current, char *lowval, char *highval)
  995. {
  996. /*
  997. starting at "current" or "userlist" if NULL, find next bot with a
  998. link_pref_val higher than "lowval" and lower than "highval"
  999. If none found return bot with best overall link_pref_val
  1000. If still not found return NULL
  1001. */
  1002. char thisval[NICKLEN + 4],
  1003. bestmatchval[NICKLEN + 4] = "z",
  1004. bestallval[NICKLEN + 4] = "z";
  1005. struct userrec *cur = NULL,
  1006. *bestmatch = NULL,
  1007. *bestall = NULL;
  1008. if (current)
  1009. cur = current->next;
  1010. else
  1011. cur = userlist;
  1012. while (cur != current) {
  1013. if (!cur)
  1014. cur = userlist;
  1015. if (cur == current)
  1016. break;
  1017. if ((cur->flags & USER_BOT) && (strcmp(cur->handle, botnetnick))) {
  1018. link_pref_val(cur, thisval);
  1019. if ((strcmp(thisval, lowval) < 0) && (strcmp(thisval, highval) > 0) &&(strcmp(thisval, bestmatchval) < 0)) {
  1020. strcpy(bestmatchval, thisval);
  1021. bestmatch = cur;
  1022. }
  1023. if ((strcmp(thisval, lowval) < 0)
  1024. && (strcmp(thisval, bestallval) < 0)) {
  1025. strcpy(bestallval, thisval);
  1026. bestall = cur;
  1027. }
  1028. }
  1029. cur = cur->next;
  1030. }
  1031. if (bestmatch)
  1032. return bestmatch;
  1033. if (bestall)
  1034. return bestall;
  1035. return NULL;
  1036. }
  1037. #ifdef HUB
  1038. void autolink_cycle(char *start)
  1039. {
  1040. struct userrec *u = NULL;
  1041. int i;
  1042. char bestval[HANDLEN + 4],
  1043. curval[HANDLEN + 4],
  1044. myval[HANDLEN + 4];
  1045. u = get_user_by_handle(userlist, botnetnick);
  1046. link_pref_val(u, myval);
  1047. strcpy(bestval, myval);
  1048. for (i = 0; i < dcc_total; i++) {
  1049. if (dcc[i].type == &DCC_BOT_NEW)
  1050. return;
  1051. if (dcc[i].type == &DCC_FORK_BOT)
  1052. return;
  1053. if (dcc[i].type == &DCC_BOT) {
  1054. if (dcc[i].status & (STAT_OFFEREDU | STAT_GETTINGU | STAT_SENDINGU))
  1055. continue; //lets let the binary have it's peace.
  1056. if (dcc[i].u.bot->numver != egg_numver)
  1057. continue; //same thing.
  1058. if (dcc[i].status & (STAT_SHARE | STAT_OFFERED | STAT_SENDING | STAT_GETTING)) {
  1059. link_pref_val(dcc[i].user, curval);
  1060. if (strcmp(myval, curval) < 0) {
  1061. /* I should be aggressive to this one */
  1062. if (dcc[i].status & STAT_AGGRESSIVE) {
  1063. putlog(LOG_MISC, "*", STR("Passively sharing with %s but should be aggressive"), dcc[i].user->handle);
  1064. putlog(LOG_DEBUG, "*", STR("My linkval: %s - %s linkval: %s"), myval, dcc[i].nick, curval);
  1065. botunlink(-2, dcc[i].nick, STR("Marked passive, should be aggressive"));
  1066. return;
  1067. }
  1068. } else {
  1069. /* I should be passive to this one */
  1070. if (!(dcc[i].status & STAT_AGGRESSIVE)) {
  1071. putlog(LOG_MISC, "*", STR("Aggressively sharing with %s but should be passive"), dcc[i].user->handle);
  1072. putlog(LOG_DEBUG, "*", STR("My linkval: %s - %s linkval: %s"), myval, dcc[i].nick, curval);
  1073. botunlink(-2, dcc[i].nick, STR("Marked aggressive, should be passive"));
  1074. return;
  1075. }
  1076. if (strcmp(curval, bestval) < 0)
  1077. strcpy(bestval, curval);
  1078. }
  1079. } else {
  1080. botunlink(-2, dcc[i].nick, STR("Linked but not sharing?"));
  1081. }
  1082. }
  1083. }
  1084. if (start)
  1085. u = get_user_by_handle(userlist, start);
  1086. else
  1087. u = NULL;
  1088. if (u) {
  1089. link_pref_val(u, curval);
  1090. if (strcmp(bestval, curval) < 0) {
  1091. /* This shouldn't happen. Getting a failed link attempt (start!=NULL)
  1092. while a dcc scan indicates we *are* connected to a better bot than
  1093. the one we failed a link to.
  1094. */
  1095. putlog(LOG_BOTS, "*", STR("Failed link attempt to %s but connected to %s already???"), u->handle, (char *) &bestval[3]);
  1096. return;
  1097. }
  1098. } else
  1099. strcpy(curval, "0");
  1100. u = next_hub(u, bestval, curval);
  1101. if ((u) && (!in_chain(u->handle)))
  1102. botlink("", -3, u->handle);
  1103. }
  1104. #endif /* HUB */
  1105. #ifdef LEAF
  1106. typedef struct hublist_entry {
  1107. struct hublist_entry *next;
  1108. struct userrec *u;
  1109. } tag_hublist_entry;
  1110. int botlinkcount = 0;
  1111. void autolink_cycle(char *start)
  1112. {
  1113. struct userrec *my_u = NULL, *u = NULL;
  1114. struct hublist_entry *hl = NULL, *hl2 = NULL;
  1115. struct bot_addr *my_ba;
  1116. char uplink[HANDLEN + 1], avoidbot[HANDLEN + 1], curhub[HANDLEN + 1];
  1117. int i, hlc;
  1118. struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
  1119. /* Reset connection attempts if we ain't called due to a failed link */
  1120. if (!start)
  1121. botlinkcount = 0;
  1122. my_u = get_user_by_handle(userlist, botnetnick);
  1123. my_ba = get_user(&USERENTRY_BOTADDR, my_u);
  1124. if (my_ba && (my_ba->uplink[0])) {
  1125. strncpyz(uplink, my_ba->uplink, sizeof(uplink));
  1126. } else {
  1127. uplink[0] = 0;
  1128. }
  1129. curhub[0] = 0;
  1130. for (i = 0; i < dcc_total; i++) {
  1131. if ((dcc[i].type == &DCC_BOT_NEW) || (dcc[i].type == &DCC_FORK_BOT))
  1132. return;
  1133. if (dcc[i].type == &DCC_BOT) {
  1134. strcpy(curhub, dcc[i].nick);
  1135. break;
  1136. }
  1137. }
  1138. if (curhub[0]) {
  1139. /* we are linked to a bot (hub) */
  1140. if (uplink[0] && !strcmp(curhub, uplink))
  1141. /* Connected to uplink, nothing more to do */
  1142. return;
  1143. if (start)
  1144. /* Failed a link... let's just wait for next regular call */
  1145. return;
  1146. if (uplink[0]) {
  1147. /* Trying the uplink */
  1148. botlink("", -3, uplink);
  1149. return;
  1150. }
  1151. /* we got a hub currently, and no set uplink. Stay here */
  1152. return;
  1153. } else {
  1154. /* no hubs connected... pick one */
  1155. if (!start) {
  1156. /* Regular interval call, no previous failed link */
  1157. if (uplink[0]) {
  1158. /* We have a set uplink, try it */
  1159. botlink("", -3, uplink);
  1160. return;
  1161. }
  1162. /* No preferred uplink, we need a random bot */
  1163. avoidbot[0] = 0;
  1164. } else {
  1165. /* We got a failed link... */
  1166. botlinkcount++;
  1167. if (botlinkcount >= 3)
  1168. /* tried 3+ random hubs without success, wait for next regular interval call */
  1169. return;
  1170. /* We need a random bot but *not* the last we tried */
  1171. strcpy(avoidbot, start);
  1172. }
  1173. }
  1174. /* Pick a random hub, but avoid 'avoidbot' */
  1175. hlc = 0;
  1176. for (u = userlist; u; u = u->next) {
  1177. get_user_flagrec(u, &fr, NULL);
  1178. if (glob_bot(fr) && strcmp(u->handle, botnetnick) && strcmp(u->handle, avoidbot) && (bot_hublevel(u) < 999)) {
  1179. putlog(LOG_DEBUG, "@", STR("Adding %s to hublist"), u->handle);
  1180. hl2 = hl;
  1181. hl = user_malloc(sizeof(struct hublist_entry));
  1182. egg_bzero(hl, sizeof(struct hublist_entry));
  1183. hl->next = hl2;
  1184. hlc++;
  1185. hl->u = u;
  1186. }
  1187. }
  1188. putlog(LOG_DEBUG, "@", STR("Picking random hub from %d hubs"), hlc);
  1189. hlc = random() % hlc;
  1190. putlog(LOG_DEBUG, "@", STR("Picked #%d for hub"), hlc);
  1191. while (hl) {
  1192. if (!hlc) {
  1193. putlog(LOG_DEBUG, "@", STR("Which is bot: %s"), hl->u->handle);
  1194. botlink("", -3, hl->u->handle);
  1195. }
  1196. hlc--;
  1197. hl2 = hl->next;
  1198. nfree(hl);
  1199. hl = hl2;
  1200. }
  1201. }
  1202. #endif /* LEAF */