summaryrefslogtreecommitdiff
path: root/src/app_add.c
diff options
context:
space:
mode:
authorFredrik Gustafsson <fredrigu@axis.com>2019-11-20 11:48:48 +0100
committerTimo Teräs <timo.teras@iki.fi>2020-04-28 14:48:49 +0300
commitd61c009f7a7ba9c99797855d8cd4e0a503c2fda5 (patch)
tree891bff6bb4146e17ec94dbfbdcb909e048a0fb09 /src/app_add.c
parentb67df9843dbdad15cb794fa26a7c216a14453690 (diff)
downloadapk-tools-d61c009f7a7ba9c99797855d8cd4e0a503c2fda5.tar.gz
apk-tools-d61c009f7a7ba9c99797855d8cd4e0a503c2fda5.tar.bz2
apk-tools-d61c009f7a7ba9c99797855d8cd4e0a503c2fda5.tar.xz
apk-tools-d61c009f7a7ba9c99797855d8cd4e0a503c2fda5.zip
apk: do not manage file ownership as non-root or when asked so
If apk is run as a non-root user, it's not possible to chown files. Maintainers note: minor wording changes on commit log and man page. Signed-off-by: Fredrik Gustafsson <fredrigu@axis.com>
Diffstat (limited to 'src/app_add.c')
-rw-r--r--src/app_add.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/app_add.c b/src/app_add.c
index 8b0ed1a..f5edae0 100644
--- a/src/app_add.c
+++ b/src/app_add.c
@@ -20,6 +20,7 @@
struct add_ctx {
const char *virtpkg;
unsigned short solver_flags;
+ unsigned short extract_flags;
};
static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int optch, const char *optarg)
@@ -30,6 +31,9 @@ static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt
case 0x10000:
dbopts->open_flags |= APK_OPENF_CREATE;
break;
+ case 0x10001:
+ actx->extract_flags |= APK_EXTRACTF_NO_CHOWN;
+ break;
case 'u':
actx->solver_flags |= APK_SOLVERF_UPGRADE;
break;
@@ -47,6 +51,7 @@ static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt
static const struct apk_option options_applet[] = {
{ 0x10000, "initdb" },
+ { 0x10001, "no-chown" },
{ 'u', "upgrade" },
{ 'l', "latest" },
{ 't', "virtual", required_argument, "NAME" },
@@ -118,6 +123,9 @@ static int add_main(void *ctx, struct apk_database *db, struct apk_string_array
apk_dependency_array_copy(&world, db->world);
+ if (getuid() != 0 || (actx->extract_flags & APK_EXTRACTF_NO_CHOWN))
+ db->extract_flags |= APK_EXTRACTF_NO_CHOWN;
+
if (actx->virtpkg) {
apk_blob_t b = APK_BLOB_STR(actx->virtpkg);
apk_blob_pull_dep(&b, db, &virtdep);