1 # Unix SMB/CIFS implementation.
3 # Copyright (C) Catalyst.Net Ltd. 2017
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 Confirm that net.join_member works
25 from samba.net import Net, LIBNET_JOIN_AUTOMATIC
26 from samba.credentials import DONT_USE_KERBEROS
27 from samba import NTSTATUSError, ntstatus
30 class NetJoinTests(samba.tests.TestCaseInTempDir):
33 super(NetJoinTests, self).setUp()
34 self.domain = os.environ["DOMAIN"]
35 self.server = os.environ["SERVER"]
36 self.lp = self.get_loadparm()
37 self.lp.set("private dir", self.tempdir)
38 self.lp.set("lock dir", self.tempdir)
39 self.lp.set("state directory", self.tempdir)
42 super(NetJoinTests, self).tearDown()
44 def test_net_join(self):
45 netbios_name = "NetJoinTest"
46 machinepass = "abcdefghij"
47 creds = self.insta_creds(template=self.get_credentials(),
48 kerberos_state=DONT_USE_KERBEROS)
50 net = Net(creds, self.lp, server=self.server)
52 # NOTE WELL: We must not run more than one successful
53 # net.join_member per file (process), as the shared
54 # secrets.ldb handle will be kept between runs.
56 (join_password, sid, domain_name) = net.join_member(
57 self.domain, netbios_name, LIBNET_JOIN_AUTOMATIC,
58 machinepass=machinepass)
59 except NTSTATUSError as e:
60 code = ctypes.c_uint32(e.args[0]).value
61 if code == ntstatus.NT_STATUS_CONNECTION_DISCONNECTED:
62 self.fail("Connection failure")
64 os.unlink(os.path.join(self.tempdir, "secrets.ldb"))