Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Various bugfixes #64

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading