about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander Barton <alex@barton.de>2012-01-22 18:17:28 +0100
committerAlexander Barton <alex@barton.de>2012-01-22 18:17:28 +0100
commit51a6a33056486c19da6b8d6e4809dde57be00ece (patch)
tree9d21e626eb0b356240dc3af399ebffc6158b54a9 /src
parent6e28f4a7d13a81db99196da23958e81f2bb8418e (diff)
downloadngircd-51a6a33056486c19da6b8d6e4809dde57be00ece.tar.gz
ngircd-51a6a33056486c19da6b8d6e4809dde57be00ece.zip
New function Client_Reject() to reject clients on connect
Diffstat (limited to 'src')
-rw-r--r--src/ngircd/client.c33
-rw-r--r--src/ngircd/client.h3
2 files changed, 36 insertions, 0 deletions
diff --git a/src/ngircd/client.c b/src/ngircd/client.c
index d1f751d4..1aaf687c 100644
--- a/src/ngircd/client.c
+++ b/src/ngircd/client.c
@@ -1097,6 +1097,39 @@ Client_StartTime(CLIENT *Client)
 } /* Client_Uptime */
 
 
+/**
+ * Reject a client when logging in.
+ *
+ * This function is called when a client isn't allowed to connect to this
+ * server. Possible reasons are bad server password, bad PAM password,
+ * or that the client is G/K-Line'd.
+ *
+ * After calling this function, the client isn't connected any more.
+ *
+ * @param Client The client to reject.
+ * @param Reason The reason why the client has been rejected.
+ * @param InformClient If true, send the exact reason to the client.
+ */
+GLOBAL void
+Client_Reject(CLIENT *Client, const char *Reason, bool InformClient)
+{
+	char info[COMMAND_LEN];
+
+	assert(Client != NULL);
+	assert(Reason != NULL);
+
+	if (InformClient)
+		snprintf(info, sizeof(info), "Access denied: %s", Reason);
+	else
+		strcpy(info, "Access denied: Bad password?");
+
+	Log(LOG_ERR,
+	    "User \"%s\" rejected (connection %d): %s!",
+	    Client_Mask(Client), Client_Conn(Client), Reason);
+	Conn_Close(Client_Conn(Client), Reason, info, true);
+}
+
+
 static unsigned long
 Count( CLIENT_TYPE Type )
 {
diff --git a/src/ngircd/client.h b/src/ngircd/client.h
index fecf5d97..7bb230b4 100644
--- a/src/ngircd/client.h
+++ b/src/ngircd/client.h
@@ -163,6 +163,9 @@ GLOBAL void Client_RegisterWhowas PARAMS(( CLIENT *Client ));
 
 GLOBAL const char *Client_TypeText PARAMS((CLIENT *Client));
 
+GLOBAL void Client_Reject PARAMS((CLIENT *Client, const char *Reason,
+				  bool InformClient));
+
 #ifdef DEBUG
 GLOBAL void Client_DebugDump PARAMS((void));
 #endif