1 /* $NetBSD: create_s.c,v 1.1.1.2 2014/04/24 12:45:48 pettai Exp $ */
4 * Copyright (c) 1997-2001 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include "kadm5_locl.h"
41 get_default(kadm5_server_context
*context
, krb5_principal princ
,
42 kadm5_principal_ent_t def
)
45 krb5_principal def_principal
;
46 krb5_const_realm realm
= krb5_principal_get_realm(context
->context
, princ
);
48 ret
= krb5_make_principal(context
->context
, &def_principal
,
49 realm
, "default", NULL
);
52 ret
= kadm5_s_get_principal(context
, def_principal
, def
,
53 KADM5_PRINCIPAL_NORMAL_MASK
);
54 krb5_free_principal (context
->context
, def_principal
);
59 create_principal(kadm5_server_context
*context
,
60 kadm5_principal_ent_t princ
,
63 uint32_t required_mask
,
64 uint32_t forbidden_mask
)
67 kadm5_principal_ent_rec defrec
, *defent
;
70 if((mask
& required_mask
) != required_mask
)
71 return KADM5_BAD_MASK
;
72 if((mask
& forbidden_mask
))
73 return KADM5_BAD_MASK
;
74 if((mask
& KADM5_POLICY
) && strcmp(princ
->policy
, "default"))
75 /* XXX no real policies for now */
76 return KADM5_UNK_POLICY
;
77 memset(ent
, 0, sizeof(*ent
));
78 ret
= krb5_copy_principal(context
->context
, princ
->principal
,
79 &ent
->entry
.principal
);
84 ret
= get_default(context
, princ
->principal
, defent
);
89 def_mask
= KADM5_ATTRIBUTES
| KADM5_MAX_LIFE
| KADM5_MAX_RLIFE
;
92 ret
= _kadm5_setup_entry(context
,
97 kadm5_free_principal_ent(context
, defent
);
101 ent
->entry
.created_by
.time
= time(NULL
);
103 return krb5_copy_principal(context
->context
, context
->caller
,
104 &ent
->entry
.created_by
.principal
);
108 kadm5_s_create_principal_with_key(void *server_handle
,
109 kadm5_principal_ent_t princ
,
114 kadm5_server_context
*context
= server_handle
;
116 ret
= create_principal(context
, princ
, mask
, &ent
,
117 KADM5_PRINCIPAL
| KADM5_KEY_DATA
,
118 KADM5_LAST_PWD_CHANGE
| KADM5_MOD_TIME
119 | KADM5_MOD_NAME
| KADM5_MKVNO
120 | KADM5_AUX_ATTRIBUTES
121 | KADM5_POLICY_CLR
| KADM5_LAST_SUCCESS
122 | KADM5_LAST_FAILED
| KADM5_FAIL_AUTH_COUNT
);
126 if ((mask
& KADM5_KVNO
) == 0)
129 ret
= hdb_seal_keys(context
->context
, context
->db
, &ent
.entry
);
133 ret
= context
->db
->hdb_open(context
->context
, context
->db
, O_RDWR
, 0);
136 ret
= context
->db
->hdb_store(context
->context
, context
->db
, 0, &ent
);
137 context
->db
->hdb_close(context
->context
, context
->db
);
140 kadm5_log_create (context
, &ent
.entry
);
143 hdb_free_entry(context
->context
, &ent
);
144 return _kadm5_error_code(ret
);
149 kadm5_s_create_principal(void *server_handle
,
150 kadm5_principal_ent_t princ
,
152 const char *password
)
156 kadm5_server_context
*context
= server_handle
;
158 ret
= create_principal(context
, princ
, mask
, &ent
,
160 KADM5_LAST_PWD_CHANGE
| KADM5_MOD_TIME
161 | KADM5_MOD_NAME
| KADM5_MKVNO
162 | KADM5_AUX_ATTRIBUTES
| KADM5_KEY_DATA
163 | KADM5_POLICY_CLR
| KADM5_LAST_SUCCESS
164 | KADM5_LAST_FAILED
| KADM5_FAIL_AUTH_COUNT
);
168 if ((mask
& KADM5_KVNO
) == 0)
171 ent
.entry
.keys
.len
= 0;
172 ent
.entry
.keys
.val
= NULL
;
174 ret
= _kadm5_set_keys(context
, &ent
.entry
, password
);
178 ret
= hdb_seal_keys(context
->context
, context
->db
, &ent
.entry
);
182 ret
= context
->db
->hdb_open(context
->context
, context
->db
, O_RDWR
, 0);
185 ret
= context
->db
->hdb_store(context
->context
, context
->db
, 0, &ent
);
186 context
->db
->hdb_close(context
->context
, context
->db
);
190 kadm5_log_create (context
, &ent
.entry
);
193 hdb_free_entry(context
->context
, &ent
);
194 return _kadm5_error_code(ret
);