ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/client.c
Revision: 3274
Committed: Sun Apr 6 12:22:23 2014 UTC (11 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 33080 byte(s)
Log Message:
- Clean up redundant/unused header includes

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2916 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2916 * Copyright (c) 1997-2014 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * USA
20     */
21    
22 michael 2916 /*! \file client.c
23     * \brief Controls clients.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "client.h"
30     #include "event.h"
31     #include "hash.h"
32     #include "irc_string.h"
33     #include "ircd.h"
34     #include "numeric.h"
35     #include "s_auth.h"
36     #include "s_bsd.h"
37 michael 1309 #include "conf.h"
38     #include "log.h"
39 adx 30 #include "s_misc.h"
40     #include "s_serv.h"
41     #include "send.h"
42     #include "whowas.h"
43     #include "s_user.h"
44     #include "memory.h"
45 michael 1654 #include "mempool.h"
46 adx 30 #include "hostmask.h"
47     #include "listener.h"
48     #include "userhost.h"
49 michael 876 #include "watch.h"
50 michael 1783 #include "rng_mt.h"
51 michael 2682 #include "parse.h"
52 adx 30
53     dlink_list listing_client_list = { NULL, NULL, 0 };
54     /* Pointer to beginning of Client list */
55     dlink_list global_client_list = {NULL, NULL, 0};
56     /* unknown/client pointer lists */
57     dlink_list unknown_list = {NULL, NULL, 0};
58     dlink_list local_client_list = {NULL, NULL, 0};
59     dlink_list serv_list = {NULL, NULL, 0};
60     dlink_list global_serv_list = {NULL, NULL, 0};
61     dlink_list oper_list = {NULL, NULL, 0};
62    
63     static EVH check_pings;
64    
65 michael 1654 static mp_pool_t *client_pool = NULL;
66     static mp_pool_t *lclient_pool = NULL;
67 adx 30
68     static dlink_list dead_list = { NULL, NULL, 0};
69     static dlink_list abort_list = { NULL, NULL, 0};
70    
71     static dlink_node *eac_next; /* next aborted client to exit */
72    
73     static void check_pings_list(dlink_list *);
74     static void check_unknowns_list(void);
75    
76    
77 michael 1798 /* client_init()
78 adx 30 *
79     * inputs - NONE
80     * output - NONE
81     * side effects - initialize client free memory
82     */
83     void
84 michael 1798 client_init(void)
85 adx 30 {
86     /* start off the check ping event .. -- adrian
87     * Every 30 seconds is plenty -- db
88     */
89 michael 1654 client_pool = mp_pool_new(sizeof(struct Client), MP_CHUNK_SIZE_CLIENT);
90     lclient_pool = mp_pool_new(sizeof(struct LocalUser), MP_CHUNK_SIZE_LCLIENT);
91 adx 30 eventAdd("check_pings", check_pings, NULL, 5);
92     }
93    
94     /*
95     * make_client - create a new Client struct and set it to initial state.
96     *
97     * from == NULL, create local client (a client connected
98     * to a socket).
99     * WARNING: This leaves the client in a dangerous
100     * state where fd == -1, dead flag is not set and
101     * the client is on the unknown_list; therefore,
102     * the first thing to do after calling make_client(NULL)
103     * is setting fd to something reasonable. -adx
104     *
105     * from, create remote client (behind a socket
106     * associated with the client defined by
107     * 'from'). ('from' is a local client!!).
108     */
109     struct Client *
110     make_client(struct Client *from)
111     {
112 michael 1654 struct Client *client_p = mp_pool_get(client_pool);
113 adx 30
114 michael 1654 memset(client_p, 0, sizeof(*client_p));
115    
116 michael 3235 if (!from)
117 adx 30 {
118 michael 1241 client_p->from = client_p; /* 'from' of local client is self! */
119 michael 1654 client_p->localClient = mp_pool_get(lclient_pool);
120    
121     memset(client_p->localClient, 0, sizeof(*client_p->localClient));
122    
123 michael 1241 client_p->localClient->since = CurrentTime;
124     client_p->localClient->lasttime = CurrentTime;
125     client_p->localClient->firsttime = CurrentTime;
126     client_p->localClient->registration = REG_INIT;
127 adx 30
128     /* as good a place as any... */
129 michael 1126 dlinkAdd(client_p, &client_p->localClient->lclient_node, &unknown_list);
130 adx 30 }
131     else
132     client_p->from = from; /* 'from' of local client is self! */
133    
134 michael 1360 client_p->idhnext = client_p;
135 adx 30 client_p->hnext = client_p;
136 michael 2678 SetUnknown(client_p);
137 adx 30 strcpy(client_p->username, "unknown");
138 michael 1559 strcpy(client_p->svid, "0");
139 adx 30
140     return client_p;
141     }
142    
143     /*
144     * free_client
145     *
146     * inputs - pointer to client
147     * output - NONE
148     * side effects - client pointed to has its memory freed
149     */
150     static void
151     free_client(struct Client *client_p)
152     {
153 michael 3235 assert(client_p);
154 adx 30 assert(client_p != &me);
155     assert(client_p->hnext == client_p);
156 michael 1360 assert(client_p->idhnext == client_p);
157 adx 30 assert(client_p->channel.head == NULL);
158     assert(dlink_list_length(&client_p->channel) == 0);
159 michael 1360 assert(dlink_list_length(&client_p->whowas) == 0);
160 michael 1667 assert(!IsServer(client_p) || (IsServer(client_p) && client_p->serv));
161 adx 30
162     MyFree(client_p->serv);
163 michael 2229 MyFree(client_p->certfp);
164 adx 30
165     if (MyConnect(client_p))
166     {
167 michael 317 assert(client_p->localClient->invited.head == NULL);
168     assert(dlink_list_length(&client_p->localClient->invited) == 0);
169 michael 2345 assert(dlink_list_length(&client_p->localClient->watches) == 0);
170 adx 30 assert(IsClosing(client_p) && IsDead(client_p));
171    
172     MyFree(client_p->localClient->response);
173     MyFree(client_p->localClient->auth_oper);
174    
175     /*
176     * clean up extra sockets from P-lines which have been discarded.
177     */
178     if (client_p->localClient->listener)
179     {
180     assert(0 < client_p->localClient->listener->ref_count);
181     if (0 == --client_p->localClient->listener->ref_count &&
182 michael 2345 !client_p->localClient->listener->active)
183 adx 30 free_listener(client_p->localClient->listener);
184     }
185    
186     dbuf_clear(&client_p->localClient->buf_recvq);
187     dbuf_clear(&client_p->localClient->buf_sendq);
188    
189 michael 1654 mp_pool_release(client_p->localClient);
190 adx 30 }
191    
192 michael 1654 mp_pool_release(client_p);
193 adx 30 }
194    
195     /*
196     * check_pings - go through the local client list and check activity
197     * kill off stuff that should die
198     *
199     * inputs - NOT USED (from event)
200     * output - next time_t when check_pings() should be called again
201 michael 2345 * side effects -
202 adx 30 *
203     *
204     * A PING can be sent to clients as necessary.
205     *
206     * Client/Server ping outs are handled.
207     */
208    
209     /*
210     * Addon from adrian. We used to call this after nextping seconds,
211     * however I've changed it to run once a second. This is only for
212     * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
213     * run once a second makes life a lot easier - when a new client connects
214     * and they need a ping in 4 seconds, if nextping was set to 20 seconds
215     * we end up waiting 20 seconds. This is stupid. :-)
216     * I will optimise (hah!) check_pings() once I've finished working on
217     * tidying up other network IO evilnesses.
218     * -- adrian
219     */
220    
221     static void
222     check_pings(void *notused)
223 michael 2345 {
224 adx 30 check_pings_list(&local_client_list);
225     check_pings_list(&serv_list);
226     check_unknowns_list();
227     }
228    
229     /* check_pings_list()
230     *
231     * inputs - pointer to list to check
232     * output - NONE
233 michael 2345 * side effects -
234 adx 30 */
235     static void
236     check_pings_list(dlink_list *list)
237     {
238 michael 2691 char scratch[IRCD_BUFSIZE];
239 michael 1644 int ping = 0; /* ping time value from client */
240     dlink_node *ptr = NULL, *next_ptr = NULL;
241 adx 30
242     DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
243     {
244 michael 1644 struct Client *client_p = ptr->data;
245 adx 30
246     /*
247     ** Note: No need to notify opers here. It's
248     ** already done when "FLAGS_DEADSOCKET" is set.
249     */
250     if (IsDead(client_p))
251     {
252     /* Ignore it, its been exited already */
253 michael 2345 continue;
254 adx 30 }
255    
256     if (!IsRegistered(client_p))
257 michael 1644 ping = CONNECTTIMEOUT;
258 adx 30 else
259 michael 1644 ping = get_client_ping(&client_p->localClient->confs);
260 adx 30
261 michael 1241 if (ping < CurrentTime - client_p->localClient->lasttime)
262 adx 30 {
263     if (!IsPingSent(client_p))
264     {
265 michael 2182 /*
266     * if we havent PINGed the connection and we havent
267     * heard from it in a while, PING it to make sure
268     * it is still alive.
269     */
270     SetPingSent(client_p);
271     client_p->localClient->lasttime = CurrentTime - ping;
272     sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
273 adx 30 }
274     else
275     {
276 michael 1241 if (CurrentTime - client_p->localClient->lasttime >= 2 * ping)
277 adx 30 {
278     /*
279     * If the client/server hasn't talked to us in 2*ping seconds
280     * and it has a ping time, then close its connection.
281     */
282     if (IsServer(client_p) || IsHandshake(client_p))
283 michael 2182 {
284     sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
285     "No response from %s, closing link",
286     get_client_name(client_p, HIDE_IP));
287     sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
288     "No response from %s, closing link",
289     get_client_name(client_p, MASK_IP));
290     ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
291     get_client_name(client_p, HIDE_IP));
292     }
293 michael 650
294 michael 1124 snprintf(scratch, sizeof(scratch), "Ping timeout: %d seconds",
295 michael 1241 (int)(CurrentTime - client_p->localClient->lasttime));
296 michael 3171 exit_client(client_p, scratch);
297 adx 30 }
298     }
299     }
300     }
301     }
302    
303     /* check_unknowns_list()
304     *
305     * inputs - pointer to list of unknown clients
306     * output - NONE
307     * side effects - unknown clients get marked for termination after n seconds
308     */
309     static void
310     check_unknowns_list(void)
311     {
312 michael 3235 dlink_node *ptr = NULL, *ptr_next = NULL;
313 adx 30
314 michael 3235 DLINK_FOREACH_SAFE(ptr, ptr_next, unknown_list.head)
315 adx 30 {
316     struct Client *client_p = ptr->data;
317    
318 michael 650 /*
319     * Check UNKNOWN connections - if they have been in this state
320 adx 30 * for > 30s, close them.
321     */
322 michael 1241 if (IsAuthFinished(client_p) && (CurrentTime - client_p->localClient->firsttime) > 30)
323 michael 3171 exit_client(client_p, "Registration timed out");
324 adx 30 }
325     }
326    
327     /* check_conf_klines()
328     *
329     * inputs - NONE
330     * output - NONE
331     * side effects - Check all connections for a pending kline against the
332     * client, exit the client if a kline matches.
333     */
334 michael 2345 void
335 adx 30 check_conf_klines(void)
336 michael 2345 {
337 adx 30 struct Client *client_p = NULL; /* current local client_p being examined */
338 michael 1632 struct MaskItem *conf = NULL;
339 adx 30 dlink_node *ptr, *next_ptr;
340    
341     DLINK_FOREACH_SAFE(ptr, next_ptr, local_client_list.head)
342     {
343     client_p = ptr->data;
344    
345     /* If a client is already being exited
346     */
347     if (IsDead(client_p) || !IsClient(client_p))
348     continue;
349    
350 michael 1632 if ((conf = find_dline_conf(&client_p->localClient->ip,
351 michael 3235 client_p->localClient->aftype)))
352 adx 30 {
353 michael 1636 if (conf->type == CONF_EXEMPT)
354 michael 2182 continue;
355 adx 30
356 michael 2813 conf_try_ban(client_p, conf);
357 adx 30 continue; /* and go examine next fd/client_p */
358     }
359    
360 michael 2522 if (ConfigFileEntry.glines)
361 adx 30 {
362 michael 2739 if ((conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
363     CONF_GLINE, client_p->localClient->aftype,
364     client_p->username, NULL, 1)))
365     {
366 michael 2813 conf_try_ban(client_p, conf);
367 michael 2739 /* and go examine next fd/client_p */
368 adx 30 continue;
369     }
370 michael 2345 }
371 adx 30
372 michael 2522 if ((conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
373     CONF_KLINE, client_p->localClient->aftype,
374 michael 2739 client_p->username, NULL, 1)))
375 adx 30 {
376 michael 2813 conf_try_ban(client_p, conf);
377 michael 2345 continue;
378 adx 30 }
379    
380 michael 1632 if ((conf = find_matching_name_conf(CONF_XLINE, client_p->info,
381 michael 1921 NULL, NULL, 0)))
382 adx 30 {
383 michael 2813 conf_try_ban(client_p, conf);
384 adx 30 continue;
385     }
386     }
387    
388     /* also check the unknowns list for new dlines */
389     DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head)
390     {
391     client_p = ptr->data;
392    
393 michael 1632 if ((conf = find_dline_conf(&client_p->localClient->ip,
394     client_p->localClient->aftype)))
395 adx 30 {
396 michael 1636 if (conf->type == CONF_EXEMPT)
397 adx 30 continue;
398    
399 michael 3171 exit_client(client_p, "D-lined");
400 adx 30 }
401     }
402     }
403    
404     /*
405 michael 2813 * conf_try_ban
406 adx 30 *
407     * inputs - pointer to client to ban
408 michael 1632 * - pointer to MaskItem
409 adx 30 * output - NONE
410     * side effects - given client_p is banned
411     */
412 michael 2811 void
413 michael 2813 conf_try_ban(struct Client *client_p, struct MaskItem *conf)
414 adx 30 {
415 michael 2182 const char *user_reason = NULL; /* What is sent to user */
416 adx 30 const char *type_string = NULL;
417     const char dline_string[] = "D-line";
418     const char kline_string[] = "K-line";
419     const char gline_string[] = "G-line";
420     const char xline_string[] = "X-line";
421    
422     switch (conf->type)
423     {
424 michael 1632 case CONF_KLINE:
425 michael 2811 if (IsExemptKline(client_p))
426     {
427     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
428     "KLINE over-ruled for %s, client is kline_exempt",
429     get_client_name(client_p, HIDE_IP));
430     return;
431     }
432    
433 adx 30 type_string = kline_string;
434     break;
435 michael 1632 case CONF_DLINE:
436 adx 30 type_string = dline_string;
437     break;
438 michael 1632 case CONF_GLINE:
439 michael 2811 if (IsExemptKline(client_p) ||
440     IsExemptGline(client_p))
441     {
442     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
443     "GLINE over-ruled for %s, client is %sline_exempt",
444     get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
445     return;
446     }
447 michael 2916
448 adx 30 type_string = gline_string;
449     break;
450 michael 1632 case CONF_XLINE:
451 adx 30 type_string = xline_string;
452 michael 1632 ++conf->count;
453 adx 30 break;
454     default:
455     assert(0);
456     break;
457     }
458    
459 michael 1632 user_reason = conf->reason ? conf->reason : type_string;
460 adx 30
461 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s active for %s",
462 adx 30 type_string, get_client_name(client_p, HIDE_IP));
463    
464     if (IsClient(client_p))
465 michael 3109 sendto_one_numeric(client_p, &me, ERR_YOUREBANNEDCREEP, user_reason);
466 adx 30
467 michael 3171 exit_client(client_p, user_reason);
468 adx 30 }
469    
470     /* update_client_exit_stats()
471     *
472     * input - pointer to client
473     * output - NONE
474 michael 2345 * side effects -
475 adx 30 */
476     static void
477     update_client_exit_stats(struct Client *client_p)
478     {
479 michael 1143 if (IsClient(client_p))
480 adx 30 {
481 michael 1013 assert(Count.total > 0);
482 adx 30 --Count.total;
483 michael 1219 if (HasUMode(client_p, UMODE_OPER))
484 adx 30 --Count.oper;
485 michael 1219 if (HasUMode(client_p, UMODE_INVISIBLE))
486 adx 30 --Count.invisi;
487     }
488 michael 1143 else if (IsServer(client_p))
489 michael 1618 sendto_realops_flags(UMODE_EXTERNAL, L_ALL, SEND_NOTICE,
490     "Server %s split from %s",
491 michael 1143 client_p->name, client_p->servptr->name);
492 adx 30
493     if (splitchecking && !splitmode)
494     check_splitmode(NULL);
495     }
496    
497     /* find_person()
498     *
499     * inputs - pointer to name
500     * output - return client pointer
501     * side effects - find person by (nick)name
502     */
503     struct Client *
504 michael 3170 find_person(const struct Client *const source_p, const char *name)
505 adx 30 {
506 michael 2475 struct Client *target_p = NULL;
507 adx 30
508     if (IsDigit(*name))
509     {
510 michael 3207 if (IsServer(source_p->from))
511 michael 2586 target_p = hash_find_id(name);
512 adx 30 }
513     else
514 michael 2475 target_p = hash_find_client(name);
515 adx 30
516 michael 2475 return (target_p && IsClient(target_p)) ? target_p : NULL;
517 adx 30 }
518    
519     /*
520 michael 2475 * find_chasing - find the client structure for a nick name (name)
521 michael 2345 * using history mechanism if necessary. If the client is not found,
522 michael 3192 * an error message (NO SUCH NICK) is generated.
523 adx 30 */
524     struct Client *
525 michael 3192 find_chasing(struct Client *source_p, const char *name)
526 adx 30 {
527 michael 3160 struct Client *who = find_person(source_p, name);
528 adx 30
529     if (who)
530 michael 1169 return who;
531 adx 30
532 michael 2475 if (IsDigit(*name))
533 michael 1169 return NULL;
534 adx 30
535 michael 2475 if ((who = whowas_get_history(name,
536 michael 2182 (time_t)ConfigFileEntry.kill_chase_time_limit))
537     == NULL)
538 adx 30 {
539 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, name);
540 michael 1169 return NULL;
541 adx 30 }
542    
543 michael 1169 return who;
544 adx 30 }
545    
546     /*
547     * get_client_name - Return the name of the client
548     * for various tracking and
549     * admin purposes. The main purpose of this function is to
550     * return the "socket host" name of the client, if that
551     * differs from the advertised name (other than case).
552     * But, this can be used to any client structure.
553     *
554     * NOTE 1:
555     * Watch out the allocation of "nbuf", if either source_p->name
556     * or source_p->sockhost gets changed into pointers instead of
557     * directly allocated within the structure...
558     *
559     * NOTE 2:
560     * Function return either a pointer to the structure (source_p) or
561     * to internal buffer (nbuf). *NEVER* use the returned pointer
562     * to modify what it points!!!
563     */
564     const char *
565 michael 3235 get_client_name(const struct Client *client_p, enum addr_mask_type type)
566 adx 30 {
567     static char nbuf[HOSTLEN * 2 + USERLEN + 5];
568    
569 michael 3235 assert(client_p);
570 adx 30
571 michael 3235 if (!MyConnect(client_p))
572     return client_p->name;
573 adx 30
574 michael 3235 if (IsServer(client_p) || IsConnecting(client_p) || IsHandshake(client_p))
575 michael 1340 {
576 michael 3235 if (!irccmp(client_p->name, client_p->host))
577     return client_p->name;
578 michael 1340 else if (ConfigServerHide.hide_server_ips)
579 michael 1328 type = MASK_IP;
580 michael 1340 }
581 adx 30
582     if (ConfigFileEntry.hide_spoof_ips)
583 michael 3235 if (type == SHOW_IP && IsIPSpoof(client_p))
584 michael 1328 type = MASK_IP;
585 adx 30
586     /* And finally, let's get the host information, ip or name */
587 michael 1328 switch (type)
588 adx 30 {
589     case SHOW_IP:
590 michael 1339 snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
591 michael 3235 client_p->name,
592     client_p->username, client_p->sockhost);
593 michael 1339 break;
594 adx 30 case MASK_IP:
595 michael 3235 if (client_p->localClient->aftype == AF_INET)
596 michael 1339 snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
597 michael 3235 client_p->name, client_p->username);
598 michael 1339 else
599     snprintf(nbuf, sizeof(nbuf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
600 michael 3235 client_p->name, client_p->username);
601 adx 30 break;
602     default:
603 michael 1124 snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
604 michael 3235 client_p->name,
605     client_p->username, client_p->host);
606 adx 30 }
607    
608 michael 1124 return nbuf;
609 adx 30 }
610    
611     void
612     free_exited_clients(void)
613     {
614 michael 887 dlink_node *ptr = NULL, *next = NULL;
615 michael 2345
616 adx 30 DLINK_FOREACH_SAFE(ptr, next, dead_list.head)
617     {
618 michael 887 free_client(ptr->data);
619 adx 30 dlinkDelete(ptr, &dead_list);
620     free_dlink_node(ptr);
621     }
622     }
623    
624     /*
625     * Exit one client, local or remote. Assuming all dependents have
626     * been already removed, and socket closed for local client.
627     *
628     * The only messages generated are QUITs on channels.
629     */
630     static void
631     exit_one_client(struct Client *source_p, const char *quitmsg)
632     {
633 michael 3235 dlink_node *ptr = NULL, *ptr_next = NULL;
634 adx 30
635     assert(!IsMe(source_p));
636    
637 michael 1118 if (IsClient(source_p))
638 adx 30 {
639 michael 3202 dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
640 adx 30
641 michael 1118 /*
642     * If a person is on a channel, send a QUIT notice
643     * to every client (person) on the same channel (so
644     * that the client can show the "**signoff" message).
645     * (Note: The notice is to the local clients *only*)
646     */
647 michael 1734 sendto_common_channels_local(source_p, 0, 0, ":%s!%s@%s QUIT :%s",
648 adx 30 source_p->name, source_p->username,
649     source_p->host, quitmsg);
650 michael 3235 DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->channel.head)
651     remove_user_from_channel(ptr->data);
652 adx 30
653 michael 2300 whowas_add_history(source_p, 0);
654     whowas_off_history(source_p);
655 adx 30
656 michael 876 watch_check_hash(source_p, RPL_LOGOFF);
657    
658 michael 889 if (MyConnect(source_p))
659 adx 30 {
660 michael 317 /* Clean up invitefield */
661 michael 3235 DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->localClient->invited.head)
662     del_invite(ptr->data, source_p);
663 michael 887
664     del_all_accepts(source_p);
665 michael 317 }
666 adx 30 }
667 michael 1118 else if (IsServer(source_p))
668     {
669     dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list);
670 adx 30
671 michael 3235 if ((ptr = dlinkFindDelete(&global_serv_list, source_p)))
672     free_dlink_node(ptr);
673 michael 1118 }
674    
675 adx 30 /* Remove source_p from the client lists */
676 michael 3187 if (source_p->id[0])
677 adx 30 hash_del_id(source_p);
678     if (source_p->name[0])
679     hash_del_client(source_p);
680    
681     if (IsUserHostIp(source_p))
682     delete_user_host(source_p->username, source_p->host, !MyConnect(source_p));
683    
684     /* remove from global client list
685     * NOTE: source_p->node.next cannot be NULL if the client is added
686     * to global_client_list (there is always &me at its end)
687     */
688 michael 3235 if (source_p->node.next) /* XXX: not needed? */
689 adx 30 dlinkDelete(&source_p->node, &global_client_list);
690    
691     update_client_exit_stats(source_p);
692    
693     /* Check to see if the client isn't already on the dead list */
694     assert(dlinkFind(&dead_list, source_p) == NULL);
695    
696     /* add to dead client dlist */
697     SetDead(source_p);
698     dlinkAdd(source_p, make_dlink_node(), &dead_list);
699     }
700    
701 michael 2345 /*
702 adx 30 * Remove all clients that depend on source_p; assumes all (S)QUITs have
703 michael 2345 * already been sent. we make sure to exit a server's dependent clients
704     * and servers before the server itself; exit_one_client takes care of
705 adx 30 * actually removing things off llists. tweaked from +CSr31 -orabidoo
706     */
707     static void
708     recurse_remove_clients(struct Client *source_p, const char *quitmsg)
709     {
710 michael 3235 dlink_node *ptr = NULL, *ptr_next = NULL;
711 adx 30
712 michael 3235 DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->client_list.head)
713 adx 30 exit_one_client(ptr->data, quitmsg);
714    
715 michael 3235 DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->server_list.head)
716 adx 30 {
717     recurse_remove_clients(ptr->data, quitmsg);
718     exit_one_client(ptr->data, quitmsg);
719     }
720     }
721    
722     /*
723     * exit_client - exit a client of any type. Generally, you can use
724     * this on any struct Client, regardless of its state.
725     *
726     * Note, you shouldn't exit remote _users_ without first doing
727 michael 1219 * AddFlag(x, FLAGS_KILLED) and propagating a kill or similar message.
728 michael 3171 *
729 michael 1219 * However, it is perfectly correct to call exit_client to force a _server_
730 adx 30 * quit (either local or remote one).
731     *
732 michael 3171 *
733 adx 30 * inputs: - a client pointer that is going to be exited
734     * output: none
735     * side effects: the client is delinked from all lists, disconnected,
736     * and the rest of IRC network is notified of the exit.
737     * Client memory is scheduled to be freed
738     */
739     void
740 michael 3171 exit_client(struct Client *source_p, const char *comment)
741 adx 30 {
742 michael 1118 dlink_node *m = NULL;
743 adx 30
744     if (MyConnect(source_p))
745     {
746     /* DO NOT REMOVE. exit_client can be called twice after a failed
747     * read/write.
748     */
749     if (IsClosing(source_p))
750     return;
751    
752     SetClosing(source_p);
753    
754     if (IsIpHash(source_p))
755     remove_one_ip(&source_p->localClient->ip);
756    
757 michael 2181 delete_auth(&source_p->localClient->auth);
758 adx 30
759 michael 1571 /*
760     * This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
761 adx 30 * STAT_HANDSHAKE or STAT_UNKNOWN
762     * all of which are lumped together into unknown_list
763     *
764     * In all above cases IsRegistered() will not be true.
765     */
766     if (!IsRegistered(source_p))
767     {
768 michael 1126 assert(dlinkFind(&unknown_list, source_p));
769    
770     dlinkDelete(&source_p->localClient->lclient_node, &unknown_list);
771 adx 30 }
772     else if (IsClient(source_p))
773     {
774 michael 1247 time_t on_for = CurrentTime - source_p->localClient->firsttime;
775 michael 1013 assert(Count.local > 0);
776 adx 30 Count.local--;
777    
778 michael 1219 if (HasUMode(source_p, UMODE_OPER))
779 michael 3235 if ((m = dlinkFindDelete(&oper_list, source_p)))
780 adx 30 free_dlink_node(m);
781    
782 michael 1126 assert(dlinkFind(&local_client_list, source_p));
783 adx 30 dlinkDelete(&source_p->localClient->lclient_node, &local_client_list);
784 michael 1126
785 michael 3235 if (source_p->localClient->list_task)
786 adx 30 free_list_task(source_p->localClient->list_task, source_p);
787    
788 michael 876 watch_del_watch_list(source_p);
789 michael 1618 sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE,
790     "Client exiting: %s (%s@%s) [%s] [%s]",
791 adx 30 source_p->name, source_p->username, source_p->host, comment,
792     ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
793     "255.255.255.255" : source_p->sockhost);
794 michael 1247 ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
795     myctime(source_p->localClient->firsttime), (unsigned int)(on_for / 3600),
796     (unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60),
797     source_p->name, source_p->username, source_p->host,
798     source_p->localClient->send.bytes>>10,
799     source_p->localClient->recv.bytes>>10);
800 adx 30 }
801 michael 1571 else if (IsServer(source_p))
802 adx 30 {
803 michael 1571 assert(Count.myserver > 0);
804     --Count.myserver;
805 adx 30
806 michael 1571 assert(dlinkFind(&serv_list, source_p));
807     dlinkDelete(&source_p->localClient->lclient_node, &serv_list);
808 adx 30 }
809    
810     if (!IsDead(source_p))
811     {
812     if (IsServer(source_p))
813     {
814 michael 3171 if (!HasFlag(source_p, FLAGS_SQUIT))
815     {
816     /* for them, we are exiting the network */
817     sendto_one(source_p, ":%s SQUIT %s :%s",
818 michael 3186 me.id, me.id, comment);
819 michael 3171 }
820 adx 30 }
821    
822     sendto_one(source_p, "ERROR :Closing Link: %s (%s)",
823     source_p->host, comment);
824     }
825    
826     close_connection(source_p);
827     }
828 michael 1991 else if (IsClient(source_p) && HasFlag(source_p->servptr, FLAGS_EOB))
829 michael 1976 sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
830     "Client exiting at %s: %s (%s@%s) [%s]",
831     source_p->servptr->name, source_p->name,
832     source_p->username, source_p->host, comment);
833 adx 30
834     if (IsServer(source_p))
835     {
836 michael 3171 char splitstr[HOSTLEN + HOSTLEN + 2] = "";
837 adx 30
838     /* This shouldn't ever happen */
839 michael 3235 assert(source_p->serv && source_p->servptr);
840 adx 30
841     if (ConfigServerHide.hide_servers)
842 michael 887 /*
843 michael 2345 * Set netsplit message to "*.net *.split" to still show
844 adx 30 * that its a split, but hide the servers splitting
845     */
846 michael 3171 strlcpy(splitstr, "*.net *.split", sizeof(splitstr));
847 adx 30 else
848     snprintf(splitstr, sizeof(splitstr), "%s %s",
849     source_p->servptr->name, source_p->name);
850    
851 michael 3171 /* Send SQUIT for source_p in every direction. source_p is already off of serv_list here */
852     if (!HasFlag(source_p, FLAGS_SQUIT))
853 michael 3186 sendto_server(NULL, NOCAPS, NOCAPS, "SQUIT %s :%s", source_p->id, comment);
854 adx 30
855 michael 3171 /* Now exit the clients internally */
856     recurse_remove_clients(source_p, splitstr);
857    
858 michael 3247 if (MyConnect(source_p))
859 adx 30 {
860 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
861 adx 30 "%s was connected for %d seconds. %llu/%llu sendK/recvK.",
862 michael 1241 source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
863 adx 30 source_p->localClient->send.bytes >> 10,
864     source_p->localClient->recv.bytes >> 10);
865 michael 1247 ilog(LOG_TYPE_IRCD, "%s was connected for %d seconds. %llu/%llu sendK/recvK.",
866 michael 2345 source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
867 adx 30 source_p->localClient->send.bytes >> 10,
868     source_p->localClient->recv.bytes >> 10);
869     }
870     }
871 michael 1219 else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED))
872 michael 3247 sendto_server(source_p->from, NOCAPS, NOCAPS, ":%s QUIT :%s",
873 michael 3186 source_p->id, comment);
874 adx 30
875     /* The client *better* be off all of the lists */
876     assert(dlinkFind(&unknown_list, source_p) == NULL);
877     assert(dlinkFind(&local_client_list, source_p) == NULL);
878     assert(dlinkFind(&serv_list, source_p) == NULL);
879     assert(dlinkFind(&oper_list, source_p) == NULL);
880    
881     exit_one_client(source_p, comment);
882     }
883    
884     /*
885     * dead_link_on_write - report a write error if not already dead,
886     * mark it as dead then exit it
887     */
888     void
889     dead_link_on_write(struct Client *client_p, int ierrno)
890     {
891     dlink_node *ptr;
892    
893     if (IsDefunct(client_p))
894     return;
895    
896     dbuf_clear(&client_p->localClient->buf_recvq);
897     dbuf_clear(&client_p->localClient->buf_sendq);
898    
899     assert(dlinkFind(&abort_list, client_p) == NULL);
900     ptr = make_dlink_node();
901     /* don't let exit_aborted_clients() finish yet */
902     dlinkAddTail(client_p, ptr, &abort_list);
903    
904     if (eac_next == NULL)
905     eac_next = ptr;
906    
907     SetDead(client_p); /* You are dead my friend */
908     }
909    
910     /*
911     * dead_link_on_read - report a read error if not already dead,
912     * mark it as dead then exit it
913     */
914     void
915     dead_link_on_read(struct Client *client_p, int error)
916     {
917 michael 2691 char errmsg[IRCD_BUFSIZE];
918 adx 30 int current_error;
919    
920     if (IsDefunct(client_p))
921     return;
922    
923     dbuf_clear(&client_p->localClient->buf_recvq);
924     dbuf_clear(&client_p->localClient->buf_sendq);
925    
926     current_error = get_sockerr(client_p->localClient->fd.fd);
927    
928     if (IsServer(client_p) || IsHandshake(client_p))
929     {
930 michael 1241 int connected = CurrentTime - client_p->localClient->firsttime;
931 michael 2345
932 adx 30 if (error == 0)
933     {
934     /* Admins get the real IP */
935 michael 1618 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
936 michael 2182 "Server %s closed the connection",
937     get_client_name(client_p, SHOW_IP));
938 adx 30
939     /* Opers get a masked IP */
940 michael 1618 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
941 michael 2182 "Server %s closed the connection",
942     get_client_name(client_p, MASK_IP));
943 adx 30
944 michael 1247 ilog(LOG_TYPE_IRCD, "Server %s closed the connection",
945 michael 2182 get_client_name(client_p, SHOW_IP));
946 adx 30 }
947     else
948     {
949 michael 617 report_error(L_ADMIN, "Lost connection to %s: %s",
950 michael 2182 get_client_name(client_p, SHOW_IP), current_error);
951 michael 617 report_error(L_OPER, "Lost connection to %s: %s",
952 michael 2182 get_client_name(client_p, MASK_IP), current_error);
953 adx 30 }
954    
955 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
956 michael 2182 "%s had been connected for %d day%s, %2d:%02d:%02d",
957     client_p->name, connected/86400,
958     (connected/86400 == 1) ? "" : "s",
959     (connected % 86400) / 3600, (connected % 3600) / 60,
960     connected % 60);
961 adx 30 }
962    
963     if (error == 0)
964     strlcpy(errmsg, "Remote host closed the connection",
965     sizeof(errmsg));
966     else
967 michael 1124 snprintf(errmsg, sizeof(errmsg), "Read error: %s",
968     strerror(current_error));
969 adx 30
970 michael 3171 exit_client(client_p, errmsg);
971 adx 30 }
972    
973     void
974     exit_aborted_clients(void)
975     {
976     dlink_node *ptr;
977     struct Client *target_p;
978     const char *notice;
979    
980     DLINK_FOREACH_SAFE(ptr, eac_next, abort_list.head)
981     {
982     target_p = ptr->data;
983     eac_next = ptr->next;
984    
985     if (target_p == NULL)
986     {
987 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
988 adx 30 "Warning: null client on abort_list!");
989     dlinkDelete(ptr, &abort_list);
990     free_dlink_node(ptr);
991     continue;
992     }
993    
994     dlinkDelete(ptr, &abort_list);
995    
996     if (IsSendQExceeded(target_p))
997     notice = "Max SendQ exceeded";
998     else
999     notice = "Write error: connection closed";
1000    
1001 michael 3171 exit_client(target_p, notice);
1002 adx 30 free_dlink_node(ptr);
1003     }
1004     }
1005    
1006     /*
1007     * accept processing, this adds a form of "caller ID" to ircd
1008 michael 887 *
1009 adx 30 * If a client puts themselves into "caller ID only" mode,
1010 michael 887 * only clients that match a client pointer they have put on
1011 adx 30 * the accept list will be allowed to message them.
1012     *
1013 michael 887 * Diane Bruce, "Dianora" db@db.net
1014 adx 30 */
1015    
1016 michael 887 void
1017     del_accept(struct split_nuh_item *accept_p, struct Client *client_p)
1018 adx 30 {
1019 michael 887 dlinkDelete(&accept_p->node, &client_p->localClient->acceptlist);
1020 adx 30
1021 michael 887 MyFree(accept_p->nickptr);
1022     MyFree(accept_p->userptr);
1023     MyFree(accept_p->hostptr);
1024     MyFree(accept_p);
1025     }
1026 adx 30
1027 michael 887 struct split_nuh_item *
1028     find_accept(const char *nick, const char *user,
1029 michael 2363 const char *host, struct Client *client_p,
1030     int (*cmpfunc)(const char *, const char *))
1031 michael 887 {
1032     dlink_node *ptr = NULL;
1033 adx 30
1034 michael 887 DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1035 adx 30 {
1036 michael 887 struct split_nuh_item *accept_p = ptr->data;
1037    
1038 michael 1652 if (!cmpfunc(accept_p->nickptr, nick) &&
1039     !cmpfunc(accept_p->userptr, user) &&
1040     !cmpfunc(accept_p->hostptr, host))
1041 michael 887 return accept_p;
1042 adx 30 }
1043    
1044 michael 887 return NULL;
1045 adx 30 }
1046    
1047 michael 887 /* accept_message()
1048 adx 30 *
1049 michael 887 * inputs - pointer to source client
1050     * - pointer to target client
1051     * output - 1 if accept this message 0 if not
1052     * side effects - See if source is on target's allow list
1053 adx 30 */
1054 michael 887 int
1055     accept_message(struct Client *source,
1056     struct Client *target)
1057 adx 30 {
1058 michael 887 dlink_node *ptr = NULL;
1059 adx 30
1060 michael 887 if (source == target || find_accept(source->name, source->username,
1061 michael 2363 source->host, target, match))
1062 michael 887 return 1;
1063 adx 30
1064 michael 1219 if (HasUMode(target, UMODE_SOFTCALLERID))
1065 michael 887 DLINK_FOREACH(ptr, target->channel.head)
1066     if (IsMember(source, ((struct Membership *)ptr->data)->chptr))
1067     return 1;
1068 adx 30
1069 michael 887 return 0;
1070 adx 30 }
1071    
1072     /* del_all_accepts()
1073     *
1074 michael 887 * inputs - pointer to exiting client
1075     * output - NONE
1076     * side effects - Walk through given clients acceptlist and remove all entries
1077 adx 30 */
1078     void
1079     del_all_accepts(struct Client *client_p)
1080     {
1081 michael 3235 dlink_node *ptr = NULL, *ptr_next = NULL;
1082 adx 30
1083 michael 3235 DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->localClient->acceptlist.head)
1084 michael 887 del_accept(ptr->data, client_p);
1085 adx 30 }
1086 michael 1783
1087     unsigned int
1088     idle_time_get(const struct Client *source_p, const struct Client *target_p)
1089     {
1090     unsigned int idle = 0;
1091     unsigned int min_idle = 0;
1092     unsigned int max_idle = 0;
1093 michael 1847 const struct ClassItem *class = get_class_ptr(&target_p->localClient->confs);
1094 michael 1783
1095 michael 1785 if (!(class->flags & CLASS_FLAGS_FAKE_IDLE) || target_p == source_p)
1096 michael 1783 return CurrentTime - target_p->localClient->last_privmsg;
1097     if (HasUMode(source_p, UMODE_OPER) &&
1098 michael 1785 !(class->flags & CLASS_FLAGS_HIDE_IDLE_FROM_OPERS))
1099 michael 1783 return CurrentTime - target_p->localClient->last_privmsg;
1100    
1101     min_idle = class->min_idle;
1102     max_idle = class->max_idle;
1103    
1104     if (min_idle == max_idle)
1105     return min_idle;
1106    
1107     if (class->flags & CLASS_FLAGS_RANDOM_IDLE)
1108     idle = genrand_int32();
1109     else
1110     idle = CurrentTime - target_p->localClient->last_privmsg;
1111    
1112 michael 3235 if (!max_idle)
1113 michael 1783 idle = 0;
1114     else
1115     idle %= max_idle;
1116    
1117     if (idle < min_idle)
1118     idle = min_idle + (idle % (max_idle - min_idle));
1119    
1120     return idle;
1121     }

Properties

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