xref: /freebsd/lib/libtacplus/taclib_private.h (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 1998, 2001, Juniper Networks, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  *	$FreeBSD$
29  */
30 
31 #ifndef TACLIB_PRIVATE_H
32 #define TACLIB_PRIVATE_H
33 
34 #include "taclib.h"
35 
36 /* Defaults */
37 #define PATH_TACPLUS_CONF	"/etc/tacplus.conf"
38 #define TACPLUS_PORT		49
39 #define TIMEOUT			3	/* In seconds */
40 
41 /* Limits */
42 #define BODYSIZE	8150		/* Maximum message body size */
43 #define ERRSIZE		128		/* Maximum error message length */
44 #define MAXCONFLINE	1024		/* Maximum config file line length */
45 #define MAXSERVERS	10		/* Maximum number of servers to try */
46 #define MAXAVPAIRS      255             /* Maximum number of AV pairs */
47 
48 /* Protocol constants. */
49 #define HDRSIZE		12		/* Size of message header */
50 
51 /* Protocol version number */
52 #define TAC_VER_MAJOR		0xc		/* Major version number */
53 
54 /* Protocol packet types */
55 #define TAC_AUTHEN		0x01		/* Authentication */
56 #define TAC_AUTHOR		0x02		/* Authorization */
57 #define TAC_ACCT		0x03		/* Accouting */
58 
59 /* Protocol header flags */
60 #define TAC_UNENCRYPTED		0x01
61 #define TAC_SINGLE_CONNECT	0x04
62 
63 struct tac_str {
64 	char		*data;
65 	size_t		 len;
66 };
67 
68 struct tac_authen_start {
69 	u_int8_t	action;
70 	u_int8_t	priv_lvl;
71 	u_int8_t	authen_type;
72 	u_int8_t	service;
73 	u_int8_t	user_len;
74 	u_int8_t	port_len;
75 	u_int8_t	rem_addr_len;
76 	u_int8_t	data_len;
77 	unsigned char	rest[1];
78 };
79 
80 struct tac_authen_reply {
81 	u_int8_t	status;
82 	u_int8_t	flags;
83 	u_int16_t	msg_len;
84 	u_int16_t	data_len;
85 	unsigned char	rest[1];
86 };
87 
88 struct tac_authen_cont {
89 	u_int16_t	user_msg_len;
90 	u_int16_t	data_len;
91 	u_int8_t	flags;
92 	unsigned char	rest[1];
93 };
94 
95 struct tac_author_request {
96 	u_int8_t	authen_meth;
97 	u_int8_t	priv_lvl;
98 	u_int8_t	authen_type;
99 	u_int8_t	service;
100 	u_int8_t	user_len;
101 	u_int8_t	port_len;
102 	u_int8_t	rem_addr_len;
103 	u_int8_t	av_cnt;
104 	unsigned char	rest[1];
105 };
106 
107 struct tac_author_response {
108 	u_int8_t	status;
109 	u_int8_t	av_cnt;
110 	u_int16_t	msg_len;
111 	u_int16_t	data_len;
112 	unsigned char	rest[1];
113 };
114 
115 struct tac_acct_start {
116 	u_int8_t	action;
117 	u_int8_t	authen_action;
118 	u_int8_t	priv_lvl;
119 	u_int8_t	authen_type;
120 	u_int8_t	authen_service;
121 	u_int8_t	user_len;
122 	u_int8_t	port_len;
123 	u_int8_t	rem_addr_len;
124 	u_int8_t	av_cnt;
125 	unsigned char	rest[1];
126 };
127 
128 struct tac_acct_reply {
129 	u_int16_t	msg_len;
130 	u_int16_t	data_len;
131 	u_int8_t	status;
132 	unsigned char	rest[1];
133 };
134 
135 struct tac_msg {
136 	u_int8_t	version;
137 	u_int8_t	type;
138 	u_int8_t	seq_no;
139 	u_int8_t	flags;
140 	u_int8_t	session_id[4];
141 	u_int32_t	length;
142 	union {
143 		struct tac_authen_start authen_start;
144 		struct tac_authen_reply authen_reply;
145 		struct tac_authen_cont authen_cont;
146 		struct tac_author_request author_request;
147 		struct tac_author_response author_response;
148 		struct tac_acct_start acct_start;
149 		struct tac_acct_reply acct_reply;
150 		unsigned char body[BODYSIZE];
151 	} u;
152 };
153 
154 struct tac_server {
155 	struct sockaddr_in addr;	/* Address of server */
156 	char		*secret;	/* Shared secret */
157 	int		 timeout;	/* Timeout in seconds */
158 	int		 flags;
159 	unsigned int	 navs;
160 	struct tac_str	 avs[MAXAVPAIRS];
161 };
162 
163 struct tac_handle {
164 	int		 fd;		/* Socket file descriptor */
165 	struct tac_server servers[MAXSERVERS];	/* Servers to contact */
166 	int		 num_servers;	/* Number of valid server entries */
167 	int		 cur_server;	/* Server we are currently using */
168 	int		 single_connect;	/* Use a single connection */
169 	int		 last_seq_no;
170 	char		 errmsg[ERRSIZE];	/* Most recent error message */
171 
172 	struct tac_str	 user;
173 	struct tac_str	 port;
174 	struct tac_str	 rem_addr;
175 	struct tac_str	 data;
176 	struct tac_str	 user_msg;
177 	struct tac_str	 avs[MAXAVPAIRS];
178 
179 	struct tac_msg	 request;
180 	struct tac_msg	 response;
181 
182 	int		 srvr_pos;	/* Scan position in response body */
183 	unsigned int	 srvr_navs;
184 	struct tac_str	 srvr_msg;
185 	struct tac_str	 srvr_data;
186 	struct tac_str	 srvr_avs[MAXAVPAIRS];
187 };
188 
189 #define is_alpha(ch) /* alphabetical */					\
190 	(((ch) >= 'A' && (ch) <= 'Z') || ((ch) >= 'a' && (ch) <= 'z'))
191 #define is_num(ch) /* numerical */					\
192 	((ch) >= '0' && (ch) <= '9')
193 #define is_alnum(ch) /* alphanumerical */				\
194 	(is_alpha(ch) || is_num(ch))
195 #define is_arg(ch) /* valid in an argument name */			\
196 	(is_alnum(ch) || (ch) == '_' || (ch) == '-')
197 
198 #endif
199