]> xenbits.xensource.com Git - libvirt.git/commitdiff
security: update user and group parsing in security_dac.c
authorMarcelo Cerri <mhcerri@linux.vnet.ibm.com>
Mon, 8 Oct 2012 20:37:02 +0000 (17:37 -0300)
committerEric Blake <eblake@redhat.com>
Mon, 8 Oct 2012 21:20:57 +0000 (15:20 -0600)
The functions virGetUserID and virGetGroupID are now able to parse
user/group names and IDs in a similar way to coreutils' chown. So, user
and group parsing in security_dac can be simplified.

src/security/security_dac.c

index a427e9deb975eb9a459f33a34f00b880b7f2bb6d..22edba22e0f52196b8c911b074a6fda7279c0441 100644 (file)
@@ -69,8 +69,8 @@ static
 int parseIds(const char *label, uid_t *uidPtr, gid_t *gidPtr)
 {
     int rc = -1;
-    unsigned int theuid;
-    unsigned int thegid;
+    uid_t theuid;
+    gid_t thegid;
     char *tmp_label = NULL;
     char *sep = NULL;
     char *owner = NULL;
@@ -94,41 +94,12 @@ int parseIds(const char *label, uid_t *uidPtr, gid_t *gidPtr)
     owner = tmp_label;
     group = sep + 1;
 
-    /* Parse owner */
-    if (*owner == '+') {
-        if (virStrToLong_ui(++owner, NULL, 10, &theuid) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid uid \"%s\" in DAC label \"%s\""),
-                           owner, label);
-            goto cleanup;
-        }
-    } else {
-        if (virGetUserID(owner, &theuid) < 0 &&
-            virStrToLong_ui(owner, NULL, 10, &theuid) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid owner \"%s\" in DAC label \"%s\""),
-                           owner, label);
-            goto cleanup;
-        }
-    }
-
-    /* Parse group */
-    if (*group == '+') {
-        if (virStrToLong_ui(++group, NULL, 10, &thegid) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid gid \"%s\" in DAC label \"%s\""),
-                           group, label);
-            goto cleanup;
-        }
-    } else {
-        if (virGetGroupID(group, &thegid) < 0 &&
-            virStrToLong_ui(group, NULL, 10, &thegid) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid group \"%s\" in DAC label \"%s\""),
-                           group, label);
-            goto cleanup;
-        }
-    }
+    /* Parse owner and group, error message is defined by
+     * virGetUserID or virGetGroupID.
+     */
+    if (virGetUserID(owner, &theuid) < 0 ||
+        virGetGroupID(group, &thegid) < 0)
+        goto cleanup;
 
     if (uidPtr)
         *uidPtr = theuid;