2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001,2002 by 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 Bad_OperPass(CLIENT *Client, char *errtoken, char *errmsg)
41 Log( LOG_WARNING, "Got invalid OPER from \"%s\": \"%s\" -- %s", Client_Mask( Client ),
43 IRC_SetPenalty(Client, 3);
44 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
49 IRC_OPER( CLIENT *Client, REQUEST *Req )
53 assert( Client != NULL );
54 assert( Req != NULL );
56 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
58 for( i = 0; i < Conf_Oper_Count; i++)
60 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
62 if( i >= Conf_Oper_Count )
63 return Bad_OperPass(Client, Req->argv[0], "not configured");
65 if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
66 return Bad_OperPass(Client, Conf_Oper[i].name, "Bad password");
68 if( Conf_Oper[i].mask && (! Match( Conf_Oper[i].mask, Client_Mask( Client ) )))
69 return Bad_OperPass(Client, Conf_Oper[i].mask, "hostmask check failed" );
71 if( ! Client_HasMode( Client, 'o' ))
73 Client_ModeAdd( Client, 'o' );
74 if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
75 IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
78 if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
80 Client_SetOperByMe( Client, true);
81 return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
86 IRC_DIE(CLIENT * Client, REQUEST * Req)
88 /* Shut down server */
93 assert(Client != NULL);
96 /* Not a local IRC operator? */
97 if ((!Client_HasMode(Client, 'o')) || (!Client_OperByMe(Client)))
98 return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
101 /* Bad number of parameters? */
107 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
108 Client_ID(Client), Req->command);
110 /* Is a message given? */
114 cl = Conn_GetClient(c);
115 if (Client_Type(cl) == CLIENT_USER)
116 IRC_WriteStrClient(cl, "NOTICE %s :%s",
117 Client_ID(cl), Req->argv[0]);
122 Log(LOG_NOTICE | LOG_snotice, "Got DIE command from \"%s\" ...",
123 Client_Mask(Client));
124 NGIRCd_SignalQuit = true;
131 IRC_REHASH( CLIENT *Client, REQUEST *Req )
133 /* Reload configuration file */
135 assert( Client != NULL );
136 assert( Req != NULL );
138 /* Not a local IRC operator? */
139 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
141 /* Bad number of parameters? */
142 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
144 Log( LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\" ...", Client_Mask( Client ));
145 NGIRCd_SignalRehash = true;
152 IRC_RESTART( CLIENT *Client, REQUEST *Req )
154 /* Restart IRC server (fork a new process) */
156 assert( Client != NULL );
157 assert( Req != NULL );
159 /* Not a local IRC operator? */
160 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
162 /* Bad number of parameters? */
163 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
165 Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\" ...", Client_Mask( Client ));
166 NGIRCd_SignalRestart = true;
172 * Connect configured or new server.
175 IRC_CONNECT(CLIENT * Client, REQUEST * Req)
178 assert(Client != NULL);
181 /* Not a local IRC operator? */
182 if ((!Client_HasMode(Client, 'o')) || (!Client_OperByMe(Client)))
183 return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
186 /* Bad number of parameters? */
187 if ((Req->argc != 1) && (Req->argc != 2) && (Req->argc != 5))
188 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
189 Client_ID(Client), Req->command);
191 /* Invalid port number? */
192 if ((Req->argc > 1) && atoi(Req->argv[1]) < 1)
193 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
194 Client_ID(Client), Req->command);
196 Log(LOG_NOTICE | LOG_snotice,
197 "Got CONNECT command from \"%s\" for \"%s\".", Client_Mask(Client),
202 if (!Conf_EnablePassiveServer(Req->argv[0]))
203 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
208 /* Connect configured server */
209 if (!Conf_EnableServer
210 (Req->argv[0], (UINT16) atoi(Req->argv[1])))
211 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
218 (Req->argv[0], (UINT16) atoi(Req->argv[1]), Req->argv[2],
219 Req->argv[3], Req->argv[4]))
220 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
230 IRC_DISCONNECT(CLIENT *Client, REQUEST *Req )
232 /* Disconnect and disable configured server */
236 assert( Client != NULL );
237 assert( Req != NULL );
239 /* Not a local IRC operator? */
240 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
242 /* Bad number of parameters? */
243 if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
245 Log( LOG_NOTICE|LOG_snotice, "Got DISCONNECT command from \"%s\" for0 \"%s\".", Client_Mask( Client ), Req->argv[0]);
247 /* Save ID of this connection */
248 my_conn = Client_Conn( Client );
250 /* Connect configured server */
251 if( ! Conf_DisableServer( Req->argv[0] )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
253 /* Are we still connected or were we killed, too? */
254 if( Conn_GetClient( my_conn )) return CONNECTED;
255 else return DISCONNECTED;
260 IRC_WALLOPS( CLIENT *Client, REQUEST *Req )
265 assert( Client != NULL );
266 assert( Req != NULL );
269 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command);
271 client_type = Client_Type(Client);
272 switch (client_type) {
274 if (!Client_OperByMe(Client))
275 return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG, Client_ID(Client));
279 from = Client_Search(Req->prefix);
286 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID(Client), Req->prefix);
288 for (to=Client_First(); to != NULL; to=Client_Next(to)) {
289 if (Client_Conn(to) < 0) /* no local connection or WALLOPS origin */
292 client_type = Client_Type(to);
293 switch (client_type) {
295 if (Client_HasMode(to, 'w'))
296 IRC_WriteStrClientPrefix(to, from, "WALLOPS :%s", Req->argv[0]);
300 IRC_WriteStrClientPrefix(to, from, "WALLOPS :%s", Req->argv[0]);