I have fixed quite a few important bugs in this commit.
[samba.git] / source / 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
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
42  int main(int argc, char *argv[])
43 {
44   pstring configfile;
45   int s;
46
47   TimeInit();
48
49   setup_logging(argv[0],True);
50   
51   charset_initialise();
52
53   if (argc < 2)
54     strcpy(configfile,CONFIGFILE);
55   else
56     strcpy(configfile,argv[1]);
57
58   dbf = stdout;
59   DEBUGLEVEL = 2;
60
61   printf("Load smb config files from %s\n",configfile);
62
63   if (!lp_load(configfile,False))
64     {
65       printf("Error loading services.\n");
66       return(1);
67     }
68
69
70   printf("Loaded services file OK.\n");
71
72   for (s=0;s<1000;s++)
73     if (VALID_SNUM(s))
74       if (strlen(lp_servicename(s)) > 8) {
75         printf("WARNING: You have some share names that are longer than 8 chars\n");
76         printf("These may give errors while browsing or may not be accessible\nto some older clients\n");
77         break;
78       }
79
80   if (argc < 4)
81     {
82       printf("Press enter to see a dump of your service definitions\n");
83       fflush(stdout);
84       getc(stdin);
85       lp_dump();      
86     }
87   
88   if (argc == 4)
89     {
90       char *cname = argv[2];
91       char *caddr = argv[3];
92       
93       /* this is totally ugly, a real `quick' hack */
94       for (s=0;s<1000;s++)
95         if (VALID_SNUM(s))
96           {              
97             if (allow_access(lp_hostsdeny(s),lp_hostsallow(s),cname,caddr))
98               {
99                 printf("Allow connection from %s (%s) to %s\n",
100                        cname,caddr,lp_servicename(s));
101               }
102             else
103               {
104                 printf("Deny connection from %s (%s) to %s\n",
105                        cname,caddr,lp_servicename(s));
106               }
107           }
108     }
109   return(0);
110 }
111
112