No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / lib / kadm5 / marshall.c
blobd7b6c87a4c7e111ed37ba88a09769a43249008ac
1 /*
2 * Copyright (c) 1997 - 1999 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #include "kadm5_locl.h"
36 __RCSID("$Heimdal: marshall.c 21745 2007-07-31 16:11:25Z lha $"
37 "$NetBSD$");
39 kadm5_ret_t
40 kadm5_store_key_data(krb5_storage *sp,
41 krb5_key_data *key)
43 krb5_data c;
44 krb5_store_int32(sp, key->key_data_ver);
45 krb5_store_int32(sp, key->key_data_kvno);
46 krb5_store_int32(sp, key->key_data_type[0]);
47 c.length = key->key_data_length[0];
48 c.data = key->key_data_contents[0];
49 krb5_store_data(sp, c);
50 krb5_store_int32(sp, key->key_data_type[1]);
51 c.length = key->key_data_length[1];
52 c.data = key->key_data_contents[1];
53 krb5_store_data(sp, c);
54 return 0;
57 kadm5_ret_t
58 kadm5_ret_key_data(krb5_storage *sp,
59 krb5_key_data *key)
61 krb5_data c;
62 int32_t tmp;
63 krb5_ret_int32(sp, &tmp);
64 key->key_data_ver = tmp;
65 krb5_ret_int32(sp, &tmp);
66 key->key_data_kvno = tmp;
67 krb5_ret_int32(sp, &tmp);
68 key->key_data_type[0] = tmp;
69 krb5_ret_data(sp, &c);
70 key->key_data_length[0] = c.length;
71 key->key_data_contents[0] = c.data;
72 krb5_ret_int32(sp, &tmp);
73 key->key_data_type[1] = tmp;
74 krb5_ret_data(sp, &c);
75 key->key_data_length[1] = c.length;
76 key->key_data_contents[1] = c.data;
77 return 0;
80 kadm5_ret_t
81 kadm5_store_tl_data(krb5_storage *sp,
82 krb5_tl_data *tl)
84 krb5_data c;
85 krb5_store_int32(sp, tl->tl_data_type);
86 c.length = tl->tl_data_length;
87 c.data = tl->tl_data_contents;
88 krb5_store_data(sp, c);
89 return 0;
92 kadm5_ret_t
93 kadm5_ret_tl_data(krb5_storage *sp,
94 krb5_tl_data *tl)
96 krb5_data c;
97 int32_t tmp;
98 krb5_ret_int32(sp, &tmp);
99 tl->tl_data_type = tmp;
100 krb5_ret_data(sp, &c);
101 tl->tl_data_length = c.length;
102 tl->tl_data_contents = c.data;
103 return 0;
106 static kadm5_ret_t
107 store_principal_ent(krb5_storage *sp,
108 kadm5_principal_ent_t princ,
109 uint32_t mask)
111 int i;
113 if (mask & KADM5_PRINCIPAL)
114 krb5_store_principal(sp, princ->principal);
115 if (mask & KADM5_PRINC_EXPIRE_TIME)
116 krb5_store_int32(sp, princ->princ_expire_time);
117 if (mask & KADM5_PW_EXPIRATION)
118 krb5_store_int32(sp, princ->pw_expiration);
119 if (mask & KADM5_LAST_PWD_CHANGE)
120 krb5_store_int32(sp, princ->last_pwd_change);
121 if (mask & KADM5_MAX_LIFE)
122 krb5_store_int32(sp, princ->max_life);
123 if (mask & KADM5_MOD_NAME) {
124 krb5_store_int32(sp, princ->mod_name != NULL);
125 if(princ->mod_name)
126 krb5_store_principal(sp, princ->mod_name);
128 if (mask & KADM5_MOD_TIME)
129 krb5_store_int32(sp, princ->mod_date);
130 if (mask & KADM5_ATTRIBUTES)
131 krb5_store_int32(sp, princ->attributes);
132 if (mask & KADM5_KVNO)
133 krb5_store_int32(sp, princ->kvno);
134 if (mask & KADM5_MKVNO)
135 krb5_store_int32(sp, princ->mkvno);
136 if (mask & KADM5_POLICY) {
137 krb5_store_int32(sp, princ->policy != NULL);
138 if(princ->policy)
139 krb5_store_string(sp, princ->policy);
141 if (mask & KADM5_AUX_ATTRIBUTES)
142 krb5_store_int32(sp, princ->aux_attributes);
143 if (mask & KADM5_MAX_RLIFE)
144 krb5_store_int32(sp, princ->max_renewable_life);
145 if (mask & KADM5_LAST_SUCCESS)
146 krb5_store_int32(sp, princ->last_success);
147 if (mask & KADM5_LAST_FAILED)
148 krb5_store_int32(sp, princ->last_failed);
149 if (mask & KADM5_FAIL_AUTH_COUNT)
150 krb5_store_int32(sp, princ->fail_auth_count);
151 if (mask & KADM5_KEY_DATA) {
152 krb5_store_int32(sp, princ->n_key_data);
153 for(i = 0; i < princ->n_key_data; i++)
154 kadm5_store_key_data(sp, &princ->key_data[i]);
156 if (mask & KADM5_TL_DATA) {
157 krb5_tl_data *tp;
159 krb5_store_int32(sp, princ->n_tl_data);
160 for(tp = princ->tl_data; tp; tp = tp->tl_data_next)
161 kadm5_store_tl_data(sp, tp);
163 return 0;
167 kadm5_ret_t
168 kadm5_store_principal_ent(krb5_storage *sp,
169 kadm5_principal_ent_t princ)
171 return store_principal_ent (sp, princ, ~0);
174 kadm5_ret_t
175 kadm5_store_principal_ent_mask(krb5_storage *sp,
176 kadm5_principal_ent_t princ,
177 uint32_t mask)
179 krb5_store_int32(sp, mask);
180 return store_principal_ent (sp, princ, mask);
183 static kadm5_ret_t
184 ret_principal_ent(krb5_storage *sp,
185 kadm5_principal_ent_t princ,
186 uint32_t mask)
188 int i;
189 int32_t tmp;
191 if (mask & KADM5_PRINCIPAL)
192 krb5_ret_principal(sp, &princ->principal);
194 if (mask & KADM5_PRINC_EXPIRE_TIME) {
195 krb5_ret_int32(sp, &tmp);
196 princ->princ_expire_time = tmp;
198 if (mask & KADM5_PW_EXPIRATION) {
199 krb5_ret_int32(sp, &tmp);
200 princ->pw_expiration = tmp;
202 if (mask & KADM5_LAST_PWD_CHANGE) {
203 krb5_ret_int32(sp, &tmp);
204 princ->last_pwd_change = tmp;
206 if (mask & KADM5_MAX_LIFE) {
207 krb5_ret_int32(sp, &tmp);
208 princ->max_life = tmp;
210 if (mask & KADM5_MOD_NAME) {
211 krb5_ret_int32(sp, &tmp);
212 if(tmp)
213 krb5_ret_principal(sp, &princ->mod_name);
214 else
215 princ->mod_name = NULL;
217 if (mask & KADM5_MOD_TIME) {
218 krb5_ret_int32(sp, &tmp);
219 princ->mod_date = tmp;
221 if (mask & KADM5_ATTRIBUTES) {
222 krb5_ret_int32(sp, &tmp);
223 princ->attributes = tmp;
225 if (mask & KADM5_KVNO) {
226 krb5_ret_int32(sp, &tmp);
227 princ->kvno = tmp;
229 if (mask & KADM5_MKVNO) {
230 krb5_ret_int32(sp, &tmp);
231 princ->mkvno = tmp;
233 if (mask & KADM5_POLICY) {
234 krb5_ret_int32(sp, &tmp);
235 if(tmp)
236 krb5_ret_string(sp, &princ->policy);
237 else
238 princ->policy = NULL;
240 if (mask & KADM5_AUX_ATTRIBUTES) {
241 krb5_ret_int32(sp, &tmp);
242 princ->aux_attributes = tmp;
244 if (mask & KADM5_MAX_RLIFE) {
245 krb5_ret_int32(sp, &tmp);
246 princ->max_renewable_life = tmp;
248 if (mask & KADM5_LAST_SUCCESS) {
249 krb5_ret_int32(sp, &tmp);
250 princ->last_success = tmp;
252 if (mask & KADM5_LAST_FAILED) {
253 krb5_ret_int32(sp, &tmp);
254 princ->last_failed = tmp;
256 if (mask & KADM5_FAIL_AUTH_COUNT) {
257 krb5_ret_int32(sp, &tmp);
258 princ->fail_auth_count = tmp;
260 if (mask & KADM5_KEY_DATA) {
261 krb5_ret_int32(sp, &tmp);
262 princ->n_key_data = tmp;
263 princ->key_data = malloc(princ->n_key_data * sizeof(*princ->key_data));
264 if (princ->key_data == NULL)
265 return ENOMEM;
266 for(i = 0; i < princ->n_key_data; i++)
267 kadm5_ret_key_data(sp, &princ->key_data[i]);
269 if (mask & KADM5_TL_DATA) {
270 krb5_ret_int32(sp, &tmp);
271 princ->n_tl_data = tmp;
272 princ->tl_data = NULL;
273 for(i = 0; i < princ->n_tl_data; i++){
274 krb5_tl_data *tp = malloc(sizeof(*tp));
275 if (tp == NULL)
276 return ENOMEM;
277 kadm5_ret_tl_data(sp, tp);
278 tp->tl_data_next = princ->tl_data;
279 princ->tl_data = tp;
282 return 0;
285 kadm5_ret_t
286 kadm5_ret_principal_ent(krb5_storage *sp,
287 kadm5_principal_ent_t princ)
289 return ret_principal_ent (sp, princ, ~0);
292 kadm5_ret_t
293 kadm5_ret_principal_ent_mask(krb5_storage *sp,
294 kadm5_principal_ent_t princ,
295 uint32_t *mask)
297 int32_t tmp;
299 krb5_ret_int32 (sp, &tmp);
300 *mask = tmp;
301 return ret_principal_ent (sp, princ, *mask);
304 kadm5_ret_t
305 _kadm5_marshal_params(krb5_context context,
306 kadm5_config_params *params,
307 krb5_data *out)
309 krb5_storage *sp = krb5_storage_emem();
311 krb5_store_int32(sp, params->mask & (KADM5_CONFIG_REALM));
313 if(params->mask & KADM5_CONFIG_REALM)
314 krb5_store_string(sp, params->realm);
315 krb5_storage_to_data(sp, out);
316 krb5_storage_free(sp);
318 return 0;
321 kadm5_ret_t
322 _kadm5_unmarshal_params(krb5_context context,
323 krb5_data *in,
324 kadm5_config_params *params)
326 krb5_storage *sp = krb5_storage_from_data(in);
327 int32_t mask;
329 krb5_ret_int32(sp, &mask);
330 params->mask = mask;
332 if(params->mask & KADM5_CONFIG_REALM)
333 krb5_ret_string(sp, &params->realm);
334 krb5_storage_free(sp);
336 return 0;