Skip to content

Commit

Permalink
Fixed sizeof command bug, introduced by logger
Browse files Browse the repository at this point in the history
  • Loading branch information
p0dalirius committed Jun 24, 2024
1 parent e5ab028 commit b7f2a69
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 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()

0 comments on commit b7f2a69

Please sign in to comment.