提交 59cf0398 编写于 作者: D Daniel P. Berrange

Also retrieve GID from SO_PEERCRED

* daemon/remote.c, src/rpc/virnetserverclient.c,
  src/rpc/virnetserverclient.h, src/rpc/virnetsocket.c,
  src/rpc/virnetsocket.h: Add gid parameter
上级 4c82f09e
...@@ -2030,6 +2030,7 @@ remoteDispatchAuthList(virNetServerPtr server ATTRIBUTE_UNUSED, ...@@ -2030,6 +2030,7 @@ remoteDispatchAuthList(virNetServerPtr server ATTRIBUTE_UNUSED,
int rv = -1; int rv = -1;
int auth = virNetServerClientGetAuth(client); int auth = virNetServerClientGetAuth(client);
uid_t callerUid; uid_t callerUid;
gid_t callerGid;
pid_t callerPid; pid_t callerPid;
/* If the client is root then we want to bypass the /* If the client is root then we want to bypass the
...@@ -2037,7 +2038,7 @@ remoteDispatchAuthList(virNetServerPtr server ATTRIBUTE_UNUSED, ...@@ -2037,7 +2038,7 @@ remoteDispatchAuthList(virNetServerPtr server ATTRIBUTE_UNUSED,
* some piece of polkit isn't present/running * some piece of polkit isn't present/running
*/ */
if (auth == VIR_NET_SERVER_SERVICE_AUTH_POLKIT) { if (auth == VIR_NET_SERVER_SERVICE_AUTH_POLKIT) {
if (virNetServerClientGetLocalIdentity(client, &callerUid, &callerPid) < 0) { if (virNetServerClientGetLocalIdentity(client, &callerUid, &callerGid, &callerPid) < 0) {
/* Don't do anything on error - it'll be validated at next /* Don't do anything on error - it'll be validated at next
* phase of auth anyway */ * phase of auth anyway */
virResetLastError(); virResetLastError();
...@@ -2463,6 +2464,7 @@ remoteDispatchAuthPolkit(virNetServerPtr server ATTRIBUTE_UNUSED, ...@@ -2463,6 +2464,7 @@ remoteDispatchAuthPolkit(virNetServerPtr server ATTRIBUTE_UNUSED,
remote_auth_polkit_ret *ret) remote_auth_polkit_ret *ret)
{ {
pid_t callerPid = -1; pid_t callerPid = -1;
gid_t callerGid = -1;
uid_t callerUid = -1; uid_t callerUid = -1;
const char *action; const char *action;
int status = -1; int status = -1;
...@@ -2493,7 +2495,7 @@ remoteDispatchAuthPolkit(virNetServerPtr server ATTRIBUTE_UNUSED, ...@@ -2493,7 +2495,7 @@ remoteDispatchAuthPolkit(virNetServerPtr server ATTRIBUTE_UNUSED,
goto authfail; goto authfail;
} }
if (virNetServerClientGetLocalIdentity(client, &callerUid, &callerPid) < 0) { if (virNetServerClientGetLocalIdentity(client, &callerUid, &callerGid, &callerPid) < 0) {
goto authfail; goto authfail;
} }
...@@ -2563,6 +2565,7 @@ remoteDispatchAuthPolkit(virNetServerPtr server, ...@@ -2563,6 +2565,7 @@ remoteDispatchAuthPolkit(virNetServerPtr server,
remote_auth_polkit_ret *ret) remote_auth_polkit_ret *ret)
{ {
pid_t callerPid; pid_t callerPid;
gid_t callerGid;
uid_t callerUid; uid_t callerUid;
PolKitCaller *pkcaller = NULL; PolKitCaller *pkcaller = NULL;
PolKitAction *pkaction = NULL; PolKitAction *pkaction = NULL;
...@@ -2590,7 +2593,7 @@ remoteDispatchAuthPolkit(virNetServerPtr server, ...@@ -2590,7 +2593,7 @@ remoteDispatchAuthPolkit(virNetServerPtr server,
goto authfail; goto authfail;
} }
if (virNetServerClientGetLocalIdentity(client, &callerUid, &callerPid) < 0) { if (virNetServerClientGetLocalIdentity(client, &callerUid, &callerGid, &callerPid) < 0) {
VIR_ERROR(_("cannot get peer socket identity")); VIR_ERROR(_("cannot get peer socket identity"));
goto authfail; goto authfail;
} }
......
...@@ -448,12 +448,12 @@ int virNetServerClientGetFD(virNetServerClientPtr client) ...@@ -448,12 +448,12 @@ int virNetServerClientGetFD(virNetServerClientPtr client)
} }
int virNetServerClientGetLocalIdentity(virNetServerClientPtr client, int virNetServerClientGetLocalIdentity(virNetServerClientPtr client,
uid_t *uid, pid_t *pid) uid_t *uid, gid_t *gid, pid_t *pid)
{ {
int ret = -1; int ret = -1;
virNetServerClientLock(client); virNetServerClientLock(client);
if (client->sock) if (client->sock)
ret = virNetSocketGetLocalIdentity(client->sock, uid, pid); ret = virNetSocketGetLocalIdentity(client->sock, uid, gid, pid);
virNetServerClientUnlock(client); virNetServerClientUnlock(client);
return ret; return ret;
} }
......
...@@ -71,7 +71,7 @@ int virNetServerClientSetIdentity(virNetServerClientPtr client, ...@@ -71,7 +71,7 @@ int virNetServerClientSetIdentity(virNetServerClientPtr client,
const char *virNetServerClientGetIdentity(virNetServerClientPtr client); const char *virNetServerClientGetIdentity(virNetServerClientPtr client);
int virNetServerClientGetLocalIdentity(virNetServerClientPtr client, int virNetServerClientGetLocalIdentity(virNetServerClientPtr client,
uid_t *uid, pid_t *pid); uid_t *uid, gid_t *gid, pid_t *pid);
void virNetServerClientRef(virNetServerClientPtr client); void virNetServerClientRef(virNetServerClientPtr client);
......
...@@ -826,6 +826,7 @@ int virNetSocketGetPort(virNetSocketPtr sock) ...@@ -826,6 +826,7 @@ int virNetSocketGetPort(virNetSocketPtr sock)
#ifdef SO_PEERCRED #ifdef SO_PEERCRED
int virNetSocketGetLocalIdentity(virNetSocketPtr sock, int virNetSocketGetLocalIdentity(virNetSocketPtr sock,
uid_t *uid, uid_t *uid,
gid_t *gid,
pid_t *pid) pid_t *pid)
{ {
struct ucred cr; struct ucred cr;
...@@ -841,6 +842,7 @@ int virNetSocketGetLocalIdentity(virNetSocketPtr sock, ...@@ -841,6 +842,7 @@ int virNetSocketGetLocalIdentity(virNetSocketPtr sock,
*pid = cr.pid; *pid = cr.pid;
*uid = cr.uid; *uid = cr.uid;
*gid = cr.gid;
virMutexUnlock(&sock->lock); virMutexUnlock(&sock->lock);
return 0; return 0;
...@@ -848,6 +850,7 @@ int virNetSocketGetLocalIdentity(virNetSocketPtr sock, ...@@ -848,6 +850,7 @@ int virNetSocketGetLocalIdentity(virNetSocketPtr sock,
#else #else
int virNetSocketGetLocalIdentity(virNetSocketPtr sock ATTRIBUTE_UNUSED, int virNetSocketGetLocalIdentity(virNetSocketPtr sock ATTRIBUTE_UNUSED,
uid_t *uid ATTRIBUTE_UNUSED, uid_t *uid ATTRIBUTE_UNUSED,
gid_t *gid ATTRIBUTE_UNUSED,
pid_t *pid ATTRIBUTE_UNUSED) pid_t *pid ATTRIBUTE_UNUSED)
{ {
/* XXX Many more OS support UNIX socket credentials we could port to. See dbus ....*/ /* XXX Many more OS support UNIX socket credentials we could port to. See dbus ....*/
......
...@@ -88,6 +88,7 @@ int virNetSocketGetPort(virNetSocketPtr sock); ...@@ -88,6 +88,7 @@ int virNetSocketGetPort(virNetSocketPtr sock);
int virNetSocketGetLocalIdentity(virNetSocketPtr sock, int virNetSocketGetLocalIdentity(virNetSocketPtr sock,
uid_t *uid, uid_t *uid,
gid_t *gid,
pid_t *pid); pid_t *pid);
int virNetSocketSetBlocking(virNetSocketPtr sock, int virNetSocketSetBlocking(virNetSocketPtr sock,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册