#include "virpolkit.h"
#include "virthreadjob.h"
#include "configmake.h"
+#include "access/viraccessapicheck.h"
#define VIR_FROM_THIS VIR_FROM_RPC
static int
remoteOpenConn(const char *uri,
bool readonly,
+ bool preserveIdentity,
virConnectPtr *conn)
{
- VIR_DEBUG("Getting secondary uri=%s readonly=%d conn=%p",
- NULLSTR(uri), readonly, conn);
+ virTypedParameterPtr params = NULL;
+ int nparams = 0;
+ int ret = -1;
+
+ VIR_DEBUG("Getting secondary uri=%s readonly=%d preserveIdent=%d conn=%p",
+ NULLSTR(uri), readonly, preserveIdentity, conn);
+
if (*conn)
return 0;
return -1;
}
+ if (preserveIdentity) {
+ VIR_AUTOUNREF(virIdentityPtr) ident = NULL;
+
+ if (!(ident = virIdentityGetCurrent()))
+ return -1;
+
+ if (virIdentityGetParameters(ident, ¶ms, &nparams) < 0)
+ goto error;
+ }
+
VIR_DEBUG("Opening driver %s", uri);
if (readonly)
*conn = virConnectOpenReadOnly(uri);
else
*conn = virConnectOpen(uri);
if (!*conn)
- return -1;
+ goto error;
VIR_DEBUG("Opened driver %p", *conn);
- return 0;
+ if (preserveIdentity) {
+ if (virConnectSetIdentity(*conn, params, nparams, 0) < 0)
+ goto error;
+
+ VIR_DEBUG("Forwarded current identity to secondary driver");
+ }
+
+ ret = 0;
+ cleanup:
+ virTypedParamsFree(params, nparams);
+ return ret;
+
+ error:
+ if (*conn) {
+ virConnectClose(*conn);
+ *conn = NULL;
+ }
+ goto cleanup;
}
if (remoteOpenConn(priv->interfaceURI,
priv->readonly,
+ true,
&priv->interfaceConn) < 0)
return NULL;
if (remoteOpenConn(priv->networkURI,
priv->readonly,
+ true,
&priv->networkConn) < 0)
return NULL;
if (remoteOpenConn(priv->nodedevURI,
priv->readonly,
+ true,
&priv->nodedevConn) < 0)
return NULL;
if (remoteOpenConn(priv->nwfilterURI,
priv->readonly,
+ true,
&priv->nwfilterConn) < 0)
return NULL;
if (remoteOpenConn(priv->secretURI,
priv->readonly,
+ true,
&priv->secretConn) < 0)
return NULL;
if (remoteOpenConn(priv->storageURI,
priv->readonly,
+ true,
&priv->storageConn) < 0)
return NULL;
#ifdef MODULE_NAME
const char *type = NULL;
#endif /* !MODULE_NAME */
+ bool preserveIdentity = false;
VIR_DEBUG("priv=%p conn=%p", priv, priv->conn);
virMutexLock(&priv->lock);
name = probeduri;
}
-#endif
+
+ preserveIdentity = true;
+#endif /* VIRTPROXYD */
VIR_DEBUG("Opening driver %s", name);
- if (priv->readonly) {
- if (!(priv->conn = virConnectOpenReadOnly(name)))
- goto cleanup;
- } else {
- if (!(priv->conn = virConnectOpen(name)))
- goto cleanup;
- }
+ if (remoteOpenConn(name,
+ priv->readonly,
+ preserveIdentity,
+ &priv->conn) < 0)
+ goto cleanup;
VIR_DEBUG("Opened %p", priv->conn);
#ifdef MODULE_NAME
}
+static int
+remoteDispatchConnectSetIdentity(virNetServerPtr server ATTRIBUTE_UNUSED,
+ virNetServerClientPtr client,
+ virNetMessagePtr msg ATTRIBUTE_UNUSED,
+ virNetMessageErrorPtr rerr,
+ remote_connect_set_identity_args *args)
+{
+ virTypedParameterPtr params = NULL;
+ int nparams = 0;
+ int rv = -1;
+ virConnectPtr conn = remoteGetHypervisorConn(client);
+ VIR_AUTOUNREF(virIdentityPtr) ident = NULL;
+ if (!conn)
+ goto cleanup;
+
+ VIR_DEBUG("Received forwarded identity");
+ if (virTypedParamsDeserialize((virTypedParameterRemotePtr) args->params.params_val,
+ args->params.params_len,
+ REMOTE_CONNECT_IDENTITY_PARAMS_MAX,
+ ¶ms,
+ &nparams) < 0)
+ goto cleanup;
+
+ VIR_TYPED_PARAMS_DEBUG(params, nparams);
+
+ if (virConnectSetIdentityEnsureACL(conn) < 0)
+ goto cleanup;
+
+ if (!(ident = virIdentityNew()))
+ goto cleanup;
+
+ if (virIdentitySetParameters(ident, params, nparams) < 0)
+ goto cleanup;
+
+ virNetServerClientSetIdentity(client, ident);
+
+ rv = 0;
+
+ cleanup:
+ virTypedParamsFree(params, nparams);
+ if (rv < 0)
+ virNetMessageSaveError(rerr);
+ return rv;
+}
+
+
+
static int
remoteDispatchDomainGetSchedulerType(virNetServerPtr server ATTRIBUTE_UNUSED,
virNetServerClientPtr client,
/* A long string, which may be NULL. */
typedef remote_nonnull_string *remote_string;
+/* Upper limit on identity parameters */
+const REMOTE_CONNECT_IDENTITY_PARAMS_MAX = 20;
+
/* Upper limit on lists of domains. */
const REMOTE_DOMAIN_LIST_MAX = 16384;
remote_typed_param params<REMOTE_DOMAIN_GUEST_INFO_PARAMS_MAX>;
};
+struct remote_connect_set_identity_args {
+ remote_typed_param params<REMOTE_CONNECT_IDENTITY_PARAMS_MAX>;
+ unsigned int flags;
+};
+
/*----- Protocol. -----*/
/* Define the program number, protocol version and procedure numbers here. */
* @generate: none
* @acl: domain:write
*/
- REMOTE_PROC_DOMAIN_GET_GUEST_INFO = 418
+ REMOTE_PROC_DOMAIN_GET_GUEST_INFO = 418,
+
+ /**
+ * @generate: client
+ * @acl: connect:write
+ */
+ REMOTE_PROC_CONNECT_SET_IDENTITY = 419
};