2 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 * Openvision retains the copyright to derivative works of
5 * this source code. Do *NOT* create a derivative of this
6 * source code before consulting with your legal department.
7 * Do *NOT* integrate *ANY* of this source code into another
8 * product before consulting with your legal department.
10 * For further information, read the top-level Openvision
11 * copyright which is contained in the top-level MIT Kerberos
14 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
20 * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
25 static char *rcsid
= "$Header$";
27 #include "server_internal.h"
28 #include <sys/types.h>
29 #include <kadm5/admin.h>
33 #define MAX_PW_HISTORY 10
34 #define MIN_PW_HISTORY 1
35 #define MIN_PW_CLASSES 1
36 #define MAX_PW_CLASSES 5
37 #define MIN_PW_LENGTH 1
40 * Function: kadm5_create_policy
42 * Purpose: Create Policies in the policy DB.
45 * entry (input) The policy entry to be written out to the DB.
46 * mask (input) Specifies which fields in entry are to ge written out
47 * and which get default values.
48 * <return value> 0 if successful otherwise an error code is returned.
51 * Entry must be a valid principal entry, and mask have a valid value.
54 * Verifies that mask does not specify that the refcount should
55 * be set as part of the creation, and calls
56 * kadm5_create_policy_internal. If the refcount *is*
57 * specified, returns KADM5_BAD_MASK.
61 kadm5_create_policy(void *server_handle
,
62 kadm5_policy_ent_t entry
, long mask
)
64 CHECK_HANDLE(server_handle
);
66 krb5_clear_error_message(((kadm5_server_handle_t
)server_handle
)->context
);
68 if (mask
& KADM5_REF_COUNT
)
69 return KADM5_BAD_MASK
;
71 return kadm5_create_policy_internal(server_handle
, entry
, mask
);
75 * Function: kadm5_create_policy_internal
77 * Purpose: Create Policies in the policy DB.
80 * entry (input) The policy entry to be written out to the DB.
81 * mask (input) Specifies which fields in entry are to ge written out
82 * and which get default values.
83 * <return value> 0 if successful otherwise an error code is returned.
86 * Entry must be a valid principal entry, and mask have a valid value.
89 * Writes the data to the database, and does a database sync if
95 kadm5_create_policy_internal(void *server_handle
,
96 kadm5_policy_ent_t entry
, long mask
)
98 kadm5_server_handle_t handle
= server_handle
;
99 osa_policy_ent_rec pent
;
103 CHECK_HANDLE(server_handle
);
105 if ((entry
== (kadm5_policy_ent_t
) NULL
) || (entry
->policy
== NULL
))
107 if(strlen(entry
->policy
) == 0)
108 return KADM5_BAD_POLICY
;
109 if (!(mask
& KADM5_POLICY
))
110 return KADM5_BAD_MASK
;
112 pent
.name
= entry
->policy
;
115 if(*p
< ' ' || *p
> '~')
116 return KADM5_BAD_POLICY
;
120 if (!(mask
& KADM5_PW_MAX_LIFE
))
121 pent
.pw_max_life
= 0;
123 pent
.pw_max_life
= entry
->pw_max_life
;
124 if (!(mask
& KADM5_PW_MIN_LIFE
))
125 pent
.pw_min_life
= 0;
127 if((mask
& KADM5_PW_MAX_LIFE
)) {
128 if(entry
->pw_min_life
> entry
->pw_max_life
&& entry
->pw_max_life
!= 0)
129 return KADM5_BAD_MIN_PASS_LIFE
;
131 pent
.pw_min_life
= entry
->pw_min_life
;
133 if (!(mask
& KADM5_PW_MIN_LENGTH
))
134 pent
.pw_min_length
= MIN_PW_LENGTH
;
136 if(entry
->pw_min_length
< MIN_PW_LENGTH
)
137 return KADM5_BAD_LENGTH
;
138 pent
.pw_min_length
= entry
->pw_min_length
;
140 if (!(mask
& KADM5_PW_MIN_CLASSES
))
141 pent
.pw_min_classes
= MIN_PW_CLASSES
;
143 if(entry
->pw_min_classes
> MAX_PW_CLASSES
|| entry
->pw_min_classes
< MIN_PW_CLASSES
)
144 return KADM5_BAD_CLASS
;
145 pent
.pw_min_classes
= entry
->pw_min_classes
;
147 if (!(mask
& KADM5_PW_HISTORY_NUM
))
148 pent
.pw_history_num
= MIN_PW_HISTORY
;
150 if(entry
->pw_history_num
< MIN_PW_HISTORY
||
151 entry
->pw_history_num
> MAX_PW_HISTORY
)
152 return KADM5_BAD_HISTORY
;
154 pent
.pw_history_num
= entry
->pw_history_num
;
156 if (!(mask
& KADM5_REF_COUNT
))
157 pent
.policy_refcnt
= 0;
159 pent
.policy_refcnt
= entry
->policy_refcnt
;
160 if ((ret
= krb5_db_create_policy(handle
->context
, &pent
)))
167 kadm5_delete_policy(void *server_handle
, kadm5_policy_t name
)
169 kadm5_server_handle_t handle
= server_handle
;
170 osa_policy_ent_t entry
;
174 CHECK_HANDLE(server_handle
);
176 krb5_clear_error_message(handle
->context
);
178 if(name
== (kadm5_policy_t
) NULL
)
180 if(strlen(name
) == 0)
181 return KADM5_BAD_POLICY
;
182 if((ret
= krb5_db_get_policy(handle
->context
, name
, &entry
,&cnt
)))
185 return KADM5_UNK_POLICY
;
187 if(entry
->policy_refcnt
!= 0) {
188 krb5_db_free_policy(handle
->context
, entry
);
189 return KADM5_POLICY_REF
;
191 krb5_db_free_policy(handle
->context
, entry
);
192 if ((ret
= krb5_db_delete_policy(handle
->context
, name
)))
199 kadm5_modify_policy(void *server_handle
,
200 kadm5_policy_ent_t entry
, long mask
)
202 CHECK_HANDLE(server_handle
);
204 krb5_clear_error_message(((kadm5_server_handle_t
)server_handle
)->context
);
206 if (mask
& KADM5_REF_COUNT
)
207 return KADM5_BAD_MASK
;
209 return kadm5_modify_policy_internal(server_handle
, entry
, mask
);
213 kadm5_modify_policy_internal(void *server_handle
,
214 kadm5_policy_ent_t entry
, long mask
)
216 kadm5_server_handle_t handle
= server_handle
;
221 CHECK_HANDLE(server_handle
);
223 if((entry
== (kadm5_policy_ent_t
) NULL
) || (entry
->policy
== NULL
))
225 if(strlen(entry
->policy
) == 0)
226 return KADM5_BAD_POLICY
;
227 if((mask
& KADM5_POLICY
))
228 return KADM5_BAD_MASK
;
230 if ((ret
= krb5_db_get_policy(handle
->context
, entry
->policy
, &p
, &cnt
)))
233 return KADM5_UNK_POLICY
;
235 if ((mask
& KADM5_PW_MAX_LIFE
))
236 p
->pw_max_life
= entry
->pw_max_life
;
237 if ((mask
& KADM5_PW_MIN_LIFE
)) {
238 if(entry
->pw_min_life
> p
->pw_max_life
&& p
->pw_max_life
!= 0) {
239 krb5_db_free_policy(handle
->context
, p
);
240 return KADM5_BAD_MIN_PASS_LIFE
;
242 p
->pw_min_life
= entry
->pw_min_life
;
244 if ((mask
& KADM5_PW_MIN_LENGTH
)) {
245 if(entry
->pw_min_length
< MIN_PW_LENGTH
) {
246 krb5_db_free_policy(handle
->context
, p
);
247 return KADM5_BAD_LENGTH
;
249 p
->pw_min_length
= entry
->pw_min_length
;
251 if ((mask
& KADM5_PW_MIN_CLASSES
)) {
252 if(entry
->pw_min_classes
> MAX_PW_CLASSES
||
253 entry
->pw_min_classes
< MIN_PW_CLASSES
) {
254 krb5_db_free_policy(handle
->context
, p
);
255 return KADM5_BAD_CLASS
;
257 p
->pw_min_classes
= entry
->pw_min_classes
;
259 if ((mask
& KADM5_PW_HISTORY_NUM
)) {
260 if(entry
->pw_history_num
< MIN_PW_HISTORY
||
261 entry
->pw_history_num
> MAX_PW_HISTORY
) {
262 krb5_db_free_policy(handle
->context
, p
);
263 return KADM5_BAD_HISTORY
;
265 p
->pw_history_num
= entry
->pw_history_num
;
267 if ((mask
& KADM5_REF_COUNT
))
268 p
->policy_refcnt
= entry
->policy_refcnt
;
269 ret
= krb5_db_put_policy(handle
->context
, p
);
270 krb5_db_free_policy(handle
->context
, p
);
275 kadm5_get_policy(void *server_handle
, kadm5_policy_t name
,
276 kadm5_policy_ent_t entry
)
279 kadm5_policy_ent_rec entry_local
, **entry_orig
, *new;
281 kadm5_server_handle_t handle
= server_handle
;
284 CHECK_HANDLE(server_handle
);
286 krb5_clear_error_message(handle
->context
);
289 * In version 1, entry is a pointer to a kadm5_policy_ent_t that
290 * should be filled with allocated memory.
292 if (handle
->api_version
== KADM5_API_VERSION_1
) {
293 entry_orig
= (kadm5_policy_ent_rec
**) entry
;
295 entry
= &entry_local
;
298 if (name
== (kadm5_policy_t
) NULL
)
300 if(strlen(name
) == 0)
301 return KADM5_BAD_POLICY
;
302 if((ret
= krb5_db_get_policy(handle
->context
, name
, &t
, &cnt
)))
306 return KADM5_UNK_POLICY
;
308 if ((entry
->policy
= (char *) malloc(strlen(t
->name
) + 1)) == NULL
) {
309 krb5_db_free_policy(handle
->context
, t
);
312 strcpy(entry
->policy
, t
->name
);
313 entry
->pw_min_life
= t
->pw_min_life
;
314 entry
->pw_max_life
= t
->pw_max_life
;
315 entry
->pw_min_length
= t
->pw_min_length
;
316 entry
->pw_min_classes
= t
->pw_min_classes
;
317 entry
->pw_history_num
= t
->pw_history_num
;
318 entry
->policy_refcnt
= t
->policy_refcnt
;
319 krb5_db_free_policy(handle
->context
, t
);
321 if (handle
->api_version
== KADM5_API_VERSION_1
) {
322 new = (kadm5_policy_ent_t
) malloc(sizeof(kadm5_policy_ent_rec
));
325 krb5_db_free_policy(handle
->context
, t
);