1 | #include <machine/rtems-bsd-user-space.h> |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (c) 1995, 1996, 1997 |
---|
5 | * The Regents of the University of California. All rights reserved. |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms, with or without |
---|
8 | * modification, are permitted provided that: (1) source code distributions |
---|
9 | * retain the above copyright notice and this paragraph in its entirety, (2) |
---|
10 | * distributions including binary code include the above copyright notice and |
---|
11 | * this paragraph in its entirety in the documentation or other materials |
---|
12 | * provided with the distribution, and (3) all advertising materials mentioning |
---|
13 | * features or use of this software display the following acknowledgement: |
---|
14 | * ``This product includes software developed by the University of California, |
---|
15 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of |
---|
16 | * the University nor the names of its contributors may be used to endorse |
---|
17 | * or promote products derived from this software without specific prior |
---|
18 | * written permission. |
---|
19 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED |
---|
20 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
---|
21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
---|
22 | * |
---|
23 | * Initial contribution from John Hawkinson (jhawk@mit.edu). |
---|
24 | */ |
---|
25 | |
---|
26 | #ifndef lint |
---|
27 | static const char rcsid[] _U_ = |
---|
28 | "@(#) $Header: /tcpdump/master/tcpdump/print-krb.c,v 1.23 2003-11-16 09:36:26 guy Exp $"; |
---|
29 | #endif |
---|
30 | |
---|
31 | #ifdef HAVE_CONFIG_H |
---|
32 | #include "config.h" |
---|
33 | #endif |
---|
34 | |
---|
35 | #include <tcpdump-stdinc.h> |
---|
36 | |
---|
37 | #include <stdio.h> |
---|
38 | |
---|
39 | #include "interface.h" |
---|
40 | #include "addrtoname.h" |
---|
41 | #include "extract.h" |
---|
42 | |
---|
43 | static const u_char *c_print(register const u_char *, register const u_char *); |
---|
44 | static const u_char *krb4_print_hdr(const u_char *); |
---|
45 | static void krb4_print(const u_char *); |
---|
46 | |
---|
47 | #define AUTH_MSG_KDC_REQUEST 1<<1 |
---|
48 | #define AUTH_MSG_KDC_REPLY 2<<1 |
---|
49 | #define AUTH_MSG_APPL_REQUEST 3<<1 |
---|
50 | #define AUTH_MSG_APPL_REQUEST_MUTUAL 4<<1 |
---|
51 | #define AUTH_MSG_ERR_REPLY 5<<1 |
---|
52 | #define AUTH_MSG_PRIVATE 6<<1 |
---|
53 | #define AUTH_MSG_SAFE 7<<1 |
---|
54 | #define AUTH_MSG_APPL_ERR 8<<1 |
---|
55 | #define AUTH_MSG_DIE 63<<1 |
---|
56 | |
---|
57 | #define KERB_ERR_OK 0 |
---|
58 | #define KERB_ERR_NAME_EXP 1 |
---|
59 | #define KERB_ERR_SERVICE_EXP 2 |
---|
60 | #define KERB_ERR_AUTH_EXP 3 |
---|
61 | #define KERB_ERR_PKT_VER 4 |
---|
62 | #define KERB_ERR_NAME_MAST_KEY_VER 5 |
---|
63 | #define KERB_ERR_SERV_MAST_KEY_VER 6 |
---|
64 | #define KERB_ERR_BYTE_ORDER 7 |
---|
65 | #define KERB_ERR_PRINCIPAL_UNKNOWN 8 |
---|
66 | #define KERB_ERR_PRINCIPAL_NOT_UNIQUE 9 |
---|
67 | #define KERB_ERR_NULL_KEY 10 |
---|
68 | |
---|
69 | struct krb { |
---|
70 | u_int8_t pvno; /* Protocol Version */ |
---|
71 | u_int8_t type; /* Type+B */ |
---|
72 | }; |
---|
73 | |
---|
74 | static char tstr[] = " [|kerberos]"; |
---|
75 | |
---|
76 | static struct tok type2str[] = { |
---|
77 | { AUTH_MSG_KDC_REQUEST, "KDC_REQUEST" }, |
---|
78 | { AUTH_MSG_KDC_REPLY, "KDC_REPLY" }, |
---|
79 | { AUTH_MSG_APPL_REQUEST, "APPL_REQUEST" }, |
---|
80 | { AUTH_MSG_APPL_REQUEST_MUTUAL, "APPL_REQUEST_MUTUAL" }, |
---|
81 | { AUTH_MSG_ERR_REPLY, "ERR_REPLY" }, |
---|
82 | { AUTH_MSG_PRIVATE, "PRIVATE" }, |
---|
83 | { AUTH_MSG_SAFE, "SAFE" }, |
---|
84 | { AUTH_MSG_APPL_ERR, "APPL_ERR" }, |
---|
85 | { AUTH_MSG_DIE, "DIE" }, |
---|
86 | { 0, NULL } |
---|
87 | }; |
---|
88 | |
---|
89 | static struct tok kerr2str[] = { |
---|
90 | { KERB_ERR_OK, "OK" }, |
---|
91 | { KERB_ERR_NAME_EXP, "NAME_EXP" }, |
---|
92 | { KERB_ERR_SERVICE_EXP, "SERVICE_EXP" }, |
---|
93 | { KERB_ERR_AUTH_EXP, "AUTH_EXP" }, |
---|
94 | { KERB_ERR_PKT_VER, "PKT_VER" }, |
---|
95 | { KERB_ERR_NAME_MAST_KEY_VER, "NAME_MAST_KEY_VER" }, |
---|
96 | { KERB_ERR_SERV_MAST_KEY_VER, "SERV_MAST_KEY_VER" }, |
---|
97 | { KERB_ERR_BYTE_ORDER, "BYTE_ORDER" }, |
---|
98 | { KERB_ERR_PRINCIPAL_UNKNOWN, "PRINCIPAL_UNKNOWN" }, |
---|
99 | { KERB_ERR_PRINCIPAL_NOT_UNIQUE,"PRINCIPAL_NOT_UNIQUE" }, |
---|
100 | { KERB_ERR_NULL_KEY, "NULL_KEY"}, |
---|
101 | { 0, NULL} |
---|
102 | }; |
---|
103 | |
---|
104 | static const u_char * |
---|
105 | c_print(register const u_char *s, register const u_char *ep) |
---|
106 | { |
---|
107 | register u_char c; |
---|
108 | register int flag; |
---|
109 | |
---|
110 | flag = 1; |
---|
111 | while (s < ep) { |
---|
112 | c = *s++; |
---|
113 | if (c == '\0') { |
---|
114 | flag = 0; |
---|
115 | break; |
---|
116 | } |
---|
117 | if (!isascii(c)) { |
---|
118 | c = toascii(c); |
---|
119 | putchar('M'); |
---|
120 | putchar('-'); |
---|
121 | } |
---|
122 | if (!isprint(c)) { |
---|
123 | c ^= 0x40; /* DEL to ?, others to alpha */ |
---|
124 | putchar('^'); |
---|
125 | } |
---|
126 | putchar(c); |
---|
127 | } |
---|
128 | if (flag) |
---|
129 | return NULL; |
---|
130 | return (s); |
---|
131 | } |
---|
132 | |
---|
133 | static const u_char * |
---|
134 | krb4_print_hdr(const u_char *cp) |
---|
135 | { |
---|
136 | cp += 2; |
---|
137 | |
---|
138 | #define PRINT if ((cp = c_print(cp, snapend)) == NULL) goto trunc |
---|
139 | |
---|
140 | PRINT; |
---|
141 | putchar('.'); |
---|
142 | PRINT; |
---|
143 | putchar('@'); |
---|
144 | PRINT; |
---|
145 | return (cp); |
---|
146 | |
---|
147 | trunc: |
---|
148 | fputs(tstr, stdout); |
---|
149 | return (NULL); |
---|
150 | |
---|
151 | #undef PRINT |
---|
152 | } |
---|
153 | |
---|
154 | static void |
---|
155 | krb4_print(const u_char *cp) |
---|
156 | { |
---|
157 | register const struct krb *kp; |
---|
158 | u_char type; |
---|
159 | u_short len; |
---|
160 | |
---|
161 | #define PRINT if ((cp = c_print(cp, snapend)) == NULL) goto trunc |
---|
162 | /* True if struct krb is little endian */ |
---|
163 | #define IS_LENDIAN(kp) (((kp)->type & 0x01) != 0) |
---|
164 | #define KTOHSP(kp, cp) (IS_LENDIAN(kp) ? EXTRACT_LE_16BITS(cp) : EXTRACT_16BITS(cp)) |
---|
165 | |
---|
166 | kp = (struct krb *)cp; |
---|
167 | |
---|
168 | if ((&kp->type) >= snapend) { |
---|
169 | fputs(tstr, stdout); |
---|
170 | return; |
---|
171 | } |
---|
172 | |
---|
173 | type = kp->type & (0xFF << 1); |
---|
174 | |
---|
175 | printf(" %s %s: ", |
---|
176 | IS_LENDIAN(kp) ? "le" : "be", tok2str(type2str, NULL, type)); |
---|
177 | |
---|
178 | switch (type) { |
---|
179 | |
---|
180 | case AUTH_MSG_KDC_REQUEST: |
---|
181 | if ((cp = krb4_print_hdr(cp)) == NULL) |
---|
182 | return; |
---|
183 | cp += 4; /* ctime */ |
---|
184 | TCHECK(*cp); |
---|
185 | printf(" %dmin ", *cp++ * 5); |
---|
186 | PRINT; |
---|
187 | putchar('.'); |
---|
188 | PRINT; |
---|
189 | break; |
---|
190 | |
---|
191 | case AUTH_MSG_APPL_REQUEST: |
---|
192 | cp += 2; |
---|
193 | TCHECK(*cp); |
---|
194 | printf("v%d ", *cp++); |
---|
195 | PRINT; |
---|
196 | TCHECK(*cp); |
---|
197 | printf(" (%d)", *cp++); |
---|
198 | TCHECK(*cp); |
---|
199 | printf(" (%d)", *cp); |
---|
200 | break; |
---|
201 | |
---|
202 | case AUTH_MSG_KDC_REPLY: |
---|
203 | if ((cp = krb4_print_hdr(cp)) == NULL) |
---|
204 | return; |
---|
205 | cp += 10; /* timestamp + n + exp + kvno */ |
---|
206 | TCHECK2(*cp, sizeof(short)); |
---|
207 | len = KTOHSP(kp, cp); |
---|
208 | printf(" (%d)", len); |
---|
209 | break; |
---|
210 | |
---|
211 | case AUTH_MSG_ERR_REPLY: |
---|
212 | if ((cp = krb4_print_hdr(cp)) == NULL) |
---|
213 | return; |
---|
214 | cp += 4; /* timestamp */ |
---|
215 | TCHECK2(*cp, sizeof(short)); |
---|
216 | printf(" %s ", tok2str(kerr2str, NULL, KTOHSP(kp, cp))); |
---|
217 | cp += 4; |
---|
218 | PRINT; |
---|
219 | break; |
---|
220 | |
---|
221 | default: |
---|
222 | fputs("(unknown)", stdout); |
---|
223 | break; |
---|
224 | } |
---|
225 | |
---|
226 | return; |
---|
227 | trunc: |
---|
228 | fputs(tstr, stdout); |
---|
229 | } |
---|
230 | |
---|
231 | void |
---|
232 | krb_print(const u_char *dat) |
---|
233 | { |
---|
234 | register const struct krb *kp; |
---|
235 | |
---|
236 | kp = (struct krb *)dat; |
---|
237 | |
---|
238 | if (dat >= snapend) { |
---|
239 | fputs(tstr, stdout); |
---|
240 | return; |
---|
241 | } |
---|
242 | |
---|
243 | switch (kp->pvno) { |
---|
244 | |
---|
245 | case 1: |
---|
246 | case 2: |
---|
247 | case 3: |
---|
248 | printf(" v%d", kp->pvno); |
---|
249 | break; |
---|
250 | |
---|
251 | case 4: |
---|
252 | printf(" v%d", kp->pvno); |
---|
253 | krb4_print((const u_char *)kp); |
---|
254 | break; |
---|
255 | |
---|
256 | case 106: |
---|
257 | case 107: |
---|
258 | fputs(" v5", stdout); |
---|
259 | /* Decode ASN.1 here "someday" */ |
---|
260 | break; |
---|
261 | } |
---|
262 | return; |
---|
263 | } |
---|