Change __signed to signed.
[dragonfly.git] / crypto / kerberosIV / lib / krb / decomp_ticket.c
1 /*
2  * Copyright (c) 1995, 1996, 1997, 1998 Kungliga Tekniska Högskolan
3  * (Royal Institute of Technology, Stockholm, Sweden).
4  * All rights reserved.
5  * 
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 
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.
16  * 
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.
20  * 
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
31  * SUCH DAMAGE.
32  */
33
34 #include "krb_locl.h"
35
36 RCSID("$Id: decomp_ticket.c,v 1.20 1999/12/02 16:58:41 joda Exp $");
37
38 /*
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.
42  *
43  * The routine returns KFAILURE if any of the "pname", "pinstance",
44  * or "prealm" fields is too big, otherwise it returns KSUCCESS.
45  *
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.
49  *
50  * See create_ticket.c for the format of the ticket packet.
51  */
52
53 int
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 */
67
68 {
69     unsigned char *p = tkt->dat;
70     
71     int little_endian;
72
73     des_pcbc_encrypt((des_cblock *)tkt->dat, (des_cblock *)tkt->dat,
74                      tkt->length, schedule, key, DES_DECRYPT);
75
76     tkt->mbz = 0;
77
78     *flags = *p++;
79
80     little_endian = *flags & 1;
81
82     if(strlen((char*)p) > ANAME_SZ)
83         return KFAILURE;
84     p += krb_get_string(p, pname, ANAME_SZ);
85
86     if(strlen((char*)p) > INST_SZ)
87         return KFAILURE;
88     p += krb_get_string(p, pinstance, INST_SZ);
89
90     if(strlen((char*)p) > REALM_SZ)
91         return KFAILURE;
92     p += krb_get_string(p, prealm, REALM_SZ);
93
94     if (*prealm == '\0')
95         krb_get_lrealm (prealm, 1);
96
97     if(tkt->length - (p - tkt->dat) < 8 + 1 + 4)
98         return KFAILURE;
99     p += krb_get_address(p, paddress);
100
101     memcpy(session, p, 8);
102     p += 8;
103
104     *life = *p++;
105     
106     p += krb_get_int(p, time_sec, 4, little_endian);
107
108     if(strlen((char*)p) > SNAME_SZ)
109         return KFAILURE;
110     p += krb_get_string(p, sname, SNAME_SZ);
111
112     if(strlen((char*)p) > INST_SZ)
113         return KFAILURE;
114     p += krb_get_string(p, sinstance, INST_SZ);
115
116     return KSUCCESS;
117 }