userrec.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. /*
  2. * userrec.c -- handles:
  3. * add_q() del_q() str2flags() flags2str() str2chflags() chflags2str()
  4. * a bunch of functions to find and change user records
  5. * change and check user (and channel-specific) flags
  6. *
  7. */
  8. #include <sys/stat.h>
  9. #include "main.h"
  10. #include "users.h"
  11. #include "chan.h"
  12. #include "modules.h"
  13. #include "tandem.h"
  14. #include "core_binds.h"
  15. extern struct dcc_t *dcc;
  16. extern struct chanset_t *chanset;
  17. extern int default_flags, default_uflags, quiet_save,
  18. dcc_total;
  19. extern char userfile[], ver[], botnetnick[], tempdir[];
  20. extern time_t now;
  21. int noshare = 1; /* don't send out to sharebots */
  22. int sort_users = 1; /* sort the userlist when saving */
  23. struct userrec *userlist = NULL; /* user records are stored here */
  24. struct userrec *lastuser = NULL; /* last accessed user record */
  25. maskrec *global_bans = NULL,
  26. *global_exempts = NULL,
  27. *global_invites = NULL;
  28. struct igrec *global_ign = NULL;
  29. int cache_hit = 0,
  30. cache_miss = 0; /* temporary cache accounting */
  31. int strict_host = 0;
  32. int userfile_perm = 0600; /* Userfile permissions,
  33. default rw------- */
  34. #ifdef S_DCCPASS
  35. extern struct cmd_pass *cmdpass;
  36. #endif /* S_DCCPASS */
  37. int count_users(struct userrec *bu)
  38. {
  39. int tot = 0;
  40. struct userrec *u;
  41. for (u = bu; u; u = u->next)
  42. tot++;
  43. return tot;
  44. }
  45. /* Convert "nick!~user@host", "nick!+user@host" and "nick!-user@host"
  46. * to "nick!user@host" if necessary. (drummer)
  47. */
  48. char *fixfrom(char *s)
  49. {
  50. char *p;
  51. static char buf[512];
  52. if (s == NULL)
  53. return NULL;
  54. strncpyz(buf, s, sizeof buf);
  55. if (strict_host)
  56. return buf;
  57. if ((p = strchr(buf, '!')))
  58. p++;
  59. else
  60. p = s; /* Sometimes we get passed just a
  61. * user@host here... */
  62. /* These are ludicrous. */
  63. if (strchr("~+-^=", *p) && (p[1] != '@')) /* added check for @ - drummer */
  64. // strcpy(p, p + 1);
  65. sprintf(p, "%s", p + 1);
  66. /* Bug was: n!~@host -> n!@host now: n!~@host */
  67. return buf;
  68. }
  69. struct userrec *check_dcclist_hand(char *handle)
  70. {
  71. int i;
  72. for (i = 0; i < dcc_total; i++)
  73. if (!egg_strcasecmp(dcc[i].nick, handle))
  74. return dcc[i].user;
  75. return NULL;
  76. }
  77. struct userrec *get_user_by_handle(struct userrec *bu, char *handle)
  78. {
  79. struct userrec *u, *ret;
  80. if (!handle)
  81. return NULL;
  82. /* FIXME: This should be done outside of this function. */
  83. rmspace(handle);
  84. if (!handle[0] || (handle[0] == '*'))
  85. return NULL;
  86. if (bu == userlist) {
  87. if (lastuser && !egg_strcasecmp(lastuser->handle, handle)) {
  88. cache_hit++;
  89. return lastuser;
  90. }
  91. ret = check_dcclist_hand(handle);
  92. if (ret) {
  93. cache_hit++;
  94. return ret;
  95. }
  96. ret = check_chanlist_hand(handle);
  97. if (ret) {
  98. cache_hit++;
  99. return ret;
  100. }
  101. cache_miss++;
  102. }
  103. for (u = bu; u; u = u->next)
  104. if (!egg_strcasecmp(u->handle, handle)) {
  105. if (bu == userlist)
  106. lastuser = u;
  107. return u;
  108. }
  109. return NULL;
  110. }
  111. /* Fix capitalization, etc
  112. */
  113. void correct_handle(char *handle)
  114. {
  115. struct userrec *u;
  116. u = get_user_by_handle(userlist, handle);
  117. if (u == NULL || handle == u->handle)
  118. return;
  119. strcpy(handle, u->handle);
  120. }
  121. /* This will be usefull in a lot of places, much more code re-use so we
  122. * endup with a smaller executable bot. <cybah>
  123. */
  124. void clear_masks(maskrec *m)
  125. {
  126. maskrec *temp = NULL;
  127. for (; m; m = temp) {
  128. temp = m->next;
  129. if (m->mask)
  130. free(m->mask);
  131. if (m->user)
  132. free(m->user);
  133. if (m->desc)
  134. free(m->desc);
  135. free(m);
  136. }
  137. }
  138. void clear_userlist(struct userrec *bu)
  139. {
  140. struct userrec *u, *v;
  141. int i;
  142. for (u = bu; u; u = v) {
  143. v = u->next;
  144. freeuser(u);
  145. }
  146. if (userlist == bu) {
  147. struct chanset_t *cst;
  148. for (i = 0; i < dcc_total; i++)
  149. dcc[i].user = NULL;
  150. clear_chanlist();
  151. lastuser = NULL;
  152. while (global_ign)
  153. delignore(global_ign->igmask);
  154. clear_masks(global_bans);
  155. clear_masks(global_exempts);
  156. clear_masks(global_invites);
  157. global_exempts = global_invites = global_bans = NULL;
  158. for (cst = chanset; cst; cst = cst->next) {
  159. clear_masks(cst->bans);
  160. clear_masks(cst->exempts);
  161. clear_masks(cst->invites);
  162. cst->bans = cst->exempts = cst->invites = NULL;
  163. }
  164. }
  165. /* Remember to set your userlist to NULL after calling this */
  166. }
  167. /* Find CLOSEST host match
  168. * (if "*!*@*" and "*!*@*clemson.edu" both match, use the latter!)
  169. *
  170. * Checks the chanlist first, to possibly avoid needless search.
  171. */
  172. struct userrec *get_user_by_host(char *host)
  173. {
  174. struct userrec *u, *ret;
  175. struct list_type *q;
  176. int cnt, i;
  177. char host2[UHOSTLEN];
  178. if (host == NULL)
  179. return NULL;
  180. rmspace(host);
  181. if (!host[0])
  182. return NULL;
  183. ret = check_chanlist(host);
  184. cnt = 0;
  185. if (ret != NULL) {
  186. cache_hit++;
  187. return ret;
  188. }
  189. cache_miss++;
  190. strncpyz(host2, host, sizeof host2);
  191. host = fixfrom(host);
  192. for (u = userlist; u; u = u->next) {
  193. q = get_user(&USERENTRY_HOSTS, u);
  194. for (; q; q = q->next) {
  195. i = wild_match(q->extra, host);
  196. if (i > cnt) {
  197. ret = u;
  198. cnt = i;
  199. }
  200. }
  201. }
  202. if (ret != NULL) {
  203. lastuser = ret;
  204. set_chanlist(host2, ret);
  205. }
  206. return ret;
  207. }
  208. /* use fixfrom() or dont? (drummer)
  209. */
  210. struct userrec *get_user_by_equal_host(char *host)
  211. {
  212. struct userrec *u;
  213. struct list_type *q;
  214. for (u = userlist; u; u = u->next)
  215. for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next)
  216. if (!rfc_casecmp(q->extra, host))
  217. return u;
  218. return NULL;
  219. }
  220. /* Try: pass_match_by_host("-",host)
  221. * will return 1 if no password is set for that host
  222. */
  223. int u_pass_match(struct userrec *u, char *in)
  224. {
  225. char *cmp, new[32], pass[16];
  226. if (!u)
  227. return 0;
  228. egg_snprintf(pass, sizeof pass, "%s", in);
  229. cmp = get_user(&USERENTRY_PASS, u);
  230. if (!cmp && (!pass[0] || (pass[0] == '-')))
  231. return 1;
  232. if (!cmp || !pass || !pass[0] || (pass[0] == '-'))
  233. return 0;
  234. if (u->flags & USER_BOT) {
  235. if (!strcmp(cmp, pass))
  236. return 1;
  237. } else {
  238. if (strlen(pass) > 15)
  239. pass[15] = 0;
  240. encrypt_pass(pass, new);
  241. if (!strcmp(cmp, new))
  242. return 1;
  243. }
  244. return 0;
  245. }
  246. int write_user(struct userrec *u, FILE * f, int idx)
  247. {
  248. char s[181];
  249. struct chanuserrec *ch;
  250. struct chanset_t *cst;
  251. struct user_entry *ue;
  252. struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
  253. fr.global = u->flags;
  254. fr.udef_global = u->flags_udef;
  255. build_flags(s, &fr, NULL);
  256. if (lfprintf(f, "%-10s - %-24s\n", u->handle, s) == EOF)
  257. return 0;
  258. for (ch = u->chanrec; ch; ch = ch->next) {
  259. cst = findchan_by_dname(ch->channel);
  260. if (cst && ((idx < 0) || channel_shared(cst))) {
  261. if (idx >= 0) {
  262. fr.match = (FR_CHAN | FR_BOT);
  263. get_user_flagrec(dcc[idx].user, &fr, ch->channel);
  264. } else
  265. fr.chan = BOT_SHARE;
  266. if ((fr.chan & BOT_SHARE) || (1)) {
  267. fr.match = FR_CHAN;
  268. fr.chan = ch->flags;
  269. fr.udef_chan = ch->flags_udef;
  270. build_flags(s, &fr, NULL);
  271. if (lfprintf(f, "! %-20s %lu %-10s %s\n", ch->channel, ch->laston, s,
  272. ch->info ? ch->info : "") == EOF)
  273. return 0;
  274. }
  275. }
  276. }
  277. for (ue = u->entries; ue; ue = ue->next) {
  278. if (ue->name) {
  279. struct list_type *lt;
  280. for (lt = ue->u.list; lt; lt = lt->next)
  281. if (lfprintf(f, "--%s %s\n", ue->name, lt->extra) == EOF)
  282. return 0;
  283. } else {
  284. if (!ue->type->write_userfile(f, u, ue))
  285. return 0;
  286. }
  287. }
  288. return 1;
  289. }
  290. int sort_compare(struct userrec *a, struct userrec *b)
  291. {
  292. /* Order by flags, then alphabetically
  293. * first bots: +h / +a / +l / other bots
  294. * then users: +n / +m / +o / other users
  295. * return true if (a > b)
  296. */
  297. if (a->flags & b->flags & USER_BOT) {
  298. if (bot_hublevel(a) > bot_hublevel(b))
  299. return 1;
  300. else if (bot_hublevel(a) < bot_hublevel(b))
  301. return 0;
  302. else if (bot_hublevel(a) == bot_hublevel(b) && bot_hublevel(a) == 999)
  303. return 0;
  304. } else {
  305. if (~a->flags & b->flags & USER_BOT)
  306. return 1;
  307. if (a->flags & ~b->flags & USER_BOT)
  308. return 0;
  309. if (~a->flags & b->flags & USER_ADMIN)
  310. return 1;
  311. if (a->flags & ~b->flags & USER_ADMIN)
  312. return 0;
  313. if (~a->flags & b->flags & USER_OWNER)
  314. return 1;
  315. if (a->flags & ~b->flags & USER_OWNER)
  316. return 0;
  317. if (~a->flags & b->flags & USER_MASTER)
  318. return 1;
  319. if (a->flags & ~b->flags & USER_MASTER)
  320. return 0;
  321. if (~a->flags & b->flags & USER_OP)
  322. return 1;
  323. if (a->flags & ~b->flags & USER_OP)
  324. return 0;
  325. }
  326. return (egg_strcasecmp(a->handle, b->handle) > 0);
  327. }
  328. void sort_userlist()
  329. {
  330. int again;
  331. struct userrec *last, *p, *c, *n;
  332. again = 1;
  333. last = NULL;
  334. while ((userlist != last) && (again)) {
  335. p = NULL;
  336. c = userlist;
  337. n = c->next;
  338. again = 0;
  339. while (n != last) {
  340. if (sort_compare(c, n)) {
  341. again = 1;
  342. c->next = n->next;
  343. n->next = c;
  344. if (p == NULL)
  345. userlist = n;
  346. else
  347. p->next = n;
  348. }
  349. p = c;
  350. c = n;
  351. n = n->next;
  352. }
  353. last = c;
  354. }
  355. }
  356. /* Rewrite the entire user file. Call USERFILE hook as well, probably
  357. * causing the channel file to be rewritten as well.
  358. */
  359. int write_userfile(int idx)
  360. {
  361. FILE *f;
  362. char *new_userfile;
  363. char s1[81], backup[DIRMAX];
  364. time_t tt;
  365. struct userrec *u;
  366. int ok;
  367. if (userlist == NULL)
  368. return 1; /* No point in saving userfile */
  369. new_userfile = malloc(strlen(userfile) + 5);
  370. sprintf(new_userfile, "%s~new", userfile);
  371. f = fopen(new_userfile, "w");
  372. chmod(new_userfile, 0600);
  373. if (f == NULL) {
  374. putlog(LOG_MISC, "*", USERF_ERRWRITE);
  375. free(new_userfile);
  376. return 2;
  377. }
  378. if (!quiet_save)
  379. putlog(LOG_MISC, "*", USERF_WRITING);
  380. if (sort_users)
  381. sort_userlist();
  382. tt = now;
  383. strcpy(s1, ctime(&tt));
  384. lfprintf(f, "#4v: %s -- %s -- written %s", ver, botnetnick, s1);
  385. ok = 1;
  386. fclose(f);
  387. call_hook(HOOK_USERFILE);
  388. f = fopen(new_userfile, "a");
  389. putlog(LOG_DEBUG, "@", "Writing user entries.");
  390. for (u = userlist; u && ok; u = u->next)
  391. ok = write_user(u, f, idx);
  392. if (!ok || fflush(f)) {
  393. putlog(LOG_MISC, "*", "%s (%s)", USERF_ERRWRITE, strerror(ferror(f)));
  394. fclose(f);
  395. free(new_userfile);
  396. return 3;
  397. }
  398. fclose(f);
  399. putlog(LOG_DEBUG, "@", "Done writing userfile.");
  400. egg_snprintf(backup, sizeof backup, "%s%s~", tempdir, userfile);
  401. copyfile(userfile, backup);
  402. movefile(new_userfile, userfile);
  403. free(new_userfile);
  404. return 0;
  405. }
  406. int change_handle(struct userrec *u, char *newh)
  407. {
  408. int i;
  409. char s[HANDLEN + 1];
  410. if (!u)
  411. return 0;
  412. /* Nothing that will confuse the userfile */
  413. if (!newh[1] && strchr(BADHANDCHARS, newh[0]))
  414. return 0;
  415. check_bind_nkch(u->handle, newh);
  416. /* Yes, even send bot nick changes now: */
  417. if (!noshare && !(u->flags & USER_UNSHARED))
  418. shareout(NULL, "h %s %s\n", u->handle, newh);
  419. strncpyz(s, u->handle, sizeof s);
  420. strncpyz(u->handle, newh, sizeof u->handle);
  421. for (i = 0; i < dcc_total; i++)
  422. if (dcc[i].type != &DCC_BOT && !egg_strcasecmp(dcc[i].nick, s)) {
  423. strncpyz(dcc[i].nick, newh, sizeof dcc[i].nick);
  424. if (dcc[i].type == &DCC_CHAT && dcc[i].u.chat->channel >= 0) {
  425. chanout_but(-1, dcc[i].u.chat->channel,
  426. "*** Handle change: %s -> %s\n", s, newh);
  427. if (dcc[i].u.chat->channel < GLOBAL_CHANS)
  428. botnet_send_nkch(i, s);
  429. }
  430. }
  431. return 1;
  432. }
  433. struct userrec *adduser(struct userrec *bu, char *handle, char *host,
  434. char *pass, int flags)
  435. {
  436. struct userrec *u, *x;
  437. int oldshare = noshare;
  438. noshare = 1;
  439. u = (struct userrec *) malloc(sizeof(struct userrec));
  440. /* u->next=bu; bu=u; */
  441. strncpyz(u->handle, handle, sizeof u->handle);
  442. u->next = NULL;
  443. u->chanrec = NULL;
  444. u->entries = NULL;
  445. if (flags != USER_DEFAULT) { /* drummer */
  446. u->flags = flags;
  447. u->flags_udef = 0;
  448. } else {
  449. u->flags = default_flags;
  450. u->flags_udef = default_uflags;
  451. }
  452. set_user(&USERENTRY_PASS, u, pass);
  453. /* Strip out commas -- they're illegal */
  454. if (host && host[0]) {
  455. char *p;
  456. /* About this fixfrom():
  457. * We should use this fixfrom before every call of adduser()
  458. * but its much easier to use here... (drummer)
  459. * Only use it if we have a host :) (dw)
  460. */
  461. host = fixfrom(host);
  462. p = strchr(host, ',');
  463. while (p != NULL) {
  464. *p = '?';
  465. p = strchr(host, ',');
  466. }
  467. set_user(&USERENTRY_HOSTS, u, host);
  468. } else
  469. set_user(&USERENTRY_HOSTS, u, "none");
  470. if (bu == userlist)
  471. clear_chanlist();
  472. noshare = oldshare;
  473. if ((!noshare) && (handle[0] != '*') && (!(flags & USER_UNSHARED)) &&
  474. (bu == userlist)) {
  475. struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
  476. char x[100];
  477. fr.global = u->flags;
  478. fr.udef_global = u->flags_udef;
  479. build_flags(x, &fr, 0);
  480. shareout(NULL, "n %s %s %s %s\n", handle, host && host[0] ? host : "none",
  481. pass, x);
  482. }
  483. if (bu == NULL)
  484. bu = u;
  485. else {
  486. if ((bu == userlist) && (lastuser != NULL))
  487. x = lastuser;
  488. else
  489. x = bu;
  490. while (x->next != NULL)
  491. x = x->next;
  492. x->next = u;
  493. if (bu == userlist)
  494. lastuser = u;
  495. }
  496. return bu;
  497. }
  498. void freeuser(struct userrec *u)
  499. {
  500. struct user_entry *ue, *ut;
  501. struct chanuserrec *ch, *z;
  502. if (u == NULL)
  503. return;
  504. ch = u->chanrec;
  505. while (ch) {
  506. z = ch;
  507. ch = ch->next;
  508. if (z->info != NULL)
  509. free(z->info);
  510. free(z);
  511. }
  512. u->chanrec = NULL;
  513. for (ue = u->entries; ue; ue = ut) {
  514. ut = ue->next;
  515. if (ue->name) {
  516. struct list_type *lt, *ltt;
  517. for (lt = ue->u.list; lt; lt = ltt) {
  518. ltt = lt->next;
  519. free(lt->extra);
  520. free(lt);
  521. }
  522. free(ue->name);
  523. free(ue);
  524. } else {
  525. ue->type->kill(ue);
  526. }
  527. }
  528. free(u);
  529. }
  530. int deluser(char *handle)
  531. {
  532. struct userrec *u = userlist, *prev = NULL;
  533. int fnd = 0;
  534. while ((u != NULL) && (!fnd)) {
  535. if (!egg_strcasecmp(u->handle, handle))
  536. fnd = 1;
  537. else {
  538. prev = u;
  539. u = u->next;
  540. }
  541. }
  542. if (!fnd)
  543. return 0;
  544. if (prev == NULL)
  545. userlist = u->next;
  546. else
  547. prev->next = u->next;
  548. if (!noshare && (handle[0] != '*') && !(u->flags & USER_UNSHARED))
  549. shareout(NULL, "k %s\n", handle);
  550. for (fnd = 0; fnd < dcc_total; fnd++)
  551. if (dcc[fnd].user == u)
  552. dcc[fnd].user = 0; /* Clear any dcc users for this entry,
  553. * null is safe-ish */
  554. clear_chanlist();
  555. freeuser(u);
  556. lastuser = NULL;
  557. return 1;
  558. }
  559. int delhost_by_handle(char *handle, char *host)
  560. {
  561. struct userrec *u;
  562. struct list_type *q, *qnext, *qprev;
  563. struct user_entry *e = NULL;
  564. int i = 0;
  565. u = get_user_by_handle(userlist, handle);
  566. if (!u)
  567. return 0;
  568. q = get_user(&USERENTRY_HOSTS, u);
  569. qprev = q;
  570. if (q) {
  571. if (!rfc_casecmp(q->extra, host)) {
  572. e = find_user_entry(&USERENTRY_HOSTS, u);
  573. e->u.extra = q->next;
  574. free(q->extra);
  575. free(q);
  576. i++;
  577. qprev = NULL;
  578. q = e->u.extra;
  579. } else
  580. q = q->next;
  581. while (q) {
  582. qnext = q->next;
  583. if (!rfc_casecmp(q->extra, host)) {
  584. if (qprev)
  585. qprev->next = q->next;
  586. else if (e) {
  587. e->u.extra = q->next;
  588. qprev = NULL;
  589. }
  590. free(q->extra);
  591. free(q);
  592. i++;
  593. } else
  594. qprev = q;
  595. q = qnext;
  596. }
  597. }
  598. if (!qprev)
  599. set_user(&USERENTRY_HOSTS, u, "none");
  600. if (!noshare && i && !(u->flags & USER_UNSHARED))
  601. shareout(NULL, "-h %s %s\n", handle, host);
  602. clear_chanlist();
  603. return i;
  604. }
  605. void addhost_by_handle(char *handle, char *host)
  606. {
  607. struct userrec *u = get_user_by_handle(userlist, handle);
  608. set_user(&USERENTRY_HOSTS, u, host);
  609. /* u will be cached, so really no overhead, even tho this looks dumb: */
  610. if ((!noshare) && !(u->flags & USER_UNSHARED)) {
  611. if (u->flags & USER_BOT)
  612. shareout(NULL, "+bh %s %s\n", handle, host);
  613. else
  614. shareout(NULL, "+h %s %s\n", handle, host);
  615. }
  616. clear_chanlist();
  617. }
  618. void touch_laston(struct userrec *u, char *where, time_t timeval)
  619. {
  620. if (!u)
  621. return;
  622. if (timeval > 1) {
  623. struct laston_info *li =
  624. (struct laston_info *) get_user(&USERENTRY_LASTON, u);
  625. if (!li)
  626. li = malloc(sizeof(struct laston_info));
  627. else if (li->lastonplace)
  628. free(li->lastonplace);
  629. li->laston = timeval;
  630. if (where) {
  631. li->lastonplace = strdup(where);
  632. } else
  633. li->lastonplace = NULL;
  634. set_user(&USERENTRY_LASTON, u, li);
  635. } else if (timeval == 1)
  636. set_user(&USERENTRY_LASTON, u, 0);
  637. }
  638. /* Go through all channel records and try to find a matching
  639. * nick. Will return the user's user record if that is known
  640. * to the bot. (Fabian)
  641. *
  642. * Warning: This is unreliable by concept!
  643. */
  644. struct userrec *get_user_by_nick(char *nick)
  645. {
  646. struct chanset_t *chan;
  647. memberlist *m;
  648. for (chan = chanset; chan; chan = chan->next) {
  649. for (m = chan->channel.member; m && m->nick[0] ;m = m->next) {
  650. if (!rfc_casecmp(nick, m->nick)) {
  651. char word[512];
  652. egg_snprintf(word, sizeof word, "%s!%s", m->nick, m->userhost);
  653. /* No need to check the return value ourself */
  654. return get_user_by_host(word);;
  655. }
  656. }
  657. }
  658. /* Sorry, no matches */
  659. return NULL;
  660. }
  661. void user_del_chan(char *dname)
  662. {
  663. struct chanuserrec *ch, *och;
  664. struct userrec *u;
  665. for (u = userlist; u; u = u->next) {
  666. ch = u->chanrec;
  667. och = NULL;
  668. while (ch) {
  669. if (!rfc_casecmp(dname, ch->channel)) {
  670. if (och)
  671. och->next = ch->next;
  672. else
  673. u->chanrec = ch->next;
  674. if (ch->info)
  675. free(ch->info);
  676. free(ch);
  677. break;
  678. }
  679. och = ch;
  680. ch = ch->next;
  681. }
  682. }
  683. }