From 1cd8302a4ba6e4553738a1547de37af12a6aa35f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 6 Sep 2020 00:17:45 +0100 Subject: Add the HideUnknown mapper This mapper hides inodes for which the user and/or group cannot be mapped to local entries --- netfs/fuse/Jamfile.jam | 23 ++++++++++++++++------- netfs/fuse/fuseApp.cpp | 12 ++++++++++++ netfs/fuse/fuseMappers.ice | 12 ++++++++++++ netfs/fuse/fuseMappersImpl.cpp | 36 ++++++++++++++++++++++++++++++++++++ netfs/fuse/fuseMappersImpl.h | 25 +++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 netfs/fuse/fuseMappers.ice create mode 100644 netfs/fuse/fuseMappersImpl.cpp create mode 100644 netfs/fuse/fuseMappersImpl.h diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam index d700c37..4d000be 100644 --- a/netfs/fuse/Jamfile.jam +++ b/netfs/fuse/Jamfile.jam @@ -3,20 +3,29 @@ import package ; lib Glacier2 : : Glacier2++11 ; constant FUSE_VER : 35 ; -obj fuseConfig : fuseConfig.ice : - tidy:none - ../ice//netfs-api - ../ice//netfs-api - ..//slicer - . -; +rule iceobj ( name : ice ) { + obj $(name) : $(ice) : + tidy:none + ../ice//netfs-api + ../ice//netfs-api + ..//slicer + . + ; +} +iceobj fuseConfig : fuseConfig.ice ; +iceobj fuseMappers : fuseMappers.ice ; + lib netfs-client-configuration : fuseConfig + fuseMappers fuseConfig.ice + fuseMappers.ice fuseConfigImpl.cpp + fuseMappersImpl.cpp : pure ../ice//netfs-api + ../lib//netfs-common ../ice//netfs-api fuseConfig ..//Ice diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index f0576b3..ff1585a 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -2,6 +2,7 @@ #include "cache.impl.h" #include "fuseDirs.h" #include "fuseFiles.h" +#include "fuseMappersImpl.h" #include "lockHelpers.h" #include #include @@ -111,7 +112,18 @@ NetFS::FuseApp::configureFromUri(const std::string & uriString) setting = boost::lexical_cast>(p->second); } }; + auto setWith = [&uri](const auto & param, auto & setting, auto && f) { + if (auto p = uri.query.find(param); p != uri.query.end()) { + setting = f(p->second); + } + }; set("async", r->Async); + setWith("mapper", r->mapper, [](auto && m) -> NetFS::Mapping::MapperPtr { + if (m == "hide") { + return std::make_shared(); + } + return {}; + }); return r; } diff --git a/netfs/fuse/fuseMappers.ice b/netfs/fuse/fuseMappers.ice new file mode 100644 index 0000000..6945eec --- /dev/null +++ b/netfs/fuse/fuseMappers.ice @@ -0,0 +1,12 @@ +#include + +["slicer:include:fuseMappersImpl.h"] +module NetFS { + module Client { + ["slicer:implementation:NetFS.Client.HideUnknownMapperImpl"] + local class HideUnknownMapper extends Mapping::Mapper { + + }; + }; +}; + diff --git a/netfs/fuse/fuseMappersImpl.cpp b/netfs/fuse/fuseMappersImpl.cpp new file mode 100644 index 0000000..9a99eca --- /dev/null +++ b/netfs/fuse/fuseMappersImpl.cpp @@ -0,0 +1,36 @@ +#include "fuseMappersImpl.h" +#include + +namespace NetFS::Client { + HideUnknownMapperImpl::HideUnknownMapperImpl() : + HideUnknownMapperImpl(std::make_shared>(), std::make_shared>()) + { + } + + HideUnknownMapperImpl::HideUnknownMapperImpl(EntryResolverPtr u, EntryResolverPtr g) : + users(std::move(u)), groups(std::move(g)) + { + } + + Mapping::FileSystem + HideUnknownMapperImpl::mapTransport(const std::string & un, const std::string & gn) + { + auto u = users->getEntry(un); + auto g = groups->getEntry(gn); + if (!u || !g) { + return {0, 0, 0xFFFFFFF}; + } + return {static_cast(u->id), static_cast(g->id), 0}; + } + + Mapping::Transport + HideUnknownMapperImpl::mapFileSystem(int uid, int gid) + { + auto u = users->getEntry(uid); + auto g = groups->getEntry(gid); + if (!u || !g) { + throw NetFS::SystemError(EPERM); + } + return {u->name, g->name, 0}; + } +} diff --git a/netfs/fuse/fuseMappersImpl.h b/netfs/fuse/fuseMappersImpl.h new file mode 100644 index 0000000..4b0677f --- /dev/null +++ b/netfs/fuse/fuseMappersImpl.h @@ -0,0 +1,25 @@ +#ifndef NETFS_MAPPING_CLIENTIMPL_H +#define NETFS_MAPPING_CLIENTIMPL_H + +#include "entries.h" +#include "entryResolver.h" +#include + +namespace NetFS { + namespace Client { + class HideUnknownMapperImpl : public HideUnknownMapper { + public: + HideUnknownMapperImpl(); + HideUnknownMapperImpl(EntryResolverPtr u, EntryResolverPtr g); + + Mapping::Transport mapFileSystem(int uid, int gid) override; + Mapping::FileSystem mapTransport(const std::string & un, const std::string & gn) override; + + protected: + EntryResolverPtr users; + EntryResolverPtr groups; + }; + } +} + +#endif -- cgit v1.2.3