s3: smbd: Cleanup. smb2_file_rename_information() can never have a @GMT path in the...
[Samba.git] / lib / cmdline / cmdline.h
blobe254a1db5c382e90a6e9fece0186b9ab485a9983
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 Wether the smb.conf file is required to be
84 * present or not?
86 * @return true on success, false if an error occured.
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 void samba_cmdline_burn(int argc, char *argv[]);
154 * @brief Sanity check the command line options.
156 * This checks for duplicates in short and long options.
158 * @param[in] opts The options array to check.
160 * @return true if valid, false otherwise.
162 bool samba_cmdline_sanity_check(const struct poptOption *opts);
165 * @brief This is a wrapper for the poptGetContext() which initializes the popt
166 * context.
168 * If Samba is build in developer mode, this will call
169 * samba_cmdline_sanity_check() before poptGetContext().
171 * @param[in] name The context name (usually argv[0] program name or
172 * getprogname())
174 * @param[in] argc Number of arguments
176 * @param[in] argv The argument array
178 * @param[in] options The address of popt option table
180 * @param[in] flags The OR'd POPT_CONTEXT_* bits
182 * @return The initialized popt context or NULL on error.
184 poptContext samba_popt_get_context(const char * name,
185 int argc, const char ** argv,
186 const struct poptOption * options,
187 unsigned int flags);
190 * @brief A popt structure for common debug options only.
192 #define POPT_COMMON_DEBUG_ONLY { \
193 .longName = NULL, \
194 .shortName = '\0', \
195 .argInfo = POPT_ARG_INCLUDE_TABLE, \
196 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_DEBUG_ONLY), \
197 .val = 0, \
198 .descrip = "Common debug options:", \
199 .argDescrip = NULL },
202 * @brief A popt structure for --option only.
204 #define POPT_COMMON_OPTION_ONLY { \
205 .longName = NULL, \
206 .shortName = '\0', \
207 .argInfo = POPT_ARG_INCLUDE_TABLE, \
208 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_OPTION_ONLY), \
209 .val = 0, \
210 .descrip = "Options:", \
211 .argDescrip = NULL },
214 * @brief A popt structure for --configfile only.
216 #define POPT_COMMON_CONFIG_ONLY { \
217 .longName = NULL, \
218 .shortName = '\0', \
219 .argInfo = POPT_ARG_INCLUDE_TABLE, \
220 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_CONFIG_ONLY), \
221 .val = 0, \
222 .descrip = "Config file:", \
223 .argDescrip = NULL },
226 * @brief A popt structure for common samba options.
228 #define POPT_COMMON_SAMBA { \
229 .longName = NULL, \
230 .shortName = '\0', \
231 .argInfo = POPT_ARG_INCLUDE_TABLE, \
232 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_SAMBA), \
233 .val = 0, \
234 .descrip = "Common Samba options:", \
235 .argDescrip = NULL },
238 * @brief A popt structure for connection options.
240 #define POPT_COMMON_CONNECTION { \
241 .longName = NULL, \
242 .shortName = '\0', \
243 .argInfo = POPT_ARG_INCLUDE_TABLE, \
244 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_CONNECTION), \
245 .val = 0, \
246 .descrip = "Connection options:", \
247 .argDescrip = NULL },
250 * @brief A popt structure for credential options.
252 #define POPT_COMMON_CREDENTIALS { \
253 .longName = NULL, \
254 .shortName = '\0', \
255 .argInfo = POPT_ARG_INCLUDE_TABLE, \
256 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_CREDENTIALS), \
257 .val = 0, \
258 .descrip = "Credential options:", \
259 .argDescrip = NULL },
262 * @brief A popt structure for version options.
264 #define POPT_COMMON_VERSION { \
265 .longName = NULL, \
266 .shortName = '\0', \
267 .argInfo = POPT_ARG_INCLUDE_TABLE, \
268 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_VERSION), \
269 .val = 0, \
270 .descrip = "Version options:", \
271 .argDescrip = NULL },
274 * @brief A popt structure for daemon options.
276 #define POPT_COMMON_DAEMON { \
277 .longName = NULL, \
278 .shortName = '\0', \
279 .argInfo = POPT_ARG_INCLUDE_TABLE, \
280 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_DAEMON), \
281 .val = 0, \
282 .descrip = "Daemon options:", \
283 .argDescrip = NULL },
286 * @brief A popt structure for common samba options.
288 #define POPT_COMMON_SAMBA_LDB { \
289 .longName = NULL, \
290 .shortName = '\0', \
291 .argInfo = POPT_ARG_INCLUDE_TABLE, \
292 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_SAMBA_LDB), \
293 .val = 0, \
294 .descrip = "Common Samba options:", \
295 .argDescrip = NULL },
297 /* TODO Get rid of me! */
298 #define POPT_LEGACY_S3 { \
299 .longName = NULL, \
300 .shortName = '\0', \
301 .argInfo = POPT_ARG_INCLUDE_TABLE, \
302 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_LEGACY_S3), \
303 .val = 0, \
304 .descrip = "Deprecated legacy options:", \
305 .argDescrip = NULL },
307 /* TODO Get rid of me! */
308 #define POPT_LEGACY_S4 { \
309 .longName = NULL, \
310 .shortName = '\0', \
311 .argInfo = POPT_ARG_INCLUDE_TABLE, \
312 .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_LEGACY_S4), \
313 .val = 0, \
314 .descrip = "Deprecated legacy options:", \
315 .argDescrip = NULL },
317 #endif /* _CMDLINE_H */