From 015916c14997b355d63a7189380fe89ae9bbe3bd Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 20 Sep 2020 20:01:05 +0100 Subject: Support for configuring new mappers in fuse client --- netfs/fuse/fuseApp.cpp | 16 +++++++++--- netfs/fuse/fuseConfig.ice | 3 ++- netfs/fuse/fuseMappers.ice | 12 ++++++--- netfs/fuse/fuseMappersImpl.cpp | 18 ++++++++++++-- netfs/fuse/fuseMappersImpl.h | 3 +++ netfs/ice/mapper.ice | 1 + netfs/unittests/Jamfile.jam | 2 ++ netfs/unittests/defaultFuseHide.xml | 15 ++++++++++++ netfs/unittests/defaultFuseMask.xml | 20 +++++++++++++++ netfs/unittests/testFuse.cpp | 49 +++++++++++++++++++++++++++++++++++++ 10 files changed, 128 insertions(+), 11 deletions(-) create mode 100644 netfs/unittests/defaultFuseHide.xml create mode 100644 netfs/unittests/defaultFuseMask.xml diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index ff1585a..04602aa 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -79,11 +79,11 @@ NetFS::FuseApp::init(struct fuse_conn_info *, struct fuse_config *) fcr = configureFromFile(arg.substr(0, colon), arg.substr(colon + 1)); } } - if (!fcr->mapper) { - fcr->mapper = std::make_shared(); + if (!fcr->Mapper) { + fcr->Mapper = std::make_shared(); } BOOST_ASSERT(fcr); - converter.mapper = fcr->mapper; + converter.mapper = fcr->Mapper; return this; } @@ -118,10 +118,18 @@ NetFS::FuseApp::configureFromUri(const std::string & uriString) } }; set("async", r->Async); - setWith("mapper", r->mapper, [](auto && m) -> NetFS::Mapping::MapperPtr { + setWith("mapper", r->Mapper, [&set, &setWith](auto && m) -> NetFS::Mapping::MapperPtr { if (m == "hide") { return std::make_shared(); } + else if (m == "mask") { + auto mi = std::make_shared(); + set("mapper.unknownuser", mi->UnknownUser); + set("mapper.unknowngroup", mi->UnknownGroup); + setWith("mapper.usermask", mi->UserMask, Client::from_octal); + setWith("mapper.groupmask", mi->GroupMask, Client::from_octal); + return mi; + } return {}; }); return r; diff --git a/netfs/fuse/fuseConfig.ice b/netfs/fuse/fuseConfig.ice index 2d2bf9f..ea489ac 100644 --- a/netfs/fuse/fuseConfig.ice +++ b/netfs/fuse/fuseConfig.ice @@ -22,7 +22,8 @@ module NetFS { ["slicer:name:async"] bool Async = false; - Mapping::Mapper mapper; + ["slicer:name:mapper"] + Mapping::Mapper Mapper; }; ["slicer:key:name","slicer:value:resource","slicer:item:resource"] diff --git a/netfs/fuse/fuseMappers.ice b/netfs/fuse/fuseMappers.ice index 582aa16..0eb5ea5 100644 --- a/netfs/fuse/fuseMappers.ice +++ b/netfs/fuse/fuseMappers.ice @@ -3,16 +3,20 @@ ["slicer:include:fuseMappersImpl.h"] module NetFS { module Client { - ["slicer:implementation:NetFS.Client.HideUnknownMapperImpl"] + ["slicer:implementation:NetFS.Client.HideUnknownMapperImpl","slicer:typename:hide"] local class HideUnknownMapper extends Mapping::Mapper { }; - ["slicer:implementation:NetFS.Client.MaskUnknownMapperImpl"] + ["slicer:implementation:NetFS.Client.MaskUnknownMapperImpl","slicer:typename:mask"] local class MaskUnknownMapper extends Mapping::Mapper { + ["slicer:name:unknownuser"] string UnknownUser = "nobody"; + ["slicer:name:unknowngroup"] string UnknownGroup = "nogroup"; - int MaskUser = 0700; - int MaskGroup = 0070; + ["slicer:name:usermask","slicer:conversion:std.string:NetFS.Client.from_octal:NetFS.Client.to_octal:nodeclare"] + int UserMask = 0700; + ["slicer:name:groupmask","slicer:conversion:std.string:NetFS.Client.from_octal:NetFS.Client.to_octal:nodeclare"] + int GroupMask = 0070; }; }; }; diff --git a/netfs/fuse/fuseMappersImpl.cpp b/netfs/fuse/fuseMappersImpl.cpp index 5bde752..c7fef9e 100644 --- a/netfs/fuse/fuseMappersImpl.cpp +++ b/netfs/fuse/fuseMappersImpl.cpp @@ -42,8 +42,8 @@ namespace NetFS::Client { } return e; }; - auto u = apply(users, un, UnknownUser, MaskUser); - auto g = apply(groups, gn, UnknownGroup, MaskGroup); + auto u = apply(users, un, UnknownUser, UserMask); + auto g = apply(groups, gn, UnknownGroup, GroupMask); return {static_cast(u->id), static_cast(g->id), mask}; } @@ -57,4 +57,18 @@ namespace NetFS::Client { } return {u->name, g->name, 0}; } + + Ice::Int + from_octal(const std::string & in) + { + return std::stoi(in, nullptr, 8); + } + + std::string + to_octal(const Ice::Int & in) + { + std::stringstream s; + s << std::oct << in; + return s.str(); + } } diff --git a/netfs/fuse/fuseMappersImpl.h b/netfs/fuse/fuseMappersImpl.h index 2bcf579..fd9e2aa 100644 --- a/netfs/fuse/fuseMappersImpl.h +++ b/netfs/fuse/fuseMappersImpl.h @@ -9,6 +9,9 @@ namespace NetFS { namespace Client { + std::string to_octal(const Ice::Int &); + Ice::Int from_octal(const std::string &); + class DLL_PUBLIC HideUnknownMapperImpl : public HideUnknownMapper, Mapping::BaseMapper { public: using BaseMapper::BaseMapper; diff --git a/netfs/ice/mapper.ice b/netfs/ice/mapper.ice index d2f31e8..505b53a 100644 --- a/netfs/ice/mapper.ice +++ b/netfs/ice/mapper.ice @@ -19,6 +19,7 @@ module NetFS { int mask; }; + ["slicer:typename:default","slicer:typeid:type"] local class Mapper { Transport mapFileSystem(int uid, int gid) throws SystemError; FileSystem mapTransport(string un, string gn) throws SystemError; diff --git a/netfs/unittests/Jamfile.jam b/netfs/unittests/Jamfile.jam index 18abadd..8d9efc3 100644 --- a/netfs/unittests/Jamfile.jam +++ b/netfs/unittests/Jamfile.jam @@ -77,6 +77,8 @@ run testLib.cpp run testFuse.cpp : -- : defaultDaemon.xml + defaultFuseHide.xml + defaultFuseMask.xml : BOOST_TEST_DYN_LINK boost_utf diff --git a/netfs/unittests/defaultFuseHide.xml b/netfs/unittests/defaultFuseHide.xml new file mode 100644 index 0000000..098a597 --- /dev/null +++ b/netfs/unittests/defaultFuseHide.xml @@ -0,0 +1,15 @@ + + + + + testvol + + testvol + + overridden + + + + + + diff --git a/netfs/unittests/defaultFuseMask.xml b/netfs/unittests/defaultFuseMask.xml new file mode 100644 index 0000000..5d45a53 --- /dev/null +++ b/netfs/unittests/defaultFuseMask.xml @@ -0,0 +1,20 @@ + + + + + testvol + + testvol + + overridden + + + uu + ug + 0100 + 0010 + + + + + diff --git a/netfs/unittests/testFuse.cpp b/netfs/unittests/testFuse.cpp index ded7077..0ad9335 100644 --- a/netfs/unittests/testFuse.cpp +++ b/netfs/unittests/testFuse.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -152,3 +153,51 @@ BOOST_AUTO_TEST_CASE(url_params_2) auto fcs = NetFS::FuseApp::configureFromUri("tcp://localhost/foo?0&async=0"); BOOST_CHECK_EQUAL(fcs->Async, false); } + +BOOST_AUTO_TEST_CASE(url_params_hide) +{ + auto fcs = NetFS::FuseApp::configureFromUri("tcp://localhost/foo?mapper=hide"); + BOOST_REQUIRE(fcs->Mapper); + BOOST_REQUIRE(std::dynamic_pointer_cast(fcs->Mapper)); +} + +BOOST_AUTO_TEST_CASE(url_params_mask_default) +{ + auto fcs = NetFS::FuseApp::configureFromUri("tcp://localhost/foo?mapper=mask"); + BOOST_REQUIRE(fcs->Mapper); + auto mapper = std::dynamic_pointer_cast(fcs->Mapper); + BOOST_REQUIRE(mapper); +} + +BOOST_AUTO_TEST_CASE(url_params_mask_nondefault) +{ + auto fcs = NetFS::FuseApp::configureFromUri( + "tcp://localhost/" + "foo?mapper=mask&mapper.unknownuser=uu&mapper.unknowngroup=ug&mapper.usermask=0100&mapper.groupmask=0010"); + BOOST_REQUIRE(fcs->Mapper); + auto mapper = std::dynamic_pointer_cast(fcs->Mapper); + BOOST_REQUIRE(mapper); + BOOST_CHECK_EQUAL(mapper->UnknownUser, "uu"); + BOOST_CHECK_EQUAL(mapper->UnknownGroup, "ug"); + BOOST_CHECK_EQUAL(mapper->UserMask, 0100); + BOOST_CHECK_EQUAL(mapper->GroupMask, 0010); +} + +BOOST_AUTO_TEST_CASE(config_file_hide) +{ + auto fcs = NetFS::FuseApp::configureFromFile(rootDir / "defaultFuseHide.xml", "testvol"); + BOOST_REQUIRE(fcs->Mapper); + BOOST_REQUIRE(std::dynamic_pointer_cast(fcs->Mapper)); +} + +BOOST_AUTO_TEST_CASE(config_file_mask) +{ + auto fcs = NetFS::FuseApp::configureFromFile(rootDir / "defaultFuseMask.xml", "testvol"); + BOOST_REQUIRE(fcs->Mapper); + auto mapper = std::dynamic_pointer_cast(fcs->Mapper); + BOOST_REQUIRE(mapper); + BOOST_CHECK_EQUAL(mapper->UnknownUser, "uu"); + BOOST_CHECK_EQUAL(mapper->UnknownGroup, "ug"); + BOOST_CHECK_EQUAL(mapper->UserMask, 0100); + BOOST_CHECK_EQUAL(mapper->GroupMask, 0010); +} -- cgit v1.2.3