From owner-freebsd-current@freebsd.org Sun Jul 9 09:47:24 2017 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D00AEDAEA4C for ; Sun, 9 Jul 2017 09:47:24 +0000 (UTC) (envelope-from shoesoft@gmx.net) Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "mout.gmx.net", Issuer "TeleSec ServerPass DE-2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2C3137ECC8 for ; Sun, 9 Jul 2017 09:47:23 +0000 (UTC) (envelope-from shoesoft@gmx.net) Received: from walrus.pepperland ([81.217.71.61]) by mail.gmx.com (mrgmx102 [212.227.17.168]) with ESMTPSA (Nemesis) id 0MB1C4-1dMPZ92XuW-009vRB; Sun, 09 Jul 2017 11:47:15 +0200 Subject: Re: Getting PID of socket client To: Johannes Lundberg , freebsd-current References: From: Stefan Ehmann Message-ID: Date: Sun, 9 Jul 2017 11:47:14 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:Vi8wFS0jkUnZ8SssDSdsTm2wxRk4DZMizBbFtXbxdAQeSmc9S4j 9ke5H0TFKxXGUwWNSW+0YU1wX9AYeiAevqE4t60bjqa8IBvhulJoqxafmpe3vRT+AtctDT1 ZOOMZFXXQ6rRMxZqISGGkvexoyYhEDNrM7NFhlJ3lZ4aVNVLM8feNBw6kxugCTDV9A34elB PLs+Yv+RlxSZuUqCciimA== X-UI-Out-Filterresults: notjunk:1;V01:K0:axHOzCSzM/g=:kElE03lrzlWXIbtEPpgXRa 4zWxR8ASOqE36jJcbPmUjBel8YX8skRjUVRyIwgvrKFv0D0bjuebybE3pLJ55Xtvx4oMHP0TG KoVRI3Za1jEYKhOuQMlu8LI32sYZciccebXcZ6stWuctFke4VAFfTov2nkdU+cWcjvCnr8UHD CaVUflIlDagi9PyQzWz2L9t1G0E6wDpxI+nJtHVd1fY7GQTNp2w5ocPbWbEP8oNWTdlzV3h3Q Ow2W2DCr2sHAMMk4iBKbe08UIwR0IpbepcWrocYcPa9LeQYjHoAPWnVnvRG/r7cGGVot975j4 u7YTQiNoYrqxXuc5DAojRKdMPdKtehbzyQM2Jyxo1wdVACUhKZgR8aereWz0U7QKPtUrq467A ByizReGJ8LhAYTQ5I+0XT7Wrf2a3ZRBZr7eNXGVRhwRVbrf3Y6dlLaW2dyq12X7Nth8s9gexE LnVZuk0n06HGhuT5MGkIlK1YHr+EnR8qhMI4FfVehDDj1a8aY3H8xPXFGOZzb3rLXnVor/Vsp Vj4FngqlHclFMWFgqKlI3TgczUH+khNBVGX5ty3WK4Ey9cJjS3ebf3bc5IGBQu/PO4gyHPo53 CSkaf53phKPUid+97GYU7eubK+ncaTbPP0BQX8AeSzBzG2xevCoZBTd3pHhFr+V0/WTmGsAAv 1+U62DbmTGbCxnq7w0iqZ+4VGn42XcAo6pmE0t5sWFe6FPm8booPinUB8ev97nq3X9fdGu5KR WxL+ePVMqA5oHlWfXWBZXskVtyZw3QMsov5qNUFPz4JNhskq2+BQ0pnJi61iIxO137QjX/eSr D9dn+x2 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Jul 2017 09:47:24 -0000 On 09.07.2017 10:03, Johannes Lundberg wrote: > Hi > > Without altering the client code (i.e. adding sendmsg(credentials)), is > there anyway of getting the client PID (or path to binary) using the file > descriptor returned by accept() on the server side? > > Similar to Linux's getsockopt with SO_PEERCRED option. You want the LOCAL_CREDS socket option from unix(4). There's also a FreeBSD sample in the UNIX network programming book. Source is available from http://unpbook.com/src.html With the following two changes it seems to work for me: unixstrserv02.c: set LOCAL_CREDS readcred.c: disable CONTROL_LEN check $ ./unixstrserv02 PID of sender = 1001 real user ID = 1001 real group ID = 1001 effective user ID = 1001 3 groups: 0 5 920