d41e8b9f66575ffc515fcbe044251c93920da87c
[samba.git] / source3 / utils / testparm.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    Test validity of smb.conf
5    Copyright (C) Karl Auer 1993, 1994-1998
6
7    Extensively modified by Andrew Tridgell, 1995
8    
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.
13    
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.
18    
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.
22 */
23
24 /*
25  * Testbed for loadparm.c/params.c
26  *
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.
30  *
31  * Useful for a quick 'syntax check' of a configuration file.
32  *
33  */
34
35 #include "includes.h"
36 #include "smb.h"
37
38 /* these live in util.c */
39 extern FILE *dbf;
40 extern int DEBUGLEVEL;
41 extern pstring myhostname;
42
43 /***********************************************
44  Here we do a set of 'hard coded' checks for bad
45  configuration settings.
46 ************************************************/
47
48 void do_global_checks(void)
49 {
50         SMB_STRUCT_STAT st;
51         if (lp_security() > SEC_SHARE && lp_revalidate(-1)) {
52                 printf("WARNING: the 'revalidate' parameter is ignored in all but \
53 'security=share' mode.\n");
54         }
55
56         if (lp_wins_support() && *lp_wins_server()) {
57                 printf("ERROR: both 'wins support = true' and 'wins server = <server>' \
58 cannot be set in the smb.conf file. nmbd will abort with this setting.\n");
59         }
60
61         if (!directory_exist(lp_lockdir(), &st)) {
62                 printf("ERROR: lock directory %s does not exist\n",
63                        lp_lockdir());
64         } else if ((st.st_mode & 0777) != 0755) {
65                 printf("WARNING: lock directory %s should have permissions 0755 for browsing to work\n",
66                        lp_lockdir());
67         }
68 }   
69
70  int main(int argc, char *argv[])
71 {
72   pstring configfile;
73   int s;
74
75   TimeInit();
76
77   setup_logging(argv[0],True);
78   
79   charset_initialise();
80
81   if (argc < 2)
82     pstrcpy(configfile,CONFIGFILE);
83   else
84     pstrcpy(configfile,argv[1]);
85
86   dbf = stdout;
87   DEBUGLEVEL = 2;
88
89   printf("Load smb config files from %s\n",configfile);
90
91   if(!get_myname(myhostname,NULL))
92   {
93     printf("Failed to get my hostname.\n");
94     return(1);
95   }
96
97   if (!lp_load(configfile,False,True,False))
98     {
99       printf("Error loading services.\n");
100       return(1);
101     }
102
103
104   printf("Loaded services file OK.\n");
105
106   do_global_checks();
107
108   for (s=0;s<1000;s++)
109     if (VALID_SNUM(s))
110       if (strlen(lp_servicename(s)) > 8) {
111         printf("WARNING: You have some share names that are longer than 8 chars\n");
112         printf("These may give errors while browsing or may not be accessible\nto some older clients\n");
113         break;
114       }
115
116   if (argc < 4)
117     {
118       printf("Press enter to see a dump of your service definitions\n");
119       fflush(stdout);
120       getc(stdin);
121       lp_dump(stdout,True);
122     }
123   
124   if (argc == 4)
125     {
126       char *cname = argv[2];
127       char *caddr = argv[3];
128       
129       /* this is totally ugly, a real `quick' hack */
130       for (s=0;s<1000;s++)
131         if (VALID_SNUM(s))
132           {              
133             if (allow_access(lp_hostsdeny(s),lp_hostsallow(s),cname,caddr))
134               {
135                 printf("Allow connection from %s (%s) to %s\n",
136                        cname,caddr,lp_servicename(s));
137               }
138             else
139               {
140                 printf("Deny connection from %s (%s) to %s\n",
141                        cname,caddr,lp_servicename(s));
142               }
143           }
144     }
145   return(0);
146 }
147
148