Support changing UNIX socket owner in virNetSocketNewListenUNIX

This patch allows owner's UID to be changed as well.
This commit is contained in:
Jiri Denemark 2011-08-12 11:10:19 +02:00
parent 70e4295bc4
commit 5d30db09a6
4 changed files with 8 additions and 5 deletions

View File

@ -182,6 +182,7 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path,
if (virNetSocketNewListenUNIX(path, if (virNetSocketNewListenUNIX(path,
mask, mask,
-1,
grp, grp,
&svc->socks[0]) < 0) &svc->socks[0]) < 0)
goto error; goto error;

View File

@ -302,6 +302,7 @@ error:
#if HAVE_SYS_UN_H #if HAVE_SYS_UN_H
int virNetSocketNewListenUNIX(const char *path, int virNetSocketNewListenUNIX(const char *path,
mode_t mask, mode_t mask,
uid_t user,
gid_t grp, gid_t grp,
virNetSocketPtr *retsock) virNetSocketPtr *retsock)
{ {
@ -344,10 +345,10 @@ int virNetSocketNewListenUNIX(const char *path,
/* chown() doesn't work for abstract sockets but we use them only /* chown() doesn't work for abstract sockets but we use them only
* if libvirtd runs unprivileged * if libvirtd runs unprivileged
*/ */
if (grp != 0 && chown(path, -1, grp)) { if (grp != 0 && chown(path, user, grp)) {
virReportSystemError(errno, virReportSystemError(errno,
_("Failed to change group ID of '%s' to %u"), _("Failed to change ownership of '%s' to %d:%d"),
path, (unsigned int) grp); path, (int) user, (int) grp);
goto error; goto error;
} }

View File

@ -47,6 +47,7 @@ int virNetSocketNewListenTCP(const char *nodename,
int virNetSocketNewListenUNIX(const char *path, int virNetSocketNewListenUNIX(const char *path,
mode_t mask, mode_t mask,
uid_t user,
gid_t grp, gid_t grp,
virNetSocketPtr *addr); virNetSocketPtr *addr);

View 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; goto cleanup;
if (virNetSocketListen(lsock, 0) < 0) 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; goto cleanup;
if (STRNEQ(virNetSocketLocalAddrString(lsock), "127.0.0.1;0")) { if (STRNEQ(virNetSocketLocalAddrString(lsock), "127.0.0.1;0")) {