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"
27 #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 IRC_OPER( CLIENT *Client, REQUEST *Req )
59 assert( Client != NULL );
60 assert( Req != NULL );
62 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
64 len = array_length(&Conf_Opers, sizeof(*op));
65 op = array_start(&Conf_Opers);
66 for (i = 0; i < len && strcmp(op[i].name, Req->argv[0]); i++)
69 return Bad_OperPass(Client, Req->argv[0], "not configured");
71 if (strcmp(op[i].pwd, Req->argv[1]) != 0)
72 return Bad_OperPass(Client, op[i].name, "bad password");
74 if (op[i].mask && (!Match(op[i].mask, Client_Mask(Client))))
75 return Bad_OperPass(Client, op[i].mask, "hostmask check failed");
77 if( ! Client_HasMode( Client, 'o' ))
79 Client_ModeAdd( Client, 'o' );
80 if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
81 IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
84 if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
86 Client_SetOperByMe( Client, true);
87 return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
92 IRC_DIE(CLIENT * Client, REQUEST * Req)
94 /* Shut down server */
99 assert(Client != NULL);
102 if (!Op_Check(Client, Req))
103 return Op_NoPrivileges(Client, Req);
105 /* Bad number of parameters? */
111 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
112 Client_ID(Client), Req->command);
114 /* Is a message given? */
118 cl = Conn_GetClient(c);
119 if (Client_Type(cl) == CLIENT_USER)
120 IRC_WriteStrClient(cl, "NOTICE %s :%s",
121 Client_ID(cl), Req->argv[0]);
126 Log(LOG_NOTICE | LOG_snotice, "Got DIE command from \"%s\" ...",
127 Client_Mask(Client));
128 NGIRCd_SignalQuit = true;
135 IRC_REHASH( CLIENT *Client, REQUEST *Req )
137 /* Reload configuration file */
139 assert( Client != NULL );
140 assert( Req != NULL );
142 if (!Op_Check(Client, Req))
143 return Op_NoPrivileges(Client, Req);
145 /* Bad number of parameters? */
146 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
148 Log( LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\" ...", Client_Mask( Client ));
149 NGIRCd_SignalRehash = true;
156 IRC_RESTART( CLIENT *Client, REQUEST *Req )
158 /* Restart IRC server (fork a new process) */
160 assert( Client != NULL );
161 assert( Req != NULL );
163 if (!Op_Check(Client, Req))
164 return Op_NoPrivileges(Client, Req);
166 /* Bad number of parameters? */
167 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
169 Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\" ...", Client_Mask( Client ));
170 NGIRCd_SignalRestart = true;
176 * Connect configured or new server.
179 IRC_CONNECT(CLIENT * Client, REQUEST * Req)
181 CLIENT *from, *target;
183 assert(Client != NULL);
186 if (Client_Type(Client) != CLIENT_SERVER
187 && !Client_HasMode(Client, 'o'))
188 return Op_NoPrivileges(Client, Req);
190 /* Bad number of parameters? */
191 if (Req->argc != 1 && Req->argc != 2 && Req->argc != 3 &&
192 Req->argc != 5 && Req->argc != 6)
193 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
194 Client_ID(Client), Req->command);
196 /* Invalid port number? */
197 if ((Req->argc > 1) && atoi(Req->argv[1]) < 1)
198 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
199 Client_ID(Client), Req->command);
202 target = Client_ThisServer();
204 if (Req->argc == 3 || Req->argc == 6) {
205 /* This CONNECT has a target parameter */
206 if (Client_Type(Client) == CLIENT_SERVER && Req->prefix)
207 from = Client_Search(Req->prefix);
209 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
210 Client_ID(Client), Req->prefix);
212 target = (Req->argc == 3) ? Client_Search(Req->argv[2])
213 : Client_Search(Req->argv[5]);
214 if (! target || Client_Type(target) != CLIENT_SERVER)
215 return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
216 Client_ID(from), Req->argv[0]);
219 if (target != Client_ThisServer()) {
220 /* Forward CONNECT command ... */
222 IRC_WriteStrClientPrefix(target, from,
223 "CONNECT %s %s :%s", Req->argv[0],
224 Req->argv[1], Req->argv[2]);
226 IRC_WriteStrClientPrefix(target, from,
227 "CONNECT %s %s %s %s %s :%s", Req->argv[0],
228 Req->argv[1], Req->argv[2], Req->argv[3],
229 Req->argv[4], Req->argv[5]);
233 if (!Op_Check(from, Req))
234 return Op_NoPrivileges(Client, Req);
238 if (!Conf_EnablePassiveServer(Req->argv[0]))
239 return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
245 /* Connect configured server */
246 if (!Conf_EnableServer
247 (Req->argv[0], (UINT16) atoi(Req->argv[1])))
248 return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
255 (Req->argv[0], (UINT16) atoi(Req->argv[1]), Req->argv[2],
256 Req->argv[3], Req->argv[4]))
257 return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
262 Log(LOG_NOTICE | LOG_snotice,
263 "Got CONNECT command from \"%s\" for \"%s\".", Client_Mask(from),
265 IRC_SendWallops(Client_ThisServer(), Client_ThisServer(),
266 "Received CONNECT %s from %s",
267 Req->argv[0], Client_ID(from));
274 * Disconnect (and disable) configured server.
277 IRC_DISCONNECT(CLIENT * Client, REQUEST * Req)
281 assert(Client != NULL);
284 if (!Op_Check(Client, Req))
285 return Op_NoPrivileges(Client, Req);
287 /* Bad number of parameters? */
289 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
290 Client_ID(Client), Req->command);
292 IRC_SendWallops(Client_ThisServer(), Client_ThisServer(),
293 "Received DISCONNECT %s from %s",
294 Req->argv[0], Client_ID(Client));
296 Log(LOG_NOTICE | LOG_snotice,
297 "Got DISCONNECT command from \"%s\" for \"%s\".",
298 Client_Mask(Client), Req->argv[0]);
300 /* Save ID of this connection */
301 my_conn = Client_Conn(Client);
303 /* Disconnect configured server */
304 if (!Conf_DisableServer(Req->argv[0]))
305 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
306 Client_ID(Client), Req->argv[0]);
308 /* Are we still connected or were we killed, too? */
309 if (Conn_GetClient(my_conn))
313 } /* IRC_DISCONNECT */
317 IRC_WALLOPS( CLIENT *Client, REQUEST *Req )
321 assert( Client != NULL );
322 assert( Req != NULL );
325 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command);
327 switch (Client_Type(Client)) {
329 if (!Client_OperByMe(Client))
330 return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG, Client_ID(Client));
334 from = Client_Search(Req->prefix);
341 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID(Client), Req->prefix);
343 IRC_SendWallops(Client, from, "%s", Req->argv[0]);