Blame


1 6e07fb41 2001-12-21 alex /*
2 6e07fb41 2001-12-21 alex * ngIRCd -- The Next Generation IRC Daemon
3 b6254bbb 2002-01-02 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
4 6e07fb41 2001-12-21 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 6e07fb41 2001-12-21 alex */
11 6e07fb41 2001-12-21 alex
12 6e07fb41 2001-12-21 alex
13 ca33cbda 2002-03-12 alex #include "portab.h"
14 490f28ff 2002-12-12 alex
15 45404a16 2005-06-01 alex static char UNUSED id[] = "$Id: parse.c,v 1.62 2005/06/01 21:52:18 alex Exp $";
16 6e07fb41 2001-12-21 alex
17 45404a16 2005-06-01 alex /**
18 45404a16 2005-06-01 alex * @file
19 45404a16 2005-06-01 alex * IRC command parser and validator.
20 45404a16 2005-06-01 alex */
21 45404a16 2005-06-01 alex
22 ca33cbda 2002-03-12 alex #include "imp.h"
23 6e07fb41 2001-12-21 alex #include <assert.h>
24 1c8c92af 2002-01-05 alex #include <stdlib.h>
25 6e07fb41 2001-12-21 alex #include <stdio.h>
26 6e07fb41 2001-12-21 alex #include <string.h>
27 57c7e236 2004-01-17 alex #include <strings.h>
28 6e07fb41 2001-12-21 alex
29 d79a7d28 2002-01-18 alex #include "ngircd.h"
30 ca33cbda 2002-03-12 alex #include "defines.h"
31 b8d7dcec 2002-12-30 alex #include "conn-func.h"
32 c2f60abe 2002-05-27 alex #include "client.h"
33 c2f60abe 2002-05-27 alex #include "channel.h"
34 c2f60abe 2002-05-27 alex #include "log.h"
35 c2f60abe 2002-05-27 alex #include "messages.h"
36 c2f60abe 2002-05-27 alex #include "tool.h"
37 c2f60abe 2002-05-27 alex
38 c2f60abe 2002-05-27 alex #include "exp.h"
39 c2f60abe 2002-05-27 alex #include "parse.h"
40 c2f60abe 2002-05-27 alex
41 c2f60abe 2002-05-27 alex #include "imp.h"
42 76c4f066 2001-12-23 alex #include "irc.h"
43 14aba7c1 2002-03-03 alex #include "irc-channel.h"
44 0c471b84 2002-11-30 alex #include "irc-info.h"
45 b56eb4d8 2002-02-27 alex #include "irc-login.h"
46 b56eb4d8 2002-02-27 alex #include "irc-mode.h"
47 c2f60abe 2002-05-27 alex #include "irc-op.h"
48 14aba7c1 2002-03-03 alex #include "irc-oper.h"
49 14aba7c1 2002-03-03 alex #include "irc-server.h"
50 b56eb4d8 2002-02-27 alex #include "irc-write.h"
51 6e07fb41 2001-12-21 alex
52 ca33cbda 2002-03-12 alex #include "exp.h"
53 1e59617d 2002-11-30 alex
54 1e59617d 2002-11-30 alex
55 1e59617d 2002-11-30 alex COMMAND My_Commands[] =
56 1e59617d 2002-11-30 alex {
57 17f7c6d3 2002-12-18 alex { "ADMIN", IRC_ADMIN, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
58 17f7c6d3 2002-12-18 alex { "AWAY", IRC_AWAY, CLIENT_USER, 0, 0, 0 },
59 17f7c6d3 2002-12-18 alex { "CONNECT", IRC_CONNECT, CLIENT_USER, 0, 0, 0 },
60 17f7c6d3 2002-12-18 alex { "DIE", IRC_DIE, CLIENT_USER, 0, 0, 0 },
61 a7956f33 2002-12-31 alex { "DISCONNECT", IRC_DISCONNECT, CLIENT_USER, 0, 0, 0 },
62 17f7c6d3 2002-12-18 alex { "ERROR", IRC_ERROR, 0xFFFF, 0, 0, 0 },
63 2152e377 2003-01-15 alex { "HELP", IRC_HELP, CLIENT_USER, 0, 0, 0 },
64 17f7c6d3 2002-12-18 alex { "INVITE", IRC_INVITE, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
65 17f7c6d3 2002-12-18 alex { "ISON", IRC_ISON, CLIENT_USER, 0, 0, 0 },
66 17f7c6d3 2002-12-18 alex { "JOIN", IRC_JOIN, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
67 17f7c6d3 2002-12-18 alex { "KICK", IRC_KICK, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
68 17f7c6d3 2002-12-18 alex { "KILL", IRC_KILL, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
69 17f7c6d3 2002-12-18 alex { "LINKS", IRC_LINKS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
70 17f7c6d3 2002-12-18 alex { "LIST", IRC_LIST, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
71 17f7c6d3 2002-12-18 alex { "LUSERS", IRC_LUSERS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
72 17f7c6d3 2002-12-18 alex { "MODE", IRC_MODE, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
73 17f7c6d3 2002-12-18 alex { "MOTD", IRC_MOTD, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
74 17f7c6d3 2002-12-18 alex { "NAMES", IRC_NAMES, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
75 17f7c6d3 2002-12-18 alex { "NICK", IRC_NICK, 0xFFFF, 0, 0, 0 },
76 17f7c6d3 2002-12-18 alex { "NJOIN", IRC_NJOIN, CLIENT_SERVER, 0, 0, 0 },
77 17f7c6d3 2002-12-18 alex { "NOTICE", IRC_NOTICE, 0xFFFF, 0, 0, 0 },
78 17f7c6d3 2002-12-18 alex { "OPER", IRC_OPER, CLIENT_USER, 0, 0, 0 },
79 17f7c6d3 2002-12-18 alex { "PART", IRC_PART, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
80 17f7c6d3 2002-12-18 alex { "PASS", IRC_PASS, 0xFFFF, 0, 0, 0 },
81 17f7c6d3 2002-12-18 alex { "PING", IRC_PING, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
82 17f7c6d3 2002-12-18 alex { "PONG", IRC_PONG, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
83 17f7c6d3 2002-12-18 alex { "PRIVMSG", IRC_PRIVMSG, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
84 17f7c6d3 2002-12-18 alex { "QUIT", IRC_QUIT, 0xFFFF, 0, 0, 0 },
85 17f7c6d3 2002-12-18 alex { "REHASH", IRC_REHASH, CLIENT_USER, 0, 0, 0 },
86 17f7c6d3 2002-12-18 alex { "RESTART", IRC_RESTART, CLIENT_USER, 0, 0, 0 },
87 17f7c6d3 2002-12-18 alex { "SERVER", IRC_SERVER, 0xFFFF, 0, 0, 0 },
88 17f7c6d3 2002-12-18 alex { "SQUIT", IRC_SQUIT, CLIENT_SERVER, 0, 0, 0 },
89 17f7c6d3 2002-12-18 alex { "STATS", IRC_STATS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
90 17f7c6d3 2002-12-18 alex { "TIME", IRC_TIME, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
91 17f7c6d3 2002-12-18 alex { "TOPIC", IRC_TOPIC, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
92 42c4e6c7 2003-01-13 alex { "TRACE", IRC_TRACE, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
93 17f7c6d3 2002-12-18 alex { "USER", IRC_USER, 0xFFFF, 0, 0, 0 },
94 17f7c6d3 2002-12-18 alex { "USERHOST", IRC_USERHOST, CLIENT_USER, 0, 0, 0 },
95 17f7c6d3 2002-12-18 alex { "VERSION", IRC_VERSION, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
96 17f7c6d3 2002-12-18 alex { "WHO", IRC_WHO, CLIENT_USER, 0, 0, 0 },
97 17f7c6d3 2002-12-18 alex { "WHOIS", IRC_WHOIS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
98 17f7c6d3 2002-12-18 alex { "WHOWAS", IRC_WHOWAS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
99 17f7c6d3 2002-12-18 alex #ifdef IRCPLUS
100 17f7c6d3 2002-12-18 alex { "CHANINFO", IRC_CHANINFO, CLIENT_SERVER, 0, 0, 0 },
101 1e59617d 2002-11-30 alex #endif
102 17f7c6d3 2002-12-18 alex { NULL, NULL, 0x0, 0, 0, 0 } /* Ende-Marke */
103 1e59617d 2002-11-30 alex };
104 6e07fb41 2001-12-21 alex
105 6e07fb41 2001-12-21 alex
106 8adff592 2005-03-19 fw LOCAL void Init_Request PARAMS(( REQUEST *Req ));
107 6e07fb41 2001-12-21 alex
108 8adff592 2005-03-19 fw LOCAL bool Validate_Prefix PARAMS(( CONN_ID Idx, REQUEST *Req, bool *Closed ));
109 8adff592 2005-03-19 fw LOCAL bool Validate_Command PARAMS(( CONN_ID Idx, REQUEST *Req, bool *Closed ));
110 8adff592 2005-03-19 fw LOCAL bool Validate_Args PARAMS(( CONN_ID Idx, REQUEST *Req, bool *Closed ));
111 6e07fb41 2001-12-21 alex
112 8adff592 2005-03-19 fw LOCAL bool Handle_Request PARAMS(( CONN_ID Idx, REQUEST *Req ));
113 6e07fb41 2001-12-21 alex
114 6e07fb41 2001-12-21 alex
115 45404a16 2005-06-01 alex /**
116 45404a16 2005-06-01 alex * Return the pointer to the global "IRC command structure".
117 45404a16 2005-06-01 alex * This structure, an array of type "COMMAND" describes all the IRC commands
118 45404a16 2005-06-01 alex * implemented by ngIRCd and how to handle them.
119 45404a16 2005-06-01 alex * @return Pointer to the global command structure.
120 45404a16 2005-06-01 alex */
121 17f7c6d3 2002-12-18 alex GLOBAL COMMAND *
122 8adff592 2005-03-19 fw Parse_GetCommandStruct( void )
123 17f7c6d3 2002-12-18 alex {
124 17f7c6d3 2002-12-18 alex return My_Commands;
125 17f7c6d3 2002-12-18 alex } /* Parse_GetCommandStruct */
126 17f7c6d3 2002-12-18 alex
127 17f7c6d3 2002-12-18 alex
128 45404a16 2005-06-01 alex /**
129 45404a16 2005-06-01 alex * Parse a command ("request") received from a client.
130 45404a16 2005-06-01 alex *
131 45404a16 2005-06-01 alex * This function is called after the connection layer received a valid CR+LF
132 45404a16 2005-06-01 alex * terminated line of text: we asume that this is a valid IRC command and
133 45404a16 2005-06-01 alex * try to do something useful with it :-)
134 45404a16 2005-06-01 alex *
135 45404a16 2005-06-01 alex * All errors are reported to the client from which the command has been
136 45404a16 2005-06-01 alex * received, and if the error is fatal this connection is closed down.
137 45404a16 2005-06-01 alex *
138 45404a16 2005-06-01 alex * This function is able to parse the syntax as described in RFC 2812,
139 45404a16 2005-06-01 alex * section 2.3.
140 45404a16 2005-06-01 alex *
141 45404a16 2005-06-01 alex * @param Idx Index of the connection from which the command has been received.
142 45404a16 2005-06-01 alex * @param Request NULL terminated line of text (the "command").
143 45404a16 2005-06-01 alex * @return true on success (valid command or "regular" error), false if a
144 45404a16 2005-06-01 alex * fatal error occured and the connection has been shut down.
145 45404a16 2005-06-01 alex */
146 8adff592 2005-03-19 fw GLOBAL bool
147 8adff592 2005-03-19 fw Parse_Request( CONN_ID Idx, char *Request )
148 6e07fb41 2001-12-21 alex {
149 6e07fb41 2001-12-21 alex REQUEST req;
150 8adff592 2005-03-19 fw char *start, *ptr;
151 8adff592 2005-03-19 fw bool closed;
152 6e07fb41 2001-12-21 alex
153 6e07fb41 2001-12-21 alex assert( Idx >= 0 );
154 6e07fb41 2001-12-21 alex assert( Request != NULL );
155 76c4f066 2001-12-23 alex
156 d4a60bd4 2001-12-25 alex #ifdef SNIFFER
157 d79a7d28 2002-01-18 alex if( NGIRCd_Sniffer ) Log( LOG_DEBUG, " <- connection %d: '%s'.", Idx, Request );
158 76c4f066 2001-12-23 alex #endif
159 e0ed3aa1 2002-07-26 alex
160 6e07fb41 2001-12-21 alex Init_Request( &req );
161 6e07fb41 2001-12-21 alex
162 363a03b8 2001-12-29 alex /* Fuehrendes und folgendes "Geraffel" verwerfen */
163 363a03b8 2001-12-29 alex ngt_TrimStr( Request );
164 363a03b8 2001-12-29 alex
165 6e07fb41 2001-12-21 alex /* gibt es ein Prefix? */
166 6e07fb41 2001-12-21 alex if( Request[0] == ':' )
167 6e07fb41 2001-12-21 alex {
168 6e07fb41 2001-12-21 alex /* Prefix vorhanden */
169 6e07fb41 2001-12-21 alex req.prefix = Request + 1;
170 6e07fb41 2001-12-21 alex ptr = strchr( Request, ' ' );
171 e0ed3aa1 2002-07-26 alex if( ! ptr )
172 e0ed3aa1 2002-07-26 alex {
173 e0ed3aa1 2002-07-26 alex Log( LOG_DEBUG, "Connection %d: Parse error: prefix without command!?", Idx );
174 e0ed3aa1 2002-07-26 alex return Conn_WriteStr( Idx, "ERROR :Prefix without command!?" );
175 e0ed3aa1 2002-07-26 alex }
176 6e07fb41 2001-12-21 alex *ptr = '\0';
177 3543c222 2002-01-09 alex #ifndef STRICT_RFC
178 3543c222 2002-01-09 alex /* multiple Leerzeichen als Trenner zwischen
179 3543c222 2002-01-09 alex * Prefix und Befehl ignorieren */
180 3543c222 2002-01-09 alex while( *(ptr + 1) == ' ' ) ptr++;
181 3543c222 2002-01-09 alex #endif
182 6e07fb41 2001-12-21 alex start = ptr + 1;
183 6e07fb41 2001-12-21 alex }
184 6e07fb41 2001-12-21 alex else start = Request;
185 6e07fb41 2001-12-21 alex
186 6e07fb41 2001-12-21 alex /* Befehl */
187 6e07fb41 2001-12-21 alex ptr = strchr( start, ' ' );
188 3543c222 2002-01-09 alex if( ptr )
189 3543c222 2002-01-09 alex {
190 3543c222 2002-01-09 alex *ptr = '\0';
191 3543c222 2002-01-09 alex #ifndef STRICT_RFC
192 3543c222 2002-01-09 alex /* multiple Leerzeichen als Trenner vor
193 fc1118cb 2003-01-12 alex * Parametern ignorieren */
194 3543c222 2002-01-09 alex while( *(ptr + 1) == ' ' ) ptr++;
195 3543c222 2002-01-09 alex #endif
196 3543c222 2002-01-09 alex }
197 6e07fb41 2001-12-21 alex req.command = start;
198 6e07fb41 2001-12-21 alex
199 6e07fb41 2001-12-21 alex /* Argumente, Parameter */
200 6e07fb41 2001-12-21 alex if( ptr )
201 6e07fb41 2001-12-21 alex {
202 6e07fb41 2001-12-21 alex /* Prinzipiell gibt es welche :-) */
203 6e07fb41 2001-12-21 alex start = ptr + 1;
204 6e07fb41 2001-12-21 alex while( start )
205 6e07fb41 2001-12-21 alex {
206 6e07fb41 2001-12-21 alex /* Parameter-String "zerlegen" */
207 76c4f066 2001-12-23 alex if( start[0] == ':' )
208 76c4f066 2001-12-23 alex {
209 76c4f066 2001-12-23 alex req.argv[req.argc] = start + 1;
210 76c4f066 2001-12-23 alex ptr = NULL;
211 76c4f066 2001-12-23 alex }
212 76c4f066 2001-12-23 alex else
213 76c4f066 2001-12-23 alex {
214 76c4f066 2001-12-23 alex req.argv[req.argc] = start;
215 76c4f066 2001-12-23 alex ptr = strchr( start, ' ' );
216 3543c222 2002-01-09 alex if( ptr )
217 3543c222 2002-01-09 alex {
218 3543c222 2002-01-09 alex *ptr = '\0';
219 3543c222 2002-01-09 alex #ifndef STRICT_RFC
220 3543c222 2002-01-09 alex /* multiple Leerzeichen als
221 3543c222 2002-01-09 alex * Parametertrenner ignorieren */
222 3543c222 2002-01-09 alex while( *(ptr + 1) == ' ' ) ptr++;
223 3543c222 2002-01-09 alex #endif
224 3543c222 2002-01-09 alex }
225 76c4f066 2001-12-23 alex }
226 e0ed3aa1 2002-07-26 alex
227 6e07fb41 2001-12-21 alex req.argc++;
228 6e07fb41 2001-12-21 alex
229 6e07fb41 2001-12-21 alex if( start[0] == ':' ) break;
230 6e07fb41 2001-12-21 alex if( req.argc > 14 ) break;
231 e0ed3aa1 2002-07-26 alex
232 6e07fb41 2001-12-21 alex if( ptr ) start = ptr + 1;
233 6e07fb41 2001-12-21 alex else start = NULL;
234 6e07fb41 2001-12-21 alex }
235 6e07fb41 2001-12-21 alex }
236 93aa0dbf 2002-01-03 alex
237 b0b797b3 2002-11-28 alex /* Daten validieren */
238 b0b797b3 2002-11-28 alex if( ! Validate_Prefix( Idx, &req, &closed )) return ! closed;
239 b0b797b3 2002-11-28 alex if( ! Validate_Command( Idx, &req, &closed )) return ! closed;
240 e0ed3aa1 2002-07-26 alex if( ! Validate_Args( Idx, &req, &closed )) return ! closed;
241 e0ed3aa1 2002-07-26 alex
242 6e07fb41 2001-12-21 alex return Handle_Request( Idx, &req );
243 6e07fb41 2001-12-21 alex } /* Parse_Request */
244 6e07fb41 2001-12-21 alex
245 6e07fb41 2001-12-21 alex
246 45404a16 2005-06-01 alex /**
247 45404a16 2005-06-01 alex * Initialize request structure.
248 45404a16 2005-06-01 alex * @param Req Request structure to be initialized.
249 45404a16 2005-06-01 alex */
250 8adff592 2005-03-19 fw LOCAL void
251 c2f60abe 2002-05-27 alex Init_Request( REQUEST *Req )
252 6e07fb41 2001-12-21 alex {
253 6e07fb41 2001-12-21 alex /* Neue Request-Struktur initialisieren */
254 6e07fb41 2001-12-21 alex
255 8adff592 2005-03-19 fw int i;
256 e0ed3aa1 2002-07-26 alex
257 6e07fb41 2001-12-21 alex assert( Req != NULL );
258 6e07fb41 2001-12-21 alex
259 6e07fb41 2001-12-21 alex Req->prefix = NULL;
260 6e07fb41 2001-12-21 alex Req->command = NULL;
261 6e07fb41 2001-12-21 alex for( i = 0; i < 15; Req->argv[i++] = NULL );
262 6e07fb41 2001-12-21 alex Req->argc = 0;
263 6e07fb41 2001-12-21 alex } /* Init_Request */
264 6e07fb41 2001-12-21 alex
265 6e07fb41 2001-12-21 alex
266 8adff592 2005-03-19 fw LOCAL bool
267 8adff592 2005-03-19 fw Validate_Prefix( CONN_ID Idx, REQUEST *Req, bool *Closed )
268 6e07fb41 2001-12-21 alex {
269 5063de59 2002-07-29 alex CLIENT *client, *c;
270 6e07fb41 2001-12-21 alex
271 e0ed3aa1 2002-07-26 alex assert( Idx >= 0 );
272 e0ed3aa1 2002-07-26 alex assert( Req != NULL );
273 6e07fb41 2001-12-21 alex
274 8adff592 2005-03-19 fw *Closed = false;
275 5063de59 2002-07-29 alex
276 e0ed3aa1 2002-07-26 alex /* ist ueberhaupt ein Prefix vorhanden? */
277 8adff592 2005-03-19 fw if( ! Req->prefix ) return true;
278 6e07fb41 2001-12-21 alex
279 5063de59 2002-07-29 alex /* Client-Struktur der Connection ermitteln */
280 5063de59 2002-07-29 alex client = Client_GetFromConn( Idx );
281 5063de59 2002-07-29 alex assert( client != NULL );
282 5063de59 2002-07-29 alex
283 5063de59 2002-07-29 alex /* nur validieren, wenn bereits registrierte Verbindung */
284 5063de59 2002-07-29 alex if(( Client_Type( client ) != CLIENT_USER ) && ( Client_Type( client ) != CLIENT_SERVER ) && ( Client_Type( client ) != CLIENT_SERVICE ))
285 5063de59 2002-07-29 alex {
286 5063de59 2002-07-29 alex /* noch nicht registrierte Verbindung.
287 5063de59 2002-07-29 alex * Das Prefix wird ignoriert. */
288 5063de59 2002-07-29 alex Req->prefix = NULL;
289 8adff592 2005-03-19 fw return true;
290 5063de59 2002-07-29 alex }
291 5063de59 2002-07-29 alex
292 e0ed3aa1 2002-07-26 alex /* pruefen, ob der im Prefix angegebene Client bekannt ist */
293 e0ed3aa1 2002-07-26 alex c = Client_Search( Req->prefix );
294 e0ed3aa1 2002-07-26 alex if( ! c )
295 e0ed3aa1 2002-07-26 alex {
296 e0ed3aa1 2002-07-26 alex /* im Prefix angegebener Client ist nicht bekannt */
297 b0b797b3 2002-11-28 alex Log( LOG_ERR, "Invalid prefix \"%s\", client not known (connection %d, command %s)!?", Req->prefix, Idx, Req->command );
298 8adff592 2005-03-19 fw if( ! Conn_WriteStr( Idx, "ERROR :Invalid prefix \"%s\", client not known!?", Req->prefix )) *Closed = true;
299 8adff592 2005-03-19 fw return false;
300 e0ed3aa1 2002-07-26 alex }
301 5063de59 2002-07-29 alex
302 e0ed3aa1 2002-07-26 alex /* pruefen, ob der Client mit dem angegebenen Prefix in Richtung
303 e0ed3aa1 2002-07-26 alex * des Senders liegt, d.h. sicherstellen, dass das Prefix nicht
304 e0ed3aa1 2002-07-26 alex * gefaelscht ist */
305 5063de59 2002-07-29 alex if( Client_NextHop( c ) != client )
306 e0ed3aa1 2002-07-26 alex {
307 e0ed3aa1 2002-07-26 alex /* das angegebene Prefix ist aus dieser Richtung, also
308 e0ed3aa1 2002-07-26 alex * aus der gegebenen Connection, ungueltig! */
309 b0b797b3 2002-11-28 alex Log( LOG_ERR, "Spoofed prefix \"%s\" from \"%s\" (connection %d, command %s)!", Req->prefix, Client_Mask( Client_GetFromConn( Idx )), Idx, Req->command );
310 8adff592 2005-03-19 fw Conn_Close( Idx, NULL, "Spoofed prefix", true);
311 8adff592 2005-03-19 fw *Closed = true;
312 8adff592 2005-03-19 fw return false;
313 e0ed3aa1 2002-07-26 alex }
314 e0ed3aa1 2002-07-26 alex
315 8adff592 2005-03-19 fw return true;
316 6e07fb41 2001-12-21 alex } /* Validate_Prefix */
317 6e07fb41 2001-12-21 alex
318 6e07fb41 2001-12-21 alex
319 8adff592 2005-03-19 fw LOCAL bool
320 8adff592 2005-03-19 fw Validate_Command( CONN_ID Idx, REQUEST *Req, bool *Closed )
321 6e07fb41 2001-12-21 alex {
322 e0ed3aa1 2002-07-26 alex assert( Idx >= 0 );
323 6e07fb41 2001-12-21 alex assert( Req != NULL );
324 8adff592 2005-03-19 fw *Closed = false;
325 e0ed3aa1 2002-07-26 alex
326 8adff592 2005-03-19 fw return true;
327 6e07fb41 2001-12-21 alex } /* Validate_Comman */
328 6e07fb41 2001-12-21 alex
329 6e07fb41 2001-12-21 alex
330 8adff592 2005-03-19 fw LOCAL bool
331 8adff592 2005-03-19 fw Validate_Args( CONN_ID Idx, REQUEST *Req, bool *Closed )
332 6e07fb41 2001-12-21 alex {
333 e0ed3aa1 2002-07-26 alex assert( Idx >= 0 );
334 6e07fb41 2001-12-21 alex assert( Req != NULL );
335 8adff592 2005-03-19 fw *Closed = false;
336 e0ed3aa1 2002-07-26 alex
337 8adff592 2005-03-19 fw return true;
338 6e07fb41 2001-12-21 alex } /* Validate_Args */
339 6e07fb41 2001-12-21 alex
340 6e07fb41 2001-12-21 alex
341 8adff592 2005-03-19 fw LOCAL bool
342 c2f60abe 2002-05-27 alex Handle_Request( CONN_ID Idx, REQUEST *Req )
343 6e07fb41 2001-12-21 alex {
344 76c4f066 2001-12-23 alex /* Client-Request verarbeiten. Bei einem schwerwiegenden Fehler
345 8adff592 2005-03-19 fw * wird die Verbindung geschlossen und false geliefert. */
346 76c4f066 2001-12-23 alex
347 1c8c92af 2002-01-05 alex CLIENT *client, *target, *prefix;
348 8adff592 2005-03-19 fw char str[LINE_LEN];
349 8adff592 2005-03-19 fw bool result;
350 1e59617d 2002-11-30 alex COMMAND *cmd;
351 8adff592 2005-03-19 fw int i;
352 76c4f066 2001-12-23 alex
353 6e07fb41 2001-12-21 alex assert( Idx >= 0 );
354 6e07fb41 2001-12-21 alex assert( Req != NULL );
355 6e07fb41 2001-12-21 alex assert( Req->command != NULL );
356 6e07fb41 2001-12-21 alex
357 76c4f066 2001-12-23 alex client = Client_GetFromConn( Idx );
358 76c4f066 2001-12-23 alex assert( client != NULL );
359 1c8c92af 2002-01-05 alex
360 fc1118cb 2003-01-12 alex /* Statuscode? */
361 fc1118cb 2003-01-12 alex if(( Client_Type( client ) == CLIENT_SERVER ) && ( strlen( Req->command ) == 3 ) && ( atoi( Req->command ) > 100 ))
362 fc1118cb 2003-01-12 alex {
363 fc1118cb 2003-01-12 alex /* Command is a status code from an other server */
364 1c8c92af 2002-01-05 alex
365 fc1118cb 2003-01-12 alex /* Determine target */
366 fc1118cb 2003-01-12 alex if( Req->argc > 0 ) target = Client_Search( Req->argv[0] );
367 1c8c92af 2002-01-05 alex else target = NULL;
368 9e18ec30 2002-01-07 alex if( ! target )
369 9e18ec30 2002-01-07 alex {
370 fc1118cb 2003-01-12 alex /* Status code without target!? */
371 dd09b17e 2002-11-20 alex if( Req->argc > 0 ) Log( LOG_WARNING, "Unknown target for status code %s: \"%s\"", Req->command, Req->argv[0] );
372 dd09b17e 2002-11-20 alex else Log( LOG_WARNING, "Unknown target for status code %s!", Req->command );
373 8adff592 2005-03-19 fw return true;
374 9e18ec30 2002-01-07 alex }
375 9e18ec30 2002-01-07 alex if( target == Client_ThisServer( ))
376 9e18ec30 2002-01-07 alex {
377 fc1118cb 2003-01-12 alex /* This server is the target, ignore it */
378 9e18ec30 2002-01-07 alex Log( LOG_DEBUG, "Ignored status code %s from \"%s\".", Req->command, Client_ID( client ));
379 8adff592 2005-03-19 fw return true;
380 9e18ec30 2002-01-07 alex }
381 76c4f066 2001-12-23 alex
382 fc1118cb 2003-01-12 alex /* Determine source */
383 9e18ec30 2002-01-07 alex if( ! Req->prefix[0] )
384 9e18ec30 2002-01-07 alex {
385 fc1118cb 2003-01-12 alex /* Oops, no prefix!? */
386 fc1118cb 2003-01-12 alex Log( LOG_WARNING, "Got status code %s from \"%s\" without prefix!?", Req->command, Client_ID( client ));
387 8adff592 2005-03-19 fw return true;
388 9e18ec30 2002-01-07 alex }
389 bc4ed226 2002-03-25 alex else prefix = Client_Search( Req->prefix );
390 9e18ec30 2002-01-07 alex if( ! prefix )
391 9e18ec30 2002-01-07 alex {
392 fc1118cb 2003-01-12 alex /* Oops, unknown prefix!? */
393 fc1118cb 2003-01-12 alex Log( LOG_WARNING, "Got status code %s from unknown source: \"%s\"", Req->command, Req->prefix );
394 8adff592 2005-03-19 fw return true;
395 9e18ec30 2002-01-07 alex }
396 1c8c92af 2002-01-05 alex
397 fc1118cb 2003-01-12 alex /* Forward status code */
398 695631b2 2002-12-26 alex strlcpy( str, Req->command, sizeof( str ));
399 1c8c92af 2002-01-05 alex for( i = 0; i < Req->argc; i++ )
400 1c8c92af 2002-01-05 alex {
401 6626395c 2002-12-26 alex if( i < Req->argc - 1 ) strlcat( str, " ", sizeof( str ));
402 6626395c 2002-12-26 alex else strlcat( str, " :", sizeof( str ));
403 6626395c 2002-12-26 alex strlcat( str, Req->argv[i], sizeof( str ));
404 1c8c92af 2002-01-05 alex }
405 ec474a4b 2002-10-04 alex return IRC_WriteStrClientPrefix( target, prefix, "%s", str );
406 1c8c92af 2002-01-05 alex }
407 1c8c92af 2002-01-05 alex
408 1e59617d 2002-11-30 alex cmd = My_Commands;
409 1e59617d 2002-11-30 alex while( cmd->name )
410 1e59617d 2002-11-30 alex {
411 1e59617d 2002-11-30 alex /* Befehl suchen */
412 1e59617d 2002-11-30 alex if( strcasecmp( Req->command, cmd->name ) != 0 )
413 1e59617d 2002-11-30 alex {
414 1e59617d 2002-11-30 alex cmd++; continue;
415 1e59617d 2002-11-30 alex }
416 1e59617d 2002-11-30 alex
417 1e59617d 2002-11-30 alex if( Client_Type( client ) & cmd->type )
418 1e59617d 2002-11-30 alex {
419 17f7c6d3 2002-12-18 alex /* Command is allowed for this client: call it and count produced bytes */
420 17f7c6d3 2002-12-18 alex Conn_ResetWCounter( );
421 17f7c6d3 2002-12-18 alex result = (cmd->function)( client, Req );
422 17f7c6d3 2002-12-18 alex cmd->bytes += Conn_WCounter( );
423 17f7c6d3 2002-12-18 alex
424 17f7c6d3 2002-12-18 alex /* Adjust counters */
425 17f7c6d3 2002-12-18 alex if( Client_Type( client ) != CLIENT_SERVER ) cmd->lcount++;
426 17f7c6d3 2002-12-18 alex else cmd->rcount++;
427 17f7c6d3 2002-12-18 alex
428 17f7c6d3 2002-12-18 alex return result;
429 1e59617d 2002-11-30 alex }
430 1e59617d 2002-11-30 alex else
431 1e59617d 2002-11-30 alex {
432 1e59617d 2002-11-30 alex /* Befehl ist fuer diesen Client-Typ nicht erlaubt! */
433 1e59617d 2002-11-30 alex return IRC_WriteStrClient( client, ERR_NOTREGISTERED_MSG, Client_ID( client ));
434 1e59617d 2002-11-30 alex }
435 1e59617d 2002-11-30 alex }
436 d1ac4039 2002-09-03 alex
437 76c4f066 2001-12-23 alex /* Unbekannter Befehl */
438 3d2e9448 2002-01-05 alex Log( LOG_DEBUG, "Connection %d: Unknown command \"%s\", %d %s,%s prefix.", Client_Conn( client ), Req->command, Req->argc, Req->argc == 1 ? "parameter" : "parameters", Req->prefix ? "" : " no" );
439 1e59617d 2002-11-30 alex if( Client_Type( client ) != CLIENT_SERVER ) return IRC_WriteStrClient( client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( client ), Req->command );
440 8adff592 2005-03-19 fw else return true;
441 6e07fb41 2001-12-21 alex } /* Handle_Request */
442 6e07fb41 2001-12-21 alex
443 6e07fb41 2001-12-21 alex
444 6e07fb41 2001-12-21 alex /* -eof- */