Fix autoconf 2.70 compatibility
[platform/upstream/krb5.git] / src / lib / krb5 / krb / in_tkt_sky.c
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/krb5/krb/in_tkt_sky.c */
3 /*
4  * Copyright 1990,1991, 2008 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.  Furthermore if you modify this software you must label
20  * your software as modified software and not distribute it in such a
21  * fashion that it might be confused with the original M.I.T. software.
22  * M.I.T. makes no representations about the suitability of
23  * this software for any purpose.  It is provided "as is" without express
24  * or implied warranty.
25  */
26
27 #include "k5-int.h"
28 #include "int-proto.h"
29
30 /* Copy the caller-provided keyblock into the AS keyblock. */
31 static krb5_error_code
32 get_as_key_skey(krb5_context context, krb5_principal client,
33                 krb5_enctype etype, krb5_prompter_fct prompter,
34                 void *prompter_data, krb5_data *salt, krb5_data *params,
35                 krb5_keyblock *as_key, void *gak_data,
36                 k5_response_items *ritems)
37 {
38     const krb5_keyblock *key = gak_data;
39
40     if (!krb5_c_valid_enctype(etype))
41         return(KRB5_PROG_ETYPE_NOSUPP);
42     if (as_key->length)
43         krb5_free_keyblock_contents(context, as_key);
44     return krb5int_c_copy_keyblock_contents(context, key, as_key);
45 }
46
47 /*
48   Similar to krb5_get_in_tkt_with_password.
49
50   Attempts to get an initial ticket for creds->client to use server
51   creds->server, (realm is taken from creds->client), with options
52   options, and using creds->times.starttime, creds->times.endtime,
53   creds->times.renew_till as from, till, and rtime.
54   creds->times.renew_till is ignored unless the RENEWABLE option is requested.
55
56   If addrs is non-NULL, it is used for the addresses requested.  If it is
57   null, the system standard addresses are used.
58
59   If keyblock is NULL, an appropriate key for creds->client is retrieved
60   from the system key store (e.g. /etc/srvtab).  If keyblock is non-NULL,
61   it is used as the decryption key.
62
63   A succesful call will place the ticket in the credentials cache ccache.
64
65   returns system errors, encryption errors
66
67 */
68 krb5_error_code KRB5_CALLCONV
69 krb5_get_in_tkt_with_skey(krb5_context context, krb5_flags options,
70                           krb5_address *const *addrs, krb5_enctype *ktypes,
71                           krb5_preauthtype *pre_auth_types,
72                           const krb5_keyblock *key, krb5_ccache ccache,
73                           krb5_creds *creds, krb5_kdc_rep **ret_as_reply)
74 {
75     krb5_error_code retval;
76     char *server;
77     krb5_principal server_princ, client_princ;
78     int use_master = 0;
79     krb5_get_init_creds_opt *opts = NULL;
80
81     retval = k5_populate_gic_opt(context, &opts, options, addrs, ktypes,
82                                  pre_auth_types, creds);
83     if (retval)
84         return retval;
85
86     retval = krb5_get_init_creds_opt_set_out_ccache(context, opts, ccache);
87     if (retval)
88         goto cleanup;
89
90 #ifndef LEAN_CLIENT
91     if (key == NULL) {
92         retval = krb5_get_init_creds_keytab(context, creds, creds->client,
93                                             NULL /* keytab */,
94                                             creds->times.starttime,
95                                             NULL /* in_tkt_service */,
96                                             opts);
97         goto cleanup;
98     }
99 #endif /* LEAN_CLIENT */
100
101     retval = krb5_unparse_name(context, creds->server, &server);
102     if (retval)
103         goto cleanup;
104     server_princ = creds->server;
105     client_princ = creds->client;
106     retval = k5_get_init_creds(context, creds, creds->client,
107                                krb5_prompter_posix, NULL, 0, server, opts,
108                                get_as_key_skey, (void *)key, &use_master,
109                                ret_as_reply);
110     krb5_free_unparsed_name(context, server);
111     if (retval)
112         goto cleanup;
113     krb5_free_principal( context, creds->server);
114     krb5_free_principal( context, creds->client);
115     creds->client = client_princ;
116     creds->server = server_princ;
117 cleanup:
118     krb5_get_init_creds_opt_free(context, opts);
119     return retval;
120 }