xref: /netbsd-src/crypto/external/bsd/heimdal/dist/lib/kadm5/common_glue.c (revision d3273b5b76f5afaafe308cead5511dbb8df8c5e9)
1*d3273b5bSchristos /*	$NetBSD: common_glue.c,v 1.2 2017/01/28 21:31:49 christos Exp $	*/
2ca1c9b0cSelric 
3ca1c9b0cSelric /*
4ca1c9b0cSelric  * Copyright (c) 1997 - 2000 Kungliga Tekniska Högskolan
5ca1c9b0cSelric  * (Royal Institute of Technology, Stockholm, Sweden).
6ca1c9b0cSelric  * All rights reserved.
7ca1c9b0cSelric  *
8ca1c9b0cSelric  * Redistribution and use in source and binary forms, with or without
9ca1c9b0cSelric  * modification, are permitted provided that the following conditions
10ca1c9b0cSelric  * are met:
11ca1c9b0cSelric  *
12ca1c9b0cSelric  * 1. Redistributions of source code must retain the above copyright
13ca1c9b0cSelric  *    notice, this list of conditions and the following disclaimer.
14ca1c9b0cSelric  *
15ca1c9b0cSelric  * 2. Redistributions in binary form must reproduce the above copyright
16ca1c9b0cSelric  *    notice, this list of conditions and the following disclaimer in the
17ca1c9b0cSelric  *    documentation and/or other materials provided with the distribution.
18ca1c9b0cSelric  *
19ca1c9b0cSelric  * 3. Neither the name of the Institute nor the names of its contributors
20ca1c9b0cSelric  *    may be used to endorse or promote products derived from this software
21ca1c9b0cSelric  *    without specific prior written permission.
22ca1c9b0cSelric  *
23ca1c9b0cSelric  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24ca1c9b0cSelric  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25ca1c9b0cSelric  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ca1c9b0cSelric  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27ca1c9b0cSelric  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28ca1c9b0cSelric  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29ca1c9b0cSelric  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30ca1c9b0cSelric  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31ca1c9b0cSelric  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32ca1c9b0cSelric  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33ca1c9b0cSelric  * SUCH DAMAGE.
34ca1c9b0cSelric  */
35ca1c9b0cSelric 
36ca1c9b0cSelric #include "kadm5_locl.h"
37ca1c9b0cSelric 
38*d3273b5bSchristos __RCSID("$NetBSD: common_glue.c,v 1.2 2017/01/28 21:31:49 christos Exp $");
39ca1c9b0cSelric 
40b9d004c6Schristos #define __CALL(F, P) (*((kadm5_common_context*)server_handle)->funcs.F)P
41b9d004c6Schristos #define __CALLABLE(F) (((kadm5_common_context*)server_handle)->funcs.F != 0)
42ca1c9b0cSelric 
43ca1c9b0cSelric kadm5_ret_t
kadm5_chpass_principal(void * server_handle,krb5_principal princ,const char * password)44ca1c9b0cSelric kadm5_chpass_principal(void *server_handle,
45ca1c9b0cSelric 		       krb5_principal princ,
46ca1c9b0cSelric 		       const char *password)
47ca1c9b0cSelric {
48b9d004c6Schristos     return __CALL(chpass_principal, (server_handle, princ, 0,
49b9d004c6Schristos 		  0, NULL, password));
50b9d004c6Schristos }
51b9d004c6Schristos 
52b9d004c6Schristos kadm5_ret_t
kadm5_chpass_principal_3(void * server_handle,krb5_principal princ,krb5_boolean keepold,int n_ks_tuple,krb5_key_salt_tuple * ks_tuple,const char * password)53b9d004c6Schristos kadm5_chpass_principal_3(void *server_handle,
54b9d004c6Schristos 		         krb5_principal princ,
55b9d004c6Schristos 		         krb5_boolean keepold,
56b9d004c6Schristos 		         int n_ks_tuple,
57b9d004c6Schristos 		         krb5_key_salt_tuple *ks_tuple,
58b9d004c6Schristos 		         const char *password)
59b9d004c6Schristos {
60b9d004c6Schristos     return __CALL(chpass_principal, (server_handle, princ, keepold,
61b9d004c6Schristos 		  n_ks_tuple, ks_tuple, password));
62ca1c9b0cSelric }
63ca1c9b0cSelric 
64ca1c9b0cSelric kadm5_ret_t
kadm5_chpass_principal_with_key(void * server_handle,krb5_principal princ,int n_key_data,krb5_key_data * key_data)65ca1c9b0cSelric kadm5_chpass_principal_with_key(void *server_handle,
66ca1c9b0cSelric 				krb5_principal princ,
67ca1c9b0cSelric 				int n_key_data,
68ca1c9b0cSelric 				krb5_key_data *key_data)
69ca1c9b0cSelric {
70ca1c9b0cSelric     return __CALL(chpass_principal_with_key,
71b9d004c6Schristos 		  (server_handle, princ, 0, n_key_data, key_data));
72b9d004c6Schristos }
73b9d004c6Schristos 
74b9d004c6Schristos kadm5_ret_t
kadm5_chpass_principal_with_key_3(void * server_handle,krb5_principal princ,int keepold,int n_key_data,krb5_key_data * key_data)75b9d004c6Schristos kadm5_chpass_principal_with_key_3(void *server_handle,
76b9d004c6Schristos 				  krb5_principal princ,
77b9d004c6Schristos 				  int keepold,
78b9d004c6Schristos 				  int n_key_data,
79b9d004c6Schristos 				  krb5_key_data *key_data)
80b9d004c6Schristos {
81b9d004c6Schristos     return __CALL(chpass_principal_with_key,
82b9d004c6Schristos 		  (server_handle, princ, keepold, n_key_data, key_data));
83b9d004c6Schristos }
84b9d004c6Schristos 
85b9d004c6Schristos kadm5_ret_t
kadm5_create_principal_3(void * server_handle,kadm5_principal_ent_t princ,uint32_t mask,int n_ks_tuple,krb5_key_salt_tuple * ks_tuple,char * password)86b9d004c6Schristos kadm5_create_principal_3(void *server_handle,
87b9d004c6Schristos 			 kadm5_principal_ent_t princ,
88b9d004c6Schristos 			 uint32_t mask,
89b9d004c6Schristos 			 int n_ks_tuple,
90b9d004c6Schristos 			 krb5_key_salt_tuple *ks_tuple,
91b9d004c6Schristos 			 char *password)
92b9d004c6Schristos {
93b9d004c6Schristos     return __CALL(create_principal,
94b9d004c6Schristos 		  (server_handle, princ, mask, n_ks_tuple, ks_tuple, password));
95ca1c9b0cSelric }
96ca1c9b0cSelric 
97ca1c9b0cSelric kadm5_ret_t
kadm5_create_principal(void * server_handle,kadm5_principal_ent_t princ,uint32_t mask,const char * password)98ca1c9b0cSelric kadm5_create_principal(void *server_handle,
99ca1c9b0cSelric 		       kadm5_principal_ent_t princ,
100ca1c9b0cSelric 		       uint32_t mask,
101ca1c9b0cSelric 		       const char *password)
102ca1c9b0cSelric {
103b9d004c6Schristos     return __CALL(create_principal,
104b9d004c6Schristos 		  (server_handle, princ, mask, 0, NULL, password));
105ca1c9b0cSelric }
106ca1c9b0cSelric 
107ca1c9b0cSelric kadm5_ret_t
kadm5_delete_principal(void * server_handle,krb5_principal princ)108ca1c9b0cSelric kadm5_delete_principal(void *server_handle,
109ca1c9b0cSelric 		       krb5_principal princ)
110ca1c9b0cSelric {
111ca1c9b0cSelric     return __CALL(delete_principal, (server_handle, princ));
112ca1c9b0cSelric }
113ca1c9b0cSelric 
114ca1c9b0cSelric kadm5_ret_t
kadm5_destroy(void * server_handle)115ca1c9b0cSelric kadm5_destroy (void *server_handle)
116ca1c9b0cSelric {
117ca1c9b0cSelric     return __CALL(destroy, (server_handle));
118ca1c9b0cSelric }
119ca1c9b0cSelric 
120ca1c9b0cSelric kadm5_ret_t
kadm5_flush(void * server_handle)121ca1c9b0cSelric kadm5_flush (void *server_handle)
122ca1c9b0cSelric {
123ca1c9b0cSelric     return __CALL(flush, (server_handle));
124ca1c9b0cSelric }
125ca1c9b0cSelric 
126ca1c9b0cSelric kadm5_ret_t
kadm5_get_principal(void * server_handle,krb5_principal princ,kadm5_principal_ent_t out,uint32_t mask)127ca1c9b0cSelric kadm5_get_principal(void *server_handle,
128ca1c9b0cSelric 		    krb5_principal princ,
129ca1c9b0cSelric 		    kadm5_principal_ent_t out,
130ca1c9b0cSelric 		    uint32_t mask)
131ca1c9b0cSelric {
132ca1c9b0cSelric     return __CALL(get_principal, (server_handle, princ, out, mask));
133ca1c9b0cSelric }
134ca1c9b0cSelric 
135b9d004c6Schristos /**
136b9d004c6Schristos  * Extract decrypted keys from kadm5_principal_ent_t object.  Mostly a
137b9d004c6Schristos  * no-op for Heimdal because we fetch the entry with decrypted keys.
138b9d004c6Schristos  * Sadly this is not fully a no-op, as we have to allocate a copy.
139b9d004c6Schristos  *
140b9d004c6Schristos  * @server_handle is the kadm5 handle
141b9d004c6Schristos  * @entry is the HDB entry for the principal in question
142b9d004c6Schristos  * @ktype is the enctype to get a key for, or -1 to get the first one
143b9d004c6Schristos  * @stype is the salttype to get a key for, or -1 to get the first match
144b9d004c6Schristos  * @kvno is the kvno to search for, or -1 to get the first match (highest kvno)
145b9d004c6Schristos  * @keyblock is where the key will be placed
146b9d004c6Schristos  * @keysalt, if not NULL, is where the salt will be placed
147b9d004c6Schristos  * @kvnop, if not NULL, is where the selected kvno will be placed
148b9d004c6Schristos  */
149b9d004c6Schristos kadm5_ret_t
kadm5_decrypt_key(void * server_handle,kadm5_principal_ent_t entry,int32_t ktype,int32_t stype,int32_t kvno,krb5_keyblock * keyblock,krb5_keysalt * keysalt,int * kvnop)150b9d004c6Schristos kadm5_decrypt_key(void *server_handle,
151b9d004c6Schristos                   kadm5_principal_ent_t entry,
152b9d004c6Schristos 		  int32_t ktype, int32_t stype,
153b9d004c6Schristos 		  int32_t kvno, krb5_keyblock *keyblock,
154b9d004c6Schristos                   krb5_keysalt *keysalt, int *kvnop)
155b9d004c6Schristos {
156b9d004c6Schristos     size_t i;
157b9d004c6Schristos 
158b9d004c6Schristos     if (kvno < 1 || stype != -1)
159b9d004c6Schristos 	return KADM5_DECRYPT_USAGE_NOSUPP;
160b9d004c6Schristos 
161b9d004c6Schristos     for (i = 0; i < entry->n_key_data; i++) {
162b9d004c6Schristos 	if (ktype != entry->key_data[i].key_data_kvno)
163b9d004c6Schristos 	    continue;
164b9d004c6Schristos 
165b9d004c6Schristos 	keyblock->keytype = ktype;
166b9d004c6Schristos 	keyblock->keyvalue.length = entry->key_data[i].key_data_length[0];
167b9d004c6Schristos 	keyblock->keyvalue.data = malloc(keyblock->keyvalue.length);
168b9d004c6Schristos 	if (keyblock->keyvalue.data == NULL)
169b9d004c6Schristos 	    return ENOMEM;
170b9d004c6Schristos 	memcpy(keyblock->keyvalue.data,
171b9d004c6Schristos 	       entry->key_data[i].key_data_contents[0],
172b9d004c6Schristos 	       keyblock->keyvalue.length);
173b9d004c6Schristos     }
174b9d004c6Schristos 
175b9d004c6Schristos     return 0;
176b9d004c6Schristos }
177b9d004c6Schristos 
178ca1c9b0cSelric kadm5_ret_t
kadm5_modify_principal(void * server_handle,kadm5_principal_ent_t princ,uint32_t mask)179ca1c9b0cSelric kadm5_modify_principal(void *server_handle,
180ca1c9b0cSelric 		       kadm5_principal_ent_t princ,
181ca1c9b0cSelric 		       uint32_t mask)
182ca1c9b0cSelric {
183ca1c9b0cSelric     return __CALL(modify_principal, (server_handle, princ, mask));
184ca1c9b0cSelric }
185ca1c9b0cSelric 
186ca1c9b0cSelric kadm5_ret_t
kadm5_randkey_principal(void * server_handle,krb5_principal princ,krb5_keyblock ** new_keys,int * n_keys)187ca1c9b0cSelric kadm5_randkey_principal(void *server_handle,
188ca1c9b0cSelric 			krb5_principal princ,
189ca1c9b0cSelric 			krb5_keyblock **new_keys,
190ca1c9b0cSelric 			int *n_keys)
191ca1c9b0cSelric {
192b9d004c6Schristos     return __CALL(randkey_principal, (server_handle, princ, FALSE, 0, NULL,
193b9d004c6Schristos 		  new_keys, n_keys));
194b9d004c6Schristos }
195b9d004c6Schristos 
196b9d004c6Schristos kadm5_ret_t
kadm5_randkey_principal_3(void * server_handle,krb5_principal princ,krb5_boolean keepold,int n_ks_tuple,krb5_key_salt_tuple * ks_tuple,krb5_keyblock ** new_keys,int * n_keys)197b9d004c6Schristos kadm5_randkey_principal_3(void *server_handle,
198b9d004c6Schristos 			  krb5_principal princ,
199b9d004c6Schristos 			  krb5_boolean keepold,
200b9d004c6Schristos 			  int n_ks_tuple,
201b9d004c6Schristos 			  krb5_key_salt_tuple *ks_tuple,
202b9d004c6Schristos 			  krb5_keyblock **new_keys,
203b9d004c6Schristos 			  int *n_keys)
204b9d004c6Schristos {
205b9d004c6Schristos     return __CALL(randkey_principal, (server_handle, princ, keepold,
206b9d004c6Schristos 				      n_ks_tuple, ks_tuple, new_keys, n_keys));
207ca1c9b0cSelric }
208ca1c9b0cSelric 
209ca1c9b0cSelric kadm5_ret_t
kadm5_rename_principal(void * server_handle,krb5_principal source,krb5_principal target)210ca1c9b0cSelric kadm5_rename_principal(void *server_handle,
211ca1c9b0cSelric 		       krb5_principal source,
212ca1c9b0cSelric 		       krb5_principal target)
213ca1c9b0cSelric {
214ca1c9b0cSelric     return __CALL(rename_principal, (server_handle, source, target));
215ca1c9b0cSelric }
216ca1c9b0cSelric 
217ca1c9b0cSelric kadm5_ret_t
kadm5_get_principals(void * server_handle,const char * expression,char *** princs,int * count)218ca1c9b0cSelric kadm5_get_principals(void *server_handle,
219ca1c9b0cSelric 		     const char *expression,
220ca1c9b0cSelric 		     char ***princs,
221ca1c9b0cSelric 		     int *count)
222ca1c9b0cSelric {
223ca1c9b0cSelric     return __CALL(get_principals, (server_handle, expression, princs, count));
224ca1c9b0cSelric }
225ca1c9b0cSelric 
226ca1c9b0cSelric kadm5_ret_t
kadm5_get_privs(void * server_handle,uint32_t * privs)227ca1c9b0cSelric kadm5_get_privs(void *server_handle,
228ca1c9b0cSelric 		uint32_t *privs)
229ca1c9b0cSelric {
230ca1c9b0cSelric     return __CALL(get_privs, (server_handle, privs));
231ca1c9b0cSelric }
232b9d004c6Schristos 
233b9d004c6Schristos 
234b9d004c6Schristos /**
235b9d004c6Schristos  * This function is allows the caller to set new keys for a principal.
236b9d004c6Schristos  * This is a trivial wrapper around kadm5_setkey_principal_3().
237b9d004c6Schristos  */
238b9d004c6Schristos kadm5_ret_t
kadm5_setkey_principal(void * server_handle,krb5_principal princ,krb5_keyblock * new_keys,int n_keys)239b9d004c6Schristos kadm5_setkey_principal(void *server_handle,
240b9d004c6Schristos                        krb5_principal princ,
241b9d004c6Schristos                        krb5_keyblock *new_keys,
242b9d004c6Schristos                        int n_keys)
243b9d004c6Schristos {
244b9d004c6Schristos     return kadm5_setkey_principal_3(server_handle, princ, 0, 0, NULL,
245b9d004c6Schristos 				    new_keys, n_keys);
246b9d004c6Schristos }
247b9d004c6Schristos 
248b9d004c6Schristos /**
249b9d004c6Schristos  * This function is allows the caller to set new keys for a principal.
250b9d004c6Schristos  * This is a simple wrapper around kadm5_get_principal() and
251b9d004c6Schristos  * kadm5_modify_principal().
252b9d004c6Schristos  */
253b9d004c6Schristos kadm5_ret_t
kadm5_setkey_principal_3(void * server_handle,krb5_principal princ,krb5_boolean keepold,int n_ks_tuple,krb5_key_salt_tuple * ks_tuple,krb5_keyblock * keyblocks,int n_keys)254b9d004c6Schristos kadm5_setkey_principal_3(void *server_handle,
255b9d004c6Schristos                          krb5_principal princ,
256b9d004c6Schristos                          krb5_boolean keepold,
257b9d004c6Schristos                          int n_ks_tuple, krb5_key_salt_tuple *ks_tuple,
258b9d004c6Schristos                          krb5_keyblock *keyblocks,
259b9d004c6Schristos                          int n_keys)
260b9d004c6Schristos {
261b9d004c6Schristos     kadm5_principal_ent_rec princ_ent;
262b9d004c6Schristos     kadm5_ret_t ret;
263b9d004c6Schristos     krb5_key_data *new_key_data = NULL;
264b9d004c6Schristos     size_t i;
265b9d004c6Schristos 
266b9d004c6Schristos     if (n_keys < 1)
267b9d004c6Schristos 	return EINVAL;
268b9d004c6Schristos     if (n_ks_tuple > 0 && n_ks_tuple != n_keys)
269b9d004c6Schristos 	return KADM5_SETKEY3_ETYPE_MISMATCH;
270b9d004c6Schristos 
271b9d004c6Schristos     /*
272b9d004c6Schristos      * If setkey_principal_3 is defined in the server handle, use that.
273b9d004c6Schristos      */
274b9d004c6Schristos     if (__CALLABLE(setkey_principal_3))
275b9d004c6Schristos 	return __CALL(setkey_principal_3,
276b9d004c6Schristos 		      (server_handle, princ, keepold, n_ks_tuple, ks_tuple,
277b9d004c6Schristos 		       keyblocks, n_keys));
278b9d004c6Schristos 
279b9d004c6Schristos     /*
280b9d004c6Schristos      * Otherwise, simulate it via a get, update, modify sequence.
281b9d004c6Schristos      */
282b9d004c6Schristos     ret = kadm5_get_principal(server_handle, princ, &princ_ent,
283b9d004c6Schristos                               KADM5_KVNO | KADM5_PRINCIPAL | KADM5_KEY_DATA);
284b9d004c6Schristos     if (ret)
285b9d004c6Schristos 	return ret;
286b9d004c6Schristos 
287b9d004c6Schristos     if (keepold) {
288b9d004c6Schristos         new_key_data = calloc((n_keys + princ_ent.n_key_data),
289b9d004c6Schristos                               sizeof(*new_key_data));
290b9d004c6Schristos 	if (new_key_data == NULL) {
291b9d004c6Schristos 	    ret = ENOMEM;
292b9d004c6Schristos 	    goto out;
293b9d004c6Schristos 	}
294b9d004c6Schristos 
295b9d004c6Schristos 	memcpy(&new_key_data[n_keys], &princ_ent.key_data[0],
296b9d004c6Schristos 		princ_ent.n_key_data * sizeof (princ_ent.key_data[0]));
297b9d004c6Schristos     } else {
298b9d004c6Schristos 	new_key_data = calloc(n_keys, sizeof(*new_key_data));
299b9d004c6Schristos 	if (new_key_data == NULL) {
300b9d004c6Schristos 	    ret = ENOMEM;
301b9d004c6Schristos 	    goto out;
302b9d004c6Schristos 	}
303b9d004c6Schristos     }
304b9d004c6Schristos 
305b9d004c6Schristos     princ_ent.kvno++;
306b9d004c6Schristos     for (i = 0; i < n_keys; i++) {
307b9d004c6Schristos 	new_key_data[i].key_data_ver = 2;
308b9d004c6Schristos 
309b9d004c6Schristos 	/* Key */
310b9d004c6Schristos 	new_key_data[i].key_data_kvno = princ_ent.kvno;
311b9d004c6Schristos 	new_key_data[i].key_data_type[0] = keyblocks[i].keytype;
312b9d004c6Schristos 	new_key_data[i].key_data_length[0] = keyblocks[i].keyvalue.length;
313b9d004c6Schristos 	new_key_data[i].key_data_contents[0] =
314b9d004c6Schristos 	    malloc(keyblocks[i].keyvalue.length);
315b9d004c6Schristos 	if (new_key_data[i].key_data_contents[0] == NULL) {
316b9d004c6Schristos 	    ret = ENOMEM;
317b9d004c6Schristos 	    goto out;
318b9d004c6Schristos 	}
319b9d004c6Schristos 	memcpy(new_key_data[i].key_data_contents[0],
320b9d004c6Schristos 	       keyblocks[i].keyvalue.data,
321b9d004c6Schristos 	       keyblocks[i].keyvalue.length);
322b9d004c6Schristos 
323b9d004c6Schristos 	/*
324b9d004c6Schristos 	 * Salt (but there's no salt, just salttype, which is kinda
325b9d004c6Schristos 	 * silly -- what's the point of setkey_3() then, besides
326b9d004c6Schristos 	 * keepold?!)
327b9d004c6Schristos 	 */
328b9d004c6Schristos 	new_key_data[i].key_data_type[1] = 0;
329b9d004c6Schristos 	if (n_ks_tuple > 0) {
330b9d004c6Schristos 	    if (ks_tuple[i].ks_enctype != keyblocks[i].keytype) {
331b9d004c6Schristos 		ret = KADM5_SETKEY3_ETYPE_MISMATCH;
332b9d004c6Schristos                 goto out;
333b9d004c6Schristos             }
334b9d004c6Schristos 	    new_key_data[i].key_data_type[1] = ks_tuple[i].ks_salttype;
335b9d004c6Schristos 	}
336b9d004c6Schristos 	new_key_data[i].key_data_length[1] = 0;
337b9d004c6Schristos 	new_key_data[i].key_data_contents[1] = NULL;
338b9d004c6Schristos     }
339b9d004c6Schristos 
340b9d004c6Schristos     /* Free old keys */
341b9d004c6Schristos     if (!keepold) {
342b9d004c6Schristos 	for (i = 0; i < princ_ent.n_key_data; i++) {
343b9d004c6Schristos 	    free(princ_ent.key_data[i].key_data_contents[0]);
344b9d004c6Schristos 	    free(princ_ent.key_data[i].key_data_contents[1]);
345b9d004c6Schristos 	}
346b9d004c6Schristos     }
347b9d004c6Schristos     free(princ_ent.key_data);
348b9d004c6Schristos     princ_ent.key_data = new_key_data;
349b9d004c6Schristos     princ_ent.n_key_data = n_keys + (keepold ? princ_ent.n_key_data : 0);
350b9d004c6Schristos     new_key_data = NULL;
351b9d004c6Schristos 
352b9d004c6Schristos     /* Modify the principal */
353b9d004c6Schristos     ret = kadm5_modify_principal(server_handle, &princ_ent, KADM5_KVNO | KADM5_KEY_DATA);
354b9d004c6Schristos 
355b9d004c6Schristos out:
356b9d004c6Schristos     if (new_key_data != NULL) {
357b9d004c6Schristos 	for (i = 0; i < n_keys; i++) {
358b9d004c6Schristos 	    free(new_key_data[i].key_data_contents[0]);
359b9d004c6Schristos 	    free(new_key_data[i].key_data_contents[1]);
360b9d004c6Schristos 	}
361b9d004c6Schristos 	free(new_key_data);
362b9d004c6Schristos     }
363b9d004c6Schristos     kadm5_free_principal_ent(server_handle, &princ_ent);
364b9d004c6Schristos     return ret;
365b9d004c6Schristos }
366b9d004c6Schristos 
367b9d004c6Schristos 
368b9d004c6Schristos kadm5_ret_t
kadm5_lock(void * server_handle)369b9d004c6Schristos kadm5_lock(void *server_handle)
370b9d004c6Schristos {
371b9d004c6Schristos     return __CALL(lock, (server_handle));
372b9d004c6Schristos }
373b9d004c6Schristos 
374b9d004c6Schristos kadm5_ret_t
kadm5_unlock(void * server_handle)375b9d004c6Schristos kadm5_unlock(void *server_handle)
376b9d004c6Schristos {
377b9d004c6Schristos     return __CALL(unlock, (server_handle));
378b9d004c6Schristos }
379b9d004c6Schristos 
380b9d004c6Schristos 
381b9d004c6Schristos kadm5_ret_t
kadm5_create_policy(void * server_handle,kadm5_policy_ent_t policy,long mask)382b9d004c6Schristos kadm5_create_policy(void *server_handle,
383b9d004c6Schristos 	                         kadm5_policy_ent_t policy, long mask)
384b9d004c6Schristos {
385b9d004c6Schristos     return KADM5_POLICY_OP_NOSUPP;
386b9d004c6Schristos }
387b9d004c6Schristos 
388b9d004c6Schristos kadm5_ret_t
kadm5_delete_policy(void * server_handle,char * name)389b9d004c6Schristos kadm5_delete_policy(void *server_handle, char *name)
390b9d004c6Schristos {
391b9d004c6Schristos     return KADM5_POLICY_OP_NOSUPP;
392b9d004c6Schristos }
393b9d004c6Schristos 
394b9d004c6Schristos 
395b9d004c6Schristos kadm5_ret_t
kadm5_modify_policy(void * server_handle,kadm5_policy_ent_t policy,uint32_t mask)396b9d004c6Schristos kadm5_modify_policy(void *server_handle, kadm5_policy_ent_t policy,
397b9d004c6Schristos 		    uint32_t mask)
398b9d004c6Schristos {
399b9d004c6Schristos     return KADM5_POLICY_OP_NOSUPP;
400b9d004c6Schristos }
401b9d004c6Schristos 
402b9d004c6Schristos kadm5_ret_t
kadm5_get_policy(void * server_handle,char * policy,kadm5_policy_ent_t ent)403b9d004c6Schristos kadm5_get_policy(void *server_handle, char *policy, kadm5_policy_ent_t ent)
404b9d004c6Schristos {
405b9d004c6Schristos     memset(ent, 0, sizeof (*ent));
406b9d004c6Schristos     return KADM5_POLICY_OP_NOSUPP;
407b9d004c6Schristos }
408b9d004c6Schristos 
409b9d004c6Schristos 
410b9d004c6Schristos kadm5_ret_t
kadm5_get_policies(void * server_handle,char * exp,char *** pols,int * count)411b9d004c6Schristos kadm5_get_policies(void *server_handle, char *exp, char ***pols, int *count)
412b9d004c6Schristos {
413b9d004c6Schristos     *count = 0;
414b9d004c6Schristos     *pols = NULL;
415b9d004c6Schristos 
416b9d004c6Schristos     return KADM5_POLICY_OP_NOSUPP;
417b9d004c6Schristos }
418b9d004c6Schristos 
419b9d004c6Schristos kadm5_ret_t
kadm5_free_policy_ent(kadm5_policy_ent_t ent)420b9d004c6Schristos kadm5_free_policy_ent(kadm5_policy_ent_t ent)
421b9d004c6Schristos {
422b9d004c6Schristos     if (ent->policy)
423b9d004c6Schristos 	free(ent->policy);
424b9d004c6Schristos     /*
425b9d004c6Schristos      * Not clear if we should free ent or not.  It might be an automatic
426b9d004c6Schristos      * struct, so we don't free it for now, just in case.
427b9d004c6Schristos      */
428b9d004c6Schristos     return 0;
429b9d004c6Schristos }
430b9d004c6Schristos 
431