LCOV - code coverage report
Current view: top level - source4/kdc/mit-kdb - kdb_samba.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 19 32 59.4 %
Date: 2024-04-21 15:09:00 Functions: 5 10 50.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    Samba KDB plugin for MIT Kerberos
       5             : 
       6             :    Copyright (c) 2010      Simo Sorce <idra@samba.org>.
       7             :    Copyright (c) 2014      Andreas Schneider <asn@samba.org>
       8             : 
       9             :    This program is free software; you can redistribute it and/or modify
      10             :    it under the terms of the GNU General Public License as published by
      11             :    the Free Software Foundation; either version 3 of the License, or
      12             :    (at your option) any later version.
      13             : 
      14             :    This program is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU General Public License for more details.
      18             : 
      19             :    You should have received a copy of the GNU General Public License
      20             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      21             : */
      22             : 
      23             : #include "includes.h"
      24             : 
      25             : #include "system/kerberos.h"
      26             : 
      27             : #include <profile.h>
      28             : #include <kdb.h>
      29             : 
      30             : #include "kdc/samba_kdc.h"
      31             : #include "kdc/mit_samba.h"
      32             : #include "kdb_samba.h"
      33             : 
      34          17 : static krb5_error_code kdb_samba_init_library(void)
      35             : {
      36          17 :         return 0;
      37             : }
      38             : 
      39          17 : static krb5_error_code kdb_samba_fini_library(void)
      40             : {
      41          17 :         return 0;
      42             : }
      43             : 
      44          17 : static krb5_error_code kdb_samba_init_module(krb5_context context,
      45             :                                              char *conf_section,
      46             :                                              char **db_args,
      47             :                                              int mode)
      48             : {
      49             :         /* TODO mit_samba_context_init */
      50             :         struct mit_samba_context *mit_ctx;
      51             :         krb5_error_code code;
      52             :         int rc;
      53             : 
      54          17 :         rc = mit_samba_context_init(&mit_ctx);
      55          17 :         if (rc != 0) {
      56           0 :                 return ENOMEM;
      57             :         }
      58             : 
      59             : 
      60          17 :         code = krb5_db_set_context(context, mit_ctx);
      61             : 
      62          17 :         return code;
      63             : }
      64          17 : static krb5_error_code kdb_samba_fini_module(krb5_context context)
      65             : {
      66             :         struct mit_samba_context *mit_ctx;
      67             : 
      68          17 :         mit_ctx = ks_get_context(context);
      69          17 :         if (mit_ctx == NULL) {
      70           0 :                 return 0;
      71             :         }
      72             : 
      73          17 :         mit_samba_context_free(mit_ctx);
      74             : 
      75          17 :         return 0;
      76             : }
      77             : 
      78           0 : static krb5_error_code kdb_samba_db_create(krb5_context context,
      79             :                                            char *conf_section,
      80             :                                            char **db_args)
      81             : {
      82             :         /* NOTE: used only by kadmin */
      83           0 :         return KRB5_KDB_DBTYPE_NOSUP;
      84             : }
      85             : 
      86           0 : static krb5_error_code kdb_samba_db_destroy(krb5_context context,
      87             :                                             char *conf_section,
      88             :                                             char **db_args)
      89             : {
      90             :         /* NOTE: used only by kadmin */
      91           0 :         return KRB5_KDB_DBTYPE_NOSUP;
      92             : }
      93             : 
      94           0 : static krb5_error_code kdb_samba_db_get_age(krb5_context context,
      95             :                                             char *db_name,
      96             :                                             time_t *age)
      97             : {
      98             :         /* TODO: returns last modification time of the db */
      99             : 
     100             :         /* NOTE: used by and affects only lookaside cache,
     101             :          *       defer implementation until needed as samba doesn't keep this
     102             :          *       specific value readily available and it would require a full
     103             :          *       database search to get it. */
     104             : 
     105           0 :         *age = time(NULL);
     106             : 
     107           0 :         return 0;
     108             : }
     109             : 
     110           0 : static krb5_error_code kdb_samba_db_lock(krb5_context context, int kmode)
     111             : {
     112             : 
     113             :         /* NOTE: important only for kadmin */
     114             :         /* NOTE: deferred as samba's DB cannot be easily locked and doesn't
     115             :          * really make sense to do so anyway as the db is shared and support
     116             :          * transactions */
     117           0 :         return 0;
     118             : }
     119             : 
     120           0 : static krb5_error_code kdb_samba_db_unlock(krb5_context context)
     121             : {
     122             : 
     123             :         /* NOTE: important only for kadmin */
     124             :         /* NOTE: deferred as samba's DB cannot be easily locked and doesn't
     125             :          * really make sense to do so anyway as the db is shared and support
     126             :          * transactions */
     127           0 :         return 0;
     128             : }
     129             : 
     130          92 : static void kdb_samba_db_free_principal_e_data(krb5_context context,
     131             :                                                krb5_octet *e_data)
     132             : {
     133             :         struct samba_kdc_entry *skdc_entry;
     134             : 
     135          92 :         skdc_entry = talloc_get_type_abort(e_data,
     136             :                                            struct samba_kdc_entry);
     137          92 :         skdc_entry->kdc_entry = NULL;
     138          92 :         TALLOC_FREE(skdc_entry);
     139          92 : }
     140             : 
     141             : kdb_vftabl kdb_function_table = {
     142             :         .maj_ver                   = KRB5_KDB_DAL_MAJOR_VERSION,
     143             :         .min_ver                   = 0,
     144             : 
     145             :         .init_library              = kdb_samba_init_library,
     146             :         .fini_library              = kdb_samba_fini_library,
     147             :         .init_module               = kdb_samba_init_module,
     148             :         .fini_module               = kdb_samba_fini_module,
     149             : 
     150             :         .create                    = kdb_samba_db_create,
     151             :         .destroy                   = kdb_samba_db_destroy,
     152             :         .get_age                   = kdb_samba_db_get_age,
     153             :         .lock                      = kdb_samba_db_lock,
     154             :         .unlock                    = kdb_samba_db_unlock,
     155             : 
     156             :         .get_principal             = kdb_samba_db_get_principal,
     157             :         .put_principal             = kdb_samba_db_put_principal,
     158             :         .delete_principal          = kdb_samba_db_delete_principal,
     159             : 
     160             :         .iterate                   = kdb_samba_db_iterate,
     161             : 
     162             :         .fetch_master_key          = kdb_samba_fetch_master_key,
     163             :         .fetch_master_key_list     = kdb_samba_fetch_master_key_list,
     164             : 
     165             :         .change_pwd                = kdb_samba_change_pwd,
     166             : 
     167             :         .decrypt_key_data          = kdb_samba_dbekd_decrypt_key_data,
     168             :         .encrypt_key_data          = kdb_samba_dbekd_encrypt_key_data,
     169             : 
     170             :         .check_policy_as           = kdb_samba_db_check_policy_as,
     171             :         .audit_as_req              = kdb_samba_db_audit_as_req,
     172             :         .check_allowed_to_delegate = kdb_samba_db_check_allowed_to_delegate,
     173             : 
     174             :         .free_principal_e_data     = kdb_samba_db_free_principal_e_data,
     175             : 
     176             :         .allowed_to_delegate_from  = kdb_samba_db_allowed_to_delegate_from,
     177             :         .issue_pac                 = kdb_samba_db_issue_pac,
     178             : };

Generated by: LCOV version 1.14