]> xenbits.xensource.com Git - libvirt.git/commitdiff
Re-factor auth code to make clearer (Jim Meyering)
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 14 Jan 2008 04:05:23 +0000 (04:05 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Mon, 14 Jan 2008 04:05:23 +0000 (04:05 +0000)
ChangeLog
src/remote_internal.c

index 186a9324c1a66e5a9438a7a4d1d20fb4529a7dc5..980332e29e768bba77cef49720e51ed94f72870e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Jan 13 22:59:53 EST 2008 Daniel P. Berrange <berrange@redhat.com>
+
+       * src/remote_internal.c: Refactor code to make error patches
+       clearer (Jim Meyering).
+
 Sun Jan 13 22:53:53 EST 2008 Daniel P. Berrange <berrange@redhat.com>
 
        * src/remote_internal.c: Fix crash when server has auth type
index 4e0909931ca0a455f11512e114d9f98c2122df9c..9eff251eba88a8100c0bc6369761c8624e0560ea 100644 (file)
@@ -3152,6 +3152,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
 
     /* Need to gather some credentials from the client */
     if (err == SASL_INTERACT) {
+        const char *msg;
         if (cred) {
             remoteAuthFreeCredentials(cred, ncred);
             cred = NULL;
@@ -3166,20 +3167,18 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
         }
         /* Run the authentication callback */
         if (auth && auth->cb) {
-            if ((*(auth->cb))(cred, ncred, auth->cbdata) < 0) {
-                __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
-                                 VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
-                                 "Failed to collect auth credentials");
-                goto cleanup;
+            if ((*(auth->cb))(cred, ncred, auth->cbdata) >= 0) {
+                remoteAuthFillInteract(cred, interact);
+                goto restart;
             }
-            remoteAuthFillInteract(cred, interact);
-            goto restart;
+            msg = "Failed to collect auth credentials";
         } else {
-            __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
-                             VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
-                             "No authentication callback available");
-            goto cleanup;
+            msg = "No authentication callback available";
         }
+        __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
+                         VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL,
+                         0, 0, msg);
+        goto cleanup;
     }
     free(iret.mechlist);
 
@@ -3231,6 +3230,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
         }
         /* Need to gather some credentials from the client */
         if (err == SASL_INTERACT) {
+            const char *msg;
             if (cred) {
                 remoteAuthFreeCredentials(cred, ncred);
                 cred = NULL;
@@ -3240,25 +3240,21 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
                                  VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
                                  "Failed to make auth credentials");
                 goto cleanup;
-                return -1;
             }
             /* Run the authentication callback */
             if (auth && auth->cb) {
-                if ((*(auth->cb))(cred, ncred, auth->cbdata) < 0) {
-                    __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
-                                     VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
-                                     "Failed to collect auth credentials");
-                    goto cleanup;
-                    return -1;
+                if ((*(auth->cb))(cred, ncred, auth->cbdata) >= 0) {
+                    remoteAuthFillInteract(cred, interact);
+                    goto restep;
                 }
-                remoteAuthFillInteract(cred, interact);
-                goto restep;
+                msg = "Failed to collect auth credentials";
             } else {
-                __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
-                                 VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
-                                 "No authentication callback available");
-                goto cleanup;
+                msg = "No authentication callback available";
             }
+            __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
+                             VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL,
+                             0, 0, msg);
+            goto cleanup;
         }
 
         if (serverin) {