mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-23 22:15:37 +02:00
5-14 C1
This commit is contained in:
parent
bf41884f36
commit
64b305b3b2
@ -58,15 +58,15 @@ NTSTATUS LsaAllocUnicodeString(PUNICODE_STRING *lsaStr, DWORD maxLen)
|
|||||||
|
|
||||||
FAIL(lsaStr == NULL);
|
FAIL(lsaStr == NULL);
|
||||||
|
|
||||||
*lsaStr = (PUNICODE_STRING) LsaApi.AllocateLsaHeap(sizeof(UNICODE_STRING));
|
*lsaStr = (PUNICODE_STRING)LsaApi.AllocateLsaHeap(sizeof(UNICODE_STRING));
|
||||||
|
|
||||||
FAIL((*lsaStr) == NULL);
|
FAIL((*lsaStr) == NULL);
|
||||||
|
|
||||||
(*lsaStr) -> Buffer = (WCHAR *) LsaApi.AllocateLsaHeap(sizeof(maxLen));
|
(*lsaStr)->Buffer = (WCHAR *)LsaApi.AllocateLsaHeap(sizeof(maxLen));
|
||||||
(*lsaStr) -> Length = 0;
|
(*lsaStr)->Length = 0;
|
||||||
(*lsaStr) -> MaximumLength = maxLen;
|
(*lsaStr)->MaximumLength = maxLen;
|
||||||
|
|
||||||
FAIL((*lsaStr) -> Buffer == NULL);
|
FAIL((*lsaStr)->Buffer == NULL);
|
||||||
|
|
||||||
ntStat = 0;
|
ntStat = 0;
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ fail:
|
|||||||
{
|
{
|
||||||
if (lsaStr && (*lsaStr))
|
if (lsaStr && (*lsaStr))
|
||||||
{
|
{
|
||||||
LsaApi.FreeLsaHeap((*lsaStr) -> Buffer);
|
LsaApi.FreeLsaHeap((*lsaStr)->Buffer);
|
||||||
|
|
||||||
LsaApi.FreeLsaHeap((*lsaStr));
|
LsaApi.FreeLsaHeap((*lsaStr));
|
||||||
}
|
}
|
||||||
@ -96,9 +96,9 @@ void LsaFreeUnicodeString(PUNICODE_STRING lsaStr)
|
|||||||
{
|
{
|
||||||
if (lsaStr)
|
if (lsaStr)
|
||||||
{
|
{
|
||||||
if (lsaStr -> Buffer)
|
if (lsaStr->Buffer)
|
||||||
{
|
{
|
||||||
LsaApi.FreeLsaHeap(lsaStr -> Buffer);
|
LsaApi.FreeLsaHeap(lsaStr->Buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
LsaApi.FreeLsaHeap(lsaStr);
|
LsaApi.FreeLsaHeap(lsaStr);
|
||||||
@ -126,7 +126,7 @@ NTSTATUS FillUnicodeString(UNICODE_STRING *lsaStr, const Char *str)
|
|||||||
|
|
||||||
FAIL(lsaStr == NULL);
|
FAIL(lsaStr == NULL);
|
||||||
|
|
||||||
FAIL(lsaStr -> Buffer == NULL);
|
FAIL(lsaStr->Buffer == NULL);
|
||||||
|
|
||||||
FAIL(str == NULL);
|
FAIL(str == NULL);
|
||||||
|
|
||||||
@ -136,21 +136,21 @@ NTSTATUS FillUnicodeString(UNICODE_STRING *lsaStr, const Char *str)
|
|||||||
|
|
||||||
cbSize = strlen(str);
|
cbSize = strlen(str);
|
||||||
|
|
||||||
FAIL(cbSize >= lsaStr -> MaximumLength);
|
FAIL(cbSize >= lsaStr->MaximumLength);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Fill string buffer.
|
// Fill string buffer.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifdef __VS_BUILD__
|
#ifdef __VS_BUILD__
|
||||||
_swprintf(lsaStr -> Buffer, L"%hs", str);
|
_swprintf(lsaStr->Buffer, L"%hs", str);
|
||||||
#else
|
#else
|
||||||
swprintf(lsaStr->Buffer, L"%hs", str);
|
swprintf(lsaStr->Buffer, L"%hs", str);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
lsaStr -> Length = cbSize * 2;
|
lsaStr->Length = cbSize * 2;
|
||||||
|
|
||||||
lsaStr -> Buffer[cbSize * 2] = 0x0000;
|
lsaStr->Buffer[cbSize * 2] = 0x0000;
|
||||||
|
|
||||||
ntStat = STATUS_SUCCESS;
|
ntStat = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
@ -37,57 +37,41 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//
|
|
||||||
// Handle to 'ntdll.dll' module and address of 'RtlInitUnicodeString()'
|
|
||||||
// function.
|
|
||||||
//
|
|
||||||
|
|
||||||
RtlInitUnicodeStringPtr RtlInitUnicodeString = NULL;
|
|
||||||
|
|
||||||
HMODULE NtDll = NULL;
|
|
||||||
|
|
||||||
#ifdef DYNAMIC_OPENSSL
|
|
||||||
//
|
//
|
||||||
// Handle to 'libcrypto.dll' and 'libssl.dll' modules.
|
// Handle to 'ntdll.dll' module and address of 'RtlInitUnicodeString()'
|
||||||
|
// function.
|
||||||
//
|
//
|
||||||
|
|
||||||
HMODULE LibCrypto = NULL;
|
RtlInitUnicodeStringPtr RtlInitUnicodeString = NULL;
|
||||||
HMODULE LibSSL = NULL;
|
|
||||||
|
HMODULE NtDll = NULL;
|
||||||
|
|
||||||
//
|
//
|
||||||
// This is global struct with dynamic loaded libssl and libcrypto
|
// This is table with addresses of LSA API functions.
|
||||||
// functions.
|
// We retrieve this table from system at package initialization
|
||||||
|
// moment.
|
||||||
//
|
//
|
||||||
|
|
||||||
SSLFuncList DynSSL;
|
LSA_SECPKG_FUNCTION_TABLE LsaApi;
|
||||||
#endif
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// This is table with addresses of LSA API functions.
|
// Called once to initialize package at system startup.
|
||||||
// We retrieve this table from system at package initialization
|
//
|
||||||
// moment.
|
// pkgId - our package's ID given by LSA (IN)
|
||||||
//
|
// func - table with adresses of LSA functions (IN)
|
||||||
|
// database - uunsed / reserved (IN)
|
||||||
|
// confident - unused / reserved (IN)
|
||||||
|
// pkgName - name of our package (OUT)
|
||||||
|
//
|
||||||
|
// RETURNS: STATUSS_SUCCESS if OK.
|
||||||
|
//
|
||||||
|
|
||||||
LSA_SECPKG_FUNCTION_TABLE LsaApi;
|
NTSTATUS NTAPI LsaApInitializePackage(ULONG pkgId,
|
||||||
|
|
||||||
//
|
|
||||||
// Called once to initialize package at system startup.
|
|
||||||
//
|
|
||||||
// pkgId - our package's ID given by LSA (IN)
|
|
||||||
// func - table with adresses of LSA functions (IN)
|
|
||||||
// database - uunsed / reserved (IN)
|
|
||||||
// confident - unused / reserved (IN)
|
|
||||||
// pkgName - name of our package (OUT)
|
|
||||||
//
|
|
||||||
// RETURNS: STATUSS_SUCCESS if OK.
|
|
||||||
//
|
|
||||||
|
|
||||||
NTSTATUS NTAPI LsaApInitializePackage(ULONG pkgId,
|
|
||||||
PLSA_SECPKG_FUNCTION_TABLE func,
|
PLSA_SECPKG_FUNCTION_TABLE func,
|
||||||
PLSA_STRING database,
|
PLSA_STRING database,
|
||||||
PLSA_STRING confident,
|
PLSA_STRING confident,
|
||||||
PLSA_STRING *pkgName)
|
PLSA_STRING *pkgName)
|
||||||
{
|
{
|
||||||
|
|
||||||
//
|
//
|
||||||
// Save table with adresses of LSA API functions.
|
// Save table with adresses of LSA API functions.
|
||||||
@ -100,36 +84,36 @@ NTSTATUS NTAPI LsaApInitializePackage(ULONG pkgId,
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
*pkgName = (PLSA_STRING) LsaApi.AllocateLsaHeap(sizeof(LSA_STRING));
|
*pkgName = (PLSA_STRING)LsaApi.AllocateLsaHeap(sizeof(LSA_STRING));
|
||||||
|
|
||||||
(*pkgName) -> Buffer = (PCHAR) LsaApi.AllocateLsaHeap(PKG_NAME_SIZE);
|
(*pkgName)->Buffer = (PCHAR)LsaApi.AllocateLsaHeap(PKG_NAME_SIZE);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Fill buffer with our name.
|
// Fill buffer with our name.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
memcpy((*pkgName) -> Buffer, PKG_NAME, PKG_NAME_SIZE);
|
memcpy((*pkgName)->Buffer, PKG_NAME, PKG_NAME_SIZE);
|
||||||
|
|
||||||
(*pkgName) -> Length = PKG_NAME_SIZE - 1;
|
(*pkgName)->Length = PKG_NAME_SIZE - 1;
|
||||||
|
|
||||||
(*pkgName) -> MaximumLength = PKG_NAME_SIZE;
|
(*pkgName)->MaximumLength = PKG_NAME_SIZE;
|
||||||
|
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Allocate new buffer in LSA address space and copy input SID to it.
|
// Allocate new buffer in LSA address space and copy input SID to it.
|
||||||
//
|
//
|
||||||
// dst - pointer that retrieves new allocated copy of input SID (OUT)
|
// dst - pointer that retrieves new allocated copy of input SID (OUT)
|
||||||
// src - input SID to copy (IN)
|
// src - input SID to copy (IN)
|
||||||
//
|
//
|
||||||
// RETURNS: 0 if OK.
|
// RETURNS: 0 if OK.
|
||||||
//
|
//
|
||||||
|
|
||||||
Int LsaCopySid(PSID &dst, PSID src)
|
Int LsaCopySid(PSID &dst, PSID src)
|
||||||
{
|
{
|
||||||
Int exitCode = 1;
|
Int exitCode = 1;
|
||||||
|
|
||||||
DWORD size = 0;
|
DWORD size = 0;
|
||||||
@ -144,27 +128,27 @@ Int LsaCopySid(PSID &dst, PSID src)
|
|||||||
|
|
||||||
exitCode = 0;
|
exitCode = 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
|
||||||
if (exitCode)
|
if (exitCode)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Allocate LSA_TOKEN_INFORMATION_V1 structure in LSA address space
|
// Allocate LSA_TOKEN_INFORMATION_V1 structure in LSA address space
|
||||||
// and fill it with data from given token.
|
// and fill it with data from given token.
|
||||||
//
|
//
|
||||||
// tokenInfo - new allocated struct with info from given token (OUT)
|
// tokenInfo - new allocated struct with info from given token (OUT)
|
||||||
// token - handle to token (IN)
|
// token - handle to token (IN)
|
||||||
//
|
//
|
||||||
// RETURNS: 0 if OK.
|
// RETURNS: 0 if OK.
|
||||||
//
|
//
|
||||||
|
|
||||||
Int LsaAllocTokenInfo(PLSA_TOKEN_INFORMATION_V1 &tokenInfo, HANDLE token)
|
Int LsaAllocTokenInfo(PLSA_TOKEN_INFORMATION_V1 &tokenInfo, HANDLE token)
|
||||||
{
|
{
|
||||||
|
|
||||||
Int exitCode = 1;
|
Int exitCode = 1;
|
||||||
|
|
||||||
@ -201,14 +185,14 @@ Int LsaAllocTokenInfo(PLSA_TOKEN_INFORMATION_V1 &tokenInfo, HANDLE token)
|
|||||||
|
|
||||||
GetTokenInformation(token, TokenUser, NULL, 0, &cbSize);
|
GetTokenInformation(token, TokenUser, NULL, 0, &cbSize);
|
||||||
|
|
||||||
pUserToken = (PTOKEN_USER) LocalAlloc(LPTR, cbSize);
|
pUserToken = (PTOKEN_USER)LocalAlloc(LPTR, cbSize);
|
||||||
|
|
||||||
FAIL(GetTokenInformation(token, TokenUser,
|
FAIL(GetTokenInformation(token, TokenUser,
|
||||||
pUserToken, cbSize, &cbSize) == FALSE);
|
pUserToken, cbSize, &cbSize) == FALSE);
|
||||||
|
|
||||||
tokenInfo -> User.User.Attributes = pUserToken -> User.Attributes;
|
tokenInfo->User.User.Attributes = pUserToken->User.Attributes;
|
||||||
|
|
||||||
FAIL(LsaCopySid(tokenInfo -> User.User.Sid, pUserToken -> User.Sid));
|
FAIL(LsaCopySid(tokenInfo->User.User.Sid, pUserToken->User.Sid));
|
||||||
|
|
||||||
//
|
//
|
||||||
// Copy TOKEN_GROUPS part from input token.
|
// Copy TOKEN_GROUPS part from input token.
|
||||||
@ -217,25 +201,25 @@ Int LsaAllocTokenInfo(PLSA_TOKEN_INFORMATION_V1 &tokenInfo, HANDLE token)
|
|||||||
|
|
||||||
GetTokenInformation(token, TokenGroups, NULL, 0, &cbSize);
|
GetTokenInformation(token, TokenGroups, NULL, 0, &cbSize);
|
||||||
|
|
||||||
pGroupsToken = (PTOKEN_GROUPS) LocalAlloc(LPTR, cbSize);
|
pGroupsToken = (PTOKEN_GROUPS)LocalAlloc(LPTR, cbSize);
|
||||||
|
|
||||||
FAIL(GetTokenInformation(token, TokenGroups,
|
FAIL(GetTokenInformation(token, TokenGroups,
|
||||||
pGroupsToken, cbSize, &cbSize) == FALSE);
|
pGroupsToken, cbSize, &cbSize) == FALSE);
|
||||||
|
|
||||||
|
|
||||||
cbSize = pGroupsToken -> GroupCount * sizeof(SID_AND_ATTRIBUTES) + sizeof(DWORD);
|
cbSize = pGroupsToken->GroupCount * sizeof(SID_AND_ATTRIBUTES) + sizeof(DWORD);
|
||||||
|
|
||||||
tokenInfo -> Groups = (PTOKEN_GROUPS) LsaApi.AllocateLsaHeap(cbSize);
|
tokenInfo->Groups = (PTOKEN_GROUPS)LsaApi.AllocateLsaHeap(cbSize);
|
||||||
|
|
||||||
tokenInfo -> Groups -> GroupCount = pGroupsToken -> GroupCount;
|
tokenInfo->Groups->GroupCount = pGroupsToken->GroupCount;
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < pGroupsToken -> GroupCount; i++)
|
for (i = 0; i < pGroupsToken->GroupCount; i++)
|
||||||
{
|
{
|
||||||
FAIL(LsaCopySid(tokenInfo -> Groups -> Groups[i].Sid,
|
FAIL(LsaCopySid(tokenInfo->Groups->Groups[i].Sid,
|
||||||
pGroupsToken -> Groups[i].Sid));
|
pGroupsToken->Groups[i].Sid));
|
||||||
|
|
||||||
tokenInfo -> Groups -> Groups[i].Attributes = pGroupsToken -> Groups[i].Attributes;
|
tokenInfo->Groups->Groups[i].Attributes = pGroupsToken->Groups[i].Attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -246,10 +230,10 @@ Int LsaAllocTokenInfo(PLSA_TOKEN_INFORMATION_V1 &tokenInfo, HANDLE token)
|
|||||||
|
|
||||||
GetTokenInformation(token, TokenPrivileges, NULL, 0, &cbSize);
|
GetTokenInformation(token, TokenPrivileges, NULL, 0, &cbSize);
|
||||||
|
|
||||||
tokenInfo -> Privileges = (PTOKEN_PRIVILEGES) LsaApi.AllocateLsaHeap(cbSize);
|
tokenInfo->Privileges = (PTOKEN_PRIVILEGES)LsaApi.AllocateLsaHeap(cbSize);
|
||||||
|
|
||||||
FAIL(GetTokenInformation(token, TokenPrivileges,
|
FAIL(GetTokenInformation(token, TokenPrivileges,
|
||||||
tokenInfo -> Privileges, cbSize, &cbSize) == FALSE);
|
tokenInfo->Privileges, cbSize, &cbSize) == FALSE);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Copy TOKEN_OWNER part from input token.
|
// Copy TOKEN_OWNER part from input token.
|
||||||
@ -258,12 +242,12 @@ Int LsaAllocTokenInfo(PLSA_TOKEN_INFORMATION_V1 &tokenInfo, HANDLE token)
|
|||||||
|
|
||||||
GetTokenInformation(token, TokenOwner, NULL, 0, &cbSize);
|
GetTokenInformation(token, TokenOwner, NULL, 0, &cbSize);
|
||||||
|
|
||||||
pOwnerToken = (PTOKEN_OWNER) LocalAlloc(LPTR, cbSize);
|
pOwnerToken = (PTOKEN_OWNER)LocalAlloc(LPTR, cbSize);
|
||||||
|
|
||||||
FAIL(GetTokenInformation(token, TokenOwner,
|
FAIL(GetTokenInformation(token, TokenOwner,
|
||||||
pOwnerToken, cbSize, &cbSize) == FALSE);
|
pOwnerToken, cbSize, &cbSize) == FALSE);
|
||||||
|
|
||||||
FAIL(LsaCopySid(tokenInfo -> Owner.Owner, pOwnerToken -> Owner));
|
FAIL(LsaCopySid(tokenInfo->Owner.Owner, pOwnerToken->Owner));
|
||||||
|
|
||||||
//
|
//
|
||||||
// Copy TOKEN_PRIMARY_GROUP part from input token.
|
// Copy TOKEN_PRIMARY_GROUP part from input token.
|
||||||
@ -272,13 +256,13 @@ Int LsaAllocTokenInfo(PLSA_TOKEN_INFORMATION_V1 &tokenInfo, HANDLE token)
|
|||||||
|
|
||||||
GetTokenInformation(token, TokenPrimaryGroup, NULL, 0, &cbSize);
|
GetTokenInformation(token, TokenPrimaryGroup, NULL, 0, &cbSize);
|
||||||
|
|
||||||
pPrimaryGroupToken = (PTOKEN_PRIMARY_GROUP) LocalAlloc(LPTR, cbSize);
|
pPrimaryGroupToken = (PTOKEN_PRIMARY_GROUP)LocalAlloc(LPTR, cbSize);
|
||||||
|
|
||||||
FAIL(GetTokenInformation(token, TokenPrimaryGroup,
|
FAIL(GetTokenInformation(token, TokenPrimaryGroup,
|
||||||
pPrimaryGroupToken, cbSize, &cbSize) == FALSE);
|
pPrimaryGroupToken, cbSize, &cbSize) == FALSE);
|
||||||
|
|
||||||
FAIL(LsaCopySid(tokenInfo -> PrimaryGroup.PrimaryGroup,
|
FAIL(LsaCopySid(tokenInfo->PrimaryGroup.PrimaryGroup,
|
||||||
pPrimaryGroupToken -> PrimaryGroup));
|
pPrimaryGroupToken->PrimaryGroup));
|
||||||
|
|
||||||
//
|
//
|
||||||
// Copy TOKEN_DEFAULT_DACL part from input token.
|
// Copy TOKEN_DEFAULT_DACL part from input token.
|
||||||
@ -292,18 +276,18 @@ Int LsaAllocTokenInfo(PLSA_TOKEN_INFORMATION_V1 &tokenInfo, HANDLE token)
|
|||||||
//FAIL(GetTokenInformation(token, TokenDefaultDacl,
|
//FAIL(GetTokenInformation(token, TokenDefaultDacl,
|
||||||
// pDaclToken, cbSize, &cbSize) == FALSE);
|
// pDaclToken, cbSize, &cbSize) == FALSE);
|
||||||
|
|
||||||
tokenInfo -> DefaultDacl.DefaultDacl = NULL;
|
tokenInfo->DefaultDacl.DefaultDacl = NULL;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Fill expiration time. Our token never expires.
|
// Fill expiration time. Our token never expires.
|
||||||
//
|
//
|
||||||
|
|
||||||
tokenInfo -> ExpirationTime.HighPart = 0x7fffffff;
|
tokenInfo->ExpirationTime.HighPart = 0x7fffffff;
|
||||||
tokenInfo -> ExpirationTime.LowPart = 0xffffffff;
|
tokenInfo->ExpirationTime.LowPart = 0xffffffff;
|
||||||
|
|
||||||
exitCode = 0;
|
exitCode = 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
|
||||||
//
|
//
|
||||||
// Clean up.
|
// Clean up.
|
||||||
@ -320,27 +304,27 @@ fail:
|
|||||||
|
|
||||||
|
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Called, when client logon process want logon user.
|
// Called, when client logon process want logon user.
|
||||||
//
|
//
|
||||||
// request - internal LSA struct for allocating client buffer (IN)
|
// request - internal LSA struct for allocating client buffer (IN)
|
||||||
// logonType - what type of logon client need (e.g. Interactive) (IN)
|
// logonType - what type of logon client need (e.g. Interactive) (IN)
|
||||||
// authData - buffer with authorization data (we use SshLsaAuth) (IN)
|
// authData - buffer with authorization data (we use SshLsaAuth) (IN)
|
||||||
// authDataClient - adress of original authData in client address space (IN)
|
// authDataClient - adress of original authData in client address space (IN)
|
||||||
// authDataSize - size of authData buffer in bytes (IN)
|
// authDataSize - size of authData buffer in bytes (IN)
|
||||||
// profile - profile data (we decide what to return) (OUT)
|
// profile - profile data (we decide what to return) (OUT)
|
||||||
// profileSize - number of bytes returnet in profile (OUT)
|
// profileSize - number of bytes returnet in profile (OUT)
|
||||||
// subStat - additional NTSTATUS code used when logon failure (OUT)
|
// subStat - additional NTSTATUS code used when logon failure (OUT)
|
||||||
// tokenInfoType - what structure we returned to LSA in tokenInfo (OUT)
|
// tokenInfoType - what structure we returned to LSA in tokenInfo (OUT)
|
||||||
// tokenInfo - structure with token's parts for LSA (OUT)
|
// tokenInfo - structure with token's parts for LSA (OUT)
|
||||||
// accountName - on which account we try to logon (OUT)
|
// accountName - on which account we try to logon (OUT)
|
||||||
// authority - ?? We use it as domain name and fill with NULL (OUT)
|
// authority - ?? We use it as domain name and fill with NULL (OUT)
|
||||||
//
|
//
|
||||||
|
|
||||||
NTSTATUS NTAPI
|
NTSTATUS NTAPI
|
||||||
LsaApLogonUser(PLSA_CLIENT_REQUEST request, SECURITY_LOGON_TYPE logonType,
|
LsaApLogonUser(PLSA_CLIENT_REQUEST request, SECURITY_LOGON_TYPE logonType,
|
||||||
PVOID authData, PVOID clientAuthData, ULONG authDataSize,
|
PVOID authData, PVOID clientAuthData, ULONG authDataSize,
|
||||||
PVOID *profile, PULONG profileSize, PLUID logonId,
|
PVOID *profile, PULONG profileSize, PLUID logonId,
|
||||||
@ -349,7 +333,7 @@ NTSTATUS NTAPI
|
|||||||
PVOID *tokenInfo,
|
PVOID *tokenInfo,
|
||||||
PLSA_UNICODE_STRING *accountName,
|
PLSA_UNICODE_STRING *accountName,
|
||||||
PLSA_UNICODE_STRING *authority)
|
PLSA_UNICODE_STRING *authority)
|
||||||
{
|
{
|
||||||
|
|
||||||
NTSTATUS ntStat = STATUS_LOGON_FAILURE;
|
NTSTATUS ntStat = STATUS_LOGON_FAILURE;
|
||||||
|
|
||||||
@ -400,7 +384,7 @@ NTSTATUS NTAPI
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
inUserName = (wchar_t *) (((char*)authData)+4);
|
inUserName = (wchar_t *)authData;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -437,7 +421,7 @@ NTSTATUS NTAPI
|
|||||||
|
|
||||||
samUserBuf[MAX_ACCOUNT_NAME_SIZE] = 0x00;
|
samUserBuf[MAX_ACCOUNT_NAME_SIZE] = 0x00;
|
||||||
|
|
||||||
RtlInitUnicodeString((PUNICODE_STRING) &samUser, samUserBuf);
|
RtlInitUnicodeString((PUNICODE_STRING)&samUser, samUserBuf);
|
||||||
|
|
||||||
NTFAIL(LsaApi.GetAuthDataForUser(&samUser, SecNameFlat, NULL,
|
NTFAIL(LsaApi.GetAuthDataForUser(&samUser, SecNameFlat, NULL,
|
||||||
&userAuth, &userAuthSize, flatName));
|
&userAuth, &userAuthSize, flatName));
|
||||||
@ -448,7 +432,7 @@ NTSTATUS NTAPI
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
memcpy (tokenSource.SourceName, "_sshlsa_", 8);
|
memcpy(tokenSource.SourceName, "_sshlsa_", 8);
|
||||||
|
|
||||||
AllocateLocallyUniqueId(&tokenSource.SourceIdentifier);
|
AllocateLocallyUniqueId(&tokenSource.SourceIdentifier);
|
||||||
|
|
||||||
@ -502,7 +486,7 @@ NTSTATUS NTAPI
|
|||||||
|
|
||||||
exitCode = 0;
|
exitCode = 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
|
||||||
if (exitCode)
|
if (exitCode)
|
||||||
{
|
{
|
||||||
@ -530,25 +514,25 @@ fail:
|
|||||||
|
|
||||||
|
|
||||||
return ntStat;
|
return ntStat;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// This functions is called, after session closed. This is only
|
|
||||||
// information for package and we don't need to do anything here.
|
|
||||||
//
|
|
||||||
|
|
||||||
VOID NTAPI LsaApLogonTerminated(PLUID logonId)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// DllMain function (called when DLL is loaded or unloaded)
|
// This functions is called, after session closed. This is only
|
||||||
//
|
// information for package and we don't need to do anything here.
|
||||||
|
//
|
||||||
|
|
||||||
BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpRes)
|
VOID NTAPI LsaApLogonTerminated(PLUID logonId)
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// DllMain function (called when DLL is loaded or unloaded)
|
||||||
|
//
|
||||||
|
|
||||||
|
BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpRes)
|
||||||
|
{
|
||||||
BOOL exitCode = FALSE;
|
BOOL exitCode = FALSE;
|
||||||
|
|
||||||
switch (dwReason)
|
switch (dwReason)
|
||||||
@ -601,7 +585,7 @@ BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpRes)
|
|||||||
|
|
||||||
exitCode = TRUE;
|
exitCode = TRUE;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
|
||||||
if (exitCode == FALSE)
|
if (exitCode == FALSE)
|
||||||
{
|
{
|
||||||
@ -610,52 +594,52 @@ fail:
|
|||||||
}
|
}
|
||||||
|
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// For compatibility only.
|
// For compatibility only.
|
||||||
//
|
//
|
||||||
|
|
||||||
NTSTATUS NTAPI LsaApCallPackagePassthrough(PLSA_CLIENT_REQUEST request,
|
NTSTATUS NTAPI LsaApCallPackagePassthrough(PLSA_CLIENT_REQUEST request,
|
||||||
PVOID submitBuf,
|
PVOID submitBuf,
|
||||||
PVOID clientBufBase,
|
PVOID clientBufBase,
|
||||||
ULONG submitBufSize,
|
ULONG submitBufSize,
|
||||||
PVOID *outBuf,
|
PVOID *outBuf,
|
||||||
PULONG outBufSize,
|
PULONG outBufSize,
|
||||||
PNTSTATUS status)
|
PNTSTATUS status)
|
||||||
{
|
{
|
||||||
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// For compatibility only.
|
// For compatibility only.
|
||||||
//
|
//
|
||||||
|
|
||||||
NTSTATUS NTAPI LsaApCallPackageUntrusted(PLSA_CLIENT_REQUEST request,
|
NTSTATUS NTAPI LsaApCallPackageUntrusted(PLSA_CLIENT_REQUEST request,
|
||||||
PVOID submitBuf,
|
PVOID submitBuf,
|
||||||
PVOID clientBufBase,
|
PVOID clientBufBase,
|
||||||
ULONG submitBufSize,
|
ULONG submitBufSize,
|
||||||
PVOID *outBuf,
|
PVOID *outBuf,
|
||||||
PULONG outBufSize,
|
PULONG outBufSize,
|
||||||
PNTSTATUS status)
|
PNTSTATUS status)
|
||||||
{
|
{
|
||||||
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// For compatibility only.
|
// For compatibility only.
|
||||||
//
|
//
|
||||||
|
|
||||||
NTSTATUS NTAPI LsaApCallPackage(PLSA_CLIENT_REQUEST request, PVOID submitBuf,
|
NTSTATUS NTAPI LsaApCallPackage(PLSA_CLIENT_REQUEST request, PVOID submitBuf,
|
||||||
PVOID clientBufBase, ULONG submitBufSize,
|
PVOID clientBufBase, ULONG submitBufSize,
|
||||||
PVOID *outBuf, PULONG outBufSize,
|
PVOID *outBuf, PULONG outBufSize,
|
||||||
PNTSTATUS status)
|
PNTSTATUS status)
|
||||||
{
|
{
|
||||||
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ generate_user_token(wchar_t* user) {
|
|||||||
LSA_OPERATIONAL_MODE mode;
|
LSA_OPERATIONAL_MODE mode;
|
||||||
ULONG auth_package_id;
|
ULONG auth_package_id;
|
||||||
NTSTATUS ret, subStatus;
|
NTSTATUS ret, subStatus;
|
||||||
KERB_S4U_LOGON *s4u_logon = NULL;
|
void * logon_info = NULL;
|
||||||
size_t logon_info_size;
|
size_t logon_info_size;
|
||||||
LSA_STRING logon_process_name, auth_package_name, originName;
|
LSA_STRING logon_process_name, auth_package_name, originName;
|
||||||
TOKEN_SOURCE sourceContext;
|
TOKEN_SOURCE sourceContext;
|
||||||
@ -64,10 +64,14 @@ generate_user_token(wchar_t* user) {
|
|||||||
LUID logonId;
|
LUID logonId;
|
||||||
QUOTA_LIMITS quotas;
|
QUOTA_LIMITS quotas;
|
||||||
DWORD cbProfile;
|
DWORD cbProfile;
|
||||||
|
BOOL domain_user = (wcschr(user, L'@') != NULL)? TRUE : FALSE;
|
||||||
|
|
||||||
InitLsaString(&logon_process_name, "ssh-agent");
|
InitLsaString(&logon_process_name, "ssh-agent");
|
||||||
//InitLsaString(&auth_package_name, MICROSOFT_KERBEROS_NAME_A);
|
if (domain_user)
|
||||||
InitLsaString(&auth_package_name, "Negotiate");
|
InitLsaString(&auth_package_name, MICROSOFT_KERBEROS_NAME_A);
|
||||||
|
else
|
||||||
|
InitLsaString(&auth_package_name, "SSH-LSA");
|
||||||
|
|
||||||
InitLsaString(&originName, "sshd");
|
InitLsaString(&originName, "sshd");
|
||||||
if (ret = LsaRegisterLogonProcess(&logon_process_name, &lsa_handle, &mode) != STATUS_SUCCESS)
|
if (ret = LsaRegisterLogonProcess(&logon_process_name, &lsa_handle, &mode) != STATUS_SUCCESS)
|
||||||
goto done;
|
goto done;
|
||||||
@ -75,12 +79,14 @@ generate_user_token(wchar_t* user) {
|
|||||||
if (ret = LsaLookupAuthenticationPackage(lsa_handle, &auth_package_name, &auth_package_id) != STATUS_SUCCESS)
|
if (ret = LsaLookupAuthenticationPackage(lsa_handle, &auth_package_name, &auth_package_id) != STATUS_SUCCESS)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
if (domain_user) {
|
||||||
|
KERB_S4U_LOGON *s4u_logon;
|
||||||
logon_info_size = sizeof(KERB_S4U_LOGON);
|
logon_info_size = sizeof(KERB_S4U_LOGON);
|
||||||
logon_info_size += (wcslen(user) * 2 + 2);
|
logon_info_size += (wcslen(user) * 2 + 2);
|
||||||
s4u_logon = malloc(logon_info_size);
|
logon_info = malloc(logon_info_size);
|
||||||
if (s4u_logon == NULL)
|
if (logon_info == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
|
s4u_logon = (KERB_S4U_LOGON*)logon_info;
|
||||||
s4u_logon->MessageType = KerbS4ULogon;
|
s4u_logon->MessageType = KerbS4ULogon;
|
||||||
s4u_logon->Flags = 0;
|
s4u_logon->Flags = 0;
|
||||||
s4u_logon->ClientUpn.Length = wcslen(user) * 2;
|
s4u_logon->ClientUpn.Length = wcslen(user) * 2;
|
||||||
@ -90,8 +96,16 @@ generate_user_token(wchar_t* user) {
|
|||||||
s4u_logon->ClientRealm.Length = 0;
|
s4u_logon->ClientRealm.Length = 0;
|
||||||
s4u_logon->ClientRealm.MaximumLength = 0;
|
s4u_logon->ClientRealm.MaximumLength = 0;
|
||||||
s4u_logon->ClientRealm.Buffer = 0;
|
s4u_logon->ClientRealm.Buffer = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logon_info_size = (wcslen(user) + 1)*sizeof(wchar_t);
|
||||||
|
logon_info = malloc(logon_info_size);
|
||||||
|
if (logon_info == NULL)
|
||||||
|
goto done;
|
||||||
|
memcpy(logon_info, user, logon_info_size);
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(sourceContext.SourceName,".Jobs ", sizeof(sourceContext.SourceName));
|
memcpy(sourceContext.SourceName,"sshagent", sizeof(sourceContext.SourceName));
|
||||||
|
|
||||||
if (AllocateLocallyUniqueId(&sourceContext.SourceIdentifier) != TRUE)
|
if (AllocateLocallyUniqueId(&sourceContext.SourceIdentifier) != TRUE)
|
||||||
goto done;
|
goto done;
|
||||||
@ -100,7 +114,7 @@ generate_user_token(wchar_t* user) {
|
|||||||
&originName,
|
&originName,
|
||||||
Network,
|
Network,
|
||||||
auth_package_id,
|
auth_package_id,
|
||||||
s4u_logon,
|
logon_info,
|
||||||
logon_info_size,
|
logon_info_size,
|
||||||
NULL,
|
NULL,
|
||||||
&sourceContext,
|
&sourceContext,
|
||||||
@ -115,8 +129,8 @@ generate_user_token(wchar_t* user) {
|
|||||||
done:
|
done:
|
||||||
if (lsa_handle)
|
if (lsa_handle)
|
||||||
LsaDeregisterLogonProcess(lsa_handle);
|
LsaDeregisterLogonProcess(lsa_handle);
|
||||||
if (s4u_logon)
|
if (logon_info)
|
||||||
free(s4u_logon);
|
free(logon_info);
|
||||||
if (pProfile)
|
if (pProfile)
|
||||||
LsaFreeReturnBuffer(pProfile);
|
LsaFreeReturnBuffer(pProfile);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user