Skip to content

Commit

Permalink
Merge #433
Browse files Browse the repository at this point in the history
433: Map mounting user's uid/gid by default (Fixes #331) r=townsend2010 a=Saviq



Co-authored-by: Michał Sawicz <[email protected]>
  • Loading branch information
bors[bot] and Saviq committed Oct 5, 2018
2 parents e43fed5 + ac0b3cb commit 3dd85ff
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
6 changes: 6 additions & 0 deletions include/multipass/sshfs_mount/sftp_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@

namespace multipass
{

namespace sftp_server
{
const int default_id = -1;
} // namespace sftp_server

class SSHSession;
class SftpServer
{
Expand Down
7 changes: 7 additions & 0 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@
#include <multipass/cli/json_formatter.h>
#include <multipass/cli/table_formatter.h>
#include <multipass/cli/yaml_formatter.h>
#include <multipass/logging/log.h>
#include <multipass/logging/standard_logger.h>

namespace mp = multipass;
namespace mpl = multipass::logging;

namespace
{
Expand Down Expand Up @@ -138,5 +141,9 @@ int mp::Client::run(const QStringList& arguments)
{
return parser.returnCodeFrom(parse_status);
}

auto logger = std::make_shared<mpl::StandardLogger>(mpl::level_from(parser.verbosityLevel()));
mpl::set_logger(logger);

return parser.chosenCommand()->run(&parser);
}
24 changes: 24 additions & 0 deletions src/client/cmd/mount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,25 @@
#include "exec.h"

#include <multipass/cli/argparser.h>
#include <multipass/logging/log.h>
#include <multipass/sshfs_mount/sftp_server.h>

#include <fmt/format.h>
#include <unistd.h>

#include <QDir>
#include <QFileInfo>

namespace mp = multipass;
namespace mpl = multipass::logging;
namespace cmd = multipass::cmd;
using RpcMethod = mp::Rpc::Stub;

namespace
{
constexpr auto category = "mount cmd";
} // namespace

mp::ReturnCode cmd::Mount::run(mp::ArgParser* parser)
{
auto ret = parse_args(parser);
Expand Down Expand Up @@ -191,6 +202,19 @@ mp::ParseCode cmd::Mount::parse_args(mp::ArgParser* parser)
}
}

if (!parser->isSet(uid_map) && !parser->isSet(gid_map))
{
mpl::log(mpl::Level::debug, category,
fmt::format("{}:{} {}(): adding default uid/gid mapping", __FILE__, __LINE__, __FUNCTION__));
auto uid_entry = request.add_uid_maps();
uid_entry->set_host_uid(getuid());
uid_entry->set_instance_uid(mp::sftp_server::default_id);

auto gid_entry = request.add_gid_maps();
gid_entry->set_host_gid(getgid());
gid_entry->set_instance_gid(mp::sftp_server::default_id);
}

return ParseCode::Ok;
}

Expand Down
14 changes: 12 additions & 2 deletions src/sshfs_mount/sftp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,12 @@ int mp::SftpServer::mapped_uid_for(const int uid)

auto map = uid_map.find(uid);
if (map != uid_map.end())
return map->second;
{
if (map->second == mp::sftp_server::default_id)
return default_uid;
else
return map->second;
}

return uid;
}
Expand All @@ -285,7 +290,12 @@ int mp::SftpServer::mapped_gid_for(const int gid)

auto map = gid_map.find(gid);
if (map != gid_map.end())
return map->second;
{
if (map->second == mp::sftp_server::default_id)
return default_gid;
else
return map->second;
}

return gid;
}
Expand Down

0 comments on commit 3dd85ff

Please sign in to comment.