]> xenbits.xensource.com Git - libvirt.git/commitdiff
Replace all remaining setgid/setuid calls with virSetUIDGID
authorJiri Denemark <jdenemar@redhat.com>
Sun, 22 May 2011 14:05:07 +0000 (17:05 +0300)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 24 May 2011 09:09:53 +0000 (12:09 +0300)
Two additional places need initgroups call to properly work in an
environment where the UID is allowed to open/create stuff through its
supplementary groups.

src/storage/storage_backend.c
src/util/util.c

index b423d110fc979a30e0f670ca770eaba1e4538878..02e455fac64c006a7b34d798ebafeb5d787559ca 100644 (file)
@@ -535,20 +535,9 @@ static int virStorageBuildSetUIDHook(void *data) {
     if (tmp->skip)
         return 0;
 
-    if ((vol->target.perms.gid != -1)
-        && (setgid(vol->target.perms.gid) != 0)) {
-        virReportSystemError(errno,
-                             _("Cannot set gid to %u before creating %s"),
-                             vol->target.perms.gid, vol->target.path);
-        return -1;
-    }
-    if ((vol->target.perms.uid != -1)
-        && (setuid(vol->target.perms.uid) != 0)) {
-        virReportSystemError(errno,
-                             _("Cannot set uid to %u before creating %s"),
-                             vol->target.perms.uid, vol->target.path);
+    if (virSetUIDGID(vol->target.perms.uid, vol->target.perms.gid) < 0)
         return -1;
-    }
+
     return 0;
 }
 
index 0b4370b93493512f13bab86bdddc80b6e59eee1a..e221abeed527ad41b1c45e22feae996bee6a3e44 100644 (file)
@@ -1476,18 +1476,8 @@ parenterror:
 
     /* set desired uid/gid, then attempt to create the file */
 
-    if ((gid != 0) && (setgid(gid) != 0)) {
+    if (virSetUIDGID(uid, gid) < 0) {
         ret = -errno;
-        virReportSystemError(errno,
-                             _("cannot set gid %u creating '%s'"),
-                             (unsigned int) gid, path);
-        goto childerror;
-    }
-    if  ((uid != 0) && (setuid(uid) != 0)) {
-        ret = -errno;
-        virReportSystemError(errno,
-                             _("cannot set uid %u creating '%s'"),
-                             (unsigned int) uid, path);
         goto childerror;
     }
     if ((fd = open(path, openflags, mode)) < 0) {
@@ -1595,16 +1585,8 @@ parenterror:
 
     /* set desired uid/gid, then attempt to create the directory */
 
-    if ((gid != 0) && (setgid(gid) != 0)) {
-        ret = -errno;
-        virReportSystemError(errno, _("cannot set gid %u creating '%s'"),
-                             (unsigned int) gid, path);
-        goto childerror;
-    }
-    if  ((uid != 0) && (setuid(uid) != 0)) {
+    if (virSetUIDGID(uid, gid) < 0) {
         ret = -errno;
-        virReportSystemError(errno, _("cannot set uid %u creating '%s'"),
-                             (unsigned int) uid, path);
         goto childerror;
     }
     if (mkdir(path, mode) < 0) {