1505d05c7Sgtb #include "k5-int.h"
27c478bd9Sstevel@tonic-gate
3505d05c7Sgtb krb5_error_code KRB5_CALLCONV
krb5_cc_copy_creds(krb5_context context,krb5_ccache incc,krb5_ccache outcc)4505d05c7Sgtb krb5_cc_copy_creds(krb5_context context, krb5_ccache incc, krb5_ccache outcc)
57c478bd9Sstevel@tonic-gate {
67c478bd9Sstevel@tonic-gate krb5_error_code code;
77c478bd9Sstevel@tonic-gate krb5_flags flags;
8505d05c7Sgtb krb5_cc_cursor cur = 0;
97c478bd9Sstevel@tonic-gate krb5_creds creds;
107c478bd9Sstevel@tonic-gate
117c478bd9Sstevel@tonic-gate flags = 0; /* turns off OPENCLOSE mode */
12505d05c7Sgtb if ((code = krb5_cc_set_flags(context, incc, flags)))
137c478bd9Sstevel@tonic-gate return(code);
147c478bd9Sstevel@tonic-gate /* the code for this will open the file for reading only, which
157c478bd9Sstevel@tonic-gate is not what I had in mind. So I won't turn off OPENCLOSE
167c478bd9Sstevel@tonic-gate for the output ccache */
177c478bd9Sstevel@tonic-gate #if 0
187c478bd9Sstevel@tonic-gate if ((code = krb5_cc_set_flags(context, outcc, flags)))
197c478bd9Sstevel@tonic-gate return(code);
207c478bd9Sstevel@tonic-gate #endif
217c478bd9Sstevel@tonic-gate
22505d05c7Sgtb if ((code = krb5_cc_start_seq_get(context, incc, &cur)))
237c478bd9Sstevel@tonic-gate goto cleanup;
247c478bd9Sstevel@tonic-gate
25505d05c7Sgtb while (!(code = krb5_cc_next_cred(context, incc, &cur, &creds))) {
267c478bd9Sstevel@tonic-gate code = krb5_cc_store_cred(context, outcc, &creds);
277c478bd9Sstevel@tonic-gate krb5_free_cred_contents(context, &creds);
287c478bd9Sstevel@tonic-gate if (code)
297c478bd9Sstevel@tonic-gate goto cleanup;
307c478bd9Sstevel@tonic-gate }
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate if (code != KRB5_CC_END)
337c478bd9Sstevel@tonic-gate goto cleanup;
347c478bd9Sstevel@tonic-gate
35505d05c7Sgtb code = krb5_cc_end_seq_get(context, incc, &cur);
36505d05c7Sgtb cur = 0;
37505d05c7Sgtb if (code)
38505d05c7Sgtb goto cleanup;
39505d05c7Sgtb
407c478bd9Sstevel@tonic-gate code = 0;
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate cleanup:
437c478bd9Sstevel@tonic-gate flags = KRB5_TC_OPENCLOSE;
447c478bd9Sstevel@tonic-gate
45505d05c7Sgtb /* If set then we are in an error pathway */
46*1da57d55SToomas Soome if (cur)
47505d05c7Sgtb krb5_cc_end_seq_get(context, incc, &cur);
48505d05c7Sgtb
497c478bd9Sstevel@tonic-gate if (code)
50505d05c7Sgtb krb5_cc_set_flags(context, incc, flags);
517c478bd9Sstevel@tonic-gate else
527c478bd9Sstevel@tonic-gate code = krb5_cc_set_flags(context, incc, flags);
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate #if 0
557c478bd9Sstevel@tonic-gate if (code)
567c478bd9Sstevel@tonic-gate krb5_cc_set_flags(context, outcc, flags);
577c478bd9Sstevel@tonic-gate else
587c478bd9Sstevel@tonic-gate code = krb5_cc_set_flags(context, outcc, flags);
597c478bd9Sstevel@tonic-gate #endif
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate return(code);
627c478bd9Sstevel@tonic-gate }
63