diff options
Diffstat (limited to 'source4/utils')
-rw-r--r-- | source4/utils/testparm.c | 183 |
1 files changed, 98 insertions, 85 deletions
diff --git a/source4/utils/testparm.c b/source4/utils/testparm.c index 71ff937a51..17e6a72746 100644 --- a/source4/utils/testparm.c +++ b/source4/utils/testparm.c @@ -72,88 +72,17 @@ static int do_global_checks(struct loadparm_context *lp_ctx) return ret; } - int main(int argc, const char *argv[]) + +static int do_share_checks(struct loadparm_context *lp_ctx, const char *cname, const char *caddr, bool silent_mode, + bool show_defaults, const char *section_name, const char *parameter_name) { - int s; - static int silent_mode = 0; int ret = 0; - poptContext pc; -/* - static int show_all_parameters = 0; - static char *new_local_machine = NULL; -*/ - static const char *section_name = NULL; - static char *parameter_name = NULL; - static const char *cname; - static const char *caddr; - static int show_defaults; - - struct poptOption long_options[] = { - POPT_AUTOHELP - {"suppress-prompt", 0, POPT_ARG_NONE, &silent_mode, 1, "Suppress prompt for enter"}, - {"verbose", 'v', POPT_ARG_NONE, &show_defaults, 1, "Show default options too"}, -/* - We need support for smb.conf macros before this will work again - {"server", 'L',POPT_ARG_STRING, &new_local_machine, 0, "Set %%L macro to servername\n"}, -*/ -/* - These are harder to do with the new code structure - {"show-all-parameters", '\0', POPT_ARG_NONE, &show_all_parameters, 1, "Show the parameters, type, possible values" }, -*/ - {"section-name", '\0', POPT_ARG_STRING, §ion_name, 0, "Limit testparm to a named section" }, - {"parameter-name", '\0', POPT_ARG_STRING, ¶meter_name, 0, "Limit testparm to a named parameter" }, - {"client-name", '\0', POPT_ARG_STRING, &cname, 0, "Client DNS name for 'hosts allow' checking (should match reverse lookup)"}, - {"client-ip", '\0', POPT_ARG_STRING, &caddr, 0, "Client IP address for 'hosts allow' checking"}, - POPT_COMMON_SAMBA - POPT_COMMON_VERSION - { NULL } - }; - - setup_logging(NULL, DEBUG_STDERR); - - pc = poptGetContext(NULL, argc, argv, long_options, - POPT_CONTEXT_KEEP_FIRST); - poptSetOtherOptionHelp(pc, "[OPTION...] [host-name] [host-ip]"); - - while(poptGetNextOpt(pc) != -1); - -/* - if (show_all_parameters) { - show_parameter_list(); - exit(0); - } -*/ - - if ( cname && ! caddr ) { - printf ( "ERROR: For 'hosts allow' check you must specify both a DNS name and an IP address.\n" ); - return(1); - } -/* - We need support for smb.conf macros before this will work again - - if (new_local_machine) { - set_local_machine_name(new_local_machine, True); - } -*/ - - /* We need this to force the output */ - lp_set_cmdline(global_loadparm, "log level", "2"); - - fprintf(stderr, "Loaded smb config files from %s\n", lp_configfile(global_loadparm)); - - if (!lp_load(lp_configfile(global_loadparm))) { - fprintf(stderr,"Error loading services.\n"); - return(1); - } - - fprintf(stderr,"Loaded services file OK.\n"); - - ret = do_global_checks(global_loadparm); + int s; - for (s=0;s<lp_numservices(global_loadparm);s++) { - struct loadparm_service *service = lp_servicebynum(global_loadparm, s); + for (s=0;s<lp_numservices(lp_ctx);s++) { + struct loadparm_service *service = lp_servicebynum(lp_ctx, s); if (service != NULL) - if (strlen(lp_servicename(lp_servicebynum(global_loadparm, s))) > 12) { + if (strlen(lp_servicename(lp_servicebynum(lp_ctx, s))) > 12) { fprintf(stderr, "WARNING: You have some share names that are longer than 12 characters.\n" ); fprintf(stderr, "These may not be accessible to some older clients.\n" ); fprintf(stderr, "(Eg. Windows9x, WindowsMe, and not listed in smbclient in Samba 3.0.)\n" ); @@ -161,8 +90,8 @@ static int do_global_checks(struct loadparm_context *lp_ctx) } } - for (s=0;s<lp_numservices(global_loadparm);s++) { - struct loadparm_service *service = lp_servicebynum(global_loadparm, s); + for (s=0;s<lp_numservices(lp_ctx);s++) { + struct loadparm_service *service = lp_servicebynum(lp_ctx, s); if (service != NULL) { const char **deny_list = lp_hostsdeny(service); const char **allow_list = lp_hostsallow(service); @@ -204,7 +133,7 @@ static int do_global_checks(struct loadparm_context *lp_ctx) section_name = GLOBAL_NAME; service = NULL; } else if ((!strwicmp(section_name, GLOBAL_NAME)) == 0 && - (service=lp_service(global_loadparm, section_name)) == NULL) { + (service=lp_service(lp_ctx, section_name)) == NULL) { fprintf(stderr,"Unknown section %s\n", section_name); return(1); @@ -212,18 +141,18 @@ static int do_global_checks(struct loadparm_context *lp_ctx) if (!parameter_name) { lp_dump_one(stdout, show_defaults, service); } else { - ret = !lp_dump_a_parameter(global_loadparm, s, parameter_name, stdout, (service == NULL)); + ret = !lp_dump_a_parameter(lp_ctx, s, parameter_name, stdout, (service == NULL)); } } else { - lp_dump(global_loadparm, stdout, show_defaults, lp_numservices(global_loadparm)); + lp_dump(lp_ctx, stdout, show_defaults, lp_numservices(lp_ctx)); } return(ret); } if(cname && caddr){ /* this is totally ugly, a real `quick' hack */ - for (s=0;s<lp_numservices(global_loadparm);s++) { - struct loadparm_service *service = lp_servicebynum(global_loadparm, s); + for (s=0;s<lp_numservices(lp_ctx);s++) { + struct loadparm_service *service = lp_servicebynum(lp_ctx, s); if (service != NULL) { if (allow_access(NULL, lp_hostsdeny(NULL), lp_hostsallow(NULL), cname, caddr) && allow_access(NULL, lp_hostsdeny(service), lp_hostsallow(service), cname, caddr)) { @@ -236,6 +165,90 @@ static int do_global_checks(struct loadparm_context *lp_ctx) } } } + + return ret; +} + + + int main(int argc, const char *argv[]) +{ + static bool silent_mode = false; + int ret = 0; + poptContext pc; +/* + static int show_all_parameters = 0; + static char *new_local_machine = NULL; +*/ + static const char *section_name = NULL; + static char *parameter_name = NULL; + static const char *cname; + static const char *caddr; + static bool show_defaults = false; + + struct poptOption long_options[] = { + POPT_AUTOHELP + {"suppress-prompt", 0, POPT_ARG_NONE, &silent_mode, true, "Suppress prompt for enter"}, + {"verbose", 'v', POPT_ARG_NONE, &show_defaults, true, "Show default options too"}, +/* + We need support for smb.conf macros before this will work again + {"server", 'L',POPT_ARG_STRING, &new_local_machine, 0, "Set %%L macro to servername\n"}, +*/ +/* + These are harder to do with the new code structure + {"show-all-parameters", '\0', POPT_ARG_NONE, &show_all_parameters, 1, "Show the parameters, type, possible values" }, +*/ + {"section-name", '\0', POPT_ARG_STRING, §ion_name, 0, "Limit testparm to a named section" }, + {"parameter-name", '\0', POPT_ARG_STRING, ¶meter_name, 0, "Limit testparm to a named parameter" }, + {"client-name", '\0', POPT_ARG_STRING, &cname, 0, "Client DNS name for 'hosts allow' checking (should match reverse lookup)"}, + {"client-ip", '\0', POPT_ARG_STRING, &caddr, 0, "Client IP address for 'hosts allow' checking"}, + POPT_COMMON_SAMBA + POPT_COMMON_VERSION + { NULL } + }; + + setup_logging(NULL, DEBUG_STDERR); + + pc = poptGetContext(NULL, argc, argv, long_options, + POPT_CONTEXT_KEEP_FIRST); + poptSetOtherOptionHelp(pc, "[OPTION...] [host-name] [host-ip]"); + + while(poptGetNextOpt(pc) != -1); + +/* + if (show_all_parameters) { + show_parameter_list(); + exit(0); + } +*/ + + if ( cname && ! caddr ) { + printf ( "ERROR: For 'hosts allow' check you must specify both a DNS name and an IP address.\n" ); + return(1); + } +/* + We need support for smb.conf macros before this will work again + + if (new_local_machine) { + set_local_machine_name(new_local_machine, True); + } +*/ + + /* We need this to force the output */ + lp_set_cmdline(global_loadparm, "log level", "2"); + + fprintf(stderr, "Loaded smb config files from %s\n", lp_configfile(global_loadparm)); + + if (!lp_load(lp_configfile(global_loadparm))) { + fprintf(stderr,"Error loading services.\n"); + return(1); + } + + fprintf(stderr,"Loaded services file OK.\n"); + + ret = do_global_checks(global_loadparm); + + ret |= do_share_checks(global_loadparm, cname, caddr, silent_mode, show_defaults, section_name, parameter_name); + return(ret); } |