mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-30 13:01:23 +03:00
always set error when returning error in auth.c
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
committed by
Andreas Schneider
parent
622d5a43b3
commit
637fc7ea59
81
src/auth.c
81
src/auth.c
@@ -384,6 +384,7 @@ int ssh_userauth_none(ssh_session session, const char *username) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user == NULL) {
|
if (user == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
leave_function();
|
leave_function();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -415,10 +416,12 @@ int ssh_userauth_none(ssh_session session, const char *username) {
|
|||||||
|
|
||||||
method = ssh_string_from_char("none");
|
method = ssh_string_from_char("none");
|
||||||
if (method == NULL) {
|
if (method == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
service = ssh_string_from_char("ssh-connection");
|
service = ssh_string_from_char("ssh-connection");
|
||||||
if (service == NULL) {
|
if (service == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -521,6 +524,7 @@ int ssh_userauth_offer_pubkey(ssh_session session, const char *username,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user == NULL) {
|
if (user == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
leave_function();
|
leave_function();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -552,14 +556,17 @@ int ssh_userauth_offer_pubkey(ssh_session session, const char *username,
|
|||||||
|
|
||||||
service = ssh_string_from_char("ssh-connection");
|
service = ssh_string_from_char("ssh-connection");
|
||||||
if (service == NULL) {
|
if (service == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
method = ssh_string_from_char("publickey");
|
method = ssh_string_from_char("publickey");
|
||||||
if (method == NULL) {
|
if (method == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
algo = ssh_string_from_char(ssh_type_to_char(type));
|
algo = ssh_string_from_char(ssh_type_to_char(type));
|
||||||
if (algo == NULL) {
|
if (algo == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -570,6 +577,7 @@ int ssh_userauth_offer_pubkey(ssh_session session, const char *username,
|
|||||||
buffer_add_u8(session->out_buffer, 0) < 0 ||
|
buffer_add_u8(session->out_buffer, 0) < 0 ||
|
||||||
buffer_add_ssh_string(session->out_buffer, algo) < 0 ||
|
buffer_add_ssh_string(session->out_buffer, algo) < 0 ||
|
||||||
buffer_add_ssh_string(session->out_buffer, publickey) < 0) {
|
buffer_add_ssh_string(session->out_buffer, publickey) < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -665,6 +673,7 @@ int ssh_userauth_pubkey(ssh_session session, const char *username,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user == NULL) {
|
if (user == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
leave_function();
|
leave_function();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -690,24 +699,32 @@ int ssh_userauth_pubkey(ssh_session session, const char *username,
|
|||||||
|
|
||||||
service = ssh_string_from_char("ssh-connection");
|
service = ssh_string_from_char("ssh-connection");
|
||||||
if (service == NULL) {
|
if (service == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
method = ssh_string_from_char("publickey");
|
method = ssh_string_from_char("publickey");
|
||||||
if (method == NULL) {
|
if (method == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
algo = ssh_string_from_char(ssh_type_to_char(privatekey->type));
|
algo = ssh_string_from_char(ssh_type_to_char(privatekey->type));
|
||||||
if (algo == NULL) {
|
if (algo == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (publickey == NULL) {
|
if (publickey == NULL) {
|
||||||
pk = publickey_from_privatekey(privatekey);
|
pk = publickey_from_privatekey(privatekey);
|
||||||
if (pk == NULL) {
|
if (pk == NULL) {
|
||||||
|
/* most likely oom, and publickey_from_privatekey does not
|
||||||
|
* return any more information */
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
pkstr = publickey_to_string(pk);
|
pkstr = publickey_to_string(pk);
|
||||||
publickey_free(pk);
|
publickey_free(pk);
|
||||||
if (pkstr == NULL) {
|
if (pkstr == NULL) {
|
||||||
|
/* same as above */
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -720,6 +737,7 @@ int ssh_userauth_pubkey(ssh_session session, const char *username,
|
|||||||
buffer_add_u8(session->out_buffer, 1) < 0 ||
|
buffer_add_u8(session->out_buffer, 1) < 0 ||
|
||||||
buffer_add_ssh_string(session->out_buffer, algo) < 0 ||
|
buffer_add_ssh_string(session->out_buffer, algo) < 0 ||
|
||||||
buffer_add_ssh_string(session->out_buffer, (publickey == NULL ? pkstr : publickey)) < 0) {
|
buffer_add_ssh_string(session->out_buffer, (publickey == NULL ? pkstr : publickey)) < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -731,8 +749,10 @@ int ssh_userauth_pubkey(ssh_session session, const char *username,
|
|||||||
|
|
||||||
sign = ssh_do_sign(session,session->out_buffer, privatekey);
|
sign = ssh_do_sign(session,session->out_buffer, privatekey);
|
||||||
if(sign == NULL)
|
if(sign == NULL)
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
if (buffer_add_ssh_string(session->out_buffer,sign) < 0) {
|
if (buffer_add_ssh_string(session->out_buffer,sign) < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
ssh_string_free(sign);
|
ssh_string_free(sign);
|
||||||
@@ -797,6 +817,7 @@ int ssh_userauth_privatekey_file(ssh_session session, const char *username,
|
|||||||
|
|
||||||
pubkeyfile = malloc(strlen(filename) + 1 + 4);
|
pubkeyfile = malloc(strlen(filename) + 1 + 4);
|
||||||
if (pubkeyfile == NULL) {
|
if (pubkeyfile == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
leave_function();
|
leave_function();
|
||||||
return SSH_AUTH_ERROR;
|
return SSH_AUTH_ERROR;
|
||||||
}
|
}
|
||||||
@@ -878,6 +899,7 @@ int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user == NULL) {
|
if (user == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
leave_function();
|
leave_function();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -890,18 +912,22 @@ int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
|
|||||||
|
|
||||||
service = ssh_string_from_char("ssh-connection");
|
service = ssh_string_from_char("ssh-connection");
|
||||||
if (service == NULL) {
|
if (service == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
method = ssh_string_from_char("publickey");
|
method = ssh_string_from_char("publickey");
|
||||||
if (method == NULL) {
|
if (method == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
algo = ssh_string_from_char(ssh_type_to_char(publickey->type));
|
algo = ssh_string_from_char(ssh_type_to_char(publickey->type));
|
||||||
if (algo == NULL) {
|
if (algo == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
key = publickey_to_string(publickey);
|
key = publickey_to_string(publickey);
|
||||||
if (key == NULL) {
|
if (key == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -913,6 +939,7 @@ int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
|
|||||||
buffer_add_u8(session->out_buffer, 1) < 0 ||
|
buffer_add_u8(session->out_buffer, 1) < 0 ||
|
||||||
buffer_add_ssh_string(session->out_buffer, algo) < 0 ||
|
buffer_add_ssh_string(session->out_buffer, algo) < 0 ||
|
||||||
buffer_add_ssh_string(session->out_buffer, key) < 0) {
|
buffer_add_ssh_string(session->out_buffer, key) < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -920,6 +947,7 @@ int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
|
|||||||
|
|
||||||
if (sign) {
|
if (sign) {
|
||||||
if (buffer_add_ssh_string(session->out_buffer, sign) < 0) {
|
if (buffer_add_ssh_string(session->out_buffer, sign) < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
ssh_string_free(sign);
|
ssh_string_free(sign);
|
||||||
@@ -1009,6 +1037,7 @@ int ssh_userauth_password(ssh_session session, const char *username,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user == NULL) {
|
if (user == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
leave_function();
|
leave_function();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -1041,14 +1070,17 @@ int ssh_userauth_password(ssh_session session, const char *username,
|
|||||||
|
|
||||||
service = ssh_string_from_char("ssh-connection");
|
service = ssh_string_from_char("ssh-connection");
|
||||||
if (service == NULL) {
|
if (service == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
method = ssh_string_from_char("password");
|
method = ssh_string_from_char("password");
|
||||||
if (method == NULL) {
|
if (method == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
pwd = ssh_string_from_char(password);
|
pwd = ssh_string_from_char(password);
|
||||||
if (pwd == NULL) {
|
if (pwd == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1058,6 +1090,7 @@ int ssh_userauth_password(ssh_session session, const char *username,
|
|||||||
buffer_add_ssh_string(session->out_buffer, method) < 0 ||
|
buffer_add_ssh_string(session->out_buffer, method) < 0 ||
|
||||||
buffer_add_u8(session->out_buffer, 0) < 0 ||
|
buffer_add_u8(session->out_buffer, 0) < 0 ||
|
||||||
buffer_add_ssh_string(session->out_buffer, pwd) < 0) {
|
buffer_add_ssh_string(session->out_buffer, pwd) < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1410,18 +1443,22 @@ static int kbdauth_init(ssh_session session, const char *user,
|
|||||||
|
|
||||||
usr = ssh_string_from_char(user);
|
usr = ssh_string_from_char(user);
|
||||||
if (usr == NULL) {
|
if (usr == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
sub = (submethods ? ssh_string_from_char(submethods) : ssh_string_from_char(""));
|
sub = (submethods ? ssh_string_from_char(submethods) : ssh_string_from_char(""));
|
||||||
if (sub == NULL) {
|
if (sub == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
service = ssh_string_from_char("ssh-connection");
|
service = ssh_string_from_char("ssh-connection");
|
||||||
if (service == NULL) {
|
if (service == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
method = ssh_string_from_char("keyboard-interactive");
|
method = ssh_string_from_char("keyboard-interactive");
|
||||||
if (method == NULL) {
|
if (method == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1431,6 +1468,7 @@ static int kbdauth_init(ssh_session session, const char *user,
|
|||||||
buffer_add_ssh_string(session->out_buffer, method) < 0 ||
|
buffer_add_ssh_string(session->out_buffer, method) < 0 ||
|
||||||
buffer_add_u32(session->out_buffer, 0) < 0 ||
|
buffer_add_u32(session->out_buffer, 0) < 0 ||
|
||||||
buffer_add_ssh_string(session->out_buffer, sub) < 0) {
|
buffer_add_ssh_string(session->out_buffer, sub) < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1602,6 +1640,7 @@ static int kbdauth_send(ssh_session session) {
|
|||||||
if (buffer_add_u8(session->out_buffer, SSH2_MSG_USERAUTH_INFO_RESPONSE) < 0 ||
|
if (buffer_add_u8(session->out_buffer, SSH2_MSG_USERAUTH_INFO_RESPONSE) < 0 ||
|
||||||
buffer_add_u32(session->out_buffer,
|
buffer_add_u32(session->out_buffer,
|
||||||
htonl(session->kbdint->nprompts)) < 0) {
|
htonl(session->kbdint->nprompts)) < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1612,10 +1651,12 @@ static int kbdauth_send(ssh_session session) {
|
|||||||
answer = ssh_string_from_char("");
|
answer = ssh_string_from_char("");
|
||||||
}
|
}
|
||||||
if (answer == NULL) {
|
if (answer == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffer_add_ssh_string(session->out_buffer, answer) < 0) {
|
if (buffer_add_ssh_string(session->out_buffer, answer) < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1672,7 +1713,7 @@ int ssh_userauth_kbdint(ssh_session session, const char *user,
|
|||||||
int rc = SSH_AUTH_ERROR;
|
int rc = SSH_AUTH_ERROR;
|
||||||
|
|
||||||
if (session->version == 1) {
|
if (session->version == 1) {
|
||||||
/* No keyb-interactive for ssh1 */
|
ssh_set_error(session, SSH_NO_ERROR, "No keyboard-interactive for ssh1");
|
||||||
return SSH_AUTH_DENIED;
|
return SSH_AUTH_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1725,8 +1766,12 @@ int ssh_userauth_kbdint(ssh_session session, const char *user,
|
|||||||
* @returns The number of prompts.
|
* @returns The number of prompts.
|
||||||
*/
|
*/
|
||||||
int ssh_userauth_kbdint_getnprompts(ssh_session session) {
|
int ssh_userauth_kbdint_getnprompts(ssh_session session) {
|
||||||
if(session==NULL || session->kbdint == NULL)
|
if(session==NULL)
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
|
if(session->kbdint == NULL) {
|
||||||
|
ssh_set_error_invalid(session, __FUNCTION__);
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
return session->kbdint->nprompts;
|
return session->kbdint->nprompts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1741,8 +1786,12 @@ int ssh_userauth_kbdint_getnprompts(ssh_session session) {
|
|||||||
* @returns The name of the message block. Do not free it.
|
* @returns The name of the message block. Do not free it.
|
||||||
*/
|
*/
|
||||||
const char *ssh_userauth_kbdint_getname(ssh_session session) {
|
const char *ssh_userauth_kbdint_getname(ssh_session session) {
|
||||||
if(session==NULL || session->kbdint == NULL)
|
if(session==NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if(session->kbdint == NULL) {
|
||||||
|
ssh_set_error_invalid(session, __FUNCTION__);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return session->kbdint->name;
|
return session->kbdint->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1758,8 +1807,12 @@ const char *ssh_userauth_kbdint_getname(ssh_session session) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const char *ssh_userauth_kbdint_getinstruction(ssh_session session) {
|
const char *ssh_userauth_kbdint_getinstruction(ssh_session session) {
|
||||||
if(session==NULL || session->kbdint == NULL)
|
if(session==NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if(session->kbdint == NULL) {
|
||||||
|
ssh_set_error_invalid(session, __FUNCTION__);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return session->kbdint->instruction;
|
return session->kbdint->instruction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1781,9 +1834,14 @@ const char *ssh_userauth_kbdint_getinstruction(ssh_session session) {
|
|||||||
*/
|
*/
|
||||||
const char *ssh_userauth_kbdint_getprompt(ssh_session session, unsigned int i,
|
const char *ssh_userauth_kbdint_getprompt(ssh_session session, unsigned int i,
|
||||||
char *echo) {
|
char *echo) {
|
||||||
if(session==NULL || session->kbdint == NULL)
|
if(session==NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (i > session->kbdint->nprompts) {
|
if(session->kbdint == NULL) {
|
||||||
|
ssh_set_error_invalid(session, __FUNCTION__);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (i > session->kbdint->nprompts) {
|
||||||
|
ssh_set_error_invalid(session, __FUNCTION__);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1844,14 +1902,18 @@ const char *ssh_userauth_kbdint_getanswer(ssh_session session, unsigned int i) {
|
|||||||
*/
|
*/
|
||||||
int ssh_userauth_kbdint_setanswer(ssh_session session, unsigned int i,
|
int ssh_userauth_kbdint_setanswer(ssh_session session, unsigned int i,
|
||||||
const char *answer) {
|
const char *answer) {
|
||||||
if (session == NULL || answer == NULL || session->kbdint == NULL ||
|
if (session == NULL)
|
||||||
|
return -1;
|
||||||
|
if (answer == NULL || session->kbdint == NULL ||
|
||||||
i > session->kbdint->nprompts) {
|
i > session->kbdint->nprompts) {
|
||||||
|
ssh_set_error_invalid(session, __FUNCTION__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session->kbdint->answers == NULL) {
|
if (session->kbdint->answers == NULL) {
|
||||||
session->kbdint->answers = malloc(sizeof(char*) * session->kbdint->nprompts);
|
session->kbdint->answers = malloc(sizeof(char*) * session->kbdint->nprompts);
|
||||||
if (session->kbdint->answers == NULL) {
|
if (session->kbdint->answers == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(session->kbdint->answers, 0, sizeof(char *) * session->kbdint->nprompts);
|
memset(session->kbdint->answers, 0, sizeof(char *) * session->kbdint->nprompts);
|
||||||
@@ -1864,6 +1926,7 @@ int ssh_userauth_kbdint_setanswer(ssh_session session, unsigned int i,
|
|||||||
|
|
||||||
session->kbdint->answers[i] = strdup(answer);
|
session->kbdint->answers[i] = strdup(answer);
|
||||||
if (session->kbdint->answers[i] == NULL) {
|
if (session->kbdint->answers[i] == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user