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

[libvirt] [PATCH v1 05/10] driver_lockd: Implement seclabel APIs



This is the client side, so there's nothing more we need to do
than call the RPC. Although, there's one interesting change: new
virLockManagerLockSeclabelConnect() had to be implemented since the
VIR_LOCK_SPACE_PROTOCOL_PROGRAM doesn't have any ConnectOpen()
procedure.

Signed-off-by: Michal Privoznik <mprivozn redhat com>
---
 src/locking/lock_driver_lockd.c | 114 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 109 insertions(+), 5 deletions(-)

diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c
index 4bb5925..cce88ac 100644
--- a/src/locking/lock_driver_lockd.c
+++ b/src/locking/lock_driver_lockd.c
@@ -31,6 +31,7 @@
 #include "virerror.h"
 #include "rpc/virnetclient.h"
 #include "lock_protocol.h"
+#include "lock_seclabel_protocol.h"
 #include "configmake.h"
 #include "virstring.h"
 
@@ -239,7 +240,9 @@ virLockManagerLockDaemonConnectionRestrict(virLockManagerPtr lock ATTRIBUTE_UNUS
 
 
 static virNetClientPtr virLockManagerLockDaemonConnectionNew(bool privileged,
-                                                             virNetClientProgramPtr *prog)
+                                                             virNetClientProgramPtr *prog,
+                                                             unsigned int prog_magic,
+                                                             unsigned int prog_version)
 {
     virNetClientPtr client = NULL;
     char *lockdpath;
@@ -263,8 +266,8 @@ static virNetClientPtr virLockManagerLockDaemonConnectionNew(bool privileged,
                                        daemonPath)))
         goto error;
 
-    if (!(*prog = virNetClientProgramNew(VIR_LOCK_SPACE_PROTOCOL_PROGRAM,
-                                         VIR_LOCK_SPACE_PROTOCOL_PROGRAM_VERSION,
+    if (!(*prog = virNetClientProgramNew(prog_magic,
+                                         prog_version,
                                          NULL,
                                          0,
                                          NULL)))
@@ -295,7 +298,9 @@ virLockManagerLockDaemonConnect(virLockManagerPtr lock,
 {
     virNetClientPtr client;
 
-    if (!(client = virLockManagerLockDaemonConnectionNew(geteuid() == 0, program)))
+    if (!(client = virLockManagerLockDaemonConnectionNew(geteuid() == 0, program,
+                                                         VIR_LOCK_SPACE_PROTOCOL_PROGRAM,
+                                                         VIR_LOCK_SPACE_PROTOCOL_PROGRAM_VERSION)))
         return NULL;
 
     if (virLockManagerLockDaemonConnectionRegister(lock,
@@ -313,6 +318,22 @@ virLockManagerLockDaemonConnect(virLockManagerPtr lock,
 }
 
 
+static virNetClientPtr
+virLockManagerLockSeclabelConnect(virLockManagerPtr lock ATTRIBUTE_UNUSED,
+                                  virNetClientProgramPtr *program,
+                                  int *counter ATTRIBUTE_UNUSED)
+{
+    virNetClientPtr client;
+
+    if (!(client = virLockManagerLockDaemonConnectionNew(geteuid() == 0, program,
+                                                         VIR_LOCK_SECLABEL_PROTOCOL_PROGRAM,
+                                                         VIR_LOCK_SECLABEL_PROTOCOL_PROGRAM_VERSION)))
+        return NULL;
+
+    return client;
+}
+
+
 static int virLockManagerLockDaemonSetupLockspace(const char *path)
 {
     virNetClientPtr client;
@@ -324,7 +345,9 @@ static int virLockManagerLockDaemonSetupLockspace(const char *path)
     memset(&args, 0, sizeof(args));
     args.path = (char*)path;
 
-    if (!(client = virLockManagerLockDaemonConnectionNew(geteuid() == 0, &program)))
+    if (!(client = virLockManagerLockDaemonConnectionNew(geteuid() == 0, &program,
+                                                         VIR_LOCK_SPACE_PROTOCOL_PROGRAM,
+                                                         VIR_LOCK_SPACE_PROTOCOL_PROGRAM_VERSION)))
         return -1;
 
     if (virNetClientProgramCall(program,
@@ -786,6 +809,84 @@ static int virLockManagerLockDaemonInquire(virLockManagerPtr lock ATTRIBUTE_UNUS
     return 0;
 }
 
+
+static int
+virLockManagerLockRememberSeclabel(virLockManagerPtr lock,
+                                   const char *path,
+                                   const char *model,
+                                   const char *seclabel)
+{
+    virNetClientPtr client = NULL;
+    virNetClientProgramPtr program = NULL;
+    int counter = 0;
+    virLockSeclabelProtocolRememberSeclabelArgs args;
+    virLockSeclabelProtocolRememberSeclabelRet ret;
+    int rv = -1;
+
+    args.path = (char *)path;
+    args.model = (char *)model;
+    args.seclabel = (char *)seclabel;
+
+    if (!(client = virLockManagerLockSeclabelConnect(lock, &program, &counter)))
+        goto cleanup;
+
+    if (virNetClientProgramCall(program, client, counter++,
+                                VIR_LOCK_SECLABEL_PROTOCOL_PROC_REMEMBER_SECLABEL,
+                                0, NULL, NULL, NULL,
+                                (xdrproc_t)xdr_virLockSeclabelProtocolRememberSeclabelArgs, &args,
+                                (xdrproc_t)xdr_virLockSeclabelProtocolRememberSeclabelRet, &ret) < 0)
+        goto cleanup;
+
+    rv = ret.ret;
+
+ cleanup:
+    virNetClientClose(client);
+    virObjectUnref(client);
+    virObjectUnref(program);
+    return rv;
+}
+
+
+static int
+virLockManagerLockRecallSeclabel(virLockManagerPtr lock,
+                                 const char *path,
+                                 const char *model,
+                                 char **seclabel)
+{
+    virNetClientPtr client = NULL;
+    virNetClientProgramPtr program = NULL;
+    int counter = 0;
+    virLockSeclabelProtocolRecallSeclabelArgs args;
+    virLockSeclabelProtocolRecallSeclabelRet ret;
+    int rv = -1;
+
+    memset(&ret, 0, sizeof(ret));
+
+    args.path = (char *)path;
+    args.model = (char *)model;
+
+    if (!(client = virLockManagerLockSeclabelConnect(lock, &program, &counter)))
+        goto cleanup;
+
+    if (virNetClientProgramCall(program, client, counter++,
+                                VIR_LOCK_SECLABEL_PROTOCOL_PROC_RECALL_SECLABEL,
+                                0, NULL, NULL, NULL,
+                                (xdrproc_t)xdr_virLockSeclabelProtocolRecallSeclabelArgs, &args,
+                                (xdrproc_t)xdr_virLockSeclabelProtocolRecallSeclabelRet, &ret) < 0)
+        goto cleanup;
+
+    if (seclabel)
+        *seclabel = ret.seclabel;
+    rv = ret.ret;
+
+ cleanup:
+    virNetClientClose(client);
+    virObjectUnref(client);
+    virObjectUnref(program);
+    return rv;
+}
+
+
 virLockDriver virLockDriverImpl =
 {
     .version = VIR_LOCK_MANAGER_VERSION,
@@ -803,4 +904,7 @@ virLockDriver virLockDriverImpl =
     .drvRelease = virLockManagerLockDaemonRelease,
 
     .drvInquire = virLockManagerLockDaemonInquire,
+
+    .drvRemember = virLockManagerLockRememberSeclabel,
+    .drvRecall = virLockManagerLockRecallSeclabel,
 };
-- 
1.8.5.5


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