]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-oper.c
Added missing include of "match.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.19 2005/03/03 08:36:19 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 "match.h"
33 #include "messages.h"
34 #include "parse.h"
35
36 #include <exp.h>
37 #include "irc-oper.h"
38
39
40 GLOBAL BOOLEAN
41 IRC_OPER( CLIENT *Client, REQUEST *Req )
42 {
43         INT i;
44
45         assert( Client != NULL );
46         assert( Req != NULL );
47
48         /* Falsche Anzahl Parameter? */
49         if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
50
51         /* Operator suchen */
52         for( i = 0; i < Conf_Oper_Count; i++)
53         {
54                 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
55         }
56         if( i >= Conf_Oper_Count )
57         {
58                 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Name \"%s\" not configured!", Client_Mask( Client ), Req->argv[0] );
59                 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
60         }
61
62         /* Stimmt das Passwort? */
63         if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
64         {
65                 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Bad password for \"%s\"!", Client_Mask( Client ), Conf_Oper[i].name );
66                 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
67         }
68
69         /* Authorized Mask? */
70         if( Conf_Oper[i].mask && (! Match( Conf_Oper[i].mask, Client_Mask( Client ) ))) {
71                 Log( LOG_WARNING, "Rejected valid OPER for \"%s\": Mask mismatch (got: \"%s\", want: \"%s\")!", Conf_Oper[i].name, Client_Mask( Client ), Conf_Oper[i].mask );
72                 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
73         }
74
75
76         if( ! Client_HasMode( Client, 'o' ))
77         {
78                 /* noch kein o-Mode gesetzt */
79                 Client_ModeAdd( Client, 'o' );
80                 if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
81                 IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
82         }
83
84         if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
85
86         Client_SetOperByMe( Client, TRUE );
87         return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
88 } /* IRC_OPER */
89
90
91 GLOBAL BOOLEAN
92 IRC_DIE( CLIENT *Client, REQUEST *Req )
93 {
94         /* Shut down server */
95
96         assert( Client != NULL );
97         assert( Req != NULL );
98
99         /* Not a local IRC operator? */
100         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
101         
102         /* Bad number of parameters? */
103         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
104
105         Log( LOG_NOTICE|LOG_snotice, "Got DIE command from \"%s\" ...", Client_Mask( Client ));
106         NGIRCd_SignalQuit = TRUE;
107         return CONNECTED;
108 } /* IRC_DIE */
109
110
111 GLOBAL BOOLEAN
112 IRC_REHASH( CLIENT *Client, REQUEST *Req )
113 {
114         /* Reload configuration file */
115
116         assert( Client != NULL );
117         assert( Req != NULL );
118
119         /* Not a local IRC operator? */
120         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
121
122         /* Bad number of parameters? */
123         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
124
125         Log( LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\" ...", Client_Mask( Client ));
126         NGIRCd_SignalRehash = TRUE;
127         
128         return CONNECTED;
129 } /* IRC_REHASH */
130
131
132 GLOBAL BOOLEAN
133 IRC_RESTART( CLIENT *Client, REQUEST *Req )
134 {
135         /* Restart IRC server (fork a new process) */
136
137         assert( Client != NULL );
138         assert( Req != NULL );
139
140         /* Not a local IRC operator? */
141         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
142
143         /* Bad number of parameters? */
144         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
145
146         Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\" ...", Client_Mask( Client ));
147         NGIRCd_SignalRestart = TRUE;
148         return CONNECTED;
149 } /* IRC_RESTART */
150
151
152 GLOBAL BOOLEAN
153 IRC_CONNECT(CLIENT *Client, REQUEST *Req )
154 {
155         /* Connect configured or new server */
156
157         assert( Client != NULL );
158         assert( Req != NULL );
159
160         /* Not a local IRC operator? */
161         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
162
163         /* Bad number of parameters? */
164         if(( Req->argc != 2 ) && ( Req->argc != 5 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
165
166         /* Invalid port number? */
167         if( atoi( Req->argv[1] ) < 1 )  return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
168
169         Log( LOG_NOTICE|LOG_snotice, "Got CONNECT command from \"%s\" for \"%s\".", Client_Mask( Client ), Req->argv[0]);
170
171         if( Req->argc == 2 )
172         {
173                 /* Connect configured server */
174                 if( ! Conf_EnableServer( Req->argv[0], atoi( Req->argv[1] ))) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
175         }
176         else
177         {
178                 /* Add server */
179                 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] );
180         }
181         return CONNECTED;
182 } /* IRC_CONNECT */
183
184
185 GLOBAL BOOLEAN
186 IRC_DISCONNECT(CLIENT *Client, REQUEST *Req )
187 {
188         /* Disconnect and disable configured server */
189
190         CONN_ID my_conn;
191
192         assert( Client != NULL );
193         assert( Req != NULL );
194
195         /* Not a local IRC operator? */
196         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
197
198         /* Bad number of parameters? */
199         if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
200
201         Log( LOG_NOTICE|LOG_snotice, "Got DISCONNECT command from \"%s\" for0 \"%s\".", Client_Mask( Client ), Req->argv[0]);
202
203         /* Save ID of this connection */
204         my_conn = Client_Conn( Client );
205
206         /* Connect configured server */
207         if( ! Conf_DisableServer( Req->argv[0] )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
208
209         /* Are we still connected or were we killed, too? */
210         if( Client_GetFromConn( my_conn )) return CONNECTED;
211         else return DISCONNECTED;
212 } /* IRC_CONNECT */
213
214
215 /* -eof- */