[monitoring-plugins] check_radius: Replace functions removed in radcli
Holger Weiss
git at monitoring-plugins.org
Fri Nov 18 11:10:11 CET 2016
Module: monitoring-plugins
Branch: master
Commit: 487a9d0a8b0700c06857d4bc35423db4e4dbc3d6
Author: Holger Weiss <holger at zedat.fu-berlin.de>
Date: Thu Nov 17 17:22:37 2016 +0100
URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=487a9d0
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 +++++++++----------
plugins/check_smtp.c | 4 ----
plugins/netutils.c | 15 ++++++++-------
plugins/netutils.h | 7 ++++++-
4 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/plugins/check_radius.c b/plugins/check_radius.c
index 518f158..b3b8c82 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"));
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index 1996c6d..05e81f2 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -59,10 +59,6 @@ enum {
#define SMTP_STARTTLS "STARTTLS\r\n"
#define SMTP_AUTH_LOGIN "AUTH LOGIN\r\n"
-#ifndef HOST_MAX_BYTES
-#define HOST_MAX_BYTES 255
-#endif
-
#define EHLO_SUPPORTS_STARTTLS 1
int process_arguments (int, char **);
diff --git a/plugins/netutils.c b/plugins/netutils.c
index 705aaf0..1bb4f07 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -359,20 +359,21 @@ is_addr (const char *address)
}
int
-resolve_host_or_addr (const char *address, int family)
+dns_lookup (const char *in, struct sockaddr_storage *ss, int family)
{
struct addrinfo hints;
struct addrinfo *res;
int retval;
- memset (&hints, 0, sizeof (hints));
+ memset (&hints, 0, sizeof(struct addrinfo));
hints.ai_family = family;
- retval = getaddrinfo (address, NULL, &hints, &res);
+ retval = getaddrinfo (in, NULL, &hints, &res);
if (retval != 0)
return FALSE;
- else {
- freeaddrinfo (res);
- return TRUE;
- }
+
+ if (ss != NULL)
+ memcpy (ss, res->ai_addr, res->ai_addrlen);
+ freeaddrinfo (res);
+ return TRUE;
}
diff --git a/plugins/netutils.h b/plugins/netutils.h
index 2766029..d7ee0dd 100644
--- a/plugins/netutils.h
+++ b/plugins/netutils.h
@@ -45,6 +45,10 @@
# endif /* UNIX_PATH_MAX */
#endif /* HAVE_SYS_UN_H */
+#ifndef HOST_MAX_BYTES
+# define HOST_MAX_BYTES 255
+#endif
+
/* process_request and wrapper macros */
#define process_tcp_request(addr, port, sbuf, rbuf, rsize) \
process_request(addr, port, IPPROTO_TCP, sbuf, rbuf, rsize)
@@ -71,8 +75,9 @@ int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer,
/* "is_*" wrapper macros and functions */
int is_host (const char *);
int is_addr (const char *);
-int resolve_host_or_addr (const char *, int);
+int dns_lookup (const char *, struct sockaddr_storage *, int);
void host_or_die(const char *str);
+#define resolve_host_or_addr(addr, family) dns_lookup(addr, NULL, family)
#define is_inet_addr(addr) resolve_host_or_addr(addr, AF_INET)
#ifdef USE_IPV6
# define is_inet6_addr(addr) resolve_host_or_addr(addr, AF_INET6)
More information about the Commits
mailing list