lib/util: consolidate module loading into common code
[amitay/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 #include "libds/common/roles.h"
43
44 struct loadparm_context;
45 struct loadparm_service;
46 struct smbcli_options;
47 struct smbcli_session_options;
48 struct gensec_settings;
49
50 #ifdef CONFIG_H_IS_FROM_SAMBA
51 #include "param/param_proto.h"
52 #endif
53
54 const char **lpcfg_interfaces(struct loadparm_context *);
55 const char *lpcfg_realm(struct loadparm_context *);
56 const char *lpcfg_netbios_name(struct loadparm_context *);
57 const char *lpcfg_private_dir(struct loadparm_context *);
58 int lpcfg_server_role(struct loadparm_context *);
59
60 void reload_charcnv(struct loadparm_context *lp_ctx);
61
62 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx);
63
64
65 char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *);
66 char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *);
67 char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *);
68 char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *);
69 char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *);
70
71 const char *lpcfg_servicename(const struct loadparm_service *service);
72
73
74 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
75                               struct loadparm_service *service,
76                               const char *type, const char *option);
77
78 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
79                            struct loadparm_service *service, const char *type,
80                            const char *option);
81 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
82                                  struct loadparm_context *lp_ctx,
83                                  struct loadparm_service *service,
84                                  const char *type,
85                                  const char *option, const char *separator);
86 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
87                 struct loadparm_service *service, const char *type,
88                 const char *option, int default_v);
89 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
90                   struct loadparm_service *service, const char *type,
91                   const char *option, int default_v);
92 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
93                             struct loadparm_service *service, const char *type,
94                             const char *option, unsigned long default_v);
95 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
96                       struct loadparm_service *service, const char *type,
97                       const char *option, double default_v);
98 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
99                      struct loadparm_service *service, const char *type,
100                      const char *option, bool default_v);
101 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
102                                      const struct loadparm_service *pservice,
103                                      const char *name);
104 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
105                  const char *pszHomename,
106                  struct loadparm_service *default_service,
107                  const char *user, const char *pszHomedir);
108 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
109                     const char *pszPrintername,
110                     struct loadparm_service *default_service);
111 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name);
112 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
113                   struct loadparm_service *service, struct parm_struct *parm);
114 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx);
115
116 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
117                             const char *pszParmName, const char *pszParmValue);
118 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
119                              struct loadparm_service *service,
120                              const char *pszParmName, const char *pszParmValue);
121
122 /**
123  * Process a parameter.
124  */
125 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
126                                 const char *pszParmName, const char *fmt, ...);
127 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
128                     const char *pszParmValue);
129 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option);
130
131 /**
132  * Display the contents of a single services record.
133  */
134 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
135                          struct loadparm_service *service,
136                          const char *parm_name, FILE * f);
137
138 /**
139  * Return info about the next service  in a service. snum==-1 gives the globals.
140  * Return NULL when out of parameters.
141  */
142 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
143                                       int allparameters);
144
145 /**
146  * Unload unused services.
147  */
148 void lpcfg_killunused(struct loadparm_context *lp_ctx,
149                    struct smbsrv_connection *smb,
150                    bool (*snumused) (struct smbsrv_connection *, int));
151
152 /**
153  * Initialise the global parameter structure.
154  */
155 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx);
156 struct loadparm_context *loadparm_init_global(bool load_default);
157 const char *lpcfg_configfile(struct loadparm_context *lp_ctx);
158 bool lpcfg_load_default(struct loadparm_context *lp_ctx);
159 const char *lp_default_path(void);
160
161 /**
162  * Load the services array from the services file.
163  *
164  * Return True on success, False on failure.
165  */
166 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename);
167
168 /**
169  * Return the max number of services.
170  */
171 int lpcfg_numservices(struct loadparm_context *lp_ctx);
172
173 /**
174  * Display the contents of the services array in human-readable form.
175  */
176 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
177              int maxtoprint);
178
179 /**
180  * Display the contents of one service in human-readable form.
181  */
182 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault);
183 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
184                                          int snum);
185 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
186                                     const char *service_name);
187
188 /**
189  * A useful volume label function.
190  */
191 const char *lp_cfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault);
192
193 /**
194  * If we are PDC then prefer us as DMB
195  */
196 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault);
197
198 /**
199  * Return the max print jobs per queue.
200  */
201 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault);
202 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx);
203 void lpcfg_smbcli_options(struct loadparm_context *lp_ctx,
204                          struct smbcli_options *options);
205 void lpcfg_smbcli_session_options(struct loadparm_context *lp_ctx,
206                                  struct smbcli_session_options *options);
207 struct dcerpc_server_info *lpcfg_dcerpc_server_info(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx);
208 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *, struct loadparm_context *);
209
210
211 /* The following definitions come from param/generic.c  */
212
213 struct param_section *param_get_section(struct param_context *ctx, const char *name);
214 struct parmlist_entry *param_section_get(struct param_section *section, 
215                                     const char *name);
216 struct parmlist_entry *param_get (struct param_context *ctx, const char *name, const char *section_name);
217 struct param_section *param_add_section(struct param_context *ctx, const char *section_name);
218 struct parmlist_entry *param_get_add(struct param_context *ctx, const char *name, const char *section_name);
219 const char *param_get_string(struct param_context *ctx, const char *param, const char *section);
220 int param_set_string(struct param_context *ctx, const char *param, const char *value, const char *section);
221 const char **param_get_string_list(struct param_context *ctx, const char *param, const char *separator, const char *section);
222 int param_set_string_list(struct param_context *ctx, const char *param, const char **list, const char *section);
223 int param_get_int(struct param_context *ctx, const char *param, int default_v, const char *section);
224 void param_set_int(struct param_context *ctx, const char *param, int value, const char *section);
225 unsigned long param_get_ulong(struct param_context *ctx, const char *param, unsigned long default_v, const char *section);
226 void param_set_ulong(struct param_context *ctx, const char *name, unsigned long value, const char *section);
227 struct param_context *param_init(TALLOC_CTX *mem_ctx);
228 int param_read(struct param_context *ctx, const char *fn);
229 int param_use(struct loadparm_context *lp_ctx, struct param_context *ctx);
230 int param_write(struct param_context *ctx, const char *fn);
231
232 /* The following definitions come from param/util.c  */
233
234
235 /**
236  * @file
237  * @brief Misc utility functions
238  */
239 bool lpcfg_is_mydomain(struct loadparm_context *lp_ctx,
240                              const char *domain);
241
242 bool lpcfg_is_my_domain_or_realm(struct loadparm_context *lp_ctx,
243                               const char *domain);
244
245 /**
246   see if a string matches either our primary or one of our secondary 
247   netbios aliases. do a case insensitive match
248 */
249 bool lpcfg_is_myname(struct loadparm_context *lp_ctx, const char *name);
250
251 /**
252  A useful function for returning a path in the Samba lock directory.
253 **/
254 char *lpcfg_lock_path(TALLOC_CTX* mem_ctx, struct loadparm_context *lp_ctx,
255                          const char *name);
256
257 /**
258  * @brief Returns an absolute path to a file in the directory containing the current config file
259  *
260  * @param name File to find, relative to the config file directory.
261  *
262  * @retval Pointer to a talloc'ed string containing the full path.
263  **/
264 char *lpcfg_config_path(TALLOC_CTX* mem_ctx, struct loadparm_context *lp_ctx,
265                            const char *name);
266
267 /**
268  * @brief Returns an absolute path to a file in the Samba private directory.
269  *
270  * @param name File to find, relative to PRIVATEDIR.
271  * if name is not relative, then use it as-is
272  *
273  * @retval Pointer to a talloc'ed string containing the full path.
274  **/
275 char *lpcfg_private_path(TALLOC_CTX* mem_ctx,
276                             struct loadparm_context *lp_ctx,
277                             const char *name);
278
279 /**
280   return a path in the smbd.tmp directory, where all temporary file
281   for smbd go. If NULL is passed for name then return the directory 
282   path itself
283 */
284 char *smbd_tmp_path(TALLOC_CTX *mem_ctx, 
285                              struct loadparm_context *lp_ctx,
286                              const char *name);
287
288 const char *lpcfg_imessaging_path(TALLOC_CTX *mem_ctx,
289                                        struct loadparm_context *lp_ctx);
290 struct smb_iconv_handle *smb_iconv_handle_reinit_lp(TALLOC_CTX *mem_ctx,
291                                                               struct loadparm_context *lp_ctx,
292                                                               struct smb_iconv_handle *old_ic);
293
294 const char *lpcfg_sam_name(struct loadparm_context *lp_ctx);
295
296 /* The following definitions come from lib/version.c  */
297
298 const char *samba_version_string(void);
299
300
301 #endif /* _PARAM_H */