Windows global stuff:
[krb5.git] / src / lib / krb5 / krb / in_tkt_ktb.c
1 /*
2  * lib/krb5/krb/in_tkt_ktb.c
3  *
4  * Copyright 1990,1991 by the Massachusetts Institute of Technology.
5  * All Rights Reserved.
6  *
7  * Export of this software from the United States of America may
8  *   require a specific license from the United States Government.
9  *   It is the responsibility of any person or organization contemplating
10  *   export to obtain such a license before exporting.
11  * 
12  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13  * distribute this software and its documentation for any purpose and
14  * without fee is hereby granted, provided that the above copyright
15  * notice appear in all copies and that both that copyright notice and
16  * this permission notice appear in supporting documentation, and that
17  * the name of M.I.T. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  M.I.T. makes no representations about the suitability of
20  * this software for any purpose.  It is provided "as is" without express
21  * or implied warranty.
22  * 
23  *
24  * krb5_get_in_tkt_with_keytab()
25  *      
26  */
27
28 #include "k5-int.h"
29
30 struct keytab_keyproc_arg {
31     krb5_keytab keytab;
32     krb5_principal client;
33 };
34
35 /*
36  * Key-generator for in_tkt_keytab, below.
37  * "keyseed" is actually a krb5_keytab, or NULL if we should fetch
38  * from system area.
39  */
40 krb5_error_code keytab_keyproc
41     PROTOTYPE((krb5_context,
42                const krb5_keytype,
43                krb5_data *,
44                krb5_const_pointer,
45                krb5_keyblock **));
46
47 krb5_error_code
48 keytab_keyproc(context, type, salt, keyseed, key)
49     krb5_context context;
50     const krb5_keytype type;
51     krb5_data * salt;
52     krb5_const_pointer keyseed;
53     krb5_keyblock ** key;
54 {
55     struct keytab_keyproc_arg * arg = (struct keytab_keyproc_arg *)keyseed;
56     krb5_keyblock *realkey;
57     krb5_error_code retval;
58     krb5_keytab kt_id;
59     krb5_keytab_entry kt_ent;
60
61     kt_id = arg->keytab;
62
63     if (!valid_keytype(type))
64         return KRB5_PROG_ETYPE_NOSUPP;
65
66     if (kt_id == NULL)
67         /* Fetch from default keytab location */
68         if (retval = krb5_kt_default(context, &kt_id))
69             return retval;
70
71
72     if (retval = krb5_kt_get_entry(context, kt_id, arg->client,
73                                    0, /* don't have vno available */
74                                    type, &kt_ent))
75             return retval;
76
77     if (retval = krb5_copy_keyblock(context, &kt_ent.key, &realkey)) {
78         (void) krb5_kt_free_entry(context, &kt_ent);
79         return retval;
80     }
81         
82     if (realkey->keytype != type) {
83         (void) krb5_kt_free_entry(context, &kt_ent);
84         krb5_free_keyblock(context, realkey);
85         return KRB5_PROG_ETYPE_NOSUPP;
86     }   
87
88     (void) krb5_kt_free_entry(context, &kt_ent);
89     *key = realkey;
90     return 0;
91 }
92
93 /*
94  Similar to krb5_get_in_tkt_with_skey.
95
96  Attempts to get an initial ticket for creds->client to use server
97  creds->server, (realm is taken from creds->client), with options
98  options, and using creds->times.starttime, creds->times.endtime, 
99  creds->times.renew_till as from, till, and rtime. 
100  creds->times.renew_till is ignored unless the RENEWABLE option is requested.
101
102  If addrs is non-NULL, it is used for the addresses requested.  If it is
103  null, the system standard addresses are used.
104
105  A succesful call will place the ticket in the credentials cache ccache.
106
107  returns system errors, encryption errors
108
109  */
110 krb5_error_code
111 krb5_get_in_tkt_with_keytab(context, options, addrs, etypes, pre_auth_types, 
112                             keytab, ccache, creds, ret_as_reply)
113     krb5_context context;
114     const krb5_flags options;
115     krb5_address * const * addrs;
116     krb5_enctype * etypes;
117     krb5_preauthtype * pre_auth_types;
118     const krb5_keytab keytab;
119     krb5_ccache ccache;
120     krb5_creds * creds;
121     krb5_kdc_rep ** ret_as_reply;
122 {
123     struct keytab_keyproc_arg arg;
124
125     arg.keytab = keytab;
126     arg.client = creds->client;
127
128     return (krb5_get_in_tkt(context, options, addrs, etypes, pre_auth_types, 
129                             keytab_keyproc, (krb5_pointer)&arg,
130                             krb5_kdc_rep_decrypt_proc, 0, creds,
131                             ccache, ret_as_reply));
132 }