2 * Copyright (c) 2004, PADL Software Pty Ltd.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of PADL Software nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include "krb5/gsskrb5_locl.h"
35 RCSID("$Id: set_cred_option.c,v 1.4 2006/10/24 20:14:13 lha Exp $");
37 static gss_OID_desc gss_krb5_import_cred_x_oid_desc =
38 {9, (void *)"\x2b\x06\x01\x04\x01\xa9\x4a\x13\x04"}; /* XXX */
40 gss_OID GSS_KRB5_IMPORT_CRED_X = &gss_krb5_import_cred_x_oid_desc;
43 import_cred(OM_uint32 *minor_status,
44 gss_cred_id_t *cred_handle,
45 const gss_buffer_t value)
49 krb5_principal keytab_principal = NULL;
50 krb5_keytab keytab = NULL;
51 krb5_storage *sp = NULL;
52 krb5_ccache id = NULL;
55 if (cred_handle == NULL || *cred_handle != GSS_C_NO_CREDENTIAL) {
60 sp = krb5_storage_from_mem(value->value, value->length);
66 /* credential cache name */
67 ret = krb5_ret_string(sp, &str);
70 major_stat = GSS_S_FAILURE;
74 ret = krb5_cc_resolve(_gsskrb5_context, str, &id);
77 major_stat = GSS_S_FAILURE;
84 /* keytab principal name */
85 ret = krb5_ret_string(sp, &str);
86 if (ret == 0 && str[0])
87 ret = krb5_parse_name(_gsskrb5_context, str, &keytab_principal);
90 major_stat = GSS_S_FAILURE;
96 /* keytab principal */
97 ret = krb5_ret_string(sp, &str);
100 major_stat = GSS_S_FAILURE;
104 ret = krb5_kt_resolve(_gsskrb5_context, str, &keytab);
107 major_stat = GSS_S_FAILURE;
114 major_stat = _gsskrb5_import_cred(minor_status, id, keytab_principal,
115 keytab, cred_handle);
118 krb5_cc_close(_gsskrb5_context, id);
119 if (keytab_principal)
120 krb5_free_principal(_gsskrb5_context, keytab_principal);
122 krb5_kt_close(_gsskrb5_context, keytab);
126 krb5_storage_free(sp);
133 _gsskrb5_set_cred_option
134 (OM_uint32 *minor_status,
135 gss_cred_id_t *cred_handle,
136 const gss_OID desired_object,
137 const gss_buffer_t value)
141 if (value == GSS_C_NO_BUFFER) {
142 *minor_status = EINVAL;
143 return GSS_S_FAILURE;
146 if (gss_oid_equal(desired_object, GSS_KRB5_IMPORT_CRED_X)) {
147 return import_cred(minor_status, cred_handle, value);
150 *minor_status = EINVAL;
151 return GSS_S_FAILURE;