1
0

users.c 33 KB

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