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