2 * Copyright (c) 1999-2001, 2003, PADL Software Pty Ltd.
3 * Copyright (c) 2004-2009, Andrew Bartlett <abartlet@samba.org>.
4 * Copyright (c) 2004, Stefan Metzmacher <metze@samba.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of PADL Software nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include "system/time.h"
37 #include "dsdb/common/flags.h"
38 #include "lib/ldb/include/ldb.h"
39 #include "lib/ldb/include/ldb_errors.h"
40 #include "librpc/gen_ndr/netlogon.h"
41 #include "libcli/security/security.h"
42 #include "auth/auth.h"
43 #include "auth/credentials/credentials.h"
44 #include "auth/auth_sam.h"
45 #include "../lib/util/util_ldb.h"
46 #include "dsdb/samdb/samdb.h"
47 #include "librpc/ndr/libndr.h"
48 #include "librpc/gen_ndr/ndr_drsblobs.h"
49 #include "librpc/gen_ndr/lsa.h"
50 #include "libcli/auth/libcli_auth.h"
51 #include "param/param.h"
52 #include "events/events.h"
54 #include "../lib/crypto/md4.h"
57 { HDB_SAMBA4_ENT_TYPE_CLIENT
, HDB_SAMBA4_ENT_TYPE_SERVER
,
58 HDB_SAMBA4_ENT_TYPE_KRBTGT
, HDB_SAMBA4_ENT_TYPE_TRUST
, HDB_SAMBA4_ENT_TYPE_ANY
};
60 enum trust_direction
{
62 INBOUND
= LSA_TRUST_DIRECTION_INBOUND
,
63 OUTBOUND
= LSA_TRUST_DIRECTION_OUTBOUND
66 static const char *trust_attrs
[] = {
71 "msDS-SupportedEncryptionTypes",
78 static KerberosTime
ldb_msg_find_krb5time_ldap_time(struct ldb_message
*msg
, const char *attr
, KerberosTime default_val
)
84 gentime
= ldb_msg_find_attr_as_string(msg
, attr
, NULL
);
88 tmp
= strptime(gentime
, "%Y%m%d%H%M%SZ", &tm
);
96 static HDBFlags
uf2HDBFlags(krb5_context context
, int userAccountControl
, enum hdb_ldb_ent_type ent_type
)
98 HDBFlags flags
= int2HDBFlags(0);
100 /* we don't allow kadmin deletes */
103 /* mark the principal as invalid to start with */
108 /* All accounts are servers, but this may be disabled again in the caller */
111 /* Account types - clear the invalid bit if it turns out to be valid */
112 if (userAccountControl
& UF_NORMAL_ACCOUNT
) {
113 if (ent_type
== HDB_SAMBA4_ENT_TYPE_CLIENT
|| ent_type
== HDB_SAMBA4_ENT_TYPE_ANY
) {
119 if (userAccountControl
& UF_INTERDOMAIN_TRUST_ACCOUNT
) {
120 if (ent_type
== HDB_SAMBA4_ENT_TYPE_CLIENT
|| ent_type
== HDB_SAMBA4_ENT_TYPE_ANY
) {
125 if (userAccountControl
& UF_WORKSTATION_TRUST_ACCOUNT
) {
126 if (ent_type
== HDB_SAMBA4_ENT_TYPE_CLIENT
|| ent_type
== HDB_SAMBA4_ENT_TYPE_ANY
) {
131 if (userAccountControl
& UF_SERVER_TRUST_ACCOUNT
) {
132 if (ent_type
== HDB_SAMBA4_ENT_TYPE_CLIENT
|| ent_type
== HDB_SAMBA4_ENT_TYPE_ANY
) {
138 /* Not permitted to act as a client if disabled */
139 if (userAccountControl
& UF_ACCOUNTDISABLE
) {
142 if (userAccountControl
& UF_LOCKOUT
) {
146 if (userAccountControl & UF_PASSWORD_NOTREQD) {
151 UF_PASSWORD_CANT_CHANGE and UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED are irrelevent
153 if (userAccountControl
& UF_TEMP_DUPLICATE_ACCOUNT
) {
157 /* UF_DONT_EXPIRE_PASSWD and UF_USE_DES_KEY_ONLY handled in LDB_message2entry() */
160 if (userAccountControl & UF_MNS_LOGON_ACCOUNT) {
164 if (userAccountControl
& UF_SMARTCARD_REQUIRED
) {
165 flags
.require_hwauth
= 1;
167 if (userAccountControl
& UF_TRUSTED_FOR_DELEGATION
) {
168 flags
.ok_as_delegate
= 1;
170 if (!(userAccountControl
& UF_NOT_DELEGATED
)) {
171 flags
.forwardable
= 1;
175 if (userAccountControl
& UF_DONT_REQUIRE_PREAUTH
) {
176 flags
.require_preauth
= 0;
178 flags
.require_preauth
= 1;
184 static int hdb_ldb_destructor(struct hdb_ldb_private
*p
)
186 hdb_entry_ex
*entry_ex
= p
->entry_ex
;
187 free_hdb_entry(&entry_ex
->entry
);
191 static void hdb_ldb_free_entry(krb5_context context
, hdb_entry_ex
*entry_ex
)
193 talloc_free(entry_ex
->ctx
);
196 static krb5_error_code
LDB_message2entry_keys(krb5_context context
,
197 struct smb_iconv_convenience
*iconv_convenience
,
199 struct ldb_message
*msg
,
200 unsigned int userAccountControl
,
201 hdb_entry_ex
*entry_ex
)
203 krb5_error_code ret
= 0;
204 enum ndr_err_code ndr_err
;
205 struct samr_Password
*hash
;
206 const struct ldb_val
*sc_val
;
207 struct supplementalCredentialsBlob scb
;
208 struct supplementalCredentialsPackage
*scpk
= NULL
;
209 bool newer_keys
= false;
210 struct package_PrimaryKerberosBlob _pkb
;
211 struct package_PrimaryKerberosCtr3
*pkb3
= NULL
;
212 struct package_PrimaryKerberosCtr4
*pkb4
= NULL
;
214 uint32_t allocated_keys
= 0;
216 entry_ex
->entry
.keys
.val
= NULL
;
217 entry_ex
->entry
.keys
.len
= 0;
219 entry_ex
->entry
.kvno
= ldb_msg_find_attr_as_int(msg
, "msDS-KeyVersionNumber", 0);
221 /* Get keys from the db */
223 hash
= samdb_result_hash(mem_ctx
, msg
, "unicodePwd");
224 sc_val
= ldb_msg_find_ldb_val(msg
, "supplementalCredentials");
226 /* unicodePwd for enctype 0x17 (23) if present */
231 /* supplementalCredentials if present */
233 ndr_err
= ndr_pull_struct_blob_all(sc_val
, mem_ctx
, iconv_convenience
, &scb
,
234 (ndr_pull_flags_fn_t
)ndr_pull_supplementalCredentialsBlob
);
235 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
236 dump_data(0, sc_val
->data
, sc_val
->length
);
241 if (scb
.sub
.signature
!= SUPPLEMENTAL_CREDENTIALS_SIGNATURE
) {
242 NDR_PRINT_DEBUG(supplementalCredentialsBlob
, &scb
);
247 for (i
=0; i
< scb
.sub
.num_packages
; i
++) {
248 if (strcmp("Primary:Kerberos-Newer-Keys", scb
.sub
.packages
[i
].name
) == 0) {
249 scpk
= &scb
.sub
.packages
[i
];
250 if (!scpk
->data
|| !scpk
->data
[0]) {
256 } else if (strcmp("Primary:Kerberos", scb
.sub
.packages
[i
].name
) == 0) {
257 scpk
= &scb
.sub
.packages
[i
];
258 if (!scpk
->data
|| !scpk
->data
[0]) {
262 * we don't break here in hope to find
263 * a Kerberos-Newer-Keys package
269 * Primary:Kerberos-Newer-Keys or Primary:Kerberos element
270 * of supplementalCredentials
275 blob
= strhex_to_data_blob(mem_ctx
, scpk
->data
);
281 /* we cannot use ndr_pull_struct_blob_all() here, as w2k and w2k3 add padding bytes */
282 ndr_err
= ndr_pull_struct_blob(&blob
, mem_ctx
, iconv_convenience
, &_pkb
,
283 (ndr_pull_flags_fn_t
)ndr_pull_package_PrimaryKerberosBlob
);
284 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
285 krb5_set_error_string(context
, "LDB_message2entry_keys: could not parse package_PrimaryKerberosBlob");
286 krb5_warnx(context
, "LDB_message2entry_keys: could not parse package_PrimaryKerberosBlob");
291 if (newer_keys
&& _pkb
.version
!= 4) {
292 krb5_set_error_string(context
, "LDB_message2entry_keys: Primary:Kerberos-Newer-Keys not version 4");
293 krb5_warnx(context
, "LDB_message2entry_keys: Primary:Kerberos-Newer-Keys not version 4");
298 if (!newer_keys
&& _pkb
.version
!= 3) {
299 krb5_set_error_string(context
, "LDB_message2entry_keys: could not parse Primary:Kerberos not version 3");
300 krb5_warnx(context
, "LDB_message2entry_keys: could not parse Primary:Kerberos not version 3");
305 if (_pkb
.version
== 4) {
306 pkb4
= &_pkb
.ctr
.ctr4
;
307 allocated_keys
+= pkb4
->num_keys
;
308 } else if (_pkb
.version
== 3) {
309 pkb3
= &_pkb
.ctr
.ctr3
;
310 allocated_keys
+= pkb3
->num_keys
;
314 if (allocated_keys
== 0) {
315 /* oh, no password. Apparently (comment in
316 * hdb-ldap.c) this violates the ASN.1, but this
317 * allows an entry with no keys (yet). */
321 /* allocate space to decode into */
322 entry_ex
->entry
.keys
.len
= 0;
323 entry_ex
->entry
.keys
.val
= calloc(allocated_keys
, sizeof(Key
));
324 if (entry_ex
->entry
.keys
.val
== NULL
) {
329 if (hash
&& !(userAccountControl
& UF_USE_DES_KEY_ONLY
)) {
333 key
.salt
= NULL
; /* No salt for this enc type */
335 ret
= krb5_keyblock_init(context
,
336 ENCTYPE_ARCFOUR_HMAC_MD5
,
337 hash
->hash
, sizeof(hash
->hash
),
343 entry_ex
->entry
.keys
.val
[entry_ex
->entry
.keys
.len
] = key
;
344 entry_ex
->entry
.keys
.len
++;
348 for (i
=0; i
< pkb4
->num_keys
; i
++) {
352 if (!pkb4
->keys
[i
].value
) continue;
354 if (userAccountControl
& UF_USE_DES_KEY_ONLY
) {
355 switch (pkb4
->keys
[i
].keytype
) {
356 case ENCTYPE_DES_CBC_CRC
:
357 case ENCTYPE_DES_CBC_MD5
:
370 if (pkb4
->salt
.string
) {
373 salt
= data_blob_string_const(pkb4
->salt
.string
);
375 key
.salt
= calloc(1, sizeof(*key
.salt
));
376 if (key
.salt
== NULL
) {
381 key
.salt
->type
= hdb_pw_salt
;
383 ret
= krb5_data_copy(&key
.salt
->salt
, salt
.data
, salt
.length
);
391 /* TODO: maybe pass the iteration_count somehow... */
393 ret
= krb5_keyblock_init(context
,
394 pkb4
->keys
[i
].keytype
,
395 pkb4
->keys
[i
].value
->data
,
396 pkb4
->keys
[i
].value
->length
,
407 entry_ex
->entry
.keys
.val
[entry_ex
->entry
.keys
.len
] = key
;
408 entry_ex
->entry
.keys
.len
++;
411 for (i
=0; i
< pkb3
->num_keys
; i
++) {
415 if (!pkb3
->keys
[i
].value
) continue;
417 if (userAccountControl
& UF_USE_DES_KEY_ONLY
) {
418 switch (pkb3
->keys
[i
].keytype
) {
419 case ENCTYPE_DES_CBC_CRC
:
420 case ENCTYPE_DES_CBC_MD5
:
433 if (pkb3
->salt
.string
) {
436 salt
= data_blob_string_const(pkb3
->salt
.string
);
438 key
.salt
= calloc(1, sizeof(*key
.salt
));
439 if (key
.salt
== NULL
) {
444 key
.salt
->type
= hdb_pw_salt
;
446 ret
= krb5_data_copy(&key
.salt
->salt
, salt
.data
, salt
.length
);
454 ret
= krb5_keyblock_init(context
,
455 pkb3
->keys
[i
].keytype
,
456 pkb3
->keys
[i
].value
->data
,
457 pkb3
->keys
[i
].value
->length
,
468 entry_ex
->entry
.keys
.val
[entry_ex
->entry
.keys
.len
] = key
;
469 entry_ex
->entry
.keys
.len
++;
475 entry_ex
->entry
.keys
.len
= 0;
477 if (entry_ex
->entry
.keys
.len
== 0 && entry_ex
->entry
.keys
.val
) {
478 free(entry_ex
->entry
.keys
.val
);
479 entry_ex
->entry
.keys
.val
= NULL
;
485 * Construct an hdb_entry from a directory entry.
487 static krb5_error_code
LDB_message2entry(krb5_context context
, HDB
*db
,
488 TALLOC_CTX
*mem_ctx
, krb5_const_principal principal
,
489 enum hdb_ldb_ent_type ent_type
,
490 struct ldb_dn
*realm_dn
,
491 struct ldb_message
*msg
,
492 hdb_entry_ex
*entry_ex
)
494 unsigned int userAccountControl
;
496 krb5_error_code ret
= 0;
497 krb5_boolean is_computer
= FALSE
;
498 struct loadparm_context
*lp_ctx
= ldb_get_opaque((struct ldb_context
*)db
->hdb_db
, "loadparm");
499 char *realm
= strupper_talloc(mem_ctx
, lp_realm(lp_ctx
));
501 struct hdb_ldb_private
*p
;
506 struct ldb_message_element
*objectclasses
;
507 struct ldb_val computer_val
;
508 const char *samAccountName
= ldb_msg_find_attr_as_string(msg
, "samAccountName", NULL
);
509 computer_val
.data
= discard_const_p(uint8_t,"computer");
510 computer_val
.length
= strlen((const char *)computer_val
.data
);
512 if (!samAccountName
) {
513 krb5_set_error_string(context
, "LDB_message2entry: no samAccountName present");
518 objectclasses
= ldb_msg_find_element(msg
, "objectClass");
520 if (objectclasses
&& ldb_msg_find_val(objectclasses
, &computer_val
)) {
524 memset(entry_ex
, 0, sizeof(*entry_ex
));
527 krb5_set_error_string(context
, "talloc_strdup: out of memory");
532 p
= talloc(mem_ctx
, struct hdb_ldb_private
);
538 p
->entry_ex
= entry_ex
;
539 p
->iconv_convenience
= lp_iconv_convenience(lp_ctx
);
541 p
->realm_dn
= talloc_reference(p
, realm_dn
);
547 talloc_set_destructor(p
, hdb_ldb_destructor
);
550 entry_ex
->free_entry
= hdb_ldb_free_entry
;
552 userAccountControl
= ldb_msg_find_attr_as_uint(msg
, "userAccountControl", 0);
555 entry_ex
->entry
.principal
= malloc(sizeof(*(entry_ex
->entry
.principal
)));
556 if (ent_type
== HDB_SAMBA4_ENT_TYPE_ANY
&& principal
== NULL
) {
557 krb5_make_principal(context
, &entry_ex
->entry
.principal
, realm
, samAccountName
, NULL
);
560 ret
= copy_Principal(principal
, entry_ex
->entry
.principal
);
562 krb5_clear_error_string(context
);
566 /* While we have copied the client principal, tests
567 * show that Win2k3 returns the 'corrected' realm, not
568 * the client-specified realm. This code attempts to
569 * replace the client principal's realm with the one
570 * we determine from our records */
572 /* this has to be with malloc() */
573 strdup_realm
= strdup(realm
);
576 krb5_clear_error_string(context
);
579 free(*krb5_princ_realm(context
, entry_ex
->entry
.principal
));
580 krb5_princ_set_realm(context
, entry_ex
->entry
.principal
, &strdup_realm
);
583 /* First try and figure out the flags based on the userAccountControl */
584 entry_ex
->entry
.flags
= uf2HDBFlags(context
, userAccountControl
, ent_type
);
586 /* Windows 2008 seems to enforce this (very sensible) rule by
587 * default - don't allow offline attacks on a user's password
588 * by asking for a ticket to them as a service (encrypted with
589 * their probably patheticly insecure password) */
591 if (entry_ex
->entry
.flags
.server
592 && lp_parm_bool(lp_ctx
, NULL
, "kdc", "require spn for service", true)) {
593 if (!is_computer
&& !ldb_msg_find_attr_as_string(msg
, "servicePrincipalName", NULL
)) {
594 entry_ex
->entry
.flags
.server
= 0;
599 /* These (created_by, modified_by) parts of the entry are not relevant for Samba4's use
600 * of the Heimdal KDC. They are stored in a the traditional
601 * DB for audit purposes, and still form part of the structure
604 /* use 'whenCreated' */
605 entry_ex
->entry
.created_by
.time
= ldb_msg_find_krb5time_ldap_time(msg
, "whenCreated", 0);
607 entry_ex
->entry
.created_by
.principal
= NULL
;
609 entry_ex
->entry
.modified_by
= (Event
*) malloc(sizeof(Event
));
610 if (entry_ex
->entry
.modified_by
== NULL
) {
611 krb5_set_error_string(context
, "malloc: out of memory");
616 /* use 'whenChanged' */
617 entry_ex
->entry
.modified_by
->time
= ldb_msg_find_krb5time_ldap_time(msg
, "whenChanged", 0);
619 entry_ex
->entry
.modified_by
->principal
= NULL
;
623 /* The lack of password controls etc applies to krbtgt by
624 * virtue of being that particular RID */
625 status
= dom_sid_split_rid(NULL
, samdb_result_dom_sid(mem_ctx
, msg
, "objectSid"), NULL
, &rid
);
627 if (!NT_STATUS_IS_OK(status
)) {
632 if (rid
== DOMAIN_RID_KRBTGT
) {
633 entry_ex
->entry
.valid_end
= NULL
;
634 entry_ex
->entry
.pw_end
= NULL
;
636 entry_ex
->entry
.flags
.invalid
= 0;
637 entry_ex
->entry
.flags
.server
= 1;
638 entry_ex
->entry
.flags
.change_pw
= 1;
639 entry_ex
->entry
.flags
.client
= 0;
640 entry_ex
->entry
.flags
.forwardable
= 1;
641 entry_ex
->entry
.flags
.ok_as_delegate
= 1;
642 } else if (entry_ex
->entry
.flags
.server
&& ent_type
== HDB_SAMBA4_ENT_TYPE_SERVER
) {
643 /* The account/password expiry only applies when the account is used as a
644 * client (ie password login), not when used as a server */
646 /* Make very well sure we don't use this for a client,
647 * it could bypass the password restrictions */
648 entry_ex
->entry
.flags
.client
= 0;
650 entry_ex
->entry
.valid_end
= NULL
;
651 entry_ex
->entry
.pw_end
= NULL
;
654 NTTIME must_change_time
655 = samdb_result_force_password_change((struct ldb_context
*)db
->hdb_db
, mem_ctx
,
657 if (must_change_time
== 0x7FFFFFFFFFFFFFFFULL
) {
658 entry_ex
->entry
.pw_end
= NULL
;
660 entry_ex
->entry
.pw_end
= malloc(sizeof(*entry_ex
->entry
.pw_end
));
661 if (entry_ex
->entry
.pw_end
== NULL
) {
665 *entry_ex
->entry
.pw_end
= nt_time_to_unix(must_change_time
);
668 acct_expiry
= samdb_result_account_expires(msg
);
669 if (acct_expiry
== 0x7FFFFFFFFFFFFFFFULL
) {
670 entry_ex
->entry
.valid_end
= NULL
;
672 entry_ex
->entry
.valid_end
= malloc(sizeof(*entry_ex
->entry
.valid_end
));
673 if (entry_ex
->entry
.valid_end
== NULL
) {
677 *entry_ex
->entry
.valid_end
= nt_time_to_unix(acct_expiry
);
681 entry_ex
->entry
.valid_start
= NULL
;
683 entry_ex
->entry
.max_life
= NULL
;
685 entry_ex
->entry
.max_renew
= NULL
;
687 entry_ex
->entry
.generation
= NULL
;
689 /* Get keys from the db */
690 ret
= LDB_message2entry_keys(context
, p
->iconv_convenience
, p
, msg
, userAccountControl
, entry_ex
);
692 /* Could be bougus data in the entry, or out of memory */
696 entry_ex
->entry
.etypes
= malloc(sizeof(*(entry_ex
->entry
.etypes
)));
697 if (entry_ex
->entry
.etypes
== NULL
) {
698 krb5_clear_error_string(context
);
702 entry_ex
->entry
.etypes
->len
= entry_ex
->entry
.keys
.len
;
703 entry_ex
->entry
.etypes
->val
= calloc(entry_ex
->entry
.etypes
->len
, sizeof(int));
704 if (entry_ex
->entry
.etypes
->val
== NULL
) {
705 krb5_clear_error_string(context
);
709 for (i
=0; i
< entry_ex
->entry
.etypes
->len
; i
++) {
710 entry_ex
->entry
.etypes
->val
[i
] = entry_ex
->entry
.keys
.val
[i
].key
.keytype
;
714 p
->msg
= talloc_steal(p
, msg
);
715 p
->samdb
= (struct ldb_context
*)db
->hdb_db
;
719 /* This doesn't free ent itself, that is for the eventual caller to do */
720 hdb_free_entry(context
, entry_ex
);
722 talloc_steal(db
, entry_ex
->ctx
);
729 * Construct an hdb_entry from a directory entry.
731 static krb5_error_code
LDB_trust_message2entry(krb5_context context
, HDB
*db
,
732 struct loadparm_context
*lp_ctx
,
733 TALLOC_CTX
*mem_ctx
, krb5_const_principal principal
,
734 enum trust_direction direction
,
735 struct ldb_dn
*realm_dn
,
736 struct ldb_message
*msg
,
737 hdb_entry_ex
*entry_ex
)
740 const char *dnsdomain
;
743 DATA_BLOB password_utf16
;
744 struct samr_Password password_hash
;
745 const struct ldb_val
*password_val
;
746 struct trustAuthInOutBlob password_blob
;
747 struct hdb_ldb_private
*p
;
749 enum ndr_err_code ndr_err
;
750 int i
, ret
, trust_direction_flags
;
752 p
= talloc(mem_ctx
, struct hdb_ldb_private
);
758 p
->entry_ex
= entry_ex
;
759 p
->iconv_convenience
= lp_iconv_convenience(lp_ctx
);
761 p
->realm_dn
= realm_dn
;
763 talloc_set_destructor(p
, hdb_ldb_destructor
);
766 entry_ex
->free_entry
= hdb_ldb_free_entry
;
768 /* use 'whenCreated' */
769 entry_ex
->entry
.created_by
.time
= ldb_msg_find_krb5time_ldap_time(msg
, "whenCreated", 0);
771 entry_ex
->entry
.created_by
.principal
= NULL
;
773 entry_ex
->entry
.valid_start
= NULL
;
775 trust_direction_flags
= ldb_msg_find_attr_as_int(msg
, "trustDirection", 0);
777 if (direction
== INBOUND
) {
778 realm
= strupper_talloc(mem_ctx
, lp_realm(lp_ctx
));
779 password_val
= ldb_msg_find_ldb_val(msg
, "trustAuthIncoming");
781 } else { /* OUTBOUND */
782 dnsdomain
= ldb_msg_find_attr_as_string(msg
, "trustPartner", NULL
);
783 realm
= strupper_talloc(mem_ctx
, dnsdomain
);
784 password_val
= ldb_msg_find_ldb_val(msg
, "trustAuthOutgoing");
787 if (!password_val
|| !(trust_direction_flags
& direction
)) {
792 ndr_err
= ndr_pull_struct_blob(password_val
, mem_ctx
, p
->iconv_convenience
, &password_blob
,
793 (ndr_pull_flags_fn_t
)ndr_pull_trustAuthInOutBlob
);
794 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
799 entry_ex
->entry
.kvno
= -1;
800 for (i
=0; i
< password_blob
.count
; i
++) {
801 if (password_blob
.current
->array
[i
].AuthType
== TRUST_AUTH_TYPE_VERSION
) {
802 entry_ex
->entry
.kvno
= password_blob
.current
->array
[i
].AuthInfo
.version
.version
;
806 for (i
=0; i
< password_blob
.count
; i
++) {
807 if (password_blob
.current
->array
[i
].AuthType
== TRUST_AUTH_TYPE_CLEAR
) {
808 password_utf16
= data_blob_const(password_blob
.current
->array
[i
].AuthInfo
.clear
.password
,
809 password_blob
.current
->array
[i
].AuthInfo
.clear
.size
);
810 /* In the future, generate all sorts of
811 * hashes, but for now we can't safely convert
812 * the random strings windows uses into
815 /* but as it is utf16 already, we can get the NT password/arcfour-hmac-md5 key */
816 mdfour(password_hash
.hash
, password_utf16
.data
, password_utf16
.length
);
818 } else if (password_blob
.current
->array
[i
].AuthType
== TRUST_AUTH_TYPE_NT4OWF
) {
819 password_hash
= password_blob
.current
->array
[i
].AuthInfo
.nt4owf
.password
;
823 entry_ex
->entry
.keys
.len
= 0;
824 entry_ex
->entry
.keys
.val
= NULL
;
826 if (i
< password_blob
.count
) {
828 /* Must have found a cleartext or MD4 password */
829 entry_ex
->entry
.keys
.val
= calloc(1, sizeof(Key
));
832 key
.salt
= NULL
; /* No salt for this enc type */
834 if (entry_ex
->entry
.keys
.val
== NULL
) {
839 ret
= krb5_keyblock_init(context
,
840 ENCTYPE_ARCFOUR_HMAC_MD5
,
841 password_hash
.hash
, sizeof(password_hash
.hash
),
844 entry_ex
->entry
.keys
.val
[entry_ex
->entry
.keys
.len
] = key
;
845 entry_ex
->entry
.keys
.len
++;
848 entry_ex
->entry
.principal
= malloc(sizeof(*(entry_ex
->entry
.principal
)));
850 ret
= copy_Principal(principal
, entry_ex
->entry
.principal
);
852 krb5_clear_error_string(context
);
856 /* While we have copied the client principal, tests
857 * show that Win2k3 returns the 'corrected' realm, not
858 * the client-specified realm. This code attempts to
859 * replace the client principal's realm with the one
860 * we determine from our records */
862 /* this has to be with malloc() */
863 strdup_realm
= strdup(realm
);
866 krb5_clear_error_string(context
);
869 free(*krb5_princ_realm(context
, entry_ex
->entry
.principal
));
870 krb5_princ_set_realm(context
, entry_ex
->entry
.principal
, &strdup_realm
);
872 entry_ex
->entry
.flags
= int2HDBFlags(0);
873 entry_ex
->entry
.flags
.immutable
= 1;
874 entry_ex
->entry
.flags
.invalid
= 0;
875 entry_ex
->entry
.flags
.server
= 1;
876 entry_ex
->entry
.flags
.require_preauth
= 1;
878 entry_ex
->entry
.pw_end
= NULL
;
880 entry_ex
->entry
.max_life
= NULL
;
882 entry_ex
->entry
.max_renew
= NULL
;
884 entry_ex
->entry
.generation
= NULL
;
886 entry_ex
->entry
.etypes
= malloc(sizeof(*(entry_ex
->entry
.etypes
)));
887 if (entry_ex
->entry
.etypes
== NULL
) {
888 krb5_clear_error_string(context
);
892 entry_ex
->entry
.etypes
->len
= entry_ex
->entry
.keys
.len
;
893 entry_ex
->entry
.etypes
->val
= calloc(entry_ex
->entry
.etypes
->len
, sizeof(int));
894 if (entry_ex
->entry
.etypes
->val
== NULL
) {
895 krb5_clear_error_string(context
);
899 for (i
=0; i
< entry_ex
->entry
.etypes
->len
; i
++) {
900 entry_ex
->entry
.etypes
->val
[i
] = entry_ex
->entry
.keys
.val
[i
].key
.keytype
;
904 p
->msg
= talloc_steal(p
, msg
);
905 p
->samdb
= (struct ldb_context
*)db
->hdb_db
;
909 /* This doesn't free ent itself, that is for the eventual caller to do */
910 hdb_free_entry(context
, entry_ex
);
912 talloc_steal(db
, entry_ex
->ctx
);
919 static krb5_error_code
LDB_lookup_principal(krb5_context context
, struct ldb_context
*ldb_ctx
,
921 krb5_const_principal principal
,
922 enum hdb_ldb_ent_type ent_type
,
923 struct ldb_dn
*realm_dn
,
924 struct ldb_message
***pmsg
)
929 const char * const *princ_attrs
= user_attrs
;
932 char *short_princ_talloc
;
934 struct ldb_result
*res
= NULL
;
936 ret
= krb5_unparse_name_flags(context
, principal
, KRB5_PRINCIPAL_UNPARSE_NO_REALM
, &short_princ
);
939 krb5_set_error_string(context
, "LDB_lookup_principal: could not parse principal");
940 krb5_warnx(context
, "LDB_lookup_principal: could not parse principal");
944 short_princ_talloc
= talloc_strdup(mem_ctx
, short_princ
);
946 if (!short_princ_talloc
) {
947 krb5_set_error_string(context
, "LDB_lookup_principal: talloc_strdup() failed!");
952 case HDB_SAMBA4_ENT_TYPE_CLIENT
:
953 case HDB_SAMBA4_ENT_TYPE_TRUST
:
954 case HDB_SAMBA4_ENT_TYPE_ANY
:
957 case HDB_SAMBA4_ENT_TYPE_KRBTGT
:
958 filter
= talloc_asprintf(mem_ctx
, "(&(objectClass=user)(samAccountName=%s))",
961 case HDB_SAMBA4_ENT_TYPE_SERVER
:
962 filter
= talloc_asprintf(mem_ctx
, "(&(objectClass=user)(samAccountName=%s))",
968 krb5_set_error_string(context
, "talloc_asprintf: out of memory");
972 lret
= ldb_search(ldb_ctx
, mem_ctx
, &res
, realm_dn
,
973 LDB_SCOPE_SUBTREE
, princ_attrs
, "%s", filter
);
974 if (lret
!= LDB_SUCCESS
) {
975 DEBUG(3, ("Failed to search for %s: %s\n", filter
, ldb_errstring(ldb_ctx
)));
976 return HDB_ERR_NOENTRY
;
977 } else if (res
->count
== 0 || res
->count
> 1) {
978 DEBUG(3, ("Failed find a single entry for %s: got %d\n", filter
, res
->count
));
980 return HDB_ERR_NOENTRY
;
982 talloc_steal(mem_ctx
, res
->msgs
);
988 static krb5_error_code
LDB_lookup_trust(krb5_context context
, struct ldb_context
*ldb_ctx
,
991 struct ldb_dn
*realm_dn
,
992 struct ldb_message
***pmsg
)
996 const char * const *attrs
= trust_attrs
;
998 struct ldb_result
*res
= NULL
;
999 filter
= talloc_asprintf(mem_ctx
, "(&(objectClass=trustedDomain)(|(flatname=%s)(trustPartner=%s)))", realm
, realm
);
1002 krb5_set_error_string(context
, "talloc_asprintf: out of memory");
1006 lret
= ldb_search(ldb_ctx
, mem_ctx
, &res
,
1007 ldb_get_default_basedn(ldb_ctx
),
1008 LDB_SCOPE_SUBTREE
, attrs
, "%s", filter
);
1009 if (lret
!= LDB_SUCCESS
) {
1010 DEBUG(3, ("Failed to search for %s: %s\n", filter
, ldb_errstring(ldb_ctx
)));
1011 return HDB_ERR_NOENTRY
;
1012 } else if (res
->count
== 0 || res
->count
> 1) {
1013 DEBUG(3, ("Failed find a single entry for %s: got %d\n", filter
, res
->count
));
1015 return HDB_ERR_NOENTRY
;
1017 talloc_steal(mem_ctx
, res
->msgs
);
1023 static krb5_error_code
LDB_open(krb5_context context
, HDB
*db
, int flags
, mode_t mode
)
1025 if (db
->hdb_master_key_set
) {
1026 krb5_warnx(context
, "LDB_open: use of a master key incompatible with LDB\n");
1027 krb5_set_error_string(context
, "LDB_open: use of a master key incompatible with LDB\n");
1028 return HDB_ERR_NOENTRY
;
1034 static krb5_error_code
LDB_close(krb5_context context
, HDB
*db
)
1039 static krb5_error_code
LDB_lock(krb5_context context
, HDB
*db
, int operation
)
1044 static krb5_error_code
LDB_unlock(krb5_context context
, HDB
*db
)
1049 static krb5_error_code
LDB_rename(krb5_context context
, HDB
*db
, const char *new_name
)
1051 return HDB_ERR_DB_INUSE
;
1054 static krb5_error_code
LDB_fetch_client(krb5_context context
, HDB
*db
,
1055 TALLOC_CTX
*mem_ctx
,
1056 krb5_const_principal principal
,
1058 hdb_entry_ex
*entry_ex
) {
1060 char *principal_string
;
1061 struct ldb_dn
*realm_dn
;
1062 krb5_error_code ret
;
1063 struct ldb_message
**msg
= NULL
;
1065 ret
= krb5_unparse_name(context
, principal
, &principal_string
);
1071 nt_status
= sam_get_results_principal((struct ldb_context
*)db
->hdb_db
,
1072 mem_ctx
, principal_string
,
1074 free(principal_string
);
1075 if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NO_SUCH_USER
)) {
1076 return HDB_ERR_NOENTRY
;
1077 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NO_MEMORY
)) {
1079 } else if (!NT_STATUS_IS_OK(nt_status
)) {
1083 ret
= LDB_message2entry(context
, db
, mem_ctx
,
1084 principal
, HDB_SAMBA4_ENT_TYPE_CLIENT
,
1085 realm_dn
, msg
[0], entry_ex
);
1089 static krb5_error_code
LDB_fetch_krbtgt(krb5_context context
, HDB
*db
,
1090 TALLOC_CTX
*mem_ctx
,
1091 krb5_const_principal principal
,
1093 hdb_entry_ex
*entry_ex
)
1095 krb5_error_code ret
;
1096 struct ldb_message
**msg
= NULL
;
1097 struct ldb_dn
*realm_dn
= ldb_get_default_basedn(db
->hdb_db
);
1099 struct loadparm_context
*lp_ctx
= talloc_get_type(ldb_get_opaque(db
->hdb_db
, "loadparm"), struct loadparm_context
);
1101 krb5_principal alloc_principal
= NULL
;
1102 if (principal
->name
.name_string
.len
!= 2
1103 || (strcmp(principal
->name
.name_string
.val
[0], KRB5_TGS_NAME
) != 0)) {
1105 return HDB_ERR_NOENTRY
;
1108 /* krbtgt case. Either us or a trusted realm */
1110 if (lp_is_my_domain_or_realm(lp_ctx
, principal
->realm
)
1111 && lp_is_my_domain_or_realm(lp_ctx
, principal
->name
.name_string
.val
[1])) {
1113 /* Cludge, cludge cludge. If the realm part of krbtgt/realm,
1114 * is in our db, then direct the caller at our primary
1117 char *realm_fixed
= strupper_talloc(mem_ctx
, lp_realm(lp_ctx
));
1119 krb5_set_error_string(context
, "strupper_talloc: out of memory");
1123 ret
= krb5_copy_principal(context
, principal
, &alloc_principal
);
1128 free(alloc_principal
->name
.name_string
.val
[1]);
1129 alloc_principal
->name
.name_string
.val
[1] = strdup(realm_fixed
);
1130 talloc_free(realm_fixed
);
1131 if (!alloc_principal
->name
.name_string
.val
[1]) {
1132 krb5_set_error_string(context
, "LDB_fetch: strdup() failed!");
1135 principal
= alloc_principal
;
1137 ret
= LDB_lookup_principal(context
, (struct ldb_context
*)db
->hdb_db
,
1139 principal
, HDB_SAMBA4_ENT_TYPE_KRBTGT
, realm_dn
, &msg
);
1142 krb5_warnx(context
, "LDB_fetch: could not find principal in DB");
1143 krb5_set_error_string(context
, "LDB_fetch: could not find principal in DB");
1147 ret
= LDB_message2entry(context
, db
, mem_ctx
,
1148 principal
, HDB_SAMBA4_ENT_TYPE_KRBTGT
,
1149 realm_dn
, msg
[0], entry_ex
);
1151 krb5_warnx(context
, "LDB_fetch: self krbtgt message2entry failed");
1156 enum trust_direction direction
= UNKNOWN
;
1158 /* Either an inbound or outbound trust */
1160 if (strcasecmp(lp_realm(lp_ctx
), principal
->realm
) == 0) {
1161 /* look for inbound trust */
1162 direction
= INBOUND
;
1163 realm
= principal
->name
.name_string
.val
[1];
1166 if (strcasecmp(lp_realm(lp_ctx
), principal
->name
.name_string
.val
[1]) == 0) {
1167 /* look for outbound trust */
1168 direction
= OUTBOUND
;
1169 realm
= principal
->realm
;
1172 /* Trusted domains are under CN=system */
1174 ret
= LDB_lookup_trust(context
, (struct ldb_context
*)db
->hdb_db
,
1176 realm
, realm_dn
, &msg
);
1179 krb5_warnx(context
, "LDB_fetch: could not find principal in DB");
1180 krb5_set_error_string(context
, "LDB_fetch: could not find principal in DB");
1184 ret
= LDB_trust_message2entry(context
, db
, lp_ctx
, mem_ctx
,
1185 principal
, direction
,
1186 realm_dn
, msg
[0], entry_ex
);
1188 krb5_warnx(context
, "LDB_fetch: trust_message2entry failed");
1193 /* we should lookup trusted domains */
1194 return HDB_ERR_NOENTRY
;
1199 static krb5_error_code
LDB_fetch_server(krb5_context context
, HDB
*db
,
1200 TALLOC_CTX
*mem_ctx
,
1201 krb5_const_principal principal
,
1203 hdb_entry_ex
*entry_ex
)
1205 krb5_error_code ret
;
1207 struct ldb_message
**msg
= NULL
;
1208 struct ldb_dn
*realm_dn
;
1209 if (principal
->name
.name_string
.len
>= 2) {
1210 /* 'normal server' case */
1213 struct ldb_dn
*user_dn
;
1214 char *principal_string
;
1216 ret
= krb5_unparse_name_flags(context
, principal
,
1217 KRB5_PRINCIPAL_UNPARSE_NO_REALM
,
1223 /* At this point we may find the host is known to be
1224 * in a different realm, so we should generate a
1225 * referral instead */
1226 nt_status
= crack_service_principal_name((struct ldb_context
*)db
->hdb_db
,
1227 mem_ctx
, principal_string
,
1228 &user_dn
, &realm_dn
);
1229 free(principal_string
);
1231 if (!NT_STATUS_IS_OK(nt_status
)) {
1232 return HDB_ERR_NOENTRY
;
1235 ldb_ret
= gendb_search_dn((struct ldb_context
*)db
->hdb_db
,
1236 mem_ctx
, user_dn
, &msg
, user_attrs
);
1239 return HDB_ERR_NOENTRY
;
1243 /* server as client principal case, but we must not lookup userPrincipalNames */
1244 realm_dn
= ldb_get_default_basedn((struct ldb_context
*)db
->hdb_db
);
1245 realm
= krb5_principal_get_realm(context
, principal
);
1247 /* Check if it is our realm, otherwise give referall */
1249 ret
= LDB_lookup_principal(context
, (struct ldb_context
*)db
->hdb_db
,
1251 principal
, HDB_SAMBA4_ENT_TYPE_SERVER
, realm_dn
, &msg
);
1258 ret
= LDB_message2entry(context
, db
, mem_ctx
,
1259 principal
, HDB_SAMBA4_ENT_TYPE_SERVER
,
1260 realm_dn
, msg
[0], entry_ex
);
1262 krb5_warnx(context
, "LDB_fetch: message2entry failed");
1268 static krb5_error_code
LDB_fetch(krb5_context context
, HDB
*db
,
1269 krb5_const_principal principal
,
1271 hdb_entry_ex
*entry_ex
)
1273 krb5_error_code ret
= HDB_ERR_NOENTRY
;
1275 TALLOC_CTX
*mem_ctx
= talloc_named(db
, 0, "LDB_fetch context");
1278 krb5_set_error_string(context
, "LDB_fetch: talloc_named() failed!");
1282 if (flags
& HDB_F_GET_CLIENT
) {
1283 ret
= LDB_fetch_client(context
, db
, mem_ctx
, principal
, flags
, entry_ex
);
1284 if (ret
!= HDB_ERR_NOENTRY
) goto done
;
1286 if (flags
& HDB_F_GET_SERVER
) {
1287 /* krbtgt fits into this situation for trusted realms, and for resolving different versions of our own realm name */
1288 ret
= LDB_fetch_krbtgt(context
, db
, mem_ctx
, principal
, flags
, entry_ex
);
1289 if (ret
!= HDB_ERR_NOENTRY
) goto done
;
1291 /* We return 'no entry' if it does not start with krbtgt/, so move to the common case quickly */
1292 ret
= LDB_fetch_server(context
, db
, mem_ctx
, principal
, flags
, entry_ex
);
1293 if (ret
!= HDB_ERR_NOENTRY
) goto done
;
1295 if (flags
& HDB_F_GET_KRBTGT
) {
1296 ret
= LDB_fetch_krbtgt(context
, db
, mem_ctx
, principal
, flags
, entry_ex
);
1297 if (ret
!= HDB_ERR_NOENTRY
) goto done
;
1301 talloc_free(mem_ctx
);
1305 static krb5_error_code
LDB_store(krb5_context context
, HDB
*db
, unsigned flags
, hdb_entry_ex
*entry
)
1307 return HDB_ERR_DB_INUSE
;
1310 static krb5_error_code
LDB_remove(krb5_context context
, HDB
*db
, krb5_const_principal principal
)
1312 return HDB_ERR_DB_INUSE
;
1315 struct hdb_ldb_seq
{
1316 struct ldb_context
*ctx
;
1319 struct ldb_message
**msgs
;
1320 struct ldb_dn
*realm_dn
;
1323 static krb5_error_code
LDB_seq(krb5_context context
, HDB
*db
, unsigned flags
, hdb_entry_ex
*entry
)
1325 krb5_error_code ret
;
1326 struct hdb_ldb_seq
*priv
= (struct hdb_ldb_seq
*)db
->hdb_dbc
;
1327 TALLOC_CTX
*mem_ctx
;
1328 hdb_entry_ex entry_ex
;
1329 memset(&entry_ex
, '\0', sizeof(entry_ex
));
1332 return HDB_ERR_NOENTRY
;
1335 mem_ctx
= talloc_named(priv
, 0, "LDB_seq context");
1338 krb5_set_error_string(context
, "LDB_seq: talloc_named() failed!");
1342 if (priv
->index
< priv
->count
) {
1343 ret
= LDB_message2entry(context
, db
, mem_ctx
,
1344 NULL
, HDB_SAMBA4_ENT_TYPE_ANY
,
1345 priv
->realm_dn
, priv
->msgs
[priv
->index
++], entry
);
1347 ret
= HDB_ERR_NOENTRY
;
1354 talloc_free(mem_ctx
);
1360 static krb5_error_code
LDB_firstkey(krb5_context context
, HDB
*db
, unsigned flags
,
1361 hdb_entry_ex
*entry
)
1363 struct ldb_context
*ldb_ctx
= (struct ldb_context
*)db
->hdb_db
;
1364 struct hdb_ldb_seq
*priv
= (struct hdb_ldb_seq
*)db
->hdb_dbc
;
1366 struct ldb_result
*res
= NULL
;
1367 krb5_error_code ret
;
1368 TALLOC_CTX
*mem_ctx
;
1376 priv
= (struct hdb_ldb_seq
*) talloc(db
, struct hdb_ldb_seq
);
1378 krb5_set_error_string(context
, "talloc: out of memory");
1382 priv
->ctx
= ldb_ctx
;
1385 priv
->realm_dn
= ldb_get_default_basedn(ldb_ctx
);
1388 mem_ctx
= talloc_named(priv
, 0, "LDB_firstkey context");
1391 krb5_set_error_string(context
, "LDB_firstkey: talloc_named() failed!");
1395 ret
= krb5_get_default_realm(context
, &realm
);
1401 lret
= ldb_search(ldb_ctx
, priv
, &res
,
1402 priv
->realm_dn
, LDB_SCOPE_SUBTREE
, user_attrs
,
1403 "(objectClass=user)");
1405 if (lret
!= LDB_SUCCESS
) {
1407 return HDB_ERR_NOENTRY
;
1410 priv
->count
= res
->count
;
1411 priv
->msgs
= talloc_steal(priv
, res
->msgs
);
1416 ret
= LDB_seq(context
, db
, flags
, entry
);
1422 talloc_free(mem_ctx
);
1427 static krb5_error_code
LDB_nextkey(krb5_context context
, HDB
*db
, unsigned flags
,
1428 hdb_entry_ex
*entry
)
1430 return LDB_seq(context
, db
, flags
, entry
);
1433 static krb5_error_code
LDB_destroy(krb5_context context
, HDB
*db
)
1439 /* This interface is to be called by the KDC, which is expecting Samba
1440 * calling conventions. It is also called by a wrapper
1441 * (hdb_ldb_create) from the kpasswdd -> krb5 -> keytab_hdb -> hdb
1444 NTSTATUS
kdc_hdb_samba4_create(TALLOC_CTX
*mem_ctx
,
1445 struct tevent_context
*ev_ctx
,
1446 struct loadparm_context
*lp_ctx
,
1447 krb5_context context
, struct HDB
**db
, const char *arg
)
1450 struct auth_session_info
*session_info
;
1451 *db
= talloc(mem_ctx
, HDB
);
1453 krb5_set_error_string(context
, "malloc: out of memory");
1454 return NT_STATUS_NO_MEMORY
;
1457 (*db
)->hdb_master_key_set
= 0;
1458 (*db
)->hdb_db
= NULL
;
1460 nt_status
= auth_system_session_info(*db
, lp_ctx
, &session_info
);
1461 if (!NT_STATUS_IS_OK(nt_status
)) {
1465 /* The idea here is very simple. Using Kerberos to
1466 * authenticate the KDC to the LDAP server is higly likely to
1469 * In future we may set this up to use EXERNAL and SSL
1470 * certificates, for now it will almost certainly be NTLMSSP
1473 cli_credentials_set_kerberos_state(session_info
->credentials
,
1474 CRED_DONT_USE_KERBEROS
);
1476 /* Setup the link to LDB */
1477 (*db
)->hdb_db
= samdb_connect(*db
, ev_ctx
, lp_ctx
, session_info
);
1478 if ((*db
)->hdb_db
== NULL
) {
1479 DEBUG(1, ("hdb_ldb_create: Cannot open samdb for KDC backend!"));
1480 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO
;
1483 (*db
)->hdb_dbc
= NULL
;
1484 (*db
)->hdb_open
= LDB_open
;
1485 (*db
)->hdb_close
= LDB_close
;
1486 (*db
)->hdb_fetch
= LDB_fetch
;
1487 (*db
)->hdb_store
= LDB_store
;
1488 (*db
)->hdb_remove
= LDB_remove
;
1489 (*db
)->hdb_firstkey
= LDB_firstkey
;
1490 (*db
)->hdb_nextkey
= LDB_nextkey
;
1491 (*db
)->hdb_lock
= LDB_lock
;
1492 (*db
)->hdb_unlock
= LDB_unlock
;
1493 (*db
)->hdb_rename
= LDB_rename
;
1494 /* we don't implement these, as we are not a lockable database */
1495 (*db
)->hdb__get
= NULL
;
1496 (*db
)->hdb__put
= NULL
;
1497 /* kadmin should not be used for deletes - use other tools instead */
1498 (*db
)->hdb__del
= NULL
;
1499 (*db
)->hdb_destroy
= LDB_destroy
;
1501 return NT_STATUS_OK
;
1504 krb5_error_code
hdb_samba4_create(krb5_context context
, struct HDB
**db
, const char *arg
)
1507 /* The global kdc_mem_ctx and kdc_lp_ctx, Disgusting, ugly hack, but it means one less private hook */
1508 nt_status
= kdc_hdb_samba4_create(kdc_mem_ctx
, kdc_ev_ctx
, kdc_lp_ctx
,
1511 if (NT_STATUS_IS_OK(nt_status
)) {