Subject: Re: Duplicating Unix Domain Sockets
From: egor duda <[email-masked]>
To: David E Euresti <[email-masked]>
Cc: [email-masked]
Date: Tue, 4 Jun 2002 10:16:30 +0400

Hi!

Tuesday, 04 June, 2002 David E Euresti [email-masked] wrote:

DEE> Allright.  So I have two solutions.
DEE> (And tell me if I should direct this to the folks at cygwin-devel)

I believe most, if not all subscribers of cygwin-developers@ are
reading cygwin@ mailing list.

DEE> #1
DEE> Make cygwin be able to implement the Ancillary data as in 4.3+BSD as
DEE> described in section 15.3.3 in Advanced Programming in the Unix
DEE> Environment.

DEE> To implement this, I would tag all messages sent on Unix domain sockets
DEE> with a tag like this:
DEE> struct tag {
DEE>         int adatalen; // Length of ancillary data
DEE>         int rdatalen; // Length of real data
DEE> }

DEE> Then when you receive it your first read the tag and if there is ancillary
DEE> data read it and do what you need to do (convert the info into an fd) and
DEE> then read the rdatalen.  If there is more rdatalen than the length of
DEE> buffer sent to you, you return what you can, and remember how much is
DEE> left.

DEE> This is obviously a big task, and opinions would be quite welcome.

DEE> #2
DEE> Just add a function that says, create_fd_from_handle_plus were I can
DEE> pass in all the parameters that the sending process could send, and so
DEE> that the same file descriptor gets created.  The problem with this is that
DEE> getting the info from one process to another (IPC?) is up to the
DEE> programmer.

It's not enough to just pass numerical value of descriptor between
processes. Each cygwin fd has several win32 handles associated with
it, which are used to actually do the job, to read or write the data,
to perform synchronization, etc. If you want to pass fd1 from proc1 to
proc2, you have to duplicate all win32 handles associated with fd1
into address space of proc2. This can be done by DuplicateHandle ()
function, but if you take a look on its docs on msdn, you'll see that
it requires process handles of proc1 and proc2 to work. Given that
proc1 and proc2 can be absolutely unrelated and run from different
accounts, there's no secure way to obtain those process handles
without help from some mediator process which run at high enough level
of privileges. 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.

Egor.            mailto:[email-masked] ICQ 5165414 FidoNet 2:5020/496.19

--
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/