2 * Copyright (c) 1997 - 1999 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
34 #include "kadm5_locl.h"
39 kadm5_store_key_data(krb5_storage
*sp
,
43 krb5_store_int32(sp
, key
->key_data_ver
);
44 krb5_store_int32(sp
, key
->key_data_kvno
);
45 krb5_store_int32(sp
, key
->key_data_type
[0]);
46 c
.length
= key
->key_data_length
[0];
47 c
.data
= key
->key_data_contents
[0];
48 krb5_store_data(sp
, c
);
49 krb5_store_int32(sp
, key
->key_data_type
[1]);
50 c
.length
= key
->key_data_length
[1];
51 c
.data
= key
->key_data_contents
[1];
52 krb5_store_data(sp
, c
);
57 kadm5_ret_key_data(krb5_storage
*sp
,
62 krb5_ret_int32(sp
, &tmp
);
63 key
->key_data_ver
= tmp
;
64 krb5_ret_int32(sp
, &tmp
);
65 key
->key_data_kvno
= tmp
;
66 krb5_ret_int32(sp
, &tmp
);
67 key
->key_data_type
[0] = tmp
;
68 krb5_ret_data(sp
, &c
);
69 key
->key_data_length
[0] = c
.length
;
70 key
->key_data_contents
[0] = c
.data
;
71 krb5_ret_int32(sp
, &tmp
);
72 key
->key_data_type
[1] = tmp
;
73 krb5_ret_data(sp
, &c
);
74 key
->key_data_length
[1] = c
.length
;
75 key
->key_data_contents
[1] = c
.data
;
80 kadm5_store_tl_data(krb5_storage
*sp
,
84 krb5_store_int32(sp
, tl
->tl_data_type
);
85 c
.length
= tl
->tl_data_length
;
86 c
.data
= tl
->tl_data_contents
;
87 krb5_store_data(sp
, c
);
92 kadm5_ret_tl_data(krb5_storage
*sp
,
97 krb5_ret_int32(sp
, &tmp
);
98 tl
->tl_data_type
= tmp
;
99 krb5_ret_data(sp
, &c
);
100 tl
->tl_data_length
= c
.length
;
101 tl
->tl_data_contents
= c
.data
;
106 store_principal_ent(krb5_storage
*sp
,
107 kadm5_principal_ent_t princ
,
112 if (mask
& KADM5_PRINCIPAL
)
113 krb5_store_principal(sp
, princ
->principal
);
114 if (mask
& KADM5_PRINC_EXPIRE_TIME
)
115 krb5_store_int32(sp
, princ
->princ_expire_time
);
116 if (mask
& KADM5_PW_EXPIRATION
)
117 krb5_store_int32(sp
, princ
->pw_expiration
);
118 if (mask
& KADM5_LAST_PWD_CHANGE
)
119 krb5_store_int32(sp
, princ
->last_pwd_change
);
120 if (mask
& KADM5_MAX_LIFE
)
121 krb5_store_int32(sp
, princ
->max_life
);
122 if (mask
& KADM5_MOD_NAME
) {
123 krb5_store_int32(sp
, princ
->mod_name
!= NULL
);
125 krb5_store_principal(sp
, princ
->mod_name
);
127 if (mask
& KADM5_MOD_TIME
)
128 krb5_store_int32(sp
, princ
->mod_date
);
129 if (mask
& KADM5_ATTRIBUTES
)
130 krb5_store_int32(sp
, princ
->attributes
);
131 if (mask
& KADM5_KVNO
)
132 krb5_store_int32(sp
, princ
->kvno
);
133 if (mask
& KADM5_MKVNO
)
134 krb5_store_int32(sp
, princ
->mkvno
);
135 if (mask
& KADM5_POLICY
) {
136 krb5_store_int32(sp
, princ
->policy
!= NULL
);
138 krb5_store_string(sp
, princ
->policy
);
140 if (mask
& KADM5_AUX_ATTRIBUTES
)
141 krb5_store_int32(sp
, princ
->aux_attributes
);
142 if (mask
& KADM5_MAX_RLIFE
)
143 krb5_store_int32(sp
, princ
->max_renewable_life
);
144 if (mask
& KADM5_LAST_SUCCESS
)
145 krb5_store_int32(sp
, princ
->last_success
);
146 if (mask
& KADM5_LAST_FAILED
)
147 krb5_store_int32(sp
, princ
->last_failed
);
148 if (mask
& KADM5_FAIL_AUTH_COUNT
)
149 krb5_store_int32(sp
, princ
->fail_auth_count
);
150 if (mask
& KADM5_KEY_DATA
) {
151 krb5_store_int32(sp
, princ
->n_key_data
);
152 for(i
= 0; i
< princ
->n_key_data
; i
++)
153 kadm5_store_key_data(sp
, &princ
->key_data
[i
]);
155 if (mask
& KADM5_TL_DATA
) {
158 krb5_store_int32(sp
, princ
->n_tl_data
);
159 for(tp
= princ
->tl_data
; tp
; tp
= tp
->tl_data_next
)
160 kadm5_store_tl_data(sp
, tp
);
167 kadm5_store_principal_ent(krb5_storage
*sp
,
168 kadm5_principal_ent_t princ
)
170 return store_principal_ent (sp
, princ
, ~0);
174 kadm5_store_principal_ent_mask(krb5_storage
*sp
,
175 kadm5_principal_ent_t princ
,
178 krb5_store_int32(sp
, mask
);
179 return store_principal_ent (sp
, princ
, mask
);
183 ret_principal_ent(krb5_storage
*sp
,
184 kadm5_principal_ent_t princ
,
190 if (mask
& KADM5_PRINCIPAL
)
191 krb5_ret_principal(sp
, &princ
->principal
);
193 if (mask
& KADM5_PRINC_EXPIRE_TIME
) {
194 krb5_ret_int32(sp
, &tmp
);
195 princ
->princ_expire_time
= tmp
;
197 if (mask
& KADM5_PW_EXPIRATION
) {
198 krb5_ret_int32(sp
, &tmp
);
199 princ
->pw_expiration
= tmp
;
201 if (mask
& KADM5_LAST_PWD_CHANGE
) {
202 krb5_ret_int32(sp
, &tmp
);
203 princ
->last_pwd_change
= tmp
;
205 if (mask
& KADM5_MAX_LIFE
) {
206 krb5_ret_int32(sp
, &tmp
);
207 princ
->max_life
= tmp
;
209 if (mask
& KADM5_MOD_NAME
) {
210 krb5_ret_int32(sp
, &tmp
);
212 krb5_ret_principal(sp
, &princ
->mod_name
);
214 princ
->mod_name
= NULL
;
216 if (mask
& KADM5_MOD_TIME
) {
217 krb5_ret_int32(sp
, &tmp
);
218 princ
->mod_date
= tmp
;
220 if (mask
& KADM5_ATTRIBUTES
) {
221 krb5_ret_int32(sp
, &tmp
);
222 princ
->attributes
= tmp
;
224 if (mask
& KADM5_KVNO
) {
225 krb5_ret_int32(sp
, &tmp
);
228 if (mask
& KADM5_MKVNO
) {
229 krb5_ret_int32(sp
, &tmp
);
232 if (mask
& KADM5_POLICY
) {
233 krb5_ret_int32(sp
, &tmp
);
235 krb5_ret_string(sp
, &princ
->policy
);
237 princ
->policy
= NULL
;
239 if (mask
& KADM5_AUX_ATTRIBUTES
) {
240 krb5_ret_int32(sp
, &tmp
);
241 princ
->aux_attributes
= tmp
;
243 if (mask
& KADM5_MAX_RLIFE
) {
244 krb5_ret_int32(sp
, &tmp
);
245 princ
->max_renewable_life
= tmp
;
247 if (mask
& KADM5_LAST_SUCCESS
) {
248 krb5_ret_int32(sp
, &tmp
);
249 princ
->last_success
= tmp
;
251 if (mask
& KADM5_LAST_FAILED
) {
252 krb5_ret_int32(sp
, &tmp
);
253 princ
->last_failed
= tmp
;
255 if (mask
& KADM5_FAIL_AUTH_COUNT
) {
256 krb5_ret_int32(sp
, &tmp
);
257 princ
->fail_auth_count
= tmp
;
259 if (mask
& KADM5_KEY_DATA
) {
260 krb5_ret_int32(sp
, &tmp
);
261 princ
->n_key_data
= tmp
;
262 princ
->key_data
= malloc(princ
->n_key_data
* sizeof(*princ
->key_data
));
263 if (princ
->key_data
== NULL
)
265 for(i
= 0; i
< princ
->n_key_data
; i
++)
266 kadm5_ret_key_data(sp
, &princ
->key_data
[i
]);
268 if (mask
& KADM5_TL_DATA
) {
269 krb5_ret_int32(sp
, &tmp
);
270 princ
->n_tl_data
= tmp
;
271 princ
->tl_data
= NULL
;
272 for(i
= 0; i
< princ
->n_tl_data
; i
++){
273 krb5_tl_data
*tp
= malloc(sizeof(*tp
));
276 kadm5_ret_tl_data(sp
, tp
);
277 tp
->tl_data_next
= princ
->tl_data
;
285 kadm5_ret_principal_ent(krb5_storage
*sp
,
286 kadm5_principal_ent_t princ
)
288 return ret_principal_ent (sp
, princ
, ~0);
292 kadm5_ret_principal_ent_mask(krb5_storage
*sp
,
293 kadm5_principal_ent_t princ
,
298 krb5_ret_int32 (sp
, &tmp
);
300 return ret_principal_ent (sp
, princ
, *mask
);
304 _kadm5_marshal_params(krb5_context context
,
305 kadm5_config_params
*params
,
308 krb5_storage
*sp
= krb5_storage_emem();
310 krb5_store_int32(sp
, params
->mask
& (KADM5_CONFIG_REALM
));
312 if(params
->mask
& KADM5_CONFIG_REALM
)
313 krb5_store_string(sp
, params
->realm
);
314 krb5_storage_to_data(sp
, out
);
315 krb5_storage_free(sp
);
321 _kadm5_unmarshal_params(krb5_context context
,
323 kadm5_config_params
*params
)
329 sp
= krb5_storage_from_data(in
);
333 ret
= krb5_ret_int32(sp
, &mask
);
338 if(params
->mask
& KADM5_CONFIG_REALM
)
339 ret
= krb5_ret_string(sp
, ¶ms
->realm
);
341 krb5_storage_free(sp
);