2 Unix SMB/CIFS implementation.
4 Database Glue between Samba and the KDC
6 Copyright (C) Guenther Deschner <gd@samba.org> 2014
7 Copyright (C) Andreas Schneider <asn@samba.org> 2014
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "lib/krb5_wrap/krb5_samba.h"
29 #include "kdc/samba_kdc.h"
32 #define DBGC_CLASS DBGC_KERBEROS
34 static void sdb_flags_to_hdb_flags(const struct SDBFlags
*s
,
37 SMB_ASSERT(sizeof(struct SDBFlags
) == sizeof(HDBFlags
));
39 h
->initial
= s
->initial
;
40 h
->forwardable
= s
->forwardable
;
41 h
->proxiable
= s
->proxiable
;
42 h
->renewable
= s
->renewable
;
43 h
->postdate
= s
->postdate
;
44 h
->server
= s
->server
;
45 h
->client
= s
->client
;
46 h
->invalid
= s
->invalid
;
47 h
->require_preauth
= s
->require_preauth
;
48 h
->change_pw
= s
->change_pw
;
49 h
->require_hwauth
= s
->require_hwauth
;
50 h
->ok_as_delegate
= s
->ok_as_delegate
;
51 h
->user_to_user
= s
->user_to_user
;
52 h
->immutable
= s
->immutable
;
53 h
->trusted_for_delegation
= s
->trusted_for_delegation
;
54 h
->allow_kerberos4
= s
->allow_kerberos4
;
55 h
->allow_digest
= s
->allow_digest
;
56 h
->locked_out
= s
->locked_out
;
57 h
->require_pwchange
= s
->require_pwchange
;
58 h
->materialize
= s
->materialize
;
59 h
->virtual_keys
= s
->virtual_keys
;
60 h
->virtual = s
->virtual;
61 h
->synthetic
= s
->synthetic
;
62 h
->no_auth_data_reqd
= s
->no_auth_data_reqd
;
63 h
->_unused24
= s
->_unused24
;
64 h
->_unused25
= s
->_unused25
;
65 h
->_unused26
= s
->_unused26
;
66 h
->_unused27
= s
->_unused27
;
67 h
->_unused28
= s
->_unused28
;
68 h
->_unused29
= s
->_unused29
;
69 h
->force_canonicalize
= s
->force_canonicalize
;
70 h
->do_not_store
= s
->do_not_store
;
73 static int sdb_salt_to_Salt(const struct sdb_salt
*s
, Salt
*h
)
78 ret
= smb_krb5_copy_data_contents(&h
->salt
, s
->salt
.data
, s
->salt
.length
);
88 static int sdb_key_to_Key(const struct sdb_key
*s
, Key
*h
)
94 h
->key
.keytype
= s
->key
.keytype
;
95 rc
= smb_krb5_copy_data_contents(&h
->key
.keyvalue
,
97 s
->key
.keyvalue
.length
);
102 if (s
->salt
!= NULL
) {
103 h
->salt
= malloc(sizeof(Salt
));
104 if (h
->salt
== NULL
) {
108 rc
= sdb_salt_to_Salt(s
->salt
,
124 static int sdb_keys_to_Keys(const struct sdb_keys
*s
, Keys
*h
)
129 if (s
->val
!= NULL
) {
130 h
->val
= malloc(h
->len
* sizeof(Key
));
131 if (h
->val
== NULL
) {
134 for (i
= 0; i
< h
->len
; i
++) {
135 ret
= sdb_key_to_Key(&s
->val
[i
],
149 static int sdb_event_to_Event(krb5_context context
,
150 const struct sdb_event
*s
, Event
*h
)
154 if (s
->principal
!= NULL
) {
155 ret
= krb5_copy_principal(context
,
170 int sdb_entry_to_hdb_entry(krb5_context context
,
171 const struct sdb_entry
*s
,
174 struct samba_kdc_entry
*ske
= s
->skdc_entry
;
180 rc
= krb5_copy_principal(context
,
189 rc
= sdb_keys_to_Keys(&s
->keys
, &h
->keys
);
194 rc
= sdb_event_to_Event(context
,
201 if (s
->modified_by
) {
202 h
->modified_by
= malloc(sizeof(Event
));
203 if (h
->modified_by
== NULL
) {
208 rc
= sdb_event_to_Event(context
,
215 h
->modified_by
= NULL
;
218 if (s
->valid_start
!= NULL
) {
219 h
->valid_start
= malloc(sizeof(KerberosTime
));
220 if (h
->valid_start
== NULL
) {
224 *h
->valid_start
= *s
->valid_start
;
226 h
->valid_start
= NULL
;
229 if (s
->valid_end
!= NULL
) {
230 h
->valid_end
= malloc(sizeof(KerberosTime
));
231 if (h
->valid_end
== NULL
) {
235 *h
->valid_end
= *s
->valid_end
;
240 if (s
->pw_end
!= NULL
) {
241 h
->pw_end
= malloc(sizeof(KerberosTime
));
242 if (h
->pw_end
== NULL
) {
246 *h
->pw_end
= *s
->pw_end
;
251 if (s
->max_life
!= NULL
) {
252 h
->max_life
= malloc(sizeof(unsigned int));
253 if (h
->max_life
== NULL
) {
257 *h
->max_life
= *s
->max_life
;
262 if (s
->max_renew
!= NULL
) {
263 h
->max_renew
= malloc(sizeof(unsigned int));
264 if (h
->max_renew
== NULL
) {
268 *h
->max_renew
= *s
->max_renew
;
273 sdb_flags_to_hdb_flags(&s
->flags
, &h
->flags
);
276 if (h
->keys
.val
!= NULL
) {
277 h
->etypes
= malloc(sizeof(*h
->etypes
));
278 if (h
->etypes
== NULL
) {
283 h
->etypes
->len
= s
->keys
.len
;
285 h
->etypes
->val
= calloc(h
->etypes
->len
, sizeof(int));
286 if (h
->etypes
->val
== NULL
) {
291 for (i
= 0; i
< h
->etypes
->len
; i
++) {
292 Key k
= h
->keys
.val
[i
];
294 h
->etypes
->val
[i
] = KRB5_KEY_TYPE(&(k
.key
));