Mercurial > dropbear
comparison cli-kex.c @ 399:a707e6148060
merge of '5fdf69ca60d1683cdd9f4c2595134bed26394834'
and '6b61c50f4cf888bea302ac8fcf5dbb573b443251'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 03 Feb 2007 08:20:34 +0000 |
parents | 454a34b2dfd1 |
children | ab57ba0cb667 |
comparison
equal
deleted
inserted
replaced
394:17d097fc111c | 399:a707e6148060 |
---|---|
120 | 120 |
121 fp = sign_key_fingerprint(keyblob, keybloblen); | 121 fp = sign_key_fingerprint(keyblob, keybloblen); |
122 fprintf(stderr, "\nHost '%s' is not in the trusted hosts file.\n(fingerprint %s)\nDo you want to continue connecting? (y/n)\n", | 122 fprintf(stderr, "\nHost '%s' is not in the trusted hosts file.\n(fingerprint %s)\nDo you want to continue connecting? (y/n)\n", |
123 cli_opts.remotehost, | 123 cli_opts.remotehost, |
124 fp); | 124 fp); |
125 m_free(fp); | |
125 | 126 |
126 tty = fopen(_PATH_TTY, "r"); | 127 tty = fopen(_PATH_TTY, "r"); |
127 if (tty) { | 128 if (tty) { |
128 response = getc(tty); | 129 response = getc(tty); |
129 fclose(tty); | 130 fclose(tty); |
130 } else { | 131 } else { |
131 response = getc(stdin); | 132 response = getc(stdin); |
132 } | 133 } |
133 | 134 |
134 if (response == 'y') { | 135 if (response == 'y') { |
135 m_free(fp); | |
136 return; | 136 return; |
137 } | 137 } |
138 | 138 |
139 dropbear_exit("Didn't validate host key"); | 139 dropbear_exit("Didn't validate host key"); |
140 } | 140 } |
143 | 143 |
144 char * filename = NULL; | 144 char * filename = NULL; |
145 FILE *hostsfile = NULL; | 145 FILE *hostsfile = NULL; |
146 int readonly = 0; | 146 int readonly = 0; |
147 struct passwd *pw = NULL; | 147 struct passwd *pw = NULL; |
148 char * homedir = NULL; | |
148 unsigned int hostlen, algolen; | 149 unsigned int hostlen, algolen; |
149 unsigned long len; | 150 unsigned long len; |
150 const char *algoname = NULL; | 151 const char *algoname = NULL; |
151 buffer * line = NULL; | 152 buffer * line = NULL; |
152 int ret; | 153 int ret; |
153 | 154 |
154 pw = getpwuid(getuid()); | 155 homedir = getenv("HOME"); |
155 | 156 |
156 if (pw == NULL) { | 157 if (!homedir) { |
157 dropbear_exit("Failed to get homedir"); | 158 pw = getpwuid(getuid()); |
158 } | 159 if (pw) { |
159 | 160 homedir = pw->pw_dir; |
160 len = strlen(pw->pw_dir); | 161 } |
161 filename = m_malloc(len + 18); /* "/.ssh/known_hosts" and null-terminator*/ | 162 pw = NULL; |
162 | 163 } |
163 snprintf(filename, len+18, "%s/.ssh", pw->pw_dir); | 164 |
164 /* Check that ~/.ssh exists - easiest way is just to mkdir */ | 165 if (homedir) { |
165 if (mkdir(filename, S_IRWXU) != 0) { | 166 |
166 if (errno != EEXIST) { | 167 len = strlen(homedir); |
167 dropbear_log(LOG_INFO, "Warning: failed creating ~/.ssh: %s", | 168 filename = m_malloc(len + 18); /* "/.ssh/known_hosts" and null-terminator*/ |
168 strerror(errno)); | 169 |
169 TRACE(("mkdir didn't work: %s", strerror(errno))) | 170 snprintf(filename, len+18, "%s/.ssh", homedir); |
170 ask_to_confirm(keyblob, keybloblen); | 171 /* Check that ~/.ssh exists - easiest way is just to mkdir */ |
171 goto out; /* only get here on success */ | 172 if (mkdir(filename, S_IRWXU) != 0) { |
172 } | 173 if (errno != EEXIST) { |
173 } | 174 dropbear_log(LOG_INFO, "Warning: failed creating %s/.ssh: %s", |
174 | 175 homedir, strerror(errno)); |
175 snprintf(filename, len+18, "%s/.ssh/known_hosts", pw->pw_dir); | 176 TRACE(("mkdir didn't work: %s", strerror(errno))) |
176 hostsfile = fopen(filename, "a+"); | 177 ask_to_confirm(keyblob, keybloblen); |
177 | 178 goto out; /* only get here on success */ |
178 if (hostsfile != NULL) { | 179 } |
179 fseek(hostsfile, 0, SEEK_SET); | 180 } |
180 } else { | 181 |
181 /* We mightn't have been able to open it if it was read-only */ | 182 snprintf(filename, len+18, "%s/.ssh/known_hosts", homedir); |
182 if (errno == EACCES || errno == EROFS) { | 183 hostsfile = fopen(filename, "a+"); |
183 TRACE(("trying readonly: %s", strerror(errno))) | 184 |
184 readonly = 1; | 185 if (hostsfile != NULL) { |
185 hostsfile = fopen(filename, "r"); | 186 fseek(hostsfile, 0, SEEK_SET); |
187 } else { | |
188 /* We mightn't have been able to open it if it was read-only */ | |
189 if (errno == EACCES || errno == EROFS) { | |
190 TRACE(("trying readonly: %s", strerror(errno))) | |
191 readonly = 1; | |
192 hostsfile = fopen(filename, "r"); | |
193 } | |
186 } | 194 } |
187 } | 195 } |
188 | 196 |
189 if (hostsfile == NULL) { | 197 if (hostsfile == NULL) { |
190 TRACE(("hostsfile didn't open: %s", strerror(errno))) | 198 TRACE(("hostsfile didn't open: %s", strerror(errno))) |
199 dropbear_log(LOG_WARNING, "Failed to open %s/.ssh/known_hosts", | |
200 homedir); | |
191 ask_to_confirm(keyblob, keybloblen); | 201 ask_to_confirm(keyblob, keybloblen); |
192 goto out; /* We only get here on success */ | 202 goto out; /* We only get here on success */ |
193 } | 203 } |
194 | 204 |
195 line = buf_new(MAX_KNOWNHOSTS_LINE); | 205 line = buf_new(MAX_KNOWNHOSTS_LINE); |