43fe83
From 0401b6b48f3743fb819cfe494d1b23ecb8796198 Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <0401b6b48f3743fb819cfe494d1b23ecb8796198.1379597659.git.jdenemar@redhat.com>
43fe83
From: "Daniel P. Berrange" <berrange@redhat.com>
43fe83
Date: Thu, 22 Aug 2013 16:00:01 +0100
43fe83
Subject: [PATCH] Also store user & group ID values in virIdentity
43fe83
43fe83
https://bugzilla.redhat.com/show_bug.cgi?id=1006272
43fe83
43fe83
Future improvements to the polkit code will require access to
43fe83
the numeric user ID, not merely user name.
43fe83
43fe83
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
43fe83
(cherry picked from commit db7a5688c05f3fd60d9d2b74c72427eb9ee9c176)
43fe83
---
43fe83
 src/rpc/virnetserverclient.c | 18 ++++++++++++++++++
43fe83
 src/util/viridentity.c       | 23 +++++++++++++++++++----
43fe83
 src/util/viridentity.h       |  2 ++
43fe83
 3 files changed, 39 insertions(+), 4 deletions(-)
43fe83
43fe83
diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c
43fe83
index 83d5cf1..19c4100 100644
43fe83
--- a/src/rpc/virnetserverclient.c
43fe83
+++ b/src/rpc/virnetserverclient.c
43fe83
@@ -652,7 +652,9 @@ virNetServerClientCreateIdentity(virNetServerClientPtr client)
43fe83
     char *processid = NULL;
43fe83
     char *processtime = NULL;
43fe83
     char *username = NULL;
43fe83
+    char *userid = NULL;
43fe83
     char *groupname = NULL;
43fe83
+    char *groupid = NULL;
43fe83
 #if WITH_SASL
43fe83
     char *saslname = NULL;
43fe83
 #endif
43fe83
@@ -672,8 +674,12 @@ virNetServerClientCreateIdentity(virNetServerClientPtr client)
43fe83
 
43fe83
         if (!(username = virGetUserName(uid)))
43fe83
             goto cleanup;
43fe83
+        if (virAsprintf(&userid, "%d", (int)uid) < 0)
43fe83
+            goto cleanup;
43fe83
         if (!(groupname = virGetGroupName(gid)))
43fe83
             goto cleanup;
43fe83
+        if (virAsprintf(&userid, "%d", (int)gid) < 0)
43fe83
+            goto cleanup;
43fe83
         if (virAsprintf(&processid, "%llu",
43fe83
                         (unsigned long long)pid) < 0)
43fe83
             goto cleanup;
43fe83
@@ -710,11 +716,21 @@ virNetServerClientCreateIdentity(virNetServerClientPtr client)
43fe83
                            VIR_IDENTITY_ATTR_UNIX_USER_NAME,
43fe83
                            username) < 0)
43fe83
         goto error;
43fe83
+    if (userid &&
43fe83
+        virIdentitySetAttr(ret,
43fe83
+                           VIR_IDENTITY_ATTR_UNIX_USER_ID,
43fe83
+                           userid) < 0)
43fe83
+        goto error;
43fe83
     if (groupname &&
43fe83
         virIdentitySetAttr(ret,
43fe83
                            VIR_IDENTITY_ATTR_UNIX_GROUP_NAME,
43fe83
                            groupname) < 0)
43fe83
         goto error;
43fe83
+    if (groupid &&
43fe83
+        virIdentitySetAttr(ret,
43fe83
+                           VIR_IDENTITY_ATTR_UNIX_GROUP_ID,
43fe83
+                           groupid) < 0)
43fe83
+        goto error;
43fe83
     if (processid &&
43fe83
         virIdentitySetAttr(ret,
43fe83
                            VIR_IDENTITY_ATTR_UNIX_PROCESS_ID,
43fe83
@@ -745,7 +761,9 @@ virNetServerClientCreateIdentity(virNetServerClientPtr client)
43fe83
 
43fe83
 cleanup:
43fe83
     VIR_FREE(username);
43fe83
+    VIR_FREE(userid);
43fe83
     VIR_FREE(groupname);
43fe83
+    VIR_FREE(groupid);
43fe83
     VIR_FREE(processid);
43fe83
     VIR_FREE(processtime);
43fe83
     VIR_FREE(seccontext);
43fe83
diff --git a/src/util/viridentity.c b/src/util/viridentity.c
43fe83
index 781f660..03c375b 100644
43fe83
--- a/src/util/viridentity.c
43fe83
+++ b/src/util/viridentity.c
43fe83
@@ -133,7 +133,9 @@ int virIdentitySetCurrent(virIdentityPtr ident)
43fe83
 virIdentityPtr virIdentityGetSystem(void)
43fe83
 {
43fe83
     char *username = NULL;
43fe83
+    char *userid = NULL;
43fe83
     char *groupname = NULL;
43fe83
+    char *groupid = NULL;
43fe83
     char *seccontext = NULL;
43fe83
     virIdentityPtr ret = NULL;
43fe83
 #if WITH_SELINUX
43fe83
@@ -147,8 +149,13 @@ virIdentityPtr virIdentityGetSystem(void)
43fe83
 
43fe83
     if (!(username = virGetUserName(getuid())))
43fe83
         goto cleanup;
43fe83
+    if (virAsprintf(&userid, "%d", (int)getuid()) < 0)
43fe83
+        goto cleanup;
43fe83
+
43fe83
     if (!(groupname = virGetGroupName(getgid())))
43fe83
         goto cleanup;
43fe83
+    if (virAsprintf(&groupid, "%d", (int)getgid()) < 0)
43fe83
+        goto cleanup;
43fe83
 
43fe83
 #if WITH_SELINUX
43fe83
     if (getcon(&con) < 0) {
43fe83
@@ -166,16 +173,22 @@ virIdentityPtr virIdentityGetSystem(void)
43fe83
     if (!(ret = virIdentityNew()))
43fe83
         goto cleanup;
43fe83
 
43fe83
-    if (username &&
43fe83
-        virIdentitySetAttr(ret,
43fe83
+    if (virIdentitySetAttr(ret,
43fe83
                            VIR_IDENTITY_ATTR_UNIX_USER_NAME,
43fe83
                            username) < 0)
43fe83
         goto error;
43fe83
-    if (groupname &&
43fe83
-        virIdentitySetAttr(ret,
43fe83
+    if (virIdentitySetAttr(ret,
43fe83
+                           VIR_IDENTITY_ATTR_UNIX_USER_ID,
43fe83
+                           userid) < 0)
43fe83
+        goto error;
43fe83
+    if (virIdentitySetAttr(ret,
43fe83
                            VIR_IDENTITY_ATTR_UNIX_GROUP_NAME,
43fe83
                            groupname) < 0)
43fe83
         goto error;
43fe83
+    if (virIdentitySetAttr(ret,
43fe83
+                           VIR_IDENTITY_ATTR_UNIX_GROUP_ID,
43fe83
+                           groupid) < 0)
43fe83
+        goto error;
43fe83
     if (seccontext &&
43fe83
         virIdentitySetAttr(ret,
43fe83
                            VIR_IDENTITY_ATTR_SELINUX_CONTEXT,
43fe83
@@ -188,7 +201,9 @@ virIdentityPtr virIdentityGetSystem(void)
43fe83
 
43fe83
 cleanup:
43fe83
     VIR_FREE(username);
43fe83
+    VIR_FREE(userid);
43fe83
     VIR_FREE(groupname);
43fe83
+    VIR_FREE(groupid);
43fe83
     VIR_FREE(seccontext);
43fe83
     VIR_FREE(processid);
43fe83
     return ret;
43fe83
diff --git a/src/util/viridentity.h b/src/util/viridentity.h
43fe83
index 4bae8d6..a240c2d 100644
43fe83
--- a/src/util/viridentity.h
43fe83
+++ b/src/util/viridentity.h
43fe83
@@ -29,7 +29,9 @@ typedef virIdentity *virIdentityPtr;
43fe83
 
43fe83
 typedef enum {
43fe83
       VIR_IDENTITY_ATTR_UNIX_USER_NAME,
43fe83
+      VIR_IDENTITY_ATTR_UNIX_USER_ID,
43fe83
       VIR_IDENTITY_ATTR_UNIX_GROUP_NAME,
43fe83
+      VIR_IDENTITY_ATTR_UNIX_GROUP_ID,
43fe83
       VIR_IDENTITY_ATTR_UNIX_PROCESS_ID,
43fe83
       VIR_IDENTITY_ATTR_UNIX_PROCESS_TIME,
43fe83
       VIR_IDENTITY_ATTR_SASL_USER_NAME,
43fe83
-- 
43fe83
1.8.3.2
43fe83