From owner-freebsd-current@freebsd.org Sun Jul 9 09:52:39 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 319A4DAEC35 for ; Sun, 9 Jul 2017 09:52:39 +0000 (UTC) (envelope-from johalun0@gmail.com) Received: from mail-wr0-x22a.google.com (mail-wr0-x22a.google.com [IPv6:2a00:1450:400c:c0c::22a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D703A7F079 for ; Sun, 9 Jul 2017 09:52:38 +0000 (UTC) (envelope-from johalun0@gmail.com) Received: by mail-wr0-x22a.google.com with SMTP id 77so100664839wrb.1 for ; Sun, 09 Jul 2017 02:52:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=74f7uDC5k03b4DeUBSEIyXBw0OlHnVTtS5YH/XmyzBU=; b=HhmstPwsT7e8WQ+NTujRFJSF7gRRnndCRbkpWxqmj571vhBp+cNnytFREtWXJdgG5g e7uhOdEY0+ahIJyqPQ8WtTJRp2CuHrYn3Uh/oN+badR5Ck9vM1ekU90JCKMuw/1oozLn ompEn+poxnCQ4Cx+PXK/MRYghkh76az2JIBV0U7n3W2vH3gMllSgs85Pu+0VL45+nKJe Kfx0ZanyfJPzJ9osEAW6n18a/+ovqvzeNm6Zw2wpnfg4jRlyrz41FdFo3WeVXvN694G3 fxBtgmOb9Fd7vuyWCBwYxxf/dZgJXAlY20rptGIOI5DOWXTVtrF3RbemFIL2/2erLRg0 8+Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=74f7uDC5k03b4DeUBSEIyXBw0OlHnVTtS5YH/XmyzBU=; b=ekDyvn8F+BIYybQcuELk2VjViR/Ugrmd39bI5kJZNdWmdN3+mWh6FjrVc9GDBPl6LJ bZ6io0iDXBkVSFyCNKFRQOU0u3LWHCiIJElMUUyVWhXKi4YfnE9g0iFS9N1HNZxKLw09 QyWCHprcY8jjB7EA7aomrVNJmBjUpO3VTtfSNnIP+SlIuwCDzHOw1tTuq416QvaE0k94 McfXlNXPIEsxW84Ad940sSYjnPwMIDREKOsDUmoZj3lZauTDfqkjx0DuiSwLx4oJbb/w Z3CWhCoyQaseD/hGzoGtkC2A229Xsl8m4lV6iAsNfiBHqERI3Jk5gGpy7vdncUZC9Imb EOEg== X-Gm-Message-State: AIVw112Kez4immcedSnN/s/YLj05M4UTVaErLrc/eD05IG+vBvGY03iw w/c61VfRIDMmOP2kOUmhJRSgKeEOWg== X-Received: by 10.28.4.141 with SMTP id 135mr4329784wme.21.1499593957342; Sun, 09 Jul 2017 02:52:37 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.154.193 with HTTP; Sun, 9 Jul 2017 02:52:36 -0700 (PDT) In-Reply-To: References: From: Johannes Lundberg Date: Sun, 9 Jul 2017 11:52:36 +0200 Message-ID: Subject: Re: Getting PID of socket client To: Stefan Ehmann Cc: freebsd-current Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.23 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:52:39 -0000 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 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 >