userrec.c 17 KB

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