fs: Explore the honeyfs directory for realfile names at init time.

The old method of checking the honeyfs directory whenever a file was
accessed for the first time required that the original path to the file
be known. If the file was renamed, copied, moved to a new directory, or
one of its parent directories was renamed before its first access, its
original path would be completely lost and the real filename would not be
resolved.

This new method ensures that all A_REALFILE attributes are populated
upfront, and the filesystem can be rearranged plenty without breaking
honeyfs.
This commit is contained in:
Sam Edwards
2016-10-06 14:15:42 -07:00
committed by Michel Oosterhof
parent 8efaee6f1a
commit 731ec40492

View File

@ -65,6 +65,25 @@ class HoneyPotFilesystem(object):
# Keep count of new files, so we can have an artificial limit
self.newcount = 0
# Get the honeyfs path from the config file and explore it for file
# contents:
self.init_honeyfs(self.cfg.get('honeypot', 'contents_path'))
def init_honeyfs(self, honeyfs_path):
"""
Explore the honeyfs at 'honeyfs_path' and set all A_REALFILE attributes on
the virtual filesystem.
"""
for path, directories, filenames in os.walk(honeyfs_path):
for filename in filenames:
realfile_path = os.path.join(path, filename)
virtual_path = '/' + os.path.relpath(realfile_path, honeyfs_path)
f = self.getfile(virtual_path, follow_symlinks=False)
if f and f[A_TYPE] == T_FILE:
self.update_realfile(f, realfile_path)
def resolve_path(self, path, cwd):
"""
@ -214,10 +233,7 @@ class HoneyPotFilesystem(object):
f = self.getfile(path)
if f[A_TYPE] == T_DIR:
raise IsADirectoryError
elif f[A_TYPE] == T_FILE:
self.update_realfile(f, '%s/%s' % \
(self.cfg.get('honeypot', 'contents_path'), path))
if f[A_REALFILE]:
elif f[A_TYPE] == T_FILE and f[A_REALFILE]:
return file(f[A_REALFILE], 'rb').read()