1998-11-13 00:53:01 +00:00
|
|
|
.\" Copyright 1998 Juniper Networks, Inc.
|
2009-09-11 11:42:56 +00:00
|
|
|
.\" Copyright 2009 Alexander Motin <mav@FreeBSD.org>.
|
1998-11-13 00:53:01 +00:00
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
1999-08-28 00:22:10 +00:00
|
|
|
.\" $FreeBSD$
|
1998-11-13 00:53:01 +00:00
|
|
|
.\"
|
2009-09-11 11:42:56 +00:00
|
|
|
.Dd August 5, 2009
|
1998-11-13 00:53:01 +00:00
|
|
|
.Dt LIBRADIUS 3
|
2001-07-10 13:41:46 +00:00
|
|
|
.Os
|
1998-11-13 00:53:01 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm libradius
|
2009-09-11 11:42:56 +00:00
|
|
|
.Nd RADIUS client/server library
|
1998-11-13 00:53:01 +00:00
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
.In radlib.h
|
2002-08-09 12:07:17 +00:00
|
|
|
.Ft "struct rad_handle *"
|
1999-10-31 04:47:59 +00:00
|
|
|
.Fn rad_acct_open "void"
|
1998-11-13 00:53:01 +00:00
|
|
|
.Ft int
|
|
|
|
.Fn rad_add_server "struct rad_handle *h" "const char *host" "int port" "const char *secret" "int timeout" "int max_tries"
|
2012-12-06 19:00:37 +00:00
|
|
|
.Ft int
|
2013-01-09 19:49:35 +00:00
|
|
|
.Fn rad_add_server_ex "struct rad_handle *h" "const char *host" "int port" "const char *secret" "int timeout" "int max_tries" "int dead_time" "struct in_addr *bindto"
|
2002-08-09 12:07:17 +00:00
|
|
|
.Ft "struct rad_handle *"
|
1999-10-31 04:47:59 +00:00
|
|
|
.Fn rad_auth_open "void"
|
1998-11-13 00:53:01 +00:00
|
|
|
.Ft void
|
|
|
|
.Fn rad_close "struct rad_handle *h"
|
|
|
|
.Ft int
|
|
|
|
.Fn rad_config "struct rad_handle *h" "const char *file"
|
|
|
|
.Ft int
|
1999-02-05 11:23:44 +00:00
|
|
|
.Fn rad_continue_send_request "struct rad_handle *h" "int selected" "int *fd" "struct timeval *tv"
|
|
|
|
.Ft int
|
1998-11-13 00:53:01 +00:00
|
|
|
.Fn rad_create_request "struct rad_handle *h" "int code"
|
2009-09-11 11:42:56 +00:00
|
|
|
.Ft int
|
|
|
|
.Fn rad_create_response "struct rad_handle *h" "int code"
|
2002-08-09 12:07:17 +00:00
|
|
|
.Ft "struct in_addr"
|
1998-11-13 00:53:01 +00:00
|
|
|
.Fn rad_cvt_addr "const void *data"
|
2012-02-12 18:29:56 +00:00
|
|
|
.Ft uint32_t
|
1998-11-13 00:53:01 +00:00
|
|
|
.Fn rad_cvt_int "const void *data"
|
|
|
|
.Ft char *
|
|
|
|
.Fn rad_cvt_string "const void *data" "size_t len"
|
|
|
|
.Ft int
|
|
|
|
.Fn rad_get_attr "struct rad_handle *h" "const void **data" "size_t *len"
|
1999-02-05 11:23:44 +00:00
|
|
|
.Ft int
|
2012-02-12 18:29:56 +00:00
|
|
|
.Fn rad_get_vendor_attr "uint32_t *vendor" "const void **data" "size_t *len"
|
2002-05-10 02:40:23 +00:00
|
|
|
.Ft int
|
1999-02-05 11:23:44 +00:00
|
|
|
.Fn rad_init_send_request "struct rad_handle *h" "int *fd" "struct timeval *tv"
|
1998-11-13 00:53:01 +00:00
|
|
|
.Ft int
|
|
|
|
.Fn rad_put_addr "struct rad_handle *h" "int type" "struct in_addr addr"
|
|
|
|
.Ft int
|
|
|
|
.Fn rad_put_attr "struct rad_handle *h" "int type" "const void *data" "size_t len"
|
|
|
|
.Ft int
|
2012-02-12 18:29:56 +00:00
|
|
|
.Fn rad_put_int "struct rad_handle *h" "int type" "uint32_t value"
|
1998-11-13 00:53:01 +00:00
|
|
|
.Ft int
|
|
|
|
.Fn rad_put_string "struct rad_handle *h" "int type" "const char *str"
|
|
|
|
.Ft int
|
2004-04-27 15:00:29 +00:00
|
|
|
.Fn rad_put_message_authentic "struct rad_handle *h"
|
|
|
|
.Ft int
|
2002-05-07 10:47:18 +00:00
|
|
|
.Fn rad_put_vendor_addr "struct rad_handle *h" "int vendor" "int type" "struct in_addr addr"
|
|
|
|
.Ft int
|
|
|
|
.Fn rad_put_vendor_attr "struct rad_handle *h" "int vendor" "int type" "const void *data" "size_t len"
|
|
|
|
.Ft int
|
2012-02-12 18:29:56 +00:00
|
|
|
.Fn rad_put_vendor_int "struct rad_handle *h" "int vendor" "int type" "uint32_t value"
|
2002-05-07 10:47:18 +00:00
|
|
|
.Ft int
|
|
|
|
.Fn rad_put_vendor_string "struct rad_handle *h" "int vendor" "int type" "const char *str"
|
2002-06-12 00:21:07 +00:00
|
|
|
.Ft ssize_t
|
|
|
|
.Fn rad_request_authenticator "struct rad_handle *h" "char *buf" "size_t len"
|
2002-05-07 10:47:18 +00:00
|
|
|
.Ft int
|
2009-09-11 11:42:56 +00:00
|
|
|
.Fn rad_receive_request "struct rad_handle *h"
|
|
|
|
.Ft int
|
1998-11-13 00:53:01 +00:00
|
|
|
.Fn rad_send_request "struct rad_handle *h"
|
2009-09-11 11:42:56 +00:00
|
|
|
.Ft int
|
|
|
|
.Fn rad_send_response "struct rad_handle *h"
|
|
|
|
.Ft "struct rad_handle *"
|
|
|
|
.Fn rad_server_open "int fd"
|
2002-08-09 12:07:17 +00:00
|
|
|
.Ft "const char *"
|
2002-06-12 00:21:07 +00:00
|
|
|
.Fn rad_server_secret "struct rad_handle *h"
|
2011-12-20 11:13:44 +00:00
|
|
|
.Ft "void"
|
|
|
|
.Fn rad_bind_to "struct rad_handle *h" "in_addr_t addr"
|
2004-04-27 15:00:29 +00:00
|
|
|
.Ft u_char *
|
|
|
|
.Fn rad_demangle "struct rad_handle *h" "const void *mangled" "size_t mlen"
|
|
|
|
.Ft u_char *
|
|
|
|
.Fn rad_demangle_mppe_key "struct rad_handle *h" "const void *mangled" "size_t mlen" "size_t *len"
|
2002-08-09 12:07:17 +00:00
|
|
|
.Ft "const char *"
|
1998-11-13 00:53:01 +00:00
|
|
|
.Fn rad_strerror "struct rad_handle *h"
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Nm
|
2009-09-11 11:42:56 +00:00
|
|
|
library implements the Remote Authentication Dial In User Service (RADIUS).
|
2004-04-27 15:00:29 +00:00
|
|
|
RADIUS, defined in RFCs 2865 and 2866,
|
1999-10-31 04:47:59 +00:00
|
|
|
allows clients to perform authentication and accounting by means of
|
|
|
|
network requests to remote servers.
|
2002-08-09 12:07:17 +00:00
|
|
|
.Ss Initialization
|
1998-11-13 00:53:01 +00:00
|
|
|
To use the library, an application must first call
|
2012-05-11 20:06:46 +00:00
|
|
|
.Fn rad_auth_open ,
|
1999-10-31 04:47:59 +00:00
|
|
|
.Fn rad_acct_open
|
2009-09-11 11:42:56 +00:00
|
|
|
or
|
|
|
|
.Fn rad_server_open
|
1998-11-13 00:53:01 +00:00
|
|
|
to obtain a
|
2002-08-09 12:07:17 +00:00
|
|
|
.Vt "struct rad_handle *" ,
|
1998-11-13 00:53:01 +00:00
|
|
|
which provides the context for subsequent operations.
|
1999-10-31 04:47:59 +00:00
|
|
|
The former function is used for RADIUS authentication and the
|
|
|
|
latter is used for RADIUS accounting.
|
1998-11-13 00:53:01 +00:00
|
|
|
Calls to
|
2012-05-11 20:06:46 +00:00
|
|
|
.Fn rad_auth_open ,
|
1999-10-31 04:47:59 +00:00
|
|
|
.Fn rad_acct_open
|
2009-09-11 11:42:56 +00:00
|
|
|
and
|
|
|
|
.Fn rad_server_open
|
2002-08-09 12:07:17 +00:00
|
|
|
always succeed unless insufficient virtual memory is available.
|
|
|
|
If
|
1999-10-31 04:47:59 +00:00
|
|
|
the necessary memory cannot be allocated, the functions return
|
1998-11-13 00:53:01 +00:00
|
|
|
.Dv NULL .
|
1999-10-31 04:47:59 +00:00
|
|
|
For compatibility with earlier versions of this library,
|
|
|
|
.Fn rad_open
|
|
|
|
is provided as a synonym for
|
|
|
|
.Fn rad_auth_open .
|
1998-11-13 00:53:01 +00:00
|
|
|
.Pp
|
|
|
|
Before issuing any RADIUS requests, the library must be made aware
|
2002-08-09 12:07:17 +00:00
|
|
|
of the servers it can contact.
|
|
|
|
The easiest way to configure the
|
1998-11-13 00:53:01 +00:00
|
|
|
library is to call
|
|
|
|
.Fn rad_config .
|
|
|
|
.Fn rad_config
|
|
|
|
causes the library to read a configuration file whose format is
|
|
|
|
described in
|
|
|
|
.Xr radius.conf 5 .
|
|
|
|
The pathname of the configuration file is passed as the
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa file
|
1998-11-13 00:53:01 +00:00
|
|
|
argument to
|
|
|
|
.Fn rad_config .
|
|
|
|
This argument may also be given as
|
|
|
|
.Dv NULL ,
|
|
|
|
in which case the standard configuration file
|
|
|
|
.Pa /etc/radius.conf
|
|
|
|
is used.
|
|
|
|
.Fn rad_config
|
2002-08-09 12:07:17 +00:00
|
|
|
returns 0 on success, or \-1 if an error occurs.
|
1998-11-13 00:53:01 +00:00
|
|
|
.Pp
|
|
|
|
The library can also be configured programmatically by calls to
|
2012-12-06 19:00:37 +00:00
|
|
|
.Fn rad_add_server
|
|
|
|
or
|
|
|
|
.Fn rad_add_server_ex .
|
|
|
|
.Fn rad_add_server
|
|
|
|
is a backward compatible function, implemented via
|
|
|
|
.Fn rad_add_server_ex .
|
1998-11-13 00:53:01 +00:00
|
|
|
The
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa host
|
1998-11-13 00:53:01 +00:00
|
|
|
parameter specifies the server host, either as a fully qualified
|
|
|
|
domain name or as a dotted-quad IP address in text form.
|
|
|
|
The
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa port
|
|
|
|
parameter specifies the UDP port to contact on the server.
|
|
|
|
If
|
|
|
|
.Fa port
|
1998-11-13 00:53:01 +00:00
|
|
|
is given as 0, the library looks up the
|
|
|
|
.Ql radius/udp
|
1999-10-31 04:47:59 +00:00
|
|
|
or
|
|
|
|
.Ql radacct/udp
|
2002-08-09 12:07:17 +00:00
|
|
|
service in the network
|
|
|
|
.Xr services 5
|
|
|
|
database, and uses the port found
|
|
|
|
there.
|
|
|
|
If no entry is found, the library uses the standard RADIUS
|
1999-10-31 04:47:59 +00:00
|
|
|
ports, 1812 for authentication and 1813 for accounting.
|
|
|
|
The shared secret for the server host is passed to the
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa secret
|
1998-11-13 00:53:01 +00:00
|
|
|
parameter.
|
2002-08-09 12:07:17 +00:00
|
|
|
It may be any
|
|
|
|
.Dv NUL Ns -terminated
|
|
|
|
string of bytes.
|
|
|
|
The RADIUS protocol
|
1998-11-13 00:53:01 +00:00
|
|
|
ignores all but the leading 128 bytes of the shared secret.
|
|
|
|
The timeout for receiving replies from the server is passed to the
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa timeout
|
|
|
|
parameter, in units of seconds.
|
|
|
|
The maximum number of repeated
|
1998-11-13 00:53:01 +00:00
|
|
|
requests to make before giving up is passed into the
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa max_tries
|
1998-11-13 00:53:01 +00:00
|
|
|
parameter.
|
2012-12-06 19:00:37 +00:00
|
|
|
Time interval in seconds when the server will not be requested
|
|
|
|
if it is marked as dead (did not answer on the last try) set with
|
|
|
|
.Fa dead_time
|
|
|
|
parameter.
|
|
|
|
.Fa bindto
|
|
|
|
parameter is an IP address on the multihomed host that is used as
|
|
|
|
a source address for all requests.
|
1998-11-13 00:53:01 +00:00
|
|
|
.Fn rad_add_server
|
2002-08-09 12:07:17 +00:00
|
|
|
returns 0 on success, or \-1 if an error occurs.
|
1998-11-13 00:53:01 +00:00
|
|
|
.Pp
|
|
|
|
.Fn rad_add_server
|
2012-12-06 19:00:37 +00:00
|
|
|
or
|
|
|
|
.Fn rad_add_server_ex
|
|
|
|
may be called multiple times, and they may be used together with
|
1998-11-13 00:53:01 +00:00
|
|
|
.Fn rad_config .
|
|
|
|
At most 10 servers may be specified.
|
|
|
|
When multiple servers are given, they are tried in round-robin
|
|
|
|
fashion until a valid response is received, or until each server's
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa max_tries
|
1998-11-13 00:53:01 +00:00
|
|
|
limit has been reached.
|
2002-08-09 12:07:17 +00:00
|
|
|
.Ss Creating a RADIUS Request
|
1998-11-13 00:53:01 +00:00
|
|
|
A RADIUS request consists of a code specifying the kind of request,
|
2002-08-09 12:07:17 +00:00
|
|
|
and zero or more attributes which provide additional information.
|
|
|
|
To
|
1998-11-13 00:53:01 +00:00
|
|
|
begin constructing a new request, call
|
|
|
|
.Fn rad_create_request .
|
|
|
|
In addition to the usual
|
2002-08-09 12:07:17 +00:00
|
|
|
.Vt "struct rad_handle *" ,
|
1998-11-13 00:53:01 +00:00
|
|
|
this function takes a
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa code
|
|
|
|
parameter which specifies the type of the request.
|
|
|
|
Most often this
|
1998-11-13 00:53:01 +00:00
|
|
|
will be
|
|
|
|
.Dv RAD_ACCESS_REQUEST .
|
|
|
|
.Fn rad_create_request
|
2002-08-09 12:07:17 +00:00
|
|
|
returns 0 on success, or \-1 on if an error occurs.
|
1998-11-13 00:53:01 +00:00
|
|
|
.Pp
|
|
|
|
After the request has been created with
|
1999-01-22 01:43:25 +00:00
|
|
|
.Fn rad_create_request ,
|
2002-08-09 12:07:17 +00:00
|
|
|
attributes can be attached to it.
|
|
|
|
This is done through calls to
|
1998-11-13 00:53:01 +00:00
|
|
|
.Fn rad_put_addr ,
|
|
|
|
.Fn rad_put_int ,
|
|
|
|
and
|
|
|
|
.Fn rad_put_string .
|
|
|
|
Each accepts a
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa type
|
1998-11-13 00:53:01 +00:00
|
|
|
parameter identifying the attribute, and a value which may be
|
2002-08-09 12:07:17 +00:00
|
|
|
an Internet address, an integer, or a
|
|
|
|
.Dv NUL Ns -terminated
|
|
|
|
string,
|
1998-11-13 00:53:01 +00:00
|
|
|
respectively.
|
2002-05-07 10:47:18 +00:00
|
|
|
Alternatively,
|
|
|
|
.Fn rad_put_vendor_addr ,
|
|
|
|
.Fn rad_put_vendor_int
|
|
|
|
or
|
|
|
|
.Fn rad_put_vendor_string
|
2002-08-09 12:07:17 +00:00
|
|
|
may be used to specify vendor specific attributes.
|
|
|
|
Vendor specific
|
2002-05-07 10:47:18 +00:00
|
|
|
definitions may be found in
|
2003-09-08 19:57:22 +00:00
|
|
|
.In radlib_vs.h
|
1998-11-13 00:53:01 +00:00
|
|
|
.Pp
|
|
|
|
The library also provides a function
|
|
|
|
.Fn rad_put_attr
|
2002-08-09 12:07:17 +00:00
|
|
|
which can be used to supply a raw, uninterpreted attribute.
|
|
|
|
The
|
|
|
|
.Fa data
|
1998-11-13 00:53:01 +00:00
|
|
|
argument points to an array of bytes, and the
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa len
|
1998-11-13 00:53:01 +00:00
|
|
|
argument specifies its length.
|
|
|
|
.Pp
|
2004-04-27 15:00:29 +00:00
|
|
|
It is possible adding the Message-Authenticator to the request.
|
|
|
|
This is an HMAC-MD5 hash of the entire Access-Request packet (see RFC 3579).
|
|
|
|
This attribute must be present in any packet that includes an EAP-Message
|
|
|
|
attribute.
|
|
|
|
It can be added by using the
|
|
|
|
.Fn rad_put_message_authentic
|
|
|
|
function.
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
library
|
|
|
|
calculates the HMAC-MD5 hash implicitly before sending the request.
|
|
|
|
If the Message-Authenticator was found inside the response packet,
|
|
|
|
then the packet is silently dropped, if the validation failed.
|
|
|
|
In order to get this feature, the library should be compiled with
|
|
|
|
OpenSSL support.
|
|
|
|
.Pp
|
1998-11-13 00:53:01 +00:00
|
|
|
The
|
|
|
|
.Fn rad_put_X
|
2002-08-09 12:07:17 +00:00
|
|
|
functions return 0 on success, or \-1 if an error occurs.
|
|
|
|
.Ss Sending the Request and Receiving the Response
|
1999-02-05 11:23:44 +00:00
|
|
|
After the RADIUS request has been constructed, it is sent either by means of
|
|
|
|
.Fn rad_send_request
|
|
|
|
or by a combination of calls to
|
|
|
|
.Fn rad_init_send_request
|
|
|
|
and
|
|
|
|
.Fn rad_continue_send_request .
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn rad_send_request
|
|
|
|
function sends the request and waits for a valid reply,
|
1998-11-13 00:53:01 +00:00
|
|
|
retrying the defined servers in round-robin fashion as necessary.
|
|
|
|
If a valid response is received,
|
|
|
|
.Fn rad_send_request
|
|
|
|
returns the RADIUS code which specifies the type of the response.
|
|
|
|
This will typically be
|
|
|
|
.Dv RAD_ACCESS_ACCEPT ,
|
|
|
|
.Dv RAD_ACCESS_REJECT ,
|
|
|
|
or
|
|
|
|
.Dv RAD_ACCESS_CHALLENGE .
|
|
|
|
If no valid response is received,
|
|
|
|
.Fn rad_send_request
|
2002-08-09 12:07:17 +00:00
|
|
|
returns \-1.
|
1998-11-13 00:53:01 +00:00
|
|
|
.Pp
|
1999-02-05 11:23:44 +00:00
|
|
|
As an alternative, if you do not wish to block waiting for a response,
|
|
|
|
.Fn rad_init_send_request
|
|
|
|
and
|
|
|
|
.Fn rad_continue_send_request
|
2002-08-09 12:07:17 +00:00
|
|
|
may be used instead.
|
|
|
|
If a reply is received from the RADIUS server or a
|
1999-02-05 11:23:44 +00:00
|
|
|
timeout occurs, these functions return a value as described for
|
|
|
|
.Fn rad_send_request .
|
|
|
|
Otherwise, a value of zero is returned and the values pointed to by
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa fd
|
1999-02-05 11:23:44 +00:00
|
|
|
and
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa tv
|
1999-02-05 11:23:44 +00:00
|
|
|
are set to the descriptor and timeout that should be passed to
|
|
|
|
.Xr select 2 .
|
|
|
|
.Pp
|
|
|
|
.Fn rad_init_send_request
|
|
|
|
must be called first, followed by repeated calls to
|
|
|
|
.Fn rad_continue_send_request
|
|
|
|
as long as a return value of zero is given.
|
|
|
|
Between each call, the application should call
|
|
|
|
.Xr select 2 ,
|
|
|
|
passing
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa *fd
|
1999-02-05 11:23:44 +00:00
|
|
|
as a read descriptor and timing out after the interval specified by
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa tv .
|
|
|
|
When
|
|
|
|
.Xr select 2
|
|
|
|
returns,
|
1999-02-05 11:23:44 +00:00
|
|
|
.Fn rad_continue_send_request
|
|
|
|
should be called with
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa selected
|
1999-02-05 11:23:44 +00:00
|
|
|
set to a non-zero value if
|
|
|
|
.Xr select 2
|
|
|
|
indicated that the descriptor is readable.
|
|
|
|
.Pp
|
1998-11-13 00:53:01 +00:00
|
|
|
Like RADIUS requests, each response may contain zero or more
|
2002-08-09 12:07:17 +00:00
|
|
|
attributes.
|
|
|
|
After a response has been received successfully by
|
1999-02-05 11:23:44 +00:00
|
|
|
.Fn rad_send_request
|
|
|
|
or
|
|
|
|
.Fn rad_continue_send_request ,
|
1998-11-13 00:53:01 +00:00
|
|
|
its attributes can be extracted one by one using
|
|
|
|
.Fn rad_get_attr .
|
|
|
|
Each time
|
|
|
|
.Fn rad_get_attr
|
|
|
|
is called, it gets the next attribute from the current response, and
|
|
|
|
stores a pointer to the data and the length of the data via the
|
|
|
|
reference parameters
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa data
|
1998-11-13 00:53:01 +00:00
|
|
|
and
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa len ,
|
|
|
|
respectively.
|
|
|
|
Note that the data resides in the response itself,
|
1998-11-13 00:53:01 +00:00
|
|
|
and must not be modified.
|
|
|
|
A successful call to
|
|
|
|
.Fn rad_get_attr
|
|
|
|
returns the RADIUS attribute type.
|
|
|
|
If no more attributes remain in the current response,
|
|
|
|
.Fn rad_get_attr
|
|
|
|
returns 0.
|
2002-08-09 12:07:17 +00:00
|
|
|
If an error such as a malformed attribute is detected, \-1 is
|
1998-11-13 00:53:01 +00:00
|
|
|
returned.
|
|
|
|
.Pp
|
2002-05-10 02:40:23 +00:00
|
|
|
If
|
|
|
|
.Fn rad_get_attr
|
|
|
|
returns
|
|
|
|
.Dv RAD_VENDOR_SPECIFIC ,
|
|
|
|
.Fn rad_get_vendor_attr
|
|
|
|
may be called to determine the vendor.
|
|
|
|
The vendor specific RADIUS attribute type is returned.
|
|
|
|
The reference parameters
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa data
|
2002-05-10 02:40:23 +00:00
|
|
|
and
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa len
|
2002-05-29 15:59:34 +00:00
|
|
|
(as returned from
|
|
|
|
.Fn rad_get_attr )
|
2002-05-10 02:40:23 +00:00
|
|
|
are passed to
|
|
|
|
.Fn rad_get_vendor_attr ,
|
|
|
|
and are adjusted to point to the vendor specific attribute data.
|
|
|
|
.Pp
|
1998-11-13 00:53:01 +00:00
|
|
|
The common types of attributes can be decoded using
|
|
|
|
.Fn rad_cvt_addr ,
|
|
|
|
.Fn rad_cvt_int ,
|
|
|
|
and
|
|
|
|
.Fn rad_cvt_string .
|
|
|
|
These functions accept a pointer to the attribute data, which should
|
|
|
|
have been obtained using
|
2002-05-10 02:40:23 +00:00
|
|
|
.Fn rad_get_attr
|
|
|
|
and optionally
|
|
|
|
.Fn rad_get_vendor_attr .
|
1998-11-13 00:53:01 +00:00
|
|
|
In the case of
|
|
|
|
.Fn rad_cvt_string ,
|
|
|
|
the length
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa len
|
|
|
|
must also be given.
|
|
|
|
These functions interpret the attribute as an
|
1998-11-13 00:53:01 +00:00
|
|
|
Internet address, an integer, or a string, respectively, and return
|
|
|
|
its value.
|
|
|
|
.Fn rad_cvt_string
|
2002-08-09 12:07:17 +00:00
|
|
|
returns its value as a
|
|
|
|
.Dv NUL Ns -terminated
|
|
|
|
string in dynamically
|
|
|
|
allocated memory.
|
|
|
|
The application should free the string using
|
1998-11-13 00:53:01 +00:00
|
|
|
.Xr free 3
|
|
|
|
when it is no longer needed.
|
|
|
|
.Pp
|
|
|
|
If insufficient virtual memory is available,
|
|
|
|
.Fn rad_cvt_string
|
|
|
|
returns
|
|
|
|
.Dv NULL .
|
|
|
|
.Fn rad_cvt_addr
|
|
|
|
and
|
|
|
|
.Fn rad_cvt_int
|
|
|
|
cannot fail.
|
2002-06-12 00:21:07 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn rad_request_authenticator
|
|
|
|
function may be used to obtain the Request-Authenticator attribute value
|
|
|
|
associated with the current RADIUS server according to the supplied
|
|
|
|
rad_handle.
|
|
|
|
The target buffer
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa buf
|
2002-06-12 00:21:07 +00:00
|
|
|
of length
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa len
|
2002-06-12 00:21:07 +00:00
|
|
|
must be supplied and should be at least 16 bytes.
|
|
|
|
The return value is the number of bytes written to
|
2002-08-09 12:07:17 +00:00
|
|
|
.Fa buf
|
|
|
|
or \-1 to indicate that
|
|
|
|
.Fa len
|
2002-06-12 00:21:07 +00:00
|
|
|
was not large enough.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn rad_server_secret
|
|
|
|
returns the secret shared with the current RADIUS server according to the
|
|
|
|
supplied rad_handle.
|
2004-04-27 15:00:29 +00:00
|
|
|
.Pp
|
|
|
|
The
|
2011-12-20 11:13:44 +00:00
|
|
|
.Fn rad_bind_to
|
|
|
|
assigns a source address for all requests to the current RADIUS server.
|
|
|
|
.Pp
|
|
|
|
The
|
2004-04-27 15:00:29 +00:00
|
|
|
.Fn rad_demangle
|
|
|
|
function demangles attributes containing passwords and MS-CHAPv1 MPPE-Keys.
|
|
|
|
The return value is
|
|
|
|
.Dv NULL
|
|
|
|
on failure, or the plaintext attribute.
|
|
|
|
This value should be freed using
|
|
|
|
.Xr free 3
|
|
|
|
when it is no longer needed.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn rad_demangle_mppe_key
|
|
|
|
function demangles the send- and recv-keys when using MPPE (see RFC 2548).
|
|
|
|
The return value is
|
|
|
|
.Dv NULL
|
|
|
|
on failure, or the plaintext attribute.
|
|
|
|
This value should be freed using
|
|
|
|
.Xr free 3
|
|
|
|
when it is no longer needed.
|
2002-08-09 12:07:17 +00:00
|
|
|
.Ss Obtaining Error Messages
|
1998-11-13 00:53:01 +00:00
|
|
|
Those functions which accept a
|
2002-08-09 12:07:17 +00:00
|
|
|
.Vt "struct rad_handle *"
|
|
|
|
argument record an error message if they fail.
|
|
|
|
The error message
|
1998-11-13 00:53:01 +00:00
|
|
|
can be retrieved by calling
|
|
|
|
.Fn rad_strerror .
|
|
|
|
The message text is overwritten on each new error for the given
|
2002-08-09 12:07:17 +00:00
|
|
|
.Vt "struct rad_handle *" .
|
1998-11-13 00:53:01 +00:00
|
|
|
Thus the message must be copied if it is to be preserved through
|
|
|
|
subsequent library calls using the same handle.
|
2002-08-09 12:07:17 +00:00
|
|
|
.Ss Cleanup
|
1998-11-13 00:53:01 +00:00
|
|
|
To free the resources used by the RADIUS library, call
|
|
|
|
.Fn rad_close .
|
2009-09-11 11:42:56 +00:00
|
|
|
.Ss Server operation
|
2010-08-16 15:18:30 +00:00
|
|
|
Server mode operates much alike to client mode, except packet send and receive
|
2020-10-09 19:12:44 +00:00
|
|
|
steps are swapped.
|
|
|
|
To operate as server you should obtain server context with
|
2009-09-11 11:42:56 +00:00
|
|
|
.Fn rad_server_open
|
|
|
|
function, passing opened and bound UDP socket file descriptor as argument.
|
|
|
|
You should define allowed clients and their secrets using
|
|
|
|
.Fn rad_add_server
|
|
|
|
function. port, timeout and max_tries arguments are ignored in server mode.
|
|
|
|
You should call
|
|
|
|
.Fn rad_receive_request
|
2020-10-09 19:12:44 +00:00
|
|
|
function to receive request from client.
|
|
|
|
If you do not want to block on socket read, you are free to use any
|
|
|
|
poll(), select() or non-blocking sockets for the socket.
|
2009-09-11 11:42:56 +00:00
|
|
|
Received request can be parsed with same parsing functions as for client.
|
|
|
|
To respond to the request you should call
|
|
|
|
.Fn rad_create_response
|
|
|
|
and fill response content with same packet writing functions as for client.
|
|
|
|
When packet is ready, it should be sent with
|
2012-05-11 20:06:46 +00:00
|
|
|
.Fn rad_send_response .
|
1998-11-13 00:53:01 +00:00
|
|
|
.Sh RETURN VALUES
|
2002-08-09 12:07:17 +00:00
|
|
|
The following functions return a non-negative value on success.
|
|
|
|
If
|
|
|
|
they detect an error, they return \-1 and record an error message
|
1998-11-13 00:53:01 +00:00
|
|
|
which can be retrieved using
|
|
|
|
.Fn rad_strerror .
|
|
|
|
.Pp
|
|
|
|
.Bl -item -offset indent -compact
|
|
|
|
.It
|
|
|
|
.Fn rad_add_server
|
|
|
|
.It
|
|
|
|
.Fn rad_config
|
|
|
|
.It
|
|
|
|
.Fn rad_create_request
|
|
|
|
.It
|
2009-09-11 11:42:56 +00:00
|
|
|
.Fn rad_create_response
|
|
|
|
.It
|
1998-11-13 00:53:01 +00:00
|
|
|
.Fn rad_get_attr
|
|
|
|
.It
|
|
|
|
.Fn rad_put_addr
|
|
|
|
.It
|
|
|
|
.Fn rad_put_attr
|
|
|
|
.It
|
|
|
|
.Fn rad_put_int
|
|
|
|
.It
|
|
|
|
.Fn rad_put_string
|
|
|
|
.It
|
2004-04-27 15:00:29 +00:00
|
|
|
.Fn rad_put_message_authentic
|
|
|
|
.It
|
1999-02-05 11:23:44 +00:00
|
|
|
.Fn rad_init_send_request
|
|
|
|
.It
|
|
|
|
.Fn rad_continue_send_request
|
|
|
|
.It
|
1998-11-13 00:53:01 +00:00
|
|
|
.Fn rad_send_request
|
2009-09-11 11:42:56 +00:00
|
|
|
.It
|
|
|
|
.Fn rad_send_response
|
1998-11-13 00:53:01 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The following functions return a
|
|
|
|
.No non- Ns Dv NULL
|
2002-08-09 12:07:17 +00:00
|
|
|
pointer on success.
|
|
|
|
If they are unable to allocate sufficient
|
1998-11-13 00:53:01 +00:00
|
|
|
virtual memory, they return
|
|
|
|
.Dv NULL ,
|
|
|
|
without recording an error message.
|
|
|
|
.Pp
|
|
|
|
.Bl -item -offset indent -compact
|
|
|
|
.It
|
1999-10-31 04:47:59 +00:00
|
|
|
.Fn rad_acct_open
|
1998-11-13 00:53:01 +00:00
|
|
|
.It
|
1999-10-31 04:47:59 +00:00
|
|
|
.Fn rad_auth_open
|
|
|
|
.It
|
2009-09-11 11:42:56 +00:00
|
|
|
.Fn rad_server_open
|
|
|
|
.It
|
1999-10-31 04:47:59 +00:00
|
|
|
.Fn rad_cvt_string
|
1998-11-13 00:53:01 +00:00
|
|
|
.El
|
2004-04-27 15:00:29 +00:00
|
|
|
.Pp
|
|
|
|
The following functions return a
|
|
|
|
.No non- Ns Dv NULL
|
|
|
|
pointer on success.
|
|
|
|
If they fail, they return
|
|
|
|
.Dv NULL ,
|
|
|
|
with recording an error message.
|
|
|
|
.Pp
|
|
|
|
.Bl -item -offset indent -compact
|
|
|
|
.It
|
|
|
|
.Fn rad_demangle
|
|
|
|
.It
|
|
|
|
.Fn rad_demangle_mppe_key
|
|
|
|
.El
|
1998-11-13 00:53:01 +00:00
|
|
|
.Sh FILES
|
2002-08-09 12:07:17 +00:00
|
|
|
.Bl -tag -width indent
|
|
|
|
.It Pa /etc/radius.conf
|
|
|
|
.El
|
1998-11-13 00:53:01 +00:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr radius.conf 5
|
|
|
|
.Rs
|
2002-08-09 12:07:17 +00:00
|
|
|
.%A "C. Rigney, et al"
|
2000-12-29 14:08:20 +00:00
|
|
|
.%T "Remote Authentication Dial In User Service (RADIUS)"
|
2004-04-27 15:00:29 +00:00
|
|
|
.%O "RFC 2865"
|
1998-11-13 00:53:01 +00:00
|
|
|
.Re
|
1999-10-31 04:47:59 +00:00
|
|
|
.Rs
|
2002-08-09 12:07:17 +00:00
|
|
|
.%A "C. Rigney"
|
|
|
|
.%T "RADIUS Accounting"
|
2004-04-27 15:00:29 +00:00
|
|
|
.%O "RFC 2866"
|
|
|
|
.Re
|
|
|
|
.Rs
|
|
|
|
.%A G. Zorn
|
|
|
|
.%T "Microsoft Vendor-specific RADIUS attributes"
|
|
|
|
.%O RFC 2548
|
|
|
|
.Re
|
|
|
|
.Rs
|
|
|
|
.%A C. Rigney, et al
|
|
|
|
.%T "RADIUS extensions"
|
|
|
|
.%O RFC 2869
|
1999-10-31 04:47:59 +00:00
|
|
|
.Re
|
1998-11-13 00:53:01 +00:00
|
|
|
.Sh AUTHORS
|
2002-08-09 12:07:17 +00:00
|
|
|
.An -nosplit
|
1999-10-31 04:47:59 +00:00
|
|
|
This software was originally written by
|
1998-11-13 00:53:01 +00:00
|
|
|
.An John Polstra ,
|
2000-11-14 11:20:58 +00:00
|
|
|
and donated to the
|
|
|
|
.Fx
|
|
|
|
project by Juniper Networks, Inc.
|
2002-08-09 12:07:17 +00:00
|
|
|
.An Oleg Semyonov
|
|
|
|
subsequently added the ability to perform RADIUS
|
1999-10-31 04:47:59 +00:00
|
|
|
accounting.
|
2004-04-27 15:00:29 +00:00
|
|
|
Later additions and changes by
|
|
|
|
.An Michael Bretterklieber .
|
2009-09-11 11:42:56 +00:00
|
|
|
Server mode support was added by
|
|
|
|
.An Alexander Motin .
|