Skip to content

Commit

Permalink
Merge pull request #64 from p0dalirius/bugfixes
Browse files Browse the repository at this point in the history
[bug] Various bugfixes
  • Loading branch information
p0dalirius authored Jun 24, 2024
2 parents e5ab028 + 29ee8c8 commit 25283e9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
12 changes: 9 additions & 3 deletions smbclientng/core/InteractiveShell.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,11 @@ def command_sizeof(self, arguments, command):
# SMB share needed : Yes

class RecursiveSizeOfPrint(object):
def __init__(self, entry, smbSession, config):
def __init__(self, entry, sessionsManager, config, logger):
self.entry = entry
self.config = config
self.sessionsManager.current_session = smbSession
self.logger = logger
self.sessionsManager = sessionsManager
self.size = 0

def update(self, entry, fullpath, depth):
Expand Down Expand Up @@ -913,7 +914,12 @@ def print(self, end='\n'):

total = 0
for entry in entries:
rsop = RecursiveSizeOfPrint(entry=entry, smbSession=self.sessionsManager.current_session, config=self.config)
rsop = RecursiveSizeOfPrint(
entry=entry,
sessionsManager=self.sessionsManager,
config=self.config,
logger=self.logger
)
# Directory
if entry.is_directory():
self.sessionsManager.current_session.find(
Expand Down
14 changes: 7 additions & 7 deletions smbclientng/core/Logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, config, logfile=None):
self.logfile = self.logfile + (".%d" % k)
open(self.logfile, "w").close()

def print(self, message=""):
def print(self, message="", end='\n'):
"""
Prints a message to stdout and logs it to a file if logging is enabled.
Expand All @@ -61,10 +61,10 @@ def print(self, message=""):

nocolor_message = re.sub(r"\x1b[\[]([0-9;]+)m", "", message)
if self.config.no_colors:
print(nocolor_message)
print(nocolor_message, end=end)
else:
print(message)
self.__write_to_logfile(nocolor_message)
print(message, end=end)
self.__write_to_logfile(nocolor_message, end=end)

def info(self, message):
"""
Expand Down Expand Up @@ -118,7 +118,7 @@ def error(self, message):
print("[\x1b[1;91merror\x1b[0m] %s" % message)
self.__write_to_logfile("[error] %s" % nocolor_message)

def __write_to_logfile(self, message):
def __write_to_logfile(self, message, end='\n'):
"""
Writes the provided message to the log file specified during Logger instance initialization.
Expand All @@ -127,8 +127,8 @@ def __write_to_logfile(self, message):
Args:
message (str): The message to be written to the log file.
"""

if self.logfile is not None:
f = open(self.logfile, "a")
f.write(message + "\n")
f.write(message + end)
f.close()
2 changes: 1 addition & 1 deletion smbclientng/core/SessionsManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, config, logger):
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):
Expand Down

0 comments on commit 25283e9

Please sign in to comment.