Re-fix #5: Always provide IP-address to all users, not just for active clients.

Signed-off-by: Jan Vidar Krey <janvidar@extatic.org>
This commit is contained in:
Jan Vidar Krey 2009-03-13 00:54:37 +01:00
parent 2edafeba4e
commit 3aecd67134
3 changed files with 21 additions and 36 deletions

View File

@ -188,50 +188,35 @@ static int check_required_login_flags(struct user* user, struct adc_message* cmd
*/ */
int check_network(struct user* user, struct adc_message* cmd) int check_network(struct user* user, struct adc_message* cmd)
{ {
int want_ipv4 = 0; const char* address = ip_convert_to_string(&user->ipaddr);
int want_ipv6 = 0;
int nat_override = 0;
const char* address = 0;
/* Add correct/verified IP addresses instead (if requested/stripped) */ /* Check for NAT override address */
address = (char*) net_get_peer_address(user->sd); if (acl_is_ip_nat_override(user->hub->acl, address))
if (address)
{ {
if (strchr(address, '.')) char* client_given_ip = adc_msg_get_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR);
if (strcmp(client_given_ip, "0.0.0.0") != 0)
{ {
user_set_nat_override(user);
adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV6_ADDR); adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV6_ADDR);
adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV6_UDP_PORT); adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV6_UDP_PORT);
want_ipv4 = 1;
}
else if (strchr(address, ':'))
{
adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR);
adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV4_UDP_PORT);
want_ipv6 = 1;
}
/* check if user can do nat override */
if (want_ipv4 && acl_is_ip_nat_override(user->hub->acl, address))
{
char* client_given_ip = adc_msg_get_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR);
if (strcmp(client_given_ip, "0.0.0.0") != 0)
{
user_set_nat_override(user);
nat_override = 1;
}
hub_free(client_given_ip); hub_free(client_given_ip);
return 0;
} }
hub_free(client_given_ip);
} }
if (!nat_override) if (strchr(address, '.'))
{ {
if (want_ipv4) adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV6_ADDR);
adc_msg_add_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR, address); adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV6_UDP_PORT);
adc_msg_add_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR, address);
if (want_ipv6) }
adc_msg_add_named_argument(cmd, ADC_INF_FLAG_IPV6_ADDR, address); else if (strchr(address, ':'))
{
adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR);
adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV4_UDP_PORT);
adc_msg_add_named_argument(cmd, ADC_INF_FLAG_IPV6_ADDR, address);
} }
return 0; return 0;
} }

View File

@ -90,7 +90,7 @@ int ip_convert_to_binary(const char* taddr, struct ip_addr_encap* raw)
} }
char* ip_convert_to_string(struct ip_addr_encap* raw) const char* ip_convert_to_string(struct ip_addr_encap* raw)
{ {
static char address[INET6_ADDRSTRLEN+1]; static char address[INET6_ADDRSTRLEN+1];
memset(address, 0, INET6_ADDRSTRLEN); memset(address, 0, INET6_ADDRSTRLEN);

View File

@ -36,7 +36,7 @@ struct ip_addr_encap {
extern int ip_convert_to_binary(const char* text_addr, struct ip_addr_encap* raw); extern int ip_convert_to_binary(const char* text_addr, struct ip_addr_encap* raw);
extern char* ip_convert_to_string(struct ip_addr_encap* raw); extern const char* ip_convert_to_string(struct ip_addr_encap* raw);
/* /*