From cbfe0b6d3b1f4d0c8cbfa1149cab7d394530ff2b Mon Sep 17 00:00:00 2001 From: Fabian Heller Date: Tue, 4 Jan 2022 12:43:14 +0100 Subject: [PATCH 1/2] Fix SSO with instance instead of port When a named instance instead of a port is used, Kerberos logins failed because the spn string was "MSSQLSvc@SERVER_NAME:None" instead of "MSSQLSvc@SERVER_NAME:INSTANCE_NAME". --- src/pytds/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytds/__init__.py b/src/pytds/__init__.py index 45d6c0b..831d929 100644 --- a/src/pytds/__init__.py +++ b/src/pytds/__init__.py @@ -1290,7 +1290,7 @@ def connect(dsn=None, database=None, user=None, password=None, timeout=None, parsed_servers.append((host, port, instance)) if use_sso: - spn = "MSSQLSvc@{}:{}".format(parsed_servers[0][0], parsed_servers[0][1]) + spn = "MSSQLSvc@{}:{}".format(parsed_servers[0][0], parsed_servers[0][1] or parsed_servers[0][2]) from . import login as pytds_login try: login.auth = pytds_login.SspiAuth(spn=spn) From 53424afdfabedb52b86cbfe5d8ed4e909b6eb3b8 Mon Sep 17 00:00:00 2001 From: Fabian Heller Date: Thu, 6 Jan 2022 12:14:57 +0100 Subject: [PATCH 2/2] Fix Kerberos Login on Linux This fixes the following error: kerberos.GSSError: (('Unspecified GSS failure. Minor code may provide more information', 851968), ('Server not found in Kerberos database', -1765328377)) --- src/pytds/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pytds/__init__.py b/src/pytds/__init__.py index 831d929..ef72a3f 100644 --- a/src/pytds/__init__.py +++ b/src/pytds/__init__.py @@ -1290,7 +1290,8 @@ def connect(dsn=None, database=None, user=None, password=None, timeout=None, parsed_servers.append((host, port, instance)) if use_sso: - spn = "MSSQLSvc@{}:{}".format(parsed_servers[0][0], parsed_servers[0][1] or parsed_servers[0][2]) + server = socket.getfqdn(parsed_servers[0][0]) + spn = "MSSQLSvc@{}:{}".format(server, parsed_servers[0][1] or parsed_servers[0][2]) from . import login as pytds_login try: login.auth = pytds_login.SspiAuth(spn=spn)