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