Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Make pass mode respect properly @owner/@group
Baptiste Daroussin committed 12 years ago
commit b9e670877450387708b8d433cd8d76dd88ce19b5
parent 421f730
2 files changed +22 -4
modified libpkg/packing.c
@@ -36,6 +36,8 @@
#include <string.h>
#include <sys/mman.h>
#include <limits.h>
+
#include <pwd.h>
+
#include <grp.h>

#include "pkg.h"
#include "private/event.h"
@@ -44,6 +46,7 @@
static const char *packing_set_format(struct archive *a, pkg_formats format);

struct packing {
+
	bool pass;
	struct archive *aread;
	struct archive *awrite;
	struct archive_entry_linkresolver *resolver;
@@ -67,6 +70,7 @@ packing_init(struct packing **pack, const char *path, pkg_formats format)
	archive_read_disk_set_symlink_physical((*pack)->aread);

	if (!is_dir(path)) {
+
		(*pack)->pass = false;
		(*pack)->awrite = archive_write_new();
		archive_write_set_format_pax_restricted((*pack)->awrite);
		ext = packing_set_format((*pack)->awrite, format);
@@ -91,6 +95,7 @@ packing_init(struct packing **pack, const char *path, pkg_formats format)
		}
	} else { /* pass mode directly write to the disk */
		pkg_debug(1, "Packing to directory '%s' (pass mode)", path);
+
		(*pack)->pass = true;
		(*pack)->awrite = archive_write_disk_new();
		archive_write_disk_set_options((*pack)->awrite,
		    EXTRACT_ARCHIVE_FLAGS);
@@ -99,6 +104,7 @@ packing_init(struct packing **pack, const char *path, pkg_formats format)
	(*pack)->resolver = archive_entry_linkresolver_new();
	archive_entry_linkresolver_set_strategy((*pack)->resolver,
	    ARCHIVE_FORMAT_TAR_PAX_RESTRICTED);
+

	return (EPKG_OK);
}

@@ -181,11 +187,21 @@ packing_append_file_attr(struct packing *pack, const char *filepath,
		archive_entry_set_size(entry, 0);
	}

-
	if (uname != NULL && uname[0] != '\0')
+
	if (uname != NULL && uname[0] != '\0') {
+
		if (pack->pass) {
+
			struct passwd* pw = getpwnam(uname);
+
			archive_entry_set_uid(entry, pw->pw_uid);
+
		}
		archive_entry_set_uname(entry, uname);
+
	}

-
	if (gname != NULL && gname[0] != '\0')
+
	if (gname != NULL && gname[0] != '\0') {
+
		if (pack->pass) {
+
			struct group *gr = (getgrnam(gname));
+
			archive_entry_set_gid(entry, gr->gr_gid);
+
		}
		archive_entry_set_gname(entry, gname);
+
	}

	if (perm != 0)
		archive_entry_set_perm(entry, perm);
modified libpkg/pkg.c
@@ -1277,13 +1277,15 @@ pkg_copy_tree(struct pkg *pkg, const char *src, const char *dest)
	while (pkg_dirs(pkg, &dir) == EPKG_OK) {
		snprintf(spath, sizeof(spath), "%s%s", src, pkg_dir_path(dir));
		snprintf(dpath, sizeof(dpath), "%s%s", dest, pkg_dir_path(dir));
-
		packing_append_file(pack, spath, dpath);
+
		packing_append_file_attr(pack, spath, dpath,
+
		    dir->uname, dir->gname, dir->perm);
	}

	while (pkg_files(pkg, &file) == EPKG_OK) {
		snprintf(spath, sizeof(spath), "%s%s", src, pkg_file_path(file));
		snprintf(dpath, sizeof(dpath), "%s%s", dest, pkg_file_path(file));
-
		packing_append_file(pack, spath, dpath);
+
		packing_append_file_attr(pack, spath, dpath,
+
		    file->uname, file->gname, file->perm);
	}

	/* Execute post-install scripts */