2 * Copyright (c) 2020 Andreas Schneider <asn@samba.org>
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.
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.
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/>.
18 #include "lib/replace/replace.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"
27 static bool _require_smbconf
;
28 static enum samba_cmdline_config_type _config_type
;
30 static bool _samba_cmdline_load_config_s4(void)
32 struct loadparm_context
*lp_ctx
= samba_cmdline_get_lp_ctx();
33 const char *config_file
= NULL
;
34 const struct samba_cmdline_daemon_cfg
*cmdline_daemon_cfg
= \
35 samba_cmdline_get_daemon_cfg();
39 config_file
= lpcfg_configfile(lp_ctx
);
40 if (config_file
== NULL
) {
41 if (is_default_dyn_CONFIGFILE()) {
42 const char *env
= getenv("SMB_CONF_PATH");
43 if (env
!= NULL
&& strlen(env
) > 0) {
44 set_dyn_CONFIGFILE(env
);
49 switch (_config_type
) {
50 case SAMBA_CMDLINE_CONFIG_SERVER
:
51 if (!cmdline_daemon_cfg
->interactive
) {
52 setup_logging(getprogname(), DEBUG_FILE
);
59 config_file
= get_dyn_CONFIGFILE();
60 ok
= lpcfg_load(lp_ctx
, config_file
);
63 "Can't load %s - run testparm to debug it\n",
66 if (_require_smbconf
) {
71 switch (_config_type
) {
72 case SAMBA_CMDLINE_CONFIG_SERVER
:
74 * We need to setup_logging *again* to ensure multi-file
75 * logging is set up as specified in smb.conf.
77 if (!cmdline_daemon_cfg
->interactive
) {
78 setup_logging(getprogname(), DEBUG_FILE
);
88 bool samba_cmdline_init(TALLOC_CTX
*mem_ctx
,
89 enum samba_cmdline_config_type config_type
,
92 struct loadparm_context
*lp_ctx
= NULL
;
93 struct cli_credentials
*creds
= NULL
;
96 ok
= samba_cmdline_init_common(mem_ctx
);
101 lp_ctx
= loadparm_init_global(false);
102 if (lp_ctx
== NULL
) {
106 ok
= samba_cmdline_set_lp_ctx(lp_ctx
);
110 _require_smbconf
= require_smbconf
;
111 _config_type
= config_type
;
113 creds
= cli_credentials_init(mem_ctx
);
117 ok
= samba_cmdline_set_creds(creds
);
122 samba_cmdline_set_load_config_fn(_samba_cmdline_load_config_s4
);