Explicitly request literal mode after .Xr.
[netbsd-mini2440.git] / dist / tcpdump / print-krb.c
blobc19c6e746d16c63fd970087988b65094272d3d05
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 1995, 1996, 1997
5 * The Regents of the University of California. All rights reserved.
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.
23 * Initial contribution from John Hawkinson (jhawk@mit.edu).
26 #include <sys/cdefs.h>
27 #ifndef lint
28 #if 0
29 static const char rcsid[] _U_ =
30 "@(#) Header: /tcpdump/master/tcpdump/print-krb.c,v 1.23 2003/11/16 09:36:26 guy Exp";
31 #else
32 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
33 #endif
34 #endif
36 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
40 #include <tcpdump-stdinc.h>
42 #include <stdio.h>
44 #include "interface.h"
45 #include "addrtoname.h"
46 #include "extract.h"
48 static const u_char *c_print(register const u_char *, register const u_char *);
49 static const u_char *krb4_print_hdr(const u_char *);
50 static void krb4_print(const u_char *);
52 #define AUTH_MSG_KDC_REQUEST 1<<1
53 #define AUTH_MSG_KDC_REPLY 2<<1
54 #define AUTH_MSG_APPL_REQUEST 3<<1
55 #define AUTH_MSG_APPL_REQUEST_MUTUAL 4<<1
56 #define AUTH_MSG_ERR_REPLY 5<<1
57 #define AUTH_MSG_PRIVATE 6<<1
58 #define AUTH_MSG_SAFE 7<<1
59 #define AUTH_MSG_APPL_ERR 8<<1
60 #define AUTH_MSG_DIE 63<<1
62 #define KERB_ERR_OK 0
63 #define KERB_ERR_NAME_EXP 1
64 #define KERB_ERR_SERVICE_EXP 2
65 #define KERB_ERR_AUTH_EXP 3
66 #define KERB_ERR_PKT_VER 4
67 #define KERB_ERR_NAME_MAST_KEY_VER 5
68 #define KERB_ERR_SERV_MAST_KEY_VER 6
69 #define KERB_ERR_BYTE_ORDER 7
70 #define KERB_ERR_PRINCIPAL_UNKNOWN 8
71 #define KERB_ERR_PRINCIPAL_NOT_UNIQUE 9
72 #define KERB_ERR_NULL_KEY 10
74 struct krb {
75 u_int8_t pvno; /* Protocol Version */
76 u_int8_t type; /* Type+B */
79 static char tstr[] = " [|kerberos]";
81 static struct tok type2str[] = {
82 { AUTH_MSG_KDC_REQUEST, "KDC_REQUEST" },
83 { AUTH_MSG_KDC_REPLY, "KDC_REPLY" },
84 { AUTH_MSG_APPL_REQUEST, "APPL_REQUEST" },
85 { AUTH_MSG_APPL_REQUEST_MUTUAL, "APPL_REQUEST_MUTUAL" },
86 { AUTH_MSG_ERR_REPLY, "ERR_REPLY" },
87 { AUTH_MSG_PRIVATE, "PRIVATE" },
88 { AUTH_MSG_SAFE, "SAFE" },
89 { AUTH_MSG_APPL_ERR, "APPL_ERR" },
90 { AUTH_MSG_DIE, "DIE" },
91 { 0, NULL }
94 static struct tok kerr2str[] = {
95 { KERB_ERR_OK, "OK" },
96 { KERB_ERR_NAME_EXP, "NAME_EXP" },
97 { KERB_ERR_SERVICE_EXP, "SERVICE_EXP" },
98 { KERB_ERR_AUTH_EXP, "AUTH_EXP" },
99 { KERB_ERR_PKT_VER, "PKT_VER" },
100 { KERB_ERR_NAME_MAST_KEY_VER, "NAME_MAST_KEY_VER" },
101 { KERB_ERR_SERV_MAST_KEY_VER, "SERV_MAST_KEY_VER" },
102 { KERB_ERR_BYTE_ORDER, "BYTE_ORDER" },
103 { KERB_ERR_PRINCIPAL_UNKNOWN, "PRINCIPAL_UNKNOWN" },
104 { KERB_ERR_PRINCIPAL_NOT_UNIQUE,"PRINCIPAL_NOT_UNIQUE" },
105 { KERB_ERR_NULL_KEY, "NULL_KEY"},
106 { 0, NULL}
109 static const u_char *
110 c_print(register const u_char *s, register const u_char *ep)
112 register u_char c;
113 register int flag;
115 flag = 1;
116 while (s < ep) {
117 c = *s++;
118 if (c == '\0') {
119 flag = 0;
120 break;
122 if (!isascii(c)) {
123 c = toascii(c);
124 putchar('M');
125 putchar('-');
127 if (!isprint(c)) {
128 c ^= 0x40; /* DEL to ?, others to alpha */
129 putchar('^');
131 putchar(c);
133 if (flag)
134 return NULL;
135 return (s);
138 static const u_char *
139 krb4_print_hdr(const u_char *cp)
141 cp += 2;
143 #define PRINT if ((cp = c_print(cp, snapend)) == NULL) goto trunc
145 PRINT;
146 putchar('.');
147 PRINT;
148 putchar('@');
149 PRINT;
150 return (cp);
152 trunc:
153 fputs(tstr, stdout);
154 return (NULL);
156 #undef PRINT
159 static void
160 krb4_print(const u_char *cp)
162 register const struct krb *kp;
163 u_char type;
164 u_short len;
166 #define PRINT if ((cp = c_print(cp, snapend)) == NULL) goto trunc
167 /* True if struct krb is little endian */
168 #define IS_LENDIAN(kp) (((kp)->type & 0x01) != 0)
169 #define KTOHSP(kp, cp) (IS_LENDIAN(kp) ? EXTRACT_LE_16BITS(cp) : EXTRACT_16BITS(cp))
171 kp = (struct krb *)cp;
173 if ((&kp->type) >= snapend) {
174 fputs(tstr, stdout);
175 return;
178 type = kp->type & (0xFF << 1);
180 printf(" %s %s: ",
181 IS_LENDIAN(kp) ? "le" : "be", tok2str(type2str, NULL, type));
183 switch (type) {
185 case AUTH_MSG_KDC_REQUEST:
186 if ((cp = krb4_print_hdr(cp)) == NULL)
187 return;
188 cp += 4; /* ctime */
189 TCHECK(*cp);
190 printf(" %dmin ", *cp++ * 5);
191 PRINT;
192 putchar('.');
193 PRINT;
194 break;
196 case AUTH_MSG_APPL_REQUEST:
197 cp += 2;
198 TCHECK(*cp);
199 printf("v%d ", *cp++);
200 PRINT;
201 TCHECK(*cp);
202 printf(" (%d)", *cp++);
203 TCHECK(*cp);
204 printf(" (%d)", *cp);
205 break;
207 case AUTH_MSG_KDC_REPLY:
208 if ((cp = krb4_print_hdr(cp)) == NULL)
209 return;
210 cp += 10; /* timestamp + n + exp + kvno */
211 TCHECK2(*cp, sizeof(short));
212 len = KTOHSP(kp, cp);
213 printf(" (%d)", len);
214 break;
216 case AUTH_MSG_ERR_REPLY:
217 if ((cp = krb4_print_hdr(cp)) == NULL)
218 return;
219 cp += 4; /* timestamp */
220 TCHECK2(*cp, sizeof(short));
221 printf(" %s ", tok2str(kerr2str, NULL, KTOHSP(kp, cp)));
222 cp += 4;
223 PRINT;
224 break;
226 default:
227 fputs("(unknown)", stdout);
228 break;
231 return;
232 trunc:
233 fputs(tstr, stdout);
236 void
237 krb_print(const u_char *dat)
239 register const struct krb *kp;
241 kp = (struct krb *)dat;
243 if (dat >= snapend) {
244 fputs(tstr, stdout);
245 return;
248 switch (kp->pvno) {
250 case 1:
251 case 2:
252 case 3:
253 printf(" v%d", kp->pvno);
254 break;
256 case 4:
257 printf(" v%d", kp->pvno);
258 krb4_print((const u_char *)kp);
259 break;
261 case 106:
262 case 107:
263 fputs(" v5", stdout);
264 /* Decode ASN.1 here "someday" */
265 break;
267 return;