/* * Modifies: * the memory cache * * Effects: * Save away creds in the ccache. * * Errors: * system errors (mutex locking) * ENOMEM */ krb5_error_code KRB5_CALLCONV krb5_mcc_store(krb5_context ctx, krb5_ccache id, krb5_creds *creds) { krb5_error_code err; krb5_mcc_link *new_node; krb5_mcc_data *mptr = (krb5_mcc_data *)id->data; new_node = malloc(sizeof(krb5_mcc_link)); if (new_node == NULL) return ENOMEM; err = krb5_copy_creds(ctx, creds, &new_node->creds); if (err) goto cleanup; err = k5_cc_mutex_lock(ctx, &mptr->lock); if (err) goto cleanup; new_node->next = mptr->link; mptr->link = new_node; update_mcc_change_time(mptr); k5_cc_mutex_unlock(ctx, &mptr->lock); return 0; cleanup: free(new_node); return err; }
/* * Modifies: * id * * Effects: * Creates/refreshes the memory cred cache id. If the cache exists, its * contents are destroyed. * * Errors: * system errors */ krb5_error_code KRB5_CALLCONV krb5_mcc_initialize(krb5_context context, krb5_ccache id, krb5_principal princ) { krb5_os_context os_ctx = &context->os_context; krb5_error_code ret; krb5_mcc_data *d; d = (krb5_mcc_data *)id->data; k5_cc_mutex_lock(context, &d->lock); krb5_mcc_free(context, id); d = (krb5_mcc_data *)id->data; ret = krb5_copy_principal(context, princ, &d->prin); update_mcc_change_time(d); if (os_ctx->os_flags & KRB5_OS_TOFFSET_VALID) { /* Store client time offsets in the cache */ d->time_offset = os_ctx->time_offset; d->usec_offset = os_ctx->usec_offset; } k5_cc_mutex_unlock(context, &d->lock); if (ret == KRB5_OK) krb5_change_cache(); return ret; }
/* Utility routine: Creates the back-end data for a memory cache, and threads it into the global linked list. Call with the global list lock held. */ static krb5_error_code new_mcc_data (const char *name, krb5_mcc_data **dataptr) { krb5_error_code err; krb5_mcc_data *d; krb5_mcc_list_node *n; d = malloc(sizeof(krb5_mcc_data)); if (d == NULL) return KRB5_CC_NOMEM; err = k5_cc_mutex_init(&d->lock); if (err) { free(d); return err; } d->name = strdup(name); if (d->name == NULL) { k5_cc_mutex_destroy(&d->lock); free(d); return KRB5_CC_NOMEM; } d->link = NULL; d->prin = NULL; d->changetime = 0; d->time_offset = 0; d->usec_offset = 0; update_mcc_change_time(d); n = malloc(sizeof(krb5_mcc_list_node)); if (n == NULL) { free(d->name); k5_cc_mutex_destroy(&d->lock); free(d); return KRB5_CC_NOMEM; } n->cache = d; n->next = mcc_head; mcc_head = n; *dataptr = d; return 0; }
/* * Modifies: * id * * Effects: * Creates/refreshes the memory cred cache id. If the cache exists, its * contents are destroyed. * * Errors: * system errors */ krb5_error_code KRB5_CALLCONV krb5_mcc_initialize(krb5_context context, krb5_ccache id, krb5_principal princ) { krb5_error_code ret; krb5_mcc_data *d; d = (krb5_mcc_data *)id->data; ret = k5_cc_mutex_lock(context, &d->lock); if (ret) return ret; krb5_mcc_free(context, id); d = (krb5_mcc_data *)id->data; ret = krb5_copy_principal(context, princ, &d->prin); update_mcc_change_time(d); k5_cc_mutex_unlock(context, &d->lock); if (ret == KRB5_OK) krb5_change_cache(); return ret; }