2 2ee05c9a 2002-03-03 alex * ngIRCd -- The Next Generation IRC Daemon
3 2ee05c9a 2002-03-03 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
5 490f28ff 2002-12-12 alex * This program is free software; you can redistribute it and/or modify
6 490f28ff 2002-12-12 alex * it under the terms of the GNU General Public License as published by
7 490f28ff 2002-12-12 alex * the Free Software Foundation; either version 2 of the License, or
8 490f28ff 2002-12-12 alex * (at your option) any later version.
9 490f28ff 2002-12-12 alex * Please read the file COPYING, README and AUTHORS for more information.
11 490f28ff 2002-12-12 alex * IRC operator commands
15 ca33cbda 2002-03-12 alex #include "portab.h"
17 4e485443 2002-12-31 alex static char UNUSED id[] = "$Id: irc-oper.c,v 1.17 2002/12/31 16:10:55 alex Exp $";
19 ca33cbda 2002-03-12 alex #include "imp.h"
20 2ee05c9a 2002-03-03 alex #include <assert.h>
21 4e485443 2002-12-31 alex #include <stdlib.h>
22 7d4e9a01 2002-04-04 alex #include <string.h>
24 2ee05c9a 2002-03-03 alex #include "ngircd.h"
25 c2f60abe 2002-05-27 alex #include "resolve.h"
26 c2f60abe 2002-05-27 alex #include "conn.h"
27 a2544e49 2002-12-30 alex #include "conf.h"
28 c2f60abe 2002-05-27 alex #include "client.h"
29 c2f60abe 2002-05-27 alex #include "channel.h"
30 2ee05c9a 2002-03-03 alex #include "irc-write.h"
31 2ee05c9a 2002-03-03 alex #include "log.h"
32 2ee05c9a 2002-03-03 alex #include "messages.h"
33 c2f60abe 2002-05-27 alex #include "parse.h"
35 2ee05c9a 2002-03-03 alex #include <exp.h>
36 2ee05c9a 2002-03-03 alex #include "irc-oper.h"
39 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
40 c2f60abe 2002-05-27 alex IRC_OPER( CLIENT *Client, REQUEST *Req )
44 2ee05c9a 2002-03-03 alex assert( Client != NULL );
45 2ee05c9a 2002-03-03 alex assert( Req != NULL );
47 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
48 2ee05c9a 2002-03-03 alex if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
50 2ee05c9a 2002-03-03 alex /* Operator suchen */
51 2ee05c9a 2002-03-03 alex for( i = 0; i < Conf_Oper_Count; i++)
53 2ee05c9a 2002-03-03 alex if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
55 2ee05c9a 2002-03-03 alex if( i >= Conf_Oper_Count )
57 2ee05c9a 2002-03-03 alex Log( LOG_WARNING, "Got invalid OPER from \"%s\": Name \"%s\" not configured!", Client_Mask( Client ), Req->argv[0] );
58 2ee05c9a 2002-03-03 alex return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
61 2ee05c9a 2002-03-03 alex /* Stimmt das Passwort? */
62 2ee05c9a 2002-03-03 alex if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
64 2ee05c9a 2002-03-03 alex Log( LOG_WARNING, "Got invalid OPER from \"%s\": Bad password for \"%s\"!", Client_Mask( Client ), Conf_Oper[i].name );
65 2ee05c9a 2002-03-03 alex return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
68 2ee05c9a 2002-03-03 alex if( ! Client_HasMode( Client, 'o' ))
70 2ee05c9a 2002-03-03 alex /* noch kein o-Mode gesetzt */
71 2ee05c9a 2002-03-03 alex Client_ModeAdd( Client, 'o' );
72 2ee05c9a 2002-03-03 alex if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
73 2ee05c9a 2002-03-03 alex IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
76 6b58ab84 2002-03-27 alex if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
78 2ee05c9a 2002-03-03 alex Client_SetOperByMe( Client, TRUE );
79 2ee05c9a 2002-03-03 alex return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
80 2ee05c9a 2002-03-03 alex } /* IRC_OPER */
83 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
84 c2f60abe 2002-05-27 alex IRC_DIE( CLIENT *Client, REQUEST *Req )
86 4e485443 2002-12-31 alex /* Shut down server */
88 2ee05c9a 2002-03-03 alex assert( Client != NULL );
89 2ee05c9a 2002-03-03 alex assert( Req != NULL );
91 4e485443 2002-12-31 alex /* Not a local IRC operator? */
92 4e485443 2002-12-31 alex if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
94 4e485443 2002-12-31 alex /* Bad number of parameters? */
95 2ee05c9a 2002-03-03 alex if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
97 15e4f674 2002-12-27 alex Log( LOG_NOTICE|LOG_snotice, "Got DIE command from \"%s\" ...", Client_Mask( Client ));
98 43a4bc5b 2002-12-19 alex NGIRCd_SignalQuit = TRUE;
99 2ee05c9a 2002-03-03 alex return CONNECTED;
100 2ee05c9a 2002-03-03 alex } /* IRC_DIE */
103 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
104 4eb57b59 2002-11-22 alex IRC_REHASH( CLIENT *Client, REQUEST *Req )
106 4e485443 2002-12-31 alex /* Reload configuration file */
108 a5c92290 2002-11-22 alex assert( Client != NULL );
109 a5c92290 2002-11-22 alex assert( Req != NULL );
111 4e485443 2002-12-31 alex /* Not a local IRC operator? */
112 a5c92290 2002-11-22 alex if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
114 4e485443 2002-12-31 alex /* Bad number of parameters? */
115 4e485443 2002-12-31 alex if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
117 15e4f674 2002-12-27 alex Log( LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\" ...", Client_Mask( Client ));
118 43a4bc5b 2002-12-19 alex NGIRCd_SignalRehash = TRUE;
120 a5c92290 2002-11-22 alex return CONNECTED;
121 4eb57b59 2002-11-22 alex } /* IRC_REHASH */
124 a5c92290 2002-11-22 alex GLOBAL BOOLEAN
125 c2f60abe 2002-05-27 alex IRC_RESTART( CLIENT *Client, REQUEST *Req )
127 4e485443 2002-12-31 alex /* Restart IRC server (fork a new process) */
129 2ee05c9a 2002-03-03 alex assert( Client != NULL );
130 2ee05c9a 2002-03-03 alex assert( Req != NULL );
132 4e485443 2002-12-31 alex /* Not a local IRC operator? */
133 2ee05c9a 2002-03-03 alex if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
135 4e485443 2002-12-31 alex /* Bad number of parameters? */
136 4e485443 2002-12-31 alex if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
138 15e4f674 2002-12-27 alex Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\" ...", Client_Mask( Client ));
139 43a4bc5b 2002-12-19 alex NGIRCd_SignalRestart = TRUE;
140 2ee05c9a 2002-03-03 alex return CONNECTED;
141 2ee05c9a 2002-03-03 alex } /* IRC_RESTART */
144 1256f347 2002-09-03 alex GLOBAL BOOLEAN
145 1256f347 2002-09-03 alex IRC_CONNECT(CLIENT *Client, REQUEST *Req )
147 4e485443 2002-12-31 alex /* Connect configured or new server */
149 1256f347 2002-09-03 alex assert( Client != NULL );
150 1256f347 2002-09-03 alex assert( Req != NULL );
152 4e485443 2002-12-31 alex /* Not a local IRC operator? */
153 1256f347 2002-09-03 alex if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
155 4e485443 2002-12-31 alex /* Bad number of parameters? */
156 4e485443 2002-12-31 alex if(( Req->argc != 2 ) && ( Req->argc != 5 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
158 4e485443 2002-12-31 alex /* Invalid port number? */
159 4e485443 2002-12-31 alex if( atoi( Req->argv[1] ) < 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
161 4e485443 2002-12-31 alex Log( LOG_NOTICE|LOG_snotice, "Got CONNECT command from \"%s\" for \"%s\".", Client_Mask( Client ), Req->argv[0]);
163 4e485443 2002-12-31 alex if( Req->argc == 2 )
165 4e485443 2002-12-31 alex /* Connect configured server */
166 4e485443 2002-12-31 alex if( ! Conf_EnableServer( Req->argv[0], atoi( Req->argv[1] ))) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
170 4e485443 2002-12-31 alex /* Add server */
171 4e485443 2002-12-31 alex 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 1256f347 2002-09-03 alex return CONNECTED;
174 1256f347 2002-09-03 alex } /* IRC_CONNECT */
177 4e485443 2002-12-31 alex GLOBAL BOOLEAN
178 4e485443 2002-12-31 alex IRC_DISCONNECT(CLIENT *Client, REQUEST *Req )
180 4e485443 2002-12-31 alex /* Disconnect and disable configured server */
182 4e485443 2002-12-31 alex CONN_ID my_conn;
184 4e485443 2002-12-31 alex assert( Client != NULL );
185 4e485443 2002-12-31 alex assert( Req != NULL );
187 4e485443 2002-12-31 alex /* Not a local IRC operator? */
188 4e485443 2002-12-31 alex if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
190 4e485443 2002-12-31 alex /* Bad number of parameters? */
191 4e485443 2002-12-31 alex if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
193 4e485443 2002-12-31 alex Log( LOG_NOTICE|LOG_snotice, "Got DISCONNECT command from \"%s\" for0 \"%s\".", Client_Mask( Client ), Req->argv[0]);
195 4e485443 2002-12-31 alex /* Save ID of this connection */
196 4e485443 2002-12-31 alex my_conn = Client_Conn( Client );
198 4e485443 2002-12-31 alex /* Connect configured server */
199 4e485443 2002-12-31 alex if( ! Conf_DisableServer( Req->argv[0] )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
201 4e485443 2002-12-31 alex /* Are we still connected or were we killed, too? */
202 4e485443 2002-12-31 alex if( Client_GetFromConn( my_conn )) return CONNECTED;
203 4e485443 2002-12-31 alex else return DISCONNECTED;
204 4e485443 2002-12-31 alex } /* IRC_CONNECT */
207 2ee05c9a 2002-03-03 alex /* -eof- */