From 6e8daa553bbd50ec541add9549bfd95030c335f5 Mon Sep 17 00:00:00 2001 From: Aaron Griffin Date: Wed, 14 Nov 2007 19:22:06 -0600 Subject: Force mode of all database files to 644 In the case of a packaging error where install or changelog had bad permissions, pacman respected the original permissions without trying to fix it - this means that some operations (changelog) artificially required root permissions to run In addition, minor function housekeeping on _alpm_unpack Signed-off-by: Aaron Griffin --- lib/libalpm/util.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index a04256ef..2a429488 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -370,12 +370,11 @@ int _alpm_lckrm() int _alpm_unpack(const char *archive, const char *prefix, const char *fn) { - register struct archive *_archive; + int ret = 0; + mode_t oldmask; + struct archive *_archive; struct archive_entry *entry; char expath[PATH_MAX]; - const int archive_flags = ARCHIVE_EXTRACT_OWNER | - ARCHIVE_EXTRACT_PERM | - ARCHIVE_EXTRACT_TIME; ALPM_LOG_FUNC; @@ -392,26 +391,38 @@ int _alpm_unpack(const char *archive, const char *prefix, const char *fn) RET_ERR(PM_ERR_PKG_OPEN, -1); } + oldmask = umask(0022); while(archive_read_next_header(_archive, &entry) == ARCHIVE_OK) { + const struct stat *st; const char *entryname; /* the name of the file in the archive */ + + st = archive_entry_stat(entry); entryname = archive_entry_pathname(entry); + + if(S_ISREG(st->st_mode)) { + archive_entry_set_mode(entry, 0644); + } if (fn && strcmp(fn, entryname)) { - if (archive_read_data_skip(_archive) != ARCHIVE_OK) - return(1); + if (archive_read_data_skip(_archive) != ARCHIVE_OK) { + ret = 1; + goto cleanup; + } continue; } snprintf(expath, PATH_MAX, "%s/%s", prefix, entryname); archive_entry_set_pathname(entry, expath); - int ret = archive_read_extract(_archive, entry, archive_flags); - if(ret == ARCHIVE_WARN) { + + int readret = archive_read_extract(_archive, entry, 0); + if(readret == ARCHIVE_WARN) { /* operation succeeded but a non-critical error was encountered */ _alpm_log(PM_LOG_DEBUG, "warning extracting %s (%s)\n", entryname, archive_error_string(_archive)); - } else if(ret != ARCHIVE_OK) { + } else if(readret != ARCHIVE_OK) { _alpm_log(PM_LOG_ERROR, _("could not extract %s (%s)\n"), entryname, archive_error_string(_archive)); - return(1); + ret = 1; + goto cleanup; } if(fn) { @@ -419,8 +430,10 @@ int _alpm_unpack(const char *archive, const char *prefix, const char *fn) } } +cleanup: + umask(oldmask); archive_read_finish(_archive); - return(0); + return(ret); } /* does the same thing as 'rm -rf' */ -- cgit v1.2.3-70-g09d2