version 1.2, 1999/09/28 04:45:37 |
version 1.5, 1999/09/29 21:14:16 |
|
|
#include "includes.h" |
#include "includes.h" |
RCSID("$Id$"); |
RCSID("$Id$"); |
|
|
#ifndef HAVE_GETHOSTNAME |
|
#include <sys/utsname.h> |
|
#endif |
|
#include "rsa.h" |
#include "rsa.h" |
#include "ssh.h" |
#include "ssh.h" |
#include "xmalloc.h" |
#include "xmalloc.h" |
|
|
if (strchr(buf, '\n')) |
if (strchr(buf, '\n')) |
*strchr(buf, '\n') = 0; |
*strchr(buf, '\n') = 0; |
if (strcmp(buf, "") == 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. */ |
/* Check if the file exists. */ |
|
|
if (strchr(buf, '\n')) |
if (strchr(buf, '\n')) |
*strchr(buf, '\n') = 0; |
*strchr(buf, '\n') = 0; |
if (strcmp(buf, "") == 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. */ |
/* Check if the file exists. */ |
|
|
int opt; |
int opt; |
struct stat st; |
struct stat st; |
FILE *f; |
FILE *f; |
#ifdef HAVE_GETHOSTNAME |
char hostname[MAXHOSTNAMELEN]; |
char hostname[257]; |
|
#else |
|
struct utsname uts; |
|
#endif |
|
extern int optind; |
extern int optind; |
extern char *optarg; |
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. */ |
/* Get user\'s passwd structure. We need this for the home directory. */ |
pw = getpwuid(getuid()); |
pw = getpwuid(getuid()); |
if (!pw) |
if (!pw) |
|
|
} |
} |
|
|
/* Create ~/.ssh directory if it doesn\'t already exist. */ |
/* 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 (stat(buf, &st) < 0) |
if (mkdir(buf, 0755) < 0) |
if (mkdir(buf, 0755) < 0) |
error("Could not create directory '%s'.", buf); |
error("Could not create directory '%s'.", buf); |
|
|
/* Parse command line arguments. */ |
/* 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) |
switch (opt) |
{ |
{ |
|
|
if (strchr(buf, '\n')) |
if (strchr(buf, '\n')) |
*strchr(buf, '\n') = 0; |
*strchr(buf, '\n') = 0; |
if (strcmp(buf, "") == 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. */ |
/* If the file aready exists, ask the user to confirm. */ |
|
|
edit this field. */ |
edit this field. */ |
if (identity_comment) |
if (identity_comment) |
{ |
{ |
strncpy(buf2, identity_comment, sizeof(buf2)); |
strlcpy(buf2, identity_comment, sizeof(buf2)); |
buf2[sizeof(buf2) - 1] = '\0'; |
|
} |
} |
else |
else |
{ |
{ |
#ifdef HAVE_GETHOSTNAME |
|
if (gethostname(hostname, sizeof(hostname)) < 0) |
if (gethostname(hostname, sizeof(hostname)) < 0) |
{ |
{ |
perror("gethostname"); |
perror("gethostname"); |
exit(1); |
exit(1); |
} |
} |
sprintf(buf2, "%s@%s", pw->pw_name, hostname); |
snprintf(buf2, sizeof 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 |
|
} |
} |
|
|
/* Save the key with the given passphrase and comment. */ |
/* Save the key with the given passphrase and comment. */ |