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
17 static char UNUSED id[] = "$Id: irc-oper.c,v 1.20 2005/03/19 18:43:48 fw Exp $";
30 #include "irc-write.h"
41 IRC_OPER( CLIENT *Client, REQUEST *Req )
45 assert( Client != NULL );
46 assert( Req != NULL );
48 /* Falsche Anzahl Parameter? */
49 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
52 for( i = 0; i < Conf_Oper_Count; i++)
54 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
56 if( i >= Conf_Oper_Count )
58 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Name \"%s\" not configured!", Client_Mask( Client ), Req->argv[0] );
59 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
62 /* Stimmt das Passwort? */
63 if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
65 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Bad password for \"%s\"!", Client_Mask( Client ), Conf_Oper[i].name );
66 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
69 /* Authorized Mask? */
70 if( Conf_Oper[i].mask && (! Match( Conf_Oper[i].mask, Client_Mask( Client ) ))) {
71 Log( LOG_WARNING, "Rejected valid OPER for \"%s\": Mask mismatch (got: \"%s\", want: \"%s\")!", Conf_Oper[i].name, Client_Mask( Client ), Conf_Oper[i].mask );
72 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
76 if( ! Client_HasMode( Client, 'o' ))
78 /* noch kein o-Mode gesetzt */
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 */
96 assert( Client != NULL );
97 assert( Req != NULL );
99 /* Not a local IRC operator? */
100 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
102 /* Bad number of parameters? */
103 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
105 Log( LOG_NOTICE|LOG_snotice, "Got DIE command from \"%s\" ...", Client_Mask( Client ));
106 NGIRCd_SignalQuit = true;
112 IRC_REHASH( CLIENT *Client, REQUEST *Req )
114 /* Reload configuration file */
116 assert( Client != NULL );
117 assert( Req != NULL );
119 /* Not a local IRC operator? */
120 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
122 /* Bad number of parameters? */
123 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
125 Log( LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\" ...", Client_Mask( Client ));
126 NGIRCd_SignalRehash = true;
133 IRC_RESTART( CLIENT *Client, REQUEST *Req )
135 /* Restart IRC server (fork a new process) */
137 assert( Client != NULL );
138 assert( Req != NULL );
140 /* Not a local IRC operator? */
141 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
143 /* Bad number of parameters? */
144 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
146 Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\" ...", Client_Mask( Client ));
147 NGIRCd_SignalRestart = true;
153 IRC_CONNECT(CLIENT *Client, REQUEST *Req )
155 /* Connect configured or new server */
157 assert( Client != NULL );
158 assert( Req != NULL );
160 /* Not a local IRC operator? */
161 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
163 /* Bad number of parameters? */
164 if(( Req->argc != 2 ) && ( Req->argc != 5 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
166 /* Invalid port number? */
167 if( atoi( Req->argv[1] ) < 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
169 Log( LOG_NOTICE|LOG_snotice, "Got CONNECT command from \"%s\" for \"%s\".", Client_Mask( Client ), Req->argv[0]);
173 /* Connect configured server */
174 if( ! Conf_EnableServer( Req->argv[0], atoi( Req->argv[1] ))) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
179 if( ! Conf_AddServer( Req->argv[0], atoi( Req->argv[1] ), Req->argv[2], Req->argv[3], Req->argv[4] )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
186 IRC_DISCONNECT(CLIENT *Client, REQUEST *Req )
188 /* Disconnect and disable configured server */
192 assert( Client != NULL );
193 assert( Req != NULL );
195 /* Not a local IRC operator? */
196 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
198 /* Bad number of parameters? */
199 if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
201 Log( LOG_NOTICE|LOG_snotice, "Got DISCONNECT command from \"%s\" for0 \"%s\".", Client_Mask( Client ), Req->argv[0]);
203 /* Save ID of this connection */
204 my_conn = Client_Conn( Client );
206 /* Connect configured server */
207 if( ! Conf_DisableServer( Req->argv[0] )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
209 /* Are we still connected or were we killed, too? */
210 if( Client_GetFromConn( my_conn )) return CONNECTED;
211 else return DISCONNECTED;