]> andersk Git - openssh.git/blobdiff - ssh-keygen.c
20070326
[openssh.git] / ssh-keygen.c
index ef417514ae105dc60a47d9382fd8b627cfc9c381..04a9b939ad5db5457a4e4a558e78ddb59ec1b206 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keygen.c,v 1.143 2006/03/30 11:05:17 dtucker Exp $ */
+/* $OpenBSD: ssh-keygen.c,v 1.160 2007/01/21 01:41:54 stevesk Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
 #include "includes.h"
 
 #include <sys/types.h>
+#include <sys/socket.h>
 #include <sys/stat.h>
+#include <sys/param.h>
 
 #include <openssl/evp.h>
 #include <openssl/pem.h>
 
+#include <errno.h>
+#include <fcntl.h>
+#include <netdb.h>
+#ifdef HAVE_PATHS_H
+# include <paths.h>
+#endif
+#include <pwd.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
 #include "xmalloc.h"
 #include "key.h"
 #include "rsa.h"
 #include "authfile.h"
 #include "uuencode.h"
 #include "buffer.h"
-#include "bufaux.h"
 #include "pathnames.h"
 #include "log.h"
 #include "misc.h"
 #include "match.h"
 #include "hostfile.h"
+#include "dns.h"
 
 #ifdef SMARTCARD
 #include "scard.h"
 #endif
-#include "dns.h"
 
 /* Number of bits in the RSA/DSA key.  This value can be set on the command line. */
 #define DEFAULT_BITS           2048
@@ -208,7 +222,8 @@ buffer_get_bignum_bits(Buffer *b, BIGNUM *value)
        if (buffer_len(b) < bytes)
                fatal("buffer_get_bignum_bits: input buffer too small: "
                    "need %d have %d", bytes, buffer_len(b));
-       BN_bin2bn(buffer_ptr(b), bytes, value);
+       if (BN_bin2bn(buffer_ptr(b), bytes, value) == NULL)
+               fatal("buffer_get_bignum_bits: BN_bin2bn failed");
        buffer_consume(b, bytes);
 }
 
@@ -226,7 +241,7 @@ do_convert_private_ssh2_from_blob(u_char *blob, u_int blen)
        buffer_init(&b);
        buffer_append(&b, blob, blen);
 
-       magic  = buffer_get_int(&b);
+       magic = buffer_get_int(&b);
        if (magic != SSH_COM_PRIVATE_KEY_MAGIC) {
                error("bad magic 0x%x != 0x%x", magic, SSH_COM_PRIVATE_KEY_MAGIC);
                buffer_free(&b);
@@ -238,7 +253,7 @@ do_convert_private_ssh2_from_blob(u_char *blob, u_int blen)
        i2 = buffer_get_int(&b);
        i3 = buffer_get_int(&b);
        i4 = buffer_get_int(&b);
-       debug("ignore (%d %d %d %d)", i1,i2,i3,i4);
+       debug("ignore (%d %d %d %d)", i1, i2, i3, i4);
        if (strcmp(cipher, "none") != 0) {
                error("unsupported cipher %s", cipher);
                xfree(cipher);
@@ -269,7 +284,7 @@ do_convert_private_ssh2_from_blob(u_char *blob, u_int blen)
                buffer_get_bignum_bits(&b, key->dsa->priv_key);
                break;
        case KEY_RSA:
-               e  = buffer_get_char(&b);
+               e = buffer_get_char(&b);
                debug("e %lx", e);
                if (e < 30) {
                        e <<= 8;
@@ -331,9 +346,8 @@ get_line(FILE *fp, char *line, size_t len)
                line[pos++] = c;
                line[pos] = '\0';
        }
-       if (c == EOF)
-               return -1;
-       return pos;
+       /* We reached EOF */
+       return -1;
 }
 
 static void
@@ -514,8 +528,10 @@ do_fingerprint(struct passwd *pw)
                xfree(fp);
                exit(0);
        }
-       if (comment)
+       if (comment) {
                xfree(comment);
+               comment = NULL;
+       }
 
        f = fopen(identity_file, "r");
        if (f != NULL) {
@@ -537,7 +553,7 @@ do_fingerprint(struct passwd *pw)
                        for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
                                ;
                        if (!*cp || *cp == '\n' || *cp == '#')
-                               continue ;
+                               continue;
                        i = strtol(cp, &ep, 10);
                        if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) {
                                int quoted = 0;
@@ -1000,13 +1016,13 @@ usage(void)
 #ifdef SMARTCARD
        fprintf(stderr, "  -D reader   Download public key from smartcard.\n");
 #endif /* SMARTCARD */
-       fprintf(stderr, "  -e          Convert OpenSSH to IETF SECSH key file.\n");
+       fprintf(stderr, "  -e          Convert OpenSSH to RFC 4716 key file.\n");
        fprintf(stderr, "  -F hostname Find hostname in known hosts file.\n");
        fprintf(stderr, "  -f filename Filename of the key file.\n");
        fprintf(stderr, "  -G file     Generate candidates for DH-GEX moduli.\n");
        fprintf(stderr, "  -g          Use generic DNS resource record format.\n");
        fprintf(stderr, "  -H          Hash names in known_hosts file.\n");
-       fprintf(stderr, "  -i          Convert IETF SECSH to OpenSSH key file.\n");
+       fprintf(stderr, "  -i          Convert RFC 4716 to OpenSSH key file.\n");
        fprintf(stderr, "  -l          Show fingerprint of key file.\n");
        fprintf(stderr, "  -M memory   Amount of memory (MB) to use for generating DH-GEX moduli.\n");
        fprintf(stderr, "  -N phrase   Provide new passphrase.\n");
@@ -1032,7 +1048,7 @@ usage(void)
  * Main program for key management.
  */
 int
-main(int ac, char **av)
+main(int argc, char **argv)
 {
        char dotsshdir[MAXPATHLEN], comment[1024], *passphrase1, *passphrase2;
        char out_file[MAXPATHLEN], *reader_id = NULL;
@@ -1054,10 +1070,10 @@ main(int ac, char **av)
        /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
        sanitise_stdfd();
 
-       __progname = ssh_get_progname(av[0]);
+       __progname = ssh_get_progname(argv[0]);
 
        SSLeay_add_all_algorithms();
-       log_init(av[0], SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_USER, 1);
+       log_init(argv[0], SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_USER, 1);
 
        init_rng();
        seed_rng();
@@ -1073,7 +1089,7 @@ main(int ac, char **av)
                exit(1);
        }
 
-       while ((opt = getopt(ac, av,
+       while ((opt = getopt(argc, argv,
            "degiqpclBHvxXyF:b:f:t:U:D:P:N:C:r:g:R:T:G:M:S:a:W:")) != -1) {
                switch (opt) {
                case 'b':
@@ -1206,9 +1222,9 @@ main(int ac, char **av)
        }
 
        /* reinit */
-       log_init(av[0], log_level, SYSLOG_FACILITY_USER, 1);
+       log_init(argv[0], log_level, SYSLOG_FACILITY_USER, 1);
 
-       if (optind < ac) {
+       if (optind < argc) {
                printf("Too many arguments.\n");
                usage();
        }
This page took 0.044422 seconds and 4 git commands to generate.