2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2008 Alexander Barton (alex@barton.de)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
11 * IRC operator commands
25 #include "conn-func.h"
29 #include "irc-write.h"
40 * Handle invalid received OPER command.
41 * Log OPER attempt and send error message to client.
44 Bad_OperPass(CLIENT *Client, char *errtoken, char *errmsg)
46 Log(LOG_WARNING, "Got invalid OPER from \"%s\": \"%s\" -- %s",
47 Client_Mask(Client), errtoken, errmsg);
48 IRC_SetPenalty(Client, 3);
49 return IRC_WriteStrClient(Client, ERR_PASSWDMISMATCH_MSG,
55 * Check that the client is an IRC operator allowed to administer this server.
58 Check_Oper(CLIENT * Client)
60 if (!Client_HasMode(Client, 'o'))
62 if (!Client_OperByMe(Client) && !Conf_AllowRemoteOper)
64 /* The client is an local IRC operator, or this server is configured
65 * to trust remote operators. */
71 * Return and log a "no privileges" message.
74 No_Privileges(CLIENT * Client, REQUEST * Req)
79 from = Client_Search(Req->prefix);
82 Log(LOG_NOTICE, "No privileges: client \"%s\" (%s), command \"%s\"",
83 Req->prefix, Client_Mask(Client), Req->command);
84 return IRC_WriteStrClient(from, ERR_NOPRIVILEGES_MSG,
87 Log(LOG_NOTICE, "No privileges: client \"%s\", command \"%s\"",
88 Client_Mask(Client), Req->command);
89 return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
92 } /* PermissionDenied */
96 IRC_OPER( CLIENT *Client, REQUEST *Req )
100 assert( Client != NULL );
101 assert( Req != NULL );
103 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
105 for( i = 0; i < Conf_Oper_Count; i++)
107 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
109 if( i >= Conf_Oper_Count )
110 return Bad_OperPass(Client, Req->argv[0], "not configured");
112 if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
113 return Bad_OperPass(Client, Conf_Oper[i].name, "bad password");
115 if( Conf_Oper[i].mask && (! Match( Conf_Oper[i].mask, Client_Mask( Client ) )))
116 return Bad_OperPass(Client, Conf_Oper[i].mask, "hostmask check failed" );
118 if( ! Client_HasMode( Client, 'o' ))
120 Client_ModeAdd( Client, 'o' );
121 if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
122 IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
125 if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
127 Client_SetOperByMe( Client, true);
128 return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
133 IRC_DIE(CLIENT * Client, REQUEST * Req)
135 /* Shut down server */
140 assert(Client != NULL);
143 if (!Check_Oper(Client))
144 return No_Privileges(Client, Req);
146 /* Bad number of parameters? */
152 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
153 Client_ID(Client), Req->command);
155 /* Is a message given? */
159 cl = Conn_GetClient(c);
160 if (Client_Type(cl) == CLIENT_USER)
161 IRC_WriteStrClient(cl, "NOTICE %s :%s",
162 Client_ID(cl), Req->argv[0]);
167 Log(LOG_NOTICE | LOG_snotice, "Got DIE command from \"%s\" ...",
168 Client_Mask(Client));
169 NGIRCd_SignalQuit = true;
176 IRC_REHASH( CLIENT *Client, REQUEST *Req )
178 /* Reload configuration file */
180 assert( Client != NULL );
181 assert( Req != NULL );
183 if (!Check_Oper(Client))
184 return No_Privileges(Client, Req);
186 /* Bad number of parameters? */
187 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
189 Log( LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\" ...", Client_Mask( Client ));
190 NGIRCd_SignalRehash = true;
197 IRC_RESTART( CLIENT *Client, REQUEST *Req )
199 /* Restart IRC server (fork a new process) */
201 assert( Client != NULL );
202 assert( Req != NULL );
204 if (!Check_Oper(Client))
205 return No_Privileges(Client, Req);
207 /* Bad number of parameters? */
208 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
210 Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\" ...", Client_Mask( Client ));
211 NGIRCd_SignalRestart = true;
217 * Connect configured or new server.
220 IRC_CONNECT(CLIENT * Client, REQUEST * Req)
222 assert(Client != NULL);
225 if (!Check_Oper(Client))
226 return No_Privileges(Client, Req);
228 /* Bad number of parameters? */
229 if ((Req->argc != 1) && (Req->argc != 2) && (Req->argc != 5))
230 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
231 Client_ID(Client), Req->command);
233 /* Invalid port number? */
234 if ((Req->argc > 1) && atoi(Req->argv[1]) < 1)
235 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
236 Client_ID(Client), Req->command);
238 IRC_SendWallops(Client_ThisServer(), Client_ThisServer(),
239 "Received CONNECT %s from %s",
240 Req->argv[0], Client_ID(Client));
242 Log(LOG_NOTICE | LOG_snotice,
243 "Got CONNECT command from \"%s\" for \"%s\".", Client_Mask(Client),
248 if (!Conf_EnablePassiveServer(Req->argv[0]))
249 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
254 /* Connect configured server */
255 if (!Conf_EnableServer
256 (Req->argv[0], (UINT16) atoi(Req->argv[1])))
257 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
264 (Req->argv[0], (UINT16) atoi(Req->argv[1]), Req->argv[2],
265 Req->argv[3], Req->argv[4]))
266 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
276 * Disconnect (and disable) configured server.
279 IRC_DISCONNECT(CLIENT * Client, REQUEST * Req)
283 assert(Client != NULL);
286 if (!Check_Oper(Client))
287 return No_Privileges(Client, Req);
289 /* Bad number of parameters? */
291 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
292 Client_ID(Client), Req->command);
294 IRC_SendWallops(Client_ThisServer(), Client_ThisServer(),
295 "Received DISCONNECT %s from %s",
296 Req->argv[0], Client_ID(Client));
298 Log(LOG_NOTICE | LOG_snotice,
299 "Got DISCONNECT command from \"%s\" for \"%s\".",
300 Client_Mask(Client), Req->argv[0]);
302 /* Save ID of this connection */
303 my_conn = Client_Conn(Client);
305 /* Disconnect configured server */
306 if (!Conf_DisableServer(Req->argv[0]))
307 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
308 Client_ID(Client), Req->argv[0]);
310 /* Are we still connected or were we killed, too? */
311 if (Conn_GetClient(my_conn))
315 } /* IRC_DISCONNECT */
319 IRC_WALLOPS( CLIENT *Client, REQUEST *Req )
323 assert( Client != NULL );
324 assert( Req != NULL );
327 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command);
329 switch (Client_Type(Client)) {
331 if (!Client_OperByMe(Client))
332 return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG, Client_ID(Client));
336 from = Client_Search(Req->prefix);
343 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID(Client), Req->prefix);
345 IRC_SendWallops(Client, from, "%s", Req->argv[0]);