Don't invoke the auth callback if all credentials were in config file

The remote driver first looks at the libvirt auth config file to
fill in any credentials. It then invokes the auth callback for
any remaining credentials. It was accidentally invoking the
auth callback even if there were not any more credentials
required.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2012-09-10 16:47:58 +01:00
parent 48fea23ba5
commit d95606e3d8
1 changed files with 21 additions and 12 deletions

View File

@ -3517,29 +3517,38 @@ static int remoteAuthInteract(virConnectPtr conn,
VIR_DEBUG("Starting SASL interaction"); VIR_DEBUG("Starting SASL interaction");
remoteAuthInteractStateClear(state, false); remoteAuthInteractStateClear(state, false);
/* Fills state->interact with any values from the auth config file */
if (remoteAuthFillFromConfig(conn, state) < 0) if (remoteAuthFillFromConfig(conn, state) < 0)
goto cleanup; goto cleanup;
/* Populates state->cred for anything not found in the auth config */
if (remoteAuthMakeCredentials(state->interact, &state->cred, &state->ncred) < 0) { if (remoteAuthMakeCredentials(state->interact, &state->cred, &state->ncred) < 0) {
virReportError(VIR_ERR_AUTH_FAILED, "%s", virReportError(VIR_ERR_AUTH_FAILED, "%s",
_("Failed to make auth credentials")); _("Failed to make auth credentials"));
goto cleanup; goto cleanup;
} }
/* Run the authentication callback */ /* If there was anything not in the auth config, we need to
if (!auth || !auth->cb) { * run the interactive callback
virReportError(VIR_ERR_AUTH_FAILED, "%s", */
_("No authentication callback available")); if (state->ncred) {
goto cleanup; /* Run the authentication callback */
if (!auth || !auth->cb) {
virReportError(VIR_ERR_AUTH_FAILED, "%s",
_("No authentication callback available"));
goto cleanup;
}
if ((*(auth->cb))(state->cred, state->ncred, auth->cbdata) < 0) {
virReportError(VIR_ERR_AUTH_FAILED, "%s",
_("Failed to collect auth credentials"));
goto cleanup;
}
/* Copy user's responses from cred into interact */
remoteAuthFillInteract(state->cred, state->interact);
} }
if ((*(auth->cb))(state->cred, state->ncred, auth->cbdata) < 0) {
virReportError(VIR_ERR_AUTH_FAILED, "%s",
_("Failed to collect auth credentials"));
goto cleanup;
}
remoteAuthFillInteract(state->cred, state->interact);
/* /*
* 'interact' now has pointers to strings in 'state->cred' * 'interact' now has pointers to strings in 'state->cred'
* so we must not free state->cred until the *next* * so we must not free state->cred until the *next*