comparison cli-kex.c @ 418:ab57ba0cb667

Add '-y' option to dbclient to accept the host key without checking - patch from Luciano Miguel Ferreira Rocha.
author Matt Johnston <matt@ucc.asn.au>
date Sun, 11 Feb 2007 08:50:21 +0000
parents 454a34b2dfd1
children 7282370416a0
comparison
equal deleted inserted replaced
417:fb02e3180d90 418:ab57ba0cb667
117 char* fp = NULL; 117 char* fp = NULL;
118 FILE *tty = NULL; 118 FILE *tty = NULL;
119 char response = 'z'; 119 char response = 'z';
120 120
121 fp = sign_key_fingerprint(keyblob, keybloblen); 121 fp = sign_key_fingerprint(keyblob, keybloblen);
122 if (cli_opts.always_accept_key) {
123 fprintf(stderr, "\nHost '%s' key accepted unconditionally.\n(fingerprint %s)\n",
124 cli_opts.remotehost,
125 fp);
126 m_free(fp);
127 return;
128 }
122 fprintf(stderr, "\nHost '%s' is not in the trusted hosts file.\n(fingerprint %s)\nDo you want to continue connecting? (y/n)\n", 129 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, 130 cli_opts.remotehost,
124 fp); 131 fp);
125 m_free(fp); 132 m_free(fp);
126 133
266 if (readonly) { 273 if (readonly) {
267 TRACE(("readonly")) 274 TRACE(("readonly"))
268 goto out; 275 goto out;
269 } 276 }
270 277
271 /* put the new entry in the file */ 278 if (!cli_opts.always_accept_key) {
272 fseek(hostsfile, 0, SEEK_END); /* In case it wasn't opened append */ 279 /* put the new entry in the file */
273 buf_setpos(line, 0); 280 fseek(hostsfile, 0, SEEK_END); /* In case it wasn't opened append */
274 buf_setlen(line, 0); 281 buf_setpos(line, 0);
275 buf_putbytes(line, ses.remotehost, hostlen); 282 buf_setlen(line, 0);
276 buf_putbyte(line, ' '); 283 buf_putbytes(line, ses.remotehost, hostlen);
277 buf_putbytes(line, algoname, algolen); 284 buf_putbyte(line, ' ');
278 buf_putbyte(line, ' '); 285 buf_putbytes(line, algoname, algolen);
279 len = line->size - line->pos; 286 buf_putbyte(line, ' ');
280 TRACE(("keybloblen %d, len %d", keybloblen, len)) 287 len = line->size - line->pos;
281 /* The only failure with base64 is buffer_overflow, but buf_getwriteptr 288 TRACE(("keybloblen %d, len %d", keybloblen, len))
282 * will die horribly in the case anyway */ 289 /* The only failure with base64 is buffer_overflow, but buf_getwriteptr
283 base64_encode(keyblob, keybloblen, buf_getwriteptr(line, len), &len); 290 * will die horribly in the case anyway */
284 buf_incrwritepos(line, len); 291 base64_encode(keyblob, keybloblen, buf_getwriteptr(line, len), &len);
285 buf_putbyte(line, '\n'); 292 buf_incrwritepos(line, len);
286 buf_setpos(line, 0); 293 buf_putbyte(line, '\n');
287 fwrite(buf_getptr(line, line->len), line->len, 1, hostsfile); 294 buf_setpos(line, 0);
288 /* We ignore errors, since there's not much we can do about them */ 295 fwrite(buf_getptr(line, line->len), line->len, 1, hostsfile);
296 /* We ignore errors, since there's not much we can do about them */
297 }
289 298
290 out: 299 out:
291 if (hostsfile != NULL) { 300 if (hostsfile != NULL) {
292 fclose(hostsfile); 301 fclose(hostsfile);
293 } 302 }