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"
40 #include "param/loadparm.h"
43 /***********************************************
44 Here we do a set of 'hard coded' checks for bad
45 configuration settings.
46 ************************************************/
48 static int do_global_checks(struct loadparm_context
*lp_ctx
)
52 if (!directory_exist(lp_lockdir(lp_ctx
))) {
53 fprintf(stderr
, "ERROR: lock directory %s does not exist\n",
58 if (!directory_exist(lp_piddir(lp_ctx
))) {
59 fprintf(stderr
, "ERROR: pid directory %s does not exist\n",
64 if (strlen(lp_winbind_separator(lp_ctx
)) != 1) {
65 fprintf(stderr
,"ERROR: the 'winbind separator' parameter must be a single character.\n");
69 if (*lp_winbind_separator(lp_ctx
) == '+') {
70 fprintf(stderr
,"'winbind separator = +' might cause problems with group membership.\n");
77 static int do_share_checks(struct loadparm_context
*lp_ctx
, const char *cname
, const char *caddr
, bool silent_mode
,
78 bool show_defaults
, const char *section_name
, const char *parameter_name
)
83 for (s
=0;s
<lp_numservices(lp_ctx
);s
++) {
84 struct loadparm_service
*service
= lp_servicebynum(lp_ctx
, s
);
86 if (strlen(lp_servicename(lp_servicebynum(lp_ctx
, s
))) > 12) {
87 fprintf(stderr
, "WARNING: You have some share names that are longer than 12 characters.\n" );
88 fprintf(stderr
, "These may not be accessible to some older clients.\n" );
89 fprintf(stderr
, "(Eg. Windows9x, WindowsMe, and not listed in smbclient in Samba 3.0.)\n" );
94 for (s
=0;s
<lp_numservices(lp_ctx
);s
++) {
95 struct loadparm_service
*service
= lp_servicebynum(lp_ctx
, s
);
96 if (service
!= NULL
) {
97 const char **deny_list
= lp_hostsdeny(service
, lp_default_service(lp_ctx
));
98 const char **allow_list
= lp_hostsallow(service
, lp_default_service(lp_ctx
));
101 for (i
=0; deny_list
[i
]; i
++) {
102 char *hasstar
= strchr_m(deny_list
[i
], '*');
103 char *hasquery
= strchr_m(deny_list
[i
], '?');
104 if(hasstar
|| hasquery
) {
105 fprintf(stderr
,"Invalid character %c in hosts deny list (%s) for service %s.\n",
106 hasstar
? *hasstar
: *hasquery
, deny_list
[i
], lp_servicename(service
) );
112 for (i
=0; allow_list
[i
]; i
++) {
113 char *hasstar
= strchr_m(allow_list
[i
], '*');
114 char *hasquery
= strchr_m(allow_list
[i
], '?');
115 if(hasstar
|| hasquery
) {
116 fprintf(stderr
,"Invalid character %c in hosts allow list (%s) for service %s.\n",
117 hasstar
? *hasstar
: *hasquery
, allow_list
[i
], lp_servicename(service
) );
127 fprintf(stderr
,"Press enter to see a dump of your service definitions\n");
131 if (section_name
!= NULL
|| parameter_name
!= NULL
) {
132 struct loadparm_service
*service
= NULL
;
134 section_name
= GLOBAL_NAME
;
136 } else if ((!strwicmp(section_name
, GLOBAL_NAME
)) == 0 &&
137 (service
=lp_service(lp_ctx
, section_name
)) == NULL
) {
138 fprintf(stderr
,"Unknown section %s\n",
142 if (!parameter_name
) {
143 lp_dump_one(stdout
, show_defaults
, service
, lp_default_service(lp_ctx
));
145 ret
= !lp_dump_a_parameter(lp_ctx
, service
, parameter_name
, stdout
);
148 lp_dump(lp_ctx
, stdout
, show_defaults
, lp_numservices(lp_ctx
));
154 /* this is totally ugly, a real `quick' hack */
155 for (s
=0;s
<lp_numservices(lp_ctx
);s
++) {
156 struct loadparm_service
*service
= lp_servicebynum(lp_ctx
, s
);
157 if (service
!= NULL
) {
158 if (allow_access(NULL
, lp_hostsdeny(NULL
, lp_default_service(lp_ctx
)), lp_hostsallow(NULL
, lp_default_service(lp_ctx
)), cname
, caddr
)
159 && allow_access(NULL
, lp_hostsdeny(service
, lp_default_service(lp_ctx
)), lp_hostsallow(service
, lp_default_service(lp_ctx
)), cname
, caddr
)) {
160 fprintf(stderr
,"Allow connection from %s (%s) to %s\n",
161 cname
,caddr
,lp_servicename(service
));
163 fprintf(stderr
,"Deny connection from %s (%s) to %s\n",
164 cname
,caddr
,lp_servicename(service
));
174 int main(int argc
, const char *argv
[])
176 static bool silent_mode
= false;
180 static int show_all_parameters = 0;
181 static char *new_local_machine = NULL;
183 static const char *section_name
= NULL
;
184 static char *parameter_name
= NULL
;
185 static const char *cname
;
186 static const char *caddr
;
187 static bool show_defaults
= false;
188 struct loadparm_context
*lp_ctx
;
190 struct poptOption long_options
[] = {
192 {"suppress-prompt", 0, POPT_ARG_NONE
, &silent_mode
, true, "Suppress prompt for enter"},
193 {"verbose", 'v', POPT_ARG_NONE
, &show_defaults
, true, "Show default options too"},
195 We need support for smb.conf macros before this will work again
196 {"server", 'L',POPT_ARG_STRING, &new_local_machine, 0, "Set %%L macro to servername\n"},
199 These are harder to do with the new code structure
200 {"show-all-parameters", '\0', POPT_ARG_NONE, &show_all_parameters, 1, "Show the parameters, type, possible values" },
202 {"section-name", '\0', POPT_ARG_STRING
, §ion_name
, 0, "Limit testparm to a named section" },
203 {"parameter-name", '\0', POPT_ARG_STRING
, ¶meter_name
, 0, "Limit testparm to a named parameter" },
204 {"client-name", '\0', POPT_ARG_STRING
, &cname
, 0, "Client DNS name for 'hosts allow' checking (should match reverse lookup)"},
205 {"client-ip", '\0', POPT_ARG_STRING
, &caddr
, 0, "Client IP address for 'hosts allow' checking"},
211 setup_logging(NULL
, DEBUG_STDERR
);
213 pc
= poptGetContext(NULL
, argc
, argv
, long_options
,
214 POPT_CONTEXT_KEEP_FIRST
);
215 poptSetOtherOptionHelp(pc
, "[OPTION...] [host-name] [host-ip]");
217 while(poptGetNextOpt(pc
) != -1);
220 if (show_all_parameters) {
221 show_parameter_list();
226 if ( cname
&& ! caddr
) {
227 printf ( "ERROR: For 'hosts allow' check you must specify both a DNS name and an IP address.\n" );
231 We need support for smb.conf macros before this will work again
233 if (new_local_machine) {
234 set_local_machine_name(new_local_machine, True);
238 lp_ctx
= cmdline_lp_ctx
;
240 /* We need this to force the output */
241 lp_set_cmdline(lp_ctx
, "log level", "2");
243 fprintf(stderr
, "Loaded smb config files from %s\n", lp_configfile(lp_ctx
));
245 if (!lp_load(lp_ctx
, lp_configfile(lp_ctx
))) {
246 fprintf(stderr
,"Error loading services.\n");
250 fprintf(stderr
,"Loaded services file OK.\n");
252 ret
= do_global_checks(lp_ctx
);
253 ret
|= do_share_checks(lp_ctx
, cname
, caddr
, silent_mode
, show_defaults
, section_name
, parameter_name
);