From owner-freebsd-current@freebsd.org Sun Jul 9 08:40:20 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 B299EDADC16 for ; Sun, 9 Jul 2017 08:40:20 +0000 (UTC) (envelope-from johalun0@gmail.com) Received: from mail-wr0-x22e.google.com (mail-wr0-x22e.google.com [IPv6:2a00:1450:400c:c0c::22e]) (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 4D6147D531 for ; Sun, 9 Jul 2017 08:40:20 +0000 (UTC) (envelope-from johalun0@gmail.com) Received: by mail-wr0-x22e.google.com with SMTP id c11so99414720wrc.3 for ; Sun, 09 Jul 2017 01:40:20 -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; bh=28JalXDUcYqZHx8tV/VkYmkaUpPmdmvXAYEp3jm6eGY=; b=EwaasLP+VbN/Xg29j3JvFOaOwr38oF1c0CFRowkkjEjEH3gpDWYaZWEIg3RIWG4pkB HSlTfhwlKTEmT72e2i+JfQXIRL+10in4Tfxcb2tQiijSNsxTZ9ID4QNmoEwEL+NYYcw6 jzbG6xt+wYrHkyAi03OyduM93iaewUbsuNHAT/ZF2noCX4qL8+0ZpymDlVdFXajeA8qE 9mk7MgRCx7A0RePdM/1lmY9DbIUkDTTylg2UUfXviZBjMVL1CTf9pFun1k4w58LPvv1L 3i8fIQCSuSa2bM/MQF3rWGNzIxN5a7ED0qVF23G2+FWMQgDX6PY8JDqBBgf2Y/oVF3C7 xBkw== 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; bh=28JalXDUcYqZHx8tV/VkYmkaUpPmdmvXAYEp3jm6eGY=; b=JwXCD+rTLsYzOFEo1ghgq2WaQc/Tv8U8dW1/7/sXeHmoEmy0GjL2X2SyAmJRNhGyHQ r06HBq+AokerDcdTcbW18W51NEr0HrWxO61lnJa8XN3VdLq2dk9Usv5zoB7OBNjYMIr6 4UYzFeeo/PtYUhQq4rEBmwwRJ/St0rFJY8avIqguXxi8zSi+qjg7oWHz/XA8r7FuT2RZ 8EOv4ufzoXN/9c3XqZoZTJd52L6Tk8bAuBo+vWwYHxRZSCy9a3vdV8uIzl1iFhCTD56m d3o0Uvdqe6uRipBNu8OXgp8C8yM6zcuZC9e26bGNQGelrqp6X6/3gizBWPXyY4TS+qPP 25EQ== X-Gm-Message-State: AIVw111Ldse+d8snAvkdvzcdKoDIvhYTRZsPaHm+MNFy5Xz87o5LFWGG 5kgIG8tY0nLpvddWkNewRYTN86vqnNty X-Received: by 10.223.171.181 with SMTP id s50mr4863773wrc.129.1499589618697; Sun, 09 Jul 2017 01:40:18 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.154.193 with HTTP; Sun, 9 Jul 2017 01:40:18 -0700 (PDT) In-Reply-To: References: From: Johannes Lundberg Date: Sun, 9 Jul 2017 10:40:18 +0200 Message-ID: Subject: Re: Getting PID of socket client To: 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 08:40:20 -0000 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 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! > >