xref: /titanic_41/usr/src/lib/gss_mechs/mech_krb5/krb5/ccache/cccopy.c (revision 505d05c73a6e56769f263d4803b22eddd168ee24)
1 #pragma ident	"%Z%%M%	%I%	%E% SMI"
2 
3 #include "k5-int.h"
4 
5 krb5_error_code KRB5_CALLCONV
krb5_cc_copy_creds(krb5_context context,krb5_ccache incc,krb5_ccache outcc)6 krb5_cc_copy_creds(krb5_context context, krb5_ccache incc, krb5_ccache outcc)
7 {
8     krb5_error_code code;
9     krb5_flags flags;
10     krb5_cc_cursor cur = 0;
11     krb5_creds creds;
12 
13     flags = 0;				/* turns off OPENCLOSE mode */
14     if ((code = krb5_cc_set_flags(context, incc, flags)))
15 	return(code);
16     /* the code for this will open the file for reading only, which
17        is not what I had in mind.  So I won't turn off OPENCLOSE
18        for the output ccache */
19 #if 0
20     if ((code = krb5_cc_set_flags(context, outcc, flags)))
21 	return(code);
22 #endif
23 
24     if ((code = krb5_cc_start_seq_get(context, incc, &cur)))
25 	goto cleanup;
26 
27     while (!(code = krb5_cc_next_cred(context, incc, &cur, &creds))) {
28 	code = krb5_cc_store_cred(context, outcc, &creds);
29 	krb5_free_cred_contents(context, &creds);
30 	if (code)
31 	    goto cleanup;
32     }
33 
34     if (code != KRB5_CC_END)
35 	goto cleanup;
36 
37     code = krb5_cc_end_seq_get(context, incc, &cur);
38     cur = 0;
39     if (code)
40         goto cleanup;
41 
42     code = 0;
43 
44 cleanup:
45     flags = KRB5_TC_OPENCLOSE;
46 
47     /* If set then we are in an error pathway */
48     if (cur)
49       krb5_cc_end_seq_get(context, incc, &cur);
50 
51     if (code)
52 	krb5_cc_set_flags(context, incc, flags);
53     else
54 	code = krb5_cc_set_flags(context, incc, flags);
55 
56 #if 0
57     if (code)
58 	krb5_cc_set_flags(context, outcc, flags);
59     else
60 	code = krb5_cc_set_flags(context, outcc, flags);
61 #endif
62 
63     return(code);
64 }
65