selftest: fix creation of builtin users in wait_for_start
authorRalph Boehme <slow@samba.org>
Mon, 8 Jan 2018 17:38:08 +0000 (18:38 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 10 Jan 2018 00:01:24 +0000 (01:01 +0100)
If "BUILTIN\Users" already exists, attempting to create it would fail,
so we should check for the existence prior to the creation.

It is unclear *why* the mapping sometimes already exist and sometime
not. There are two places where they would have been created:

1. libnet_join_add_dom_rids_to_builtins tries to add the mapping when
joining a domain, but at that point winbindd isn't running

2. when a user is authenticated in smbd, which clearly can't have
happended when in the function wait_for_start

Go figure...

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
selftest/target/Samba3.pm

index 851460c502b10213b4f7add8de497278610db6a9..0f41b0ea1c02daedd969161611a7fdf6a0f43974 100755 (executable)
@@ -2333,6 +2333,7 @@ force_user:x:$gid_force_user:
 sub wait_for_start($$$$$)
 {
        my ($self, $envvars, $nmbd, $winbindd, $smbd) = @_;
+       my $cmd;
        my $ret;
 
        if ($nmbd eq "yes") {
@@ -2366,8 +2367,7 @@ sub wait_for_start($$$$$)
        if ($winbindd eq "yes") {
            print "checking for winbindd\n";
            my $count = 0;
-           my $cmd = "";
-           $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR='$envvars->{SELFTEST_WINBINDD_SOCKET_DIR}' ";
+           $cmd = "SELFTEST_WINBINDD_SOCKET_DIR='$envvars->{SELFTEST_WINBINDD_SOCKET_DIR}' ";
            $cmd .= "NSS_WRAPPER_PASSWD='$envvars->{NSS_WRAPPER_PASSWD}' ";
            $cmd .= "NSS_WRAPPER_GROUP='$envvars->{NSS_WRAPPER_GROUP}' ";
            $cmd .= Samba::bindir_path($self, "wbinfo") . " --ping-dc";
@@ -2419,9 +2419,28 @@ sub wait_for_start($$$$$)
            return 1;
        }
 
+       # note: creating builtin groups requires winbindd for the
+       # unix id allocator
+       my $create_builtin_users = "no";
        if ($winbindd eq "yes") {
-           # note: creating builtin groups requires winbindd for the
-           # unix id allocator
+               $cmd = "SELFTEST_WINBINDD_SOCKET_DIR='$envvars->{SELFTEST_WINBINDD_SOCKET_DIR}' ";
+               $cmd .= "NSS_WRAPPER_PASSWD='$envvars->{NSS_WRAPPER_PASSWD}' ";
+               $cmd .= "NSS_WRAPPER_GROUP='$envvars->{NSS_WRAPPER_GROUP}' ";
+               $cmd .= Samba::bindir_path($self, "wbinfo") . " --sid-to-gid=S-1-5-32-545";
+               my $wbinfo_out = qx($cmd 2>&1);
+               if ($? != 0) {
+                       # wbinfo doesn't give us a better error code then
+                       # WBC_ERR_DOMAIN_NOT_FOUND, but at least that's
+                       # different then WBC_ERR_WINBIND_NOT_AVAILABLE
+                       if ($wbinfo_out !~ /WBC_ERR_DOMAIN_NOT_FOUND/) {
+                               print("Failed to run \"wbinfo --sid-to-gid=S-1-5-32-545\": $wbinfo_out");
+                               teardown_env($self, $envvars);
+                               return 0;
+                       }
+                       $create_builtin_users = "yes";
+               }
+       }
+       if ($create_builtin_users eq "yes") {
            $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} sam createbuiltingroup Users");
            if ($ret != 0) {
                print "Failed to create BUILTIN\\Users group\n";