Blob


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 */
18 #include "portab.h"
20 #include "imp.h"
21 #include <assert.h>
22 #include <string.h>
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"
35 #include <exp.h>
36 #include "irc-oper.h"
39 GLOBAL BOOLEAN
40 IRC_OPER( CLIENT *Client, REQUEST *Req )
41 {
42 INT i;
44 assert( Client != NULL );
45 assert( Req != NULL );
47 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
49 /* Falsche Anzahl Parameter? */
50 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
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 }
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 }
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 }
78 if( ! Client_OperByMe( Client )) Log( LOG_NOTICE|LOG_snotice, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
80 Client_SetOperByMe( Client, TRUE );
81 return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
82 } /* IRC_OPER */
85 GLOBAL BOOLEAN
86 IRC_DIE( CLIENT *Client, REQUEST *Req )
87 {
88 assert( Client != NULL );
89 assert( Req != NULL );
91 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
93 /* Falsche Anzahl Parameter? */
94 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
96 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
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 */
104 GLOBAL BOOLEAN
105 IRC_RESTART( CLIENT *Client, REQUEST *Req )
107 assert( Client != NULL );
108 assert( Req != NULL );
110 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
112 /* Falsche Anzahl Parameter? */
113 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
115 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
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 */
123 GLOBAL BOOLEAN
124 IRC_CONNECT(CLIENT *Client, REQUEST *Req )
126 /* Vorlaeufige Version zu Debug-Zwecken: es wird einfach
127 * der "passive mode" aufgehoben, mehr passiert nicht ... */
129 assert( Client != NULL );
130 assert( Req != NULL );
132 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
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 ));
138 Log( LOG_NOTICE|LOG_snotice, "Got CONNECT command from \"%s\".", Client_Mask( Client ));
139 NGIRCd_Passive = FALSE;
140 return CONNECTED;
141 } /* IRC_CONNECT */
144 /* -eof- */