]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - lib/libradius/libradius.3
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / lib / libradius / libradius.3
1 .\" Copyright 1998 Juniper Networks, Inc.
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .\" $FreeBSD$
26 .\"
27 .Dd April 27, 2004
28 .Dt LIBRADIUS 3
29 .Os
30 .Sh NAME
31 .Nm libradius
32 .Nd RADIUS client library
33 .Sh SYNOPSIS
34 .In radlib.h
35 .Ft "struct rad_handle *"
36 .Fn rad_acct_open "void"
37 .Ft int
38 .Fn rad_add_server "struct rad_handle *h" "const char *host" "int port" "const char *secret" "int timeout" "int max_tries"
39 .Ft "struct rad_handle *"
40 .Fn rad_auth_open "void"
41 .Ft void
42 .Fn rad_close "struct rad_handle *h"
43 .Ft int
44 .Fn rad_config "struct rad_handle *h" "const char *file"
45 .Ft int
46 .Fn rad_continue_send_request "struct rad_handle *h" "int selected" "int *fd" "struct timeval *tv"
47 .Ft int
48 .Fn rad_create_request "struct rad_handle *h" "int code"
49 .Ft "struct in_addr"
50 .Fn rad_cvt_addr "const void *data"
51 .Ft u_int32_t
52 .Fn rad_cvt_int "const void *data"
53 .Ft char *
54 .Fn rad_cvt_string "const void *data" "size_t len"
55 .Ft int
56 .Fn rad_get_attr "struct rad_handle *h" "const void **data" "size_t *len"
57 .Ft int
58 .Fn rad_get_vendor_attr "u_int32_t *vendor" "const void **data" "size_t *len"
59 .Ft int
60 .Fn rad_init_send_request "struct rad_handle *h" "int *fd" "struct timeval *tv"
61 .Ft int
62 .Fn rad_put_addr "struct rad_handle *h" "int type" "struct in_addr addr"
63 .Ft int
64 .Fn rad_put_attr "struct rad_handle *h" "int type" "const void *data" "size_t len"
65 .Ft int
66 .Fn rad_put_int "struct rad_handle *h" "int type" "u_int32_t value"
67 .Ft int
68 .Fn rad_put_string "struct rad_handle *h" "int type" "const char *str"
69 .Ft int
70 .Fn rad_put_message_authentic "struct rad_handle *h"
71 .Ft int
72 .Fn rad_put_vendor_addr "struct rad_handle *h" "int vendor" "int type" "struct in_addr addr"
73 .Ft int
74 .Fn rad_put_vendor_attr "struct rad_handle *h" "int vendor" "int type" "const void *data" "size_t len"
75 .Ft int
76 .Fn rad_put_vendor_int "struct rad_handle *h" "int vendor" "int type" "u_int32_t value"
77 .Ft int
78 .Fn rad_put_vendor_string "struct rad_handle *h" "int vendor" "int type" "const char *str"
79 .Ft ssize_t
80 .Fn rad_request_authenticator "struct rad_handle *h" "char *buf" "size_t len"
81 .Ft int
82 .Fn rad_send_request "struct rad_handle *h"
83 .Ft "const char *"
84 .Fn rad_server_secret "struct rad_handle *h"
85 .Ft u_char *
86 .Fn rad_demangle "struct rad_handle *h" "const void *mangled" "size_t mlen"
87 .Ft u_char *
88 .Fn rad_demangle_mppe_key "struct rad_handle *h" "const void *mangled" "size_t mlen" "size_t *len"
89 .Ft "const char *"
90 .Fn rad_strerror "struct rad_handle *h"
91 .Sh DESCRIPTION
92 The
93 .Nm
94 library implements the client side of the Remote Authentication Dial
95 In User Service (RADIUS).
96 RADIUS, defined in RFCs 2865 and 2866,
97 allows clients to perform authentication and accounting by means of
98 network requests to remote servers.
99 .Ss Initialization
100 To use the library, an application must first call
101 .Fn rad_auth_open
102 or
103 .Fn rad_acct_open
104 to obtain a
105 .Vt "struct rad_handle *" ,
106 which provides the context for subsequent operations.
107 The former function is used for RADIUS authentication and the
108 latter is used for RADIUS accounting.
109 Calls to
110 .Fn rad_auth_open
111 and
112 .Fn rad_acct_open
113 always succeed unless insufficient virtual memory is available.
114 If
115 the necessary memory cannot be allocated, the functions return
116 .Dv NULL .
117 For compatibility with earlier versions of this library,
118 .Fn rad_open
119 is provided as a synonym for
120 .Fn rad_auth_open .
121 .Pp
122 Before issuing any RADIUS requests, the library must be made aware
123 of the servers it can contact.
124 The easiest way to configure the
125 library is to call
126 .Fn rad_config .
127 .Fn rad_config
128 causes the library to read a configuration file whose format is
129 described in
130 .Xr radius.conf 5 .
131 The pathname of the configuration file is passed as the
132 .Fa file
133 argument to
134 .Fn rad_config .
135 This argument may also be given as
136 .Dv NULL ,
137 in which case the standard configuration file
138 .Pa /etc/radius.conf
139 is used.
140 .Fn rad_config
141 returns 0 on success, or \-1 if an error occurs.
142 .Pp
143 The library can also be configured programmatically by calls to
144 .Fn rad_add_server .
145 The
146 .Fa host
147 parameter specifies the server host, either as a fully qualified
148 domain name or as a dotted-quad IP address in text form.
149 The
150 .Fa port
151 parameter specifies the UDP port to contact on the server.
152 If
153 .Fa port
154 is given as 0, the library looks up the
155 .Ql radius/udp
156 or
157 .Ql radacct/udp
158 service in the network
159 .Xr services 5
160 database, and uses the port found
161 there.
162 If no entry is found, the library uses the standard RADIUS
163 ports, 1812 for authentication and 1813 for accounting.
164 The shared secret for the server host is passed to the
165 .Fa secret
166 parameter.
167 It may be any
168 .Dv NUL Ns -terminated
169 string of bytes.
170 The RADIUS protocol
171 ignores all but the leading 128 bytes of the shared secret.
172 The timeout for receiving replies from the server is passed to the
173 .Fa timeout
174 parameter, in units of seconds.
175 The maximum number of repeated
176 requests to make before giving up is passed into the
177 .Fa max_tries
178 parameter.
179 .Fn rad_add_server
180 returns 0 on success, or \-1 if an error occurs.
181 .Pp
182 .Fn rad_add_server
183 may be called multiple times, and it may be used together with
184 .Fn rad_config .
185 At most 10 servers may be specified.
186 When multiple servers are given, they are tried in round-robin
187 fashion until a valid response is received, or until each server's
188 .Fa max_tries
189 limit has been reached.
190 .Ss Creating a RADIUS Request
191 A RADIUS request consists of a code specifying the kind of request,
192 and zero or more attributes which provide additional information.
193 To
194 begin constructing a new request, call
195 .Fn rad_create_request .
196 In addition to the usual
197 .Vt "struct rad_handle *" ,
198 this function takes a
199 .Fa code
200 parameter which specifies the type of the request.
201 Most often this
202 will be
203 .Dv RAD_ACCESS_REQUEST .
204 .Fn rad_create_request
205 returns 0 on success, or \-1 on if an error occurs.
206 .Pp
207 After the request has been created with
208 .Fn rad_create_request ,
209 attributes can be attached to it.
210 This is done through calls to
211 .Fn rad_put_addr ,
212 .Fn rad_put_int ,
213 and
214 .Fn rad_put_string .
215 Each accepts a
216 .Fa type
217 parameter identifying the attribute, and a value which may be
218 an Internet address, an integer, or a
219 .Dv NUL Ns -terminated
220 string,
221 respectively.
222 Alternatively,
223 .Fn rad_put_vendor_addr ,
224 .Fn rad_put_vendor_int
225 or
226 .Fn rad_put_vendor_string
227 may be used to specify vendor specific attributes.
228 Vendor specific
229 definitions may be found in
230 .In radlib_vs.h
231 .Pp
232 The library also provides a function
233 .Fn rad_put_attr
234 which can be used to supply a raw, uninterpreted attribute.
235 The
236 .Fa data
237 argument points to an array of bytes, and the
238 .Fa len
239 argument specifies its length.
240 .Pp
241 It is possible adding the Message-Authenticator to the request.
242 This is an HMAC-MD5 hash of the entire Access-Request packet (see RFC 3579).
243 This attribute must be present in any packet that includes an EAP-Message
244 attribute.
245 It can be added by using the
246 .Fn rad_put_message_authentic
247 function.
248 The
249 .Nm
250 library
251 calculates the HMAC-MD5 hash implicitly before sending the request.
252 If the Message-Authenticator was found inside the response packet,
253 then the packet is silently dropped, if the validation failed.
254 In order to get this feature, the library should be compiled with
255 OpenSSL support.
256 .Pp
257 The
258 .Fn rad_put_X
259 functions return 0 on success, or \-1 if an error occurs.
260 .Ss Sending the Request and Receiving the Response
261 After the RADIUS request has been constructed, it is sent either by means of
262 .Fn rad_send_request
263 or by a combination of calls to
264 .Fn rad_init_send_request
265 and
266 .Fn rad_continue_send_request .
267 .Pp
268 The
269 .Fn rad_send_request
270 function sends the request and waits for a valid reply,
271 retrying the defined servers in round-robin fashion as necessary.
272 If a valid response is received,
273 .Fn rad_send_request
274 returns the RADIUS code which specifies the type of the response.
275 This will typically be
276 .Dv RAD_ACCESS_ACCEPT ,
277 .Dv RAD_ACCESS_REJECT ,
278 or
279 .Dv RAD_ACCESS_CHALLENGE .
280 If no valid response is received,
281 .Fn rad_send_request
282 returns \-1.
283 .Pp
284 As an alternative, if you do not wish to block waiting for a response,
285 .Fn rad_init_send_request
286 and
287 .Fn rad_continue_send_request
288 may be used instead.
289 If a reply is received from the RADIUS server or a
290 timeout occurs, these functions return a value as described for
291 .Fn rad_send_request .
292 Otherwise, a value of zero is returned and the values pointed to by
293 .Fa fd
294 and
295 .Fa tv
296 are set to the descriptor and timeout that should be passed to
297 .Xr select 2 .
298 .Pp
299 .Fn rad_init_send_request
300 must be called first, followed by repeated calls to
301 .Fn rad_continue_send_request
302 as long as a return value of zero is given.
303 Between each call, the application should call
304 .Xr select 2 ,
305 passing
306 .Fa *fd
307 as a read descriptor and timing out after the interval specified by
308 .Fa tv .
309 When
310 .Xr select 2
311 returns,
312 .Fn rad_continue_send_request
313 should be called with
314 .Fa selected
315 set to a non-zero value if
316 .Xr select 2
317 indicated that the descriptor is readable.
318 .Pp
319 Like RADIUS requests, each response may contain zero or more
320 attributes.
321 After a response has been received successfully by
322 .Fn rad_send_request
323 or
324 .Fn rad_continue_send_request ,
325 its attributes can be extracted one by one using
326 .Fn rad_get_attr .
327 Each time
328 .Fn rad_get_attr
329 is called, it gets the next attribute from the current response, and
330 stores a pointer to the data and the length of the data via the
331 reference parameters
332 .Fa data
333 and
334 .Fa len ,
335 respectively.
336 Note that the data resides in the response itself,
337 and must not be modified.
338 A successful call to
339 .Fn rad_get_attr
340 returns the RADIUS attribute type.
341 If no more attributes remain in the current response,
342 .Fn rad_get_attr
343 returns 0.
344 If an error such as a malformed attribute is detected, \-1 is
345 returned.
346 .Pp
347 If
348 .Fn rad_get_attr
349 returns
350 .Dv RAD_VENDOR_SPECIFIC ,
351 .Fn rad_get_vendor_attr
352 may be called to determine the vendor.
353 The vendor specific RADIUS attribute type is returned.
354 The reference parameters
355 .Fa data
356 and
357 .Fa len
358 (as returned from
359 .Fn rad_get_attr )
360 are passed to
361 .Fn rad_get_vendor_attr ,
362 and are adjusted to point to the vendor specific attribute data.
363 .Pp
364 The common types of attributes can be decoded using
365 .Fn rad_cvt_addr ,
366 .Fn rad_cvt_int ,
367 and
368 .Fn rad_cvt_string .
369 These functions accept a pointer to the attribute data, which should
370 have been obtained using
371 .Fn rad_get_attr
372 and optionally
373 .Fn rad_get_vendor_attr .
374 In the case of
375 .Fn rad_cvt_string ,
376 the length
377 .Fa len
378 must also be given.
379 These functions interpret the attribute as an
380 Internet address, an integer, or a string, respectively, and return
381 its value.
382 .Fn rad_cvt_string
383 returns its value as a
384 .Dv NUL Ns -terminated
385 string in dynamically
386 allocated memory.
387 The application should free the string using
388 .Xr free 3
389 when it is no longer needed.
390 .Pp
391 If insufficient virtual memory is available,
392 .Fn rad_cvt_string
393 returns
394 .Dv NULL .
395 .Fn rad_cvt_addr
396 and
397 .Fn rad_cvt_int
398 cannot fail.
399 .Pp
400 The
401 .Fn rad_request_authenticator
402 function may be used to obtain the Request-Authenticator attribute value
403 associated with the current RADIUS server according to the supplied
404 rad_handle.
405 The target buffer
406 .Fa buf
407 of length
408 .Fa len
409 must be supplied and should be at least 16 bytes.
410 The return value is the number of bytes written to
411 .Fa buf
412 or \-1 to indicate that
413 .Fa len
414 was not large enough.
415 .Pp
416 The
417 .Fn rad_server_secret
418 returns the secret shared with the current RADIUS server according to the
419 supplied rad_handle.
420 .Pp
421 The
422 .Fn rad_demangle
423 function demangles attributes containing passwords and MS-CHAPv1 MPPE-Keys.
424 The return value is
425 .Dv NULL
426 on failure, or the plaintext attribute.
427 This value should be freed using
428 .Xr free 3
429 when it is no longer needed.
430 .Pp
431 The
432 .Fn rad_demangle_mppe_key
433 function demangles the send- and recv-keys when using MPPE (see RFC 2548).
434 The return value is
435 .Dv NULL
436 on failure, or the plaintext attribute.
437 This value should be freed using
438 .Xr free 3
439 when it is no longer needed.
440 .Ss Obtaining Error Messages
441 Those functions which accept a
442 .Vt "struct rad_handle *"
443 argument record an error message if they fail.
444 The error message
445 can be retrieved by calling
446 .Fn rad_strerror .
447 The message text is overwritten on each new error for the given
448 .Vt "struct rad_handle *" .
449 Thus the message must be copied if it is to be preserved through
450 subsequent library calls using the same handle.
451 .Ss Cleanup
452 To free the resources used by the RADIUS library, call
453 .Fn rad_close .
454 .Sh RETURN VALUES
455 The following functions return a non-negative value on success.
456 If
457 they detect an error, they return \-1 and record an error message
458 which can be retrieved using
459 .Fn rad_strerror .
460 .Pp
461 .Bl -item -offset indent -compact
462 .It
463 .Fn rad_add_server
464 .It
465 .Fn rad_config
466 .It
467 .Fn rad_create_request
468 .It
469 .Fn rad_get_attr
470 .It
471 .Fn rad_put_addr
472 .It
473 .Fn rad_put_attr
474 .It
475 .Fn rad_put_int
476 .It
477 .Fn rad_put_string
478 .It
479 .Fn rad_put_message_authentic
480 .It
481 .Fn rad_init_send_request
482 .It
483 .Fn rad_continue_send_request
484 .It
485 .Fn rad_send_request
486 .El
487 .Pp
488 The following functions return a
489 .No non- Ns Dv NULL
490 pointer on success.
491 If they are unable to allocate sufficient
492 virtual memory, they return
493 .Dv NULL ,
494 without recording an error message.
495 .Pp
496 .Bl -item -offset indent -compact
497 .It
498 .Fn rad_acct_open
499 .It
500 .Fn rad_auth_open
501 .It
502 .Fn rad_cvt_string
503 .El
504 .Pp
505 The following functions return a
506 .No non- Ns Dv NULL
507 pointer on success.
508 If they fail, they return
509 .Dv NULL ,
510 with recording an error message.
511 .Pp
512 .Bl -item -offset indent -compact
513 .It
514 .Fn rad_demangle
515 .It
516 .Fn rad_demangle_mppe_key
517 .El
518 .Sh FILES
519 .Bl -tag -width indent
520 .It Pa /etc/radius.conf
521 .El
522 .Sh SEE ALSO
523 .Xr radius.conf 5
524 .Rs
525 .%A "C. Rigney, et al"
526 .%T "Remote Authentication Dial In User Service (RADIUS)"
527 .%O "RFC 2865"
528 .Re
529 .Rs
530 .%A "C. Rigney"
531 .%T "RADIUS Accounting"
532 .%O "RFC 2866"
533 .Re
534 .Rs
535 .%A G. Zorn
536 .%T "Microsoft Vendor-specific RADIUS attributes"
537 .%O RFC 2548
538 .Re
539 .Rs
540 .%A C. Rigney, et al
541 .%T "RADIUS extensions"
542 .%O RFC 2869
543 .Re
544 .Sh AUTHORS
545 .An -nosplit
546 This software was originally written by
547 .An John Polstra ,
548 and donated to the
549 .Fx
550 project by Juniper Networks, Inc.
551 .An Oleg Semyonov
552 subsequently added the ability to perform RADIUS
553 accounting.
554 Later additions and changes by
555 .An Michael Bretterklieber .