aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Benedikt Morbach <moben@exherbo.org> 2018-04-09 17:31:55 +0200
committerAvatar Benedikt Morbach <moben@exherbo.org> 2018-04-09 19:39:10 +0200
commit917cc160a14ee45801ff227f5678854dc4c0c06e (patch)
tree129559555b7232076862efa38015ab256ac16b15
parent589fe420875f39119e1d3d8eff9eb0ac0889816b (diff)
downloadpaludis-917cc160a14ee45801ff227f5678854dc4c0c06e.tar.gz
paludis-917cc160a14ee45801ff227f5678854dc4c0c06e.tar.xz
add reduced_username() to Environment
-rw-r--r--paludis/environment.hh5
-rw-r--r--paludis/environments/paludis/paludis_environment.cc10
-rw-r--r--paludis/environments/paludis/paludis_environment.hh3
-rw-r--r--paludis/environments/portage/portage_environment.hh3
-rw-r--r--paludis/environments/test/test_environment.cc6
-rw-r--r--paludis/environments/test/test_environment.hh2
6 files changed, 28 insertions, 1 deletions
diff --git a/paludis/environment.hh b/paludis/environment.hh
index 494e9fd..fafd477 100644
--- a/paludis/environment.hh
+++ b/paludis/environment.hh
@@ -422,6 +422,11 @@ namespace paludis
PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
/**
+ * User name to use when reduced privs are permissible.
+ */
+ virtual std::string reduced_username() const = 0;
+
+ /**
* User id to use when reduced privs are permissible.
*/
virtual uid_t reduced_uid() const = 0;
diff --git a/paludis/environments/paludis/paludis_environment.cc b/paludis/environments/paludis/paludis_environment.cc
index bbb1628..1667c9c 100644
--- a/paludis/environments/paludis/paludis_environment.cc
+++ b/paludis/environments/paludis/paludis_environment.cc
@@ -294,6 +294,16 @@ PaludisEnvironment::mirrors(const std::string & m) const
return _imp->config->mirrors_conf()->query(m);
}
+std::string
+PaludisEnvironment::reduced_username() const
+{
+ uid_t u(getuid());
+ if (0 == u)
+ return _imp->config->reduced_username();
+ else
+ return get_user_name(u);
+}
+
uid_t
PaludisEnvironment::reduced_uid() const
{
diff --git a/paludis/environments/paludis/paludis_environment.hh b/paludis/environments/paludis/paludis_environment.hh
index 080bf0d..7015375 100644
--- a/paludis/environments/paludis/paludis_environment.hh
+++ b/paludis/environments/paludis/paludis_environment.hh
@@ -85,6 +85,9 @@ namespace paludis
virtual std::shared_ptr<const FSPathSequence> hook_dirs() const
PALUDIS_ATTRIBUTE((warn_unused_result));
+ virtual std::string reduced_username() const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
virtual uid_t reduced_uid() const
PALUDIS_ATTRIBUTE((warn_unused_result));
diff --git a/paludis/environments/portage/portage_environment.hh b/paludis/environments/portage/portage_environment.hh
index 4794ba6..9937d58 100644
--- a/paludis/environments/portage/portage_environment.hh
+++ b/paludis/environments/portage/portage_environment.hh
@@ -76,7 +76,6 @@ namespace paludis
bool _add_string_to_world(const std::string &) const;
bool _remove_string_from_world(const std::string &) const;
- std::string reduced_username() const;
std::string reduced_groupname() const;
protected:
@@ -142,6 +141,8 @@ namespace paludis
virtual bool unmasked_by_user(const std::shared_ptr<const PackageID> &, const std::string &) const
PALUDIS_ATTRIBUTE((warn_unused_result));
+ virtual std::string reduced_username() const;
+
virtual uid_t reduced_uid() const;
virtual gid_t reduced_gid() const;
diff --git a/paludis/environments/test/test_environment.cc b/paludis/environments/test/test_environment.cc
index 78223cc..bae4386 100644
--- a/paludis/environments/test/test_environment.cc
+++ b/paludis/environments/test/test_environment.cc
@@ -115,6 +115,12 @@ TestEnvironment::accept_license(const std::string &, const std::shared_ptr<const
return true;
}
+std::string
+TestEnvironment::reduced_username() const
+{
+ return getenv_with_default(env_vars::reduced_username, get_user_name(getuid()));
+}
+
uid_t
TestEnvironment::reduced_uid() const
{
diff --git a/paludis/environments/test/test_environment.hh b/paludis/environments/test/test_environment.hh
index b778872..c07511e 100644
--- a/paludis/environments/test/test_environment.hh
+++ b/paludis/environments/test/test_environment.hh
@@ -77,6 +77,8 @@ namespace paludis
virtual std::shared_ptr<const FSPathSequence> hook_dirs() const
PALUDIS_ATTRIBUTE((warn_unused_result));
+ virtual std::string reduced_username() const;
+
virtual uid_t reduced_uid() const;
virtual gid_t reduced_gid() const;