]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-oper.c
- string.h wird nun includiert.
[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.4 2002/04/04 13:03:39 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 "conf.h"
26 #include "irc-write.h"
27 #include "log.h"
28 #include "messages.h"
29
30 #include <exp.h>
31 #include "irc-oper.h"
32
33
34 GLOBAL BOOLEAN IRC_OPER( CLIENT *Client, REQUEST *Req )
35 {
36         INT i;
37
38         assert( Client != NULL );
39         assert( Req != NULL );
40
41         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
42
43         /* Falsche Anzahl Parameter? */
44         if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
45
46         /* Operator suchen */
47         for( i = 0; i < Conf_Oper_Count; i++)
48         {
49                 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
50         }
51         if( i >= Conf_Oper_Count )
52         {
53                 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Name \"%s\" not configured!", Client_Mask( Client ), Req->argv[0] );
54                 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
55         }
56
57         /* Stimmt das Passwort? */
58         if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
59         {
60                 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Bad password for \"%s\"!", Client_Mask( Client ), Conf_Oper[i].name );
61                 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
62         }
63
64         if( ! Client_HasMode( Client, 'o' ))
65         {
66                 /* noch kein o-Mode gesetzt */
67                 Client_ModeAdd( Client, 'o' );
68                 if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
69                 IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
70         }
71
72         if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
73
74         Client_SetOperByMe( Client, TRUE );
75         return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
76 } /* IRC_OPER */
77
78
79 GLOBAL BOOLEAN IRC_DIE( CLIENT *Client, REQUEST *Req )
80 {
81         assert( Client != NULL );
82         assert( Req != NULL );
83
84         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
85
86         /* Falsche Anzahl Parameter? */
87         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
88
89         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
90
91         Log( LOG_NOTICE|LOG_snotice, "Got DIE command from \"%s\", going down!", Client_Mask( Client ));
92         NGIRCd_Quit = TRUE;
93         return CONNECTED;
94 } /* IRC_DIE */
95
96
97 GLOBAL BOOLEAN IRC_RESTART( CLIENT *Client, REQUEST *Req )
98 {
99         assert( Client != NULL );
100         assert( Req != NULL );
101
102         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
103
104         /* Falsche Anzahl Parameter? */
105         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
106
107         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
108
109         Log( LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\", going down!", Client_Mask( Client ));
110         NGIRCd_Restart = TRUE;
111         return CONNECTED;
112 } /* IRC_RESTART */
113
114
115 /* -eof- */