users.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  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[], *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. set_cmd_pass(s, 1);
  689. }
  690. #endif /* S_DCCPASS */
  691. else
  692. restore_chanban(NULL, s);
  693. } else if (lasthand[0])
  694. set_user(&USERENTRY_HOSTS, u, s);
  695. }
  696. } else if (!strcmp(code, "%")) { /* exemptmasks */
  697. if (!lasthand[0])
  698. continue; /* Skip this entry. */
  699. if (s[0]) {
  700. if (lasthand[0] == '#' || lasthand[0] == '+')
  701. restore_chanexempt(cst,s);
  702. else if (lasthand[0] == '*')
  703. if (lasthand[1] == EXEMPT_NAME[1])
  704. restore_chanexempt(NULL, s);
  705. }
  706. } else if (!strcmp(code, "@")) { /* Invitemasks */
  707. if (!lasthand[0])
  708. continue; /* Skip this entry. */
  709. if (s[0]) {
  710. if (lasthand[0] == '#' || lasthand[0] == '+') {
  711. restore_chaninvite(cst,s);
  712. } else if (lasthand[0] == '*') {
  713. if (lasthand[1] == INVITE_NAME[1]) {
  714. restore_chaninvite(NULL, s);
  715. } else if (lasthand[1] == CONFIG_NAME[1]) {
  716. userfile_cfg_line(s);
  717. }
  718. }
  719. }
  720. } else if (!strcmp(code, "!")) {
  721. /* ! #chan laston flags [info] */
  722. char *chname, *st, *fl;
  723. if (u) {
  724. chname = newsplit(&s);
  725. st = newsplit(&s);
  726. fl = newsplit(&s);
  727. rmspace(s);
  728. fr.match = FR_CHAN;
  729. break_down_flags(fl, &fr, 0);
  730. if (findchan_by_dname(chname)) {
  731. for (cr = u->chanrec; cr; cr = cr->next)
  732. if (!rfc_casecmp(cr->channel, chname))
  733. break;
  734. if (!cr) {
  735. cr = (struct chanuserrec *)
  736. user_malloc(sizeof(struct chanuserrec));
  737. cr->next = u->chanrec;
  738. u->chanrec = cr;
  739. strncpyz(cr->channel, chname, 80);
  740. cr->laston = atoi(st);
  741. cr->flags = fr.chan;
  742. cr->flags_udef = fr.udef_chan;
  743. if (s[0]) {
  744. cr->info = (char *) user_malloc(strlen(s) + 1);
  745. strcpy(cr->info, s);
  746. } else
  747. cr->info = NULL;
  748. }
  749. }
  750. }
  751. } else if (!strcmp(code, "+")) { // channels
  752. int code2;
  753. Context;
  754. if (s[0] && lasthand[0] == '*' && lasthand[1] == CHANS_NAME[1]) {
  755. code2 = Tcl_Eval(interp, s);
  756. if (code2 != TCL_OK) {
  757. putlog(LOG_MISC, "*", "Tcl error in userfile");
  758. putlog(LOG_MISC, "*", "%s",
  759. Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY));
  760. return 0;
  761. }
  762. }
  763. } else if (!strncmp(code, "::", 2)) {
  764. /* channel-specific bans */
  765. strcpy(lasthand, &code[2]);
  766. u = NULL;
  767. if (!findchan_by_dname(lasthand)) {
  768. strcpy(s1, lasthand);
  769. strcat(s1, " ");
  770. if (strstr(ignored, s1) == NULL) {
  771. strcat(ignored, lasthand);
  772. strcat(ignored, " ");
  773. }
  774. lasthand[0] = 0;
  775. } else {
  776. /* Remove all bans for this channel to avoid dupes */
  777. /* NOTE only remove bans for when getting a userfile
  778. * from another bot & that channel is shared */
  779. cst = findchan_by_dname(lasthand);
  780. if ((*ret == userlist) || channel_shared(cst)) {
  781. clear_masks(cst->bans);
  782. cst->bans = NULL;
  783. } else {
  784. /* otherwise ignore any bans for this channel */
  785. cst = NULL;
  786. lasthand[0] = 0;
  787. }
  788. }
  789. } else if (!strncmp(code, "&&", 2)) {
  790. /* channel-specific exempts */
  791. strcpy(lasthand, &code[2]);
  792. u = NULL;
  793. if (!findchan_by_dname(lasthand)) {
  794. strcpy(s1, lasthand);
  795. strcat(s1, " ");
  796. if (strstr(ignored, s1) == NULL) {
  797. strcat(ignored, lasthand);
  798. strcat(ignored, " ");
  799. }
  800. lasthand[0] = 0;
  801. } else {
  802. /* Remove all exempts for this channel to avoid dupes */
  803. /* NOTE only remove exempts for when getting a userfile
  804. * from another bot & that channel is shared */
  805. cst = findchan_by_dname(lasthand);
  806. if ((*ret == userlist) || channel_shared(cst)) {
  807. clear_masks(cst->exempts);
  808. cst->exempts = NULL;
  809. } else {
  810. /* otherwise ignore any exempts for this channel */
  811. cst = NULL;
  812. lasthand[0] = 0;
  813. }
  814. }
  815. } else if (!strncmp(code, "$$", 2)) {
  816. /* channel-specific invites */
  817. strcpy(lasthand, &code[2]);
  818. u = NULL;
  819. if (!findchan_by_dname(lasthand)) {
  820. strcpy(s1, lasthand);
  821. strcat(s1, " ");
  822. if (strstr(ignored, s1) == NULL) {
  823. strcat(ignored, lasthand);
  824. strcat(ignored, " ");
  825. }
  826. lasthand[0] = 0;
  827. } else {
  828. /* Remove all invites for this channel to avoid dupes */
  829. /* NOTE only remove invites for when getting a userfile
  830. * from another bot & that channel is shared */
  831. cst = findchan_by_dname(lasthand);
  832. if ((*ret == userlist) || channel_shared(cst)) {
  833. clear_masks(cst->invites);
  834. cst->invites = NULL;
  835. } else {
  836. /* otherwise ignore any invites for this channel */
  837. cst = NULL;
  838. lasthand[0] = 0;
  839. }
  840. }
  841. } else if (!strncmp(code, "--", 2)) {
  842. Context;
  843. if (u) {
  844. /* new format storage */
  845. struct user_entry *ue;
  846. int ok = 0;
  847. for (ue = u->entries; ue && !ok; ue = ue->next)
  848. if (ue->name && !egg_strcasecmp(code + 2, ue->name)) {
  849. struct list_type *list;
  850. list = user_malloc(sizeof(struct list_type));
  851. list->next = NULL;
  852. list->extra = user_malloc(strlen(s) + 1);
  853. strcpy(list->extra, s);
  854. list_append((&ue->u.list), list);
  855. ok = 1;
  856. }
  857. if (!ok) {
  858. ue = user_malloc(sizeof(struct user_entry));
  859. ue->name = user_malloc(strlen(code + 1));
  860. ue->type = NULL;
  861. strcpy(ue->name, code + 2);
  862. ue->u.list = user_malloc(sizeof(struct list_type));
  863. ue->u.list->next = NULL;
  864. ue->u.list->extra = user_malloc(strlen(s) + 1);
  865. strcpy(ue->u.list->extra, s);
  866. list_insert((&u->entries), ue);
  867. }
  868. }
  869. } else if (!rfc_casecmp(code, BAN_NAME)) {
  870. strcpy(lasthand, code);
  871. u = NULL;
  872. } else if (!rfc_casecmp(code, IGNORE_NAME)) {
  873. strcpy(lasthand, code);
  874. u = NULL;
  875. } else if (!rfc_casecmp(code, EXEMPT_NAME)) {
  876. strcpy(lasthand, code);
  877. u = NULL;
  878. } else if (!rfc_casecmp(code, INVITE_NAME)) {
  879. strcpy(lasthand, code);
  880. u = NULL;
  881. } else if (!rfc_casecmp(code, CHANS_NAME)) {
  882. strcpy(lasthand, code);
  883. u = NULL;
  884. } else if (!rfc_casecmp(code, CONFIG_NAME)) {
  885. strcpy(lasthand, code);
  886. u = NULL;
  887. } else if (code[0] == '*') {
  888. lasthand[0] = 0;
  889. u = NULL;
  890. } else {
  891. pass = newsplit(&s);
  892. attr = newsplit(&s);
  893. rmspace(s);
  894. Context;
  895. if (!attr[0] || !pass[0]) {
  896. putlog(LOG_MISC, "*", "* %s '%s'!", USERF_CORRUPT, code);
  897. lasthand[0] = 0;
  898. } else {
  899. u = get_user_by_handle(bu, code);
  900. if (u && !(u->flags & USER_UNSHARED)) {
  901. putlog(LOG_ERROR, "@", "* %s '%s'!", USERF_DUPE, code);
  902. lasthand[0] = 0;
  903. u = NULL;
  904. } else if (u) {
  905. lasthand[0] = 0;
  906. u = NULL;
  907. } else {
  908. fr.match = FR_GLOBAL;
  909. break_down_flags(attr, &fr, 0);
  910. strcpy(lasthand, code);
  911. cst = NULL;
  912. if (strlen(code) > HANDLEN)
  913. code[HANDLEN] = 0;
  914. if (strlen(pass) > 20) {
  915. putlog(LOG_MISC, "*", "* %s '%s'", USERF_BROKEPASS, code);
  916. strcpy(pass, "-");
  917. }
  918. bu = adduser(bu, code, 0, pass,
  919. sanity_check(fr.global &USER_VALID));
  920. u = get_user_by_handle(bu, code);
  921. for (i = 0; i < dcc_total; i++)
  922. if (!egg_strcasecmp(code, dcc[i].nick))
  923. dcc[i].user = u;
  924. u->flags_udef = fr.udef_global;
  925. /* if s starts with '/' it's got file info */
  926. }
  927. }
  928. }
  929. }
  930. }
  931. }
  932. fclose(f);
  933. (*ret) = bu;
  934. if (ignored[0]) {
  935. putlog(LOG_MISC, "*", "%s %s", USERF_IGNBANS, ignored);
  936. }
  937. putlog(LOG_MISC, "*", "Userfile loaded, unpacking...");
  938. for (u = bu; u; u = u->next) {
  939. struct user_entry *e;
  940. if (!(u->flags & USER_BOT) && !egg_strcasecmp (u->handle, botnetnick)) {
  941. putlog(LOG_MISC, "*", "(!) I have a user record, but without +b");
  942. /* u->flags |= USER_BOT; */
  943. }
  944. for (e = u->entries; e; e = e->next)
  945. if (e->name) {
  946. struct user_entry_type *uet = find_entry_type(e->name);
  947. if (uet) {
  948. e->type = uet;
  949. uet->unpack(u, e);
  950. nfree(e->name);
  951. e->name = NULL;
  952. }
  953. }
  954. }
  955. /* process the user data *now* */
  956. #ifdef LEAF
  957. unlink(userfile);
  958. #endif /* LEAF */
  959. return 1;
  960. }
  961. /* New methodology - cycle through list 3 times
  962. * 1st time scan for +sh bots and link if none connected
  963. * 2nd time scan for +h bots
  964. * 3rd time scan for +a/+h bots */
  965. void link_pref_val(struct userrec *u, char *val)
  966. {
  967. /* val must be HANDLEN + 4 chars minimum */
  968. struct bot_addr *ba;
  969. val[0] = 'Z';
  970. val[1] = 0;
  971. if (!u)
  972. return;
  973. if (!(u->flags & USER_BOT))
  974. return;
  975. ba = get_user(&USERENTRY_BOTADDR, u);
  976. if (!ba)
  977. return;
  978. if (!ba->hublevel)
  979. return;
  980. sprintf(val, STR("%02d%s"), ba->hublevel, u->handle);
  981. }
  982. struct userrec *next_hub(struct userrec *current, char *lowval, char *highval)
  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. char thisval[NICKLEN + 4],
  991. bestmatchval[NICKLEN + 4] = "z",
  992. bestallval[NICKLEN + 4] = "z";
  993. struct userrec *cur = NULL,
  994. *bestmatch = NULL,
  995. *bestall = NULL;
  996. if (current)
  997. cur = current->next;
  998. else
  999. cur = userlist;
  1000. while (cur != current) {
  1001. if (!cur)
  1002. cur = userlist;
  1003. if (cur == current)
  1004. break;
  1005. if ((cur->flags & USER_BOT) && (strcmp(cur->handle, botnetnick))) {
  1006. link_pref_val(cur, thisval);
  1007. if ((strcmp(thisval, lowval) < 0) && (strcmp(thisval, highval) > 0) &&(strcmp(thisval, bestmatchval) < 0)) {
  1008. strcpy(bestmatchval, thisval);
  1009. bestmatch = cur;
  1010. }
  1011. if ((strcmp(thisval, lowval) < 0)
  1012. && (strcmp(thisval, bestallval) < 0)) {
  1013. strcpy(bestallval, thisval);
  1014. bestall = cur;
  1015. }
  1016. }
  1017. cur = cur->next;
  1018. }
  1019. if (bestmatch)
  1020. return bestmatch;
  1021. if (bestall)
  1022. return bestall;
  1023. return NULL;
  1024. }
  1025. #ifdef HUB
  1026. void autolink_cycle(char *start)
  1027. {
  1028. struct userrec *u = NULL;
  1029. int i;
  1030. char bestval[HANDLEN + 4],
  1031. curval[HANDLEN + 4],
  1032. myval[HANDLEN + 4];
  1033. u = get_user_by_handle(userlist, botnetnick);
  1034. link_pref_val(u, myval);
  1035. strcpy(bestval, myval);
  1036. for (i = 0; i < dcc_total; i++) {
  1037. if (dcc[i].type == &DCC_BOT_NEW)
  1038. return;
  1039. if (dcc[i].type == &DCC_FORK_BOT)
  1040. return;
  1041. if (dcc[i].type == &DCC_BOT) {
  1042. if (dcc[i].status & (STAT_OFFEREDU | STAT_GETTINGU | STAT_SENDINGU))
  1043. continue; //lets let the binary have it's peace.
  1044. if (dcc[i].u.bot->numver != egg_numver)
  1045. continue; //same thing.
  1046. if (dcc[i].status & (STAT_SHARE | STAT_OFFERED | STAT_SENDING | STAT_GETTING)) {
  1047. link_pref_val(dcc[i].user, curval);
  1048. if (strcmp(myval, curval) < 0) {
  1049. /* I should be aggressive to this one */
  1050. if (dcc[i].status & STAT_AGGRESSIVE) {
  1051. putlog(LOG_MISC, "*", STR("Passively sharing with %s but should be aggressive"), dcc[i].user->handle);
  1052. putlog(LOG_DEBUG, "*", STR("My linkval: %s - %s linkval: %s"), myval, dcc[i].nick, curval);
  1053. botunlink(-2, dcc[i].nick, STR("Marked passive, should be aggressive"));
  1054. return;
  1055. }
  1056. } else {
  1057. /* I should be passive to this one */
  1058. if (!(dcc[i].status & STAT_AGGRESSIVE)) {
  1059. putlog(LOG_MISC, "*", STR("Aggressively sharing with %s but should be passive"), dcc[i].user->handle);
  1060. putlog(LOG_DEBUG, "*", STR("My linkval: %s - %s linkval: %s"), myval, dcc[i].nick, curval);
  1061. botunlink(-2, dcc[i].nick, STR("Marked aggressive, should be passive"));
  1062. return;
  1063. }
  1064. if (strcmp(curval, bestval) < 0)
  1065. strcpy(bestval, curval);
  1066. }
  1067. } else {
  1068. botunlink(-2, dcc[i].nick, STR("Linked but not sharing?"));
  1069. }
  1070. }
  1071. }
  1072. if (start)
  1073. u = get_user_by_handle(userlist, start);
  1074. else
  1075. u = NULL;
  1076. if (u) {
  1077. link_pref_val(u, curval);
  1078. if (strcmp(bestval, curval) < 0) {
  1079. /* This shouldn't happen. Getting a failed link attempt (start!=NULL)
  1080. while a dcc scan indicates we *are* connected to a better bot than
  1081. the one we failed a link to.
  1082. */
  1083. putlog(LOG_BOTS, "*", STR("Failed link attempt to %s but connected to %s already???"), u->handle, (char *) &bestval[3]);
  1084. return;
  1085. }
  1086. } else
  1087. strcpy(curval, "0");
  1088. u = next_hub(u, bestval, curval);
  1089. if ((u) && (!in_chain(u->handle)))
  1090. botlink("", -3, u->handle);
  1091. }
  1092. #endif /* HUB */
  1093. #ifdef LEAF
  1094. typedef struct hublist_entry {
  1095. struct hublist_entry *next;
  1096. struct userrec *u;
  1097. } tag_hublist_entry;
  1098. int botlinkcount = 0;
  1099. void autolink_cycle(char *start)
  1100. {
  1101. struct userrec *my_u = NULL, *u = NULL;
  1102. struct hublist_entry *hl = NULL, *hl2 = NULL;
  1103. struct bot_addr *my_ba;
  1104. char uplink[HANDLEN + 1], avoidbot[HANDLEN + 1], curhub[HANDLEN + 1];
  1105. int i, hlc;
  1106. struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
  1107. /* Reset connection attempts if we ain't called due to a failed link */
  1108. if (!start)
  1109. botlinkcount = 0;
  1110. my_u = get_user_by_handle(userlist, botnetnick);
  1111. my_ba = get_user(&USERENTRY_BOTADDR, my_u);
  1112. if (my_ba && (my_ba->uplink[0])) {
  1113. strncpy0(uplink, my_ba->uplink, sizeof(uplink));
  1114. } else {
  1115. uplink[0] = 0;
  1116. }
  1117. curhub[0] = 0;
  1118. for (i = 0; i < dcc_total; i++) {
  1119. if ((dcc[i].type == &DCC_BOT_NEW) || (dcc[i].type == &DCC_FORK_BOT))
  1120. return;
  1121. if (dcc[i].type == &DCC_BOT) {
  1122. strcpy(curhub, dcc[i].nick);
  1123. break;
  1124. }
  1125. }
  1126. if (curhub[0]) {
  1127. /* we are linked to a bot (hub) */
  1128. if (uplink[0] && !strcmp(curhub, uplink))
  1129. /* Connected to uplink, nothing more to do */
  1130. return;
  1131. if (start)
  1132. /* Failed a link... let's just wait for next regular call */
  1133. return;
  1134. if (uplink[0]) {
  1135. /* Trying the uplink */
  1136. botlink("", -3, uplink);
  1137. return;
  1138. }
  1139. /* we got a hub currently, and no set uplink. Stay here */
  1140. return;
  1141. } else {
  1142. /* no hubs connected... pick one */
  1143. if (!start) {
  1144. /* Regular interval call, no previous failed link */
  1145. if (uplink[0]) {
  1146. /* We have a set uplink, try it */
  1147. botlink("", -3, uplink);
  1148. return;
  1149. }
  1150. /* No preferred uplink, we need a random bot */
  1151. avoidbot[0] = 0;
  1152. } else {
  1153. /* We got a failed link... */
  1154. botlinkcount++;
  1155. if (botlinkcount >= 3)
  1156. /* tried 3+ random hubs without success, wait for next regular interval call */
  1157. return;
  1158. /* We need a random bot but *not* the last we tried */
  1159. strcpy(avoidbot, start);
  1160. }
  1161. }
  1162. /* Pick a random hub, but avoid 'avoidbot' */
  1163. hlc = 0;
  1164. for (u = userlist; u; u = u->next) {
  1165. get_user_flagrec(u, &fr, NULL);
  1166. if (glob_bot(fr) && strcmp(u->handle, botnetnick) && strcmp(u->handle, avoidbot) && (bot_hublevel(u) < 999)) {
  1167. putlog(LOG_DEBUG, "@", STR("Adding %s to hublist"), u->handle);
  1168. hl2 = hl;
  1169. hl = user_malloc(sizeof(struct hublist_entry));
  1170. egg_bzero(hl, sizeof(struct hublist_entry));
  1171. hl->next = hl2;
  1172. hlc++;
  1173. hl->u = u;
  1174. }
  1175. }
  1176. putlog(LOG_DEBUG, "@", STR("Picking random hub from %d hubs"), hlc);
  1177. hlc = random() % hlc;
  1178. putlog(LOG_DEBUG, "@", STR("Picked #%d for hub"), hlc);
  1179. while (hl) {
  1180. if (!hlc) {
  1181. putlog(LOG_DEBUG, "@", STR("Which is bot: %s"), hl->u->handle);
  1182. botlink("", -3, hl->u->handle);
  1183. }
  1184. hlc--;
  1185. hl2 = hl->next;
  1186. nfree(hl);
  1187. hl = hl2;
  1188. }
  1189. }
  1190. #endif /* LEAF */