static cc_int32 ccache_move(cc_ccache_t io_source_ccache, cc_ccache_t io_destination_ccache) { struct cc_ccache *s = (struct cc_ccache *)io_source_ccache; struct cc_ccache *d = (struct cc_ccache *)io_destination_ccache; krb5_error_code ret; if (s->id == NULL) return ccErrInvalidCCache; if (d == NULL) return ccErrBadParam; if (d->id == NULL) { ret = heim_krb5_cc_new_unique(milcontext, heim_krb5_cc_get_type(milcontext, s->id), NULL, &d->id); if (ret) return ccErrInvalidCCache; } ret = heim_krb5_cc_move(milcontext, s->id, d->id); if (ret) return LOG_FAILURE(ret, "move cache"); s->id = NULL; return ccNoError; }
KLStatus KLAcquireNewInitialTicketsWithPassword(KLPrincipal inPrincipal, KLLoginOptions inLoginOptions, const char *inPassword, char **outCredCacheName) { krb5_context context = mshim_ctx(); krb5_error_code ret; krb5_ccache cache; krb5_creds creds; char *service = NULL; krb5_get_init_creds_opt *opt = NULL; LOG_ENTRY(); if (inLoginOptions) { service = inLoginOptions->service; opt = inLoginOptions->opt; } ret = heim_krb5_get_init_creds_password(context, &creds, inPrincipal, inPassword, NULL, NULL, 0, service, opt); if (ret) return ret; ret = heim_krb5_cc_cache_match(context, inPrincipal, &cache); if (ret) ret = heim_krb5_cc_new_unique(context, NULL, NULL, &cache); if (ret) goto out; ret = heim_krb5_cc_initialize(context, cache, creds.client); if(ret) goto out; ret = heim_krb5_cc_store_cred(context, cache, &creds); if (ret) goto out; if (outCredCacheName) *outCredCacheName = strdup(heim_krb5_cc_get_name(context, cache)); out: if (cache) { if (ret) krb5_cc_destroy((mit_krb5_context)context, (mit_krb5_ccache)cache); else heim_krb5_cc_close(context, cache); } heim_krb5_free_cred_contents(context, &creds); return ret; }
static cc_int32 context_create_new_ccache(cc_context_t in_context, cc_uint32 in_cred_vers, const char *in_principal, cc_ccache_t *out_ccache) { krb5_principal principal; krb5_error_code ret; krb5_ccache id; LOG_ENTRY(); if (in_cred_vers != cc_credentials_v5) return ccErrBadCredentialsVersion; if (out_ccache == NULL || in_principal == NULL) return ccErrBadParam; update_time(&context_change_time); ret = heim_krb5_parse_name(milcontext, in_principal, &principal); if (ret) return LOG_FAILURE(ret, "parse name"); ret = heim_krb5_cc_new_unique(milcontext, NULL, NULL, &id); if (ret) { heim_krb5_free_principal(milcontext, principal); return LOG_FAILURE(ret, "new unique"); } ret = heim_krb5_cc_initialize(milcontext, id, principal); heim_krb5_free_principal(milcontext, principal); if (ret) { mit_krb5_cc_destroy((mit_krb5_context)milcontext, (mit_krb5_ccache)id); return LOG_FAILURE(ret, "cc init"); } *out_ccache = create_ccache(id); return ccNoError; }