]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-oper.c
Added missing include for <sys/select.h>.
[ngircd-alex.git] / src / ngircd / irc-oper.c
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  */
13
14
15 #include "portab.h"
16
17 static char UNUSED id[] = "$Id: irc-oper.c,v 1.17 2002/12/31 16:10:55 alex Exp $";
18
19 #include "imp.h"
20 #include <assert.h>
21 #include <stdlib.h>
22 #include <string.h>
23
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"
34
35 #include <exp.h>
36 #include "irc-oper.h"
37
38
39 GLOBAL BOOLEAN
40 IRC_OPER( CLIENT *Client, REQUEST *Req )
41 {
42         INT i;
43
44         assert( Client != NULL );
45         assert( Req != NULL );
46
47         /* Falsche Anzahl Parameter? */
48         if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
49
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         }
60
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         }
67
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         }
75
76         if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
77
78         Client_SetOperByMe( Client, TRUE );
79         return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
80 } /* IRC_OPER */
81
82
83 GLOBAL BOOLEAN
84 IRC_DIE( CLIENT *Client, REQUEST *Req )
85 {
86         /* Shut down server */
87
88         assert( Client != NULL );
89         assert( Req != NULL );
90
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 ));
93         
94         /* Bad number of parameters? */
95         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
96
97         Log( LOG_NOTICE|LOG_snotice, "Got DIE command from \"%s\" ...", Client_Mask( Client ));
98         NGIRCd_SignalQuit = TRUE;
99         return CONNECTED;
100 } /* IRC_DIE */
101
102
103 GLOBAL BOOLEAN
104 IRC_REHASH( CLIENT *Client, REQUEST *Req )
105 {
106         /* Reload configuration file */
107
108         assert( Client != NULL );
109         assert( Req != NULL );
110
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 ));
113
114         /* Bad number of parameters? */
115         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
116
117         Log( LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\" ...", Client_Mask( Client ));
118         NGIRCd_SignalRehash = TRUE;
119         
120         return CONNECTED;
121 } /* IRC_REHASH */
122
123
124 GLOBAL BOOLEAN
125 IRC_RESTART( CLIENT *Client, REQUEST *Req )
126 {
127         /* Restart IRC server (fork a new process) */
128
129         assert( Client != NULL );
130         assert( Req != NULL );
131
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 ));
134
135         /* Bad number of parameters? */
136         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
137
138         Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\" ...", Client_Mask( Client ));
139         NGIRCd_SignalRestart = TRUE;
140         return CONNECTED;
141 } /* IRC_RESTART */
142
143
144 GLOBAL BOOLEAN
145 IRC_CONNECT(CLIENT *Client, REQUEST *Req )
146 {
147         /* Connect configured or new server */
148
149         assert( Client != NULL );
150         assert( Req != NULL );
151
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 ));
154
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 );
157
158         /* Invalid port number? */
159         if( atoi( Req->argv[1] ) < 1 )  return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
160
161         Log( LOG_NOTICE|LOG_snotice, "Got CONNECT command from \"%s\" for \"%s\".", Client_Mask( Client ), Req->argv[0]);
162
163         if( Req->argc == 2 )
164         {
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] );
167         }
168         else
169         {
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] );
172         }
173         return CONNECTED;
174 } /* IRC_CONNECT */
175
176
177 GLOBAL BOOLEAN
178 IRC_DISCONNECT(CLIENT *Client, REQUEST *Req )
179 {
180         /* Disconnect and disable configured server */
181
182         CONN_ID my_conn;
183
184         assert( Client != NULL );
185         assert( Req != NULL );
186
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 ));
189
190         /* Bad number of parameters? */
191         if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
192
193         Log( LOG_NOTICE|LOG_snotice, "Got DISCONNECT command from \"%s\" for0 \"%s\".", Client_Mask( Client ), Req->argv[0]);
194
195         /* Save ID of this connection */
196         my_conn = Client_Conn( Client );
197
198         /* Connect configured server */
199         if( ! Conf_DisableServer( Req->argv[0] )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
200
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 */
205
206
207 /* -eof- */