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 2 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, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * Testbed for loadparm.c/params.c
28 * This module simply loads a specified configuration file and
29 * if successful, dumps it's contents to stdout. Note that the
30 * operation is performed with DEBUGLEVEL at 3.
32 * Useful for a quick 'syntax check' of a configuration file.
37 #include "system/filesys.h"
38 #include "lib/cmdline/popt_common.h"
39 #include "lib/socket/socket.h"
42 /***********************************************
43 Here we do a set of 'hard coded' checks for bad
44 configuration settings.
45 ************************************************/
47 static int do_global_checks(void)
51 if (!directory_exist(lp_lockdir())) {
52 fprintf(stderr
, "ERROR: lock directory %s does not exist\n",
57 if (!directory_exist(lp_piddir())) {
58 fprintf(stderr
, "ERROR: pid directory %s does not exist\n",
63 if (strlen(lp_winbind_separator()) != 1) {
64 fprintf(stderr
,"ERROR: the 'winbind separator' parameter must be a single character.\n");
68 if (*lp_winbind_separator() == '+') {
69 fprintf(stderr
,"'winbind separator = +' might cause problems with group membership.\n");
75 int main(int argc
, const char *argv
[])
78 static BOOL silent_mode
= False
;
82 static BOOL show_all_parameters = False;
83 static char *new_local_machine = NULL;
85 static const char *section_name
= NULL
;
86 static char *parameter_name
= NULL
;
87 static const char *cname
;
88 static const char *caddr
;
89 static int show_defaults
;
91 struct poptOption long_options
[] = {
93 {"suppress-prompt", '\0', POPT_ARG_VAL
, &silent_mode
, 1, "Suppress prompt for enter"},
94 {"verbose", 'v', POPT_ARG_NONE
, &show_defaults
, 1, "Show default options too"},
96 We need support for smb.conf macros before this will work again
97 {"server", 'L',POPT_ARG_STRING, &new_local_machine, 0, "Set %%L macro to servername\n"},
100 These are harder to do with the new code structure
101 {"show-all-parameters", '\0', POPT_ARG_VAL, &show_all_parameters, True, "Show the parameters, type, possible values" },
103 {"section-name", '\0', POPT_ARG_STRING
, §ion_name
, 0, "Limit testparm to a named section" },
104 {"parameter-name", '\0', POPT_ARG_STRING
, ¶meter_name
, 0, "Limit testparm to a named parameter" },
105 {"client-name", '\0', POPT_ARG_STRING
, &cname
, 0, "Client DNS name for 'hosts allow' checking (should match reverse lookup)"},
106 {"client-ip", '\0', POPT_ARG_STRING
, &caddr
, 0, "Client IP address for 'hosts allow' checking"},
112 setup_logging(NULL
, DEBUG_STDERR
);
114 pc
= poptGetContext(NULL
, argc
, argv
, long_options
,
115 POPT_CONTEXT_KEEP_FIRST
);
116 poptSetOtherOptionHelp(pc
, "[OPTION...] [host-name] [host-ip]");
118 while(poptGetNextOpt(pc
) != -1);
121 if (show_all_parameters) {
122 show_parameter_list();
127 if ( cname
&& ! caddr
) {
128 printf ( "ERROR: For 'hosts allow' check you must specify both a DNS name and an IP address.\n" );
132 We need support for smb.conf macros before this will work again
134 if (new_local_machine) {
135 set_local_machine_name(new_local_machine, True);
139 /* We need this to force the output */
140 lp_set_cmdline("log level", "2");
142 fprintf(stderr
,"Load smb config files from %s\n",lp_configfile());
145 fprintf(stderr
,"Error loading services.\n");
149 fprintf(stderr
,"Loaded services file OK.\n");
151 ret
= do_global_checks();
153 for (s
=0;s
<lp_numservices();s
++) {
155 if (strlen(lp_servicename(s
)) > 12) {
156 fprintf(stderr
, "WARNING: You have some share names that are longer than 12 characters.\n" );
157 fprintf(stderr
, "These may not be accessible to some older clients.\n" );
158 fprintf(stderr
, "(Eg. Windows9x, WindowsMe, and not listed in smbclient in Samba 3.0.)\n" );
163 for (s
=0;s
<lp_numservices();s
++) {
165 const char **deny_list
= lp_hostsdeny(s
);
166 const char **allow_list
= lp_hostsallow(s
);
169 for (i
=0; deny_list
[i
]; i
++) {
170 char *hasstar
= strchr_m(deny_list
[i
], '*');
171 char *hasquery
= strchr_m(deny_list
[i
], '?');
172 if(hasstar
|| hasquery
) {
173 fprintf(stderr
,"Invalid character %c in hosts deny list (%s) for service %s.\n",
174 hasstar
? *hasstar
: *hasquery
, deny_list
[i
], lp_servicename(s
) );
180 for (i
=0; allow_list
[i
]; i
++) {
181 char *hasstar
= strchr_m(allow_list
[i
], '*');
182 char *hasquery
= strchr_m(allow_list
[i
], '?');
183 if(hasstar
|| hasquery
) {
184 fprintf(stderr
,"Invalid character %c in hosts allow list (%s) for service %s.\n",
185 hasstar
? *hasstar
: *hasquery
, allow_list
[i
], lp_servicename(s
) );
195 fprintf(stderr
,"Press enter to see a dump of your service definitions\n");
199 if (section_name
|| parameter_name
) {
200 BOOL isGlobal
= False
;
202 section_name
= GLOBAL_NAME
;
204 } else if ((isGlobal
=!strwicmp(section_name
, GLOBAL_NAME
)) == 0 &&
205 (s
=lp_servicenumber(section_name
)) == -1) {
206 fprintf(stderr
,"Unknown section %s\n",
210 if (!parameter_name
) {
211 if (isGlobal
== True
) {
212 lp_dump(stdout
, show_defaults
, 0);
214 lp_dump_one(stdout
, show_defaults
, s
);
217 ret
= !lp_dump_a_parameter(s
, parameter_name
, stdout
, isGlobal
);
220 lp_dump(stdout
, show_defaults
, lp_numservices());
226 /* this is totally ugly, a real `quick' hack */
227 for (s
=0;s
<lp_numservices();s
++) {
229 if (allow_access(NULL
, lp_hostsdeny(-1), lp_hostsallow(-1), cname
, caddr
)
230 && allow_access(NULL
, lp_hostsdeny(s
), lp_hostsallow(s
), cname
, caddr
)) {
231 fprintf(stderr
,"Allow connection from %s (%s) to %s\n",
232 cname
,caddr
,lp_servicename(s
));
234 fprintf(stderr
,"Deny connection from %s (%s) to %s\n",
235 cname
,caddr
,lp_servicename(s
));