version 1.131, 2018/09/21 12:20:12 |
version 1.132, 2019/06/28 13:35:04 |
|
|
{ |
{ |
int fd, oerrno; |
int fd, oerrno; |
|
|
if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0) |
if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600)) == -1) |
return SSH_ERR_SYSTEM_ERROR; |
return SSH_ERR_SYSTEM_ERROR; |
if (atomicio(vwrite, fd, sshbuf_mutable_ptr(keybuf), |
if (atomicio(vwrite, fd, sshbuf_mutable_ptr(keybuf), |
sshbuf_len(keybuf)) != sshbuf_len(keybuf)) { |
sshbuf_len(keybuf)) != sshbuf_len(keybuf)) { |
|
|
struct stat st; |
struct stat st; |
int r; |
int r; |
|
|
if (fstat(fd, &st) < 0) |
if (fstat(fd, &st) == -1) |
return SSH_ERR_SYSTEM_ERROR; |
return SSH_ERR_SYSTEM_ERROR; |
if ((st.st_mode & (S_IFSOCK|S_IFCHR|S_IFIFO)) == 0 && |
if ((st.st_mode & (S_IFSOCK|S_IFCHR|S_IFIFO)) == 0 && |
st.st_size > MAX_KEY_FILE_SIZE) |
st.st_size > MAX_KEY_FILE_SIZE) |
|
|
{ |
{ |
struct stat st; |
struct stat st; |
|
|
if (fstat(fd, &st) < 0) |
if (fstat(fd, &st) == -1) |
return SSH_ERR_SYSTEM_ERROR; |
return SSH_ERR_SYSTEM_ERROR; |
/* |
/* |
* if a key owned by the user is accessed, then we check the |
* if a key owned by the user is accessed, then we check the |
|
|
if (commentp != NULL) |
if (commentp != NULL) |
*commentp = NULL; |
*commentp = NULL; |
|
|
if ((fd = open(filename, O_RDONLY)) < 0) { |
if ((fd = open(filename, O_RDONLY)) == -1) { |
if (perm_ok != NULL) |
if (perm_ok != NULL) |
*perm_ok = 0; |
*perm_ok = 0; |
return SSH_ERR_SYSTEM_ERROR; |
return SSH_ERR_SYSTEM_ERROR; |
|
|
if (commentp != NULL) |
if (commentp != NULL) |
*commentp = NULL; |
*commentp = NULL; |
|
|
if ((fd = open(filename, O_RDONLY)) < 0) |
if ((fd = open(filename, O_RDONLY)) == -1) |
return SSH_ERR_SYSTEM_ERROR; |
return SSH_ERR_SYSTEM_ERROR; |
if (sshkey_perm_ok(fd, filename) != 0) { |
if (sshkey_perm_ok(fd, filename) != 0) { |
r = SSH_ERR_KEY_BAD_PERMISSIONS; |
r = SSH_ERR_KEY_BAD_PERMISSIONS; |