]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - lib/libtacplus/libtacplus.3
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / lib / libtacplus / libtacplus.3
1 .\" Copyright (c) 1998, 2001, 2002, 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 December 11, 2009
28 .Dt LIBTACPLUS 3
29 .Os
30 .Sh NAME
31 .Nm libtacplus
32 .Nd TACACS+ client library
33 .Sh SYNOPSIS
34 .In taclib.h
35 .Ft int
36 .Fn tac_add_server "struct tac_handle *h" "const char *host" "int port" "const char *secret" "int timeout" "int flags"
37 .Ft void
38 .Fn tac_clear_avs "struct tac_handle *h"
39 .Ft void
40 .Fn tac_close "struct tac_handle *h"
41 .Ft int
42 .Fn tac_config "struct tac_handle *h" "const char *path"
43 .Ft int
44 .Fn tac_create_authen "struct tac_handle *h" "int action" "int type" "int service"
45 .Ft int
46 .Fn tac_create_author "struct tac_handle *h" "int method" "int type" "int service"
47 .Ft int
48 .Fn tac_create_acct "struct tac_handle *h" "int acct" "int action" "int type" "int service"
49 .Ft char *
50 .Fn tac_get_av "struct tac_handle *h" "u_int index"
51 .Ft char *
52 .Fn tac_get_av_value "struct tac_handle *h" "const char *attribute"
53 .Ft void *
54 .Fn tac_get_data "struct tac_handle *h" "size_t *len"
55 .Ft char *
56 .Fn tac_get_msg "struct tac_handle *h"
57 .Ft struct tac_handle *
58 .Fn tac_open "void"
59 .Ft int
60 .Fn tac_send_authen "struct tac_handle *h"
61 .Ft int
62 .Fn tac_send_author "struct tac_handle *h"
63 .Ft int
64 .Fn tac_send_acct "struct tac_handle *h"
65 .Ft int
66 .Fn tac_set_av "struct tac_handle *h" "u_int index" "const char *av_pair"
67 .Ft int
68 .Fn tac_set_data "struct tac_handle *h" "const void *data" "size_t data_len"
69 .Ft int
70 .Fn tac_set_msg "struct tac_handle *h" "const char *msg"
71 .Ft int
72 .Fn tac_set_port "struct tac_handle *h" "const char *port"
73 .Ft int
74 .Fn tac_set_priv "struct tac_handle *h" "int priv"
75 .Ft int
76 .Fn tac_set_rem_addr "struct tac_handle *h" "const char *addr"
77 .Ft int
78 .Fn tac_set_user "struct tac_handle *h" "const char *user"
79 .Ft const char *
80 .Fn tac_strerror "struct tac_handle *h"
81 .Sh DESCRIPTION
82 The
83 .Nm
84 library implements the client side of the TACACS+ network access
85 control protocol.
86 TACACS+ allows clients to perform authentication,
87 authorization, and accounting by means of network requests to remote
88 servers.
89 This library currently supports only the authentication
90 and authorization portion of the protocol.
91 .Sh INITIALIZATION
92 To use the library, an application must first call
93 .Fn tac_open
94 to obtain a
95 .Va struct tac_handle * ,
96 which provides context for subsequent operations.
97 Calls to
98 .Fn tac_open
99 always succeed unless insufficient virtual memory is available.
100 If
101 the necessary memory cannot be allocated,
102 .Fn tac_open
103 returns
104 .Dv NULL .
105 .Pp
106 Before issuing any TACACS+ requests, the library must be made aware
107 of the servers it can contact.
108 The easiest way to configure the
109 library is to call
110 .Fn tac_config .
111 .Fn tac_config
112 causes the library to read a configuration file whose format is
113 described in
114 .Xr tacplus.conf 5 .
115 The pathname of the configuration file is passed as the
116 .Va file
117 argument to
118 .Fn tac_config .
119 This argument may also be given as
120 .Dv NULL ,
121 in which case the standard configuration file
122 .Pa /etc/tacplus.conf
123 is used.
124 .Fn tac_config
125 returns 0 on success, or \-1 if an error occurs.
126 .Pp
127 The library can also be configured programmatically by calls to
128 .Fn tac_add_server .
129 The
130 .Va host
131 parameter specifies the server host, either as a fully qualified
132 domain name or as a dotted-quad IP address in text form.
133 The
134 .Va port
135 parameter specifies the TCP port to contact on the server.
136 If
137 .Va port
138 is given as 0, the library uses port 49, the standard TACACS+ port.
139 The shared secret for the server host is passed to the
140 .Va secret
141 parameter.
142 It may be any null-terminated string of bytes.
143 The timeout for receiving replies from the server is passed to the
144 .Va timeout
145 parameter, in units of seconds.
146 The
147 .Va flags
148 parameter is a bit mask of flags to specify various characteristics of
149 the server.
150 It may contain:
151 .Bl -tag -width Fl
152 .It Dv TAC_SRVR_SINGLE_CONNECT
153 Causes the library to attempt to negotiate single connection mode
154 when communicating with the server.
155 In single connection mode, the
156 original TCP connection is held open for multiple TACACS+ sessions.
157 Older servers do not support this mode, and some of them become
158 confused if the client attempts to negotiate it.
159 .El
160 .Pp
161 .Fn tac_add_server
162 returns 0 on success, or \-1 if an error occurs.
163 .Pp
164 .Fn tac_add_server
165 may be called multiple times, and it may be used together with
166 .Fn tac_config .
167 At most 10 servers may be specified.
168 When multiple servers are given, they are tried in round-robin
169 fashion until a working, accessible server is found.
170 Once the
171 library finds such a server, it continues to use it as long as it
172 works.
173 .Sh CREATING A TACACS+ AUTHENTICATION REQUEST
174 To begin constructing a new authentication request, call
175 .Fn tac_create_authen .
176 The
177 .Va action ,
178 .Va type ,
179 and
180 .Va service
181 arguments must be set to appropriate values as defined in the
182 TACACS+ protocol specification.
183 The
184 .In taclib.h
185 header file contains symbolic constants for these values.
186 .Sh CREATING A TACACS+ AUTHORIZATION REQUEST
187 To begin constructing a new authorization request, call
188 .Fn tac_create_author .
189 The
190 .Va method ,
191 .Va type ,
192 and
193 .Va service
194 arguments must be set to appropriate values as defined in the
195 TACACS+ protocol specification.
196 The
197 .In taclib.h
198 header file contains symbolic constants for these values.
199 .Sh CREATING A TACACS+ ACCOUNTING REQUEST
200 To begin constructing a new accounting request, call
201 .Fn tac_create_acct .
202 The
203 .Va acct ,
204 .Va action ,
205 .Va type ,
206 and
207 .Va service
208 arguments must be set to appropriate values as defined in the
209 TACACS+ protocol specification.
210 The
211 .In taclib.h
212 header file contains symbolic constants for these values.
213 .Sh SETTING OPTIONAL PARAMETERS ON A REQUEST
214 After creating a request,
215 various optional parameters may be attached to it through calls to
216 .Fn tac_set_av ,
217 .Fn tac_set_data ,
218 .Fn tac_set_port ,
219 .Fn tac_set_priv ,
220 .Fn tac_set_rem_addr ,
221 and
222 .Fn tac_set_user .
223 The library creates its own copies of any strings provided to these
224 functions, so that it is not necessary for the caller to preserve
225 them.
226 By default, each of these parameters is empty except for the
227 privilege level, which defaults to
228 .Ql USER
229 privilege.
230 .Pp
231 .Fn tac_set_av
232 only applies to the context of an authorization request.
233 The format
234 for an attribute value pair is defined in the TACACS+ protocol
235 specification.
236 The index specified can be any value between 0 and
237 255 inclusive and indicates the position in the list to place the
238 attribute value pair.
239 Calling
240 .Fn tac_set_av
241 with same index twice effectively replaces the value at that position.
242 Use
243 .Fn tac_clear_avs
244 to clear all attribute value pairs that may have been set.
245 .Sh SENDING THE AUTHENTICATION REQUEST AND RECEIVING THE RESPONSE
246 After the TACACS+ authentication request has been constructed, it is
247 sent by means of
248 .Fn tac_send_authen .
249 This function connects to a server if not already connected, sends
250 the request, and waits for a reply.
251 On failure,
252 .Fn tac_send_authen
253 returns \-1.
254 Otherwise, it returns the TACACS+ status code and flags,
255 packed into an integer value.
256 The status can be extracted using the
257 macro
258 .Fn TAC_AUTHEN_STATUS .
259 Possible status codes, defined in
260 .In taclib.h ,
261 include:
262 .Pp
263 .Bl -item -compact -offset indent
264 .It
265 .Dv TAC_AUTHEN_STATUS_PASS
266 .It
267 .Dv TAC_AUTHEN_STATUS_FAIL
268 .It
269 .Dv TAC_AUTHEN_STATUS_GETDATA
270 .It
271 .Dv TAC_AUTHEN_STATUS_GETUSER
272 .It
273 .Dv TAC_AUTHEN_STATUS_GETPASS
274 .It
275 .Dv TAC_AUTHEN_STATUS_RESTART
276 .It
277 .Dv TAC_AUTHEN_STATUS_ERROR
278 .It
279 .Dv TAC_AUTHEN_STATUS_FOLLOW
280 .El
281 .Pp
282 The only flag is the no-echo flag, which can be tested using the
283 macro
284 .Fn TAC_AUTHEN_NOECHO .
285 .Sh EXTRACTING INFORMATION FROM THE SERVER'S AUTHENTICATION RESPONSE
286 An authentication response packet from the server may contain a
287 server message, a data string, or both.
288 After a successful call to
289 .Fn tac_send_authen ,
290 this information may be retrieved from the response by calling
291 .Fn tac_get_msg
292 and
293 .Fn tac_get_data .
294 These functions return dynamically-allocated copies of the
295 information from the packet.
296 The caller is responsible for freeing
297 the copies when it no longer needs them.
298 The data returned from
299 these functions is guaranteed to be terminated by a null byte.
300 .Pp
301 In the case of
302 .Fn tac_get_data ,
303 the
304 .Va len
305 argument points to a location into which the library will store the
306 actual length of the received data, not including the null
307 terminator.
308 This argument may be given as
309 .Dv NULL
310 if the caller is not interested in the length.
311 .Sh SENDING AUTHENTICATION CONTINUE PACKETS
312 If
313 .Fn tac_send_authen
314 returns a value containing one of the status codes
315 .Dv TAC_AUTHEN_STATUS_GETDATA ,
316 .Dv TAC_AUTHEN_STATUS_GETUSER ,
317 or
318 .Dv TAC_AUTHEN_STATUS_GETPASS ,
319 then the client must provide additional information to the server by
320 means of a TACACS+ CONTINUE packet.
321 To do so, the application must
322 first set the packet's user message and/or data fields using
323 .Fn tac_set_msg
324 and
325 .Fn tac_set_data .
326 The client then sends the CONTINUE packet with
327 .Fn tac_send_authen .
328 N.B.,
329 .Fn tac_create_authen
330 should
331 .Em not
332 be called to construct a CONTINUE packet; it is used only for the
333 initial authentication request.
334 .Pp
335 When it receives the CONTINUE packet, the server may again request
336 more information by returning
337 .Dv TAC_AUTHEN_STATUS_GETDATA ,
338 .Dv TAC_AUTHEN_STATUS_GETUSER ,
339 or
340 .Dv TAC_AUTHEN_STATUS_GETPASS .
341 The application should send further CONTINUEs until some other
342 status is received from the server.
343 .Sh SENDING THE AUTHORIZATION REQUEST AND RECEIVING THE RESPONSE
344 After the TACACS+ authorization request has been constructed, it
345 is sent by means of
346 .Fn tac_send_author .
347 This function connects to a server if not already connected, sends
348 the request, and waits for a reply.
349 On failure,
350 .Fn tac_send_author
351 returns \-1.
352 Otherwise, it returns the TACACS+ status code and
353 number of attribute value (AV) pairs received packed into an
354 integer value.
355 The status can be extracted using the macro
356 .Fn TAC_AUTHOR_STATUS .
357 Possible status codes, defined in
358 .In taclib.h ,
359 include:
360 .Pp
361 .Bl -item -compact -offset indent
362 .It
363 .Dv TAC_AUTHOR_STATUS_PASS_ADD
364 .It
365 .Dv TAC_AUTHOR_STATUS_PASS_REPL
366 .It
367 .Dv TAC_AUTHOR_STATUS_FAIL
368 .It
369 .Dv TAC_AUTHOR_STATUS_ERROR
370 .El
371 .Pp
372 The number of AV pairs received is obtained using
373 .Fn TAC_AUTHEN_AV_COUNT .
374 .Sh SENDING THE ACCOUNTING REQUEST AND RECEIVING THE RESPONSE
375 After the TACACS+ authorization request has been constructed, it
376 is sent by means of
377 .Fn tac_send_acct .
378 This function connects to a server if not already connected, sends
379 the request, and waits for a reply.
380 On failure,
381 .Fn tac_send_acct
382 returns \-1.
383 Otherwise, it returns the TACACS+ status code
384 Possible status codes, defined in
385 .In taclib.h ,
386 include:
387 .Pp
388 .Bl -item -compact -offset indent
389 .It
390 .Dv TAC_ACCT_STATUS_SUCCESS
391 .It
392 .Dv TAC_ACCT_STATUS_ERROR
393 .It
394 .Dv TAC_ACCT_STATUS_FOLLOW
395 .El
396 .Sh EXTRACTING INFORMATION FROM THE SERVER'S AUTHORIZATION RESPONSE
397 Like an authentication response packet, an authorization
398 response packet from the
399 server may contain a server message, a data string, or both.
400 Refer
401 to EXTRACTING INFORMATION FROM THE SERVER'S AUTHENTICATION RESPONSE
402 for instruction on extraction of those values.
403 .Pp
404 An authorization response packet from the server may also contain
405 attribute value (AV) pairs.
406 To extract these, use
407 .Fn tac_get_av
408 or
409 .Fn tac_get_av_value .
410 .Fn tac_get_av
411 takes the index of the AV pair as it is positioned in the list.
412 The indexes start at 0 (use
413 .Fn TAC_AUTHEN_AV_COUNT
414 on the return value of
415 .Fn tac_send_author
416 to get the total number of items in this list).
417 Alternatively,
418 .Fn tac_get_av_value
419 can be used.
420 .Fn tac_get_av_value
421 takes the attribute name and returns the
422 corresponding value only, not the AV pair.
423 These functions return
424 dynamically-allocated copies of the information from the packet.
425 The caller is responsible for freeing the copies when it no longer
426 needs them.
427 The data returned from these functions is guaranteed
428 to be terminated by a null byte.
429 .Sh OBTAINING ERROR MESSAGES
430 Those functions which accept a
431 .Va struct tac_handle *
432 argument record an error message if they fail.
433 The error message
434 can be retrieved by calling
435 .Fn tac_strerror .
436 The message text is overwritten on each new error for the given
437 .Va struct tac_handle * .
438 Thus the message must be copied if it is to be preserved through
439 subsequent library calls using the same handle.
440 .Sh CLEANUP
441 To free the resources used by the TACACS+ library, call
442 .Fn tac_close .
443 .Sh RETURN VALUES
444 The following functions return a non-negative value on success.
445 If
446 they detect an error, they return \-1 and record an error message
447 which can be retrieved using
448 .Fn tac_strerror .
449 .Pp
450 .Bl -item -offset indent -compact
451 .It
452 .Fn tac_add_server
453 .It
454 .Fn tac_config
455 .It
456 .Fn tac_create_authen
457 .It
458 .Fn tac_create_author
459 .It
460 .Fn tac_create_acct
461 .It
462 .Fn tac_send_authen
463 .It
464 .Fn tac_send_author
465 .It
466 .Fn tac_send_acct
467 .It
468 .Fn tac_set_av
469 .It
470 .Fn tac_set_data
471 .It
472 .Fn tac_set_msg
473 .It
474 .Fn tac_set_port
475 .It
476 .Fn tac_set_priv
477 .It
478 .Fn tac_set_rem_addr
479 .It
480 .Fn tac_set_user
481 .El
482 .Pp
483 The following functions return a
484 .No non- Ns Dv NULL
485 pointer on success.
486 If they are unable to allocate sufficient
487 virtual memory, they return
488 .Dv NULL
489 and record an error message which can be retrieved using
490 .Fn tac_strerror .
491 .Pp
492 .Bl -item -offset indent -compact
493 .It
494 .Fn tac_get_av
495 .It
496 .Fn tac_get_av_value
497 .It
498 .Fn tac_get_data
499 .It
500 .Fn tac_get_msg
501 .El
502 .Pp
503 The following functions return a
504 .No non- Ns Dv NULL
505 pointer on success.
506 If they are unable to allocate sufficient
507 virtual memory, they return
508 .Dv NULL ,
509 without recording an error message.
510 .Pp
511 .Bl -item -offset indent -compact
512 .It
513 .Fn tac_open
514 .El
515 .Sh FILES
516 .Pa /etc/tacplus.conf
517 .Sh SEE ALSO
518 .Xr tacplus.conf 5
519 .Rs
520 .%A D. Carrel
521 .%A Lol Grant
522 .%T The TACACS+ Protocol, Version 1.78
523 .%O draft-grant-tacacs-02.txt (Internet Draft)
524 .Re
525 .Sh AUTHORS
526 .An -nosplit
527 This software was written by
528 .An John Polstra
529 and
530 .An Paul Fraley ,
531 and donated to the
532 .Fx
533 project by Juniper Networks, Inc.