Allow installing/removing binpkgs as non-root.
--HG-- extra : convert_revision : 3781ef0a422530623cf64f45f87948e00d7e50e8
This commit is contained in:
parent
a6f956257d
commit
bb6355fe12
@ -134,12 +134,6 @@ main(int argc, char **argv)
|
|||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
if (geteuid() != 0) {
|
|
||||||
printf("ERROR: root permissions are needed to install"
|
|
||||||
"and remove binary packages.\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Install into root directory by default. */
|
/* Install into root directory by default. */
|
||||||
if (strcasecmp(argv[0], "install") == 0) {
|
if (strcasecmp(argv[0], "install") == 0) {
|
||||||
rv = xbps_install_binary_pkg(argv[1], root);
|
rv = xbps_install_binary_pkg(argv[1], root);
|
||||||
|
20
lib/unpack.c
20
lib/unpack.c
@ -117,13 +117,12 @@ unpack_archive_init(prop_dictionary_t pkg, const char *destdir,
|
|||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Flags for extracting files in binary packages.
|
* Flags for extracting files in binary packages.
|
||||||
* TODO: change this for non root users.
|
|
||||||
*/
|
*/
|
||||||
#define EXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | \
|
#define EXTRACT_FLAGS ARCHIVE_EXTRACT_SECURE_NODOTDOT | \
|
||||||
ARCHIVE_EXTRACT_TIME | \
|
|
||||||
ARCHIVE_EXTRACT_SECURE_NODOTDOT | \
|
|
||||||
ARCHIVE_EXTRACT_SECURE_SYMLINKS | \
|
ARCHIVE_EXTRACT_SECURE_SYMLINKS | \
|
||||||
ARCHIVE_EXTRACT_UNLINK
|
ARCHIVE_EXTRACT_UNLINK
|
||||||
|
#define FEXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | \
|
||||||
|
ARCHIVE_EXTRACT_TIME | EXTRACT_FLAGS
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: remove printfs and return appropiate errors to be interpreted by
|
* TODO: remove printfs and return appropiate errors to be interpreted by
|
||||||
@ -138,7 +137,7 @@ unpack_archive_fini(struct archive *ar, const char *destdir,
|
|||||||
const char *prepost = "./XBPS_PREPOST_INSTALL";
|
const char *prepost = "./XBPS_PREPOST_INSTALL";
|
||||||
const char *pkgname, *version;
|
const char *pkgname, *version;
|
||||||
char *buf;
|
char *buf;
|
||||||
int rv = 0;
|
int rv = 0, flags = 0;
|
||||||
bool actgt = false;
|
bool actgt = false;
|
||||||
|
|
||||||
assert(ar != NULL);
|
assert(ar != NULL);
|
||||||
@ -147,6 +146,11 @@ unpack_archive_fini(struct archive *ar, const char *destdir,
|
|||||||
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
|
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
|
||||||
prop_dictionary_get_cstring_nocopy(pkg, "version", &version);
|
prop_dictionary_get_cstring_nocopy(pkg, "version", &version);
|
||||||
|
|
||||||
|
if (getuid() == 0)
|
||||||
|
flags = FEXTRACT_FLAGS;
|
||||||
|
else
|
||||||
|
flags = EXTRACT_FLAGS;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This length is '.%s/metadata/%s/prepost-inst' not
|
* This length is '.%s/metadata/%s/prepost-inst' not
|
||||||
* including nul.
|
* including nul.
|
||||||
@ -172,8 +176,7 @@ unpack_archive_fini(struct archive *ar, const char *destdir,
|
|||||||
|
|
||||||
archive_entry_set_pathname(entry, buf);
|
archive_entry_set_pathname(entry, buf);
|
||||||
|
|
||||||
if ((rv = archive_read_extract(ar, entry,
|
if ((rv = archive_read_extract(ar, entry, flags)) != 0)
|
||||||
EXTRACT_FLAGS)) != 0)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if ((rv = xbps_file_exec(buf, destdir, "pre",
|
if ((rv = xbps_file_exec(buf, destdir, "pre",
|
||||||
@ -190,8 +193,7 @@ unpack_archive_fini(struct archive *ar, const char *destdir,
|
|||||||
/*
|
/*
|
||||||
* Extract all data from the archive now.
|
* Extract all data from the archive now.
|
||||||
*/
|
*/
|
||||||
if ((rv = archive_read_extract(ar, entry,
|
if ((rv = archive_read_extract(ar, entry, flags)) != 0) {
|
||||||
EXTRACT_FLAGS)) != 0) {
|
|
||||||
printf("\ncouldn't unpack %s (%s), exiting!\n",
|
printf("\ncouldn't unpack %s (%s), exiting!\n",
|
||||||
archive_entry_pathname(entry), strerror(errno));
|
archive_entry_pathname(entry), strerror(errno));
|
||||||
(void)fflush(stdout);
|
(void)fflush(stdout);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user