summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2002-06-14 02:06:58 +0000
committerAndrew Bartlett <abartlet@samba.org>2002-06-14 02:06:58 +0000
commit0886638844b6ea5253cae217682c680cc7b6cec8 (patch)
treee4bae78ffbf3770fff68ee8a85fe9ac563b6dbc4 /source3
parentbaef1358d2b5a98a592f0247911a31d79148dcba (diff)
downloadsamba-0886638844b6ea5253cae217682c680cc7b6cec8.tar.gz
samba-0886638844b6ea5253cae217682c680cc7b6cec8.tar.bz2
samba-0886638844b6ea5253cae217682c680cc7b6cec8.zip
Patch (from ctrlsoft <jelmer@nl.linux.org>) to poptify testparm, and the
modifications required to suppress the const warnings. Andrew Bartlett (This used to be commit ec4f1e9e2f6c162a475b424d63b9802387ad905e)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/access.c18
-rw-r--r--source3/lib/debug.c4
-rw-r--r--source3/utils/testparm.c271
3 files changed, 139 insertions, 154 deletions
diff --git a/source3/lib/access.c b/source3/lib/access.c
index 62d47b82cf..4e524735e4 100644
--- a/source3/lib/access.c
+++ b/source3/lib/access.c
@@ -188,7 +188,7 @@ static int list_match(char **list,char *item, int (*match_fn)(char *, char *))
/* return true if access should be allowed */
-BOOL allow_access(char **deny_list,char **allow_list,
+static BOOL allow_access_internal(char **deny_list,char **allow_list,
char *cname,char *caddr)
{
char *client[2];
@@ -240,6 +240,22 @@ BOOL allow_access(char **deny_list,char **allow_list,
return (True);
}
+/* return true if access should be allowed */
+BOOL allow_access(char **deny_list,char **allow_list,
+ const char *cname, const char *caddr)
+{
+ BOOL ret;
+
+ char *nc_cname = smb_xstrdup(cname);
+ char *nc_caddr = smb_xstrdup(caddr);
+
+ ret = allow_access_internal(deny_list, allow_list, nc_cname, nc_caddr);
+
+ SAFE_FREE(nc_cname);
+ SAFE_FREE(nc_caddr);
+ return ret;
+}
+
/* return true if the char* contains ip addrs only. Used to avoid
gethostbyaddr() calls */
static BOOL only_ipaddrs_in_list(char** list)
diff --git a/source3/lib/debug.c b/source3/lib/debug.c
index 834c1b38f7..255b0568f1 100644
--- a/source3/lib/debug.c
+++ b/source3/lib/debug.c
@@ -516,7 +516,7 @@ void debug_init(void)
* get ready for syslog stuff
* ************************************************************************** **
*/
-void setup_logging(char *pname, BOOL interactive)
+void setup_logging(const char *pname, BOOL interactive)
{
debug_init();
@@ -531,7 +531,7 @@ void setup_logging(char *pname, BOOL interactive)
}
#ifdef WITH_SYSLOG
else {
- char *p = strrchr_m( pname,'/' );
+ const char *p = strrchr_m( pname,'/' );
if (p)
pname = p + 1;
#ifdef LOG_DAEMON
diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c
index b727f883fd..b63fbf4145 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
@@ -170,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;
+ 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);
}