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 "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, 0, 0};
  424. n = num_notes(u->handle);
  425. fr.global = u->flags;
  426. fr.udef_global = u->flags_udef;
  427. build_flags(s, &fr, NULL);
  428. li = get_user(&USERENTRY_LASTON, u);
  429. if (!li || !li->laston)
  430. strcpy(s1, "never");
  431. else {
  432. now2 = now - li->laston;
  433. if (now2 > 86400)
  434. #ifdef S_UTCTIME
  435. egg_strftime(s1, 7, "%d %b", gmtime(&li->laston));
  436. #else /* !S_UTCTIME */
  437. egg_strftime(s1, 7, "%d %b", localtime(&li->laston));
  438. #endif /* S_UTCTIME */
  439. else
  440. #ifdef S_UTCTIME
  441. egg_strftime(s1, 6, "%H:%M", gmtime(&li->laston));
  442. #else /* !S_UTCTIME */
  443. egg_strftime(s1, 6, "%H:%M", localtime(&li->laston));
  444. #endif /* S_UTCTIME */
  445. }
  446. egg_snprintf(format, sizeof format, "%%-%us %%-5s%%5d %%-15s %%s (%%-10.10s)", HANDLEN);
  447. dprintf(idx, format, u->handle, get_user(&USERENTRY_PASS, u) ? "yes" : "no", n, s, s1, (li && li->lastonplace) ? li->lastonplace : "nowhere");
  448. dprintf(idx, "\n");
  449. /* channel flags? */
  450. for (ch = u->chanrec; ch; ch = ch->next) {
  451. fr.match = FR_CHAN | FR_GLOBAL;
  452. chan = findchan_by_dname(ch->channel);
  453. get_user_flagrec(dcc[idx].user, &fr, ch->channel);
  454. if (!channel_private(chan) || (channel_private(chan) && (chan_op(fr) || glob_owner(fr)))) {
  455. if (glob_op(fr) || chan_op(fr)) {
  456. if (ch->laston == 0L)
  457. strcpy(s1, "never");
  458. else {
  459. now2 = now - (ch->laston);
  460. if (now2 > 86400)
  461. #ifdef S_UTCTIME
  462. egg_strftime(s1, 7, "%d %b", gmtime(&ch->laston));
  463. #else /* !S_UTCTIME */
  464. egg_strftime(s1, 7, "%d %b", localtime(&ch->laston));
  465. #endif /* S_UTCTIME */
  466. else
  467. #ifdef S_UTCTIME
  468. egg_strftime(s1, 6, "%H:%M", gmtime(&ch->laston));
  469. #else /* !S_UTCTIME */
  470. egg_strftime(s1, 6, "%H:%M", localtime(&ch->laston));
  471. #endif /* S_UTCTIME */
  472. }
  473. fr.match = FR_CHAN;
  474. fr.chan = ch->flags;
  475. fr.udef_chan = ch->flags_udef;
  476. build_flags(s, &fr, NULL);
  477. egg_snprintf(format, sizeof format, "%%%us %%-18s %%-15s %%s\n", HANDLEN-9);
  478. dprintf(idx, format, " ", ch->channel, s, s1);
  479. if (ch->info != NULL)
  480. dprintf(idx, " INFO: %s\n", ch->info);
  481. }
  482. }
  483. }
  484. /* user-defined extra fields */
  485. for (ue = u->entries; ue; ue = ue->next)
  486. if (!ue->name && ue->type->display)
  487. ue->type->display(idx, ue, u);
  488. }
  489. /* show user by ident */
  490. void tell_user_ident(int idx, char *id, int master)
  491. {
  492. char format[81] = "";
  493. struct userrec *u = NULL;
  494. struct flag_record user = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  495. get_user_flagrec(dcc[idx].user, &user, NULL);
  496. u = get_user_by_handle(userlist, id);
  497. if (u == NULL)
  498. u = get_user_by_host(id);
  499. if (u == NULL || (u && !whois_access(dcc[idx].user, u))) {
  500. dprintf(idx, "%s.\n", USERF_NOMATCH);
  501. return;
  502. }
  503. egg_snprintf(format, sizeof format, "%%-%us PASS NOTES FLAGS LAST\n", HANDLEN);
  504. dprintf(idx, format, "HANDLE");
  505. tell_user(idx, u, master);
  506. }
  507. /* match string:
  508. * wildcard to match nickname or hostmasks
  509. * +attr to find all with attr */
  510. void tell_users_match(int idx, char *mtch, int start, int limit, int master, char *chname)
  511. {
  512. char format[81] = "";
  513. struct userrec *u = NULL;
  514. int fnd = 0, cnt, nomns = 0, flags = 0;
  515. struct list_type *q = NULL;
  516. struct flag_record user, pls, mns;
  517. dprintf(idx, "*** %s '%s':\n", MISC_MATCHING, mtch);
  518. cnt = 0;
  519. egg_snprintf(format, sizeof format, "%%-%us PASS NOTES FLAGS LAST\n", HANDLEN);
  520. dprintf(idx, format, "HANDLE");
  521. if (start > 1)
  522. dprintf(idx, "(%s %d)\n", MISC_SKIPPING, start - 1);
  523. if (strchr("+-&|", *mtch)) {
  524. user.match = pls.match = FR_GLOBAL | FR_BOT | FR_CHAN;
  525. break_down_flags(mtch, &pls, &mns);
  526. mns.match = pls.match ^ (FR_AND | FR_OR);
  527. if (!mns.global && !mns.udef_global && !mns.chan && !mns.udef_chan &&
  528. !mns.bot) {
  529. nomns = 1;
  530. if (!pls.global && !pls.udef_global && !pls.chan && !pls.udef_chan &&
  531. !pls.bot) {
  532. /* happy now BB you weenie :P */
  533. dprintf(idx, "Unknown flag specified for matching!!\n");
  534. return;
  535. }
  536. }
  537. if (!chname || !chname[0])
  538. chname = dcc[idx].u.chat->con_chan;
  539. flags = 1;
  540. }
  541. for (u = userlist; u; u = u->next) {
  542. if (!whois_access(dcc[idx].user, u)) {
  543. continue;
  544. } else if (flags) {
  545. get_user_flagrec(u, &user, chname);
  546. if (flagrec_eq(&pls, &user)) {
  547. if (nomns || !flagrec_eq(&mns, &user)) {
  548. cnt++;
  549. if ((cnt <= limit) && (cnt >= start))
  550. tell_user(idx, u, master);
  551. if (cnt == limit + 1)
  552. dprintf(idx, MISC_TRUNCATED, limit);
  553. }
  554. }
  555. } else if (wild_match(mtch, u->handle)) {
  556. cnt++;
  557. if ((cnt <= limit) && (cnt >= start))
  558. tell_user(idx, u, master);
  559. if (cnt == limit + 1)
  560. dprintf(idx, MISC_TRUNCATED, limit);
  561. } else {
  562. fnd = 0;
  563. for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next) {
  564. if ((wild_match(mtch, q->extra)) && (!fnd)) {
  565. cnt++;
  566. fnd = 1;
  567. if ((cnt <= limit) && (cnt >= start)) {
  568. tell_user(idx, u, master);
  569. }
  570. if (cnt == limit + 1)
  571. dprintf(idx, MISC_TRUNCATED, limit);
  572. }
  573. }
  574. }
  575. }
  576. dprintf(idx, MISC_FOUNDMATCH, cnt, cnt == 1 ? "" : MISC_MATCH_PLURAL);
  577. }
  578. #ifdef HUB
  579. void backup_userfile()
  580. {
  581. char s[DIRMAX] = "", s2[DIRMAX] = "";
  582. putlog(LOG_MISC, "*", USERF_BACKUP);
  583. egg_snprintf(s, sizeof s, "%s.u.0", tempdir);
  584. egg_snprintf(s2, sizeof s2, "%s.u.1", tempdir);
  585. movefile(s, s2);
  586. copyfile(userfile, s);
  587. }
  588. #endif /* HUB */
  589. /*
  590. * tagged lines in the user file:
  591. * * OLD:
  592. * # (comment)
  593. * ; (comment)
  594. * - hostmask(s)
  595. * + email
  596. * * dcc directory
  597. * = comment
  598. * : info line
  599. * . xtra (Tcl)
  600. * ! channel-specific
  601. * !! global laston
  602. * :: channel-specific bans
  603. * NEW:
  604. * *ban global bans
  605. * *ignore global ignores
  606. * ::#chan channel bans
  607. * - entries in each
  608. * + denotes tcl command
  609. * <handle> begin user entry
  610. * --KEY INFO - info on each
  611. * NEWER:
  612. * % exemptmask(s)
  613. * @ Invitemask(s)
  614. * *exempt global exempts
  615. * *Invite global Invites
  616. * && channel-specific exempts
  617. * &&#chan channel exempts
  618. * $$ channel-specific Invites
  619. * $$#chan channel Invites
  620. */
  621. int readuserfile(char *file, struct userrec **ret)
  622. {
  623. char *p = NULL, buf[1024] = "", lasthand[512] = "", *attr = NULL, *pass = NULL;
  624. char *code = NULL, s1[1024] = "", *s = NULL, cbuf[1024] = "", *temps = NULL, ignored[512] = "";
  625. FILE *f = NULL;
  626. struct userrec *bu = NULL, *u = NULL;
  627. struct chanset_t *cst = NULL;
  628. struct flag_record fr;
  629. struct chanuserrec *cr = NULL;
  630. int i, line = 0;
  631. bu = (*ret);
  632. ignored[0] = 0;
  633. if (bu == userlist) {
  634. clear_chanlist();
  635. lastuser = NULL;
  636. global_bans = NULL;
  637. global_ign = NULL;
  638. global_exempts = NULL;
  639. global_invites = NULL;
  640. }
  641. lasthand[0] = 0;
  642. f = fopen(file, "r");
  643. if (f == NULL)
  644. return 0;
  645. noshare = 1;
  646. /* read opening comment */
  647. s = buf;
  648. fgets(cbuf, 180, f);
  649. temps = (char *) decrypt_string(SALT1, cbuf);
  650. egg_snprintf(s, 180, temps);
  651. free(temps);
  652. if (s[1] < '4') {
  653. fatal(USERF_OLDFMT, 0);
  654. }
  655. if (s[1] > '4')
  656. fatal(USERF_INVALID, 0);
  657. while (!feof(f)) {
  658. s = buf;
  659. fgets(cbuf, 1024, f);
  660. temps = (char *) decrypt_string(SALT1, cbuf);
  661. egg_snprintf(s, 1024, temps);
  662. free(temps);
  663. if (!feof(f)) {
  664. line++;
  665. if (s[0] != '#' && s[0] != ';' && s[0]) {
  666. code = newsplit(&s);
  667. rmspace(s);
  668. if (!strcmp(code, "-")) {
  669. if (!lasthand[0])
  670. continue; /* Skip this entry. */
  671. if (u) { /* only break it down if there a real users */
  672. p = strchr(s, ',');
  673. while (p != NULL) {
  674. splitc(s1, s, ',');
  675. rmspace(s1);
  676. if (s1[0])
  677. set_user(&USERENTRY_HOSTS, u, s1);
  678. p = strchr(s, ',');
  679. }
  680. }
  681. /* channel bans are never stacked with , */
  682. if (s[0]) {
  683. if (lasthand[0] && strchr(CHANMETA, lasthand[0]) != NULL)
  684. restore_chanban(cst, s);
  685. else if (lasthand[0] == '*') {
  686. if (lasthand[1] == IGNORE_NAME[1])
  687. restore_ignore(s);
  688. #ifdef S_DCCPASS
  689. else if (lasthand[1] == CONFIG_NAME[1]) {
  690. set_cmd_pass(s, 1);
  691. }
  692. #endif /* S_DCCPASS */
  693. else
  694. restore_chanban(NULL, s);
  695. } else if (lasthand[0])
  696. set_user(&USERENTRY_HOSTS, u, s);
  697. }
  698. } else if (!strcmp(code, "%")) { /* exemptmasks */
  699. if (!lasthand[0])
  700. continue; /* Skip this entry. */
  701. if (s[0]) {
  702. if (lasthand[0] == '#' || lasthand[0] == '+')
  703. restore_chanexempt(cst,s);
  704. else if (lasthand[0] == '*')
  705. if (lasthand[1] == EXEMPT_NAME[1])
  706. restore_chanexempt(NULL, s);
  707. }
  708. } else if (!strcmp(code, "@")) { /* Invitemasks */
  709. if (!lasthand[0])
  710. continue; /* Skip this entry. */
  711. if (s[0]) {
  712. if (lasthand[0] == '#' || lasthand[0] == '+') {
  713. restore_chaninvite(cst,s);
  714. } else if (lasthand[0] == '*') {
  715. if (lasthand[1] == INVITE_NAME[1]) {
  716. restore_chaninvite(NULL, s);
  717. } else if (lasthand[1] == CONFIG_NAME[1]) {
  718. userfile_cfg_line(s);
  719. }
  720. }
  721. }
  722. } else if (!strcmp(code, "!")) {
  723. /* ! #chan laston flags [info] */
  724. char *chname = NULL, *st = NULL, *fl = NULL;
  725. if (u) {
  726. chname = newsplit(&s);
  727. st = newsplit(&s);
  728. fl = newsplit(&s);
  729. rmspace(s);
  730. fr.match = FR_CHAN;
  731. break_down_flags(fl, &fr, 0);
  732. if (findchan_by_dname(chname)) {
  733. for (cr = u->chanrec; cr; cr = cr->next)
  734. if (!rfc_casecmp(cr->channel, chname))
  735. break;
  736. if (!cr) {
  737. cr = (struct chanuserrec *) calloc(1, 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 = strdup(s);
  746. } else
  747. cr->info = NULL;
  748. }
  749. }
  750. }
  751. } else if (!strcmp(code, "+")) {
  752. if (s[0] && lasthand[0] == '*' && lasthand[1] == CHANS_NAME[1]) {
  753. char *options = NULL, *chan = NULL, *my_ptr = NULL;
  754. char resultbuf[2048] = "";
  755. options = my_ptr = strdup(s);
  756. newsplit(&options);
  757. newsplit(&options);
  758. chan = newsplit(&options);
  759. /* hack to remove { } */
  760. newsplit(&options);
  761. options[strlen(options) - 1] = 0;
  762. if (channel_add(resultbuf, chan, options) != OK) {
  763. putlog(LOG_MISC, "*", "Channel parsing error in userfile on line %d", line);
  764. free(my_ptr);
  765. return 0;
  766. }
  767. free(my_ptr);
  768. }
  769. } else if (!strncmp(code, "::", 2)) {
  770. /* channel-specific bans */
  771. strcpy(lasthand, &code[2]);
  772. u = NULL;
  773. if (!findchan_by_dname(lasthand)) {
  774. strcpy(s1, lasthand);
  775. strcat(s1, " ");
  776. if (strstr(ignored, s1) == NULL) {
  777. strcat(ignored, lasthand);
  778. strcat(ignored, " ");
  779. }
  780. lasthand[0] = 0;
  781. } else {
  782. /* Remove all bans for this channel to avoid dupes */
  783. /* NOTE only remove bans for when getting a userfile
  784. * from another bot & that channel is shared */
  785. cst = findchan_by_dname(lasthand);
  786. if ((*ret == userlist) || channel_shared(cst)) {
  787. clear_masks(cst->bans);
  788. cst->bans = NULL;
  789. } else {
  790. /* otherwise ignore any bans for this channel */
  791. cst = NULL;
  792. lasthand[0] = 0;
  793. }
  794. }
  795. } else if (!strncmp(code, "&&", 2)) {
  796. /* channel-specific exempts */
  797. strcpy(lasthand, &code[2]);
  798. u = NULL;
  799. if (!findchan_by_dname(lasthand)) {
  800. strcpy(s1, lasthand);
  801. strcat(s1, " ");
  802. if (strstr(ignored, s1) == NULL) {
  803. strcat(ignored, lasthand);
  804. strcat(ignored, " ");
  805. }
  806. lasthand[0] = 0;
  807. } else {
  808. /* Remove all exempts for this channel to avoid dupes */
  809. /* NOTE only remove exempts for when getting a userfile
  810. * from another bot & that channel is shared */
  811. cst = findchan_by_dname(lasthand);
  812. if ((*ret == userlist) || channel_shared(cst)) {
  813. clear_masks(cst->exempts);
  814. cst->exempts = NULL;
  815. } else {
  816. /* otherwise ignore any exempts for this channel */
  817. cst = NULL;
  818. lasthand[0] = 0;
  819. }
  820. }
  821. } else if (!strncmp(code, "$$", 2)) {
  822. /* channel-specific invites */
  823. strcpy(lasthand, &code[2]);
  824. u = NULL;
  825. if (!findchan_by_dname(lasthand)) {
  826. strcpy(s1, lasthand);
  827. strcat(s1, " ");
  828. if (strstr(ignored, s1) == NULL) {
  829. strcat(ignored, lasthand);
  830. strcat(ignored, " ");
  831. }
  832. lasthand[0] = 0;
  833. } else {
  834. /* Remove all invites for this channel to avoid dupes */
  835. /* NOTE only remove invites for when getting a userfile
  836. * from another bot & that channel is shared */
  837. cst = findchan_by_dname(lasthand);
  838. if ((*ret == userlist) || channel_shared(cst)) {
  839. clear_masks(cst->invites);
  840. cst->invites = NULL;
  841. } else {
  842. /* otherwise ignore any invites for this channel */
  843. cst = NULL;
  844. lasthand[0] = 0;
  845. }
  846. }
  847. } else if (!strncmp(code, "--", 2)) {
  848. if (u) {
  849. /* new format storage */
  850. struct user_entry *ue = NULL;
  851. int ok = 0;
  852. for (ue = u->entries; ue && !ok; ue = ue->next)
  853. if (ue->name && !egg_strcasecmp(code + 2, ue->name)) {
  854. struct list_type *list = NULL;
  855. list = calloc(1, sizeof(struct list_type));
  856. list->next = NULL;
  857. list->extra = strdup(s);
  858. list_append((&ue->u.list), list);
  859. ok = 1;
  860. }
  861. if (!ok) {
  862. ue = calloc(1, sizeof(struct user_entry));
  863. ue->name = calloc(1, strlen(code + 1));
  864. ue->type = NULL;
  865. strcpy(ue->name, code + 2);
  866. ue->u.list = calloc(1, sizeof(struct list_type));
  867. ue->u.list->next = NULL;
  868. ue->u.list->extra = strdup(s);
  869. list_insert((&u->entries), ue);
  870. }
  871. }
  872. } else if (!rfc_casecmp(code, BAN_NAME)) {
  873. strcpy(lasthand, code);
  874. u = NULL;
  875. } else if (!rfc_casecmp(code, IGNORE_NAME)) {
  876. strcpy(lasthand, code);
  877. u = NULL;
  878. } else if (!rfc_casecmp(code, EXEMPT_NAME)) {
  879. strcpy(lasthand, code);
  880. u = NULL;
  881. } else if (!rfc_casecmp(code, INVITE_NAME)) {
  882. strcpy(lasthand, code);
  883. u = NULL;
  884. } else if (!rfc_casecmp(code, CHANS_NAME)) {
  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. if (!attr[0] || !pass[0]) {
  898. putlog(LOG_MISC, "*", "* %s line: %d!", USERF_CORRUPT, line);
  899. lasthand[0] = 0;
  900. return 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, sanity_check(fr.global &USER_VALID));
  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. u->flags_udef = fr.udef_global;
  929. /* if s starts with '/' it's got file info */
  930. }
  931. }
  932. }
  933. }
  934. }
  935. }
  936. fclose(f);
  937. (*ret) = bu;
  938. if (ignored[0]) {
  939. putlog(LOG_MISC, "*", "%s %s", USERF_IGNBANS, ignored);
  940. }
  941. putlog(LOG_MISC, "*", "Userfile loaded, unpacking...");
  942. for (u = bu; u; u = u->next) {
  943. struct user_entry *e = NULL;
  944. if (!(u->flags & USER_BOT) && !egg_strcasecmp (u->handle, conf.bot->nick)) {
  945. putlog(LOG_MISC, "*", "(!) I have a user record, but without +b");
  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->flags & USER_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->flags & USER_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. int i;
  1029. link_pref_val(conf.bot->u, myval);
  1030. strcpy(bestval, myval);
  1031. for (i = 0; i < dcc_total; i++) {
  1032. if (dcc[i].type == &DCC_BOT_NEW)
  1033. return;
  1034. if (dcc[i].type == &DCC_FORK_BOT)
  1035. return;
  1036. if (dcc[i].type == &DCC_BOT) {
  1037. if (dcc[i].status & (STAT_OFFEREDU | STAT_GETTINGU | STAT_SENDINGU))
  1038. continue; /* lets let the binary have it's peace. */
  1039. if (dcc[i].u.bot->bts != buildts)
  1040. continue; /* same thing. */
  1041. if (dcc[i].status & (STAT_SHARE | STAT_OFFERED | STAT_SENDING | STAT_GETTING)) {
  1042. link_pref_val(dcc[i].user, curval);
  1043. if (strcmp(myval, curval) < 0) {
  1044. /* I should be aggressive to this one */
  1045. if (dcc[i].status & STAT_AGGRESSIVE) {
  1046. putlog(LOG_MISC, "*", "Passively sharing with %s but should be aggressive", dcc[i].user->handle);
  1047. putlog(LOG_DEBUG, "*", "My linkval: %s - %s linkval: %s", myval, dcc[i].nick, curval);
  1048. botunlink(-2, dcc[i].nick, "Marked passive, should be aggressive");
  1049. return;
  1050. }
  1051. } else {
  1052. /* I should be passive to this one */
  1053. if (!(dcc[i].status & STAT_AGGRESSIVE)) {
  1054. putlog(LOG_MISC, "*", "Aggressively sharing with %s but should be passive", dcc[i].user->handle);
  1055. putlog(LOG_DEBUG, "*", "My linkval: %s - %s linkval: %s", myval, dcc[i].nick, curval);
  1056. botunlink(-2, dcc[i].nick, "Marked aggressive, should be passive");
  1057. return;
  1058. }
  1059. if (strcmp(curval, bestval) < 0)
  1060. strcpy(bestval, curval);
  1061. }
  1062. } else {
  1063. botunlink(-2, dcc[i].nick, "Linked but not sharing?");
  1064. }
  1065. }
  1066. }
  1067. if (start)
  1068. u = get_user_by_handle(userlist, start);
  1069. else
  1070. u = NULL;
  1071. if (u) {
  1072. link_pref_val(u, curval);
  1073. if (strcmp(bestval, curval) < 0) {
  1074. /* This shouldn't happen. Getting a failed link attempt (start!=NULL)
  1075. while a dcc scan indicates we *are* connected to a better bot than
  1076. the one we failed a link to.
  1077. */
  1078. putlog(LOG_BOTS, "*", "Failed link attempt to %s but connected to %s already???", u->handle, (char *) &bestval[2]);
  1079. return;
  1080. }
  1081. } else
  1082. strcpy(curval, "0");
  1083. u = next_hub(u, bestval, curval);
  1084. if ((u) && (!in_chain(u->handle)))
  1085. botlink("", -3, u->handle);
  1086. }
  1087. #endif /* HUB */
  1088. #ifdef LEAF
  1089. typedef struct hublist_entry {
  1090. struct hublist_entry *next;
  1091. struct userrec *u;
  1092. } tag_hublist_entry;
  1093. int botlinkcount = 0;
  1094. void autolink_cycle(char *start)
  1095. {
  1096. struct userrec *u = NULL;
  1097. struct hublist_entry *hl = NULL, *hl2 = NULL;
  1098. struct bot_addr *my_ba = NULL;
  1099. char uplink[HANDLEN + 1] = "", avoidbot[HANDLEN + 1] = "", curhub[HANDLEN + 1] = "";
  1100. int i, hlc;
  1101. struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
  1102. /* Reset connection attempts if we ain't called due to a failed link */
  1103. if (!start)
  1104. botlinkcount = 0;
  1105. my_ba = get_user(&USERENTRY_BOTADDR, conf.bot->u);
  1106. if (my_ba && (my_ba->uplink[0])) {
  1107. strncpyz(uplink, my_ba->uplink, sizeof(uplink));
  1108. } else {
  1109. uplink[0] = 0;
  1110. }
  1111. curhub[0] = 0;
  1112. for (i = 0; i < dcc_total; i++) {
  1113. if ((dcc[i].type == &DCC_BOT_NEW) || (dcc[i].type == &DCC_FORK_BOT))
  1114. return;
  1115. if (dcc[i].type == &DCC_BOT) {
  1116. strcpy(curhub, dcc[i].nick);
  1117. break;
  1118. }
  1119. }
  1120. if (curhub[0]) {
  1121. /* we are linked to a bot (hub) */
  1122. if (uplink[0] && !strcmp(curhub, uplink))
  1123. /* Connected to uplink, nothing more to do */
  1124. return;
  1125. if (start)
  1126. /* Failed a link... let's just wait for next regular call */
  1127. return;
  1128. if (uplink[0]) {
  1129. /* Trying the uplink */
  1130. botlink("", -3, uplink);
  1131. return;
  1132. }
  1133. /* we got a hub currently, and no set uplink. Stay here */
  1134. return;
  1135. } else {
  1136. /* no hubs connected... pick one */
  1137. if (!start) {
  1138. /* Regular interval call, no previous failed link */
  1139. if (uplink[0]) {
  1140. /* We have a set uplink, try it */
  1141. botlink("", -3, uplink);
  1142. return;
  1143. }
  1144. /* No preferred uplink, we need a random bot */
  1145. avoidbot[0] = 0;
  1146. } else {
  1147. /* We got a failed link... */
  1148. botlinkcount++;
  1149. if (botlinkcount >= 3)
  1150. /* tried 3+ random hubs without success, wait for next regular interval call */
  1151. return;
  1152. /* We need a random bot but *not* the last we tried */
  1153. strcpy(avoidbot, start);
  1154. }
  1155. }
  1156. /* Pick a random hub, but avoid 'avoidbot' */
  1157. hlc = 0;
  1158. for (u = userlist; u; u = u->next) {
  1159. get_user_flagrec(u, &fr, NULL);
  1160. if (glob_bot(fr) && strcmp(u->handle, conf.bot->nick) && strcmp(u->handle, avoidbot) && (bot_hublevel(u) < 999)) {
  1161. putlog(LOG_DEBUG, "@", "Adding %s to hublist", u->handle);
  1162. hl2 = hl;
  1163. hl = calloc(1, sizeof(struct hublist_entry));
  1164. hl->next = hl2;
  1165. hlc++;
  1166. hl->u = u;
  1167. }
  1168. }
  1169. putlog(LOG_DEBUG, "@", "Picking random hub from %d hubs", hlc);
  1170. hlc = randint(hlc);
  1171. putlog(LOG_DEBUG, "@", "Picked #%d for hub", hlc);
  1172. while (hl) {
  1173. if (!hlc) {
  1174. putlog(LOG_DEBUG, "@", "Which is bot: %s", hl->u->handle);
  1175. botlink("", -3, hl->u->handle);
  1176. }
  1177. hlc--;
  1178. hl2 = hl->next;
  1179. free(hl);
  1180. hl = hl2;
  1181. }
  1182. }
  1183. #endif /* LEAF */