[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH RFC 01/12] Remove hack using existance of an 'identity' string to disable auth



From: "Daniel P. Berrange" <berrange redhat com>

Currently the server determines whether authentication of clients
is complete, by checking whether an identity is set. This patch
removes that lame hack and replaces it with an explicit method
for changing the client auth code

* daemon/remote.c: Update for new APis
* src/libvirt_private.syms, src/rpc/virnetserverclient.c,
  src/rpc/virnetserverclient.h: Remove virNetServerClientGetIdentity
  and virNetServerClientSetIdentity, adding a new method
  virNetServerClientSetAuth.
---
 daemon/remote.c              |   14 +++++---------
 src/libvirt_private.syms     |    2 +-
 src/rpc/virnetserverclient.c |   36 ++++++++----------------------------
 src/rpc/virnetserverclient.h |    5 +----
 4 files changed, 15 insertions(+), 42 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 3b8ccd9..362a25a 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -2048,10 +2048,8 @@ remoteDispatchAuthList(virNetServerPtr server ATTRIBUTE_UNUSED,
             if (rv > 0 || rv < sizeof ident) {
                 VIR_INFO("Bypass polkit auth for privileged client %s",
                          ident);
-                if (virNetServerClientSetIdentity(client, ident) < 0)
-                    virResetLastError();
-                else
-                    auth = VIR_NET_SERVER_SERVICE_AUTH_NONE;
+                virNetServerClientSetAuth(client, 0);
+                auth = VIR_NET_SERVER_SERVICE_AUTH_NONE;
             }
             rv = -1;
         }
@@ -2191,9 +2189,7 @@ remoteSASLFinish(virNetServerClientPtr client)
     if (!virNetSASLContextCheckIdentity(saslCtxt, identity))
         return -2;
 
-    if (virNetServerClientSetIdentity(client, identity) < 0)
-        goto error;
-
+    virNetServerClientSetAuth(client, 0);
     virNetServerClientSetSASLSession(client, priv->sasl);
 
     VIR_DEBUG("Authentication successful %d", virNetServerClientGetFD(client));
@@ -2530,7 +2526,7 @@ remoteDispatchAuthPolkit(virNetServerPtr server ATTRIBUTE_UNUSED,
              action, callerPid, callerUid);
     ret->complete = 1;
 
-    virNetServerClientSetIdentity(client, ident);
+    virNetServerClientSetAuth(client, 0);
     virMutexUnlock(&priv->lock);
 
     return 0;
@@ -2668,8 +2664,8 @@ remoteDispatchAuthPolkit(virNetServerPtr server,
              action, callerPid, callerUid,
              polkit_result_to_string_representation(pkresult));
     ret->complete = 1;
-    virNetServerClientSetIdentity(client, ident);
 
+    virNetServerClientSetAuth(client, 0);
     virMutexUnlock(&priv->lock);
     return 0;
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a0530b1..363f316 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1303,8 +1303,8 @@ virNetServerClientRef;
 virNetServerClientRemoteAddrString;
 virNetServerClientRemoveFilter;
 virNetServerClientSendMessage;
+virNetServerClientSetAuth;
 virNetServerClientSetCloseHook;
-virNetServerClientSetIdentity;
 virNetServerClientSetPrivateData;
 virNetServerClientStartKeepAlive;
 
diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c
index 67600fd..81dbb32 100644
--- a/src/rpc/virnetserverclient.c
+++ b/src/rpc/virnetserverclient.c
@@ -67,7 +67,6 @@ struct _virNetServerClient
     virNetSocketPtr sock;
     int auth;
     bool readonly;
-    char *identity;
     virNetTLSContextPtr tlsCtxt;
     virNetTLSSessionPtr tls;
 #if HAVE_SASL
@@ -408,6 +407,13 @@ int virNetServerClientGetAuth(virNetServerClientPtr client)
     return auth;
 }
 
+void virNetServerClientSetAuth(virNetServerClientPtr client, int auth)
+{
+    virNetServerClientLock(client);
+    client->auth = auth;
+    virNetServerClientUnlock(client);
+}
+
 bool virNetServerClientGetReadonly(virNetServerClientPtr client)
 {
     bool readonly;
@@ -492,31 +498,6 @@ void virNetServerClientSetSASLSession(virNetServerClientPtr client,
 #endif
 
 
-int virNetServerClientSetIdentity(virNetServerClientPtr client,
-                                  const char *identity)
-{
-    int ret = -1;
-    virNetServerClientLock(client);
-    if (!(client->identity = strdup(identity))) {
-        virReportOOMError();
-        goto error;
-    }
-    ret = 0;
-
-error:
-    virNetServerClientUnlock(client);
-    return ret;
-}
-
-const char *virNetServerClientGetIdentity(virNetServerClientPtr client)
-{
-    const char *identity;
-    virNetServerClientLock(client);
-    identity = client->identity;
-    virNetServerClientLock(client);
-    return identity;
-}
-
 void virNetServerClientSetPrivateData(virNetServerClientPtr client,
                                       void *opaque,
                                       virNetServerClientFreeFunc ff)
@@ -600,7 +581,6 @@ void virNetServerClientFree(virNetServerClientPtr client)
         client->privateDataFreeFunc)
         client->privateDataFreeFunc(client->privateData);
 
-    VIR_FREE(client->identity);
 #if HAVE_SASL
     virNetSASLSessionFree(client->sasl);
 #endif
@@ -1130,7 +1110,7 @@ bool virNetServerClientNeedAuth(virNetServerClientPtr client)
 {
     bool need = false;
     virNetServerClientLock(client);
-    if (client->auth && !client->identity)
+    if (client->auth)
         need = true;
     virNetServerClientUnlock(client);
     return need;
diff --git a/src/rpc/virnetserverclient.h b/src/rpc/virnetserverclient.h
index 154a160..633e9e1 100644
--- a/src/rpc/virnetserverclient.h
+++ b/src/rpc/virnetserverclient.h
@@ -52,6 +52,7 @@ void virNetServerClientRemoveFilter(virNetServerClientPtr client,
                                     int filterID);
 
 int virNetServerClientGetAuth(virNetServerClientPtr client);
+void virNetServerClientSetAuth(virNetServerClientPtr client, int auth);
 bool virNetServerClientGetReadonly(virNetServerClientPtr client);
 
 bool virNetServerClientHasTLSSession(virNetServerClientPtr client);
@@ -66,10 +67,6 @@ int virNetServerClientGetFD(virNetServerClientPtr client);
 
 bool virNetServerClientIsSecure(virNetServerClientPtr client);
 
-int virNetServerClientSetIdentity(virNetServerClientPtr client,
-                                  const char *identity);
-const char *virNetServerClientGetIdentity(virNetServerClientPtr client);
-
 int virNetServerClientGetUNIXIdentity(virNetServerClientPtr client,
                                       uid_t *uid, gid_t *gid, pid_t *pid);
 
-- 
1.7.7.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]