From 5c6eacdb04cd18d96dc6313c2a6f934925967e79 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Dec 2007 23:32:27 +0100 Subject: r26350: More tests. (This used to be commit 87799f55d5d85bf9a15a9637143faa32183b181b) --- source4/lib/cmdline/popt_common.c | 6 ++-- source4/param/loadparm.c | 74 +++++++++++++++------------------------ source4/param/tests/loadparm.c | 41 ++++++++++++++++++++++ source4/smb_server/smb/signing.c | 2 +- 4 files changed, 74 insertions(+), 49 deletions(-) diff --git a/source4/lib/cmdline/popt_common.c b/source4/lib/cmdline/popt_common.c index aae22e00c3..2bbb59dbda 100644 --- a/source4/lib/cmdline/popt_common.c +++ b/source4/lib/cmdline/popt_common.c @@ -62,11 +62,11 @@ static void popt_samba_callback(poptContext con, struct loadparm_context *lp_ctx = global_loadparm; /* FIXME: allow overriding */ if (reason == POPT_CALLBACK_REASON_POST) { - if (!lp_loaded()) { + if (lp_ctx == NULL) { if (getenv("SMB_CONF_PATH")) - lp_load(talloc_autofree_context(), getenv("SMB_CONF_PATH"), NULL); + lp_load(talloc_autofree_context(), getenv("SMB_CONF_PATH"), &lp_ctx); else - lp_load(talloc_autofree_context(), dyn_CONFIGFILE, NULL); + lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx); } /* Hook any 'every Samba program must do this, after * the smb.conf is setup' functions here */ diff --git a/source4/param/loadparm.c b/source4/param/loadparm.c index 8cdc82c961..8155dce444 100644 --- a/source4/param/loadparm.c +++ b/source4/param/loadparm.c @@ -2198,24 +2198,15 @@ struct parm_struct *lp_next_parameter(struct loadparm_context *lp_ctx, int snum, } -/*************************************************************************** - Auto-load some home services. -***************************************************************************/ - +/** + * Auto-load some home services. + */ static void lp_add_auto_services(struct loadparm_context *lp_ctx, const char *str) { return; } -/*************************************************************************** - Have we loaded a services file yet? -***************************************************************************/ - -bool lp_loaded(void) -{ - return (global_loadparm != NULL); -} /*************************************************************************** Unload unused services. @@ -2255,9 +2246,9 @@ static int lp_destructor(struct loadparm_context *lp_ctx) return 0; } -/*************************************************************************** - Initialise the global parameter structure. -***************************************************************************/ +/** + * Initialise the global parameter structure. + */ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx) { int i; @@ -2423,10 +2414,11 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx) return lp_ctx; } -/*************************************************************************** - Load the services array from the services file. Return True on success, - False on failure. -***************************************************************************/ +/** + * Load the services array from the services file. + * + * Return True on success, False on failure. + */ bool lp_load(TALLOC_CTX *mem_ctx, const char *filename, struct loadparm_context **ret_lp) { char *n2; @@ -2481,18 +2473,18 @@ bool lp_load(TALLOC_CTX *mem_ctx, const char *filename, struct loadparm_context return bRetval; } -/*************************************************************************** - Return the max number of services. -***************************************************************************/ +/** + * Return the max number of services. + */ int lp_numservices(struct loadparm_context *lp_ctx) { return lp_ctx->iNumServices; } -/*************************************************************************** -Display the contents of the services array in human-readable form. -***************************************************************************/ +/** + * Display the contents of the services array in human-readable form. + */ void lp_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults, int maxtoprint) @@ -2510,10 +2502,9 @@ void lp_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults, lp_dump_one(f, show_defaults, lp_ctx->services[iService]); } -/*************************************************************************** -Display the contents of one service in human-readable form. -***************************************************************************/ - +/** + * Display the contents of one service in human-readable form. + */ void lp_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service) { if (service != NULL) { @@ -2555,9 +2546,9 @@ struct loadparm_service *lp_service(struct loadparm_context *lp_ctx, } -/******************************************************************* - A useful volume label function. -********************************************************************/ +/** + * A useful volume label function. + */ const char *volume_label(struct loadparm_service *service) { const char *ret = lp_volume(service); @@ -2567,15 +2558,9 @@ const char *volume_label(struct loadparm_service *service) } -/*********************************************************** - If we are PDC then prefer us as DMB -************************************************************/ - -bool lp_domain_logons(struct loadparm_context *lp_ctx) -{ - return (lp_server_role(lp_ctx) == ROLE_DOMAIN_CONTROLLER); -} - +/** + * If we are PDC then prefer us as DMB + */ const char *lp_printername(struct loadparm_service *service) { const char *ret = _lp_printername(service); @@ -2586,10 +2571,9 @@ const char *lp_printername(struct loadparm_service *service) } -/******************************************************************* - Return the max print jobs per queue. -********************************************************************/ - +/** + * Return the max print jobs per queue. + */ int lp_maxprintjobs(struct loadparm_service *service) { int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault.iMaxPrintJobs; diff --git a/source4/param/tests/loadparm.c b/source4/param/tests/loadparm.c index 1d689c0a9a..92871e043d 100644 --- a/source4/param/tests/loadparm.c +++ b/source4/param/tests/loadparm.c @@ -37,6 +37,35 @@ static bool test_set_option(struct torture_context *tctx) return true; } +static bool test_set_cmdline(struct torture_context *tctx) +{ + struct loadparm_context *lp_ctx = loadparm_init(tctx); + torture_assert(tctx, lp_set_cmdline(lp_ctx, "workgroup", "werkgroep"), "lp_set_cmdline failed"); + torture_assert(tctx, lp_do_global_parameter(lp_ctx, "workgroup", "barbla"), "lp_set_option failed"); + torture_assert_str_equal(tctx, "WERKGROEP", lp_workgroup(lp_ctx), "workgroup"); + return true; +} + +static bool test_do_global_parameter(struct torture_context *tctx) +{ + struct loadparm_context *lp_ctx = loadparm_init(tctx); + torture_assert(tctx, lp_do_global_parameter(lp_ctx, "workgroup", "werkgroep42"), + "lp_set_cmdline failed"); + torture_assert_str_equal(tctx, lp_workgroup(lp_ctx), "WERKGROEP42", "workgroup"); + return true; +} + + +static bool test_do_global_parameter_var(struct torture_context *tctx) +{ + struct loadparm_context *lp_ctx = loadparm_init(tctx); + torture_assert(tctx, lp_do_global_parameter_var(lp_ctx, "workgroup", "werk%s%d", "groep", 42), + "lp_set_cmdline failed"); + torture_assert_str_equal(tctx, lp_workgroup(lp_ctx), "WERKGROEP42", "workgroup"); + return true; +} + + static bool test_set_option_invalid(struct torture_context *tctx) { struct loadparm_context *lp_ctx = loadparm_init(tctx); @@ -108,12 +137,21 @@ static bool test_lp_do_service_parameter(struct torture_context *tctx) return true; } +static bool test_lp_service(struct torture_context *tctx) +{ + struct loadparm_context *lp_ctx = loadparm_init(tctx); + struct loadparm_service *service = lp_add_service(lp_ctx, &sDefault, "foo"); + torture_assert(tctx, service == lp_service(lp_ctx, "foo"), "invalid service"); + return true; +} + struct torture_suite *torture_local_loadparm(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = torture_suite_create(mem_ctx, "LOADPARM"); torture_suite_add_simple_test(suite, "create", test_create); torture_suite_add_simple_test(suite, "set_option", test_set_option); + torture_suite_add_simple_test(suite, "set_cmdline", test_set_cmdline); torture_suite_add_simple_test(suite, "set_option_invalid", test_set_option_invalid); torture_suite_add_simple_test(suite, "set_option_parametric", test_set_option_parametric); torture_suite_add_simple_test(suite, "set_lp_parm_double", test_lp_parm_double); @@ -121,6 +159,9 @@ struct torture_suite *torture_local_loadparm(TALLOC_CTX *mem_ctx) torture_suite_add_simple_test(suite, "set_lp_parm_int", test_lp_parm_int); torture_suite_add_simple_test(suite, "set_lp_parm_bytes", test_lp_parm_bytes); torture_suite_add_simple_test(suite, "service_parameter", test_lp_do_service_parameter); + torture_suite_add_simple_test(suite, "lp_service", test_lp_service); + torture_suite_add_simple_test(suite, "do_global_parameter_var", test_do_global_parameter_var); + torture_suite_add_simple_test(suite, "do_global_parameter", test_do_global_parameter); return suite; } diff --git a/source4/smb_server/smb/signing.c b/source4/smb_server/smb/signing.c index 146d8c7256..3693579c46 100644 --- a/source4/smb_server/smb/signing.c +++ b/source4/smb_server/smb/signing.c @@ -114,7 +114,7 @@ bool smbsrv_init_signing(struct smbsrv_connection *smb_conn) smb_conn->signing.mandatory_signing = true; break; case SMB_SIGNING_AUTO: - if (lp_domain_logons(smb_conn->lp_ctx)) { + if (lp_server_role(smb_conn->lp_ctx) == ROLE_DOMAIN_CONTROLLER) { smb_conn->signing.allow_smb_signing = true; } else { smb_conn->signing.allow_smb_signing = false; -- cgit