12c195535SJohn Polstra /*- 21a61aeb8SPaul Traina * Copyright (c) 1998, 2001, Juniper Networks, Inc. 32c195535SJohn Polstra * All rights reserved. 42c195535SJohn Polstra * 52c195535SJohn Polstra * Redistribution and use in source and binary forms, with or without 62c195535SJohn Polstra * modification, are permitted provided that the following conditions 72c195535SJohn Polstra * are met: 82c195535SJohn Polstra * 1. Redistributions of source code must retain the above copyright 92c195535SJohn Polstra * notice, this list of conditions and the following disclaimer. 102c195535SJohn Polstra * 2. Redistributions in binary form must reproduce the above copyright 112c195535SJohn Polstra * notice, this list of conditions and the following disclaimer in the 122c195535SJohn Polstra * documentation and/or other materials provided with the distribution. 132c195535SJohn Polstra * 142c195535SJohn Polstra * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 152c195535SJohn Polstra * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 162c195535SJohn Polstra * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 172c195535SJohn Polstra * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 182c195535SJohn Polstra * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 192c195535SJohn Polstra * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 202c195535SJohn Polstra * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 212c195535SJohn Polstra * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 222c195535SJohn Polstra * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 232c195535SJohn Polstra * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 242c195535SJohn Polstra * SUCH DAMAGE. 252c195535SJohn Polstra * 262c195535SJohn Polstra * $FreeBSD$ 272c195535SJohn Polstra */ 282c195535SJohn Polstra 292c195535SJohn Polstra #ifndef TACLIB_PRIVATE_H 302c195535SJohn Polstra #define TACLIB_PRIVATE_H 312c195535SJohn Polstra 322c195535SJohn Polstra #include "taclib.h" 332c195535SJohn Polstra 342c195535SJohn Polstra /* Defaults */ 352c195535SJohn Polstra #define PATH_TACPLUS_CONF "/etc/tacplus.conf" 362c195535SJohn Polstra #define TACPLUS_PORT 49 372c195535SJohn Polstra #define TIMEOUT 3 /* In seconds */ 382c195535SJohn Polstra 392c195535SJohn Polstra /* Limits */ 402c195535SJohn Polstra #define BODYSIZE 8150 /* Maximum message body size */ 412c195535SJohn Polstra #define ERRSIZE 128 /* Maximum error message length */ 422c195535SJohn Polstra #define MAXCONFLINE 1024 /* Maximum config file line length */ 432c195535SJohn Polstra #define MAXSERVERS 10 /* Maximum number of servers to try */ 441a61aeb8SPaul Traina #define MAXAVPAIRS 255 /* Maximum number of AV pairs */ 452c195535SJohn Polstra 462c195535SJohn Polstra /* Protocol constants. */ 472c195535SJohn Polstra #define HDRSIZE 12 /* Size of message header */ 482c195535SJohn Polstra 492c195535SJohn Polstra /* Protocol version number */ 502c195535SJohn Polstra #define TAC_VER_MAJOR 0xc /* Major version number */ 512c195535SJohn Polstra 522c195535SJohn Polstra /* Protocol packet types */ 532c195535SJohn Polstra #define TAC_AUTHEN 0x01 /* Authentication */ 542c195535SJohn Polstra #define TAC_AUTHOR 0x02 /* Authorization */ 552c195535SJohn Polstra #define TAC_ACCT 0x03 /* Accouting */ 562c195535SJohn Polstra 572c195535SJohn Polstra /* Protocol header flags */ 582c195535SJohn Polstra #define TAC_UNENCRYPTED 0x01 592c195535SJohn Polstra #define TAC_SINGLE_CONNECT 0x04 602c195535SJohn Polstra 612c195535SJohn Polstra struct tac_server { 622c195535SJohn Polstra struct sockaddr_in addr; /* Address of server */ 632c195535SJohn Polstra char *secret; /* Shared secret */ 642c195535SJohn Polstra int timeout; /* Timeout in seconds */ 652c195535SJohn Polstra int flags; 662c195535SJohn Polstra }; 672c195535SJohn Polstra 682c195535SJohn Polstra /* 692c195535SJohn Polstra * An optional string of bytes specified by the client for inclusion in 702c195535SJohn Polstra * a request. The data is always a dynamically allocated copy that 712c195535SJohn Polstra * belongs to the library. It is copied into the request packet just 722c195535SJohn Polstra * before sending the request. 732c195535SJohn Polstra */ 742c195535SJohn Polstra struct clnt_str { 752c195535SJohn Polstra void *data; 762c195535SJohn Polstra size_t len; 772c195535SJohn Polstra }; 782c195535SJohn Polstra 792c195535SJohn Polstra /* 802c195535SJohn Polstra * An optional string of bytes from a server response. The data resides 812c195535SJohn Polstra * in the response packet itself, and must not be freed. 822c195535SJohn Polstra */ 832c195535SJohn Polstra struct srvr_str { 842c195535SJohn Polstra const void *data; 852c195535SJohn Polstra size_t len; 862c195535SJohn Polstra }; 872c195535SJohn Polstra 882c195535SJohn Polstra struct tac_authen_start { 892c195535SJohn Polstra u_int8_t action; 902c195535SJohn Polstra u_int8_t priv_lvl; 912c195535SJohn Polstra u_int8_t authen_type; 922c195535SJohn Polstra u_int8_t service; 932c195535SJohn Polstra u_int8_t user_len; 942c195535SJohn Polstra u_int8_t port_len; 952c195535SJohn Polstra u_int8_t rem_addr_len; 962c195535SJohn Polstra u_int8_t data_len; 972c195535SJohn Polstra unsigned char rest[1]; 982c195535SJohn Polstra }; 992c195535SJohn Polstra 1002c195535SJohn Polstra struct tac_authen_reply { 1012c195535SJohn Polstra u_int8_t status; 1022c195535SJohn Polstra u_int8_t flags; 1032c195535SJohn Polstra u_int16_t msg_len; 1042c195535SJohn Polstra u_int16_t data_len; 1052c195535SJohn Polstra unsigned char rest[1]; 1062c195535SJohn Polstra }; 1072c195535SJohn Polstra 1082c195535SJohn Polstra struct tac_authen_cont { 1092c195535SJohn Polstra u_int16_t user_msg_len; 1102c195535SJohn Polstra u_int16_t data_len; 1112c195535SJohn Polstra u_int8_t flags; 1122c195535SJohn Polstra unsigned char rest[1]; 1132c195535SJohn Polstra }; 1142c195535SJohn Polstra 1151a61aeb8SPaul Traina struct tac_author_request { 1161a61aeb8SPaul Traina u_int8_t authen_meth; 1171a61aeb8SPaul Traina u_int8_t priv_lvl; 1181a61aeb8SPaul Traina u_int8_t authen_type; 1191a61aeb8SPaul Traina u_int8_t service; 1201a61aeb8SPaul Traina u_int8_t user_len; 1211a61aeb8SPaul Traina u_int8_t port_len; 1221a61aeb8SPaul Traina u_int8_t rem_addr_len; 1231a61aeb8SPaul Traina u_int8_t av_cnt; 1241a61aeb8SPaul Traina unsigned char rest[1]; 1251a61aeb8SPaul Traina }; 1261a61aeb8SPaul Traina 1271a61aeb8SPaul Traina struct tac_author_response { 1281a61aeb8SPaul Traina u_int8_t status; 1291a61aeb8SPaul Traina u_int8_t av_cnt; 1301a61aeb8SPaul Traina u_int16_t msg_len; 1311a61aeb8SPaul Traina u_int16_t data_len; 1321a61aeb8SPaul Traina unsigned char rest[1]; 1331a61aeb8SPaul Traina }; 1341a61aeb8SPaul Traina 135db3a20a5SShteryana Shopova struct tac_acct_start { 136db3a20a5SShteryana Shopova u_int8_t action; 137db3a20a5SShteryana Shopova u_int8_t authen_action; 138db3a20a5SShteryana Shopova u_int8_t priv_lvl; 139db3a20a5SShteryana Shopova u_int8_t authen_type; 140db3a20a5SShteryana Shopova u_int8_t authen_service; 141db3a20a5SShteryana Shopova u_int8_t user_len; 142db3a20a5SShteryana Shopova u_int8_t port_len; 143db3a20a5SShteryana Shopova u_int8_t rem_addr_len; 144db3a20a5SShteryana Shopova u_int8_t av_cnt; 145db3a20a5SShteryana Shopova unsigned char rest[1]; 146db3a20a5SShteryana Shopova }; 147db3a20a5SShteryana Shopova 148db3a20a5SShteryana Shopova struct tac_acct_reply { 149db3a20a5SShteryana Shopova u_int16_t msg_len; 150db3a20a5SShteryana Shopova u_int16_t data_len; 151db3a20a5SShteryana Shopova u_int8_t status; 152db3a20a5SShteryana Shopova unsigned char rest[1]; 153db3a20a5SShteryana Shopova }; 154db3a20a5SShteryana Shopova 1552c195535SJohn Polstra struct tac_msg { 1562c195535SJohn Polstra u_int8_t version; 1572c195535SJohn Polstra u_int8_t type; 1582c195535SJohn Polstra u_int8_t seq_no; 1592c195535SJohn Polstra u_int8_t flags; 1602c195535SJohn Polstra u_int8_t session_id[4]; 1612c195535SJohn Polstra u_int32_t length; 1622c195535SJohn Polstra union { 1632c195535SJohn Polstra struct tac_authen_start authen_start; 1642c195535SJohn Polstra struct tac_authen_reply authen_reply; 1652c195535SJohn Polstra struct tac_authen_cont authen_cont; 1661a61aeb8SPaul Traina struct tac_author_request author_request; 1671a61aeb8SPaul Traina struct tac_author_response author_response; 168db3a20a5SShteryana Shopova struct tac_acct_start acct_start; 169db3a20a5SShteryana Shopova struct tac_acct_reply acct_reply; 1702c195535SJohn Polstra unsigned char body[BODYSIZE]; 1712c195535SJohn Polstra } u; 1722c195535SJohn Polstra }; 1732c195535SJohn Polstra 1742c195535SJohn Polstra struct tac_handle { 1752c195535SJohn Polstra int fd; /* Socket file descriptor */ 1762c195535SJohn Polstra struct tac_server servers[MAXSERVERS]; /* Servers to contact */ 1772c195535SJohn Polstra int num_servers; /* Number of valid server entries */ 1782c195535SJohn Polstra int cur_server; /* Server we are currently using */ 1792c195535SJohn Polstra int single_connect; /* Use a single connection */ 1802c195535SJohn Polstra int last_seq_no; 1812c195535SJohn Polstra char errmsg[ERRSIZE]; /* Most recent error message */ 1822c195535SJohn Polstra 1832c195535SJohn Polstra struct clnt_str user; 1842c195535SJohn Polstra struct clnt_str port; 1852c195535SJohn Polstra struct clnt_str rem_addr; 1862c195535SJohn Polstra struct clnt_str data; 1872c195535SJohn Polstra struct clnt_str user_msg; 1881a61aeb8SPaul Traina struct clnt_str avs[MAXAVPAIRS]; 1892c195535SJohn Polstra 1902c195535SJohn Polstra struct tac_msg request; 1912c195535SJohn Polstra struct tac_msg response; 1922c195535SJohn Polstra 1932c195535SJohn Polstra int srvr_pos; /* Scan position in response body */ 1942c195535SJohn Polstra struct srvr_str srvr_msg; 1952c195535SJohn Polstra struct srvr_str srvr_data; 1961a61aeb8SPaul Traina struct srvr_str srvr_avs[MAXAVPAIRS]; 1972c195535SJohn Polstra }; 1982c195535SJohn Polstra 1992c195535SJohn Polstra #endif 200