r26350: More tests.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 8 Dec 2007 22:32:27 +0000 (23:32 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 21 Dec 2007 04:48:55 +0000 (05:48 +0100)
(This used to be commit 87799f55d5d85bf9a15a9637143faa32183b181b)

source4/lib/cmdline/popt_common.c
source4/param/loadparm.c
source4/param/tests/loadparm.c
source4/smb_server/smb/signing.c

index aae22e00c345616f3e96f85d2b85e78e0342efbe..2bbb59dbda823910ee7b01b06c96d770ff564aef 100644 (file)
@@ -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 */
index 8cdc82c96133a396070e3eb0496d4a5e34fb20bd..8155dce444b42a707cb66c04f147ed3198c08637 100644 (file)
@@ -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;
index 1d689c0a9a18357e55b29a2a2654096ff29822c9..92871e043d85e87b14b24f291442c0212b667816 100644 (file)
@@ -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;
 }
index 146d8c72564e1c3de745996f09cc91003ad681a9..3693579c460453ccbe0008206ff070d4cb1a108c 100644 (file)
@@ -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;