[pacman-dev] [PATCH 1/2] util: Add _alpm_access_flags
This changes _alpm_access* to use faccessat, which allows behavior flags to be passed. Signed-off-by: Ryan Gonzalez <rymg19@gmail.com> --- lib/libalpm/util.c | 18 ++++++++++++------ lib/libalpm/util.h | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index a4d62c7c..8d653b16 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -1333,16 +1333,22 @@ alpm_time_t _alpm_parsedate(const char *line) return (alpm_time_t)result; } -/** Wrapper around access() which takes a dir and file argument +int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int amode) { + return _alpm_access_flags(handle, dir, file, amode, 0); +} + +/** Wrapper around faccessat() which takes a dir and file argument * separately and generates an appropriate error message. * If dir is NULL file will be treated as the whole path. * @param handle an alpm handle * @param dir directory path ending with and slash * @param file filename - * @param amode access mode as described in access() - * @return int value returned by access() + * @param amode access mode as described in faccessat() + * @param flags flags to pass as described in faccessat() + * @return int value returned by faccessat() */ -int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int amode) +int _alpm_access_flags(alpm_handle_t *handle, const char *dir, const char *file, int amode, + int flags) { size_t len = 0; int ret = 0; @@ -1354,11 +1360,11 @@ int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int a CALLOC(check_path, len, sizeof(char), RET_ERR(handle, ALPM_ERR_MEMORY, -1)); snprintf(check_path, len, "%s%s", dir, file); - ret = access(check_path, amode); + ret = faccessat(AT_FDCWD, check_path, amode, flags); free(check_path); } else { dir = ""; - ret = access(file, amode); + ret = faccessat(AT_FDCWD, file, amode, flags); } if(ret != 0) { diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 71dadc2c..1af79571 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -143,6 +143,8 @@ alpm_time_t _alpm_parsedate(const char *line); int _alpm_raw_cmp(const char *first, const char *second); int _alpm_raw_ncmp(const char *first, const char *second, size_t max); int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int amode); +int _alpm_access_flags(alpm_handle_t *handle, const char *dir, const char *file, int amode, + int flags); int _alpm_fnmatch_patterns(alpm_list_t *patterns, const char *string); int _alpm_fnmatch(const void *pattern, const void *string); void *_alpm_realloc(void **data, size_t *current, const size_t required); -- 2.23.0
Otherwise, symlinks to non-removable files will be logged as unable to be removed. Signed-off-by: Ryan Gonzalez <rymg19@gmail.com> --- lib/libalpm/remove.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 9030bfee..bb980e7d 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -339,7 +339,7 @@ static int can_remove_file(alpm_handle_t *handle, const alpm_file_t *file) /* If we fail write permissions due to a read-only filesystem, abort. * Assume all other possible failures are covered somewhere else */ - if(_alpm_access(handle, NULL, filepath, W_OK) == -1) { + if(_alpm_access_flags(handle, NULL, filepath, W_OK, AT_SYMLINK_NOFOLLOW) == -1) { if(errno != EACCES && errno != ETXTBSY && access(filepath, F_OK) == 0) { /* only return failure if the file ACTUALLY exists and we can't write to * it - ignore "chmod -w" simple permission failures */ -- 2.23.0
On 28/11/19 6:40 am, Ryan Gonzalez wrote:
Otherwise, symlinks to non-removable files will be logged as unable to be removed.
Signed-off-by: Ryan Gonzalez <rymg19@gmail.com> --- lib/libalpm/remove.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 9030bfee..bb980e7d 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -339,7 +339,7 @@ static int can_remove_file(alpm_handle_t *handle, const alpm_file_t *file)
/* If we fail write permissions due to a read-only filesystem, abort. * Assume all other possible failures are covered somewhere else */ - if(_alpm_access(handle, NULL, filepath, W_OK) == -1) { + if(_alpm_access_flags(handle, NULL, filepath, W_OK, AT_SYMLINK_NOFOLLOW) == -1) {
AT_SYMLINK_NOFOLLOW is available on Linux and MSYS2 (which are the largest users of pacman), but not BSD/OSX and we do have some users there.
if(errno != EACCES && errno != ETXTBSY && access(filepath, F_OK) == 0) { /* only return failure if the file ACTUALLY exists and we can't write to * it - ignore "chmod -w" simple permission failures */
participants (2)
-
Allan McRae
-
Ryan Gonzalez