userrec.c 17 KB

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