Blame


1 38b9cb88 2001-12-14 alex /*
2 38b9cb88 2001-12-14 alex * ngIRCd -- The Next Generation IRC Daemon
3 03d971d9 2002-01-02 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
4 38b9cb88 2001-12-14 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 38b9cb88 2001-12-14 alex *
11 490f28ff 2002-12-12 alex * IRC commands
12 38b9cb88 2001-12-14 alex */
13 38b9cb88 2001-12-14 alex
14 38b9cb88 2001-12-14 alex
15 ca33cbda 2002-03-12 alex #include "portab.h"
16 38b9cb88 2001-12-14 alex
17 42c4e6c7 2003-01-13 alex static char UNUSED id[] = "$Id: irc.c,v 1.117 2003/01/13 18:56:30 alex Exp $";
18 490f28ff 2002-12-12 alex
19 ca33cbda 2002-03-12 alex #include "imp.h"
20 38b9cb88 2001-12-14 alex #include <assert.h>
21 44a2b3cf 2002-12-12 alex #include <stdio.h>
22 2a13cd22 2001-12-23 alex #include <string.h>
23 38b9cb88 2001-12-14 alex
24 42c4e6c7 2003-01-13 alex #include "ngircd.h"
25 42c4e6c7 2003-01-13 alex #include "conn.h"
26 42c4e6c7 2003-01-13 alex #include "resolve.h"
27 42c4e6c7 2003-01-13 alex #include "conf.h"
28 b8d7dcec 2002-12-30 alex #include "conn-func.h"
29 2a13cd22 2001-12-23 alex #include "client.h"
30 c2f60abe 2002-05-27 alex #include "channel.h"
31 0c471b84 2002-11-30 alex #include "defines.h"
32 ef7f7a90 2002-02-27 alex #include "irc-write.h"
33 2a13cd22 2001-12-23 alex #include "log.h"
34 2a13cd22 2001-12-23 alex #include "messages.h"
35 c2f60abe 2002-05-27 alex #include "parse.h"
36 2a13cd22 2001-12-23 alex
37 ca33cbda 2002-03-12 alex #include "exp.h"
38 38b9cb88 2001-12-14 alex #include "irc.h"
39 38b9cb88 2001-12-14 alex
40 38b9cb88 2001-12-14 alex
41 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
42 0c471b84 2002-11-30 alex IRC_ERROR( CLIENT *Client, REQUEST *Req )
43 bbfe9e8b 2001-12-25 alex {
44 bbfe9e8b 2001-12-25 alex assert( Client != NULL );
45 bbfe9e8b 2001-12-25 alex assert( Req != NULL );
46 bbfe9e8b 2001-12-25 alex
47 0c471b84 2002-11-30 alex if( Req->argc < 1 ) Log( LOG_NOTICE, "Got ERROR from \"%s\"!", Client_Mask( Client ));
48 0c471b84 2002-11-30 alex else Log( LOG_NOTICE, "Got ERROR from \"%s\": %s!", Client_Mask( Client ), Req->argv[0] );
49 45d447d9 2001-12-25 alex
50 0c471b84 2002-11-30 alex return CONNECTED;
51 0c471b84 2002-11-30 alex } /* IRC_ERROR */
52 1fd9216c 2002-11-24 alex
53 1fd9216c 2002-11-24 alex
54 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
55 0c471b84 2002-11-30 alex IRC_KILL( CLIENT *Client, REQUEST *Req )
56 72ebf4f2 2001-12-27 alex {
57 0c471b84 2002-11-30 alex CLIENT *prefix, *c;
58 b99af4fa 2002-12-06 alex CHAR reason[COMMAND_LEN];
59 01b58a05 2002-12-31 alex CONN_ID my_conn, conn;
60 0c471b84 2002-11-30 alex
61 72ebf4f2 2001-12-27 alex assert( Client != NULL );
62 72ebf4f2 2001-12-27 alex assert( Req != NULL );
63 72ebf4f2 2001-12-27 alex
64 4d2f279d 2002-12-26 alex /* Is the user an IRC operator? */
65 b99af4fa 2002-12-06 alex if(( Client_Type( Client ) != CLIENT_SERVER ) && ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
66 b99af4fa 2002-12-06 alex
67 4d2f279d 2002-12-26 alex /* Bad number of parameters? */
68 0c471b84 2002-11-30 alex if(( Req->argc != 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
69 72ebf4f2 2001-12-27 alex
70 b99af4fa 2002-12-06 alex if( Req->prefix ) prefix = Client_Search( Req->prefix );
71 b99af4fa 2002-12-06 alex else prefix = Client;
72 0c471b84 2002-11-30 alex if( ! prefix )
73 72ebf4f2 2001-12-27 alex {
74 0c471b84 2002-11-30 alex Log( LOG_WARNING, "Got KILL with invalid prefix: \"%s\"!", Req->prefix );
75 0c471b84 2002-11-30 alex prefix = Client_ThisServer( );
76 0c471b84 2002-11-30 alex }
77 c3d9c40a 2002-06-10 alex
78 1443bc38 2003-01-08 alex if( Client != Client_ThisServer( )) Log( LOG_NOTICE|LOG_snotice, "Got KILL command from \"%s\" for \"%s\": %s", Client_Mask( prefix ), Req->argv[0], Req->argv[1] );
79 3c01ac4e 2002-02-27 alex
80 4d2f279d 2002-12-26 alex /* Build reason string */
81 b316c380 2002-12-26 alex if( Client_Type( Client ) == CLIENT_USER ) snprintf( reason, sizeof( reason ), "KILLed by %s: %s", Client_ID( Client ), Req->argv[1] );
82 695631b2 2002-12-26 alex else strlcpy( reason, Req->argv[1], sizeof( reason ));
83 b99af4fa 2002-12-06 alex
84 4d2f279d 2002-12-26 alex /* Inform other servers */
85 b99af4fa 2002-12-06 alex IRC_WriteStrServersPrefix( Client, prefix, "KILL %s :%s", Req->argv[0], reason );
86 0c471b84 2002-11-30 alex
87 01b58a05 2002-12-31 alex /* Save ID of this connection */
88 01b58a05 2002-12-31 alex my_conn = Client_Conn( Client );
89 01b58a05 2002-12-31 alex
90 4d2f279d 2002-12-26 alex /* Do we host such a client? */
91 0c471b84 2002-11-30 alex c = Client_Search( Req->argv[0] );
92 0c471b84 2002-11-30 alex if( c )
93 0c471b84 2002-11-30 alex {
94 01bec0da 2002-12-27 alex /* Yes, there is such a client -- but is it a valid user? */
95 8340e426 2002-12-27 alex if( Client_Type( c ) == CLIENT_SERVER ) IRC_WriteStrClient( Client, ERR_CANTKILLSERVER_MSG, Client_ID( Client ));
96 8340e426 2002-12-27 alex else if( Client_Type( c ) != CLIENT_USER )IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
97 01bec0da 2002-12-27 alex else
98 01bec0da 2002-12-27 alex {
99 01bec0da 2002-12-27 alex /* Kill user NOW! */
100 01bec0da 2002-12-27 alex conn = Client_Conn( c );
101 01bec0da 2002-12-27 alex Client_Destroy( c, NULL, reason, FALSE );
102 9d82635b 2003-01-08 alex if( conn != NONE ) Conn_Close( conn, NULL, reason, TRUE );
103 01bec0da 2002-12-27 alex }
104 72ebf4f2 2001-12-27 alex }
105 0c471b84 2002-11-30 alex else Log( LOG_NOTICE, "Client with nick \"%s\" is unknown here.", Req->argv[0] );
106 92fb409f 2002-01-26 alex
107 4d2f279d 2002-12-26 alex /* Are we still connected or were we killed, too? */
108 1443bc38 2003-01-08 alex if(( my_conn > NONE ) && ( Client_GetFromConn( my_conn ))) return CONNECTED;
109 4d2f279d 2002-12-26 alex else return DISCONNECTED;
110 0c471b84 2002-11-30 alex } /* IRC_KILL */
111 cd6e4049 2002-02-27 alex
112 72ebf4f2 2001-12-27 alex
113 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
114 c2f60abe 2002-05-27 alex IRC_NOTICE( CLIENT *Client, REQUEST *Req )
115 72ebf4f2 2001-12-27 alex {
116 db58d347 2002-01-05 alex CLIENT *to, *from;
117 72ebf4f2 2001-12-27 alex
118 72ebf4f2 2001-12-27 alex assert( Client != NULL );
119 72ebf4f2 2001-12-27 alex assert( Req != NULL );
120 72ebf4f2 2001-12-27 alex
121 1e83e666 2002-10-09 alex if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return CONNECTED;
122 72ebf4f2 2001-12-27 alex
123 72ebf4f2 2001-12-27 alex /* Falsche Anzahl Parameter? */
124 72ebf4f2 2001-12-27 alex if( Req->argc != 2 ) return CONNECTED;
125 db58d347 2002-01-05 alex
126 c7408364 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
127 db58d347 2002-01-05 alex else from = Client;
128 c2ee5437 2002-01-11 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
129 72ebf4f2 2001-12-27 alex
130 72ebf4f2 2001-12-27 alex to = Client_Search( Req->argv[0] );
131 9fd8254a 2002-06-11 alex if(( to ) && ( Client_Type( to ) == CLIENT_USER ))
132 72ebf4f2 2001-12-27 alex {
133 72ebf4f2 2001-12-27 alex /* Okay, Ziel ist ein User */
134 db58d347 2002-01-05 alex return IRC_WriteStrClientPrefix( to, from, "NOTICE %s :%s", Client_ID( to ), Req->argv[1] );
135 72ebf4f2 2001-12-27 alex }
136 db58d347 2002-01-05 alex else return CONNECTED;
137 72ebf4f2 2001-12-27 alex } /* IRC_NOTICE */
138 72ebf4f2 2001-12-27 alex
139 72ebf4f2 2001-12-27 alex
140 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
141 0c471b84 2002-11-30 alex IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
142 fb9d6ce1 2001-12-31 alex {
143 0c471b84 2002-11-30 alex CLIENT *cl, *from;
144 180095be 2002-02-27 alex CHANNEL *chan;
145 fb9d6ce1 2001-12-31 alex
146 fb9d6ce1 2001-12-31 alex assert( Client != NULL );
147 fb9d6ce1 2001-12-31 alex assert( Req != NULL );
148 fb9d6ce1 2001-12-31 alex
149 fb9d6ce1 2001-12-31 alex /* Falsche Anzahl Parameter? */
150 0c471b84 2002-11-30 alex if( Req->argc == 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
151 0c471b84 2002-11-30 alex if( Req->argc == 1 ) return IRC_WriteStrClient( Client, ERR_NOTEXTTOSEND_MSG, Client_ID( Client ));
152 180095be 2002-02-27 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
153 fb9d6ce1 2001-12-31 alex
154 c7408364 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
155 180095be 2002-02-27 alex else from = Client;
156 0c471b84 2002-11-30 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
157 180095be 2002-02-27 alex
158 0c471b84 2002-11-30 alex cl = Client_Search( Req->argv[0] );
159 0c471b84 2002-11-30 alex if( cl )
160 180095be 2002-02-27 alex {
161 0c471b84 2002-11-30 alex /* Okay, Ziel ist ein Client. Aber ist es auch ein User? */
162 0c471b84 2002-11-30 alex if( Client_Type( cl ) != CLIENT_USER ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
163 180095be 2002-02-27 alex
164 0c471b84 2002-11-30 alex /* Okay, Ziel ist ein User */
165 0c471b84 2002-11-30 alex if(( Client_Type( Client ) != CLIENT_SERVER ) && ( strchr( Client_Modes( cl ), 'a' )))
166 180095be 2002-02-27 alex {
167 0c471b84 2002-11-30 alex /* Ziel-User ist AWAY: Meldung verschicken */
168 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( cl ), Client_Away( cl ))) return DISCONNECTED;
169 eab20bee 2002-01-29 alex }
170 eab20bee 2002-01-29 alex
171 0c471b84 2002-11-30 alex /* Text senden */
172 0c471b84 2002-11-30 alex if( Client_Conn( from ) > NONE ) Conn_UpdateIdle( Client_Conn( from ));
173 0c471b84 2002-11-30 alex return IRC_WriteStrClientPrefix( cl, from, "PRIVMSG %s :%s", Client_ID( cl ), Req->argv[1] );
174 eab20bee 2002-01-29 alex }
175 804b1ec4 2001-12-31 alex
176 0c471b84 2002-11-30 alex chan = Channel_Search( Req->argv[0] );
177 0c471b84 2002-11-30 alex if( chan ) return Channel_Write( chan, from, Client, Req->argv[1] );
178 804b1ec4 2001-12-31 alex
179 0c471b84 2002-11-30 alex return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
180 0c471b84 2002-11-30 alex } /* IRC_PRIVMSG */
181 804b1ec4 2001-12-31 alex
182 804b1ec4 2001-12-31 alex
183 42c4e6c7 2003-01-13 alex GLOBAL BOOLEAN
184 42c4e6c7 2003-01-13 alex IRC_TRACE( CLIENT *Client, REQUEST *Req )
185 42c4e6c7 2003-01-13 alex {
186 42c4e6c7 2003-01-13 alex CLIENT *from, *target;
187 42c4e6c7 2003-01-13 alex CONN_ID idx, idx2;
188 42c4e6c7 2003-01-13 alex CHAR ver[64], *ptr;
189 42c4e6c7 2003-01-13 alex
190 42c4e6c7 2003-01-13 alex assert( Client != NULL );
191 42c4e6c7 2003-01-13 alex assert( Req != NULL );
192 42c4e6c7 2003-01-13 alex
193 42c4e6c7 2003-01-13 alex /* Bad number of arguments? */
194 42c4e6c7 2003-01-13 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
195 42c4e6c7 2003-01-13 alex
196 42c4e6c7 2003-01-13 alex /* Search sender */
197 42c4e6c7 2003-01-13 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
198 42c4e6c7 2003-01-13 alex else from = Client;
199 42c4e6c7 2003-01-13 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
200 42c4e6c7 2003-01-13 alex
201 42c4e6c7 2003-01-13 alex /* Search target */
202 42c4e6c7 2003-01-13 alex if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
203 42c4e6c7 2003-01-13 alex else target = Client_ThisServer( );
204 42c4e6c7 2003-01-13 alex
205 42c4e6c7 2003-01-13 alex strlcpy( ver, NGIRCd_VersionAddition( ), sizeof( ver ));
206 42c4e6c7 2003-01-13 alex ptr = strchr( ver, '-' );
207 42c4e6c7 2003-01-13 alex if( ptr ) *ptr = '\0';
208 42c4e6c7 2003-01-13 alex
209 42c4e6c7 2003-01-13 alex /* Forward command to other server? */
210 42c4e6c7 2003-01-13 alex if( target != Client_ThisServer( ))
211 42c4e6c7 2003-01-13 alex {
212 42c4e6c7 2003-01-13 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
213 42c4e6c7 2003-01-13 alex
214 42c4e6c7 2003-01-13 alex /* Send RPL_TRACELINK back to initiator */
215 42c4e6c7 2003-01-13 alex idx = Client_Conn( Client ); assert( idx > NONE );
216 42c4e6c7 2003-01-13 alex idx2 = Client_Conn( Client_NextHop( target )); assert( idx2 > NONE );
217 42c4e6c7 2003-01-13 alex if( ! IRC_WriteStrClient( from, RPL_TRACELINK_MSG, Client_ID( from ), PACKAGE, VERSION, Client_ID( target ), Client_ID( Client_NextHop( target )), ver, time( NULL ) - Conn_StartTime( idx ), Conn_SendQ( idx ), Conn_SendQ( idx2 ))) return DISCONNECTED;
218 42c4e6c7 2003-01-13 alex
219 42c4e6c7 2003-01-13 alex /* Forward command */
220 42c4e6c7 2003-01-13 alex IRC_WriteStrClientPrefix( target, from, "TRACE %s", Req->argv[0] );
221 42c4e6c7 2003-01-13 alex return CONNECTED;
222 42c4e6c7 2003-01-13 alex }
223 42c4e6c7 2003-01-13 alex
224 42c4e6c7 2003-01-13 alex if( ! IRC_WriteStrClient( from, RPL_TRACESERVER_MSG, Client_ID( from ), Conf_ServerName, Client_Mask( Client_ThisServer( )), ver )) return DISCONNECTED;
225 42c4e6c7 2003-01-13 alex return IRC_WriteStrClient( from, RPL_TRACEEND_MSG, Client_ID( from ), Conf_ServerName, PACKAGE, VERSION, NGIRCd_DebugLevel );
226 42c4e6c7 2003-01-13 alex } /* IRC_TRACE */
227 42c4e6c7 2003-01-13 alex
228 42c4e6c7 2003-01-13 alex
229 38b9cb88 2001-12-14 alex /* -eof- */