1
0

userrec.c 18 KB

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