From e514ac54d247abb7074921920ebdcf535ff2627c Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Mon, 24 Jun 2024 13:19:54 +0200 Subject: [PATCH] Connected logger to other classes --- smbclientng/__main__.py | 8 ++++++-- smbclientng/core/InteractiveShell.py | 4 +++- smbclientng/core/Module.py | 3 ++- smbclientng/core/SMBSession.py | 3 ++- smbclientng/core/SessionsManager.py | 5 +++-- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/smbclientng/__main__.py b/smbclientng/__main__.py index d36fd17..67767f2 100644 --- a/smbclientng/__main__.py +++ b/smbclientng/__main__.py @@ -9,6 +9,7 @@ from smbclientng.core.Config import Config from smbclientng.core.Credentials import Credentials from smbclientng.core.InteractiveShell import InteractiveShell +from smbclientng.core.Logger import Logger from smbclientng.core.SessionsManager import SessionsManager @@ -106,7 +107,9 @@ def main(): config.not_interactive = options.not_interactive config.startup_script = options.startup_script - sessionsManager = SessionsManager(config=config) + logger = Logger(config=config, logfile=None) + + sessionsManager = SessionsManager(config=config, logger=logger) if any([(options.auth_domain != '.'), (options.auth_username is not None), (options.auth_password is not None),(options.auth_hashes is not None)]): credentials = Credentials( @@ -127,7 +130,8 @@ def main(): # Start the main interactive command line shell = InteractiveShell( sessionsManager=sessionsManager, - config=config + config=config, + logger=logger ) shell.run() diff --git a/smbclientng/core/InteractiveShell.py b/smbclientng/core/InteractiveShell.py index b56cbe1..0137e01 100644 --- a/smbclientng/core/InteractiveShell.py +++ b/smbclientng/core/InteractiveShell.py @@ -81,10 +81,12 @@ class InteractiveShell(object): running = True modules = {} - def __init__(self, sessionsManager, config): + def __init__(self, sessionsManager, config, logger): # Objects self.sessionsManager = sessionsManager self.config = config + self.logger = logger + # Internals self.commandCompleterObject = CommandCompleter(smbSession=self.sessionsManager.current_session, config=self.config) readline.set_completer(self.commandCompleterObject.complete) readline.parse_and_bind("tab: complete") diff --git a/smbclientng/core/Module.py b/smbclientng/core/Module.py index 70b0777..9c6d402 100644 --- a/smbclientng/core/Module.py +++ b/smbclientng/core/Module.py @@ -20,9 +20,10 @@ class Module(object): smbSession = None options = None - def __init__(self, smbSession, config): + def __init__(self, smbSession, config, logger): self.smbSession = smbSession self.config = config + self.logger = logger def parseArgs(self): raise NotImplementedError("Subclasses must implement this method") diff --git a/smbclientng/core/SMBSession.py b/smbclientng/core/SMBSession.py index 3e0b848..dded3bf 100644 --- a/smbclientng/core/SMBSession.py +++ b/smbclientng/core/SMBSession.py @@ -53,10 +53,11 @@ class SMBSession(object): test_rights(sharename): Tests read and write access rights on a share. """ - def __init__(self, host, port, credentials, config=None): + def __init__(self, host, port, credentials, config=None, logger=None): super(SMBSession, self).__init__() # Objects self.config = config + self.logger = logger # Target server self.host = host diff --git a/smbclientng/core/SessionsManager.py b/smbclientng/core/SessionsManager.py index 57acda8..9ed070f 100644 --- a/smbclientng/core/SessionsManager.py +++ b/smbclientng/core/SessionsManager.py @@ -17,13 +17,14 @@ class SessionsManager(object): current_session_id = None sessions = {} - def __init__(self, config): + def __init__(self, config, logger): self.sessions = {} self.next_session_id = 1 self.current_session = None self.current_session_id = None - self.config = config + self.config = config, + self.logger = logger def create_new_session(self, credentials, host, port=445): """