Skip to content

Commit

Permalink
fix issue #93
Browse files Browse the repository at this point in the history
  • Loading branch information
gijzelaerr committed Apr 12, 2022
1 parent 89d54fa commit f032a5a
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions pymonetdb/mapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def __init__(self):
self.hostname = ""
self.port = 0
self.username = ""
self.password = ""
self.database = ""
self.language = ""
self.handshake_options = None
Expand Down Expand Up @@ -158,7 +157,6 @@ def connect(self, database: str, username: str, password: str, language: str, #
self.hostname = hostname
self.port = port
self.username = username
self.password = password
self.database = database
self.language = language
self.unix_socket = unix_socket
Expand Down Expand Up @@ -199,17 +197,17 @@ def connect(self, database: str, username: str, password: str, language: str, #

if not (self.language == 'control' and not self.hostname):
# control doesn't require authentication over socket
self._login()
self._login(password=password)

self.socket.settimeout(socket.getdefaulttimeout())
self.state = STATE_READY

def _login(self, iteration=0):
def _login(self, iteration=0, password: Optional[str] = None):
""" Reads challenge from line, generate response and check if
everything is okay """

challenge = self._getblock()
response = self._challenge_response(challenge)
response = self._challenge_response(challenge, password)
self._putblock(response)
prompt = self._getblock().strip()

Expand All @@ -232,7 +230,7 @@ def _login(self, iteration=0):
if redirect[1] == "merovingian":
logger.debug("restarting authentication")
if iteration <= 10:
self._login(iteration=iteration + 1)
self._login(iteration=iteration + 1, password=password)
else:
raise OperationalError("maximal number of redirects "
"reached (10)")
Expand All @@ -245,7 +243,7 @@ def _login(self, iteration=0):
(self.hostname, self.port, self.database))
self.socket.close()
self.connect(hostname=self.hostname, port=self.port,
username=self.username, password=self.password,
username=self.username, password=password,
database=self.database, language=self.language)

else:
Expand Down Expand Up @@ -322,7 +320,7 @@ def cmd(self, operation): # noqa: C901
else:
raise ProgrammingError("unknown state: %s" % response)

def _challenge_response(self, challenge): # noqa: C901
def _challenge_response(self, challenge: str, password: str): # noqa: C901
""" generate a response to a mapi login challenge """

challenges = challenge.split(':')
Expand All @@ -331,7 +329,6 @@ def _challenge_response(self, challenge): # noqa: C901
challenges.pop()

salt, identity, protocol, hashes, endian = challenges[:5]
password = self.password

if protocol == '9':
algo = challenges[5]
Expand Down

0 comments on commit f032a5a

Please sign in to comment.