add WITH_SENDFILE profiling data (from Pierre Belanger)
[Samba.git] / source / utils / testparm.c
blob26068fcbf3749d3225a8b2a51c998ebbdda609bb
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 extern BOOL AllowDebugChange;
39 extern int parsed_debuglevel_class[DBGC_LAST];
41 /* these live in util.c */
42 extern FILE *dbf;
44 /***********************************************
45 Here we do a set of 'hard coded' checks for bad
46 configuration settings.
47 ************************************************/
49 static int do_global_checks(void)
51 int ret = 0;
52 SMB_STRUCT_STAT st;
54 if (lp_security() == SEC_DOMAIN && !lp_encrypted_passwords()) {
55 printf("ERROR: in 'security=domain' mode the 'encrypt passwords' parameter must also be set to 'true'.\n");
56 ret = 1;
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");
62 ret = 1;
65 if (!directory_exist(lp_lockdir(), &st)) {
66 printf("ERROR: lock directory %s does not exist\n",
67 lp_lockdir());
68 ret = 1;
69 } else if ((st.st_mode & 0777) != 0755) {
70 printf("WARNING: lock directory %s should have permissions 0755 for browsing to work\n",
71 lp_lockdir());
72 ret = 1;
75 if (!directory_exist(lp_piddir(), &st)) {
76 printf("ERROR: pid directory %s does not exist\n",
77 lp_piddir());
78 ret = 1;
82 * Password server sanity checks.
85 if((lp_security() == SEC_SERVER || lp_security() == SEC_DOMAIN) && !lp_passwordserver()) {
86 pstring sec_setting;
87 if(lp_security() == SEC_SERVER)
88 pstrcpy(sec_setting, "server");
89 else if(lp_security() == SEC_DOMAIN)
90 pstrcpy(sec_setting, "domain");
92 printf("ERROR: The setting 'security=%s' requires the 'password server' parameter be set \
93 to a valid password server.\n", sec_setting );
94 ret = 1;
98 * Password chat sanity checks.
101 if(lp_security() == SEC_USER && lp_unix_password_sync()) {
104 * Check that we have a valid lp_passwd_program() if not using pam.
107 #ifdef WITH_PAM
108 if (!lp_pam_password_change()) {
109 #endif
111 if(lp_passwd_program() == NULL) {
112 printf("ERROR: the 'unix password sync' parameter is set and there is no valid 'passwd program' \
113 parameter.\n" );
114 ret = 1;
115 } else {
116 pstring passwd_prog;
117 pstring truncated_prog;
118 char *p;
120 pstrcpy( passwd_prog, lp_passwd_program());
121 p = passwd_prog;
122 *truncated_prog = '\0';
123 next_token(&p, truncated_prog, NULL, sizeof(pstring));
125 if(access(truncated_prog, F_OK) == -1) {
126 printf("ERROR: the 'unix password sync' parameter is set and the 'passwd program' (%s) \
127 cannot be executed (error was %s).\n", truncated_prog, strerror(errno) );
128 ret = 1;
132 #ifdef WITH_PAM
134 #endif
136 if(lp_passwd_chat() == NULL) {
137 printf("ERROR: the 'unix password sync' parameter is set and there is no valid 'passwd chat' \
138 parameter.\n");
139 ret = 1;
143 * Check that we have a valid script and that it hasn't
144 * been written to expect the old password.
147 if(lp_encrypted_passwords()) {
148 if(strstr( lp_passwd_chat(), "%o")!=NULL) {
149 printf("ERROR: the 'passwd chat' script [%s] expects to use the old plaintext password \
150 via the %%o substitution. With encrypted passwords this is not possible.\n", lp_passwd_chat() );
151 ret = 1;
156 if (!lp_status(-1) && lp_max_smbd_processes()) {
157 printf("ERROR: the 'max smbd processes' parameter is set and the 'status' parameter is set to 'no'.\n");
158 ret = 1;
161 if (strlen(lp_winbind_separator()) != 1) {
162 printf("ERROR: the 'winbind separator' parameter must be a single character.\n");
163 ret = 1;
166 if (*lp_winbind_separator() == '+') {
167 printf("'winbind separator = +' might cause problems with group membership.\n");
170 return ret;
173 static void usage(char *pname)
175 printf("Usage: %s [-sh] [-L servername] [configfilename] [hostname hostIP]\n", pname);
176 printf("\t-s Suppress prompt for enter\n");
177 printf("\t-x Print only smb.conf parameters with values that are non-default\n");
178 printf("\t-h Print usage\n");
179 printf("\t-L servername Set %%L macro to servername\n");
180 printf("\t-t encoding Print parameters with encoding\n");
181 printf("\tconfigfilename Configuration file to test\n");
182 printf("\thostname hostIP. Hostname and Host IP address to test\n");
183 printf("\t against \"host allow\" and \"host deny\"\n");
184 printf("\n");
188 int main(int argc, char *argv[])
190 extern char *optarg;
191 extern int optind;
192 extern fstring local_machine;
193 pstring configfile;
194 int opt;
195 int s;
196 BOOL show_defaults=True;
197 BOOL silent_mode = False;
198 int ret = 0;
199 pstring term_code;
201 *term_code = 0;
203 TimeInit();
205 setup_logging(argv[0],True);
207 charset_initialise();
209 while ((opt = getopt(argc, argv,"shL:t:x")) != EOF) {
210 switch (opt) {
211 case 's':
212 silent_mode = True;
213 break;
214 case 'L':
215 fstrcpy(local_machine,optarg);
216 break;
217 case 'h':
218 usage(argv[0]);
219 exit(0);
220 break;
221 case 't':
222 pstrcpy(term_code,optarg);
223 break;
224 case 'x':
225 show_defaults=False;
226 break;
227 default:
228 printf("Incorrect program usage\n");
229 usage(argv[0]);
230 exit(1);
231 break;
235 argc += (1 - optind);
237 if ((argc == 1) || (argc == 3))
238 pstrcpy(configfile,CONFIGFILE);
239 else if ((argc == 2) || (argc == 4))
240 pstrcpy(configfile,argv[optind]);
242 dbf = stdout;
243 DEBUGLEVEL = 2;
244 AllowDebugChange = False;
246 printf("Load smb config files from %s\n",configfile);
248 if (!lp_load(configfile,False,True,False)) {
249 printf("Error loading services.\n");
250 return(1);
253 printf("Loaded services file OK.\n");
255 ret = do_global_checks();
257 for (s=0;s<1000;s++) {
258 if (VALID_SNUM(s))
259 if (strlen(lp_servicename(s)) > 8) {
260 printf("WARNING: You have some share names that are longer than 8 chars\n");
261 printf("These may give errors while browsing or may not be accessible\nto some older clients\n");
262 break;
266 for (s=0;s<1000;s++) {
267 if (VALID_SNUM(s)) {
268 char *deny_list = lp_hostsdeny(s);
269 char *allow_list = lp_hostsallow(s);
270 if(deny_list) {
271 char *hasstar = strchr(deny_list, '*');
272 char *hasquery = strchr(deny_list, '?');
273 if(hasstar || hasquery) {
274 printf("Invalid character %c in hosts deny list %s for service %s.\n",
275 hasstar ? *hasstar : *hasquery, deny_list, lp_servicename(s) );
279 if(allow_list) {
280 char *hasstar = strchr(allow_list, '*');
281 char *hasquery = strchr(allow_list, '?');
282 if(hasstar || hasquery) {
283 printf("Invalid character %c in hosts allow list %s for service %s.\n",
284 hasstar ? *hasstar : *hasquery, allow_list, lp_servicename(s) );
288 if(lp_level2_oplocks(s) && !lp_oplocks(s)) {
289 printf("Invalid combination of parameters for service %s. \
290 Level II oplocks can only be set if oplocks are also set.\n",
291 lp_servicename(s) );
296 if (*term_code)
297 interpret_coding_system(term_code);
299 if (argc < 3) {
300 if (!silent_mode) {
301 printf("Press enter to see a dump of your service definitions\n");
302 fflush(stdout);
303 getc(stdin);
305 memcpy(DEBUGLEVEL_CLASS,parsed_debuglevel_class,sizeof(parsed_debuglevel_class));
306 lp_dump(stdout,show_defaults, lp_numservices(), _dos_to_unix_static);
309 if (argc >= 3) {
310 char *cname;
311 char *caddr;
313 if (argc == 3) {
314 cname = argv[optind];
315 caddr = argv[optind+1];
316 } else {
317 cname = argv[optind+1];
318 caddr = argv[optind+2];
321 /* this is totally ugly, a real `quick' hack */
322 for (s=0;s<1000;s++) {
323 if (VALID_SNUM(s)) {
324 if (allow_access(lp_hostsdeny(s),lp_hostsallow(s),cname,caddr)) {
325 printf("Allow connection from %s (%s) to %s\n",
326 cname,caddr,lp_servicename(s));
327 } else {
328 printf("Deny connection from %s (%s) to %s\n",
329 cname,caddr,lp_servicename(s));
334 return(ret);