2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1995, 1996
26 * The Regents of the University of California. All rights reserved.
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
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.
44 * Initial contribution from John Hawkinson (jhawk@mit.edu).
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 $";
52 #include <sys/param.h>
54 #include <sys/socket.h>
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>
67 #include "interface.h"
68 #include "addrtoname.h"
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
);
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
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
99 u_char pvno
; /* Protocol Version */
100 u_char type
; /* Type+B */
103 static char tstr
[] = " [|kerberos]";
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" },
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"},
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))
153 c_print(register const u_char
*s
, register const u_char
*ep
)
159 while (ep
== NULL
|| s
< ep
) {
171 c
^= 0x40; /* DEL to ?, others to alpha */
182 krb4_print_hdr(const u_char
*cp
)
186 #define PRINT if ((cp=c_print(cp, snapend))==NULL) goto trunc
204 krb4_print(const u_char
*cp
)
206 register const struct krb
*kp
;
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))
215 kp
= (struct krb
*)cp
;
217 if ((&kp
->type
) >= snapend
) {
222 type
= kp
->type
& (0xFF << 1);
225 IS_LENDIAN(kp
) ? "le" : "be", tok2str(type2str
, NULL
, type
));
229 case AUTH_MSG_KDC_REQUEST
:
230 if ((cp
= krb4_print_hdr(cp
)) == NULL
)
234 printf(" %dmin ", *cp
++ * 5);
241 case AUTH_MSG_APPL_REQUEST
:
244 printf("v%d ", *cp
++);
248 printf(" (%d)", *cp
++);
250 printf(" (%d)", *cp
);
254 case AUTH_MSG_KDC_REPLY
:
255 if ((cp
= krb4_print_hdr(cp
)) == NULL
)
257 cp
+= 10; /* timestamp + n + exp + kvno */
259 len
= KTOHSP(kp
, cp
);
260 printf(" (%d)", len
);
264 case AUTH_MSG_ERR_REPLY
:
265 if ((cp
= krb4_print_hdr(cp
)) == NULL
)
267 cp
+= 4; /* timestamp */
269 printf(" %s ", tok2str(kerr2str
, NULL
, KTOHSP(kp
, cp
)));
276 fputs("(unknown)", stdout
);
286 krb_print(const u_char
*dat
, u_int length
)
288 register const struct krb
*kp
;
290 kp
= (struct krb
*)dat
;
292 if (dat
>= snapend
) {
302 printf(" v%d", kp
->pvno
);
306 printf(" v%d", kp
->pvno
);
307 krb4_print((const u_char
*)kp
);
312 fputs(" v5", stdout
);
313 /* Decode ASN.1 here "someday" */