2020-07-16 15:15:07 +02:00
/*
* Copyright ( c ) 2020 Andreas Schneider < asn @ samba . org >
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "lib/replace/replace.h"
# include <talloc.h>
# include "lib/param/param.h"
# include "lib/util/debug.h"
# include "lib/util/fault.h"
2020-07-27 16:13:53 +02:00
# include "auth/credentials/credentials.h"
2020-08-10 15:09:54 +02:00
# include "dynconfig/dynconfig.h"
2020-07-16 15:15:07 +02:00
# include "cmdline_private.h"
static bool _require_smbconf ;
2021-11-08 12:09:16 +01:00
static enum samba_cmdline_config_type _config_type ;
2020-07-16 15:15:07 +02:00
2020-08-10 15:09:54 +02:00
static bool _samba_cmdline_load_config_s4 ( void )
{
struct loadparm_context * lp_ctx = samba_cmdline_get_lp_ctx ( ) ;
const char * config_file = NULL ;
2022-05-26 15:46:08 +12:00
const struct samba_cmdline_daemon_cfg * cmdline_daemon_cfg = \
samba_cmdline_get_daemon_cfg ( ) ;
2020-08-10 15:09:54 +02:00
bool ok ;
/* Load smb conf */
config_file = lpcfg_configfile ( lp_ctx ) ;
if ( config_file = = NULL ) {
if ( is_default_dyn_CONFIGFILE ( ) ) {
const char * env = getenv ( " SMB_CONF_PATH " ) ;
if ( env ! = NULL & & strlen ( env ) > 0 ) {
set_dyn_CONFIGFILE ( env ) ;
}
}
}
2021-11-08 12:09:43 +01:00
switch ( _config_type ) {
2022-05-26 15:46:08 +12:00
case SAMBA_CMDLINE_CONFIG_SERVER :
2021-11-08 12:09:43 +01:00
if ( ! cmdline_daemon_cfg - > interactive ) {
setup_logging ( getprogname ( ) , DEBUG_FILE ) ;
}
break ;
default :
break ;
}
2020-08-10 15:09:54 +02:00
config_file = get_dyn_CONFIGFILE ( ) ;
ok = lpcfg_load ( lp_ctx , config_file ) ;
if ( ! ok ) {
fprintf ( stderr ,
" Can't load %s - run testparm to debug it \n " ,
config_file ) ;
if ( _require_smbconf ) {
return false ;
}
}
2022-05-26 15:46:08 +12:00
switch ( _config_type ) {
case SAMBA_CMDLINE_CONFIG_SERVER :
/*
* We need to setup_logging * again * to ensure multi - file
* logging is set up as specified in smb . conf .
*/
if ( ! cmdline_daemon_cfg - > interactive ) {
setup_logging ( getprogname ( ) , DEBUG_FILE ) ;
}
break ;
default :
break ;
}
2020-08-10 15:09:54 +02:00
return true ;
}
2020-08-11 16:37:16 +02:00
bool samba_cmdline_init ( TALLOC_CTX * mem_ctx ,
enum samba_cmdline_config_type config_type ,
bool require_smbconf )
2020-07-16 15:15:07 +02:00
{
struct loadparm_context * lp_ctx = NULL ;
2020-07-27 16:13:53 +02:00
struct cli_credentials * creds = NULL ;
2020-07-16 15:15:07 +02:00
bool ok ;
ok = samba_cmdline_init_common ( mem_ctx ) ;
if ( ! ok ) {
return false ;
}
lp_ctx = loadparm_init_global ( false ) ;
if ( lp_ctx = = NULL ) {
return false ;
}
ok = samba_cmdline_set_lp_ctx ( lp_ctx ) ;
if ( ! ok ) {
return false ;
}
_require_smbconf = require_smbconf ;
2021-11-08 12:09:16 +01:00
_config_type = config_type ;
2020-07-16 15:15:07 +02:00
2020-07-27 16:13:53 +02:00
creds = cli_credentials_init ( mem_ctx ) ;
if ( creds = = NULL ) {
return false ;
}
ok = samba_cmdline_set_creds ( creds ) ;
if ( ! ok ) {
return false ;
}
2020-08-10 15:09:54 +02:00
samba_cmdline_set_load_config_fn ( _samba_cmdline_load_config_s4 ) ;
2020-07-16 15:15:07 +02:00
return true ;
}