Skip to contentSkip to conversation

linux-user: add SO_PEERCRED support for getsockopt

PATCH New [email protected] 1 participant 1 message Nov 14, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: add SO_PEERCRED support for getsockopt

From: Akos PASZTORY <[email protected]>

---
 linux-user/syscall.c      |   34 +++++++++++++++++++++++++++++++++-
 linux-user/syscall_defs.h |    6 ++++++
 2 files changed, 39 insertions(+), 1 deletions(-)
linux-user/syscall.c +33 -1
index f227097..47b2c7e 100644
@@ -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;
linux-user/syscall_defs.h +6 -0
index 9dd1b8e..7af6122 100644
@@ -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;
+};
Signature · 1 line
1.7.7.2