Skip to content

Commit 796d297

Browse files
authored
fix open call for ssh-keygen (#764)
* fix open call for ssh-keygen * fix test * fix formatting
1 parent a915f06 commit 796d297

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

authfile.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,19 @@ sshkey_save_public(const struct sshkey *key, const char *path,
515515

516516
if ((fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1)
517517
return SSH_ERR_SYSTEM_ERROR;
518+
#ifdef WINDOWS
519+
/* Windows POSIX adapter does not support fdopen() on open(file)
520+
but still want file created with same owner as upstream */
521+
close(fd);
522+
if ((f = fopen(path, "w")) == NULL)
523+
return SSH_ERR_SYSTEM_ERROR;
524+
#else /* WINDOWS */
518525
if ((f = fdopen(fd, "w")) == NULL) {
519526
r = SSH_ERR_SYSTEM_ERROR;
520527
close(fd);
521528
goto fail;
522529
}
530+
#endif /* WINDOWS */
523531
if ((r = sshkey_write(key, f)) != 0)
524532
goto fail;
525533
fprintf(f, " %s\n", comment);

0 commit comments

Comments
 (0)