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