aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-03-31 16:56:00 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-03-31 16:56:00 +0000
commit2379d4810190fc258ffbfda8571d12f9d2f90545 (patch)
treeae507fdf40aeb1519b8e11bd6e1d2f19ac4093fc
parent08bb298811dccc127e90e456ac9af0ac11bf758c (diff)
downloadpaludis-2379d4810190fc258ffbfda8571d12f9d2f90545.tar.gz
paludis-2379d4810190fc258ffbfda8571d12f9d2f90545.tar.xz
Handle getgrgid returning NULL. Fixes: ticket:174
-rw-r--r--paludis/repositories/gentoo/ebuild_entries.cc9
-rw-r--r--paludis/util/system.cc31
-rw-r--r--paludis/util/system.hh14
3 files changed, 50 insertions, 4 deletions
diff --git a/paludis/repositories/gentoo/ebuild_entries.cc b/paludis/repositories/gentoo/ebuild_entries.cc
index 61dd702..1c79675 100644
--- a/paludis/repositories/gentoo/ebuild_entries.cc
+++ b/paludis/repositories/gentoo/ebuild_entries.cc
@@ -31,6 +31,7 @@
#include <paludis/util/log.hh>
#include <paludis/util/strip.hh>
#include <paludis/util/tokeniser.hh>
+#include <paludis/util/system.hh>
#include <fstream>
#include <list>
@@ -477,8 +478,8 @@ EbuildEntries::install(const QualifiedPackageName & q, const VersionSpec & v,
{
Log::get_instance()->message(ll_warning, lc_context, "Directory '" +
stringify(f) + "' owned by group '" +
- stringify(getgrgid(f.group())->gr_name) + "', not '" +
- stringify(getgrgid(_imp->environment->reduced_gid())->gr_name) +
+ stringify(get_group_name(f.group())) + "', not '" +
+ stringify(get_group_name(_imp->environment->reduced_gid())) +
"', so cannot enable userpriv");
fetch_userpriv_ok = false;
}
@@ -527,8 +528,8 @@ EbuildEntries::install(const QualifiedPackageName & q, const VersionSpec & v,
{
Log::get_instance()->message(ll_warning, lc_context, "Directory '" +
stringify(f) + "' owned by group '" +
- stringify(getgrgid(f.group())->gr_name) + "', not '" +
- stringify(getgrgid(_imp->environment->reduced_gid())->gr_name) + "', cannot enable userpriv");
+ stringify(get_group_name(f.group())) + "', not '" +
+ stringify(get_group_name(_imp->environment->reduced_gid())) + "', cannot enable userpriv");
userpriv_ok = false;
}
else if (! f.has_permission(fs_ug_group, fs_perm_write))
diff --git a/paludis/util/system.cc b/paludis/util/system.cc
index 546dd00..ead268f 100644
--- a/paludis/util/system.cc
+++ b/paludis/util/system.cc
@@ -29,6 +29,7 @@
#include <unistd.h>
#include <errno.h>
#include <grp.h>
+#include <pwd.h>
#include <map>
#include <iostream>
#include "config.h"
@@ -411,3 +412,33 @@ Command::stderr_prefix() const
return _imp->stderr_prefix;
}
+std::string
+paludis::get_user_name(const uid_t u)
+{
+ const struct passwd * const p(getpwuid(u));
+ if (p)
+ return stringify(p->pw_name);
+ else
+ {
+ Context c("When getting user name for uid '" + stringify(u) + "':");
+ Log::get_instance()->message(ll_warning, lc_context, "getpwuid("
+ + stringify(u) + ") returned null");
+ return stringify(u);
+ }
+}
+
+std::string
+paludis::get_group_name(const gid_t u)
+{
+ const struct group * const p(getgrgid(u));
+ if (p)
+ return stringify(p->gr_name);
+ else
+ {
+ Context c("When getting group name for gid '" + stringify(u) + "':");
+ Log::get_instance()->message(ll_warning, lc_context, "getgrgid("
+ + stringify(u) + ") returned null");
+ return stringify(u);
+ }
+}
+
diff --git a/paludis/util/system.hh b/paludis/util/system.hh
index 7cb10ba..0fdc783 100644
--- a/paludis/util/system.hh
+++ b/paludis/util/system.hh
@@ -152,6 +152,20 @@ namespace paludis
* \ingroup grpsystem
*/
void set_run_command_stderr_fds(const int, const int) PALUDIS_VISIBLE;
+
+ /**
+ * Fetch the username for a uid, or the uid as a string if not available.
+ *
+ * \ingroup grpsystem
+ */
+ std::string get_user_name(const uid_t) PALUDIS_VISIBLE;
+
+ /**
+ * Fetch the group name for a gid, or the gid as a string if not available.
+ *
+ * \ingroup grpsystem
+ */
+ std::string get_group_name(const gid_t) PALUDIS_VISIBLE;
}
#endif