users.c 32 KB

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