2 Unix SMB/CIFS implementation.
3 Test validity of smb.conf
4 Copyright (C) Karl Auer 1993, 1994-1998
6 Extensively modified by Andrew Tridgell, 1995
7 Converted to popt by Jelmer Vernooij (jelmer@nl.linux.org), 2002
8 Updated for Samba4 by Andrew Bartlett <abartlet@samba.org> 2006
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * Testbed for loadparm.c/params.c
27 * This module simply loads a specified configuration file and
28 * if successful, dumps it's contents to stdout. Note that the
29 * operation is performed with DEBUGLEVEL at 3.
31 * Useful for a quick 'syntax check' of a configuration file.
36 #include "system/filesys.h"
37 #include "lib/cmdline/popt_common.h"
38 #include "lib/socket/socket.h"
39 #include "param/param.h"
42 /***********************************************
43 Here we do a set of 'hard coded' checks for bad
44 configuration settings.
45 ************************************************/
47 static int do_global_checks(struct loadparm_context
*lp_ctx
)
51 if (!directory_exist(lp_lockdir(lp_ctx
))) {
52 fprintf(stderr
, "ERROR: lock directory %s does not exist\n",
57 if (!directory_exist(lp_piddir(lp_ctx
))) {
58 fprintf(stderr
, "ERROR: pid directory %s does not exist\n",
63 if (strlen(lp_winbind_separator(lp_ctx
)) != 1) {
64 fprintf(stderr
,"ERROR: the 'winbind separator' parameter must be a single character.\n");
68 if (*lp_winbind_separator(lp_ctx
) == '+') {
69 fprintf(stderr
,"'winbind separator = +' might cause problems with group membership.\n");
76 static int do_share_checks(struct loadparm_context
*lp_ctx
, const char *cname
, const char *caddr
, bool silent_mode
,
77 bool show_defaults
, const char *section_name
, const char *parameter_name
)
82 for (s
=0;s
<lp_numservices(lp_ctx
);s
++) {
83 struct loadparm_service
*service
= lp_servicebynum(lp_ctx
, s
);
85 if (strlen(lp_servicename(lp_servicebynum(lp_ctx
, s
))) > 12) {
86 fprintf(stderr
, "WARNING: You have some share names that are longer than 12 characters.\n" );
87 fprintf(stderr
, "These may not be accessible to some older clients.\n" );
88 fprintf(stderr
, "(Eg. Windows9x, WindowsMe, and not listed in smbclient in Samba 3.0.)\n" );
93 for (s
=0;s
<lp_numservices(lp_ctx
);s
++) {
94 struct loadparm_service
*service
= lp_servicebynum(lp_ctx
, s
);
95 if (service
!= NULL
) {
96 const char **deny_list
= lp_hostsdeny(service
, lp_default_service(lp_ctx
));
97 const char **allow_list
= lp_hostsallow(service
, lp_default_service(lp_ctx
));
100 for (i
=0; deny_list
[i
]; i
++) {
101 char *hasstar
= strchr_m(deny_list
[i
], '*');
102 char *hasquery
= strchr_m(deny_list
[i
], '?');
103 if(hasstar
|| hasquery
) {
104 fprintf(stderr
,"Invalid character %c in hosts deny list (%s) for service %s.\n",
105 hasstar
? *hasstar
: *hasquery
, deny_list
[i
], lp_servicename(service
) );
111 for (i
=0; allow_list
[i
]; i
++) {
112 char *hasstar
= strchr_m(allow_list
[i
], '*');
113 char *hasquery
= strchr_m(allow_list
[i
], '?');
114 if(hasstar
|| hasquery
) {
115 fprintf(stderr
,"Invalid character %c in hosts allow list (%s) for service %s.\n",
116 hasstar
? *hasstar
: *hasquery
, allow_list
[i
], lp_servicename(service
) );
126 fprintf(stderr
,"Press enter to see a dump of your service definitions\n");
130 if (section_name
!= NULL
|| parameter_name
!= NULL
) {
131 struct loadparm_service
*service
= NULL
;
133 section_name
= GLOBAL_NAME
;
135 } else if ((!strwicmp(section_name
, GLOBAL_NAME
)) == 0 &&
136 (service
=lp_service(lp_ctx
, section_name
)) == NULL
) {
137 fprintf(stderr
,"Unknown section %s\n",
141 if (!parameter_name
) {
142 lp_dump_one(stdout
, show_defaults
, service
, lp_default_service(lp_ctx
));
144 ret
= !lp_dump_a_parameter(lp_ctx
, service
, parameter_name
, stdout
);
147 lp_dump(lp_ctx
, stdout
, show_defaults
, lp_numservices(lp_ctx
));
153 /* this is totally ugly, a real `quick' hack */
154 for (s
=0;s
<lp_numservices(lp_ctx
);s
++) {
155 struct loadparm_service
*service
= lp_servicebynum(lp_ctx
, s
);
156 if (service
!= NULL
) {
157 if (allow_access(NULL
, lp_hostsdeny(NULL
, lp_default_service(lp_ctx
)), lp_hostsallow(NULL
, lp_default_service(lp_ctx
)), cname
, caddr
)
158 && allow_access(NULL
, lp_hostsdeny(service
, lp_default_service(lp_ctx
)), lp_hostsallow(service
, lp_default_service(lp_ctx
)), cname
, caddr
)) {
159 fprintf(stderr
,"Allow connection from %s (%s) to %s\n",
160 cname
,caddr
,lp_servicename(service
));
162 fprintf(stderr
,"Deny connection from %s (%s) to %s\n",
163 cname
,caddr
,lp_servicename(service
));
173 int main(int argc
, const char *argv
[])
175 static bool silent_mode
= false;
179 static int show_all_parameters = 0;
180 static char *new_local_machine = NULL;
182 static const char *section_name
= NULL
;
183 static char *parameter_name
= NULL
;
184 static const char *cname
;
185 static const char *caddr
;
186 static bool show_defaults
= false;
187 struct loadparm_context
*lp_ctx
;
189 struct poptOption long_options
[] = {
191 {"suppress-prompt", 0, POPT_ARG_NONE
, &silent_mode
, true, "Suppress prompt for enter"},
192 {"verbose", 'v', POPT_ARG_NONE
, &show_defaults
, true, "Show default options too"},
194 We need support for smb.conf macros before this will work again
195 {"server", 'L',POPT_ARG_STRING, &new_local_machine, 0, "Set %%L macro to servername\n"},
198 These are harder to do with the new code structure
199 {"show-all-parameters", '\0', POPT_ARG_NONE, &show_all_parameters, 1, "Show the parameters, type, possible values" },
201 {"section-name", '\0', POPT_ARG_STRING
, §ion_name
, 0, "Limit testparm to a named section" },
202 {"parameter-name", '\0', POPT_ARG_STRING
, ¶meter_name
, 0, "Limit testparm to a named parameter" },
203 {"client-name", '\0', POPT_ARG_STRING
, &cname
, 0, "Client DNS name for 'hosts allow' checking (should match reverse lookup)"},
204 {"client-ip", '\0', POPT_ARG_STRING
, &caddr
, 0, "Client IP address for 'hosts allow' checking"},
210 setup_logging(NULL
, DEBUG_STDERR
);
212 pc
= poptGetContext(NULL
, argc
, argv
, long_options
,
213 POPT_CONTEXT_KEEP_FIRST
);
214 poptSetOtherOptionHelp(pc
, "[OPTION...] [host-name] [host-ip]");
216 while(poptGetNextOpt(pc
) != -1);
219 if (show_all_parameters) {
220 show_parameter_list();
225 if ( cname
&& ! caddr
) {
226 printf ( "ERROR: For 'hosts allow' check you must specify both a DNS name and an IP address.\n" );
230 We need support for smb.conf macros before this will work again
232 if (new_local_machine) {
233 set_local_machine_name(new_local_machine, True);
237 lp_ctx
= cmdline_lp_ctx
;
239 /* We need this to force the output */
240 lp_set_cmdline(lp_ctx
, "log level", "2");
242 fprintf(stderr
, "Loaded smb config files from %s\n", lp_configfile(lp_ctx
));
244 if (!lp_load(lp_ctx
, lp_configfile(lp_ctx
))) {
245 fprintf(stderr
,"Error loading services.\n");
249 fprintf(stderr
,"Loaded services file OK.\n");
251 ret
= do_global_checks(lp_ctx
);
252 ret
|= do_share_checks(lp_ctx
, cname
, caddr
, silent_mode
, show_defaults
, section_name
, parameter_name
);