public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH 0/1] Recognizing native Windows AF_UNIX sockets
@ 2021-01-30 16:34 Ken Brown
  2021-01-30 16:34 ` [PATCH 1/1] Cygwin: recognize native Windows AF_UNIX sockets as reparse points Ken Brown
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ken Brown @ 2021-01-30 16:34 UTC (permalink / raw)
  To: cygwin-patches

This patch attempts to fix the problem reported here:

  https://cygwin.com/pipermail/cygwin/2020-September/246362.html

See also the followup here:

  https://cygwin.com/pipermail/cygwin/2021-January/247666.html

The problem, briefly, is that on certain recent versions of Windows
10, including 2004 but not 1909, native Windows AF_UNIX sockets are
represented by reparse points that Cygwin doesn't recognize.  As a
result, tools like 'ls' and 'rm' don't work.

I will get access to a machine running 2004 so I can test my patch,
but I'm posting it now in case someone else wants to test it before I
can.  To test it, compile and run the program native_unix_socket.c
appended below, and then try to remove the file foo.sock that it
creates.  This should fail on W10 2004 without my patch, but it should
succeed like this with the patch:

$ gcc -o native_unix_socket native_unix_socket.c -lws2_32

$ ./native_unix_socket.exe
getsockname works
fam = 1, len = 11
offsetof clen = 9
strlen = 8
name = foo.sock

$ ls -l foo.sock
-rwxr-xr-x 1 kbrown None 0 2021-01-30 10:46 foo.sock*

$ rm foo.sock

$ ls -l foo.sock
ls: cannot access 'foo.sock': No such file or directory

$ cat native_unix_socket.c
/* https://cygwin.com/pipermail/cygwin/2020-September/246362.html

   gcc -o native_unix_socket native_unix_socket.c -lws2_32

*/

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stddef.h>
#include <stdio.h>
/* #include <afunix.h> */

#define WIN32_LEAN_AND_MEAN

#define UNIX_PATH_MAX 108

typedef struct sockaddr_un
{
     ADDRESS_FAMILY sun_family;     /* AF_UNIX */
     char sun_path[UNIX_PATH_MAX];  /* pathname */
} SOCKADDR_UN, *PSOCKADDR_UN;

int __cdecl main(int argc, char *argv[])
{
    WSADATA wsadata;
    struct sockaddr_un addr;
    socklen_t len;
    int z = AF_UNIX;
    SOCKET s, s0;

    if (WSAStartup(MAKEWORD(2,2), &wsadata) != 0) {
        printf("STartup failed\n");
        return 0;
    }
    s0 = socket(AF_UNIX, SOCK_STREAM, 0);
    memset(&addr, 0, sizeof(addr));

    addr.sun_family = AF_UNIX;
    //strcpy(addr.sun_path, argv[1]);
    strcpy(addr.sun_path, "foo.sock");

    z = bind(s0, (const struct sockaddr *) &addr, strlen(addr.sun_path) + sizeof (addr.sun_family));
    if (z != 0) {
        printf("bind failed %ld\n", WSAGetLastError());
    }
    len = sizeof(addr);
    z = getsockname(s0, (struct sockaddr *)&addr, &len);
    if (z != 0) {
        printf("getsockname failed %ld\n", WSAGetLastError());
    } else {
        printf("getsockname works\n");
        printf("fam = %d, len = %d\n", addr.sun_family, len);
        int clen = len - offsetof(struct sockaddr_un, sun_path);
        printf("offsetof clen = %d\n", clen);
        printf("strlen = %zd\n", strlen(addr.sun_path));
        printf("name = %s\n", addr.sun_path);
    }
}

Ken Brown (1):
  Cygwin: recognize native Windows AF_UNIX sockets as reparse points

 winsup/cygwin/path.cc | 4 ++++
 1 file changed, 4 insertions(+)

-- 
2.30.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/1] Cygwin: recognize native Windows AF_UNIX sockets as reparse points
  2021-01-30 16:34 [PATCH 0/1] Recognizing native Windows AF_UNIX sockets Ken Brown
@ 2021-01-30 16:34 ` Ken Brown
  2021-01-30 20:58 ` [PATCH 0/1] Recognizing native Windows AF_UNIX sockets Ken Brown
  2021-02-01  9:54 ` Corinna Vinschen
  2 siblings, 0 replies; 4+ messages in thread
From: Ken Brown @ 2021-01-30 16:34 UTC (permalink / raw)
  To: cygwin-patches

Allow check_reparse_point_target to recognize reparse points with
reparse tag IO_REPARSE_TAG_AF_UNIX.  These are used in recent versions
of Windows 10 to represent AF_UNIX sockets.

check_reparse_point_target now returns PATH_REP on files of this type,
so that they are treated as known reparse points (but not as sockets).
This allows tools like 'rm', 'ls', etc. to operate on these files.

Addresses: https://cygwin.com/pipermail/cygwin/2020-September/246362.html
	   https://cygwin.com/pipermail/cygwin/2021-January/247666.html
---
 winsup/cygwin/path.cc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 6dc162806..9d2184d6a 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -2640,6 +2640,10 @@ check_reparse_point_target (HANDLE h, bool remote, PREPARSE_DATA_BUFFER rp,
         return PATH_REP | PATH_REP_NOAPI;
 #endif
     }
+  else if (rp->ReparseTag == IO_REPARSE_TAG_AF_UNIX)
+    /* Native Windows AF_UNIX socket; recognize this as a reparse
+       point but not as a socket. */
+    return PATH_REP;
   return 0;
 }
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/1] Recognizing native Windows AF_UNIX sockets
  2021-01-30 16:34 [PATCH 0/1] Recognizing native Windows AF_UNIX sockets Ken Brown
  2021-01-30 16:34 ` [PATCH 1/1] Cygwin: recognize native Windows AF_UNIX sockets as reparse points Ken Brown
@ 2021-01-30 20:58 ` Ken Brown
  2021-02-01  9:54 ` Corinna Vinschen
  2 siblings, 0 replies; 4+ messages in thread
From: Ken Brown @ 2021-01-30 20:58 UTC (permalink / raw)
  To: cygwin-patches

On 1/30/2021 11:34 AM, Ken Brown via Cygwin-patches wrote:
> This patch attempts to fix the problem reported here:
> 
>    https://cygwin.com/pipermail/cygwin/2020-September/246362.html
> 
> See also the followup here:
> 
>    https://cygwin.com/pipermail/cygwin/2021-January/247666.html
> 
> The problem, briefly, is that on certain recent versions of Windows
> 10, including 2004 but not 1909, native Windows AF_UNIX sockets are
> represented by reparse points that Cygwin doesn't recognize.  As a
> result, tools like 'ls' and 'rm' don't work.
> 
> I will get access to a machine running 2004 so I can test my patch,
> but I'm posting it now in case someone else wants to test it before I
> can.  To test it, compile and run the program native_unix_socket.c
> appended below, and then try to remove the file foo.sock that it
> creates.  This should fail on W10 2004 without my patch, but it should
> succeed like this with the patch:

I've just tested on W10 20H2.  In Cygwin 3.1.7 I see the problem:

$ ./native_unix_socket.exe
getsockname works
fam = 1, len = 11
offsetof clen = 9
strlen = 8
name = foo.sock

$ ls -l foo.sock
-rw-r----- 1 Unknown+User Unknown+Group 0 2021-01-30 15:51 foo.sock

$ rm foo.sock
rm: remove write-protected regular empty file 'foo.sock'? y
rm: cannot remove 'foo.sock': Permission denied

After I apply the patch, all is well:

$ ./native_unix_socket.exe
getsockname works
fam = 1, len = 11
offsetof clen = 9
strlen = 8
name = foo.sock

$ ls -l foo.sock
-rwxr-xr-x 1 kbrown None 0 2021-01-30 15:52 foo.sock*

$ rm foo.sock

$ ls -l foo.sock
ls: cannot access 'foo.sock': No such file or directory

Ken

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/1] Recognizing native Windows AF_UNIX sockets
  2021-01-30 16:34 [PATCH 0/1] Recognizing native Windows AF_UNIX sockets Ken Brown
  2021-01-30 16:34 ` [PATCH 1/1] Cygwin: recognize native Windows AF_UNIX sockets as reparse points Ken Brown
  2021-01-30 20:58 ` [PATCH 0/1] Recognizing native Windows AF_UNIX sockets Ken Brown
@ 2021-02-01  9:54 ` Corinna Vinschen
  2 siblings, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2021-02-01  9:54 UTC (permalink / raw)
  To: cygwin-patches

On Jan 30 11:34, Ken Brown via Cygwin-patches wrote:
> This patch attempts to fix the problem reported here:
> 
>   https://cygwin.com/pipermail/cygwin/2020-September/246362.html
> 
> See also the followup here:
> 
>   https://cygwin.com/pipermail/cygwin/2021-January/247666.html
> 
> The problem, briefly, is that on certain recent versions of Windows
> 10, including 2004 but not 1909, native Windows AF_UNIX sockets are
> represented by reparse points that Cygwin doesn't recognize.  As a
> result, tools like 'ls' and 'rm' don't work.

LGTM, please push.


Thanks,
Corinna

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-01  9:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-30 16:34 [PATCH 0/1] Recognizing native Windows AF_UNIX sockets Ken Brown
2021-01-30 16:34 ` [PATCH 1/1] Cygwin: recognize native Windows AF_UNIX sockets as reparse points Ken Brown
2021-01-30 20:58 ` [PATCH 0/1] Recognizing native Windows AF_UNIX sockets Ken Brown
2021-02-01  9:54 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).