Merge pull request #234 from Duncaen/umask

Fix pkgdb and files plist permissions with restictive umask.
This commit is contained in:
Juan RP 2017-10-25 09:13:26 +02:00 committed by GitHub
commit eae215e2a0
3 changed files with 13 additions and 1 deletions

View File

@ -461,15 +461,19 @@ unpack_archive(struct xbps_handle *xhp,
* Externalize binpkg files.plist to disk, if not empty. * Externalize binpkg files.plist to disk, if not empty.
*/ */
if (xbps_dictionary_count(binpkg_filesd)) { if (xbps_dictionary_count(binpkg_filesd)) {
mode_t prev_umask;
prev_umask = umask(022);
buf = xbps_xasprintf("%s/.%s-files.plist", xhp->metadir, pkgname); buf = xbps_xasprintf("%s/.%s-files.plist", xhp->metadir, pkgname);
if (!xbps_dictionary_externalize_to_file(binpkg_filesd, buf)) { if (!xbps_dictionary_externalize_to_file(binpkg_filesd, buf)) {
rv = errno; rv = errno;
umask(prev_umask);
free(buf); free(buf);
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgver, "%s: [unpack] failed to externalize pkg " rv, pkgver, "%s: [unpack] failed to externalize pkg "
"pkg metadata files: %s", pkgver, strerror(rv)); "pkg metadata files: %s", pkgver, strerror(rv));
goto out; goto out;
} }
umask(prev_umask);
free(buf); free(buf);
} }
/* /*

View File

@ -216,6 +216,7 @@ int
xbps_pkgdb_update(struct xbps_handle *xhp, bool flush, bool update) xbps_pkgdb_update(struct xbps_handle *xhp, bool flush, bool update)
{ {
xbps_dictionary_t pkgdb_storage; xbps_dictionary_t pkgdb_storage;
mode_t prev_umask;
static int cached_rv; static int cached_rv;
int rv = 0; int rv = 0;
@ -227,9 +228,13 @@ xbps_pkgdb_update(struct xbps_handle *xhp, bool flush, bool update)
if (pkgdb_storage == NULL || if (pkgdb_storage == NULL ||
!xbps_dictionary_equals(xhp->pkgdb, pkgdb_storage)) { !xbps_dictionary_equals(xhp->pkgdb, pkgdb_storage)) {
/* flush dictionary to storage */ /* flush dictionary to storage */
if (!xbps_dictionary_externalize_to_file(xhp->pkgdb, xhp->pkgdb_plist)) prev_umask = umask(022);
if (!xbps_dictionary_externalize_to_file(xhp->pkgdb, xhp->pkgdb_plist)) {
umask(prev_umask);
return errno; return errno;
} }
umask(prev_umask);
}
if (pkgdb_storage) if (pkgdb_storage)
xbps_object_release(pkgdb_storage); xbps_object_release(pkgdb_storage);

View File

@ -74,6 +74,7 @@ xbps_get_remote_repo_string(const char *uri)
int HIDDEN int HIDDEN
xbps_repo_sync(struct xbps_handle *xhp, const char *uri) xbps_repo_sync(struct xbps_handle *xhp, const char *uri)
{ {
mode_t prev_umask;
const char *arch, *fetchstr = NULL; const char *arch, *fetchstr = NULL;
char *repodata, *lrepodir, *uri_fixedp; char *repodata, *lrepodir, *uri_fixedp;
int rv = 0; int rv = 0;
@ -130,6 +131,7 @@ xbps_repo_sync(struct xbps_handle *xhp, const char *uri)
/* /*
* Download plist index file from repository. * Download plist index file from repository.
*/ */
prev_umask = umask(022);
if ((rv = xbps_fetch_file(xhp, repodata, NULL)) == -1) { if ((rv = xbps_fetch_file(xhp, repodata, NULL)) == -1) {
/* reposync error cb */ /* reposync error cb */
fetchstr = xbps_fetch_error_string(); fetchstr = xbps_fetch_error_string();
@ -139,6 +141,7 @@ xbps_repo_sync(struct xbps_handle *xhp, const char *uri)
repodata, fetchstr ? fetchstr : strerror(errno)); repodata, fetchstr ? fetchstr : strerror(errno));
} else if (rv == 1) } else if (rv == 1)
rv = 0; rv = 0;
umask(prev_umask);
free(repodata); free(repodata);