]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Support changing UNIX socket owner in virNetSocketNewListenUNIX
authorJiri Denemark <jdenemar@redhat.com>
Fri, 12 Aug 2011 09:10:19 +0000 (11:10 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 15 Aug 2011 13:21:31 +0000 (15:21 +0200)
This patch allows owner's UID to be changed as well.

src/rpc/virnetserverservice.c
src/rpc/virnetsocket.c
src/rpc/virnetsocket.h
tests/virnetsockettest.c

index e63603f288fbb609ebd1d9af09e89d24bf82165c..28202a43073c96701135162b831ee4f59c8b2b64 100644 (file)
@@ -182,6 +182,7 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path,
 
     if (virNetSocketNewListenUNIX(path,
                                   mask,
+                                  -1,
                                   grp,
                                   &svc->socks[0]) < 0)
         goto error;
index d040aed212adcdad771679760daac1fcfa6bbc5b..82a11d85e156e628757762bad8144a5a36a84ce4 100644 (file)
@@ -302,6 +302,7 @@ error:
 #if HAVE_SYS_UN_H
 int virNetSocketNewListenUNIX(const char *path,
                               mode_t mask,
+                              uid_t user,
                               gid_t grp,
                               virNetSocketPtr *retsock)
 {
@@ -344,10 +345,10 @@ int virNetSocketNewListenUNIX(const char *path,
     /* chown() doesn't work for abstract sockets but we use them only
      * if libvirtd runs unprivileged
      */
-    if (grp != 0 && chown(path, -1, grp)) {
+    if (grp != 0 && chown(path, user, grp)) {
         virReportSystemError(errno,
-                             _("Failed to change group ID of '%s' to %u"),
-                             path, (unsigned int) grp);
+                             _("Failed to change ownership of '%s' to %d:%d"),
+                             path, (int) user, (int) grp);
         goto error;
     }
 
index 24110a6d4742fb97c51961e9b704037b5e0464b6..f7e5ebbb78f824f6f59d72365347f0260f8f6276 100644 (file)
@@ -47,6 +47,7 @@ int virNetSocketNewListenTCP(const char *nodename,
 
 int virNetSocketNewListenUNIX(const char *path,
                               mode_t mask,
+                              uid_t user,
                               gid_t grp,
                               virNetSocketPtr *addr);
 
index fba7e15be711571ab08e1c43732a43c454a83c74..fae15a30020dfa491719e533631886dd22f7c0d4 100644 (file)
@@ -214,7 +214,7 @@ static int testSocketUNIXAccept(const void *data ATTRIBUTE_UNUSED)
         }
     }
 
-    if (virNetSocketNewListenUNIX(path, 0700, getgid(), &lsock) < 0)
+    if (virNetSocketNewListenUNIX(path, 0700, -1, getgid(), &lsock) < 0)
         goto cleanup;
 
     if (virNetSocketListen(lsock, 0) < 0)
@@ -263,7 +263,7 @@ static int testSocketUNIXAddrs(const void *data ATTRIBUTE_UNUSED)
         }
     }
 
-    if (virNetSocketNewListenUNIX(path, 0700, getgid(), &lsock) < 0)
+    if (virNetSocketNewListenUNIX(path, 0700, -1, getgid(), &lsock) < 0)
         goto cleanup;
 
     if (STRNEQ(virNetSocketLocalAddrString(lsock), "127.0.0.1;0")) {