Remove building with NOCRYPTO option
[minix.git] / crypto / external / bsd / heimdal / dist / lib / kadm5 / marshall.c
blob60a3987c4146d5ff5efb947ca42afebff79fe995
1 /* $NetBSD: marshall.c,v 1.1.1.2 2014/04/24 12:45:49 pettai Exp $ */
3 /*
4 * Copyright (c) 1997 - 1999 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
36 #include "kadm5_locl.h"
38 __RCSID("NetBSD");
40 kadm5_ret_t
41 kadm5_store_key_data(krb5_storage *sp,
42 krb5_key_data *key)
44 krb5_data c;
45 krb5_store_int32(sp, key->key_data_ver);
46 krb5_store_int32(sp, key->key_data_kvno);
47 krb5_store_int32(sp, key->key_data_type[0]);
48 c.length = key->key_data_length[0];
49 c.data = key->key_data_contents[0];
50 krb5_store_data(sp, c);
51 krb5_store_int32(sp, key->key_data_type[1]);
52 c.length = key->key_data_length[1];
53 c.data = key->key_data_contents[1];
54 krb5_store_data(sp, c);
55 return 0;
58 kadm5_ret_t
59 kadm5_ret_key_data(krb5_storage *sp,
60 krb5_key_data *key)
62 krb5_data c;
63 int32_t tmp;
64 krb5_ret_int32(sp, &tmp);
65 key->key_data_ver = tmp;
66 krb5_ret_int32(sp, &tmp);
67 key->key_data_kvno = tmp;
68 krb5_ret_int32(sp, &tmp);
69 key->key_data_type[0] = tmp;
70 krb5_ret_data(sp, &c);
71 key->key_data_length[0] = c.length;
72 key->key_data_contents[0] = c.data;
73 krb5_ret_int32(sp, &tmp);
74 key->key_data_type[1] = tmp;
75 krb5_ret_data(sp, &c);
76 key->key_data_length[1] = c.length;
77 key->key_data_contents[1] = c.data;
78 return 0;
81 kadm5_ret_t
82 kadm5_store_tl_data(krb5_storage *sp,
83 krb5_tl_data *tl)
85 krb5_data c;
86 krb5_store_int32(sp, tl->tl_data_type);
87 c.length = tl->tl_data_length;
88 c.data = tl->tl_data_contents;
89 krb5_store_data(sp, c);
90 return 0;
93 kadm5_ret_t
94 kadm5_ret_tl_data(krb5_storage *sp,
95 krb5_tl_data *tl)
97 krb5_data c;
98 int32_t tmp;
99 krb5_ret_int32(sp, &tmp);
100 tl->tl_data_type = tmp;
101 krb5_ret_data(sp, &c);
102 tl->tl_data_length = c.length;
103 tl->tl_data_contents = c.data;
104 return 0;
107 static kadm5_ret_t
108 store_principal_ent(krb5_storage *sp,
109 kadm5_principal_ent_t princ,
110 uint32_t mask)
112 int i;
114 if (mask & KADM5_PRINCIPAL)
115 krb5_store_principal(sp, princ->principal);
116 if (mask & KADM5_PRINC_EXPIRE_TIME)
117 krb5_store_int32(sp, princ->princ_expire_time);
118 if (mask & KADM5_PW_EXPIRATION)
119 krb5_store_int32(sp, princ->pw_expiration);
120 if (mask & KADM5_LAST_PWD_CHANGE)
121 krb5_store_int32(sp, princ->last_pwd_change);
122 if (mask & KADM5_MAX_LIFE)
123 krb5_store_int32(sp, princ->max_life);
124 if (mask & KADM5_MOD_NAME) {
125 krb5_store_int32(sp, princ->mod_name != NULL);
126 if(princ->mod_name)
127 krb5_store_principal(sp, princ->mod_name);
129 if (mask & KADM5_MOD_TIME)
130 krb5_store_int32(sp, princ->mod_date);
131 if (mask & KADM5_ATTRIBUTES)
132 krb5_store_int32(sp, princ->attributes);
133 if (mask & KADM5_KVNO)
134 krb5_store_int32(sp, princ->kvno);
135 if (mask & KADM5_MKVNO)
136 krb5_store_int32(sp, princ->mkvno);
137 if (mask & KADM5_POLICY) {
138 krb5_store_int32(sp, princ->policy != NULL);
139 if(princ->policy)
140 krb5_store_string(sp, princ->policy);
142 if (mask & KADM5_AUX_ATTRIBUTES)
143 krb5_store_int32(sp, princ->aux_attributes);
144 if (mask & KADM5_MAX_RLIFE)
145 krb5_store_int32(sp, princ->max_renewable_life);
146 if (mask & KADM5_LAST_SUCCESS)
147 krb5_store_int32(sp, princ->last_success);
148 if (mask & KADM5_LAST_FAILED)
149 krb5_store_int32(sp, princ->last_failed);
150 if (mask & KADM5_FAIL_AUTH_COUNT)
151 krb5_store_int32(sp, princ->fail_auth_count);
152 if (mask & KADM5_KEY_DATA) {
153 krb5_store_int32(sp, princ->n_key_data);
154 for(i = 0; i < princ->n_key_data; i++)
155 kadm5_store_key_data(sp, &princ->key_data[i]);
157 if (mask & KADM5_TL_DATA) {
158 krb5_tl_data *tp;
160 krb5_store_int32(sp, princ->n_tl_data);
161 for(tp = princ->tl_data; tp; tp = tp->tl_data_next)
162 kadm5_store_tl_data(sp, tp);
164 return 0;
168 kadm5_ret_t
169 kadm5_store_principal_ent(krb5_storage *sp,
170 kadm5_principal_ent_t princ)
172 return store_principal_ent (sp, princ, ~0);
175 kadm5_ret_t
176 kadm5_store_principal_ent_mask(krb5_storage *sp,
177 kadm5_principal_ent_t princ,
178 uint32_t mask)
180 krb5_store_int32(sp, mask);
181 return store_principal_ent (sp, princ, mask);
184 static kadm5_ret_t
185 ret_principal_ent(krb5_storage *sp,
186 kadm5_principal_ent_t princ,
187 uint32_t mask)
189 int i;
190 int32_t tmp;
192 if (mask & KADM5_PRINCIPAL)
193 krb5_ret_principal(sp, &princ->principal);
195 if (mask & KADM5_PRINC_EXPIRE_TIME) {
196 krb5_ret_int32(sp, &tmp);
197 princ->princ_expire_time = tmp;
199 if (mask & KADM5_PW_EXPIRATION) {
200 krb5_ret_int32(sp, &tmp);
201 princ->pw_expiration = tmp;
203 if (mask & KADM5_LAST_PWD_CHANGE) {
204 krb5_ret_int32(sp, &tmp);
205 princ->last_pwd_change = tmp;
207 if (mask & KADM5_MAX_LIFE) {
208 krb5_ret_int32(sp, &tmp);
209 princ->max_life = tmp;
211 if (mask & KADM5_MOD_NAME) {
212 krb5_ret_int32(sp, &tmp);
213 if(tmp)
214 krb5_ret_principal(sp, &princ->mod_name);
215 else
216 princ->mod_name = NULL;
218 if (mask & KADM5_MOD_TIME) {
219 krb5_ret_int32(sp, &tmp);
220 princ->mod_date = tmp;
222 if (mask & KADM5_ATTRIBUTES) {
223 krb5_ret_int32(sp, &tmp);
224 princ->attributes = tmp;
226 if (mask & KADM5_KVNO) {
227 krb5_ret_int32(sp, &tmp);
228 princ->kvno = tmp;
230 if (mask & KADM5_MKVNO) {
231 krb5_ret_int32(sp, &tmp);
232 princ->mkvno = tmp;
234 if (mask & KADM5_POLICY) {
235 krb5_ret_int32(sp, &tmp);
236 if(tmp)
237 krb5_ret_string(sp, &princ->policy);
238 else
239 princ->policy = NULL;
241 if (mask & KADM5_AUX_ATTRIBUTES) {
242 krb5_ret_int32(sp, &tmp);
243 princ->aux_attributes = tmp;
245 if (mask & KADM5_MAX_RLIFE) {
246 krb5_ret_int32(sp, &tmp);
247 princ->max_renewable_life = tmp;
249 if (mask & KADM5_LAST_SUCCESS) {
250 krb5_ret_int32(sp, &tmp);
251 princ->last_success = tmp;
253 if (mask & KADM5_LAST_FAILED) {
254 krb5_ret_int32(sp, &tmp);
255 princ->last_failed = tmp;
257 if (mask & KADM5_FAIL_AUTH_COUNT) {
258 krb5_ret_int32(sp, &tmp);
259 princ->fail_auth_count = tmp;
261 if (mask & KADM5_KEY_DATA) {
262 krb5_ret_int32(sp, &tmp);
263 princ->n_key_data = tmp;
264 princ->key_data = malloc(princ->n_key_data * sizeof(*princ->key_data));
265 if (princ->key_data == NULL && princ->n_key_data != 0)
266 return ENOMEM;
267 for(i = 0; i < princ->n_key_data; i++)
268 kadm5_ret_key_data(sp, &princ->key_data[i]);
270 if (mask & KADM5_TL_DATA) {
271 krb5_ret_int32(sp, &tmp);
272 princ->n_tl_data = tmp;
273 princ->tl_data = NULL;
274 for(i = 0; i < princ->n_tl_data; i++){
275 krb5_tl_data *tp = malloc(sizeof(*tp));
276 if (tp == NULL)
277 return ENOMEM;
278 kadm5_ret_tl_data(sp, tp);
279 tp->tl_data_next = princ->tl_data;
280 princ->tl_data = tp;
283 return 0;
286 kadm5_ret_t
287 kadm5_ret_principal_ent(krb5_storage *sp,
288 kadm5_principal_ent_t princ)
290 return ret_principal_ent (sp, princ, ~0);
293 kadm5_ret_t
294 kadm5_ret_principal_ent_mask(krb5_storage *sp,
295 kadm5_principal_ent_t princ,
296 uint32_t *mask)
298 int32_t tmp;
300 krb5_ret_int32 (sp, &tmp);
301 *mask = tmp;
302 return ret_principal_ent (sp, princ, *mask);
305 kadm5_ret_t
306 _kadm5_marshal_params(krb5_context context,
307 kadm5_config_params *params,
308 krb5_data *out)
310 krb5_storage *sp = krb5_storage_emem();
312 krb5_store_int32(sp, params->mask & (KADM5_CONFIG_REALM));
314 if(params->mask & KADM5_CONFIG_REALM)
315 krb5_store_string(sp, params->realm);
316 krb5_storage_to_data(sp, out);
317 krb5_storage_free(sp);
319 return 0;
322 kadm5_ret_t
323 _kadm5_unmarshal_params(krb5_context context,
324 krb5_data *in,
325 kadm5_config_params *params)
327 krb5_error_code ret;
328 krb5_storage *sp;
329 int32_t mask;
331 sp = krb5_storage_from_data(in);
332 if (sp == NULL)
333 return ENOMEM;
335 ret = krb5_ret_int32(sp, &mask);
336 if (ret)
337 goto out;
338 params->mask = mask;
340 if(params->mask & KADM5_CONFIG_REALM)
341 ret = krb5_ret_string(sp, &params->realm);
342 out:
343 krb5_storage_free(sp);
345 return ret;