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.17 2002/12/31 16:10:55 alex Exp $";
30 #include "irc-write.h"
40 IRC_OPER( CLIENT *Client, REQUEST *Req )
44 assert( Client != NULL );
45 assert( Req != NULL );
47 /* Falsche Anzahl Parameter? */
48 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
51 for( i = 0; i < Conf_Oper_Count; i++)
53 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
55 if( i >= Conf_Oper_Count )
57 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Name \"%s\" not configured!", Client_Mask( Client ), Req->argv[0] );
58 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
61 /* Stimmt das Passwort? */
62 if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
64 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Bad password for \"%s\"!", Client_Mask( Client ), Conf_Oper[i].name );
65 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
68 if( ! Client_HasMode( Client, 'o' ))
70 /* noch kein o-Mode gesetzt */
71 Client_ModeAdd( Client, 'o' );
72 if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
73 IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
76 if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
78 Client_SetOperByMe( Client, TRUE );
79 return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
84 IRC_DIE( CLIENT *Client, REQUEST *Req )
86 /* Shut down server */
88 assert( Client != NULL );
89 assert( Req != NULL );
91 /* Not a local IRC operator? */
92 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
94 /* Bad number of parameters? */
95 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
97 Log( LOG_NOTICE|LOG_snotice, "Got DIE command from \"%s\" ...", Client_Mask( Client ));
98 NGIRCd_SignalQuit = TRUE;
104 IRC_REHASH( CLIENT *Client, REQUEST *Req )
106 /* Reload configuration file */
108 assert( Client != NULL );
109 assert( Req != NULL );
111 /* Not a local IRC operator? */
112 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
114 /* Bad number of parameters? */
115 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
117 Log( LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\" ...", Client_Mask( Client ));
118 NGIRCd_SignalRehash = TRUE;
125 IRC_RESTART( CLIENT *Client, REQUEST *Req )
127 /* Restart IRC server (fork a new process) */
129 assert( Client != NULL );
130 assert( Req != NULL );
132 /* Not a local IRC operator? */
133 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
135 /* Bad number of parameters? */
136 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
138 Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\" ...", Client_Mask( Client ));
139 NGIRCd_SignalRestart = TRUE;
145 IRC_CONNECT(CLIENT *Client, REQUEST *Req )
147 /* Connect configured or new server */
149 assert( Client != NULL );
150 assert( Req != NULL );
152 /* Not a local IRC operator? */
153 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
155 /* Bad number of parameters? */
156 if(( Req->argc != 2 ) && ( Req->argc != 5 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
158 /* Invalid port number? */
159 if( atoi( Req->argv[1] ) < 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
161 Log( LOG_NOTICE|LOG_snotice, "Got CONNECT command from \"%s\" for \"%s\".", Client_Mask( Client ), Req->argv[0]);
165 /* Connect configured server */
166 if( ! Conf_EnableServer( Req->argv[0], atoi( Req->argv[1] ))) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
171 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] );
178 IRC_DISCONNECT(CLIENT *Client, REQUEST *Req )
180 /* Disconnect and disable configured server */
184 assert( Client != NULL );
185 assert( Req != NULL );
187 /* Not a local IRC operator? */
188 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
190 /* Bad number of parameters? */
191 if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
193 Log( LOG_NOTICE|LOG_snotice, "Got DISCONNECT command from \"%s\" for0 \"%s\".", Client_Mask( Client ), Req->argv[0]);
195 /* Save ID of this connection */
196 my_conn = Client_Conn( Client );
198 /* Connect configured server */
199 if( ! Conf_DisableServer( Req->argv[0] )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
201 /* Are we still connected or were we killed, too? */
202 if( Client_GetFromConn( my_conn )) return CONNECTED;
203 else return DISCONNECTED;