Skip to content

Commit dec395b

Browse files
committed
disabled broken fdopen and routed usage in code to Win CRTs _fdopen, also logging in Network mode, to get elevated tokens for admin
1 parent 3760840 commit dec395b

File tree

4 files changed

+20
-33
lines changed

4 files changed

+20
-33
lines changed

auth-passwd.c

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -335,39 +335,11 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
335335

336336
return 0;
337337
}
338-
339-
/*
340-
* First, try logon in INTERACTIVE mode.
341-
*/
342338

343339
worked = LogonUserW(user_UTF16, domain_UTF16, password_UTF16,
344-
LOGON32_LOGON_INTERACTIVE,
340+
LOGON32_LOGON_NETWORK,
345341
LOGON32_PROVIDER_DEFAULT, &hToken);
346342

347-
/*
348-
* If no success, try NETWORK mode.
349-
*/
350-
351-
if (!worked)
352-
{
353-
HANDLE weakToken = INVALID_HANDLE_VALUE;
354-
355-
debug3("Netork login attemp [%s][%ls]...",
356-
username, domain_UTF16);
357-
358-
worked = LogonUserW(user_UTF16, domain_UTF16, password_UTF16,
359-
LOGON32_LOGON_NETWORK,
360-
LOGON32_PROVIDER_DEFAULT, &weakToken);
361-
362-
if (worked)
363-
{
364-
debug("Duplicating token...");
365-
366-
debug3(DuplicateTokenEx(weakToken, MAXIMUM_ALLOWED,
367-
NULL, SecurityImpersonation,
368-
TokenPrimary, &hToken) == 0);
369-
}
370-
}
371343

372344
free(user_UTF16);
373345
free(password_UTF16);

auth.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,8 @@ auth_openfile(const char *file, struct passwd *pw, int strict_modes,
647647
int fd;
648648
FILE *f;
649649

650-
#if(0)def WIN32_FIXME
651-
if ((fd = WSHELPwopen(file, O_RDONLY|O_NONBLOCK)) == -1) {
650+
#ifdef WIN32_FIXME
651+
if ((fd = _wopen(file, O_RDONLY|O_NONBLOCK)) == -1) {
652652
#else
653653
if ((fd = open(file, O_RDONLY|O_NONBLOCK)) == -1) {
654654
#endif
@@ -658,6 +658,13 @@ auth_openfile(const char *file, struct passwd *pw, int strict_modes,
658658
return NULL;
659659
}
660660

661+
#ifdef WIN32_FIXME
662+
if ((f = _fdopen(fd, "r")) == NULL) {
663+
_close(fd);
664+
return NULL;
665+
}
666+
667+
#else
661668
if (fstat(fd, &st) < 0) {
662669
close(fd);
663670
return NULL;
@@ -668,13 +675,13 @@ auth_openfile(const char *file, struct passwd *pw, int strict_modes,
668675
close(fd);
669676
return NULL;
670677
}
671-
#ifndef WIN32_FIXME
672678
unset_nonblock(fd);
673-
#endif
679+
674680
if ((f = fdopen(fd, "r")) == NULL) {
675681
close(fd);
676682
return NULL;
677683
}
684+
#endif
678685
if (strict_modes &&
679686
secure_filename(f, file, pw, line, sizeof(line)) != 0) {
680687
fclose(f);

contrib/win32/win32compat/fileio.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,10 @@ fileio_fdopen(struct w32_io* pio, const char *mode) {
556556
int fd_flags = 0;
557557
debug2("fdopen - io:%p", pio);
558558

559+
/* logic below doesn't work with overlapped file HANDLES */
560+
errno = ENOTSUP;
561+
return NULL;
562+
559563
if (mode[1] == '\0') {
560564
switch (*mode) {
561565
case 'r':

ssh-keygen.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
#include "krl.h"
5959
#include "digest.h"
6060

61+
#ifdef WIN32_FIXME
62+
#define open(a,b,...) _open((a), (b), __VA_ARGS__)
63+
#define fdopen(a,b) _fdopen((a), (b))
64+
#endif
6165

6266
#ifdef WITH_OPENSSL
6367
# define DEFAULT_KEY_TYPE_NAME "rsa"

0 commit comments

Comments
 (0)