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 0b0e91ebfbb..33414f47a24 100644 --- a/server/fd.c +++ b/server/fd.c @@ -1971,6 +1971,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 ); }
+ /* POSIX requires that open(2) throws EOPNOTSUPP when `path` is a UNIX + * socket. *BSD throws EOPNOTSUPP in this case and the additional case of + * O_SHLOCK or O_EXLOCK being passed when `path` resides on a filesystem + * without lock support. + * + * Contrary to POSIX, Linux returns ENXIO in this case, so we also check + * that error code here. */ + if ((errno == EOPNOTSUPP || 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 */