]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-login.c
Whitespace fixes: remove trailing tabulator characters.
[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 *modes;
172
173         assert( Client != NULL );
174         assert( Req != NULL );
175
176 #ifndef STRICT_RFC
177         /* Some IRC clients, for example BitchX, send the NICK and USER
178          * commands in the wrong order ... */
179         if( Client_Type( Client ) == CLIENT_UNKNOWN
180             || Client_Type( Client ) == CLIENT_GOTPASS
181             || Client_Type( Client ) == CLIENT_GOTNICK
182             || Client_Type( Client ) == CLIENT_GOTUSER
183             || Client_Type( Client ) == CLIENT_USER
184             || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
185 #else
186         if( Client_Type( Client ) == CLIENT_UNKNOWN
187             || Client_Type( Client ) == CLIENT_GOTPASS
188             || Client_Type( Client ) == CLIENT_GOTNICK
189             || Client_Type( Client ) == CLIENT_USER
190             || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
191 #endif
192         {
193                 /* User registration or change of nickname */
194
195                 /* Wrong number of arguments? */
196                 if( Req->argc != 1 )
197                         return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG,
198                                                    Client_ID( Client ),
199                                                    Req->command );
200
201                 /* Search "target" client */
202                 if( Client_Type( Client ) == CLIENT_SERVER )
203                 {
204                         target = Client_Search( Req->prefix );
205                         if( ! target )
206                                 return IRC_WriteStrClient( Client,
207                                                            ERR_NOSUCHNICK_MSG,
208                                                            Client_ID( Client ),
209                                                            Req->argv[0] );
210                 }
211                 else
212                 {
213                         /* Is this a restricted client? */
214                         if( Client_HasMode( Client, 'r' ))
215                                 return IRC_WriteStrClient( Client,
216                                                            ERR_RESTRICTED_MSG,
217                                                            Client_ID( Client ));
218
219                         target = Client;
220                 }
221
222 #ifndef STRICT_RFC
223                 /* If the clients tries to change to its own nickname we won't
224                  * do anything. This is how the original ircd behaves and some
225                  * clients (for example Snak) expect it to be like this.
226                  * But I doubt that this is "really the right thing" ... */
227                 if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 )
228                         return CONNECTED;
229 #endif
230
231                 /* Check that the new nickname is available. Special case:
232                  * the client only changes from/to upper to lower case. */
233                 if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
234                 {
235                         if( ! Client_CheckNick( target, Req->argv[0] ))
236                                 return CONNECTED;
237                 }
238
239                 if(( Client_Type( target ) != CLIENT_USER )
240                    && ( Client_Type( target ) != CLIENT_SERVER ))
241                 {
242                         /* New client */
243                         Log( LOG_DEBUG, "Connection %d: got valid NICK command ...", 
244                              Client_Conn( Client ));
245
246                         /* Register new nickname of this client */
247                         Client_SetID( target, Req->argv[0] );
248
249                         /* If we received a valid USER command already then
250                          * register the new client! */
251                         if( Client_Type( Client ) == CLIENT_GOTUSER )
252                                 return Hello_User( Client );
253                         else
254                                 Client_SetType( Client, CLIENT_GOTNICK );
255                 }
256                 else
257                 {
258                         /* Nickname change */
259                         if (Client_Conn(target) > NONE) {
260                                 /* Local client */
261                                 Log(LOG_INFO,
262                                     "User \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
263                                     Client_Mask(target), Client_Conn(target),
264                                     Client_ID(target), Req->argv[0]);
265                                 Conn_UpdateIdle(Client_Conn(target));
266                         }
267                         else
268                         {
269                                 /* Remote client */
270                                 Log( LOG_DEBUG,
271                                      "User \"%s\" changed nick: \"%s\" -> \"%s\".",
272                                      Client_Mask( target ), Client_ID( target ),
273                                      Req->argv[0] );
274                         }
275
276                         /* Inform all users and servers (which have to know)
277                          * of this nickname change */
278                         if( Client_Type( Client ) == CLIENT_USER )
279                                 IRC_WriteStrClientPrefix( Client, Client,
280                                                           "NICK :%s",
281                                                           Req->argv[0] );
282                         IRC_WriteStrServersPrefix( Client, target,
283                                                    "NICK :%s", Req->argv[0] );
284                         IRC_WriteStrRelatedPrefix( target, target, false,
285                                                    "NICK :%s", Req->argv[0] );
286
287                         /* Register old nickname for WHOWAS queries */
288                         Client_RegisterWhowas( target );
289
290                         /* Save new nickname */
291                         Client_SetID( target, Req->argv[0] );
292
293                         IRC_SetPenalty( target, 2 );
294                 }
295
296                 return CONNECTED;
297         }
298         else if( Client_Type( Client ) == CLIENT_SERVER )
299         {
300                 /* Server introduces new client */
301
302                 /* Falsche Anzahl Parameter? */
303                 if( Req->argc != 7 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
304
305                 /* Nick ueberpruefen */
306                 c = Client_Search( Req->argv[0] );
307                 if( c )
308                 {
309                         /* Der neue Nick ist auf diesem Server bereits registriert:
310                          * sowohl der neue, als auch der alte Client muessen nun
311                          * disconnectiert werden. */
312                         Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
313                         Kill_Nick( Req->argv[0], "Nick collision" );
314                         return CONNECTED;
315                 }
316
317                 /* Server, zu dem der Client connectiert ist, suchen */
318                 intr_c = Client_GetFromToken( Client, atoi( Req->argv[4] ));
319                 if( ! intr_c )
320                 {
321                         Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
322                         Kill_Nick( Req->argv[0], "Unknown server" );
323                         return CONNECTED;
324                 }
325
326                 /* Neue Client-Struktur anlegen */
327                 c = Client_NewRemoteUser( intr_c, Req->argv[0], atoi( Req->argv[1] ), Req->argv[2], Req->argv[3], atoi( Req->argv[4] ), Req->argv[5] + 1, Req->argv[6], true);
328                 if( ! c )
329                 {
330                         /* Eine neue Client-Struktur konnte nicht angelegt werden.
331                          * Der Client muss disconnectiert werden, damit der Netz-
332                          * status konsistent bleibt. */
333                         Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
334                         Kill_Nick( Req->argv[0], "Server error" );
335                         return CONNECTED;
336                 }
337
338                 modes = Client_Modes( c );
339                 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": "" );
340                 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": "" );
341
342                 /* Andere Server, ausser dem Introducer, informieren */
343                 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] );
344
345                 return CONNECTED;
346         }
347         else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
348 } /* IRC_NICK */
349
350
351 GLOBAL bool
352 IRC_USER( CLIENT *Client, REQUEST *Req )
353 {
354 #ifdef IDENTAUTH
355         char *ptr;
356 #endif
357
358         assert( Client != NULL );
359         assert( Req != NULL );
360
361 #ifndef STRICT_RFC
362         if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_UNKNOWN )
363 #else
364         if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS )
365 #endif
366         {
367                 /* Wrong number of parameters? */
368                 if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
369
370                 /* User name */
371 #ifdef IDENTAUTH
372                 ptr = Client_User( Client );
373                 if( ! ptr || ! *ptr || *ptr == '~' ) Client_SetUser( Client, Req->argv[0], false );
374 #else
375                 Client_SetUser( Client, Req->argv[0], false );
376 #endif
377
378                 /* "Real name" or user info text: Don't set it to the empty string, the original ircd
379                  * can't deal with such "real names" (e. g. "USER user * * :") ... */
380                 if( *Req->argv[3] ) Client_SetInfo( Client, Req->argv[3] );
381                 else Client_SetInfo( Client, "-" );
382
383                 Log( LOG_DEBUG, "Connection %d: got valid USER command ...", Client_Conn( Client ));
384                 if( Client_Type( Client ) == CLIENT_GOTNICK ) return Hello_User( Client );
385                 else Client_SetType( Client, CLIENT_GOTUSER );
386                 return CONNECTED;
387         }
388         else if( Client_Type( Client ) == CLIENT_USER || Client_Type( Client ) == CLIENT_SERVER || Client_Type( Client ) == CLIENT_SERVICE )
389         {
390                 return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
391         }
392         else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
393 } /* IRC_USER */
394
395
396 /**
397  * Service registration.
398  * ngIRCd does not support services at the moment, so this function is a
399  * dummy that returns ERR_ERRONEUSNICKNAME on each call.
400  */
401 GLOBAL bool
402 IRC_SERVICE(CLIENT *Client, REQUEST *Req)
403 {
404         assert(Client != NULL);
405         assert(Req != NULL);
406
407         if (Client_Type(Client) != CLIENT_GOTPASS)
408                 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
409                                           Client_ID(Client));
410
411         if (Req->argc != 6)
412                 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
413                                           Client_ID(Client), Req->command);
414
415         return IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
416                                   Client_ID(Client), Req->argv[0]);
417 } /* IRC_SERVICE */
418
419
420 GLOBAL bool
421 IRC_QUIT( CLIENT *Client, REQUEST *Req )
422 {
423         CLIENT *target;
424         char quitmsg[LINE_LEN];
425
426         assert( Client != NULL );
427         assert( Req != NULL );
428
429         /* Wrong number of arguments? */
430         if( Req->argc > 1 )
431                 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
432
433         if (Req->argc == 1)
434                 strlcpy(quitmsg, Req->argv[0], sizeof quitmsg);
435
436         if ( Client_Type( Client ) == CLIENT_SERVER )
437         {
438                 /* Server */
439                 target = Client_Search( Req->prefix );
440                 if( ! target )
441                 {
442                         /* Den Client kennen wir nicht (mehr), also nichts zu tun. */
443                         Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
444                         return CONNECTED;
445                 }
446
447                 Client_Destroy( target, "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
448
449                 return CONNECTED;
450         }
451         else
452         {
453                 if (Req->argc == 1 && quitmsg[0] != '\"') {
454                         /* " " to avoid confusion */
455                         strlcpy(quitmsg, "\"", sizeof quitmsg);
456                         strlcat(quitmsg, Req->argv[0], sizeof quitmsg-1);
457                         strlcat(quitmsg, "\"", sizeof quitmsg );
458                 }
459
460                 /* User, Service, oder noch nicht registriert */
461                 Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
462
463                 return DISCONNECTED;
464         }
465 } /* IRC_QUIT */
466
467
468 GLOBAL bool
469 IRC_PING(CLIENT *Client, REQUEST *Req)
470 {
471         CLIENT *target, *from;
472
473         assert(Client != NULL);
474         assert(Req != NULL);
475
476         /* Wrong number of arguments? */
477         if (Req->argc < 1)
478                 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
479                                           Client_ID(Client));
480 #ifdef STRICT_RFC
481         /* Don't ignore additional arguments when in "strict" mode */
482         if (Req->argc > 2)
483                  return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
484                                            Client_ID(Client), Req->command);
485 #endif
486
487         if (Req->argc > 1) {
488                 /* A target has been specified ... */
489                 target = Client_Search(Req->argv[1]);
490
491                 if (!target || Client_Type(target) != CLIENT_SERVER)
492                         return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
493                                         Client_ID(Client), Req->argv[1]);
494
495                 if (target != Client_ThisServer()) {
496                         /* Ok, we have to forward the PING */
497                         if (Client_Type(Client) == CLIENT_SERVER)
498                                 from = Client_Search(Req->prefix);
499                         else
500                                 from = Client;
501                         if (!from)
502                                 return IRC_WriteStrClient(Client,
503                                                 ERR_NOSUCHSERVER_MSG,
504                                                 Client_ID(Client), Req->prefix);
505
506                         return IRC_WriteStrClientPrefix(target, from,
507                                         "PING %s :%s", Req->argv[0],
508                                         Req->argv[1] );
509                 }
510         }
511
512         if (Client_Type(Client) == CLIENT_SERVER) {
513                 if (Req->prefix)
514                         from = Client_Search(Req->prefix);
515                 else
516                         from = Client;
517         } else
518                 from = Client_ThisServer();
519         if (!from)
520                 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
521                                         Client_ID(Client), Req->prefix);
522
523         Log(LOG_DEBUG, "Connection %d: got PING, sending PONG ...",
524             Client_Conn(Client));
525
526 #ifdef STRICT_RFC
527         return IRC_WriteStrClient(Client, "PONG %s :%s",
528                 Client_ID(from), Client_ID(Client));
529 #else
530         /* Some clients depend on the argument being returned in the PONG
531          * reply (not mentioned in any RFC, though) */
532         return IRC_WriteStrClient(Client, "PONG %s :%s",
533                 Client_ID(from), Req->argv[0]);
534 #endif
535 } /* IRC_PING */
536
537
538 GLOBAL bool
539 IRC_PONG(CLIENT *Client, REQUEST *Req)
540 {
541         CLIENT *target, *from;
542         char *s;
543
544         assert(Client != NULL);
545         assert(Req != NULL);
546
547         /* Wrong number of arguments? */
548         if (Req->argc < 1)
549                 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
550                                           Client_ID(Client));
551         if (Req->argc > 2)
552                 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
553                                           Client_ID(Client), Req->command);
554
555         /* Forward? */
556         if (Req->argc == 2 && Client_Type(Client) == CLIENT_SERVER) {
557                 target = Client_Search(Req->argv[0]);
558                 if (!target)
559                         return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
560                                         Client_ID(Client), Req->argv[0]);
561
562                 from = Client_Search(Req->prefix);
563
564                 if (target != Client_ThisServer() && target != from) {
565                         /* Ok, we have to forward the message. */
566                         if (!from)
567                                 return IRC_WriteStrClient(Client,
568                                                 ERR_NOSUCHSERVER_MSG,
569                                                 Client_ID(Client), Req->prefix);
570
571                         if (Client_Type(Client_NextHop(target)) != CLIENT_SERVER)
572                                 s = Client_ID(from);
573                         else
574                                 s = Req->argv[0];
575                         return IRC_WriteStrClientPrefix(target, from,
576                                  "PONG %s :%s", s, Req->argv[1]);
577                 }
578         }
579
580         /* The connection timestamp has already been updated when the data has
581          * been read from so socket, so we don't need to update it here. */
582
583         if (Client_Conn(Client) > NONE)
584                 Log(LOG_DEBUG,
585                         "Connection %d: received PONG. Lag: %ld seconds.",
586                         Client_Conn(Client),
587                         time(NULL) - Conn_LastPing(Client_Conn(Client)));
588         else
589                  Log(LOG_DEBUG,
590                         "Connection %d: received PONG.", Client_Conn(Client));
591
592         return CONNECTED;
593 } /* IRC_PONG */
594
595
596 static bool
597 Hello_User(CLIENT * Client)
598 {
599         assert(Client != NULL);
600
601         /* Check password ... */
602         if (strcmp(Client_Password(Client), Conf_ServerPwd) != 0) {
603                 /* Bad password! */
604                 Log(LOG_ERR,
605                     "User \"%s\" rejected (connection %d): Bad password!",
606                     Client_Mask(Client), Client_Conn(Client));
607                 Conn_Close(Client_Conn(Client), NULL, "Bad password", true);
608                 return DISCONNECTED;
609         }
610
611         Log(LOG_NOTICE, "User \"%s\" registered (connection %d).",
612             Client_Mask(Client), Client_Conn(Client));
613
614         /* Inform other servers */
615         IRC_WriteStrServers(NULL, "NICK %s 1 %s %s 1 +%s :%s",
616                             Client_ID(Client), Client_User(Client),
617                             Client_Hostname(Client), Client_Modes(Client),
618                             Client_Info(Client));
619
620         if (!IRC_WriteStrClient
621             (Client, RPL_WELCOME_MSG, Client_ID(Client), Client_Mask(Client)))
622                 return false;
623         if (!IRC_WriteStrClient
624             (Client, RPL_YOURHOST_MSG, Client_ID(Client),
625              Client_ID(Client_ThisServer()), PACKAGE_VERSION, TARGET_CPU,
626              TARGET_VENDOR, TARGET_OS))
627                 return false;
628         if (!IRC_WriteStrClient
629             (Client, RPL_CREATED_MSG, Client_ID(Client), NGIRCd_StartStr))
630                 return false;
631         if (!IRC_WriteStrClient
632             (Client, RPL_MYINFO_MSG, Client_ID(Client),
633              Client_ID(Client_ThisServer()), PACKAGE_VERSION, USERMODES,
634              CHANMODES))
635                 return false;
636
637         /* Features supported by this server (005 numeric, ISUPPORT),
638          * see <http://www.irc.org/tech_docs/005.html> for details. */
639         if (!IRC_Send_ISUPPORT(Client))
640                 return DISCONNECTED;
641
642         Client_SetType(Client, CLIENT_USER);
643
644         if (!IRC_Send_LUSERS(Client))
645                 return DISCONNECTED;
646         if (!IRC_Show_MOTD(Client))
647                 return DISCONNECTED;
648
649         /* Suspend the client for a second ... */
650         IRC_SetPenalty(Client, 1);
651
652         return CONNECTED;
653 } /* Hello_User */
654
655
656 static void
657 Kill_Nick( char *Nick, char *Reason )
658 {
659         REQUEST r;
660
661         assert( Nick != NULL );
662         assert( Reason != NULL );
663
664         r.prefix = (char *)Client_ThisServer( );
665         r.argv[0] = Nick;
666         r.argv[1] = Reason;
667         r.argc = 2;
668
669         Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s", Nick, Reason );
670         IRC_KILL( Client_ThisServer( ), &r );
671 } /* Kill_Nick */
672
673
674 /* -eof- */