Skip to content

Commit 8485fd9

Browse files
committed
Merge branch 'L1'
2 parents 03ade97 + 69546ae commit 8485fd9

File tree

4 files changed

+270
-11
lines changed

4 files changed

+270
-11
lines changed

auth-passwd.c

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,65 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
223223
/*
224224
* Identify domain or local login.
225225
*/
226-
227-
domain_UTF16 = strchr(authctxt -> user, '@') ? NULL : L".";
226+
227+
char *username = authctxt->user;
228+
229+
char *domainslash = strchr(authctxt->user, '\\');
230+
if (domainslash) {
231+
// domain\username format
232+
char *domainname = authctxt->user;
233+
*domainslash = '\0';
234+
username = ++domainslash; // username is past the domain \ is the username
235+
236+
// Convert domainname from UTF-8 to UTF-16
237+
buffer_size = MultiByteToWideChar(CP_UTF8, 0, domainname, -1, NULL, 0);
238+
239+
if (buffer_size > 0)
240+
{
241+
domain_UTF16 = xmalloc(4 * buffer_size);
242+
}
243+
else
244+
{
245+
return 0;
246+
}
247+
248+
if (0 == MultiByteToWideChar(CP_UTF8, 0, domainname,
249+
-1, domain_UTF16, buffer_size))
250+
{
251+
free(domain_UTF16);
252+
253+
return 0;
254+
}
255+
}
256+
else if (domainslash = strchr(authctxt->user, '@')) {
257+
// username@domain format
258+
username = authctxt->user;
259+
*domainslash = '\0';
260+
char *domainname = ++domainslash; // domainname is past the user@
261+
262+
// Convert domainname from UTF-8 to UTF-16
263+
buffer_size = MultiByteToWideChar(CP_UTF8, 0, domainname, -1, NULL, 0);
264+
265+
if (buffer_size > 0)
266+
{
267+
domain_UTF16 = xmalloc(4 * buffer_size);
268+
}
269+
else
270+
{
271+
return 0;
272+
}
273+
274+
if (0 == MultiByteToWideChar(CP_UTF8, 0, domainname,
275+
-1, domain_UTF16, buffer_size))
276+
{
277+
free(domain_UTF16);
278+
279+
return 0;
280+
}
281+
}
282+
else {
283+
domain_UTF16 = strchr(authctxt->user, '@') ? NULL : L".";
284+
}
228285

229286
authctxt -> methoddata = hToken;
230287

@@ -237,7 +294,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
237294
* Convert username from UTF-8 to UTF-16
238295
*/
239296

240-
buffer_size = MultiByteToWideChar(CP_UTF8, 0, authctxt -> user, -1, NULL, 0);
297+
buffer_size = MultiByteToWideChar(CP_UTF8, 0, username, -1, NULL, 0);
241298

242299
if (buffer_size > 0)
243300
{
@@ -248,7 +305,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
248305
return 0;
249306
}
250307

251-
if (0 == MultiByteToWideChar(CP_UTF8, 0, authctxt -> user,
308+
if (0 == MultiByteToWideChar(CP_UTF8, 0, username,
252309
-1, user_UTF16, buffer_size))
253310
{
254311
free(user_UTF16);
@@ -296,7 +353,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
296353
HANDLE weakToken = INVALID_HANDLE_VALUE;
297354

298355
debug3("Netork login attemp [%s][%ls]...",
299-
authctxt -> user, domain_UTF16);
356+
username, domain_UTF16);
300357

301358
worked = LogonUserW(user_UTF16, domain_UTF16, password_UTF16,
302359
LOGON32_LOGON_NETWORK,
@@ -314,6 +371,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
314371

315372
free(user_UTF16);
316373
free(password_UTF16);
374+
if (domainslash) free(domain_UTF16);
317375

318376
/*
319377
* If login still fails, go out.
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
Set-StrictMode -Version Latest
2+
$Win32Macro = 'WIN32_FIXME'
3+
$sourceRoot = 'C:\openssh\Win32-OpenSSH'
4+
5+
[int]$g_code = 0
6+
[int]$g_win32 = 0
7+
[int]$g_unix = 0
8+
9+
function AnalyzeFile($file, [bool]$log)
10+
{
11+
$file = Join-Path $sourceRoot $file
12+
if ($log) { Write-Host -ForegroundColor Gray $file }
13+
$content = Get-Content $file
14+
[int]$commentlines = 0 #comments
15+
[int]$emptylines = 0 #emptylines
16+
[int]$code = 0 #all code lines
17+
[int]$win32 = 0 #win32 only lines
18+
[int]$win32substituted = 0#lines in win32 block that have a corresponding Unix block (#ifdef with #else)
19+
[int]$unix = 0; #unix only lines
20+
[int]$unixsubstituted = 0 #lines in unix block that have a corresponding Win32 block (#ifdef with #else)
21+
[int]$total = 0
22+
[int]$nestedmacros = 0 #tracks nested macro blocks inside a win32 or a unix block
23+
[bool]$incommentblock = $false
24+
[bool]$inWin32block = $false
25+
[bool]$inUnixblock = $false
26+
[int]$currentblockcode = 0
27+
[bool]$insubstitutedblock = $false
28+
29+
30+
foreach ($linestr in $content)
31+
{
32+
$total++
33+
$line = [String]$linestr
34+
$line = $line.Trim()
35+
#skip if line is empty
36+
if ($line.Length -gt 0)
37+
{
38+
if ($incommentblock)
39+
{
40+
$commentlines++
41+
if ($line.EndsWith('*/')) {$incommentblock = $false}
42+
}
43+
else
44+
{
45+
if ($line.StartsWith('//')) {$commentlines++}
46+
elseif ($line.StartsWith('/*'))
47+
{
48+
if (!($line.EndsWith('*/'))) { $incommentblock = $true }
49+
$commentlines++
50+
}
51+
else
52+
{
53+
$code++
54+
if ($inWin32block)
55+
{
56+
$win32++
57+
$currentblockcode++
58+
#keep skipping inner #ifdefs
59+
if ($line.StartsWith('#ifdef')) {$nestedmacros++}
60+
61+
if ($line.EndsWith('#endif') -or $line.EndsWith('#else'))
62+
{
63+
if ($nestedmacros -eq 0)
64+
{
65+
$inWin32block = $false
66+
if ($line.EndsWith('#else'))
67+
{
68+
$inUnixblock = $true
69+
$insubstitutedblock = $true
70+
$win32substituted += $currentblockcode
71+
}
72+
elseif ($insubstitutedblock)
73+
{
74+
$win32substituted += $currentblockcode
75+
$insubstitutedblock = $false
76+
}
77+
$currentblockcode = 0
78+
}
79+
else
80+
{
81+
if ($line.EndsWith('#endif')) {$nestedmacros--}
82+
}
83+
}
84+
}
85+
elseif ($inUnixblock)
86+
{
87+
$unix++
88+
$currentblockcode++
89+
#keep skipping inner #ifdefs
90+
if ($line.StartsWith('#ifdef')) {$nestedmacros++}
91+
92+
if ($line.EndsWith('#endif') -or $line.EndsWith('#else'))
93+
{
94+
if ($nestedmacros -eq 0)
95+
{
96+
$inUnixblock = $false
97+
if ($line.EndsWith('#else'))
98+
{
99+
$inWin32block = $true
100+
$insubstitutedblock = $true
101+
$unixsubstituted += $currentblockcode
102+
}
103+
elseif ($insubstitutedblock)
104+
{
105+
$unixsubstituted += $currentblockcode
106+
$insubstitutedblock = $false
107+
}
108+
109+
$currentblockcode = 0
110+
}
111+
else
112+
{
113+
if ($line.EndsWith('#endif')) {$nestedmacros--}
114+
}
115+
}
116+
}
117+
else
118+
{
119+
if ($line.StartsWith('#ifdef') -and $line.Contains($Win32Macro))
120+
{
121+
$inWin32block = $true
122+
$currentblockcode = 0
123+
}
124+
if ($line.StartsWith('#ifndef') -and $line.Contains($Win32Macro))
125+
{
126+
$inUnixblock = $true
127+
$currentblockcode = 0;
128+
}
129+
}
130+
131+
}
132+
}
133+
}
134+
else {$emptylines++}
135+
}
136+
137+
if ($log)
138+
{
139+
Write-Host -ForegroundColor Yellow " Comments " $commentlines
140+
Write-Host -ForegroundColor Green " Blank " $emptylines
141+
Write-Host -ForegroundColor Cyan " Code " $code
142+
Write-Host -ForegroundColor DarkMagenta " Total " $total " check("($commentlines+$emptylines+$code)")"
143+
Write-Host -ForegroundColor Cyan " Win32 " $win32
144+
Write-Host -ForegroundColor Cyan " Unix " $unix
145+
Write-Host -ForegroundColor Cyan " Win32sub " $win32substituted
146+
Write-Host -ForegroundColor Cyan " Unixsub " $unixsubstituted
147+
}
148+
149+
$global:g_code += $code
150+
$global:g_win32 += $win32
151+
$global:g_unix += $unix
152+
153+
}
154+
155+
156+
function AnalyzeProject($project, [bool]$log)
157+
{
158+
if ($log) { Write-Host "Project: " $project}
159+
$projectName = $project
160+
$projectroot = Join-Path $sourceRoot 'contrib\win32\openssh'
161+
$project = Join-Path $projectroot $project
162+
$project = $project + '.vcxproj'
163+
164+
$global:g_code = 0
165+
$global:g_win32 = 0
166+
$global:g_unix = 0
167+
168+
$c = Get-Content $project
169+
foreach ($ln in $c){
170+
$l = [String]$ln
171+
$l = $l.Trim()
172+
173+
if ($l.StartsWith('<ClCompile Include="$(OpenSSH-Src-Path)'))
174+
{
175+
$l = $l.Replace('<ClCompile Include="$(OpenSSH-Src-Path)','')
176+
$l = $l.Substring(0, $l.IndexOf('"'))
177+
AnalyzeFile $l $log
178+
}
179+
}
180+
181+
if ($log)
182+
{
183+
Write-Host " Total Code " $global:g_code
184+
Write-Host " Win32 Code " $global:g_win32
185+
Write-Host " Unix Code " $global:g_unix
186+
}
187+
188+
Write-Host $projectName " " (100 - ($global:g_unix*100/($global:g_code - $global:g_win32))) "%"
189+
190+
}
191+
192+
193+
AnalyzeProject libssh
194+
AnalyzeProject scp
195+
AnalyzeProject sftp
196+
AnalyzeProject sftp-server
197+
AnalyzeProject ssh
198+
AnalyzeProject ssh-add
199+
AnalyzeProject ssh-agent
200+
AnalyzeProject sshd

pathnames.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
# define _PATH_HOST_ECDSA_KEY_FILE "ssh_host_ecdsa_key"
4444
# define _PATH_HOST_ED25519_KEY_FILE "ssh_host_ed25519_key"
4545
# define _PATH_HOST_RSA_KEY_FILE "ssh_host_rsa_key"
46-
# define _PATH_DH_MODULI "/moduli"
47-
# define _PATH_DH_PRIMES "/primes"
46+
# define _PATH_DH_MODULI "moduli"
47+
# define _PATH_DH_PRIMES "primes"
4848
# define _PATH_SSH_PROGRAM "ssh.exe"
4949

5050
#else

sftp.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,10 +2473,11 @@ main(int argc, char **argv)
24732473

24742474
WSHELPinitialize();
24752475

2476-
allocate_standard_descriptor(STDIN_FILENO);
2477-
allocate_standard_descriptor(STDOUT_FILENO);
2478-
allocate_standard_descriptor(STDERR_FILENO);
2479-
2476+
//allocate_standard_descriptor(STDIN_FILENO);
2477+
//allocate_standard_descriptor(STDOUT_FILENO);
2478+
//allocate_standard_descriptor(STDERR_FILENO);
2479+
setvbuf(stdout, NULL, _IONBF, 0);
2480+
24802481
LoadLibrary("libwindbg.dll");
24812482

24822483
//sfd_start = 3;

0 commit comments

Comments
 (0)