xref: /onnv-gate/usr/src/lib/gss_mechs/mech_krb5/krb5/ccache/cccopy.c (revision 781:57319a72b15f)
10Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
20Sstevel@tonic-gate 
3*781Sgtb #include "k5-int.h"
40Sstevel@tonic-gate 
5*781Sgtb krb5_error_code KRB5_CALLCONV
krb5_cc_copy_creds(krb5_context context,krb5_ccache incc,krb5_ccache outcc)6*781Sgtb krb5_cc_copy_creds(krb5_context context, krb5_ccache incc, krb5_ccache outcc)
70Sstevel@tonic-gate {
80Sstevel@tonic-gate     krb5_error_code code;
90Sstevel@tonic-gate     krb5_flags flags;
10*781Sgtb     krb5_cc_cursor cur = 0;
110Sstevel@tonic-gate     krb5_creds creds;
120Sstevel@tonic-gate 
130Sstevel@tonic-gate     flags = 0;				/* turns off OPENCLOSE mode */
14*781Sgtb     if ((code = krb5_cc_set_flags(context, incc, flags)))
150Sstevel@tonic-gate 	return(code);
160Sstevel@tonic-gate     /* the code for this will open the file for reading only, which
170Sstevel@tonic-gate        is not what I had in mind.  So I won't turn off OPENCLOSE
180Sstevel@tonic-gate        for the output ccache */
190Sstevel@tonic-gate #if 0
200Sstevel@tonic-gate     if ((code = krb5_cc_set_flags(context, outcc, flags)))
210Sstevel@tonic-gate 	return(code);
220Sstevel@tonic-gate #endif
230Sstevel@tonic-gate 
24*781Sgtb     if ((code = krb5_cc_start_seq_get(context, incc, &cur)))
250Sstevel@tonic-gate 	goto cleanup;
260Sstevel@tonic-gate 
27*781Sgtb     while (!(code = krb5_cc_next_cred(context, incc, &cur, &creds))) {
280Sstevel@tonic-gate 	code = krb5_cc_store_cred(context, outcc, &creds);
290Sstevel@tonic-gate 	krb5_free_cred_contents(context, &creds);
300Sstevel@tonic-gate 	if (code)
310Sstevel@tonic-gate 	    goto cleanup;
320Sstevel@tonic-gate     }
330Sstevel@tonic-gate 
340Sstevel@tonic-gate     if (code != KRB5_CC_END)
350Sstevel@tonic-gate 	goto cleanup;
360Sstevel@tonic-gate 
37*781Sgtb     code = krb5_cc_end_seq_get(context, incc, &cur);
38*781Sgtb     cur = 0;
39*781Sgtb     if (code)
40*781Sgtb         goto cleanup;
41*781Sgtb 
420Sstevel@tonic-gate     code = 0;
430Sstevel@tonic-gate 
440Sstevel@tonic-gate cleanup:
450Sstevel@tonic-gate     flags = KRB5_TC_OPENCLOSE;
460Sstevel@tonic-gate 
47*781Sgtb     /* If set then we are in an error pathway */
48*781Sgtb     if (cur)
49*781Sgtb       krb5_cc_end_seq_get(context, incc, &cur);
50*781Sgtb 
510Sstevel@tonic-gate     if (code)
52*781Sgtb 	krb5_cc_set_flags(context, incc, flags);
530Sstevel@tonic-gate     else
540Sstevel@tonic-gate 	code = krb5_cc_set_flags(context, incc, flags);
550Sstevel@tonic-gate 
560Sstevel@tonic-gate #if 0
570Sstevel@tonic-gate     if (code)
580Sstevel@tonic-gate 	krb5_cc_set_flags(context, outcc, flags);
590Sstevel@tonic-gate     else
600Sstevel@tonic-gate 	code = krb5_cc_set_flags(context, outcc, flags);
610Sstevel@tonic-gate #endif
620Sstevel@tonic-gate 
630Sstevel@tonic-gate     return(code);
640Sstevel@tonic-gate }
65