Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 9 Jul 2017 10:40:18 +0200
From:      Johannes Lundberg <johalun0@gmail.com>
To:        freebsd-current <freebsd-current@freebsd.org>
Subject:   Re: Getting PID of socket client
Message-ID:  <CAECmPwuP3LV2Z_kZWojC_K9Lv%2BsGuM27Ec0XuotjcEPGrZCruw@mail.gmail.com>
In-Reply-To: <CAECmPwsD=PYqoG9EA=Wyq16hcrdbf7SQ3Owxdf%2BWSvYWazJfXA@mail.gmail.com>
References:  <CAECmPwsD=PYqoG9EA=Wyq16hcrdbf7SQ3Owxdf%2BWSvYWazJfXA@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
follow-up

Seems like at least OpenBSD implemented SO_PEERCRED which returns a struct
sockpeercred.

/* Read using getsockopt() with SOL_SOCKET, SO_PEERCRED */
struct sockpeercred {
uid_t uid; /* effective user id */
gid_t gid; /* effective group id */
pid_t pid;
};

If not anyone is oppose to this or know some other secret API that provides
similar functionality, I can see if I can put together a patch for this
very useful API.



On Sun, Jul 9, 2017 at 10:03 AM, Johannes Lundberg <johalun0@gmail.com>
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.
>
> Thanks!
>
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAECmPwuP3LV2Z_kZWojC_K9Lv%2BsGuM27Ec0XuotjcEPGrZCruw>