s4-param Add hook between Samba3 and Samba4 loadparm systems.
[samba.git] / source4 / param / param.h
1 /* 
2    Unix SMB/CIFS implementation.
3    Generic parameter parsing interface
4    Copyright (C) Jelmer Vernooij                                          2005
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef _PARAM_H /* _PARAM_H */
21 #define _PARAM_H 
22
23 struct loadparm_s3_context;
24
25 struct parmlist_entry;
26
27 struct param_context {
28         struct param_section *sections;
29 };
30
31 struct param_section {
32         const char *name;
33         struct param_section *prev, *next;
34         struct parmlist *parameters;
35 };
36
37 struct param_context;
38 struct smbsrv_connection;
39
40 #define Auto (2)
41
42 typedef NTSTATUS (*init_module_fn) (void);
43
44 /* this needs to be a string which is not in the C library. We
45    previously used "init_module", but that meant that modules which
46    did not define this function ended up calling the C library
47    function init_module() which makes a system call */
48 #define SAMBA_INIT_MODULE "samba_init_module"
49
50 #include "libds/common/roles.h"
51
52 enum announce_as {/* Types of machine we can announce as. */
53         ANNOUNCE_AS_NT_SERVER=1,
54         ANNOUNCE_AS_WIN95=2,
55         ANNOUNCE_AS_WFW=3,
56         ANNOUNCE_AS_NT_WORKSTATION=4
57 };
58
59 struct loadparm_context;
60 struct loadparm_service;
61 struct smbcli_options;
62 struct smbcli_session_options;
63 struct gensec_settings;
64
65 #ifdef CONFIG_H_IS_FROM_SAMBA
66 #include "param/param_proto.h"
67 #endif
68
69 const char **lpcfg_interfaces(struct loadparm_context *);
70 const char *lpcfg_realm(struct loadparm_context *);
71 const char *lpcfg_netbios_name(struct loadparm_context *);
72 const char *lpcfg_private_dir(struct loadparm_context *);
73 int lpcfg_server_role(struct loadparm_context *);
74
75 void reload_charcnv(struct loadparm_context *lp_ctx);
76
77 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx);
78 struct parm_struct *lpcfg_parm_table(void);
79
80
81 char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *);
82 char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *);
83 char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *);
84 char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *);
85 char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *);
86
87 const char *lpcfg_servicename(const struct loadparm_service *service);
88
89
90 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
91                               struct loadparm_service *service,
92                               const char *type, const char *option);
93
94 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
95                            struct loadparm_service *service, const char *type,
96                            const char *option);
97 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
98                                  struct loadparm_context *lp_ctx,
99                                  struct loadparm_service *service,
100                                  const char *type,
101                                  const char *option, const char *separator);
102 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
103                 struct loadparm_service *service, const char *type,
104                 const char *option, int default_v);
105 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
106                   struct loadparm_service *service, const char *type,
107                   const char *option, int default_v);
108 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
109                             struct loadparm_service *service, const char *type,
110                             const char *option, unsigned long default_v);
111 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
112                       struct loadparm_service *service, const char *type,
113                       const char *option, double default_v);
114 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
115                      struct loadparm_service *service, const char *type,
116                      const char *option, bool default_v);
117 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
118                                      const struct loadparm_service *pservice,
119                                      const char *name);
120 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
121                  const char *pszHomename,
122                  struct loadparm_service *default_service,
123                  const char *user, const char *pszHomedir);
124 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
125                     const char *pszPrintername,
126                     struct loadparm_service *default_service);
127 struct parm_struct *lpcfg_parm_struct(const char *name);
128 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
129                   struct loadparm_service *service, struct parm_struct *parm);
130 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx);
131
132 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
133                             const char *pszParmName, const char *pszParmValue);
134 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
135                              struct loadparm_service *service,
136                              const char *pszParmName, const char *pszParmValue);
137
138 /**
139  * Process a parameter.
140  */
141 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
142                                 const char *pszParmName, const char *fmt, ...);
143 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
144                     const char *pszParmValue);
145 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option);
146
147 /**
148  * Display the contents of a single services record.
149  */
150 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
151                          struct loadparm_service *service,
152                          const char *parm_name, FILE * f);
153
154 /**
155  * Return info about the next service  in a service. snum==-1 gives the globals.
156  * Return NULL when out of parameters.
157  */
158 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
159                                       int allparameters);
160
161 /**
162  * Unload unused services.
163  */
164 void lpcfg_killunused(struct loadparm_context *lp_ctx,
165                    struct smbsrv_connection *smb,
166                    bool (*snumused) (struct smbsrv_connection *, int));
167
168 /**
169  * Initialise the global parameter structure.
170  */
171 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx);
172 struct loadparm_context *loadparm_init_global(bool load_default);
173 const char *lpcfg_configfile(struct loadparm_context *lp_ctx);
174 bool lpcfg_load_default(struct loadparm_context *lp_ctx);
175 const char *lp_default_path(void);
176
177 /**
178  * Load the services array from the services file.
179  *
180  * Return True on success, False on failure.
181  */
182 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename);
183
184 /**
185  * Return the max number of services.
186  */
187 int lpcfg_numservices(struct loadparm_context *lp_ctx);
188
189 /**
190  * Display the contents of the services array in human-readable form.
191  */
192 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
193              int maxtoprint);
194
195 /**
196  * Display the contents of one service in human-readable form.
197  */
198 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault);
199 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
200                                          int snum);
201 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
202                                     const char *service_name);
203
204 /**
205  * A useful volume label function.
206  */
207 const char *lp_cfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault);
208
209 /**
210  * If we are PDC then prefer us as DMB
211  */
212 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault);
213
214 /**
215  * Return the max print jobs per queue.
216  */
217 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault);
218 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx);
219 void lpcfg_smbcli_options(struct loadparm_context *lp_ctx,
220                          struct smbcli_options *options);
221 void lpcfg_smbcli_session_options(struct loadparm_context *lp_ctx,
222                                  struct smbcli_session_options *options);
223 struct dcerpc_server_info *lpcfg_dcerpc_server_info(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx);
224 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *, struct loadparm_context *);
225
226
227 /* The following definitions come from param/generic.c  */
228
229 struct param_section *param_get_section(struct param_context *ctx, const char *name);
230 struct parmlist_entry *param_section_get(struct param_section *section, 
231                                     const char *name);
232 struct parmlist_entry *param_get (struct param_context *ctx, const char *name, const char *section_name);
233 struct param_section *param_add_section(struct param_context *ctx, const char *section_name);
234 struct parmlist_entry *param_get_add(struct param_context *ctx, const char *name, const char *section_name);
235 const char *param_get_string(struct param_context *ctx, const char *param, const char *section);
236 int param_set_string(struct param_context *ctx, const char *param, const char *value, const char *section);
237 const char **param_get_string_list(struct param_context *ctx, const char *param, const char *separator, const char *section);
238 int param_set_string_list(struct param_context *ctx, const char *param, const char **list, const char *section);
239 int param_get_int(struct param_context *ctx, const char *param, int default_v, const char *section);
240 void param_set_int(struct param_context *ctx, const char *param, int value, const char *section);
241 unsigned long param_get_ulong(struct param_context *ctx, const char *param, unsigned long default_v, const char *section);
242 void param_set_ulong(struct param_context *ctx, const char *name, unsigned long value, const char *section);
243 struct param_context *param_init(TALLOC_CTX *mem_ctx);
244 int param_read(struct param_context *ctx, const char *fn);
245 int param_use(struct loadparm_context *lp_ctx, struct param_context *ctx);
246 int param_write(struct param_context *ctx, const char *fn);
247
248 /* The following definitions come from param/util.c  */
249
250
251 /**
252  * @file
253  * @brief Misc utility functions
254  */
255 bool lpcfg_is_mydomain(struct loadparm_context *lp_ctx,
256                              const char *domain);
257
258 bool lpcfg_is_my_domain_or_realm(struct loadparm_context *lp_ctx,
259                               const char *domain);
260
261 /**
262   see if a string matches either our primary or one of our secondary 
263   netbios aliases. do a case insensitive match
264 */
265 bool lpcfg_is_myname(struct loadparm_context *lp_ctx, const char *name);
266
267 /**
268  A useful function for returning a path in the Samba lock directory.
269 **/
270 char *lpcfg_lock_path(TALLOC_CTX* mem_ctx, struct loadparm_context *lp_ctx,
271                          const char *name);
272
273 /**
274  * @brief Returns an absolute path to a file in the directory containing the current config file
275  *
276  * @param name File to find, relative to the config file directory.
277  *
278  * @retval Pointer to a talloc'ed string containing the full path.
279  **/
280 char *lpcfg_config_path(TALLOC_CTX* mem_ctx, struct loadparm_context *lp_ctx,
281                            const char *name);
282
283 /**
284  * @brief Returns an absolute path to a file in the Samba private directory.
285  *
286  * @param name File to find, relative to PRIVATEDIR.
287  * if name is not relative, then use it as-is
288  *
289  * @retval Pointer to a talloc'ed string containing the full path.
290  **/
291 char *lpcfg_private_path(TALLOC_CTX* mem_ctx,
292                             struct loadparm_context *lp_ctx,
293                             const char *name);
294
295 /**
296   return a path in the smbd.tmp directory, where all temporary file
297   for smbd go. If NULL is passed for name then return the directory 
298   path itself
299 */
300 char *smbd_tmp_path(TALLOC_CTX *mem_ctx, 
301                              struct loadparm_context *lp_ctx,
302                              const char *name);
303
304 /**
305  * Obtain the init function from a shared library file
306  */
307 init_module_fn load_module(TALLOC_CTX *mem_ctx, const char *path);
308
309 /**
310  * Obtain list of init functions from the modules in the specified
311  * directory
312  */
313 init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path);
314
315 /**
316  * Run the specified init functions.
317  *
318  * @return true if all functions ran successfully, false otherwise
319  */
320 bool run_init_functions(init_module_fn *fns);
321
322 /**
323  * Load the initialization functions from DSO files for a specific subsystem.
324  *
325  * Will return an array of function pointers to initialization functions
326  */
327 init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, const char *subsystem);
328 const char *lpcfg_imessaging_path(TALLOC_CTX *mem_ctx,
329                                        struct loadparm_context *lp_ctx);
330 struct smb_iconv_handle *smb_iconv_handle_reinit_lp(TALLOC_CTX *mem_ctx,
331                                                               struct loadparm_context *lp_ctx,
332                                                               struct smb_iconv_handle *old_ic);
333
334 const char *lpcfg_sam_name(struct loadparm_context *lp_ctx);
335
336 /* The following definitions come from lib/version.c  */
337
338 const char *samba_version_string(void);
339
340
341 #endif /* _PARAM_H */