From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5731 invoked by alias); 5 Jun 2002 16:34:25 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 5723 invoked from network); 5 Jun 2002 16:34:24 -0000 Received: from unknown (HELO fort-point-station.mit.edu) (18.7.7.76) by sources.redhat.com with SMTP; 5 Jun 2002 16:34:24 -0000 Received: from central-city-carrier-station.mit.edu (CENTRAL-CITY-CARRIER-STATION.MIT.EDU [18.7.7.72]) by fort-point-station.mit.edu (8.9.2/8.9.2) with ESMTP id MAA15718; Wed, 5 Jun 2002 12:34:23 -0400 (EDT) Received: from manawatu-mail-centre.mit.edu (MANAWATU-MAIL-CENTRE.MIT.EDU [18.7.7.71]) by central-city-carrier-station.mit.edu (8.9.2/8.9.2) with ESMTP id MAA25284; Wed, 5 Jun 2002 12:34:22 -0400 (EDT) Received: from cathedral-seven.mit.edu (CATHEDRAL-SEVEN.MIT.EDU [18.7.16.65]) by manawatu-mail-centre.mit.edu (8.9.2/8.9.2) with ESMTP id MAA01870; Wed, 5 Jun 2002 12:34:21 -0400 (EDT) Received: from localhost (davie@localhost) by cathedral-seven.mit.edu (8.9.3) with ESMTP id MAA25023; Wed, 5 Jun 2002 12:34:20 -0400 (EDT) Date: Wed, 05 Jun 2002 12:30:00 -0000 From: David E Euresti To: Robert Collins cc: "'egor duda'" Subject: RE: Duplicating Unix Domain Sockets In-Reply-To: <00b101c20bc5$1b7f8500$0200a8c0@lifelesswks> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2002-06/txt/msg00232.txt.bz2 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/