selftest: Clear environment before provision
authorJamie McClymont <jamiemcclymont@catalyst.net.nz>
Mon, 29 Jan 2018 05:59:34 +0000 (18:59 +1300)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 22 Mar 2018 07:00:25 +0000 (08:00 +0100)
Currently, if an environment is being provisioned after a test which used
ad_member_rfc2307, the provisioning process has all of the following in its
environment:

{
'DC_NETBIOSNAME'               => 'LOCALDC',
'DC_PASSWORD'                  => 'locDCpass1',
'DC_SERVER_IP'                 => '127.0.0.21',
'DC_SERVER_IPV6'               => 'fd00:0000:0000:0000:0000:0000:5357:5f15',
'DC_SERVER'                    => 'localdc',
'DC_USERNAME'                  => 'Administrator',
'DOMAIN'                       => 'SAMBADOMAIN',
'LOCAL_PATH'                   => '/.../st/ad_member_rfc2307/share',
'LOCK_DIR'                     => '/.../st/ad_member_rfc2307/lockdir',
'NETBIOSNAME'                  => 'RFC2307MEMBER',
'NMBD_SOCKET_DIR'              => '/.../st/ad_member_rfc2307/nmbd',
'NSS_WRAPPER_GROUP'            => '/.../st/ad_member_rfc2307/private/group',
'NSS_WRAPPER_HOSTNAME'         => 'rfc2307member.samba.example.com',
'NSS_WRAPPER_HOSTS'            => '/.../st/hosts',
'NSS_WRAPPER_MODULE_FN_PREFIX' => 'winbind',
'NSS_WRAPPER_MODULE_SO_PATH'   => '/.../bin/default/nsswitch/libnss-wrapper-winbind.so',
'NSS_WRAPPER_PASSWD'           => '/.../st/ad_member_rfc2307/private/passwd',
'PASSWORD'                     => 'loCalMemberPass',
'REALM'                        => 'SAMBA.EXAMPLE.COM',
'RESOLV_WRAPPER_HOSTS'         => '/.../st/dns_host_file',
'SELFTEST_WINBINDD_SOCKET_DIR' => '/.../st/ad_member_rfc2307/winbindd',
'SERVER_IP'                    => '127.0.0.34',
'SERVER_IPV6'                  => 'fd00:0000:0000:0000:0000:0000:5357:5f22',
'SERVER'                       => 'RFC2307MEMBER',
'USERID'                       => '55668',
'USERNAME'                     => 'jamiemcclymont',
}

Unsurprisingly, some of these can cause issues for the provisioning process, if
a reduced subset of tests is being run which causes the provision to encounter
never-before-seen pairs of adjacent environments.

For example, a run with only
TESTS='--include-env=vampire_dc --include-env=ad_member_rfc2307'
would fail to start up the vampire_dc with:
Could not find machine account in secrets database:
Failed to fetch machine account password from secrets.ldb:
Could not find entry to match filter:
'(&(flatname=SAMBADOMAIN)(objectclass=primaryDomain))' base: 'cn=Primary Domains': No such object: dsdb_search at ../source4/dsdb/common/util.c:4641

Signed-off-by: Jamie McClymont <jamiemcclymont@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
selftest/selftest.pl

index 42c1e62736fbb997433a4daed53795d5434ee477..a772613b8e10fa53f7bdd79d80fba37e9d41610e 100755 (executable)
@@ -942,6 +942,19 @@ sub setup_env($$)
 
        $option = "client" if $option eq "";
 
+       # Initially clear out the environment for the provision, so previous envs'
+       # variables don't leak in. Provisioning steps must explicitly set their
+       # necessary variables when calling out to other executables
+       foreach (@exported_envvars) {
+               unless ($_ == "NSS_WRAPPER_HOSTS" ||
+                       $_ == "RESOLV_WRAPPER_HOSTS")
+               {
+                       delete $ENV{$_};
+               }
+       }
+       delete $ENV{SOCKET_WRAPPER_DEFAULT_IFACE};
+       delete $ENV{SMB_CONF_PATH};
+
        $ENV{KRB5CCNAME} = "FILE:${selftest_krbt_ccache_path}.${envname}/ignore";
 
        if (defined(get_running_env($envname))) {