]> arthur.barton.de Git - ngircd-alex.git/commitdiff
Save client IP address text for "WebIRC" users
authorAlexander Barton <alex@barton.de>
Mon, 26 Aug 2013 20:54:00 +0000 (22:54 +0200)
committerAlexander Barton <alex@barton.de>
Mon, 26 Aug 2013 20:54:00 +0000 (22:54 +0200)
This patch introduces a new field in the CLIENT structure, "ipa_text",
which points to an optional textual representation of the client IP
address (or NULL) which can be used to store the "real" IP address
information of a client using the "WEBIRC" protocol.

Without this patch, ngIRCd ignored the <ip-address> paramater ...

In addition, the functions Client_SetIPAText() and Client_IPAText()
have been introduced to set and get the textual representation of the
client IP address.

Client_IPAText() can be used even when no "IP address text" has been
set before, it then returns the real IP address of the connection.

Closes bug #159.

src/ngircd/client.c
src/ngircd/client.h
src/ngircd/irc-info.c
src/ngircd/irc-login.c

index 72774ca9f4c749449d40a9344393aa3f6eef54b0..26d4929d732b04ecaaef3c24527465fafbe94160 100644 (file)
@@ -128,6 +128,8 @@ Client_Exit( void )
                        free(c->account_name);
                if (c->cloaked)
                        free(c->cloaked);
+               if (c->ipa_text)
+                       free(c->ipa_text);
                free( c );
                c = next;
        }
@@ -326,6 +328,8 @@ Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool Sen
                                free(c->account_name);
                        if (c->cloaked)
                                free(c->cloaked);
+                       if (c->ipa_text)
+                               free(c->ipa_text);
                        free( c );
                        break;
                }
@@ -368,6 +372,27 @@ Client_SetHostname( CLIENT *Client, const char *Hostname )
 } /* Client_SetHostname */
 
 
+/**
+ * Set IP address to display for a client.
+ *
+ * @param Client The client.
+ * @param IPAText Textual representation of the IP address or NULL to unset.
+ */
+GLOBAL void
+Client_SetIPAText(CLIENT *Client, const char *IPAText)
+{
+       assert(Client != NULL);
+
+       if (Client->ipa_text)
+               free(Client->ipa_text);
+
+       if (*IPAText)
+               Client->ipa_text = strndup(IPAText, CLIENT_HOST_LEN - 1);
+       else
+               Client->ipa_text = NULL;
+}
+
+
 GLOBAL void
 Client_SetID( CLIENT *Client, const char *ID )
 {
@@ -789,6 +814,21 @@ Client_HostnameDisplayed(CLIENT *Client)
        return Client->cloaked;
 }
 
+GLOBAL const char *
+Client_IPAText(CLIENT *Client)
+{
+       assert(Client != NULL);
+
+       /* Not a local client? */
+       if (Client_Conn(Client) <= NONE)
+               return "0.0.0.0";
+
+       if (!Client->ipa_text)
+               return Conn_GetIPAInfo(Client_Conn(Client));
+       else
+               return Client->ipa_text;
+}
+
 /**
  * Update (and generate, if necessary) the cloaked hostname of a client.
  *
index 702f114cf0f484d773f6d237d81a2152cbbb03f5..71d413b2f01be419f8c72c997cb33ca620e01a7e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2012 Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -49,6 +49,7 @@ typedef struct _CLIENT
        struct _CLIENT *topserver;      /* toplevel servers (only valid if client is a server) */
        char host[CLIENT_HOST_LEN];     /* hostname of the client */
        char *cloaked;                  /* cloaked hostname of the client */
+       char *ipa_text;                 /* textual representaton of IP address */
        char user[CLIENT_USER_LEN];     /* user name ("login") */
 #if defined(PAM) && defined(IDENTAUTH)
        char orig_user[CLIENT_USER_LEN];/* user name supplied by USER command */
@@ -114,6 +115,7 @@ GLOBAL char *Client_OrigUser PARAMS(( CLIENT *Client ));
 GLOBAL char *Client_Hostname PARAMS(( CLIENT *Client ));
 GLOBAL char *Client_HostnameCloaked PARAMS((CLIENT *Client));
 GLOBAL char *Client_HostnameDisplayed PARAMS(( CLIENT *Client ));
+GLOBAL const char *Client_IPAText PARAMS(( CLIENT *Client ));
 GLOBAL char *Client_Modes PARAMS(( CLIENT *Client ));
 GLOBAL char *Client_Flags PARAMS(( CLIENT *Client ));
 GLOBAL CLIENT *Client_Introducer PARAMS(( CLIENT *Client ));
@@ -131,6 +133,7 @@ GLOBAL bool Client_HasMode PARAMS(( CLIENT *Client, char Mode ));
 GLOBAL bool Client_HasFlag PARAMS(( CLIENT *Client, char Flag ));
 
 GLOBAL void Client_SetHostname PARAMS(( CLIENT *Client, const char *Hostname ));
+GLOBAL void Client_SetIPAText PARAMS(( CLIENT *Client, const char *IPAText ));
 GLOBAL void Client_SetID PARAMS(( CLIENT *Client, const char *Nick ));
 GLOBAL void Client_SetUser PARAMS(( CLIENT *Client, const char *User, bool Idented ));
 GLOBAL void Client_SetOrigUser PARAMS(( CLIENT *Client, const char *User ));
index 47a3797974a0d8c9f511c86b32055aa30b4f60fb..3d77237f4e08f95928d826462734dafc3f19e759 100644 (file)
@@ -407,8 +407,8 @@ IRC_WHOIS_SendReply(CLIENT *Client, CLIENT *from, CLIENT *c)
            (from == c || (!Conf_MorePrivacy && Client_HasMode(from, 'o')))) {
                /* Client hostname */
                if (!IRC_WriteStrClient(from, RPL_WHOISHOST_MSG,
-                                       Client_ID(from), Client_ID(c), Client_Hostname(c),
-                                       Conn_GetIPAInfo(Client_Conn(c))))
+                                       Client_ID(from), Client_ID(c),
+                                       Client_Hostname(c), Client_IPAText(c)))
                        return DISCONNECTED;
                /* Client modes */
                if (!IRC_WriteStrClient(from, RPL_WHOISMODES_MSG,
index 26dae6b73b2826ca82a47d2263f4f7b6607fe7d6..88804ef2b8b7dd1f95b71522ebc2ff3b84496827 100644 (file)
@@ -610,6 +610,8 @@ IRC_WEBIRC(CLIENT *Client, REQUEST *Req)
        Client_SetUser(Client, Req->argv[1], true);
        Client_SetOrigUser(Client, Req->argv[1]);
        Client_SetHostname(Client, Req->argv[2]);
+       Client_SetIPAText(Client, Req->argv[3]);
+
        return CONNECTED;
 } /* IRC_WEBIRC */