8
#include "k5-platform.h" /* pull in asprintf decl/defn */
9
#include "test_ccapi_util.h"
12
// ---------------------------------------------------------------------------
14
cc_int32 destroy_all_ccaches(cc_context_t context) {
15
cc_int32 err = ccNoError;
16
cc_ccache_t ccache = NULL;
19
err = cc_context_open_default_ccache(context, &ccache);
21
err = cc_ccache_destroy(ccache);
24
if (err == ccErrCCacheNotFound) {
28
log_error("cc_context_open_default_ccache or cc_ccache_destroy failed with %s (%d)", translate_ccapi_error(err), err);
35
// ---------------------------------------------------------------------------
37
cc_int32 new_v5_creds_union (cc_credentials_union *out_union, const char *realm)
39
cc_int32 err = ccNoError;
40
cc_credentials_union *cred_union = NULL;
41
cc_credentials_v5_t *v5creds = NULL;
42
static int num_runs = 1;
46
if (!out_union) { err = ccErrBadParam; }
49
v5creds = malloc (sizeof (*v5creds));
56
asprintf(&client, "client@%s", realm);
57
asprintf(&server, "host/%d%s@%s", num_runs++, realm, realm);
58
if (!client || !server) {
64
v5creds->client = client;
65
v5creds->server = server;
66
v5creds->keyblock.type = 1;
67
v5creds->keyblock.length = 0;
68
v5creds->keyblock.data = NULL;
69
v5creds->authtime = time (NULL);
70
v5creds->starttime = time (NULL);
71
v5creds->endtime = time(NULL) + 1000;
72
v5creds->renew_till = time(NULL) + 10000;
74
v5creds->ticket_flags = TKT_FLG_FORWARDABLE | TKT_FLG_PROXIABLE | TKT_FLG_RENEWABLE | TKT_FLG_INITIAL;
75
v5creds->addresses = NULL;
76
v5creds->ticket.type = 0;
77
v5creds->ticket.length = 0;
78
v5creds->ticket.data = NULL;
79
v5creds->second_ticket.type = 0;
80
v5creds->second_ticket.length = 0;
81
v5creds->second_ticket.data = NULL;
82
v5creds->authdata = NULL;
87
cred_union = malloc (sizeof (*cred_union));
89
cred_union->version = cc_credentials_v5;
90
cred_union->credentials.credentials_v5 = v5creds;
96
*out_union = *cred_union;
104
// ---------------------------------------------------------------------------
106
void release_v5_creds_union(cc_credentials_union *creds_union) {
107
cc_credentials_v5_t *v5creds = NULL;
110
if (creds_union->credentials.credentials_v5) {
111
v5creds = creds_union->credentials.credentials_v5;
112
if (v5creds->client) { free(v5creds->client); }
113
if (v5creds->server) { free(v5creds->server); }
114
if (v5creds->keyblock.data) { free(v5creds->keyblock.data); }
115
if (v5creds->ticket.data) { free(v5creds->ticket.data); }
116
if (v5creds->second_ticket.data) { free(v5creds->second_ticket.data); }
124
// ---------------------------------------------------------------------------
126
// return zero when both unions are considered equal, non-zero when not
128
int compare_v5_creds_unions(const cc_credentials_union *a, const cc_credentials_union *b) {
133
(a->version == cc_credentials_v5) &&
134
(a->version == b->version) &&
135
(strcmp(a->credentials.credentials_v5->client, b->credentials.credentials_v5->client) == 0) &&
136
(strcmp(a->credentials.credentials_v5->server, b->credentials.credentials_v5->server) == 0))