17c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
27c478bd9Sstevel@tonic-gate 
3*505d05c7Sgtb #include "k5-int.h"
47c478bd9Sstevel@tonic-gate 
5*505d05c7Sgtb krb5_error_code KRB5_CALLCONV
krb5_cc_copy_creds(krb5_context context,krb5_ccache incc,krb5_ccache outcc)6*505d05c7Sgtb krb5_cc_copy_creds(krb5_context context, krb5_ccache incc, krb5_ccache outcc)
77c478bd9Sstevel@tonic-gate {
87c478bd9Sstevel@tonic-gate     krb5_error_code code;
97c478bd9Sstevel@tonic-gate     krb5_flags flags;
10*505d05c7Sgtb     krb5_cc_cursor cur = 0;
117c478bd9Sstevel@tonic-gate     krb5_creds creds;
127c478bd9Sstevel@tonic-gate 
137c478bd9Sstevel@tonic-gate     flags = 0;				/* turns off OPENCLOSE mode */
14*505d05c7Sgtb     if ((code = krb5_cc_set_flags(context, incc, flags)))
157c478bd9Sstevel@tonic-gate 	return(code);
167c478bd9Sstevel@tonic-gate     /* the code for this will open the file for reading only, which
177c478bd9Sstevel@tonic-gate        is not what I had in mind.  So I won't turn off OPENCLOSE
187c478bd9Sstevel@tonic-gate        for the output ccache */
197c478bd9Sstevel@tonic-gate #if 0
207c478bd9Sstevel@tonic-gate     if ((code = krb5_cc_set_flags(context, outcc, flags)))
217c478bd9Sstevel@tonic-gate 	return(code);
227c478bd9Sstevel@tonic-gate #endif
237c478bd9Sstevel@tonic-gate 
24*505d05c7Sgtb     if ((code = krb5_cc_start_seq_get(context, incc, &cur)))
257c478bd9Sstevel@tonic-gate 	goto cleanup;
267c478bd9Sstevel@tonic-gate 
27*505d05c7Sgtb     while (!(code = krb5_cc_next_cred(context, incc, &cur, &creds))) {
287c478bd9Sstevel@tonic-gate 	code = krb5_cc_store_cred(context, outcc, &creds);
297c478bd9Sstevel@tonic-gate 	krb5_free_cred_contents(context, &creds);
307c478bd9Sstevel@tonic-gate 	if (code)
317c478bd9Sstevel@tonic-gate 	    goto cleanup;
327c478bd9Sstevel@tonic-gate     }
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate     if (code != KRB5_CC_END)
357c478bd9Sstevel@tonic-gate 	goto cleanup;
367c478bd9Sstevel@tonic-gate 
37*505d05c7Sgtb     code = krb5_cc_end_seq_get(context, incc, &cur);
38*505d05c7Sgtb     cur = 0;
39*505d05c7Sgtb     if (code)
40*505d05c7Sgtb         goto cleanup;
41*505d05c7Sgtb 
427c478bd9Sstevel@tonic-gate     code = 0;
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate cleanup:
457c478bd9Sstevel@tonic-gate     flags = KRB5_TC_OPENCLOSE;
467c478bd9Sstevel@tonic-gate 
47*505d05c7Sgtb     /* If set then we are in an error pathway */
48*505d05c7Sgtb     if (cur)
49*505d05c7Sgtb       krb5_cc_end_seq_get(context, incc, &cur);
50*505d05c7Sgtb 
517c478bd9Sstevel@tonic-gate     if (code)
52*505d05c7Sgtb 	krb5_cc_set_flags(context, incc, flags);
537c478bd9Sstevel@tonic-gate     else
547c478bd9Sstevel@tonic-gate 	code = krb5_cc_set_flags(context, incc, flags);
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #if 0
577c478bd9Sstevel@tonic-gate     if (code)
587c478bd9Sstevel@tonic-gate 	krb5_cc_set_flags(context, outcc, flags);
597c478bd9Sstevel@tonic-gate     else
607c478bd9Sstevel@tonic-gate 	code = krb5_cc_set_flags(context, outcc, flags);
617c478bd9Sstevel@tonic-gate #endif
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate     return(code);
647c478bd9Sstevel@tonic-gate }
65