xref: /freebsd/lib/libradius/libradius.3 (revision abac9a9ee357d09bdb6deba0cdad6f0be2d93922)
1082bfe67SJohn Polstra.\" Copyright 1998 Juniper Networks, Inc.
2082bfe67SJohn Polstra.\" All rights reserved.
3082bfe67SJohn Polstra.\"
4082bfe67SJohn Polstra.\" Redistribution and use in source and binary forms, with or without
5082bfe67SJohn Polstra.\" modification, are permitted provided that the following conditions
6082bfe67SJohn Polstra.\" are met:
7082bfe67SJohn Polstra.\" 1. Redistributions of source code must retain the above copyright
8082bfe67SJohn Polstra.\"    notice, this list of conditions and the following disclaimer.
9082bfe67SJohn Polstra.\" 2. Redistributions in binary form must reproduce the above copyright
10082bfe67SJohn Polstra.\"    notice, this list of conditions and the following disclaimer in the
11082bfe67SJohn Polstra.\"    documentation and/or other materials provided with the distribution.
12082bfe67SJohn Polstra.\"
13082bfe67SJohn Polstra.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14082bfe67SJohn Polstra.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15082bfe67SJohn Polstra.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16082bfe67SJohn Polstra.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17082bfe67SJohn Polstra.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18082bfe67SJohn Polstra.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19082bfe67SJohn Polstra.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20082bfe67SJohn Polstra.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21082bfe67SJohn Polstra.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22082bfe67SJohn Polstra.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23082bfe67SJohn Polstra.\" SUCH DAMAGE.
24082bfe67SJohn Polstra.\"
25082bfe67SJohn Polstra.\"	$FreeBSD$
26082bfe67SJohn Polstra.\"
27082bfe67SJohn Polstra.Dd July 29, 1998
28082bfe67SJohn Polstra.Dt LIBRADIUS 3
29082bfe67SJohn Polstra.Os FreeBSD
30082bfe67SJohn Polstra.Sh NAME
31082bfe67SJohn Polstra.Nm libradius
32082bfe67SJohn Polstra.Nd RADIUS client library
33082bfe67SJohn Polstra.Sh SYNOPSIS
34082bfe67SJohn Polstra.Fd #include <radlib.h>
35082bfe67SJohn Polstra.Ft int
36082bfe67SJohn Polstra.Fn rad_add_server "struct rad_handle *h" "const char *host" "int port" "const char *secret" "int timeout" "int max_tries"
37082bfe67SJohn Polstra.Ft void
38082bfe67SJohn Polstra.Fn rad_close "struct rad_handle *h"
39082bfe67SJohn Polstra.Ft int
40082bfe67SJohn Polstra.Fn rad_config "struct rad_handle *h" "const char *file"
41082bfe67SJohn Polstra.Ft int
42082bfe67SJohn Polstra.Fn rad_create_request "struct rad_handle *h" "int code"
43082bfe67SJohn Polstra.Ft struct in_addr
44082bfe67SJohn Polstra.Fn rad_cvt_addr "const void *data"
45082bfe67SJohn Polstra.Ft u_int32_t
46082bfe67SJohn Polstra.Fn rad_cvt_int "const void *data"
47082bfe67SJohn Polstra.Ft char *
48082bfe67SJohn Polstra.Fn rad_cvt_string "const void *data" "size_t len"
49082bfe67SJohn Polstra.Ft int
50082bfe67SJohn Polstra.Fn rad_get_attr "struct rad_handle *h" "const void **data" "size_t *len"
51082bfe67SJohn Polstra.Ft struct rad_handle *
52082bfe67SJohn Polstra.Fn rad_open "void"
53082bfe67SJohn Polstra.Ft int
54082bfe67SJohn Polstra.Fn rad_put_addr "struct rad_handle *h" "int type" "struct in_addr addr"
55082bfe67SJohn Polstra.Ft int
56082bfe67SJohn Polstra.Fn rad_put_attr "struct rad_handle *h" "int type" "const void *data" "size_t len"
57082bfe67SJohn Polstra.Ft int
58082bfe67SJohn Polstra.Fn rad_put_int "struct rad_handle *h" "int type" "u_int32_t value"
59082bfe67SJohn Polstra.Ft int
60082bfe67SJohn Polstra.Fn rad_put_string "struct rad_handle *h" "int type" "const char *str"
61082bfe67SJohn Polstra.Ft int
62082bfe67SJohn Polstra.Fn rad_send_request "struct rad_handle *h"
63082bfe67SJohn Polstra.Ft const char *
64082bfe67SJohn Polstra.Fn rad_strerror "struct rad_handle *h"
65082bfe67SJohn Polstra.Sh DESCRIPTION
66082bfe67SJohn PolstraThe
67082bfe67SJohn Polstra.Nm
68082bfe67SJohn Polstralibrary implements the client side of the Remote Authentication
69082bfe67SJohn PolstraDial In User Service (RADIUS).  RADIUS, defined in RFC 2138, allows
70082bfe67SJohn Polstraclients to perform authentication by means of network requests to
71082bfe67SJohn Polstraremote authentication servers.
72082bfe67SJohn Polstra.Sh INITIALIZATION
73082bfe67SJohn PolstraTo use the library, an application must first call
74082bfe67SJohn Polstra.Fn rad_open
75082bfe67SJohn Polstrato obtain a
76082bfe67SJohn Polstra.Va struct rad_handle * ,
77082bfe67SJohn Polstrawhich provides the context for subsequent operations.
78082bfe67SJohn PolstraCalls to
79082bfe67SJohn Polstra.Fn rad_open
80082bfe67SJohn Polstraalways succeed unless insufficient virtual memory is available.  If
81082bfe67SJohn Polstrathe necessary memory cannot be allocated,
82082bfe67SJohn Polstra.Fn rad_open
83082bfe67SJohn Polstrareturns
84082bfe67SJohn Polstra.Dv NULL .
85082bfe67SJohn Polstra.Pp
86082bfe67SJohn PolstraBefore issuing any RADIUS requests, the library must be made aware
87082bfe67SJohn Polstraof the servers it can contact.  The easiest way to configure the
88082bfe67SJohn Polstralibrary is to call
89082bfe67SJohn Polstra.Fn rad_config .
90082bfe67SJohn Polstra.Fn rad_config
91082bfe67SJohn Polstracauses the library to read a configuration file whose format is
92082bfe67SJohn Polstradescribed in
93082bfe67SJohn Polstra.Xr radius.conf 5 .
94082bfe67SJohn PolstraThe pathname of the configuration file is passed as the
95082bfe67SJohn Polstra.Va file
96082bfe67SJohn Polstraargument to
97082bfe67SJohn Polstra.Fn rad_config .
98082bfe67SJohn PolstraThis argument may also be given as
99082bfe67SJohn Polstra.Dv NULL ,
100082bfe67SJohn Polstrain which case the standard configuration file
101082bfe67SJohn Polstra.Pa /etc/radius.conf
102082bfe67SJohn Polstrais used.
103082bfe67SJohn Polstra.Fn rad_config
104082bfe67SJohn Polstrareturns 0 on success, or -1 if an error occurs.
105082bfe67SJohn Polstra.Pp
106082bfe67SJohn PolstraThe library can also be configured programmatically by calls to
107082bfe67SJohn Polstra.Fn rad_add_server .
108082bfe67SJohn PolstraThe
109082bfe67SJohn Polstra.Va host
110082bfe67SJohn Polstraparameter specifies the server host, either as a fully qualified
111082bfe67SJohn Polstradomain name or as a dotted-quad IP address in text form.
112082bfe67SJohn PolstraThe
113082bfe67SJohn Polstra.Va port
114082bfe67SJohn Polstraparameter specifies the UDP port to contact on the server.  If
115082bfe67SJohn Polstra.Va port
116082bfe67SJohn Polstrais given as 0, the library looks up the
117082bfe67SJohn Polstra.Ql radius/udp
118082bfe67SJohn Polstraservice in the network services database, and uses the port found
119082bfe67SJohn Polstrathere.  If no entry is found, the library uses port 1812, the standard
120082bfe67SJohn PolstraRADIUS port.  The shared secret for the server host is passed to the
121082bfe67SJohn Polstra.Va secret
122082bfe67SJohn Polstraparameter.
123082bfe67SJohn PolstraIt may be any NUL-terminated string of bytes.  The RADIUS protocol
124082bfe67SJohn Polstraignores all but the leading 128 bytes of the shared secret.
125082bfe67SJohn PolstraThe timeout for receiving replies from the server is passed to the
126082bfe67SJohn Polstra.Va timeout
127082bfe67SJohn Polstraparameter, in units of seconds.  The maximum number of repeated
128082bfe67SJohn Polstrarequests to make before giving up is passed into the
129082bfe67SJohn Polstra.Va max_tries
130082bfe67SJohn Polstraparameter.
131082bfe67SJohn Polstra.Fn rad_add_server
132082bfe67SJohn Polstrareturns 0 on success, or -1 if an error occurs.
133082bfe67SJohn Polstra.Pp
134082bfe67SJohn Polstra.Fn rad_add_server
135082bfe67SJohn Polstramay be called multiple times, and it may be used together with
136082bfe67SJohn Polstra.Fn rad_config .
137082bfe67SJohn PolstraAt most 10 servers may be specified.
138082bfe67SJohn PolstraWhen multiple servers are given, they are tried in round-robin
139082bfe67SJohn Polstrafashion until a valid response is received, or until each server's
140082bfe67SJohn Polstra.Va max_tries
141082bfe67SJohn Polstralimit has been reached.
142082bfe67SJohn Polstra.Sh CREATING A RADIUS REQUEST
143082bfe67SJohn PolstraA RADIUS request consists of a code specifying the kind of request,
144082bfe67SJohn Polstraand zero or more attributes which provide additional information.  To
145082bfe67SJohn Polstrabegin constructing a new request, call
146082bfe67SJohn Polstra.Fn rad_create_request .
147082bfe67SJohn PolstraIn addition to the usual
148082bfe67SJohn Polstra.Va struct rad_handle * ,
149082bfe67SJohn Polstrathis function takes a
150082bfe67SJohn Polstra.Va code
151082bfe67SJohn Polstraparameter which specifies the type of the request.  Most often this
152082bfe67SJohn Polstrawill be
153082bfe67SJohn Polstra.Dv RAD_ACCESS_REQUEST .
154082bfe67SJohn Polstra.Fn rad_create_request
155082bfe67SJohn Polstrareturns 0 on success, or -1 on if an error occurs.
156082bfe67SJohn Polstra.Pp
157082bfe67SJohn PolstraAfter the request has been created with
158abac9a9eSBrian Somers.Fn rad_create_request ,
159082bfe67SJohn Polstraattributes can be attached to it.  This is done through calls to
160082bfe67SJohn Polstra.Fn rad_put_addr ,
161082bfe67SJohn Polstra.Fn rad_put_int ,
162082bfe67SJohn Polstraand
163082bfe67SJohn Polstra.Fn rad_put_string .
164082bfe67SJohn PolstraEach accepts a
165082bfe67SJohn Polstra.Va type
166082bfe67SJohn Polstraparameter identifying the attribute, and a value which may be
167082bfe67SJohn Polstraan Internet address, an integer, or a NUL-terminated string,
168082bfe67SJohn Polstrarespectively.
169082bfe67SJohn Polstra.Pp
170082bfe67SJohn PolstraThe library also provides a function
171082bfe67SJohn Polstra.Fn rad_put_attr
172082bfe67SJohn Polstrawhich can be used to supply a raw, uninterpreted attribute.  The
173082bfe67SJohn Polstra.Va data
174082bfe67SJohn Polstraargument points to an array of bytes, and the
175082bfe67SJohn Polstra.Va len
176082bfe67SJohn Polstraargument specifies its length.
177082bfe67SJohn Polstra.Pp
178082bfe67SJohn PolstraThe
179082bfe67SJohn Polstra.Fn rad_put_X
180082bfe67SJohn Polstrafunctions return 0 on success, or -1 if an error occurs.
181082bfe67SJohn Polstra.Sh SENDING THE REQUEST AND RECEIVING THE RESPONSE
182082bfe67SJohn PolstraAfter the RADIUS request has been constructed, it is sent by means
183082bfe67SJohn Polstraof
184082bfe67SJohn Polstra.Fn rad_send_request .
185082bfe67SJohn PolstraThis function sends the request and waits for a valid reply,
186082bfe67SJohn Polstraretrying the defined servers in round-robin fashion as necessary.
187082bfe67SJohn PolstraIf a valid response is received,
188082bfe67SJohn Polstra.Fn rad_send_request
189082bfe67SJohn Polstrareturns the RADIUS code which specifies the type of the response.
190082bfe67SJohn PolstraThis will typically be
191082bfe67SJohn Polstra.Dv RAD_ACCESS_ACCEPT ,
192082bfe67SJohn Polstra.Dv RAD_ACCESS_REJECT ,
193082bfe67SJohn Polstraor
194082bfe67SJohn Polstra.Dv RAD_ACCESS_CHALLENGE .
195082bfe67SJohn PolstraIf no valid response is received,
196082bfe67SJohn Polstra.Fn rad_send_request
197082bfe67SJohn Polstrareturns -1.
198082bfe67SJohn Polstra.Pp
199082bfe67SJohn PolstraLike RADIUS requests, each response may contain zero or more
200082bfe67SJohn Polstraattributes.  After a response has been received successfully by
201082bfe67SJohn Polstra.Fn rad_send_request ,
202082bfe67SJohn Polstraits attributes can be extracted one by one using
203082bfe67SJohn Polstra.Fn rad_get_attr .
204082bfe67SJohn PolstraEach time
205082bfe67SJohn Polstra.Fn rad_get_attr
206082bfe67SJohn Polstrais called, it gets the next attribute from the current response, and
207082bfe67SJohn Polstrastores a pointer to the data and the length of the data via the
208082bfe67SJohn Polstrareference parameters
209082bfe67SJohn Polstra.Va data
210082bfe67SJohn Polstraand
211082bfe67SJohn Polstra.Va len ,
212082bfe67SJohn Polstrarespectively.  Note that the data resides in the response itself,
213082bfe67SJohn Polstraand must not be modified.
214082bfe67SJohn PolstraA successful call to
215082bfe67SJohn Polstra.Fn rad_get_attr
216082bfe67SJohn Polstrareturns the RADIUS attribute type.
217082bfe67SJohn PolstraIf no more attributes remain in the current response,
218082bfe67SJohn Polstra.Fn rad_get_attr
219082bfe67SJohn Polstrareturns 0.
220082bfe67SJohn PolstraIf an error such as a malformed attribute is detected, -1 is
221082bfe67SJohn Polstrareturned.
222082bfe67SJohn Polstra.Pp
223082bfe67SJohn PolstraThe common types of attributes can be decoded using
224082bfe67SJohn Polstra.Fn rad_cvt_addr ,
225082bfe67SJohn Polstra.Fn rad_cvt_int ,
226082bfe67SJohn Polstraand
227082bfe67SJohn Polstra.Fn rad_cvt_string .
228082bfe67SJohn PolstraThese functions accept a pointer to the attribute data, which should
229082bfe67SJohn Polstrahave been obtained using
230082bfe67SJohn Polstra.Fn rad_get_attr .
231082bfe67SJohn PolstraIn the case of
232082bfe67SJohn Polstra.Fn rad_cvt_string ,
233082bfe67SJohn Polstrathe length
234082bfe67SJohn Polstra.Va len
235082bfe67SJohn Polstramust also be given.  These functions interpret the attribute as an
236082bfe67SJohn PolstraInternet address, an integer, or a string, respectively, and return
237082bfe67SJohn Polstraits value.
238082bfe67SJohn Polstra.Fn rad_cvt_string
239082bfe67SJohn Polstrareturns its value as a NUL-terminated string in dynamically
240082bfe67SJohn Polstraallocated memory.  The application should free the string using
241082bfe67SJohn Polstra.Xr free 3
242082bfe67SJohn Polstrawhen it is no longer needed.
243082bfe67SJohn Polstra.Pp
244082bfe67SJohn PolstraIf insufficient virtual memory is available,
245082bfe67SJohn Polstra.Fn rad_cvt_string
246082bfe67SJohn Polstrareturns
247082bfe67SJohn Polstra.Dv NULL .
248082bfe67SJohn Polstra.Fn rad_cvt_addr
249082bfe67SJohn Polstraand
250082bfe67SJohn Polstra.Fn rad_cvt_int
251082bfe67SJohn Polstracannot fail.
252082bfe67SJohn Polstra.Sh OBTAINING ERROR MESSAGES
253082bfe67SJohn PolstraThose functions which accept a
254082bfe67SJohn Polstra.Va struct rad_handle *
255082bfe67SJohn Polstraargument record an error message if they fail.  The error message
256082bfe67SJohn Polstracan be retrieved by calling
257082bfe67SJohn Polstra.Fn rad_strerror .
258082bfe67SJohn PolstraThe message text is overwritten on each new error for the given
259082bfe67SJohn Polstra.Va struct rad_handle * .
260082bfe67SJohn PolstraThus the message must be copied if it is to be preserved through
261082bfe67SJohn Polstrasubsequent library calls using the same handle.
262082bfe67SJohn Polstra.Sh CLEANUP
263082bfe67SJohn PolstraTo free the resources used by the RADIUS library, call
264082bfe67SJohn Polstra.Fn rad_close .
265082bfe67SJohn Polstra.Sh RETURN VALUES
266082bfe67SJohn PolstraThe following functions return a non-negative value on success.  If
267082bfe67SJohn Polstrathey detect an error, they return -1 and record an error message
268082bfe67SJohn Polstrawhich can be retrieved using
269082bfe67SJohn Polstra.Fn rad_strerror .
270082bfe67SJohn Polstra.Pp
271082bfe67SJohn Polstra.Bl -item -offset indent -compact
272082bfe67SJohn Polstra.It
273082bfe67SJohn Polstra.Fn rad_add_server
274082bfe67SJohn Polstra.It
275082bfe67SJohn Polstra.Fn rad_config
276082bfe67SJohn Polstra.It
277082bfe67SJohn Polstra.Fn rad_create_request
278082bfe67SJohn Polstra.It
279082bfe67SJohn Polstra.Fn rad_get_attr
280082bfe67SJohn Polstra.It
281082bfe67SJohn Polstra.Fn rad_put_addr
282082bfe67SJohn Polstra.It
283082bfe67SJohn Polstra.Fn rad_put_attr
284082bfe67SJohn Polstra.It
285082bfe67SJohn Polstra.Fn rad_put_int
286082bfe67SJohn Polstra.It
287082bfe67SJohn Polstra.Fn rad_put_string
288082bfe67SJohn Polstra.It
289082bfe67SJohn Polstra.Fn rad_send_request
290082bfe67SJohn Polstra.El
291082bfe67SJohn Polstra.Pp
292082bfe67SJohn PolstraThe following functions return a
293082bfe67SJohn Polstra.No non- Ns Dv NULL
294082bfe67SJohn Polstrapointer on success.  If they are unable to allocate sufficient
295082bfe67SJohn Polstravirtual memory, they return
296082bfe67SJohn Polstra.Dv NULL ,
297082bfe67SJohn Polstrawithout recording an error message.
298082bfe67SJohn Polstra.Pp
299082bfe67SJohn Polstra.Bl -item -offset indent -compact
300082bfe67SJohn Polstra.It
301082bfe67SJohn Polstra.Fn rad_cvt_string
302082bfe67SJohn Polstra.It
303082bfe67SJohn Polstra.Fn rad_open
304082bfe67SJohn Polstra.El
305082bfe67SJohn Polstra.Sh FILES
306082bfe67SJohn Polstra.Pa /etc/radius.conf
307082bfe67SJohn Polstra.Sh SEE ALSO
308082bfe67SJohn Polstra.Xr radius.conf 5
309082bfe67SJohn Polstra.Rs
310082bfe67SJohn Polstra.%A C. Rigney, et al
311082bfe67SJohn Polstra.%T Remote Authentication Dial In User Service (RADIUS)
312082bfe67SJohn Polstra.%O RFC 2138
313082bfe67SJohn Polstra.Re
314082bfe67SJohn Polstra.Sh AUTHORS
315082bfe67SJohn PolstraThis software was written by
316082bfe67SJohn Polstra.An John Polstra ,
317082bfe67SJohn Polstraand donated to the FreeBSD project by Juniper Networks, Inc.
318