vnc: auth reject cleanup

protocol_client_auth_vnc() has two places where the auth can fail,
with identical code sending the reject message to the client.
Move the common code to the end of the function and make both
error paths jump there.  No functional change.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Gerd Hoffmann 2010-10-07 11:50:24 +02:00
parent cb42a870c3
commit 6bffdf0f83

View File

@ -2085,15 +2085,7 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len)
if (!vs->vd->password || !vs->vd->password[0]) { if (!vs->vd->password || !vs->vd->password[0]) {
VNC_DEBUG("No password configured on server"); VNC_DEBUG("No password configured on server");
vnc_write_u32(vs, 1); /* Reject auth */ goto reject;
if (vs->minor >= 8) {
static const char err[] = "Authentication failed";
vnc_write_u32(vs, sizeof(err));
vnc_write(vs, err, sizeof(err));
}
vnc_flush(vs);
vnc_client_error(vs);
return 0;
} }
memcpy(response, vs->challenge, VNC_AUTH_CHALLENGE_SIZE); memcpy(response, vs->challenge, VNC_AUTH_CHALLENGE_SIZE);
@ -2109,6 +2101,17 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len)
/* Compare expected vs actual challenge response */ /* Compare expected vs actual challenge response */
if (memcmp(response, data, VNC_AUTH_CHALLENGE_SIZE) != 0) { if (memcmp(response, data, VNC_AUTH_CHALLENGE_SIZE) != 0) {
VNC_DEBUG("Client challenge reponse did not match\n"); VNC_DEBUG("Client challenge reponse did not match\n");
goto reject;
} else {
VNC_DEBUG("Accepting VNC challenge response\n");
vnc_write_u32(vs, 0); /* Accept auth */
vnc_flush(vs);
start_client_init(vs);
}
return 0;
reject:
vnc_write_u32(vs, 1); /* Reject auth */ vnc_write_u32(vs, 1); /* Reject auth */
if (vs->minor >= 8) { if (vs->minor >= 8) {
static const char err[] = "Authentication failed"; static const char err[] = "Authentication failed";
@ -2117,13 +2120,6 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len)
} }
vnc_flush(vs); vnc_flush(vs);
vnc_client_error(vs); vnc_client_error(vs);
} else {
VNC_DEBUG("Accepting VNC challenge response\n");
vnc_write_u32(vs, 0); /* Accept auth */
vnc_flush(vs);
start_client_init(vs);
}
return 0; return 0;
} }