LCOV - code coverage report
Current view: top level - source4/kdc - hdb-samba4-plugin.c (source / functions) Hit Total Coverage
Test: coverage report for master 98b443d9 Lines: 11 21 52.4 %
Date: 2024-05-31 13:13:24 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    KDC Server startup
       5             : 
       6             :    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005-20011
       7             : 
       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.
      12             : 
      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.
      17             : 
      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/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "kdc/kdc-glue.h"
      24             : #include "lib/param/param.h"
      25             : 
      26          68 : static krb5_error_code hdb_samba4_create(krb5_context context, struct HDB **db, const char *arg)
      27             : {
      28           0 :         NTSTATUS nt_status;
      29          68 :         void *ptr = NULL;
      30          68 :         struct samba_kdc_base_context *base_ctx = NULL;
      31             : 
      32          68 :         if (sscanf(arg, "&%p", &ptr) != 1) {
      33           0 :                 return EINVAL;
      34             :         }
      35             : 
      36          68 :         base_ctx = talloc_get_type_abort(ptr, struct samba_kdc_base_context);
      37             : 
      38             :         /* The global kdc_mem_ctx and kdc_lp_ctx, Disgusting, ugly hack, but it means one less private hook */
      39          68 :         nt_status = hdb_samba4_kpasswd_create_kdc(base_ctx, context, db);
      40             : 
      41          68 :         if (NT_STATUS_IS_OK(nt_status)) {
      42          68 :                 return 0;
      43           0 :         } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ERROR_DS_INCOMPATIBLE_VERSION)) {
      44           0 :                 return EINVAL;
      45           0 :         } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_CANT_ACCESS_DOMAIN_INFO)) {
      46             :                 
      47           0 :                 krb5_set_error_message(context, EINVAL, "Failed to open Samba4 LDB at %s", lpcfg_private_path(base_ctx, base_ctx->lp_ctx, "sam.ldb"));
      48             :         } else {
      49           0 :                 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));
      50             :         }
      51             : 
      52           0 :         return EINVAL;
      53             : }
      54             : 
      55             : #if (HDB_INTERFACE_VERSION != 11)
      56             : #error "Unsupported Heimdal HDB version"
      57             : #endif
      58             : 
      59             : #if HDB_INTERFACE_VERSION >= 8
      60          93 : static krb5_error_code hdb_samba4_init(krb5_context context, void **ctx)
      61             : {
      62          93 :         *ctx = NULL;
      63          93 :         return 0;
      64             : }
      65             : 
      66           0 : static void hdb_samba4_fini(void *ctx)
      67             : {
      68           0 : }
      69             : #endif
      70             : 
      71             : /* Only used in the hdb-backed keytab code
      72             :  * for a keytab of 'samba4&<address>' or samba4, to find
      73             :  * kpasswd's key in the main DB
      74             :  *
      75             :  * The <address> is the string form of a pointer to a talloced struct hdb_samba_context
      76             :  */
      77             : struct hdb_method hdb_samba4_interface = {
      78             :         HDB_INTERFACE_VERSION,
      79             : #if HDB_INTERFACE_VERSION >= 8
      80             :         .init = hdb_samba4_init,
      81             :         .fini = hdb_samba4_fini,
      82             : #endif
      83             :         .prefix = "samba4",
      84             :         .create = hdb_samba4_create
      85             : };

Generated by: LCOV version 1.14