change declaration of krb5_decode_kdc_rep for ANSI stuff
[krb5.git] / src / lib / krb5 / krb / decode_kdc.c
1 /*
2  * $Source$
3  * $Author$
4  *
5  * Copyright 1990 by the Massachusetts Institute of Technology.
6  *
7  * For copying and distribution information, please see the file
8  * <krb5/mit-copyright.h>.
9  *
10  * krb5_decode_kdc_rep() function.
11  */
12
13 #if !defined(lint) && !defined(SABER)
14 static char rcsid_decode_kdc_c[] =
15 "$Id$";
16 #endif  /* !lint & !SABER */
17
18 #include <krb5/copyright.h>
19
20 #include <krb5/krb5.h>
21 #include <krb5/krb5_err.h>
22 #include <krb5/isode_err.h>
23 #include <krb5/asn1.h>
24
25 #include <errno.h>
26
27 #include <krb5/ext-proto.h>
28
29 /*
30  Takes a KDC_REP message and decrypts encrypted part using etype and
31  *key, putting result in *rep.
32  dec_rep->client,ticket,session.last_req,server,caddrs
33  are all set to allocated storage which should be freed by the caller
34  when finished with the response.
35
36  If the response isn't a KDC_REP (tgs or as), it returns an error from
37  the decoding routines (usually ISODE_50_LOCAL_ERR_BADDECODE).
38
39  returns errors from encryption routines, system errors
40  */
41
42 krb5_error_code
43 krb5_decode_kdc_rep(DECLARG(krb5_data *, enc_rep),
44                     DECLARG(krb5_keyblock *, key),
45                     DECLARG(krb5_enctype, etype),
46                     DECLARG(krb5_kdc_rep **, dec_rep))
47 OLDDECLARG(krb5_data *, enc_rep)
48 OLDDECLARG(krb5_keyblock *, key)
49 OLDDECLARG(krb5_enctype, etype)
50 OLDDECLARG(krb5_kdc_rep **, dec_rep)
51 {
52     krb5_error_code retval;
53     krb5_kdc_rep *local_dec_rep;
54
55
56     /* XXX maybe caller should specify type expected? */
57     retval = decode_krb5_as_rep(enc_rep, &local_dec_rep);
58     switch (retval) {
59     case ISODE_50_LOCAL_ERR_BADMSGTYPE:
60         retval = decode_krb5_tgs_rep(enc_rep, &local_dec_rep);
61         switch (retval) {
62         case 0:
63             break;
64         default:
65             return(retval);
66         }
67     case 0:
68         break;
69     default:
70         return (retval);
71     }
72
73     if (local_dec_rep->etype != etype) {
74         return KRB5KDC_ERR_ETYPE_NOSUPP; /* XXX */
75     }
76     if (retval = krb5_kdc_rep_decrypt_proc(key, 0, local_dec_rep)) {
77         krb5_free_kdc_rep(local_dec_rep);
78         return(retval);
79     }
80     *dec_rep = local_dec_rep;
81     return 0;
82 }
83