Re-factor auth code to make clearer (Jim Meyering)

This commit is contained in:
Daniel P. Berrange 2008-01-14 04:05:23 +00:00
parent b2083ea907
commit 6aae9a9efb
2 changed files with 25 additions and 24 deletions

View File

@ -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

View 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) {