comparison svr-kex.c @ 986:8d0c33e8ddab coverity

merge
author Matt Johnston <matt@ucc.asn.au>
date Sun, 04 Jan 2015 22:33:12 +0800
parents 2b62f26cf808
children aaf576b27a10
comparison
equal deleted inserted replaced
975:bfc8e66ceacf 986:8d0c33e8ddab
82 send_msg_newkeys(); 82 send_msg_newkeys();
83 ses.requirenext = SSH_MSG_NEWKEYS; 83 ses.requirenext = SSH_MSG_NEWKEYS;
84 TRACE(("leave recv_msg_kexdh_init")) 84 TRACE(("leave recv_msg_kexdh_init"))
85 } 85 }
86 86
87
87 #ifdef DROPBEAR_DELAY_HOSTKEY 88 #ifdef DROPBEAR_DELAY_HOSTKEY
89
90 static void fsync_parent_dir(const char* fn) {
91 #ifdef HAVE_LIBGEN_H
92 char *fn_dir = m_strdup(fn);
93 char *dir = dirname(fn_dir);
94 int dirfd = open(dir, O_RDONLY);
95
96 if (dirfd != -1) {
97 if (fsync(dirfd) != 0) {
98 TRACE(("fsync of directory %s failed: %s", dir, strerror(errno)))
99 }
100 m_close(dirfd);
101 } else {
102 TRACE(("error opening directory %s for fsync: %s", dir, strerror(errno)))
103 }
104
105 free(fn_dir);
106 #endif
107 }
108
88 static void svr_ensure_hostkey() { 109 static void svr_ensure_hostkey() {
89 110
90 const char* fn = NULL; 111 const char* fn = NULL;
91 char *fn_temp = NULL; 112 char *fn_temp = NULL;
92 enum signkey_type type = ses.newkeys->algo_hostkey; 113 enum signkey_type type = ses.newkeys->algo_hostkey;
139 strerror(errno)); 160 strerror(errno));
140 /* XXX fallback to non-atomic copy for some filesystems? */ 161 /* XXX fallback to non-atomic copy for some filesystems? */
141 goto out; 162 goto out;
142 } 163 }
143 } 164 }
165
166 /* ensure directory update is flushed to disk, otherwise we can end up
167 with zero-byte hostkey files if the power goes off */
168 fsync_parent_dir(fn);
144 169
145 ret = readhostkey(fn, svr_opts.hostkey, &type); 170 ret = readhostkey(fn, svr_opts.hostkey, &type);
146 171
147 if (ret == DROPBEAR_SUCCESS) { 172 if (ret == DROPBEAR_SUCCESS) {
148 char *fp = NULL; 173 char *fp = NULL;