aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-28 00:46:33 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-28 00:46:33 +0100
commit466730de5349f8f530628e50be7321eeb3a4d004 (patch)
tree93304d3bf39c5a19f74490435aedb6c5be2598f8
parentaeb0e030283f70b98044d4e9d8b82050f11b2049 (diff)
downloadpaludis-466730de5349f8f530628e50be7321eeb3a4d004.tar.gz
paludis-466730de5349f8f530628e50be7321eeb3a4d004.tar.xz
make installed accounts dep upon their primary group
-rw-r--r--paludis/repositories/accounts/installed_accounts_id.cc71
1 files changed, 70 insertions, 1 deletions
diff --git a/paludis/repositories/accounts/installed_accounts_id.cc b/paludis/repositories/accounts/installed_accounts_id.cc
index 55e08fe..faecdde 100644
--- a/paludis/repositories/accounts/installed_accounts_id.cc
+++ b/paludis/repositories/accounts/installed_accounts_id.cc
@@ -18,6 +18,7 @@
*/
#include <paludis/repositories/accounts/installed_accounts_id.hh>
+#include <paludis/repositories/accounts/accounts_dep_key.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/config_file.hh>
@@ -27,12 +28,20 @@
#include <paludis/util/simple_visitor_cast.hh>
#include <paludis/util/tokeniser.hh>
#include <paludis/util/make_named_values.hh>
+#include <paludis/util/mutex.hh>
+#include <paludis/util/log.hh>
#include <paludis/name.hh>
#include <paludis/version_spec.hh>
#include <paludis/literal_metadata_key.hh>
#include <paludis/repository.hh>
#include <paludis/action.hh>
#include <paludis/user_dep_spec.hh>
+#include <sys/types.h>
+#include <pwd.h>
+#include <grp.h>
+#include <unistd.h>
+#include <list>
+#include <vector>
using namespace paludis;
using namespace paludis::accounts_repository;
@@ -50,6 +59,9 @@ namespace paludis
const std::tr1::shared_ptr<const LiteralMetadataValueKey<bool> > transient_key;
+ mutable Mutex mutex;
+ mutable std::tr1::shared_ptr<const AccountsDepKey> dependencies_key;
+
const bool is_user;
Implementation(const Environment * const e,
@@ -81,6 +93,62 @@ InstalledAccountsID::~InstalledAccountsID()
void
InstalledAccountsID::need_keys_added() const
{
+ Lock lock(_imp->mutex);
+
+ if (_imp->is_user && ! _imp->dependencies_key)
+ {
+ std::tr1::shared_ptr<Set<std::string> > groups(new Set<std::string>);
+
+ /* depend upon our primary group */
+ {
+ int pwd_buf_sz(sysconf(_SC_GETPW_R_SIZE_MAX));
+ if (-1 == pwd_buf_sz || pwd_buf_sz > 1024 * 128)
+ {
+ Log::get_instance()->message("accounts.getpw_r_size_max", ll_warning, lc_context) <<
+ "Got dodgy value " << pwd_buf_sz << " from sysconf(_SC_GETPW_R_SIZE_MAX)";
+ pwd_buf_sz = 1024 * 128;
+ }
+ std::vector<char> pwd_buf(pwd_buf_sz);
+
+ struct passwd pwd;
+ struct passwd * pwd_result;
+
+ if (0 == getpwnam_r(stringify(name().package()).c_str(), &pwd, &pwd_buf[0], pwd_buf_sz, &pwd_result))
+ {
+ int grp_buf_sz(sysconf(_SC_GETGR_R_SIZE_MAX));
+ if (-1 == grp_buf_sz || grp_buf_sz > 1024 * 128)
+ {
+ Log::get_instance()->message("accounts.getgr_r_size_max", ll_warning, lc_context) <<
+ "Got dodgy value " << grp_buf_sz << " from sysconf(_SC_GETPW_R_SIZE_MAX)";
+ grp_buf_sz = 1024 * 128;
+ }
+ std::vector<char> grp_buf(grp_buf_sz);
+
+ struct group grp;
+ struct group * grp_result;
+ if (0 == getgrgid_r(pwd.pw_gid, &grp, &grp_buf[0], grp_buf_sz, &grp_result))
+ {
+ /* really we should only do this if the group in question is managed by accounts. users
+ * might have accounts installed by hand with a group that's unmanaged. */
+ groups->insert(stringify(grp.gr_name));
+ }
+ else
+ Log::get_instance()->message("accounts.getgrgid_r", ll_warning, lc_context) <<
+ "getgrgid_r failed for " << name();
+ }
+ else
+ Log::get_instance()->message("accounts.getpwnam_r", ll_warning, lc_context) <<
+ "getpwnam_r failed for " << name();
+ }
+
+ /* ...and our secondary groups */
+ {
+ /* first person who gets annoyed by this not existing gets to implement it. */
+ }
+
+ _imp->dependencies_key.reset(new AccountsDepKey(_imp->env, groups));
+ add_metadata_key(_imp->dependencies_key);
+ }
}
void
@@ -178,7 +246,8 @@ InstalledAccountsID::build_dependencies_key() const
const std::tr1::shared_ptr<const MetadataSpecTreeKey<DependencySpecTree> >
InstalledAccountsID::run_dependencies_key() const
{
- return make_null_shared_ptr();
+ need_keys_added();
+ return _imp->dependencies_key;
}
const std::tr1::shared_ptr<const MetadataSpecTreeKey<DependencySpecTree> >