xref: /freebsd/lib/libradius/libradius.3 (revision 3d265fce43746c293ae826e9603adbfe09f93cf6)
1082bfe67SJohn Polstra.\" Copyright 1998 Juniper Networks, Inc.
23fc0b61cSAlexander Motin.\" Copyright 2009 Alexander Motin <mav@FreeBSD.org>.
3082bfe67SJohn Polstra.\" All rights reserved.
4082bfe67SJohn Polstra.\"
5082bfe67SJohn Polstra.\" Redistribution and use in source and binary forms, with or without
6082bfe67SJohn Polstra.\" modification, are permitted provided that the following conditions
7082bfe67SJohn Polstra.\" are met:
8082bfe67SJohn Polstra.\" 1. Redistributions of source code must retain the above copyright
9082bfe67SJohn Polstra.\"    notice, this list of conditions and the following disclaimer.
10082bfe67SJohn Polstra.\" 2. Redistributions in binary form must reproduce the above copyright
11082bfe67SJohn Polstra.\"    notice, this list of conditions and the following disclaimer in the
12082bfe67SJohn Polstra.\"    documentation and/or other materials provided with the distribution.
13082bfe67SJohn Polstra.\"
14082bfe67SJohn Polstra.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15082bfe67SJohn Polstra.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16082bfe67SJohn Polstra.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17082bfe67SJohn Polstra.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18082bfe67SJohn Polstra.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19082bfe67SJohn Polstra.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20082bfe67SJohn Polstra.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21082bfe67SJohn Polstra.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22082bfe67SJohn Polstra.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23082bfe67SJohn Polstra.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24082bfe67SJohn Polstra.\" SUCH DAMAGE.
25082bfe67SJohn Polstra.\"
267f3dea24SPeter Wemm.\" $FreeBSD$
27082bfe67SJohn Polstra.\"
283fc0b61cSAlexander Motin.Dd August 5, 2009
29082bfe67SJohn Polstra.Dt LIBRADIUS 3
30a307d598SRuslan Ermilov.Os
31082bfe67SJohn Polstra.Sh NAME
32082bfe67SJohn Polstra.Nm libradius
333fc0b61cSAlexander Motin.Nd RADIUS client/server library
34082bfe67SJohn Polstra.Sh SYNOPSIS
3532eef9aeSRuslan Ermilov.In radlib.h
3681b380a8SRuslan Ermilov.Ft "struct rad_handle *"
370981dfefSJohn Polstra.Fn rad_acct_open "void"
38082bfe67SJohn Polstra.Ft int
39082bfe67SJohn Polstra.Fn rad_add_server "struct rad_handle *h" "const char *host" "int port" "const char *secret" "int timeout" "int max_tries"
40bf5a1b65SSergey Matveychuk.Ft int
4199d9e4ecSAndrey V. Elsukov.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"
4281b380a8SRuslan Ermilov.Ft "struct rad_handle *"
430981dfefSJohn Polstra.Fn rad_auth_open "void"
44082bfe67SJohn Polstra.Ft void
45082bfe67SJohn Polstra.Fn rad_close "struct rad_handle *h"
46082bfe67SJohn Polstra.Ft int
47082bfe67SJohn Polstra.Fn rad_config "struct rad_handle *h" "const char *file"
48082bfe67SJohn Polstra.Ft int
4948caee2aSBrian Somers.Fn rad_continue_send_request "struct rad_handle *h" "int selected" "int *fd" "struct timeval *tv"
5048caee2aSBrian Somers.Ft int
51082bfe67SJohn Polstra.Fn rad_create_request "struct rad_handle *h" "int code"
523fc0b61cSAlexander Motin.Ft int
533fc0b61cSAlexander Motin.Fn rad_create_response "struct rad_handle *h" "int code"
5481b380a8SRuslan Ermilov.Ft "struct in_addr"
55082bfe67SJohn Polstra.Fn rad_cvt_addr "const void *data"
566b99842aSEd Schouten.Ft uint32_t
57082bfe67SJohn Polstra.Fn rad_cvt_int "const void *data"
58082bfe67SJohn Polstra.Ft char *
59082bfe67SJohn Polstra.Fn rad_cvt_string "const void *data" "size_t len"
60082bfe67SJohn Polstra.Ft int
61082bfe67SJohn Polstra.Fn rad_get_attr "struct rad_handle *h" "const void **data" "size_t *len"
6248caee2aSBrian Somers.Ft int
636b99842aSEd Schouten.Fn rad_get_vendor_attr "uint32_t *vendor" "const void **data" "size_t *len"
64fc3f62faSBrian Somers.Ft int
6548caee2aSBrian Somers.Fn rad_init_send_request "struct rad_handle *h" "int *fd" "struct timeval *tv"
66082bfe67SJohn Polstra.Ft int
67082bfe67SJohn Polstra.Fn rad_put_addr "struct rad_handle *h" "int type" "struct in_addr addr"
68082bfe67SJohn Polstra.Ft int
69082bfe67SJohn Polstra.Fn rad_put_attr "struct rad_handle *h" "int type" "const void *data" "size_t len"
70082bfe67SJohn Polstra.Ft int
716b99842aSEd Schouten.Fn rad_put_int "struct rad_handle *h" "int type" "uint32_t value"
72082bfe67SJohn Polstra.Ft int
73082bfe67SJohn Polstra.Fn rad_put_string "struct rad_handle *h" "int type" "const char *str"
74082bfe67SJohn Polstra.Ft int
75b4b831efSRuslan Ermilov.Fn rad_put_message_authentic "struct rad_handle *h"
76b4b831efSRuslan Ermilov.Ft int
77b49a88f6SBrian Somers.Fn rad_put_vendor_addr "struct rad_handle *h" "int vendor" "int type" "struct in_addr addr"
78b49a88f6SBrian Somers.Ft int
79b49a88f6SBrian Somers.Fn rad_put_vendor_attr "struct rad_handle *h" "int vendor" "int type" "const void *data" "size_t len"
80b49a88f6SBrian Somers.Ft int
816b99842aSEd Schouten.Fn rad_put_vendor_int "struct rad_handle *h" "int vendor" "int type" "uint32_t value"
82b49a88f6SBrian Somers.Ft int
83b49a88f6SBrian Somers.Fn rad_put_vendor_string "struct rad_handle *h" "int vendor" "int type" "const char *str"
84628e6cd4SBrian Somers.Ft ssize_t
85628e6cd4SBrian Somers.Fn rad_request_authenticator "struct rad_handle *h" "char *buf" "size_t len"
86b49a88f6SBrian Somers.Ft int
873fc0b61cSAlexander Motin.Fn rad_receive_request "struct rad_handle *h"
883fc0b61cSAlexander Motin.Ft int
89082bfe67SJohn Polstra.Fn rad_send_request "struct rad_handle *h"
903fc0b61cSAlexander Motin.Ft int
913fc0b61cSAlexander Motin.Fn rad_send_response "struct rad_handle *h"
923fc0b61cSAlexander Motin.Ft "struct rad_handle *"
933fc0b61cSAlexander Motin.Fn rad_server_open "int fd"
9481b380a8SRuslan Ermilov.Ft "const char *"
95628e6cd4SBrian Somers.Fn rad_server_secret "struct rad_handle *h"
9607d7b74bSAlexander V. Chernikov.Ft "void"
9707d7b74bSAlexander V. Chernikov.Fn rad_bind_to "struct rad_handle *h" "in_addr_t addr"
98b4b831efSRuslan Ermilov.Ft u_char *
99b4b831efSRuslan Ermilov.Fn rad_demangle "struct rad_handle *h" "const void *mangled" "size_t mlen"
100b4b831efSRuslan Ermilov.Ft u_char *
101b4b831efSRuslan Ermilov.Fn rad_demangle_mppe_key "struct rad_handle *h" "const void *mangled" "size_t mlen" "size_t *len"
10281b380a8SRuslan Ermilov.Ft "const char *"
103082bfe67SJohn Polstra.Fn rad_strerror "struct rad_handle *h"
104082bfe67SJohn Polstra.Sh DESCRIPTION
105082bfe67SJohn PolstraThe
106082bfe67SJohn Polstra.Nm
1073fc0b61cSAlexander Motinlibrary implements the Remote Authentication Dial In User Service (RADIUS).
108b4b831efSRuslan ErmilovRADIUS, defined in RFCs 2865 and 2866,
1090981dfefSJohn Polstraallows clients to perform authentication and accounting by means of
1100981dfefSJohn Polstranetwork requests to remote servers.
11181b380a8SRuslan Ermilov.Ss Initialization
112082bfe67SJohn PolstraTo use the library, an application must first call
113a3fb6da9SGlen Barber.Fn rad_auth_open ,
1140981dfefSJohn Polstra.Fn rad_acct_open
1153fc0b61cSAlexander Motinor
1163fc0b61cSAlexander Motin.Fn rad_server_open
117082bfe67SJohn Polstrato obtain a
11881b380a8SRuslan Ermilov.Vt "struct rad_handle *" ,
119082bfe67SJohn Polstrawhich provides the context for subsequent operations.
1200981dfefSJohn PolstraThe former function is used for RADIUS authentication and the
1210981dfefSJohn Polstralatter is used for RADIUS accounting.
122082bfe67SJohn PolstraCalls to
123a3fb6da9SGlen Barber.Fn rad_auth_open ,
1240981dfefSJohn Polstra.Fn rad_acct_open
1253fc0b61cSAlexander Motinand
1263fc0b61cSAlexander Motin.Fn rad_server_open
12781b380a8SRuslan Ermilovalways succeed unless insufficient virtual memory is available.
12881b380a8SRuslan ErmilovIf
1290981dfefSJohn Polstrathe necessary memory cannot be allocated, the functions return
130082bfe67SJohn Polstra.Dv NULL .
1310981dfefSJohn PolstraFor compatibility with earlier versions of this library,
1320981dfefSJohn Polstra.Fn rad_open
1330981dfefSJohn Polstrais provided as a synonym for
1340981dfefSJohn Polstra.Fn rad_auth_open .
135082bfe67SJohn Polstra.Pp
136082bfe67SJohn PolstraBefore issuing any RADIUS requests, the library must be made aware
13781b380a8SRuslan Ermilovof the servers it can contact.
13881b380a8SRuslan ErmilovThe easiest way to configure the
139082bfe67SJohn Polstralibrary is to call
140082bfe67SJohn Polstra.Fn rad_config .
141082bfe67SJohn Polstra.Fn rad_config
142082bfe67SJohn Polstracauses the library to read a configuration file whose format is
143082bfe67SJohn Polstradescribed in
144082bfe67SJohn Polstra.Xr radius.conf 5 .
145082bfe67SJohn PolstraThe pathname of the configuration file is passed as the
14681b380a8SRuslan Ermilov.Fa file
147082bfe67SJohn Polstraargument to
148082bfe67SJohn Polstra.Fn rad_config .
149082bfe67SJohn PolstraThis argument may also be given as
150082bfe67SJohn Polstra.Dv NULL ,
151082bfe67SJohn Polstrain which case the standard configuration file
152082bfe67SJohn Polstra.Pa /etc/radius.conf
153082bfe67SJohn Polstrais used.
154082bfe67SJohn Polstra.Fn rad_config
15581b380a8SRuslan Ermilovreturns 0 on success, or \-1 if an error occurs.
156082bfe67SJohn Polstra.Pp
157082bfe67SJohn PolstraThe library can also be configured programmatically by calls to
158bf5a1b65SSergey Matveychuk.Fn rad_add_server
159bf5a1b65SSergey Matveychukor
160bf5a1b65SSergey Matveychuk.Fn rad_add_server_ex .
161bf5a1b65SSergey Matveychuk.Fn rad_add_server
162bf5a1b65SSergey Matveychukis a backward compatible function, implemented via
163bf5a1b65SSergey Matveychuk.Fn rad_add_server_ex .
164082bfe67SJohn PolstraThe
16581b380a8SRuslan Ermilov.Fa host
166082bfe67SJohn Polstraparameter specifies the server host, either as a fully qualified
167082bfe67SJohn Polstradomain name or as a dotted-quad IP address in text form.
168082bfe67SJohn PolstraThe
16981b380a8SRuslan Ermilov.Fa port
17081b380a8SRuslan Ermilovparameter specifies the UDP port to contact on the server.
17181b380a8SRuslan ErmilovIf
17281b380a8SRuslan Ermilov.Fa port
173082bfe67SJohn Polstrais given as 0, the library looks up the
174082bfe67SJohn Polstra.Ql radius/udp
1750981dfefSJohn Polstraor
1760981dfefSJohn Polstra.Ql radacct/udp
17781b380a8SRuslan Ermilovservice in the network
17881b380a8SRuslan Ermilov.Xr services 5
17981b380a8SRuslan Ermilovdatabase, and uses the port found
18081b380a8SRuslan Ermilovthere.
18181b380a8SRuslan ErmilovIf no entry is found, the library uses the standard RADIUS
1820981dfefSJohn Polstraports, 1812 for authentication and 1813 for accounting.
1830981dfefSJohn PolstraThe shared secret for the server host is passed to the
18481b380a8SRuslan Ermilov.Fa secret
185082bfe67SJohn Polstraparameter.
18681b380a8SRuslan ErmilovIt may be any
18781b380a8SRuslan Ermilov.Dv NUL Ns -terminated
18881b380a8SRuslan Ermilovstring of bytes.
18981b380a8SRuslan ErmilovThe RADIUS protocol
190082bfe67SJohn Polstraignores all but the leading 128 bytes of the shared secret.
191082bfe67SJohn PolstraThe timeout for receiving replies from the server is passed to the
19281b380a8SRuslan Ermilov.Fa timeout
19381b380a8SRuslan Ermilovparameter, in units of seconds.
19481b380a8SRuslan ErmilovThe maximum number of repeated
195082bfe67SJohn Polstrarequests to make before giving up is passed into the
19681b380a8SRuslan Ermilov.Fa max_tries
197082bfe67SJohn Polstraparameter.
198bf5a1b65SSergey MatveychukTime interval in seconds when the server will not be requested
199bf5a1b65SSergey Matveychukif it is marked as dead (did not answer on the last try) set with
200bf5a1b65SSergey Matveychuk.Fa dead_time
201bf5a1b65SSergey Matveychukparameter.
202bf5a1b65SSergey Matveychuk.Fa bindto
203bf5a1b65SSergey Matveychukparameter is an IP address on the multihomed host that is used as
204bf5a1b65SSergey Matveychuka source address for all requests.
205082bfe67SJohn Polstra.Fn rad_add_server
20681b380a8SRuslan Ermilovreturns 0 on success, or \-1 if an error occurs.
207082bfe67SJohn Polstra.Pp
208082bfe67SJohn Polstra.Fn rad_add_server
209bf5a1b65SSergey Matveychukor
210bf5a1b65SSergey Matveychuk.Fn rad_add_server_ex
211bf5a1b65SSergey Matveychukmay be called multiple times, and they may be used together with
212082bfe67SJohn Polstra.Fn rad_config .
213082bfe67SJohn PolstraAt most 10 servers may be specified.
214082bfe67SJohn PolstraWhen multiple servers are given, they are tried in round-robin
215082bfe67SJohn Polstrafashion until a valid response is received, or until each server's
21681b380a8SRuslan Ermilov.Fa max_tries
217082bfe67SJohn Polstralimit has been reached.
21881b380a8SRuslan Ermilov.Ss Creating a RADIUS Request
219082bfe67SJohn PolstraA RADIUS request consists of a code specifying the kind of request,
22081b380a8SRuslan Ermilovand zero or more attributes which provide additional information.
22181b380a8SRuslan ErmilovTo
222082bfe67SJohn Polstrabegin constructing a new request, call
223082bfe67SJohn Polstra.Fn rad_create_request .
224082bfe67SJohn PolstraIn addition to the usual
22581b380a8SRuslan Ermilov.Vt "struct rad_handle *" ,
226082bfe67SJohn Polstrathis function takes a
22781b380a8SRuslan Ermilov.Fa code
22881b380a8SRuslan Ermilovparameter which specifies the type of the request.
22981b380a8SRuslan ErmilovMost often this
230082bfe67SJohn Polstrawill be
231082bfe67SJohn Polstra.Dv RAD_ACCESS_REQUEST .
232082bfe67SJohn Polstra.Fn rad_create_request
23381b380a8SRuslan Ermilovreturns 0 on success, or \-1 on if an error occurs.
234082bfe67SJohn Polstra.Pp
235082bfe67SJohn PolstraAfter the request has been created with
236abac9a9eSBrian Somers.Fn rad_create_request ,
23781b380a8SRuslan Ermilovattributes can be attached to it.
23881b380a8SRuslan ErmilovThis is done through calls to
239082bfe67SJohn Polstra.Fn rad_put_addr ,
240082bfe67SJohn Polstra.Fn rad_put_int ,
241082bfe67SJohn Polstraand
242082bfe67SJohn Polstra.Fn rad_put_string .
243082bfe67SJohn PolstraEach accepts a
24481b380a8SRuslan Ermilov.Fa type
245082bfe67SJohn Polstraparameter identifying the attribute, and a value which may be
24681b380a8SRuslan Ermilovan Internet address, an integer, or a
24781b380a8SRuslan Ermilov.Dv NUL Ns -terminated
24881b380a8SRuslan Ermilovstring,
249082bfe67SJohn Polstrarespectively.
250b49a88f6SBrian SomersAlternatively,
251b49a88f6SBrian Somers.Fn rad_put_vendor_addr ,
252b49a88f6SBrian Somers.Fn rad_put_vendor_int
253b49a88f6SBrian Somersor
254b49a88f6SBrian Somers.Fn rad_put_vendor_string
25581b380a8SRuslan Ermilovmay be used to specify vendor specific attributes.
25681b380a8SRuslan ErmilovVendor specific
257b49a88f6SBrian Somersdefinitions may be found in
258fe08efe6SRuslan Ermilov.In radlib_vs.h
259082bfe67SJohn Polstra.Pp
260082bfe67SJohn PolstraThe library also provides a function
261082bfe67SJohn Polstra.Fn rad_put_attr
26281b380a8SRuslan Ermilovwhich can be used to supply a raw, uninterpreted attribute.
26381b380a8SRuslan ErmilovThe
26481b380a8SRuslan Ermilov.Fa data
265082bfe67SJohn Polstraargument points to an array of bytes, and the
26681b380a8SRuslan Ermilov.Fa len
267082bfe67SJohn Polstraargument specifies its length.
268082bfe67SJohn Polstra.Pp
269b4b831efSRuslan ErmilovIt is possible adding the Message-Authenticator to the request.
270b4b831efSRuslan ErmilovThis is an HMAC-MD5 hash of the entire Access-Request packet (see RFC 3579).
271b4b831efSRuslan ErmilovThis attribute must be present in any packet that includes an EAP-Message
272b4b831efSRuslan Ermilovattribute.
273b4b831efSRuslan ErmilovIt can be added by using the
274b4b831efSRuslan Ermilov.Fn rad_put_message_authentic
275b4b831efSRuslan Ermilovfunction.
276b4b831efSRuslan ErmilovThe
277b4b831efSRuslan Ermilov.Nm
278b4b831efSRuslan Ermilovlibrary
279b4b831efSRuslan Ermilovcalculates the HMAC-MD5 hash implicitly before sending the request.
280b4b831efSRuslan ErmilovIf the Message-Authenticator was found inside the response packet,
281b4b831efSRuslan Ermilovthen the packet is silently dropped, if the validation failed.
282b4b831efSRuslan ErmilovIn order to get this feature, the library should be compiled with
283b4b831efSRuslan ErmilovOpenSSL support.
284b4b831efSRuslan Ermilov.Pp
285082bfe67SJohn PolstraThe
286082bfe67SJohn Polstra.Fn rad_put_X
28781b380a8SRuslan Ermilovfunctions return 0 on success, or \-1 if an error occurs.
28881b380a8SRuslan Ermilov.Ss Sending the Request and Receiving the Response
28948caee2aSBrian SomersAfter the RADIUS request has been constructed, it is sent either by means of
29048caee2aSBrian Somers.Fn rad_send_request
29148caee2aSBrian Somersor by a combination of calls to
29248caee2aSBrian Somers.Fn rad_init_send_request
29348caee2aSBrian Somersand
29448caee2aSBrian Somers.Fn rad_continue_send_request .
29548caee2aSBrian Somers.Pp
29648caee2aSBrian SomersThe
29748caee2aSBrian Somers.Fn rad_send_request
29848caee2aSBrian Somersfunction sends the request and waits for a valid reply,
299082bfe67SJohn Polstraretrying the defined servers in round-robin fashion as necessary.
300082bfe67SJohn PolstraIf a valid response is received,
301082bfe67SJohn Polstra.Fn rad_send_request
302082bfe67SJohn Polstrareturns the RADIUS code which specifies the type of the response.
303082bfe67SJohn PolstraThis will typically be
304082bfe67SJohn Polstra.Dv RAD_ACCESS_ACCEPT ,
305082bfe67SJohn Polstra.Dv RAD_ACCESS_REJECT ,
306082bfe67SJohn Polstraor
307082bfe67SJohn Polstra.Dv RAD_ACCESS_CHALLENGE .
308082bfe67SJohn PolstraIf no valid response is received,
309082bfe67SJohn Polstra.Fn rad_send_request
31081b380a8SRuslan Ermilovreturns \-1.
311082bfe67SJohn Polstra.Pp
31248caee2aSBrian SomersAs an alternative, if you do not wish to block waiting for a response,
31348caee2aSBrian Somers.Fn rad_init_send_request
31448caee2aSBrian Somersand
31548caee2aSBrian Somers.Fn rad_continue_send_request
31681b380a8SRuslan Ermilovmay be used instead.
31781b380a8SRuslan ErmilovIf a reply is received from the RADIUS server or a
31848caee2aSBrian Somerstimeout occurs, these functions return a value as described for
31948caee2aSBrian Somers.Fn rad_send_request .
32048caee2aSBrian SomersOtherwise, a value of zero is returned and the values pointed to by
32181b380a8SRuslan Ermilov.Fa fd
32248caee2aSBrian Somersand
32381b380a8SRuslan Ermilov.Fa tv
32448caee2aSBrian Somersare set to the descriptor and timeout that should be passed to
32548caee2aSBrian Somers.Xr select 2 .
32648caee2aSBrian Somers.Pp
32748caee2aSBrian Somers.Fn rad_init_send_request
32848caee2aSBrian Somersmust be called first, followed by repeated calls to
32948caee2aSBrian Somers.Fn rad_continue_send_request
33048caee2aSBrian Somersas long as a return value of zero is given.
33148caee2aSBrian SomersBetween each call, the application should call
33248caee2aSBrian Somers.Xr select 2 ,
33348caee2aSBrian Somerspassing
33481b380a8SRuslan Ermilov.Fa *fd
33548caee2aSBrian Somersas a read descriptor and timing out after the interval specified by
33681b380a8SRuslan Ermilov.Fa tv .
33781b380a8SRuslan ErmilovWhen
33881b380a8SRuslan Ermilov.Xr select 2
33981b380a8SRuslan Ermilovreturns,
34048caee2aSBrian Somers.Fn rad_continue_send_request
34148caee2aSBrian Somersshould be called with
34281b380a8SRuslan Ermilov.Fa selected
34348caee2aSBrian Somersset to a non-zero value if
34448caee2aSBrian Somers.Xr select 2
34548caee2aSBrian Somersindicated that the descriptor is readable.
34648caee2aSBrian Somers.Pp
347082bfe67SJohn PolstraLike RADIUS requests, each response may contain zero or more
34881b380a8SRuslan Ermilovattributes.
34981b380a8SRuslan ErmilovAfter a response has been received successfully by
35048caee2aSBrian Somers.Fn rad_send_request
35148caee2aSBrian Somersor
35248caee2aSBrian Somers.Fn rad_continue_send_request ,
353082bfe67SJohn Polstraits attributes can be extracted one by one using
354082bfe67SJohn Polstra.Fn rad_get_attr .
355082bfe67SJohn PolstraEach time
356082bfe67SJohn Polstra.Fn rad_get_attr
357082bfe67SJohn Polstrais called, it gets the next attribute from the current response, and
358082bfe67SJohn Polstrastores a pointer to the data and the length of the data via the
359082bfe67SJohn Polstrareference parameters
36081b380a8SRuslan Ermilov.Fa data
361082bfe67SJohn Polstraand
36281b380a8SRuslan Ermilov.Fa len ,
36381b380a8SRuslan Ermilovrespectively.
36481b380a8SRuslan ErmilovNote that the data resides in the response itself,
365082bfe67SJohn Polstraand must not be modified.
366082bfe67SJohn PolstraA successful call to
367082bfe67SJohn Polstra.Fn rad_get_attr
368082bfe67SJohn Polstrareturns the RADIUS attribute type.
369082bfe67SJohn PolstraIf no more attributes remain in the current response,
370082bfe67SJohn Polstra.Fn rad_get_attr
371082bfe67SJohn Polstrareturns 0.
37281b380a8SRuslan ErmilovIf an error such as a malformed attribute is detected, \-1 is
373082bfe67SJohn Polstrareturned.
374082bfe67SJohn Polstra.Pp
375fc3f62faSBrian SomersIf
376fc3f62faSBrian Somers.Fn rad_get_attr
377fc3f62faSBrian Somersreturns
378fc3f62faSBrian Somers.Dv RAD_VENDOR_SPECIFIC ,
379fc3f62faSBrian Somers.Fn rad_get_vendor_attr
380fc3f62faSBrian Somersmay be called to determine the vendor.
381fc3f62faSBrian SomersThe vendor specific RADIUS attribute type is returned.
382fc3f62faSBrian SomersThe reference parameters
38381b380a8SRuslan Ermilov.Fa data
384fc3f62faSBrian Somersand
38581b380a8SRuslan Ermilov.Fa len
38648091bb0SRuslan Ermilov(as returned from
38748091bb0SRuslan Ermilov.Fn rad_get_attr )
388fc3f62faSBrian Somersare passed to
389fc3f62faSBrian Somers.Fn rad_get_vendor_attr ,
390fc3f62faSBrian Somersand are adjusted to point to the vendor specific attribute data.
391fc3f62faSBrian Somers.Pp
392082bfe67SJohn PolstraThe common types of attributes can be decoded using
393082bfe67SJohn Polstra.Fn rad_cvt_addr ,
394082bfe67SJohn Polstra.Fn rad_cvt_int ,
395082bfe67SJohn Polstraand
396082bfe67SJohn Polstra.Fn rad_cvt_string .
397082bfe67SJohn PolstraThese functions accept a pointer to the attribute data, which should
398082bfe67SJohn Polstrahave been obtained using
399fc3f62faSBrian Somers.Fn rad_get_attr
400fc3f62faSBrian Somersand optionally
401fc3f62faSBrian Somers.Fn rad_get_vendor_attr .
402082bfe67SJohn PolstraIn the case of
403082bfe67SJohn Polstra.Fn rad_cvt_string ,
404082bfe67SJohn Polstrathe length
40581b380a8SRuslan Ermilov.Fa len
40681b380a8SRuslan Ermilovmust also be given.
40781b380a8SRuslan ErmilovThese functions interpret the attribute as an
408082bfe67SJohn PolstraInternet address, an integer, or a string, respectively, and return
409082bfe67SJohn Polstraits value.
410082bfe67SJohn Polstra.Fn rad_cvt_string
41181b380a8SRuslan Ermilovreturns its value as a
41281b380a8SRuslan Ermilov.Dv NUL Ns -terminated
41381b380a8SRuslan Ermilovstring in dynamically
41481b380a8SRuslan Ermilovallocated memory.
41581b380a8SRuslan ErmilovThe application should free the string using
416082bfe67SJohn Polstra.Xr free 3
417082bfe67SJohn Polstrawhen it is no longer needed.
418082bfe67SJohn Polstra.Pp
419082bfe67SJohn PolstraIf insufficient virtual memory is available,
420082bfe67SJohn Polstra.Fn rad_cvt_string
421082bfe67SJohn Polstrareturns
422082bfe67SJohn Polstra.Dv NULL .
423082bfe67SJohn Polstra.Fn rad_cvt_addr
424082bfe67SJohn Polstraand
425082bfe67SJohn Polstra.Fn rad_cvt_int
426082bfe67SJohn Polstracannot fail.
427628e6cd4SBrian Somers.Pp
428628e6cd4SBrian SomersThe
429628e6cd4SBrian Somers.Fn rad_request_authenticator
430628e6cd4SBrian Somersfunction may be used to obtain the Request-Authenticator attribute value
431628e6cd4SBrian Somersassociated with the current RADIUS server according to the supplied
432628e6cd4SBrian Somersrad_handle.
433628e6cd4SBrian SomersThe target buffer
43481b380a8SRuslan Ermilov.Fa buf
435628e6cd4SBrian Somersof length
43681b380a8SRuslan Ermilov.Fa len
437628e6cd4SBrian Somersmust be supplied and should be at least 16 bytes.
438628e6cd4SBrian SomersThe return value is the number of bytes written to
43981b380a8SRuslan Ermilov.Fa buf
44081b380a8SRuslan Ermilovor \-1 to indicate that
44181b380a8SRuslan Ermilov.Fa len
442628e6cd4SBrian Somerswas not large enough.
443628e6cd4SBrian Somers.Pp
444628e6cd4SBrian SomersThe
445628e6cd4SBrian Somers.Fn rad_server_secret
446628e6cd4SBrian Somersreturns the secret shared with the current RADIUS server according to the
447628e6cd4SBrian Somerssupplied rad_handle.
448b4b831efSRuslan Ermilov.Pp
449b4b831efSRuslan ErmilovThe
45007d7b74bSAlexander V. Chernikov.Fn rad_bind_to
45107d7b74bSAlexander V. Chernikovassigns a source address for all requests to the current RADIUS server.
45207d7b74bSAlexander V. Chernikov.Pp
45307d7b74bSAlexander V. ChernikovThe
454b4b831efSRuslan Ermilov.Fn rad_demangle
455b4b831efSRuslan Ermilovfunction demangles attributes containing passwords and MS-CHAPv1 MPPE-Keys.
456b4b831efSRuslan ErmilovThe return value is
457b4b831efSRuslan Ermilov.Dv NULL
458b4b831efSRuslan Ermilovon failure, or the plaintext attribute.
459b4b831efSRuslan ErmilovThis value should be freed using
460b4b831efSRuslan Ermilov.Xr free 3
461b4b831efSRuslan Ermilovwhen it is no longer needed.
462b4b831efSRuslan Ermilov.Pp
463b4b831efSRuslan ErmilovThe
464b4b831efSRuslan Ermilov.Fn rad_demangle_mppe_key
465b4b831efSRuslan Ermilovfunction demangles the send- and recv-keys when using MPPE (see RFC 2548).
466b4b831efSRuslan ErmilovThe return value is
467b4b831efSRuslan Ermilov.Dv NULL
468b4b831efSRuslan Ermilovon failure, or the plaintext attribute.
469b4b831efSRuslan ErmilovThis value should be freed using
470b4b831efSRuslan Ermilov.Xr free 3
471b4b831efSRuslan Ermilovwhen it is no longer needed.
47281b380a8SRuslan Ermilov.Ss Obtaining Error Messages
473082bfe67SJohn PolstraThose functions which accept a
47481b380a8SRuslan Ermilov.Vt "struct rad_handle *"
47581b380a8SRuslan Ermilovargument record an error message if they fail.
47681b380a8SRuslan ErmilovThe error message
477082bfe67SJohn Polstracan be retrieved by calling
478082bfe67SJohn Polstra.Fn rad_strerror .
479082bfe67SJohn PolstraThe message text is overwritten on each new error for the given
48081b380a8SRuslan Ermilov.Vt "struct rad_handle *" .
481082bfe67SJohn PolstraThus the message must be copied if it is to be preserved through
482082bfe67SJohn Polstrasubsequent library calls using the same handle.
48381b380a8SRuslan Ermilov.Ss Cleanup
484082bfe67SJohn PolstraTo free the resources used by the RADIUS library, call
485082bfe67SJohn Polstra.Fn rad_close .
4863fc0b61cSAlexander Motin.Ss Server operation
487c2025a76SJoel DahlServer mode operates much alike to client mode, except packet send and receive
488*3d265fceSGordon Berglingsteps are swapped.
489*3d265fceSGordon BerglingTo operate as server you should obtain server context with
4903fc0b61cSAlexander Motin.Fn rad_server_open
4913fc0b61cSAlexander Motinfunction, passing opened and bound UDP socket file descriptor as argument.
4923fc0b61cSAlexander MotinYou should define allowed clients and their secrets using
4933fc0b61cSAlexander Motin.Fn rad_add_server
4943fc0b61cSAlexander Motinfunction. port, timeout and max_tries arguments are ignored in server mode.
4953fc0b61cSAlexander MotinYou should call
4963fc0b61cSAlexander Motin.Fn rad_receive_request
497*3d265fceSGordon Berglingfunction to receive request from client.
498*3d265fceSGordon BerglingIf you do not want to block on socket read, you are free to use any
499*3d265fceSGordon Berglingpoll(), select() or non-blocking sockets for the socket.
5003fc0b61cSAlexander MotinReceived request can be parsed with same parsing functions as for client.
5013fc0b61cSAlexander MotinTo respond to the request you should call
5023fc0b61cSAlexander Motin.Fn rad_create_response
5033fc0b61cSAlexander Motinand fill response content with same packet writing functions as for client.
5043fc0b61cSAlexander MotinWhen packet is ready, it should be sent with
505a3fb6da9SGlen Barber.Fn rad_send_response .
506082bfe67SJohn Polstra.Sh RETURN VALUES
50781b380a8SRuslan ErmilovThe following functions return a non-negative value on success.
50881b380a8SRuslan ErmilovIf
50981b380a8SRuslan Ermilovthey detect an error, they return \-1 and record an error message
510082bfe67SJohn Polstrawhich can be retrieved using
511082bfe67SJohn Polstra.Fn rad_strerror .
512082bfe67SJohn Polstra.Pp
513082bfe67SJohn Polstra.Bl -item -offset indent -compact
514082bfe67SJohn Polstra.It
515082bfe67SJohn Polstra.Fn rad_add_server
516082bfe67SJohn Polstra.It
517082bfe67SJohn Polstra.Fn rad_config
518082bfe67SJohn Polstra.It
519082bfe67SJohn Polstra.Fn rad_create_request
520082bfe67SJohn Polstra.It
5213fc0b61cSAlexander Motin.Fn rad_create_response
5223fc0b61cSAlexander Motin.It
523082bfe67SJohn Polstra.Fn rad_get_attr
524082bfe67SJohn Polstra.It
525082bfe67SJohn Polstra.Fn rad_put_addr
526082bfe67SJohn Polstra.It
527082bfe67SJohn Polstra.Fn rad_put_attr
528082bfe67SJohn Polstra.It
529082bfe67SJohn Polstra.Fn rad_put_int
530082bfe67SJohn Polstra.It
531082bfe67SJohn Polstra.Fn rad_put_string
532082bfe67SJohn Polstra.It
533b4b831efSRuslan Ermilov.Fn rad_put_message_authentic
534b4b831efSRuslan Ermilov.It
53548caee2aSBrian Somers.Fn rad_init_send_request
53648caee2aSBrian Somers.It
53748caee2aSBrian Somers.Fn rad_continue_send_request
53848caee2aSBrian Somers.It
539082bfe67SJohn Polstra.Fn rad_send_request
5403fc0b61cSAlexander Motin.It
5413fc0b61cSAlexander Motin.Fn rad_send_response
542082bfe67SJohn Polstra.El
543082bfe67SJohn Polstra.Pp
544082bfe67SJohn PolstraThe following functions return a
545082bfe67SJohn Polstra.No non- Ns Dv NULL
54681b380a8SRuslan Ermilovpointer on success.
54781b380a8SRuslan ErmilovIf they are unable to allocate sufficient
548082bfe67SJohn Polstravirtual memory, they return
549082bfe67SJohn Polstra.Dv NULL ,
550082bfe67SJohn Polstrawithout recording an error message.
551082bfe67SJohn Polstra.Pp
552082bfe67SJohn Polstra.Bl -item -offset indent -compact
553082bfe67SJohn Polstra.It
5540981dfefSJohn Polstra.Fn rad_acct_open
555082bfe67SJohn Polstra.It
5560981dfefSJohn Polstra.Fn rad_auth_open
5570981dfefSJohn Polstra.It
5583fc0b61cSAlexander Motin.Fn rad_server_open
5593fc0b61cSAlexander Motin.It
5600981dfefSJohn Polstra.Fn rad_cvt_string
561082bfe67SJohn Polstra.El
562b4b831efSRuslan Ermilov.Pp
563b4b831efSRuslan ErmilovThe following functions return a
564b4b831efSRuslan Ermilov.No non- Ns Dv NULL
565b4b831efSRuslan Ermilovpointer on success.
566b4b831efSRuslan ErmilovIf they fail, they return
567b4b831efSRuslan Ermilov.Dv NULL ,
568b4b831efSRuslan Ermilovwith recording an error message.
569b4b831efSRuslan Ermilov.Pp
570b4b831efSRuslan Ermilov.Bl -item -offset indent -compact
571b4b831efSRuslan Ermilov.It
572b4b831efSRuslan Ermilov.Fn rad_demangle
573b4b831efSRuslan Ermilov.It
574b4b831efSRuslan Ermilov.Fn rad_demangle_mppe_key
575b4b831efSRuslan Ermilov.El
576082bfe67SJohn Polstra.Sh FILES
57781b380a8SRuslan Ermilov.Bl -tag -width indent
57881b380a8SRuslan Ermilov.It Pa /etc/radius.conf
57981b380a8SRuslan Ermilov.El
580082bfe67SJohn Polstra.Sh SEE ALSO
581082bfe67SJohn Polstra.Xr radius.conf 5
582082bfe67SJohn Polstra.Rs
58381b380a8SRuslan Ermilov.%A "C. Rigney, et al"
58442635956SRuslan Ermilov.%T "Remote Authentication Dial In User Service (RADIUS)"
585b4b831efSRuslan Ermilov.%O "RFC 2865"
586082bfe67SJohn Polstra.Re
5870981dfefSJohn Polstra.Rs
58881b380a8SRuslan Ermilov.%A "C. Rigney"
58981b380a8SRuslan Ermilov.%T "RADIUS Accounting"
590b4b831efSRuslan Ermilov.%O "RFC 2866"
591b4b831efSRuslan Ermilov.Re
592b4b831efSRuslan Ermilov.Rs
593b4b831efSRuslan Ermilov.%A G. Zorn
594b4b831efSRuslan Ermilov.%T "Microsoft Vendor-specific RADIUS attributes"
595b4b831efSRuslan Ermilov.%O RFC 2548
596b4b831efSRuslan Ermilov.Re
597b4b831efSRuslan Ermilov.Rs
598b4b831efSRuslan Ermilov.%A C. Rigney, et al
599b4b831efSRuslan Ermilov.%T "RADIUS extensions"
600b4b831efSRuslan Ermilov.%O RFC 2869
6010981dfefSJohn Polstra.Re
602082bfe67SJohn Polstra.Sh AUTHORS
60381b380a8SRuslan Ermilov.An -nosplit
6040981dfefSJohn PolstraThis software was originally written by
605082bfe67SJohn Polstra.An John Polstra ,
606b5c508fbSRuslan Ermilovand donated to the
607b5c508fbSRuslan Ermilov.Fx
608b5c508fbSRuslan Ermilovproject by Juniper Networks, Inc.
60981b380a8SRuslan Ermilov.An Oleg Semyonov
61081b380a8SRuslan Ermilovsubsequently added the ability to perform RADIUS
6110981dfefSJohn Polstraaccounting.
612b4b831efSRuslan ErmilovLater additions and changes by
613b4b831efSRuslan Ermilov.An Michael Bretterklieber .
6143fc0b61cSAlexander MotinServer mode support was added by
6153fc0b61cSAlexander Motin.An Alexander Motin .
616