Date: Sun, 9 Jul 2017 11:52:36 +0200 From: Johannes Lundberg <johalun0@gmail.com> To: Stefan Ehmann <shoesoft@gmx.net> Cc: freebsd-current <freebsd-current@freebsd.org> Subject: Re: Getting PID of socket client Message-ID: <CAECmPwuAm%2Bn6DyFR01OgatxN9Jj3um-50jOpP0jeB4=N%2Bj=yxg@mail.gmail.com> In-Reply-To: <a42d8db6-675f-b021-fc50-6ef87d310623@gmx.net> References: <CAECmPwsD=PYqoG9EA=Wyq16hcrdbf7SQ3Owxdf%2BWSvYWazJfXA@mail.gmail.com> <a42d8db6-675f-b021-fc50-6ef87d310623@gmx.net>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi Yeah I forgot to mention the LOCAL_CREDS. It does not return the PID of the client process but i guess it could be expanded to include that instead of adding another option for that. On Sun, Jul 9, 2017 at 11:47 AM, Stefan Ehmann <shoesoft@gmx.net> wrote: > 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 >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAECmPwuAm%2Bn6DyFR01OgatxN9Jj3um-50jOpP0jeB4=N%2Bj=yxg>