Blob


1 /*
2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
4 *
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.
10 *
11 * IRC operator commands
12 */
15 #include "portab.h"
17 static char UNUSED id[] = "$Id: irc-oper.c,v 1.17 2002/12/31 16:10:55 alex Exp $";
19 #include "imp.h"
20 #include <assert.h>
21 #include <stdlib.h>
22 #include <string.h>
24 #include "ngircd.h"
25 #include "resolve.h"
26 #include "conn.h"
27 #include "conf.h"
28 #include "client.h"
29 #include "channel.h"
30 #include "irc-write.h"
31 #include "log.h"
32 #include "messages.h"
33 #include "parse.h"
35 #include <exp.h>
36 #include "irc-oper.h"
39 GLOBAL BOOLEAN
40 IRC_OPER( CLIENT *Client, REQUEST *Req )
41 {
42 INT i;
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 );
50 /* Operator suchen */
51 for( i = 0; i < Conf_Oper_Count; i++)
52 {
53 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
54 }
55 if( i >= Conf_Oper_Count )
56 {
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 ));
59 }
61 /* Stimmt das Passwort? */
62 if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
63 {
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 ));
66 }
68 if( ! Client_HasMode( Client, 'o' ))
69 {
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 ));
74 }
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 ));
80 } /* IRC_OPER */
83 GLOBAL BOOLEAN
84 IRC_DIE( CLIENT *Client, REQUEST *Req )
85 {
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;
99 return CONNECTED;
100 } /* IRC_DIE */
103 GLOBAL BOOLEAN
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;
120 return CONNECTED;
121 } /* IRC_REHASH */
124 GLOBAL BOOLEAN
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;
140 return CONNECTED;
141 } /* IRC_RESTART */
144 GLOBAL BOOLEAN
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]);
163 if( Req->argc == 2 )
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] );
168 else
170 /* Add server */
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] );
173 return CONNECTED;
174 } /* IRC_CONNECT */
177 GLOBAL BOOLEAN
178 IRC_DISCONNECT(CLIENT *Client, REQUEST *Req )
180 /* Disconnect and disable configured server */
182 CONN_ID my_conn;
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;
204 } /* IRC_CONNECT */
207 /* -eof- */