]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-oper.c
- Parser auf Befehlstabelle umgestellt.
[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  * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
6  * der GNU General Public License (GPL), wie von der Free Software Foundation
7  * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
8  * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
9  * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
10  * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
11  *
12  * $Id: irc-oper.c,v 1.11 2002/11/30 15:04:57 alex Exp $
13  *
14  * irc-oper.c: IRC-Operator-Befehle
15  */
16
17
18 #include "portab.h"
19
20 #include "imp.h"
21 #include <assert.h>
22 #include <string.h>
23
24 #include "ngircd.h"
25 #include "resolve.h"
26 #include "conf.h"
27 #include "conn.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         assert( Client != NULL );
87         assert( Req != NULL );
88
89         /* Falsche Anzahl Parameter? */
90         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
91
92         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
93
94         Log( LOG_NOTICE|LOG_snotice, "Got DIE command from \"%s\", going down!", Client_Mask( Client ));
95         NGIRCd_Quit = TRUE;
96         return CONNECTED;
97 } /* IRC_DIE */
98
99
100 GLOBAL BOOLEAN
101 IRC_REHASH( CLIENT *Client, REQUEST *Req )
102 {
103         assert( Client != NULL );
104         assert( Req != NULL );
105
106         /* Falsche Anzahl Parameter? */
107         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
108
109         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
110
111         Log( LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\", re-reading configuration ...", Client_Mask( Client ));
112         NGIRCd_Rehash( );
113         
114         return CONNECTED;
115 } /* IRC_REHASH */
116
117
118 GLOBAL BOOLEAN
119 IRC_RESTART( CLIENT *Client, REQUEST *Req )
120 {
121         assert( Client != NULL );
122         assert( Req != NULL );
123
124         /* Falsche Anzahl Parameter? */
125         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
126
127         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
128
129         Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\", going down!", Client_Mask( Client ));
130         NGIRCd_Restart = TRUE;
131         return CONNECTED;
132 } /* IRC_RESTART */
133
134
135 GLOBAL BOOLEAN
136 IRC_CONNECT(CLIENT *Client, REQUEST *Req )
137 {
138         /* Vorlaeufige Version zu Debug-Zwecken: es wird einfach
139          * der "passive mode" aufgehoben, mehr passiert nicht ... */
140
141         assert( Client != NULL );
142         assert( Req != NULL );
143
144         /* Falsche Anzahl Parameter? */
145         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
146         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
147
148         Log( LOG_NOTICE|LOG_snotice, "Got CONNECT command from \"%s\".", Client_Mask( Client ));
149         NGIRCd_Passive = FALSE;
150         return CONNECTED;
151 } /* IRC_CONNECT */
152
153
154 /* -eof- */