diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-04-06 22:28:24 -0800 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-04-06 22:28:24 -0800 |
| commit | 448106b84d7c403dc3cba93b084dfcc9c683ecc8 (patch) | |
| tree | 787cddd194c7f6ca44c824b8375e80dc1637a1be /lib | |
| parent | bdff93464cb854e29d9e02660be65b26ceb8d4bf (diff) | |
| download | tinytac-448106b84d7c403dc3cba93b084dfcc9c683ecc8.tar.gz tinytac-448106b84d7c403dc3cba93b084dfcc9c683ecc8.tar.bz2 tinytac-448106b84d7c403dc3cba93b084dfcc9c683ecc8.tar.xz tinytac-448106b84d7c403dc3cba93b084dfcc9c683ecc8.zip | |
libtinytac: adding initial RFC datagithub/master
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/libtinytac/lproto.c | 105 | ||||
| -rw-r--r-- | lib/libtinytac/lproto.h | 184 |
2 files changed, 289 insertions, 0 deletions
diff --git a/lib/libtinytac/lproto.c b/lib/libtinytac/lproto.c new file mode 100644 index 0000000..864ecdb --- /dev/null +++ b/lib/libtinytac/lproto.c | |||
| @@ -0,0 +1,105 @@ | |||
| 1 | /* | ||
| 2 | * Tiny TACACS+ Client Library | ||
| 3 | * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>. | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions are | ||
| 8 | * met: | ||
| 9 | * | ||
| 10 | * * Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * * 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 | * * Neither the name of David M. Syzdek nor the | ||
| 16 | * names of its contributors may be used to endorse or promote products | ||
| 17 | * derived from this software without specific prior written permission. | ||
| 18 | * | ||
| 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 20 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR | ||
| 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 29 | * SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | #define _LIB_LIBTINYTAC_LPROTO_C 1 | ||
| 32 | #include "lproto.h" | ||
| 33 | |||
| 34 | |||
| 35 | /////////////// | ||
| 36 | // // | ||
| 37 | // Headers // | ||
| 38 | // // | ||
| 39 | /////////////// | ||
| 40 | #pragma mark - Headers | ||
| 41 | |||
| 42 | #include <stdlib.h> | ||
| 43 | #include <string.h> | ||
| 44 | #include <strings.h> | ||
| 45 | #include <unistd.h> | ||
| 46 | #include <fcntl.h> | ||
| 47 | #include <sys/types.h> | ||
| 48 | #include <sys/uio.h> | ||
| 49 | #include <time.h> | ||
| 50 | #include <sys/socket.h> | ||
| 51 | #include <arpa/inet.h> | ||
| 52 | #include <netinet/in.h> | ||
| 53 | #include <netdb.h> | ||
| 54 | #include <assert.h> | ||
| 55 | |||
| 56 | |||
| 57 | /////////////////// | ||
| 58 | // // | ||
| 59 | // Definitions // | ||
| 60 | // // | ||
| 61 | /////////////////// | ||
| 62 | #pragma mark - Definitions | ||
| 63 | |||
| 64 | |||
| 65 | ////////////////// | ||
| 66 | // // | ||
| 67 | // Prototypes // | ||
| 68 | // // | ||
| 69 | ////////////////// | ||
| 70 | #pragma mark - Prototypes | ||
| 71 | |||
| 72 | //--------------------// | ||
| 73 | // TinyTac prototypes // | ||
| 74 | //--------------------// | ||
| 75 | #pragma mark TinyTac prototypes | ||
| 76 | |||
| 77 | |||
| 78 | //-------------------// | ||
| 79 | // object prototypes // | ||
| 80 | //-------------------// | ||
| 81 | #pragma mark object prototypes | ||
| 82 | |||
| 83 | |||
| 84 | ///////////////// | ||
| 85 | // // | ||
| 86 | // Variables // | ||
| 87 | // // | ||
| 88 | ///////////////// | ||
| 89 | #pragma mark - Variables | ||
| 90 | |||
| 91 | |||
| 92 | ///////////////// | ||
| 93 | // // | ||
| 94 | // Functions // | ||
| 95 | // // | ||
| 96 | ///////////////// | ||
| 97 | #pragma mark - Functions | ||
| 98 | |||
| 99 | //-------------------// | ||
| 100 | // TinyTac functions // | ||
| 101 | //-------------------// | ||
| 102 | #pragma mark TinyTac functions | ||
| 103 | |||
| 104 | |||
| 105 | /* end of source */ | ||
diff --git a/lib/libtinytac/lproto.h b/lib/libtinytac/lproto.h new file mode 100644 index 0000000..d24029e --- /dev/null +++ b/lib/libtinytac/lproto.h | |||
| @@ -0,0 +1,184 @@ | |||
| 1 | /* | ||
| 2 | * Tiny TACACS+ Client Library | ||
| 3 | * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>. | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions are | ||
| 8 | * met: | ||
| 9 | * | ||
| 10 | * * Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * * 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 | * * Neither the name of David M. Syzdek nor the | ||
| 16 | * names of its contributors may be used to endorse or promote products | ||
| 17 | * derived from this software without specific prior written permission. | ||
| 18 | * | ||
| 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 20 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR | ||
| 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 29 | * SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | #ifndef _LIB_LIBTINYTAC_LPROTO_H | ||
| 32 | #define _LIB_LIBTINYTAC_LPROTO_H 1 | ||
| 33 | |||
| 34 | |||
| 35 | /////////////// | ||
| 36 | // // | ||
| 37 | // Headers // | ||
| 38 | // // | ||
| 39 | /////////////// | ||
| 40 | #pragma mark - Headers | ||
| 41 | |||
| 42 | #include "libtinytac.h" | ||
| 43 | |||
| 44 | #include <stdio.h> | ||
| 45 | #include <stdlib.h> | ||
| 46 | #include <string.h> | ||
| 47 | #include <strings.h> | ||
| 48 | |||
| 49 | |||
| 50 | /////////////////// | ||
| 51 | // // | ||
| 52 | // Definitions // | ||
| 53 | // // | ||
| 54 | /////////////////// | ||
| 55 | #pragma mark - Definitions | ||
| 56 | |||
| 57 | #define TTAC_MINOR_TO_VERSION( minor, ver ) ((ver & 0xff00) | ((minor & 0x00ff) << 0)) | ||
| 58 | #define TTAC_MAJOR_TO_VERSION( major, ver ) ((ver & 0x00ff) | ((major & 0x00ff) << 4)) | ||
| 59 | #define TTAC_VERSION_TO_MINOR( ver ) ((ver & 0x00ff) >> 0) | ||
| 60 | #define TTAC_VERSION_TO_MAJOR( ver ) ((ver & 0xff00) >> 4) | ||
| 61 | |||
| 62 | |||
| 63 | ////////////////// | ||
| 64 | // // | ||
| 65 | // Data Types // | ||
| 66 | // // | ||
| 67 | ////////////////// | ||
| 68 | #pragma mark - Data Types | ||
| 69 | |||
| 70 | // RFC 8907 Section 4.1. The TACACS+ Packet Header | ||
| 71 | typedef struct tinytac_header | ||
| 72 | { | ||
| 73 | uint8_t pckt_version; // 4 bits major and 4 bits minor | ||
| 74 | uint8_t pckt_type; | ||
| 75 | uint8_t pckt_seq_no; | ||
| 76 | uint8_t pckt_flags; | ||
| 77 | uint32_t pckt_session_id; | ||
| 78 | uint32_t pckt_length; | ||
| 79 | uint8_t pckt_body[]; | ||
| 80 | } tinyrad_header_t; | ||
| 81 | |||
| 82 | |||
| 83 | // RFC 8907 Section 5.1. The Authentication START Packet Body | ||
| 84 | typedef struct tinytac_packet_authen_start | ||
| 85 | { | ||
| 86 | uint8_t bdy_action; | ||
| 87 | uint8_t bdy_priv_lvl; | ||
| 88 | uint8_t bdy_authen_type; | ||
| 89 | uint8_t bdy_authen_service; | ||
| 90 | uint8_t bdy_user_len; | ||
| 91 | uint8_t bdy_port_len; | ||
| 92 | uint8_t bdy_rem_addr_len; | ||
| 93 | uint8_t bdy_data_len; | ||
| 94 | uint8_t bdy_bytes[]; | ||
| 95 | } tinyrad_authen_start_t; | ||
| 96 | |||
| 97 | |||
| 98 | // RFC 8907 Section 5.2. The Authentication REPLY Packet Body | ||
| 99 | typedef struct tinytac_packet_authen_reply | ||
| 100 | { | ||
| 101 | uint8_t bdy_status; | ||
| 102 | uint8_t bdy_flags; | ||
| 103 | uint16_t bdy_server_msg_len; | ||
| 104 | uint16_t bdy_data_len; | ||
| 105 | uint8_t bdy_bytes[]; | ||
| 106 | } tinyrad_authen_reply_t; | ||
| 107 | |||
| 108 | |||
| 109 | // RFC 8907 Section 5.3. The Authentication CONTINUE Packet Body | ||
| 110 | typedef struct tinytac_packet_authen_continue | ||
| 111 | { | ||
| 112 | uint16_t bdy_user_msg_len; | ||
| 113 | uint16_t bdy_data_len; | ||
| 114 | uint8_t bdy_flags; | ||
| 115 | uint8_t bdy_bytes[]; | ||
| 116 | } tinyrad_authen_contiue_t; | ||
| 117 | |||
| 118 | |||
| 119 | // RFC 8907 Section 6.1. The Authorization REQUEST Packet Body | ||
| 120 | typedef struct tinytac_packet_author_request | ||
| 121 | { | ||
| 122 | uint8_t bdy_authen_method; | ||
| 123 | uint8_t bdy_priv_lvl; | ||
| 124 | uint8_t bdy_authen_type; | ||
| 125 | uint8_t bdy_authen_service; | ||
| 126 | uint8_t bdy_user_len; | ||
| 127 | uint8_t bdy_port_len; | ||
| 128 | uint8_t bdy_rem_addr_len; | ||
| 129 | uint8_t bdy_arg_cnt; | ||
| 130 | uint8_t bdy_bytes[]; | ||
| 131 | } tinyrad_author_request_t; | ||
| 132 | |||
| 133 | |||
| 134 | // RFC 8907 Section 6.2. The Authorization REPLY Packet Body | ||
| 135 | typedef struct tinytac_packet_author_reply | ||
| 136 | { | ||
| 137 | uint8_t bdy_status; | ||
| 138 | uint8_t bdy_arg_cnt; | ||
| 139 | uint16_t bdy_server_msg_len; | ||
| 140 | uint16_t bdy_data_len; | ||
| 141 | uint8_t bdy_bytes[]; | ||
| 142 | } tinyrad_author_reply_t; | ||
| 143 | |||
| 144 | |||
| 145 | // RFC 8907 Section 7.1. The Account REQUEST Packet Body | ||
| 146 | typedef struct tinytac_packet_acct_reqeust | ||
| 147 | { | ||
| 148 | uint8_t bdy_flags; | ||
| 149 | uint8_t bdy_authen_method; | ||
| 150 | uint8_t bdy_priv_lvl; | ||
| 151 | uint8_t bdy_authen_type; | ||
| 152 | uint8_t bdy_authen_service; | ||
| 153 | uint8_t bdy_user_len; | ||
| 154 | uint8_t bdy_port_len; | ||
| 155 | uint8_t bdy_rem_addr_len; | ||
| 156 | uint8_t bdy_arg_cnt; | ||
| 157 | uint8_t bdy_bytes[]; | ||
| 158 | } tinyrad_acct_request_t; | ||
| 159 | |||
| 160 | |||
| 161 | // RFC 8907 Section 7.2. The Accounting REPLY Packet Body | ||
| 162 | typedef struct tinytac_packet_acct_reply | ||
| 163 | { | ||
| 164 | uint16_t bdy_server_msg_len; | ||
| 165 | uint16_t bdy_data_len; | ||
| 166 | uint8_t bdy_status; | ||
| 167 | uint8_t bdy_bytes[]; | ||
| 168 | } tinyrad_acct_reply_t; | ||
| 169 | |||
| 170 | |||
| 171 | ////////////////// | ||
| 172 | // // | ||
| 173 | // Prototypes // | ||
| 174 | // // | ||
| 175 | ////////////////// | ||
| 176 | #pragma mark - Prototypes | ||
| 177 | |||
| 178 | //-------------------// | ||
| 179 | // object prototypes // | ||
| 180 | //-------------------// | ||
| 181 | #pragma mark object prototypes | ||
| 182 | |||
| 183 | |||
| 184 | #endif /* end of header */ | ||
