Loading fs/CMakeLists.txt +1 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,6 @@ find_package(FUSE3 REQUIRED) find_package(Boost 1.56.0 COMPONENTS system filesystem serialization) include_directories(${FUSE3_INCLUDE_DIR} include/) set(SOURCE_FILES src/main.cpp src/main.h src/fuse_ops.h src/util.cpp src/metadata.h src/metadata.cpp src/metadata_ops.h src/metadata_ops.cpp src/dentry_ops.cpp src/dentry_ops.h src/configure.h src/fuse_ops/file.cpp src/fuse_ops/directory.cpp) set(SOURCE_FILES src/main.cpp src/main.h src/fuse_ops.h src/util.cpp src/metadata.h src/metadata.cpp src/metadata_ops.h src/metadata_ops.cpp src/dentry_ops.cpp src/dentry_ops.h src/configure.h src/fuse_ops/file.cpp src/fuse_ops/directory.cpp src/fuse_ops/permission.cpp src/fuse_utils.h) add_executable(adafs ${SOURCE_FILES} src/main.cpp) target_link_libraries(adafs ${FUSE3_LIBRARIES} -lpthread -lboost_system -lboost_filesystem -lboost_serialization) No newline at end of file fs/src/fuse_ops.h +1 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ #define FS_FUSE_OPS_H #include "main.h" #include "fuse_utils.h" // file int adafs_getattr(const char*, struct stat*, struct fuse_file_info*); Loading fs/src/fuse_ops/directory.cpp +50 −1 Original line number Diff line number Diff line Loading @@ -4,14 +4,63 @@ #include "../main.h" #include "../fuse_ops.h" #include "../metadata.h" #include "../metadata_ops.h" using namespace std; /** Open directory * * Unless the 'default_permissions' mount option is given, * this method should check if opendir is permitted for this * directory. Optionally opendir may also return an arbitrary * filehandle in the fuse_file_info structure, which will be * passed to readdir, closedir and fsyncdir. */ int adafs_opendir(const char* p, struct fuse_file_info* fi) { ADAFS_DATA->logger->info("FUSE: adafs_opendir() enter"s); // XXX error handling auto path = bfs::path(p); auto md = make_shared<Metadata>(); get_metadata(*md, path); int access = fi->flags & O_ACCMODE; // ADAFS_DATA->logger->info("access variable: {}", access); switch (access) { case O_RDONLY: return chk_access(*md, R_OK); case O_WRONLY: return chk_access(*md, W_OK); case O_RDWR: return chk_access(*md, R_OK | W_OK); default: return -EACCES; } return 0; } /** Read directory * * The filesystem may choose between two modes of operation: * * 1) The readdir implementation ignores the offset parameter, and * passes zero to the filler function's offset. The filler * function will not return '1' (unless an error happens), so the * whole directory is read in a single readdir operation. * * 2) The readdir implementation keeps track of the offsets of the * directory entries. It uses the offset parameter and always * passes non-zero offset to the filler function. When the buffer * is full (or an error happens) the filler function will return * '1'. */ int adafs_readdir(const char* p, void* buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info* fi, enum fuse_readdir_flags flags) { ADAFS_DATA->logger->info("bb_readdir(path=\"{}\", buf={}, offset={}", p, buf, offset); ADAFS_DATA->logger->info("FUSE: adafs_readdir(path=\"{}\", buf={}, offset={}", p, buf, offset); // ADAFS_DATA->logger->info("bb_readdir(path=\"%s\", buf=0x%08x, filler=0x%08x, offset=%lld, fi=0x%08x)", // p, buf, filler, offset, fi); return 0; Loading fs/src/fuse_ops/permission.cpp 0 → 100644 +38 −0 Original line number Diff line number Diff line // // Created by draze on 3/19/17. // #include "../fuse_utils.h" using namespace std; int chk_access(const Metadata& md, const int& mode) { ADAFS_DATA->logger->info("chk_access() enter: md.uid: {}, fusecontextuid: {}", md.uid(), fuse_get_context()->uid); // root user is a god if (fuse_get_context()->uid == 0) return 0; // mode should be unsigned int. Init here. //check user if (md.uid() == fuse_get_context()->uid) { ADAFS_DATA->logger->info("Metadata UID: {}, fuse context uid: {}, mode: {}", md.uid(), fuse_get_context()->uid, mode); // XXX } //check group if (md.gid() == fuse_get_context()->gid) { ADAFS_DATA->logger->info("Metadata GID: {}, fuse context gid: {}, mode: {}", md.uid(), fuse_get_context()->gid, mode); // XXX } //check public ADAFS_DATA->logger->info("mode {}, mdi mode: {}, mdi & mode {}", mode, (int) md.mode(), (mode & md.mode())); if ((mode & (int) md.mode()) == mode) { return 0; } return -EACCES; } fs/src/fuse_utils.h 0 → 100644 +12 −0 Original line number Diff line number Diff line // // Created by draze on 3/19/17. // #ifndef FS_FUSE_UTILS_H #define FS_FUSE_UTILS_H #include "metadata.h" int chk_access(const Metadata& md, const int& mode); #endif //FS_FUSE_UTILS_H Loading
fs/CMakeLists.txt +1 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,6 @@ find_package(FUSE3 REQUIRED) find_package(Boost 1.56.0 COMPONENTS system filesystem serialization) include_directories(${FUSE3_INCLUDE_DIR} include/) set(SOURCE_FILES src/main.cpp src/main.h src/fuse_ops.h src/util.cpp src/metadata.h src/metadata.cpp src/metadata_ops.h src/metadata_ops.cpp src/dentry_ops.cpp src/dentry_ops.h src/configure.h src/fuse_ops/file.cpp src/fuse_ops/directory.cpp) set(SOURCE_FILES src/main.cpp src/main.h src/fuse_ops.h src/util.cpp src/metadata.h src/metadata.cpp src/metadata_ops.h src/metadata_ops.cpp src/dentry_ops.cpp src/dentry_ops.h src/configure.h src/fuse_ops/file.cpp src/fuse_ops/directory.cpp src/fuse_ops/permission.cpp src/fuse_utils.h) add_executable(adafs ${SOURCE_FILES} src/main.cpp) target_link_libraries(adafs ${FUSE3_LIBRARIES} -lpthread -lboost_system -lboost_filesystem -lboost_serialization) No newline at end of file
fs/src/fuse_ops.h +1 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ #define FS_FUSE_OPS_H #include "main.h" #include "fuse_utils.h" // file int adafs_getattr(const char*, struct stat*, struct fuse_file_info*); Loading
fs/src/fuse_ops/directory.cpp +50 −1 Original line number Diff line number Diff line Loading @@ -4,14 +4,63 @@ #include "../main.h" #include "../fuse_ops.h" #include "../metadata.h" #include "../metadata_ops.h" using namespace std; /** Open directory * * Unless the 'default_permissions' mount option is given, * this method should check if opendir is permitted for this * directory. Optionally opendir may also return an arbitrary * filehandle in the fuse_file_info structure, which will be * passed to readdir, closedir and fsyncdir. */ int adafs_opendir(const char* p, struct fuse_file_info* fi) { ADAFS_DATA->logger->info("FUSE: adafs_opendir() enter"s); // XXX error handling auto path = bfs::path(p); auto md = make_shared<Metadata>(); get_metadata(*md, path); int access = fi->flags & O_ACCMODE; // ADAFS_DATA->logger->info("access variable: {}", access); switch (access) { case O_RDONLY: return chk_access(*md, R_OK); case O_WRONLY: return chk_access(*md, W_OK); case O_RDWR: return chk_access(*md, R_OK | W_OK); default: return -EACCES; } return 0; } /** Read directory * * The filesystem may choose between two modes of operation: * * 1) The readdir implementation ignores the offset parameter, and * passes zero to the filler function's offset. The filler * function will not return '1' (unless an error happens), so the * whole directory is read in a single readdir operation. * * 2) The readdir implementation keeps track of the offsets of the * directory entries. It uses the offset parameter and always * passes non-zero offset to the filler function. When the buffer * is full (or an error happens) the filler function will return * '1'. */ int adafs_readdir(const char* p, void* buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info* fi, enum fuse_readdir_flags flags) { ADAFS_DATA->logger->info("bb_readdir(path=\"{}\", buf={}, offset={}", p, buf, offset); ADAFS_DATA->logger->info("FUSE: adafs_readdir(path=\"{}\", buf={}, offset={}", p, buf, offset); // ADAFS_DATA->logger->info("bb_readdir(path=\"%s\", buf=0x%08x, filler=0x%08x, offset=%lld, fi=0x%08x)", // p, buf, filler, offset, fi); return 0; Loading
fs/src/fuse_ops/permission.cpp 0 → 100644 +38 −0 Original line number Diff line number Diff line // // Created by draze on 3/19/17. // #include "../fuse_utils.h" using namespace std; int chk_access(const Metadata& md, const int& mode) { ADAFS_DATA->logger->info("chk_access() enter: md.uid: {}, fusecontextuid: {}", md.uid(), fuse_get_context()->uid); // root user is a god if (fuse_get_context()->uid == 0) return 0; // mode should be unsigned int. Init here. //check user if (md.uid() == fuse_get_context()->uid) { ADAFS_DATA->logger->info("Metadata UID: {}, fuse context uid: {}, mode: {}", md.uid(), fuse_get_context()->uid, mode); // XXX } //check group if (md.gid() == fuse_get_context()->gid) { ADAFS_DATA->logger->info("Metadata GID: {}, fuse context gid: {}, mode: {}", md.uid(), fuse_get_context()->gid, mode); // XXX } //check public ADAFS_DATA->logger->info("mode {}, mdi mode: {}, mdi & mode {}", mode, (int) md.mode(), (mode & md.mode())); if ((mode & (int) md.mode()) == mode) { return 0; } return -EACCES; }
fs/src/fuse_utils.h 0 → 100644 +12 −0 Original line number Diff line number Diff line // // Created by draze on 3/19/17. // #ifndef FS_FUSE_UTILS_H #define FS_FUSE_UTILS_H #include "metadata.h" int chk_access(const Metadata& md, const int& mode); #endif //FS_FUSE_UTILS_H