1 /*
2  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 #include <k5-int.h>
9 
10 KRB5_DLLIMP krb5_error_code KRB5_CALLCONV
11 krb5_cc_copy_creds(context, incc, outcc)
12    krb5_context context;
13    krb5_ccache incc;
14    krb5_ccache outcc;
15 {
16     krb5_error_code code;
17     krb5_flags flags;
18     krb5_cc_cursor cur;
19     krb5_creds creds;
20 
21     flags = 0;				/* turns off OPENCLOSE mode */
22     if ((code = krb5_cc_set_flags(context, incc, flags)) != NULL)
23 	return(code);
24     /* the code for this will open the file for reading only, which
25        is not what I had in mind.  So I won't turn off OPENCLOSE
26        for the output ccache */
27 #if 0
28     if ((code = krb5_cc_set_flags(context, outcc, flags)))
29 	return(code);
30 #endif
31 
32     if ((code = krb5_cc_start_seq_get(context, incc, &cur)) != NULL)
33 	goto cleanup;
34 
35     while ((code = krb5_cc_next_cred(context, incc, &cur, &creds)) == NULL) {
36 	code = krb5_cc_store_cred(context, outcc, &creds);
37 	krb5_free_cred_contents(context, &creds);
38 	if (code)
39 	    goto cleanup;
40     }
41 
42     if (code != KRB5_CC_END)
43 	goto cleanup;
44 
45     code = 0;
46 
47 cleanup:
48     flags = KRB5_TC_OPENCLOSE;
49 
50     if (code)
51 	(void) krb5_cc_set_flags(context, incc, flags);
52     else
53 	code = krb5_cc_set_flags(context, incc, flags);
54 
55 #if 0
56     if (code)
57 	krb5_cc_set_flags(context, outcc, flags);
58     else
59 	code = krb5_cc_set_flags(context, outcc, flags);
60 #endif
61 
62     return(code);
63 }
64