From 7d243cd43b7c8a9ecb9cb9752bd978aa0f6d3f95 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 9 Mar 2005 23:00:20 +0000 Subject: [PATCH] * fhandler_socket.cc (fhandler_socket::eid_pipe_name): Fix format string. (fhandler_socket::connect): Set sun_path before running eid credential transaction. Run transaction only if OS connect was successful. (fhandler_socket::accept): Run transaction only if OS accept was successful. --- winsup/cygwin/ChangeLog | 11 +++- winsup/cygwin/fhandler_socket.cc | 94 +++++++++++++++++--------------- 2 files changed, 61 insertions(+), 44 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index a7c6e409f..3f74133b6 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,4 +1,13 @@ -2005-03-08 Corinna Vinschen +2005-03-09 Corinna Vinschen + + * fhandler_socket.cc (fhandler_socket::eid_pipe_name): Fix format + string. + (fhandler_socket::connect): Set sun_path before running eid credential + transaction. Run transaction only if OS connect was successful. + (fhandler_socket::accept): Run transaction only if OS accept was + successful. + +2005-03-09 Corinna Vinschen * signal.cc (sigprocmask): Rename first parameter to "how". (handle_sigprocmask): Ditto. Check "how" for being a valid "how" value. diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index 9dcd63959..f3e57ee17 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -56,7 +56,8 @@ secret_event_name (char *buf, short port, int *secret_ptr) char * fhandler_socket::eid_pipe_name (char *buf) { - __small_sprintf (buf, "\\\\.\\pipe\\cygwin-unix-$s", get_sun_path ()); + __small_sprintf (buf, "\\\\.\\pipe\\cygwin-unix-%s", get_sun_path ()); + debug_printf ("%s", buf); return buf; } @@ -666,30 +667,34 @@ fhandler_socket::connect (const struct sockaddr *name, int namelen) res = -1; } - /* eid credential transaction. */ - if (wincap.has_named_pipes ()) + if (!res || in_progress) { - struct ucred in = { getpid (), geteuid32 (), getegid32 () }; - struct ucred out = { (pid_t) 0, (__uid32_t) -1, (__gid32_t) -1 }; - DWORD bytes = 0; - if (CallNamedPipe(eid_pipe_name ((char *) alloca (CYG_MAX_PATH + 1)), - &in, sizeof in, &out, sizeof out, &bytes, 1000)) + /* eid credential transaction. */ + set_sun_path (name->sa_data); + if (wincap.has_named_pipes ()) { - debug_printf ("Received eid credentials: pid: %d, uid: %d, gid: %d", - out.pid, out.uid, out.gid); - sec_peer_pid = out.pid; - sec_peer_uid = out.uid; - sec_peer_gid = out.gid; + struct ucred in = { getpid (), geteuid32 (), getegid32 () }; + struct ucred out = { (pid_t) 0, (__uid32_t) -1, (__gid32_t) -1 }; + DWORD bytes = 0; + if (CallNamedPipe(eid_pipe_name ((char *) alloca (CYG_MAX_PATH + 1)), + &in, sizeof in, &out, sizeof out, &bytes, 1000)) + { + debug_printf ("Received eid credentials: pid: %d, uid: %d" + ", gid: %d", out.pid, out.uid, out.gid); + sec_peer_pid = out.pid; + sec_peer_uid = out.uid; + sec_peer_gid = out.gid; + } + else + debug_printf ("Receiving eid credentials failed: %E"); + } + else /* 9x */ + { + /* Incorrect but wrong pid at least doesn't break getpeereid. */ + sec_peer_pid = getpid (); + sec_peer_uid = geteuid32 (); + sec_peer_gid = getegid32 (); } - else - debug_printf ("Receiving eid credentials failed: %E"); - } - else /* 9x */ - { - /* Incorrect but wrong pid at least doesn't break getpeereid. */ - sec_peer_pid = getpid (); - sec_peer_uid = geteuid32 (); - sec_peer_gid = getegid32 (); } } @@ -796,31 +801,34 @@ fhandler_socket::accept (struct sockaddr *peer, int *len) return -1; } - /* eid credential transaction. */ - if (wincap.has_named_pipes ()) + if ((SOCKET) res != INVALID_SOCKET || in_progress) { - DWORD bytes = 0; - bool ret = ConnectNamedPipe (sec_pipe, NULL); - if (ret || GetLastError () == ERROR_PIPE_CONNECTED) + /* eid credential transaction. */ + if (wincap.has_named_pipes ()) { - if (!ReadFile (sec_pipe, &out, sizeof out, &bytes, NULL)) - debug_printf ("Receiving eid credentials failed: %E"); + DWORD bytes = 0; + bool ret = ConnectNamedPipe (sec_pipe, NULL); + if (ret || GetLastError () == ERROR_PIPE_CONNECTED) + { + if (!ReadFile (sec_pipe, &out, sizeof out, &bytes, NULL)) + debug_printf ("Receiving eid credentials failed: %E"); + else + debug_printf ("Received eid credentials: pid: %d, uid: %d" + ", gid: %d", out.pid, out.uid, out.gid); + if (!WriteFile (sec_pipe, &in, sizeof in, &bytes, NULL)) + debug_printf ("Sending eid credentials failed: %E"); + DisconnectNamedPipe (sec_pipe); + } else - debug_printf ("Received eid credentials: pid: %d, uid: %d, gid: %d", - out.pid, out.uid, out.gid); - if (!WriteFile (sec_pipe, &in, sizeof in, &bytes, NULL)) - debug_printf ("Sending eid credentials failed: %E"); - DisconnectNamedPipe (sec_pipe); + debug_printf ("Connecting the eid credential pipe failed: %E"); + } + else /* 9x */ + { + /* Incorrect but wrong pid at least doesn't break getpeereid. */ + out.pid = sec_pid; + out.uid = sec_uid; + out.gid = sec_gid; } - else - debug_printf ("Connecting the eid credential pipe failed: %E"); - } - else /* 9x */ - { - /* Incorrect but wrong pid at least doesn't break getpeereid. */ - out.pid = sec_pid; - out.uid = sec_uid; - out.gid = sec_gid; } }