summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--netfs/fuse/fuseApp.cpp16
-rw-r--r--netfs/fuse/fuseConfig.ice3
-rw-r--r--netfs/fuse/fuseMappers.ice12
-rw-r--r--netfs/fuse/fuseMappersImpl.cpp18
-rw-r--r--netfs/fuse/fuseMappersImpl.h3
-rw-r--r--netfs/ice/mapper.ice1
-rw-r--r--netfs/unittests/Jamfile.jam2
-rw-r--r--netfs/unittests/defaultFuseHide.xml15
-rw-r--r--netfs/unittests/defaultFuseMask.xml20
-rw-r--r--netfs/unittests/testFuse.cpp49
10 files changed, 128 insertions, 11 deletions
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<Mapping::DefaultMapper>();
+ if (!fcr->Mapper) {
+ fcr->Mapper = std::make_shared<Mapping::DefaultMapper>();
}
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<NetFS::Client::HideUnknownMapperImpl>();
}
+ else if (m == "mask") {
+ auto mi = std::make_shared<NetFS::Client::MaskUnknownMapperImpl>();
+ 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<int>(u->id), static_cast<int>(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
:
<define>BOOST_TEST_DYN_LINK
<library>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 @@
+<?xml version="1.0" encoding="ascii"?>
+<config>
+ <resources>
+ <resource>
+ <name>testvol</name>
+ <resource>
+ <export>testvol</export>
+ <endpoints>
+ <endpoint>overridden</endpoint>
+ </endpoints>
+ <mapper type="hide"/>
+ </resource>
+ </resource>
+ </resources>
+</config>
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 @@
+<?xml version="1.0" encoding="ascii"?>
+<config>
+ <resources>
+ <resource>
+ <name>testvol</name>
+ <resource>
+ <export>testvol</export>
+ <endpoints>
+ <endpoint>overridden</endpoint>
+ </endpoints>
+ <mapper type="mask">
+ <unknownuser>uu</unknownuser>
+ <unknowngroup>ug</unknowngroup>
+ <usermask>0100</usermask>
+ <groupmask>0010</groupmask>
+ </mapper>
+ </resource>
+ </resource>
+ </resources>
+</config>
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 <filesystem>
#include <fuse.h>
#include <fuseApp.h>
+#include <fuseMappersImpl.h>
#include <ostream>
#include <thread>
@@ -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<NetFS::Client::HideUnknownMapperImpl>(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<NetFS::Client::MaskUnknownMapperImpl>(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<NetFS::Client::MaskUnknownMapperImpl>(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<NetFS::Client::HideUnknownMapperImpl>(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<NetFS::Client::MaskUnknownMapperImpl>(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);
+}