Blame


1 c23199d9 2002-02-27 alex /*
2 c23199d9 2002-02-27 alex * ngIRCd -- The Next Generation IRC Daemon
3 c23199d9 2002-02-27 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
4 c23199d9 2002-02-27 alex *
5 490f28ff 2002-12-12 alex * This program is free software; you can redistribute it and/or modify
6 490f28ff 2002-12-12 alex * it under the terms of the GNU General Public License as published by
7 490f28ff 2002-12-12 alex * the Free Software Foundation; either version 2 of the License, or
8 490f28ff 2002-12-12 alex * (at your option) any later version.
9 490f28ff 2002-12-12 alex * Please read the file COPYING, README and AUTHORS for more information.
10 c23199d9 2002-02-27 alex *
11 490f28ff 2002-12-12 alex * Login and logout
12 c23199d9 2002-02-27 alex */
13 c23199d9 2002-02-27 alex
14 c23199d9 2002-02-27 alex
15 ca33cbda 2002-03-12 alex #include "portab.h"
16 490f28ff 2002-12-12 alex
17 cb76d96e 2004-03-11 alex static char UNUSED id[] = "$Id: irc-login.c,v 1.40 2004/03/11 22:16:31 alex Exp $";
18 c23199d9 2002-02-27 alex
19 ca33cbda 2002-03-12 alex #include "imp.h"
20 c23199d9 2002-02-27 alex #include <assert.h>
21 c23199d9 2002-02-27 alex #include <stdio.h>
22 c23199d9 2002-02-27 alex #include <stdlib.h>
23 c23199d9 2002-02-27 alex #include <string.h>
24 57c7e236 2004-01-17 alex #include <strings.h>
25 c23199d9 2002-02-27 alex
26 c23199d9 2002-02-27 alex #include "ngircd.h"
27 c2f60abe 2002-05-27 alex #include "resolve.h"
28 b8d7dcec 2002-12-30 alex #include "conn-func.h"
29 a2544e49 2002-12-30 alex #include "conf.h"
30 c2f60abe 2002-05-27 alex #include "client.h"
31 c2f60abe 2002-05-27 alex #include "channel.h"
32 c23199d9 2002-02-27 alex #include "log.h"
33 c23199d9 2002-02-27 alex #include "messages.h"
34 c2f60abe 2002-05-27 alex #include "parse.h"
35 ff988331 2003-01-08 alex #include "irc.h"
36 0c471b84 2002-11-30 alex #include "irc-info.h"
37 c2f60abe 2002-05-27 alex #include "irc-write.h"
38 05e2c0f0 2003-12-04 alex #include "cvs-version.h"
39 c23199d9 2002-02-27 alex
40 ca33cbda 2002-03-12 alex #include "exp.h"
41 c23199d9 2002-02-27 alex #include "irc-login.h"
42 c23199d9 2002-02-27 alex
43 c23199d9 2002-02-27 alex
44 c2f60abe 2002-05-27 alex LOCAL BOOLEAN Hello_User PARAMS(( CLIENT *Client ));
45 c2f60abe 2002-05-27 alex LOCAL VOID Kill_Nick PARAMS(( CHAR *Nick, CHAR *Reason ));
46 c23199d9 2002-02-27 alex
47 c23199d9 2002-02-27 alex
48 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
49 c2f60abe 2002-05-27 alex IRC_PASS( CLIENT *Client, REQUEST *Req )
50 c23199d9 2002-02-27 alex {
51 c23199d9 2002-02-27 alex assert( Client != NULL );
52 c23199d9 2002-02-27 alex assert( Req != NULL );
53 c23199d9 2002-02-27 alex
54 c23199d9 2002-02-27 alex /* Fehler liefern, wenn kein lokaler Client */
55 c23199d9 2002-02-27 alex if( Client_Conn( Client ) <= NONE ) return IRC_WriteStrClient( Client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( Client ), Req->command );
56 c23199d9 2002-02-27 alex
57 c23199d9 2002-02-27 alex if(( Client_Type( Client ) == CLIENT_UNKNOWN ) && ( Req->argc == 1))
58 c23199d9 2002-02-27 alex {
59 c23199d9 2002-02-27 alex /* noch nicht registrierte unbekannte Verbindung */
60 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got PASS command ...", Client_Conn( Client ));
61 c23199d9 2002-02-27 alex
62 c23199d9 2002-02-27 alex /* Passwort speichern */
63 c23199d9 2002-02-27 alex Client_SetPassword( Client, Req->argv[0] );
64 c23199d9 2002-02-27 alex
65 c23199d9 2002-02-27 alex Client_SetType( Client, CLIENT_GOTPASS );
66 c23199d9 2002-02-27 alex return CONNECTED;
67 c23199d9 2002-02-27 alex }
68 c23199d9 2002-02-27 alex else if((( Client_Type( Client ) == CLIENT_UNKNOWN ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER )) && (( Req->argc == 3 ) || ( Req->argc == 4 )))
69 c23199d9 2002-02-27 alex {
70 65f3adca 2002-11-26 alex CHAR c2, c4, *type, *impl, *serverver, *flags, *ptr, *ircflags;
71 c67bb2ac 2002-09-02 alex INT protohigh, protolow;
72 c67bb2ac 2002-09-02 alex
73 c23199d9 2002-02-27 alex /* noch nicht registrierte Server-Verbindung */
74 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got PASS command (new server link) ...", Client_Conn( Client ));
75 c23199d9 2002-02-27 alex
76 c23199d9 2002-02-27 alex /* Passwort speichern */
77 c23199d9 2002-02-27 alex Client_SetPassword( Client, Req->argv[0] );
78 c23199d9 2002-02-27 alex
79 ad1cbe34 2002-09-03 alex /* Protokollversion ermitteln */
80 ad1cbe34 2002-09-03 alex if( strlen( Req->argv[1] ) >= 4 )
81 c67bb2ac 2002-09-02 alex {
82 55ee4c95 2002-09-03 alex c2 = Req->argv[1][2];
83 55ee4c95 2002-09-03 alex c4 = Req->argv[1][4];
84 55ee4c95 2002-09-03 alex
85 ad1cbe34 2002-09-03 alex Req->argv[1][4] = '\0';
86 c67bb2ac 2002-09-02 alex protolow = atoi( &Req->argv[1][2] );
87 c67bb2ac 2002-09-02 alex Req->argv[1][2] = '\0';
88 c67bb2ac 2002-09-02 alex protohigh = atoi( Req->argv[1] );
89 ad1cbe34 2002-09-03 alex
90 55ee4c95 2002-09-03 alex Req->argv[1][2] = c2;
91 55ee4c95 2002-09-03 alex Req->argv[1][4] = c4;
92 ad1cbe34 2002-09-03 alex }
93 ad1cbe34 2002-09-03 alex else protohigh = protolow = 0;
94 c67bb2ac 2002-09-02 alex
95 ad1cbe34 2002-09-03 alex /* Protokoll-Typ */
96 ad1cbe34 2002-09-03 alex if( strlen( Req->argv[1] ) > 4 ) type = &Req->argv[1][4];
97 ad1cbe34 2002-09-03 alex else type = NULL;
98 65f3adca 2002-11-26 alex
99 65f3adca 2002-11-26 alex /* IRC-Flags (nach RFC 2813) */
100 65f3adca 2002-11-26 alex if( Req->argc >= 4 ) ircflags = Req->argv[3];
101 65f3adca 2002-11-26 alex else ircflags = "";
102 ad1cbe34 2002-09-03 alex
103 c67bb2ac 2002-09-02 alex /* Implementation, Version und ngIRCd-Flags */
104 c67bb2ac 2002-09-02 alex impl = Req->argv[2];
105 c67bb2ac 2002-09-02 alex ptr = strchr( impl, '|' );
106 c67bb2ac 2002-09-02 alex if( ptr ) *ptr = '\0';
107 c67bb2ac 2002-09-02 alex
108 ad1cbe34 2002-09-03 alex if( type && ( strcmp( type, PROTOIRCPLUS ) == 0 ))
109 c67bb2ac 2002-09-02 alex {
110 ad1cbe34 2002-09-03 alex /* auf der anderen Seite laeuft ein Server, der
111 ad1cbe34 2002-09-03 alex * ebenfalls das IRC+-Protokoll versteht */
112 c67bb2ac 2002-09-02 alex serverver = ptr + 1;
113 c67bb2ac 2002-09-02 alex flags = strchr( serverver, ':' );
114 c67bb2ac 2002-09-02 alex if( flags )
115 c67bb2ac 2002-09-02 alex {
116 c67bb2ac 2002-09-02 alex *flags = '\0';
117 c67bb2ac 2002-09-02 alex flags++;
118 c67bb2ac 2002-09-02 alex }
119 c67bb2ac 2002-09-02 alex else flags = "";
120 9f122037 2002-12-03 alex Log( LOG_INFO, "Peer announces itself as %s-%s using protocol %d.%d/IRC+ (flags: \"%s\").", impl, serverver, protohigh, protolow, flags );
121 c67bb2ac 2002-09-02 alex }
122 c67bb2ac 2002-09-02 alex else
123 c67bb2ac 2002-09-02 alex {
124 65f3adca 2002-11-26 alex /* auf der anderen Seite laeuft ein Server, der
125 65f3adca 2002-11-26 alex * nur das Originalprotokoll unterstuetzt */
126 65f3adca 2002-11-26 alex serverver = "";
127 65f3adca 2002-11-26 alex if( strchr( ircflags, 'Z' )) flags = "Z";
128 65f3adca 2002-11-26 alex else flags = "";
129 9f122037 2002-12-03 alex Log( LOG_INFO, "Peer announces itself as \"%s\" using protocol %d.%d (flags: \"%s\").", impl, protohigh, protolow, flags );
130 c67bb2ac 2002-09-02 alex }
131 c67bb2ac 2002-09-02 alex
132 c23199d9 2002-02-27 alex Client_SetType( Client, CLIENT_GOTPASSSERVER );
133 5aa9c8f4 2002-09-03 alex Client_SetFlags( Client, flags );
134 5aa9c8f4 2002-09-03 alex
135 c23199d9 2002-02-27 alex return CONNECTED;
136 c23199d9 2002-02-27 alex }
137 c23199d9 2002-02-27 alex else if(( Client_Type( Client ) == CLIENT_UNKNOWN ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER ))
138 c23199d9 2002-02-27 alex {
139 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
140 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
141 c23199d9 2002-02-27 alex }
142 c23199d9 2002-02-27 alex else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
143 c23199d9 2002-02-27 alex } /* IRC_PASS */
144 c23199d9 2002-02-27 alex
145 c23199d9 2002-02-27 alex
146 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
147 c2f60abe 2002-05-27 alex IRC_NICK( CLIENT *Client, REQUEST *Req )
148 c23199d9 2002-02-27 alex {
149 c23199d9 2002-02-27 alex CLIENT *intr_c, *target, *c;
150 c23199d9 2002-02-27 alex CHAR *modes;
151 c23199d9 2002-02-27 alex
152 c23199d9 2002-02-27 alex assert( Client != NULL );
153 c23199d9 2002-02-27 alex assert( Req != NULL );
154 c23199d9 2002-02-27 alex
155 c23199d9 2002-02-27 alex /* Zumindest BitchX sendet NICK-USER in der falschen Reihenfolge. */
156 c23199d9 2002-02-27 alex #ifndef STRICT_RFC
157 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_UNKNOWN || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTUSER || Client_Type( Client ) == CLIENT_USER || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
158 c23199d9 2002-02-27 alex #else
159 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_UNKNOWN || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_USER || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
160 c23199d9 2002-02-27 alex #endif
161 c23199d9 2002-02-27 alex {
162 c23199d9 2002-02-27 alex /* User-Registrierung bzw. Nick-Aenderung */
163 c23199d9 2002-02-27 alex
164 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
165 c23199d9 2002-02-27 alex if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
166 c23199d9 2002-02-27 alex
167 c23199d9 2002-02-27 alex /* "Ziel-Client" ermitteln */
168 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_SERVER )
169 c23199d9 2002-02-27 alex {
170 bc4ed226 2002-03-25 alex target = Client_Search( Req->prefix );
171 c23199d9 2002-02-27 alex if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
172 c23199d9 2002-02-27 alex }
173 c23199d9 2002-02-27 alex else
174 c23199d9 2002-02-27 alex {
175 c23199d9 2002-02-27 alex /* Ist der Client "restricted"? */
176 c23199d9 2002-02-27 alex if( Client_HasMode( Client, 'r' )) return IRC_WriteStrClient( Client, ERR_RESTRICTED_MSG, Client_ID( Client ));
177 c23199d9 2002-02-27 alex target = Client;
178 c23199d9 2002-02-27 alex }
179 c23199d9 2002-02-27 alex
180 c23199d9 2002-02-27 alex #ifndef STRICT_RFC
181 c23199d9 2002-02-27 alex /* Wenn der Client zu seinem eigenen Nick wechseln will, so machen
182 c23199d9 2002-02-27 alex * wir nichts. So macht es das Original und mind. Snak hat probleme,
183 c23199d9 2002-02-27 alex * wenn wir es nicht so machen. Ob es so okay ist? Hm ... */
184 c23199d9 2002-02-27 alex if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 ) return CONNECTED;
185 c23199d9 2002-02-27 alex #endif
186 5b4e9152 2002-04-08 alex
187 c23199d9 2002-02-27 alex /* pruefen, ob Nick bereits vergeben. Speziallfall: der Client
188 c23199d9 2002-02-27 alex * will nur die Gross- und Kleinschreibung aendern. Das darf
189 c23199d9 2002-02-27 alex * er natuerlich machen :-) */
190 c23199d9 2002-02-27 alex if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
191 c23199d9 2002-02-27 alex {
192 c23199d9 2002-02-27 alex if( ! Client_CheckNick( target, Req->argv[0] )) return CONNECTED;
193 c23199d9 2002-02-27 alex }
194 c23199d9 2002-02-27 alex
195 c23199d9 2002-02-27 alex if(( Client_Type( target ) != CLIENT_USER ) && ( Client_Type( target ) != CLIENT_SERVER ))
196 c23199d9 2002-02-27 alex {
197 c23199d9 2002-02-27 alex /* Neuer Client */
198 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got valid NICK command ...", Client_Conn( Client ));
199 c23199d9 2002-02-27 alex
200 c23199d9 2002-02-27 alex /* Client-Nick registrieren */
201 c23199d9 2002-02-27 alex Client_SetID( target, Req->argv[0] );
202 c23199d9 2002-02-27 alex
203 c23199d9 2002-02-27 alex /* schon ein USER da? Dann registrieren! */
204 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTUSER ) return Hello_User( Client );
205 c23199d9 2002-02-27 alex else Client_SetType( Client, CLIENT_GOTNICK );
206 c23199d9 2002-02-27 alex }
207 c23199d9 2002-02-27 alex else
208 c23199d9 2002-02-27 alex {
209 c23199d9 2002-02-27 alex /* Nick-Aenderung */
210 5b4e9152 2002-04-08 alex if( Client_Conn( target ) > NONE )
211 5b4e9152 2002-04-08 alex {
212 5b4e9152 2002-04-08 alex /* lokaler Client */
213 5b4e9152 2002-04-08 alex Log( LOG_INFO, "User \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".", Client_Mask( target ), Client_Conn( target ), Client_ID( target ), Req->argv[0] );
214 5b4e9152 2002-04-08 alex }
215 5b4e9152 2002-04-08 alex else
216 5b4e9152 2002-04-08 alex {
217 5b4e9152 2002-04-08 alex /* Remote-Client */
218 5b4e9152 2002-04-08 alex Log( LOG_DEBUG, "User \"%s\" changed nick: \"%s\" -> \"%s\".", Client_Mask( target ), Client_ID( target ), Req->argv[0] );
219 5b4e9152 2002-04-08 alex }
220 c23199d9 2002-02-27 alex
221 0370c484 2002-03-02 alex /* alle betroffenen User und Server ueber Nick-Aenderung informieren */
222 0370c484 2002-03-02 alex if( Client_Type( Client ) == CLIENT_USER ) IRC_WriteStrClientPrefix( Client, Client, "NICK :%s", Req->argv[0] );
223 0370c484 2002-03-02 alex IRC_WriteStrServersPrefix( Client, target, "NICK :%s", Req->argv[0] );
224 0370c484 2002-03-02 alex IRC_WriteStrRelatedPrefix( target, target, FALSE, "NICK :%s", Req->argv[0] );
225 0370c484 2002-03-02 alex
226 c23199d9 2002-02-27 alex /* neuen Client-Nick speichern */
227 c23199d9 2002-02-27 alex Client_SetID( target, Req->argv[0] );
228 7b6e2662 2003-11-05 alex IRC_SetPenalty( target, 2 );
229 c23199d9 2002-02-27 alex }
230 c23199d9 2002-02-27 alex
231 c23199d9 2002-02-27 alex return CONNECTED;
232 c23199d9 2002-02-27 alex }
233 c23199d9 2002-02-27 alex else if( Client_Type( Client ) == CLIENT_SERVER )
234 c23199d9 2002-02-27 alex {
235 c23199d9 2002-02-27 alex /* Server fuehrt neuen Client ein */
236 c23199d9 2002-02-27 alex
237 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
238 c23199d9 2002-02-27 alex if( Req->argc != 7 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
239 c23199d9 2002-02-27 alex
240 c23199d9 2002-02-27 alex /* Nick ueberpruefen */
241 bc4ed226 2002-03-25 alex c = Client_Search( Req->argv[0] );
242 c23199d9 2002-02-27 alex if( c )
243 c23199d9 2002-02-27 alex {
244 c23199d9 2002-02-27 alex /* Der neue Nick ist auf diesem Server bereits registriert:
245 c23199d9 2002-02-27 alex * sowohl der neue, als auch der alte Client muessen nun
246 c23199d9 2002-02-27 alex * disconnectiert werden. */
247 c23199d9 2002-02-27 alex Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
248 c23199d9 2002-02-27 alex Kill_Nick( Req->argv[0], "Nick collision" );
249 c23199d9 2002-02-27 alex return CONNECTED;
250 c23199d9 2002-02-27 alex }
251 c23199d9 2002-02-27 alex
252 c23199d9 2002-02-27 alex /* Server, zu dem der Client connectiert ist, suchen */
253 c23199d9 2002-02-27 alex intr_c = Client_GetFromToken( Client, atoi( Req->argv[4] ));
254 c23199d9 2002-02-27 alex if( ! intr_c )
255 c23199d9 2002-02-27 alex {
256 c23199d9 2002-02-27 alex Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
257 c23199d9 2002-02-27 alex Kill_Nick( Req->argv[0], "Unknown server" );
258 c23199d9 2002-02-27 alex return CONNECTED;
259 c23199d9 2002-02-27 alex }
260 c23199d9 2002-02-27 alex
261 c23199d9 2002-02-27 alex /* Neue Client-Struktur anlegen */
262 c23199d9 2002-02-27 alex 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 );
263 c23199d9 2002-02-27 alex if( ! c )
264 c23199d9 2002-02-27 alex {
265 c23199d9 2002-02-27 alex /* Eine neue Client-Struktur konnte nicht angelegt werden.
266 c23199d9 2002-02-27 alex * Der Client muss disconnectiert werden, damit der Netz-
267 c23199d9 2002-02-27 alex * status konsistent bleibt. */
268 c23199d9 2002-02-27 alex Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
269 c23199d9 2002-02-27 alex Kill_Nick( Req->argv[0], "Server error" );
270 c23199d9 2002-02-27 alex return CONNECTED;
271 c23199d9 2002-02-27 alex }
272 c23199d9 2002-02-27 alex
273 c23199d9 2002-02-27 alex modes = Client_Modes( c );
274 c23199d9 2002-02-27 alex 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": "" );
275 c23199d9 2002-02-27 alex 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": "" );
276 c23199d9 2002-02-27 alex
277 c23199d9 2002-02-27 alex /* Andere Server, ausser dem Introducer, informieren */
278 c23199d9 2002-02-27 alex 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] );
279 c23199d9 2002-02-27 alex
280 c23199d9 2002-02-27 alex return CONNECTED;
281 c23199d9 2002-02-27 alex }
282 c23199d9 2002-02-27 alex else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
283 c23199d9 2002-02-27 alex } /* IRC_NICK */
284 c23199d9 2002-02-27 alex
285 c23199d9 2002-02-27 alex
286 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
287 c2f60abe 2002-05-27 alex IRC_USER( CLIENT *Client, REQUEST *Req )
288 c23199d9 2002-02-27 alex {
289 b79b315d 2003-12-27 alex #ifdef IDENTAUTH
290 b79b315d 2003-12-27 alex CHAR *ptr;
291 b79b315d 2003-12-27 alex #endif
292 b79b315d 2003-12-27 alex
293 c23199d9 2002-02-27 alex assert( Client != NULL );
294 c23199d9 2002-02-27 alex assert( Req != NULL );
295 c23199d9 2002-02-27 alex
296 c23199d9 2002-02-27 alex #ifndef STRICT_RFC
297 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_UNKNOWN )
298 c23199d9 2002-02-27 alex #else
299 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS )
300 c23199d9 2002-02-27 alex #endif
301 c23199d9 2002-02-27 alex {
302 6667bb6b 2004-02-04 alex /* Wrong number of parameters? */
303 c23199d9 2002-02-27 alex if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
304 c23199d9 2002-02-27 alex
305 6667bb6b 2004-02-04 alex /* User name */
306 b79b315d 2003-12-27 alex #ifdef IDENTAUTH
307 b79b315d 2003-12-27 alex ptr = Client_User( Client );
308 6667bb6b 2004-02-04 alex if( ! ptr || ! *ptr || *ptr == '~' ) Client_SetUser( Client, Req->argv[0], FALSE );
309 6667bb6b 2004-02-04 alex #else
310 c23199d9 2002-02-27 alex Client_SetUser( Client, Req->argv[0], FALSE );
311 6667bb6b 2004-02-04 alex #endif
312 c23199d9 2002-02-27 alex
313 6667bb6b 2004-02-04 alex /* "Real name" or user info text: Don't set it to the empty string, the original ircd
314 6667bb6b 2004-02-04 alex * can't deal with such "real names" (e. g. "USER user * * :") ... */
315 6667bb6b 2004-02-04 alex if( *Req->argv[3] ) Client_SetInfo( Client, Req->argv[3] );
316 6667bb6b 2004-02-04 alex else Client_SetInfo( Client, "-" );
317 6667bb6b 2004-02-04 alex
318 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got valid USER command ...", Client_Conn( Client ));
319 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTNICK ) return Hello_User( Client );
320 c23199d9 2002-02-27 alex else Client_SetType( Client, CLIENT_GOTUSER );
321 c23199d9 2002-02-27 alex return CONNECTED;
322 c23199d9 2002-02-27 alex }
323 c23199d9 2002-02-27 alex else if( Client_Type( Client ) == CLIENT_USER || Client_Type( Client ) == CLIENT_SERVER || Client_Type( Client ) == CLIENT_SERVICE )
324 c23199d9 2002-02-27 alex {
325 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
326 c23199d9 2002-02-27 alex }
327 c23199d9 2002-02-27 alex else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
328 c23199d9 2002-02-27 alex } /* IRC_USER */
329 c23199d9 2002-02-27 alex
330 c23199d9 2002-02-27 alex
331 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
332 c2f60abe 2002-05-27 alex IRC_QUIT( CLIENT *Client, REQUEST *Req )
333 c23199d9 2002-02-27 alex {
334 c23199d9 2002-02-27 alex CLIENT *target;
335 c23199d9 2002-02-27 alex
336 c23199d9 2002-02-27 alex assert( Client != NULL );
337 c23199d9 2002-02-27 alex assert( Req != NULL );
338 c23199d9 2002-02-27 alex
339 7f795915 2002-04-14 alex if ( Client_Type( Client ) == CLIENT_SERVER )
340 c23199d9 2002-02-27 alex {
341 c23199d9 2002-02-27 alex /* Server */
342 c23199d9 2002-02-27 alex
343 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
344 c23199d9 2002-02-27 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
345 c23199d9 2002-02-27 alex
346 c23199d9 2002-02-27 alex target = Client_Search( Req->prefix );
347 c23199d9 2002-02-27 alex if( ! target )
348 c23199d9 2002-02-27 alex {
349 9fc7e66f 2002-03-11 alex /* Den Client kennen wir nicht (mehr), also nichts zu tun. */
350 f7a0ff1f 2002-03-11 alex Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
351 c23199d9 2002-02-27 alex return CONNECTED;
352 c23199d9 2002-02-27 alex }
353 c23199d9 2002-02-27 alex
354 50ec7a56 2002-03-11 alex if( Req->argc == 0 ) Client_Destroy( target, "Got QUIT command.", NULL, TRUE );
355 50ec7a56 2002-03-11 alex else Client_Destroy( target, "Got QUIT command.", Req->argv[0], TRUE );
356 c23199d9 2002-02-27 alex
357 c23199d9 2002-02-27 alex return CONNECTED;
358 c23199d9 2002-02-27 alex }
359 7f795915 2002-04-14 alex else
360 7f795915 2002-04-14 alex {
361 7f795915 2002-04-14 alex /* User, Service, oder noch nicht registriert */
362 7f795915 2002-04-14 alex
363 7f795915 2002-04-14 alex /* Falsche Anzahl Parameter? */
364 7f795915 2002-04-14 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
365 7f795915 2002-04-14 alex
366 7f795915 2002-04-14 alex if( Req->argc == 0 ) Conn_Close( Client_Conn( Client ), "Got QUIT command.", NULL, TRUE );
367 7f795915 2002-04-14 alex else Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argv[0], TRUE );
368 7f795915 2002-04-14 alex
369 7f795915 2002-04-14 alex return DISCONNECTED;
370 7f795915 2002-04-14 alex }
371 c23199d9 2002-02-27 alex } /* IRC_QUIT */
372 c23199d9 2002-02-27 alex
373 c23199d9 2002-02-27 alex
374 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
375 c2f60abe 2002-05-27 alex IRC_PING( CLIENT *Client, REQUEST *Req )
376 c23199d9 2002-02-27 alex {
377 c23199d9 2002-02-27 alex CLIENT *target, *from;
378 c23199d9 2002-02-27 alex
379 c23199d9 2002-02-27 alex assert( Client != NULL );
380 c23199d9 2002-02-27 alex assert( Req != NULL );
381 c23199d9 2002-02-27 alex
382 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
383 c23199d9 2002-02-27 alex if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
384 5fa05dce 2002-03-10 alex #ifdef STRICT_RFC
385 c23199d9 2002-02-27 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
386 5fa05dce 2002-03-10 alex #endif
387 c23199d9 2002-02-27 alex
388 5fa05dce 2002-03-10 alex if( Req->argc > 1 )
389 c23199d9 2002-02-27 alex {
390 c23199d9 2002-02-27 alex /* es wurde ein Ziel-Client angegeben */
391 bc4ed226 2002-03-25 alex target = Client_Search( Req->argv[1] );
392 ae6a7e7c 2003-01-01 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
393 c23199d9 2002-02-27 alex if( target != Client_ThisServer( ))
394 c23199d9 2002-02-27 alex {
395 c23199d9 2002-02-27 alex /* ok, forwarden */
396 bc4ed226 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
397 c23199d9 2002-02-27 alex else from = Client;
398 c23199d9 2002-02-27 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
399 c23199d9 2002-02-27 alex return IRC_WriteStrClientPrefix( target, from, "PING %s :%s", Client_ID( from ), Req->argv[1] );
400 c23199d9 2002-02-27 alex }
401 c23199d9 2002-02-27 alex }
402 c23199d9 2002-02-27 alex
403 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got PING, sending PONG ...", Client_Conn( Client ));
404 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, "PONG %s :%s", Client_ID( Client_ThisServer( )), Client_ID( Client ));
405 c23199d9 2002-02-27 alex } /* IRC_PING */
406 c23199d9 2002-02-27 alex
407 c23199d9 2002-02-27 alex
408 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
409 c2f60abe 2002-05-27 alex IRC_PONG( CLIENT *Client, REQUEST *Req )
410 c23199d9 2002-02-27 alex {
411 c23199d9 2002-02-27 alex CLIENT *target, *from;
412 c23199d9 2002-02-27 alex
413 c23199d9 2002-02-27 alex assert( Client != NULL );
414 c23199d9 2002-02-27 alex assert( Req != NULL );
415 c23199d9 2002-02-27 alex
416 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
417 c23199d9 2002-02-27 alex if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
418 c23199d9 2002-02-27 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
419 c23199d9 2002-02-27 alex
420 c23199d9 2002-02-27 alex /* forwarden? */
421 c23199d9 2002-02-27 alex if( Req->argc == 2 )
422 c23199d9 2002-02-27 alex {
423 bc4ed226 2002-03-25 alex target = Client_Search( Req->argv[1] );
424 ae6a7e7c 2003-01-01 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
425 c23199d9 2002-02-27 alex if( target != Client_ThisServer( ))
426 c23199d9 2002-02-27 alex {
427 c23199d9 2002-02-27 alex /* ok, forwarden */
428 bc4ed226 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
429 c23199d9 2002-02-27 alex else from = Client;
430 c23199d9 2002-02-27 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
431 c23199d9 2002-02-27 alex return IRC_WriteStrClientPrefix( target, from, "PONG %s :%s", Client_ID( from ), Req->argv[1] );
432 c23199d9 2002-02-27 alex }
433 c23199d9 2002-02-27 alex }
434 c23199d9 2002-02-27 alex
435 c23199d9 2002-02-27 alex /* Der Connection-Timestamp wurde schon beim Lesen aus dem Socket
436 bcc51385 2002-03-26 alex * aktualisiert, daher muss das hier nicht mehr gemacht werden. */
437 c23199d9 2002-02-27 alex
438 c23199d9 2002-02-27 alex if( Client_Conn( Client ) > NONE ) Log( LOG_DEBUG, "Connection %d: received PONG. Lag: %ld seconds.", Client_Conn( Client ), time( NULL ) - Conn_LastPing( Client_Conn( Client )));
439 c23199d9 2002-02-27 alex else Log( LOG_DEBUG, "Connection %d: received PONG.", Client_Conn( Client ));
440 c23199d9 2002-02-27 alex
441 c23199d9 2002-02-27 alex return CONNECTED;
442 c23199d9 2002-02-27 alex } /* IRC_PONG */
443 c23199d9 2002-02-27 alex
444 c23199d9 2002-02-27 alex
445 c2f60abe 2002-05-27 alex LOCAL BOOLEAN
446 c2f60abe 2002-05-27 alex Hello_User( CLIENT *Client )
447 c23199d9 2002-02-27 alex {
448 05e2c0f0 2003-12-04 alex #ifdef CVSDATE
449 05e2c0f0 2003-12-04 alex CHAR ver[12], vertxt[30];
450 05e2c0f0 2003-12-04 alex #endif
451 05e2c0f0 2003-12-04 alex
452 c23199d9 2002-02-27 alex assert( Client != NULL );
453 c23199d9 2002-02-27 alex
454 05e2c0f0 2003-12-04 alex /* Check password ... */
455 c23199d9 2002-02-27 alex if( strcmp( Client_Password( Client ), Conf_ServerPwd ) != 0 )
456 c23199d9 2002-02-27 alex {
457 05e2c0f0 2003-12-04 alex /* Bad password! */
458 c23199d9 2002-02-27 alex Log( LOG_ERR, "User \"%s\" rejected (connection %d): Bad password!", Client_Mask( Client ), Client_Conn( Client ));
459 c23199d9 2002-02-27 alex Conn_Close( Client_Conn( Client ), NULL, "Bad password", TRUE );
460 c23199d9 2002-02-27 alex return DISCONNECTED;
461 c23199d9 2002-02-27 alex }
462 c23199d9 2002-02-27 alex
463 c23199d9 2002-02-27 alex Log( LOG_NOTICE, "User \"%s\" registered (connection %d).", Client_Mask( Client ), Client_Conn( Client ));
464 c23199d9 2002-02-27 alex
465 05e2c0f0 2003-12-04 alex /* Inform other servers */
466 c23199d9 2002-02-27 alex IRC_WriteStrServers( NULL, "NICK %s 1 %s %s 1 +%s :%s", Client_ID( Client ), Client_User( Client ), Client_Hostname( Client ), Client_Modes( Client ), Client_Info( Client ));
467 c23199d9 2002-02-27 alex
468 05e2c0f0 2003-12-04 alex /* Welcome :-) */
469 c23199d9 2002-02-27 alex if( ! IRC_WriteStrClient( Client, RPL_WELCOME_MSG, Client_ID( Client ), Client_Mask( Client ))) return FALSE;
470 05e2c0f0 2003-12-04 alex
471 05e2c0f0 2003-12-04 alex /* Version and system type */
472 05e2c0f0 2003-12-04 alex #ifdef CVSDATE
473 05e2c0f0 2003-12-04 alex strlcpy( ver, CVSDATE, sizeof( ver ));
474 05e2c0f0 2003-12-04 alex strncpy( ver + 4, ver + 5, 2 );
475 05e2c0f0 2003-12-04 alex strncpy( ver + 6, ver + 8, 3 );
476 05e2c0f0 2003-12-04 alex snprintf( vertxt, sizeof( vertxt ), "%s(%s)", PACKAGE_VERSION, ver );
477 05e2c0f0 2003-12-04 alex if( ! IRC_WriteStrClient( Client, RPL_YOURHOST_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )), vertxt, TARGET_CPU, TARGET_VENDOR, TARGET_OS )) return FALSE;
478 05e2c0f0 2003-12-04 alex #else
479 62796722 2003-03-31 alex if( ! IRC_WriteStrClient( Client, RPL_YOURHOST_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )), PACKAGE_VERSION, TARGET_CPU, TARGET_VENDOR, TARGET_OS )) return FALSE;
480 05e2c0f0 2003-12-04 alex #endif
481 05e2c0f0 2003-12-04 alex
482 c23199d9 2002-02-27 alex if( ! IRC_WriteStrClient( Client, RPL_CREATED_MSG, Client_ID( Client ), NGIRCd_StartStr )) return FALSE;
483 05e2c0f0 2003-12-04 alex #ifdef CVSDATE
484 05e2c0f0 2003-12-04 alex if( ! IRC_WriteStrClient( Client, RPL_MYINFO_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )), vertxt, USERMODES, CHANMODES )) return FALSE;
485 05e2c0f0 2003-12-04 alex #else
486 62796722 2003-03-31 alex if( ! IRC_WriteStrClient( Client, RPL_MYINFO_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )), PACKAGE_VERSION, USERMODES, CHANMODES )) return FALSE;
487 05e2c0f0 2003-12-04 alex #endif
488 c23199d9 2002-02-27 alex
489 a3f59f1a 2002-12-22 alex /* Features */
490 c428ac75 2003-01-02 alex if( ! IRC_WriteStrClient( Client, RPL_ISUPPORT_MSG, Client_ID( Client ), CLIENT_NICK_LEN - 1, CHANNEL_TOPIC_LEN - 1, CLIENT_AWAY_LEN - 1, Conf_MaxJoins )) return DISCONNECTED;
491 a3f59f1a 2002-12-22 alex
492 c23199d9 2002-02-27 alex Client_SetType( Client, CLIENT_USER );
493 c23199d9 2002-02-27 alex
494 c23199d9 2002-02-27 alex if( ! IRC_Send_LUSERS( Client )) return DISCONNECTED;
495 c23199d9 2002-02-27 alex if( ! IRC_Show_MOTD( Client )) return DISCONNECTED;
496 c23199d9 2002-02-27 alex
497 7b6e2662 2003-11-05 alex /* Suspend the client for a second ... */
498 7b6e2662 2003-11-05 alex IRC_SetPenalty( Client, 1 );
499 7b6e2662 2003-11-05 alex
500 c23199d9 2002-02-27 alex return CONNECTED;
501 c23199d9 2002-02-27 alex } /* Hello_User */
502 c23199d9 2002-02-27 alex
503 c23199d9 2002-02-27 alex
504 c2f60abe 2002-05-27 alex LOCAL VOID
505 c2f60abe 2002-05-27 alex Kill_Nick( CHAR *Nick, CHAR *Reason )
506 c23199d9 2002-02-27 alex {
507 ff988331 2003-01-08 alex REQUEST r;
508 c23199d9 2002-02-27 alex
509 c23199d9 2002-02-27 alex assert( Nick != NULL );
510 c23199d9 2002-02-27 alex assert( Reason != NULL );
511 c23199d9 2002-02-27 alex
512 cb76d96e 2004-03-11 alex r.prefix = (CHAR *)Client_ThisServer( );
513 ff988331 2003-01-08 alex r.argv[0] = Nick;
514 ff988331 2003-01-08 alex r.argv[1] = Reason;
515 ff988331 2003-01-08 alex r.argc = 2;
516 c23199d9 2002-02-27 alex
517 ff988331 2003-01-08 alex Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s", Nick, Reason );
518 ff988331 2003-01-08 alex IRC_KILL( Client_ThisServer( ), &r );
519 c23199d9 2002-02-27 alex } /* Kill_Nick */
520 c23199d9 2002-02-27 alex
521 c23199d9 2002-02-27 alex
522 c23199d9 2002-02-27 alex /* -eof- */