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