2 * Copyright (c) 1997 - 2000 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"
36 __RCSID("$Heimdal: ent_setup.c 18823 2006-10-22 10:15:53Z lha $"
39 #define set_value(X, V) do { if((X) == NULL) (X) = malloc(sizeof(*(X))); *(X) = V; } while(0)
40 #define set_null(X) do { if((X) != NULL) free((X)); (X) = NULL; } while (0)
43 attr_to_flags(unsigned attr
, HDBFlags
*flags
)
45 flags
->postdate
= !(attr
& KRB5_KDB_DISALLOW_POSTDATED
);
46 flags
->forwardable
= !(attr
& KRB5_KDB_DISALLOW_FORWARDABLE
);
47 flags
->initial
= !!(attr
& KRB5_KDB_DISALLOW_TGT_BASED
);
48 flags
->renewable
= !(attr
& KRB5_KDB_DISALLOW_RENEWABLE
);
49 flags
->proxiable
= !(attr
& KRB5_KDB_DISALLOW_PROXIABLE
);
51 flags
->invalid
= !!(attr
& KRB5_KDB_DISALLOW_ALL_TIX
);
52 flags
->require_preauth
= !!(attr
& KRB5_KDB_REQUIRES_PRE_AUTH
);
54 flags
->server
= !(attr
& KRB5_KDB_DISALLOW_SVR
);
55 flags
->change_pw
= !!(attr
& KRB5_KDB_PWCHANGE_SERVICE
);
56 flags
->client
= 1; /* XXX */
57 flags
->ok_as_delegate
= !!(attr
& KRB5_KDB_OK_AS_DELEGATE
);
58 flags
->trusted_for_delegation
= !!(attr
& KRB5_KDB_TRUSTED_FOR_DELEGATION
);
59 flags
->allow_kerberos4
= !!(attr
& KRB5_KDB_ALLOW_KERBEROS4
);
60 flags
->allow_digest
= !!(attr
& KRB5_KDB_ALLOW_DIGEST
);
64 * Modify the `ent' according to `tl_data'.
68 perform_tl_data(krb5_context context
,
71 const krb5_tl_data
*tl_data
)
75 if (tl_data
->tl_data_type
== KRB5_TL_PASSWORD
) {
76 heim_utf8_string pw
= tl_data
->tl_data_contents
;
78 if (pw
[tl_data
->tl_data_length
] != '\0')
79 return KADM5_BAD_TL_TYPE
;
81 ret
= hdb_entry_set_password(context
, db
, &ent
->entry
, pw
);
83 } else if (tl_data
->tl_data_type
== KRB5_TL_LAST_PWD_CHANGE
) {
87 if (tl_data
->tl_data_length
!= 4)
88 return KADM5_BAD_TL_TYPE
;
90 s
= tl_data
->tl_data_contents
;
92 t
= s
[0] | (s
[1] << 8) | (s
[2] << 16) | (s
[3] << 24);
94 ret
= hdb_entry_set_pw_change_time(context
, &ent
->entry
, t
);
96 } else if (tl_data
->tl_data_type
== KRB5_TL_EXTENSION
) {
99 ret
= decode_HDB_extension(tl_data
->tl_data_contents
,
100 tl_data
->tl_data_length
,
104 return KADM5_BAD_TL_TYPE
;
106 ret
= hdb_replace_extension(context
, &ent
->entry
, &ext
);
107 free_HDB_extension(&ext
);
109 return KADM5_BAD_TL_TYPE
;
116 * Create the hdb entry `ent' based on data from `princ' with
117 * `princ_mask' specifying what fields to be gotten from there and
118 * `mask' specifying what fields we want filled in.
122 _kadm5_setup_entry(kadm5_server_context
*context
,
125 kadm5_principal_ent_t princ
,
127 kadm5_principal_ent_t def
,
130 if(mask
& KADM5_PRINC_EXPIRE_TIME
131 && princ_mask
& KADM5_PRINC_EXPIRE_TIME
) {
132 if (princ
->princ_expire_time
)
133 set_value(ent
->entry
.valid_end
, princ
->princ_expire_time
);
135 set_null(ent
->entry
.valid_end
);
137 if(mask
& KADM5_PW_EXPIRATION
138 && princ_mask
& KADM5_PW_EXPIRATION
) {
139 if (princ
->pw_expiration
)
140 set_value(ent
->entry
.pw_end
, princ
->pw_expiration
);
142 set_null(ent
->entry
.pw_end
);
144 if(mask
& KADM5_ATTRIBUTES
) {
145 if (princ_mask
& KADM5_ATTRIBUTES
) {
146 attr_to_flags(princ
->attributes
, &ent
->entry
.flags
);
147 } else if(def_mask
& KADM5_ATTRIBUTES
) {
148 attr_to_flags(def
->attributes
, &ent
->entry
.flags
);
149 ent
->entry
.flags
.invalid
= 0;
151 ent
->entry
.flags
.client
= 1;
152 ent
->entry
.flags
.server
= 1;
153 ent
->entry
.flags
.forwardable
= 1;
154 ent
->entry
.flags
.proxiable
= 1;
155 ent
->entry
.flags
.renewable
= 1;
156 ent
->entry
.flags
.postdate
= 1;
159 if(mask
& KADM5_MAX_LIFE
) {
160 if(princ_mask
& KADM5_MAX_LIFE
) {
162 set_value(ent
->entry
.max_life
, princ
->max_life
);
164 set_null(ent
->entry
.max_life
);
165 } else if(def_mask
& KADM5_MAX_LIFE
) {
167 set_value(ent
->entry
.max_life
, def
->max_life
);
169 set_null(ent
->entry
.max_life
);
173 && princ_mask
& KADM5_KVNO
)
174 ent
->entry
.kvno
= princ
->kvno
;
175 if(mask
& KADM5_MAX_RLIFE
) {
176 if(princ_mask
& KADM5_MAX_RLIFE
) {
177 if(princ
->max_renewable_life
)
178 set_value(ent
->entry
.max_renew
, princ
->max_renewable_life
);
180 set_null(ent
->entry
.max_renew
);
181 } else if(def_mask
& KADM5_MAX_RLIFE
) {
182 if(def
->max_renewable_life
)
183 set_value(ent
->entry
.max_renew
, def
->max_renewable_life
);
185 set_null(ent
->entry
.max_renew
);
188 if(mask
& KADM5_KEY_DATA
189 && princ_mask
& KADM5_KEY_DATA
) {
190 _kadm5_set_keys2(context
, &ent
->entry
,
191 princ
->n_key_data
, princ
->key_data
);
193 if(mask
& KADM5_TL_DATA
) {
196 for (tl
= princ
->tl_data
; tl
!= NULL
; tl
= tl
->tl_data_next
) {
198 ret
= perform_tl_data(context
->context
, context
->db
, ent
, tl
);
203 if(mask
& KADM5_FAIL_AUTH_COUNT
) {