2008-01-31 05:44:26 -05:00
|
|
|
/*****************************************************************************
|
|
|
|
|
*
|
2014-01-19 21:12:50 -05:00
|
|
|
* Monitoring check_radius plugin
|
2008-01-31 05:44:26 -05:00
|
|
|
*
|
2006-06-20 07:17:03 -04:00
|
|
|
* License: GPL
|
2014-01-18 03:40:24 -05:00
|
|
|
* Copyright (c) 1999-2008 Monitoring Plugins Development Team
|
2008-01-31 05:44:26 -05:00
|
|
|
*
|
2006-06-20 07:17:03 -04:00
|
|
|
* Description:
|
2008-01-31 05:44:26 -05:00
|
|
|
*
|
2006-06-20 07:17:03 -04:00
|
|
|
* This file contains the check_radius plugin
|
2008-01-31 05:44:26 -05:00
|
|
|
*
|
|
|
|
|
* Tests to see if a radius server is accepting connections.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2006-06-20 07:17:03 -04:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2008-01-31 05:44:26 -05:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2006-06-20 07:17:03 -04:00
|
|
|
* (at your option) any later version.
|
2008-01-31 05:44:26 -05:00
|
|
|
*
|
2006-06-20 07:17:03 -04:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
2008-01-31 05:44:26 -05:00
|
|
|
*
|
2006-06-20 07:17:03 -04:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2008-01-31 05:44:26 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
2006-06-20 07:17:03 -04:00
|
|
|
*
|
2008-01-31 05:44:26 -05:00
|
|
|
*****************************************************************************/
|
2002-02-28 01:42:51 -05:00
|
|
|
|
2003-01-16 01:22:03 -05:00
|
|
|
const char *progname = "check_radius";
|
2008-04-23 04:19:13 -04:00
|
|
|
const char *copyright = "2000-2008";
|
2014-01-18 03:40:24 -05:00
|
|
|
const char *email = "devel@monitoring-plugins.org";
|
2003-08-04 03:42:24 -04:00
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
#include "utils.h"
|
2003-08-10 02:53:22 -04:00
|
|
|
#include "netutils.h"
|
2004-12-03 18:02:04 -05:00
|
|
|
|
2016-11-05 12:22:39 -04:00
|
|
|
#if defined(HAVE_LIBRADCLI)
|
|
|
|
|
#include <radcli/radcli.h>
|
|
|
|
|
#elif defined(HAVE_LIBFREERADIUS_CLIENT)
|
2014-06-22 08:10:38 -04:00
|
|
|
#include <freeradius-client.h>
|
|
|
|
|
#elif defined(HAVE_LIBRADIUSCLIENT_NG)
|
2007-09-23 05:48:37 -04:00
|
|
|
#include <radiusclient-ng.h>
|
|
|
|
|
#else
|
2003-08-04 03:42:24 -04:00
|
|
|
#include <radiusclient.h>
|
2007-09-23 05:48:37 -04:00
|
|
|
#endif
|
2003-08-04 03:42:24 -04:00
|
|
|
|
2002-02-28 01:42:51 -05:00
|
|
|
int process_arguments (int, char **);
|
2003-08-10 02:53:22 -04:00
|
|
|
void print_help (void);
|
|
|
|
|
void print_usage (void);
|
2002-02-28 01:42:51 -05:00
|
|
|
|
2016-11-05 12:22:39 -04:00
|
|
|
#if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI)
|
2007-09-23 05:48:37 -04:00
|
|
|
#define my_rc_conf_str(a) rc_conf_str(rch,a)
|
2016-11-16 18:03:50 -05:00
|
|
|
#if defined(HAVE_LIBRADCLI)
|
|
|
|
|
#define my_rc_send_server(a,b) rc_send_server(rch,a,b,AUTH)
|
|
|
|
|
#else
|
2007-09-23 05:48:37 -04:00
|
|
|
#define my_rc_send_server(a,b) rc_send_server(rch,a,b)
|
2016-11-16 18:03:50 -05:00
|
|
|
#endif
|
2016-11-05 12:22:39 -04:00
|
|
|
#if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADCLI)
|
2014-06-22 08:10:38 -04:00
|
|
|
#define my_rc_buildreq(a,b,c,d,e,f) rc_buildreq(rch,a,b,c,d,(a)->secret,e,f)
|
|
|
|
|
#else
|
2007-09-23 05:48:37 -04:00
|
|
|
#define my_rc_buildreq(a,b,c,d,e,f) rc_buildreq(rch,a,b,c,d,e,f)
|
2014-06-22 08:10:38 -04:00
|
|
|
#endif
|
2007-09-23 05:48:37 -04:00
|
|
|
#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_avpair_add(a,b,c,d) rc_avpair_add(a, b, c, d)
|
|
|
|
|
#define my_rc_read_dictionary(a) rc_read_dictionary(a)
|
|
|
|
|
#endif
|
2010-04-14 03:38:52 -04:00
|
|
|
|
|
|
|
|
/* REJECT_RC is only defined in some version of radiusclient. It has
|
|
|
|
|
* been reported from radiusclient-ng 0.5.6 on FreeBSD 7.2-RELEASE */
|
|
|
|
|
#ifndef REJECT_RC
|
|
|
|
|
#define REJECT_RC BADRESP_RC
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-09-23 05:48:37 -04:00
|
|
|
int my_rc_read_config(char *);
|
|
|
|
|
|
2016-11-05 12:22:39 -04:00
|
|
|
#if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI)
|
2014-06-22 08:10:38 -04:00
|
|
|
rc_handle *rch = NULL;
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-02-28 01:42:51 -05:00
|
|
|
char *server = NULL;
|
|
|
|
|
char *username = NULL;
|
|
|
|
|
char *password = NULL;
|
2004-03-18 15:31:52 -05:00
|
|
|
char *nasid = NULL;
|
Fix Debian bug #482947: No --nas-ip-address option
| check_radius doesn't seem to provide any way to modify the
| NAS-IP-Address attribute that it uses in the packets it sends, but it
| does so for NAS-Identifier.
|
| Instead, it hardcodes the IP address that it gets from the
| rc_own_ipaddress() library call, and that in turn translates into
| calling gethostbyname() on the result of uname(). This call can easily
| fail, and its result can easily be unsuitable - for example when the
| Nagios instance uses its own virtual host, and you don't want the
| original system hostname leaked to the RADIUS servers you monitor with
| this.
|
| Furthermore, this behaviour is inconsistent with RFC 2865, which
| defines the two attributes as analogous and never suggests hardcoding
| the value of either of them in client software.
Therefore, this commit adds the "-N, --nas-ip-address" option which
allows for specifying the value of the NAS-IP-Address attribute.
| I've also noticed that the original code for NAS-IP-Address hardcoding
| is broken in its error handling - it does "return (ERROR_PC)", which
| is meaningless in the context of check_radius.c. That actually seems
| to be copy&waste from radiusclient-0.3.2/src/radexample.c. :) I fixed
| that.
|
| While debugging, I also took the opportunity to decouple the
| nas-identifier rc_avpair_add() instance from the initial three,
| because this is just bad practice to lump a fourth optional attribute
| into the same block with the required attributes, the error handling
| for which is throwing the same daft message "Out of Memory?"...
[ http://bugs.debian.org/482947 ]
(Contributed by Josip Rodin, forwarded by Jan Wagner.)
2010-04-11 10:33:44 -04:00
|
|
|
char *nasipaddress = NULL;
|
2002-02-28 01:42:51 -05:00
|
|
|
char *expect = NULL;
|
|
|
|
|
char *config_file = NULL;
|
2003-08-10 02:53:22 -04:00
|
|
|
unsigned short port = PW_AUTH_UDP_PORT;
|
2002-02-28 01:42:51 -05:00
|
|
|
int retries = 1;
|
|
|
|
|
int verbose = FALSE;
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
|
|
|
|
|
|
The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@
|
|
|
|
|
tags in the comments. With in the tags, the XML is assembled sequentially.
|
|
|
|
|
You can define entities in tags. You also have all the #defines available as
|
|
|
|
|
entities.
|
|
|
|
|
|
|
|
|
|
Please note that all tags must be lowercase to use the DocBook XML DTD.
|
|
|
|
|
|
|
|
|
|
@@-<article>
|
|
|
|
|
|
|
|
|
|
<sect1>
|
|
|
|
|
<title>Quick Reference</title>
|
|
|
|
|
<!-- The refentry forms a manpage -->
|
|
|
|
|
<refentry>
|
|
|
|
|
<refmeta>
|
|
|
|
|
<manvolnum>5<manvolnum>
|
|
|
|
|
</refmeta>
|
|
|
|
|
<refnamdiv>
|
2003-01-13 07:15:16 -05:00
|
|
|
<refname>&progname;</refname>
|
2002-02-28 01:42:51 -05:00
|
|
|
<refpurpose>&SUMMARY;</refpurpose>
|
|
|
|
|
</refnamdiv>
|
|
|
|
|
</refentry>
|
|
|
|
|
</sect1>
|
|
|
|
|
|
|
|
|
|
<sect1>
|
|
|
|
|
<title>FAQ</title>
|
|
|
|
|
</sect1>
|
|
|
|
|
|
|
|
|
|
<sect1>
|
|
|
|
|
<title>Theory, Installation, and Operation</title>
|
|
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
|
<title>General Description</title>
|
|
|
|
|
<para>
|
|
|
|
|
&DESCRIPTION;
|
|
|
|
|
</para>
|
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
|
<title>Future Enhancements</title>
|
2002-11-13 21:26:34 -05:00
|
|
|
<para>Todo List</para>
|
2002-02-28 01:42:51 -05:00
|
|
|
<itemizedlist>
|
|
|
|
|
<listitem>Add option to get password from a secured file rather than the command line</listitem>
|
|
|
|
|
</itemizedlist>
|
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
|
<title>Functions</title>
|
|
|
|
|
-@@
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
2004-12-01 18:54:51 -05:00
|
|
|
|
|
|
|
|
|
2002-02-28 01:42:51 -05:00
|
|
|
int
|
|
|
|
|
main (int argc, char **argv)
|
|
|
|
|
{
|
2016-11-17 11:22:37 -05:00
|
|
|
struct sockaddr_storage ss;
|
|
|
|
|
char name[HOST_NAME_MAX];
|
2002-02-28 01:42:51 -05:00
|
|
|
char msg[BUFFER_LEN];
|
2003-08-04 03:42:24 -04:00
|
|
|
SEND_DATA data;
|
2004-12-02 19:55:28 -05:00
|
|
|
int result = STATE_UNKNOWN;
|
2014-06-22 08:10:38 -04:00
|
|
|
uint32_t client_id, service;
|
2003-08-10 02:53:22 -04:00
|
|
|
char *str;
|
2002-02-28 01:42:51 -05:00
|
|
|
|
2003-08-22 02:22:38 -04:00
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
|
textdomain (PACKAGE);
|
|
|
|
|
|
2008-05-07 06:02:42 -04:00
|
|
|
/* Parse extra opts if any */
|
|
|
|
|
argv=np_extra_opts (&argc, argv, progname);
|
|
|
|
|
|
2004-12-03 18:55:29 -05:00
|
|
|
if (process_arguments (argc, argv) == ERROR)
|
2004-12-02 11:51:25 -05:00
|
|
|
usage4 (_("Could not parse arguments"));
|
2002-02-28 01:42:51 -05:00
|
|
|
|
2003-08-10 02:53:22 -04:00
|
|
|
str = strdup ("dictionary");
|
2007-09-23 05:48:37 -04:00
|
|
|
if ((config_file && my_rc_read_config (config_file)) ||
|
|
|
|
|
my_rc_read_dictionary (my_rc_conf_str (str)))
|
2014-06-22 15:43:38 -04:00
|
|
|
die (STATE_UNKNOWN, _("Config file error\n"));
|
2002-02-28 01:42:51 -05:00
|
|
|
|
|
|
|
|
service = PW_AUTHENTICATE_ONLY;
|
|
|
|
|
|
2007-01-23 11:42:01 -05:00
|
|
|
memset (&data, 0, sizeof(data));
|
2007-09-23 05:48:37 -04:00
|
|
|
if (!(my_rc_avpair_add (&data.send_pairs, PW_SERVICE_TYPE, &service, 0) &&
|
|
|
|
|
my_rc_avpair_add (&data.send_pairs, PW_USER_NAME, username, 0) &&
|
Fix Debian bug #482947: No --nas-ip-address option
| check_radius doesn't seem to provide any way to modify the
| NAS-IP-Address attribute that it uses in the packets it sends, but it
| does so for NAS-Identifier.
|
| Instead, it hardcodes the IP address that it gets from the
| rc_own_ipaddress() library call, and that in turn translates into
| calling gethostbyname() on the result of uname(). This call can easily
| fail, and its result can easily be unsuitable - for example when the
| Nagios instance uses its own virtual host, and you don't want the
| original system hostname leaked to the RADIUS servers you monitor with
| this.
|
| Furthermore, this behaviour is inconsistent with RFC 2865, which
| defines the two attributes as analogous and never suggests hardcoding
| the value of either of them in client software.
Therefore, this commit adds the "-N, --nas-ip-address" option which
allows for specifying the value of the NAS-IP-Address attribute.
| I've also noticed that the original code for NAS-IP-Address hardcoding
| is broken in its error handling - it does "return (ERROR_PC)", which
| is meaningless in the context of check_radius.c. That actually seems
| to be copy&waste from radiusclient-0.3.2/src/radexample.c. :) I fixed
| that.
|
| While debugging, I also took the opportunity to decouple the
| nas-identifier rc_avpair_add() instance from the initial three,
| because this is just bad practice to lump a fourth optional attribute
| into the same block with the required attributes, the error handling
| for which is throwing the same daft message "Out of Memory?"...
[ http://bugs.debian.org/482947 ]
(Contributed by Josip Rodin, forwarded by Jan Wagner.)
2010-04-11 10:33:44 -04:00
|
|
|
my_rc_avpair_add (&data.send_pairs, PW_USER_PASSWORD, password, 0)
|
|
|
|
|
))
|
2014-06-22 15:43:38 -04:00
|
|
|
die (STATE_UNKNOWN, _("Out of Memory?\n"));
|
2002-02-28 01:42:51 -05:00
|
|
|
|
Fix Debian bug #482947: No --nas-ip-address option
| check_radius doesn't seem to provide any way to modify the
| NAS-IP-Address attribute that it uses in the packets it sends, but it
| does so for NAS-Identifier.
|
| Instead, it hardcodes the IP address that it gets from the
| rc_own_ipaddress() library call, and that in turn translates into
| calling gethostbyname() on the result of uname(). This call can easily
| fail, and its result can easily be unsuitable - for example when the
| Nagios instance uses its own virtual host, and you don't want the
| original system hostname leaked to the RADIUS servers you monitor with
| this.
|
| Furthermore, this behaviour is inconsistent with RFC 2865, which
| defines the two attributes as analogous and never suggests hardcoding
| the value of either of them in client software.
Therefore, this commit adds the "-N, --nas-ip-address" option which
allows for specifying the value of the NAS-IP-Address attribute.
| I've also noticed that the original code for NAS-IP-Address hardcoding
| is broken in its error handling - it does "return (ERROR_PC)", which
| is meaningless in the context of check_radius.c. That actually seems
| to be copy&waste from radiusclient-0.3.2/src/radexample.c. :) I fixed
| that.
|
| While debugging, I also took the opportunity to decouple the
| nas-identifier rc_avpair_add() instance from the initial three,
| because this is just bad practice to lump a fourth optional attribute
| into the same block with the required attributes, the error handling
| for which is throwing the same daft message "Out of Memory?"...
[ http://bugs.debian.org/482947 ]
(Contributed by Josip Rodin, forwarded by Jan Wagner.)
2010-04-11 10:33:44 -04:00
|
|
|
if (nasid != NULL) {
|
|
|
|
|
if (!(my_rc_avpair_add (&data.send_pairs, PW_NAS_IDENTIFIER, nasid, 0)))
|
2014-06-22 15:43:38 -04:00
|
|
|
die (STATE_UNKNOWN, _("Invalid NAS-Identifier\n"));
|
Fix Debian bug #482947: No --nas-ip-address option
| check_radius doesn't seem to provide any way to modify the
| NAS-IP-Address attribute that it uses in the packets it sends, but it
| does so for NAS-Identifier.
|
| Instead, it hardcodes the IP address that it gets from the
| rc_own_ipaddress() library call, and that in turn translates into
| calling gethostbyname() on the result of uname(). This call can easily
| fail, and its result can easily be unsuitable - for example when the
| Nagios instance uses its own virtual host, and you don't want the
| original system hostname leaked to the RADIUS servers you monitor with
| this.
|
| Furthermore, this behaviour is inconsistent with RFC 2865, which
| defines the two attributes as analogous and never suggests hardcoding
| the value of either of them in client software.
Therefore, this commit adds the "-N, --nas-ip-address" option which
allows for specifying the value of the NAS-IP-Address attribute.
| I've also noticed that the original code for NAS-IP-Address hardcoding
| is broken in its error handling - it does "return (ERROR_PC)", which
| is meaningless in the context of check_radius.c. That actually seems
| to be copy&waste from radiusclient-0.3.2/src/radexample.c. :) I fixed
| that.
|
| While debugging, I also took the opportunity to decouple the
| nas-identifier rc_avpair_add() instance from the initial three,
| because this is just bad practice to lump a fourth optional attribute
| into the same block with the required attributes, the error handling
| for which is throwing the same daft message "Out of Memory?"...
[ http://bugs.debian.org/482947 ]
(Contributed by Josip Rodin, forwarded by Jan Wagner.)
2010-04-11 10:33:44 -04:00
|
|
|
}
|
2002-02-28 01:42:51 -05:00
|
|
|
|
2016-11-17 11:22:37 -05:00
|
|
|
if (nasipaddress == NULL) {
|
|
|
|
|
if (gethostname (name, sizeof(name)) != 0)
|
|
|
|
|
die (STATE_UNKNOWN, _("gethostname() failed!\n"));
|
|
|
|
|
nasipaddress = name;
|
Fix Debian bug #482947: No --nas-ip-address option
| check_radius doesn't seem to provide any way to modify the
| NAS-IP-Address attribute that it uses in the packets it sends, but it
| does so for NAS-Identifier.
|
| Instead, it hardcodes the IP address that it gets from the
| rc_own_ipaddress() library call, and that in turn translates into
| calling gethostbyname() on the result of uname(). This call can easily
| fail, and its result can easily be unsuitable - for example when the
| Nagios instance uses its own virtual host, and you don't want the
| original system hostname leaked to the RADIUS servers you monitor with
| this.
|
| Furthermore, this behaviour is inconsistent with RFC 2865, which
| defines the two attributes as analogous and never suggests hardcoding
| the value of either of them in client software.
Therefore, this commit adds the "-N, --nas-ip-address" option which
allows for specifying the value of the NAS-IP-Address attribute.
| I've also noticed that the original code for NAS-IP-Address hardcoding
| is broken in its error handling - it does "return (ERROR_PC)", which
| is meaningless in the context of check_radius.c. That actually seems
| to be copy&waste from radiusclient-0.3.2/src/radexample.c. :) I fixed
| that.
|
| While debugging, I also took the opportunity to decouple the
| nas-identifier rc_avpair_add() instance from the initial three,
| because this is just bad practice to lump a fourth optional attribute
| into the same block with the required attributes, the error handling
| for which is throwing the same daft message "Out of Memory?"...
[ http://bugs.debian.org/482947 ]
(Contributed by Josip Rodin, forwarded by Jan Wagner.)
2010-04-11 10:33:44 -04:00
|
|
|
}
|
2016-11-17 11:22:37 -05:00
|
|
|
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);
|
Fix Debian bug #482947: No --nas-ip-address option
| check_radius doesn't seem to provide any way to modify the
| NAS-IP-Address attribute that it uses in the packets it sends, but it
| does so for NAS-Identifier.
|
| Instead, it hardcodes the IP address that it gets from the
| rc_own_ipaddress() library call, and that in turn translates into
| calling gethostbyname() on the result of uname(). This call can easily
| fail, and its result can easily be unsuitable - for example when the
| Nagios instance uses its own virtual host, and you don't want the
| original system hostname leaked to the RADIUS servers you monitor with
| this.
|
| Furthermore, this behaviour is inconsistent with RFC 2865, which
| defines the two attributes as analogous and never suggests hardcoding
| the value of either of them in client software.
Therefore, this commit adds the "-N, --nas-ip-address" option which
allows for specifying the value of the NAS-IP-Address attribute.
| I've also noticed that the original code for NAS-IP-Address hardcoding
| is broken in its error handling - it does "return (ERROR_PC)", which
| is meaningless in the context of check_radius.c. That actually seems
| to be copy&waste from radiusclient-0.3.2/src/radexample.c. :) I fixed
| that.
|
| While debugging, I also took the opportunity to decouple the
| nas-identifier rc_avpair_add() instance from the initial three,
| because this is just bad practice to lump a fourth optional attribute
| into the same block with the required attributes, the error handling
| for which is throwing the same daft message "Out of Memory?"...
[ http://bugs.debian.org/482947 ]
(Contributed by Josip Rodin, forwarded by Jan Wagner.)
2010-04-11 10:33:44 -04:00
|
|
|
if (my_rc_avpair_add (&(data.send_pairs), PW_NAS_IP_ADDRESS, &client_id, 0) == NULL)
|
2014-06-22 15:43:38 -04:00
|
|
|
die (STATE_UNKNOWN, _("Invalid NAS-IP-Address\n"));
|
2002-02-28 01:42:51 -05:00
|
|
|
|
2007-09-23 05:48:37 -04:00
|
|
|
my_rc_buildreq (&data, PW_ACCESS_REQUEST, server, port, (int)timeout_interval,
|
2003-08-10 02:53:22 -04:00
|
|
|
retries);
|
2002-02-28 01:42:51 -05:00
|
|
|
|
2007-09-23 05:48:37 -04:00
|
|
|
result = my_rc_send_server (&data, msg);
|
2002-02-28 01:42:51 -05:00
|
|
|
rc_avpair_free (data.send_pairs);
|
|
|
|
|
if (data.receive_pairs)
|
|
|
|
|
rc_avpair_free (data.receive_pairs);
|
|
|
|
|
|
|
|
|
|
if (result == TIMEOUT_RC)
|
2014-06-22 15:43:38 -04:00
|
|
|
die (STATE_CRITICAL, _("Timeout\n"));
|
2002-02-28 01:42:51 -05:00
|
|
|
if (result == ERROR_RC)
|
2014-06-22 15:43:38 -04:00
|
|
|
die (STATE_CRITICAL, _("Auth Error\n"));
|
2010-04-14 03:38:52 -04:00
|
|
|
if (result == REJECT_RC)
|
2014-06-22 15:43:38 -04:00
|
|
|
die (STATE_WARNING, _("Auth Failed\n"));
|
2010-04-14 03:38:52 -04:00
|
|
|
if (result == BADRESP_RC)
|
2014-06-22 15:43:38 -04:00
|
|
|
die (STATE_WARNING, _("Bad Response\n"));
|
2002-02-28 01:42:51 -05:00
|
|
|
if (expect && !strstr (msg, expect))
|
2014-06-22 15:43:38 -04:00
|
|
|
die (STATE_WARNING, "%s\n", msg);
|
2002-02-28 01:42:51 -05:00
|
|
|
if (result == OK_RC)
|
2014-06-22 15:43:38 -04:00
|
|
|
die (STATE_OK, _("Auth OK\n"));
|
2010-04-14 03:38:52 -04:00
|
|
|
(void)snprintf(msg, sizeof(msg), _("Unexpected result code %d"), result);
|
2014-06-22 15:43:38 -04:00
|
|
|
die (STATE_UNKNOWN, "%s\n", msg);
|
2002-02-28 01:42:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* process command-line arguments */
|
|
|
|
|
int
|
|
|
|
|
process_arguments (int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
int c;
|
|
|
|
|
|
2003-08-10 02:53:22 -04:00
|
|
|
int option = 0;
|
|
|
|
|
static struct option longopts[] = {
|
2002-02-28 01:42:51 -05:00
|
|
|
{"hostname", required_argument, 0, 'H'},
|
|
|
|
|
{"port", required_argument, 0, 'P'},
|
|
|
|
|
{"username", required_argument, 0, 'u'},
|
|
|
|
|
{"password", required_argument, 0, 'p'},
|
2004-03-18 15:31:52 -05:00
|
|
|
{"nas-id", required_argument, 0, 'n'},
|
Fix Debian bug #482947: No --nas-ip-address option
| check_radius doesn't seem to provide any way to modify the
| NAS-IP-Address attribute that it uses in the packets it sends, but it
| does so for NAS-Identifier.
|
| Instead, it hardcodes the IP address that it gets from the
| rc_own_ipaddress() library call, and that in turn translates into
| calling gethostbyname() on the result of uname(). This call can easily
| fail, and its result can easily be unsuitable - for example when the
| Nagios instance uses its own virtual host, and you don't want the
| original system hostname leaked to the RADIUS servers you monitor with
| this.
|
| Furthermore, this behaviour is inconsistent with RFC 2865, which
| defines the two attributes as analogous and never suggests hardcoding
| the value of either of them in client software.
Therefore, this commit adds the "-N, --nas-ip-address" option which
allows for specifying the value of the NAS-IP-Address attribute.
| I've also noticed that the original code for NAS-IP-Address hardcoding
| is broken in its error handling - it does "return (ERROR_PC)", which
| is meaningless in the context of check_radius.c. That actually seems
| to be copy&waste from radiusclient-0.3.2/src/radexample.c. :) I fixed
| that.
|
| While debugging, I also took the opportunity to decouple the
| nas-identifier rc_avpair_add() instance from the initial three,
| because this is just bad practice to lump a fourth optional attribute
| into the same block with the required attributes, the error handling
| for which is throwing the same daft message "Out of Memory?"...
[ http://bugs.debian.org/482947 ]
(Contributed by Josip Rodin, forwarded by Jan Wagner.)
2010-04-11 10:33:44 -04:00
|
|
|
{"nas-ip-address", required_argument, 0, 'N'},
|
2002-02-28 01:42:51 -05:00
|
|
|
{"filename", required_argument, 0, 'F'},
|
|
|
|
|
{"expect", required_argument, 0, 'e'},
|
|
|
|
|
{"retries", required_argument, 0, 'r'},
|
|
|
|
|
{"timeout", required_argument, 0, 't'},
|
|
|
|
|
{"verbose", no_argument, 0, 'v'},
|
|
|
|
|
{"version", no_argument, 0, 'V'},
|
|
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
while (1) {
|
Fix Debian bug #482947: No --nas-ip-address option
| check_radius doesn't seem to provide any way to modify the
| NAS-IP-Address attribute that it uses in the packets it sends, but it
| does so for NAS-Identifier.
|
| Instead, it hardcodes the IP address that it gets from the
| rc_own_ipaddress() library call, and that in turn translates into
| calling gethostbyname() on the result of uname(). This call can easily
| fail, and its result can easily be unsuitable - for example when the
| Nagios instance uses its own virtual host, and you don't want the
| original system hostname leaked to the RADIUS servers you monitor with
| this.
|
| Furthermore, this behaviour is inconsistent with RFC 2865, which
| defines the two attributes as analogous and never suggests hardcoding
| the value of either of them in client software.
Therefore, this commit adds the "-N, --nas-ip-address" option which
allows for specifying the value of the NAS-IP-Address attribute.
| I've also noticed that the original code for NAS-IP-Address hardcoding
| is broken in its error handling - it does "return (ERROR_PC)", which
| is meaningless in the context of check_radius.c. That actually seems
| to be copy&waste from radiusclient-0.3.2/src/radexample.c. :) I fixed
| that.
|
| While debugging, I also took the opportunity to decouple the
| nas-identifier rc_avpair_add() instance from the initial three,
| because this is just bad practice to lump a fourth optional attribute
| into the same block with the required attributes, the error handling
| for which is throwing the same daft message "Out of Memory?"...
[ http://bugs.debian.org/482947 ]
(Contributed by Josip Rodin, forwarded by Jan Wagner.)
2010-04-11 10:33:44 -04:00
|
|
|
c = getopt_long (argc, argv, "+hVvH:P:F:u:p:n:N:t:r:e:", longopts,
|
2003-08-10 02:53:22 -04:00
|
|
|
&option);
|
2002-02-28 01:42:51 -05:00
|
|
|
|
|
|
|
|
if (c == -1 || c == EOF || c == 1)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
|
case '?': /* print short usage statement if args not parsable */
|
2007-01-28 16:46:41 -05:00
|
|
|
usage5 ();
|
2002-02-28 01:42:51 -05:00
|
|
|
case 'h': /* help */
|
|
|
|
|
print_help ();
|
2015-10-04 13:02:43 -04:00
|
|
|
exit (STATE_UNKNOWN);
|
2002-02-28 01:42:51 -05:00
|
|
|
case 'V': /* version */
|
2008-11-23 00:38:47 -05:00
|
|
|
print_revision (progname, NP_VERSION);
|
2015-10-04 13:02:43 -04:00
|
|
|
exit (STATE_UNKNOWN);
|
2002-02-28 01:42:51 -05:00
|
|
|
case 'v': /* verbose mode */
|
|
|
|
|
verbose = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
case 'H': /* hostname */
|
|
|
|
|
if (is_host (optarg) == FALSE) {
|
2004-12-01 18:54:51 -05:00
|
|
|
usage2 (_("Invalid hostname/address"), optarg);
|
2002-02-28 01:42:51 -05:00
|
|
|
}
|
|
|
|
|
server = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case 'P': /* port */
|
|
|
|
|
if (is_intnonneg (optarg))
|
2016-11-21 08:49:03 -05:00
|
|
|
port = (unsigned short)atoi (optarg);
|
2002-02-28 01:42:51 -05:00
|
|
|
else
|
2004-12-25 18:17:46 -05:00
|
|
|
usage4 (_("Port must be a positive integer"));
|
2002-02-28 01:42:51 -05:00
|
|
|
break;
|
|
|
|
|
case 'u': /* username */
|
|
|
|
|
username = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case 'p': /* password */
|
2008-05-20 03:57:13 -04:00
|
|
|
password = strdup(optarg);
|
|
|
|
|
|
|
|
|
|
/* Delete the password from process list */
|
|
|
|
|
while (*optarg != '\0') {
|
|
|
|
|
*optarg = 'X';
|
|
|
|
|
optarg++;
|
|
|
|
|
}
|
2002-02-28 01:42:51 -05:00
|
|
|
break;
|
2004-03-18 15:31:52 -05:00
|
|
|
case 'n': /* nas id */
|
|
|
|
|
nasid = optarg;
|
|
|
|
|
break;
|
Fix Debian bug #482947: No --nas-ip-address option
| check_radius doesn't seem to provide any way to modify the
| NAS-IP-Address attribute that it uses in the packets it sends, but it
| does so for NAS-Identifier.
|
| Instead, it hardcodes the IP address that it gets from the
| rc_own_ipaddress() library call, and that in turn translates into
| calling gethostbyname() on the result of uname(). This call can easily
| fail, and its result can easily be unsuitable - for example when the
| Nagios instance uses its own virtual host, and you don't want the
| original system hostname leaked to the RADIUS servers you monitor with
| this.
|
| Furthermore, this behaviour is inconsistent with RFC 2865, which
| defines the two attributes as analogous and never suggests hardcoding
| the value of either of them in client software.
Therefore, this commit adds the "-N, --nas-ip-address" option which
allows for specifying the value of the NAS-IP-Address attribute.
| I've also noticed that the original code for NAS-IP-Address hardcoding
| is broken in its error handling - it does "return (ERROR_PC)", which
| is meaningless in the context of check_radius.c. That actually seems
| to be copy&waste from radiusclient-0.3.2/src/radexample.c. :) I fixed
| that.
|
| While debugging, I also took the opportunity to decouple the
| nas-identifier rc_avpair_add() instance from the initial three,
| because this is just bad practice to lump a fourth optional attribute
| into the same block with the required attributes, the error handling
| for which is throwing the same daft message "Out of Memory?"...
[ http://bugs.debian.org/482947 ]
(Contributed by Josip Rodin, forwarded by Jan Wagner.)
2010-04-11 10:33:44 -04:00
|
|
|
case 'N': /* nas ip address */
|
|
|
|
|
nasipaddress = optarg;
|
|
|
|
|
break;
|
2002-02-28 01:42:51 -05:00
|
|
|
case 'F': /* configuration file */
|
|
|
|
|
config_file = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case 'e': /* expect */
|
|
|
|
|
expect = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case 'r': /* retries */
|
|
|
|
|
if (is_intpos (optarg))
|
|
|
|
|
retries = atoi (optarg);
|
|
|
|
|
else
|
2004-12-25 18:17:46 -05:00
|
|
|
usage4 (_("Number of retries must be a positive integer"));
|
2002-02-28 01:42:51 -05:00
|
|
|
break;
|
|
|
|
|
case 't': /* timeout */
|
|
|
|
|
if (is_intpos (optarg))
|
2016-11-21 08:49:03 -05:00
|
|
|
timeout_interval = (unsigned)atoi (optarg);
|
2002-02-28 01:42:51 -05:00
|
|
|
else
|
2004-11-23 19:46:40 -05:00
|
|
|
usage2 (_("Timeout interval must be a positive integer"), optarg);
|
2002-02-28 01:42:51 -05:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-09-26 06:57:44 -04:00
|
|
|
|
|
|
|
|
if (server == NULL)
|
2007-12-10 02:52:00 -05:00
|
|
|
usage4 (_("Hostname was not supplied"));
|
2007-09-26 06:57:44 -04:00
|
|
|
if (username == NULL)
|
|
|
|
|
usage4 (_("User not specified"));
|
|
|
|
|
if (password == NULL)
|
|
|
|
|
usage4 (_("Password not specified"));
|
|
|
|
|
if (config_file == NULL)
|
|
|
|
|
usage4 (_("Configuration file not specified"));
|
|
|
|
|
|
2002-02-28 01:42:51 -05:00
|
|
|
return OK;
|
|
|
|
|
}
|
2003-08-10 02:53:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
print_help (void)
|
|
|
|
|
{
|
|
|
|
|
char *myport;
|
2012-06-29 00:57:48 -04:00
|
|
|
xasprintf (&myport, "%d", PW_AUTH_UDP_PORT);
|
2003-08-10 02:53:22 -04:00
|
|
|
|
2008-11-23 00:38:47 -05:00
|
|
|
print_revision (progname, NP_VERSION);
|
2003-08-10 02:53:22 -04:00
|
|
|
|
2004-11-23 19:46:40 -05:00
|
|
|
printf ("Copyright (c) 1999 Robert August Vincent II\n");
|
|
|
|
|
printf (COPYRIGHT, copyright, email);
|
2003-08-10 02:53:22 -04:00
|
|
|
|
2009-02-19 19:00:13 -05:00
|
|
|
printf("%s\n", _("Tests to see if a RADIUS server is accepting connections."));
|
2006-06-20 07:17:03 -04:00
|
|
|
|
|
|
|
|
printf ("\n\n");
|
2003-08-10 02:53:22 -04:00
|
|
|
|
|
|
|
|
print_usage ();
|
|
|
|
|
|
2010-04-14 06:11:45 -04:00
|
|
|
printf (UT_HELP_VRSN);
|
|
|
|
|
printf (UT_EXTRA_OPTS);
|
2003-08-10 02:53:22 -04:00
|
|
|
|
2010-04-14 06:11:45 -04:00
|
|
|
printf (UT_HOST_PORT, 'P', myport);
|
2003-08-10 02:53:22 -04:00
|
|
|
|
2006-06-20 07:17:03 -04:00
|
|
|
printf (" %s\n", "-u, --username=STRING");
|
|
|
|
|
printf (" %s\n", _("The user to authenticate"));
|
|
|
|
|
printf (" %s\n", "-p, --password=STRING");
|
2016-11-30 11:38:36 -05:00
|
|
|
printf (" %s\n", _("Password for authentication (SECURITY RISK)"));
|
2006-06-20 07:17:03 -04:00
|
|
|
printf (" %s\n", "-n, --nas-id=STRING");
|
|
|
|
|
printf (" %s\n", _("NAS identifier"));
|
Fix Debian bug #482947: No --nas-ip-address option
| check_radius doesn't seem to provide any way to modify the
| NAS-IP-Address attribute that it uses in the packets it sends, but it
| does so for NAS-Identifier.
|
| Instead, it hardcodes the IP address that it gets from the
| rc_own_ipaddress() library call, and that in turn translates into
| calling gethostbyname() on the result of uname(). This call can easily
| fail, and its result can easily be unsuitable - for example when the
| Nagios instance uses its own virtual host, and you don't want the
| original system hostname leaked to the RADIUS servers you monitor with
| this.
|
| Furthermore, this behaviour is inconsistent with RFC 2865, which
| defines the two attributes as analogous and never suggests hardcoding
| the value of either of them in client software.
Therefore, this commit adds the "-N, --nas-ip-address" option which
allows for specifying the value of the NAS-IP-Address attribute.
| I've also noticed that the original code for NAS-IP-Address hardcoding
| is broken in its error handling - it does "return (ERROR_PC)", which
| is meaningless in the context of check_radius.c. That actually seems
| to be copy&waste from radiusclient-0.3.2/src/radexample.c. :) I fixed
| that.
|
| While debugging, I also took the opportunity to decouple the
| nas-identifier rc_avpair_add() instance from the initial three,
| because this is just bad practice to lump a fourth optional attribute
| into the same block with the required attributes, the error handling
| for which is throwing the same daft message "Out of Memory?"...
[ http://bugs.debian.org/482947 ]
(Contributed by Josip Rodin, forwarded by Jan Wagner.)
2010-04-11 10:33:44 -04:00
|
|
|
printf (" %s\n", "-N, --nas-ip-address=STRING");
|
|
|
|
|
printf (" %s\n", _("NAS IP Address"));
|
2006-06-20 07:17:03 -04:00
|
|
|
printf (" %s\n", "-F, --filename=STRING");
|
|
|
|
|
printf (" %s\n", _("Configuration file"));
|
|
|
|
|
printf (" %s\n", "-e, --expect=STRING");
|
|
|
|
|
printf (" %s\n", _("Response string to expect from the server"));
|
|
|
|
|
printf (" %s\n", "-r, --retries=INTEGER");
|
|
|
|
|
printf (" %s\n", _("Number of times to retry a failed connection"));
|
2003-08-10 02:53:22 -04:00
|
|
|
|
plugins/*.c: Alterations for timeout messages.
.c file changes for misleading timeout messages in help functions. Solution to pull request #1209 tracker by awiddersheim.
Files: plugins/check_apt.c, plugins/check_by_ssh.c, plugins/check_dbi.c, plugins/check_dig.c, plugins/check_disk.c, plugins/check_dns.c, plugins/check_game.c, plugins/check_http.c, plugins/check_ldap.c, plugins/check_ntp.c, plugins/check_ntp_peer.c, plugins/check_ntp_time.c, plugins/check_nwstat.c, plugins/check_overcr.c, plugins/check_pgsql.c, plugins/check_ping.c, plugins/check_procs.c, plugins/check_radius.c, plugins/check_real.c, plugins/check_smtp.c, plugins/check_snmp.c, plugins/check_ssh.c, plugins/check_tcp.c, plugins/check_time.c, plugins/check_ups.c, plugins/negate.c
2014-01-20 15:05:37 -05:00
|
|
|
printf (UT_CONN_TIMEOUT, timeout_interval);
|
2003-08-10 02:53:22 -04:00
|
|
|
|
2008-04-27 10:35:26 -04:00
|
|
|
printf ("\n");
|
2009-02-19 19:00:13 -05:00
|
|
|
printf ("%s\n", _("This plugin tests a RADIUS server to see if it is accepting connections."));
|
2006-06-20 07:17:03 -04:00
|
|
|
printf ("%s\n", _("The server to test must be specified in the invocation, as well as a user"));
|
|
|
|
|
printf ("%s\n", _("name and password. A configuration file may also be present. The format of"));
|
|
|
|
|
printf ("%s\n", _("the configuration file is described in the radiusclient library sources."));
|
|
|
|
|
printf ("%s\n", _("The password option presents a substantial security issue because the"));
|
2008-05-20 03:57:13 -04:00
|
|
|
printf ("%s\n", _("password can possibly be determined by careful watching of the command line"));
|
2014-01-19 20:20:28 -05:00
|
|
|
printf ("%s\n", _("in a process listing. This risk is exacerbated because the plugin will"));
|
|
|
|
|
printf ("%s\n", _("typically be executed at regular predictable intervals. Please be sure that"));
|
2008-04-23 04:19:13 -04:00
|
|
|
printf ("%s\n", _("the password used does not allow access to sensitive system resources."));
|
2003-08-10 02:53:22 -04:00
|
|
|
|
2010-04-14 06:11:45 -04:00
|
|
|
printf (UT_SUPPORT);
|
2003-08-10 02:53:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
print_usage (void)
|
|
|
|
|
{
|
2010-04-22 08:57:14 -04:00
|
|
|
printf ("%s\n", _("Usage:"));
|
Fix Debian bug #482947: No --nas-ip-address option
| check_radius doesn't seem to provide any way to modify the
| NAS-IP-Address attribute that it uses in the packets it sends, but it
| does so for NAS-Identifier.
|
| Instead, it hardcodes the IP address that it gets from the
| rc_own_ipaddress() library call, and that in turn translates into
| calling gethostbyname() on the result of uname(). This call can easily
| fail, and its result can easily be unsuitable - for example when the
| Nagios instance uses its own virtual host, and you don't want the
| original system hostname leaked to the RADIUS servers you monitor with
| this.
|
| Furthermore, this behaviour is inconsistent with RFC 2865, which
| defines the two attributes as analogous and never suggests hardcoding
| the value of either of them in client software.
Therefore, this commit adds the "-N, --nas-ip-address" option which
allows for specifying the value of the NAS-IP-Address attribute.
| I've also noticed that the original code for NAS-IP-Address hardcoding
| is broken in its error handling - it does "return (ERROR_PC)", which
| is meaningless in the context of check_radius.c. That actually seems
| to be copy&waste from radiusclient-0.3.2/src/radexample.c. :) I fixed
| that.
|
| While debugging, I also took the opportunity to decouple the
| nas-identifier rc_avpair_add() instance from the initial three,
| because this is just bad practice to lump a fourth optional attribute
| into the same block with the required attributes, the error handling
| for which is throwing the same daft message "Out of Memory?"...
[ http://bugs.debian.org/482947 ]
(Contributed by Josip Rodin, forwarded by Jan Wagner.)
2010-04-11 10:33:44 -04:00
|
|
|
printf ("%s -H host -F config_file -u username -p password\n\
|
|
|
|
|
[-P port] [-t timeout] [-r retries] [-e expect]\n\
|
|
|
|
|
[-n nas-id] [-N nas-ip-addr]\n", progname);
|
2003-08-10 02:53:22 -04:00
|
|
|
}
|
2007-09-23 05:48:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int my_rc_read_config(char * a)
|
|
|
|
|
{
|
2016-11-05 12:22:39 -04:00
|
|
|
#if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI)
|
2007-09-23 05:48:37 -04:00
|
|
|
rch = rc_read_config(a);
|
|
|
|
|
return (rch == NULL) ? 1 : 0;
|
|
|
|
|
#else
|
|
|
|
|
return rc_read_config(a);
|
|
|
|
|
#endif
|
|
|
|
|
}
|