From 4e2db52c1c2e4f2121b75d9b075d4779cc3f22e3 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Thu, 29 May 2003 16:16:59 +0000 Subject: [PATCH] * fhandler_socket.cc (fhandler_socket::dup): Rearrange. Fix conditional. --- winsup/cygwin/ChangeLog | 8 +++++- winsup/cygwin/fhandler_socket.cc | 43 ++++++++++++++++---------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 978b09c61..9fb7debcc 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2003-05-29 Pierre Humblet + Corinna Vinschen + + * fhandler_socket.cc (fhandler_socket::dup): Rearrange. Fix + conditional. + 2003-05-28 Christopher Faylor * mkvers.sh: Avoid "-dontuse" tags. @@ -9,7 +15,7 @@ (mount_info::conv_to_win32_path): Use build_win32 to build windows path. * path.h (mount_item::fnmunge): Declare new function. - (mount_item::build_win32): Ditto. + (mount_item::build_win32): Ditto. * sys/mount.h (MOUNT_ENC): Define. 2003-05-28 Corinna Vinschen diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index 0858c98a9..23914e47e 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -396,33 +396,34 @@ fhandler_socket::dup (fhandler_base *child) debug_printf ("here"); fhandler_socket *fhs = (fhandler_socket *) child; fhs->addr_family = addr_family; - fhs->set_io_handle (get_io_handle ()); if (get_addr_family () == AF_LOCAL) fhs->set_sun_path (get_sun_path ()); fhs->set_socket_type (get_socket_type ()); - /* Since WSADuplicateSocket() fails on NT systems when the process - is currently impersonating a non-privileged account, we revert - to the original account before calling WSADuplicateSocket() and - switch back afterwards as it's also in fork(). - If WSADuplicateSocket() still fails for some reason, we fall back - to DuplicateHandle(). */ - - WSASetLastError (0); - if (cygheap->user.issetuid ()) - RevertToSelf (); - fhs->fixup_before_fork_exec (GetCurrentProcessId ()); - if (cygheap->user.issetuid ()) - ImpersonateLoggedOnUser (cygheap->user.token); - if (winsock2_active && !WSAGetLastError ()) + if (winsock2_active) { - fhs->fixup_after_fork (hMainProc); - if (get_io_handle() != (HANDLE) INVALID_SOCKET) - return 0; + /* Since WSADuplicateSocket() fails on NT systems when the process + is currently impersonating a non-privileged account, we revert + to the original account before calling WSADuplicateSocket() and + switch back afterwards as it's also in fork(). + If WSADuplicateSocket() still fails for some reason, we fall back + to DuplicateHandle(). */ + WSASetLastError (0); + if (cygheap->user.issetuid ()) + RevertToSelf (); + fhs->set_io_handle (get_io_handle ()); + fhs->fixup_before_fork_exec (GetCurrentProcessId ()); + if (cygheap->user.issetuid ()) + ImpersonateLoggedOnUser (cygheap->user.token); + if (!WSAGetLastError ()) + { + fhs->fixup_after_fork (hMainProc); + if (fhs->get_io_handle() != (HANDLE) INVALID_SOCKET) + return 0; + } + debug_printf ("WSADuplicateSocket failed, trying DuplicateHandle"); } - debug_printf ("WSADuplicateSocket failed, trying DuplicateHandle"); - /* We don't call fhandler_base::dup here since that requires to have winsock called from fhandler_base and it creates only inheritable sockets which is wrong for winsock2. */ @@ -435,7 +436,7 @@ fhandler_socket::dup (fhandler_base *child) __seterrno (); return -1; } - child->set_io_handle (nh); + fhs->set_io_handle (nh); return 0; }