summaryrefslogtreecommitdiff
path: root/src/io_archive.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/io_archive.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/io_archive.c')
-rw-r--r--src/io_archive.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/io_archive.c b/src/io_archive.c
index 22145ab..1d34927 100644
--- a/src/io_archive.c
+++ b/src/io_archive.c
@@ -337,7 +337,8 @@ int apk_tar_write_padding(struct apk_ostream *os, const struct apk_file_info *ae
int apk_archive_entry_extract(int atfd, const struct apk_file_info *ae,
const char *extract_name, const char *link_target,
struct apk_istream *is,
- apk_progress_cb cb, void *cb_ctx)
+ apk_progress_cb cb, void *cb_ctx,
+ unsigned int apk_extract_flags)
{
struct apk_xattr *xattr;
const char *fn = extract_name ?: ae->name;
@@ -385,22 +386,24 @@ int apk_archive_entry_extract(int atfd, const struct apk_file_info *ae,
return ret;
}
- r = fchownat(atfd, fn, ae->uid, ae->gid, atflags);
- if (r < 0) {
- apk_error("Failed to set ownership on %s: %s",
- fn, strerror(errno));
- if (!ret) ret = -errno;
- }
-
- /* chown resets suid bit so we need set it again */
- if (ae->mode & 07000) {
- r = fchmodat(atfd, fn, ae->mode & 07777, atflags);
+ if (!(apk_extract_flags & APK_EXTRACTF_NO_CHOWN)) {
+ r = fchownat(atfd, fn, ae->uid, ae->gid, atflags);
if (r < 0) {
- apk_error("Failed to set file permissions "
- "on %s: %s",
+ apk_error("Failed to set ownership on %s: %s",
fn, strerror(errno));
if (!ret) ret = -errno;
}
+
+ /* chown resets suid bit so we need set it again */
+ if (ae->mode & 07000) {
+ r = fchmodat(atfd, fn, ae->mode & 07777, atflags);
+ if (r < 0) {
+ apk_error("Failed to set file permissions "
+ "on %s: %s",
+ fn, strerror(errno));
+ if (!ret) ret = -errno;
+ }
+ }
}
/* extract xattrs */