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

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).