From patchwork Mon Nov 14 13:09:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: akos.pasztory@gmail.com X-Patchwork-Id: 125523 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 58F28B71F5 for ; Tue, 15 Nov 2011 00:10:04 +1100 (EST) Received: from localhost ([::1]:45497 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RPwIT-0005xI-Fu for incoming@patchwork.ozlabs.org; Mon, 14 Nov 2011 08:10:01 -0500 Received: from eggs.gnu.org ([140.186.70.92]:56183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RPwIN-0005x1-VC for qemu-devel@nongnu.org; Mon, 14 Nov 2011 08:09:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RPwIN-0000wC-0E for qemu-devel@nongnu.org; Mon, 14 Nov 2011 08:09:55 -0500 Received: from smtp.nokia.com ([147.243.128.24]:45638 helo=mgw-da01.nokia.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RPwIM-0000vf-Qp for qemu-devel@nongnu.org; Mon, 14 Nov 2011 08:09:54 -0500 Received: from forgotten.research.nokia.com ([172.21.23.154]) by mgw-da01.nokia.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id pAED9iPu023078; Mon, 14 Nov 2011 15:09:44 +0200 From: akos.pasztory@gmail.com To: qemu-devel@nongnu.org Date: Mon, 14 Nov 2011 15:09:49 +0200 Message-Id: <1321276189-20673-1-git-send-email-akos.pasztory@gmail.com> X-Mailer: git-send-email 1.7.7.2 X-Nokia-AV: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) X-Received-From: 147.243.128.24 Cc: riku.voipio@iki.fi Subject: [Qemu-devel] [PATCH] linux-user: add SO_PEERCRED support for getsockopt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Akos PASZTORY Signed-off-by: Akos PASZTORY --- linux-user/syscall.c | 34 +++++++++++++++++++++++++++++++++- linux-user/syscall_defs.h | 6 ++++++ 2 files changed, 39 insertions(+), 1 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f227097..47b2c7e 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1530,9 +1530,41 @@ static abi_long do_getsockopt(int sockfd, int level, int optname, case TARGET_SO_LINGER: case TARGET_SO_RCVTIMEO: case TARGET_SO_SNDTIMEO: - case TARGET_SO_PEERCRED: case TARGET_SO_PEERNAME: goto unimplemented; + case TARGET_SO_PEERCRED: { + struct ucred cr; + socklen_t crlen; + struct target_ucred *tcr; + + if (get_user_u32(len, optlen)) { + return -TARGET_EFAULT; + } + if (len < 0) { + return -TARGET_EINVAL; + } + + crlen = sizeof(cr); + ret = get_errno(getsockopt(sockfd, level, SO_PEERCRED, + &cr, &crlen)); + if (ret < 0) { + return ret; + } + if (len > crlen) { + len = crlen; + } + if (!lock_user_struct(VERIFY_WRITE, tcr, optval_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(cr.pid, &tcr->pid); + __put_user(cr.uid, &tcr->uid); + __put_user(cr.gid, &tcr->gid); + unlock_user_struct(tcr, optval_addr, 1); + if (put_user_u32(len, optlen)) { + return -TARGET_EFAULT; + } + break; + } /* Options with 'int' argument. */ case TARGET_SO_DEBUG: optname = SO_DEBUG; diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 9dd1b8e..7af6122 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -2336,3 +2336,9 @@ struct target_rlimit64 { uint64_t rlim_cur; uint64_t rlim_max; }; + +struct target_ucred { + uint32_t pid; + uint32_t uid; + uint32_t gid; +};