Skip to content

Commit 18ba20f

Browse files
committed
Revert "Revert "Fix to domain logon and minor reformats to scp.""
This reverts commit d8f4e79.
1 parent d8f4e79 commit 18ba20f

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed
0 Bytes
Binary file not shown.

contrib/win32/win32compat/pwd.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <stdio.h>
3434
#include <LM.h>
3535
#include <sddl.h>
36+
#include <DsGetDC.h>
3637
#define SECURITY_WIN32
3738
#include <security.h>
3839
#include "inc\pwd.h"
@@ -70,6 +71,7 @@ get_passwd(const char *user_utf8, LPWSTR user_sid) {
7071
wchar_t reg_path[MAX_PATH], profile_home[MAX_PATH];
7172
HKEY reg_key = 0;
7273
int tmp_len = MAX_PATH;
74+
PDOMAIN_CONTROLLER_INFOW pdc = NULL;
7375

7476
errno = 0;
7577

@@ -98,12 +100,26 @@ get_passwd(const char *user_utf8, LPWSTR user_sid) {
98100
}
99101

100102
if (user_sid == NULL) {
101-
if (NetUserGetInfo(udom_utf16, uname_utf16, 23, &user_info) != NERR_Success ||
103+
if (NetUserGetInfo(udom_utf16, uname_utf16, 23, &user_info) != NERR_Success) {
104+
if (DsGetDcNameW(NULL, udom_utf16, NULL, NULL, DS_DIRECTORY_SERVICE_PREFERRED, &pdc) == ERROR_SUCCESS) {
105+
if (NetUserGetInfo(pdc->DomainControllerName, uname_utf16, 23, &user_info) != NERR_Success ||
102106
ConvertSidToStringSidW(((LPUSER_INFO_23)user_info)->usri23_user_sid, &user_sid_local) == FALSE) {
103107
errno = ENOMEM; //??
104108
goto done;
109+
}
105110
}
106-
user_sid = user_sid_local;
111+
else {
112+
errno = ENOMEM; //??
113+
goto done;
114+
}
115+
}
116+
else {
117+
if (ConvertSidToStringSidW(((LPUSER_INFO_23)user_info)->usri23_user_sid, &user_sid_local) == FALSE) {
118+
errno = ENOMEM; //??
119+
goto done;
120+
}
121+
}
122+
user_sid = user_sid_local;
107123
}
108124

109125
if (swprintf(reg_path, MAX_PATH, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%ls", user_sid) == MAX_PATH ||
@@ -135,6 +151,8 @@ get_passwd(const char *user_utf8, LPWSTR user_sid) {
135151
LocalFree(user_sid_local);
136152
if (reg_key)
137153
RegCloseKey(reg_key);
154+
if (pdc)
155+
NetApiBufferFree(pdc);
138156
return ret;
139157
}
140158

scp.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,45 +1135,42 @@ main(int argc, char **argv)
11351135
throughlocal = 1;
11361136
break;
11371137
case 'o':
1138-
case 'c':
1138+
addargs(&remote_remote_args, "-%c", ch);
1139+
addargs(&remote_remote_args, "%s", optarg);
1140+
addargs(&args, "-%c", ch);
1141+
addargs(&args, "%s", optarg);
1142+
break;
1143+
case 'c':
11391144
addargs(&remote_remote_args, "-%c", ch);
11401145
addargs(&remote_remote_args, "%s", optarg);
11411146
addargs(&args, "-%c", ch);
11421147
addargs(&args, "%s", optarg);
11431148

1144-
cipher = malloc(strlen(optarg) + 1);
1145-
if (cipher)
1146-
strcpy(cipher, optarg);
1149+
cipher = xstrdup(optarg);;
11471150
break;
11481151
case 'i':
11491152
addargs(&remote_remote_args, "-%c", ch);
11501153
addargs(&remote_remote_args, "%s", optarg);
11511154
addargs(&args, "-%c", ch);
11521155
addargs(&args, "%s", optarg);
11531156

1154-
identity = malloc(strlen(optarg) + 1);
1155-
if (identity)
1156-
strcpy(identity, optarg);
1157+
identity = xstrdup(optarg);;
11571158
break;
11581159
case 'F':
11591160
addargs(&remote_remote_args, "-%c", ch);
11601161
addargs(&remote_remote_args, "%s", optarg);
11611162
addargs(&args, "-%c", ch);
11621163
addargs(&args, "%s", optarg);
11631164

1164-
ssh_config = malloc(strlen(optarg) + 1);
1165-
if (ssh_config)
1166-
strcpy(ssh_config, optarg);
1165+
ssh_config = xstrdup(optarg);;
11671166
break;
11681167
case 'P':
11691168
addargs(&remote_remote_args, "-p");
11701169
addargs(&remote_remote_args, "%s", optarg);
11711170
addargs(&args, "-p");
11721171
addargs(&args, "%s", optarg);
11731172

1174-
port = malloc(strlen(optarg) + 1);
1175-
if (port)
1176-
strcpy(port, optarg);
1173+
port = xstrdup(optarg);;
11771174
break;
11781175
case 'B':
11791176
addargs(&remote_remote_args, "\"-oBatchmode yes\"");
@@ -1361,7 +1358,7 @@ toremote(char *targ, int argc, char **argv)
13611358
return;
13621359
}
13631360

1364-
for (i = 0; i < argc - 1; i++) {
1361+
for (i = 0; i < argc - 1; i++) {
13651362
src = colon(argv[i]);
13661363
if (src && throughlocal) { /* extended remote to remote */
13671364
*src++ = 0;

0 commit comments

Comments
 (0)