aboutsummaryrefslogtreecommitdiff
path: root/src/keyfiles.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2010-10-20 14:47:11 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2010-10-20 14:47:11 +0200
commit98221f4e3640b2522851e49c7f81f5e500ed4a25 (patch)
treef1dc9608ec61cfb2d73a64580589b6746a04c198 /src/keyfiles.c
parent8e2699e16139c8efdc54a06471de29966ccc233a (diff)
downloadlibssh-98221f4e3640b2522851e49c7f81f5e500ed4a25.tar.gz
libssh-98221f4e3640b2522851e49c7f81f5e500ed4a25.tar.xz
libssh-98221f4e3640b2522851e49c7f81f5e500ed4a25.zip
Fixed a bunch of smallish bugs
http://linuxtesting.org/upstream-tracker/test_results/libssh/current/test_results.html for a whole list
Diffstat (limited to 'src/keyfiles.c')
-rw-r--r--src/keyfiles.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/keyfiles.c b/src/keyfiles.c
index 08169787..e7351f07 100644
--- a/src/keyfiles.c
+++ b/src/keyfiles.c
@@ -802,7 +802,7 @@ ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
#endif
return NULL;
}
-
+ ZERO_STRUCTP(privkey);
privkey->type = type;
privkey->dsa_priv = dsa;
privkey->rsa_priv = rsa;
@@ -955,23 +955,28 @@ int ssh_publickey_to_file(ssh_session session, const char *file,
unsigned char *pubkey_64;
size_t len;
int rc;
-
+ if(session==NULL)
+ return SSH_ERROR;
+ if(file==NULL || pubkey==NULL){
+ ssh_set_error(session, SSH_FATAL, "Invalid parameters");
+ return SSH_ERROR;
+ }
pubkey_64 = bin_to_base64(pubkey->string, ssh_string_len(pubkey));
if (pubkey_64 == NULL) {
- return -1;
+ return SSH_ERROR;
}
user = ssh_get_local_username(session);
if (user == NULL) {
SAFE_FREE(pubkey_64);
- return -1;
+ return SSH_ERROR;
}
rc = gethostname(host, sizeof(host));
if (rc < 0) {
SAFE_FREE(user);
SAFE_FREE(pubkey_64);
- return -1;
+ return SSH_ERROR;
}
snprintf(buffer, sizeof(buffer), "%s %s %s@%s\n",
@@ -990,7 +995,7 @@ int ssh_publickey_to_file(ssh_session session, const char *file,
if (fp == NULL) {
ssh_set_error(session, SSH_REQUEST_DENIED,
"Error opening %s: %s", file, strerror(errno));
- return -1;
+ return SSH_ERROR;
}
len = strlen(buffer);
@@ -999,11 +1004,11 @@ int ssh_publickey_to_file(ssh_session session, const char *file,
"Unable to write to %s", file);
fclose(fp);
unlink(file);
- return -1;
+ return SSH_ERROR;
}
fclose(fp);
- return 0;
+ return SSH_OK;
}
/**