From 487a9d0a8b0700c06857d4bc35423db4e4dbc3d6 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Thu, 17 Nov 2016 17:22:37 +0100 Subject: check_radius: Replace functions removed in radcli The radcli library no longer offers the rc_get_ipaddr(), rc_good_ipaddr(), and rc_own_ipaddress() functions. --- plugins/check_radius.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'plugins/check_radius.c') diff --git a/plugins/check_radius.c b/plugins/check_radius.c index 518f1588..b3b8c829 100644 --- a/plugins/check_radius.c +++ b/plugins/check_radius.c @@ -62,14 +62,12 @@ void print_usage (void); #else #define my_rc_buildreq(a,b,c,d,e,f) rc_buildreq(rch,a,b,c,d,e,f) #endif -#define my_rc_own_ipaddress() rc_own_ipaddress(rch) #define my_rc_avpair_add(a,b,c,d) rc_avpair_add(rch,a,b,c,-1,d) #define my_rc_read_dictionary(a) rc_read_dictionary(rch, a) #else #define my_rc_conf_str(a) rc_conf_str(a) #define my_rc_send_server(a,b) rc_send_server(a, b) #define my_rc_buildreq(a,b,c,d,e,f) rc_buildreq(a,b,c,d,e,f) -#define my_rc_own_ipaddress() rc_own_ipaddress() #define my_rc_avpair_add(a,b,c,d) rc_avpair_add(a, b, c, d) #define my_rc_read_dictionary(a) rc_read_dictionary(a) #endif @@ -155,6 +153,8 @@ Please note that all tags must be lowercase to use the DocBook XML DTD. int main (int argc, char **argv) { + struct sockaddr_storage ss; + char name[HOST_NAME_MAX]; char msg[BUFFER_LEN]; SEND_DATA data; int result = STATE_UNKNOWN; @@ -190,15 +190,14 @@ main (int argc, char **argv) die (STATE_UNKNOWN, _("Invalid NAS-Identifier\n")); } - if (nasipaddress != NULL) { - if (rc_good_ipaddr (nasipaddress)) - die (STATE_UNKNOWN, _("Invalid NAS-IP-Address\n")); - if ((client_id = rc_get_ipaddr(nasipaddress)) == 0) - die (STATE_UNKNOWN, _("Invalid NAS-IP-Address\n")); - } else { - if ((client_id = my_rc_own_ipaddress ()) == 0) - die (STATE_UNKNOWN, _("Can't find local IP for NAS-IP-Address\n")); + if (nasipaddress == NULL) { + if (gethostname (name, sizeof(name)) != 0) + die (STATE_UNKNOWN, _("gethostname() failed!\n")); + nasipaddress = name; } + if (!dns_lookup (nasipaddress, &ss, AF_INET)) /* TODO: Support IPv6. */ + die (STATE_UNKNOWN, _("Invalid NAS-IP-Address\n")); + client_id = ntohl (((struct sockaddr_in *)&ss)->sin_addr.s_addr); if (my_rc_avpair_add (&(data.send_pairs), PW_NAS_IP_ADDRESS, &client_id, 0) == NULL) die (STATE_UNKNOWN, _("Invalid NAS-IP-Address\n")); -- cgit v1.2.3