smbd: Fix crossing automounter mount points
[Samba.git] / python / samba / tests / net_join.py
blob5bc3a1aab3dac5bcdd1732517f702010996f003d
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/>.
19 """
20 Confirm that net.join_member works
21 """
23 import samba.tests
24 import os
25 from samba.net import Net, LIBNET_JOIN_AUTOMATIC
26 from samba.credentials import DONT_USE_KERBEROS
27 from samba import NTSTATUSError, ntstatus
28 import ctypes
31 class NetJoinTests(samba.tests.TestCaseInTempDir):
33 def setUp(self):
34 super().setUp()
35 self.domain = os.environ["DOMAIN"]
36 self.server = os.environ["SERVER"]
37 self.lp = self.get_loadparm()
38 self.lp.set("private dir", self.tempdir)
39 self.lp.set("lock dir", self.tempdir)
40 self.lp.set("state directory", self.tempdir)
42 def test_net_join(self):
43 netbios_name = "NetJoinTest"
44 machinepass = "abcdefghij"
45 creds = self.insta_creds(template=self.get_credentials(),
46 kerberos_state=DONT_USE_KERBEROS)
48 net = Net(creds, self.lp, server=self.server)
50 # NOTE WELL: We must not run more than one successful
51 # net.join_member per file (process), as the shared
52 # secrets.ldb handle will be kept between runs.
53 try:
54 (join_password, sid, domain_name) = net.join_member(
55 self.domain, netbios_name, LIBNET_JOIN_AUTOMATIC,
56 machinepass=machinepass)
57 except NTSTATUSError as e:
58 code = ctypes.c_uint32(e.args[0]).value
59 if code == ntstatus.NT_STATUS_CONNECTION_DISCONNECTED:
60 self.fail("Connection failure")
61 raise
62 os.unlink(os.path.join(self.tempdir, "secrets.ldb"))
63 pass