Skip to content

Commit 52bdef5

Browse files
committed
pwd.c refactoring and clean up
1 parent fe53a41 commit 52bdef5

27 files changed

+330
-520
lines changed

auth.c

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -385,29 +385,20 @@ auth_root_allowed(const char *method)
385385

386386
#ifdef WIN32_FIXME
387387

388-
wchar_t *expand_authorized_keys(const wchar_t *filename, struct passwd *pw)
388+
char *expand_authorized_keys(const char *filename, struct passwd *pw)
389389
{
390-
wchar_t *file_w, ret[MAXPATHLEN], pw_name_w[MAXPATHLEN], filename_w[MAXPATHLEN];
391-
390+
wchar_t *file_w, ret[MAXPATHLEN], pw_name_w[MAXPATHLEN], filename_w[MAXPATHLEN], pw_dir_w[MAXPATHLEN];
391+
char* expanded_utf8[MAXPATHLEN];
392392
int i;
393393

394394
wchar_t *slash;
395395

396-
i = MultiByteToWideChar(CP_UTF8, 0, filename, -1, filename_w, MAXPATHLEN);
397-
398-
if (i == 0)
399-
{
400-
fatal("expand_authorized_keys: unable to convert path to UTF-16");
401-
}
402-
403-
MultiByteToWideChar(CP_UTF8, 0, pw -> pw_name, -1, pw_name_w, MAXPATHLEN);
404-
405-
if (i == 0)
406-
{
407-
fatal("expand_authorized_keys: unable to convert path to UTF-16");
408-
}
409-
410-
file_w = percent_expand_w(filename_w, L"h", pw -> pw_dir,
396+
if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, filename_w, MAXPATHLEN) == 0 ||
397+
MultiByteToWideChar(CP_UTF8, 0, pw->pw_name, -1, pw_name_w, MAXPATHLEN) == 0 ||
398+
MultiByteToWideChar(CP_UTF8, 0, pw->pw_dir, -1, pw_dir_w, MAXPATHLEN) == 0)
399+
fatal("expand_authorized_keys -MultiByteToWideChar failed" );
400+
401+
file_w = percent_expand_w(filename_w, L"h", pw_dir_w,
411402
L"u", pw_name_w, (char *) NULL);
412403

413404
/*
@@ -444,9 +435,12 @@ wchar_t *expand_authorized_keys(const wchar_t *filename, struct passwd *pw)
444435
fatal("expand_authorized_keys: path too long");
445436
}
446437

438+
if (WideCharToMultiByte(CP_UTF8, 0, ret, -1, expanded_utf8, MAXPATHLEN, NULL, NULL) == 0)
439+
fatal("expand_authorized_keys: WideCharToMultiByte failed");
440+
447441
free(file_w);
448442

449-
return (_wcsdup(ret));
443+
return (xstrdup(expanded_utf8));
450444
}
451445

452446
#else /* WIN32_FIXME */
@@ -639,23 +633,15 @@ auth_openfile(const char *file, struct passwd *pw, int strict_modes,
639633
FILE *f;
640634

641635
#ifdef WIN32_FIXME
642-
if ((fd = _wopen(file, O_RDONLY|O_NONBLOCK)) == -1) {
636+
if ((f = fopen(file, "r")) == NULL)
637+
return NULL;
643638
#else
644639
if ((fd = open(file, O_RDONLY|O_NONBLOCK)) == -1) {
645-
#endif
646640
if (log_missing || errno != ENOENT)
647641
debug("Could not open %s '%s': %s", file_type, file,
648642
strerror(errno));
649643
return NULL;
650644
}
651-
652-
#ifdef WIN32_FIXME
653-
if ((f = _fdopen(fd, "r")) == NULL) {
654-
_close(fd);
655-
return NULL;
656-
}
657-
658-
#else
659645
if (fstat(fd, &st) < 0) {
660646
close(fd);
661647
return NULL;

auth.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,7 @@ char *get_challenge(Authctxt *);
196196
int verify_response(Authctxt *, const char *);
197197
void abandon_challenge_response(Authctxt *);
198198

199-
#ifndef WIN32_FIXME
200199
char *expand_authorized_keys(const char *, struct passwd *pw);
201-
#else
202-
wchar_t *expand_authorized_keys(const wchar_t *filename, struct passwd *pw);
203-
#endif
204200

205201
char *authorized_principals_file(struct passwd *);
206202

authfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ sshkey_perm_ok(int fd, const char *filename)
183183
if (check_ntsec(filename))
184184
#endif
185185

186-
#ifndef WIN32_FIXME//R
186+
#ifndef WINDOWS /*TODO - implement permission checks on Windows*/
187187
if ((st.st_uid == getuid()) && (st.st_mode & 077) != 0) {
188188
error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
189189
error("@ WARNING: UNPROTECTED PRIVATE KEY FILE! @");

channels.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@ channel_post_mux_listener(Channel *c, fd_set *readset, fd_set *writeset)
19971997
c->notbefore = monotime() + 1;
19981998
return;
19991999
}
2000-
2000+
#ifndef WINDOWS /*TODO - implement user check for Windows*/
20012001
if (getpeereid(newsock, &euid, &egid) < 0) {
20022002
error("%s getpeereid failed: %s", __func__,
20032003
strerror(errno));
@@ -2010,6 +2010,7 @@ channel_post_mux_listener(Channel *c, fd_set *readset, fd_set *writeset)
20102010
close(newsock);
20112011
return;
20122012
}
2013+
#endif
20132014
nc = channel_new("multiplex client", SSH_CHANNEL_MUX_CLIENT,
20142015
newsock, newsock, -1, c->local_window_max,
20152016
c->local_maxpacket, 0, "mux-control", 1);

contrib/win32/openssh/config.h.vs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,7 @@
15811581
#define _CRT_SECURE_NO_DEPRECATE 1
15821582
#define _CRT_NONSTDC_NO_DEPRECATE 1
15831583
#define WIN32_FIXME 1
1584+
#define WINDOWS 1
15841585

15851586
/* Define if you must implement a startup_needs function for your platform */
15861587
#define HAVE_STARTUP_NEEDS 1

contrib/win32/openssh/win32compat.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@
151151
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\gettimeofday.c" />
152152
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\homedirhelp.c" />
153153
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\kerberos.c" />
154-
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\pwd.c" />
155154
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\startupneeds.c" />
156155
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\strcasecmp.c" />
157156
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\stringhelp.c" />

contrib/win32/openssh/win32compat.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@
5757
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\kerberos.c">
5858
<Filter>Source Files</Filter>
5959
</ClCompile>
60-
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\pwd.c">
61-
<Filter>Source Files</Filter>
62-
</ClCompile>
6360
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\startupneeds.c">
6461
<Filter>Source Files</Filter>
6562
</ClCompile>

contrib/win32/openssh/win32iocompat.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\signal_sigalrm.c" />
151151
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\signal_sigchld.c" />
152152
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\w32log.c" />
153+
<ClCompile Include="..\win32compat\pwd.c" />
153154
</ItemGroup>
154155
<ItemGroup>
155156
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\w32fd.h" />
@@ -168,6 +169,8 @@
168169
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\dlfcn.h" />
169170
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\syslog.h" />
170171
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\signal_internal.h" />
172+
<ClInclude Include="..\win32compat\inc\pwd.h" />
173+
<ClInclude Include="..\win32compat\inc\sys\param.h" />
171174
</ItemGroup>
172175
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
173176
<ImportGroup Label="ExtensionTargets">

contrib/win32/openssh/win32iocompat.vcxproj.filters

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\fileio.c" />
88
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\termio.c" />
99
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\misc.c" />
10-
<ClCompile Include="..\win32compat\w32log.c" />
11-
<ClCompile Include="..\win32compat\signal_sigchld.c" />
12-
<ClCompile Include="..\win32compat\signal_sigalrm.c" />
10+
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\signal_sigalrm.c" />
11+
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\signal_sigchld.c" />
12+
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\w32log.c" />
13+
<ClCompile Include="..\win32compat\pwd.c" />
1314
</ItemGroup>
1415
<ItemGroup>
1516
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\w32fd.h" />
@@ -49,13 +50,15 @@
4950
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\sys\statvfs.h">
5051
<Filter>inc\sys</Filter>
5152
</ClInclude>
52-
<ClInclude Include="..\win32compat\inc\syslog.h">
53+
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\dlfcn.h" />
54+
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\syslog.h" />
55+
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\signal_internal.h" />
56+
<ClInclude Include="..\win32compat\inc\pwd.h">
5357
<Filter>inc</Filter>
5458
</ClInclude>
55-
<ClInclude Include="..\win32compat\inc\dlfcn.h">
56-
<Filter>inc</Filter>
59+
<ClInclude Include="..\win32compat\inc\sys\param.h">
60+
<Filter>inc\sys</Filter>
5761
</ClInclude>
58-
<ClInclude Include="..\win32compat\signal_internal.h" />
5962
</ItemGroup>
6063
<ItemGroup>
6164
<Filter Include="inc">

contrib/win32/win32compat/fileio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ fileio_fstat(struct w32_io* pio, struct _stat64 *buf) {
557557

558558
int
559559
fileio_stat(const char *path, struct _stat64 *buf) {
560+
/* TODO - path is UTD -8, support unicode*/
560561
return _stat64(path, buf);
561562
}
562563

0 commit comments

Comments
 (0)