comparison svr-runopts.c @ 47:4b53a43f0082

- client pubkey auth works - rearrange the runopts code for client and server (hostkey reading is needed by both (if the client is doing pubkey auth. otherwise....))
author Matt Johnston <matt@ucc.asn.au>
date Fri, 06 Aug 2004 16:18:01 +0000
parents f789045062e6
children eee77ac31ccc
comparison
equal deleted inserted replaced
46:3bea78e1b175 47:4b53a43f0082
31 31
32 svr_runopts svr_opts; /* GLOBAL */ 32 svr_runopts svr_opts; /* GLOBAL */
33 33
34 static sign_key * loadhostkeys(const char * dsskeyfile, 34 static sign_key * loadhostkeys(const char * dsskeyfile,
35 const char * rsakeyfile); 35 const char * rsakeyfile);
36 static int readhostkey(const char * filename, sign_key * hostkey, int type);
37 static void printhelp(const char * progname); 36 static void printhelp(const char * progname);
38 37
39 static void printhelp(const char * progname) { 38 static void printhelp(const char * progname) {
40 39
41 fprintf(stderr, "Dropbear sshd v%s\n" 40 fprintf(stderr, "Dropbear sshd v%s\n"
261 } 260 }
262 } 261 }
263 262
264 } 263 }
265 264
266 265 static void disablekey(int type, const char* filename) {
267 /* returns success or failure */ 266
268 static int readhostkey(const char * filename, sign_key * hostkey, int type) {
269
270 int ret = DROPBEAR_FAILURE;
271 int i; 267 int i;
272 buffer *buf; 268
273 269 for (i = 0; sshhostkey[i].name != NULL; i++) {
274 buf = buf_new(2000); 270 if (sshhostkey[i].val == type) {
275 271 sshhostkey[i].usable = 0;
276 if (buf_readfile(buf, filename) == DROPBEAR_FAILURE) { 272 break;
277 goto out; 273 }
278 } 274 }
279 buf_setpos(buf, 0); 275 fprintf(stderr, "Failed reading '%s', disabling %s\n", filename,
280 if (buf_get_priv_key(buf, hostkey, &type) == DROPBEAR_FAILURE) { 276 type == DROPBEAR_SIGNKEY_DSS ? "DSS" : "RSA");
281 goto out;
282 }
283
284 ret = DROPBEAR_SUCCESS;
285 out:
286 if (ret == DROPBEAR_FAILURE) {
287 for (i = 0; sshhostkey[i].name != NULL; i++) {
288 if (sshhostkey[i].val == type) {
289 sshhostkey[i].usable = 0;
290 break;
291 }
292 }
293 fprintf(stderr, "Failed reading '%s', disabling %s\n", filename,
294 type == DROPBEAR_SIGNKEY_DSS ? "DSS" : "RSA");
295 }
296
297 buf_burn(buf);
298 buf_free(buf);
299 return ret;
300 } 277 }
301 278
302 static sign_key * loadhostkeys(const char * dsskeyfile, 279 static sign_key * loadhostkeys(const char * dsskeyfile,
303 const char * rsakeyfile) { 280 const char * rsakeyfile) {
304 281
305 sign_key * hostkey; 282 sign_key * hostkey;
283 int ret;
284 int type;
306 285
307 TRACE(("enter loadhostkeys")); 286 TRACE(("enter loadhostkeys"));
308 287
309 hostkey = new_sign_key(); 288 hostkey = new_sign_key();
310 289
311 #ifdef DROPBEAR_RSA 290 #ifdef DROPBEAR_RSA
312 (void)readhostkey(rsakeyfile, hostkey, DROPBEAR_SIGNKEY_RSA); 291 type = DROPBEAR_SIGNKEY_RSA;
313 #endif 292 ret = readhostkey(rsakeyfile, hostkey, &type);
314 293 if (ret == DROPBEAR_FAILURE) {
315 #ifdef DROPBEAR_DSS 294 disablekey(DROPBEAR_SIGNKEY_RSA, rsakeyfile);
316 (void)readhostkey(dsskeyfile, hostkey, DROPBEAR_SIGNKEY_DSS); 295 }
296 #endif
297 #ifdef DROPBEAR_DSS
298 type = DROPBEAR_SIGNKEY_RSA;
299 ret = readhostkey(dsskeyfile, hostkey, &type);
300 if (ret == DROPBEAR_FAILURE) {
301 disablekey(DROPBEAR_SIGNKEY_DSS, dsskeyfile);
302 }
317 #endif 303 #endif
318 304
319 if ( 1 305 if ( 1
320 #ifdef DROPBEAR_DSS 306 #ifdef DROPBEAR_DSS
321 && hostkey->dsskey == NULL 307 && hostkey->dsskey == NULL