2 * Copyright (c) 1995, 1996, 1997, 1998 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 RCSID("$Id: decomp_ticket.c,v 1.20 1999/12/02 16:58:41 joda Exp $");
39 * This routine takes a ticket and pointers to the variables that
40 * should be filled in based on the information in the ticket. It
41 * fills in values for its arguments.
43 * The routine returns KFAILURE if any of the "pname", "pinstance",
44 * or "prealm" fields is too big, otherwise it returns KSUCCESS.
46 * The corresponding routine to generate tickets is create_ticket.
47 * When changes are made to this routine, the corresponding changes
48 * should also be made to that file.
50 * See create_ticket.c for the format of the ticket packet.
54 decomp_ticket(KTEXT tkt, /* The ticket to be decoded */
55 unsigned char *flags, /* Kerberos ticket flags */
56 char *pname, /* Authentication name */
57 char *pinstance, /* Principal's instance */
58 char *prealm, /* Principal's authentication domain */
59 u_int32_t *paddress,/* Net address of entity requesting ticket */
60 unsigned char *session, /* Session key inserted in ticket */
61 int *life, /* Lifetime of the ticket */
62 u_int32_t *time_sec, /* Issue time and date */
63 char *sname, /* Service name */
64 char *sinstance, /* Service instance */
65 des_cblock *key, /* Service's secret key (to decrypt the ticket) */
66 des_key_schedule schedule) /* The precomputed key schedule */
69 unsigned char *p = tkt->dat;
73 des_pcbc_encrypt((des_cblock *)tkt->dat, (des_cblock *)tkt->dat,
74 tkt->length, schedule, key, DES_DECRYPT);
80 little_endian = *flags & 1;
82 if(strlen((char*)p) > ANAME_SZ)
84 p += krb_get_string(p, pname, ANAME_SZ);
86 if(strlen((char*)p) > INST_SZ)
88 p += krb_get_string(p, pinstance, INST_SZ);
90 if(strlen((char*)p) > REALM_SZ)
92 p += krb_get_string(p, prealm, REALM_SZ);
95 krb_get_lrealm (prealm, 1);
97 if(tkt->length - (p - tkt->dat) < 8 + 1 + 4)
99 p += krb_get_address(p, paddress);
101 memcpy(session, p, 8);
106 p += krb_get_int(p, time_sec, 4, little_endian);
108 if(strlen((char*)p) > SNAME_SZ)
110 p += krb_get_string(p, sname, SNAME_SZ);
112 if(strlen((char*)p) > INST_SZ)
114 p += krb_get_string(p, sinstance, INST_SZ);