]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Don't invoke the auth callback if all credentials were in config file
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 10 Sep 2012 15:47:58 +0000 (16:47 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 11 Sep 2012 11:16:18 +0000 (12:16 +0100)
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>
src/remote/remote_driver.c

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