LCOV - code coverage report
Current view: top level - lib/cmdline - cmdline_s4.c (source / functions) Hit Total Coverage
Test: coverage report for vadcx-master-patch-75612 fe003de8 Lines: 50 56 89.3 %
Date: 2024-02-29 22:57:05 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        4966 : static bool _samba_cmdline_load_config_s4(void)
      31             : {
      32        4966 :         struct loadparm_context *lp_ctx = samba_cmdline_get_lp_ctx();
      33        4966 :         const char *config_file = NULL;
      34         395 :         const struct samba_cmdline_daemon_cfg *cmdline_daemon_cfg = \
      35        4966 :                 samba_cmdline_get_daemon_cfg();
      36         395 :         bool ok;
      37             : 
      38             :         /* Load smb conf */
      39        4966 :         config_file = lpcfg_configfile(lp_ctx);
      40        4966 :         if (config_file == NULL) {
      41        4966 :                 if (is_default_dyn_CONFIGFILE()) {
      42        1449 :                         const char *env = getenv("SMB_CONF_PATH");
      43        1449 :                         if (env != NULL && strlen(env) > 0) {
      44        1397 :                                 set_dyn_CONFIGFILE(env);
      45             :                         }
      46             :                 }
      47             :         }
      48             : 
      49        4966 :         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        4508 :         default:
      56        4508 :                 break;
      57             :         }
      58             : 
      59        4966 :         config_file = get_dyn_CONFIGFILE();
      60        4966 :         ok = lpcfg_load(lp_ctx, config_file);
      61        4966 :         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        4966 :         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        4508 :         default:
      82        4508 :                 break;
      83             :         }
      84             : 
      85        4571 :         return true;
      86             : }
      87             : 
      88        4980 : bool samba_cmdline_init(TALLOC_CTX *mem_ctx,
      89             :                         enum samba_cmdline_config_type config_type,
      90             :                         bool require_smbconf)
      91             : {
      92        4980 :         struct loadparm_context *lp_ctx = NULL;
      93        4980 :         struct cli_credentials *creds = NULL;
      94         395 :         bool ok;
      95             : 
      96        4980 :         ok = samba_cmdline_init_common(mem_ctx);
      97        4980 :         if (!ok) {
      98           0 :                 return false;
      99             :         }
     100             : 
     101        4980 :         lp_ctx = loadparm_init_global(false);
     102        4980 :         if (lp_ctx == NULL) {
     103           0 :                 return false;
     104             :         }
     105             : 
     106        4980 :         ok = samba_cmdline_set_lp_ctx(lp_ctx);
     107        4980 :         if (!ok) {
     108           0 :                 return false;
     109             :         }
     110        4980 :         _require_smbconf = require_smbconf;
     111        4980 :         _config_type = config_type;
     112             : 
     113        4980 :         creds = cli_credentials_init(mem_ctx);
     114        4980 :         if (creds == NULL) {
     115           0 :                 return false;
     116             :         }
     117        4980 :         ok = samba_cmdline_set_creds(creds);
     118        4980 :         if (!ok) {
     119           0 :                 return false;
     120             :         }
     121             : 
     122        4980 :         samba_cmdline_set_load_config_fn(_samba_cmdline_load_config_s4);
     123             : 
     124        4980 :         return true;
     125             : }

Generated by: LCOV version 1.14