View | Details | Raw Unified | Return to bug 1783 | Differences between
and this patch

Collapse All | Expand All

(-)ssh-keygen.c (-64 / +60 lines)
Lines 406-416 do_convert_from_ssh2(struct passwd *pw) Link Here
406
		perror(identity_file);
406
		perror(identity_file);
407
		exit(1);
407
		exit(1);
408
	}
408
	}
409
	fp = fopen(identity_file, "r");
409
	if ((fp = fopen(identity_file, "r")) == NULL)
410
	if (fp == NULL) {
410
		fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
411
		perror(identity_file);
412
		exit(1);
413
	}
414
	encoded[0] = '\0';
411
	encoded[0] = '\0';
415
	while ((blen = get_line(fp, line, sizeof(line))) != -1) {
412
	while ((blen = get_line(fp, line, sizeof(line))) != -1) {
416
		if (line[blen - 1] == '\\')
413
		if (line[blen - 1] == '\\')
Lines 553-619 do_fingerprint(struct passwd *pw) Link Here
553
		comment = NULL;
550
		comment = NULL;
554
	}
551
	}
555
552
556
	f = fopen(identity_file, "r");
553
	if ((f = fopen(identity_file, "r")) == NULL)
557
	if (f != NULL) {
554
		fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
558
		while (fgets(line, sizeof(line), f)) {
559
			if ((cp = strchr(line, '\n')) == NULL) {
560
				error("line %d too long: %.40s...",
561
				    num + 1, line);
562
				skip = 1;
563
				continue;
564
			}
565
			num++;
566
			if (skip) {
567
				skip = 0;
568
				continue;
569
			}
570
			*cp = '\0';
571
555
572
			/* Skip leading whitespace, empty and comment lines. */
556
	while (fgets(line, sizeof(line), f)) {
573
			for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
557
		if ((cp = strchr(line, '\n')) == NULL) {
574
				;
558
			error("line %d too long: %.40s...",
575
			if (!*cp || *cp == '\n' || *cp == '#')
559
			    num + 1, line);
576
				continue;
560
			skip = 1;
577
			i = strtol(cp, &ep, 10);
561
			continue;
578
			if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) {
562
		}
579
				int quoted = 0;
563
		num++;
580
				comment = cp;
564
		if (skip) {
581
				for (; *cp && (quoted || (*cp != ' ' &&
565
			skip = 0;
582
				    *cp != '\t')); cp++) {
566
			continue;
583
					if (*cp == '\\' && cp[1] == '"')
567
		}
584
						cp++;	/* Skip both */
568
		*cp = '\0';
585
					else if (*cp == '"')
569
586
						quoted = !quoted;
570
		/* Skip leading whitespace, empty and comment lines. */
587
				}
571
		for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
588
				if (!*cp)
572
			;
589
					continue;
573
		if (!*cp || *cp == '\n' || *cp == '#')
590
				*cp++ = '\0';
574
			continue;
575
		i = strtol(cp, &ep, 10);
576
		if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) {
577
			int quoted = 0;
578
			comment = cp;
579
			for (; *cp && (quoted || (*cp != ' ' &&
580
			    *cp != '\t')); cp++) {
581
				if (*cp == '\\' && cp[1] == '"')
582
					cp++;	/* Skip both */
583
				else if (*cp == '"')
584
					quoted = !quoted;
591
			}
585
			}
592
			ep = cp;
586
			if (!*cp)
593
			public = key_new(KEY_RSA1);
587
				continue;
588
			*cp++ = '\0';
589
		}
590
		ep = cp;
591
		public = key_new(KEY_RSA1);
592
		if (key_read(public, &cp) != 1) {
593
			cp = ep;
594
			key_free(public);
595
			public = key_new(KEY_UNSPEC);
594
			if (key_read(public, &cp) != 1) {
596
			if (key_read(public, &cp) != 1) {
595
				cp = ep;
596
				key_free(public);
597
				key_free(public);
597
				public = key_new(KEY_UNSPEC);
598
				continue;
598
				if (key_read(public, &cp) != 1) {
599
					key_free(public);
600
					continue;
601
				}
602
			}
599
			}
603
			comment = *cp ? cp : comment;
604
			fp = key_fingerprint(public, fptype, rep);
605
			ra = key_fingerprint(public, SSH_FP_MD5, SSH_FP_RANDOMART);
606
			printf("%u %s %s (%s)\n", key_size(public), fp,
607
			    comment ? comment : "no comment", key_type(public));
608
			if (log_level >= SYSLOG_LEVEL_VERBOSE)
609
				printf("%s\n", ra);
610
			xfree(ra);
611
			xfree(fp);
612
			key_free(public);
613
			invalid = 0;
614
		}
600
		}
615
		fclose(f);
601
		comment = *cp ? cp : comment;
602
		fp = key_fingerprint(public, fptype, rep);
603
		ra = key_fingerprint(public, SSH_FP_MD5, SSH_FP_RANDOMART);
604
		printf("%u %s %s (%s)\n", key_size(public), fp,
605
		    comment ? comment : "no comment", key_type(public));
606
		if (log_level >= SYSLOG_LEVEL_VERBOSE)
607
			printf("%s\n", ra);
608
		xfree(ra);
609
		xfree(fp);
610
		key_free(public);
611
		invalid = 0;
616
	}
612
	}
613
	fclose(f);
614
617
	if (invalid) {
615
	if (invalid) {
618
		printf("%s is not a public key file.\n", identity_file);
616
		printf("%s is not a public key file.\n", identity_file);
619
		exit(1);
617
		exit(1);
Lines 668-674 do_known_hosts(struct passwd *pw, const Link Here
668
		have_identity = 1;
666
		have_identity = 1;
669
	}
667
	}
670
	if ((in = fopen(identity_file, "r")) == NULL)
668
	if ((in = fopen(identity_file, "r")) == NULL)
671
		fatal("fopen: %s", strerror(errno));
669
		fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
672
670
673
	/*
671
	/*
674
	 * Find hosts goes to stdout, hash and deletions happen in-place
672
	 * Find hosts goes to stdout, hash and deletions happen in-place
Lines 1415-1424 do_show_cert(struct passwd *pw) Link Here
1415
1413
1416
	if (!have_identity)
1414
	if (!have_identity)
1417
		ask_filename(pw, "Enter file in which the key is");
1415
		ask_filename(pw, "Enter file in which the key is");
1418
	if (stat(identity_file, &st) < 0) {
1416
	if (stat(identity_file, &st) < 0)
1419
		perror(identity_file);
1417
		fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
1420
		exit(1);
1421
	}
1422
	if ((key = key_load_public(identity_file, NULL)) == NULL)
1418
	if ((key = key_load_public(identity_file, NULL)) == NULL)
1423
		fatal("%s is not a public key", identity_file);
1419
		fatal("%s is not a public key", identity_file);
1424
	if (!key_is_cert(key))
1420
	if (!key_is_cert(key))

Return to bug 1783