]>
Commit | Line | Data |
---|---|---|
b7080c8e A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights | |
7 | * Reserved. This file contains Original Code and/or Modifications of | |
8 | * Original Code as defined in and that are subject to the Apple Public | |
9 | * Source License Version 1.0 (the 'License'). You may not use this file | |
10 | * except in compliance with the License. Please obtain a copy of the | |
11 | * License at http://www.apple.com/publicsource and read it before using | |
12 | * this file. | |
13 | * | |
14 | * The Original Code and all software distributed under the License are | |
15 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
19 | * License for the specific language governing rights and limitations | |
20 | * under the License." | |
21 | * | |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
24 | /* | |
25 | * Copyright (c) 1995, 1996 | |
26 | * The Regents of the University of California. All rights reserved. | |
27 | * | |
28 | * Redistribution and use in source and binary forms, with or without | |
29 | * modification, are permitted provided that: (1) source code distributions | |
30 | * retain the above copyright notice and this paragraph in its entirety, (2) | |
31 | * distributions including binary code include the above copyright notice and | |
32 | * this paragraph in its entirety in the documentation or other materials | |
33 | * provided with the distribution, and (3) all advertising materials mentioning | |
34 | * features or use of this software display the following acknowledgement: | |
35 | * ``This product includes software developed by the University of California, | |
36 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of | |
37 | * the University nor the names of its contributors may be used to endorse | |
38 | * or promote products derived from this software without specific prior | |
39 | * written permission. | |
40 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED | |
41 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF | |
42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
43 | * | |
44 | * Initial contribution from John Hawkinson (jhawk@mit.edu). | |
45 | */ | |
46 | ||
47 | #ifndef lint | |
48 | static const char rcsid[] = | |
49 | "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-krb.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $"; | |
50 | #endif | |
51 | ||
52 | #include <sys/param.h> | |
53 | #include <sys/time.h> | |
54 | #include <sys/socket.h> | |
55 | ||
56 | #include <netinet/in.h> | |
57 | #include <netinet/in_systm.h> | |
58 | #include <netinet/ip.h> | |
59 | #include <netinet/ip_var.h> | |
60 | #include <netinet/udp.h> | |
61 | #include <netinet/udp_var.h> | |
62 | ||
63 | #include <ctype.h> | |
64 | #include <errno.h> | |
65 | #include <stdio.h> | |
66 | ||
67 | #include "interface.h" | |
68 | #include "addrtoname.h" | |
69 | ||
70 | const u_char *c_print(register const u_char *, register const u_char *); | |
71 | const u_char *krb4_print_hdr(const u_char *); | |
72 | void krb4_print(const u_char *); | |
73 | void krb_print(const u_char *, u_int); | |
74 | ||
75 | ||
76 | #define AUTH_MSG_KDC_REQUEST 1<<1 | |
77 | #define AUTH_MSG_KDC_REPLY 2<<1 | |
78 | #define AUTH_MSG_APPL_REQUEST 3<<1 | |
79 | #define AUTH_MSG_APPL_REQUEST_MUTUAL 4<<1 | |
80 | #define AUTH_MSG_ERR_REPLY 5<<1 | |
81 | #define AUTH_MSG_PRIVATE 6<<1 | |
82 | #define AUTH_MSG_SAFE 7<<1 | |
83 | #define AUTH_MSG_APPL_ERR 8<<1 | |
84 | #define AUTH_MSG_DIE 63<<1 | |
85 | ||
86 | #define KERB_ERR_OK 0 | |
87 | #define KERB_ERR_NAME_EXP 1 | |
88 | #define KERB_ERR_SERVICE_EXP 2 | |
89 | #define KERB_ERR_AUTH_EXP 3 | |
90 | #define KERB_ERR_PKT_VER 4 | |
91 | #define KERB_ERR_NAME_MAST_KEY_VER 5 | |
92 | #define KERB_ERR_SERV_MAST_KEY_VER 6 | |
93 | #define KERB_ERR_BYTE_ORDER 7 | |
94 | #define KERB_ERR_PRINCIPAL_UNKNOWN 8 | |
95 | #define KERB_ERR_PRINCIPAL_NOT_UNIQUE 9 | |
96 | #define KERB_ERR_NULL_KEY 10 | |
97 | ||
98 | struct krb { | |
99 | u_char pvno; /* Protocol Version */ | |
100 | u_char type; /* Type+B */ | |
101 | }; | |
102 | ||
103 | static char tstr[] = " [|kerberos]"; | |
104 | ||
105 | static struct tok type2str[] = { | |
106 | { AUTH_MSG_KDC_REQUEST, "KDC_REQUEST" }, | |
107 | { AUTH_MSG_KDC_REPLY, "KDC_REPLY" }, | |
108 | { AUTH_MSG_APPL_REQUEST, "APPL_REQUEST" }, | |
109 | { AUTH_MSG_APPL_REQUEST_MUTUAL, "APPL_REQUEST_MUTUAL" }, | |
110 | { AUTH_MSG_ERR_REPLY, "ERR_REPLY" }, | |
111 | { AUTH_MSG_PRIVATE, "PRIVATE" }, | |
112 | { AUTH_MSG_SAFE, "SAFE" }, | |
113 | { AUTH_MSG_APPL_ERR, "APPL_ERR" }, | |
114 | { AUTH_MSG_DIE, "DIE" }, | |
115 | { 0, NULL } | |
116 | }; | |
117 | ||
118 | static struct tok kerr2str[] = { | |
119 | { KERB_ERR_OK, "OK" }, | |
120 | { KERB_ERR_NAME_EXP, "NAME_EXP" }, | |
121 | { KERB_ERR_SERVICE_EXP, "SERVICE_EXP" }, | |
122 | { KERB_ERR_AUTH_EXP, "AUTH_EXP" }, | |
123 | { KERB_ERR_PKT_VER, "PKT_VER" }, | |
124 | { KERB_ERR_NAME_MAST_KEY_VER, "NAME_MAST_KEY_VER" }, | |
125 | { KERB_ERR_SERV_MAST_KEY_VER, "SERV_MAST_KEY_VER" }, | |
126 | { KERB_ERR_BYTE_ORDER, "BYTE_ORDER" }, | |
127 | { KERB_ERR_PRINCIPAL_UNKNOWN, "PRINCIPAL_UNKNOWN" }, | |
128 | { KERB_ERR_PRINCIPAL_NOT_UNIQUE, "PRINCIPAL_NOT_UNIQUE" }, | |
129 | { KERB_ERR_NULL_KEY, "NULL_KEY"}, | |
130 | { 0, NULL} | |
131 | }; | |
132 | ||
133 | ||
134 | /* little endian (unaligned) to host byte order */ | |
135 | /* XXX need to look at this... */ | |
136 | #define vtohlp(x) ((( ((char *)(x))[0] ) ) | \ | |
137 | (( ((char *)(x))[1] ) << 8) | \ | |
138 | (( ((char *)(x))[2] ) << 16) | \ | |
139 | (( ((char *)(x))[3] ) << 24)) | |
140 | #define vtohsp(x) ((( ((char *)(x))[0] ) ) | \ | |
141 | (( ((char *)(x))[1] ) << 8)) | |
142 | /* network (big endian) (unaligned) to host byte order */ | |
143 | #define ntohlp(x) ((( ((char *)(x))[3] ) ) | \ | |
144 | (( ((char *)(x))[2] ) << 8) | \ | |
145 | (( ((char *)(x))[1] ) << 16) | \ | |
146 | (( ((char *)(x))[0] ) << 24)) | |
147 | #define ntohsp(x) ((( ((char *)(x))[1] ) ) | \ | |
148 | (( ((char *)(x))[0] ) << 8)) | |
149 | ||
150 | ||
151 | ||
152 | const u_char * | |
153 | c_print(register const u_char *s, register const u_char *ep) | |
154 | { | |
155 | register u_char c; | |
156 | register int flag; | |
157 | ||
158 | flag = 1; | |
159 | while (ep == NULL || s < ep) { | |
160 | c = *s++; | |
161 | if (c == '\0') { | |
162 | flag = 0; | |
163 | break; | |
164 | } | |
165 | if (!isascii(c)) { | |
166 | c = toascii(c); | |
167 | putchar('M'); | |
168 | putchar('-'); | |
169 | } | |
170 | if (!isprint(c)) { | |
171 | c ^= 0x40; /* DEL to ?, others to alpha */ | |
172 | putchar('^'); | |
173 | } | |
174 | putchar(c); | |
175 | } | |
176 | if (flag) | |
177 | return NULL; | |
178 | return(s); | |
179 | } | |
180 | ||
181 | const u_char * | |
182 | krb4_print_hdr(const u_char *cp) | |
183 | { | |
184 | cp+=2; | |
185 | ||
186 | #define PRINT if ((cp=c_print(cp, snapend))==NULL) goto trunc | |
187 | ||
188 | TCHECK2(cp, 0); | |
189 | PRINT; | |
190 | TCHECK2(cp, 0); | |
191 | putchar('.'); PRINT; | |
192 | TCHECK2(cp, 0); | |
193 | putchar('@'); PRINT; | |
194 | return(cp); | |
195 | ||
196 | trunc: | |
197 | fputs(tstr, stdout); | |
198 | return(NULL); | |
199 | ||
200 | #undef PRINT | |
201 | } | |
202 | ||
203 | void | |
204 | krb4_print(const u_char *cp) | |
205 | { | |
206 | register const struct krb *kp; | |
207 | u_char type; | |
208 | u_short len; | |
209 | ||
210 | #define PRINT if ((cp=c_print(cp, snapend))==NULL) goto trunc | |
211 | /* True if struct krb is little endian */ | |
212 | #define IS_LENDIAN(kp) (((kp)->type & 0x01) != 0) | |
213 | #define KTOHSP(kp, cp) (IS_LENDIAN(kp) ? vtohsp(cp) : ntohsp(cp)) | |
214 | ||
215 | kp = (struct krb *)cp; | |
216 | ||
217 | if ((&kp->type) >= snapend) { | |
218 | fputs(tstr, stdout); | |
219 | return; | |
220 | } | |
221 | ||
222 | type = kp->type & (0xFF << 1); | |
223 | ||
224 | printf(" %s %s: ", | |
225 | IS_LENDIAN(kp) ? "le" : "be", tok2str(type2str, NULL, type)); | |
226 | ||
227 | switch (type) { | |
228 | ||
229 | case AUTH_MSG_KDC_REQUEST: | |
230 | if ((cp = krb4_print_hdr(cp)) == NULL) | |
231 | return; | |
232 | cp += 4; /* ctime */ | |
233 | TCHECK2(cp, 0); | |
234 | printf(" %dmin ", *cp++ * 5); | |
235 | TCHECK2(cp, 0); | |
236 | PRINT; | |
237 | TCHECK2(cp, 0); | |
238 | putchar('.'); PRINT; | |
239 | break; | |
240 | ||
241 | case AUTH_MSG_APPL_REQUEST: | |
242 | cp += 2; | |
243 | TCHECK2(cp, 0); | |
244 | printf("v%d ", *cp++); | |
245 | TCHECK2(cp, 0); | |
246 | PRINT; | |
247 | TCHECK2(cp, 0); | |
248 | printf(" (%d)", *cp++); | |
249 | TCHECK2(cp, 0); | |
250 | printf(" (%d)", *cp); | |
251 | TCHECK2(cp, 0); | |
252 | break; | |
253 | ||
254 | case AUTH_MSG_KDC_REPLY: | |
255 | if ((cp = krb4_print_hdr(cp)) == NULL) | |
256 | return; | |
257 | cp += 10; /* timestamp + n + exp + kvno */ | |
258 | TCHECK2(cp, 0); | |
259 | len = KTOHSP(kp, cp); | |
260 | printf(" (%d)", len); | |
261 | TCHECK2(cp, 0); | |
262 | break; | |
263 | ||
264 | case AUTH_MSG_ERR_REPLY: | |
265 | if ((cp = krb4_print_hdr(cp)) == NULL) | |
266 | return; | |
267 | cp += 4; /* timestamp */ | |
268 | TCHECK2(cp, 0); | |
269 | printf(" %s ", tok2str(kerr2str, NULL, KTOHSP(kp, cp))); | |
270 | cp += 4; | |
271 | TCHECK2(cp, 0); | |
272 | PRINT; | |
273 | break; | |
274 | ||
275 | default: | |
276 | fputs("(unknown)", stdout); | |
277 | break; | |
278 | } | |
279 | ||
280 | return; | |
281 | trunc: | |
282 | fputs(tstr, stdout); | |
283 | } | |
284 | ||
285 | void | |
286 | krb_print(const u_char *dat, u_int length) | |
287 | { | |
288 | register const struct krb *kp; | |
289 | ||
290 | kp = (struct krb *)dat; | |
291 | ||
292 | if (dat >= snapend) { | |
293 | fputs(tstr, stdout); | |
294 | return; | |
295 | } | |
296 | ||
297 | switch (kp->pvno) { | |
298 | ||
299 | case 1: | |
300 | case 2: | |
301 | case 3: | |
302 | printf(" v%d", kp->pvno); | |
303 | break; | |
304 | ||
305 | case 4: | |
306 | printf(" v%d", kp->pvno); | |
307 | krb4_print((const u_char *)kp); | |
308 | break; | |
309 | ||
310 | case 106: | |
311 | case 107: | |
312 | fputs(" v5", stdout); | |
313 | /* Decode ASN.1 here "someday" */ | |
314 | break; | |
315 | } | |
316 | return; | |
317 | } |