Skip to content

Commit

Permalink
Added support for connecting and listening to IPv6 addresses.
Browse files Browse the repository at this point in the history
This removes all the IPv4-only legacy functions, to avoid having
islands of API which are IPv4 and IPv6 only. API changes:
rc_find_server: modified (requires flags which specify the server type ACCT/AUTH)
rc_get_src_addr: modified (added const to an argument)
rc_gethostbyname: removed
rc_gethostbyaddr: removed
rc_get_ipaddr: removed
rc_ip_hostname: removed
rc_own_ipaddress: removed
rc_own_bind_ipaddress: removed

The removed functions are obsolete by today's standards, i.e., getaddrinfo()
  • Loading branch information
Nikos Mavrogiannopoulos committed Mar 3, 2015
1 parent 29fa57e commit 9f2da1c
Show file tree
Hide file tree
Showing 10 changed files with 374 additions and 401 deletions.
2 changes: 2 additions & 0 deletions etc/radiusclient.conf.in
Expand Up @@ -34,6 +34,8 @@ issue @pkgsysconfdir@/issue
# RADIUS listens separated by a colon from the hostname. if
# no port is specified /etc/services is consulted of the radius
# service. if this fails also a compiled in default is used.
# For IPv6 addresses use the '[IPv6]:port:secret' format, or
# simply '[IPv6]'.
authserver localhost

# RADIUS server to use for accouting requests. All that I
Expand Down
22 changes: 11 additions & 11 deletions include/freeradius-client.h
Expand Up @@ -34,6 +34,11 @@
#include <stdio.h>
#include <time.h>


/* for struct addrinfo and sockaddr_storage */
#include <sys/socket.h>
#include <netdb.h>

#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
Expand Down Expand Up @@ -94,8 +99,9 @@ typedef struct pw_auth_hdr
struct rc_conf
{
struct _option *config_options;
uint32_t this_host_ipaddr;
uint32_t *this_host_bind_ipaddr;
struct sockaddr_storage own_bind_addr;
unsigned own_bind_addr_set;

struct map2id_s *map2id_list;
struct dict_attr *dictionary_attributes;
struct dict_value *dictionary_values;
Expand Down Expand Up @@ -488,7 +494,6 @@ rc_handle *rc_read_config(char const *);
char *rc_conf_str(rc_handle const *, char const *);
int rc_conf_int(rc_handle const *, char const *);
SERVER *rc_conf_srv(rc_handle const *, char const *);
int rc_find_server(rc_handle const *, char const *, uint32_t *, char *);
void rc_config_free(rc_handle *);
int rc_add_config(rc_handle *, char const *, char const *, char const *, int);
rc_handle *rc_config_init(rc_handle *);
Expand All @@ -507,17 +512,12 @@ void rc_dict_free(rc_handle *);

/* ip_util.c */

struct hostent *rc_gethostbyname(char const *);
struct hostent *rc_gethostbyaddr(char const *, size_t, int);
uint32_t rc_get_ipaddr(char const *);

int rc_good_ipaddr(char const *);
char const *rc_ip_hostname(uint32_t);
unsigned short rc_getport(int);
int rc_own_hostname(char *, int);
uint32_t rc_own_ipaddress(rc_handle *);
uint32_t rc_own_bind_ipaddress(rc_handle *);
struct sockaddr;
int rc_get_srcaddr(struct sockaddr *, struct sockaddr *);
int rc_get_srcaddr(struct sockaddr *, const struct sockaddr *);


/* log.c */
Expand All @@ -527,7 +527,7 @@ void rc_log(int, char const *, ...);

/* sendserver.c */

int rc_send_server(rc_handle *, SEND_DATA *, char *);
int rc_send_server(rc_handle *, SEND_DATA *, char *, unsigned flags);

/* util.c */

Expand Down
5 changes: 5 additions & 0 deletions include/includes.h
Expand Up @@ -14,6 +14,9 @@
*
*/

#ifndef RC_INCLUDES_H
# define RC_INCLUDES_H

#include "config.h"

/* AIX requires this to be the first thing in the file. */
Expand Down Expand Up @@ -180,3 +183,5 @@ int sigprocmask (int, sigset_t *, sigset_t *);
/* rlib/lock.c */
int do_lock_exclusive(FILE *);
int do_unlock(FILE *);

#endif
8 changes: 7 additions & 1 deletion lib/avpair.c
Expand Up @@ -588,7 +588,13 @@ int rc_avpair_parse (rc_handle const *rh, char const *buffer, VALUE_PAIR **first
break;

case PW_TYPE_IPADDR:
pair->lvalue = rc_get_ipaddr(valstr);
if (inet_pton(AF_INET, valstr, &pair->lvalue) == 0) {
rc_log(LOG_ERR, "rc_avpair_parse: invalid IPv4 address %s", valstr);
free(pair);
return -1;
}

pair->lvalue = ntohl(pair->lvalue);
break;

case PW_TYPE_IPV6ADDR:
Expand Down
12 changes: 7 additions & 5 deletions lib/buildreq.c
Expand Up @@ -11,8 +11,7 @@
#include <config.h>
#include <includes.h>
#include <freeradius-client.h>

unsigned char rc_get_id();
#include "util.h"

/** Build a skeleton RADIUS request using information from the config file
*
Expand Down Expand Up @@ -73,11 +72,14 @@ int rc_aaa(rc_handle *rh, uint32_t client_port, VALUE_PAIR *send, VALUE_PAIR **r
double start_time = 0;
double now = 0;
time_t dtime;
unsigned type;

if (request_type != PW_ACCOUNTING_REQUEST) {
aaaserver = rc_conf_srv(rh, "authserver");
type = AUTH;
} else {
aaaserver = rc_conf_srv(rh, "acctserver");
type = ACCT;
}
if (aaaserver == NULL)
return ERROR_RC;
Expand Down Expand Up @@ -134,7 +136,7 @@ int rc_aaa(rc_handle *rh, uint32_t client_port, VALUE_PAIR *send, VALUE_PAIR **r
rc_avpair_assign(adt_vp, &dtime, 0);
}

result = rc_send_server (rh, &data, msg);
result = rc_send_server (rh, &data, msg, type);
if (result == TIMEOUT_RC && radius_deadtime > 0)
aaaserver->deadtime_ends[i] = start_time + (double)radius_deadtime;
}
Expand All @@ -161,7 +163,7 @@ int rc_aaa(rc_handle *rh, uint32_t client_port, VALUE_PAIR *send, VALUE_PAIR **r
rc_avpair_assign(adt_vp, &dtime, 0);
}

result = rc_send_server (rh, &data, msg);
result = rc_send_server (rh, &data, msg, type);
if (result != TIMEOUT_RC)
aaaserver->deadtime_ends[i] = -1;
}
Expand Down Expand Up @@ -267,7 +269,7 @@ int rc_check(rc_handle *rh, char *host, char *secret, unsigned short port, char
rc_avpair_add(rh, &(data.send_pairs), PW_SERVICE_TYPE, &service_type, 0, 0);

rc_buildreq(rh, &data, PW_STATUS_SERVER, host, port, secret, timeout, retries);
result = rc_send_server (rh, &data, msg);
result = rc_send_server (rh, &data, msg, ACCT);

rc_avpair_free(data.receive_pairs);

Expand Down

0 comments on commit 9f2da1c

Please sign in to comment.