preparing for release of 2.0.0beta3
[Samba.git] / source / utils / testparm.c
blob9bf741e24f14ae3df926ef7da22d69bf7814c9ae
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
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.
35 #include "includes.h"
36 #include "smb.h"
38 /* these live in util.c */
39 extern FILE *dbf;
40 extern int DEBUGLEVEL;
41 extern pstring myhostname;
43 /***********************************************
44 Here we do a set of 'hard coded' checks for bad
45 configuration settings.
46 ************************************************/
47 static void do_global_checks(void)
49 SMB_STRUCT_STAT st;
50 if (lp_security() > SEC_SHARE && lp_revalidate(-1)) {
51 printf("WARNING: the 'revalidate' parameter is ignored in all but \
52 'security=share' mode.\n");
55 if (lp_security() == SEC_DOMAIN && !lp_encrypted_passwords()) {
56 printf("ERROR: in 'security=domain' mode the 'encrypt passwords' parameter must also be set to 'true'.\n");
59 if (lp_wins_support() && *lp_wins_server()) {
60 printf("ERROR: both 'wins support = true' and 'wins server = <server>' \
61 cannot be set in the smb.conf file. nmbd will abort with this setting.\n");
64 if (!directory_exist(lp_lockdir(), &st)) {
65 printf("ERROR: lock directory %s does not exist\n",
66 lp_lockdir());
67 } else if ((st.st_mode & 0777) != 0755) {
68 printf("WARNING: lock directory %s should have permissions 0755 for browsing to work\n",
69 lp_lockdir());
73 int main(int argc, char *argv[])
75 extern char *optarg;
76 extern int optind;
77 pstring configfile;
78 int opt;
79 int s;
80 BOOL silent_mode = False;
82 TimeInit();
84 setup_logging(argv[0],True);
86 charset_initialise();
88 while ((opt = getopt(argc, argv,"s")) != EOF) {
89 switch (opt) {
90 case 's':
91 silent_mode = True;
92 break;
96 argc += (1 - optind);
98 if ((argc == 1) || (argc == 3))
99 pstrcpy(configfile,CONFIGFILE);
100 else if ((argc == 2) || (argc == 4))
101 pstrcpy(configfile,argv[optind]);
103 dbf = stdout;
104 DEBUGLEVEL = 2;
106 printf("Load smb config files from %s\n",configfile);
108 if(!get_myname(myhostname,NULL))
110 printf("Failed to get my hostname.\n");
111 return(1);
114 if (!lp_load(configfile,False,True,False))
116 printf("Error loading services.\n");
117 return(1);
121 printf("Loaded services file OK.\n");
123 do_global_checks();
125 for (s=0;s<1000;s++)
126 if (VALID_SNUM(s))
127 if (strlen(lp_servicename(s)) > 8) {
128 printf("WARNING: You have some share names that are longer than 8 chars\n");
129 printf("These may give errors while browsing or may not be accessible\nto some older clients\n");
130 break;
133 if (argc < 3)
135 if (!silent_mode) {
136 printf("Press enter to see a dump of your service definitions\n");
137 fflush(stdout);
138 getc(stdin);
140 lp_dump(stdout,True);
143 if (argc >= 3)
145 char *cname;
146 char *caddr;
148 if (argc == 3) {
149 cname = argv[optind];
150 caddr = argv[optind+1];
151 } else if (argc == 4) {
152 cname = argv[optind+1];
153 caddr = argv[optind+2];
156 /* this is totally ugly, a real `quick' hack */
157 for (s=0;s<1000;s++)
158 if (VALID_SNUM(s))
160 if (allow_access(lp_hostsdeny(s),lp_hostsallow(s),cname,caddr))
162 printf("Allow connection from %s (%s) to %s\n",
163 cname,caddr,lp_servicename(s));
165 else
167 printf("Deny connection from %s (%s) to %s\n",
168 cname,caddr,lp_servicename(s));
172 return(0);