libxbps: sane umask for pkgdb and files plists
This commit is contained in:
parent
4999f3f2fc
commit
cd4c07a467
25
lib/pkgdb.c
25
lib/pkgdb.c
@ -63,23 +63,25 @@ int
|
|||||||
xbps_pkgdb_lock(struct xbps_handle *xhp)
|
xbps_pkgdb_lock(struct xbps_handle *xhp)
|
||||||
{
|
{
|
||||||
mode_t prev_umask;
|
mode_t prev_umask;
|
||||||
int rv;
|
int rv = 0;
|
||||||
/*
|
/*
|
||||||
* Use a mandatory file lock to only allow one writer to pkgdb,
|
* Use a mandatory file lock to only allow one writer to pkgdb,
|
||||||
* other writers will block.
|
* other writers will block.
|
||||||
*/
|
*/
|
||||||
|
prev_umask = umask(022);
|
||||||
xhp->pkgdb_plist = xbps_xasprintf("%s/%s", xhp->metadir, XBPS_PKGDB);
|
xhp->pkgdb_plist = xbps_xasprintf("%s/%s", xhp->metadir, XBPS_PKGDB);
|
||||||
if (xbps_pkgdb_init(xhp) == ENOENT) {
|
if (xbps_pkgdb_init(xhp) == ENOENT) {
|
||||||
/* if metadir does not exist, create it */
|
/* if metadir does not exist, create it */
|
||||||
if (access(xhp->metadir, R_OK|X_OK) == -1) {
|
if (access(xhp->metadir, R_OK|X_OK) == -1) {
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT) {
|
||||||
return errno;
|
rv = errno;
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
if (xbps_mkpath(xhp->metadir, 0755) == -1) {
|
if (xbps_mkpath(xhp->metadir, 0755) == -1) {
|
||||||
rv = errno;
|
rv = errno;
|
||||||
xbps_dbg_printf(xhp, "[pkgdb] failed to create metadir "
|
xbps_dbg_printf(xhp, "[pkgdb] failed to create metadir "
|
||||||
"%s: %s\n", xhp->metadir, strerror(rv));
|
"%s: %s\n", xhp->metadir, strerror(rv));
|
||||||
return rv;
|
goto ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* if pkgdb is unexistent, create it with an empty dictionary */
|
/* if pkgdb is unexistent, create it with an empty dictionary */
|
||||||
@ -88,27 +90,26 @@ xbps_pkgdb_lock(struct xbps_handle *xhp)
|
|||||||
rv = errno;
|
rv = errno;
|
||||||
xbps_dbg_printf(xhp, "[pkgdb] failed to create pkgdb "
|
xbps_dbg_printf(xhp, "[pkgdb] failed to create pkgdb "
|
||||||
"%s: %s\n", xhp->pkgdb_plist, strerror(rv));
|
"%s: %s\n", xhp->pkgdb_plist, strerror(rv));
|
||||||
return rv;
|
goto ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_umask = umask(022);
|
|
||||||
if ((pkgdb_fd = open(xhp->pkgdb_plist, O_CREAT|O_RDWR|O_CLOEXEC, 0664)) == -1) {
|
if ((pkgdb_fd = open(xhp->pkgdb_plist, O_CREAT|O_RDWR|O_CLOEXEC, 0664)) == -1) {
|
||||||
rv = errno;
|
rv = errno;
|
||||||
xbps_dbg_printf(xhp, "[pkgdb] cannot open pkgdb for locking "
|
xbps_dbg_printf(xhp, "[pkgdb] cannot open pkgdb for locking "
|
||||||
"%s: %s\n", xhp->pkgdb_plist, strerror(rv));
|
"%s: %s\n", xhp->pkgdb_plist, strerror(rv));
|
||||||
free(xhp->pkgdb_plist);
|
free(xhp->pkgdb_plist);
|
||||||
umask(prev_umask);
|
goto ret;
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
umask(prev_umask);
|
|
||||||
|
|
||||||
if (lockf(pkgdb_fd, F_TLOCK, 0) == -1) {
|
if (lockf(pkgdb_fd, F_TLOCK, 0) == -1) {
|
||||||
rv = errno;
|
rv = errno;
|
||||||
xbps_dbg_printf(xhp, "[pkgdb] cannot lock pkgdb: %s\n", strerror(rv));
|
xbps_dbg_printf(xhp, "[pkgdb] cannot lock pkgdb: %s\n", strerror(rv));
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
ret:
|
||||||
|
umask(prev_umask);
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user