[scan] Use open()/close() instead of euidaccess() to support ACL's

Fixes #474
This commit is contained in:
ejurgensen 2018-01-06 20:10:34 +01:00
parent 8d043dd9e9
commit 45d193e56c
2 changed files with 17 additions and 11 deletions

View File

@ -53,7 +53,7 @@ AC_CHECK_HEADERS([sys/wait.h sys/param.h dirent.h getopt.h stdint.h], [],
[AC_MSG_ERROR([[Missing header required to build forked-daapd]])]) [AC_MSG_ERROR([[Missing header required to build forked-daapd]])])
AC_CHECK_HEADERS([time.h], [], AC_CHECK_HEADERS([time.h], [],
[AC_MSG_ERROR([[Missing header required to build forked-daapd]])]) [AC_MSG_ERROR([[Missing header required to build forked-daapd]])])
AC_CHECK_FUNCS_ONCE([posix_fadvise euidaccess pipe2]) AC_CHECK_FUNCS_ONCE([posix_fadvise pipe2])
AC_CHECK_FUNCS([strptime strtok_r], [], AC_CHECK_FUNCS([strptime strtok_r], [],
[AC_MSG_ERROR([[Missing function required to build forked-daapd]])]) [AC_MSG_ERROR([[Missing function required to build forked-daapd]])])

View File

@ -1058,6 +1058,7 @@ process_inotify_dir(struct watch_info *wi, char *path, struct inotify_event *ie)
int flags = 0; int flags = 0;
int ret; int ret;
int parent_id; int parent_id;
int fd;
DPRINTF(E_DBG, L_SCAN, "Directory event: 0x%x, cookie 0x%x, wd %d\n", ie->mask, ie->cookie, wi->wd); DPRINTF(E_DBG, L_SCAN, "Directory event: 0x%x, cookie 0x%x, wd %d\n", ie->mask, ie->cookie, wi->wd);
@ -1151,11 +1152,11 @@ process_inotify_dir(struct watch_info *wi, char *path, struct inotify_event *ie)
free(wi->path); free(wi->path);
wi->path = s; wi->path = s;
#ifdef HAVE_EUIDACCESS // We don't use access() or euidaccess() because they don't work with ACL's
if (euidaccess(path, (R_OK | X_OK)) < 0) // - this also means we can't check for executable permission, which stat()
#else // will require
if (access(path, (R_OK | X_OK)) < 0) fd = open(path, O_RDONLY);
#endif if (fd < 0)
{ {
DPRINTF(E_LOG, L_SCAN, "Directory access to '%s' failed: %s\n", path, strerror(errno)); DPRINTF(E_LOG, L_SCAN, "Directory access to '%s' failed: %s\n", path, strerror(errno));
@ -1176,6 +1177,9 @@ process_inotify_dir(struct watch_info *wi, char *path, struct inotify_event *ie)
{ {
DPRINTF(E_INFO, L_SCAN, "Directory event, but '%s' already being watched\n", path); DPRINTF(E_INFO, L_SCAN, "Directory event, but '%s' already being watched\n", path);
} }
if (fd > 0)
close(fd);
} }
if (ie->mask & IN_CREATE) if (ie->mask & IN_CREATE)
@ -1202,6 +1206,7 @@ process_inotify_file(struct watch_info *wi, char *path, struct inotify_event *ie
int type; int type;
int i; int i;
int dir_id; int dir_id;
int fd;
char *ptr; char *ptr;
int ret; int ret;
@ -1237,11 +1242,9 @@ process_inotify_file(struct watch_info *wi, char *path, struct inotify_event *ie
return; return;
} }
#ifdef HAVE_EUIDACCESS // We don't use access() or euidaccess() because they don't work with ACL's
if (euidaccess(path, R_OK) < 0) fd = open(path, O_RDONLY);
#else if (fd < 0)
if (access(path, R_OK) < 0)
#endif
{ {
DPRINTF(E_LOG, L_SCAN, "File access to '%s' failed: %s\n", path, strerror(errno)); DPRINTF(E_LOG, L_SCAN, "File access to '%s' failed: %s\n", path, strerror(errno));
@ -1254,6 +1257,9 @@ process_inotify_file(struct watch_info *wi, char *path, struct inotify_event *ie
ie->mask |= IN_CLOSE_WRITE; ie->mask |= IN_CLOSE_WRITE;
} }
if (fd > 0)
close(fd);
} }
if (ie->mask & IN_MOVED_TO) if (ie->mask & IN_MOVED_TO)