Allow installing/removing binpkgs as non-root.

--HG--
extra : convert_revision : 3781ef0a422530623cf64f45f87948e00d7e50e8
This commit is contained in:
Juan RP 2009-02-07 18:05:40 +01:00
parent a6f956257d
commit bb6355fe12
2 changed files with 11 additions and 15 deletions

View File

@ -134,12 +134,6 @@ main(int argc, char **argv)
if (argc != 2)
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. */
if (strcasecmp(argv[0], "install") == 0) {
rv = xbps_install_binary_pkg(argv[1], root);

View File

@ -117,13 +117,12 @@ unpack_archive_init(prop_dictionary_t pkg, const char *destdir,
}
/*
* Flags for extracting files in binary packages.
* TODO: change this for non root users.
*/
#define EXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | \
ARCHIVE_EXTRACT_TIME | \
ARCHIVE_EXTRACT_SECURE_NODOTDOT | \
#define EXTRACT_FLAGS ARCHIVE_EXTRACT_SECURE_NODOTDOT | \
ARCHIVE_EXTRACT_SECURE_SYMLINKS | \
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
@ -138,7 +137,7 @@ unpack_archive_fini(struct archive *ar, const char *destdir,
const char *prepost = "./XBPS_PREPOST_INSTALL";
const char *pkgname, *version;
char *buf;
int rv = 0;
int rv = 0, flags = 0;
bool actgt = false;
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, "version", &version);
if (getuid() == 0)
flags = FEXTRACT_FLAGS;
else
flags = EXTRACT_FLAGS;
/*
* This length is '.%s/metadata/%s/prepost-inst' not
* including nul.
@ -172,8 +176,7 @@ unpack_archive_fini(struct archive *ar, const char *destdir,
archive_entry_set_pathname(entry, buf);
if ((rv = archive_read_extract(ar, entry,
EXTRACT_FLAGS)) != 0)
if ((rv = archive_read_extract(ar, entry, flags)) != 0)
break;
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.
*/
if ((rv = archive_read_extract(ar, entry,
EXTRACT_FLAGS)) != 0) {
if ((rv = archive_read_extract(ar, entry, flags)) != 0) {
printf("\ncouldn't unpack %s (%s), exiting!\n",
archive_entry_pathname(entry), strerror(errno));
(void)fflush(stdout);