=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/ssh-keygen.c,v retrieving revision 1.2 retrieving revision 1.5 diff -u -r1.2 -r1.5 --- src/usr.bin/ssh/ssh-keygen.c 1999/09/28 04:45:37 1.2 +++ src/usr.bin/ssh/ssh-keygen.c 1999/09/29 21:14:16 1.5 @@ -14,11 +14,8 @@ */ #include "includes.h" -RCSID("$Id: ssh-keygen.c,v 1.2 1999/09/28 04:45:37 provos Exp $"); +RCSID("$Id: ssh-keygen.c,v 1.5 1999/09/29 21:14:16 deraadt Exp $"); -#ifndef HAVE_GETHOSTNAME -#include -#endif #include "rsa.h" #include "ssh.h" #include "xmalloc.h" @@ -78,7 +75,7 @@ if (strchr(buf, '\n')) *strchr(buf, '\n') = 0; if (strcmp(buf, "") == 0) - sprintf(buf, "%s/%s", pw->pw_dir, SSH_CLIENT_IDENTITY); + snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, SSH_CLIENT_IDENTITY); } /* Check if the file exists. */ @@ -197,7 +194,7 @@ if (strchr(buf, '\n')) *strchr(buf, '\n') = 0; if (strcmp(buf, "") == 0) - sprintf(buf, "%s/%s", pw->pw_dir, SSH_CLIENT_IDENTITY); + snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, SSH_CLIENT_IDENTITY); } /* Check if the file exists. */ @@ -314,14 +311,20 @@ int opt; struct stat st; FILE *f; -#ifdef HAVE_GETHOSTNAME - char hostname[257]; -#else - struct utsname uts; -#endif + char hostname[MAXHOSTNAMELEN]; extern int optind; extern char *optarg; + /* check if RSA support exists */ + if (rsa_alive() == 0) { + extern char *__progname; + + fprintf(stderr, + "%s: no RSA support in libssl and libcrypto. See ssl(8).\n", + __progname); + exit(1); + } + /* Get user\'s passwd structure. We need this for the home directory. */ pw = getpwuid(getuid()); if (!pw) @@ -331,13 +334,13 @@ } /* Create ~/.ssh directory if it doesn\'t already exist. */ - sprintf(buf, "%s/%s", pw->pw_dir, SSH_USER_DIR); + snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, SSH_USER_DIR); if (stat(buf, &st) < 0) if (mkdir(buf, 0755) < 0) error("Could not create directory '%s'.", buf); /* Parse command line arguments. */ - while ((opt = getopt(ac, av, "pcb:f:P:N:C:")) != EOF) + while ((opt = getopt(ac, av, "qpcb:f:P:N:C:")) != EOF) { switch (opt) { @@ -438,7 +441,7 @@ if (strchr(buf, '\n')) *strchr(buf, '\n') = 0; if (strcmp(buf, "") == 0) - sprintf(buf, "%s/%s", pw->pw_dir, SSH_CLIENT_IDENTITY); + snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, SSH_CLIENT_IDENTITY); } /* If the file aready exists, ask the user to confirm. */ @@ -484,26 +487,16 @@ edit this field. */ if (identity_comment) { - strncpy(buf2, identity_comment, sizeof(buf2)); - buf2[sizeof(buf2) - 1] = '\0'; + strlcpy(buf2, identity_comment, sizeof(buf2)); } else { -#ifdef HAVE_GETHOSTNAME if (gethostname(hostname, sizeof(hostname)) < 0) { perror("gethostname"); exit(1); } - sprintf(buf2, "%s@%s", pw->pw_name, hostname); -#else - if (uname(&uts) < 0) - { - perror("uname"); - exit(1); - } - sprintf(buf2, "%s@%s", pw->pw_name, uts.nodename); -#endif + snprintf(buf2, sizeof buf2, "%s@%s", pw->pw_name, hostname); } /* Save the key with the given passphrase and comment. */