From 6aae9a9efb736b9d07d2e57bba169c3cb60893ae Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Mon, 14 Jan 2008 04:05:23 +0000 Subject: [PATCH] Re-factor auth code to make clearer (Jim Meyering) --- ChangeLog | 5 +++++ src/remote_internal.c | 44 ++++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 186a9324c1..980332e29e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Jan 13 22:59:53 EST 2008 Daniel P. Berrange + + * src/remote_internal.c: Refactor code to make error patches + clearer (Jim Meyering). + Sun Jan 13 22:53:53 EST 2008 Daniel P. Berrange * src/remote_internal.c: Fix crash when server has auth type diff --git a/src/remote_internal.c b/src/remote_internal.c index 4e0909931c..9eff251eba 100644 --- a/src/remote_internal.c +++ b/src/remote_internal.c @@ -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) {