]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-oper.c
- Dokumentation aktualisiert.
[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.8 2002/09/03 23:54:59 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         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
48
49         /* Falsche Anzahl Parameter? */
50         if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
51
52         /* Operator suchen */
53         for( i = 0; i < Conf_Oper_Count; i++)
54         {
55                 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
56         }
57         if( i >= Conf_Oper_Count )
58         {
59                 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Name \"%s\" not configured!", Client_Mask( Client ), Req->argv[0] );
60                 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
61         }
62
63         /* Stimmt das Passwort? */
64         if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
65         {
66                 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Bad password for \"%s\"!", Client_Mask( Client ), Conf_Oper[i].name );
67                 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
68         }
69
70         if( ! Client_HasMode( Client, 'o' ))
71         {
72                 /* noch kein o-Mode gesetzt */
73                 Client_ModeAdd( Client, 'o' );
74                 if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
75                 IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
76         }
77
78         if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
79
80         Client_SetOperByMe( Client, TRUE );
81         return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
82 } /* IRC_OPER */
83
84
85 GLOBAL BOOLEAN
86 IRC_DIE( CLIENT *Client, REQUEST *Req )
87 {
88         assert( Client != NULL );
89         assert( Req != NULL );
90
91         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
92
93         /* Falsche Anzahl Parameter? */
94         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
95
96         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
97
98         Log( LOG_NOTICE|LOG_snotice, "Got DIE command from \"%s\", going down!", Client_Mask( Client ));
99         NGIRCd_Quit = TRUE;
100         return CONNECTED;
101 } /* IRC_DIE */
102
103
104 GLOBAL BOOLEAN
105 IRC_RESTART( CLIENT *Client, REQUEST *Req )
106 {
107         assert( Client != NULL );
108         assert( Req != NULL );
109
110         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
111
112         /* Falsche Anzahl Parameter? */
113         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
114
115         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
116
117         Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\", going down!", Client_Mask( Client ));
118         NGIRCd_Restart = TRUE;
119         return CONNECTED;
120 } /* IRC_RESTART */
121
122
123 GLOBAL BOOLEAN
124 IRC_CONNECT(CLIENT *Client, REQUEST *Req )
125 {
126         /* Vorlaeufige Version zu Debug-Zwecken: es wird einfach
127          * der "passive mode" aufgehoben, mehr passiert nicht ... */
128
129         assert( Client != NULL );
130         assert( Req != NULL );
131
132         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
133
134         /* Falsche Anzahl Parameter? */
135         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
136         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
137
138         Log( LOG_NOTICE|LOG_snotice, "Got CONNECT command from \"%s\".", Client_Mask( Client ));
139         NGIRCd_Passive = FALSE;
140         return CONNECTED;
141 } /* IRC_CONNECT */
142
143
144 /* -eof- */