]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-oper.c
d71bcaaf6ccccef7b7f34ee85586364d6ffd1020
[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.1 2002/03/03 17:15:11 alex Exp $
13  *
14  * irc-oper.c: IRC-Operator-Befehle
15  *
16  * $Log: irc-oper.c,v $
17  * Revision 1.1  2002/03/03 17:15:11  alex
18  * - Source in weitere Module fuer IRC-Befehle aufgesplitted.
19  *
20  */
21
22
23 #include <portab.h>
24 #include "global.h"
25
26 #include <imp.h>
27 #include <assert.h>
28
29 #include "ngircd.h"
30 #include "conf.h"
31 #include "irc-write.h"
32 #include "log.h"
33 #include "messages.h"
34
35 #include <exp.h>
36 #include "irc-oper.h"
37
38
39 GLOBAL BOOLEAN IRC_OPER( CLIENT *Client, REQUEST *Req )
40 {
41         INT i;
42
43         assert( Client != NULL );
44         assert( Req != NULL );
45
46         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
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, "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 IRC_DIE( CLIENT *Client, REQUEST *Req )
85 {
86         assert( Client != NULL );
87         assert( Req != NULL );
88
89         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
90
91         /* Falsche Anzahl Parameter? */
92         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
93
94         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
95
96         Log( LOG_NOTICE, "Got DIE command from \"%s\", going down!", Client_Mask( Client ));
97         NGIRCd_Quit = TRUE;
98         return CONNECTED;
99 } /* IRC_DIE */
100
101
102 GLOBAL BOOLEAN IRC_RESTART( CLIENT *Client, REQUEST *Req )
103 {
104         assert( Client != NULL );
105         assert( Req != NULL );
106
107         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
108
109         /* Falsche Anzahl Parameter? */
110         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
111
112         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
113
114         Log( LOG_NOTICE, "Got RESTART command from \"%s\", going down!", Client_Mask( Client ));
115         NGIRCd_Restart = TRUE;
116         return CONNECTED;
117 } /* IRC_RESTART */
118
119
120 /* -eof- */