torture3: Add a little gencache_parse load test
[Samba.git] / source4 / kdc / hdb-samba4.c
blob47d59d4aeca753d5d9a4d2cf23cb9d57d92931da
1 /*
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>
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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
32 * SUCH DAMAGE.
35 #include "includes.h"
36 #include "kdc/kdc-glue.h"
37 #include "kdc/db-glue.h"
38 #include "auth/auth_sam.h"
39 #include <ldb.h>
41 static krb5_error_code hdb_samba4_open(krb5_context context, HDB *db, int flags, mode_t mode)
43 if (db->hdb_master_key_set) {
44 krb5_error_code ret = HDB_ERR_NOENTRY;
45 krb5_warnx(context, "hdb_samba4_open: use of a master key incompatible with LDB\n");
46 krb5_set_error_message(context, ret, "hdb_samba4_open: use of a master key incompatible with LDB\n");
47 return ret;
50 return 0;
53 static krb5_error_code hdb_samba4_close(krb5_context context, HDB *db)
55 return 0;
58 static krb5_error_code hdb_samba4_lock(krb5_context context, HDB *db, int operation)
60 return 0;
63 static krb5_error_code hdb_samba4_unlock(krb5_context context, HDB *db)
65 return 0;
68 static krb5_error_code hdb_samba4_rename(krb5_context context, HDB *db, const char *new_name)
70 return HDB_ERR_DB_INUSE;
73 static krb5_error_code hdb_samba4_store(krb5_context context, HDB *db, unsigned flags, hdb_entry_ex *entry)
75 return HDB_ERR_DB_INUSE;
78 static krb5_error_code hdb_samba4_remove(krb5_context context, HDB *db, krb5_const_principal principal)
80 return HDB_ERR_DB_INUSE;
83 static krb5_error_code hdb_samba4_fetch_kvno(krb5_context context, HDB *db,
84 krb5_const_principal principal,
85 unsigned flags,
86 krb5_kvno kvno,
87 hdb_entry_ex *entry_ex)
89 struct samba_kdc_db_context *kdc_db_ctx;
91 kdc_db_ctx = talloc_get_type_abort(db->hdb_db,
92 struct samba_kdc_db_context);
94 return samba_kdc_fetch(context, kdc_db_ctx, principal, flags, kvno, entry_ex);
97 static krb5_error_code hdb_samba4_firstkey(krb5_context context, HDB *db, unsigned flags,
98 hdb_entry_ex *entry)
100 struct samba_kdc_db_context *kdc_db_ctx;
102 kdc_db_ctx = talloc_get_type_abort(db->hdb_db,
103 struct samba_kdc_db_context);
105 return samba_kdc_firstkey(context, kdc_db_ctx, entry);
108 static krb5_error_code hdb_samba4_nextkey(krb5_context context, HDB *db, unsigned flags,
109 hdb_entry_ex *entry)
111 struct samba_kdc_db_context *kdc_db_ctx;
113 kdc_db_ctx = talloc_get_type_abort(db->hdb_db,
114 struct samba_kdc_db_context);
116 return samba_kdc_nextkey(context, kdc_db_ctx, entry);
119 static krb5_error_code hdb_samba4_destroy(krb5_context context, HDB *db)
121 talloc_free(db);
122 return 0;
125 static krb5_error_code
126 hdb_samba4_check_constrained_delegation(krb5_context context, HDB *db,
127 hdb_entry_ex *entry,
128 krb5_const_principal target_principal)
130 struct samba_kdc_db_context *kdc_db_ctx;
132 kdc_db_ctx = talloc_get_type_abort(db->hdb_db,
133 struct samba_kdc_db_context);
135 return samba_kdc_check_s4u2proxy(context, kdc_db_ctx,
136 entry,
137 target_principal);
140 static krb5_error_code
141 hdb_samba4_check_pkinit_ms_upn_match(krb5_context context, HDB *db,
142 hdb_entry_ex *entry,
143 krb5_const_principal certificate_principal)
145 struct samba_kdc_db_context *kdc_db_ctx;
147 kdc_db_ctx = talloc_get_type_abort(db->hdb_db,
148 struct samba_kdc_db_context);
150 return samba_kdc_check_pkinit_ms_upn_match(context, kdc_db_ctx,
151 entry,
152 certificate_principal);
155 static krb5_error_code
156 hdb_samba4_check_s4u2self(krb5_context context, HDB *db,
157 hdb_entry_ex *entry,
158 krb5_const_principal target_principal)
160 struct samba_kdc_db_context *kdc_db_ctx;
162 kdc_db_ctx = talloc_get_type_abort(db->hdb_db,
163 struct samba_kdc_db_context);
165 return samba_kdc_check_s4u2self(context, kdc_db_ctx,
166 entry,
167 target_principal);
170 static krb5_error_code hdb_samba4_auth_status(krb5_context context, HDB *db,
171 hdb_entry_ex *entry,
172 int hdb_auth_status)
174 struct samba_kdc_db_context *kdc_db_ctx = talloc_get_type_abort(db->hdb_db,
175 struct samba_kdc_db_context);
176 struct samba_kdc_entry *p = talloc_get_type(entry->ctx, struct samba_kdc_entry);
178 if (hdb_auth_status == HDB_AUTH_WRONG_PASSWORD) {
179 authsam_update_bad_pwd_count(kdc_db_ctx->samdb, p->msg, ldb_get_default_basedn(kdc_db_ctx->samdb));
180 } else if (hdb_auth_status == HDB_AUTH_SUCCESS) {
181 authsam_zero_bad_pwd_count(kdc_db_ctx->samdb, p->msg);
183 return 0;
186 /* This interface is to be called by the KDC and libnet_keytab_dump,
187 * which is expecting Samba calling conventions.
188 * It is also called by a wrapper (hdb_samba4_create) from the
189 * kpasswdd -> krb5 -> keytab_hdb -> hdb code */
191 NTSTATUS hdb_samba4_create_kdc(struct samba_kdc_base_context *base_ctx,
192 krb5_context context, struct HDB **db)
194 struct samba_kdc_db_context *kdc_db_ctx;
195 NTSTATUS nt_status;
197 if (hdb_interface_version != HDB_INTERFACE_VERSION) {
198 krb5_set_error_message(context, EINVAL, "Heimdal HDB interface version mismatch between build-time and run-time libraries!");
199 return NT_STATUS_ERROR_DS_INCOMPATIBLE_VERSION;
202 *db = talloc(base_ctx, HDB);
203 if (!*db) {
204 krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
205 return NT_STATUS_NO_MEMORY;
208 (*db)->hdb_master_key_set = 0;
209 (*db)->hdb_db = NULL;
210 (*db)->hdb_capability_flags = 0;
212 nt_status = samba_kdc_setup_db_ctx(*db, base_ctx, &kdc_db_ctx);
213 if (!NT_STATUS_IS_OK(nt_status)) {
214 talloc_free(*db);
215 return nt_status;
217 (*db)->hdb_db = kdc_db_ctx;
219 (*db)->hdb_dbc = NULL;
220 (*db)->hdb_open = hdb_samba4_open;
221 (*db)->hdb_close = hdb_samba4_close;
222 (*db)->hdb_fetch_kvno = hdb_samba4_fetch_kvno;
223 (*db)->hdb_store = hdb_samba4_store;
224 (*db)->hdb_remove = hdb_samba4_remove;
225 (*db)->hdb_firstkey = hdb_samba4_firstkey;
226 (*db)->hdb_nextkey = hdb_samba4_nextkey;
227 (*db)->hdb_lock = hdb_samba4_lock;
228 (*db)->hdb_unlock = hdb_samba4_unlock;
229 (*db)->hdb_rename = hdb_samba4_rename;
230 /* we don't implement these, as we are not a lockable database */
231 (*db)->hdb__get = NULL;
232 (*db)->hdb__put = NULL;
233 /* kadmin should not be used for deletes - use other tools instead */
234 (*db)->hdb__del = NULL;
235 (*db)->hdb_destroy = hdb_samba4_destroy;
237 (*db)->hdb_auth_status = hdb_samba4_auth_status;
238 (*db)->hdb_check_constrained_delegation = hdb_samba4_check_constrained_delegation;
239 (*db)->hdb_check_pkinit_ms_upn_match = hdb_samba4_check_pkinit_ms_upn_match;
240 (*db)->hdb_check_s4u2self = hdb_samba4_check_s4u2self;
242 return NT_STATUS_OK;