return "drsException: " + self.value
-def drsuapi_connect(server, lp, creds):
+def drsuapi_connect(server, lp, creds, ip=None):
"""Make a DRSUAPI connection to the server.
:param server: the name of the server to connect to
:param lp: a samba line parameter object
:param creds: credential used for the connection
+ :param ip: Forced target server name
:return: A tuple with the drsuapi bind object, the drsuapi handle
and the supported extensions.
:raise drsException: if the connection fails
binding_options = "seal"
if lp.log_level() >= 9:
binding_options += ",print"
- binding_string = "ncacn_ip_tcp:%s[%s]" % (server, binding_options)
+
+ # Allow forcing the IP
+ if ip is not None:
+ binding_options += f",target_hostname={server}"
+ binding_string = f"ncacn_ip_tcp:{ip}[{binding_options}]"
+ else:
+ binding_string = "ncacn_ip_tcp:%s[%s]" % (server, binding_options)
+
try:
drsuapiBind = drsuapi.drsuapi(binding_string, lp, creds)
(drsuapiHandle, bindSupportedExtensions) = drs_DsBind(drsuapiBind)