Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #132 add support for AF_UNIX bind on macOS #133

Merged
merged 1 commit into from
Jul 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 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,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;
Expand Down