summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander Barton <alex@barton.de>2010-08-17 20:54:33 +0200
committerAlexander Barton <alex@barton.de>2010-08-17 20:54:33 +0200
commit6fdd3479f126a866c022c39dcd424d6042de6875 (patch)
tree0149218c33f9568f9a3005820efe6205eefd85f5
parent617640e0a358dc29c5e4f82eb6b828030ef21670 (diff)
downloadngircd-6fdd3479f126a866c022c39dcd424d6042de6875.tar.gz
ngircd-6fdd3479f126a866c022c39dcd424d6042de6875.zip
Implement Client_HostnameCloaked() and Client_MaskCloaked()
These two functions return the cloaked hostname, if the client has
enabled hostname cloaking indicated by the -- still to implement --
user mode "x". See furter patches :-)
-rw-r--r--src/ngircd/client.c43
-rw-r--r--src/ngircd/client.h2
2 files changed, 45 insertions, 0 deletions
diff --git a/src/ngircd/client.c b/src/ngircd/client.c
index a067ef72..dd4113e4 100644
--- a/src/ngircd/client.c
+++ b/src/ngircd/client.c
@@ -660,6 +660,23 @@ Client_Hostname(CLIENT *Client)
 } /* Client_Hostname */
 
 
+/**
+ * Get potentially cloaked hostname of a client.
+ * If the client has not enabled cloaking, the real hostname is used.
+ * @param Client Pointer to client structure
+ * @return Pointer to client hostname
+ */
+GLOBAL char *
+Client_HostnameCloaked(CLIENT *Client)
+{
+	assert(Client != NULL);
+	if (Client_HasMode(Client, 'x'))
+		return Client_ID(Client->introducer);
+	else
+		return Client_Hostname(Client);
+} /* Client_HostnameCloaked */
+
+
 GLOBAL char *
 Client_Password( CLIENT *Client )
 {
@@ -756,6 +773,32 @@ Client_Mask( CLIENT *Client )
 } /* Client_Mask */
 
 
+/**
+ * Return ID of a client with cloaked hostname: "client!user@server-name"
+ * This client ID is used for IRC prefixes, for example.
+ * Please note that this function uses a global static buffer, so you can't
+ * nest invocations without overwriting erlier results!
+ * If the client has not enabled cloaking, the real hostname is used.
+ * @param Client Pointer to client structure
+ * @return Pointer to global buffer containing the client ID
+ */
+GLOBAL char *
+Client_MaskCloaked(CLIENT *Client)
+{
+	static char Mask_Buffer[GETID_LEN];
+
+	assert (Client != NULL);
+
+	/* Is the client using cloaking at all? */
+	if (!Client_HasMode(Client, 'x'))
+	    return Client_Mask(Client);
+
+	snprintf(Mask_Buffer, GETID_LEN, "%s!%s@%s",
+		 Client->id, Client->user, Client_ID(Client->introducer));
+	return Mask_Buffer;
+} /* Client_MaskCloaked */
+
+
 GLOBAL CLIENT *
 Client_Introducer( CLIENT *Client )
 {
diff --git a/src/ngircd/client.h b/src/ngircd/client.h
index bd000a56..98a0d1a4 100644
--- a/src/ngircd/client.h
+++ b/src/ngircd/client.h
@@ -93,12 +93,14 @@ GLOBAL int Client_Type PARAMS(( CLIENT *Client ));
 GLOBAL CONN_ID Client_Conn PARAMS(( CLIENT *Client ));
 GLOBAL char *Client_ID PARAMS(( CLIENT *Client ));
 GLOBAL char *Client_Mask PARAMS(( CLIENT *Client ));
+GLOBAL char *Client_MaskCloaked PARAMS(( CLIENT *Client ));
 GLOBAL char *Client_Info PARAMS(( CLIENT *Client ));
 GLOBAL char *Client_User PARAMS(( CLIENT *Client ));
 #ifdef PAM
 GLOBAL char *Client_OrigUser PARAMS(( CLIENT *Client ));
 #endif
 GLOBAL char *Client_Hostname PARAMS(( CLIENT *Client ));
+GLOBAL char *Client_HostnameCloaked PARAMS(( CLIENT *Client ));
 GLOBAL char *Client_Password PARAMS(( CLIENT *Client ));
 GLOBAL char *Client_Modes PARAMS(( CLIENT *Client ));
 GLOBAL char *Client_Flags PARAMS(( CLIENT *Client ));