Release bumped to "gts4".
[tac_plus.git] / packet.h
1 #ifndef PACKET_H
2 #define PACKET_H 1
3
4 #include "tac_plus.h"
5
6 #include <sys/types.h>          /* for u_* */
7
8
9 /* All tacacs+ packets have the same header format */
10
11 struct tac_plus_pak_hdr {
12     u_char version;
13
14 #define TAC_PLUS_MAJOR_VER_MASK 0xf0
15 #define TAC_PLUS_MAJOR_VER      0xc0
16
17 #define TAC_PLUS_MINOR_VER_0    0x0
18 #define TAC_PLUS_VER_0  (TAC_PLUS_MAJOR_VER | TAC_PLUS_MINOR_VER_0)
19
20 #define TAC_PLUS_MINOR_VER_1    0x01
21 #define TAC_PLUS_VER_1  (TAC_PLUS_MAJOR_VER | TAC_PLUS_MINOR_VER_1)
22
23     u_char type;
24
25 #define TAC_PLUS_AUTHEN                 1
26 #define TAC_PLUS_AUTHOR                 2
27 #define TAC_PLUS_ACCT                   3
28
29     u_char seq_no;              /* packet sequence number */
30     u_char encryption;          /* packet is encrypted or cleartext */
31
32 #define TAC_PLUS_ENCRYPTED 0x0          /* packet is encrypted */
33 #define TAC_PLUS_CLEAR     0x1          /* packet is not encrypted */
34
35     int session_id;             /* session identifier FIXME: Is this needed? */
36     int datalength;             /* length of encrypted data following this
37                                  * header */
38     /* datalength bytes of encrypted data */
39 };
40
41 #define TAC_PLUS_HDR_SIZE 12
42
43 typedef struct tac_plus_pak_hdr HDR;
44
45 /* Authentication packet NAS sends to us */
46
47 struct authen_start {
48     u_char action;
49
50 #define TAC_PLUS_AUTHEN_LOGIN    0x1
51 #define TAC_PLUS_AUTHEN_CHPASS   0x2
52 #define TAC_PLUS_AUTHEN_SENDPASS 0x3 /* deprecated */
53 #define TAC_PLUS_AUTHEN_SENDAUTH 0x4
54
55     u_char priv_lvl;
56
57 #define TAC_PLUS_PRIV_LVL_MIN 0x0
58 #define TAC_PLUS_PRIV_LVL_MAX 0xf
59
60     u_char authen_type;
61
62 #define TAC_PLUS_AUTHEN_TYPE_ASCII  1
63 #define TAC_PLUS_AUTHEN_TYPE_PAP    2
64 #define TAC_PLUS_AUTHEN_TYPE_CHAP   3
65 #define TAC_PLUS_AUTHEN_TYPE_ARAP   4
66 #ifdef MSCHAP
67 #define TAC_PLUS_AUTHEN_TYPE_MSCHAP 5
68 #endif /* MSCHAP */
69
70     u_char service;
71
72 #define TAC_PLUS_AUTHEN_SVC_LOGIN  1
73 #define TAC_PLUS_AUTHEN_SVC_ENABLE 2
74 #define TAC_PLUS_AUTHEN_SVC_PPP    3
75 #define TAC_PLUS_AUTHEN_SVC_ARAP   4
76 #define TAC_PLUS_AUTHEN_SVC_PT     5
77 #define TAC_PLUS_AUTHEN_SVC_RCMD   6
78 #define TAC_PLUS_AUTHEN_SVC_X25    7
79 #define TAC_PLUS_AUTHEN_SVC_NASI   8
80
81     u_char user_len;
82     u_char port_len;
83     u_char rem_addr_len;
84     u_char data_len;
85     /* <user_len bytes of char data> */
86     /* <port_len bytes of char data> */
87     /* <rem_addr_len bytes of u_char data> */
88     /* <data_len bytes of u_char data> */
89 };
90
91 #define TAC_AUTHEN_START_FIXED_FIELDS_SIZE 8
92
93 /* Authentication continue packet NAS sends to us */
94 struct authen_cont {
95     u_short user_msg_len;
96     u_short user_data_len;
97     u_char flags;
98
99 #define TAC_PLUS_CONTINUE_FLAG_ABORT 0x1
100
101     /* <user_msg_len bytes of u_char data> */
102     /* <user_data_len bytes of u_char data> */
103 };
104
105 #define TAC_AUTHEN_CONT_FIXED_FIELDS_SIZE 5
106
107 /* Authentication reply packet we send to NAS */
108 struct authen_reply {
109     u_char status;
110
111 #define TAC_PLUS_AUTHEN_STATUS_PASS     1
112 #define TAC_PLUS_AUTHEN_STATUS_FAIL     2
113 #define TAC_PLUS_AUTHEN_STATUS_GETDATA  3
114 #define TAC_PLUS_AUTHEN_STATUS_GETUSER  4
115 #define TAC_PLUS_AUTHEN_STATUS_GETPASS  5
116 #define TAC_PLUS_AUTHEN_STATUS_RESTART  6
117 #define TAC_PLUS_AUTHEN_STATUS_ERROR    7
118 #define TAC_PLUS_AUTHEN_STATUS_FOLLOW   0x21
119
120     u_char flags;
121
122 #define TAC_PLUS_AUTHEN_FLAG_NOECHO     0x1
123
124     u_short msg_len;
125     u_short data_len;
126
127     /* <msg_len bytes of char data> */
128     /* <data_len bytes of u_char data> */
129 };
130
131 #define TAC_AUTHEN_REPLY_FIXED_FIELDS_SIZE 6
132
133 /* An authorization request packet */
134 struct author {
135     u_char authen_method;
136     u_char priv_lvl;
137     u_char authen_type;
138     u_char service;
139
140     u_char user_len;
141     u_char port_len;
142     u_char rem_addr_len;
143     u_char arg_cnt;             /* the number of args */
144
145     /* <arg_cnt u_chars containing the lengths of args 1 to arg n> */
146     /* <user_len bytes of char data> */
147     /* <port_len bytes of char data> */
148     /* <rem_addr_len bytes of u_char data> */
149     /* <char data for each arg> */
150 };
151
152 #define TAC_AUTHOR_REQ_FIXED_FIELDS_SIZE 8
153
154 /* An authorization reply packet */
155 struct author_reply {
156     u_char status;
157     u_char arg_cnt;
158     u_short msg_len;
159     u_short data_len;
160
161     /* <arg_cnt u_chars containing the lengths of arg 1 to arg n> */
162     /* <msg_len bytes of char data> */
163     /* <data_len bytes of char data> */
164     /* <char data for each arg> */
165 };
166
167 #define TAC_AUTHOR_REPLY_FIXED_FIELDS_SIZE 6
168
169 struct acct {
170     u_char flags;
171
172 #define TAC_PLUS_ACCT_FLAG_MORE     0x1
173 #define TAC_PLUS_ACCT_FLAG_START    0x2
174 #define TAC_PLUS_ACCT_FLAG_STOP     0x4
175 #define TAC_PLUS_ACCT_FLAG_WATCHDOG 0x8
176
177     u_char authen_method;
178     u_char priv_lvl;
179     u_char authen_type;
180     u_char authen_service;
181     u_char user_len;
182     u_char port_len;
183     u_char rem_addr_len;
184     u_char arg_cnt; /* the number of cmd args */
185     /* one u_char containing size for each arg */
186     /* <user_len bytes of char data> */
187     /* <port_len bytes of char data> */
188     /* <rem_addr_len bytes of u_char data> */
189     /* char data for args 1 ... n */
190 };
191
192 #define TAC_ACCT_REQ_FIXED_FIELDS_SIZE 9
193
194 struct acct_reply {
195     u_short msg_len;
196     u_short data_len;
197     u_char status;
198
199 #define TAC_PLUS_ACCT_STATUS_SUCCESS 0x1
200 #define TAC_PLUS_ACCT_STATUS_ERROR   0x2
201 #define TAC_PLUS_ACCT_STATUS_FOLLOW  0x21
202
203 };
204
205 #define TAC_ACCT_REPLY_FIXED_FIELDS_SIZE 5
206
207
208 extern void send_acct_reply TAC_ARGS((unsigned status, const char *msg, const char *data));
209 extern void send_author_reply TAC_ARGS((unsigned status, const char *msg, const char *data, int arg_cnt, /* const */ char **args));
210 extern void send_authen_error TAC_ARGS((const char *msg));
211 extern void send_authen_reply TAC_ARGS((int status, const char *msg, unsigned msg_len, const unsigned char *data, unsigned data_len, unsigned flags));
212 extern u_char *get_authen_continue TAC_ARGS((void));
213 extern u_char *read_packet TAC_ARGS((void));
214 extern void send_error_reply TAC_ARGS((int type, char *msg));
215
216
217 #endif /* PACKET_H */