diff options
author | Marat Radchenko <marat@slonopotamus.org> | 2023-07-14 00:59:48 +0300 |
---|---|---|
committer | Marat Radchenko <marat@slonopotamus.org> | 2023-07-14 23:10:06 +0300 |
commit | 445c6eded6f438ae964738a85dac745b8dc178eb (patch) | |
tree | 8834f8e116a6e8a25afabe92efa736c95a5245ae | |
parent | 290be5c929f8dd1d65d0a3dbaaab8c1870b54196 (diff) | |
download | bindfs-445c6eded6f438ae964738a85dac745b8dc178eb.tar.gz |
resolves #132 add support for AF_UNIX bind on macOS
-rw-r--r-- | src/bindfs.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/bindfs.c b/src/bindfs.c index 00a7592..40fe960 100644 --- a/src/bindfs.c +++ b/src/bindfs.c @@ -94,6 +94,8 @@ /* Apple Structs */ #ifdef __APPLE__ #include <sys/param.h> +#include <sys/socket.h> +#include <sys/un.h> #define G_PREFIX "org" #define G_KAUTH_FILESEC_XATTR G_PREFIX ".apple.system.Security" #define A_PREFIX "com" @@ -904,10 +906,36 @@ static int bindfs_mknod(const char *path, mode_t mode, dev_t rdev) mode = permchain_apply(settings.create_permchain, mode); - if (S_ISFIFO(mode)) + if (S_ISFIFO(mode)) { res = mkfifo(real_path, mode); - else +#ifdef __APPLE__ + } else if (S_ISSOCK(mode)) { + struct sockaddr_un su; + int fd; + + if (strlen(real_path) >= sizeof(su.sun_path)) { + errno = ENAMETOOLONG; + return -1; + } + fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd >= 0) { + /* + * We must bind the socket to the underlying file + * system to create the socket file, even though + * we'll never listen on this socket. + */ + su.sun_family = AF_UNIX; + strncpy(su.sun_path, real_path, sizeof(su.sun_path)); + res = bind(fd, (struct sockaddr*)&su, sizeof(su)); + close(fd); + } else { + res = -1; + } +#endif + } else { res = mknod(real_path, mode, rdev); + } + if (res == -1) { free(real_path); return -errno; |