aboutsummaryrefslogtreecommitdiff
path: root/paludis/repositories
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-06-24 01:26:14 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-06-24 01:26:14 +0100
commit571e096926ba2518e001dd1e7681cf1dfd94482d (patch)
tree08e37d825e300bf2615f0395d1075c2022f922e1 /paludis/repositories
parent64f0748bd372d7fd7075d69dbdc730ffd93cc941 (diff)
downloadpaludis-571e096926ba2518e001dd1e7681cf1dfd94482d.tar.gz
paludis-571e096926ba2518e001dd1e7681cf1dfd94482d.tar.xz
importare can now change file ownership to root.
importare --rewrite-ids-over-to-root n will rewrite any uid or gid greater than n to 0. -1 disables, which is the default for now. Fixes: ticket:599
Diffstat (limited to 'paludis/repositories')
-rw-r--r--paludis/repositories/e/exndbam_repository.cc15
-rw-r--r--paludis/repositories/e/vdb_merger.cc13
-rw-r--r--paludis/repositories/unpackaged/installed_repository.cc30
-rw-r--r--paludis/repositories/unpackaged/installed_repository_TEST.cc3
-rw-r--r--paludis/repositories/unpackaged/registration.cc9
-rw-r--r--paludis/repositories/unpackaged/unpackaged_repository.cc4
-rw-r--r--paludis/repositories/unpackaged/unpackaged_repository.hh3
-rw-r--r--paludis/repositories/unpackaged/unpackaged_repository_TEST.cc6
8 files changed, 82 insertions, 1 deletions
diff --git a/paludis/repositories/e/exndbam_repository.cc b/paludis/repositories/e/exndbam_repository.cc
index d129ade..d64cfc0 100644
--- a/paludis/repositories/e/exndbam_repository.cc
+++ b/paludis/repositories/e/exndbam_repository.cc
@@ -43,6 +43,7 @@
#include <paludis/package_id.hh>
#include <paludis/action.hh>
#include <paludis/literal_metadata_key.hh>
+#include <tr1/functional>
#include <fstream>
using namespace paludis;
@@ -264,6 +265,18 @@ ExndbamRepository::need_keys_added() const
{
}
+namespace
+{
+ std::pair<uid_t, gid_t>
+ get_new_ids_or_minus_one(const Environment * const env, const FSEntry & f)
+ {
+ if (f.owner() == env->reduced_uid() || f.group() == env->reduced_gid())
+ return std::make_pair(0, 0);
+ else
+ return std::make_pair(-1, -1);
+ }
+}
+
void
ExndbamRepository::merge(const MergeParams & m)
{
@@ -337,6 +350,8 @@ ExndbamRepository::merge(const MergeParams & m)
(k::config_protect(), config_protect)
(k::config_protect_mask(), config_protect_mask)
(k::package_id(), m[k::package_id()])
+ (k::get_new_ids_or_minus_one(), std::tr1::bind(&get_new_ids_or_minus_one, _imp->params.environment,
+ std::tr1::placeholders::_1))
(k::options(), m[k::options()]));
if (! merger.check())
diff --git a/paludis/repositories/e/vdb_merger.cc b/paludis/repositories/e/vdb_merger.cc
index a62b040..2d30cf4 100644
--- a/paludis/repositories/e/vdb_merger.cc
+++ b/paludis/repositories/e/vdb_merger.cc
@@ -62,6 +62,18 @@ namespace paludis
};
}
+namespace
+{
+ std::pair<uid_t, gid_t>
+ get_new_ids_or_minus_one(const Environment * const env, const FSEntry & f)
+ {
+ if (f.owner() == env->reduced_uid() || f.group() == env->reduced_gid())
+ return std::make_pair(0, 0);
+ else
+ return std::make_pair(-1, -1);
+ }
+}
+
VDBMerger::VDBMerger(const VDBMergerParams & p) :
Merger(MergerParams::named_create()
(k::environment(), p[k::environment()])
@@ -69,6 +81,7 @@ VDBMerger::VDBMerger(const VDBMergerParams & p) :
(k::install_under(), FSEntry("/"))
(k::root(), p[k::root()])
(k::no_chown(), ! getenv_with_default("PALUDIS_NO_CHOWN", "").empty())
+ (k::get_new_ids_or_minus_one(), std::tr1::bind(&get_new_ids_or_minus_one, p[k::environment()], std::tr1::placeholders::_1))
(k::options(), p[k::options()])),
PrivateImplementationPattern<VDBMerger>(new Implementation<VDBMerger>(p)),
_imp(PrivateImplementationPattern<VDBMerger>::_imp)
diff --git a/paludis/repositories/unpackaged/installed_repository.cc b/paludis/repositories/unpackaged/installed_repository.cc
index 4379d08..03fe9f7 100644
--- a/paludis/repositories/unpackaged/installed_repository.cc
+++ b/paludis/repositories/unpackaged/installed_repository.cc
@@ -223,9 +223,26 @@ InstalledUnpackagedRepository::some_ids_might_support_action(const SupportsActio
return v.result;
}
+namespace
+{
+ std::pair<uid_t, gid_t>
+ get_new_ids_or_minus_one(const Environment * const env, const int rewrite_ids_over_to_root, const FSEntry & f)
+ {
+ if (f.owner() == env->reduced_uid() || f.group() == env->reduced_gid())
+ return std::make_pair(0, 0);
+ else if ((-1 != rewrite_ids_over_to_root) && (f.owner() > static_cast<unsigned int>(rewrite_ids_over_to_root)
+ || f.group() > static_cast<unsigned int>(rewrite_ids_over_to_root)))
+ return std::make_pair(0, 0);
+ else
+ return std::make_pair(-1, -1);
+ }
+}
+
void
InstalledUnpackagedRepository::merge(const MergeParams & m)
{
+ using namespace std::tr1::placeholders;
+
Context context("When merging '" + stringify(*m[k::package_id()]) + "' at '" + stringify(m[k::image_dir()])
+ "' to InstalledUnpackagedRepository repository '" + stringify(name()) + "':");
@@ -243,6 +260,17 @@ InstalledUnpackagedRepository::merge(const MergeParams & m)
install_under = kk->value();
}
+ int rewrite_ids_over_to_root(-1);
+ {
+ Repository::MetadataConstIterator k(m[k::package_id()]->repository()->find_metadata("rewrite_ids_over_to_root"));
+ if (k == m[k::package_id()]->repository()->end_metadata())
+ throw InstallActionError("Could not fetch rewrite_ids_over_to_root key from owning repository");
+ const MetadataValueKey<long> * kk(visitor_cast<const MetadataValueKey<long> >(**k));
+ if (! kk)
+ throw InstallActionError("Fetched rewrite_ids_over_to_root key but did not get a long key from owning repository");
+ rewrite_ids_over_to_root = kk->value();
+ }
+
std::tr1::shared_ptr<const PackageID> if_overwritten_id, if_same_name_id;
{
std::tr1::shared_ptr<const PackageIDSequence> ids(package_ids(m[k::package_id()]->name()));
@@ -321,6 +349,8 @@ InstalledUnpackagedRepository::merge(const MergeParams & m)
(k::config_protect(), getenv_with_default("CONFIG_PROTECT", ""))
(k::config_protect_mask(), getenv_with_default("CONFIG_PROTECT_MASK", ""))
(k::package_id(), m[k::package_id()])
+ (k::get_new_ids_or_minus_one(), std::tr1::bind(&get_new_ids_or_minus_one, _imp->params.environment,
+ rewrite_ids_over_to_root, _1))
(k::options(), MergerOptions() + mo_rewrite_symlinks + mo_allow_empty_dirs));
if (! merger.check())
diff --git a/paludis/repositories/unpackaged/installed_repository_TEST.cc b/paludis/repositories/unpackaged/installed_repository_TEST.cc
index 58a4908..23479a8 100644
--- a/paludis/repositories/unpackaged/installed_repository_TEST.cc
+++ b/paludis/repositories/unpackaged/installed_repository_TEST.cc
@@ -376,6 +376,7 @@ namespace test_cases
(k::install_under(), FSEntry("/"))
(k::build_dependencies(), "")
(k::run_dependencies(), "")
+ (k::rewrite_ids_over_to_root(), -1)
(k::description(), "")
));
env.package_database()->add_repository(1, source_repo);
@@ -431,6 +432,7 @@ namespace test_cases
(k::install_under(), FSEntry("/"))
(k::build_dependencies(), "")
(k::run_dependencies(), "")
+ (k::rewrite_ids_over_to_root(), -1)
(k::description(), "")
));
env.package_database()->add_repository(1, source_repo);
@@ -487,6 +489,7 @@ namespace test_cases
(k::location(), FSEntry("installed_repository_TEST_dir/src4b2"))
(k::install_under(), FSEntry("/"))
(k::build_dependencies(), "")
+ (k::rewrite_ids_over_to_root(), -1)
(k::run_dependencies(), "")
(k::description(), "")
));
diff --git a/paludis/repositories/unpackaged/registration.cc b/paludis/repositories/unpackaged/registration.cc
index 34affa7..117bec5 100644
--- a/paludis/repositories/unpackaged/registration.cc
+++ b/paludis/repositories/unpackaged/registration.cc
@@ -21,6 +21,7 @@
#include <paludis/util/attributes.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/destringify.hh>
#include <paludis/repositories/unpackaged/installed_repository.hh>
#include <paludis/repositories/unpackaged/unpackaged_repository.hh>
#include <paludis/repositories/unpackaged/exceptions.hh>
@@ -68,6 +69,13 @@ namespace
if (m->end() != m->find("description"))
description = m->find("description")->second;
+ int rewrite_ids_over_to_root(-1);
+ if (m->end() != m->find("rewrite_ids_over_to_root") && ! m->find("rewrite_ids_over_to_root")->second.empty())
+ {
+ Context item_context("When handling rewrite_ids_over_to_root key:");
+ rewrite_ids_over_to_root = destringify<int>(m->find("rewrite_ids_over_to_root")->second);
+ }
+
return make_shared_ptr(new UnpackagedRepository(RepositoryName("unpackaged"),
unpackaged_repositories::UnpackagedRepositoryParams::named_create()
(k::environment(), env)
@@ -78,6 +86,7 @@ namespace
(k::slot(), SlotName(slot))
(k::build_dependencies(), build_dependencies)
(k::run_dependencies(), run_dependencies)
+ (k::rewrite_ids_over_to_root(), rewrite_ids_over_to_root)
(k::description(), description)));
}
diff --git a/paludis/repositories/unpackaged/unpackaged_repository.cc b/paludis/repositories/unpackaged/unpackaged_repository.cc
index 794400d..410aeb9 100644
--- a/paludis/repositories/unpackaged/unpackaged_repository.cc
+++ b/paludis/repositories/unpackaged/unpackaged_repository.cc
@@ -45,6 +45,7 @@ namespace paludis
std::tr1::shared_ptr<const MetadataValueKey<FSEntry> > location_key;
std::tr1::shared_ptr<const MetadataValueKey<FSEntry> > install_under_key;
+ std::tr1::shared_ptr<const MetadataValueKey<long> > rewrite_ids_over_to_root_key;
std::tr1::shared_ptr<const MetadataValueKey<std::string> > name_key;
std::tr1::shared_ptr<const MetadataValueKey<std::string> > slot_key;
std::tr1::shared_ptr<const MetadataValueKey<std::string> > format_key;
@@ -64,6 +65,8 @@ namespace paludis
mkt_significant, params[k::location()])),
install_under_key(new LiteralMetadataValueKey<FSEntry> ("install_under", "install_under",
mkt_significant, params[k::install_under()])),
+ rewrite_ids_over_to_root_key(new LiteralMetadataValueKey<long> ("rewrite_ids_over_to_root", "rewrite_ids_over_to_root",
+ mkt_normal, params[k::rewrite_ids_over_to_root()])),
name_key(new LiteralMetadataValueKey<std::string> ("name", "name",
mkt_normal, stringify(params[k::name()]))),
slot_key(new LiteralMetadataValueKey<std::string> ("slot", "slot",
@@ -116,6 +119,7 @@ UnpackagedRepository::_add_metadata_keys() const
clear_metadata_keys();
add_metadata_key(_imp->location_key);
add_metadata_key(_imp->install_under_key);
+ add_metadata_key(_imp->rewrite_ids_over_to_root_key);
add_metadata_key(_imp->name_key);
add_metadata_key(_imp->slot_key);
add_metadata_key(_imp->format_key);
diff --git a/paludis/repositories/unpackaged/unpackaged_repository.hh b/paludis/repositories/unpackaged/unpackaged_repository.hh
index 0d27f1b..2f72592 100644
--- a/paludis/repositories/unpackaged/unpackaged_repository.hh
+++ b/paludis/repositories/unpackaged/unpackaged_repository.hh
@@ -39,7 +39,8 @@ namespace paludis
kc::Field<k::slot, SlotName>,
kc::Field<k::build_dependencies, std::string>,
kc::Field<k::run_dependencies, std::string>,
- kc::Field<k::description, std::string>
+ kc::Field<k::description, std::string>,
+ kc::Field<k::rewrite_ids_over_to_root, int>
> UnpackagedRepositoryParams;
}
diff --git a/paludis/repositories/unpackaged/unpackaged_repository_TEST.cc b/paludis/repositories/unpackaged/unpackaged_repository_TEST.cc
index bbff750..0a39157 100644
--- a/paludis/repositories/unpackaged/unpackaged_repository_TEST.cc
+++ b/paludis/repositories/unpackaged/unpackaged_repository_TEST.cc
@@ -61,6 +61,7 @@ namespace test_cases
(k::build_dependencies(), "")
(k::run_dependencies(), "")
(k::description(), "")
+ (k::rewrite_ids_over_to_root(), -1)
));
env.package_database()->add_repository(1, repo);
@@ -89,6 +90,7 @@ namespace test_cases
(k::install_under(), FSEntry("/"))
(k::build_dependencies(), "")
(k::run_dependencies(), "")
+ (k::rewrite_ids_over_to_root(), -1)
(k::description(), "")
));
env.package_database()->add_repository(1, repo);
@@ -123,6 +125,7 @@ namespace test_cases
(k::install_under(), FSEntry("/"))
(k::build_dependencies(), "")
(k::run_dependencies(), "")
+ (k::rewrite_ids_over_to_root(), -1)
(k::description(), "")
));
env.package_database()->add_repository(1, repo);
@@ -152,6 +155,7 @@ namespace test_cases
(k::install_under(), FSEntry("/"))
(k::build_dependencies(), "")
(k::run_dependencies(), "")
+ (k::rewrite_ids_over_to_root(), -1)
(k::description(), "")
));
env.package_database()->add_repository(1, repo);
@@ -194,6 +198,7 @@ namespace test_cases
(k::install_under(), FSEntry("/"))
(k::build_dependencies(), "")
(k::run_dependencies(), "")
+ (k::rewrite_ids_over_to_root(), -1)
(k::description(), "")
));
env.package_database()->add_repository(1, repo);
@@ -248,6 +253,7 @@ namespace test_cases
(k::install_under(), FSEntry("/magic/pixie"))
(k::build_dependencies(), "")
(k::run_dependencies(), "")
+ (k::rewrite_ids_over_to_root(), -1)
(k::description(), "")
));
env.package_database()->add_repository(1, repo);