CVE-2019-3824 ldb: Improve code style and layout in wildcard processing
[Samba.git] / source4 / kdc / hdb-samba4-plugin.c
blob6f76124995d327bbf9e0c2ef0d173a023da2f5d2
1 /*
2 Unix SMB/CIFS implementation.
4 KDC Server startup
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005-20011
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "kdc/kdc-glue.h"
24 #include "kdc/db-glue.h"
25 #include "lib/util/samba_util.h"
26 #include "lib/param/param.h"
27 #include "source4/lib/events/events.h"
29 static krb5_error_code hdb_samba4_create(krb5_context context, struct HDB **db, const char *arg)
31 NTSTATUS nt_status;
32 void *ptr;
33 struct samba_kdc_base_context *base_ctx;
35 if (sscanf(arg, "&%p", &ptr) == 1) {
36 base_ctx = talloc_get_type_abort(ptr, struct samba_kdc_base_context);
37 } else if (arg[0] == '\0' || file_exist(arg)) {
38 /* This mode for use in kadmin, rather than in Samba */
40 setup_logging("hdb_samba4", DEBUG_DEFAULT_STDERR);
42 base_ctx = talloc_zero(NULL, struct samba_kdc_base_context);
43 if (!base_ctx) {
44 return ENOMEM;
47 base_ctx->ev_ctx = s4_event_context_init(base_ctx);
48 base_ctx->lp_ctx = loadparm_init_global(false);
49 if (arg[0]) {
50 lpcfg_load(base_ctx->lp_ctx, arg);
51 } else {
52 lpcfg_load_default(base_ctx->lp_ctx);
54 } else {
55 return EINVAL;
58 /* The global kdc_mem_ctx and kdc_lp_ctx, Disgusting, ugly hack, but it means one less private hook */
59 nt_status = hdb_samba4_create_kdc(base_ctx, context, db);
61 if (NT_STATUS_IS_OK(nt_status)) {
62 return 0;
63 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ERROR_DS_INCOMPATIBLE_VERSION)) {
64 return EINVAL;
65 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_CANT_ACCESS_DOMAIN_INFO)) {
67 krb5_set_error_message(context, EINVAL, "Failed to open Samba4 LDB at %s", lpcfg_private_path(base_ctx, base_ctx->lp_ctx, "sam.ldb"));
68 } else {
69 krb5_set_error_message(context, EINVAL, "Failed to connect to Samba4 DB: %s (%s)", get_friendly_nt_error_msg(nt_status), nt_errstr(nt_status));
72 return EINVAL;
75 #if (HDB_INTERFACE_VERSION != 8 && HDB_INTERFACE_VERSION != 7)
76 #error "Unsupported Heimdal HDB version"
77 #endif
79 #if HDB_INTERFACE_VERSION >= 8
80 static krb5_error_code hdb_samba4_init(krb5_context context, void **ctx)
82 *ctx = NULL;
83 return 0;
86 static void hdb_samba4_fini(void *ctx)
89 #endif
91 /* Only used in the hdb-backed keytab code
92 * for a keytab of 'samba4&<address>' or samba4, to find
93 * kpasswd's key in the main DB, and to
94 * copy all the keys into a file (libnet_keytab_export)
96 * The <address> is the string form of a pointer to a talloced struct hdb_samba_context
98 struct hdb_method hdb_samba4_interface = {
99 HDB_INTERFACE_VERSION,
100 #if HDB_INTERFACE_VERSION >= 8
101 .init = hdb_samba4_init,
102 .fini = hdb_samba4_fini,
103 #endif
104 .prefix = "samba4",
105 .create = hdb_samba4_create