fdopen fix in keygen utility

This commit is contained in:
Manoj Ampalam 2016-10-16 15:19:26 -07:00
parent c25f6a0d5e
commit 12db568b03

View File

@ -990,6 +990,11 @@ do_gen_all_hostkeys(struct passwd *pw)
} }
sshkey_free(private); sshkey_free(private);
strlcat(identity_file, ".pub", sizeof(identity_file)); strlcat(identity_file, ".pub", sizeof(identity_file));
#ifdef WINDOWS
if ((f = fopen(identity_file, "w")) == NULL) {
error("fopen %s failed: %s", identity_file, strerror(errno));
/* TODO - set permissions on file */
#else
fd = open(identity_file, O_WRONLY | O_CREAT | O_TRUNC, 0644); fd = open(identity_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd == -1) { if (fd == -1) {
error("Could not save your public key in %s", error("Could not save your public key in %s",
@ -999,9 +1004,11 @@ do_gen_all_hostkeys(struct passwd *pw)
continue; continue;
} }
f = fdopen(fd, "w"); f = fdopen(fd, "w");
if (f == NULL) { if (f == NULL) {
error("fdopen %s failed", identity_file); error("fdopen %s failed", identity_file);
close(fd); close(fd);
#endif
sshkey_free(public); sshkey_free(public);
first = 0; first = 0;
continue; continue;
@ -2765,10 +2772,10 @@ passphrase_again:
printf("Your identification has been saved in %s.\n", identity_file); printf("Your identification has been saved in %s.\n", identity_file);
strlcat(identity_file, ".pub", sizeof(identity_file)); strlcat(identity_file, ".pub", sizeof(identity_file));
/* TODO - for windows call fopen directly*/
#ifdef WINDOWS #ifdef WINDOWS
if ((f = fopen(identity_file, "w")) == NULL) if ((f = fopen(identity_file, "w")) == NULL)
fatal("fopen %s failed: %s", identity_file, strerror(errno)); fatal("fopen %s failed: %s", identity_file, strerror(errno));
/* TODO - set permissions on file */
#else #else
if ((fd = open(identity_file, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) if ((fd = open(identity_file, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1)
fatal("Unable to save public key to %s: %s", fatal("Unable to save public key to %s: %s",