diff --git a/auth-passwd.c b/auth-passwd.c index d846b01..0626fb3 100644 --- a/auth-passwd.c +++ b/auth-passwd.c @@ -223,8 +223,65 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password) /* * Identify domain or local login. */ - - domain_UTF16 = strchr(authctxt -> user, '@') ? NULL : L"."; + + char *username = authctxt->user; + + char *domainslash = strchr(authctxt->user, '\\'); + if (domainslash) { + // domain\username format + char *domainname = authctxt->user; + *domainslash = '\0'; + username = ++domainslash; // username is past the domain \ is the username + + // Convert domainname from UTF-8 to UTF-16 + buffer_size = MultiByteToWideChar(CP_UTF8, 0, domainname, -1, NULL, 0); + + if (buffer_size > 0) + { + domain_UTF16 = xmalloc(4 * buffer_size); + } + else + { + return 0; + } + + if (0 == MultiByteToWideChar(CP_UTF8, 0, domainname, + -1, domain_UTF16, buffer_size)) + { + free(domain_UTF16); + + return 0; + } + } + else if (domainslash = strchr(authctxt->user, '@')) { + // username@domain format + username = authctxt->user; + *domainslash = '\0'; + char *domainname = ++domainslash; // domainname is past the user@ + + // Convert domainname from UTF-8 to UTF-16 + buffer_size = MultiByteToWideChar(CP_UTF8, 0, domainname, -1, NULL, 0); + + if (buffer_size > 0) + { + domain_UTF16 = xmalloc(4 * buffer_size); + } + else + { + return 0; + } + + if (0 == MultiByteToWideChar(CP_UTF8, 0, domainname, + -1, domain_UTF16, buffer_size)) + { + free(domain_UTF16); + + return 0; + } + } + else { + domain_UTF16 = strchr(authctxt->user, '@') ? NULL : L"."; + } authctxt -> methoddata = hToken; @@ -237,7 +294,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password) * Convert username from UTF-8 to UTF-16 */ - buffer_size = MultiByteToWideChar(CP_UTF8, 0, authctxt -> user, -1, NULL, 0); + buffer_size = MultiByteToWideChar(CP_UTF8, 0, username, -1, NULL, 0); if (buffer_size > 0) { @@ -248,7 +305,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password) return 0; } - if (0 == MultiByteToWideChar(CP_UTF8, 0, authctxt -> user, + if (0 == MultiByteToWideChar(CP_UTF8, 0, username, -1, user_UTF16, buffer_size)) { free(user_UTF16); @@ -296,7 +353,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password) HANDLE weakToken = INVALID_HANDLE_VALUE; debug3("Netork login attemp [%s][%ls]...", - authctxt -> user, domain_UTF16); + username, domain_UTF16); worked = LogonUserW(user_UTF16, domain_UTF16, password_UTF16, LOGON32_LOGON_NETWORK, @@ -314,6 +371,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password) free(user_UTF16); free(password_UTF16); + if (domainslash) free(domain_UTF16); /* * If login still fails, go out. diff --git a/contrib/win32/openssh/AnalyzeCodeDiff.ps1 b/contrib/win32/openssh/AnalyzeCodeDiff.ps1 new file mode 100644 index 0000000..560a67f --- /dev/null +++ b/contrib/win32/openssh/AnalyzeCodeDiff.ps1 @@ -0,0 +1,200 @@ +Set-StrictMode -Version Latest +$Win32Macro = 'WIN32_FIXME' +$sourceRoot = 'C:\openssh\Win32-OpenSSH' + +[int]$g_code = 0 +[int]$g_win32 = 0 +[int]$g_unix = 0 + +function AnalyzeFile($file, [bool]$log) +{ + $file = Join-Path $sourceRoot $file + if ($log) { Write-Host -ForegroundColor Gray $file } + $content = Get-Content $file + [int]$commentlines = 0 #comments + [int]$emptylines = 0 #emptylines + [int]$code = 0 #all code lines + [int]$win32 = 0 #win32 only lines + [int]$win32substituted = 0#lines in win32 block that have a corresponding Unix block (#ifdef with #else) + [int]$unix = 0; #unix only lines + [int]$unixsubstituted = 0 #lines in unix block that have a corresponding Win32 block (#ifdef with #else) + [int]$total = 0 + [int]$nestedmacros = 0 #tracks nested macro blocks inside a win32 or a unix block + [bool]$incommentblock = $false + [bool]$inWin32block = $false + [bool]$inUnixblock = $false + [int]$currentblockcode = 0 + [bool]$insubstitutedblock = $false + + + foreach ($linestr in $content) + { + $total++ + $line = [String]$linestr + $line = $line.Trim() + #skip if line is empty + if ($line.Length -gt 0) + { + if ($incommentblock) + { + $commentlines++ + if ($line.EndsWith('*/')) {$incommentblock = $false} + } + else + { + if ($line.StartsWith('//')) {$commentlines++} + elseif ($line.StartsWith('/*')) + { + if (!($line.EndsWith('*/'))) { $incommentblock = $true } + $commentlines++ + } + else + { + $code++ + if ($inWin32block) + { + $win32++ + $currentblockcode++ + #keep skipping inner #ifdefs + if ($line.StartsWith('#ifdef')) {$nestedmacros++} + + if ($line.EndsWith('#endif') -or $line.EndsWith('#else')) + { + if ($nestedmacros -eq 0) + { + $inWin32block = $false + if ($line.EndsWith('#else')) + { + $inUnixblock = $true + $insubstitutedblock = $true + $win32substituted += $currentblockcode + } + elseif ($insubstitutedblock) + { + $win32substituted += $currentblockcode + $insubstitutedblock = $false + } + $currentblockcode = 0 + } + else + { + if ($line.EndsWith('#endif')) {$nestedmacros--} + } + } + } + elseif ($inUnixblock) + { + $unix++ + $currentblockcode++ + #keep skipping inner #ifdefs + if ($line.StartsWith('#ifdef')) {$nestedmacros++} + + if ($line.EndsWith('#endif') -or $line.EndsWith('#else')) + { + if ($nestedmacros -eq 0) + { + $inUnixblock = $false + if ($line.EndsWith('#else')) + { + $inWin32block = $true + $insubstitutedblock = $true + $unixsubstituted += $currentblockcode + } + elseif ($insubstitutedblock) + { + $unixsubstituted += $currentblockcode + $insubstitutedblock = $false + } + + $currentblockcode = 0 + } + else + { + if ($line.EndsWith('#endif')) {$nestedmacros--} + } + } + } + else + { + if ($line.StartsWith('#ifdef') -and $line.Contains($Win32Macro)) + { + $inWin32block = $true + $currentblockcode = 0 + } + if ($line.StartsWith('#ifndef') -and $line.Contains($Win32Macro)) + { + $inUnixblock = $true + $currentblockcode = 0; + } + } + + } + } + } + else {$emptylines++} + } + + if ($log) + { + Write-Host -ForegroundColor Yellow " Comments " $commentlines + Write-Host -ForegroundColor Green " Blank " $emptylines + Write-Host -ForegroundColor Cyan " Code " $code + Write-Host -ForegroundColor DarkMagenta " Total " $total " check("($commentlines+$emptylines+$code)")" + Write-Host -ForegroundColor Cyan " Win32 " $win32 + Write-Host -ForegroundColor Cyan " Unix " $unix + Write-Host -ForegroundColor Cyan " Win32sub " $win32substituted + Write-Host -ForegroundColor Cyan " Unixsub " $unixsubstituted + } + + $global:g_code += $code + $global:g_win32 += $win32 + $global:g_unix += $unix + +} + + +function AnalyzeProject($project, [bool]$log) +{ + if ($log) { Write-Host "Project: " $project} + $projectName = $project + $projectroot = Join-Path $sourceRoot 'contrib\win32\openssh' + $project = Join-Path $projectroot $project + $project = $project + '.vcxproj' + + $global:g_code = 0 + $global:g_win32 = 0 + $global:g_unix = 0 + + $c = Get-Content $project + foreach ($ln in $c){ + $l = [String]$ln + $l = $l.Trim() + + if ($l.StartsWith('