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
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * Testbed for loadparm.c/params.c
26 * This module simply loads a specified configuration file and
27 * if successful, dumps it's contents to stdout. Note that the
28 * operation is performed with DEBUGLEVEL at 3.
30 * Useful for a quick 'syntax check' of a configuration file.
37 extern BOOL AllowDebugChange;
39 /***********************************************
40 Here we do a set of 'hard coded' checks for bad
41 configuration settings.
42 ************************************************/
44 static int do_global_checks(void)
49 if (lp_security() == SEC_DOMAIN && !lp_encrypted_passwords()) {
50 printf("ERROR: in 'security=domain' mode the 'encrypt passwords' parameter must also be set to 'true'.\n");
54 if (lp_wins_support() && wins_srv_count()) {
55 printf("ERROR: both 'wins support = true' and 'wins server = <server>' \
56 cannot be set in the smb.conf file. nmbd will abort with this setting.\n");
60 if (!directory_exist(lp_lockdir(), &st)) {
61 printf("ERROR: lock directory %s does not exist\n",
64 } else if ((st.st_mode & 0777) != 0755) {
65 printf("WARNING: lock directory %s should have permissions 0755 for browsing to work\n",
71 * Password server sanity checks.
74 if((lp_security() == SEC_SERVER || lp_security() == SEC_DOMAIN) && !lp_passwordserver()) {
76 if(lp_security() == SEC_SERVER)
77 pstrcpy(sec_setting, "server");
78 else if(lp_security() == SEC_DOMAIN)
79 pstrcpy(sec_setting, "domain");
81 printf("ERROR: The setting 'security=%s' requires the 'password server' parameter be set \
82 to a valid password server.\n", sec_setting );
88 * Check 'hosts equiv' and 'use rhosts' compatability with 'hostname lookup' value.
91 if(*lp_hosts_equiv() && !lp_hostname_lookups()) {
92 printf("ERROR: The setting 'hosts equiv = %s' requires that 'hostname lookups = yes'.\n", lp_hosts_equiv());
97 * Password chat sanity checks.
100 if(lp_security() == SEC_USER && lp_unix_password_sync()) {
103 * Check that we have a valid lp_passwd_program() if not using pam.
107 if (!lp_pam_password_change()) {
110 if(lp_passwd_program() == NULL) {
111 printf("ERROR: the 'unix password sync' parameter is set and there is no valid 'passwd program' \
116 pstring truncated_prog;
119 pstrcpy( passwd_prog, lp_passwd_program());
121 *truncated_prog = '\0';
122 next_token(&p, truncated_prog, NULL, sizeof(pstring));
124 if(access(truncated_prog, F_OK) == -1) {
125 printf("ERROR: the 'unix password sync' parameter is set and the 'passwd program' (%s) \
126 cannot be executed (error was %s).\n", truncated_prog, strerror(errno) );
135 if(lp_passwd_chat() == NULL) {
136 printf("ERROR: the 'unix password sync' parameter is set and there is no valid 'passwd chat' \
142 * Check that we have a valid script and that it hasn't
143 * been written to expect the old password.
146 if(lp_encrypted_passwords()) {
147 if(strstr( lp_passwd_chat(), "%o")!=NULL) {
148 printf("ERROR: the 'passwd chat' script [%s] expects to use the old plaintext password \
149 via the %%o substitution. With encrypted passwords this is not possible.\n", lp_passwd_chat() );
158 static void usage(char *pname)
160 printf("Usage: %s [-sh] [-L servername] [configfilename] [hostname hostIP]\n", pname);
161 printf("\t-s Suppress prompt for enter\n");
162 printf("\t-h Print usage\n");
163 printf("\t-L servername Set %%L macro to servername\n");
164 printf("\t-t encoding Print parameters with encoding\n");
165 printf("\tconfigfilename Configuration file to test\n");
166 printf("\thostname hostIP. Hostname and Host IP address to test\n");
167 printf("\t against \"host allow\" and \"host deny\"\n");
172 int main(int argc, char *argv[])
176 extern fstring local_machine;
180 BOOL silent_mode = False;
186 setup_logging(argv[0],True);
188 while ((opt = getopt(argc, argv,"shL:t:")) != EOF) {
194 fstrcpy(local_machine,optarg);
201 pstrcpy(term_code,optarg);
204 printf("Incorrect program usage\n");
211 argc += (1 - optind);
213 if ((argc == 1) || (argc == 3))
214 pstrcpy(configfile, dyn_CONFIGFILE);
215 else if ((argc == 2) || (argc == 4))
216 pstrcpy(configfile,argv[optind]);
220 AllowDebugChange = False;
222 printf("Load smb config files from %s\n",configfile);
224 if (!lp_load(configfile,False,True,False)) {
225 printf("Error loading services.\n");
229 printf("Loaded services file OK.\n");
231 ret = do_global_checks();
233 for (s=0;s<1000;s++) {
235 if (strlen(lp_servicename(s)) > 8) {
236 printf("WARNING: You have some share names that are longer than 8 chars\n");
237 printf("These may give errors while browsing or may not be accessible\nto some older clients\n");
242 for (s=0;s<1000;s++) {
244 char **deny_list = lp_hostsdeny(s);
245 char **allow_list = lp_hostsallow(s);
248 for (i=0; deny_list[i]; i++) {
249 char *hasstar = strchr_m(deny_list[i], '*');
250 char *hasquery = strchr_m(deny_list[i], '?');
251 if(hasstar || hasquery) {
252 printf("Invalid character %c in hosts deny list (%s) for service %s.\n",
253 hasstar ? *hasstar : *hasquery, deny_list[i], lp_servicename(s) );
259 for (i=0; allow_list[i]; i++) {
260 char *hasstar = strchr_m(allow_list[i], '*');
261 char *hasquery = strchr_m(allow_list[i], '?');
262 if(hasstar || hasquery) {
263 printf("Invalid character %c in hosts allow list (%s) for service %s.\n",
264 hasstar ? *hasstar : *hasquery, allow_list[i], lp_servicename(s) );
269 if(lp_level2_oplocks(s) && !lp_oplocks(s)) {
270 printf("Invalid combination of parameters for service %s. \
271 Level II oplocks can only be set if oplocks are also set.\n",
279 printf("Press enter to see a dump of your service definitions\n");
283 lp_dump(stdout,True, lp_numservices());
291 cname = argv[optind];
292 caddr = argv[optind+1];
294 cname = argv[optind+1];
295 caddr = argv[optind+2];
298 /* this is totally ugly, a real `quick' hack */
299 for (s=0;s<1000;s++) {
301 if (allow_access(lp_hostsdeny(s),lp_hostsallow(s),cname,caddr)) {
302 printf("Allow connection from %s (%s) to %s\n",
303 cname,caddr,lp_servicename(s));
305 printf("Deny connection from %s (%s) to %s\n",
306 cname,caddr,lp_servicename(s));