Create recyclix-flow.svg
[hband-ld-preload-libs.git] / src / nofail_setfacl.c
blobd2de5ca0c6ef2ee0aa6414eba11ff1b3abc3115d
1 /*
2 * gcc -D _GNU_SOURCE -shared -fPIC -o nofail_setfacl.so nofail_setfacl.c
4 */
6 #include <dlfcn.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <unistd.h>
10 #include <string.h>
11 #include <errno.h>
12 #include <err.h>
13 #include <limits.h>
15 #define XATTRNAME "system.posix_acl_access"
16 #define NOTICEMSG "%s: Could not set acl"
17 #define NOTICEMSGFD (NOTICEMSG + 4)
18 #define SUCCESS 0
19 #define MIN(a,b) (((a)<(b))?(a):(b))
21 int setxattr (const char *path, const char *name, const void *value, size_t size, int flags)
23 int (*orig_setxattr)(const char*, const char*, const void*, size_t, int) = dlsym(RTLD_NEXT, __func__);
24 int result = orig_setxattr(path, name, value, size, flags);
26 if(result < 0 && errno == EOPNOTSUPP)
28 if(strcmp(name, XATTRNAME)==0)
30 warnx(NOTICEMSG, path);
31 result = SUCCESS;
34 return result;
37 int lsetxattr (const char *path, const char *name, const void *value, size_t size, int flags)
39 int (*orig_lsetxattr)(const char*, const char*, const void*, size_t, int) = dlsym(RTLD_NEXT, __func__);
40 int result = orig_lsetxattr(path, name, value, size, flags);
42 if(result < 0 && errno == EOPNOTSUPP)
44 if(strcmp(name, XATTRNAME)==0)
46 warnx(NOTICEMSG, path);
47 result = SUCCESS;
50 return result;
53 int fsetxattr (int fd, const char *name, const void *value, size_t size, int flags)
55 int (*orig_fsetxattr)(int, const char*, const void*, size_t, int) = dlsym(RTLD_NEXT, __func__);
56 int result = orig_fsetxattr(fd, name, value, size, flags);
58 if(result < 0 && errno == EOPNOTSUPP)
60 if(strcmp(name, XATTRNAME)==0)
62 char linkpath[PATH_MAX];
63 char path[PATH_MAX];
64 sprintf(linkpath, "/proc/self/fd/%d", fd);
65 ssize_t sz = readlink(linkpath, path, PATH_MAX);
66 path[MIN(sz, PATH_MAX-1)] = '\0';
67 warnx(NOTICEMSG, path);
68 result = SUCCESS;
71 return result;