From: Ally Sommers dropbear.sh@gmail.com
Deleting the socket file is a common pattern with AF_UNIX sockets, and is analogous to unbinding. --- server/fd.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
diff --git a/server/fd.c b/server/fd.c index eaebe044f37..8697b07070a 100644 --- a/server/fd.c +++ b/server/fd.c @@ -1957,6 +1957,24 @@ struct fd *open_fd( struct fd *root, const char *name, struct unicode_str nt_nam fd->unix_fd = open( name, O_RDONLY | (flags & ~(O_TRUNC | O_CREAT | O_EXCL)), *mode ); }
+ /* open(3) throws ENXIO when `path` is one of: + * 1. a FIFO, and open(3) is called with O_WRONLY | O_NONBLOCK, + * and no other process is currently attempting to read from `path`. + * 2. a special device file, and the device it corresponds to does not exist. + * 3. a UNIX socket. + * We can confirm the third case to allow for unlinking a socket. + */ + if (errno == ENXIO && !stat( name, &st ) && S_ISSOCK(st.st_mode)) + { + if ((access & DELETE) && unlink( name )) + { + file_set_error(); + goto error; + } + else + fd->unix_fd = open( name, O_CREAT | O_RDWR, S_IRWXU ); + } + if (fd->unix_fd == -1) { /* check for trailing slash on file path */