Skip to content

Commit

Permalink
Merge pull request #81 from p0dalirius/Create-an-alias-find-to-module…
Browse files Browse the repository at this point in the history
…-find

[enhancement] Implemented an alias 'find' to 'module find', Fixes #77
p0dalirius authored Jul 4, 2024
2 parents 14aa407 + 4acedc3 commit 33fc89d
Showing 3 changed files with 34 additions and 12 deletions.
10 changes: 10 additions & 0 deletions smbclientng/core/CommandCompleter.py
Original file line number Diff line number Diff line change
@@ -91,6 +91,16 @@ class CommandCompleter(object):
"subcommands": [],
"autocomplete": []
},
"find": {
"description": [
"Search for files in a directory hierarchy",
"Syntax: find [-h] [-name NAME] [-iname INAME] [-type TYPE] [-size SIZE] [-ls]",
" [-download] [-maxdepth MAXDEPTH] [-mindepth MINDEPTH]",
" [PATH ...]"
],
"subcommands": [],
"autocomplete": []
},
"get": {
"description": [
"Get a remote file.",
32 changes: 22 additions & 10 deletions smbclientng/core/InteractiveShell.py
Original file line number Diff line number Diff line change
@@ -183,6 +183,10 @@ def process_line(self, commandLine):
# debug
elif command == "debug":
self.command_debug(arguments, command)

# Find
elif command == "find":
self.command_find(arguments, command)

# Get a file
elif command == "get":
@@ -196,14 +200,6 @@ def process_line(self, commandLine):
elif command in ["ls", "dir"]:
self.command_ls(arguments, command)

# Creates a new remote directory
elif command == "mkdir":
self.command_mkdir(arguments, command)

# Put a file
elif command == "put":
self.command_put(arguments, command)

# Shows the content of a local file
elif command == "lcat":
self.command_lcat(arguments, command)
@@ -248,6 +244,10 @@ def process_line(self, commandLine):
elif command == "ltree":
self.command_ltree(arguments, command)

# Creates a new remote directory
elif command == "mkdir":
self.command_mkdir(arguments, command)

# Modules
elif command == "module":
self.command_module(arguments, command)
@@ -256,6 +256,10 @@ def process_line(self, commandLine):
elif command == "mount":
self.command_mount(arguments, command)

# Put a file
elif command == "put":
self.command_put(arguments, command)

# Reconnects the current SMB session
elif command in ["connect", "reconnect"]:
self.command_reconnect(arguments, command)
@@ -391,6 +395,16 @@ def command_close(self, arguments, command):
if self.sessionsManager.current_session.connected:
self.sessionsManager.current_session.close_smb_session()

def command_find(self, arguments, command):
module_name = "find"

if module_name in self.modules.keys():
module = self.modules[module_name](self.sessionsManager.current_session, self.config, self.logger)
arguments_string = ' '.join(arguments)
module.run(arguments_string)
else:
self.logger.error("Module '%s' does not exist." % module_name)

@command_arguments_required
@active_smb_connection_needed
@smb_share_is_set
@@ -741,8 +755,6 @@ def command_mkdir(self, arguments, command):
self.sessionsManager.current_session.mkdir(path=arguments[0])

@command_arguments_required
@active_smb_connection_needed
@smb_share_is_set
def command_module(self, arguments, command):
module_name = arguments[0]

4 changes: 2 additions & 2 deletions smbclientng/modules/Find.py
Original file line number Diff line number Diff line change
@@ -181,9 +181,9 @@ def __find_callback(self, entry, fullpath, depth):
windows_ls_entry(entry, fullpath)
else:
if entry.is_directory():
print("%s" % fullpath)
print("%s" % fullpath.replace(ntpath.sep, '/'))
else:
print("%s" % fullpath)
print("%s" % fullpath.replace(ntpath.sep, '/'))

return None

0 comments on commit 33fc89d

Please sign in to comment.