aboutsummaryrefslogtreecommitdiff
path: root/linux-user/syscall.c
diff options
context:
space:
mode:
authorAkos PASZTORY <akos.pasztory@gmail.com>2011-11-14 15:09:49 +0200
committerRiku Voipio <riku.voipio@linaro.org>2012-02-02 17:51:20 +0200
commit583359a68922fb91b793a5ad3a2dd4536bf9b99e (patch)
treedca8f47fd7c756c9dba65ba3b519b6c556e5d3c2 /linux-user/syscall.c
parent50171d42071d492b916f737b227bc6f3751fee7c (diff)
linux-user: add SO_PEERCRED support for getsockopt
Signed-off-by: Akos PASZTORY <akos.pasztory@gmail.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
Diffstat (limited to 'linux-user/syscall.c')
-rw-r--r--linux-user/syscall.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index c6bfcd8815..15b8b22936 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;