From: David Mulder Date: Mon, 25 Oct 2021 14:49:35 +0000 (-0600) Subject: samba-tool: Pick local host if calling samba-tool from DC X-Git-Tag: ldb-2.5.0~354 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c9195e28bc51ac375d609f8306db2456f348167;p=thirdparty%2Fsamba.git samba-tool: Pick local host if calling samba-tool from DC It is reasonable to assume, that if we are running a command from a DC, that a user expects that the command will run against this DC. Signed-off-by: David Mulder Reviewed-by: Rowland Penny Autobuild-User(master): David Mulder Autobuild-Date(master): Tue Oct 26 14:23:42 UTC 2021 on sn-devel-184 --- diff --git a/python/samba/netcmd/common.py b/python/samba/netcmd/common.py index bb17bfa10f2..588806b2ad3 100644 --- a/python/samba/netcmd/common.py +++ b/python/samba/netcmd/common.py @@ -18,6 +18,7 @@ # import re +from socket import gethostname from samba.dcerpc import nbt from samba.net import Net import ldb @@ -59,6 +60,10 @@ def netcmd_finddc(lp, creds, realm=None): '''Return domain-name of a writable/ldap-capable DC for the default domain (parameter "realm" in smb.conf) unless another realm has been specified as argument''' + # It is reasonable to assume, that if we are running a command from a DC, + # that a user expects that the command will run against this DC. + if lp.get('server role') == 'active directory domain controller': + return gethostname() net = Net(creds=creds, lp=lp) if realm is None: realm = lp.get('realm')