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 * 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 )
58 assert( Client != NULL );
59 assert( Req != NULL );
61 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
63 for( i = 0; i < Conf_Oper_Count; i++)
65 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
67 if( i >= Conf_Oper_Count )
68 return Bad_OperPass(Client, Req->argv[0], "not configured");
70 if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
71 return Bad_OperPass(Client, Conf_Oper[i].name, "bad password");
73 if( Conf_Oper[i].mask && (! Match( Conf_Oper[i].mask, Client_Mask( Client ) )))
74 return Bad_OperPass(Client, Conf_Oper[i].mask, "hostmask check failed" );
76 if( ! Client_HasMode( Client, 'o' ))
78 Client_ModeAdd( Client, 'o' );
79 if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
80 IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
83 if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
85 Client_SetOperByMe( Client, true);
86 return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
91 IRC_DIE(CLIENT * Client, REQUEST * Req)
93 /* Shut down server */
98 assert(Client != NULL);
101 /* Not a local IRC operator? */
102 if ((!Client_HasMode(Client, 'o')) || (!Client_OperByMe(Client)))
103 return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
106 /* Bad number of parameters? */
112 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
113 Client_ID(Client), Req->command);
115 /* Is a message given? */
119 cl = Conn_GetClient(c);
120 if (Client_Type(cl) == CLIENT_USER)
121 IRC_WriteStrClient(cl, "NOTICE %s :%s",
122 Client_ID(cl), Req->argv[0]);
127 Log(LOG_NOTICE | LOG_snotice, "Got DIE command from \"%s\" ...",
128 Client_Mask(Client));
129 NGIRCd_SignalQuit = true;
136 IRC_REHASH( CLIENT *Client, REQUEST *Req )
138 /* Reload configuration file */
140 assert( Client != NULL );
141 assert( Req != NULL );
143 /* Not a local IRC operator? */
144 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
146 /* Bad number of parameters? */
147 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
149 Log( LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\" ...", Client_Mask( Client ));
150 NGIRCd_SignalRehash = true;
157 IRC_RESTART( CLIENT *Client, REQUEST *Req )
159 /* Restart IRC server (fork a new process) */
161 assert( Client != NULL );
162 assert( Req != NULL );
164 /* Not a local IRC operator? */
165 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
167 /* Bad number of parameters? */
168 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
170 Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\" ...", Client_Mask( Client ));
171 NGIRCd_SignalRestart = true;
177 * Connect configured or new server.
180 IRC_CONNECT(CLIENT * Client, REQUEST * Req)
183 assert(Client != NULL);
186 /* Not a local IRC operator? */
187 if ((!Client_HasMode(Client, 'o')) || (!Client_OperByMe(Client)))
188 return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
191 /* Bad number of parameters? */
192 if ((Req->argc != 1) && (Req->argc != 2) && (Req->argc != 5))
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);
201 Log(LOG_NOTICE | LOG_snotice,
202 "Got CONNECT command from \"%s\" for \"%s\".", Client_Mask(Client),
207 if (!Conf_EnablePassiveServer(Req->argv[0]))
208 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
213 /* Connect configured server */
214 if (!Conf_EnableServer
215 (Req->argv[0], (UINT16) atoi(Req->argv[1])))
216 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
223 (Req->argv[0], (UINT16) atoi(Req->argv[1]), Req->argv[2],
224 Req->argv[3], Req->argv[4]))
225 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
235 IRC_DISCONNECT(CLIENT *Client, REQUEST *Req )
237 /* Disconnect and disable configured server */
241 assert( Client != NULL );
242 assert( Req != NULL );
244 /* Not a local IRC operator? */
245 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
247 /* Bad number of parameters? */
248 if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
250 Log( LOG_NOTICE|LOG_snotice, "Got DISCONNECT command from \"%s\" for0 \"%s\".", Client_Mask( Client ), Req->argv[0]);
252 /* Save ID of this connection */
253 my_conn = Client_Conn( Client );
255 /* Connect configured server */
256 if( ! Conf_DisableServer( Req->argv[0] )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
258 /* Are we still connected or were we killed, too? */
259 if( Conn_GetClient( my_conn )) return CONNECTED;
260 else return DISCONNECTED;
265 IRC_WALLOPS( CLIENT *Client, REQUEST *Req )
270 assert( Client != NULL );
271 assert( Req != NULL );
274 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command);
276 client_type = Client_Type(Client);
277 switch (client_type) {
279 if (!Client_OperByMe(Client))
280 return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG, Client_ID(Client));
284 from = Client_Search(Req->prefix);
291 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID(Client), Req->prefix);
293 for (to=Client_First(); to != NULL; to=Client_Next(to)) {
294 if (Client_Conn(to) < 0) /* no local connection or WALLOPS origin */
297 client_type = Client_Type(to);
298 switch (client_type) {
300 if (Client_HasMode(to, 'w'))
301 IRC_WriteStrClientPrefix(to, from, "WALLOPS :%s", Req->argv[0]);
305 IRC_WriteStrClientPrefix(to, from, "WALLOPS :%s", Req->argv[0]);