1*7f2fe78bSCy Schubert /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2*7f2fe78bSCy Schubert /*
3*7f2fe78bSCy Schubert * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
4*7f2fe78bSCy Schubert */
5*7f2fe78bSCy Schubert
6*7f2fe78bSCy Schubert #include "k5-int.h"
7*7f2fe78bSCy Schubert #include <kadm5/admin.h>
8*7f2fe78bSCy Schubert #include <stdlib.h>
9*7f2fe78bSCy Schubert #include "server_internal.h"
10*7f2fe78bSCy Schubert
11*7f2fe78bSCy Schubert kadm5_ret_t
kadm5_free_policy_ent(void * server_handle,kadm5_policy_ent_t val)12*7f2fe78bSCy Schubert kadm5_free_policy_ent(void *server_handle, kadm5_policy_ent_t val)
13*7f2fe78bSCy Schubert {
14*7f2fe78bSCy Schubert krb5_tl_data *tl_next;
15*7f2fe78bSCy Schubert
16*7f2fe78bSCy Schubert _KADM5_CHECK_HANDLE(server_handle);
17*7f2fe78bSCy Schubert
18*7f2fe78bSCy Schubert if (val == NULL)
19*7f2fe78bSCy Schubert return KADM5_OK;
20*7f2fe78bSCy Schubert
21*7f2fe78bSCy Schubert free(val->policy);
22*7f2fe78bSCy Schubert free(val->allowed_keysalts);
23*7f2fe78bSCy Schubert for (; val->tl_data; val->tl_data = tl_next) {
24*7f2fe78bSCy Schubert tl_next = val->tl_data->tl_data_next;
25*7f2fe78bSCy Schubert free(val->tl_data->tl_data_contents);
26*7f2fe78bSCy Schubert free(val->tl_data);
27*7f2fe78bSCy Schubert }
28*7f2fe78bSCy Schubert memset(val, 0, sizeof(*val));
29*7f2fe78bSCy Schubert return KADM5_OK;
30*7f2fe78bSCy Schubert }
31*7f2fe78bSCy Schubert
32*7f2fe78bSCy Schubert kadm5_ret_t
kadm5_free_name_list(void * server_handle,char ** names,int count)33*7f2fe78bSCy Schubert kadm5_free_name_list(void *server_handle, char **names, int count)
34*7f2fe78bSCy Schubert {
35*7f2fe78bSCy Schubert _KADM5_CHECK_HANDLE(server_handle);
36*7f2fe78bSCy Schubert
37*7f2fe78bSCy Schubert while (count--)
38*7f2fe78bSCy Schubert free(names[count]);
39*7f2fe78bSCy Schubert free(names);
40*7f2fe78bSCy Schubert return KADM5_OK;
41*7f2fe78bSCy Schubert }
42*7f2fe78bSCy Schubert
43*7f2fe78bSCy Schubert /* XXX this ought to be in libkrb5.a, but isn't */
krb5_free_key_data_contents(context,key)44*7f2fe78bSCy Schubert kadm5_ret_t krb5_free_key_data_contents(context, key)
45*7f2fe78bSCy Schubert krb5_context context;
46*7f2fe78bSCy Schubert krb5_key_data *key;
47*7f2fe78bSCy Schubert {
48*7f2fe78bSCy Schubert int i, idx;
49*7f2fe78bSCy Schubert
50*7f2fe78bSCy Schubert idx = (key->key_data_ver == 1 ? 1 : 2);
51*7f2fe78bSCy Schubert for (i = 0; i < idx; i++)
52*7f2fe78bSCy Schubert zapfree(key->key_data_contents[i], key->key_data_length[i]);
53*7f2fe78bSCy Schubert return KADM5_OK;
54*7f2fe78bSCy Schubert }
55*7f2fe78bSCy Schubert
kadm5_free_key_data(void * server_handle,krb5_int16 * n_key_data,krb5_key_data * key_data)56*7f2fe78bSCy Schubert kadm5_ret_t kadm5_free_key_data(void *server_handle,
57*7f2fe78bSCy Schubert krb5_int16 *n_key_data,
58*7f2fe78bSCy Schubert krb5_key_data *key_data)
59*7f2fe78bSCy Schubert {
60*7f2fe78bSCy Schubert kadm5_server_handle_t handle = server_handle;
61*7f2fe78bSCy Schubert int i, nkeys = (int) *n_key_data;
62*7f2fe78bSCy Schubert
63*7f2fe78bSCy Schubert _KADM5_CHECK_HANDLE(server_handle);
64*7f2fe78bSCy Schubert
65*7f2fe78bSCy Schubert if (key_data == NULL)
66*7f2fe78bSCy Schubert return KADM5_OK;
67*7f2fe78bSCy Schubert
68*7f2fe78bSCy Schubert for (i = 0; i < nkeys; i++)
69*7f2fe78bSCy Schubert krb5_free_key_data_contents(handle->context, &key_data[i]);
70*7f2fe78bSCy Schubert free(key_data);
71*7f2fe78bSCy Schubert return KADM5_OK;
72*7f2fe78bSCy Schubert }
73*7f2fe78bSCy Schubert
74*7f2fe78bSCy Schubert kadm5_ret_t
kadm5_free_principal_ent(void * server_handle,kadm5_principal_ent_t val)75*7f2fe78bSCy Schubert kadm5_free_principal_ent(void *server_handle, kadm5_principal_ent_t val)
76*7f2fe78bSCy Schubert {
77*7f2fe78bSCy Schubert kadm5_server_handle_t handle = server_handle;
78*7f2fe78bSCy Schubert krb5_tl_data *tl;
79*7f2fe78bSCy Schubert int i;
80*7f2fe78bSCy Schubert
81*7f2fe78bSCy Schubert _KADM5_CHECK_HANDLE(server_handle);
82*7f2fe78bSCy Schubert
83*7f2fe78bSCy Schubert if (!val)
84*7f2fe78bSCy Schubert return KADM5_OK;
85*7f2fe78bSCy Schubert
86*7f2fe78bSCy Schubert krb5_free_principal(handle->context, val->principal);
87*7f2fe78bSCy Schubert krb5_free_principal(handle->context, val->mod_name);
88*7f2fe78bSCy Schubert free(val->policy);
89*7f2fe78bSCy Schubert if (val->n_key_data) {
90*7f2fe78bSCy Schubert for (i = 0; i < val->n_key_data; i++)
91*7f2fe78bSCy Schubert krb5_free_key_data_contents(handle->context, &val->key_data[i]);
92*7f2fe78bSCy Schubert free(val->key_data);
93*7f2fe78bSCy Schubert }
94*7f2fe78bSCy Schubert
95*7f2fe78bSCy Schubert while (val->tl_data) {
96*7f2fe78bSCy Schubert tl = val->tl_data->tl_data_next;
97*7f2fe78bSCy Schubert free(val->tl_data->tl_data_contents);
98*7f2fe78bSCy Schubert free(val->tl_data);
99*7f2fe78bSCy Schubert val->tl_data = tl;
100*7f2fe78bSCy Schubert }
101*7f2fe78bSCy Schubert return KADM5_OK;
102*7f2fe78bSCy Schubert }
103*7f2fe78bSCy Schubert
104*7f2fe78bSCy Schubert kadm5_ret_t
kadm5_free_strings(void * server_handle,krb5_string_attr * strings,int count)105*7f2fe78bSCy Schubert kadm5_free_strings(void *server_handle, krb5_string_attr *strings,
106*7f2fe78bSCy Schubert int count)
107*7f2fe78bSCy Schubert {
108*7f2fe78bSCy Schubert int i;
109*7f2fe78bSCy Schubert
110*7f2fe78bSCy Schubert _KADM5_CHECK_HANDLE(server_handle);
111*7f2fe78bSCy Schubert
112*7f2fe78bSCy Schubert if (!strings)
113*7f2fe78bSCy Schubert return KADM5_OK;
114*7f2fe78bSCy Schubert
115*7f2fe78bSCy Schubert for (i = 0; i < count; i++) {
116*7f2fe78bSCy Schubert free(strings[i].key);
117*7f2fe78bSCy Schubert free(strings[i].value);
118*7f2fe78bSCy Schubert }
119*7f2fe78bSCy Schubert free(strings);
120*7f2fe78bSCy Schubert return KADM5_OK;
121*7f2fe78bSCy Schubert }
122*7f2fe78bSCy Schubert
123*7f2fe78bSCy Schubert kadm5_ret_t
kadm5_free_kadm5_key_data(krb5_context context,int n_key_data,kadm5_key_data * key_data)124*7f2fe78bSCy Schubert kadm5_free_kadm5_key_data(krb5_context context, int n_key_data,
125*7f2fe78bSCy Schubert kadm5_key_data *key_data)
126*7f2fe78bSCy Schubert {
127*7f2fe78bSCy Schubert int i;
128*7f2fe78bSCy Schubert
129*7f2fe78bSCy Schubert if (key_data == NULL)
130*7f2fe78bSCy Schubert return KADM5_OK;
131*7f2fe78bSCy Schubert
132*7f2fe78bSCy Schubert for (i = 0; i < n_key_data; i++) {
133*7f2fe78bSCy Schubert krb5_free_keyblock_contents(context, &key_data[i].key);
134*7f2fe78bSCy Schubert krb5_free_data_contents(context, &key_data[i].salt.data);
135*7f2fe78bSCy Schubert }
136*7f2fe78bSCy Schubert free(key_data);
137*7f2fe78bSCy Schubert
138*7f2fe78bSCy Schubert return KADM5_OK;
139*7f2fe78bSCy Schubert }
140