about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander Barton <alex@barton.de>2008-04-13 19:25:46 +0200
committerAlexander Barton <alex@barton.de>2009-09-30 16:00:05 +0200
commit926204cacd05f49f24e79d0af404c2da4cfdbe3a (patch)
tree8ade6484159d897e83dfbdbb6ac87c2016f2af4f /src
parent3bf0c6f3b9cbeded68c2c7f7a6f2a020616b73f5 (diff)
downloadngircd-926204cacd05f49f24e79d0af404c2da4cfdbe3a.tar.gz
ngircd-926204cacd05f49f24e79d0af404c2da4cfdbe3a.zip
New local functions Check_Oper() and No_Privileges().
Diffstat (limited to 'src')
-rw-r--r--src/ngircd/irc-oper.c53
1 files changed, 39 insertions, 14 deletions
diff --git a/src/ngircd/irc-oper.c b/src/ngircd/irc-oper.c
index 736163c1..7033031a 100644
--- a/src/ngircd/irc-oper.c
+++ b/src/ngircd/irc-oper.c
@@ -50,6 +50,35 @@ Bad_OperPass(CLIENT *Client, char *errtoken, char *errmsg)
 } /* Bad_OperPass */
 
 
+/**
+ * Check that the client is an IRC operator allowed to administer this server.
+ */
+static bool
+Check_Oper(CLIENT * Client)
+{
+	if (!Client_HasMode(Client, 'o'))
+		return false;
+	if (!Client_OperByMe(Client) && !Conf_AllowRemoteOper)
+		return false;
+	/* The client is an local IRC operator, or this server is configured
+	 * to trust remote operators. */
+	return true;
+} /* CheckOper */
+
+
+/**
+ * Return and log a "no privileges" message.
+ */
+static bool
+No_Privileges(CLIENT * Client, REQUEST * Req)
+{
+	Log(LOG_NOTICE, "No privileges: client \"%s\", command \"%s\"",
+	    Client_Mask(Client), Req->command);
+	return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
+				  Client_ID(Client));
+} /* PermissionDenied */
+
+
 GLOBAL bool
 IRC_OPER( CLIENT *Client, REQUEST *Req )
 {
@@ -98,10 +127,8 @@ IRC_DIE(CLIENT * Client, REQUEST * Req)
 	assert(Client != NULL);
 	assert(Req != NULL);
 
-	/* Not a local IRC operator? */
-	if ((!Client_HasMode(Client, 'o')) || (!Client_OperByMe(Client)))
-		return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
-					  Client_ID(Client));
+	if (!Check_Oper(Client))
+		return No_Privileges(Client, Req);
 
 	/* Bad number of parameters? */
 #ifdef STRICT_RFC
@@ -140,8 +167,8 @@ IRC_REHASH( CLIENT *Client, REQUEST *Req )
 	assert( Client != NULL );
 	assert( Req != NULL );
 
-	/* Not a local IRC operator? */
-	if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
+	if (!Check_Oper(Client))
+		return No_Privileges(Client, Req);
 
 	/* Bad number of parameters? */
 	if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
@@ -161,8 +188,8 @@ IRC_RESTART( CLIENT *Client, REQUEST *Req )
 	assert( Client != NULL );
 	assert( Req != NULL );
 
-	/* Not a local IRC operator? */
-	if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
+	if (!Check_Oper(Client))
+		return No_Privileges(Client, Req);
 
 	/* Bad number of parameters? */
 	if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
@@ -183,10 +210,8 @@ IRC_CONNECT(CLIENT * Client, REQUEST * Req)
 	assert(Client != NULL);
 	assert(Req != NULL);
 
-	/* Not a local IRC operator? */
-	if ((!Client_HasMode(Client, 'o')) || (!Client_OperByMe(Client)))
-		return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
-					  Client_ID(Client));
+	if (!Check_Oper(Client))
+		return No_Privileges(Client, Req);
 
 	/* Bad number of parameters? */
 	if ((Req->argc != 1) && (Req->argc != 2) && (Req->argc != 5))
@@ -241,8 +266,8 @@ IRC_DISCONNECT(CLIENT *Client, REQUEST *Req )
 	assert( Client != NULL );
 	assert( Req != NULL );
 
-	/* Not a local IRC operator? */
-	if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
+	if (!Check_Oper(Client))
+		return No_Privileges(Client, Req);
 
 	/* Bad number of parameters? */
 	if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );