LCOV - code coverage report
Current view: top level - lib/cmdline - cmdline_s4.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 50 56 89.3 %
Date: 2024-04-21 15:09:00 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2020      Andreas Schneider <asn@samba.org>
       3             :  *
       4             :  * This program is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 3 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * This program is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #include "lib/replace/replace.h"
      19             : #include <talloc.h>
      20             : #include "lib/param/param.h"
      21             : #include "lib/util/debug.h"
      22             : #include "lib/util/fault.h"
      23             : #include "auth/credentials/credentials.h"
      24             : #include "dynconfig/dynconfig.h"
      25             : #include "cmdline_private.h"
      26             : 
      27             : static bool _require_smbconf;
      28             : static enum samba_cmdline_config_type _config_type;
      29             : 
      30        4979 : static bool _samba_cmdline_load_config_s4(void)
      31             : {
      32        4979 :         struct loadparm_context *lp_ctx = samba_cmdline_get_lp_ctx();
      33        4979 :         const char *config_file = NULL;
      34         395 :         const struct samba_cmdline_daemon_cfg *cmdline_daemon_cfg = \
      35        4979 :                 samba_cmdline_get_daemon_cfg();
      36         395 :         bool ok;
      37             : 
      38             :         /* Load smb conf */
      39        4979 :         config_file = lpcfg_configfile(lp_ctx);
      40        4979 :         if (config_file == NULL) {
      41        4979 :                 if (is_default_dyn_CONFIGFILE()) {
      42        1463 :                         const char *env = getenv("SMB_CONF_PATH");
      43        1463 :                         if (env != NULL && strlen(env) > 0) {
      44        1411 :                                 set_dyn_CONFIGFILE(env);
      45             :                         }
      46             :                 }
      47             :         }
      48             : 
      49        4979 :         switch (_config_type) {
      50          80 :         case SAMBA_CMDLINE_CONFIG_SERVER:
      51          80 :                 if (!cmdline_daemon_cfg->interactive) {
      52          11 :                         setup_logging(getprogname(), DEBUG_FILE);
      53             :                 }
      54          63 :                 break;
      55        4521 :         default:
      56        4521 :                 break;
      57             :         }
      58             : 
      59        4979 :         config_file = get_dyn_CONFIGFILE();
      60        4979 :         ok = lpcfg_load(lp_ctx, config_file);
      61        4979 :         if (!ok) {
      62         125 :                 fprintf(stderr,
      63             :                         "Can't load %s - run testparm to debug it\n",
      64             :                         config_file);
      65             : 
      66         125 :                 if (_require_smbconf) {
      67           0 :                         return false;
      68             :                 }
      69             :         }
      70             : 
      71        4979 :         switch (_config_type) {
      72          80 :         case SAMBA_CMDLINE_CONFIG_SERVER:
      73             :                 /*
      74             :                  * We need to setup_logging *again* to ensure multi-file
      75             :                  * logging is set up as specified in smb.conf.
      76             :                  */
      77          80 :                 if (!cmdline_daemon_cfg->interactive) {
      78          11 :                         setup_logging(getprogname(), DEBUG_FILE);
      79             :                 }
      80          63 :                 break;
      81        4521 :         default:
      82        4521 :                 break;
      83             :         }
      84             : 
      85        4584 :         return true;
      86             : }
      87             : 
      88        4993 : bool samba_cmdline_init(TALLOC_CTX *mem_ctx,
      89             :                         enum samba_cmdline_config_type config_type,
      90             :                         bool require_smbconf)
      91             : {
      92        4993 :         struct loadparm_context *lp_ctx = NULL;
      93        4993 :         struct cli_credentials *creds = NULL;
      94         395 :         bool ok;
      95             : 
      96        4993 :         ok = samba_cmdline_init_common(mem_ctx);
      97        4993 :         if (!ok) {
      98           0 :                 return false;
      99             :         }
     100             : 
     101        4993 :         lp_ctx = loadparm_init_global(false);
     102        4993 :         if (lp_ctx == NULL) {
     103           0 :                 return false;
     104             :         }
     105             : 
     106        4993 :         ok = samba_cmdline_set_lp_ctx(lp_ctx);
     107        4993 :         if (!ok) {
     108           0 :                 return false;
     109             :         }
     110        4993 :         _require_smbconf = require_smbconf;
     111        4993 :         _config_type = config_type;
     112             : 
     113        4993 :         creds = cli_credentials_init(mem_ctx);
     114        4993 :         if (creds == NULL) {
     115           0 :                 return false;
     116             :         }
     117        4993 :         ok = samba_cmdline_set_creds(creds);
     118        4993 :         if (!ok) {
     119           0 :                 return false;
     120             :         }
     121             : 
     122        4993 :         samba_cmdline_set_load_config_fn(_samba_cmdline_load_config_s4);
     123             : 
     124        4993 :         return true;
     125             : }

Generated by: LCOV version 1.14