]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-login.c
NICK: allow servers and services to use RFC 1459 syntax (2 parameters).
[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 GLOBAL bool
372 IRC_USER( CLIENT *Client, REQUEST *Req )
373 {
374 #ifdef IDENTAUTH
375         char *ptr;
376 #endif
377
378         assert( Client != NULL );
379         assert( Req != NULL );
380
381 #ifndef STRICT_RFC
382         if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_UNKNOWN )
383 #else
384         if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS )
385 #endif
386         {
387                 /* Wrong number of parameters? */
388                 if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
389
390                 /* User name */
391 #ifdef IDENTAUTH
392                 ptr = Client_User( Client );
393                 if( ! ptr || ! *ptr || *ptr == '~' ) Client_SetUser( Client, Req->argv[0], false );
394 #else
395                 Client_SetUser( Client, Req->argv[0], false );
396 #endif
397
398                 /* "Real name" or user info text: Don't set it to the empty string, the original ircd
399                  * can't deal with such "real names" (e. g. "USER user * * :") ... */
400                 if( *Req->argv[3] ) Client_SetInfo( Client, Req->argv[3] );
401                 else Client_SetInfo( Client, "-" );
402
403                 Log( LOG_DEBUG, "Connection %d: got valid USER command ...", Client_Conn( Client ));
404                 if( Client_Type( Client ) == CLIENT_GOTNICK ) return Hello_User( Client );
405                 else Client_SetType( Client, CLIENT_GOTUSER );
406                 return CONNECTED;
407         }
408         else if( Client_Type( Client ) == CLIENT_USER || Client_Type( Client ) == CLIENT_SERVER || Client_Type( Client ) == CLIENT_SERVICE )
409         {
410                 return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
411         }
412         else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
413 } /* IRC_USER */
414
415
416 /**
417  * Service registration.
418  * ngIRCd does not support services at the moment, so this function is a
419  * dummy that returns ERR_ERRONEUSNICKNAME on each call.
420  */
421 GLOBAL bool
422 IRC_SERVICE(CLIENT *Client, REQUEST *Req)
423 {
424         assert(Client != NULL);
425         assert(Req != NULL);
426
427         if (Client_Type(Client) != CLIENT_GOTPASS)
428                 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
429                                           Client_ID(Client));
430
431         if (Req->argc != 6)
432                 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
433                                           Client_ID(Client), Req->command);
434
435         return IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
436                                   Client_ID(Client), Req->argv[0]);
437 } /* IRC_SERVICE */
438
439
440 GLOBAL bool
441 IRC_QUIT( CLIENT *Client, REQUEST *Req )
442 {
443         CLIENT *target;
444         char quitmsg[LINE_LEN];
445
446         assert( Client != NULL );
447         assert( Req != NULL );
448
449         /* Wrong number of arguments? */
450         if( Req->argc > 1 )
451                 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
452
453         if (Req->argc == 1)
454                 strlcpy(quitmsg, Req->argv[0], sizeof quitmsg);
455
456         if ( Client_Type( Client ) == CLIENT_SERVER )
457         {
458                 /* Server */
459                 target = Client_Search( Req->prefix );
460                 if( ! target )
461                 {
462                         /* Den Client kennen wir nicht (mehr), also nichts zu tun. */
463                         Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
464                         return CONNECTED;
465                 }
466
467                 Client_Destroy( target, "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
468
469                 return CONNECTED;
470         }
471         else
472         {
473                 if (Req->argc == 1 && quitmsg[0] != '\"') {
474                         /* " " to avoid confusion */
475                         strlcpy(quitmsg, "\"", sizeof quitmsg);
476                         strlcat(quitmsg, Req->argv[0], sizeof quitmsg-1);
477                         strlcat(quitmsg, "\"", sizeof quitmsg );
478                 }
479
480                 /* User, Service, oder noch nicht registriert */
481                 Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
482
483                 return DISCONNECTED;
484         }
485 } /* IRC_QUIT */
486
487
488 GLOBAL bool
489 IRC_PING(CLIENT *Client, REQUEST *Req)
490 {
491         CLIENT *target, *from;
492
493         assert(Client != NULL);
494         assert(Req != NULL);
495
496         /* Wrong number of arguments? */
497         if (Req->argc < 1)
498                 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
499                                           Client_ID(Client));
500 #ifdef STRICT_RFC
501         /* Don't ignore additional arguments when in "strict" mode */
502         if (Req->argc > 2)
503                  return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
504                                            Client_ID(Client), Req->command);
505 #endif
506
507         if (Req->argc > 1) {
508                 /* A target has been specified ... */
509                 target = Client_Search(Req->argv[1]);
510
511                 if (!target || Client_Type(target) != CLIENT_SERVER)
512                         return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
513                                         Client_ID(Client), Req->argv[1]);
514
515                 if (target != Client_ThisServer()) {
516                         /* Ok, we have to forward the PING */
517                         if (Client_Type(Client) == CLIENT_SERVER)
518                                 from = Client_Search(Req->prefix);
519                         else
520                                 from = Client;
521                         if (!from)
522                                 return IRC_WriteStrClient(Client,
523                                                 ERR_NOSUCHSERVER_MSG,
524                                                 Client_ID(Client), Req->prefix);
525
526                         return IRC_WriteStrClientPrefix(target, from,
527                                         "PING %s :%s", Req->argv[0],
528                                         Req->argv[1] );
529                 }
530         }
531
532         if (Client_Type(Client) == CLIENT_SERVER) {
533                 if (Req->prefix)
534                         from = Client_Search(Req->prefix);
535                 else
536                         from = Client;
537         } else
538                 from = Client_ThisServer();
539         if (!from)
540                 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
541                                         Client_ID(Client), Req->prefix);
542
543         Log(LOG_DEBUG, "Connection %d: got PING, sending PONG ...",
544             Client_Conn(Client));
545
546 #ifdef STRICT_RFC
547         return IRC_WriteStrClient(Client, "PONG %s :%s",
548                 Client_ID(from), Client_ID(Client));
549 #else
550         /* Some clients depend on the argument being returned in the PONG
551          * reply (not mentioned in any RFC, though) */
552         return IRC_WriteStrClient(Client, "PONG %s :%s",
553                 Client_ID(from), Req->argv[0]);
554 #endif
555 } /* IRC_PING */
556
557
558 GLOBAL bool
559 IRC_PONG(CLIENT *Client, REQUEST *Req)
560 {
561         CLIENT *target, *from;
562         char *s;
563
564         assert(Client != NULL);
565         assert(Req != NULL);
566
567         /* Wrong number of arguments? */
568         if (Req->argc < 1)
569                 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
570                                           Client_ID(Client));
571         if (Req->argc > 2)
572                 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
573                                           Client_ID(Client), Req->command);
574
575         /* Forward? */
576         if (Req->argc == 2 && Client_Type(Client) == CLIENT_SERVER) {
577                 target = Client_Search(Req->argv[0]);
578                 if (!target)
579                         return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
580                                         Client_ID(Client), Req->argv[0]);
581
582                 from = Client_Search(Req->prefix);
583
584                 if (target != Client_ThisServer() && target != from) {
585                         /* Ok, we have to forward the message. */
586                         if (!from)
587                                 return IRC_WriteStrClient(Client,
588                                                 ERR_NOSUCHSERVER_MSG,
589                                                 Client_ID(Client), Req->prefix);
590
591                         if (Client_Type(Client_NextHop(target)) != CLIENT_SERVER)
592                                 s = Client_ID(from);
593                         else
594                                 s = Req->argv[0];
595                         return IRC_WriteStrClientPrefix(target, from,
596                                  "PONG %s :%s", s, Req->argv[1]);
597                 }
598         }
599
600         /* The connection timestamp has already been updated when the data has
601          * been read from so socket, so we don't need to update it here. */
602
603         if (Client_Conn(Client) > NONE)
604                 Log(LOG_DEBUG,
605                         "Connection %d: received PONG. Lag: %ld seconds.",
606                         Client_Conn(Client),
607                         time(NULL) - Conn_LastPing(Client_Conn(Client)));
608         else
609                  Log(LOG_DEBUG,
610                         "Connection %d: received PONG.", Client_Conn(Client));
611
612         return CONNECTED;
613 } /* IRC_PONG */
614
615
616 static bool
617 Hello_User(CLIENT * Client)
618 {
619         assert(Client != NULL);
620
621         /* Check password ... */
622         if (strcmp(Client_Password(Client), Conf_ServerPwd) != 0) {
623                 /* Bad password! */
624                 Log(LOG_ERR,
625                     "User \"%s\" rejected (connection %d): Bad password!",
626                     Client_Mask(Client), Client_Conn(Client));
627                 Conn_Close(Client_Conn(Client), NULL, "Bad password", true);
628                 return DISCONNECTED;
629         }
630
631         Log(LOG_NOTICE, "User \"%s\" registered (connection %d).",
632             Client_Mask(Client), Client_Conn(Client));
633
634         /* Inform other servers */
635         IRC_WriteStrServers(NULL, "NICK %s 1 %s %s 1 +%s :%s",
636                             Client_ID(Client), Client_User(Client),
637                             Client_Hostname(Client), Client_Modes(Client),
638                             Client_Info(Client));
639
640         if (!IRC_WriteStrClient
641             (Client, RPL_WELCOME_MSG, Client_ID(Client), Client_Mask(Client)))
642                 return false;
643         if (!IRC_WriteStrClient
644             (Client, RPL_YOURHOST_MSG, Client_ID(Client),
645              Client_ID(Client_ThisServer()), PACKAGE_VERSION, TARGET_CPU,
646              TARGET_VENDOR, TARGET_OS))
647                 return false;
648         if (!IRC_WriteStrClient
649             (Client, RPL_CREATED_MSG, Client_ID(Client), NGIRCd_StartStr))
650                 return false;
651         if (!IRC_WriteStrClient
652             (Client, RPL_MYINFO_MSG, Client_ID(Client),
653              Client_ID(Client_ThisServer()), PACKAGE_VERSION, USERMODES,
654              CHANMODES))
655                 return false;
656
657         /* Features supported by this server (005 numeric, ISUPPORT),
658          * see <http://www.irc.org/tech_docs/005.html> for details. */
659         if (!IRC_Send_ISUPPORT(Client))
660                 return DISCONNECTED;
661
662         Client_SetType(Client, CLIENT_USER);
663
664         if (!IRC_Send_LUSERS(Client))
665                 return DISCONNECTED;
666         if (!IRC_Show_MOTD(Client))
667                 return DISCONNECTED;
668
669         /* Suspend the client for a second ... */
670         IRC_SetPenalty(Client, 1);
671
672         return CONNECTED;
673 } /* Hello_User */
674
675
676 static void
677 Kill_Nick( char *Nick, char *Reason )
678 {
679         REQUEST r;
680
681         assert( Nick != NULL );
682         assert( Reason != NULL );
683
684         r.prefix = (char *)Client_ThisServer( );
685         r.argv[0] = Nick;
686         r.argv[1] = Reason;
687         r.argc = 2;
688
689         Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s", Nick, Reason );
690         IRC_KILL( Client_ThisServer( ), &r );
691 } /* Kill_Nick */
692
693
694 /* -eof- */