]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-oper.c
- new file header format (in english);
[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  * $Id: irc-oper.c,v 1.12 2002/12/12 12:24:18 alex Exp $
12  *
13  * IRC operator commands
14  */
15
16
17 #include "portab.h"
18
19 static char UNUSED id[] = "$Id: irc-oper.c,v 1.12 2002/12/12 12:24:18 alex Exp $";
20
21 #include "imp.h"
22 #include <assert.h>
23 #include <string.h>
24
25 #include "ngircd.h"
26 #include "resolve.h"
27 #include "conf.h"
28 #include "conn.h"
29 #include "client.h"
30 #include "channel.h"
31 #include "irc-write.h"
32 #include "log.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         if( ! Client_HasMode( Client, 'o' ))
70         {
71                 /* noch kein o-Mode gesetzt */
72                 Client_ModeAdd( Client, 'o' );
73                 if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
74                 IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
75         }
76
77         if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
78
79         Client_SetOperByMe( Client, TRUE );
80         return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
81 } /* IRC_OPER */
82
83
84 GLOBAL BOOLEAN
85 IRC_DIE( CLIENT *Client, REQUEST *Req )
86 {
87         assert( Client != NULL );
88         assert( Req != NULL );
89
90         /* Falsche Anzahl Parameter? */
91         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
92
93         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
94
95         Log( LOG_NOTICE|LOG_snotice, "Got DIE command from \"%s\", going down!", Client_Mask( Client ));
96         NGIRCd_Quit = TRUE;
97         return CONNECTED;
98 } /* IRC_DIE */
99
100
101 GLOBAL BOOLEAN
102 IRC_REHASH( CLIENT *Client, REQUEST *Req )
103 {
104         assert( Client != NULL );
105         assert( Req != NULL );
106
107         /* Falsche Anzahl Parameter? */
108         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
109
110         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
111
112         Log( LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\", re-reading configuration ...", Client_Mask( Client ));
113         NGIRCd_Rehash( );
114         
115         return CONNECTED;
116 } /* IRC_REHASH */
117
118
119 GLOBAL BOOLEAN
120 IRC_RESTART( CLIENT *Client, REQUEST *Req )
121 {
122         assert( Client != NULL );
123         assert( Req != NULL );
124
125         /* Falsche Anzahl Parameter? */
126         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
127
128         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
129
130         Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\", going down!", Client_Mask( Client ));
131         NGIRCd_Restart = TRUE;
132         return CONNECTED;
133 } /* IRC_RESTART */
134
135
136 GLOBAL BOOLEAN
137 IRC_CONNECT(CLIENT *Client, REQUEST *Req )
138 {
139         /* Vorlaeufige Version zu Debug-Zwecken: es wird einfach
140          * der "passive mode" aufgehoben, mehr passiert nicht ... */
141
142         assert( Client != NULL );
143         assert( Req != NULL );
144
145         /* Falsche Anzahl Parameter? */
146         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
147         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
148
149         Log( LOG_NOTICE|LOG_snotice, "Got CONNECT command from \"%s\".", Client_Mask( Client ));
150         NGIRCd_Passive = FALSE;
151         return CONNECTED;
152 } /* IRC_CONNECT */
153
154
155 /* -eof- */