1c19800e8SDoug Rabson /*
2*ae771770SStanislav Sedov * Copyright (c) 2004 - 2005 Kungliga Tekniska Högskolan
3c19800e8SDoug Rabson * (Royal Institute of Technology, Stockholm, Sweden).
4c19800e8SDoug Rabson * All rights reserved.
5c19800e8SDoug Rabson *
6c19800e8SDoug Rabson * Redistribution and use in source and binary forms, with or without
7c19800e8SDoug Rabson * modification, are permitted provided that the following conditions
8c19800e8SDoug Rabson * are met:
9c19800e8SDoug Rabson *
10c19800e8SDoug Rabson * 1. Redistributions of source code must retain the above copyright
11c19800e8SDoug Rabson * notice, this list of conditions and the following disclaimer.
12c19800e8SDoug Rabson *
13c19800e8SDoug Rabson * 2. Redistributions in binary form must reproduce the above copyright
14c19800e8SDoug Rabson * notice, this list of conditions and the following disclaimer in the
15c19800e8SDoug Rabson * documentation and/or other materials provided with the distribution.
16c19800e8SDoug Rabson *
17c19800e8SDoug Rabson * 3. Neither the name of the Institute nor the names of its contributors
18c19800e8SDoug Rabson * may be used to endorse or promote products derived from this software
19c19800e8SDoug Rabson * without specific prior written permission.
20c19800e8SDoug Rabson *
21c19800e8SDoug Rabson * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22c19800e8SDoug Rabson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23c19800e8SDoug Rabson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24c19800e8SDoug Rabson * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25c19800e8SDoug Rabson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26c19800e8SDoug Rabson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27c19800e8SDoug Rabson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28c19800e8SDoug Rabson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29c19800e8SDoug Rabson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30c19800e8SDoug Rabson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31c19800e8SDoug Rabson * SUCH DAMAGE.
32c19800e8SDoug Rabson */
33c19800e8SDoug Rabson
34c19800e8SDoug Rabson #include "hdb_locl.h"
35c19800e8SDoug Rabson #include <der.h>
36c19800e8SDoug Rabson
37c19800e8SDoug Rabson krb5_error_code
hdb_entry_check_mandatory(krb5_context context,const hdb_entry * ent)38c19800e8SDoug Rabson hdb_entry_check_mandatory(krb5_context context, const hdb_entry *ent)
39c19800e8SDoug Rabson {
40*ae771770SStanislav Sedov size_t i;
41c19800e8SDoug Rabson
42c19800e8SDoug Rabson if (ent->extensions == NULL)
43c19800e8SDoug Rabson return 0;
44c19800e8SDoug Rabson
45c19800e8SDoug Rabson /*
46c19800e8SDoug Rabson * check for unknown extensions and if they where tagged mandatory
47c19800e8SDoug Rabson */
48c19800e8SDoug Rabson
49c19800e8SDoug Rabson for (i = 0; i < ent->extensions->len; i++) {
50c19800e8SDoug Rabson if (ent->extensions->val[i].data.element !=
51c19800e8SDoug Rabson choice_HDB_extension_data_asn1_ellipsis)
52c19800e8SDoug Rabson continue;
53c19800e8SDoug Rabson if (ent->extensions->val[i].mandatory) {
54*ae771770SStanislav Sedov krb5_set_error_message(context, HDB_ERR_MANDATORY_OPTION,
55*ae771770SStanislav Sedov "Principal have unknown "
56c19800e8SDoug Rabson "mandatory extension");
57c19800e8SDoug Rabson return HDB_ERR_MANDATORY_OPTION;
58c19800e8SDoug Rabson }
59c19800e8SDoug Rabson }
60c19800e8SDoug Rabson return 0;
61c19800e8SDoug Rabson }
62c19800e8SDoug Rabson
63c19800e8SDoug Rabson HDB_extension *
hdb_find_extension(const hdb_entry * entry,int type)64c19800e8SDoug Rabson hdb_find_extension(const hdb_entry *entry, int type)
65c19800e8SDoug Rabson {
66*ae771770SStanislav Sedov size_t i;
67c19800e8SDoug Rabson
68c19800e8SDoug Rabson if (entry->extensions == NULL)
69c19800e8SDoug Rabson return NULL;
70c19800e8SDoug Rabson
71c19800e8SDoug Rabson for (i = 0; i < entry->extensions->len; i++)
72*ae771770SStanislav Sedov if (entry->extensions->val[i].data.element == (unsigned)type)
73c19800e8SDoug Rabson return &entry->extensions->val[i];
74c19800e8SDoug Rabson return NULL;
75c19800e8SDoug Rabson }
76c19800e8SDoug Rabson
77c19800e8SDoug Rabson /*
78c19800e8SDoug Rabson * Replace the extension `ext' in `entry'. Make a copy of the
79c19800e8SDoug Rabson * extension, so the caller must still free `ext' on both success and
80c19800e8SDoug Rabson * failure. Returns 0 or error code.
81c19800e8SDoug Rabson */
82c19800e8SDoug Rabson
83c19800e8SDoug Rabson krb5_error_code
hdb_replace_extension(krb5_context context,hdb_entry * entry,const HDB_extension * ext)84c19800e8SDoug Rabson hdb_replace_extension(krb5_context context,
85c19800e8SDoug Rabson hdb_entry *entry,
86c19800e8SDoug Rabson const HDB_extension *ext)
87c19800e8SDoug Rabson {
88c19800e8SDoug Rabson HDB_extension *ext2;
89c19800e8SDoug Rabson HDB_extension *es;
90c19800e8SDoug Rabson int ret;
91c19800e8SDoug Rabson
92c19800e8SDoug Rabson ext2 = NULL;
93c19800e8SDoug Rabson
94c19800e8SDoug Rabson if (entry->extensions == NULL) {
95c19800e8SDoug Rabson entry->extensions = calloc(1, sizeof(*entry->extensions));
96c19800e8SDoug Rabson if (entry->extensions == NULL) {
97*ae771770SStanislav Sedov krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
98c19800e8SDoug Rabson return ENOMEM;
99c19800e8SDoug Rabson }
100c19800e8SDoug Rabson } else if (ext->data.element != choice_HDB_extension_data_asn1_ellipsis) {
101c19800e8SDoug Rabson ext2 = hdb_find_extension(entry, ext->data.element);
102c19800e8SDoug Rabson } else {
103c19800e8SDoug Rabson /*
104c19800e8SDoug Rabson * This is an unknown extention, and we are asked to replace a
105c19800e8SDoug Rabson * possible entry in `entry' that is of the same type. This
106c19800e8SDoug Rabson * might seem impossible, but ASN.1 CHOICE comes to our
107c19800e8SDoug Rabson * rescue. The first tag in each branch in the CHOICE is
108c19800e8SDoug Rabson * unique, so just find the element in the list that have the
109c19800e8SDoug Rabson * same tag was we are putting into the list.
110c19800e8SDoug Rabson */
111c19800e8SDoug Rabson Der_class replace_class, list_class;
112c19800e8SDoug Rabson Der_type replace_type, list_type;
113c19800e8SDoug Rabson unsigned int replace_tag, list_tag;
114c19800e8SDoug Rabson size_t size;
115*ae771770SStanislav Sedov size_t i;
116c19800e8SDoug Rabson
117c19800e8SDoug Rabson ret = der_get_tag(ext->data.u.asn1_ellipsis.data,
118c19800e8SDoug Rabson ext->data.u.asn1_ellipsis.length,
119c19800e8SDoug Rabson &replace_class, &replace_type, &replace_tag,
120c19800e8SDoug Rabson &size);
121c19800e8SDoug Rabson if (ret) {
122*ae771770SStanislav Sedov krb5_set_error_message(context, ret, "hdb: failed to decode "
123c19800e8SDoug Rabson "replacement hdb extention");
124c19800e8SDoug Rabson return ret;
125c19800e8SDoug Rabson }
126c19800e8SDoug Rabson
127c19800e8SDoug Rabson for (i = 0; i < entry->extensions->len; i++) {
128c19800e8SDoug Rabson HDB_extension *ext3 = &entry->extensions->val[i];
129c19800e8SDoug Rabson
130c19800e8SDoug Rabson if (ext3->data.element != choice_HDB_extension_data_asn1_ellipsis)
131c19800e8SDoug Rabson continue;
132c19800e8SDoug Rabson
133c19800e8SDoug Rabson ret = der_get_tag(ext3->data.u.asn1_ellipsis.data,
134c19800e8SDoug Rabson ext3->data.u.asn1_ellipsis.length,
135c19800e8SDoug Rabson &list_class, &list_type, &list_tag,
136c19800e8SDoug Rabson &size);
137c19800e8SDoug Rabson if (ret) {
138*ae771770SStanislav Sedov krb5_set_error_message(context, ret, "hdb: failed to decode "
139c19800e8SDoug Rabson "present hdb extention");
140c19800e8SDoug Rabson return ret;
141c19800e8SDoug Rabson }
142c19800e8SDoug Rabson
143c19800e8SDoug Rabson if (MAKE_TAG(replace_class,replace_type,replace_type) ==
144c19800e8SDoug Rabson MAKE_TAG(list_class,list_type,list_type)) {
145c19800e8SDoug Rabson ext2 = ext3;
146c19800e8SDoug Rabson break;
147c19800e8SDoug Rabson }
148c19800e8SDoug Rabson }
149c19800e8SDoug Rabson }
150c19800e8SDoug Rabson
151c19800e8SDoug Rabson if (ext2) {
152c19800e8SDoug Rabson free_HDB_extension(ext2);
153c19800e8SDoug Rabson ret = copy_HDB_extension(ext, ext2);
154c19800e8SDoug Rabson if (ret)
155*ae771770SStanislav Sedov krb5_set_error_message(context, ret, "hdb: failed to copy replacement "
156c19800e8SDoug Rabson "hdb extention");
157c19800e8SDoug Rabson return ret;
158c19800e8SDoug Rabson }
159c19800e8SDoug Rabson
160c19800e8SDoug Rabson es = realloc(entry->extensions->val,
161c19800e8SDoug Rabson (entry->extensions->len+1)*sizeof(entry->extensions->val[0]));
162c19800e8SDoug Rabson if (es == NULL) {
163*ae771770SStanislav Sedov krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
164c19800e8SDoug Rabson return ENOMEM;
165c19800e8SDoug Rabson }
166c19800e8SDoug Rabson entry->extensions->val = es;
167c19800e8SDoug Rabson
168c19800e8SDoug Rabson ret = copy_HDB_extension(ext,
169c19800e8SDoug Rabson &entry->extensions->val[entry->extensions->len]);
170c19800e8SDoug Rabson if (ret == 0)
171c19800e8SDoug Rabson entry->extensions->len++;
172c19800e8SDoug Rabson else
173*ae771770SStanislav Sedov krb5_set_error_message(context, ret, "hdb: failed to copy new extension");
174c19800e8SDoug Rabson
175c19800e8SDoug Rabson return ret;
176c19800e8SDoug Rabson }
177c19800e8SDoug Rabson
178c19800e8SDoug Rabson krb5_error_code
hdb_clear_extension(krb5_context context,hdb_entry * entry,int type)179c19800e8SDoug Rabson hdb_clear_extension(krb5_context context,
180c19800e8SDoug Rabson hdb_entry *entry,
181c19800e8SDoug Rabson int type)
182c19800e8SDoug Rabson {
183*ae771770SStanislav Sedov size_t i;
184c19800e8SDoug Rabson
185c19800e8SDoug Rabson if (entry->extensions == NULL)
186c19800e8SDoug Rabson return 0;
187c19800e8SDoug Rabson
188c19800e8SDoug Rabson for (i = 0; i < entry->extensions->len; i++) {
189*ae771770SStanislav Sedov if (entry->extensions->val[i].data.element == (unsigned)type) {
190c19800e8SDoug Rabson free_HDB_extension(&entry->extensions->val[i]);
191c19800e8SDoug Rabson memmove(&entry->extensions->val[i],
192c19800e8SDoug Rabson &entry->extensions->val[i + 1],
193c19800e8SDoug Rabson sizeof(entry->extensions->val[i]) * (entry->extensions->len - i - 1));
194c19800e8SDoug Rabson entry->extensions->len--;
195c19800e8SDoug Rabson }
196c19800e8SDoug Rabson }
197c19800e8SDoug Rabson if (entry->extensions->len == 0) {
198c19800e8SDoug Rabson free(entry->extensions->val);
199c19800e8SDoug Rabson free(entry->extensions);
200c19800e8SDoug Rabson entry->extensions = NULL;
201c19800e8SDoug Rabson }
202c19800e8SDoug Rabson
203c19800e8SDoug Rabson return 0;
204c19800e8SDoug Rabson }
205c19800e8SDoug Rabson
206c19800e8SDoug Rabson
207c19800e8SDoug Rabson krb5_error_code
hdb_entry_get_pkinit_acl(const hdb_entry * entry,const HDB_Ext_PKINIT_acl ** a)208c19800e8SDoug Rabson hdb_entry_get_pkinit_acl(const hdb_entry *entry, const HDB_Ext_PKINIT_acl **a)
209c19800e8SDoug Rabson {
210c19800e8SDoug Rabson const HDB_extension *ext;
211c19800e8SDoug Rabson
212c19800e8SDoug Rabson ext = hdb_find_extension(entry, choice_HDB_extension_data_pkinit_acl);
213c19800e8SDoug Rabson if (ext)
214c19800e8SDoug Rabson *a = &ext->data.u.pkinit_acl;
215c19800e8SDoug Rabson else
216c19800e8SDoug Rabson *a = NULL;
217c19800e8SDoug Rabson
218c19800e8SDoug Rabson return 0;
219c19800e8SDoug Rabson }
220c19800e8SDoug Rabson
221c19800e8SDoug Rabson krb5_error_code
hdb_entry_get_pkinit_hash(const hdb_entry * entry,const HDB_Ext_PKINIT_hash ** a)222c19800e8SDoug Rabson hdb_entry_get_pkinit_hash(const hdb_entry *entry, const HDB_Ext_PKINIT_hash **a)
223c19800e8SDoug Rabson {
224c19800e8SDoug Rabson const HDB_extension *ext;
225c19800e8SDoug Rabson
226c19800e8SDoug Rabson ext = hdb_find_extension(entry, choice_HDB_extension_data_pkinit_cert_hash);
227c19800e8SDoug Rabson if (ext)
228c19800e8SDoug Rabson *a = &ext->data.u.pkinit_cert_hash;
229c19800e8SDoug Rabson else
230c19800e8SDoug Rabson *a = NULL;
231c19800e8SDoug Rabson
232c19800e8SDoug Rabson return 0;
233c19800e8SDoug Rabson }
234c19800e8SDoug Rabson
235c19800e8SDoug Rabson krb5_error_code
hdb_entry_get_pkinit_cert(const hdb_entry * entry,const HDB_Ext_PKINIT_cert ** a)236*ae771770SStanislav Sedov hdb_entry_get_pkinit_cert(const hdb_entry *entry, const HDB_Ext_PKINIT_cert **a)
237*ae771770SStanislav Sedov {
238*ae771770SStanislav Sedov const HDB_extension *ext;
239*ae771770SStanislav Sedov
240*ae771770SStanislav Sedov ext = hdb_find_extension(entry, choice_HDB_extension_data_pkinit_cert);
241*ae771770SStanislav Sedov if (ext)
242*ae771770SStanislav Sedov *a = &ext->data.u.pkinit_cert;
243*ae771770SStanislav Sedov else
244*ae771770SStanislav Sedov *a = NULL;
245*ae771770SStanislav Sedov
246*ae771770SStanislav Sedov return 0;
247*ae771770SStanislav Sedov }
248*ae771770SStanislav Sedov
249*ae771770SStanislav Sedov krb5_error_code
hdb_entry_get_pw_change_time(const hdb_entry * entry,time_t * t)250c19800e8SDoug Rabson hdb_entry_get_pw_change_time(const hdb_entry *entry, time_t *t)
251c19800e8SDoug Rabson {
252c19800e8SDoug Rabson const HDB_extension *ext;
253c19800e8SDoug Rabson
254c19800e8SDoug Rabson ext = hdb_find_extension(entry, choice_HDB_extension_data_last_pw_change);
255c19800e8SDoug Rabson if (ext)
256c19800e8SDoug Rabson *t = ext->data.u.last_pw_change;
257c19800e8SDoug Rabson else
258c19800e8SDoug Rabson *t = 0;
259c19800e8SDoug Rabson
260c19800e8SDoug Rabson return 0;
261c19800e8SDoug Rabson }
262c19800e8SDoug Rabson
263c19800e8SDoug Rabson krb5_error_code
hdb_entry_set_pw_change_time(krb5_context context,hdb_entry * entry,time_t t)264c19800e8SDoug Rabson hdb_entry_set_pw_change_time(krb5_context context,
265c19800e8SDoug Rabson hdb_entry *entry,
266c19800e8SDoug Rabson time_t t)
267c19800e8SDoug Rabson {
268c19800e8SDoug Rabson HDB_extension ext;
269c19800e8SDoug Rabson
270c19800e8SDoug Rabson ext.mandatory = FALSE;
271c19800e8SDoug Rabson ext.data.element = choice_HDB_extension_data_last_pw_change;
272c19800e8SDoug Rabson if (t == 0)
273c19800e8SDoug Rabson t = time(NULL);
274c19800e8SDoug Rabson ext.data.u.last_pw_change = t;
275c19800e8SDoug Rabson
276c19800e8SDoug Rabson return hdb_replace_extension(context, entry, &ext);
277c19800e8SDoug Rabson }
278c19800e8SDoug Rabson
279c19800e8SDoug Rabson int
hdb_entry_get_password(krb5_context context,HDB * db,const hdb_entry * entry,char ** p)280c19800e8SDoug Rabson hdb_entry_get_password(krb5_context context, HDB *db,
281c19800e8SDoug Rabson const hdb_entry *entry, char **p)
282c19800e8SDoug Rabson {
283c19800e8SDoug Rabson HDB_extension *ext;
284c19800e8SDoug Rabson char *str;
285c19800e8SDoug Rabson int ret;
286c19800e8SDoug Rabson
287c19800e8SDoug Rabson ext = hdb_find_extension(entry, choice_HDB_extension_data_password);
288c19800e8SDoug Rabson if (ext) {
289*ae771770SStanislav Sedov heim_utf8_string xstr;
290c19800e8SDoug Rabson heim_octet_string pw;
291c19800e8SDoug Rabson
292c19800e8SDoug Rabson if (db->hdb_master_key_set && ext->data.u.password.mkvno) {
293c19800e8SDoug Rabson hdb_master_key key;
294c19800e8SDoug Rabson
295c19800e8SDoug Rabson key = _hdb_find_master_key(ext->data.u.password.mkvno,
296c19800e8SDoug Rabson db->hdb_master_key);
297c19800e8SDoug Rabson
298c19800e8SDoug Rabson if (key == NULL) {
299*ae771770SStanislav Sedov krb5_set_error_message(context, HDB_ERR_NO_MKEY,
300*ae771770SStanislav Sedov "master key %d missing",
301c19800e8SDoug Rabson *ext->data.u.password.mkvno);
302c19800e8SDoug Rabson return HDB_ERR_NO_MKEY;
303c19800e8SDoug Rabson }
304c19800e8SDoug Rabson
305c19800e8SDoug Rabson ret = _hdb_mkey_decrypt(context, key, HDB_KU_MKEY,
306c19800e8SDoug Rabson ext->data.u.password.password.data,
307c19800e8SDoug Rabson ext->data.u.password.password.length,
308c19800e8SDoug Rabson &pw);
309c19800e8SDoug Rabson } else {
310c19800e8SDoug Rabson ret = der_copy_octet_string(&ext->data.u.password.password, &pw);
311c19800e8SDoug Rabson }
312c19800e8SDoug Rabson if (ret) {
313*ae771770SStanislav Sedov krb5_clear_error_message(context);
314c19800e8SDoug Rabson return ret;
315c19800e8SDoug Rabson }
316c19800e8SDoug Rabson
317*ae771770SStanislav Sedov xstr = pw.data;
318*ae771770SStanislav Sedov if (xstr[pw.length - 1] != '\0') {
319*ae771770SStanislav Sedov krb5_set_error_message(context, EINVAL, "malformed password");
320c19800e8SDoug Rabson return EINVAL;
321c19800e8SDoug Rabson }
322c19800e8SDoug Rabson
323*ae771770SStanislav Sedov *p = strdup(xstr);
324c19800e8SDoug Rabson
325c19800e8SDoug Rabson der_free_octet_string(&pw);
326c19800e8SDoug Rabson if (*p == NULL) {
327*ae771770SStanislav Sedov krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
328c19800e8SDoug Rabson return ENOMEM;
329c19800e8SDoug Rabson }
330c19800e8SDoug Rabson return 0;
331c19800e8SDoug Rabson }
332c19800e8SDoug Rabson
333c19800e8SDoug Rabson ret = krb5_unparse_name(context, entry->principal, &str);
334c19800e8SDoug Rabson if (ret == 0) {
335*ae771770SStanislav Sedov krb5_set_error_message(context, ENOENT,
336*ae771770SStanislav Sedov "no password attribute for %s", str);
337c19800e8SDoug Rabson free(str);
338c19800e8SDoug Rabson } else
339*ae771770SStanislav Sedov krb5_clear_error_message(context);
340c19800e8SDoug Rabson
341c19800e8SDoug Rabson return ENOENT;
342c19800e8SDoug Rabson }
343c19800e8SDoug Rabson
344c19800e8SDoug Rabson int
hdb_entry_set_password(krb5_context context,HDB * db,hdb_entry * entry,const char * p)345c19800e8SDoug Rabson hdb_entry_set_password(krb5_context context, HDB *db,
346c19800e8SDoug Rabson hdb_entry *entry, const char *p)
347c19800e8SDoug Rabson {
348c19800e8SDoug Rabson HDB_extension ext;
349c19800e8SDoug Rabson hdb_master_key key;
350c19800e8SDoug Rabson int ret;
351c19800e8SDoug Rabson
352c19800e8SDoug Rabson ext.mandatory = FALSE;
353c19800e8SDoug Rabson ext.data.element = choice_HDB_extension_data_password;
354c19800e8SDoug Rabson
355c19800e8SDoug Rabson if (db->hdb_master_key_set) {
356c19800e8SDoug Rabson
357c19800e8SDoug Rabson key = _hdb_find_master_key(NULL, db->hdb_master_key);
358c19800e8SDoug Rabson if (key == NULL) {
359*ae771770SStanislav Sedov krb5_set_error_message(context, HDB_ERR_NO_MKEY,
360*ae771770SStanislav Sedov "hdb_entry_set_password: "
361c19800e8SDoug Rabson "failed to find masterkey");
362c19800e8SDoug Rabson return HDB_ERR_NO_MKEY;
363c19800e8SDoug Rabson }
364c19800e8SDoug Rabson
365c19800e8SDoug Rabson ret = _hdb_mkey_encrypt(context, key, HDB_KU_MKEY,
366c19800e8SDoug Rabson p, strlen(p) + 1,
367c19800e8SDoug Rabson &ext.data.u.password.password);
368c19800e8SDoug Rabson if (ret)
369c19800e8SDoug Rabson return ret;
370c19800e8SDoug Rabson
371c19800e8SDoug Rabson ext.data.u.password.mkvno =
372c19800e8SDoug Rabson malloc(sizeof(*ext.data.u.password.mkvno));
373c19800e8SDoug Rabson if (ext.data.u.password.mkvno == NULL) {
374c19800e8SDoug Rabson free_HDB_extension(&ext);
375*ae771770SStanislav Sedov krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
376c19800e8SDoug Rabson return ENOMEM;
377c19800e8SDoug Rabson }
378c19800e8SDoug Rabson *ext.data.u.password.mkvno = _hdb_mkey_version(key);
379c19800e8SDoug Rabson
380c19800e8SDoug Rabson } else {
381c19800e8SDoug Rabson ext.data.u.password.mkvno = NULL;
382c19800e8SDoug Rabson
383c19800e8SDoug Rabson ret = krb5_data_copy(&ext.data.u.password.password,
384c19800e8SDoug Rabson p, strlen(p) + 1);
385c19800e8SDoug Rabson if (ret) {
386*ae771770SStanislav Sedov krb5_set_error_message(context, ret, "malloc: out of memory");
387c19800e8SDoug Rabson free_HDB_extension(&ext);
388c19800e8SDoug Rabson return ret;
389c19800e8SDoug Rabson }
390c19800e8SDoug Rabson }
391c19800e8SDoug Rabson
392c19800e8SDoug Rabson ret = hdb_replace_extension(context, entry, &ext);
393c19800e8SDoug Rabson
394c19800e8SDoug Rabson free_HDB_extension(&ext);
395c19800e8SDoug Rabson
396c19800e8SDoug Rabson return ret;
397c19800e8SDoug Rabson }
398c19800e8SDoug Rabson
399c19800e8SDoug Rabson int
hdb_entry_clear_password(krb5_context context,hdb_entry * entry)400c19800e8SDoug Rabson hdb_entry_clear_password(krb5_context context, hdb_entry *entry)
401c19800e8SDoug Rabson {
402c19800e8SDoug Rabson return hdb_clear_extension(context, entry,
403c19800e8SDoug Rabson choice_HDB_extension_data_password);
404c19800e8SDoug Rabson }
405c19800e8SDoug Rabson
406c19800e8SDoug Rabson krb5_error_code
hdb_entry_get_ConstrainedDelegACL(const hdb_entry * entry,const HDB_Ext_Constrained_delegation_acl ** a)407c19800e8SDoug Rabson hdb_entry_get_ConstrainedDelegACL(const hdb_entry *entry,
408c19800e8SDoug Rabson const HDB_Ext_Constrained_delegation_acl **a)
409c19800e8SDoug Rabson {
410c19800e8SDoug Rabson const HDB_extension *ext;
411c19800e8SDoug Rabson
412c19800e8SDoug Rabson ext = hdb_find_extension(entry,
413c19800e8SDoug Rabson choice_HDB_extension_data_allowed_to_delegate_to);
414c19800e8SDoug Rabson if (ext)
415c19800e8SDoug Rabson *a = &ext->data.u.allowed_to_delegate_to;
416c19800e8SDoug Rabson else
417c19800e8SDoug Rabson *a = NULL;
418c19800e8SDoug Rabson
419c19800e8SDoug Rabson return 0;
420c19800e8SDoug Rabson }
421c19800e8SDoug Rabson
422c19800e8SDoug Rabson krb5_error_code
hdb_entry_get_aliases(const hdb_entry * entry,const HDB_Ext_Aliases ** a)423c19800e8SDoug Rabson hdb_entry_get_aliases(const hdb_entry *entry, const HDB_Ext_Aliases **a)
424c19800e8SDoug Rabson {
425c19800e8SDoug Rabson const HDB_extension *ext;
426c19800e8SDoug Rabson
427c19800e8SDoug Rabson ext = hdb_find_extension(entry, choice_HDB_extension_data_aliases);
428c19800e8SDoug Rabson if (ext)
429c19800e8SDoug Rabson *a = &ext->data.u.aliases;
430c19800e8SDoug Rabson else
431c19800e8SDoug Rabson *a = NULL;
432c19800e8SDoug Rabson
433c19800e8SDoug Rabson return 0;
434c19800e8SDoug Rabson }
435