Skip to content

Commit f384477

Browse files
committed
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.
1 parent 673d697 commit f384477

File tree

5 files changed

+59
-10
lines changed

5 files changed

+59
-10
lines changed

readconf.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ static struct {
294294
{ NULL, oBadOption }
295295
};
296296

297+
#ifdef WIN32_FIXME
298+
char user_hostfile_name[MAX_PATH] ; // full path of "known_hosts"
299+
char user_hostfile_name2[MAX_PATH] ; // full path of "known_hosts2"
300+
#endif
301+
297302
/*
298303
* Adds a local TCP/IP port forward to options. Never returns if there is an
299304
* error.
@@ -379,7 +384,7 @@ clear_forwardings(Options *options)
379384

380385
void
381386
add_identity_file(Options *options, const char *dir, const char *filename,
382-
int userprovided)
387+
int userprovided, struct passwd *pw)
383388
{
384389
char *path;
385390
int i;
@@ -391,7 +396,12 @@ add_identity_file(Options *options, const char *dir, const char *filename,
391396
if (dir == NULL) /* no dir, filename is absolute */
392397
path = xstrdup(filename);
393398
else
399+
#ifndef WIN32_FIXME
394400
(void)xasprintf(&path, "%.100s%.100s", dir, filename);
401+
#else
402+
if ( strcmp(dir, "~/") == 0)
403+
(void)xasprintf(&path, "%.100s\\%.100s", pw->pw_dir, filename);
404+
#endif
395405

396406
/* Avoid registering duplicates */
397407
for (i = 0; i < options->num_identity_files; i++) {
@@ -995,7 +1005,7 @@ process_config_line(Options *options, struct passwd *pw, const char *host,
9951005
fatal("%.200s line %d: Too many identity files specified (max %d).",
9961006
filename, linenum, SSH_MAX_IDENTITY_FILES);
9971007
add_identity_file(options, NULL,
998-
arg, flags & SSHCONF_USERCONF);
1008+
arg, flags & SSHCONF_USERCONF, pw);
9991009
}
10001010
break;
10011011

@@ -1748,9 +1758,18 @@ fill_default_options_for_canonicalization(Options *options)
17481758
* Called after processing other sources of option data, this fills those
17491759
* options for which no value has been specified with their default values.
17501760
*/
1761+
#ifndef WIN32_FIXME
17511762
void
17521763
fill_default_options(Options * options)
1764+
#else
1765+
void fill_default_options(Options * options, struct passwd *pw)
1766+
#endif
17531767
{
1768+
#ifdef WIN32_FIXME
1769+
sprintf(user_hostfile_name,"%s\\%s\\known_hosts", pw->pw_dir, _PATH_SSH_USER_DIR );// SSH_USER_HOSTFILE2;
1770+
sprintf(user_hostfile_name2,"%s\\%s\\known_hosts2", pw->pw_dir, _PATH_SSH_USER_DIR );// SSH_USER_HOSTFILE2;
1771+
#endif
1772+
17541773
if (options->forward_agent == -1)
17551774
options->forward_agent = 0;
17561775
if (options->forward_x11 == -1)
@@ -1818,19 +1837,19 @@ fill_default_options(Options * options)
18181837
if (options->num_identity_files == 0) {
18191838
if (options->protocol & SSH_PROTO_1) {
18201839
add_identity_file(options, "~/",
1821-
_PATH_SSH_CLIENT_IDENTITY, 0);
1840+
_PATH_SSH_CLIENT_IDENTITY, 0, pw);
18221841
}
18231842
if (options->protocol & SSH_PROTO_2) {
18241843
add_identity_file(options, "~/",
1825-
_PATH_SSH_CLIENT_ID_RSA, 0);
1844+
_PATH_SSH_CLIENT_ID_RSA, 0, pw);
18261845
add_identity_file(options, "~/",
1827-
_PATH_SSH_CLIENT_ID_DSA, 0);
1846+
_PATH_SSH_CLIENT_ID_DSA, 0, pw);
18281847
#ifdef OPENSSL_HAS_ECC
18291848
add_identity_file(options, "~/",
1830-
_PATH_SSH_CLIENT_ID_ECDSA, 0);
1849+
_PATH_SSH_CLIENT_ID_ECDSA, 0, pw);
18311850
#endif
18321851
add_identity_file(options, "~/",
1833-
_PATH_SSH_CLIENT_ID_ED25519, 0);
1852+
_PATH_SSH_CLIENT_ID_ED25519, 0, pw);
18341853
}
18351854
}
18361855
if (options->escape_char == -1)
@@ -1843,9 +1862,17 @@ fill_default_options(Options * options)
18431862
}
18441863
if (options->num_user_hostfiles == 0) {
18451864
options->user_hostfiles[options->num_user_hostfiles++] =
1865+
#ifdef WIN32_FIXME
1866+
user_hostfile_name ;
1867+
#else
18461868
xstrdup(_PATH_SSH_USER_HOSTFILE);
1869+
#endif
18471870
options->user_hostfiles[options->num_user_hostfiles++] =
1871+
#ifdef WIN32_FIXME
1872+
user_hostfile_name2 ;
1873+
#else
18481874
xstrdup(_PATH_SSH_USER_HOSTFILE2);
1875+
#endif
18491876
}
18501877
if (options->log_level == SYSLOG_LEVEL_NOT_SET)
18511878
options->log_level = SYSLOG_LEVEL_INFO;

readconf.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ typedef struct {
189189
#define SSH_UPDATE_HOSTKEYS_ASK 2
190190

191191
void initialize_options(Options *);
192+
#ifdef WIN32_FIXME
193+
void fill_default_options(Options *, struct passwd *pw);
194+
#else
192195
void fill_default_options(Options *);
196+
#endif
193197
void fill_default_options_for_canonicalization(Options *);
194198
int process_config_line(Options *, struct passwd *, const char *,
195199
const char *, char *, const char *, int, int *, int);
@@ -202,6 +206,6 @@ void dump_client_config(Options *o, const char *host);
202206

203207
void add_local_forward(Options *, const struct Forward *);
204208
void add_remote_forward(Options *, const struct Forward *);
205-
void add_identity_file(Options *, const char *, const char *, int);
209+
void add_identity_file(Options *, const char *, const char *, int, struct passwd *);
206210

207211
#endif /* READCONF_H */

runconfigure

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
./configure --build=i686-pc-mingw32 --host=i686-pc-mingw32 --with-ssl-dir=../openssl-1.0.2d --with-zlib=../zlib-1.2.8 --with-kerberos5
1+
@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
2+
./configure --build=i686-pc-mingw32 --host=i686-pc-mingw32 --with-ssl-dir=../openssl-1.0.2d --with-kerberos5

ssh-keysign.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,13 @@ main(int argc, char **argv)
209209
/* verify that ssh-keysign is enabled by the admin */
210210
initialize_options(&options);
211211
(void)read_config_file(_PATH_HOST_CONFIG_FILE, pw, "", "", &options, 0);
212+
213+
#ifndef WIN32_FIXME
212214
fill_default_options(&options);
215+
#else
216+
fill_default_options(&options, pw);
217+
#endif
218+
213219
if (options.enable_ssh_keysign != 1)
214220
fatal("ssh-keysign not enabled in %s",
215221
_PATH_HOST_CONFIG_FILE);

ssh.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@
126126
extern int PassInputFd;
127127
extern int PassOutputFd;
128128

129+
char dotsshdir[MAX_PATH];
130+
129131
#endif /* WIN32_FIXME */
130132

131133
extern char *__progname;
@@ -587,6 +589,7 @@ main(int ac, char **av)
587589
char cname[NI_MAXHOST];
588590
struct stat st;
589591
struct passwd *pw;
592+
590593
int timeout_ms;
591594
extern int optind, optreset;
592595
extern char *optarg;
@@ -811,7 +814,7 @@ main(int ac, char **av)
811814
strerror(errno));
812815
break;
813816
}
814-
add_identity_file(&options, NULL, optarg, 1);
817+
add_identity_file(&options, NULL, optarg, 1, pw);
815818
break;
816819
case 'I':
817820
#ifdef ENABLE_PKCS11
@@ -1055,6 +1058,10 @@ main(int ac, char **av)
10551058
PassOutputFd = _open_osfhandle(options.passOutputHandle_, O_WRONLY);
10561059
}
10571060

1061+
// create various Windows user home directory based file names
1062+
sprintf(dotsshdir,"%s\\%s", pw->pw_dir, _PATH_SSH_USER_DIR );
1063+
_mkdir(dotsshdir); //this base directory for the user is needed
1064+
10581065
#endif
10591066

10601067
/* Check that we got a host name. */
@@ -1189,7 +1196,11 @@ main(int ac, char **av)
11891196
}
11901197

11911198
/* Fill configuration defaults. */
1199+
#ifndef WIN32_FIXME
11921200
fill_default_options(&options);
1201+
#else
1202+
fill_default_options(&options, pw);
1203+
#endif
11931204

11941205
if (options.port == 0)
11951206
options.port = default_ssh_port();

0 commit comments

Comments
 (0)