2 2ee05c9a 2002-03-03 alex * ngIRCd -- The Next Generation IRC Daemon
3 2ee05c9a 2002-03-03 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
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.
11 490f28ff 2002-12-12 alex * IRC operator commands
15 ca33cbda 2002-03-12 alex #include "portab.h"
17 4b9e52eb 2007-08-02 fw static char UNUSED id[] = "$Id: irc-oper.c,v 1.29 2007/08/02 10:14:26 fw Exp $";
19 ca33cbda 2002-03-12 alex #include "imp.h"
20 2ee05c9a 2002-03-03 alex #include <assert.h>
21 4e485443 2003-12-31 alex #include <stdlib.h>
22 7d4e9a01 2002-04-04 alex #include <string.h>
24 2ee05c9a 2002-03-03 alex #include "ngircd.h"
25 c2f60abe 2002-05-27 alex #include "resolve.h"
26 3e8978d8 2006-07-23 alex #include "conn-func.h"
27 a2544e49 2003-12-30 alex #include "conf.h"
28 c2f60abe 2002-05-27 alex #include "client.h"
29 c2f60abe 2002-05-27 alex #include "channel.h"
30 2ee05c9a 2002-03-03 alex #include "irc-write.h"
31 2ee05c9a 2002-03-03 alex #include "log.h"
32 e7f87828 2005-03-03 alex #include "match.h"
33 2ee05c9a 2002-03-03 alex #include "messages.h"
34 c2f60abe 2002-05-27 alex #include "parse.h"
36 2ee05c9a 2002-03-03 alex #include <exp.h>
37 2ee05c9a 2002-03-03 alex #include "irc-oper.h"
41 fcf65bee 2005-06-12 fw Bad_OperPass(CLIENT *Client, char *errtoken, char *errmsg)
43 fcf65bee 2005-06-12 fw Log( LOG_WARNING, "Got invalid OPER from \"%s\": \"%s\" -- %s", Client_Mask( Client ),
44 fcf65bee 2005-06-12 fw errtoken, errmsg);
45 fcf65bee 2005-06-12 fw IRC_SetPenalty(Client, 3);
46 fcf65bee 2005-06-12 fw return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
51 c2f60abe 2002-05-27 alex IRC_OPER( CLIENT *Client, REQUEST *Req )
53 70facb7f 2005-07-11 fw unsigned int i;
55 2ee05c9a 2002-03-03 alex assert( Client != NULL );
56 2ee05c9a 2002-03-03 alex assert( Req != NULL );
58 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
59 2ee05c9a 2002-03-03 alex if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
61 2ee05c9a 2002-03-03 alex /* Operator suchen */
62 2ee05c9a 2002-03-03 alex for( i = 0; i < Conf_Oper_Count; i++)
64 2ee05c9a 2002-03-03 alex if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
66 2ee05c9a 2002-03-03 alex if( i >= Conf_Oper_Count )
67 fcf65bee 2005-06-12 fw return Bad_OperPass(Client, Req->argv[0], "not configured");
69 2ee05c9a 2002-03-03 alex /* Stimmt das Passwort? */
70 2ee05c9a 2002-03-03 alex if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
71 fcf65bee 2005-06-12 fw return Bad_OperPass(Client, Conf_Oper[i].name, "Bad password");
73 490c9d04 2005-03-02 alex /* Authorized Mask? */
74 74424cb1 2005-06-12 fw if( Conf_Oper[i].mask && (! Match( Conf_Oper[i].mask, Client_Mask( Client ) )))
75 fcf65bee 2005-06-12 fw return Bad_OperPass(Client, Conf_Oper[i].mask, "hostmask check failed" );
77 2ee05c9a 2002-03-03 alex if( ! Client_HasMode( Client, 'o' ))
79 2ee05c9a 2002-03-03 alex /* noch kein o-Mode gesetzt */
80 2ee05c9a 2002-03-03 alex Client_ModeAdd( Client, 'o' );
81 2ee05c9a 2002-03-03 alex if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
82 2ee05c9a 2002-03-03 alex IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
85 6b58ab84 2002-03-27 alex if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
87 8adff592 2005-03-19 fw Client_SetOperByMe( Client, true);
88 2ee05c9a 2002-03-03 alex return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
89 2ee05c9a 2002-03-03 alex } /* IRC_OPER */
93 3e8978d8 2006-07-23 alex IRC_DIE(CLIENT * Client, REQUEST * Req)
95 4e485443 2003-12-31 alex /* Shut down server */
100 3e8978d8 2006-07-23 alex assert(Client != NULL);
101 3e8978d8 2006-07-23 alex assert(Req != NULL);
103 4e485443 2003-12-31 alex /* Not a local IRC operator? */
104 3e8978d8 2006-07-23 alex if ((!Client_HasMode(Client, 'o')) || (!Client_OperByMe(Client)))
105 3e8978d8 2006-07-23 alex return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
106 3e8978d8 2006-07-23 alex Client_ID(Client));
108 4e485443 2003-12-31 alex /* Bad number of parameters? */
109 3e8978d8 2006-07-23 alex #ifdef STRICT_RFC
110 3e8978d8 2006-07-23 alex if (Req->argc != 0)
112 3e8978d8 2006-07-23 alex if (Req->argc > 1)
114 3e8978d8 2006-07-23 alex return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
115 3e8978d8 2006-07-23 alex Client_ID(Client), Req->command);
117 3e8978d8 2006-07-23 alex /* Is a message given? */
118 3e8978d8 2006-07-23 alex if (Req->argc > 0) {
119 3e8978d8 2006-07-23 alex c = Conn_First();
120 3e8978d8 2006-07-23 alex while (c != NONE) {
121 3e8978d8 2006-07-23 alex cl = Conn_GetClient(c);
122 3e8978d8 2006-07-23 alex if (Client_Type(cl) == CLIENT_USER)
123 3e8978d8 2006-07-23 alex IRC_WriteStrClient(cl, "NOTICE %s :%s",
124 3e8978d8 2006-07-23 alex Client_ID(cl), Req->argv[0]);
125 3e8978d8 2006-07-23 alex c = Conn_Next(c);
129 3e8978d8 2006-07-23 alex Log(LOG_NOTICE | LOG_snotice, "Got DIE command from \"%s\" ...",
130 3e8978d8 2006-07-23 alex Client_Mask(Client));
131 8adff592 2005-03-19 fw NGIRCd_SignalQuit = true;
133 2ee05c9a 2002-03-03 alex return CONNECTED;
134 2ee05c9a 2002-03-03 alex } /* IRC_DIE */
138 4eb57b59 2002-11-22 alex IRC_REHASH( CLIENT *Client, REQUEST *Req )
140 4e485443 2003-12-31 alex /* Reload configuration file */
142 a5c92290 2002-11-22 alex assert( Client != NULL );
143 a5c92290 2002-11-22 alex assert( Req != NULL );
145 4e485443 2003-12-31 alex /* Not a local IRC operator? */
146 a5c92290 2002-11-22 alex if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
148 4e485443 2003-12-31 alex /* Bad number of parameters? */
149 4e485443 2003-12-31 alex if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
151 15e4f674 2002-12-27 alex Log( LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\" ...", Client_Mask( Client ));
152 8adff592 2005-03-19 fw NGIRCd_SignalRehash = true;
154 a5c92290 2002-11-22 alex return CONNECTED;
155 4eb57b59 2002-11-22 alex } /* IRC_REHASH */
159 c2f60abe 2002-05-27 alex IRC_RESTART( CLIENT *Client, REQUEST *Req )
161 4e485443 2003-12-31 alex /* Restart IRC server (fork a new process) */
163 2ee05c9a 2002-03-03 alex assert( Client != NULL );
164 2ee05c9a 2002-03-03 alex assert( Req != NULL );
166 4e485443 2003-12-31 alex /* Not a local IRC operator? */
167 2ee05c9a 2002-03-03 alex if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
169 4e485443 2003-12-31 alex /* Bad number of parameters? */
170 4e485443 2003-12-31 alex if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
172 15e4f674 2002-12-27 alex Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\" ...", Client_Mask( Client ));
173 8adff592 2005-03-19 fw NGIRCd_SignalRestart = true;
174 2ee05c9a 2002-03-03 alex return CONNECTED;
175 2ee05c9a 2002-03-03 alex } /* IRC_RESTART */
179 dd3a3bc6 2006-05-10 alex * Connect configured or new server.
182 dd3a3bc6 2006-05-10 alex IRC_CONNECT(CLIENT * Client, REQUEST * Req)
185 dd3a3bc6 2006-05-10 alex assert(Client != NULL);
186 dd3a3bc6 2006-05-10 alex assert(Req != NULL);
188 4e485443 2003-12-31 alex /* Not a local IRC operator? */
189 dd3a3bc6 2006-05-10 alex if ((!Client_HasMode(Client, 'o')) || (!Client_OperByMe(Client)))
190 dd3a3bc6 2006-05-10 alex return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
191 dd3a3bc6 2006-05-10 alex Client_ID(Client));
193 4e485443 2003-12-31 alex /* Bad number of parameters? */
194 2275add3 2007-06-28 fw if ((Req->argc != 1) && (Req->argc != 2) && (Req->argc != 5))
195 dd3a3bc6 2006-05-10 alex return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
196 dd3a3bc6 2006-05-10 alex Client_ID(Client), Req->command);
198 4e485443 2003-12-31 alex /* Invalid port number? */
199 2275add3 2007-06-28 fw if ((Req->argc > 1) && atoi(Req->argv[1]) < 1)
200 dd3a3bc6 2006-05-10 alex return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
201 dd3a3bc6 2006-05-10 alex Client_ID(Client), Req->command);
203 dd3a3bc6 2006-05-10 alex Log(LOG_NOTICE | LOG_snotice,
204 dd3a3bc6 2006-05-10 alex "Got CONNECT command from \"%s\" for \"%s\".", Client_Mask(Client),
205 dd3a3bc6 2006-05-10 alex Req->argv[0]);
207 2275add3 2007-06-28 fw switch (Req->argc) {
209 2275add3 2007-06-28 fw if (!Conf_EnablePassiveServer(Req->argv[0]))
210 2275add3 2007-06-28 fw return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
211 2275add3 2007-06-28 fw Client_ID(Client),
212 2275add3 2007-06-28 fw Req->argv[0]);
215 4e485443 2003-12-31 alex /* Connect configured server */
216 dd3a3bc6 2006-05-10 alex if (!Conf_EnableServer
217 dd3a3bc6 2006-05-10 alex (Req->argv[0], (UINT16) atoi(Req->argv[1])))
218 dd3a3bc6 2006-05-10 alex return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
219 dd3a3bc6 2006-05-10 alex Client_ID(Client),
220 dd3a3bc6 2006-05-10 alex Req->argv[0]);
223 4e485443 2003-12-31 alex /* Add server */
224 dd3a3bc6 2006-05-10 alex if (!Conf_AddServer
225 dd3a3bc6 2006-05-10 alex (Req->argv[0], (UINT16) atoi(Req->argv[1]), Req->argv[2],
226 dd3a3bc6 2006-05-10 alex Req->argv[3], Req->argv[4]))
227 dd3a3bc6 2006-05-10 alex return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
228 dd3a3bc6 2006-05-10 alex Client_ID(Client),
229 dd3a3bc6 2006-05-10 alex Req->argv[0]);
232 1256f347 2002-09-03 alex return CONNECTED;
233 1256f347 2002-09-03 alex } /* IRC_CONNECT */
237 4e485443 2003-12-31 alex IRC_DISCONNECT(CLIENT *Client, REQUEST *Req )
239 4e485443 2003-12-31 alex /* Disconnect and disable configured server */
241 4e485443 2003-12-31 alex CONN_ID my_conn;
243 4e485443 2003-12-31 alex assert( Client != NULL );
244 4e485443 2003-12-31 alex assert( Req != NULL );
246 4e485443 2003-12-31 alex /* Not a local IRC operator? */
247 4e485443 2003-12-31 alex if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
249 4e485443 2003-12-31 alex /* Bad number of parameters? */
250 4e485443 2003-12-31 alex if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
252 4e485443 2003-12-31 alex Log( LOG_NOTICE|LOG_snotice, "Got DISCONNECT command from \"%s\" for0 \"%s\".", Client_Mask( Client ), Req->argv[0]);
254 4e485443 2003-12-31 alex /* Save ID of this connection */
255 4e485443 2003-12-31 alex my_conn = Client_Conn( Client );
257 4e485443 2003-12-31 alex /* Connect configured server */
258 4e485443 2003-12-31 alex if( ! Conf_DisableServer( Req->argv[0] )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
260 4e485443 2003-12-31 alex /* Are we still connected or were we killed, too? */
261 87f4b1c6 2006-04-23 fw if( Conn_GetClient( my_conn )) return CONNECTED;
262 4e485443 2003-12-31 alex else return DISCONNECTED;
263 4e485443 2003-12-31 alex } /* IRC_CONNECT */
267 4b9e52eb 2007-08-02 fw IRC_WALLOPS( CLIENT *Client, REQUEST *Req )
269 4b9e52eb 2007-08-02 fw CLIENT *to, *from;
270 4b9e52eb 2007-08-02 fw int client_type;
272 4b9e52eb 2007-08-02 fw assert( Client != NULL );
273 4b9e52eb 2007-08-02 fw assert( Req != NULL );
275 4b9e52eb 2007-08-02 fw if (Req->argc != 1)
276 4b9e52eb 2007-08-02 fw return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command);
278 4b9e52eb 2007-08-02 fw client_type = Client_Type(Client);
279 4b9e52eb 2007-08-02 fw switch (client_type) {
280 4b9e52eb 2007-08-02 fw case CLIENT_USER:
281 4b9e52eb 2007-08-02 fw if (!Client_OperByMe(Client))
282 4b9e52eb 2007-08-02 fw return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG, Client_ID(Client));
283 4b9e52eb 2007-08-02 fw from = Client;
285 4b9e52eb 2007-08-02 fw case CLIENT_SERVER:
286 4b9e52eb 2007-08-02 fw from = Client_Search(Req->prefix);
289 4b9e52eb 2007-08-02 fw return CONNECTED;
293 4b9e52eb 2007-08-02 fw return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID(Client), Req->prefix);
295 4b9e52eb 2007-08-02 fw for (to=Client_First(); to != NULL; to=Client_Next(to)) {
296 4b9e52eb 2007-08-02 fw if (Client_Conn(to) < 0) /* no local connection or WALLOPS origin */
299 4b9e52eb 2007-08-02 fw client_type = Client_Type(to);
300 4b9e52eb 2007-08-02 fw switch (client_type) {
301 4b9e52eb 2007-08-02 fw case CLIENT_USER:
302 4b9e52eb 2007-08-02 fw if (Client_HasMode(to, 'w'))
303 4b9e52eb 2007-08-02 fw IRC_WriteStrClientPrefix(to, from, "WALLOPS :%s", Req->argv[0]);
305 4b9e52eb 2007-08-02 fw case CLIENT_SERVER:
306 4b9e52eb 2007-08-02 fw if (to != Client)
307 4b9e52eb 2007-08-02 fw IRC_WriteStrClientPrefix(to, from, "WALLOPS :%s", Req->argv[0]);
311 4b9e52eb 2007-08-02 fw return CONNECTED;
316 2ee05c9a 2002-03-03 alex /* -eof- */