ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/src/client.c
Revision: 603
Committed: Sun May 14 10:32:26 2006 UTC (17 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 49429 byte(s)
Log Message:
- Made cleanup_pending_glines() an event started off when loading
  the m_gline module
- Removed s_gline.c, s_gline.h and metadata.c

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * client.c: Controls clients.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "client.h"
27     #include "channel_mode.h"
28     #include "common.h"
29     #include "hash.h"
30     #include "ircd.h"
31     #include "numeric.h"
32     #include "packet.h"
33     #include "s_auth.h"
34     #include "s_conf.h"
35 db 101 #include "parse_aline.h"
36 adx 30 #include "s_serv.h"
37     #include "send.h"
38     #include "whowas.h"
39     #include "s_user.h"
40     #include "hostmask.h"
41     #include "listener.h"
42     #include "userhost.h"
43 michael 221 #include "watch.h"
44 adx 30
45     dlink_list listing_client_list = { NULL, NULL, 0 };
46     /* Pointer to beginning of Client list */
47     dlink_list global_client_list = {NULL, NULL, 0};
48     /* unknown/client pointer lists */
49     dlink_list unknown_list = {NULL, NULL, 0};
50     dlink_list local_client_list = {NULL, NULL, 0};
51     dlink_list serv_list = {NULL, NULL, 0};
52     dlink_list global_serv_list = {NULL, NULL, 0};
53     dlink_list oper_list = {NULL, NULL, 0};
54    
55     static EVH check_pings;
56    
57     static BlockHeap *client_heap = NULL;
58     static BlockHeap *lclient_heap = NULL;
59    
60     static dlink_list dead_list = { NULL, NULL, 0};
61     static dlink_list abort_list = { NULL, NULL, 0};
62    
63     static dlink_node *eac_next; /* next aborted client to exit */
64    
65     static void check_pings_list(dlink_list *);
66     static void check_unknowns_list(void);
67 adx 68 static void close_connection(struct Client *);
68 adx 30 static void ban_them(struct Client *client_p, struct ConfItem *conf);
69 db 232 static void del_all_accepts(struct Client *);
70 adx 30
71     /* init_client()
72     *
73     * inputs - NONE
74     * output - NONE
75     * side effects - initialize client free memory
76     */
77     void
78     init_client(void)
79     {
80     /* start off the check ping event .. -- adrian
81     * Every 30 seconds is plenty -- db
82     */
83     client_heap = BlockHeapCreate("client", sizeof(struct Client), CLIENT_HEAP_SIZE);
84     lclient_heap = BlockHeapCreate("local client", sizeof(struct LocalUser), LCLIENT_HEAP_SIZE);
85     eventAdd("check_pings", check_pings, NULL, 5);
86     }
87    
88     /*
89     * make_client - create a new Client struct and set it to initial state.
90     *
91     * from == NULL, create local client (a client connected
92     * to a socket).
93     * WARNING: This leaves the client in a dangerous
94     * state where fd == -1, dead flag is not set and
95     * the client is on the unknown_list; therefore,
96     * the first thing to do after calling make_client(NULL)
97     * is setting fd to something reasonable. -adx
98     *
99     * from, create remote client (behind a socket
100     * associated with the client defined by
101     * 'from'). ('from' is a local client!!).
102     */
103     struct Client *
104     make_client(struct Client *from)
105     {
106     struct Client *client_p = BlockHeapAlloc(client_heap);
107    
108     if (from == NULL)
109     {
110     client_p->from = client_p; /* 'from' of local client is self! */
111     client_p->since = client_p->lasttime = client_p->firsttime = CurrentTime;
112    
113     client_p->localClient = BlockHeapAlloc(lclient_heap);
114 michael 502 client_p->localClient->registration = REG_INIT;
115 adx 30 /* as good a place as any... */
116 michael 471 dlinkAdd(client_p, &client_p->localClient->lclient_node, &unknown_list);
117 adx 30 }
118     else
119 michael 316 client_p->from = from;
120 adx 30
121     client_p->hnext = client_p;
122     client_p->status = STAT_UNKNOWN;
123     strcpy(client_p->username, "unknown");
124    
125     return client_p;
126     }
127    
128     /*
129     * free_client
130     *
131     * inputs - pointer to client
132     * output - NONE
133     * side effects - client pointed to has its memory freed
134     */
135     static void
136     free_client(struct Client *client_p)
137     {
138     assert(client_p != NULL);
139     assert(client_p != &me);
140     assert(client_p->hnext == client_p);
141     assert(client_p->channel.head == NULL);
142     assert(dlink_list_length(&client_p->channel) == 0);
143    
144     MyFree(client_p->away);
145     MyFree(client_p->serv);
146    
147     if (MyConnect(client_p))
148     {
149 michael 315 assert(dlink_list_length(&client_p->localClient->invited) == 0);
150     assert(client_p->localClient->invited.head == NULL);
151 adx 30 assert(IsClosing(client_p) && IsDead(client_p));
152    
153     MyFree(client_p->localClient->response);
154     MyFree(client_p->localClient->auth_oper);
155    
156     /*
157     * clean up extra sockets from P-lines which have been discarded.
158     */
159     if (client_p->localClient->listener)
160     {
161     assert(0 < client_p->localClient->listener->ref_count);
162     if (0 == --client_p->localClient->listener->ref_count &&
163     !client_p->localClient->listener->active)
164     free_listener(client_p->localClient->listener);
165     }
166    
167     dbuf_clear(&client_p->localClient->buf_recvq);
168     dbuf_clear(&client_p->localClient->buf_sendq);
169    
170     BlockHeapFree(lclient_heap, client_p->localClient);
171     }
172    
173     BlockHeapFree(client_heap, client_p);
174     }
175    
176     /*
177     * check_pings - go through the local client list and check activity
178     * kill off stuff that should die
179     *
180     * inputs - NOT USED (from event)
181     * output - next time_t when check_pings() should be called again
182     * side effects -
183     *
184     *
185     * A PING can be sent to clients as necessary.
186     *
187     * Client/Server ping outs are handled.
188     */
189    
190     /*
191     * Addon from adrian. We used to call this after nextping seconds,
192     * however I've changed it to run once a second. This is only for
193     * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
194     * run once a second makes life a lot easier - when a new client connects
195     * and they need a ping in 4 seconds, if nextping was set to 20 seconds
196     * we end up waiting 20 seconds. This is stupid. :-)
197     * I will optimise (hah!) check_pings() once I've finished working on
198     * tidying up other network IO evilnesses.
199     * -- adrian
200     */
201    
202     static void
203     check_pings(void *notused)
204     {
205     check_pings_list(&local_client_list);
206     check_pings_list(&serv_list);
207     check_unknowns_list();
208     }
209    
210     /* check_pings_list()
211     *
212     * inputs - pointer to list to check
213     * output - NONE
214     * side effects -
215     */
216     static void
217     check_pings_list(dlink_list *list)
218     {
219     char scratch[32]; /* way too generous but... */
220     struct Client *client_p; /* current local client_p being examined */
221     int ping, pingwarn; /* ping time value from client */
222     dlink_node *ptr, *next_ptr;
223    
224     DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
225     {
226     client_p = ptr->data;
227    
228     /*
229     ** Note: No need to notify opers here. It's
230     ** already done when "FLAGS_DEADSOCKET" is set.
231     */
232     if (IsDead(client_p))
233     {
234     /* Ignore it, its been exited already */
235     continue;
236     }
237    
238     if (client_p->localClient->reject_delay > 0)
239     {
240     if (client_p->localClient->reject_delay <= CurrentTime)
241     exit_client(client_p, &me, "Rejected");
242     continue;
243     }
244    
245     if (GlobalSetOptions.idletime && IsClient(client_p))
246     {
247     if (!IsExemptKline(client_p) && !IsOper(client_p) &&
248     !IsIdlelined(client_p) &&
249     ((CurrentTime - client_p->localClient->last) > GlobalSetOptions.idletime))
250     {
251     struct ConfItem *conf;
252     struct AccessItem *aconf;
253    
254     conf = make_conf_item(KLINE_TYPE);
255 db 139 aconf = &conf->conf.AccessItem;
256 adx 30
257     DupString(aconf->host, client_p->host);
258     DupString(aconf->reason, "idle exceeder");
259     DupString(aconf->user, client_p->username);
260     aconf->hold = CurrentTime + 60;
261     add_temp_line(conf);
262    
263     sendto_realops_flags(UMODE_ALL, L_ALL,
264     "Idle time limit exceeded for %s - temp k-lining",
265     get_client_name(client_p, HIDE_IP));
266     exit_client(client_p, &me, aconf->reason);
267     continue;
268     }
269     }
270    
271     if (!IsRegistered(client_p))
272     ping = CONNECTTIMEOUT, pingwarn = 0;
273     else
274     ping = get_client_ping(client_p, &pingwarn);
275    
276     if (ping < CurrentTime - client_p->lasttime)
277     {
278     if (!IsPingSent(client_p))
279     {
280     /*
281     * if we havent PINGed the connection and we havent
282     * heard from it in a while, PING it to make sure
283     * it is still alive.
284     */
285     SetPingSent(client_p);
286     ClearPingWarning(client_p);
287     client_p->lasttime = CurrentTime - ping;
288     sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
289     }
290     else
291     {
292     if (CurrentTime - client_p->lasttime >= 2 * ping)
293     {
294     /*
295     * If the client/server hasn't talked to us in 2*ping seconds
296     * and it has a ping time, then close its connection.
297     */
298     if (IsServer(client_p) || IsHandshake(client_p))
299     {
300     sendto_realops_flags(UMODE_ALL, L_ADMIN,
301     "No response from %s, closing link",
302     get_client_name(client_p, HIDE_IP));
303     sendto_realops_flags(UMODE_ALL, L_OPER,
304     "No response from %s, closing link",
305     get_client_name(client_p, MASK_IP));
306     ilog(L_NOTICE, "No response from %s, closing link",
307     get_client_name(client_p, HIDE_IP));
308     }
309     ircsprintf(scratch, "Ping timeout: %d seconds",
310     (int)(CurrentTime - client_p->lasttime));
311    
312     exit_client(client_p, &me, scratch);
313     }
314     else if (!IsPingWarning(client_p) && pingwarn > 0 &&
315     (IsServer(client_p) || IsHandshake(client_p)) &&
316     CurrentTime - client_p->lasttime >= ping + pingwarn)
317     {
318     /*
319     * If the server hasn't replied in pingwarn seconds after sending
320     * the PING, notify the opers so that they are aware of the problem.
321     */
322     SetPingWarning(client_p);
323     sendto_realops_flags(UMODE_ALL, L_ADMIN,
324     "Warning, no response from %s in %d seconds",
325     get_client_name(client_p, HIDE_IP), pingwarn);
326     sendto_realops_flags(UMODE_ALL, L_OPER,
327     "Warning, no response from %s in %d seconds",
328     get_client_name(client_p, MASK_IP), pingwarn);
329     ilog(L_NOTICE, "No response from %s in %d seconds",
330     get_client_name(client_p, HIDE_IP), pingwarn);
331     }
332     }
333     }
334     }
335     }
336    
337     /* check_unknowns_list()
338     *
339     * inputs - pointer to list of unknown clients
340     * output - NONE
341     * side effects - unknown clients get marked for termination after n seconds
342     */
343     static void
344     check_unknowns_list(void)
345     {
346     dlink_node *ptr, *next_ptr;
347    
348     DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head)
349     {
350     struct Client *client_p = ptr->data;
351    
352     if (client_p->localClient->reject_delay > 0)
353     {
354     if (client_p->localClient->reject_delay <= CurrentTime)
355 adx 224 exit_client(client_p, &me, "Rejected");
356 adx 30 continue;
357     }
358    
359     /* Check UNKNOWN connections - if they have been in this state
360     * for > 30s, close them.
361     */
362     if (client_p->firsttime ? ((CurrentTime - client_p->firsttime) > 30) : 0)
363     exit_client(client_p, &me, "Connection timed out");
364     }
365     }
366    
367     /* check_conf_klines()
368     *
369     * inputs - NONE
370     * output - NONE
371     * side effects - Check all connections for a pending kline against the
372     * client, exit the client if a kline matches.
373     */
374     void
375     check_conf_klines(void)
376     {
377     struct Client *client_p = NULL; /* current local client_p being examined */
378     struct AccessItem *aconf = NULL;
379     struct ConfItem *conf = NULL;
380     dlink_node *ptr, *next_ptr;
381    
382     DLINK_FOREACH_SAFE(ptr, next_ptr, local_client_list.head)
383     {
384     client_p = ptr->data;
385    
386     /* If a client is already being exited
387     */
388     if (IsDead(client_p) || !IsClient(client_p))
389     continue;
390    
391     /* if there is a returned struct ConfItem then kill it */
392     if ((aconf = find_dline_conf(&client_p->localClient->ip,
393     client_p->localClient->aftype)) != NULL)
394     {
395     if (aconf->status & CONF_EXEMPTDLINE)
396 adx 224 continue;
397 adx 30
398 db 141 conf = aconf->conf_ptr;
399 adx 30 ban_them(client_p, conf);
400     continue; /* and go examine next fd/client_p */
401     }
402    
403 adx 224 if (ConfigFileEntry.glines && (aconf = find_gline(client_p)) != NULL)
404 adx 30 {
405 adx 224 if (IsExemptKline(client_p) || IsExemptGline(client_p))
406 adx 30 {
407     sendto_realops_flags(UMODE_ALL, L_ALL,
408 adx 224 "GLINE over-ruled for %s, client is %cline_exempt",
409     get_client_name(client_p, HIDE_IP),
410     IsExemptKline(client_p) ? 'k' : 'g');
411 adx 30 continue;
412     }
413    
414 db 141 conf = aconf->conf_ptr;
415 adx 30 ban_them(client_p, conf);
416     /* and go examine next fd/client_p */
417     continue;
418     }
419    
420     if ((aconf = find_kill(client_p)) != NULL)
421     {
422    
423     /* if there is a returned struct AccessItem.. then kill it */
424     if (IsExemptKline(client_p))
425     {
426     sendto_realops_flags(UMODE_ALL, L_ALL,
427     "KLINE over-ruled for %s, client is kline_exempt",
428     get_client_name(client_p, HIDE_IP));
429     continue;
430     }
431    
432 db 141 conf = aconf->conf_ptr;
433 adx 30 ban_them(client_p, conf);
434     continue;
435     }
436    
437     /* if there is a returned struct MatchItem then kill it */
438     if ((conf = find_matching_name_conf(XLINE_TYPE, client_p->info,
439     NULL, NULL, 0)) != NULL ||
440     (conf = find_matching_name_conf(RXLINE_TYPE, client_p->info,
441     NULL, NULL, 0)) != NULL)
442     {
443     ban_them(client_p, conf);
444     continue;
445     }
446     }
447    
448     /* also check the unknowns list for new dlines */
449     DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head)
450     {
451     client_p = ptr->data;
452    
453     if ((aconf = find_dline_conf(&client_p->localClient->ip,
454     client_p->localClient->aftype)))
455     {
456     if (aconf->status & CONF_EXEMPTDLINE)
457     continue;
458    
459     exit_client(client_p, &me, "D-lined");
460     }
461     }
462     }
463    
464     /*
465     * ban_them
466     *
467     * inputs - pointer to client to ban
468     * - pointer to ConfItem
469     * output - NONE
470     * side effects - given client_p is banned
471     */
472     static void
473     ban_them(struct Client *client_p, struct ConfItem *conf)
474     {
475     const char *user_reason = NULL; /* What is sent to user */
476     const char *channel_reason = NULL; /* What is sent to channel */
477     struct AccessItem *aconf = NULL;
478     struct MatchItem *xconf = NULL;
479     const char *type_string = NULL;
480     const char dline_string[] = "D-line";
481     const char kline_string[] = "K-line";
482     const char gline_string[] = "G-line";
483     const char xline_string[] = "X-line";
484    
485     switch (conf->type)
486     {
487     case RKLINE_TYPE:
488     case KLINE_TYPE:
489     type_string = kline_string;
490 db 139 aconf = &conf->conf.AccessItem;
491 adx 30 break;
492     case DLINE_TYPE:
493     type_string = dline_string;
494 db 139 aconf = &conf->conf.AccessItem;
495 adx 30 break;
496     case GLINE_TYPE:
497     type_string = gline_string;
498 db 139 aconf = &conf->conf.AccessItem;
499 adx 30 break;
500     case RXLINE_TYPE:
501     case XLINE_TYPE:
502     type_string = xline_string;
503 db 139 xconf = &conf->conf.MatchItem;
504 adx 30 ++xconf->count;
505     break;
506     default:
507     assert(0);
508     break;
509     }
510    
511     if (ConfigFileEntry.kline_with_reason)
512     {
513     if (aconf != NULL)
514     user_reason = aconf->reason ? aconf->reason : type_string;
515     if (xconf != NULL)
516     user_reason = xconf->reason ? xconf->reason : type_string;
517     }
518     else
519     user_reason = type_string;
520    
521     if (ConfigFileEntry.kline_reason != NULL)
522     channel_reason = ConfigFileEntry.kline_reason;
523     else
524     channel_reason = user_reason;
525    
526     sendto_realops_flags(UMODE_ALL, L_ALL, "%s active for %s",
527     type_string, get_client_name(client_p, HIDE_IP));
528    
529     if (IsClient(client_p))
530     sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP),
531     me.name, client_p->name, user_reason);
532    
533     exit_client(client_p, &me, channel_reason);
534     }
535    
536     /* update_client_exit_stats()
537     *
538     * input - pointer to client
539     * output - NONE
540     * side effects -
541     */
542     static void
543     update_client_exit_stats(struct Client *client_p)
544     {
545 michael 529 if (IsClient(client_p))
546 adx 30 {
547     --Count.total;
548     if (IsOper(client_p))
549     --Count.oper;
550     if (IsInvisible(client_p))
551     --Count.invisi;
552     }
553 michael 529 else if (IsServer(client_p))
554     sendto_realops_flags(UMODE_EXTERNAL, L_ALL,
555     "Server %s split from %s",
556     client_p->name, client_p->servptr->name);
557 adx 30
558     if (splitchecking && !splitmode)
559     check_splitmode(NULL);
560     }
561    
562     /* find_person()
563     *
564     * inputs - pointer to name
565     * output - return client pointer
566     * side effects - find person by (nick)name
567     */
568     /* XXX - ugly wrapper */
569     struct Client *
570     find_person(const struct Client *client_p, const char *name)
571     {
572     struct Client *c2ptr;
573    
574     if (IsDigit(*name))
575     {
576     if ((c2ptr = hash_find_id(name)) != NULL)
577     {
578     /* invisible users shall not be found by UID guessing */
579     if (IsInvisible(c2ptr) && !IsServer(client_p))
580     c2ptr = NULL;
581     }
582     }
583     else
584     c2ptr = find_client(name);
585    
586     return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL);
587     }
588    
589     /*
590     * find_chasing - find the client structure for a nick name (user)
591     * using history mechanism if necessary. If the client is not found,
592     * an error message (NO SUCH NICK) is generated. If the client was found
593     * through the history, chasing will be 1 and otherwise 0.
594     */
595     struct Client *
596     find_chasing(struct Client *client_p, struct Client *source_p, const char *user, int *chasing)
597     {
598     struct Client *who = find_person(client_p, user);
599    
600     if (chasing)
601     *chasing = 0;
602    
603     if (who)
604 michael 450 return who;
605 adx 30
606     if (IsDigit(*user))
607 michael 450 return NULL;
608 adx 30
609     if ((who = get_history(user,
610     (time_t)ConfigFileEntry.kill_chase_time_limit))
611     == NULL)
612     {
613     sendto_one(source_p, form_str(ERR_NOSUCHNICK),
614     me.name, source_p->name, user);
615 michael 450 return NULL;
616 adx 30 }
617    
618     if (chasing)
619     *chasing = 1;
620    
621 michael 450 return who;
622 adx 30 }
623    
624     /*
625     * get_client_name - Return the name of the client
626     * for various tracking and
627     * admin purposes. The main purpose of this function is to
628     * return the "socket host" name of the client, if that
629     * differs from the advertised name (other than case).
630     * But, this can be used to any client structure.
631     *
632     * NOTE 1:
633     * Watch out the allocation of "nbuf", if either source_p->name
634     * or source_p->sockhost gets changed into pointers instead of
635     * directly allocated within the structure...
636     *
637     * NOTE 2:
638     * Function return either a pointer to the structure (source_p) or
639     * to internal buffer (nbuf). *NEVER* use the returned pointer
640     * to modify what it points!!!
641     */
642     const char *
643 michael 551 get_client_name(const struct Client *client, int showip)
644 adx 30 {
645     static char nbuf[HOSTLEN * 2 + USERLEN + 5];
646    
647     assert(client != NULL);
648    
649 michael 551 if (!irccmp(client->name, client->host))
650 michael 450 return client->name;
651 adx 30
652     if (ConfigServerHide.hide_server_ips)
653     if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
654     showip = MASK_IP;
655    
656     if (ConfigFileEntry.hide_spoof_ips)
657     if (showip == SHOW_IP && IsIPSpoof(client))
658     showip = MASK_IP;
659    
660     /* And finally, let's get the host information, ip or name */
661     switch (showip)
662     {
663     case SHOW_IP:
664     if (MyConnect(client))
665     {
666     ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username,
667     client->sockhost);
668     break;
669     }
670     case MASK_IP:
671     ircsprintf(nbuf, "%s[%s@255.255.255.255]", client->name,
672     client->username);
673     break;
674     default:
675     ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username,
676     client->host);
677     }
678    
679 michael 450 return nbuf;
680 adx 30 }
681    
682     void
683     free_exited_clients(void)
684     {
685     dlink_node *ptr, *next;
686     struct Client *target_p;
687    
688     DLINK_FOREACH_SAFE(ptr, next, dead_list.head)
689     {
690     target_p = ptr->data;
691    
692     if (ptr->data == NULL)
693     {
694     sendto_realops_flags(UMODE_ALL, L_ALL,
695     "Warning: null client on dead_list!");
696     dlinkDelete(ptr, &dead_list);
697     free_dlink_node(ptr);
698     continue;
699     }
700    
701     free_client(target_p);
702     dlinkDelete(ptr, &dead_list);
703     free_dlink_node(ptr);
704     }
705     }
706    
707     /*
708     * Exit one client, local or remote. Assuming all dependents have
709     * been already removed, and socket closed for local client.
710     *
711     * The only messages generated are QUITs on channels.
712     */
713     static void
714     exit_one_client(struct Client *source_p, const char *quitmsg)
715     {
716     dlink_node *lp = NULL, *next_lp = NULL;
717    
718 michael 529 assert(!IsMe(source_p) && (source_p != &me));
719 adx 30
720 michael 529 if (IsClient(source_p))
721 adx 30 {
722     if (source_p->servptr->serv != NULL)
723     dlinkDelete(&source_p->lnode, &source_p->servptr->serv->users);
724    
725 michael 315 /*
726     * If a person is on a channel, send a QUIT notice
727     * to every client (person) on the same channel (so
728     * that the client can show the "**signoff" message).
729     * (Note: The notice is to the local clients *only*)
730     */
731 adx 30 sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s",
732     source_p->name, source_p->username,
733     source_p->host, quitmsg);
734     DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
735     remove_user_from_channel(lp->data);
736    
737     add_history(source_p, 0);
738     off_history(source_p);
739    
740 michael 193 assert(source_p->whowas.head == NULL);
741     assert(source_p->whowas.tail == NULL);
742    
743 michael 568 hash_check_watch(source_p, RPL_LOGOFF);
744    
745 db 238 /* Do local vs. remote processing here */
746     if (MyConnect(source_p))
747 adx 30 {
748 michael 315 /* Clean up invitefield */
749 michael 316 DLINK_FOREACH_SAFE(lp, next_lp, source_p->localClient->invited.head)
750 michael 315 del_invite(lp->data, source_p);
751    
752 db 238 /* Clean up allow lists */
753     del_all_accepts(source_p);
754     }
755     else
756     {
757 adx 30 source_p->from->serv->dep_users--;
758     assert(source_p->from->serv->dep_users >= 0);
759     }
760     }
761 michael 529 else if (IsServer(source_p))
762     {
763     dlinkDelete(&source_p->lnode, &source_p->servptr->serv->servers);
764 adx 30
765 michael 529 if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL)
766     free_dlink_node(lp);
767    
768     if (!MyConnect(source_p))
769     {
770     source_p->from->serv->dep_servers--;
771     assert(source_p->from->serv->dep_servers > 0);
772     }
773     }
774    
775 adx 30 /* Remove source_p from the client lists */
776     if (HasID(source_p))
777     hash_del_id(source_p);
778     if (source_p->name[0])
779     hash_del_client(source_p);
780    
781     if (IsUserHostIp(source_p))
782     delete_user_host(source_p->username, source_p->host, !MyConnect(source_p));
783    
784     /* remove from global client list
785     * NOTE: source_p->node.next cannot be NULL if the client is added
786     * to global_client_list (there is always &me at its end)
787     */
788     if (source_p != NULL && source_p->node.next != NULL)
789     dlinkDelete(&source_p->node, &global_client_list);
790    
791     update_client_exit_stats(source_p);
792    
793     /* Check to see if the client isn't already on the dead list */
794     assert(dlinkFind(&dead_list, source_p) == NULL);
795    
796     /* add to dead client dlist */
797     SetDead(source_p);
798     dlinkAdd(source_p, make_dlink_node(), &dead_list);
799     }
800    
801     /* Recursively send QUITs and SQUITs for source_p and all its dependent clients
802     * and servers to those servers that need them. A server needs the client
803     * QUITs if it can't figure them out from the SQUIT (ie pre-TS4) or if it
804     * isn't getting the SQUIT because of @#(*&@)# hostmasking. With TS4, once
805     * a link gets a SQUIT, it doesn't need any QUIT/SQUITs for clients depending
806     * on that one -orabidoo
807     *
808     * This is now called on each local server -adx
809     */
810     static void
811     recurse_send_quits(struct Client *original_source_p, struct Client *source_p,
812     struct Client *from, struct Client *to, const char *comment,
813     const char *splitstr, const char *myname)
814     {
815     dlink_node *ptr, *next;
816     struct Client *target_p;
817     int hidden = match(myname, source_p->name);
818    
819     assert(to != source_p); /* should be already removed from serv_list */
820    
821     /* If this server can handle quit storm (QS) removal
822     * of dependents, just send the SQUIT
823     *
824     * Always check *all* dependent servers if some of them are
825     * hidden behind fakename. If so, send out the QUITs -adx
826     */
827     if (hidden || !IsCapable(to, CAP_QS))
828     DLINK_FOREACH_SAFE(ptr, next, source_p->serv->users.head)
829     {
830     target_p = ptr->data;
831     sendto_one(to, ":%s QUIT :%s", target_p->name, splitstr);
832     }
833    
834     DLINK_FOREACH_SAFE(ptr, next, source_p->serv->servers.head)
835     recurse_send_quits(original_source_p, ptr->data, from, to,
836     comment, splitstr, myname);
837    
838     if (!hidden && ((source_p == original_source_p && to != from) ||
839     !IsCapable(to, CAP_QS)))
840     {
841     /* don't use a prefix here - we have to be 100% sure the message
842     * will be accepted without Unknown prefix etc.. */
843     sendto_one(to, "SQUIT %s :%s", ID_or_name(source_p, to), comment);
844     }
845     }
846    
847     /*
848     * Remove all clients that depend on source_p; assumes all (S)QUITs have
849     * already been sent. we make sure to exit a server's dependent clients
850     * and servers before the server itself; exit_one_client takes care of
851     * actually removing things off llists. tweaked from +CSr31 -orabidoo
852     */
853     static void
854     recurse_remove_clients(struct Client *source_p, const char *quitmsg)
855     {
856     dlink_node *ptr, *next;
857    
858     DLINK_FOREACH_SAFE(ptr, next, source_p->serv->users.head)
859     exit_one_client(ptr->data, quitmsg);
860    
861     DLINK_FOREACH_SAFE(ptr, next, source_p->serv->servers.head)
862     {
863     recurse_remove_clients(ptr->data, quitmsg);
864     exit_one_client(ptr->data, quitmsg);
865     }
866    
867     assert(source_p->serv->dep_servers == 1);
868     assert(source_p->serv->dep_users == 0);
869     }
870    
871     /*
872     ** Remove *everything* that depends on source_p, from all lists, and sending
873     ** all necessary QUITs and SQUITs. source_p itself is still on the lists,
874     ** and its SQUITs have been sent except for the upstream one -orabidoo
875     */
876     static void
877     remove_dependents(struct Client *source_p, struct Client *from,
878     const char *comment, const char *splitstr)
879     {
880     struct Client *to;
881     struct ConfItem *conf;
882 db 126 struct AccessItem *aconf;
883 adx 30 static char myname[HOSTLEN+1];
884     dlink_node *ptr;
885    
886     DLINK_FOREACH(ptr, serv_list.head)
887     {
888     to = ptr->data;
889    
890     if ((conf = to->serv->sconf) != NULL)
891 db 126 {
892 db 139 aconf = &conf->conf.AccessItem;
893 db 126 strlcpy(myname, my_name_for_link(aconf), sizeof(myname));
894     }
895 adx 30 else
896     strlcpy(myname, me.name, sizeof(myname));
897     recurse_send_quits(source_p, source_p, from, to,
898     comment, splitstr, myname);
899     }
900    
901     recurse_remove_clients(source_p, splitstr);
902     }
903    
904     /*
905     * exit_client - exit a client of any type. Generally, you can use
906     * this on any struct Client, regardless of its state.
907     *
908     * Note, you shouldn't exit remote _users_ without first doing
909     * SetKilled and propagating a kill or similar message. However,
910     * it is perfectly correct to call exit_client to force a _server_
911     * quit (either local or remote one).
912     *
913     * inputs: - a client pointer that is going to be exited
914     * - for servers, the second argument is a pointer to who
915     * is firing the server. This side won't get any generated
916     * messages. NEVER NULL!
917     * output: none
918     * side effects: the client is delinked from all lists, disconnected,
919     * and the rest of IRC network is notified of the exit.
920     * Client memory is scheduled to be freed
921     */
922     void
923     exit_client(struct Client *source_p, struct Client *from, const char *comment)
924     {
925 michael 568 dlink_node *m = NULL;
926 adx 30
927     if (MyConnect(source_p))
928     {
929 michael 568 /*
930     * DO NOT REMOVE. exit_client can be called twice after a failed
931 adx 30 * read/write.
932     */
933     if (IsClosing(source_p))
934     return;
935    
936     SetClosing(source_p);
937    
938     if (IsIpHash(source_p))
939     remove_one_ip(&source_p->localClient->ip);
940    
941     delete_auth(source_p);
942    
943 michael 471 if (IsClient(source_p))
944 adx 30 {
945 michael 450 --Count.local;
946 adx 30
947     if (IsOper(source_p))
948     {
949     if ((m = dlinkFindDelete(&oper_list, source_p)) != NULL)
950     free_dlink_node(m);
951     }
952    
953     dlinkDelete(&source_p->localClient->lclient_node, &local_client_list);
954     if (source_p->localClient->list_task != NULL)
955     free_list_task(source_p->localClient->list_task, source_p);
956 michael 471
957 michael 221 hash_del_watch_list(source_p);
958 adx 30 sendto_realops_flags(UMODE_CCONN, L_ALL, "Client exiting: %s (%s@%s) [%s] [%s]",
959     source_p->name, source_p->username, source_p->host, comment,
960     ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
961     "255.255.255.255" : source_p->sockhost);
962     }
963 michael 471 else if (!IsRegistered(source_p))
964     {
965     /*
966     * This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
967     * STAT_HANDSHAKE or STAT_UNKNOWN
968     * all of which are lumped together into unknown_list
969     *
970     * In all above cases IsRegistered() will not be true.
971     */
972     dlinkDelete(&source_p->localClient->lclient_node, &unknown_list);
973     }
974 adx 30
975     /* As soon as a client is known to be a server of some sort
976     * it has to be put on the serv_list, or SJOIN's to this new server
977     * from the connect burst will not be seen.
978     */
979 michael 398 if (IsServer(source_p) || IsConnecting(source_p) || IsHandshake(source_p))
980 adx 30 {
981     if ((m = dlinkFindDelete(&serv_list, source_p)) != NULL)
982     {
983     free_dlink_node(m);
984     unset_chcap_usage_counts(source_p);
985     }
986    
987     if (IsServer(source_p))
988 michael 398 --Count.myserver;
989 adx 30 }
990    
991     log_user_exit(source_p);
992    
993     if (!IsDead(source_p))
994     {
995     if (IsServer(source_p))
996     {
997     /* for them, we are exiting the network */
998     sendto_one(source_p, ":%s SQUIT %s :%s",
999     ID_or_name(from, source_p), me.name, comment);
1000     }
1001    
1002     sendto_one(source_p, "ERROR :Closing Link: %s (%s)",
1003     source_p->host, comment);
1004     }
1005    
1006     /*
1007     ** Currently only server connections can have
1008     ** depending remote clients here, but it does no
1009     ** harm to check for all local clients. In
1010     ** future some other clients than servers might
1011     ** have remotes too...
1012     **
1013     ** Close the Client connection first and mark it
1014     ** so that no messages are attempted to send to it.
1015     ** Remember it makes source_p->from == NULL.
1016     */
1017     close_connection(source_p);
1018     }
1019    
1020 michael 529 if (IsClient(source_p) && !IsKilled(source_p))
1021 adx 30 {
1022 michael 529 sendto_server(from->from, source_p, NULL, CAP_TS6, NOCAPS,
1023     ":%s QUIT :%s", ID(source_p), comment);
1024     sendto_server(from->from, source_p, NULL, NOCAPS, CAP_TS6,
1025     ":%s QUIT :%s", source_p->name, comment);
1026     }
1027     else if (IsServer(source_p))
1028     {
1029 adx 30 char splitstr[HOSTLEN + HOSTLEN + 2];
1030    
1031     /* This shouldn't ever happen */
1032     assert(source_p->serv != NULL && source_p->servptr != NULL);
1033    
1034     if (ConfigServerHide.hide_servers)
1035 michael 398 /*
1036     * set netsplit message to "*.net *.split" to still show
1037 adx 30 * that its a split, but hide the servers splitting
1038     */
1039     strcpy(splitstr, "*.net *.split");
1040     else
1041     snprintf(splitstr, sizeof(splitstr), "%s %s",
1042     source_p->servptr->name, source_p->name);
1043    
1044     remove_dependents(source_p, from->from, comment, splitstr);
1045    
1046     if (source_p->servptr == &me)
1047     {
1048     sendto_realops_flags(UMODE_ALL, L_ALL,
1049     "%s was connected for %d seconds. %llu/%llu sendK/recvK.",
1050     source_p->name, (int)(CurrentTime - source_p->firsttime),
1051     source_p->localClient->send.bytes >> 10,
1052     source_p->localClient->recv.bytes >> 10);
1053     ilog(L_NOTICE, "%s was connected for %d seconds. %llu/%llu sendK/recvK.",
1054     source_p->name, (int)(CurrentTime - source_p->firsttime),
1055     source_p->localClient->send.bytes >> 10,
1056     source_p->localClient->recv.bytes >> 10);
1057     }
1058     }
1059    
1060     /* The client *better* be off all of the lists */
1061     assert(dlinkFind(&unknown_list, source_p) == NULL);
1062     assert(dlinkFind(&local_client_list, source_p) == NULL);
1063     assert(dlinkFind(&serv_list, source_p) == NULL);
1064     assert(dlinkFind(&oper_list, source_p) == NULL);
1065    
1066     exit_one_client(source_p, comment);
1067     }
1068    
1069     /*
1070 adx 68 * close_connection
1071     * Close the physical connection. This function must make
1072     * MyConnect(client_p) == FALSE, and set client_p->from == NULL.
1073     */
1074     static void
1075     close_connection(struct Client *client_p)
1076     {
1077     struct ConfItem *conf;
1078     struct AccessItem *aconf;
1079     struct ClassItem *aclass;
1080    
1081     assert(NULL != client_p);
1082    
1083 michael 529 if (IsClient(client_p))
1084 adx 68 {
1085 michael 529 ++ServerStats.is_cl;
1086     ServerStats.is_cbs += client_p->localClient->send.bytes;
1087     ServerStats.is_cbr += client_p->localClient->recv.bytes;
1088     ServerStats.is_cti += CurrentTime - client_p->firsttime;
1089     }
1090     else if (IsServer(client_p))
1091     {
1092 michael 515 ++ServerStats.is_sv;
1093     ServerStats.is_sbs += client_p->localClient->send.bytes;
1094     ServerStats.is_sbr += client_p->localClient->recv.bytes;
1095     ServerStats.is_sti += CurrentTime - client_p->firsttime;
1096 adx 68
1097     /* XXX Does this even make any sense at all anymore?
1098     * scheduling a 'quick' reconnect could cause a pile of
1099     * nick collides under TSora protocol... -db
1100     */
1101     /*
1102     * If the connection has been up for a long amount of time, schedule
1103     * a 'quick' reconnect, else reset the next-connect cycle.
1104     */
1105 db 101 if ((conf = find_exact_name_conf(SERVER_TYPE,
1106     client_p->name, client_p->username,
1107     client_p->host)))
1108 adx 68 {
1109     /*
1110     * Reschedule a faster reconnect, if this was a automatically
1111     * connected configuration entry. (Note that if we have had
1112     * a rehash in between, the status has been changed to
1113     * CONF_ILLEGAL). But only do this if it was a "good" link.
1114     */
1115 db 139 aconf = &conf->conf.AccessItem;
1116     aclass = &((struct ConfItem *)aconf->class_ptr)->conf.ClassItem;
1117 adx 68 aconf->hold = time(NULL);
1118     aconf->hold += (aconf->hold - client_p->since > HANGONGOODLINK) ?
1119     HANGONRETRYDELAY : ConFreq(aclass);
1120     }
1121     }
1122     else
1123 michael 515 ++ServerStats.is_ni;
1124 adx 68
1125     if (!IsDead(client_p))
1126     {
1127     /* attempt to flush any pending dbufs. Evil, but .. -- adrian */
1128     /* there is still a chance that we might send data to this socket
1129     * even if it is marked as blocked (COMM_SELECT_READ handler is called
1130     * before COMM_SELECT_WRITE). Let's try, nothing to lose.. -adx
1131     */
1132     ClearSendqBlocked(client_p);
1133     send_queued_write(client_p);
1134     }
1135    
1136     #ifdef HAVE_LIBCRYPTO
1137     if (client_p->localClient->fd.ssl)
1138 michael 452 {
1139     SSL_set_shutdown(client_p->localClient->fd.ssl, SSL_RECEIVED_SHUTDOWN);
1140    
1141     if (!SSL_shutdown(client_p->localClient->fd.ssl))
1142     SSL_shutdown(client_p->localClient->fd.ssl);
1143     }
1144 adx 68 #endif
1145     if (client_p->localClient->fd.flags.open)
1146     fd_close(&client_p->localClient->fd);
1147    
1148     if (HasServlink(client_p))
1149     {
1150     if (client_p->localClient->ctrlfd.flags.open)
1151     fd_close(&client_p->localClient->ctrlfd);
1152     }
1153    
1154     dbuf_clear(&client_p->localClient->buf_sendq);
1155     dbuf_clear(&client_p->localClient->buf_recvq);
1156    
1157     MyFree(client_p->localClient->passwd);
1158 adx 365 detach_confs(client_p);
1159 adx 68 client_p->from = NULL; /* ...this should catch them! >:) --msa */
1160     }
1161    
1162     /*
1163     * report_error - report an error from an errno.
1164     * Record error to log and also send a copy to all *LOCAL* opers online.
1165     *
1166     * text is a *format* string for outputing error. It must
1167     * contain only two '%s', the first will be replaced
1168     * by the sockhost from the client_p, and the latter will
1169     * be taken from sys_errlist[errno].
1170     *
1171     * client_p if not NULL, is the *LOCAL* client associated with
1172     * the error.
1173     *
1174     * Cannot use perror() within daemon. stderr is closed in
1175     * ircd and cannot be used. And, worse yet, it might have
1176     * been reassigned to a normal connection...
1177     *
1178     * Actually stderr is still there IFF ircd was run with -s --Rodder
1179     */
1180     void
1181 adx 224 report_error(int level, const char *text, const char *who, int error)
1182 adx 68 {
1183 adx 224 who = (who != NULL) ? who : "";
1184 adx 68
1185     sendto_realops_flags(UMODE_DEBUG, level, text, who, strerror(error));
1186     log_oper_action(LOG_IOERR_TYPE, NULL, "%s %s %s\n", who, text, strerror(error));
1187     ilog(L_ERROR, text, who, strerror(error));
1188     }
1189    
1190     /*
1191 adx 30 * dead_link_on_write - report a write error if not already dead,
1192     * mark it as dead then exit it
1193     */
1194     void
1195     dead_link_on_write(struct Client *client_p, int ierrno)
1196     {
1197     dlink_node *ptr;
1198    
1199     if (IsDefunct(client_p))
1200     return;
1201    
1202     dbuf_clear(&client_p->localClient->buf_recvq);
1203     dbuf_clear(&client_p->localClient->buf_sendq);
1204    
1205     assert(dlinkFind(&abort_list, client_p) == NULL);
1206     ptr = make_dlink_node();
1207     /* don't let exit_aborted_clients() finish yet */
1208     dlinkAddTail(client_p, ptr, &abort_list);
1209    
1210     if (eac_next == NULL)
1211     eac_next = ptr;
1212    
1213     SetDead(client_p); /* You are dead my friend */
1214     }
1215    
1216     /*
1217     * dead_link_on_read - report a read error if not already dead,
1218     * mark it as dead then exit it
1219     */
1220     void
1221     dead_link_on_read(struct Client *client_p, int error)
1222     {
1223     char errmsg[255];
1224     int current_error;
1225    
1226     if (IsDefunct(client_p))
1227     return;
1228    
1229     dbuf_clear(&client_p->localClient->buf_recvq);
1230     dbuf_clear(&client_p->localClient->buf_sendq);
1231    
1232     current_error = get_sockerr(client_p->localClient->fd.fd);
1233    
1234     if (IsServer(client_p) || IsHandshake(client_p))
1235     {
1236     int connected = CurrentTime - client_p->firsttime;
1237    
1238     if (error == 0)
1239     {
1240     /* Admins get the real IP */
1241     sendto_realops_flags(UMODE_ALL, L_ADMIN,
1242     "Server %s closed the connection",
1243     get_client_name(client_p, SHOW_IP));
1244    
1245     /* Opers get a masked IP */
1246     sendto_realops_flags(UMODE_ALL, L_OPER,
1247     "Server %s closed the connection",
1248     get_client_name(client_p, MASK_IP));
1249    
1250     ilog(L_NOTICE, "Server %s closed the connection",
1251     get_client_name(client_p, SHOW_IP));
1252     }
1253     else
1254     {
1255     report_error(L_ADMIN, "Lost connection to %s: %d",
1256     get_client_name(client_p, SHOW_IP), current_error);
1257     report_error(L_OPER, "Lost connection to %s: %d",
1258     get_client_name(client_p, MASK_IP), current_error);
1259     }
1260    
1261     sendto_realops_flags(UMODE_ALL, L_ALL,
1262     "%s had been connected for %d day%s, %2d:%02d:%02d",
1263     client_p->name, connected/86400,
1264     (connected/86400 == 1) ? "" : "s",
1265     (connected % 86400) / 3600, (connected % 3600) / 60,
1266     connected % 60);
1267     }
1268    
1269     if (error == 0)
1270     strlcpy(errmsg, "Remote host closed the connection",
1271     sizeof(errmsg));
1272     else
1273     ircsprintf(errmsg, "Read error: %s",
1274     strerror(current_error));
1275    
1276     exit_client(client_p, &me, errmsg);
1277     }
1278    
1279     void
1280     exit_aborted_clients(void)
1281     {
1282     dlink_node *ptr;
1283     struct Client *target_p;
1284     const char *notice;
1285    
1286     DLINK_FOREACH_SAFE(ptr, eac_next, abort_list.head)
1287     {
1288     target_p = ptr->data;
1289     eac_next = ptr->next;
1290    
1291     if (target_p == NULL)
1292     {
1293     sendto_realops_flags(UMODE_ALL, L_ALL,
1294     "Warning: null client on abort_list!");
1295     dlinkDelete(ptr, &abort_list);
1296     free_dlink_node(ptr);
1297     continue;
1298     }
1299    
1300     dlinkDelete(ptr, &abort_list);
1301    
1302     if (IsSendQExceeded(target_p))
1303     notice = "Max SendQ exceeded";
1304     else
1305     notice = "Write error: connection closed";
1306    
1307     exit_client(target_p, &me, notice);
1308     free_dlink_node(ptr);
1309     }
1310     }
1311    
1312     /*
1313     * accept processing, this adds a form of "caller ID" to ircd
1314     *
1315     * If a client puts themselves into "caller ID only" mode,
1316     * only clients that match a client pointer they have put on
1317     * the accept list will be allowed to message them.
1318     *
1319 db 232 * Diane Bruce, "Dianora" db@db.net
1320 adx 30 */
1321    
1322 michael 235 void
1323 metalrock 362 del_accept(struct Accept *acceptvar, struct Client *client_p)
1324 michael 235 {
1325 metalrock 362 dlinkDelete(&acceptvar->node, &client_p->localClient->acceptlist);
1326 michael 235
1327 metalrock 362 MyFree(acceptvar->nick);
1328     MyFree(acceptvar->user);
1329     MyFree(acceptvar->host);
1330     MyFree(acceptvar);
1331 michael 235 }
1332    
1333     struct Accept *
1334     find_accept(const char *nick, const char *user,
1335     const char *host, struct Client *client_p, int do_match)
1336     {
1337     dlink_node *ptr = NULL;
1338     /* XXX We wouldn't need that if match() would return 0 on match */
1339     int (*cmpfunc)(const char *, const char *) = do_match ? match : irccmp;
1340    
1341     DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1342     {
1343 metalrock 362 struct Accept *acceptvar = ptr->data;
1344 michael 235
1345 metalrock 362 if (cmpfunc(acceptvar->nick, nick) == do_match &&
1346     cmpfunc(acceptvar->user, user) == do_match &&
1347     cmpfunc(acceptvar->host, host) == do_match)
1348     return acceptvar;
1349 michael 235 }
1350    
1351     return NULL;
1352     }
1353    
1354 adx 30 /* accept_message()
1355     *
1356 michael 385 * inputs - pointer to source client
1357 adx 30 * - pointer to target client
1358     * output - 1 if accept this message 0 if not
1359     * side effects - See if source is on target's allow list
1360     */
1361     int
1362 michael 235 accept_message(struct Client *source,
1363     struct Client *target)
1364 adx 30 {
1365 michael 235 dlink_node *ptr = NULL;
1366 adx 30
1367 michael 236 if (source == target || find_accept(source->name, source->username,
1368     source->host, target, 1))
1369 michael 235 return 1;
1370 adx 30
1371 michael 235 if (IsSoftCallerId(target))
1372 adx 30 DLINK_FOREACH(ptr, target->channel.head)
1373 michael 385 if (IsMember(source, ((struct Membership *)ptr->data)->chptr))
1374 michael 235 return 1;
1375 adx 30
1376 michael 235 return 0;
1377 adx 30 }
1378    
1379     /* del_all_accepts()
1380     *
1381     * inputs - pointer to exiting client
1382     * output - NONE
1383 db 232 * side effects - Walk through given clients acceptlist and remove all entries
1384 adx 30 */
1385     void
1386     del_all_accepts(struct Client *client_p)
1387     {
1388 michael 235 dlink_node *ptr = NULL, *next_ptr = NULL;
1389 adx 30
1390 db 232 DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head)
1391 michael 235 del_accept(ptr->data, client_p);
1392 adx 30 }
1393    
1394     /* set_initial_nick()
1395     *
1396     * inputs
1397     * output
1398     * side effects -
1399     *
1400     * This function is only called to set up an initially registering
1401     * client.
1402     */
1403     void
1404 michael 457 set_initial_nick(struct Client *source_p, const char *nick)
1405 adx 30 {
1406 michael 237 char buf[USERLEN + 1];
1407 adx 30
1408     /* This had to be copied here to avoid problems.. */
1409     source_p->tsinfo = CurrentTime;
1410 michael 502 source_p->localClient->registration &= ~REG_NEED_NICK;
1411 adx 30
1412     if (source_p->name[0])
1413     hash_del_client(source_p);
1414    
1415     strlcpy(source_p->name, nick, sizeof(source_p->name));
1416     hash_add_client(source_p);
1417    
1418     /* fd_desc is long enough */
1419 db 460 fd_note(&source_p->localClient->fd, "Nick: %s", nick);
1420 adx 30
1421 michael 502 if (!source_p->localClient->registration)
1422 adx 30 {
1423     strlcpy(buf, source_p->username, sizeof(buf));
1424    
1425     /*
1426     * USER already received, now we have NICK.
1427     * *NOTE* For servers "NICK" *must* precede the
1428     * user message (giving USER before NICK is possible
1429     * only for local client connection!). register_user
1430     * may reject the client and call exit_client for it
1431     * --must test this and exit m_nick too!!!
1432     */
1433 michael 458 register_local_user(source_p, buf);
1434 adx 30 }
1435     }
1436    
1437     /* change_local_nick()
1438     *
1439     * inputs - pointer to server
1440     * - pointer to client
1441     * - nick
1442     * output -
1443     * side effects - changes nick of a LOCAL user
1444     */
1445     void
1446     change_local_nick(struct Client *client_p, struct Client *source_p, const char *nick)
1447     {
1448 michael 221 int samenick = 0;
1449 michael 237
1450 adx 30 /*
1451 michael 237 * Client just changing his/her nick. If he/she is
1452     * on a channel, send note of change to all clients
1453     * on that channel. Propagate notice to other servers.
1454     */
1455 adx 30 if ((source_p->localClient->last_nick_change +
1456     ConfigFileEntry.max_nick_time) < CurrentTime)
1457     source_p->localClient->number_of_nick_changes = 0;
1458     source_p->localClient->last_nick_change = CurrentTime;
1459     source_p->localClient->number_of_nick_changes++;
1460    
1461     if ((ConfigFileEntry.anti_nick_flood &&
1462     (source_p->localClient->number_of_nick_changes
1463     <= ConfigFileEntry.max_nick_changes)) ||
1464     !ConfigFileEntry.anti_nick_flood ||
1465     (IsOper(source_p) && ConfigFileEntry.no_oper_flood))
1466     {
1467 michael 221 samenick = !irccmp(source_p->name, nick);
1468     if (!samenick)
1469 adx 30 source_p->tsinfo = CurrentTime;
1470    
1471     /* XXX - the format of this notice should eventually be changed
1472     * to either %s[%s@%s], or even better would be get_client_name() -bill
1473     */
1474     sendto_realops_flags(UMODE_NCHANGE, L_ALL, "Nick change: From %s to %s [%s@%s]",
1475     source_p->name, nick, source_p->username, source_p->host);
1476     sendto_common_channels_local(source_p, 1, ":%s!%s@%s NICK :%s",
1477     source_p->name, source_p->username,
1478     source_p->host, nick);
1479    
1480     add_history(source_p, 1);
1481 michael 511
1482 michael 405 sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS,
1483 adx 30 ":%s NICK %s :%lu",
1484     ID(source_p), nick, (unsigned long)source_p->tsinfo);
1485 michael 405 sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6,
1486 adx 30 ":%s NICK %s :%lu",
1487     source_p->name, nick, (unsigned long)source_p->tsinfo);
1488     }
1489     else
1490     {
1491     sendto_one(source_p, form_str(ERR_NICKTOOFAST),
1492     me.name, source_p->name, source_p->name,
1493     nick, ConfigFileEntry.max_nick_time);
1494     return;
1495     }
1496    
1497     /* Finally, add to hash */
1498 michael 221 assert(source_p->name[0]);
1499 adx 30
1500 michael 221 hash_del_client(source_p);
1501 michael 511
1502 michael 221 if (!samenick)
1503     hash_check_watch(source_p, RPL_LOGOFF);
1504 adx 30 strcpy(source_p->name, nick);
1505     hash_add_client(source_p);
1506    
1507 michael 221 if (!samenick)
1508     hash_check_watch(source_p, RPL_LOGON);
1509 adx 30
1510     /* fd_desc is long enough */
1511     fd_note(&client_p->localClient->fd, "Nick: %s", nick);
1512     }
1513 adx 65
1514     /* log_user_exit()
1515     *
1516     * inputs - pointer to connecting client
1517     * output - NONE
1518     * side effects - Current exiting client is logged to
1519     * either SYSLOG or to file.
1520     */
1521     void
1522     log_user_exit(struct Client *source_p)
1523     {
1524     time_t on_for = CurrentTime - source_p->firsttime;
1525     #ifdef SYSLOG_USERS
1526     if (IsClient(source_p))
1527     {
1528     ilog(L_INFO, "%s (%3ld:%02ld:%02ld): %s!%s@%s %llu/%llu\n",
1529     myctime(source_p->firsttime),
1530     (signed long) on_for / 3600,
1531     (signed long) (on_for % 3600)/60,
1532     (signed long) on_for % 60,
1533     source_p->name, source_p->username, source_p->host,
1534     source_p->localClient->send.bytes>>10,
1535     source_p->localClient->recv.bytes>>10);
1536     }
1537     #else
1538     {
1539     char linebuf[BUFSIZ];
1540    
1541     /*
1542     * This conditional makes the logfile active only after
1543     * it's been created - thus logging can be turned off by
1544     * removing the file.
1545     * -Taner
1546     */
1547     if (IsClient(source_p))
1548     {
1549     if (user_log_fb == NULL)
1550     {
1551     if ((ConfigLoggingEntry.userlog[0] != '\0') &&
1552     (user_log_fb = fbopen(ConfigLoggingEntry.userlog, "r")) != NULL)
1553     {
1554     fbclose(user_log_fb);
1555     user_log_fb = fbopen(ConfigLoggingEntry.userlog, "a");
1556     }
1557     }
1558    
1559     if (user_log_fb != NULL)
1560     {
1561     size_t nbytes = ircsprintf(linebuf,
1562     "%s (%3ld:%02ld:%02ld): %s!%s@%s %llu/%llu\n",
1563     myctime(source_p->firsttime),
1564     (signed long) on_for / 3600,
1565     (signed long) (on_for % 3600)/60,
1566     (signed long) on_for % 60,
1567     source_p->name, source_p->username, source_p->host,
1568     source_p->localClient->send.bytes>>10,
1569     source_p->localClient->recv.bytes>>10);
1570     fbputs(linebuf, user_log_fb, nbytes);
1571     }
1572     }
1573     }
1574     #endif
1575     }
1576    
1577    
1578     /* log_oper_action()
1579     *
1580     * inputs - type of oper log entry
1581     * - pointer to oper
1582     * - const char *pattern == format string
1583     * - var args for format string
1584     * output - none
1585     * side effects - corresponding log is written to, if its present.
1586     *
1587     * rewritten sept 5 2005 - Dianora
1588     */
1589     void
1590     log_oper_action(int log_type, const struct Client *source_p,
1591     const char *pattern, ...)
1592     {
1593     va_list args;
1594     char linebuf[IRCD_BUFSIZE];
1595     FBFILE *log_fb;
1596     char *logfile;
1597     const char *log_message;
1598     size_t nbytes;
1599     size_t n_preamble;
1600     char *p;
1601    
1602     switch(log_type)
1603     {
1604     case LOG_OPER_TYPE:
1605     logfile = ConfigLoggingEntry.operlog;
1606     log_message = "OPER";
1607     break;
1608     case LOG_FAILED_OPER_TYPE:
1609     logfile = ConfigLoggingEntry.failed_operlog;
1610     log_message = "FAILED OPER";
1611     break;
1612     case LOG_KLINE_TYPE:
1613     logfile = ConfigLoggingEntry.klinelog;
1614     log_message = "KLINE";
1615     break;
1616     case LOG_RKLINE_TYPE:
1617     logfile = ConfigLoggingEntry.klinelog;
1618     log_message = "RKLINE";
1619     break;
1620     case LOG_DLINE_TYPE:
1621     logfile = ConfigLoggingEntry.klinelog;
1622     log_message = "DLINE";
1623     break;
1624     case LOG_TEMP_DLINE_TYPE:
1625     logfile = ConfigLoggingEntry.klinelog;
1626     log_message = "TEMP DLINE";
1627     break;
1628     case LOG_TEMP_KLINE_TYPE:
1629     logfile = ConfigLoggingEntry.klinelog;
1630     log_message = "TEMP KLINE";
1631     break;
1632     case LOG_GLINE_TYPE:
1633     logfile = ConfigLoggingEntry.glinelog;
1634     log_message = "GLINE";
1635     break;
1636     case LOG_KILL_TYPE:
1637     logfile = ConfigLoggingEntry.killlog;
1638     log_message = "KILL";
1639     break;
1640     case LOG_IOERR_TYPE:
1641     logfile = ConfigLoggingEntry.ioerrlog;
1642     log_message = "IO ERR";
1643     break;
1644     default:
1645     return;
1646     }
1647    
1648     if (*logfile == '\0')
1649     return;
1650    
1651     p = linebuf;
1652     if (source_p != NULL)
1653     {
1654     n_preamble = ircsprintf(linebuf, "%s %s by (%s!%s@%s) :",
1655     myctime(CurrentTime), log_message,
1656     source_p->name, source_p->username, source_p->host);
1657    
1658     }
1659     else
1660     {
1661     n_preamble = ircsprintf(linebuf, "%s %s :",
1662     myctime(CurrentTime), log_message);
1663     }
1664    
1665     p += n_preamble;
1666    
1667     if ((log_fb = fbopen(logfile, "r")) != NULL)
1668     {
1669     fbclose(log_fb);
1670     log_fb = fbopen(logfile, "a");
1671     if (log_fb == NULL)
1672     return;
1673     va_start(args, pattern);
1674     /* XXX add check for IRCD_BUFSIZE-(n_preamble+1) < 0 ? -db */
1675     nbytes = vsnprintf(p, IRCD_BUFSIZE-(n_preamble+1), pattern, args);
1676     nbytes += n_preamble;
1677     va_end(args);
1678     fbputs(linebuf, log_fb, nbytes);
1679     fbclose(log_fb);
1680     }
1681     }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision