mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-12 13:17:58 +03:00
esx: Avoid using vSphere SessionIsActive function
A login session with the vSphere API might expire after some idle time.
The esxVI_EnsureSession function uses the SessionIsActive function to
check if the current session has expired and a relogin needs to be done.
But the SessionIsActive function needs the Sessions.ValidateSession
privilege that is considered as an admin level privilege.
Only vCenter actually provides the SessionIsActive function. This results
in requiring an admin level privilege even for read-only operations on
a vCenter server.
ESX and VMware Server don't provide the SessionIsActive function and
the code already works around that. Use the same workaround for vCenter
again.
This basically reverts commit 5699034b65
.
This commit is contained in:
parent
55e6d8cd9e
commit
647ac97ab6
@ -2043,11 +2043,21 @@ esxVI_BuildSelectSetCollection(esxVI_Context *ctx)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Cannot use the SessionIsActive() function here, because at least
|
||||
* ESX Server 3.5.0 build-64607 and ESX 4.0.0 build-171294 return an
|
||||
* method-not-implemented fault when calling it. The vCenter Server
|
||||
* implements this method, but because it can be used to check any
|
||||
* session it requires the Sessions.ValidateSession privilege that is
|
||||
* considered as an admin privilege.
|
||||
*
|
||||
* Instead query the session manager for the current session of this
|
||||
* connection and re-login if there is no current session.
|
||||
*/
|
||||
int
|
||||
esxVI_EnsureSession(esxVI_Context *ctx)
|
||||
{
|
||||
int result = -1;
|
||||
esxVI_Boolean active = esxVI_Boolean_Undefined;
|
||||
esxVI_String *propertyNameList = NULL;
|
||||
esxVI_ObjectContent *sessionManager = NULL;
|
||||
esxVI_DynamicProperty *dynamicProperty = NULL;
|
||||
@ -2065,29 +2075,6 @@ esxVI_EnsureSession(esxVI_Context *ctx)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (ctx->hasSessionIsActive) {
|
||||
/*
|
||||
* Use SessionIsActive to check if there is an active session for this
|
||||
* connection, and re-login if there isn't.
|
||||
*/
|
||||
if (esxVI_SessionIsActive(ctx, ctx->session->key,
|
||||
ctx->session->userName, &active) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (active != esxVI_Boolean_True) {
|
||||
esxVI_UserSession_Free(&ctx->session);
|
||||
|
||||
if (esxVI_Login(ctx, ctx->username, ctx->password, NULL,
|
||||
&ctx->session) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Query the session manager for the current session of this connection
|
||||
* and re-login if there is no current session for this connection.
|
||||
*/
|
||||
if (esxVI_String_AppendValueToList(&propertyNameList,
|
||||
"currentSession") < 0 ||
|
||||
esxVI_LookupObjectContentByType(ctx, ctx->service->sessionManager,
|
||||
@ -2124,7 +2111,6 @@ esxVI_EnsureSession(esxVI_Context *ctx)
|
||||
"last login"));
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
result = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user