users.c 32 KB

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