userrec.c 17 KB

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