12c195535SJohn Polstra /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 35e53a4f9SPedro F. Giffuni * 41a61aeb8SPaul Traina * Copyright (c) 1998, 2001, Juniper Networks, Inc. 52c195535SJohn Polstra * All rights reserved. 62c195535SJohn Polstra * 72c195535SJohn Polstra * Redistribution and use in source and binary forms, with or without 82c195535SJohn Polstra * modification, are permitted provided that the following conditions 92c195535SJohn Polstra * are met: 102c195535SJohn Polstra * 1. Redistributions of source code must retain the above copyright 112c195535SJohn Polstra * notice, this list of conditions and the following disclaimer. 122c195535SJohn Polstra * 2. Redistributions in binary form must reproduce the above copyright 132c195535SJohn Polstra * notice, this list of conditions and the following disclaimer in the 142c195535SJohn Polstra * documentation and/or other materials provided with the distribution. 152c195535SJohn Polstra * 162c195535SJohn Polstra * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 172c195535SJohn Polstra * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 182c195535SJohn Polstra * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 192c195535SJohn Polstra * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 202c195535SJohn Polstra * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 212c195535SJohn Polstra * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 222c195535SJohn Polstra * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 232c195535SJohn Polstra * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 242c195535SJohn Polstra * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 252c195535SJohn Polstra * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 262c195535SJohn Polstra * SUCH DAMAGE. 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 61*21850106SDag-Erling Smørgrav struct tac_str { 62*21850106SDag-Erling Smørgrav char *data; 632c195535SJohn Polstra size_t len; 642c195535SJohn Polstra }; 652c195535SJohn Polstra 662c195535SJohn Polstra struct tac_authen_start { 672c195535SJohn Polstra u_int8_t action; 682c195535SJohn Polstra u_int8_t priv_lvl; 692c195535SJohn Polstra u_int8_t authen_type; 702c195535SJohn Polstra u_int8_t service; 712c195535SJohn Polstra u_int8_t user_len; 722c195535SJohn Polstra u_int8_t port_len; 732c195535SJohn Polstra u_int8_t rem_addr_len; 742c195535SJohn Polstra u_int8_t data_len; 752c195535SJohn Polstra unsigned char rest[1]; 762c195535SJohn Polstra }; 772c195535SJohn Polstra 782c195535SJohn Polstra struct tac_authen_reply { 792c195535SJohn Polstra u_int8_t status; 802c195535SJohn Polstra u_int8_t flags; 812c195535SJohn Polstra u_int16_t msg_len; 822c195535SJohn Polstra u_int16_t data_len; 832c195535SJohn Polstra unsigned char rest[1]; 842c195535SJohn Polstra }; 852c195535SJohn Polstra 862c195535SJohn Polstra struct tac_authen_cont { 872c195535SJohn Polstra u_int16_t user_msg_len; 882c195535SJohn Polstra u_int16_t data_len; 892c195535SJohn Polstra u_int8_t flags; 902c195535SJohn Polstra unsigned char rest[1]; 912c195535SJohn Polstra }; 922c195535SJohn Polstra 931a61aeb8SPaul Traina struct tac_author_request { 941a61aeb8SPaul Traina u_int8_t authen_meth; 951a61aeb8SPaul Traina u_int8_t priv_lvl; 961a61aeb8SPaul Traina u_int8_t authen_type; 971a61aeb8SPaul Traina u_int8_t service; 981a61aeb8SPaul Traina u_int8_t user_len; 991a61aeb8SPaul Traina u_int8_t port_len; 1001a61aeb8SPaul Traina u_int8_t rem_addr_len; 1011a61aeb8SPaul Traina u_int8_t av_cnt; 1021a61aeb8SPaul Traina unsigned char rest[1]; 1031a61aeb8SPaul Traina }; 1041a61aeb8SPaul Traina 1051a61aeb8SPaul Traina struct tac_author_response { 1061a61aeb8SPaul Traina u_int8_t status; 1071a61aeb8SPaul Traina u_int8_t av_cnt; 1081a61aeb8SPaul Traina u_int16_t msg_len; 1091a61aeb8SPaul Traina u_int16_t data_len; 1101a61aeb8SPaul Traina unsigned char rest[1]; 1111a61aeb8SPaul Traina }; 1121a61aeb8SPaul Traina 113db3a20a5SShteryana Shopova struct tac_acct_start { 114db3a20a5SShteryana Shopova u_int8_t action; 115db3a20a5SShteryana Shopova u_int8_t authen_action; 116db3a20a5SShteryana Shopova u_int8_t priv_lvl; 117db3a20a5SShteryana Shopova u_int8_t authen_type; 118db3a20a5SShteryana Shopova u_int8_t authen_service; 119db3a20a5SShteryana Shopova u_int8_t user_len; 120db3a20a5SShteryana Shopova u_int8_t port_len; 121db3a20a5SShteryana Shopova u_int8_t rem_addr_len; 122db3a20a5SShteryana Shopova u_int8_t av_cnt; 123db3a20a5SShteryana Shopova unsigned char rest[1]; 124db3a20a5SShteryana Shopova }; 125db3a20a5SShteryana Shopova 126db3a20a5SShteryana Shopova struct tac_acct_reply { 127db3a20a5SShteryana Shopova u_int16_t msg_len; 128db3a20a5SShteryana Shopova u_int16_t data_len; 129db3a20a5SShteryana Shopova u_int8_t status; 130db3a20a5SShteryana Shopova unsigned char rest[1]; 131db3a20a5SShteryana Shopova }; 132db3a20a5SShteryana Shopova 1332c195535SJohn Polstra struct tac_msg { 1342c195535SJohn Polstra u_int8_t version; 1352c195535SJohn Polstra u_int8_t type; 1362c195535SJohn Polstra u_int8_t seq_no; 1372c195535SJohn Polstra u_int8_t flags; 1382c195535SJohn Polstra u_int8_t session_id[4]; 1392c195535SJohn Polstra u_int32_t length; 1402c195535SJohn Polstra union { 1412c195535SJohn Polstra struct tac_authen_start authen_start; 1422c195535SJohn Polstra struct tac_authen_reply authen_reply; 1432c195535SJohn Polstra struct tac_authen_cont authen_cont; 1441a61aeb8SPaul Traina struct tac_author_request author_request; 1451a61aeb8SPaul Traina struct tac_author_response author_response; 146db3a20a5SShteryana Shopova struct tac_acct_start acct_start; 147db3a20a5SShteryana Shopova struct tac_acct_reply acct_reply; 1482c195535SJohn Polstra unsigned char body[BODYSIZE]; 1492c195535SJohn Polstra } u; 1502c195535SJohn Polstra }; 1512c195535SJohn Polstra 152*21850106SDag-Erling Smørgrav struct tac_server { 153*21850106SDag-Erling Smørgrav struct sockaddr_in addr; /* Address of server */ 154*21850106SDag-Erling Smørgrav char *secret; /* Shared secret */ 155*21850106SDag-Erling Smørgrav int timeout; /* Timeout in seconds */ 156*21850106SDag-Erling Smørgrav int flags; 157*21850106SDag-Erling Smørgrav unsigned int navs; 158*21850106SDag-Erling Smørgrav struct tac_str avs[MAXAVPAIRS]; 159*21850106SDag-Erling Smørgrav }; 160*21850106SDag-Erling Smørgrav 1612c195535SJohn Polstra struct tac_handle { 1622c195535SJohn Polstra int fd; /* Socket file descriptor */ 1632c195535SJohn Polstra struct tac_server servers[MAXSERVERS]; /* Servers to contact */ 1642c195535SJohn Polstra int num_servers; /* Number of valid server entries */ 1652c195535SJohn Polstra int cur_server; /* Server we are currently using */ 1662c195535SJohn Polstra int single_connect; /* Use a single connection */ 1672c195535SJohn Polstra int last_seq_no; 1682c195535SJohn Polstra char errmsg[ERRSIZE]; /* Most recent error message */ 1692c195535SJohn Polstra 170*21850106SDag-Erling Smørgrav struct tac_str user; 171*21850106SDag-Erling Smørgrav struct tac_str port; 172*21850106SDag-Erling Smørgrav struct tac_str rem_addr; 173*21850106SDag-Erling Smørgrav struct tac_str data; 174*21850106SDag-Erling Smørgrav struct tac_str user_msg; 175*21850106SDag-Erling Smørgrav struct tac_str avs[MAXAVPAIRS]; 1762c195535SJohn Polstra 1772c195535SJohn Polstra struct tac_msg request; 1782c195535SJohn Polstra struct tac_msg response; 1792c195535SJohn Polstra 1802c195535SJohn Polstra int srvr_pos; /* Scan position in response body */ 181*21850106SDag-Erling Smørgrav unsigned int srvr_navs; 182*21850106SDag-Erling Smørgrav struct tac_str srvr_msg; 183*21850106SDag-Erling Smørgrav struct tac_str srvr_data; 184*21850106SDag-Erling Smørgrav struct tac_str srvr_avs[MAXAVPAIRS]; 1852c195535SJohn Polstra }; 1862c195535SJohn Polstra 187*21850106SDag-Erling Smørgrav #define is_alpha(ch) /* alphabetical */ \ 188*21850106SDag-Erling Smørgrav (((ch) >= 'A' && (ch) <= 'Z') || ((ch) >= 'a' && (ch) <= 'z')) 189*21850106SDag-Erling Smørgrav #define is_num(ch) /* numerical */ \ 190*21850106SDag-Erling Smørgrav ((ch) >= '0' && (ch) <= '9') 191*21850106SDag-Erling Smørgrav #define is_alnum(ch) /* alphanumerical */ \ 192*21850106SDag-Erling Smørgrav (is_alpha(ch) || is_num(ch)) 193*21850106SDag-Erling Smørgrav #define is_arg(ch) /* valid in an argument name */ \ 194*21850106SDag-Erling Smørgrav (is_alnum(ch) || (ch) == '_' || (ch) == '-') 195*21850106SDag-Erling Smørgrav 1962c195535SJohn Polstra #endif 197