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 #if !defined(lint) && !defined(__CODECENTER__)
26 static char *rcsid
= "$Header$";
29 #include "server_internal.h"
30 #include <sys/types.h>
31 #include <kadm5/admin.h>
35 #define MAX_PW_HISTORY 10
36 #define MIN_PW_HISTORY 1
37 #define MIN_PW_CLASSES 1
38 #define MAX_PW_CLASSES 5
39 #define MIN_PW_LENGTH 1
42 * Function: kadm5_create_policy
44 * Purpose: Create Policies in the policy DB.
47 * entry (input) The policy entry to be written out to the DB.
48 * mask (input) Specifies which fields in entry are to ge written out
49 * and which get default values.
50 * <return value> 0 if successful otherwise an error code is returned.
53 * Entry must be a valid principal entry, and mask have a valid value.
56 * Verifies that mask does not specify that the refcount should
57 * be set as part of the creation, and calls
58 * kadm5_create_policy_internal. If the refcount *is*
59 * specified, returns KADM5_BAD_MASK.
63 kadm5_create_policy(void *server_handle
,
64 kadm5_policy_ent_t entry
, long mask
)
66 CHECK_HANDLE(server_handle
);
68 krb5_clear_error_message(((kadm5_server_handle_t
)server_handle
)->context
);
70 if (mask
& KADM5_REF_COUNT
)
71 return KADM5_BAD_MASK
;
73 return kadm5_create_policy_internal(server_handle
, entry
, mask
);
77 * Function: kadm5_create_policy_internal
79 * Purpose: Create Policies in the policy DB.
82 * entry (input) The policy entry to be written out to the DB.
83 * mask (input) Specifies which fields in entry are to ge written out
84 * and which get default values.
85 * <return value> 0 if successful otherwise an error code is returned.
88 * Entry must be a valid principal entry, and mask have a valid value.
91 * Writes the data to the database, and does a database sync if
97 kadm5_create_policy_internal(void *server_handle
,
98 kadm5_policy_ent_t entry
, long mask
)
100 kadm5_server_handle_t handle
= server_handle
;
101 osa_policy_ent_rec pent
;
105 CHECK_HANDLE(server_handle
);
107 if ((entry
== (kadm5_policy_ent_t
) NULL
) || (entry
->policy
== NULL
))
109 if(strlen(entry
->policy
) == 0)
110 return KADM5_BAD_POLICY
;
111 if (!(mask
& KADM5_POLICY
))
112 return KADM5_BAD_MASK
;
114 pent
.name
= entry
->policy
;
117 if(*p
< ' ' || *p
> '~')
118 return KADM5_BAD_POLICY
;
122 if (!(mask
& KADM5_PW_MAX_LIFE
))
123 pent
.pw_max_life
= 0;
125 pent
.pw_max_life
= entry
->pw_max_life
;
126 if (!(mask
& KADM5_PW_MIN_LIFE
))
127 pent
.pw_min_life
= 0;
129 if((mask
& KADM5_PW_MAX_LIFE
)) {
130 if(entry
->pw_min_life
> entry
->pw_max_life
&& entry
->pw_max_life
!= 0)
131 return KADM5_BAD_MIN_PASS_LIFE
;
133 pent
.pw_min_life
= entry
->pw_min_life
;
135 if (!(mask
& KADM5_PW_MIN_LENGTH
))
136 pent
.pw_min_length
= MIN_PW_LENGTH
;
138 if(entry
->pw_min_length
< MIN_PW_LENGTH
)
139 return KADM5_BAD_LENGTH
;
140 pent
.pw_min_length
= entry
->pw_min_length
;
142 if (!(mask
& KADM5_PW_MIN_CLASSES
))
143 pent
.pw_min_classes
= MIN_PW_CLASSES
;
145 if(entry
->pw_min_classes
> MAX_PW_CLASSES
|| entry
->pw_min_classes
< MIN_PW_CLASSES
)
146 return KADM5_BAD_CLASS
;
147 pent
.pw_min_classes
= entry
->pw_min_classes
;
149 if (!(mask
& KADM5_PW_HISTORY_NUM
))
150 pent
.pw_history_num
= MIN_PW_HISTORY
;
152 if(entry
->pw_history_num
< MIN_PW_HISTORY
||
153 entry
->pw_history_num
> MAX_PW_HISTORY
)
154 return KADM5_BAD_HISTORY
;
156 pent
.pw_history_num
= entry
->pw_history_num
;
158 if (!(mask
& KADM5_REF_COUNT
))
159 pent
.policy_refcnt
= 0;
161 pent
.policy_refcnt
= entry
->policy_refcnt
;
162 if ((ret
= krb5_db_create_policy(handle
->context
, &pent
)))
169 kadm5_delete_policy(void *server_handle
, kadm5_policy_t name
)
171 kadm5_server_handle_t handle
= server_handle
;
172 osa_policy_ent_t entry
;
176 CHECK_HANDLE(server_handle
);
178 krb5_clear_error_message(handle
->context
);
180 if(name
== (kadm5_policy_t
) NULL
)
182 if(strlen(name
) == 0)
183 return KADM5_BAD_POLICY
;
184 if((ret
= krb5_db_get_policy(handle
->context
, name
, &entry
,&cnt
)))
187 return KADM5_UNK_POLICY
;
189 if(entry
->policy_refcnt
!= 0) {
190 krb5_db_free_policy(handle
->context
, entry
);
191 return KADM5_POLICY_REF
;
193 krb5_db_free_policy(handle
->context
, entry
);
194 if ((ret
= krb5_db_delete_policy(handle
->context
, name
)))
201 kadm5_modify_policy(void *server_handle
,
202 kadm5_policy_ent_t entry
, long mask
)
204 CHECK_HANDLE(server_handle
);
206 krb5_clear_error_message(((kadm5_server_handle_t
)server_handle
)->context
);
208 if (mask
& KADM5_REF_COUNT
)
209 return KADM5_BAD_MASK
;
211 return kadm5_modify_policy_internal(server_handle
, entry
, mask
);
215 kadm5_modify_policy_internal(void *server_handle
,
216 kadm5_policy_ent_t entry
, long mask
)
218 kadm5_server_handle_t handle
= server_handle
;
223 CHECK_HANDLE(server_handle
);
225 if((entry
== (kadm5_policy_ent_t
) NULL
) || (entry
->policy
== NULL
))
227 if(strlen(entry
->policy
) == 0)
228 return KADM5_BAD_POLICY
;
229 if((mask
& KADM5_POLICY
))
230 return KADM5_BAD_MASK
;
232 if ((ret
= krb5_db_get_policy(handle
->context
, entry
->policy
, &p
, &cnt
)))
235 return KADM5_UNK_POLICY
;
237 if ((mask
& KADM5_PW_MAX_LIFE
))
238 p
->pw_max_life
= entry
->pw_max_life
;
239 if ((mask
& KADM5_PW_MIN_LIFE
)) {
240 if(entry
->pw_min_life
> p
->pw_max_life
&& p
->pw_max_life
!= 0) {
241 krb5_db_free_policy(handle
->context
, p
);
242 return KADM5_BAD_MIN_PASS_LIFE
;
244 p
->pw_min_life
= entry
->pw_min_life
;
246 if ((mask
& KADM5_PW_MIN_LENGTH
)) {
247 if(entry
->pw_min_length
< MIN_PW_LENGTH
) {
248 krb5_db_free_policy(handle
->context
, p
);
249 return KADM5_BAD_LENGTH
;
251 p
->pw_min_length
= entry
->pw_min_length
;
253 if ((mask
& KADM5_PW_MIN_CLASSES
)) {
254 if(entry
->pw_min_classes
> MAX_PW_CLASSES
||
255 entry
->pw_min_classes
< MIN_PW_CLASSES
) {
256 krb5_db_free_policy(handle
->context
, p
);
257 return KADM5_BAD_CLASS
;
259 p
->pw_min_classes
= entry
->pw_min_classes
;
261 if ((mask
& KADM5_PW_HISTORY_NUM
)) {
262 if(entry
->pw_history_num
< MIN_PW_HISTORY
||
263 entry
->pw_history_num
> MAX_PW_HISTORY
) {
264 krb5_db_free_policy(handle
->context
, p
);
265 return KADM5_BAD_HISTORY
;
267 p
->pw_history_num
= entry
->pw_history_num
;
269 if ((mask
& KADM5_REF_COUNT
))
270 p
->policy_refcnt
= entry
->policy_refcnt
;
271 ret
= krb5_db_put_policy(handle
->context
, p
);
272 krb5_db_free_policy(handle
->context
, p
);
277 kadm5_get_policy(void *server_handle
, kadm5_policy_t name
,
278 kadm5_policy_ent_t entry
)
281 kadm5_policy_ent_rec entry_local
, **entry_orig
, *new;
283 kadm5_server_handle_t handle
= server_handle
;
286 CHECK_HANDLE(server_handle
);
288 krb5_clear_error_message(handle
->context
);
291 * In version 1, entry is a pointer to a kadm5_policy_ent_t that
292 * should be filled with allocated memory.
294 if (handle
->api_version
== KADM5_API_VERSION_1
) {
295 entry_orig
= (kadm5_policy_ent_rec
**) entry
;
297 entry
= &entry_local
;
300 if (name
== (kadm5_policy_t
) NULL
)
302 if(strlen(name
) == 0)
303 return KADM5_BAD_POLICY
;
304 if((ret
= krb5_db_get_policy(handle
->context
, name
, &t
, &cnt
)))
308 return KADM5_UNK_POLICY
;
310 if ((entry
->policy
= (char *) malloc(strlen(t
->name
) + 1)) == NULL
) {
311 krb5_db_free_policy(handle
->context
, t
);
314 strcpy(entry
->policy
, t
->name
);
315 entry
->pw_min_life
= t
->pw_min_life
;
316 entry
->pw_max_life
= t
->pw_max_life
;
317 entry
->pw_min_length
= t
->pw_min_length
;
318 entry
->pw_min_classes
= t
->pw_min_classes
;
319 entry
->pw_history_num
= t
->pw_history_num
;
320 entry
->policy_refcnt
= t
->policy_refcnt
;
321 krb5_db_free_policy(handle
->context
, t
);
323 if (handle
->api_version
== KADM5_API_VERSION_1
) {
324 new = (kadm5_policy_ent_t
) malloc(sizeof(kadm5_policy_ent_rec
));
327 krb5_db_free_policy(handle
->context
, t
);