Fix bug 7866 - "net" in v3-6-test broken.
authorJeremy Allison <jra@samba.org>
Wed, 15 Dec 2010 18:57:23 +0000 (10:57 -0800)
committerJeremy Allison <jra@samba.org>
Wed, 15 Dec 2010 19:45:25 +0000 (20:45 +0100)
Someone wasn't careful about testing when not running as root :-).

Autobuild-User: Jeremy Allison <jra@samba.org>
Autobuild-Date: Wed Dec 15 20:45:25 CET 2010 on sn-devel-104

source3/utils/net.c
source3/utils/net_ads.c
source3/utils/net_lookup.c

index 44119dc2c6f0b9f15c7778a5e003d592ee87a55b..13eed2f9ca6c64a4e6ae383eb9f90c043b2bea6c 100644 (file)
@@ -924,11 +924,11 @@ static struct functable net_func[] = {
                c->opt_password = getenv("PASSWD");
        }
 
+       /* Failing to init the msg_ctx isn't a fatal error. Only
+          root-level things (joining/leaving domains etc.) will be denied. */
+
        c->msg_ctx = messaging_init(c, procid_self(),
                                    event_context_init(c));
-       if (c->msg_ctx == NULL) {
-               exit(1);
-       }
 
        rc = net_run_function(c, argc_new-1, argv_new+1, "net", net_func);
 
index 858830f3c1dba8d05db6d8a09b5535425c37f58c..0b2165d73fed4792024c1df9236138cc8970f824 100644 (file)
@@ -968,6 +968,12 @@ static int net_ads_leave(struct net_context *c, int argc, const char **argv)
                use_in_memory_ccache();
        }
 
+       if (!c->msg_ctx) {
+               d_fprintf(stderr, _("Could not initialise message context. "
+                       "Try running as root\n"));
+               return -1;
+       }
+
        werr = libnet_init_UnjoinCtx(ctx, &r);
        if (!W_ERROR_IS_OK(werr)) {
                d_fprintf(stderr, _("Could not initialise unjoin context.\n"));
@@ -1348,6 +1354,13 @@ int net_ads_join(struct net_context *c, int argc, const char **argv)
                goto fail;
        }
 
+       if (!c->msg_ctx) {
+               d_fprintf(stderr, _("Could not initialise message context. "
+                       "Try running as root\n"));
+               werr = WERR_ACCESS_DENIED;
+               goto fail;
+       }
+
        /* Do the domain join here */
 
        r->in.domain_name       = domain;
index 0a85da346fd7ffe55f88bc2e77310007036c0dc6..2afa75c609e2c1e9a14287cf2de44e8b694cb3fd 100644 (file)
@@ -410,6 +410,12 @@ static int net_lookup_dsgetdcname(struct net_context *c, int argc, const char **
                site_name = argv[2];
        }
 
+        if (!c->msg_ctx) {
+               d_fprintf(stderr, _("Could not initialise message context. "
+                       "Try running as root\n"));
+               return -1;
+        }
+
        status = dsgetdcname(mem_ctx, c->msg_ctx, domain_name, NULL, site_name,
                             flags, &info);
        if (!NT_STATUS_IS_OK(status)) {