Skip to content

Commit

Permalink
resolves mpartel#132 add support for AF_UNIX bind on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
slonopotamus committed Jul 13, 2023
1 parent 290be5c commit cc9fca5
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/bindfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -904,10 +906,37 @@ 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));
if (res == 0)
close(fd);
} else {
res = -1;
}
#endif
} else {
res = mknod(real_path, mode, rdev);
}

if (res == -1) {
free(real_path);
return -errno;
Expand Down

0 comments on commit cc9fca5

Please sign in to comment.