2 Unix SMB/Netbios implementation.
4 Test validity of smb.conf
5 Copyright (C) Karl Auer 1993, 1994-1998
7 Extensively modified by Andrew Tridgell, 1995
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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.
38 /***********************************************
39 Here we do a set of 'hard coded' checks for bad
40 configuration settings.
41 ************************************************/
43 static int do_global_checks(void)
48 if (lp_security() == SEC_DOMAIN && !lp_encrypted_passwords()) {
49 printf("ERROR: in 'security=domain' mode the 'encrypt passwords' parameter must also be set to 'true'.\n");
53 if (lp_wins_support() && wins_srv_count()) {
54 printf("ERROR: both 'wins support = true' and 'wins server = <server>' \
55 cannot be set in the smb.conf file. nmbd will abort with this setting.\n");
59 if (!directory_exist(lp_lockdir(), &st)) {
60 printf("ERROR: lock directory %s does not exist\n",
63 } else if ((st.st_mode & 0777) != 0755) {
64 printf("WARNING: lock directory %s should have permissions 0755 for browsing to work\n",
70 * Password server sanity checks.
73 if((lp_security() == SEC_SERVER || lp_security() == SEC_DOMAIN) && !lp_passwordserver()) {
75 if(lp_security() == SEC_SERVER)
76 pstrcpy(sec_setting, "server");
77 else if(lp_security() == SEC_DOMAIN)
78 pstrcpy(sec_setting, "domain");
80 printf("ERROR: The setting 'security=%s' requires the 'password server' parameter be set \
81 to a valid password server.\n", sec_setting );
87 * Check 'hosts equiv' and 'use rhosts' compatability with 'hostname lookup' value.
90 if(*lp_hosts_equiv() && !lp_hostname_lookups()) {
91 printf("ERROR: The setting 'hosts equiv = %s' requires that 'hostname lookups = yes'.\n", lp_hosts_equiv());
95 if(lp_use_rhosts() && !lp_hostname_lookups()) {
96 printf("ERROR: The setting 'use rhosts = yes' requires the 'hostname lookups = yes'.\n");
102 * Password chat sanity checks.
105 if(lp_security() == SEC_USER && lp_unix_password_sync()) {
108 * Check that we have a valid lp_passwd_program() if not using pam.
112 if (!lp_pam_password_change()) {
115 if(lp_passwd_program() == NULL) {
116 printf("ERROR: the 'unix password sync' parameter is set and there is no valid 'passwd program' \
121 pstring truncated_prog;
124 pstrcpy( passwd_prog, lp_passwd_program());
126 *truncated_prog = '\0';
127 next_token(&p, truncated_prog, NULL, sizeof(pstring));
129 if(access(truncated_prog, F_OK) == -1) {
130 printf("ERROR: the 'unix password sync' parameter is set and the 'passwd program' (%s) \
131 cannot be executed (error was %s).\n", truncated_prog, strerror(errno) );
140 if(lp_passwd_chat() == NULL) {
141 printf("ERROR: the 'unix password sync' parameter is set and there is no valid 'passwd chat' \
147 * Check that we have a valid script and that it hasn't
148 * been written to expect the old password.
151 if(lp_encrypted_passwords()) {
152 if(strstr( lp_passwd_chat(), "%o")!=NULL) {
153 printf("ERROR: the 'passwd chat' script [%s] expects to use the old plaintext password \
154 via the %%o substitution. With encrypted passwords this is not possible.\n", lp_passwd_chat() );
163 static void usage(char *pname)
165 printf("Usage: %s [-sh] [-L servername] [configfilename] [hostname hostIP]\n", pname);
166 printf("\t-s Suppress prompt for enter\n");
167 printf("\t-h Print usage\n");
168 printf("\t-L servername Set %%L macro to servername\n");
169 printf("\t-t encoding Print parameters with encoding\n");
170 printf("\tconfigfilename Configuration file to test\n");
171 printf("\thostname hostIP. Hostname and Host IP address to test\n");
172 printf("\t against \"host allow\" and \"host deny\"\n");
177 int main(int argc, char *argv[])
181 extern fstring local_machine;
185 BOOL silent_mode = False;
193 setup_logging(argv[0],True);
195 while ((opt = getopt(argc, argv,"shL:t:")) != EOF) {
201 fstrcpy(local_machine,optarg);
208 pstrcpy(term_code,optarg);
211 printf("Incorrect program usage\n");
218 argc += (1 - optind);
220 if ((argc == 1) || (argc == 3))
221 pstrcpy(configfile, dyn_CONFIGFILE);
222 else if ((argc == 2) || (argc == 4))
223 pstrcpy(configfile,argv[optind]);
228 printf("Load smb config files from %s\n",configfile);
230 if (!lp_load(configfile,False,True,False)) {
231 printf("Error loading services.\n");
235 printf("Loaded services file OK.\n");
237 ret = do_global_checks();
239 for (s=0;s<1000;s++) {
241 if (strlen(lp_servicename(s)) > 8) {
242 printf("WARNING: You have some share names that are longer than 8 chars\n");
243 printf("These may give errors while browsing or may not be accessible\nto some older clients\n");
248 for (s=0;s<1000;s++) {
250 char **deny_list = lp_hostsdeny(s);
251 char **allow_list = lp_hostsallow(s);
254 for (i=0; deny_list[i]; i++) {
255 char *hasstar = strchr_m(deny_list[i], '*');
256 char *hasquery = strchr_m(deny_list[i], '?');
257 if(hasstar || hasquery) {
258 printf("Invalid character %c in hosts deny list (%s) for service %s.\n",
259 hasstar ? *hasstar : *hasquery, deny_list[i], lp_servicename(s) );
265 for (i=0; allow_list[i]; i++) {
266 char *hasstar = strchr_m(allow_list[i], '*');
267 char *hasquery = strchr_m(allow_list[i], '?');
268 if(hasstar || hasquery) {
269 printf("Invalid character %c in hosts allow list (%s) for service %s.\n",
270 hasstar ? *hasstar : *hasquery, allow_list[i], lp_servicename(s) );
275 if(lp_level2_oplocks(s) && !lp_oplocks(s)) {
276 printf("Invalid combination of parameters for service %s. \
277 Level II oplocks can only be set if oplocks are also set.\n",
285 printf("Press enter to see a dump of your service definitions\n");
289 lp_dump(stdout,True, lp_numservices());
297 cname = argv[optind];
298 caddr = argv[optind+1];
300 cname = argv[optind+1];
301 caddr = argv[optind+2];
304 /* this is totally ugly, a real `quick' hack */
305 for (s=0;s<1000;s++) {
307 if (allow_access(lp_hostsdeny(s),lp_hostsallow(s),cname,caddr)) {
308 printf("Allow connection from %s (%s) to %s\n",
309 cname,caddr,lp_servicename(s));
311 printf("Deny connection from %s (%s) to %s\n",
312 cname,caddr,lp_servicename(s));