]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-oper.c
- Cleaned up handling of server configuration structures.
[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.16 2002/12/30 00:01:45 alex Exp $";
18
19 #include "imp.h"
20 #include <assert.h>
21 #include <string.h>
22
23 #include "ngircd.h"
24 #include "resolve.h"
25 #include "conn.h"
26 #include "conf.h"
27 #include "client.h"
28 #include "channel.h"
29 #include "irc-write.h"
30 #include "log.h"
31 #include "messages.h"
32 #include "parse.h"
33
34 #include <exp.h>
35 #include "irc-oper.h"
36
37
38 GLOBAL BOOLEAN
39 IRC_OPER( CLIENT *Client, REQUEST *Req )
40 {
41         INT i;
42
43         assert( Client != NULL );
44         assert( Req != NULL );
45
46         /* Falsche Anzahl Parameter? */
47         if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
48
49         /* Operator suchen */
50         for( i = 0; i < Conf_Oper_Count; i++)
51         {
52                 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
53         }
54         if( i >= Conf_Oper_Count )
55         {
56                 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Name \"%s\" not configured!", Client_Mask( Client ), Req->argv[0] );
57                 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
58         }
59
60         /* Stimmt das Passwort? */
61         if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
62         {
63                 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Bad password for \"%s\"!", Client_Mask( Client ), Conf_Oper[i].name );
64                 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
65         }
66
67         if( ! Client_HasMode( Client, 'o' ))
68         {
69                 /* noch kein o-Mode gesetzt */
70                 Client_ModeAdd( Client, 'o' );
71                 if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
72                 IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
73         }
74
75         if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
76
77         Client_SetOperByMe( Client, TRUE );
78         return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
79 } /* IRC_OPER */
80
81
82 GLOBAL BOOLEAN
83 IRC_DIE( CLIENT *Client, REQUEST *Req )
84 {
85         assert( Client != NULL );
86         assert( Req != NULL );
87
88         /* Falsche Anzahl Parameter? */
89         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
90
91         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
92
93         Log( LOG_NOTICE|LOG_snotice, "Got DIE command from \"%s\" ...", Client_Mask( Client ));
94         NGIRCd_SignalQuit = TRUE;
95         return CONNECTED;
96 } /* IRC_DIE */
97
98
99 GLOBAL BOOLEAN
100 IRC_REHASH( CLIENT *Client, REQUEST *Req )
101 {
102         assert( Client != NULL );
103         assert( Req != NULL );
104
105         /* Falsche Anzahl Parameter? */
106         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
107
108         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
109
110         Log( LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\" ...", Client_Mask( Client ));
111         NGIRCd_SignalRehash = TRUE;
112         
113         return CONNECTED;
114 } /* IRC_REHASH */
115
116
117 GLOBAL BOOLEAN
118 IRC_RESTART( CLIENT *Client, REQUEST *Req )
119 {
120         assert( Client != NULL );
121         assert( Req != NULL );
122
123         /* Falsche Anzahl Parameter? */
124         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
125
126         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
127
128         Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\" ...", Client_Mask( Client ));
129         NGIRCd_SignalRestart = TRUE;
130         return CONNECTED;
131 } /* IRC_RESTART */
132
133
134 GLOBAL BOOLEAN
135 IRC_CONNECT(CLIENT *Client, REQUEST *Req )
136 {
137         /* Vorlaeufige Version zu Debug-Zwecken: es wird einfach
138          * der "passive mode" aufgehoben, mehr passiert nicht ... */
139
140         assert( Client != NULL );
141         assert( Req != NULL );
142
143         /* Falsche Anzahl Parameter? */
144         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
145         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
146
147         Log( LOG_NOTICE|LOG_snotice, "Got CONNECT command from \"%s\".", Client_Mask( Client ));
148         NGIRCd_Passive = FALSE;
149         return CONNECTED;
150 } /* IRC_CONNECT */
151
152
153 /* -eof- */