cc_int32 ccs_credentials_release (ccs_credentials_t io_credentials) { cc_int32 err = ccNoError; if (!err && io_credentials) { cci_credentials_union_release (io_credentials->cred_union); cci_identifier_release (io_credentials->identifier); free (io_credentials); } return cci_check_error (err); }
cc_uint32 cci_credentials_union_read (cc_credentials_union **out_credentials_union, k5_ipc_stream io_stream) { cc_int32 err = ccNoError; cc_credentials_union *credentials_union = NULL; if (!io_stream ) { err = cci_check_error (ccErrBadParam); } if (!out_credentials_union) { err = cci_check_error (ccErrBadParam); } if (!err) { credentials_union = calloc (1, sizeof (*credentials_union)); if (!credentials_union) { err = cci_check_error (ccErrNoMem); } } if (!err) { err = krb5int_ipc_stream_read_uint32 (io_stream, &credentials_union->version); } if (!err) { if (credentials_union->version == cc_credentials_v4) { err = cci_credentials_v4_read (&credentials_union->credentials.credentials_v4, io_stream); } else if (credentials_union->version == cc_credentials_v5) { err = cci_credentials_v5_read (&credentials_union->credentials.credentials_v5, io_stream); } else { err = ccErrBadCredentialsVersion; } } if (!err) { *out_credentials_union = credentials_union; credentials_union = NULL; } if (credentials_union) { cci_credentials_union_release (credentials_union); } return cci_check_error (err); }
cc_uint32 cci_cred_union_to_credentials_union (const cred_union *in_cred_union, cc_credentials_union **out_credentials_union) { cc_int32 err = ccNoError; cc_credentials_union *creds_union = NULL; if (!in_cred_union ) { err = cci_check_error (ccErrBadParam); } if (!out_credentials_union) { err = cci_check_error (ccErrBadParam); } if (!err) { creds_union = calloc (1, sizeof (*creds_union)); if (!creds_union) { err = cci_check_error (ccErrNoMem); } } if (!err) { if (in_cred_union->cred_type == CC_CRED_V4) { cc_credentials_v4_compat *compat_v4creds = in_cred_union->cred.pV4Cred; cc_credentials_v4_t *v4creds = NULL; if (!err) { v4creds = malloc (sizeof (*v4creds)); if (!v4creds) { err = cci_check_error (ccErrNoMem); } } if (!err) { creds_union->version = cc_credentials_v4; creds_union->credentials.credentials_v4 = v4creds; v4creds->version = compat_v4creds->kversion; strncpy (v4creds->principal, compat_v4creds->principal, KRB_NAME_SZ); strncpy (v4creds->principal_instance, compat_v4creds->principal_instance, KRB_INSTANCE_SZ); strncpy (v4creds->service, compat_v4creds->service, KRB_NAME_SZ); strncpy (v4creds->service_instance, compat_v4creds->service_instance, KRB_INSTANCE_SZ); strncpy (v4creds->realm, compat_v4creds->realm, KRB_REALM_SZ); memcpy (v4creds->session_key, compat_v4creds->session_key, 8); v4creds->kvno = compat_v4creds->kvno; v4creds->string_to_key_type = compat_v4creds->str_to_key; v4creds->issue_date = compat_v4creds->issue_date; v4creds->lifetime = compat_v4creds->lifetime; v4creds->address = compat_v4creds->address; v4creds->ticket_size = compat_v4creds->ticket_sz; memcpy (v4creds->ticket, compat_v4creds->ticket, MAX_V4_CRED_LEN); } } else if (in_cred_union->cred_type == CC_CRED_V5) { cc_credentials_v5_compat *compat_v5creds = in_cred_union->cred.pV5Cred; cc_credentials_v5_t *v5creds = NULL; if (!err) { v5creds = malloc (sizeof (*v5creds)); if (v5creds) { *v5creds = cci_credentials_v5_initializer; } else { err = cci_check_error (ccErrNoMem); } } if (!err) { if (!compat_v5creds->client) { err = cci_check_error (ccErrBadParam); } else { v5creds->client = strdup (compat_v5creds->client); if (!v5creds->client) { err = cci_check_error (ccErrNoMem); } } } if (!err) { if (!compat_v5creds->server) { err = cci_check_error (ccErrBadParam); } else { v5creds->server = strdup (compat_v5creds->server); if (!v5creds->server) { err = cci_check_error (ccErrNoMem); } } } if (!err) { err = cci_cc_data_copy_contents (&v5creds->keyblock, &compat_v5creds->keyblock); } if (!err) { err = cci_cc_data_array_copy (&v5creds->addresses, compat_v5creds->addresses); } if (!err) { err = cci_cc_data_copy_contents (&v5creds->ticket, &compat_v5creds->ticket); } if (!err) { err = cci_cc_data_copy_contents (&v5creds->second_ticket, &compat_v5creds->second_ticket); } if (!err) { err = cci_cc_data_array_copy (&v5creds->authdata, compat_v5creds->authdata); } if (!err) { creds_union->version = cc_credentials_v5; creds_union->credentials.credentials_v5 = v5creds; v5creds->authtime = compat_v5creds->authtime; v5creds->starttime = compat_v5creds->starttime; v5creds->endtime = compat_v5creds->endtime; v5creds->renew_till = compat_v5creds->renew_till; v5creds->is_skey = compat_v5creds->is_skey; v5creds->ticket_flags = compat_v5creds->ticket_flags; } } else { err = cci_check_error (ccErrBadCredentialsVersion); } } if (!err) { *out_credentials_union = creds_union; creds_union = NULL; } if (creds_union) { cci_credentials_union_release (creds_union); } return cci_check_error (err); }