From 4d9b633c79ca86140af90c92b7a732dc0bbbe2bd Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 2 Sep 2020 00:12:06 +0100 Subject: Tidy up of previous commit of extensible mapper --- Jamroot.jam | 4 ++-- netfs/daemon/daemonService.cpp | 7 ++++++- netfs/daemon/daemonService.h | 7 ++++--- netfs/daemon/daemonVolume.cpp | 7 ++++--- netfs/daemon/daemonVolume.h | 9 +++++---- netfs/daemon/modeCheck.cpp | 5 ++--- netfs/daemon/modeCheck.h | 10 ++++++---- netfs/fuse/fuseApp.impl.h | 3 +-- netfs/ice/typeConverter.cpp | 4 ++-- netfs/lib/defaultMapper.cpp | 19 +++++++++++++++---- netfs/lib/defaultMapper.h | 10 +++++++--- netfs/lib/entCache.cpp | 6 +----- netfs/lib/entCache.h | 25 ------------------------- netfs/lib/entCache.impl.h | 11 +---------- netfs/lib/entries.cpp | 16 ++++++++++++++++ netfs/lib/entries.h | 27 +++++++++++++++++++++++++++ netfs/lib/entryResolver.h | 7 +++++-- 17 files changed, 104 insertions(+), 73 deletions(-) create mode 100644 netfs/lib/entries.cpp create mode 100644 netfs/lib/entries.h diff --git a/Jamroot.jam b/Jamroot.jam index 368a244..af15ca5 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -14,8 +14,7 @@ project 17 hidden "-Wl,-z,defs,--warn-once,--gc-sections" - release:"-flto=3" - release:"-flto=3" + release:on debuggcc:-Wlogical-op debug:extra debug:on @@ -36,6 +35,7 @@ project tidy:slicer-daemonConfig.cpp tidy:fuseConfig.h tidy:slicer-fuseConfig.cpp + tidy:slicer-mapper.cpp tidy:directory.h tidy:exceptions.h tidy:file.h diff --git a/netfs/daemon/daemonService.cpp b/netfs/daemon/daemonService.cpp index 18b050d..6ffcf71 100644 --- a/netfs/daemon/daemonService.cpp +++ b/netfs/daemon/daemonService.cpp @@ -1,9 +1,14 @@ #include "daemonService.h" #include "daemon.h" #include "daemonVolume.h" +#include #include -ServiceServer::ServiceServer(NetFS::Daemon::ConfigurationPtr c) : config(std::move(c)) { } +ServiceServer::ServiceServer(NetFS::Daemon::ConfigurationPtr c) : + userLookup(std::make_shared>()), groupLookup(std::make_shared>()), + config(std::move(c)) +{ +} NetFS::VolumePrxPtr ServiceServer::connect(const std::string share, const std::string authtoken, const Ice::Current & ice) diff --git a/netfs/daemon/daemonService.h b/netfs/daemon/daemonService.h index e0f80ef..753583e 100644 --- a/netfs/daemon/daemonService.h +++ b/netfs/daemon/daemonService.h @@ -2,7 +2,8 @@ #define DAEMONSERVICE_H #include -#include +#include +#include #include class ServiceServer : public NetFS::Service { @@ -12,8 +13,8 @@ public: NetFS::VolumePrxPtr connect(const std::string share, const std::string auth, const Ice::Current &) override; private: - EntCache userLookup; - EntCache groupLookup; + EntryResolverPtr userLookup; + EntryResolverPtr groupLookup; NetFS::Daemon::ConfigurationPtr config; }; diff --git a/netfs/daemon/daemonVolume.cpp b/netfs/daemon/daemonVolume.cpp index 7ae3a1f..ff75e06 100644 --- a/netfs/daemon/daemonVolume.cpp +++ b/netfs/daemon/daemonVolume.cpp @@ -16,9 +16,10 @@ extern std::map files; -VolumeServer::VolumeServer(const std::filesystem::path & r, const EntCache & u, const EntCache & g) : - root(std::filesystem::canonical(r)), userLookup(u), groupLookup(g), - converter(std::make_shared()) +VolumeServer::VolumeServer( + const std::filesystem::path & r, const EntryResolverPtr & u, const EntryResolverPtr & g) : + root(std::filesystem::canonical(r)), + userLookup(*u), groupLookup(*g), converter(std::make_shared(u, g)) { } diff --git a/netfs/daemon/daemonVolume.h b/netfs/daemon/daemonVolume.h index b75c5d6..649d8c2 100644 --- a/netfs/daemon/daemonVolume.h +++ b/netfs/daemon/daemonVolume.h @@ -1,7 +1,8 @@ #ifndef DAEMONVOLUME_H #define DAEMONVOLUME_H -#include +#include +#include #include #include #include @@ -9,7 +10,7 @@ class VolumeServer : public NetFS::Volume { public: - VolumeServer(const std::filesystem::path & root, const EntCache &, const EntCache &); + VolumeServer(const std::filesystem::path & root, const EntryResolverPtr &, const EntryResolverPtr &); NetFS::DirectoryPrxPtr opendir(const NetFS::ReqEnv, std::string path, const Ice::Current &) override; @@ -47,8 +48,8 @@ protected: private: const std::filesystem::path root; - const EntCache & userLookup; - const EntCache & groupLookup; + EntryResolver & userLookup; + EntryResolver & groupLookup; EntryTypeConverter converter; }; diff --git a/netfs/daemon/modeCheck.cpp b/netfs/daemon/modeCheck.cpp index 6e65888..177d9b8 100644 --- a/netfs/daemon/modeCheck.cpp +++ b/netfs/daemon/modeCheck.cpp @@ -1,9 +1,8 @@ #include "modeCheck.h" -#include #include -ModeCheck::ModeCheck(const NetFS::ReqEnv & re, const std::filesystem::path & r, const EntCache & u, - const EntCache & g) : +ModeCheck::ModeCheck(const NetFS::ReqEnv & re, const std::filesystem::path & r, const EntryResolver & u, + const EntryResolver & g) : myu(u.getEntry(re.user)->id), myg(g.getEntry(re.grp)->id), root(r), userLookup(u), groupLookup(g) { diff --git a/netfs/daemon/modeCheck.h b/netfs/daemon/modeCheck.h index 693ad8d..6365816 100644 --- a/netfs/daemon/modeCheck.h +++ b/netfs/daemon/modeCheck.h @@ -1,14 +1,16 @@ #ifndef NETFS_DAEMON_IOHELPERS #define NETFS_DAEMON_IOHELPERS -#include +#include +#include #include #include #include class ModeCheck { public: - ModeCheck(const NetFS::ReqEnv & re, const std::filesystem::path &, const EntCache &, const EntCache &); + ModeCheck(const NetFS::ReqEnv & re, const std::filesystem::path &, const EntryResolver &, + const EntryResolver &); void AssertReadParent(const std::filesystem::path &) const; void AssertRead(const std::filesystem::path &) const; @@ -27,8 +29,8 @@ public: private: static struct stat lstat(const std::filesystem::path &); - const EntCache & userLookup; - const EntCache & groupLookup; + const EntryResolver & userLookup; + const EntryResolver & groupLookup; }; #endif diff --git a/netfs/fuse/fuseApp.impl.h b/netfs/fuse/fuseApp.impl.h index e433ee7..9947f36 100644 --- a/netfs/fuse/fuseApp.impl.h +++ b/netfs/fuse/fuseApp.impl.h @@ -12,8 +12,7 @@ namespace NetFS { { auto & map = getMap(); Lock(_proxymaplock); - while (map.find(fh = ++openHandleId) != map.end()) - ; + while (map.find(fh = ++openHandleId) != map.end()) { } map.emplace(fh, std::make_shared(params...)); } diff --git a/netfs/ice/typeConverter.cpp b/netfs/ice/typeConverter.cpp index 6b33828..b1ade2b 100644 --- a/netfs/ice/typeConverter.cpp +++ b/netfs/ice/typeConverter.cpp @@ -1,7 +1,7 @@ #include "typeConverter.h" #include -EntryTypeConverter::EntryTypeConverter(NetFS::Mapping::MapperPtr m) : mapper(m) { } +EntryTypeConverter::EntryTypeConverter(NetFS::Mapping::MapperPtr m) : mapper(std::move(m)) { } // Wrapper function to assure no unexpected corruption occurs // during narrowing assignments. @@ -67,7 +67,7 @@ EntryTypeConverter::convert(const struct stat & s) const NetFS::Attr a {}; a.dev = s.st_dev; a.inode = s.st_ino; - a.mode = s.st_mode & ~map.mask; + safeAssign(a.mode, s.st_mode & ~map.mask); a.links = s.st_nlink; a.uid = std::move(map.username); a.gid = std::move(map.groupname); diff --git a/netfs/lib/defaultMapper.cpp b/netfs/lib/defaultMapper.cpp index 1d75e12..27b20d3 100644 --- a/netfs/lib/defaultMapper.cpp +++ b/netfs/lib/defaultMapper.cpp @@ -1,12 +1,23 @@ #include "defaultMapper.h" +#include "entCache.h" #include namespace NetFS::Mapping { + DefaultMapper::DefaultMapper() : + DefaultMapper(std::make_shared>(), std::make_shared>()) + { + } + + DefaultMapper::DefaultMapper(EntryResolverPtr u, EntryResolverPtr g) : + users(std::move(u)), groups(std::move(g)) + { + } + FileSystem DefaultMapper::mapTransport(const std::string & un, const std::string & gn) { - auto u = users.getEntry(un); - auto g = groups.getEntry(gn); + auto u = users->getEntry(un); + auto g = groups->getEntry(gn); if (!u || !g) { throw NetFS::SystemError(EPERM); } @@ -16,8 +27,8 @@ namespace NetFS::Mapping { Transport DefaultMapper::mapFileSystem(int uid, int gid) { - auto u = users.getEntry(uid); - auto g = groups.getEntry(gid); + auto u = users->getEntry(uid); + auto g = groups->getEntry(gid); if (!u || !g) { throw NetFS::SystemError(EPERM); } diff --git a/netfs/lib/defaultMapper.h b/netfs/lib/defaultMapper.h index 719c7bf..214f9ed 100644 --- a/netfs/lib/defaultMapper.h +++ b/netfs/lib/defaultMapper.h @@ -1,19 +1,23 @@ #ifndef NETFS_MAPPING_DEFAULTIMPL_H #define NETFS_MAPPING_DEFAULTIMPL_H -#include "entCache.h" +#include "entries.h" +#include "entryResolver.h" #include namespace NetFS { namespace Mapping { class DefaultMapper : public Mapper { public: + DefaultMapper(); + DefaultMapper(EntryResolverPtr users, EntryResolverPtr groups); + Transport mapFileSystem(int uid, int gid) override; FileSystem mapTransport(const std::string & un, const std::string & gn) override; protected: - UserEntCache users; - GroupEntCache groups; + EntryResolverPtr users; + EntryResolverPtr groups; }; } } diff --git a/netfs/lib/entCache.cpp b/netfs/lib/entCache.cpp index d9f61df..e1a20a5 100644 --- a/netfs/lib/entCache.cpp +++ b/netfs/lib/entCache.cpp @@ -1,9 +1,5 @@ #include "entCache.impl.h" - -static_assert(std::is_nothrow_move_constructible_v); -static_assert(std::is_nothrow_move_assignable_v); -static_assert(std::is_nothrow_move_constructible_v); -static_assert(std::is_nothrow_move_assignable_v); +#include "entries.h" template class EntCache; template class EntCache; diff --git a/netfs/lib/entCache.h b/netfs/lib/entCache.h index 02224f5..7a9a3ef 100644 --- a/netfs/lib/entCache.h +++ b/netfs/lib/entCache.h @@ -3,29 +3,7 @@ #include "entryResolver.h" #include -#include #include -#include -#include - -class User { -public: - User(uid_t, std::string, gid_t); - uid_t id; - std::string name; - gid_t group; -}; - -class Group { -public: - Group(gid_t, std::string); - - bool hasMember(uid_t) const; - - gid_t id; - std::string name; - std::set members; -}; template class EntCache : public EntryResolver { public: @@ -58,7 +36,4 @@ protected: mutable time_t fillTime {0}; }; -using UserEntCache = EntCache; -using GroupEntCache = EntCache; - #endif diff --git a/netfs/lib/entCache.impl.h b/netfs/lib/entCache.impl.h index 6243d7d..ad8fb33 100644 --- a/netfs/lib/entCache.impl.h +++ b/netfs/lib/entCache.impl.h @@ -2,6 +2,7 @@ #define ENTCACHE_IMPL_H #include "entCache.h" +#include "entries.h" #include #include #include @@ -50,8 +51,6 @@ EntCache::getEntryNoFill(const key_t & key) const noexcept return nullptr; } -User::User(uid_t u, std::string n, gid_t g) : id(u), name(std::move(n)), group(g) { } - const int BUFLEN = 8196; template<> @@ -71,8 +70,6 @@ EntCache::fillCache() const noexcept time(&fillTime); } -Group::Group(gid_t g, std::string n) : id(g), name(std::move(n)) { } - template<> void EntCache::fillCache() const noexcept @@ -97,10 +94,4 @@ EntCache::fillCache() const noexcept time(&fillTime); } -bool -Group::hasMember(uid_t u) const -{ - return (members.find(u) != members.end()); -} - #endif diff --git a/netfs/lib/entries.cpp b/netfs/lib/entries.cpp new file mode 100644 index 0000000..bde15e6 --- /dev/null +++ b/netfs/lib/entries.cpp @@ -0,0 +1,16 @@ +#include "entries.h" + +static_assert(std::is_nothrow_move_constructible_v); +static_assert(std::is_nothrow_move_assignable_v); +static_assert(std::is_nothrow_move_constructible_v); +static_assert(std::is_nothrow_move_assignable_v); + +User::User(uid_t u, std::string n, gid_t g) : id(u), name(std::move(n)), group(g) { } + +Group::Group(gid_t g, std::string n) : id(g), name(std::move(n)) { } + +bool +Group::hasMember(uid_t u) const noexcept +{ + return (members.find(u) != members.end()); +} diff --git a/netfs/lib/entries.h b/netfs/lib/entries.h new file mode 100644 index 0000000..6e032e1 --- /dev/null +++ b/netfs/lib/entries.h @@ -0,0 +1,27 @@ +#ifndef ENTRIES_H +#define ENTRIES_H + +#include +#include +#include + +class User { +public: + User(uid_t, std::string, gid_t); + uid_t id; + std::string name; + gid_t group; +}; + +class Group { +public: + Group(gid_t, std::string); + + bool hasMember(uid_t) const noexcept; + + gid_t id; + std::string name; + std::set members; +}; + +#endif diff --git a/netfs/lib/entryResolver.h b/netfs/lib/entryResolver.h index 84eb6ed..86aaace 100644 --- a/netfs/lib/entryResolver.h +++ b/netfs/lib/entryResolver.h @@ -6,9 +6,12 @@ template class EntryResolver { public: virtual ~EntryResolver() noexcept = default; + using EntryPtr = std::shared_ptr; - virtual std::shared_ptr getEntry(const decltype(entry_t::id) &) const noexcept = 0; - virtual std::shared_ptr getEntry(const decltype(entry_t::name) &) const noexcept = 0; + virtual EntryPtr getEntry(const decltype(entry_t::id) &) const noexcept = 0; + virtual EntryPtr getEntry(const decltype(entry_t::name) &) const noexcept = 0; }; +template using EntryResolverPtr = std::shared_ptr>; + #endif -- cgit v1.2.3