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