users.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  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, norestruct;
  26. extern char botnetnick[], netpass[];
  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. egg_strftime(s1, 7, "%d %b", localtime(&li->laston));
  445. else
  446. egg_strftime(s1, 6, "%H:%M", localtime(&li->laston));
  447. }
  448. egg_snprintf(format, sizeof format, "%%-%us %%-5s%%5d %%-15s %%s (%%-10.10s)",
  449. HANDLEN);
  450. dprintf(idx, format, u->handle,
  451. get_user(&USERENTRY_PASS, u) ? "yes" : "no", n, s, s1,
  452. (li && li->lastonplace) ? li->lastonplace : "nowhere");
  453. dprintf(idx, "\n");
  454. /* channel flags? */
  455. for (ch = u->chanrec; ch; ch = ch->next) {
  456. fr.match = FR_CHAN | FR_GLOBAL;
  457. chan = findchan_by_dname(ch->channel);
  458. get_user_flagrec(dcc[idx].user, &fr, ch->channel);
  459. if (!channel_private(chan) || (channel_private(chan) && (chan_op(fr) || glob_owner(fr)))) {
  460. if (glob_op(fr) || chan_op(fr)) {
  461. if (ch->laston == 0L)
  462. strcpy(s1, "never");
  463. else {
  464. now2 = now - (ch->laston);
  465. if (now2 > 86400)
  466. egg_strftime(s1, 7, "%d %b", localtime(&ch->laston));
  467. else
  468. egg_strftime(s1, 6, "%H:%M", localtime(&ch->laston));
  469. }
  470. fr.match = FR_CHAN;
  471. fr.chan = ch->flags;
  472. fr.udef_chan = ch->flags_udef;
  473. build_flags(s, &fr, NULL);
  474. egg_snprintf(format, sizeof format, "%%%us %%-18s %%-15s %%s\n", HANDLEN-9);
  475. dprintf(idx, format, " ", ch->channel, s, s1);
  476. if (ch->info != NULL)
  477. dprintf(idx, " INFO: %s\n", ch->info);
  478. }
  479. }
  480. }
  481. /* user-defined extra fields */
  482. for (ue = u->entries; ue; ue = ue->next)
  483. if (!ue->name && ue->type->display)
  484. ue->type->display(idx, ue, u);
  485. }
  486. /* show user by ident */
  487. void tell_user_ident(int idx, char *id, int master)
  488. {
  489. char format[81];
  490. struct userrec *u;
  491. struct flag_record user = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  492. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  493. int noax = 0;
  494. get_user_flagrec(dcc[idx].user, &user, NULL);
  495. u = get_user_by_handle(userlist, id);
  496. if (u == NULL)
  497. u = get_user_by_host(id);
  498. if (u) {
  499. get_user_flagrec(u, &fr, NULL);
  500. if (glob_master(fr) && !glob_master(user)) { u = dcc[idx].user; noax = 1; }
  501. else if (glob_owner(fr) && !glob_owner(user)) { u = dcc[idx].user; noax = 1; }
  502. else if (glob_admin(fr) && !glob_admin(user)) { u = dcc[idx].user; noax = 1; }
  503. else if (glob_bot(fr) && !glob_master(user)) { u = dcc[idx].user; noax = 1; }
  504. }
  505. if (u == NULL || noax) {
  506. dprintf(idx, "%s.\n", USERF_NOMATCH);
  507. return;
  508. }
  509. egg_snprintf(format, sizeof format, STR("%%-%us PASS NOTES FLAGS LAST\n"),
  510. HANDLEN);
  511. dprintf(idx, format, STR("HANDLE"));
  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,
  518. int master, char *chname)
  519. {
  520. char format[81];
  521. struct userrec *u;
  522. int fnd = 0, cnt, nomns = 0, flags = 0;
  523. struct list_type *q;
  524. struct flag_record user, pls, mns;
  525. dprintf(idx, STR("*** %s '%s':\n"), MISC_MATCHING, mtch);
  526. cnt = 0;
  527. egg_snprintf(format, sizeof format, STR("%%-%us PASS NOTES FLAGS LAST\n"),
  528. HANDLEN);
  529. dprintf(idx, format, STR("HANDLE"));
  530. if (start > 1)
  531. dprintf(idx, STR("(%s %d)\n"), MISC_SKIPPING, start - 1);
  532. if (strchr("+-&|", *mtch)) {
  533. user.match = pls.match = FR_GLOBAL | FR_BOT | FR_CHAN;
  534. break_down_flags(mtch, &pls, &mns);
  535. mns.match = pls.match ^ (FR_AND | FR_OR);
  536. if (!mns.global && !mns.udef_global && !mns.chan && !mns.udef_chan &&
  537. !mns.bot) {
  538. nomns = 1;
  539. if (!pls.global && !pls.udef_global && !pls.chan && !pls.udef_chan &&
  540. !pls.bot) {
  541. /* happy now BB you weenie :P */
  542. dprintf(idx, STR("Unknown flag specified for matching!!\n"));
  543. return;
  544. }
  545. }
  546. if (!chname || !chname[0])
  547. chname = dcc[idx].u.chat->con_chan;
  548. flags = 1;
  549. }
  550. for (u = userlist; u; u = u->next) {
  551. if (flags) {
  552. get_user_flagrec(u, &user, chname);
  553. if (flagrec_eq(&pls, &user)) {
  554. if (nomns || !flagrec_eq(&mns, &user)) {
  555. cnt++;
  556. if ((cnt <= limit) && (cnt >= start))
  557. tell_user(idx, u, master);
  558. if (cnt == limit + 1)
  559. dprintf(idx, MISC_TRUNCATED, limit);
  560. }
  561. }
  562. } else if (wild_match(mtch, u->handle)) {
  563. cnt++;
  564. if ((cnt <= limit) && (cnt >= start))
  565. tell_user(idx, u, master);
  566. if (cnt == limit + 1)
  567. dprintf(idx, MISC_TRUNCATED, limit);
  568. } else {
  569. fnd = 0;
  570. for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next) {
  571. if ((wild_match(mtch, q->extra)) && (!fnd)) {
  572. cnt++;
  573. fnd = 1;
  574. if ((cnt <= limit) && (cnt >= start)) {
  575. tell_user(idx, u, master);
  576. }
  577. if (cnt == limit + 1)
  578. dprintf(idx, MISC_TRUNCATED, limit);
  579. }
  580. }
  581. }
  582. }
  583. dprintf(idx, MISC_FOUNDMATCH, cnt, cnt == 1 ? "" : MISC_MATCH_PLURAL);
  584. }
  585. /*
  586. * tagged lines in the user file:
  587. * * OLD:
  588. * # (comment)
  589. * ; (comment)
  590. * - hostmask(s)
  591. * + email
  592. * * dcc directory
  593. * = comment
  594. * : info line
  595. * . xtra (Tcl)
  596. * ! channel-specific
  597. * !! global laston
  598. * :: channel-specific bans
  599. * NEW:
  600. * *ban global bans
  601. * *ignore global ignores
  602. * ::#chan channel bans
  603. * - entries in each
  604. * + denotes tcl command
  605. * <handle> begin user entry
  606. * --KEY INFO - info on each
  607. * NEWER:
  608. * % exemptmask(s)
  609. * @ Invitemask(s)
  610. * *exempt global exempts
  611. * *Invite global Invites
  612. * && channel-specific exempts
  613. * &&#chan channel exempts
  614. * $$ channel-specific Invites
  615. * $$#chan channel Invites
  616. */
  617. int readuserfile(char *file, struct userrec **ret)
  618. {
  619. char *p, buf[1024], lasthand[512], *attr, *pass, *code, s1[1024], *s, cbuf[1024], *temps;
  620. char *horesak;
  621. FILE *f;
  622. struct userrec *bu, *u = NULL;
  623. struct chanset_t *cst = NULL;
  624. int i;
  625. char ignored[512];
  626. struct flag_record fr;
  627. struct chanuserrec *cr;
  628. Context;
  629. bu = (*ret);
  630. ignored[0] = 0;
  631. if (bu == userlist) {
  632. clear_chanlist();
  633. lastuser = NULL;
  634. global_bans = NULL;
  635. global_ign = NULL;
  636. global_exempts = NULL;
  637. global_invites = NULL;
  638. }
  639. lasthand[0] = 0;
  640. f = fopen(file, "r");
  641. if (f == NULL)
  642. return 0;
  643. /* read opening comment */
  644. s = buf;
  645. fscanf(f, "%s\n", cbuf);
  646. horesak = decryptit(cbuf);
  647. temps = (char *) decrypt_string(netpass, horesak);
  648. snprintf(s, 1024, temps);
  649. nfree(temps);
  650. if (s[1] < '4') {
  651. fatal(USERF_OLDFMT, 0);
  652. }
  653. if (s[1] > '4')
  654. fatal(USERF_INVALID, 0);
  655. while (!feof(f)) {
  656. s = buf;
  657. fscanf(f, "%s\n", cbuf);
  658. horesak = decryptit(cbuf);
  659. temps = (char *) decrypt_string(netpass, horesak);
  660. snprintf(s, 1024, temps);
  661. nfree(temps);
  662. if (!feof(f)) {
  663. if (s[0] != '#' && s[0] != ';' && s[0]) {
  664. code = newsplit(&s);
  665. rmspace(s);
  666. if (!strcmp(code, "-")) {
  667. if (!lasthand[0])
  668. continue; /* Skip this entry. */
  669. if (u) { /* only break it down if there a real users */
  670. p = strchr(s, ',');
  671. while (p != NULL) {
  672. splitc(s1, s, ',');
  673. rmspace(s1);
  674. if (s1[0])
  675. set_user(&USERENTRY_HOSTS, u, s1);
  676. p = strchr(s, ',');
  677. }
  678. }
  679. /* channel bans are never stacked with , */
  680. if (s[0]) {
  681. if (lasthand[0] && strchr(CHANMETA, lasthand[0]) != NULL)
  682. restore_chanban(cst, s);
  683. else if (lasthand[0] == '*') {
  684. if (lasthand[1] == IGNORE_NAME[1])
  685. restore_ignore(s);
  686. #ifdef S_DCCPASS
  687. else if (lasthand[1] == CONFIG_NAME[1]) {
  688. Context;
  689. set_cmd_pass(s, 1);
  690. }
  691. #endif
  692. else
  693. restore_chanban(NULL, s);
  694. } else if (lasthand[0])
  695. set_user(&USERENTRY_HOSTS, u, s);
  696. }
  697. } else if (!strcmp(code, "%")) { /* exemptmasks */
  698. if (!lasthand[0])
  699. continue; /* Skip this entry. */
  700. if (s[0]) {
  701. if (lasthand[0] == '#' || lasthand[0] == '+')
  702. restore_chanexempt(cst,s);
  703. else if (lasthand[0] == '*')
  704. if (lasthand[1] == EXEMPT_NAME[1])
  705. restore_chanexempt(NULL, s);
  706. }
  707. } else if (!strcmp(code, "@")) { /* Invitemasks */
  708. if (!lasthand[0])
  709. continue; /* Skip this entry. */
  710. if (s[0]) {
  711. if (lasthand[0] == '#' || lasthand[0] == '+') {
  712. restore_chaninvite(cst,s);
  713. } else if (lasthand[0] == '*') {
  714. if (lasthand[1] == INVITE_NAME[1]) {
  715. restore_chaninvite(NULL, s);
  716. } else if (lasthand[1] == CONFIG_NAME[1]) {
  717. userfile_cfg_line(s);
  718. }
  719. }
  720. }
  721. } else if (!strcmp(code, "!")) {
  722. /* ! #chan laston flags [info] */
  723. char *chname, *st, *fl;
  724. if (u) {
  725. chname = newsplit(&s);
  726. st = newsplit(&s);
  727. fl = newsplit(&s);
  728. rmspace(s);
  729. fr.match = FR_CHAN;
  730. break_down_flags(fl, &fr, 0);
  731. if (findchan_by_dname(chname)) {
  732. for (cr = u->chanrec; cr; cr = cr->next)
  733. if (!rfc_casecmp(cr->channel, chname))
  734. break;
  735. if (!cr) {
  736. cr = (struct chanuserrec *)
  737. user_malloc(sizeof(struct chanuserrec));
  738. cr->next = u->chanrec;
  739. u->chanrec = cr;
  740. strncpyz(cr->channel, chname, 80);
  741. cr->laston = atoi(st);
  742. cr->flags = fr.chan;
  743. cr->flags_udef = fr.udef_chan;
  744. if (s[0]) {
  745. cr->info = (char *) user_malloc(strlen(s) + 1);
  746. strcpy(cr->info, s);
  747. } else
  748. cr->info = NULL;
  749. }
  750. }
  751. }
  752. } else if (!strcmp(code, "+")) { // channels
  753. int code2;
  754. Context;
  755. if (s[0] && lasthand[0] == '*' && lasthand[1] == CHANS_NAME[1]) {
  756. code2 = Tcl_Eval(interp, s);
  757. if (code2 != TCL_OK) {
  758. putlog(LOG_MISC, "*", "Tcl error in userfile");
  759. putlog(LOG_MISC, "*", "%s",
  760. Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY));
  761. return 0;
  762. }
  763. call_hook(HOOK_SWITCH_STATIC);
  764. }
  765. } else if (!strncmp(code, "::", 2)) {
  766. /* channel-specific bans */
  767. strcpy(lasthand, &code[2]);
  768. u = NULL;
  769. if (!findchan_by_dname(lasthand)) {
  770. strcpy(s1, lasthand);
  771. strcat(s1, " ");
  772. if (strstr(ignored, s1) == NULL) {
  773. strcat(ignored, lasthand);
  774. strcat(ignored, " ");
  775. }
  776. lasthand[0] = 0;
  777. } else {
  778. /* Remove all bans for this channel to avoid dupes */
  779. /* NOTE only remove bans for when getting a userfile
  780. * from another bot & that channel is shared */
  781. cst = findchan_by_dname(lasthand);
  782. if ((*ret == userlist) || channel_shared(cst)) {
  783. clear_masks(cst->bans);
  784. cst->bans = NULL;
  785. } else {
  786. /* otherwise ignore any bans for this channel */
  787. cst = NULL;
  788. lasthand[0] = 0;
  789. }
  790. }
  791. } else if (!strncmp(code, "&&", 2)) {
  792. /* channel-specific exempts */
  793. strcpy(lasthand, &code[2]);
  794. u = NULL;
  795. if (!findchan_by_dname(lasthand)) {
  796. strcpy(s1, lasthand);
  797. strcat(s1, " ");
  798. if (strstr(ignored, s1) == NULL) {
  799. strcat(ignored, lasthand);
  800. strcat(ignored, " ");
  801. }
  802. lasthand[0] = 0;
  803. } else {
  804. /* Remove all exempts for this channel to avoid dupes */
  805. /* NOTE only remove exempts for when getting a userfile
  806. * from another bot & that channel is shared */
  807. cst = findchan_by_dname(lasthand);
  808. if ((*ret == userlist) || channel_shared(cst)) {
  809. clear_masks(cst->exempts);
  810. cst->exempts = NULL;
  811. } else {
  812. /* otherwise ignore any exempts for this channel */
  813. cst = NULL;
  814. lasthand[0] = 0;
  815. }
  816. }
  817. } else if (!strncmp(code, "$$", 2)) {
  818. /* channel-specific invites */
  819. strcpy(lasthand, &code[2]);
  820. u = NULL;
  821. if (!findchan_by_dname(lasthand)) {
  822. strcpy(s1, lasthand);
  823. strcat(s1, " ");
  824. if (strstr(ignored, s1) == NULL) {
  825. strcat(ignored, lasthand);
  826. strcat(ignored, " ");
  827. }
  828. lasthand[0] = 0;
  829. } else {
  830. /* Remove all invites for this channel to avoid dupes */
  831. /* NOTE only remove invites for when getting a userfile
  832. * from another bot & that channel is shared */
  833. cst = findchan_by_dname(lasthand);
  834. if ((*ret == userlist) || channel_shared(cst)) {
  835. clear_masks(cst->invites);
  836. cst->invites = NULL;
  837. } else {
  838. /* otherwise ignore any invites for this channel */
  839. cst = NULL;
  840. lasthand[0] = 0;
  841. }
  842. }
  843. } else if (!strncmp(code, "--", 2)) {
  844. Context;
  845. if (u) {
  846. /* new format storage */
  847. struct user_entry *ue;
  848. int ok = 0;
  849. for (ue = u->entries; ue && !ok; ue = ue->next)
  850. if (ue->name && !egg_strcasecmp(code + 2, ue->name)) {
  851. struct list_type *list;
  852. list = user_malloc(sizeof(struct list_type));
  853. list->next = NULL;
  854. list->extra = user_malloc(strlen(s) + 1);
  855. strcpy(list->extra, s);
  856. list_append((&ue->u.list), list);
  857. ok = 1;
  858. }
  859. if (!ok) {
  860. ue = user_malloc(sizeof(struct user_entry));
  861. ue->name = user_malloc(strlen(code + 1));
  862. ue->type = NULL;
  863. strcpy(ue->name, code + 2);
  864. ue->u.list = user_malloc(sizeof(struct list_type));
  865. ue->u.list->next = NULL;
  866. ue->u.list->extra = user_malloc(strlen(s) + 1);
  867. strcpy(ue->u.list->extra, s);
  868. list_insert((&u->entries), ue);
  869. }
  870. }
  871. } else if (!rfc_casecmp(code, BAN_NAME)) {
  872. strcpy(lasthand, code);
  873. u = NULL;
  874. } else if (!rfc_casecmp(code, IGNORE_NAME)) {
  875. strcpy(lasthand, code);
  876. u = NULL;
  877. } else if (!rfc_casecmp(code, EXEMPT_NAME)) {
  878. strcpy(lasthand, code);
  879. u = NULL;
  880. } else if (!rfc_casecmp(code, INVITE_NAME)) {
  881. strcpy(lasthand, code);
  882. u = NULL;
  883. } else if (!rfc_casecmp(code, CHANS_NAME)) {
  884. call_hook(HOOK_SWITCH_STATIC);
  885. strcpy(lasthand, code);
  886. u = NULL;
  887. } else if (!rfc_casecmp(code, CONFIG_NAME)) {
  888. strcpy(lasthand, code);
  889. u = NULL;
  890. } else if (code[0] == '*') {
  891. lasthand[0] = 0;
  892. u = NULL;
  893. } else {
  894. pass = newsplit(&s);
  895. attr = newsplit(&s);
  896. rmspace(s);
  897. Context;
  898. if (!attr[0] || !pass[0]) {
  899. putlog(LOG_MISC, "*", "* %s '%s'!", USERF_CORRUPT, code);
  900. lasthand[0] = 0;
  901. } else {
  902. u = get_user_by_handle(bu, code);
  903. if (u && !(u->flags & USER_UNSHARED)) {
  904. putlog(LOG_ERROR, "@", "* %s '%s'!", USERF_DUPE, code);
  905. lasthand[0] = 0;
  906. u = NULL;
  907. } else if (u) {
  908. lasthand[0] = 0;
  909. u = NULL;
  910. } else {
  911. fr.match = FR_GLOBAL;
  912. break_down_flags(attr, &fr, 0);
  913. strcpy(lasthand, code);
  914. cst = NULL;
  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,
  922. sanity_check(fr.global &USER_VALID));
  923. u = get_user_by_handle(bu, code);
  924. for (i = 0; i < dcc_total; i++)
  925. if (!egg_strcasecmp(code, dcc[i].nick))
  926. dcc[i].user = u;
  927. u->flags_udef = fr.udef_global;
  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;
  943. if (!(u->flags & USER_BOT) && !egg_strcasecmp (u->handle, botnetnick)) {
  944. putlog(LOG_MISC, "*", "(!) I have a user record, but without +b");
  945. /* u->flags |= USER_BOT; */
  946. }
  947. for (e = u->entries; e; e = e->next)
  948. if (e->name) {
  949. struct user_entry_type *uet = find_entry_type(e->name);
  950. if (uet) {
  951. e->type = uet;
  952. uet->unpack(u, e);
  953. nfree(e->name);
  954. e->name = NULL;
  955. }
  956. }
  957. }
  958. /* process the user data *now* */
  959. Context;
  960. #ifdef LEAF
  961. unlink(userfile);
  962. #endif
  963. return 1;
  964. }
  965. /* New methodology - cycle through list 3 times
  966. * 1st time scan for +sh bots and link if none connected
  967. * 2nd time scan for +h bots
  968. * 3rd time scan for +a/+h bots */
  969. void link_pref_val(struct userrec *u, char *val)
  970. {
  971. /* val must be HANDLEN + 4 chars minimum */
  972. struct bot_addr *ba;
  973. val[0] = 'Z';
  974. val[1] = 0;
  975. if (!u)
  976. return;
  977. if (!(u->flags & USER_BOT))
  978. return;
  979. ba = get_user(&USERENTRY_BOTADDR, u);
  980. if (!ba)
  981. return;
  982. if (!ba->hublevel)
  983. return;
  984. sprintf(val, STR("%02d%s"), ba->hublevel, u->handle);
  985. }
  986. struct userrec *next_hub(struct userrec *current, char *lowval, char *highval)
  987. {
  988. /*
  989. starting at "current" or "userlist" if NULL, find next bot with a
  990. link_pref_val higher than "lowval" and lower than "highval"
  991. If none found return bot with best overall link_pref_val
  992. If still not found return NULL
  993. */
  994. char thisval[NICKLEN + 4],
  995. bestmatchval[NICKLEN + 4] = "z",
  996. bestallval[NICKLEN + 4] = "z";
  997. struct userrec *cur = NULL,
  998. *bestmatch = NULL,
  999. *bestall = NULL;
  1000. if (current)
  1001. cur = current->next;
  1002. else
  1003. cur = userlist;
  1004. while (cur != current) {
  1005. if (!cur)
  1006. cur = userlist;
  1007. if (cur == current)
  1008. break;
  1009. if ((cur->flags & USER_BOT) && (strcmp(cur->handle, botnetnick))) {
  1010. link_pref_val(cur, thisval);
  1011. if ((strcmp(thisval, lowval) < 0) && (strcmp(thisval, highval) > 0) &&(strcmp(thisval, bestmatchval) < 0)) {
  1012. strcpy(bestmatchval, thisval);
  1013. bestmatch = cur;
  1014. }
  1015. if ((strcmp(thisval, lowval) < 0)
  1016. && (strcmp(thisval, bestallval) < 0)) {
  1017. strcpy(bestallval, thisval);
  1018. bestall = cur;
  1019. }
  1020. }
  1021. cur = cur->next;
  1022. }
  1023. if (bestmatch)
  1024. return bestmatch;
  1025. if (bestall)
  1026. return bestall;
  1027. return NULL;
  1028. }
  1029. #ifdef HUB
  1030. void autolink_cycle(char *start)
  1031. {
  1032. struct userrec *u = NULL;
  1033. int i;
  1034. char bestval[HANDLEN + 4],
  1035. curval[HANDLEN + 4],
  1036. myval[HANDLEN + 4];
  1037. if (norestruct) return; //this shouldn't ever happen..
  1038. u = get_user_by_handle(userlist, botnetnick);
  1039. link_pref_val(u, myval);
  1040. strcpy(bestval, myval);
  1041. for (i = 0; i < dcc_total; i++) {
  1042. if (dcc[i].type == &DCC_BOT_NEW)
  1043. return;
  1044. if (dcc[i].type == &DCC_FORK_BOT)
  1045. return;
  1046. if (dcc[i].type == &DCC_BOT) {
  1047. if (dcc[i].status & (STAT_OFFEREDU | STAT_GETTINGU | STAT_SENDINGU))
  1048. continue; //lets let the binary have it's peace.
  1049. if (dcc[i].u.bot->numver != egg_numver)
  1050. continue; //same thing.
  1051. if (dcc[i].status & (STAT_SHARE | STAT_OFFERED | STAT_SENDING | STAT_GETTING)) {
  1052. link_pref_val(dcc[i].user, curval);
  1053. if (strcmp(myval, curval) < 0) {
  1054. /* I should be aggressive to this one */
  1055. if (dcc[i].status & STAT_AGGRESSIVE) {
  1056. putlog(LOG_MISC, "*", STR("Passively sharing with %s but should be aggressive"), dcc[i].user->handle);
  1057. putlog(LOG_DEBUG, "*", STR("My linkval: %s - %s linkval: %s"), myval, dcc[i].nick, curval);
  1058. botunlink(-2, dcc[i].nick, STR("Marked passive, should be aggressive"));
  1059. return;
  1060. }
  1061. } else {
  1062. /* I should be passive to this one */
  1063. if (!(dcc[i].status & STAT_AGGRESSIVE)) {
  1064. putlog(LOG_MISC, "*", STR("Aggressively sharing with %s but should be passive"), dcc[i].user->handle);
  1065. putlog(LOG_DEBUG, "*", STR("My linkval: %s - %s linkval: %s"), myval, dcc[i].nick, curval);
  1066. botunlink(-2, dcc[i].nick, STR("Marked aggressive, should be passive"));
  1067. return;
  1068. }
  1069. if (strcmp(curval, bestval) < 0)
  1070. strcpy(bestval, curval);
  1071. }
  1072. } else {
  1073. botunlink(-2, dcc[i].nick, STR("Linked but not sharing?"));
  1074. }
  1075. }
  1076. }
  1077. if (start)
  1078. u = get_user_by_handle(userlist, start);
  1079. else
  1080. u = NULL;
  1081. if (u) {
  1082. link_pref_val(u, curval);
  1083. if (strcmp(bestval, curval) < 0) {
  1084. /* This shouldn't happen. Getting a failed link attempt (start!=NULL)
  1085. while a dcc scan indicates we *are* connected to a better bot than
  1086. the one we failed a link to.
  1087. */
  1088. putlog(LOG_BOTS, "*", STR("Failed link attempt to %s but connected to %s already???"), u->handle, (char *) &bestval[3]);
  1089. return;
  1090. }
  1091. } else
  1092. strcpy(curval, "0");
  1093. u = next_hub(u, bestval, curval);
  1094. if ((u) && (!in_chain(u->handle)))
  1095. botlink("", -3, u->handle);
  1096. }
  1097. #endif /* HUB */
  1098. #ifdef LEAF
  1099. typedef struct hublist_entry {
  1100. struct hublist_entry *next;
  1101. struct userrec *u;
  1102. } tag_hublist_entry;
  1103. int botlinkcount = 0;
  1104. void autolink_cycle(char *start)
  1105. {
  1106. struct userrec *u = NULL,
  1107. *ul = NULL;
  1108. struct hublist_entry *hl = NULL,
  1109. *hl2 = NULL;
  1110. struct bot_addr *ba;
  1111. char uplink[HANDLEN + 1],
  1112. avoidbot[HANDLEN + 1],
  1113. curhub[HANDLEN + 1];
  1114. int i,
  1115. hlc;
  1116. struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0 };
  1117. if (norestruct) return;
  1118. /* Reset connection attempts if we ain't called due to a failed link */
  1119. if (!start)
  1120. botlinkcount = 0;
  1121. u = get_user_by_handle(userlist, botnetnick);
  1122. ba = get_user(&USERENTRY_BOTADDR, u);
  1123. if (ba && (ba->uplink[0])) {
  1124. strncpy0(uplink, ba->uplink, sizeof(uplink));
  1125. } else {
  1126. uplink[0] = 0;
  1127. }
  1128. curhub[0] = 0;
  1129. for (i = 0; i < dcc_total; i++) {
  1130. if (dcc[i].type == &DCC_BOT_NEW)
  1131. return;
  1132. if (dcc[i].type == &DCC_FORK_BOT)
  1133. return;
  1134. if (dcc[i].type == &DCC_BOT) {
  1135. strcpy(curhub, dcc[i].nick);
  1136. break;
  1137. }
  1138. }
  1139. if (curhub[0]) {
  1140. /* we got a hub */
  1141. if (uplink[0] && !strcmp(curhub, uplink))
  1142. /* Connected to uplink, nothing more to do */
  1143. return;
  1144. if (start)
  1145. /* Failed a link... let's just wait for next regular call */
  1146. return;
  1147. if (uplink[0]) {
  1148. /* Trying the uplink */
  1149. botlink("", -3, uplink);
  1150. return;
  1151. }
  1152. /* we got a hub currently, and no set uplink. Stay here */
  1153. return;
  1154. } else {
  1155. /* no hubs connected... pick one */
  1156. if (!start) {
  1157. /* Regular interval call, no previous failed link */
  1158. if (uplink[0]) {
  1159. /* We have a set uplink, try it */
  1160. botlink("", -3, uplink);
  1161. return;
  1162. }
  1163. /* No preferred uplink, we need a random bot */
  1164. avoidbot[0] = 0;
  1165. } else {
  1166. /* We got a failed link... */
  1167. botlinkcount++;
  1168. if (botlinkcount >= 3)
  1169. /* tried 3+ random hubs without success, wait for next regular interval call */
  1170. return;
  1171. /* We need a random bot but *not* the last we tried */
  1172. strcpy(avoidbot, start);
  1173. }
  1174. }
  1175. /* Pick a random hub, but avoid 'avoidbot' */
  1176. ul = userlist;
  1177. hlc = 0;
  1178. while (ul) {
  1179. get_user_flagrec(ul, &fr, NULL);
  1180. if (glob_bot(fr) &&
  1181. strcmp(ul->handle, botnetnick) &&
  1182. strcmp(u->handle, avoidbot) &&
  1183. (bot_hublevel(ul) < 999)) {
  1184. hl2 = hl;
  1185. hl = user_malloc(sizeof(struct hublist_entry));
  1186. egg_bzero(hl, sizeof(struct hublist_entry));
  1187. hl->next = hl2;
  1188. hlc++;
  1189. hl->u = ul;
  1190. }
  1191. ul = ul->next;
  1192. }
  1193. hlc = random() % hlc;
  1194. while (hl) {
  1195. if (!hlc)
  1196. botlink("", -3, hl->u->handle);
  1197. hlc--;
  1198. hl2 = hl->next;
  1199. nfree(hl);
  1200. hl = hl2;
  1201. }
  1202. }
  1203. #endif /* LEAF */