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.22 2005/06/12 18:02:09 fw 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 "match.h"
33 #include "messages.h"
34 #include "parse.h"
36 #include <exp.h>
37 #include "irc-oper.h"
40 LOCAL bool
41 Bad_OperPass(CLIENT *Client, char *errtoken, char *errmsg)
42 {
43 Log( LOG_WARNING, "Got invalid OPER from \"%s\": \"%s\" -- %s", Client_Mask( Client ),
44 errtoken, errmsg);
45 IRC_SetPenalty(Client, 3);
46 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
47 }
50 GLOBAL bool
51 IRC_OPER( CLIENT *Client, REQUEST *Req )
52 {
53 int i;
55 assert( Client != NULL );
56 assert( Req != NULL );
58 /* Falsche Anzahl Parameter? */
59 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
61 /* Operator suchen */
62 for( i = 0; i < Conf_Oper_Count; i++)
63 {
64 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
65 }
66 if( i >= Conf_Oper_Count )
67 return Bad_OperPass(Client, Req->argv[0], "not configured");
69 /* Stimmt das Passwort? */
70 if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
71 return Bad_OperPass(Client, Conf_Oper[i].name, "Bad password");
73 /* Authorized Mask? */
74 if( Conf_Oper[i].mask && (! Match( Conf_Oper[i].mask, Client_Mask( Client ) )))
75 return Bad_OperPass(Client, Conf_Oper[i].mask, "hostmask check failed" );
77 if( ! Client_HasMode( Client, 'o' ))
78 {
79 /* noch kein o-Mode gesetzt */
80 Client_ModeAdd( Client, 'o' );
81 if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
82 IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
83 }
85 if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
87 Client_SetOperByMe( Client, true);
88 return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
89 } /* IRC_OPER */
92 GLOBAL bool
93 IRC_DIE( CLIENT *Client, REQUEST *Req )
94 {
95 /* Shut down server */
97 assert( Client != NULL );
98 assert( Req != NULL );
100 /* Not a local IRC operator? */
101 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
103 /* Bad number of parameters? */
104 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
106 Log( LOG_NOTICE|LOG_snotice, "Got DIE command from \"%s\" ...", Client_Mask( Client ));
107 NGIRCd_SignalQuit = true;
108 return CONNECTED;
109 } /* IRC_DIE */
112 GLOBAL bool
113 IRC_REHASH( CLIENT *Client, REQUEST *Req )
115 /* Reload configuration file */
117 assert( Client != NULL );
118 assert( Req != NULL );
120 /* Not a local IRC operator? */
121 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
123 /* Bad number of parameters? */
124 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
126 Log( LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\" ...", Client_Mask( Client ));
127 NGIRCd_SignalRehash = true;
129 return CONNECTED;
130 } /* IRC_REHASH */
133 GLOBAL bool
134 IRC_RESTART( CLIENT *Client, REQUEST *Req )
136 /* Restart IRC server (fork a new process) */
138 assert( Client != NULL );
139 assert( Req != NULL );
141 /* Not a local IRC operator? */
142 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
144 /* Bad number of parameters? */
145 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
147 Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\" ...", Client_Mask( Client ));
148 NGIRCd_SignalRestart = true;
149 return CONNECTED;
150 } /* IRC_RESTART */
153 GLOBAL bool
154 IRC_CONNECT(CLIENT *Client, REQUEST *Req )
156 /* Connect configured or new server */
158 assert( Client != NULL );
159 assert( Req != NULL );
161 /* Not a local IRC operator? */
162 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
164 /* Bad number of parameters? */
165 if(( Req->argc != 2 ) && ( Req->argc != 5 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
167 /* Invalid port number? */
168 if( atoi( Req->argv[1] ) < 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
170 Log( LOG_NOTICE|LOG_snotice, "Got CONNECT command from \"%s\" for \"%s\".", Client_Mask( Client ), Req->argv[0]);
172 if( Req->argc == 2 )
174 /* Connect configured server */
175 if( ! Conf_EnableServer( Req->argv[0], atoi( Req->argv[1] ))) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
177 else
179 /* Add server */
180 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] );
182 return CONNECTED;
183 } /* IRC_CONNECT */
186 GLOBAL bool
187 IRC_DISCONNECT(CLIENT *Client, REQUEST *Req )
189 /* Disconnect and disable configured server */
191 CONN_ID my_conn;
193 assert( Client != NULL );
194 assert( Req != NULL );
196 /* Not a local IRC operator? */
197 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
199 /* Bad number of parameters? */
200 if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
202 Log( LOG_NOTICE|LOG_snotice, "Got DISCONNECT command from \"%s\" for0 \"%s\".", Client_Mask( Client ), Req->argv[0]);
204 /* Save ID of this connection */
205 my_conn = Client_Conn( Client );
207 /* Connect configured server */
208 if( ! Conf_DisableServer( Req->argv[0] )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
210 /* Are we still connected or were we killed, too? */
211 if( Client_GetFromConn( my_conn )) return CONNECTED;
212 else return DISCONNECTED;
213 } /* IRC_CONNECT */
216 /* -eof- */