mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-27 07:54:50 +02:00
ssh client creates .ssh directory and points to well defined files relative to user home directory
Will fix problems like new hosts to be added to known_hosts file which was failing when .ssh directory did not exist. Also default user's public keys like id_rsa pairs are picked up properly from the user's homdir/.ssh base.
This commit is contained in:
parent
673d697444
commit
f384477c6d
41
readconf.c
41
readconf.c
@ -294,6 +294,11 @@ static struct {
|
|||||||
{ NULL, oBadOption }
|
{ NULL, oBadOption }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef WIN32_FIXME
|
||||||
|
char user_hostfile_name[MAX_PATH] ; // full path of "known_hosts"
|
||||||
|
char user_hostfile_name2[MAX_PATH] ; // full path of "known_hosts2"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adds a local TCP/IP port forward to options. Never returns if there is an
|
* Adds a local TCP/IP port forward to options. Never returns if there is an
|
||||||
* error.
|
* error.
|
||||||
@ -379,7 +384,7 @@ clear_forwardings(Options *options)
|
|||||||
|
|
||||||
void
|
void
|
||||||
add_identity_file(Options *options, const char *dir, const char *filename,
|
add_identity_file(Options *options, const char *dir, const char *filename,
|
||||||
int userprovided)
|
int userprovided, struct passwd *pw)
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
int i;
|
int i;
|
||||||
@ -391,7 +396,12 @@ add_identity_file(Options *options, const char *dir, const char *filename,
|
|||||||
if (dir == NULL) /* no dir, filename is absolute */
|
if (dir == NULL) /* no dir, filename is absolute */
|
||||||
path = xstrdup(filename);
|
path = xstrdup(filename);
|
||||||
else
|
else
|
||||||
|
#ifndef WIN32_FIXME
|
||||||
(void)xasprintf(&path, "%.100s%.100s", dir, filename);
|
(void)xasprintf(&path, "%.100s%.100s", dir, filename);
|
||||||
|
#else
|
||||||
|
if ( strcmp(dir, "~/") == 0)
|
||||||
|
(void)xasprintf(&path, "%.100s\\%.100s", pw->pw_dir, filename);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Avoid registering duplicates */
|
/* Avoid registering duplicates */
|
||||||
for (i = 0; i < options->num_identity_files; i++) {
|
for (i = 0; i < options->num_identity_files; i++) {
|
||||||
@ -995,7 +1005,7 @@ parse_time:
|
|||||||
fatal("%.200s line %d: Too many identity files specified (max %d).",
|
fatal("%.200s line %d: Too many identity files specified (max %d).",
|
||||||
filename, linenum, SSH_MAX_IDENTITY_FILES);
|
filename, linenum, SSH_MAX_IDENTITY_FILES);
|
||||||
add_identity_file(options, NULL,
|
add_identity_file(options, NULL,
|
||||||
arg, flags & SSHCONF_USERCONF);
|
arg, flags & SSHCONF_USERCONF, pw);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1748,9 +1758,18 @@ fill_default_options_for_canonicalization(Options *options)
|
|||||||
* Called after processing other sources of option data, this fills those
|
* Called after processing other sources of option data, this fills those
|
||||||
* options for which no value has been specified with their default values.
|
* options for which no value has been specified with their default values.
|
||||||
*/
|
*/
|
||||||
|
#ifndef WIN32_FIXME
|
||||||
void
|
void
|
||||||
fill_default_options(Options * options)
|
fill_default_options(Options * options)
|
||||||
|
#else
|
||||||
|
void fill_default_options(Options * options, struct passwd *pw)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
|
#ifdef WIN32_FIXME
|
||||||
|
sprintf(user_hostfile_name,"%s\\%s\\known_hosts", pw->pw_dir, _PATH_SSH_USER_DIR );// SSH_USER_HOSTFILE2;
|
||||||
|
sprintf(user_hostfile_name2,"%s\\%s\\known_hosts2", pw->pw_dir, _PATH_SSH_USER_DIR );// SSH_USER_HOSTFILE2;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (options->forward_agent == -1)
|
if (options->forward_agent == -1)
|
||||||
options->forward_agent = 0;
|
options->forward_agent = 0;
|
||||||
if (options->forward_x11 == -1)
|
if (options->forward_x11 == -1)
|
||||||
@ -1818,19 +1837,19 @@ fill_default_options(Options * options)
|
|||||||
if (options->num_identity_files == 0) {
|
if (options->num_identity_files == 0) {
|
||||||
if (options->protocol & SSH_PROTO_1) {
|
if (options->protocol & SSH_PROTO_1) {
|
||||||
add_identity_file(options, "~/",
|
add_identity_file(options, "~/",
|
||||||
_PATH_SSH_CLIENT_IDENTITY, 0);
|
_PATH_SSH_CLIENT_IDENTITY, 0, pw);
|
||||||
}
|
}
|
||||||
if (options->protocol & SSH_PROTO_2) {
|
if (options->protocol & SSH_PROTO_2) {
|
||||||
add_identity_file(options, "~/",
|
add_identity_file(options, "~/",
|
||||||
_PATH_SSH_CLIENT_ID_RSA, 0);
|
_PATH_SSH_CLIENT_ID_RSA, 0, pw);
|
||||||
add_identity_file(options, "~/",
|
add_identity_file(options, "~/",
|
||||||
_PATH_SSH_CLIENT_ID_DSA, 0);
|
_PATH_SSH_CLIENT_ID_DSA, 0, pw);
|
||||||
#ifdef OPENSSL_HAS_ECC
|
#ifdef OPENSSL_HAS_ECC
|
||||||
add_identity_file(options, "~/",
|
add_identity_file(options, "~/",
|
||||||
_PATH_SSH_CLIENT_ID_ECDSA, 0);
|
_PATH_SSH_CLIENT_ID_ECDSA, 0, pw);
|
||||||
#endif
|
#endif
|
||||||
add_identity_file(options, "~/",
|
add_identity_file(options, "~/",
|
||||||
_PATH_SSH_CLIENT_ID_ED25519, 0);
|
_PATH_SSH_CLIENT_ID_ED25519, 0, pw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options->escape_char == -1)
|
if (options->escape_char == -1)
|
||||||
@ -1843,9 +1862,17 @@ fill_default_options(Options * options)
|
|||||||
}
|
}
|
||||||
if (options->num_user_hostfiles == 0) {
|
if (options->num_user_hostfiles == 0) {
|
||||||
options->user_hostfiles[options->num_user_hostfiles++] =
|
options->user_hostfiles[options->num_user_hostfiles++] =
|
||||||
|
#ifdef WIN32_FIXME
|
||||||
|
user_hostfile_name ;
|
||||||
|
#else
|
||||||
xstrdup(_PATH_SSH_USER_HOSTFILE);
|
xstrdup(_PATH_SSH_USER_HOSTFILE);
|
||||||
|
#endif
|
||||||
options->user_hostfiles[options->num_user_hostfiles++] =
|
options->user_hostfiles[options->num_user_hostfiles++] =
|
||||||
|
#ifdef WIN32_FIXME
|
||||||
|
user_hostfile_name2 ;
|
||||||
|
#else
|
||||||
xstrdup(_PATH_SSH_USER_HOSTFILE2);
|
xstrdup(_PATH_SSH_USER_HOSTFILE2);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (options->log_level == SYSLOG_LEVEL_NOT_SET)
|
if (options->log_level == SYSLOG_LEVEL_NOT_SET)
|
||||||
options->log_level = SYSLOG_LEVEL_INFO;
|
options->log_level = SYSLOG_LEVEL_INFO;
|
||||||
|
@ -189,7 +189,11 @@ typedef struct {
|
|||||||
#define SSH_UPDATE_HOSTKEYS_ASK 2
|
#define SSH_UPDATE_HOSTKEYS_ASK 2
|
||||||
|
|
||||||
void initialize_options(Options *);
|
void initialize_options(Options *);
|
||||||
|
#ifdef WIN32_FIXME
|
||||||
|
void fill_default_options(Options *, struct passwd *pw);
|
||||||
|
#else
|
||||||
void fill_default_options(Options *);
|
void fill_default_options(Options *);
|
||||||
|
#endif
|
||||||
void fill_default_options_for_canonicalization(Options *);
|
void fill_default_options_for_canonicalization(Options *);
|
||||||
int process_config_line(Options *, struct passwd *, const char *,
|
int process_config_line(Options *, struct passwd *, const char *,
|
||||||
const char *, char *, const char *, int, int *, int);
|
const char *, char *, const char *, int, int *, int);
|
||||||
@ -202,6 +206,6 @@ void dump_client_config(Options *o, const char *host);
|
|||||||
|
|
||||||
void add_local_forward(Options *, const struct Forward *);
|
void add_local_forward(Options *, const struct Forward *);
|
||||||
void add_remote_forward(Options *, const struct Forward *);
|
void add_remote_forward(Options *, const struct Forward *);
|
||||||
void add_identity_file(Options *, const char *, const char *, int);
|
void add_identity_file(Options *, const char *, const char *, int, struct passwd *);
|
||||||
|
|
||||||
#endif /* READCONF_H */
|
#endif /* READCONF_H */
|
||||||
|
@ -1 +1,2 @@
|
|||||||
./configure --build=i686-pc-mingw32 --host=i686-pc-mingw32 --with-ssl-dir=../openssl-1.0.2d --with-zlib=../zlib-1.2.8 --with-kerberos5
|
@REM ./configure --build=i686-pc-mingw32 --host=i686-pc-mingw32 --with-ssl-dir=../openssl-1.0.2d --with-zlib=../zlib-1.2.8 --with-kerberos5
|
||||||
|
./configure --build=i686-pc-mingw32 --host=i686-pc-mingw32 --with-ssl-dir=../openssl-1.0.2d --with-kerberos5
|
@ -209,7 +209,13 @@ main(int argc, char **argv)
|
|||||||
/* verify that ssh-keysign is enabled by the admin */
|
/* verify that ssh-keysign is enabled by the admin */
|
||||||
initialize_options(&options);
|
initialize_options(&options);
|
||||||
(void)read_config_file(_PATH_HOST_CONFIG_FILE, pw, "", "", &options, 0);
|
(void)read_config_file(_PATH_HOST_CONFIG_FILE, pw, "", "", &options, 0);
|
||||||
|
|
||||||
|
#ifndef WIN32_FIXME
|
||||||
fill_default_options(&options);
|
fill_default_options(&options);
|
||||||
|
#else
|
||||||
|
fill_default_options(&options, pw);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (options.enable_ssh_keysign != 1)
|
if (options.enable_ssh_keysign != 1)
|
||||||
fatal("ssh-keysign not enabled in %s",
|
fatal("ssh-keysign not enabled in %s",
|
||||||
_PATH_HOST_CONFIG_FILE);
|
_PATH_HOST_CONFIG_FILE);
|
||||||
|
13
ssh.c
13
ssh.c
@ -126,6 +126,8 @@
|
|||||||
extern int PassInputFd;
|
extern int PassInputFd;
|
||||||
extern int PassOutputFd;
|
extern int PassOutputFd;
|
||||||
|
|
||||||
|
char dotsshdir[MAX_PATH];
|
||||||
|
|
||||||
#endif /* WIN32_FIXME */
|
#endif /* WIN32_FIXME */
|
||||||
|
|
||||||
extern char *__progname;
|
extern char *__progname;
|
||||||
@ -587,6 +589,7 @@ main(int ac, char **av)
|
|||||||
char cname[NI_MAXHOST];
|
char cname[NI_MAXHOST];
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
|
||||||
int timeout_ms;
|
int timeout_ms;
|
||||||
extern int optind, optreset;
|
extern int optind, optreset;
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
@ -811,7 +814,7 @@ main(int ac, char **av)
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
add_identity_file(&options, NULL, optarg, 1);
|
add_identity_file(&options, NULL, optarg, 1, pw);
|
||||||
break;
|
break;
|
||||||
case 'I':
|
case 'I':
|
||||||
#ifdef ENABLE_PKCS11
|
#ifdef ENABLE_PKCS11
|
||||||
@ -1055,6 +1058,10 @@ main(int ac, char **av)
|
|||||||
PassOutputFd = _open_osfhandle(options.passOutputHandle_, O_WRONLY);
|
PassOutputFd = _open_osfhandle(options.passOutputHandle_, O_WRONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create various Windows user home directory based file names
|
||||||
|
sprintf(dotsshdir,"%s\\%s", pw->pw_dir, _PATH_SSH_USER_DIR );
|
||||||
|
_mkdir(dotsshdir); //this base directory for the user is needed
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Check that we got a host name. */
|
/* Check that we got a host name. */
|
||||||
@ -1189,7 +1196,11 @@ main(int ac, char **av)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Fill configuration defaults. */
|
/* Fill configuration defaults. */
|
||||||
|
#ifndef WIN32_FIXME
|
||||||
fill_default_options(&options);
|
fill_default_options(&options);
|
||||||
|
#else
|
||||||
|
fill_default_options(&options, pw);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (options.port == 0)
|
if (options.port == 0)
|
||||||
options.port = default_ssh_port();
|
options.port = default_ssh_port();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user