s4:kdc: also provide cross-realm keys via samba_kdc_seq()
[Samba.git] / lib / cmdline / cmdline_s4.c
blobf8be4ed670cf795fb21144a4d10474fddb9f3fd8
1 /*
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"
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"
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();
36 bool ok;
38 /* Load smb conf */
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);
54 break;
55 default:
56 break;
59 config_file = get_dyn_CONFIGFILE();
60 ok = lpcfg_load(lp_ctx, config_file);
61 if (!ok) {
62 fprintf(stderr,
63 "Can't load %s - run testparm to debug it\n",
64 config_file);
66 if (_require_smbconf) {
67 return false;
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);
80 break;
81 default:
82 break;
85 return true;
88 bool samba_cmdline_init(TALLOC_CTX *mem_ctx,
89 enum samba_cmdline_config_type config_type,
90 bool require_smbconf)
92 struct loadparm_context *lp_ctx = NULL;
93 struct cli_credentials *creds = NULL;
94 bool ok;
96 ok = samba_cmdline_init_common(mem_ctx);
97 if (!ok) {
98 return false;
101 lp_ctx = loadparm_init_global(false);
102 if (lp_ctx == NULL) {
103 return false;
106 ok = samba_cmdline_set_lp_ctx(lp_ctx);
107 if (!ok) {
108 return false;
110 _require_smbconf = require_smbconf;
111 _config_type = config_type;
113 creds = cli_credentials_init(mem_ctx);
114 if (creds == NULL) {
115 return false;
117 ok = samba_cmdline_set_creds(creds);
118 if (!ok) {
119 return false;
122 samba_cmdline_set_load_config_fn(_samba_cmdline_load_config_s4);
124 return true;