/[cvs]/eggdrop1.9/src/userrec.c
ViewVC logotype

Contents of /eggdrop1.9/src/userrec.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.34 - (show annotations) (download) (as text)
Wed Oct 10 10:44:04 2001 UTC (18 years, 3 months ago) by tothwolf
Branch: MAIN
Changes since 1.33: +32 -140 lines
File MIME type: text/x-chdr
all expmem functions and support removed
all memory status/debugging code removed
all #ifdef DEBUG_MEM code removed

nmalloc macro/n_malloc function removed, use malloc() now
mod_malloc function removed
my_strdup function removed, use malloc_strcpy macro now
channel_malloc removed, use malloc_memset macro now
n_malloc_null function removed, use malloc_memset macro now
user_malloc macro/_user_malloc function removed, use malloc() now

nrealloc macro/n_realloc function removed, use realloc() now
mod_realloc function removed

nfree macro/n_free function removed, use free() now
mod_free function removed
my_free macro removed, use free_null macro now
Tcl_Free compat macro now uses free() instead of removed n_free function

malloc->strcpy now uses malloc_strcpy macro
free(ptr);ptr=NULL; now uses free_null macro
malloc->bzero now uses malloc_memset macro
get_data_ptr macro/_get_data_ptr function removed, use malloc_memset macro now

compat memcpy removed
compat memset removed
egg_memcpy/my_memcpy misuse/mess changed to memcpy
egg_bzero/bzero macro removed, use memset() now

many uninitialized pointers now default to NULL

match.c is now compiled on it's own instead of being included into tclhash.c
match.c cleanup, removed broken/incomplete ircII compat code
wild_match macro removed, _wild_match function renamed to wild_match
wild_match_per function no longer declared static
added prototypes for wild_match and wild_match_per functions

Major function/macro changes:
  nmalloc -> malloc()
  nrealloc -> realloc()
  nfree -> free()

Bugs found and fixed during audit:
  buffer overflow in adduser()

Bugs fixed when code was removed:
  typo in filedb3.c: EBUG_MEM -> DEBUG_MEM
  extra egg_bzero call from filesys.c

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23