1 /*
2 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
3 *
4 * Openvision retains the copyright to derivative works of
5 * this source code. Do *NOT* create a derivative of this
6 * source code before consulting with your legal department.
7 * Do *NOT* integrate *ANY* of this source code into another
8 * product before consulting with your legal department.
9 *
10 * For further information, read the top-level Openvision
11 * copyright which is contained in the top-level MIT Kerberos
12 * copyright.
13 *
14 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
15 *
16 */
17
18
19 /*
20 * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
21 *
22 * $Header$
23 */
24
25 #if !defined(lint) && !defined(__CODECENTER__)
26 static char *rcsid = "$Header$";
27 #endif
28 #include "server_internal.h"
29 #include <kadm5/admin.h>
30 #include <stdlib.h>
31
32 kadm5_ret_t
kadm5_free_policy_ent(void * server_handle,kadm5_policy_ent_t val)33 kadm5_free_policy_ent(void *server_handle, kadm5_policy_ent_t val)
34 {
35 kadm5_server_handle_t handle = server_handle;
36
37 _KADM5_CHECK_HANDLE(server_handle);
38
39 if(val) {
40 if (val->policy)
41 free(val->policy);
42 if (handle->api_version == KADM5_API_VERSION_1)
43 free(val);
44 }
45 return KADM5_OK;
46 }
47
48 kadm5_ret_t
kadm5_free_name_list(void * server_handle,char ** names,int count)49 kadm5_free_name_list(void *server_handle, char **names, int count)
50 {
51 _KADM5_CHECK_HANDLE(server_handle);
52
53 while (count--)
54 free(names[count]);
55 free(names);
56 return KADM5_OK;
57 }
58
59 /* XXX this ought to be in libkrb5.a, but isn't */
krb5_free_key_data_contents(context,key)60 kadm5_ret_t krb5_free_key_data_contents(context, key)
61 krb5_context context;
62 krb5_key_data *key;
63 {
64 int i, idx;
65
66 idx = (key->key_data_ver == 1 ? 1 : 2);
67 for (i = 0; i < idx; i++) {
68 if (key->key_data_contents[i]) {
69 memset(key->key_data_contents[i], 0, key->key_data_length[i]);
70 free(key->key_data_contents[i]);
71 }
72 }
73 return KADM5_OK;
74 }
75
kadm5_free_key_data(void * server_handle,krb5_int16 * n_key_data,krb5_key_data * key_data)76 kadm5_ret_t kadm5_free_key_data(void *server_handle,
77 krb5_int16 *n_key_data,
78 krb5_key_data *key_data)
79 {
80 kadm5_server_handle_t handle = server_handle;
81 int i, nkeys = (int) *n_key_data;
82
83 _KADM5_CHECK_HANDLE(server_handle);
84
85 if (key_data == NULL)
86 return KADM5_OK;
87
88 for (i = 0; i < nkeys; i++)
89 krb5_free_key_data_contents(handle->context, &key_data[i]);
90 free(key_data);
91 return KADM5_OK;
92 }
93
94 kadm5_ret_t
kadm5_free_principal_ent(void * server_handle,kadm5_principal_ent_t val)95 kadm5_free_principal_ent(void *server_handle,
96 kadm5_principal_ent_t val)
97 {
98 kadm5_server_handle_t handle = server_handle;
99 int i;
100
101 _KADM5_CHECK_HANDLE(server_handle);
102
103 if(val) {
104 if(val->principal)
105 krb5_free_principal(handle->context, val->principal);
106 if(val->mod_name)
107 krb5_free_principal(handle->context, val->mod_name);
108 if(val->policy)
109 free(val->policy);
110 if (handle->api_version > KADM5_API_VERSION_1) {
111 if (val->n_key_data) {
112 for (i = 0; i < val->n_key_data; i++)
113 krb5_free_key_data_contents(handle->context,
114 &val->key_data[i]);
115 free(val->key_data);
116 }
117 if (val->tl_data) {
118 krb5_tl_data *tl;
119
120 while (val->tl_data) {
121 tl = val->tl_data->tl_data_next;
122 free(val->tl_data->tl_data_contents);
123 free(val->tl_data);
124 val->tl_data = tl;
125 }
126 }
127 }
128
129 if (handle->api_version == KADM5_API_VERSION_1)
130 free(val);
131 }
132 return KADM5_OK;
133 }
134