delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/06/05/12:34:39

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Wed, 5 Jun 2002 12:34:20 -0400 (EDT)
From: David E Euresti <davie AT MIT DOT EDU>
To: Robert Collins <robert DOT collins AT itdomain DOT com DOT au>
cc: "'egor duda'" <cygwin AT cygwin DOT com>
Subject: RE: Duplicating Unix Domain Sockets
In-Reply-To: <00b101c20bc5$1b7f8500$0200a8c0@lifelesswks>
Message-ID: <Pine.GSO.4.30L.0206051218280.22895-100000@cathedral-seven.mit.edu>
MIME-Version: 1.0

Hello,
	Ideas about how to use the cygserver below.  Please comment.

On Tue, 4 Jun 2002, Robert Collins wrote:

>
>
> > -----Original Message-----
> > From: cygwin-owner AT cygwin DOT com
> > [mailto:cygwin-owner AT cygwin DOT com] On Behalf Of egor duda
>
>
> > That's what cygwin daemon is for -- to provide a
> > services that require high privileges to normal non-privileged
> > processes. After such handle duplication service (with appropriate
> > security checks) is implemented in cygwin daemon, it would be simple
> > to augment AF_UNIX sockets protocol to be able to pass auxiliary
> > information such as fds.
>
> And as the daemon's features for handle passing are complete (the tty
> code works fine), this should be easily achievable now. I don't have
> time myself, but will happily provide pointers for anyone wanting to add
> the necessary code to the cygserver.
>
> Rob


I tried to follow the code and I see that it calls Duplicate socket and
all that good stuff.
So here's the procedure as it currently works on Unix:

sender: Call sendmsg() with msghdr filled in.
receiver: Call recvmsg(), suddenly the msghdr has a file descriptor

Here are some assumptions that have to be used.
#1 The sending procedure doesn't know about the other side of the socket.
It could be a socketpair followed by a fork, or a unix socket on /tmp or
something like that.
#2 The receiving procedure doesn't know where the socket is coming
from it's coming from.
#3 There may be multiple processes trying to pass multiple file
descriptors at the same time.

So here's what I'm thinking the cygserver could do.
On a call to sendmsg() with the msghdr filled in, get the file
descriptor, extract enough information to duplicate it.  Call into
cygserver saying WriteFileDescriptor or something like that with all this
info.

The cygserver grabs it, duplicates the Handle, and stashes it away.

The receiver calls RecvMsg and in the process calls the cygserver
ReadFileDescriptor, now there may or may not be a descriptor waiting for
it.  If there is then it duplicates the handle, and creates a file
descriptor for it.

Now the big problem is how the cygserver will tell where the destination
of the file handle is.  I think, mind I say I think, that this could be
solved by calling into getpeername, but I'm not certain.

Another problem is how to tell the cygserver, and how the cygserver will
tell us, that the handle has been duplicated and we can close the handle.
(We don't want to leave stray handles flying around)

Unfortunately this means that the cygserver needs to be running for all
apps that want to use Unix domain sockets.

Comments?

David


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019