aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBernhard R. Link <brlink@debian.org>2011-02-12 19:35:53 +0100
committerAndreas Schneider <asn@cryptomilk.org>2011-02-12 20:11:50 +0100
commit637fc7ea59ec3ecf78e9920257a7c1d8a768607e (patch)
treef7e44b808284c66598a5ab254b354e38c9671178 /src
parent622d5a43b35a3ff55cd7eaaeceb1663a67c67d60 (diff)
downloadlibssh-637fc7ea59ec3ecf78e9920257a7c1d8a768607e.tar.gz
libssh-637fc7ea59ec3ecf78e9920257a7c1d8a768607e.tar.xz
libssh-637fc7ea59ec3ecf78e9920257a7c1d8a768607e.zip
always set error when returning error in auth.c
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src')
-rw-r--r--src/auth.c81
1 files changed, 72 insertions, 9 deletions
diff --git a/src/auth.c b/src/auth.c
index 3e10e552..8327a173 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -384,6 +384,7 @@ int ssh_userauth_none(ssh_session session, const char *username) {
}
if (user == NULL) {
+ ssh_set_error_oom(session);
leave_function();
return rc;
}
@@ -415,10 +416,12 @@ int ssh_userauth_none(ssh_session session, const char *username) {
method = ssh_string_from_char("none");
if (method == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
service = ssh_string_from_char("ssh-connection");
if (service == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -521,6 +524,7 @@ int ssh_userauth_offer_pubkey(ssh_session session, const char *username,
}
if (user == NULL) {
+ ssh_set_error_oom(session);
leave_function();
return rc;
}
@@ -552,14 +556,17 @@ int ssh_userauth_offer_pubkey(ssh_session session, const char *username,
service = ssh_string_from_char("ssh-connection");
if (service == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
method = ssh_string_from_char("publickey");
if (method == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
algo = ssh_string_from_char(ssh_type_to_char(type));
if (algo == NULL) {
+ ssh_set_error_oom(session);
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_ssh_string(session->out_buffer, algo) < 0 ||
buffer_add_ssh_string(session->out_buffer, publickey) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -665,6 +673,7 @@ int ssh_userauth_pubkey(ssh_session session, const char *username,
}
if (user == NULL) {
+ ssh_set_error_oom(session);
leave_function();
return rc;
}
@@ -690,24 +699,32 @@ int ssh_userauth_pubkey(ssh_session session, const char *username,
service = ssh_string_from_char("ssh-connection");
if (service == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
method = ssh_string_from_char("publickey");
if (method == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
algo = ssh_string_from_char(ssh_type_to_char(privatekey->type));
if (algo == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
if (publickey == NULL) {
pk = publickey_from_privatekey(privatekey);
if (pk == NULL) {
+ /* most likely oom, and publickey_from_privatekey does not
+ * return any more information */
+ ssh_set_error_oom(session);
goto error;
}
pkstr = publickey_to_string(pk);
publickey_free(pk);
if (pkstr == NULL) {
+ /* same as above */
+ ssh_set_error_oom(session);
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_ssh_string(session->out_buffer, algo) < 0 ||
buffer_add_ssh_string(session->out_buffer, (publickey == NULL ? pkstr : publickey)) < 0) {
+ ssh_set_error_oom(session);
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);
if(sign == NULL)
+ ssh_set_error_oom(session);
goto error;
if (buffer_add_ssh_string(session->out_buffer,sign) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
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);
if (pubkeyfile == NULL) {
+ ssh_set_error_oom(session);
leave_function();
return SSH_AUTH_ERROR;
}
@@ -878,6 +899,7 @@ int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
}
if (user == NULL) {
+ ssh_set_error_oom(session);
leave_function();
return rc;
}
@@ -890,18 +912,22 @@ int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
service = ssh_string_from_char("ssh-connection");
if (service == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
method = ssh_string_from_char("publickey");
if (method == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
algo = ssh_string_from_char(ssh_type_to_char(publickey->type));
if (algo == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
key = publickey_to_string(publickey);
if (key == NULL) {
+ ssh_set_error_oom(session);
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_ssh_string(session->out_buffer, algo) < 0 ||
buffer_add_ssh_string(session->out_buffer, key) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -920,6 +947,7 @@ int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
if (sign) {
if (buffer_add_ssh_string(session->out_buffer, sign) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
ssh_string_free(sign);
@@ -1009,6 +1037,7 @@ int ssh_userauth_password(ssh_session session, const char *username,
}
if (user == NULL) {
+ ssh_set_error_oom(session);
leave_function();
return rc;
}
@@ -1041,14 +1070,17 @@ int ssh_userauth_password(ssh_session session, const char *username,
service = ssh_string_from_char("ssh-connection");
if (service == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
method = ssh_string_from_char("password");
if (method == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
pwd = ssh_string_from_char(password);
if (pwd == NULL) {
+ ssh_set_error_oom(session);
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_u8(session->out_buffer, 0) < 0 ||
buffer_add_ssh_string(session->out_buffer, pwd) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -1410,18 +1443,22 @@ static int kbdauth_init(ssh_session session, const char *user,
usr = ssh_string_from_char(user);
if (usr == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
sub = (submethods ? ssh_string_from_char(submethods) : ssh_string_from_char(""));
if (sub == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
service = ssh_string_from_char("ssh-connection");
if (service == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
method = ssh_string_from_char("keyboard-interactive");
if (method == NULL) {
+ ssh_set_error_oom(session);
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_u32(session->out_buffer, 0) < 0 ||
buffer_add_ssh_string(session->out_buffer, sub) < 0) {
+ ssh_set_error_oom(session);
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 ||
buffer_add_u32(session->out_buffer,
htonl(session->kbdint->nprompts)) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -1612,10 +1651,12 @@ static int kbdauth_send(ssh_session session) {
answer = ssh_string_from_char("");
}
if (answer == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
if (buffer_add_ssh_string(session->out_buffer, answer) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -1672,7 +1713,7 @@ int ssh_userauth_kbdint(ssh_session session, const char *user,
int rc = SSH_AUTH_ERROR;
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;
}
@@ -1725,8 +1766,12 @@ int ssh_userauth_kbdint(ssh_session session, const char *user,
* @returns The number of prompts.
*/
int ssh_userauth_kbdint_getnprompts(ssh_session session) {
- if(session==NULL || session->kbdint == NULL)
- return SSH_ERROR;
+ if(session==NULL)
+ return SSH_ERROR;
+ if(session->kbdint == NULL) {
+ ssh_set_error_invalid(session, __FUNCTION__);
+ return SSH_ERROR;
+ }
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.
*/
const char *ssh_userauth_kbdint_getname(ssh_session session) {
- if(session==NULL || session->kbdint == NULL)
+ if(session==NULL)
+ return NULL;
+ if(session->kbdint == NULL) {
+ ssh_set_error_invalid(session, __FUNCTION__);
return NULL;
+ }
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) {
- if(session==NULL || session->kbdint == NULL)
- return NULL;
+ if(session==NULL)
+ return NULL;
+ if(session->kbdint == NULL) {
+ ssh_set_error_invalid(session, __FUNCTION__);
+ return NULL;
+ }
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,
char *echo) {
- if(session==NULL || session->kbdint == NULL)
+ if(session==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;
}
@@ -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,
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) {
+ ssh_set_error_invalid(session, __FUNCTION__);
return -1;
}
if (session->kbdint->answers == NULL) {
session->kbdint->answers = malloc(sizeof(char*) * session->kbdint->nprompts);
if (session->kbdint->answers == NULL) {
+ ssh_set_error_oom(session);
return -1;
}
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);
if (session->kbdint->answers[i] == NULL) {
+ ssh_set_error_oom(session);
return -1;
}