users.c 33 KB

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