]> andersk Git - gssapi-openssh.git/blobdiff - openssh/ssh-keygen.c
Import of OpenSSH 4.9p1
[gssapi-openssh.git] / openssh / ssh-keygen.c
index 04a9b939ad5db5457a4e4a558e78ddb59ec1b206..69b16e6f50e2ffe4ef8410b4cee772fe24d3930b 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keygen.c,v 1.160 2007/01/21 01:41:54 stevesk Exp $ */
+/* $OpenBSD: ssh-keygen.c,v 1.165 2008/01/19 22:37:19 djm Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -21,6 +21,7 @@
 
 #include <openssl/evp.h>
 #include <openssl/pem.h>
+#include "openbsd-compat/openssl-compat.h"
 
 #include <errno.h>
 #include <fcntl.h>
@@ -141,8 +142,7 @@ ask_filename(struct passwd *pw, const char *prompt)
        fprintf(stderr, "%s (%s): ", prompt, identity_file);
        if (fgets(buf, sizeof(buf), stdin) == NULL)
                exit(1);
-       if (strchr(buf, '\n'))
-               *strchr(buf, '\n') = 0;
+       buf[strcspn(buf, "\n")] = '\0';
        if (strcmp(buf, "") != 0)
                strlcpy(identity_file, buf, sizeof(identity_file));
        have_identity = 1;
@@ -505,7 +505,7 @@ do_fingerprint(struct passwd *pw)
        FILE *f;
        Key *public;
        char *comment = NULL, *cp, *ep, line[16*1024], *fp;
-       int i, skip = 0, num = 1, invalid = 1;
+       int i, skip = 0, num = 0, invalid = 1;
        enum fp_rep rep;
        enum fp_type fptype;
        struct stat st;
@@ -536,9 +536,9 @@ do_fingerprint(struct passwd *pw)
        f = fopen(identity_file, "r");
        if (f != NULL) {
                while (fgets(line, sizeof(line), f)) {
-                       i = strlen(line) - 1;
-                       if (line[i] != '\n') {
-                               error("line %d too long: %.40s...", num, line);
+                       if ((cp = strchr(line, '\n')) == NULL) {
+                               error("line %d too long: %.40s...",
+                                   num + 1, line);
                                skip = 1;
                                continue;
                        }
@@ -547,7 +547,7 @@ do_fingerprint(struct passwd *pw)
                                skip = 0;
                                continue;
                        }
-                       line[i] = '\0';
+                       *cp = '\0';
 
                        /* Skip leading whitespace, empty and comment lines. */
                        for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
@@ -598,7 +598,7 @@ do_fingerprint(struct passwd *pw)
 }
 
 static void
-print_host(FILE *f, char *name, Key *public, int hash)
+print_host(FILE *f, const char *name, Key *public, int hash)
 {
        if (hash && (name = host_hash(name, NULL, 0)) == NULL)
                fatal("hash_host failed");
@@ -615,7 +615,7 @@ do_known_hosts(struct passwd *pw, const char *name)
        Key *public;
        char *cp, *cp2, *kp, *kp2;
        char line[16*1024], tmp[MAXPATHLEN], old[MAXPATHLEN];
-       int c, i, skip = 0, inplace = 0, num = 0, invalid = 0, has_unhashed = 0;
+       int c, skip = 0, inplace = 0, num = 0, invalid = 0, has_unhashed = 0;
 
        if (!have_identity) {
                cp = tilde_expand_filename(_PATH_SSH_USER_HOSTFILE, pw->pw_uid);
@@ -650,19 +650,18 @@ do_known_hosts(struct passwd *pw, const char *name)
        }
 
        while (fgets(line, sizeof(line), in)) {
-               num++;
-               i = strlen(line) - 1;
-               if (line[i] != '\n') {
-                       error("line %d too long: %.40s...", num, line);
+               if ((cp = strchr(line, '\n')) == NULL) {
+                       error("line %d too long: %.40s...", num + 1, line);
                        skip = 1;
                        invalid = 1;
                        continue;
                }
+               num++;
                if (skip) {
                        skip = 0;
                        continue;
                }
-               line[i] = '\0';
+               *cp = '\0';
 
                /* Skip leading whitespace, empty and comment lines. */
                for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
@@ -726,7 +725,8 @@ do_known_hosts(struct passwd *pw, const char *name)
                                        printf("# Host %s found: "
                                            "line %d type %s\n", name,
                                            num, key_type(public));
-                                       print_host(out, cp, public, hash_hosts);
+                                       print_host(out, name, public,
+                                           hash_hosts);
                                }
                                if (delete_host && !c)
                                        print_host(out, cp, public, 0);
@@ -750,7 +750,7 @@ do_known_hosts(struct passwd *pw, const char *name)
        fclose(in);
 
        if (invalid) {
-               fprintf(stderr, "%s is not a valid known_host file.\n",
+               fprintf(stderr, "%s is not a valid known_hosts file.\n",
                    identity_file);
                if (inplace) {
                        fprintf(stderr, "Not replacing existing known_hosts "
@@ -962,8 +962,7 @@ do_change_comment(struct passwd *pw)
                        key_free(private);
                        exit(1);
                }
-               if (strchr(new_comment, '\n'))
-                       *strchr(new_comment, '\n') = 0;
+               new_comment[strcspn(new_comment, "\n")] = '\0';
        }
 
        /* Save the file using the new passphrase. */
@@ -1006,7 +1005,7 @@ do_change_comment(struct passwd *pw)
 static void
 usage(void)
 {
-       fprintf(stderr, "Usage: %s [options]\n", __progname);
+       fprintf(stderr, "usage: %s [options]\n", __progname);
        fprintf(stderr, "Options:\n");
        fprintf(stderr, "  -a trials   Number of trials for screening DH-GEX moduli.\n");
        fprintf(stderr, "  -B          Show bubblebabble digest of key file.\n");
This page took 0.543534 seconds and 4 git commands to generate.