From owner-freebsd-questions@FreeBSD.ORG Tue Feb 5 14:57:45 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8637C16A418 for ; Tue, 5 Feb 2008 14:57:45 +0000 (UTC) (envelope-from SRS0=2UaJgY=S2=vvelox.net=v.velox@yourhostingaccount.com) Received: from mailout07.yourhostingaccount.com (mailout07.yourhostingaccount.com [65.254.253.60]) by mx1.freebsd.org (Postfix) with ESMTP id 3B9EF13C458 for ; Tue, 5 Feb 2008 14:57:45 +0000 (UTC) (envelope-from SRS0=2UaJgY=S2=vvelox.net=v.velox@yourhostingaccount.com) Received: from mailscan19.yourhostingaccount.com ([10.1.15.19] helo=mailscan19.yourhostingaccount.com) by mailout07.yourhostingaccount.com with esmtp (Exim) id 1JMOlg-0006iP-ON for freebsd-questions@freebsd.org; Tue, 05 Feb 2008 09:27:24 -0500 Received: from impout03.yourhostingaccount.com ([10.1.55.3] helo=impout03.yourhostingaccount.com) by mailscan19.yourhostingaccount.com with esmtp (Exim) id 1JMOlg-0003Hi-8k; Tue, 05 Feb 2008 09:27:24 -0500 Received: from authsmtp08.yourhostingaccount.com ([10.1.18.8]) by impout03.yourhostingaccount.com with NO UCE id lqTP1Y00H0ASqTN0000000; Tue, 05 Feb 2008 09:27:23 -0500 X-EN-OrigOutIP: 10.1.18.8 X-EN-IMPSID: lqTP1Y00H0ASqTN0000000 Received: from c-98-206-161-17.hsd1.il.comcast.net ([98.206.161.17] helo=vixen42) by authsmtp08.yourhostingaccount.com with esmtpa (Exim) id 1JMOlf-00050u-In; Tue, 05 Feb 2008 09:27:23 -0500 Date: Tue, 5 Feb 2008 08:28:26 -0600 From: "Zane C.B." To: "Heiko Wundram (Beenic)" Message-ID: <20080205082826.03224660@vixen42> In-Reply-To: <200802041536.30469.wundram@beenic.net> References: <20080204043021.1a8ee670@vixen42> <200802041254.44475.wundram@beenic.net> <20080204082152.2129c3c6@vixen42> <200802041536.30469.wundram@beenic.net> X-Mailer: Claws Mail 3.0.2 (GTK+ 2.12.5; i386-portbld-freebsd6.3) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-EN-UserInfo: 0d1ca1697cdb7a831d4877828571b7ab:1570f0de6936c69fef9e164fffc541bc X-EN-AuthUser: vvelox2 Sender: "Zane C.B." X-EN-OrigIP: 98.206.161.17 X-EN-OrigHost: c-98-206-161-17.hsd1.il.comcast.net Cc: freebsd-questions@freebsd.org Subject: Re: unix domain socket security and PID retrieval X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Feb 2008 14:57:45 -0000 On Mon, 4 Feb 2008 15:36:30 +0100 "Heiko Wundram (Beenic)" wrote: > Am Montag, 4. Februar 2008 15:21:52 schrieb Zane C.B.: > > I've come across that mentioned in unix(4). There is no support > > for it in regards to Perl. Another problem is it requires support > > for that on both ends. > > > > More and more it looks like getting either PID and/or user info > > about the other process connecting up to it is impossible, with > > out writing some sort of authentication system for the two to use > > or both ends have to support the LOCAL_CREDS stuff. > > I cannot believe that this doesn't exist for Perl (everything > exists for Perl in one way or another...), and anyway, a quick > search on CPAN found this, which looks as though it's (at least > part of) what you're looking for: > > http://search.cpan.org/~mjp/Socket-MsgHdr-0.01/MsgHdr.pm > > Finally, thinking back to the last time I used SCM_CREDS on Linux > (which is a loooong time ago), I'm not even sure that the sender > has to send an SCM_CREDS message (which would invalidate my former > reply); I think it's enough if the receiver requests to get one > (which will be filled in by the kernel), see the description in the > referenced page above which shows you how to set up the > corresponding recvmsg call. > > Sending one is only required in case the sender is root and wants > to spoof it's credentials to the remote process (IIRC). Been spending a bit of time messing around with it and it appears to be broken. I've tried various things, but it does not seem to fetch any thing. #!/usr/bin/perl use Socket::MsgHdr; use Socket; use IO::Socket::UNIX; unlink("/tmp/testsocket"); my $listen_socket = new IO::Socket::UNIX( Local => "/tmp/testsocket", Listen=>1); while(my $conn = $listen_socket->accept){ my $inHdr = Socket::MsgHdr->new(buflen=>8192, namelen=>256); recvmsg($conn, $inHdr, LOCAL_CREDS); my $creds=$conn->sockopt(LOCAL_CREDS); print $creds; my @cmsg = $inHdr->cmsghdr(); $conn->send($#cmsg."\n"); while (my ($level, $type, $data) = splice(@cmsg, 0, 3)) { $conn->send($level."\n". $type."\n". $data."\n\n"); } $conn->close; };