aboutsummaryrefslogtreecommitdiffstats
path: root/src/libunixonacid/access_at.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2025-06-30 22:04:01 +0000
committerLaurent Bercot <ska@appnovation.com>2025-06-30 22:04:01 +0000
commit17cfa0cb58bcfadb08b355eb5fd511ed6829ee5d (patch)
treec543b313369bb13e5a6a894c0c1b1fb408ef4586 /src/libunixonacid/access_at.c
parentd4895d80b1b1af9086b08f7c6cb12f274baf2ddc (diff)
downloadskalibs-17cfa0cb58bcfadb08b355eb5fd511ed6829ee5d.tar.gz
Refactor _at functions, add symlink_at
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libunixonacid/access_at.c')
-rw-r--r--src/libunixonacid/access_at.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/libunixonacid/access_at.c b/src/libunixonacid/access_at.c
index e7f988c..f974fbe 100644
--- a/src/libunixonacid/access_at.c
+++ b/src/libunixonacid/access_at.c
@@ -27,30 +27,32 @@ int access_at (int dirfd, char const *file, int amode, unsigned int flag)
#include <skalibs/djbunix.h>
#include <skalibs/unix-transactional.h>
+#include "at-internal.h"
+
+struct access_s
+{
+ char const *file ;
+ int amode ;
+} ;
+
+static int do_access (void *p)
+{
+ struct access_s *b = p ;
+ return access(b->file, b->amode) ;
+}
+
+static void cancel_access (int r, void *p)
+{
+ (void)r ;
+ (void)p ;
+}
int access_at (int dirfd, char const *file, int amode, unsigned int flag)
{
- int fdhere ;
- if (getuid() != geteuid() || getgid() != getegid())
- return (errno = ENOSYS, -1) ;
- (void)flag ;
- fdhere = openc_read(".") ;
- if (fdhere < 0) return -1 ;
- if (fd_chdir(dirfd) < 0)
- {
- fd_close(fdhere) ;
- return -1 ;
- }
- if (access(file, amode) < 0)
- {
- int e = errno ;
- fd_chdir(fdhere) ;
- fd_close(fdhere) ;
- return (errno = e, -1) ;
- }
- fd_chdir(fdhere) ;
- fd_close(fdhere) ;
- return 0 ;
+ struct access_s args = { .file = file, .amode = amode } ;
+ if (flag && (getuid() != geteuid() || getgid() != getegid()))
+ return (errno = ENOSYS, 1) ;
+ return emulate_at(dirfd, &do_access, &cancel_access, &args) ;
}
#endif