1*13132SGlenn.Barry@oracle.com /*
2*13132SGlenn.Barry@oracle.com * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
3*13132SGlenn.Barry@oracle.com */
40Sstevel@tonic-gate
55053Sgtb #include "gssapiP_krb5.h"
60Sstevel@tonic-gate
75053Sgtb OM_uint32 KRB5_CALLCONV
gss_krb5int_copy_ccache(minor_status,cred_handle,out_ccache)85053Sgtb gss_krb5int_copy_ccache(minor_status, cred_handle, out_ccache)
90Sstevel@tonic-gate OM_uint32 *minor_status;
100Sstevel@tonic-gate gss_cred_id_t cred_handle;
110Sstevel@tonic-gate krb5_ccache out_ccache;
120Sstevel@tonic-gate {
135053Sgtb OM_uint32 stat;
140Sstevel@tonic-gate krb5_gss_cred_id_t k5creds;
150Sstevel@tonic-gate krb5_cc_cursor cursor;
160Sstevel@tonic-gate krb5_creds creds;
170Sstevel@tonic-gate krb5_error_code code;
185053Sgtb krb5_context context;
190Sstevel@tonic-gate
200Sstevel@tonic-gate /* validate the cred handle */
215053Sgtb stat = krb5_gss_validate_cred(minor_status, cred_handle);
225053Sgtb if (stat)
235053Sgtb return(stat);
245053Sgtb
250Sstevel@tonic-gate k5creds = (krb5_gss_cred_id_t) cred_handle;
265053Sgtb code = k5_mutex_lock(&k5creds->lock);
275053Sgtb if (code) {
285053Sgtb *minor_status = code;
295053Sgtb return GSS_S_FAILURE;
305053Sgtb }
310Sstevel@tonic-gate if (k5creds->usage == GSS_C_ACCEPT) {
325053Sgtb k5_mutex_unlock(&k5creds->lock);
330Sstevel@tonic-gate *minor_status = (OM_uint32) G_BAD_USAGE;
345053Sgtb return(GSS_S_FAILURE);
350Sstevel@tonic-gate }
360Sstevel@tonic-gate
375053Sgtb code = krb5_gss_init_context(&context);
385053Sgtb if (code) {
395053Sgtb k5_mutex_unlock(&k5creds->lock);
405053Sgtb *minor_status = code;
415053Sgtb return GSS_S_FAILURE;
425053Sgtb }
430Sstevel@tonic-gate
440Sstevel@tonic-gate code = krb5_cc_start_seq_get(context, k5creds->ccache, &cursor);
450Sstevel@tonic-gate if (code) {
465053Sgtb k5_mutex_unlock(&k5creds->lock);
470Sstevel@tonic-gate *minor_status = code;
48*13132SGlenn.Barry@oracle.com save_error_info(*minor_status, context);
495053Sgtb krb5_free_context(context);
505053Sgtb return(GSS_S_FAILURE);
510Sstevel@tonic-gate }
525053Sgtb while (!code && !krb5_cc_next_cred(context, k5creds->ccache, &cursor, &creds))
530Sstevel@tonic-gate code = krb5_cc_store_cred(context, out_ccache, &creds);
540Sstevel@tonic-gate krb5_cc_end_seq_get(context, k5creds->ccache, &cursor);
555053Sgtb k5_mutex_unlock(&k5creds->lock);
565053Sgtb krb5_free_context(context);
570Sstevel@tonic-gate if (code) {
580Sstevel@tonic-gate *minor_status = code;
59*13132SGlenn.Barry@oracle.com save_error_info(*minor_status, context);
605053Sgtb return(GSS_S_FAILURE);
610Sstevel@tonic-gate } else {
620Sstevel@tonic-gate *minor_status = 0;
635053Sgtb return(GSS_S_COMPLETE);
640Sstevel@tonic-gate }
650Sstevel@tonic-gate }
66