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

[libvirt] [PATCH v6 1/5] vz: save session uuid on login



This session uuid acts as authN token for different multihost vz operations one
of which is migration. Unfortunately we can't get it from server at any time
thus we need to save it at login.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy virtuozzo com>
---
 src/vz/vz_sdk.c   | 39 +++++++++++++++++++++++++++++----------
 src/vz/vz_utils.h |  2 +-
 2 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index de73c31..8950b97 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -37,6 +37,9 @@
 #define VIR_FROM_THIS VIR_FROM_PARALLELS
 #define JOB_INFINIT_WAIT_TIMEOUT UINT_MAX
 
+static int
+prlsdkUUIDParse(const char *uuidstr, unsigned char *uuid);
+
 VIR_LOG_INIT("parallels.sdk");
 
 /*
@@ -228,24 +231,40 @@ prlsdkDeinit(void)
 int
 prlsdkConnect(vzConnPtr privconn)
 {
-    PRL_RESULT ret;
+    int ret = -1;
+    PRL_RESULT pret;
     PRL_HANDLE job = PRL_INVALID_HANDLE;
+    PRL_HANDLE result = PRL_INVALID_HANDLE;
+    PRL_HANDLE response = PRL_INVALID_HANDLE;
+    char session_uuid[VIR_UUID_STRING_BUFLEN + 2];
+    PRL_UINT32 buflen = ARRAY_CARDINALITY(session_uuid);
 
-    ret = PrlSrv_Create(&privconn->server);
-    if (PRL_FAILED(ret)) {
-        logPrlError(ret);
-        return -1;
-    }
+    pret = PrlSrv_Create(&privconn->server);
+    prlsdkCheckRetGoto(pret, cleanup);
 
     job = PrlSrv_LoginLocalEx(privconn->server, NULL, 0,
                               PSL_HIGH_SECURITY, PACF_NON_INTERACTIVE_MODE);
+    if (PRL_FAILED(getJobResult(job, &result)))
+        goto cleanup;
 
-    if (waitJob(job)) {
+    pret = PrlResult_GetParam(result, &response);
+    prlsdkCheckRetGoto(pret, cleanup);
+
+    pret = PrlLoginResponse_GetSessionUuid(response, session_uuid, &buflen);
+    prlsdkCheckRetGoto(pret, cleanup);
+
+    if (prlsdkUUIDParse(session_uuid, privconn->session_uuid) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    if (ret < 0)
         PrlHandle_Free(privconn->server);
-        return -1;
-    }
+    PrlHandle_Free(result);
+    PrlHandle_Free(response);
 
-    return 0;
+    return ret;
 }
 
 void
diff --git a/src/vz/vz_utils.h b/src/vz/vz_utils.h
index ed100ac..b685478 100644
--- a/src/vz/vz_utils.h
+++ b/src/vz/vz_utils.h
@@ -54,7 +54,7 @@ struct _vzConn {
 
     /* Immutable pointer, self-locking APIs */
     virDomainObjListPtr domains;
-
+    unsigned char session_uuid[VIR_UUID_BUFLEN];
     PRL_HANDLE server;
     virCapsPtr caps;
     virDomainXMLOptionPtr xmlopt;
-- 
1.8.3.1


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