1
0
mirror of https://github.com/osmarks/ngircd.git synced 2025-08-28 00:12:19 +00:00

Merge branch 'bug159-WebircIPA'

* bug159-WebircIPA:
  Introduce Free_Client() function to free CLIENT structure
  Save client IP address text for "WebIRC" users
This commit is contained in:
Alexander Barton 2013-08-26 23:22:20 +02:00
commit 44698e44e8
4 changed files with 77 additions and 17 deletions

View File

@ -62,6 +62,8 @@ static CLIENT *New_Client_Struct PARAMS(( void ));
static void Generate_MyToken PARAMS(( CLIENT *Client )); static void Generate_MyToken PARAMS(( CLIENT *Client ));
static void Adjust_Counters PARAMS(( CLIENT *Client )); static void Adjust_Counters PARAMS(( CLIENT *Client ));
static void Free_Client PARAMS(( CLIENT **Client ));
static CLIENT *Init_New_Client PARAMS((CONN_ID Idx, CLIENT *Introducer, static CLIENT *Init_New_Client PARAMS((CONN_ID Idx, CLIENT *Introducer,
CLIENT *TopServer, int Type, const char *ID, CLIENT *TopServer, int Type, const char *ID,
const char *User, const char *Hostname, const char *Info, const char *User, const char *Hostname, const char *Info,
@ -120,18 +122,15 @@ Client_Exit( void )
cnt = 0; cnt = 0;
c = My_Clients; c = My_Clients;
while( c ) while(c) {
{
cnt++; cnt++;
next = (CLIENT *)c->next; next = (CLIENT *)c->next;
if (c->account_name) Free_Client(&c);
free(c->account_name);
if (c->cloaked)
free(c->cloaked);
free( c );
c = next; c = next;
} }
if( cnt ) Log( LOG_INFO, "Freed %d client structure%s.", cnt, cnt == 1 ? "" : "s" ); if (cnt)
Log(LOG_INFO, "Freed %d client structure%s.",
cnt, cnt == 1 ? "" : "s");
} /* Client_Exit */ } /* Client_Exit */
@ -322,11 +321,7 @@ Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool Sen
} }
} }
if (c->account_name) Free_Client(&c);
free(c->account_name);
if (c->cloaked)
free(c->cloaked);
free( c );
break; break;
} }
last = c; last = c;
@ -368,6 +363,27 @@ Client_SetHostname( CLIENT *Client, const char *Hostname )
} /* Client_SetHostname */ } /* 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 GLOBAL void
Client_SetID( CLIENT *Client, const char *ID ) Client_SetID( CLIENT *Client, const char *ID )
{ {
@ -789,6 +805,21 @@ Client_HostnameDisplayed(CLIENT *Client)
return Client->cloaked; 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. * Update (and generate, if necessary) the cloaked hostname of a client.
* *
@ -1370,6 +1401,11 @@ MyCount( CLIENT_TYPE Type )
} /* MyCount */ } /* MyCount */
/**
* Allocate and initialize new CLIENT strcuture.
*
* @return Pointer to CLIENT structure or NULL on error.
*/
static CLIENT * static CLIENT *
New_Client_Struct( void ) New_Client_Struct( void )
{ {
@ -1392,8 +1428,27 @@ New_Client_Struct( void )
c->mytoken = -1; c->mytoken = -1;
return c; return c;
} /* New_Client */ }
/**
* Free a CLIENT structure and its member variables.
*/
static void
Free_Client(CLIENT **Client)
{
assert(Client != NULL);
assert(*Client != NULL);
if ((*Client)->account_name)
free((*Client)->account_name);
if ((*Client)->cloaked)
free((*Client)->cloaked);
if ((*Client)->ipa_text)
free((*Client)->ipa_text);
free(*Client);
*Client = NULL;
}
static void static void
Generate_MyToken( CLIENT *Client ) Generate_MyToken( CLIENT *Client )

View File

@ -1,6 +1,6 @@
/* /*
* ngIRCd -- The Next Generation IRC Daemon * 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 * 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 * 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) */ struct _CLIENT *topserver; /* toplevel servers (only valid if client is a server) */
char host[CLIENT_HOST_LEN]; /* hostname of the client */ char host[CLIENT_HOST_LEN]; /* hostname of the client */
char *cloaked; /* cloaked 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") */ char user[CLIENT_USER_LEN]; /* user name ("login") */
#if defined(PAM) && defined(IDENTAUTH) #if defined(PAM) && defined(IDENTAUTH)
char orig_user[CLIENT_USER_LEN];/* user name supplied by USER command */ 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_Hostname PARAMS(( CLIENT *Client ));
GLOBAL char *Client_HostnameCloaked PARAMS((CLIENT *Client)); GLOBAL char *Client_HostnameCloaked PARAMS((CLIENT *Client));
GLOBAL char *Client_HostnameDisplayed 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_Modes PARAMS(( CLIENT *Client ));
GLOBAL char *Client_Flags PARAMS(( CLIENT *Client )); GLOBAL char *Client_Flags PARAMS(( CLIENT *Client ));
GLOBAL CLIENT *Client_Introducer 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 bool Client_HasFlag PARAMS(( CLIENT *Client, char Flag ));
GLOBAL void Client_SetHostname PARAMS(( CLIENT *Client, const char *Hostname )); 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_SetID PARAMS(( CLIENT *Client, const char *Nick ));
GLOBAL void Client_SetUser PARAMS(( CLIENT *Client, const char *User, bool Idented )); GLOBAL void Client_SetUser PARAMS(( CLIENT *Client, const char *User, bool Idented ));
GLOBAL void Client_SetOrigUser PARAMS(( CLIENT *Client, const char *User )); GLOBAL void Client_SetOrigUser PARAMS(( CLIENT *Client, const char *User ));

View File

@ -407,8 +407,8 @@ IRC_WHOIS_SendReply(CLIENT *Client, CLIENT *from, CLIENT *c)
(from == c || (!Conf_MorePrivacy && Client_HasMode(from, 'o')))) { (from == c || (!Conf_MorePrivacy && Client_HasMode(from, 'o')))) {
/* Client hostname */ /* Client hostname */
if (!IRC_WriteStrClient(from, RPL_WHOISHOST_MSG, if (!IRC_WriteStrClient(from, RPL_WHOISHOST_MSG,
Client_ID(from), Client_ID(c), Client_Hostname(c), Client_ID(from), Client_ID(c),
Conn_GetIPAInfo(Client_Conn(c)))) Client_Hostname(c), Client_IPAText(c)))
return DISCONNECTED; return DISCONNECTED;
/* Client modes */ /* Client modes */
if (!IRC_WriteStrClient(from, RPL_WHOISMODES_MSG, if (!IRC_WriteStrClient(from, RPL_WHOISMODES_MSG,

View File

@ -610,6 +610,8 @@ IRC_WEBIRC(CLIENT *Client, REQUEST *Req)
Client_SetUser(Client, Req->argv[1], true); Client_SetUser(Client, Req->argv[1], true);
Client_SetOrigUser(Client, Req->argv[1]); Client_SetOrigUser(Client, Req->argv[1]);
Client_SetHostname(Client, Req->argv[2]); Client_SetHostname(Client, Req->argv[2]);
Client_SetIPAText(Client, Req->argv[3]);
return CONNECTED; return CONNECTED;
} /* IRC_WEBIRC */ } /* IRC_WEBIRC */