s3:smbd: s/EVENT_FD/TEVENT_FD
[Samba/gebeck_regimport.git] / source4 / kdc / hdb-samba4.c
blob6a9e5587bfd9340e88cbf416eb5996947d9ba734
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"
39 static krb5_error_code hdb_samba4_open(krb5_context context, HDB *db, int flags, mode_t mode)
41 if (db->hdb_master_key_set) {
42 krb5_error_code ret = HDB_ERR_NOENTRY;
43 krb5_warnx(context, "hdb_samba4_open: use of a master key incompatible with LDB\n");
44 krb5_set_error_message(context, ret, "hdb_samba4_open: use of a master key incompatible with LDB\n");
45 return ret;
48 return 0;
51 static krb5_error_code hdb_samba4_close(krb5_context context, HDB *db)
53 return 0;
56 static krb5_error_code hdb_samba4_lock(krb5_context context, HDB *db, int operation)
58 return 0;
61 static krb5_error_code hdb_samba4_unlock(krb5_context context, HDB *db)
63 return 0;
66 static krb5_error_code hdb_samba4_rename(krb5_context context, HDB *db, const char *new_name)
68 return HDB_ERR_DB_INUSE;
71 static krb5_error_code hdb_samba4_store(krb5_context context, HDB *db, unsigned flags, hdb_entry_ex *entry)
73 return HDB_ERR_DB_INUSE;
76 static krb5_error_code hdb_samba4_remove(krb5_context context, HDB *db, krb5_const_principal principal)
78 return HDB_ERR_DB_INUSE;
81 static krb5_error_code hdb_samba4_fetch_kvno(krb5_context context, HDB *db,
82 krb5_const_principal principal,
83 unsigned flags,
84 krb5_kvno kvno,
85 hdb_entry_ex *entry_ex)
87 struct samba_kdc_db_context *kdc_db_ctx;
89 kdc_db_ctx = talloc_get_type_abort(db->hdb_db,
90 struct samba_kdc_db_context);
92 return samba_kdc_fetch(context, kdc_db_ctx, principal, flags, kvno, entry_ex);
95 static krb5_error_code hdb_samba4_firstkey(krb5_context context, HDB *db, unsigned flags,
96 hdb_entry_ex *entry)
98 struct samba_kdc_db_context *kdc_db_ctx;
100 kdc_db_ctx = talloc_get_type_abort(db->hdb_db,
101 struct samba_kdc_db_context);
103 return samba_kdc_firstkey(context, kdc_db_ctx, entry);
106 static krb5_error_code hdb_samba4_nextkey(krb5_context context, HDB *db, unsigned flags,
107 hdb_entry_ex *entry)
109 struct samba_kdc_db_context *kdc_db_ctx;
111 kdc_db_ctx = talloc_get_type_abort(db->hdb_db,
112 struct samba_kdc_db_context);
114 return samba_kdc_nextkey(context, kdc_db_ctx, entry);
117 static krb5_error_code hdb_samba4_destroy(krb5_context context, HDB *db)
119 talloc_free(db);
120 return 0;
123 static krb5_error_code
124 hdb_samba4_check_constrained_delegation(krb5_context context, HDB *db,
125 hdb_entry_ex *entry,
126 krb5_const_principal target_principal)
128 struct samba_kdc_db_context *kdc_db_ctx;
130 kdc_db_ctx = talloc_get_type_abort(db->hdb_db,
131 struct samba_kdc_db_context);
133 return samba_kdc_check_s4u2proxy(context, kdc_db_ctx,
134 entry,
135 target_principal);
138 static krb5_error_code
139 hdb_samba4_check_pkinit_ms_upn_match(krb5_context context, HDB *db,
140 hdb_entry_ex *entry,
141 krb5_const_principal certificate_principal)
143 struct samba_kdc_db_context *kdc_db_ctx;
145 kdc_db_ctx = talloc_get_type_abort(db->hdb_db,
146 struct samba_kdc_db_context);
148 return samba_kdc_check_pkinit_ms_upn_match(context, kdc_db_ctx,
149 entry,
150 certificate_principal);
153 static krb5_error_code
154 hdb_samba4_check_s4u2self(krb5_context context, HDB *db,
155 hdb_entry_ex *entry,
156 krb5_const_principal target_principal)
158 struct samba_kdc_db_context *kdc_db_ctx;
160 kdc_db_ctx = talloc_get_type_abort(db->hdb_db,
161 struct samba_kdc_db_context);
163 return samba_kdc_check_s4u2self(context, kdc_db_ctx,
164 entry,
165 target_principal);
168 /* This interface is to be called by the KDC and libnet_keytab_dump,
169 * which is expecting Samba calling conventions.
170 * It is also called by a wrapper (hdb_samba4_create) from the
171 * kpasswdd -> krb5 -> keytab_hdb -> hdb code */
173 NTSTATUS hdb_samba4_create_kdc(struct samba_kdc_base_context *base_ctx,
174 krb5_context context, struct HDB **db)
176 struct samba_kdc_db_context *kdc_db_ctx;
177 NTSTATUS nt_status;
179 *db = talloc(base_ctx, HDB);
180 if (!*db) {
181 krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
182 return NT_STATUS_NO_MEMORY;
185 (*db)->hdb_master_key_set = 0;
186 (*db)->hdb_db = NULL;
187 (*db)->hdb_capability_flags = 0;
189 nt_status = samba_kdc_setup_db_ctx(*db, base_ctx, &kdc_db_ctx);
190 if (!NT_STATUS_IS_OK(nt_status)) {
191 talloc_free(*db);
192 return nt_status;
194 (*db)->hdb_db = kdc_db_ctx;
196 (*db)->hdb_dbc = NULL;
197 (*db)->hdb_open = hdb_samba4_open;
198 (*db)->hdb_close = hdb_samba4_close;
199 (*db)->hdb_fetch_kvno = hdb_samba4_fetch_kvno;
200 (*db)->hdb_store = hdb_samba4_store;
201 (*db)->hdb_remove = hdb_samba4_remove;
202 (*db)->hdb_firstkey = hdb_samba4_firstkey;
203 (*db)->hdb_nextkey = hdb_samba4_nextkey;
204 (*db)->hdb_lock = hdb_samba4_lock;
205 (*db)->hdb_unlock = hdb_samba4_unlock;
206 (*db)->hdb_rename = hdb_samba4_rename;
207 /* we don't implement these, as we are not a lockable database */
208 (*db)->hdb__get = NULL;
209 (*db)->hdb__put = NULL;
210 /* kadmin should not be used for deletes - use other tools instead */
211 (*db)->hdb__del = NULL;
212 (*db)->hdb_destroy = hdb_samba4_destroy;
214 (*db)->hdb_auth_status = NULL;
215 (*db)->hdb_check_constrained_delegation = hdb_samba4_check_constrained_delegation;
216 (*db)->hdb_check_pkinit_ms_upn_match = hdb_samba4_check_pkinit_ms_upn_match;
217 (*db)->hdb_check_s4u2self = hdb_samba4_check_s4u2self;
219 return NT_STATUS_OK;