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
24 #include "conn-func.h"
28 #include "irc-write.h"
39 * Handle invalid received OPER command.
40 * Log OPER attempt and send error message to client.
43 Bad_OperPass(CLIENT *Client, char *errtoken, char *errmsg)
45 Log(LOG_WARNING, "Got invalid OPER from \"%s\": \"%s\" -- %s",
46 Client_Mask(Client), errtoken, errmsg);
47 IRC_SetPenalty(Client, 3);
48 return IRC_WriteStrClient(Client, ERR_PASSWDMISMATCH_MSG,
54 * Check that the client is an IRC operator allowed to administer this server.
57 Check_Oper(CLIENT * Client)
59 if (!Client_HasMode(Client, 'o'))
61 if (!Client_OperByMe(Client) && !Conf_AllowRemoteOper)
63 /* The client is an local IRC operator, or this server is configured
64 * to trust remote operators. */
70 * Return and log a "no privileges" message.
73 No_Privileges(CLIENT * Client, REQUEST * Req)
75 Log(LOG_NOTICE, "No privileges: client \"%s\", command \"%s\"",
76 Client_Mask(Client), Req->command);
77 return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
79 } /* PermissionDenied */
83 IRC_OPER( CLIENT *Client, REQUEST *Req )
87 assert( Client != NULL );
88 assert( Req != NULL );
90 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
92 for( i = 0; i < Conf_Oper_Count; i++)
94 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
96 if( i >= Conf_Oper_Count )
97 return Bad_OperPass(Client, Req->argv[0], "not configured");
99 if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
100 return Bad_OperPass(Client, Conf_Oper[i].name, "bad password");
102 if( Conf_Oper[i].mask && (! Match( Conf_Oper[i].mask, Client_Mask( Client ) )))
103 return Bad_OperPass(Client, Conf_Oper[i].mask, "hostmask check failed" );
105 if( ! Client_HasMode( Client, 'o' ))
107 Client_ModeAdd( Client, 'o' );
108 if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
109 IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
112 if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
114 Client_SetOperByMe( Client, true);
115 return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
120 IRC_DIE(CLIENT * Client, REQUEST * Req)
122 /* Shut down server */
127 assert(Client != NULL);
130 if (!Check_Oper(Client))
131 return No_Privileges(Client, Req);
133 /* Bad number of parameters? */
139 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
140 Client_ID(Client), Req->command);
142 /* Is a message given? */
146 cl = Conn_GetClient(c);
147 if (Client_Type(cl) == CLIENT_USER)
148 IRC_WriteStrClient(cl, "NOTICE %s :%s",
149 Client_ID(cl), Req->argv[0]);
154 Log(LOG_NOTICE | LOG_snotice, "Got DIE command from \"%s\" ...",
155 Client_Mask(Client));
156 NGIRCd_SignalQuit = true;
163 IRC_REHASH( CLIENT *Client, REQUEST *Req )
165 /* Reload configuration file */
167 assert( Client != NULL );
168 assert( Req != NULL );
170 if (!Check_Oper(Client))
171 return No_Privileges(Client, Req);
173 /* Bad number of parameters? */
174 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
176 Log( LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\" ...", Client_Mask( Client ));
177 NGIRCd_SignalRehash = true;
184 IRC_RESTART( CLIENT *Client, REQUEST *Req )
186 /* Restart IRC server (fork a new process) */
188 assert( Client != NULL );
189 assert( Req != NULL );
191 if (!Check_Oper(Client))
192 return No_Privileges(Client, Req);
194 /* Bad number of parameters? */
195 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
197 Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\" ...", Client_Mask( Client ));
198 NGIRCd_SignalRestart = true;
204 * Connect configured or new server.
207 IRC_CONNECT(CLIENT * Client, REQUEST * Req)
210 assert(Client != NULL);
213 if (!Check_Oper(Client))
214 return No_Privileges(Client, Req);
216 /* Bad number of parameters? */
217 if ((Req->argc != 1) && (Req->argc != 2) && (Req->argc != 5))
218 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
219 Client_ID(Client), Req->command);
221 /* Invalid port number? */
222 if ((Req->argc > 1) && atoi(Req->argv[1]) < 1)
223 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
224 Client_ID(Client), Req->command);
226 Log(LOG_NOTICE | LOG_snotice,
227 "Got CONNECT command from \"%s\" for \"%s\".", Client_Mask(Client),
232 if (!Conf_EnablePassiveServer(Req->argv[0]))
233 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
238 /* Connect configured server */
239 if (!Conf_EnableServer
240 (Req->argv[0], (UINT16) atoi(Req->argv[1])))
241 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
248 (Req->argv[0], (UINT16) atoi(Req->argv[1]), Req->argv[2],
249 Req->argv[3], Req->argv[4]))
250 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
260 * Disconnect (and disable) configured server.
263 IRC_DISCONNECT(CLIENT * Client, REQUEST * Req)
267 assert(Client != NULL);
270 if (!Check_Oper(Client))
271 return No_Privileges(Client, Req);
273 /* Bad number of parameters? */
275 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
276 Client_ID(Client), Req->command);
278 Log(LOG_NOTICE | LOG_snotice,
279 "Got DISCONNECT command from \"%s\" for \"%s\".",
280 Client_Mask(Client), Req->argv[0]);
282 /* Save ID of this connection */
283 my_conn = Client_Conn(Client);
285 /* Disconnect configured server */
286 if (!Conf_DisableServer(Req->argv[0]))
287 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
288 Client_ID(Client), Req->argv[0]);
290 /* Are we still connected or were we killed, too? */
291 if (Conn_GetClient(my_conn))
295 } /* IRC_DISCONNECT */
299 IRC_WALLOPS( CLIENT *Client, REQUEST *Req )
303 assert( Client != NULL );
304 assert( Req != NULL );
307 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command);
309 switch (Client_Type(Client)) {
311 if (!Client_OperByMe(Client))
312 return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG, Client_ID(Client));
316 from = Client_Search(Req->prefix);
323 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID(Client), Req->prefix);
325 IRC_SendWallops(Client, from, Req->argv[0]);