summaryrefslogtreecommitdiff
path: root/source3/utils/testparm.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2002-07-15 10:35:28 +0000
committerAndrew Tridgell <tridge@samba.org>2002-07-15 10:35:28 +0000
commite90b65284812aaa5ff9e9935ce9bbad7791cbbcd (patch)
tree9e744d1dc2f93934a4b49166a37383d3cb2b2139 /source3/utils/testparm.c
parentec167dc9cc0ec2ee461837c25a371d2981744208 (diff)
downloadsamba-e90b65284812aaa5ff9e9935ce9bbad7791cbbcd.tar.gz
updated the 3.0 branch from the head branch - ready for alpha18
(This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce)
Diffstat (limited to 'source3/utils/testparm.c')
-rw-r--r--source3/utils/testparm.c277
1 files changed, 126 insertions, 151 deletions
diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c
index c6e417a2bc3..1d48249a758 100644
--- a/source3/utils/testparm.c
+++ b/source3/utils/testparm.c
@@ -4,6 +4,7 @@
Copyright (C) Karl Auer 1993, 1994-1998
Extensively modified by Andrew Tridgell, 1995
+ Converted to popt by Jelmer Vernooij (jelmer@nl.linux.org), 2002
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -67,6 +68,12 @@ cannot be set in the smb.conf file. nmbd will abort with this setting.\n");
ret = 1;
}
+ if (!directory_exist(lp_piddir(), &st)) {
+ printf("ERROR: pid directory %s does not exist\n",
+ lp_piddir());
+ ret = 1;
+ }
+
/*
* Password server sanity checks.
*/
@@ -164,158 +171,126 @@ via the %%o substitution. With encrypted passwords this is not possible.\n", lp_
return ret;
}
-static void usage(char *pname)
+int main(int argc, char *argv[])
{
- printf("Usage: %s [-sh] [-L servername] [configfilename] [hostname hostIP]\n", pname);
- printf("\t-s Suppress prompt for enter\n");
- printf("\t-h Print usage\n");
- printf("\t-L servername Set %%L macro to servername\n");
- printf("\t-t encoding Print parameters with encoding\n");
- printf("\tconfigfilename Configuration file to test\n");
- printf("\thostname hostIP. Hostname and Host IP address to test\n");
- printf("\t against \"host allow\" and \"host deny\"\n");
- printf("\n");
-}
+ extern char *optarg;
+ extern int optind;
+ extern fstring local_machine;
+ const char *config_file = dyn_CONFIGFILE;
+ int s;
+ static BOOL silent_mode = False;
+ int ret = 0;
+ int opt;
+ poptContext pc;
+ static char *term_code = "";
+ static char *new_local_machine = local_machine;
+ const char *cname;
+ const char *caddr;
+ struct poptOption long_options[] = {
+ POPT_AUTOHELP
+ {"suppress-prompt", 's', POPT_ARG_VAL, &silent_mode, 1, "Suppress prompt for enter"},
+ {"server", 'L',POPT_ARG_STRING, &new_local_machine, 0, "Set %%L macro to servername\n"},
+ {"encoding", 't', POPT_ARG_STRING, &term_code, 0, "Print parameters with encoding"},
+ {0,0,0,0}
+ };
-int main(int argc, char *argv[])
-{
- extern char *optarg;
- extern int optind;
- extern fstring local_machine;
- pstring configfile;
- int opt;
- int s;
- BOOL silent_mode = False;
- int ret = 0;
- pstring term_code;
-
- *term_code = 0;
-
- setup_logging(argv[0],True);
-
- while ((opt = getopt(argc, argv,"shL:t:")) != EOF) {
- switch (opt) {
- case 's':
- silent_mode = True;
- break;
- case 'L':
- fstrcpy(local_machine,optarg);
- break;
- case 'h':
- usage(argv[0]);
- exit(0);
- break;
- case 't':
- pstrcpy(term_code,optarg);
- break;
- default:
- printf("Incorrect program usage\n");
- usage(argv[0]);
- exit(1);
- break;
- }
- }
-
- argc += (1 - optind);
-
- if ((argc == 1) || (argc == 3))
- pstrcpy(configfile, dyn_CONFIGFILE);
- else if ((argc == 2) || (argc == 4))
- pstrcpy(configfile,argv[optind]);
-
- dbf = x_stdout;
- DEBUGLEVEL = 2;
- AllowDebugChange = False;
-
- printf("Load smb config files from %s\n",configfile);
-
- if (!lp_load(configfile,False,True,False)) {
- printf("Error loading services.\n");
- return(1);
- }
-
- printf("Loaded services file OK.\n");
-
- ret = do_global_checks();
-
- for (s=0;s<1000;s++) {
- if (VALID_SNUM(s))
- if (strlen(lp_servicename(s)) > 8) {
- printf("WARNING: You have some share names that are longer than 8 chars\n");
- printf("These may give errors while browsing or may not be accessible\nto some older clients\n");
- break;
- }
- }
-
- for (s=0;s<1000;s++) {
- if (VALID_SNUM(s)) {
- char **deny_list = lp_hostsdeny(s);
- char **allow_list = lp_hostsallow(s);
- int i;
- if(deny_list) {
- for (i=0; deny_list[i]; i++) {
- char *hasstar = strchr_m(deny_list[i], '*');
- char *hasquery = strchr_m(deny_list[i], '?');
- if(hasstar || hasquery) {
- printf("Invalid character %c in hosts deny list (%s) for service %s.\n",
- hasstar ? *hasstar : *hasquery, deny_list[i], lp_servicename(s) );
- }
- }
- }
-
- if(allow_list) {
- for (i=0; allow_list[i]; i++) {
- char *hasstar = strchr_m(allow_list[i], '*');
- char *hasquery = strchr_m(allow_list[i], '?');
- if(hasstar || hasquery) {
- printf("Invalid character %c in hosts allow list (%s) for service %s.\n",
- hasstar ? *hasstar : *hasquery, allow_list[i], lp_servicename(s) );
- }
- }
- }
-
- if(lp_level2_oplocks(s) && !lp_oplocks(s)) {
- printf("Invalid combination of parameters for service %s. \
-Level II oplocks can only be set if oplocks are also set.\n",
- lp_servicename(s) );
- }
- }
- }
-
- if (argc < 3) {
- if (!silent_mode) {
- printf("Press enter to see a dump of your service definitions\n");
- fflush(stdout);
- getc(stdin);
- }
- lp_dump(stdout,True, lp_numservices());
- }
-
- if (argc >= 3) {
- char *cname;
- char *caddr;
-
- if (argc == 3) {
- cname = argv[optind];
- caddr = argv[optind+1];
- } else {
- cname = argv[optind+1];
- caddr = argv[optind+2];
- }
-
- /* this is totally ugly, a real `quick' hack */
- for (s=0;s<1000;s++) {
- if (VALID_SNUM(s)) {
- if (allow_access(lp_hostsdeny(s),lp_hostsallow(s),cname,caddr)) {
- printf("Allow connection from %s (%s) to %s\n",
- cname,caddr,lp_servicename(s));
- } else {
- printf("Deny connection from %s (%s) to %s\n",
- cname,caddr,lp_servicename(s));
- }
- }
- }
- }
- return(ret);
+ pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
+ POPT_CONTEXT_KEEP_FIRST);
+
+ while((opt = poptGetNextOpt(pc)) != -1);
+
+ setup_logging(poptGetArg(pc), True);
+
+ if (poptPeekArg(pc))
+ config_file = poptGetArg(pc);
+
+ cname = poptGetArg(pc);
+ caddr = poptGetArg(pc);
+
+ fstrcpy(local_machine,new_local_machine);
+
+ dbf = x_stdout;
+ DEBUGLEVEL = 2;
+ AllowDebugChange = False;
+
+ printf("Load smb config files from %s\n",config_file);
+
+ if (!lp_load(config_file,False,True,False)) {
+ printf("Error loading services.\n");
+ return(1);
+ }
+
+ printf("Loaded services file OK.\n");
+
+ ret = do_global_checks();
+
+ for (s=0;s<1000;s++) {
+ if (VALID_SNUM(s))
+ if (strlen(lp_servicename(s)) > 8) {
+ printf("WARNING: You have some share names that are longer than 8 chars\n");
+ printf("These may give errors while browsing or may not be accessible\nto some older clients\n");
+ break;
+ }
+ }
+
+ for (s=0;s<1000;s++) {
+ if (VALID_SNUM(s)) {
+ char **deny_list = lp_hostsdeny(s);
+ char **allow_list = lp_hostsallow(s);
+ int i;
+ if(deny_list) {
+ for (i=0; deny_list[i]; i++) {
+ char *hasstar = strchr_m(deny_list[i], '*');
+ char *hasquery = strchr_m(deny_list[i], '?');
+ if(hasstar || hasquery) {
+ printf("Invalid character %c in hosts deny list (%s) for service %s.\n",
+ hasstar ? *hasstar : *hasquery, deny_list[i], lp_servicename(s) );
+ }
+ }
+ }
+
+ if(allow_list) {
+ for (i=0; allow_list[i]; i++) {
+ char *hasstar = strchr_m(allow_list[i], '*');
+ char *hasquery = strchr_m(allow_list[i], '?');
+ if(hasstar || hasquery) {
+ printf("Invalid character %c in hosts allow list (%s) for service %s.\n",
+ hasstar ? *hasstar : *hasquery, allow_list[i], lp_servicename(s) );
+ }
+ }
+ }
+
+ if(lp_level2_oplocks(s) && !lp_oplocks(s)) {
+ printf("Invalid combination of parameters for service %s. \
+ Level II oplocks can only be set if oplocks are also set.\n",
+ lp_servicename(s) );
+ }
+ }
+ }
+
+ if (!cname) {
+ if (!silent_mode) {
+ printf("Press enter to see a dump of your service definitions\n");
+ fflush(stdout);
+ getc(stdin);
+ }
+ lp_dump(stdout,True, lp_numservices());
+ }
+
+ if(cname && caddr){
+ /* this is totally ugly, a real `quick' hack */
+ for (s=0;s<1000;s++) {
+ if (VALID_SNUM(s)) {
+ if (allow_access(lp_hostsdeny(s), lp_hostsallow(s), cname, caddr)) {
+ printf("Allow connection from %s (%s) to %s\n",
+ cname,caddr,lp_servicename(s));
+ } else {
+ printf("Deny connection from %s (%s) to %s\n",
+ cname,caddr,lp_servicename(s));
+ }
+ }
+ }
+ }
+ return(ret);
}