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 cac9f279 2005-06-04 fw static char UNUSED id[] = "$Id: irc-login.c,v 1.44 2005/06/04 12:32:09 fw 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 8adff592 2005-03-19 fw LOCAL bool Hello_User PARAMS(( CLIENT *Client ));
45 8adff592 2005-03-19 fw LOCAL void Kill_Nick PARAMS(( char *Nick, char *Reason ));
46 c23199d9 2002-02-27 alex
47 c23199d9 2002-02-27 alex
48 8adff592 2005-03-19 fw GLOBAL bool
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 8adff592 2005-03-19 fw char c2, c4, *type, *impl, *serverver, *flags, *ptr, *ircflags;
71 8adff592 2005-03-19 fw 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 95f8b963 2005-05-17 alex /**
147 95f8b963 2005-05-17 alex * IRC "NICK" command.
148 95f8b963 2005-05-17 alex * This function implements the IRC command "NICK" which is used to register
149 95f8b963 2005-05-17 alex * with the server, to change already registered nicknames and to introduce
150 95f8b963 2005-05-17 alex * new users which are connected to other servers.
151 95f8b963 2005-05-17 alex */
152 8adff592 2005-03-19 fw GLOBAL bool
153 c2f60abe 2002-05-27 alex IRC_NICK( CLIENT *Client, REQUEST *Req )
154 c23199d9 2002-02-27 alex {
155 c23199d9 2002-02-27 alex CLIENT *intr_c, *target, *c;
156 8adff592 2005-03-19 fw char *modes;
157 c23199d9 2002-02-27 alex
158 c23199d9 2002-02-27 alex assert( Client != NULL );
159 c23199d9 2002-02-27 alex assert( Req != NULL );
160 c23199d9 2002-02-27 alex
161 c23199d9 2002-02-27 alex #ifndef STRICT_RFC
162 95f8b963 2005-05-17 alex /* Some IRC clients, for example BitchX, send the NICK and USER
163 95f8b963 2005-05-17 alex * commands in the wrong order ... */
164 95f8b963 2005-05-17 alex if( Client_Type( Client ) == CLIENT_UNKNOWN
165 95f8b963 2005-05-17 alex || Client_Type( Client ) == CLIENT_GOTPASS
166 95f8b963 2005-05-17 alex || Client_Type( Client ) == CLIENT_GOTNICK
167 95f8b963 2005-05-17 alex || Client_Type( Client ) == CLIENT_GOTUSER
168 95f8b963 2005-05-17 alex || Client_Type( Client ) == CLIENT_USER
169 95f8b963 2005-05-17 alex || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
170 c23199d9 2002-02-27 alex #else
171 95f8b963 2005-05-17 alex if( Client_Type( Client ) == CLIENT_UNKNOWN
172 95f8b963 2005-05-17 alex || Client_Type( Client ) == CLIENT_GOTPASS
173 95f8b963 2005-05-17 alex || Client_Type( Client ) == CLIENT_GOTNICK
174 95f8b963 2005-05-17 alex || Client_Type( Client ) == CLIENT_USER
175 95f8b963 2005-05-17 alex || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
176 c23199d9 2002-02-27 alex #endif
177 c23199d9 2002-02-27 alex {
178 95f8b963 2005-05-17 alex /* User registration or change of nickname */
179 c23199d9 2002-02-27 alex
180 95f8b963 2005-05-17 alex /* Wrong number of arguments? */
181 95f8b963 2005-05-17 alex if( Req->argc != 1 )
182 95f8b963 2005-05-17 alex return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG,
183 95f8b963 2005-05-17 alex Client_ID( Client ),
184 95f8b963 2005-05-17 alex Req->command );
185 c23199d9 2002-02-27 alex
186 95f8b963 2005-05-17 alex /* Search "target" client */
187 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_SERVER )
188 c23199d9 2002-02-27 alex {
189 bc4ed226 2002-03-25 alex target = Client_Search( Req->prefix );
190 95f8b963 2005-05-17 alex if( ! target )
191 95f8b963 2005-05-17 alex return IRC_WriteStrClient( Client,
192 95f8b963 2005-05-17 alex ERR_NOSUCHNICK_MSG,
193 95f8b963 2005-05-17 alex Client_ID( Client ),
194 95f8b963 2005-05-17 alex Req->argv[0] );
195 c23199d9 2002-02-27 alex }
196 c23199d9 2002-02-27 alex else
197 c23199d9 2002-02-27 alex {
198 95f8b963 2005-05-17 alex /* Is this a restricted client? */
199 95f8b963 2005-05-17 alex if( Client_HasMode( Client, 'r' ))
200 95f8b963 2005-05-17 alex return IRC_WriteStrClient( Client,
201 95f8b963 2005-05-17 alex ERR_RESTRICTED_MSG,
202 95f8b963 2005-05-17 alex Client_ID( Client ));
203 95f8b963 2005-05-17 alex
204 c23199d9 2002-02-27 alex target = Client;
205 c23199d9 2002-02-27 alex }
206 c23199d9 2002-02-27 alex
207 c23199d9 2002-02-27 alex #ifndef STRICT_RFC
208 95f8b963 2005-05-17 alex /* If the clients tries to change to its own nickname we won't
209 95f8b963 2005-05-17 alex * do anything. This is how the original ircd behaves and some
210 95f8b963 2005-05-17 alex * clients (for example Snak) expect it to be like this.
211 95f8b963 2005-05-17 alex * But I doubt that this is "really the right thing" ... */
212 95f8b963 2005-05-17 alex if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 )
213 95f8b963 2005-05-17 alex return CONNECTED;
214 c23199d9 2002-02-27 alex #endif
215 5b4e9152 2002-04-08 alex
216 95f8b963 2005-05-17 alex /* Check that the new nickname is available. Special case:
217 95f8b963 2005-05-17 alex * the client only changes from/to upper to lower case. */
218 c23199d9 2002-02-27 alex if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
219 c23199d9 2002-02-27 alex {
220 95f8b963 2005-05-17 alex if( ! Client_CheckNick( target, Req->argv[0] ))
221 95f8b963 2005-05-17 alex return CONNECTED;
222 c23199d9 2002-02-27 alex }
223 c23199d9 2002-02-27 alex
224 95f8b963 2005-05-17 alex if(( Client_Type( target ) != CLIENT_USER )
225 95f8b963 2005-05-17 alex && ( Client_Type( target ) != CLIENT_SERVER ))
226 c23199d9 2002-02-27 alex {
227 95f8b963 2005-05-17 alex /* New client */
228 95f8b963 2005-05-17 alex Log( LOG_DEBUG, "Connection %d: got valid NICK command ...",
229 95f8b963 2005-05-17 alex Client_Conn( Client ));
230 c23199d9 2002-02-27 alex
231 95f8b963 2005-05-17 alex /* Register new nickname of this client */
232 c23199d9 2002-02-27 alex Client_SetID( target, Req->argv[0] );
233 c23199d9 2002-02-27 alex
234 95f8b963 2005-05-17 alex /* If we received a valid USER command already then
235 95f8b963 2005-05-17 alex * register the new client! */
236 95f8b963 2005-05-17 alex if( Client_Type( Client ) == CLIENT_GOTUSER )
237 95f8b963 2005-05-17 alex return Hello_User( Client );
238 95f8b963 2005-05-17 alex else
239 95f8b963 2005-05-17 alex Client_SetType( Client, CLIENT_GOTNICK );
240 c23199d9 2002-02-27 alex }
241 c23199d9 2002-02-27 alex else
242 c23199d9 2002-02-27 alex {
243 95f8b963 2005-05-17 alex /* Nickname change */
244 5b4e9152 2002-04-08 alex if( Client_Conn( target ) > NONE )
245 5b4e9152 2002-04-08 alex {
246 95f8b963 2005-05-17 alex /* Local client */
247 95f8b963 2005-05-17 alex Log( LOG_INFO,
248 95f8b963 2005-05-17 alex "User \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
249 95f8b963 2005-05-17 alex Client_Mask( target ), Client_Conn( target ),
250 95f8b963 2005-05-17 alex Client_ID( target ), Req->argv[0] );
251 5b4e9152 2002-04-08 alex }
252 5b4e9152 2002-04-08 alex else
253 5b4e9152 2002-04-08 alex {
254 95f8b963 2005-05-17 alex /* Remote client */
255 95f8b963 2005-05-17 alex Log( LOG_DEBUG,
256 95f8b963 2005-05-17 alex "User \"%s\" changed nick: \"%s\" -> \"%s\".",
257 95f8b963 2005-05-17 alex Client_Mask( target ), Client_ID( target ),
258 95f8b963 2005-05-17 alex Req->argv[0] );
259 5b4e9152 2002-04-08 alex }
260 c23199d9 2002-02-27 alex
261 95f8b963 2005-05-17 alex /* Inform all users and servers (which have to know)
262 95f8b963 2005-05-17 alex * of this nickname change */
263 95f8b963 2005-05-17 alex if( Client_Type( Client ) == CLIENT_USER )
264 95f8b963 2005-05-17 alex IRC_WriteStrClientPrefix( Client, Client,
265 95f8b963 2005-05-17 alex "NICK :%s",
266 95f8b963 2005-05-17 alex Req->argv[0] );
267 95f8b963 2005-05-17 alex IRC_WriteStrServersPrefix( Client, target,
268 95f8b963 2005-05-17 alex "NICK :%s", Req->argv[0] );
269 95f8b963 2005-05-17 alex IRC_WriteStrRelatedPrefix( target, target, false,
270 95f8b963 2005-05-17 alex "NICK :%s", Req->argv[0] );
271 95f8b963 2005-05-17 alex
272 95f8b963 2005-05-17 alex /* Register old nickname for WHOWAS queries */
273 95f8b963 2005-05-17 alex Client_RegisterWhowas( target );
274 95f8b963 2005-05-17 alex
275 95f8b963 2005-05-17 alex /* Save new nickname */
276 c23199d9 2002-02-27 alex Client_SetID( target, Req->argv[0] );
277 95f8b963 2005-05-17 alex
278 7b6e2662 2003-11-05 alex IRC_SetPenalty( target, 2 );
279 c23199d9 2002-02-27 alex }
280 c23199d9 2002-02-27 alex
281 c23199d9 2002-02-27 alex return CONNECTED;
282 c23199d9 2002-02-27 alex }
283 c23199d9 2002-02-27 alex else if( Client_Type( Client ) == CLIENT_SERVER )
284 c23199d9 2002-02-27 alex {
285 95f8b963 2005-05-17 alex /* Server introduces new client */
286 c23199d9 2002-02-27 alex
287 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
288 c23199d9 2002-02-27 alex if( Req->argc != 7 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
289 c23199d9 2002-02-27 alex
290 c23199d9 2002-02-27 alex /* Nick ueberpruefen */
291 bc4ed226 2002-03-25 alex c = Client_Search( Req->argv[0] );
292 c23199d9 2002-02-27 alex if( c )
293 c23199d9 2002-02-27 alex {
294 c23199d9 2002-02-27 alex /* Der neue Nick ist auf diesem Server bereits registriert:
295 c23199d9 2002-02-27 alex * sowohl der neue, als auch der alte Client muessen nun
296 c23199d9 2002-02-27 alex * disconnectiert werden. */
297 c23199d9 2002-02-27 alex Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
298 c23199d9 2002-02-27 alex Kill_Nick( Req->argv[0], "Nick collision" );
299 c23199d9 2002-02-27 alex return CONNECTED;
300 c23199d9 2002-02-27 alex }
301 c23199d9 2002-02-27 alex
302 c23199d9 2002-02-27 alex /* Server, zu dem der Client connectiert ist, suchen */
303 c23199d9 2002-02-27 alex intr_c = Client_GetFromToken( Client, atoi( Req->argv[4] ));
304 c23199d9 2002-02-27 alex if( ! intr_c )
305 c23199d9 2002-02-27 alex {
306 c23199d9 2002-02-27 alex Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
307 c23199d9 2002-02-27 alex Kill_Nick( Req->argv[0], "Unknown server" );
308 c23199d9 2002-02-27 alex return CONNECTED;
309 c23199d9 2002-02-27 alex }
310 c23199d9 2002-02-27 alex
311 c23199d9 2002-02-27 alex /* Neue Client-Struktur anlegen */
312 8adff592 2005-03-19 fw 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);
313 c23199d9 2002-02-27 alex if( ! c )
314 c23199d9 2002-02-27 alex {
315 c23199d9 2002-02-27 alex /* Eine neue Client-Struktur konnte nicht angelegt werden.
316 c23199d9 2002-02-27 alex * Der Client muss disconnectiert werden, damit der Netz-
317 c23199d9 2002-02-27 alex * status konsistent bleibt. */
318 c23199d9 2002-02-27 alex Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
319 c23199d9 2002-02-27 alex Kill_Nick( Req->argv[0], "Server error" );
320 c23199d9 2002-02-27 alex return CONNECTED;
321 c23199d9 2002-02-27 alex }
322 c23199d9 2002-02-27 alex
323 c23199d9 2002-02-27 alex modes = Client_Modes( c );
324 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": "" );
325 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": "" );
326 c23199d9 2002-02-27 alex
327 c23199d9 2002-02-27 alex /* Andere Server, ausser dem Introducer, informieren */
328 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] );
329 c23199d9 2002-02-27 alex
330 c23199d9 2002-02-27 alex return CONNECTED;
331 c23199d9 2002-02-27 alex }
332 c23199d9 2002-02-27 alex else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
333 c23199d9 2002-02-27 alex } /* IRC_NICK */
334 c23199d9 2002-02-27 alex
335 c23199d9 2002-02-27 alex
336 8adff592 2005-03-19 fw GLOBAL bool
337 c2f60abe 2002-05-27 alex IRC_USER( CLIENT *Client, REQUEST *Req )
338 c23199d9 2002-02-27 alex {
339 b79b315d 2003-12-27 alex #ifdef IDENTAUTH
340 8adff592 2005-03-19 fw char *ptr;
341 b79b315d 2003-12-27 alex #endif
342 b79b315d 2003-12-27 alex
343 c23199d9 2002-02-27 alex assert( Client != NULL );
344 c23199d9 2002-02-27 alex assert( Req != NULL );
345 c23199d9 2002-02-27 alex
346 c23199d9 2002-02-27 alex #ifndef STRICT_RFC
347 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_UNKNOWN )
348 c23199d9 2002-02-27 alex #else
349 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS )
350 c23199d9 2002-02-27 alex #endif
351 c23199d9 2002-02-27 alex {
352 6667bb6b 2004-02-04 alex /* Wrong number of parameters? */
353 c23199d9 2002-02-27 alex if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
354 c23199d9 2002-02-27 alex
355 6667bb6b 2004-02-04 alex /* User name */
356 b79b315d 2003-12-27 alex #ifdef IDENTAUTH
357 b79b315d 2003-12-27 alex ptr = Client_User( Client );
358 8adff592 2005-03-19 fw if( ! ptr || ! *ptr || *ptr == '~' ) Client_SetUser( Client, Req->argv[0], false );
359 6667bb6b 2004-02-04 alex #else
360 8adff592 2005-03-19 fw Client_SetUser( Client, Req->argv[0], false );
361 6667bb6b 2004-02-04 alex #endif
362 c23199d9 2002-02-27 alex
363 6667bb6b 2004-02-04 alex /* "Real name" or user info text: Don't set it to the empty string, the original ircd
364 6667bb6b 2004-02-04 alex * can't deal with such "real names" (e. g. "USER user * * :") ... */
365 6667bb6b 2004-02-04 alex if( *Req->argv[3] ) Client_SetInfo( Client, Req->argv[3] );
366 6667bb6b 2004-02-04 alex else Client_SetInfo( Client, "-" );
367 6667bb6b 2004-02-04 alex
368 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got valid USER command ...", Client_Conn( Client ));
369 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTNICK ) return Hello_User( Client );
370 c23199d9 2002-02-27 alex else Client_SetType( Client, CLIENT_GOTUSER );
371 c23199d9 2002-02-27 alex return CONNECTED;
372 c23199d9 2002-02-27 alex }
373 c23199d9 2002-02-27 alex else if( Client_Type( Client ) == CLIENT_USER || Client_Type( Client ) == CLIENT_SERVER || Client_Type( Client ) == CLIENT_SERVICE )
374 c23199d9 2002-02-27 alex {
375 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
376 c23199d9 2002-02-27 alex }
377 c23199d9 2002-02-27 alex else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
378 c23199d9 2002-02-27 alex } /* IRC_USER */
379 c23199d9 2002-02-27 alex
380 c23199d9 2002-02-27 alex
381 8adff592 2005-03-19 fw GLOBAL bool
382 c2f60abe 2002-05-27 alex IRC_QUIT( CLIENT *Client, REQUEST *Req )
383 c23199d9 2002-02-27 alex {
384 c23199d9 2002-02-27 alex CLIENT *target;
385 cac9f279 2005-06-04 fw char quitmsg[LINE_LEN];
386 c23199d9 2002-02-27 alex
387 c23199d9 2002-02-27 alex assert( Client != NULL );
388 c23199d9 2002-02-27 alex assert( Req != NULL );
389 cac9f279 2005-06-04 fw
390 cac9f279 2005-06-04 fw /* Wrong number of arguments? */
391 cac9f279 2005-06-04 fw if( Req->argc > 1 )
392 cac9f279 2005-06-04 fw return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
393 c23199d9 2002-02-27 alex
394 cac9f279 2005-06-04 fw if (Req->argc == 1)
395 cac9f279 2005-06-04 fw strlcpy(quitmsg, Req->argv[0], sizeof quitmsg);
396 cac9f279 2005-06-04 fw
397 7f795915 2002-04-14 alex if ( Client_Type( Client ) == CLIENT_SERVER )
398 c23199d9 2002-02-27 alex {
399 c23199d9 2002-02-27 alex /* Server */
400 c23199d9 2002-02-27 alex target = Client_Search( Req->prefix );
401 c23199d9 2002-02-27 alex if( ! target )
402 c23199d9 2002-02-27 alex {
403 9fc7e66f 2002-03-11 alex /* Den Client kennen wir nicht (mehr), also nichts zu tun. */
404 f7a0ff1f 2002-03-11 alex Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
405 c23199d9 2002-02-27 alex return CONNECTED;
406 c23199d9 2002-02-27 alex }
407 c23199d9 2002-02-27 alex
408 cac9f279 2005-06-04 fw Client_Destroy( target, "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
409 c23199d9 2002-02-27 alex
410 c23199d9 2002-02-27 alex return CONNECTED;
411 c23199d9 2002-02-27 alex }
412 7f795915 2002-04-14 alex else
413 7f795915 2002-04-14 alex {
414 cac9f279 2005-06-04 fw if (Req->argc == 1 && quitmsg[0] != '\"') {
415 cac9f279 2005-06-04 fw /* " " to avoid confusion */
416 cac9f279 2005-06-04 fw strlcpy(quitmsg, "\"", sizeof quitmsg);
417 cac9f279 2005-06-04 fw strlcat(quitmsg, Req->argv[0], sizeof quitmsg-1);
418 cac9f279 2005-06-04 fw strlcat(quitmsg, "\"", sizeof quitmsg );
419 cac9f279 2005-06-04 fw }
420 cac9f279 2005-06-04 fw
421 7f795915 2002-04-14 alex /* User, Service, oder noch nicht registriert */
422 cac9f279 2005-06-04 fw Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
423 7f795915 2002-04-14 alex
424 7f795915 2002-04-14 alex return DISCONNECTED;
425 7f795915 2002-04-14 alex }
426 c23199d9 2002-02-27 alex } /* IRC_QUIT */
427 c23199d9 2002-02-27 alex
428 c23199d9 2002-02-27 alex
429 8adff592 2005-03-19 fw GLOBAL bool
430 c2f60abe 2002-05-27 alex IRC_PING( CLIENT *Client, REQUEST *Req )
431 c23199d9 2002-02-27 alex {
432 c23199d9 2002-02-27 alex CLIENT *target, *from;
433 c23199d9 2002-02-27 alex
434 c23199d9 2002-02-27 alex assert( Client != NULL );
435 c23199d9 2002-02-27 alex assert( Req != NULL );
436 c23199d9 2002-02-27 alex
437 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
438 c23199d9 2002-02-27 alex if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
439 5fa05dce 2002-03-10 alex #ifdef STRICT_RFC
440 c23199d9 2002-02-27 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
441 5fa05dce 2002-03-10 alex #endif
442 c23199d9 2002-02-27 alex
443 5fa05dce 2002-03-10 alex if( Req->argc > 1 )
444 c23199d9 2002-02-27 alex {
445 c23199d9 2002-02-27 alex /* es wurde ein Ziel-Client angegeben */
446 bc4ed226 2002-03-25 alex target = Client_Search( Req->argv[1] );
447 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] );
448 c23199d9 2002-02-27 alex if( target != Client_ThisServer( ))
449 c23199d9 2002-02-27 alex {
450 c23199d9 2002-02-27 alex /* ok, forwarden */
451 bc4ed226 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
452 c23199d9 2002-02-27 alex else from = Client;
453 c23199d9 2002-02-27 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
454 c23199d9 2002-02-27 alex return IRC_WriteStrClientPrefix( target, from, "PING %s :%s", Client_ID( from ), Req->argv[1] );
455 c23199d9 2002-02-27 alex }
456 c23199d9 2002-02-27 alex }
457 c23199d9 2002-02-27 alex
458 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got PING, sending PONG ...", Client_Conn( Client ));
459 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, "PONG %s :%s", Client_ID( Client_ThisServer( )), Client_ID( Client ));
460 c23199d9 2002-02-27 alex } /* IRC_PING */
461 c23199d9 2002-02-27 alex
462 c23199d9 2002-02-27 alex
463 8adff592 2005-03-19 fw GLOBAL bool
464 c2f60abe 2002-05-27 alex IRC_PONG( CLIENT *Client, REQUEST *Req )
465 c23199d9 2002-02-27 alex {
466 c23199d9 2002-02-27 alex CLIENT *target, *from;
467 c23199d9 2002-02-27 alex
468 c23199d9 2002-02-27 alex assert( Client != NULL );
469 c23199d9 2002-02-27 alex assert( Req != NULL );
470 c23199d9 2002-02-27 alex
471 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
472 c23199d9 2002-02-27 alex if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
473 c23199d9 2002-02-27 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
474 c23199d9 2002-02-27 alex
475 c23199d9 2002-02-27 alex /* forwarden? */
476 c23199d9 2002-02-27 alex if( Req->argc == 2 )
477 c23199d9 2002-02-27 alex {
478 bc4ed226 2002-03-25 alex target = Client_Search( Req->argv[1] );
479 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] );
480 c23199d9 2002-02-27 alex if( target != Client_ThisServer( ))
481 c23199d9 2002-02-27 alex {
482 c23199d9 2002-02-27 alex /* ok, forwarden */
483 bc4ed226 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
484 c23199d9 2002-02-27 alex else from = Client;
485 c23199d9 2002-02-27 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
486 c23199d9 2002-02-27 alex return IRC_WriteStrClientPrefix( target, from, "PONG %s :%s", Client_ID( from ), Req->argv[1] );
487 c23199d9 2002-02-27 alex }
488 c23199d9 2002-02-27 alex }
489 c23199d9 2002-02-27 alex
490 c23199d9 2002-02-27 alex /* Der Connection-Timestamp wurde schon beim Lesen aus dem Socket
491 bcc51385 2002-03-26 alex * aktualisiert, daher muss das hier nicht mehr gemacht werden. */
492 c23199d9 2002-02-27 alex
493 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 )));
494 c23199d9 2002-02-27 alex else Log( LOG_DEBUG, "Connection %d: received PONG.", Client_Conn( Client ));
495 c23199d9 2002-02-27 alex
496 c23199d9 2002-02-27 alex return CONNECTED;
497 c23199d9 2002-02-27 alex } /* IRC_PONG */
498 c23199d9 2002-02-27 alex
499 c23199d9 2002-02-27 alex
500 8adff592 2005-03-19 fw LOCAL bool
501 c2f60abe 2002-05-27 alex Hello_User( CLIENT *Client )
502 c23199d9 2002-02-27 alex {
503 05e2c0f0 2003-12-04 alex #ifdef CVSDATE
504 8adff592 2005-03-19 fw char ver[12], vertxt[30];
505 05e2c0f0 2003-12-04 alex #endif
506 05e2c0f0 2003-12-04 alex
507 c23199d9 2002-02-27 alex assert( Client != NULL );
508 c23199d9 2002-02-27 alex
509 05e2c0f0 2003-12-04 alex /* Check password ... */
510 c23199d9 2002-02-27 alex if( strcmp( Client_Password( Client ), Conf_ServerPwd ) != 0 )
511 c23199d9 2002-02-27 alex {
512 05e2c0f0 2003-12-04 alex /* Bad password! */
513 c23199d9 2002-02-27 alex Log( LOG_ERR, "User \"%s\" rejected (connection %d): Bad password!", Client_Mask( Client ), Client_Conn( Client ));
514 8adff592 2005-03-19 fw Conn_Close( Client_Conn( Client ), NULL, "Bad password", true);
515 c23199d9 2002-02-27 alex return DISCONNECTED;
516 c23199d9 2002-02-27 alex }
517 c23199d9 2002-02-27 alex
518 c23199d9 2002-02-27 alex Log( LOG_NOTICE, "User \"%s\" registered (connection %d).", Client_Mask( Client ), Client_Conn( Client ));
519 c23199d9 2002-02-27 alex
520 05e2c0f0 2003-12-04 alex /* Inform other servers */
521 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 ));
522 c23199d9 2002-02-27 alex
523 05e2c0f0 2003-12-04 alex /* Welcome :-) */
524 8adff592 2005-03-19 fw if( ! IRC_WriteStrClient( Client, RPL_WELCOME_MSG, Client_ID( Client ), Client_Mask( Client ))) return false;
525 05e2c0f0 2003-12-04 alex
526 05e2c0f0 2003-12-04 alex /* Version and system type */
527 05e2c0f0 2003-12-04 alex #ifdef CVSDATE
528 f56a1bdf 2005-03-21 alex strlcpy( ver, CVSDATE, sizeof( ver ));
529 f56a1bdf 2005-03-21 alex strncpy( ver + 4, ver + 5, 2 );
530 f56a1bdf 2005-03-21 alex strncpy( ver + 6, ver + 8, 3 );
531 05e2c0f0 2003-12-04 alex snprintf( vertxt, sizeof( vertxt ), "%s(%s)", PACKAGE_VERSION, ver );
532 8adff592 2005-03-19 fw if( ! IRC_WriteStrClient( Client, RPL_YOURHOST_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )), vertxt, TARGET_CPU, TARGET_VENDOR, TARGET_OS )) return false;
533 05e2c0f0 2003-12-04 alex #else
534 8adff592 2005-03-19 fw if( ! IRC_WriteStrClient( Client, RPL_YOURHOST_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )), PACKAGE_VERSION, TARGET_CPU, TARGET_VENDOR, TARGET_OS )) return false;
535 05e2c0f0 2003-12-04 alex #endif
536 05e2c0f0 2003-12-04 alex
537 8adff592 2005-03-19 fw if( ! IRC_WriteStrClient( Client, RPL_CREATED_MSG, Client_ID( Client ), NGIRCd_StartStr )) return false;
538 05e2c0f0 2003-12-04 alex #ifdef CVSDATE
539 8adff592 2005-03-19 fw if( ! IRC_WriteStrClient( Client, RPL_MYINFO_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )), vertxt, USERMODES, CHANMODES )) return false;
540 05e2c0f0 2003-12-04 alex #else
541 8adff592 2005-03-19 fw if( ! IRC_WriteStrClient( Client, RPL_MYINFO_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )), PACKAGE_VERSION, USERMODES, CHANMODES )) return false;
542 05e2c0f0 2003-12-04 alex #endif
543 c23199d9 2002-02-27 alex
544 a3f59f1a 2002-12-22 alex /* Features */
545 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;
546 a3f59f1a 2002-12-22 alex
547 c23199d9 2002-02-27 alex Client_SetType( Client, CLIENT_USER );
548 c23199d9 2002-02-27 alex
549 c23199d9 2002-02-27 alex if( ! IRC_Send_LUSERS( Client )) return DISCONNECTED;
550 c23199d9 2002-02-27 alex if( ! IRC_Show_MOTD( Client )) return DISCONNECTED;
551 c23199d9 2002-02-27 alex
552 7b6e2662 2003-11-05 alex /* Suspend the client for a second ... */
553 7b6e2662 2003-11-05 alex IRC_SetPenalty( Client, 1 );
554 7b6e2662 2003-11-05 alex
555 c23199d9 2002-02-27 alex return CONNECTED;
556 c23199d9 2002-02-27 alex } /* Hello_User */
557 c23199d9 2002-02-27 alex
558 c23199d9 2002-02-27 alex
559 8adff592 2005-03-19 fw LOCAL void
560 8adff592 2005-03-19 fw Kill_Nick( char *Nick, char *Reason )
561 c23199d9 2002-02-27 alex {
562 ff988331 2003-01-08 alex REQUEST r;
563 c23199d9 2002-02-27 alex
564 c23199d9 2002-02-27 alex assert( Nick != NULL );
565 c23199d9 2002-02-27 alex assert( Reason != NULL );
566 c23199d9 2002-02-27 alex
567 8adff592 2005-03-19 fw r.prefix = (char *)Client_ThisServer( );
568 ff988331 2003-01-08 alex r.argv[0] = Nick;
569 ff988331 2003-01-08 alex r.argv[1] = Reason;
570 ff988331 2003-01-08 alex r.argc = 2;
571 c23199d9 2002-02-27 alex
572 ff988331 2003-01-08 alex Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s", Nick, Reason );
573 ff988331 2003-01-08 alex IRC_KILL( Client_ThisServer( ), &r );
574 c23199d9 2002-02-27 alex } /* Kill_Nick */
575 c23199d9 2002-02-27 alex
576 c23199d9 2002-02-27 alex
577 c23199d9 2002-02-27 alex /* -eof- */