s3-libnet: avoid using lp_dns_hostname() in join code
[samba4-gss.git] / lib / cmdline / cmdline.h
blobce5dd2392dfb6e24a5cbf13042b23b1587d48188
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 #ifndef _CMDLINE_H
19 #define _CMDLINE_H
21 #include "auth/credentials/credentials.h"
22 #include <popt.h>
24 #ifndef POPT_TABLEEND
25 #define POPT_TABLEEND { \
26 .longName = NULL, \
27 .shortName = 0, \
28 .argInfo = 0, \
29 .arg = NULL, \
30 .val = 0, \
31 .descrip = NULL, \
32 .argDescrip = NULL }
33 #endif
35 enum samba_cmdline_config_type {
36 SAMBA_CMDLINE_CONFIG_NONE = 0,
37 SAMBA_CMDLINE_CONFIG_CLIENT,
38 SAMBA_CMDLINE_CONFIG_SERVER,
41 enum smb_cmdline_popt_options {
42 SAMBA_CMDLINE_POPT_OPT_DEBUG_ONLY = 1,
43 SAMBA_CMDLINE_POPT_OPT_OPTION_ONLY,
44 SAMBA_CMDLINE_POPT_OPT_CONFIG_ONLY,
45 SAMBA_CMDLINE_POPT_OPT_SAMBA,
46 SAMBA_CMDLINE_POPT_OPT_CONNECTION,
47 SAMBA_CMDLINE_POPT_OPT_CREDENTIALS,
48 SAMBA_CMDLINE_POPT_OPT_VERSION,
49 SAMBA_CMDLINE_POPT_OPT_DAEMON,
50 SAMBA_CMDLINE_POPT_OPT_SAMBA_LDB,
51 SAMBA_CMDLINE_POPT_OPT_LEGACY_S3,
52 SAMBA_CMDLINE_POPT_OPT_LEGACY_S4,
55 struct samba_cmdline_daemon_cfg {
56 bool daemon;
57 bool interactive;
58 bool fork;
59 bool no_process_group;
62 /**
63 * @brief Initialize the commandline interface for parsing options.
65 * This initializes the interface for parsing options given on the command
66 * line. It sets up the loadparm and client credentials contexts.
67 * The function will also setup fault handler, set logging to STDERR by
68 * default, setup talloc logging and the panic handler.
70 * The function also setups a callback for loading the smb.conf file, the
71 * config file will be parsed after the commandline options have been parsed
72 * by popt. This is done by one of the following options parser:
74 * POPT_COMMON_DEBUG_ONLY
75 * POPT_COMMON_OPTION_ONLY
76 * POPT_COMMON_CONFIG_ONLY
77 * POPT_COMMON_SAMBA
79 * @param[in] mem_ctx The talloc memory context to use for allocating memory.
80 * This should be a long living context till the client
81 * exits.
83 * @param[in] require_smbconf Whether the smb.conf file is required to be
84 * present or not?
86 * @return true on success, false if an error occurred.
88 bool samba_cmdline_init(TALLOC_CTX *mem_ctx,
89 enum samba_cmdline_config_type config_type,
90 bool require_smbconf);
92 /**
93 * @brief Get a pointer of loadparm context used for the command line interface.
95 * @return The loadparm context.
97 struct loadparm_context *samba_cmdline_get_lp_ctx(void);
99 /**
100 * @brief Get the client credentials of the command line interface.
102 * @return A pointer to the client credentials.
104 struct cli_credentials *samba_cmdline_get_creds(void);
107 * @brief Get a pointer to the poptOption for the given option section.
109 * You should not directly use this function, but the macros.
111 * @param[in] opt The options to retrieve.
113 * @return A pointer to the poptOption array.
115 * @see POPT_COMMON_DEBUG_ONLY
116 * @see POPT_COMMON_OPTION_ONLY
117 * @see POPT_COMMON_CONFIG_ONLY
118 * @see POPT_COMMON_SAMBA
119 * @see POPT_COMMON_CONNECTION
120 * @see POPT_COMMON_CREDENTIALS
121 * @see POPT_COMMON_VERSION
123 struct poptOption *samba_cmdline_get_popt(enum smb_cmdline_popt_options opt);
126 * @brief Get a pointer to the poptOptions for daemons
128 * @return A pointer to the daemon options
130 * @see POPT_COMMON_DAEMON
132 struct samba_cmdline_daemon_cfg *samba_cmdline_get_daemon_cfg(void);
134 void samba_cmdline_set_machine_account_fn(
135 NTSTATUS (*fn) (struct cli_credentials *cred,
136 struct loadparm_context *lp_ctx));
139 * @brief Burn secrets on the command line.
141 * This function removes secrets from the command line so we don't leak e.g.
142 * passwords on 'ps aux' output.
144 * It should be called after processing the options and you should pass down
145 * argv from main().
147 * @param[in] argc The number of arguments.
149 * @param[in] argv[] The argument array we should remove secrets from.
151 * @return true if a password was removed, false otherwise.
153 bool samba_cmdline_burn(int argc, char *argv[]);
156 * @brief Sanity check the command line options.
158 * This checks for duplicates in short and long options.
160 * @param[in] opts The options array to check.
162 * @return true if valid, false otherwise.
164 bool samba_cmdline_sanity_check(const struct poptOption *opts);
167 * @brief This is a wrapper for the poptGetContext() which initializes the popt
168 * context.
170 * If Samba is build in developer mode, this will call
171 * samba_cmdline_sanity_check() before poptGetContext().
173 * @param[in] name The context name (usually argv[0] program name or
174 * getprogname())
176 * @param[in] argc Number of arguments
178 * @param[in] argv The argument array
180 * @param[in] options The address of popt option table
182 * @param[in] flags The OR'd POPT_CONTEXT_* bits
184 * @return The initialized popt context or NULL on error.
186 poptContext samba_popt_get_context(const char * name,
187 int argc, const char ** argv,
188 const struct poptOption * options,
189 unsigned int flags);
192 * @brief A popt structure for common debug options only.
194 #define POPT_COMMON_DEBUG_ONLY { \
195 .longName = NULL, \
196 .shortName = '\0', \
197 .argInfo = POPT_ARG_INCLUDE_TABLE, \
198 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_DEBUG_ONLY), \
199 .val = 0, \
200 .descrip = "Common debug options:", \
201 .argDescrip = NULL },
204 * @brief A popt structure for --option only.
206 #define POPT_COMMON_OPTION_ONLY { \
207 .longName = NULL, \
208 .shortName = '\0', \
209 .argInfo = POPT_ARG_INCLUDE_TABLE, \
210 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_OPTION_ONLY), \
211 .val = 0, \
212 .descrip = "Options:", \
213 .argDescrip = NULL },
216 * @brief A popt structure for --configfile only.
218 #define POPT_COMMON_CONFIG_ONLY { \
219 .longName = NULL, \
220 .shortName = '\0', \
221 .argInfo = POPT_ARG_INCLUDE_TABLE, \
222 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_CONFIG_ONLY), \
223 .val = 0, \
224 .descrip = "Config file:", \
225 .argDescrip = NULL },
228 * @brief A popt structure for common samba options.
230 #define POPT_COMMON_SAMBA { \
231 .longName = NULL, \
232 .shortName = '\0', \
233 .argInfo = POPT_ARG_INCLUDE_TABLE, \
234 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_SAMBA), \
235 .val = 0, \
236 .descrip = "Common Samba options:", \
237 .argDescrip = NULL },
240 * @brief A popt structure for connection options.
242 #define POPT_COMMON_CONNECTION { \
243 .longName = NULL, \
244 .shortName = '\0', \
245 .argInfo = POPT_ARG_INCLUDE_TABLE, \
246 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_CONNECTION), \
247 .val = 0, \
248 .descrip = "Connection options:", \
249 .argDescrip = NULL },
252 * @brief A popt structure for credential options.
254 #define POPT_COMMON_CREDENTIALS { \
255 .longName = NULL, \
256 .shortName = '\0', \
257 .argInfo = POPT_ARG_INCLUDE_TABLE, \
258 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_CREDENTIALS), \
259 .val = 0, \
260 .descrip = "Credential options:", \
261 .argDescrip = NULL },
264 * @brief A popt structure for version options.
266 #define POPT_COMMON_VERSION { \
267 .longName = NULL, \
268 .shortName = '\0', \
269 .argInfo = POPT_ARG_INCLUDE_TABLE, \
270 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_VERSION), \
271 .val = 0, \
272 .descrip = "Version options:", \
273 .argDescrip = NULL },
276 * @brief A popt structure for daemon options.
278 #define POPT_COMMON_DAEMON { \
279 .longName = NULL, \
280 .shortName = '\0', \
281 .argInfo = POPT_ARG_INCLUDE_TABLE, \
282 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_DAEMON), \
283 .val = 0, \
284 .descrip = "Daemon options:", \
285 .argDescrip = NULL },
288 * @brief A popt structure for common samba options.
290 #define POPT_COMMON_SAMBA_LDB { \
291 .longName = NULL, \
292 .shortName = '\0', \
293 .argInfo = POPT_ARG_INCLUDE_TABLE, \
294 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_SAMBA_LDB), \
295 .val = 0, \
296 .descrip = "Common Samba options:", \
297 .argDescrip = NULL },
299 /* TODO Get rid of me! */
300 #define POPT_LEGACY_S3 { \
301 .longName = NULL, \
302 .shortName = '\0', \
303 .argInfo = POPT_ARG_INCLUDE_TABLE, \
304 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_LEGACY_S3), \
305 .val = 0, \
306 .descrip = "Deprecated legacy options:", \
307 .argDescrip = NULL },
309 /* TODO Get rid of me! */
310 #define POPT_LEGACY_S4 { \
311 .longName = NULL, \
312 .shortName = '\0', \
313 .argInfo = POPT_ARG_INCLUDE_TABLE, \
314 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_LEGACY_S4), \
315 .val = 0, \
316 .descrip = "Deprecated legacy options:", \
317 .argDescrip = NULL },
319 #endif /* _CMDLINE_H */