]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/client.c
Merge branch 'HelpText'
[ngircd-alex.git] / src / ngircd / client.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001-2012 Alexander Barton (alex@barton.de)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * Please read the file COPYING, README and AUTHORS for more information.
10  */
11
12 #define __client_c__
13
14 #include "portab.h"
15
16 /**
17  * @file
18  * Client management.
19  */
20
21 #include "imp.h"
22 #include <assert.h>
23 #include <unistd.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <strings.h>
28 #include <netdb.h>
29
30 #include "defines.h"
31 #include "conn.h"
32
33 #include "exp.h"
34 #include "client.h"
35
36 #include <imp.h>
37 #include "ngircd.h"
38 #include "channel.h"
39 #include "conf.h"
40 #include "conn-func.h"
41 #include "hash.h"
42 #include "irc-write.h"
43 #include "log.h"
44 #include "messages.h"
45
46 #include <exp.h>
47
48 #define GETID_LEN (CLIENT_NICK_LEN-1) + 1 + (CLIENT_USER_LEN-1) + 1 + (CLIENT_HOST_LEN-1) + 1
49
50 static CLIENT *This_Server, *My_Clients;
51
52 static WHOWAS My_Whowas[MAX_WHOWAS];
53 static int Last_Whowas = -1;
54 static long Max_Users, My_Max_Users;
55
56
57 static unsigned long Count PARAMS(( CLIENT_TYPE Type ));
58 static unsigned long MyCount PARAMS(( CLIENT_TYPE Type ));
59
60 static CLIENT *New_Client_Struct PARAMS(( void ));
61 static void Generate_MyToken PARAMS(( CLIENT *Client ));
62 static void Adjust_Counters PARAMS(( CLIENT *Client ));
63
64 static CLIENT *Init_New_Client PARAMS((CONN_ID Idx, CLIENT *Introducer,
65                                        CLIENT *TopServer, int Type, const char *ID,
66                                        const char *User, const char *Hostname, const char *Info,
67                                        int Hops, int Token, const char *Modes,
68                                        bool Idented));
69
70 static void Destroy_UserOrService PARAMS((CLIENT *Client,const char *Txt, const char *FwdMsg,
71                                         bool SendQuit));
72
73 static void cb_introduceClient PARAMS((CLIENT *Client, CLIENT *Prefix,
74                                        void *i));
75
76 GLOBAL void
77 Client_Init( void )
78 {
79         struct hostent *h;
80         
81         This_Server = New_Client_Struct( );
82         if( ! This_Server )
83         {
84                 Log( LOG_EMERG, "Can't allocate client structure for server! Going down." );
85                 Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
86                 exit( 1 );
87         }
88
89         /* Client-Struktur dieses Servers */
90         This_Server->next = NULL;
91         This_Server->type = CLIENT_SERVER;
92         This_Server->conn_id = NONE;
93         This_Server->introducer = This_Server;
94         This_Server->mytoken = 1;
95         This_Server->hops = 0;
96
97         gethostname( This_Server->host, CLIENT_HOST_LEN );
98         if (Conf_DNS) {
99                 h = gethostbyname( This_Server->host );
100                 if (h) strlcpy(This_Server->host, h->h_name, sizeof(This_Server->host));
101         }
102         Client_SetID( This_Server, Conf_ServerName );
103         Client_SetInfo( This_Server, Conf_ServerInfo );
104
105         My_Clients = This_Server;
106         
107         memset( &My_Whowas, 0, sizeof( My_Whowas ));
108 } /* Client_Init */
109
110
111 GLOBAL void
112 Client_Exit( void )
113 {
114         CLIENT *c, *next;
115         int cnt;
116
117         if( NGIRCd_SignalRestart ) Client_Destroy( This_Server, "Server going down (restarting).", NULL, false );
118         else Client_Destroy( This_Server, "Server going down.", NULL, false );
119         
120         cnt = 0;
121         c = My_Clients;
122         while( c )
123         {
124                 cnt++;
125                 next = (CLIENT *)c->next;
126                 free( c );
127                 c = next;
128         }
129         if( cnt ) Log( LOG_INFO, "Freed %d client structure%s.", cnt, cnt == 1 ? "" : "s" );
130 } /* Client_Exit */
131
132
133 GLOBAL CLIENT *
134 Client_ThisServer( void )
135 {
136         return This_Server;
137 } /* Client_ThisServer */
138
139
140 /**
141  * Initialize new local client; wrapper function for Init_New_Client().
142  * @return New CLIENT structure.
143  */
144 GLOBAL CLIENT *
145 Client_NewLocal(CONN_ID Idx, const char *Hostname, int Type, bool Idented)
146 {
147         return Init_New_Client(Idx, This_Server, NULL, Type, NULL, NULL,
148                 Hostname, NULL, 0, 0, NULL, Idented);
149 } /* Client_NewLocal */
150
151
152 /**
153  * Initialize new remote server; wrapper function for Init_New_Client().
154  * @return New CLIENT structure.
155  */
156 GLOBAL CLIENT *
157 Client_NewRemoteServer(CLIENT *Introducer, const char *Hostname, CLIENT *TopServer,
158  int Hops, int Token, const char *Info, bool Idented)
159 {
160         return Init_New_Client(NONE, Introducer, TopServer, CLIENT_SERVER,
161                 Hostname, NULL, Hostname, Info, Hops, Token, NULL, Idented);
162 } /* Client_NewRemoteServer */
163
164
165 /**
166  * Initialize new remote client; wrapper function for Init_New_Client().
167  * @return New CLIENT structure.
168  */
169 GLOBAL CLIENT *
170 Client_NewRemoteUser(CLIENT *Introducer, const char *Nick, int Hops, const char *User,
171  const char *Hostname, int Token, const char *Modes, const char *Info, bool Idented)
172 {
173         return Init_New_Client(NONE, Introducer, NULL, CLIENT_USER, Nick,
174                 User, Hostname, Info, Hops, Token, Modes, Idented);
175 } /* Client_NewRemoteUser */
176
177
178 /**
179  * Initialize new client and set up the given parameters like client type,
180  * user name, host name, introducing server etc. ...
181  * @return New CLIENT structure.
182  */
183 static CLIENT *
184 Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer,
185   int Type, const char *ID, const char *User, const char *Hostname,
186   const char *Info, int Hops, int Token, const char *Modes, bool Idented)
187 {
188         CLIENT *client;
189
190         assert(Idx >= NONE);
191         assert(Introducer != NULL);
192
193         client = New_Client_Struct();
194         if (!client)
195                 return NULL;
196
197         client->starttime = time(NULL);
198         client->conn_id = Idx;
199         client->introducer = Introducer;
200         client->topserver = TopServer;
201         client->type = Type;
202         if (ID)
203                 Client_SetID(client, ID);
204         if (User) {
205                 Client_SetUser(client, User, Idented);
206                 Client_SetOrigUser(client, User);
207         }
208         if (Hostname)
209                 Client_SetHostname(client, Hostname);
210         if (Info)
211                 Client_SetInfo(client, Info);
212         client->hops = Hops;
213         client->token = Token;
214         if (Modes)
215                 Client_SetModes(client, Modes);
216         if (Type == CLIENT_SERVER)
217                 Generate_MyToken(client);
218
219         if (strchr(client->modes, 'a'))
220                 strlcpy(client->away, DEFAULT_AWAY_MSG, sizeof(client->away));
221
222         client->next = (POINTER *)My_Clients;
223         My_Clients = client;
224
225         Adjust_Counters(client);
226
227         return client;
228 } /* Init_New_Client */
229
230
231 GLOBAL void
232 Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool SendQuit )
233 {
234         /* remove a client */
235         
236         CLIENT *last, *c;
237         char msg[LINE_LEN];
238         const char *txt;
239
240         assert( Client != NULL );
241
242         txt = LogMsg ? LogMsg : FwdMsg;
243         if (!txt)
244                 txt = "Reason unknown";
245
246         /* netsplit message */
247         if( Client->type == CLIENT_SERVER ) {
248                 strlcpy(msg, This_Server->id, sizeof (msg));
249                 strlcat(msg, " ", sizeof (msg));
250                 strlcat(msg, Client->id, sizeof (msg));
251         }
252
253         last = NULL;
254         c = My_Clients;
255         while( c )
256         {
257                 if(( Client->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c != Client ))
258                 {
259                         /*
260                          * The client that is about to be removed is a server,
261                          * the client we are checking right now is a child of that
262                          * server and thus has to be removed, too.
263                          *
264                          * Call Client_Destroy() recursively with the server as the
265                          * new "object to be removed". This starts the cycle again, until
266                          * all servers that are linked via the original server have been
267                          * removed.
268                          */
269                         Client_Destroy( c, NULL, msg, false );
270                         last = NULL;
271                         c = My_Clients;
272                         continue;
273                 }
274                 if( c == Client )
275                 {
276                         /* found  the client: remove it */
277                         if( last ) last->next = c->next;
278                         else My_Clients = (CLIENT *)c->next;
279
280                         if(c->type == CLIENT_USER || c->type == CLIENT_SERVICE)
281                                 Destroy_UserOrService(c, txt, FwdMsg, SendQuit);
282                         else if( c->type == CLIENT_SERVER )
283                         {
284                                 if (c != This_Server) {
285                                         if (c->conn_id != NONE)
286                                                 Log(LOG_NOTICE|LOG_snotice,
287                                                     "Server \"%s\" unregistered (connection %d): %s.",
288                                                 c->id, c->conn_id, txt);
289                                         else
290                                                 Log(LOG_NOTICE|LOG_snotice,
291                                                     "Server \"%s\" unregistered: %s.",
292                                                     c->id, txt);
293                                 }
294
295                                 /* inform other servers */
296                                 if( ! NGIRCd_SignalQuit )
297                                 {
298                                         if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :%s", c->id, FwdMsg );
299                                         else IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :", c->id );
300                                 }
301                         }
302                         else
303                         {
304                                 if (c->conn_id != NONE) {
305                                         if (c->id[0])
306                                                 Log(LOG_NOTICE,
307                                                     "Client \"%s\" unregistered (connection %d): %s.",
308                                                     c->id, c->conn_id, txt);
309                                         else
310                                                 Log(LOG_NOTICE,
311                                                     "Client unregistered (connection %d): %s.",
312                                                     c->conn_id, txt);
313                                 } else {
314                                         Log(LOG_WARNING,
315                                             "Unregistered unknown client \"%s\": %s",
316                                             c->id[0] ? c->id : "(No Nick)", txt);
317                                 }
318                         }
319
320                         free( c );
321                         break;
322                 }
323                 last = c;
324                 c = (CLIENT *)c->next;
325         }
326 } /* Client_Destroy */
327
328
329 /**
330  * Set client hostname.
331  *
332  * If global hostname cloaking is in effect, don't set the real hostname
333  * but the configured one.
334  *
335  * @param Client The client of which the hostname should be set.
336  * @param Hostname The new hostname.
337  */
338 GLOBAL void
339 Client_SetHostname( CLIENT *Client, const char *Hostname )
340 {
341         assert(Client != NULL);
342         assert(Hostname != NULL);
343
344         if (strlen(Conf_CloakHost)) {
345                 char cloak[GETID_LEN];
346
347                 strlcpy(cloak, Hostname, GETID_LEN);
348                 strlcat(cloak, Conf_CloakHostSalt, GETID_LEN);
349                 snprintf(cloak, GETID_LEN, Conf_CloakHost, Hash(cloak));
350
351                 LogDebug("Updating hostname of \"%s\": \"%s\" -> \"%s\"",
352                         Client_ID(Client), Client->host, cloak);
353                 strlcpy(Client->host, cloak, sizeof(Client->host));
354         } else {
355                 LogDebug("Updating hostname of \"%s\": \"%s\" -> \"%s\"",
356                          Client_ID(Client), Client->host, Hostname);
357                 strlcpy(Client->host, Hostname, sizeof(Client->host));
358         }
359 } /* Client_SetHostname */
360
361
362 GLOBAL void
363 Client_SetID( CLIENT *Client, const char *ID )
364 {
365         assert( Client != NULL );
366         assert( ID != NULL );
367         
368         strlcpy( Client->id, ID, sizeof( Client->id ));
369
370         if (Conf_CloakUserToNick) {
371                 strlcpy( Client->user, ID, sizeof( Client->user ));
372                 strlcpy( Client->info, ID, sizeof( Client->info ));
373         }
374
375         /* Hash */
376         Client->hash = Hash( Client->id );
377 } /* Client_SetID */
378
379
380 GLOBAL void
381 Client_SetUser( CLIENT *Client, const char *User, bool Idented )
382 {
383         /* set clients username */
384
385         assert( Client != NULL );
386         assert( User != NULL );
387
388         if (Conf_CloakUserToNick) {
389                 strlcpy(Client->user, Client->id, sizeof(Client->user));
390         } else if (Idented) {
391                 strlcpy(Client->user, User, sizeof(Client->user));
392         } else {
393                 Client->user[0] = '~';
394                 strlcpy(Client->user + 1, User, sizeof(Client->user) - 1);
395         }
396 } /* Client_SetUser */
397
398
399 /**
400  * Set "original" user name of a client.
401  * This function saves the "original" user name, the user name specified by
402  * the peer using the USER command, into the CLIENT structure. This user
403  * name may be used for authentication, for example.
404  * @param Client The client.
405  * @param User User name to set.
406  */
407 GLOBAL void
408 Client_SetOrigUser(CLIENT UNUSED *Client, const char UNUSED *User)
409 {
410         assert(Client != NULL);
411         assert(User != NULL);
412
413 #if defined(PAM) && defined(IDENTAUTH)
414         strlcpy(Client->orig_user, User, sizeof(Client->orig_user));
415 #endif
416 } /* Client_SetOrigUser */
417
418
419 GLOBAL void
420 Client_SetInfo( CLIENT *Client, const char *Info )
421 {
422         /* set client hostname */
423
424         assert( Client != NULL );
425         assert( Info != NULL );
426
427         if (Conf_CloakUserToNick)
428                 strlcpy(Client->info, Client->id, sizeof(Client->info));
429         else
430                 strlcpy(Client->info, Info, sizeof(Client->info));
431 } /* Client_SetInfo */
432
433
434 GLOBAL void
435 Client_SetModes( CLIENT *Client, const char *Modes )
436 {
437         assert( Client != NULL );
438         assert( Modes != NULL );
439
440         strlcpy(Client->modes, Modes, sizeof( Client->modes ));
441 } /* Client_SetModes */
442
443
444 GLOBAL void
445 Client_SetFlags( CLIENT *Client, const char *Flags )
446 {
447         assert( Client != NULL );
448         assert( Flags != NULL );
449
450         strlcpy(Client->flags, Flags, sizeof(Client->flags));
451 } /* Client_SetFlags */
452
453
454 GLOBAL void
455 Client_SetAway( CLIENT *Client, const char *Txt )
456 {
457         /* Set AWAY reason of client */
458
459         assert( Client != NULL );
460         assert( Txt != NULL );
461
462         strlcpy( Client->away, Txt, sizeof( Client->away ));
463         LogDebug("%s \"%s\" is away: %s", Client_TypeText(Client),
464                  Client_Mask(Client), Txt);
465 } /* Client_SetAway */
466
467
468 GLOBAL void
469 Client_SetType( CLIENT *Client, int Type )
470 {
471         assert( Client != NULL );
472         Client->type = Type;
473         if( Type == CLIENT_SERVER ) Generate_MyToken( Client );
474         Adjust_Counters( Client );
475 } /* Client_SetType */
476
477
478 GLOBAL void
479 Client_SetHops( CLIENT *Client, int Hops )
480 {
481         assert( Client != NULL );
482         Client->hops = Hops;
483 } /* Client_SetHops */
484
485
486 GLOBAL void
487 Client_SetToken( CLIENT *Client, int Token )
488 {
489         assert( Client != NULL );
490         Client->token = Token;
491 } /* Client_SetToken */
492
493
494 GLOBAL void
495 Client_SetIntroducer( CLIENT *Client, CLIENT *Introducer )
496 {
497         assert( Client != NULL );
498         assert( Introducer != NULL );
499         Client->introducer = Introducer;
500 } /* Client_SetIntroducer */
501
502
503 GLOBAL void
504 Client_SetOperByMe( CLIENT *Client, bool OperByMe )
505 {
506         assert( Client != NULL );
507         Client->oper_by_me = OperByMe;
508 } /* Client_SetOperByMe */
509
510
511 GLOBAL bool
512 Client_ModeAdd( CLIENT *Client, char Mode )
513 {
514         /* Set Mode.
515          * If Client already alread had Mode, return false.
516          * If the Mode was newly set, return true.
517          */
518
519         char x[2];
520
521         assert( Client != NULL );
522
523         x[0] = Mode; x[1] = '\0';
524         if (!strchr( Client->modes, x[0])) {
525                 strlcat( Client->modes, x, sizeof( Client->modes ));
526                 return true;
527         }
528         else return false;
529 } /* Client_ModeAdd */
530
531
532 GLOBAL bool
533 Client_ModeDel( CLIENT *Client, char Mode )
534 {
535         /* Delete Mode.
536          * If Mode was removed, return true.
537          * If Client did not have Mode, return false.
538          */
539
540         char x[2], *p;
541
542         assert( Client != NULL );
543
544         x[0] = Mode; x[1] = '\0';
545
546         p = strchr( Client->modes, x[0] );
547         if( ! p ) return false;
548
549         /* Client has Mode -> delete */
550         while( *p )
551         {
552                 *p = *(p + 1);
553                 p++;
554         }
555         return true;
556 } /* Client_ModeDel */
557
558
559 GLOBAL CLIENT *
560 Client_Search( const char *Nick )
561 {
562         /* return Client-Structure that has the corresponding Nick.
563          * If none is found, return NULL.
564          */
565
566         char search_id[CLIENT_ID_LEN], *ptr;
567         CLIENT *c = NULL;
568         UINT32 search_hash;
569
570         assert( Nick != NULL );
571
572         /* copy Nick and truncate hostmask if necessary */
573         strlcpy( search_id, Nick, sizeof( search_id ));
574         ptr = strchr( search_id, '!' );
575         if( ptr ) *ptr = '\0';
576
577         search_hash = Hash(search_id);
578
579         c = My_Clients;
580         while (c) {
581                 if (c->hash == search_hash && strcasecmp(c->id, search_id) == 0)
582                         return c;
583                 c = (CLIENT *)c->next;
584         }
585         return NULL;
586 } /* Client_Search */
587
588
589 /**
590  * Get client structure ("introducer") identfied by a server token.
591  * @return CLIENT structure or NULL if none could be found.
592  */
593 GLOBAL CLIENT *
594 Client_GetFromToken( CLIENT *Client, int Token )
595 {
596         CLIENT *c;
597
598         assert( Client != NULL );
599
600         if (!Token)
601                 return NULL;
602
603         c = My_Clients;
604         while (c) {
605                 if ((c->type == CLIENT_SERVER) && (c->introducer == Client) &&
606                         (c->token == Token))
607                                 return c;
608                 c = (CLIENT *)c->next;
609         }
610         return NULL;
611 } /* Client_GetFromToken */
612
613
614 GLOBAL int
615 Client_Type( CLIENT *Client )
616 {
617         assert( Client != NULL );
618         return Client->type;
619 } /* Client_Type */
620
621
622 GLOBAL CONN_ID
623 Client_Conn( CLIENT *Client )
624 {
625         assert( Client != NULL );
626         return Client->conn_id;
627 } /* Client_Conn */
628
629
630 GLOBAL char *
631 Client_ID( CLIENT *Client )
632 {
633         assert( Client != NULL );
634
635 #ifdef DEBUG
636         if(Client->type == CLIENT_USER)
637                 assert(strlen(Client->id) < Conf_MaxNickLength);
638 #endif
639                                                    
640         if( Client->id[0] ) return Client->id;
641         else return "*";
642 } /* Client_ID */
643
644
645 GLOBAL char *
646 Client_Info( CLIENT *Client )
647 {
648         assert( Client != NULL );
649         return Client->info;
650 } /* Client_Info */
651
652
653 GLOBAL char *
654 Client_User( CLIENT *Client )
655 {
656         assert( Client != NULL );
657         return Client->user[0] ? Client->user : "~";
658 } /* Client_User */
659
660
661 #ifdef PAM
662
663 /**
664  * Get the "original" user name as supplied by the USER command.
665  * The user name as given by the client is used for authentication instead
666  * of the one detected using IDENT requests.
667  * @param Client The client.
668  * @return Original user name.
669  */
670 GLOBAL char *
671 Client_OrigUser(CLIENT *Client) {
672 #ifndef IDENTAUTH
673         char *user = Client->user;
674
675         if (user[0] == '~')
676                 user++;
677         return user;
678 #else
679         return Client->orig_user;
680 #endif
681 } /* Client_OrigUser */
682
683 #endif
684
685 /**
686  * Return the hostname of a client.
687  * @param Client Pointer to client structure
688  * @return Pointer to client hostname
689  */
690 GLOBAL char *
691 Client_Hostname(CLIENT *Client)
692 {
693         assert (Client != NULL);
694         return Client->host;
695 }
696
697 /**
698  * Return the cloaked hostname of a client, if set.
699  * @param Client Pointer to the client structure.
700  * @return Pointer to the cloaked hostname or NULL if not set.
701  */
702 GLOBAL char *
703 Client_HostnameCloaked(CLIENT *Client)
704 {
705         assert(Client != NULL);
706         return Client->cloaked;
707 }
708
709 /**
710  * Get (potentially cloaked) hostname of a client to display it to other users.
711  *
712  * If the client has not enabled cloaking, the real hostname is used.
713  * Please note that this function uses a global static buffer, so you can't
714  * nest invocations without overwriting earlier results!
715  *
716  * @param Client Pointer to client structure
717  * @return Pointer to client hostname
718  */
719 GLOBAL char *
720 Client_HostnameDisplayed(CLIENT *Client)
721 {
722         assert(Client != NULL);
723
724         /* Client isn't cloaked at all, return real hostname: */
725         if (!Client_HasMode(Client, 'x'))
726                 return Client_Hostname(Client);
727
728         /* Use an already saved cloaked hostname, if there is one */
729         if (Client->cloaked[0])
730                 return Client->cloaked;
731
732         Client_UpdateCloakedHostname(Client, NULL, NULL);
733         return Client->cloaked;
734 }
735
736 /**
737  * Update (and generate, if necessary) the cloaked hostname of a client.
738  *
739  * The newly set cloaked hostname is announced in the network using METADATA
740  * commands to peers that support this feature.
741  *
742  * @param Client The client of which the cloaked hostname should be updated.
743  * @param Origin The originator of the hostname change, or NULL if this server.
744  * @param Hostname The new cloaked hostname, or NULL if it should be generated.
745  */
746 GLOBAL void
747 Client_UpdateCloakedHostname(CLIENT *Client, CLIENT *Origin,
748                              const char *Hostname)
749 {
750         static char Cloak_Buffer[CLIENT_HOST_LEN];
751
752         assert(Client != NULL);
753         if (!Origin)
754                 Origin = Client_ThisServer();
755
756         if (!Hostname) {
757                 /* Generate new cloaked hostname */
758                 if (*Conf_CloakHostModeX) {
759                         strlcpy(Cloak_Buffer, Client->host, CLIENT_HOST_LEN);
760                         strlcat(Cloak_Buffer, Conf_CloakHostSalt,
761                                 CLIENT_HOST_LEN);
762                         snprintf(Client->cloaked, sizeof(Client->cloaked),
763                                  Conf_CloakHostModeX, Hash(Cloak_Buffer));
764                 } else
765                         strlcpy(Client->cloaked, Client_ID(Client->introducer),
766                                 sizeof(Client->cloaked));
767         } else
768                 strlcpy(Client->cloaked, Hostname, sizeof(Client->cloaked));
769         LogDebug("Cloaked hostname of \"%s\" updated to \"%s\"",
770                  Client_ID(Client), Client->cloaked);
771
772         /* Inform other servers in the network */
773         IRC_WriteStrServersPrefixFlag(Client_NextHop(Origin), Origin, 'M',
774                                       "METADATA %s cloakhost :%s",
775                                       Client_ID(Client), Client->cloaked);
776 }
777
778 GLOBAL char *
779 Client_Modes( CLIENT *Client )
780 {
781         assert( Client != NULL );
782         return Client->modes;
783 } /* Client_Modes */
784
785
786 GLOBAL char *
787 Client_Flags( CLIENT *Client )
788 {
789         assert( Client != NULL );
790         return Client->flags;
791 } /* Client_Flags */
792
793
794 GLOBAL bool
795 Client_OperByMe( CLIENT *Client )
796 {
797         assert( Client != NULL );
798         return Client->oper_by_me;
799 } /* Client_OperByMe */
800
801
802 GLOBAL int
803 Client_Hops( CLIENT *Client )
804 {
805         assert( Client != NULL );
806         return Client->hops;
807 } /* Client_Hops */
808
809
810 GLOBAL int
811 Client_Token( CLIENT *Client )
812 {
813         assert( Client != NULL );
814         return Client->token;
815 } /* Client_Token */
816
817
818 GLOBAL int
819 Client_MyToken( CLIENT *Client )
820 {
821         assert( Client != NULL );
822         return Client->mytoken;
823 } /* Client_MyToken */
824
825
826 GLOBAL CLIENT *
827 Client_NextHop( CLIENT *Client )
828 {
829         CLIENT *c;
830
831         assert( Client != NULL );
832
833         c = Client;
834         while( c->introducer && ( c->introducer != c ) && ( c->introducer != This_Server ))
835                 c = c->introducer;
836
837         return c;
838 } /* Client_NextHop */
839
840
841 /**
842  * Return ID of a client: "client!user@host"
843  * This client ID is used for IRC prefixes, for example.
844  * Please note that this function uses a global static buffer, so you can't
845  * nest invocations without overwriting earlier results!
846  * @param Client Pointer to client structure
847  * @return Pointer to global buffer containing the client ID
848  */
849 GLOBAL char *
850 Client_Mask( CLIENT *Client )
851 {
852         static char Mask_Buffer[GETID_LEN];
853
854         assert (Client != NULL);
855
856         /* Servers: return name only, there is no "mask" */
857         if (Client->type == CLIENT_SERVER)
858                 return Client->id;
859
860         snprintf(Mask_Buffer, GETID_LEN, "%s!%s@%s",
861                  Client->id, Client->user, Client->host);
862         return Mask_Buffer;
863 } /* Client_Mask */
864
865
866 /**
867  * Return ID of a client with cloaked hostname: "client!user@server-name"
868  *
869  * This client ID is used for IRC prefixes, for example.
870  * Please note that this function uses a global static buffer, so you can't
871  * nest invocations without overwriting earlier results!
872  * If the client has not enabled cloaking, the real hostname is used.
873  *
874  * @param Client Pointer to client structure
875  * @return Pointer to global buffer containing the client ID
876  */
877 GLOBAL char *
878 Client_MaskCloaked(CLIENT *Client)
879 {
880         static char Mask_Buffer[GETID_LEN];
881
882         assert (Client != NULL);
883
884         /* Is the client using cloaking at all? */
885         if (!Client_HasMode(Client, 'x'))
886                 return Client_Mask(Client);
887
888         snprintf(Mask_Buffer, GETID_LEN, "%s!%s@%s", Client->id, Client->user,
889                  Client_HostnameDisplayed(Client));
890
891         return Mask_Buffer;
892 } /* Client_MaskCloaked */
893
894
895 GLOBAL CLIENT *
896 Client_Introducer( CLIENT *Client )
897 {
898         assert( Client != NULL );
899         return Client->introducer;
900 } /* Client_Introducer */
901
902
903 GLOBAL CLIENT *
904 Client_TopServer( CLIENT *Client )
905 {
906         assert( Client != NULL );
907         return Client->topserver;
908 } /* Client_TopServer */
909
910
911 GLOBAL bool
912 Client_HasMode( CLIENT *Client, char Mode )
913 {
914         assert( Client != NULL );
915         return strchr( Client->modes, Mode ) != NULL;
916 } /* Client_HasMode */
917
918
919 GLOBAL char *
920 Client_Away( CLIENT *Client )
921 {
922         assert( Client != NULL );
923         return Client->away;
924 } /* Client_Away */
925
926
927 /**
928  * Make sure that a given nickname is valid.
929  *
930  * If the nickname is not valid for the given client, this function sends back
931  * the appropriate error messages.
932  *
933  * @param       Client Client that wants to change the nickname.
934  * @param       Nick New nickname.
935  * @returns     true if nickname is valid, false otherwise.
936  */
937 GLOBAL bool
938 Client_CheckNick(CLIENT *Client, char *Nick)
939 {
940         assert(Client != NULL);
941         assert(Nick != NULL);
942
943         if (!Client_IsValidNick(Nick)) {
944                 if (strlen(Nick ) >= Conf_MaxNickLength)
945                         IRC_WriteStrClient(Client, ERR_NICKNAMETOOLONG_MSG,
946                                            Client_ID(Client), Nick,
947                                            Conf_MaxNickLength - 1);
948                 else
949                         IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
950                                            Client_ID(Client), Nick);
951                 return false;
952         }
953
954         if (Client_Type(Client) != CLIENT_SERVER
955             && Client_Type(Client) != CLIENT_SERVICE) {
956                 /* Make sure that this isn't a restricted/forbidden nickname */
957                 if (Conf_NickIsBlocked(Nick)) {
958                         IRC_WriteStrClient(Client, ERR_FORBIDDENNICKNAME_MSG,
959                                            Client_ID(Client), Nick);
960                         return false;
961                 }
962         }
963
964         /* Nickname already registered? */
965         if (Client_Search(Nick)) {
966                 IRC_WriteStrClient(Client, ERR_NICKNAMEINUSE_MSG,
967                         Client_ID(Client), Nick);
968                 return false;
969         }
970
971         return true;
972 } /* Client_CheckNick */
973
974
975 GLOBAL bool
976 Client_CheckID( CLIENT *Client, char *ID )
977 {
978         char str[COMMAND_LEN];
979         CLIENT *c;
980
981         assert( Client != NULL );
982         assert( Client->conn_id > NONE );
983         assert( ID != NULL );
984
985         /* ID too long? */
986         if (strlen(ID) > CLIENT_ID_LEN) {
987                 IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID(Client), ID);
988                 return false;
989         }
990
991         /* ID already in use? */
992         c = My_Clients;
993         while (c) {
994                 if (strcasecmp(c->id, ID) == 0) {
995                         snprintf(str, sizeof(str), "ID \"%s\" already registered", ID);
996                         if (c->conn_id != NONE)
997                                 Log(LOG_ERR, "%s (on connection %d)!", str, c->conn_id);
998                         else
999                                 Log(LOG_ERR, "%s (via network)!", str);
1000                         Conn_Close(Client->conn_id, str, str, true);
1001                         return false;
1002                 }
1003                 c = (CLIENT *)c->next;
1004         }
1005
1006         return true;
1007 } /* Client_CheckID */
1008
1009
1010 GLOBAL CLIENT *
1011 Client_First( void )
1012 {
1013         return My_Clients;
1014 } /* Client_First */
1015
1016
1017 GLOBAL CLIENT *
1018 Client_Next( CLIENT *c )
1019 {
1020         assert( c != NULL );
1021         return (CLIENT *)c->next;
1022 } /* Client_Next */
1023
1024
1025 GLOBAL long
1026 Client_UserCount( void )
1027 {
1028         return Count( CLIENT_USER );
1029 } /* Client_UserCount */
1030
1031
1032 GLOBAL long
1033 Client_ServiceCount( void )
1034 {
1035         return Count( CLIENT_SERVICE );;
1036 } /* Client_ServiceCount */
1037
1038
1039 GLOBAL long
1040 Client_ServerCount( void )
1041 {
1042         return Count( CLIENT_SERVER );
1043 } /* Client_ServerCount */
1044
1045
1046 GLOBAL long
1047 Client_MyUserCount( void )
1048 {
1049         return MyCount( CLIENT_USER );
1050 } /* Client_MyUserCount */
1051
1052
1053 GLOBAL long
1054 Client_MyServiceCount( void )
1055 {
1056         return MyCount( CLIENT_SERVICE );
1057 } /* Client_MyServiceCount */
1058
1059
1060 GLOBAL unsigned long
1061 Client_MyServerCount( void )
1062 {
1063         CLIENT *c;
1064         unsigned long cnt = 0;
1065
1066         c = My_Clients;
1067         while( c )
1068         {
1069                 if(( c->type == CLIENT_SERVER ) && ( c->hops == 1 )) cnt++;
1070                 c = (CLIENT *)c->next;
1071         }
1072         return cnt;
1073 } /* Client_MyServerCount */
1074
1075
1076 GLOBAL unsigned long
1077 Client_OperCount( void )
1078 {
1079         CLIENT *c;
1080         unsigned long cnt = 0;
1081
1082         c = My_Clients;
1083         while( c )
1084         {
1085                 if( c && ( c->type == CLIENT_USER ) && ( strchr( c->modes, 'o' ))) cnt++;
1086                 c = (CLIENT *)c->next;
1087         }
1088         return cnt;
1089 } /* Client_OperCount */
1090
1091
1092 GLOBAL unsigned long
1093 Client_UnknownCount( void )
1094 {
1095         CLIENT *c;
1096         unsigned long cnt = 0;
1097
1098         c = My_Clients;
1099         while( c )
1100         {
1101                 if( c && ( c->type != CLIENT_USER ) && ( c->type != CLIENT_SERVICE ) && ( c->type != CLIENT_SERVER )) cnt++;
1102                 c = (CLIENT *)c->next;
1103         }
1104
1105         return cnt;
1106 } /* Client_UnknownCount */
1107
1108
1109 GLOBAL long
1110 Client_MaxUserCount( void )
1111 {
1112         return Max_Users;
1113 } /* Client_MaxUserCount */
1114
1115
1116 GLOBAL long
1117 Client_MyMaxUserCount( void )
1118 {
1119         return My_Max_Users;
1120 } /* Client_MyMaxUserCount */
1121
1122
1123 /**
1124  * Check that a given nickname is valid.
1125  *
1126  * @param       Nick the nickname to check.
1127  * @returns     true if nickname is valid, false otherwise.
1128  */
1129 GLOBAL bool
1130 Client_IsValidNick(const char *Nick)
1131 {
1132         const char *ptr;
1133         static const char goodchars[] = ";0123456789-";
1134
1135         assert (Nick != NULL);
1136
1137         if (strchr(goodchars, Nick[0]))
1138                 return false;
1139         if (strlen(Nick ) >= Conf_MaxNickLength)
1140                 return false;
1141
1142         ptr = Nick;
1143         while (*ptr) {
1144                 if (*ptr < 'A' && !strchr(goodchars, *ptr ))
1145                         return false;
1146                 if (*ptr > '}')
1147                         return false;
1148                 ptr++;
1149         }
1150
1151         return true;
1152 } /* Client_IsValidNick */
1153
1154
1155 /**
1156  * Return pointer to "My_Whowas" structure.
1157  */
1158 GLOBAL WHOWAS *
1159 Client_GetWhowas( void )
1160 {
1161         return My_Whowas;
1162 } /* Client_GetWhowas */
1163
1164 /**
1165  * Return the index of the last used WHOWAS entry.
1166  */
1167 GLOBAL int
1168 Client_GetLastWhowasIndex( void )
1169 {
1170         return Last_Whowas;
1171 } /* Client_GetLastWhowasIndex */
1172
1173
1174 /**
1175  * Get the start time of this client.
1176  * The result is the start time in seconds since 1970-01-01, as reported
1177  * by the C function time(NULL).
1178  */
1179 GLOBAL time_t
1180 Client_StartTime(CLIENT *Client)
1181 {
1182         assert( Client != NULL );
1183         return Client->starttime;
1184 } /* Client_Uptime */
1185
1186
1187 /**
1188  * Reject a client when logging in.
1189  *
1190  * This function is called when a client isn't allowed to connect to this
1191  * server. Possible reasons are bad server password, bad PAM password,
1192  * or that the client is G/K-Line'd.
1193  *
1194  * After calling this function, the client isn't connected any more.
1195  *
1196  * @param Client The client to reject.
1197  * @param Reason The reason why the client has been rejected.
1198  * @param InformClient If true, send the exact reason to the client.
1199  */
1200 GLOBAL void
1201 Client_Reject(CLIENT *Client, const char *Reason, bool InformClient)
1202 {
1203         char info[COMMAND_LEN];
1204
1205         assert(Client != NULL);
1206         assert(Reason != NULL);
1207
1208         if (InformClient)
1209                 snprintf(info, sizeof(info), "Access denied: %s", Reason);
1210         else
1211                 strcpy(info, "Access denied: Bad password?");
1212
1213         Log(LOG_ERR,
1214             "User \"%s\" rejected (connection %d): %s!",
1215             Client_Mask(Client), Client_Conn(Client), Reason);
1216         Conn_Close(Client_Conn(Client), Reason, info, true);
1217 }
1218
1219
1220 /**
1221  * Introduce a new user or service client in the network.
1222  *
1223  * @param From Remote server introducing the client or NULL (local).
1224  * @param Client New client.
1225  * @param Type Type of the client (CLIENT_USER or CLIENT_SERVICE).
1226  */
1227 GLOBAL void
1228 Client_Introduce(CLIENT *From, CLIENT *Client, int Type)
1229 {
1230         /* Set client type (user or service) */
1231         Client_SetType(Client, Type);
1232
1233         if (From) {
1234                 if (Conf_NickIsService(Conf_GetServer(Client_Conn(From)),
1235                                    Client_ID(Client)))
1236                         Client_SetType(Client, CLIENT_SERVICE);
1237                 LogDebug("%s \"%s\" (+%s) registered (via %s, on %s, %d hop%s).",
1238                          Client_TypeText(Client), Client_Mask(Client),
1239                          Client_Modes(Client), Client_ID(From),
1240                          Client_ID(Client_Introducer(Client)),
1241                          Client_Hops(Client), Client_Hops(Client) > 1 ? "s": "");
1242         } else {
1243                 Log(LOG_NOTICE, "%s \"%s\" registered (connection %d).",
1244                     Client_TypeText(Client), Client_Mask(Client),
1245                     Client_Conn(Client));
1246                 Log_ServerNotice('c', "Client connecting: %s (%s@%s) [%s] - %s",
1247                                  Client_ID(Client), Client_User(Client),
1248                                  Client_Hostname(Client),
1249                                  Conn_IPA(Client_Conn(Client)),
1250                                  Client_TypeText(Client));
1251         }
1252
1253         /* Inform other servers */
1254         IRC_WriteStrServersPrefixFlag_CB(From,
1255                                 From != NULL ? From : Client_ThisServer(),
1256                                 '\0', cb_introduceClient, (void *)Client);
1257 } /* Client_Introduce */
1258
1259
1260 static unsigned long
1261 Count( CLIENT_TYPE Type )
1262 {
1263         CLIENT *c;
1264         unsigned long cnt = 0;
1265
1266         c = My_Clients;
1267         while( c )
1268         {
1269                 if( c->type == Type ) cnt++;
1270                 c = (CLIENT *)c->next;
1271         }
1272         return cnt;
1273 } /* Count */
1274
1275
1276 static unsigned long
1277 MyCount( CLIENT_TYPE Type )
1278 {
1279         CLIENT *c;
1280         unsigned long cnt = 0;
1281
1282         c = My_Clients;
1283         while( c )
1284         {
1285                 if(( c->introducer == This_Server ) && ( c->type == Type )) cnt++;
1286                 c = (CLIENT *)c->next;
1287         }
1288         return cnt;
1289 } /* MyCount */
1290
1291
1292 static CLIENT *
1293 New_Client_Struct( void )
1294 {
1295         /* Neue CLIENT-Struktur pre-initialisieren */
1296
1297         CLIENT *c;
1298
1299         c = (CLIENT *)malloc( sizeof( CLIENT ));
1300         if( ! c )
1301         {
1302                 Log( LOG_EMERG, "Can't allocate memory! [New_Client_Struct]" );
1303                 return NULL;
1304         }
1305
1306         memset( c, 0, sizeof ( CLIENT ));
1307
1308         c->type = CLIENT_UNKNOWN;
1309         c->conn_id = NONE;
1310         c->oper_by_me = false;
1311         c->hops = -1;
1312         c->token = -1;
1313         c->mytoken = -1;
1314
1315         return c;
1316 } /* New_Client */
1317
1318
1319 static void
1320 Generate_MyToken( CLIENT *Client )
1321 {
1322         CLIENT *c;
1323         int token;
1324
1325         c = My_Clients;
1326         token = 2;
1327         while( c )
1328         {
1329                 if( c->mytoken == token )
1330                 {
1331                         /* Das Token wurde bereits vergeben */
1332                         token++;
1333                         c = My_Clients;
1334                         continue;
1335                 }
1336                 else c = (CLIENT *)c->next;
1337         }
1338         Client->mytoken = token;
1339         LogDebug("Assigned token %d to server \"%s\".", token, Client->id);
1340 } /* Generate_MyToken */
1341
1342
1343 static void
1344 Adjust_Counters( CLIENT *Client )
1345 {
1346         long count;
1347
1348         assert( Client != NULL );
1349
1350         if( Client->type != CLIENT_USER ) return;
1351
1352         if( Client->conn_id != NONE )
1353         {
1354                 /* Local connection */
1355                 count = Client_MyUserCount( );
1356                 if( count > My_Max_Users ) My_Max_Users = count;
1357         }
1358         count = Client_UserCount( );
1359         if( count > Max_Users ) Max_Users = count;
1360 } /* Adjust_Counters */
1361
1362
1363 /**
1364  * Register client in My_Whowas structure for further recall by WHOWAS.
1365  * Note: Only clients that have been connected at least 30 seconds will be
1366  * registered to prevent automated IRC bots to "destroy" a nice server
1367  * history database.
1368  */
1369 GLOBAL void
1370 Client_RegisterWhowas( CLIENT *Client )
1371 {
1372         int slot;
1373         time_t now;
1374
1375         assert( Client != NULL );
1376
1377         /* Don't register WHOWAS information when "MorePrivacy" is enabled. */
1378         if (Conf_MorePrivacy)
1379                 return;
1380
1381         now = time(NULL);
1382         /* Don't register clients that were connected less than 30 seconds. */
1383         if( now - Client->starttime < 30 )
1384                 return;
1385
1386         slot = Last_Whowas + 1;
1387         if( slot >= MAX_WHOWAS || slot < 0 ) slot = 0;
1388
1389 #ifdef DEBUG
1390         Log( LOG_DEBUG, "Saving WHOWAS information to slot %d ...", slot );
1391 #endif
1392
1393         My_Whowas[slot].time = now;
1394         strlcpy( My_Whowas[slot].id, Client_ID( Client ),
1395                  sizeof( My_Whowas[slot].id ));
1396         strlcpy( My_Whowas[slot].user, Client_User( Client ),
1397                  sizeof( My_Whowas[slot].user ));
1398         strlcpy( My_Whowas[slot].host, Client_HostnameDisplayed( Client ),
1399                  sizeof( My_Whowas[slot].host ));
1400         strlcpy( My_Whowas[slot].info, Client_Info( Client ),
1401                  sizeof( My_Whowas[slot].info ));
1402         strlcpy( My_Whowas[slot].server, Client_ID( Client_Introducer( Client )),
1403                  sizeof( My_Whowas[slot].server ));
1404
1405         Last_Whowas = slot;
1406 } /* Client_RegisterWhowas */
1407
1408
1409 GLOBAL const char *
1410 Client_TypeText(CLIENT *Client)
1411 {
1412         assert(Client != NULL);
1413         switch (Client_Type(Client)) {
1414                 case CLIENT_USER:
1415                         return "User";
1416                         break;
1417                 case CLIENT_SERVICE:
1418                         return "Service";
1419                         break;
1420                 case CLIENT_SERVER:
1421                         return "Server";
1422                         break;
1423                 default:
1424                         return "Client";
1425         }
1426 } /* Client_TypeText */
1427
1428
1429 /**
1430  * Destroy user or service client.
1431  */
1432 static void
1433 Destroy_UserOrService(CLIENT *Client, const char *Txt, const char *FwdMsg, bool SendQuit)
1434 {
1435         if(Client->conn_id != NONE) {
1436                 /* Local (directly connected) client */
1437                 Log(LOG_NOTICE,
1438                     "%s \"%s\" unregistered (connection %d): %s.",
1439                     Client_TypeText(Client), Client_Mask(Client),
1440                     Client->conn_id, Txt);
1441                 Log_ServerNotice('c', "Client exiting: %s (%s@%s) [%s]",
1442                                  Client_ID(Client), Client_User(Client),
1443                                  Client_Hostname(Client), Txt);
1444
1445                 if (SendQuit) {
1446                         /* Inforam all the other servers */
1447                         if (FwdMsg)
1448                                 IRC_WriteStrServersPrefix(NULL,
1449                                                 Client, "QUIT :%s", FwdMsg );
1450                         else
1451                                 IRC_WriteStrServersPrefix(NULL,
1452                                                 Client, "QUIT :");
1453                 }
1454         } else {
1455                 /* Remote client */
1456                 LogDebug("%s \"%s\" unregistered: %s.",
1457                          Client_TypeText(Client), Client_Mask(Client), Txt);
1458
1459                 if(SendQuit) {
1460                         /* Inform all the other servers, but the ones in the
1461                          * direction we got the QUIT from */
1462                         if(FwdMsg)
1463                                 IRC_WriteStrServersPrefix(Client_NextHop(Client),
1464                                                 Client, "QUIT :%s", FwdMsg );
1465                         else
1466                                 IRC_WriteStrServersPrefix(Client_NextHop(Client),
1467                                                 Client, "QUIT :" );
1468                 }
1469         }
1470
1471         /* Unregister client from channels */
1472         Channel_Quit(Client, FwdMsg ? FwdMsg : Client->id);
1473
1474         /* Register client in My_Whowas structure */
1475         Client_RegisterWhowas(Client);
1476 } /* Destroy_UserOrService */
1477
1478
1479 /**
1480  * Introduce a new user or service client to a remote server.
1481  *
1482  * This function differentiates between RFC1459 and RFC2813 server links and
1483  * generates the appropriate commands to register the new user or service.
1484  *
1485  * @param To            The remote server to inform.
1486  * @param Prefix        Prefix for the generated commands.
1487  * @param data          CLIENT structure of the new client.
1488  */
1489 static void
1490 cb_introduceClient(CLIENT *To, CLIENT *Prefix, void *data)
1491 {
1492         CLIENT *c = (CLIENT *)data;
1493         CONN_ID conn;
1494         char *modes, *user, *host;
1495
1496         modes = Client_Modes(c);
1497         user = Client_User(c) ? Client_User(c) : "-";
1498         host = Client_Hostname(c) ? Client_Hostname(c) : "-";
1499
1500         conn = Client_Conn(To);
1501         if (Conn_Options(conn) & CONN_RFC1459) {
1502                 /* RFC 1459 mode: separate NICK and USER commands */
1503                 Conn_WriteStr(conn, "NICK %s :%d", Client_ID(c),
1504                               Client_Hops(c) + 1);
1505                 Conn_WriteStr(conn, ":%s USER %s %s %s :%s",
1506                               Client_ID(c), user, host,
1507                               Client_ID(Client_Introducer(c)), Client_Info(c));
1508                 if (modes[0])
1509                         Conn_WriteStr(conn, ":%s MODE %s +%s",
1510                                       Client_ID(c), Client_ID(c), modes);
1511         } else {
1512                 /* RFC 2813 mode: one combined NICK or SERVICE command */
1513                 if (Client_Type(c) == CLIENT_SERVICE
1514                     && strchr(Client_Flags(To), 'S'))
1515                         IRC_WriteStrClientPrefix(To, Prefix,
1516                                                  "SERVICE %s %d * +%s %d :%s",
1517                                                  Client_Mask(c),
1518                                                  Client_MyToken(Client_Introducer(c)),
1519                                                  Client_Modes(c), Client_Hops(c) + 1,
1520                                                  Client_Info(c));
1521                 else
1522                         IRC_WriteStrClientPrefix(To, Prefix,
1523                                                  "NICK %s %d %s %s %d +%s :%s",
1524                                                  Client_ID(c), Client_Hops(c) + 1,
1525                                                  user, host,
1526                                                  Client_MyToken(Client_Introducer(c)),
1527                                                  modes, Client_Info(c));
1528         }
1529 } /* cb_introduceClient */
1530
1531
1532 #ifdef DEBUG
1533
1534 GLOBAL void
1535 Client_DebugDump(void)
1536 {
1537         CLIENT *c;
1538
1539         Log(LOG_DEBUG, "Client status:");
1540         c = My_Clients;
1541         while (c) {
1542                 Log(LOG_DEBUG,
1543                     " - %s: type=%d, host=%s, user=%s, conn=%d, start=%ld, flags=%s",
1544                    Client_ID(c), Client_Type(c), Client_Hostname(c),
1545                    Client_User(c), Client_Conn(c), Client_StartTime(c),
1546                    Client_Flags(c));
1547                 c = (CLIENT *)c->next;
1548         }
1549 } /* Client_DumpClients */
1550
1551 #endif
1552
1553
1554 /* -eof- */