mirror of
				https://github.com/osmarks/ngircd.git
				synced 2025-10-30 05:23:00 +00:00 
			
		
		
		
	Change cloaked hostname to be malloc'd on demand
This shaves a few bytes when cloaked hostnames are not used and restricts the cloakhost announcement iif there is something to send.
This commit is contained in:
		| @@ -318,6 +318,8 @@ Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool Sen | |||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | 			if (c->cloaked) | ||||||
|  | 				free(c->cloaked); | ||||||
| 			free( c ); | 			free( c ); | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| @@ -744,8 +746,6 @@ Client_HostnameCloaked(CLIENT *Client) | |||||||
|  * Get (potentially cloaked) hostname of a client to display it to other users. |  * Get (potentially cloaked) hostname of a client to display it to other users. | ||||||
|  * |  * | ||||||
|  * If the client has not enabled cloaking, the real hostname is used. |  * If the client has not enabled cloaking, the real hostname is used. | ||||||
|  * Please note that this function uses a global static buffer, so you can't |  | ||||||
|  * nest invocations without overwriting earlier results! |  | ||||||
|  * |  * | ||||||
|  * @param Client Pointer to client structure |  * @param Client Pointer to client structure | ||||||
|  * @return Pointer to client hostname |  * @return Pointer to client hostname | ||||||
| @@ -760,7 +760,7 @@ Client_HostnameDisplayed(CLIENT *Client) | |||||||
| 		return Client_Hostname(Client); | 		return Client_Hostname(Client); | ||||||
|  |  | ||||||
| 	/* Use an already saved cloaked hostname, if there is one */ | 	/* Use an already saved cloaked hostname, if there is one */ | ||||||
| 	if (Client->cloaked[0]) | 	if (Client->cloaked) | ||||||
| 		return Client->cloaked; | 		return Client->cloaked; | ||||||
|  |  | ||||||
| 	Client_UpdateCloakedHostname(Client, NULL, NULL); | 	Client_UpdateCloakedHostname(Client, NULL, NULL); | ||||||
| @@ -781,25 +781,32 @@ GLOBAL void | |||||||
| Client_UpdateCloakedHostname(CLIENT *Client, CLIENT *Origin, | Client_UpdateCloakedHostname(CLIENT *Client, CLIENT *Origin, | ||||||
| 			     const char *Hostname) | 			     const char *Hostname) | ||||||
| { | { | ||||||
| 	static char Cloak_Buffer[CLIENT_HOST_LEN]; | 	char Cloak_Buffer[CLIENT_HOST_LEN]; | ||||||
|  |  | ||||||
| 	assert(Client != NULL); | 	assert(Client != NULL); | ||||||
| 	if (!Origin) | 	if (!Origin) | ||||||
| 		Origin = Client_ThisServer(); | 		Origin = Client_ThisServer(); | ||||||
|  |  | ||||||
|  | 	if (!Client->cloaked) { | ||||||
|  | 		Client->cloaked = malloc(CLIENT_HOST_LEN); | ||||||
|  | 		if (!Client->cloaked) | ||||||
|  | 			return; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	if (!Hostname) { | 	if (!Hostname) { | ||||||
| 		/* Generate new cloaked hostname */ | 		/* Generate new cloaked hostname */ | ||||||
| 		if (*Conf_CloakHostModeX) { | 		if (*Conf_CloakHostModeX) { | ||||||
| 			strlcpy(Cloak_Buffer, Client->host, CLIENT_HOST_LEN); | 			strlcpy(Cloak_Buffer, Client->host, | ||||||
|  | 				sizeof(Cloak_Buffer)); | ||||||
| 			strlcat(Cloak_Buffer, Conf_CloakHostSalt, | 			strlcat(Cloak_Buffer, Conf_CloakHostSalt, | ||||||
| 				CLIENT_HOST_LEN); | 				sizeof(Cloak_Buffer)); | ||||||
| 			snprintf(Client->cloaked, sizeof(Client->cloaked), | 			snprintf(Client->cloaked, CLIENT_HOST_LEN, | ||||||
| 				 Conf_CloakHostModeX, Hash(Cloak_Buffer)); | 				 Conf_CloakHostModeX, Hash(Cloak_Buffer)); | ||||||
| 		} else | 		} else | ||||||
| 			strlcpy(Client->cloaked, Client_ID(Client->introducer), | 			strlcpy(Client->cloaked, Client_ID(Client->introducer), | ||||||
| 				sizeof(Client->cloaked)); | 				CLIENT_HOST_LEN); | ||||||
| 	} else | 	} else | ||||||
| 		strlcpy(Client->cloaked, Hostname, sizeof(Client->cloaked)); | 		strlcpy(Client->cloaked, Hostname, CLIENT_HOST_LEN); | ||||||
| 	LogDebug("Cloaked hostname of \"%s\" updated to \"%s\"", | 	LogDebug("Cloaked hostname of \"%s\" updated to \"%s\"", | ||||||
| 		 Client_ID(Client), Client->cloaked); | 		 Client_ID(Client), Client->cloaked); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -48,7 +48,7 @@ typedef struct _CLIENT | |||||||
| 	struct _CLIENT *introducer;	/* ID of the servers which the client is connected to */ | 	struct _CLIENT *introducer;	/* ID of the servers which the client is connected to */ | ||||||
| 	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[CLIENT_HOST_LEN];	/* cloaked hostname of the client */ | 	char *cloaked;			/* cloaked hostname of the client */ | ||||||
| 	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 */ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Federico G. Schwindt
					Federico G. Schwindt