This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Duplicating Unix Domain Sockets


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

On Tue, 4 Jun 2002, Robert Collins wrote:

>
>
> > -----Original Message-----
> > From: cygwin-owner@cygwin.com
> > [mailto:cygwin-owner@cygwin.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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]