public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: Allow to set SO_PEERCRED zero (v2)
Date: Mon,  7 Dec 2020 15:30:15 +0000 (GMT)	[thread overview]
Message-ID: <20201207153015.CC7AC3894C35@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=9e573ba50f129bff7b6e1be10cf4bbcb70f1efdd

commit 9e573ba50f129bff7b6e1be10cf4bbcb70f1efdd
Author: Mark Geisert <mark@maxrnd.com>
Date:   Mon Dec 7 02:29:36 2020 -0800

    Cygwin: Allow to set SO_PEERCRED zero (v2)
    
    The existing code errors as EINVAL any attempt to set a value for
    SO_PEERCRED via setsockopt() on an AF_UNIX/AF_LOCAL socket.  But to
    enable the workaround set_no_getpeereid behavior for Python one has
    to be able to set SO_PEERCRED to zero.  Ergo, this patch.  Python has
    no way to specify a NULL pointer for 'optval'.
    
    This v2 of patch allows the original working (i.e., allow NULL,0 for
    optval,optlen to mean turn off SO_PEERCRED) in addition to the new
    working described above.  The sense of the 'if' stmt is reversed for
    readability.

Diff:
---
 winsup/cygwin/fhandler_socket_local.cc | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/fhandler_socket_local.cc b/winsup/cygwin/fhandler_socket_local.cc
index c94bf828f..964f3e819 100644
--- a/winsup/cygwin/fhandler_socket_local.cc
+++ b/winsup/cygwin/fhandler_socket_local.cc
@@ -1430,10 +1430,14 @@ fhandler_socket_local::setsockopt (int level, int optname, const void *optval,
 	     FIXME: In the long run we should find a more generic solution
 	     which doesn't require a blocking handshake in accept/connect
 	     to exchange SO_PEERCRED credentials. */
-	  if (optval || optlen)
-	    set_errno (EINVAL);
-	  else
+	  /* Temporary: Allow SO_PEERCRED to only be zeroed. Two ways to
+	     accomplish this: pass NULL,0 for optval,optlen; or pass the
+	     address,length of an '(int) 0' set up by the caller. */
+	  if ((!optval && !optlen) ||
+		(optlen == (socklen_t) sizeof (int) && !*(int *) optval))
 	    ret = af_local_set_no_getpeereid ();
+	  else
+	    set_errno (EINVAL);
 	  return ret;
 
 	case SO_REUSEADDR:


                 reply	other threads:[~2020-12-07 15:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201207153015.CC7AC3894C35@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).