]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-login.c
USER: servers and services can alter user information after registration.
[ngircd-alex.git] / src / ngircd / irc-login.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001-2008 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  * Login and logout
12  */
13
14
15 #include "portab.h"
16
17 #include "imp.h"
18 #include <assert.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <strings.h>
23
24 #include "ngircd.h"
25 #include "resolve.h"
26 #include "conn-func.h"
27 #include "conf.h"
28 #include "client.h"
29 #include "channel.h"
30 #include "log.h"
31 #include "messages.h"
32 #include "parse.h"
33 #include "irc.h"
34 #include "irc-info.h"
35 #include "irc-write.h"
36
37 #include "exp.h"
38 #include "irc-login.h"
39
40
41 static bool Hello_User PARAMS(( CLIENT *Client ));
42 static void Kill_Nick PARAMS(( char *Nick, char *Reason ));
43
44
45 /**
46  * Handler for the IRC command "PASS".
47  * See RFC 2813 section 4.1.1, and RFC 2812 section 3.1.1.
48  */
49 GLOBAL bool
50 IRC_PASS( CLIENT *Client, REQUEST *Req )
51 {
52         char *type, *orig_flags;
53         int protohigh, protolow;
54
55         assert( Client != NULL );
56         assert( Req != NULL );
57
58         /* Return an error if this is not a local client */
59         if (Client_Conn(Client) <= NONE)
60                 return IRC_WriteStrClient(Client, ERR_UNKNOWNCOMMAND_MSG,
61                                           Client_ID(Client), Req->command);
62
63         if (Client_Type(Client) == CLIENT_UNKNOWN && Req->argc == 1) {
64                 /* Not yet registered "unknown" connection, PASS with one
65                  * argument: either a regular client, service, or server
66                  * using the old RFC 1459 section 4.1.1 syntax. */
67                 LogDebug("Connection %d: got PASS command ...",
68                          Client_Conn(Client));
69         } else if ((Client_Type(Client) == CLIENT_UNKNOWN ||
70                     Client_Type(Client) == CLIENT_UNKNOWNSERVER) &&
71                    (Req->argc == 3 || Req->argc == 4)) {
72                 /* Not yet registered "unknown" connection or outgoing server
73                  * link, PASS with three or four argument: server using the
74                  * RFC 2813 section 4.1.1 syntax. */
75                 LogDebug("Connection %d: got PASS command (new server link) ...",
76                          Client_Conn(Client));
77         } else if (Client_Type(Client) == CLIENT_UNKNOWN ||
78                    Client_Type(Client) == CLIENT_UNKNOWNSERVER) {
79                 /* Unregistered connection, but wrong number of arguments: */
80                 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
81                                           Client_ID(Client), Req->command);
82         } else {
83                 /* Registered connection, PASS command is not allowed! */
84                 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
85                                           Client_ID(Client));
86         }
87
88         Client_SetPassword(Client, Req->argv[0]);
89         Client_SetType(Client, CLIENT_GOTPASS);
90
91         /* Protocol version */
92         if (Req->argc >= 2 && strlen(Req->argv[1]) >= 4) {
93                 int c2, c4;
94
95                 c2 = Req->argv[1][2];
96                 c4 = Req->argv[1][4];
97
98                 Req->argv[1][4] = '\0';
99                 protolow = atoi(&Req->argv[1][2]);
100                 Req->argv[1][2] = '\0';
101                 protohigh = atoi(Req->argv[1]);
102
103                 Req->argv[1][2] = c2;
104                 Req->argv[1][4] = c4;
105         } else
106                 protohigh = protolow = 0;
107
108         /* Protocol type, see doc/Protocol.txt */
109         if (Req->argc >= 2 && strlen(Req->argv[1]) > 4)
110                 type = &Req->argv[1][4];
111         else
112                 type = NULL;
113
114         /* Protocol flags/options */
115         if (Req->argc >= 4)
116                 orig_flags = Req->argv[3];
117         else
118                 orig_flags = "";
119
120         /* Implementation, version and IRC+ flags */
121         if (Req->argc >= 3) {
122                 char *impl, *ptr, *serverver, *flags;
123
124                 impl = Req->argv[2];
125                 ptr = strchr(impl, '|');
126                 if (ptr)
127                         *ptr = '\0';
128
129                 if (type && strcmp(type, PROTOIRCPLUS) == 0) {
130                         /* The peer seems to be a server which supports the
131                          * IRC+ protocol (see doc/Protocol.txt). */
132                         serverver = ptr + 1;
133                         flags = strchr(serverver, ':');
134                         if (flags) {
135                                 *flags = '\0';
136                                 flags++;
137                         } else
138                                 flags = "";
139                         Log(LOG_INFO,
140                             "Peer announces itself as %s-%s using protocol %d.%d/IRC+ (flags: \"%s\").",
141                             impl, serverver, protohigh, protolow, flags);
142                 } else {
143                         /* The peer seems to be a server supporting the
144                          * "original" IRC protocol (RFC 2813). */
145                         serverver = "";
146                         if (strchr(orig_flags, 'Z'))
147                                 flags = "Z";
148                         else
149                                 flags = "";
150                         Log(LOG_INFO,
151                             "Peer announces itself as \"%s\" using protocol %d.%d (flags: \"%s\").",
152                             impl, protohigh, protolow, flags);
153                 }
154                 Client_SetFlags(Client, flags);
155         }
156
157         return CONNECTED;
158 } /* IRC_PASS */
159
160
161 /**
162  * IRC "NICK" command.
163  * This function implements the IRC command "NICK" which is used to register
164  * with the server, to change already registered nicknames and to introduce
165  * new users which are connected to other servers.
166  */
167 GLOBAL bool
168 IRC_NICK( CLIENT *Client, REQUEST *Req )
169 {
170         CLIENT *intr_c, *target, *c;
171         char *nick, *user, *hostname, *modes, *info;
172         int token, hops;
173
174         assert( Client != NULL );
175         assert( Req != NULL );
176
177 #ifndef STRICT_RFC
178         /* Some IRC clients, for example BitchX, send the NICK and USER
179          * commands in the wrong order ... */
180         if( Client_Type( Client ) == CLIENT_UNKNOWN
181             || Client_Type( Client ) == CLIENT_GOTPASS
182             || Client_Type( Client ) == CLIENT_GOTNICK
183             || Client_Type( Client ) == CLIENT_GOTUSER
184             || Client_Type( Client ) == CLIENT_USER
185             || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
186 #else
187         if( Client_Type( Client ) == CLIENT_UNKNOWN
188             || Client_Type( Client ) == CLIENT_GOTPASS
189             || Client_Type( Client ) == CLIENT_GOTNICK
190             || Client_Type( Client ) == CLIENT_USER
191             || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
192 #endif
193         {
194                 /* User registration or change of nickname */
195
196                 /* Wrong number of arguments? */
197                 if( Req->argc != 1 )
198                         return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG,
199                                                    Client_ID( Client ),
200                                                    Req->command );
201
202                 /* Search "target" client */
203                 if( Client_Type( Client ) == CLIENT_SERVER )
204                 {
205                         target = Client_Search( Req->prefix );
206                         if( ! target )
207                                 return IRC_WriteStrClient( Client,
208                                                            ERR_NOSUCHNICK_MSG,
209                                                            Client_ID( Client ),
210                                                            Req->argv[0] );
211                 }
212                 else
213                 {
214                         /* Is this a restricted client? */
215                         if( Client_HasMode( Client, 'r' ))
216                                 return IRC_WriteStrClient( Client,
217                                                            ERR_RESTRICTED_MSG,
218                                                            Client_ID( Client ));
219
220                         target = Client;
221                 }
222
223 #ifndef STRICT_RFC
224                 /* If the clients tries to change to its own nickname we won't
225                  * do anything. This is how the original ircd behaves and some
226                  * clients (for example Snak) expect it to be like this.
227                  * But I doubt that this is "really the right thing" ... */
228                 if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 )
229                         return CONNECTED;
230 #endif
231
232                 /* Check that the new nickname is available. Special case:
233                  * the client only changes from/to upper to lower case. */
234                 if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
235                 {
236                         if( ! Client_CheckNick( target, Req->argv[0] ))
237                                 return CONNECTED;
238                 }
239
240                 if(( Client_Type( target ) != CLIENT_USER )
241                    && ( Client_Type( target ) != CLIENT_SERVER ))
242                 {
243                         /* New client */
244                         Log( LOG_DEBUG, "Connection %d: got valid NICK command ...", 
245                              Client_Conn( Client ));
246
247                         /* Register new nickname of this client */
248                         Client_SetID( target, Req->argv[0] );
249
250                         /* If we received a valid USER command already then
251                          * register the new client! */
252                         if( Client_Type( Client ) == CLIENT_GOTUSER )
253                                 return Hello_User( Client );
254                         else
255                                 Client_SetType( Client, CLIENT_GOTNICK );
256                 }
257                 else
258                 {
259                         /* Nickname change */
260                         if (Client_Conn(target) > NONE) {
261                                 /* Local client */
262                                 Log(LOG_INFO,
263                                     "User \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
264                                     Client_Mask(target), Client_Conn(target),
265                                     Client_ID(target), Req->argv[0]);
266                                 Conn_UpdateIdle(Client_Conn(target));
267                         }
268                         else
269                         {
270                                 /* Remote client */
271                                 Log( LOG_DEBUG,
272                                      "User \"%s\" changed nick: \"%s\" -> \"%s\".",
273                                      Client_Mask( target ), Client_ID( target ),
274                                      Req->argv[0] );
275                         }
276
277                         /* Inform all users and servers (which have to know)
278                          * of this nickname change */
279                         if( Client_Type( Client ) == CLIENT_USER )
280                                 IRC_WriteStrClientPrefix( Client, Client,
281                                                           "NICK :%s",
282                                                           Req->argv[0] );
283                         IRC_WriteStrServersPrefix( Client, target,
284                                                    "NICK :%s", Req->argv[0] );
285                         IRC_WriteStrRelatedPrefix( target, target, false,
286                                                    "NICK :%s", Req->argv[0] );
287
288                         /* Register old nickname for WHOWAS queries */
289                         Client_RegisterWhowas( target );
290
291                         /* Save new nickname */
292                         Client_SetID( target, Req->argv[0] );
293
294                         IRC_SetPenalty( target, 2 );
295                 }
296
297                 return CONNECTED;
298         } else if(Client_Type(Client) == CLIENT_SERVER ||
299                   Client_Type(Client) == CLIENT_SERVICE) {
300                 /* Server or service introduces new client */
301
302                 /* Bad number of parameters? */
303                 if (Req->argc != 2 && Req->argc != 7)
304                         return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
305                                                   Client_ID(Client), Req->command);
306
307                 if (Req->argc >= 7) {
308                         nick = Req->argv[0];
309                         hops = atoi(Req->argv[1]);
310                         user = Req->argv[2];
311                         hostname = Req->argv[3];
312                         token = atoi(Req->argv[4]);
313                         modes = Req->argv[5] + 1;
314                         info = Req->argv[6];
315                 } else {
316                         nick = Req->argv[0];
317                         hops = 1;
318                         user = Req->argv[0];
319                         hostname = Client_ID(Client);
320                         token = atoi(Req->argv[1]);
321                         modes = "";
322                         info = Req->argv[0];
323                 }
324
325                 /* Nick ueberpruefen */
326                 c = Client_Search(nick);
327                 if(c) {
328                         /* Der neue Nick ist auf diesem Server bereits registriert:
329                          * sowohl der neue, als auch der alte Client muessen nun
330                          * disconnectiert werden. */
331                         Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
332                         Kill_Nick( Req->argv[0], "Nick collision" );
333                         return CONNECTED;
334                 }
335
336                 /* Server, zu dem der Client connectiert ist, suchen */
337                 intr_c = Client_GetFromToken(Client, token);
338                 if( ! intr_c )
339                 {
340                         Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
341                         Kill_Nick( Req->argv[0], "Unknown server" );
342                         return CONNECTED;
343                 }
344
345                 /* Neue Client-Struktur anlegen */
346                 c = Client_NewRemoteUser(intr_c, nick, hops, user, hostname,
347                                          token, modes, info, true);
348                 if( ! c )
349                 {
350                         /* Eine neue Client-Struktur konnte nicht angelegt werden.
351                          * Der Client muss disconnectiert werden, damit der Netz-
352                          * status konsistent bleibt. */
353                         Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
354                         Kill_Nick( Req->argv[0], "Server error" );
355                         return CONNECTED;
356                 }
357
358                 modes = Client_Modes( c );
359                 if( *modes ) Log( LOG_DEBUG, "User \"%s\" (+%s) registered (via %s, on %s, %d hop%s).", Client_Mask( c ), modes, Client_ID( Client ), Client_ID( intr_c ), Client_Hops( c ), Client_Hops( c ) > 1 ? "s": "" );
360                 else Log( LOG_DEBUG, "User \"%s\" registered (via %s, on %s, %d hop%s).", Client_Mask( c ), Client_ID( Client ), Client_ID( intr_c ), Client_Hops( c ), Client_Hops( c ) > 1 ? "s": "" );
361
362                 /* Andere Server, ausser dem Introducer, informieren */
363                 IRC_WriteStrServersPrefix( Client, Client, "NICK %s %d %s %s %d %s :%s", Req->argv[0], atoi( Req->argv[1] ) + 1, Req->argv[2], Req->argv[3], Client_MyToken( intr_c ), Req->argv[5], Req->argv[6] );
364
365                 return CONNECTED;
366         }
367         else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
368 } /* IRC_NICK */
369
370
371 /**
372  * Handler for the IRC command "USER".
373  */
374 GLOBAL bool
375 IRC_USER(CLIENT * Client, REQUEST * Req)
376 {
377         CLIENT *c;
378 #ifdef IDENTAUTH
379         char *ptr;
380 #endif
381
382         assert(Client != NULL);
383         assert(Req != NULL);
384
385         if (Client_Type(Client) == CLIENT_GOTNICK ||
386 #ifndef STRICT_RFC
387             Client_Type(Client) == CLIENT_UNKNOWN ||
388 #endif
389             Client_Type(Client) == CLIENT_GOTPASS)
390         {
391                 /* New connection */
392                 if (Req->argc != 4)
393                         return IRC_WriteStrClient(Client,
394                                                   ERR_NEEDMOREPARAMS_MSG,
395                                                   Client_ID(Client),
396                                                   Req->command);
397
398                 /* User name */
399 #ifdef IDENTAUTH
400                 ptr = Client_User(Client);
401                 if (!ptr || !*ptr || *ptr == '~')
402                         Client_SetUser(Client, Req->argv[0], false);
403 #else
404                 Client_SetUser(Client, Req->argv[0], false);
405 #endif
406
407                 /* "Real name" or user info text: Don't set it to the empty
408                  * string, the original ircd can't deal with such "real names"
409                  * (e. g. "USER user * * :") ... */
410                 if (*Req->argv[3])
411                         Client_SetInfo(Client, Req->argv[3]);
412                 else
413                         Client_SetInfo(Client, "-");
414
415                 LogDebug("Connection %d: got valid USER command ...",
416                     Client_Conn(Client));
417                 if (Client_Type(Client) == CLIENT_GOTNICK)
418                         return Hello_User(Client);
419                 else
420                         Client_SetType(Client, CLIENT_GOTUSER);
421                 return CONNECTED;
422
423         } else if (Client_Type(Client) == CLIENT_SERVER ||
424                    Client_Type(Client) == CLIENT_SERVICE) {
425                 /* Server/service updating an user */
426                 if (Req->argc != 4)
427                         return IRC_WriteStrClient(Client,
428                                                   ERR_NEEDMOREPARAMS_MSG,
429                                                   Client_ID(Client),
430                                                   Req->command);
431                 c = Client_Search(Req->prefix);
432                 if (!c)
433                         return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
434                                                   Client_ID(Client),
435                                                   Req->prefix);
436
437                 Client_SetUser(c, Req->argv[0], true);
438                 Client_SetHostname(c, Req->argv[1]);
439                 Client_SetInfo(c, Req->argv[3]);
440
441                 LogDebug("Connection %d: got valid USER command for \"%s\".",
442                          Client_Conn(Client), Client_Mask(c));
443                 return CONNECTED;
444         } else if (Client_Type(Client) == CLIENT_USER) {
445                 /* Already registered connection */
446                 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
447                                           Client_ID(Client));
448         } else {
449                 /* Unexpected/invalid connection state? */
450                 return IRC_WriteStrClient(Client, ERR_NOTREGISTERED_MSG,
451                                           Client_ID(Client));
452         }
453 } /* IRC_USER */
454
455
456 /**
457  * Service registration.
458  * ngIRCd does not support services at the moment, so this function is a
459  * dummy that returns ERR_ERRONEUSNICKNAME on each call.
460  */
461 GLOBAL bool
462 IRC_SERVICE(CLIENT *Client, REQUEST *Req)
463 {
464         assert(Client != NULL);
465         assert(Req != NULL);
466
467         if (Client_Type(Client) != CLIENT_GOTPASS)
468                 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
469                                           Client_ID(Client));
470
471         if (Req->argc != 6)
472                 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
473                                           Client_ID(Client), Req->command);
474
475         return IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
476                                   Client_ID(Client), Req->argv[0]);
477 } /* IRC_SERVICE */
478
479
480 GLOBAL bool
481 IRC_QUIT( CLIENT *Client, REQUEST *Req )
482 {
483         CLIENT *target;
484         char quitmsg[LINE_LEN];
485
486         assert( Client != NULL );
487         assert( Req != NULL );
488
489         /* Wrong number of arguments? */
490         if( Req->argc > 1 )
491                 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
492
493         if (Req->argc == 1)
494                 strlcpy(quitmsg, Req->argv[0], sizeof quitmsg);
495
496         if ( Client_Type( Client ) == CLIENT_SERVER )
497         {
498                 /* Server */
499                 target = Client_Search( Req->prefix );
500                 if( ! target )
501                 {
502                         /* Den Client kennen wir nicht (mehr), also nichts zu tun. */
503                         Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
504                         return CONNECTED;
505                 }
506
507                 Client_Destroy( target, "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
508
509                 return CONNECTED;
510         }
511         else
512         {
513                 if (Req->argc == 1 && quitmsg[0] != '\"') {
514                         /* " " to avoid confusion */
515                         strlcpy(quitmsg, "\"", sizeof quitmsg);
516                         strlcat(quitmsg, Req->argv[0], sizeof quitmsg-1);
517                         strlcat(quitmsg, "\"", sizeof quitmsg );
518                 }
519
520                 /* User, Service, oder noch nicht registriert */
521                 Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
522
523                 return DISCONNECTED;
524         }
525 } /* IRC_QUIT */
526
527
528 GLOBAL bool
529 IRC_PING(CLIENT *Client, REQUEST *Req)
530 {
531         CLIENT *target, *from;
532
533         assert(Client != NULL);
534         assert(Req != NULL);
535
536         /* Wrong number of arguments? */
537         if (Req->argc < 1)
538                 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
539                                           Client_ID(Client));
540 #ifdef STRICT_RFC
541         /* Don't ignore additional arguments when in "strict" mode */
542         if (Req->argc > 2)
543                  return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
544                                            Client_ID(Client), Req->command);
545 #endif
546
547         if (Req->argc > 1) {
548                 /* A target has been specified ... */
549                 target = Client_Search(Req->argv[1]);
550
551                 if (!target || Client_Type(target) != CLIENT_SERVER)
552                         return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
553                                         Client_ID(Client), Req->argv[1]);
554
555                 if (target != Client_ThisServer()) {
556                         /* Ok, we have to forward the PING */
557                         if (Client_Type(Client) == CLIENT_SERVER)
558                                 from = Client_Search(Req->prefix);
559                         else
560                                 from = Client;
561                         if (!from)
562                                 return IRC_WriteStrClient(Client,
563                                                 ERR_NOSUCHSERVER_MSG,
564                                                 Client_ID(Client), Req->prefix);
565
566                         return IRC_WriteStrClientPrefix(target, from,
567                                         "PING %s :%s", Req->argv[0],
568                                         Req->argv[1] );
569                 }
570         }
571
572         if (Client_Type(Client) == CLIENT_SERVER) {
573                 if (Req->prefix)
574                         from = Client_Search(Req->prefix);
575                 else
576                         from = Client;
577         } else
578                 from = Client_ThisServer();
579         if (!from)
580                 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
581                                         Client_ID(Client), Req->prefix);
582
583         Log(LOG_DEBUG, "Connection %d: got PING, sending PONG ...",
584             Client_Conn(Client));
585
586 #ifdef STRICT_RFC
587         return IRC_WriteStrClient(Client, "PONG %s :%s",
588                 Client_ID(from), Client_ID(Client));
589 #else
590         /* Some clients depend on the argument being returned in the PONG
591          * reply (not mentioned in any RFC, though) */
592         return IRC_WriteStrClient(Client, "PONG %s :%s",
593                 Client_ID(from), Req->argv[0]);
594 #endif
595 } /* IRC_PING */
596
597
598 GLOBAL bool
599 IRC_PONG(CLIENT *Client, REQUEST *Req)
600 {
601         CLIENT *target, *from;
602         char *s;
603
604         assert(Client != NULL);
605         assert(Req != NULL);
606
607         /* Wrong number of arguments? */
608         if (Req->argc < 1)
609                 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
610                                           Client_ID(Client));
611         if (Req->argc > 2)
612                 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
613                                           Client_ID(Client), Req->command);
614
615         /* Forward? */
616         if (Req->argc == 2 && Client_Type(Client) == CLIENT_SERVER) {
617                 target = Client_Search(Req->argv[0]);
618                 if (!target)
619                         return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
620                                         Client_ID(Client), Req->argv[0]);
621
622                 from = Client_Search(Req->prefix);
623
624                 if (target != Client_ThisServer() && target != from) {
625                         /* Ok, we have to forward the message. */
626                         if (!from)
627                                 return IRC_WriteStrClient(Client,
628                                                 ERR_NOSUCHSERVER_MSG,
629                                                 Client_ID(Client), Req->prefix);
630
631                         if (Client_Type(Client_NextHop(target)) != CLIENT_SERVER)
632                                 s = Client_ID(from);
633                         else
634                                 s = Req->argv[0];
635                         return IRC_WriteStrClientPrefix(target, from,
636                                  "PONG %s :%s", s, Req->argv[1]);
637                 }
638         }
639
640         /* The connection timestamp has already been updated when the data has
641          * been read from so socket, so we don't need to update it here. */
642
643         if (Client_Conn(Client) > NONE)
644                 Log(LOG_DEBUG,
645                         "Connection %d: received PONG. Lag: %ld seconds.",
646                         Client_Conn(Client),
647                         time(NULL) - Conn_LastPing(Client_Conn(Client)));
648         else
649                  Log(LOG_DEBUG,
650                         "Connection %d: received PONG.", Client_Conn(Client));
651
652         return CONNECTED;
653 } /* IRC_PONG */
654
655
656 static bool
657 Hello_User(CLIENT * Client)
658 {
659         assert(Client != NULL);
660
661         /* Check password ... */
662         if (strcmp(Client_Password(Client), Conf_ServerPwd) != 0) {
663                 /* Bad password! */
664                 Log(LOG_ERR,
665                     "User \"%s\" rejected (connection %d): Bad password!",
666                     Client_Mask(Client), Client_Conn(Client));
667                 Conn_Close(Client_Conn(Client), NULL, "Bad password", true);
668                 return DISCONNECTED;
669         }
670
671         Log(LOG_NOTICE, "User \"%s\" registered (connection %d).",
672             Client_Mask(Client), Client_Conn(Client));
673
674         /* Inform other servers */
675         IRC_WriteStrServers(NULL, "NICK %s 1 %s %s 1 +%s :%s",
676                             Client_ID(Client), Client_User(Client),
677                             Client_Hostname(Client), Client_Modes(Client),
678                             Client_Info(Client));
679
680         if (!IRC_WriteStrClient
681             (Client, RPL_WELCOME_MSG, Client_ID(Client), Client_Mask(Client)))
682                 return false;
683         if (!IRC_WriteStrClient
684             (Client, RPL_YOURHOST_MSG, Client_ID(Client),
685              Client_ID(Client_ThisServer()), PACKAGE_VERSION, TARGET_CPU,
686              TARGET_VENDOR, TARGET_OS))
687                 return false;
688         if (!IRC_WriteStrClient
689             (Client, RPL_CREATED_MSG, Client_ID(Client), NGIRCd_StartStr))
690                 return false;
691         if (!IRC_WriteStrClient
692             (Client, RPL_MYINFO_MSG, Client_ID(Client),
693              Client_ID(Client_ThisServer()), PACKAGE_VERSION, USERMODES,
694              CHANMODES))
695                 return false;
696
697         /* Features supported by this server (005 numeric, ISUPPORT),
698          * see <http://www.irc.org/tech_docs/005.html> for details. */
699         if (!IRC_Send_ISUPPORT(Client))
700                 return DISCONNECTED;
701
702         Client_SetType(Client, CLIENT_USER);
703
704         if (!IRC_Send_LUSERS(Client))
705                 return DISCONNECTED;
706         if (!IRC_Show_MOTD(Client))
707                 return DISCONNECTED;
708
709         /* Suspend the client for a second ... */
710         IRC_SetPenalty(Client, 1);
711
712         return CONNECTED;
713 } /* Hello_User */
714
715
716 static void
717 Kill_Nick( char *Nick, char *Reason )
718 {
719         REQUEST r;
720
721         assert( Nick != NULL );
722         assert( Reason != NULL );
723
724         r.prefix = (char *)Client_ThisServer( );
725         r.argv[0] = Nick;
726         r.argv[1] = Reason;
727         r.argc = 2;
728
729         Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s", Nick, Reason );
730         IRC_KILL( Client_ThisServer( ), &r );
731 } /* Kill_Nick */
732
733
734 /* -eof- */