aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Pärtel <martin.partel@gmail.com>2023-07-15 14:59:53 +0300
committerGitHub <noreply@github.com>2023-07-15 14:59:53 +0300
commitaff180a0607e1b6f4060fc9cbe70b10831b1b234 (patch)
tree62261e53e35ffc43569cf0480e1a8905877893e0
parentae0c8e730693bacf42b2eac9ccd0dd3350bf9d4b (diff)
parent445c6eded6f438ae964738a85dac745b8dc178eb (diff)
downloadbindfs-aff180a0607e1b6f4060fc9cbe70b10831b1b234.tar.gz
Merge pull request #133 from slonopotamus/unix-sockets-on-macos
resolves #132 add support for AF_UNIX bind on macOS
-rw-r--r--src/bindfs.c32
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;