This commit is contained in:
DavidXanatos 2022-05-28 12:39:32 +02:00
parent 70dfb50673
commit e158b4f63f
2 changed files with 54 additions and 28 deletions

View File

@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed ### Fixed
- fixed edge issue with windows 11 after KB5014019 - fixed edge issue with windows 11 after KB5014019
- fixed issues with the new delete mechanism with "SeparateUserFolders=y" - fixed issues with the new delete mechanism with "SeparateUserFolders=y"
- fixed credential issue [#1770](https://github.com/sandboxie-plus/Sandboxie/pull/1770)

View File

@ -63,9 +63,9 @@ static BOOL Cred_CredWriteW(void *pCredential, ULONG Flags);
static BOOL Cred_CredWriteA(void *pCredential, ULONG Flags); static BOOL Cred_CredWriteA(void *pCredential, ULONG Flags);
static BOOL Cred_CredReadW( static BOOL Cred_CredReadW(
void *TargetName, ULONG Type, ULONG Flags, void **ppCredential); const wchar_t *TargetName, ULONG Type, ULONG Flags, void **ppCredential);
static BOOL Cred_CredReadA( static BOOL Cred_CredReadA(
void *TargetName, ULONG Type, ULONG Flags, void **ppCredential); const char *TargetName, ULONG Type, ULONG Flags, void **ppCredential);
static BOOL Cred_CredWriteDomainCredentialsW( static BOOL Cred_CredWriteDomainCredentialsW(
void *pTargetInfo, void *pCredential, ULONG Flags); void *pTargetInfo, void *pCredential, ULONG Flags);
@ -87,8 +87,8 @@ static BOOL Cred_CredRenameW(
static BOOL Cred_CredRenameA( static BOOL Cred_CredRenameA(
void *OldTargetName, void *NewTargetName, ULONG Type, ULONG Flags); void *OldTargetName, void *NewTargetName, ULONG Type, ULONG Flags);
static BOOL Cred_CredDeleteW(void *TargetName, ULONG Type, ULONG Flags); static BOOL Cred_CredDeleteW(const wchar_t *TargetName, ULONG Type, ULONG Flags);
static BOOL Cred_CredDeleteA(void *TargetName, ULONG Type, ULONG Flags); static BOOL Cred_CredDeleteA(const char *TargetName, ULONG Type, ULONG Flags);
static BOOL Cred_CredEnumerateW( static BOOL Cred_CredEnumerateW(
void *pFilter, ULONG Flags, ULONG *pCount, void ***ppCredentials); void *pFilter, ULONG Flags, ULONG *pCount, void ***ppCredentials);
@ -149,6 +149,8 @@ static const WCHAR *Cred_DomainCred = L"DomainCred-";
extern const WCHAR *Pst_OpenProtectedStorage; extern const WCHAR *Pst_OpenProtectedStorage;
//static BOOLEAN Cred_Trace = FALSE;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// SBIEDLL_HOOK_CRED // SBIEDLL_HOOK_CRED
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -181,6 +183,8 @@ _FX BOOLEAN Cred_Init_AdvApi(HMODULE module)
if (SbieApi_QueryConfBool(NULL, L"OpenCredentials", FALSE)) if (SbieApi_QueryConfBool(NULL, L"OpenCredentials", FALSE))
return TRUE; return TRUE;
//Cred_Trace = SbieApi_QueryConfBool(NULL, L"CredTrace", FALSE);
// __sys_CredMarshalCredential = (P_CredMarshalCredential) // __sys_CredMarshalCredential = (P_CredMarshalCredential)
// GetProcAddress(module, "CredMarshalCredential"); // GetProcAddress(module, "CredMarshalCredential");
@ -263,7 +267,8 @@ _FX WCHAR *Cred_GetName(
if (DomainName) if (DomainName)
len += wcslen(DomainName); len += wcslen(DomainName);
if (TargetName) if (TargetName)
len += wcslen(TargetName) + 10; //len += wcslen(TargetName) + 10;
len += wcslen(TargetName);
else else
TargetName = L"?"; TargetName = L"?";
@ -272,7 +277,8 @@ _FX WCHAR *Cred_GetName(
if (DomainName) if (DomainName)
Sbie_snwprintf(name, len, L"%s%s-%s", Cred_DomainCred, DomainName, TargetName); Sbie_snwprintf(name, len, L"%s%s-%s", Cred_DomainCred, DomainName, TargetName);
else else
Sbie_snwprintf(name, len, L"%s%08X-%s", Cred_SimpleCred, Type, TargetName); //Sbie_snwprintf(name, len, L"%s%08X-%s", Cred_SimpleCred, Type, TargetName);
Sbie_snwprintf(name, len, L"%s-%s", Cred_SimpleCred, TargetName);
return name; return name;
} }
@ -733,6 +739,12 @@ _FX BOOL Cred_CredWriteW(void *pCredential, ULONG Flags)
return FALSE; return FALSE;
} }
/*if (Cred_Trace) {
WCHAR msg[1024];
Sbie_snwprintf(msg, 1024, L"CredWriteW: %s (%d)", cred->TargetName, cred->Type);
SbieApi_MonitorPutMsg(MONITOR_OTHER | MONITOR_TRACE, msg);
}*/
name = Cred_GetName(NULL, cred->TargetName, cred->Type); name = Cred_GetName(NULL, cred->TargetName, cred->Type);
ok = Cred_WriteItem(name, mrshcred, mrshcred_len); ok = Cred_WriteItem(name, mrshcred, mrshcred_len);
@ -752,7 +764,7 @@ _FX BOOL Cred_CredWriteW(void *pCredential, ULONG Flags)
_FX BOOL Cred_CredReadW( _FX BOOL Cred_CredReadW(
void *TargetName, ULONG Type, ULONG Flags, void **ppCredential) const wchar_t* TargetName, ULONG Type, ULONG Flags, void** ppCredential)
{ {
HRESULT hr; HRESULT hr;
WCHAR *name; WCHAR *name;
@ -778,8 +790,9 @@ _FX BOOL Cred_CredReadW(
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
Cred_CoTaskMemFree(mrshcred); Cred_CoTaskMemFree(mrshcred);
return __sys_CredReadW(TargetName, Type, Flags, ppCredential); ok = __sys_CredReadW(TargetName, Type, Flags, ppCredential);
} }
else {
*ppCredential = Cred_Unserialize1(mrshcred); *ppCredential = Cred_Unserialize1(mrshcred);
@ -788,13 +801,21 @@ _FX BOOL Cred_CredReadW(
if (*ppCredential) { if (*ppCredential) {
err = 0; err = 0;
ok = TRUE; ok = TRUE;
} else { }
else {
err = ERROR_NOT_FOUND; err = ERROR_NOT_FOUND;
ok = FALSE; ok = FALSE;
} }
SetLastError(err); SetLastError(err);
}
/*if (Cred_Trace) {
WCHAR msg[1024];
Sbie_snwprintf(msg, 1024, L"CredReadW: %s (%d) = %d", TargetName, Type, FAILED(hr) ? ok : (ok ? 2 : -1));
SbieApi_MonitorPutMsg(MONITOR_OTHER | MONITOR_TRACE, msg);
}*/
return ok; return ok;
} }
@ -944,24 +965,23 @@ _FX BOOL Cred_CredReadDomainCredentialsW(
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
_FX BOOL Cred_CredDeleteW(void *TargetName, ULONG Type, ULONG Flags) _FX BOOL Cred_CredDeleteW(const wchar_t *TargetName, ULONG Type, ULONG Flags)
{ {
WCHAR *name; WCHAR *name;
ULONG zero; ULONG zero;
PCREDENTIALW *cred; CREDENTIALW *cred;
if (!Cred_PreparePStore()) { if (!Cred_PreparePStore()) {
SetLastError(ERROR_NOT_FOUND); SetLastError(ERROR_NOT_FOUND);
return FALSE; return FALSE;
} }
name = Cred_GetName(NULL, TargetName, Type);
if (Cred_CredReadW(name, Type, Flags, (void **)&cred)) { if (Cred_CredReadW(TargetName, Type, Flags, &cred)) {
if (!cred) { if (!cred) {
SetLastError(ERROR_NOT_FOUND); SetLastError(ERROR_NOT_FOUND);
return FALSE; return FALSE;
} }
if (cred[0]->CredentialBlobSize == sizeof(ULONG) && *(ULONG *)cred[0]->CredentialBlob == 0) { if (cred->CredentialBlobSize == sizeof(ULONG) && *(ULONG *)cred->CredentialBlob == 0) {
LocalFree(cred); LocalFree(cred);
SetLastError(ERROR_NOT_FOUND); SetLastError(ERROR_NOT_FOUND);
return FALSE; return FALSE;
@ -973,10 +993,15 @@ _FX BOOL Cred_CredDeleteW(void *TargetName, ULONG Type, ULONG Flags)
} }
LocalFree(cred); LocalFree(cred);
zero = 0; zero = 0;
name = Cred_GetName(NULL, TargetName, Type);
if (!Cred_WriteItem(name, &zero, sizeof(ULONG))) { if (!Cred_WriteItem(name, &zero, sizeof(ULONG))) {
Dll_Free(name);
SetLastError(ERROR_NOT_FOUND); SetLastError(ERROR_NOT_FOUND);
return FALSE; return FALSE;
} }
Dll_Free(name);
return TRUE; return TRUE;
} }
@ -1193,7 +1218,7 @@ _FX BOOL Cred_CredRenameA(
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
_FX BOOL Cred_CredDeleteA(void *TargetName, ULONG Type, ULONG Flags) _FX BOOL Cred_CredDeleteA(const char *TargetName, ULONG Type, ULONG Flags)
{ {
SbieApi_Log(2205, L"CredDeleteA"); SbieApi_Log(2205, L"CredDeleteA");
SetLastError(ERROR_NO_SUCH_LOGON_SESSION); SetLastError(ERROR_NO_SUCH_LOGON_SESSION);
@ -1207,7 +1232,7 @@ _FX BOOL Cred_CredDeleteA(void *TargetName, ULONG Type, ULONG Flags)
_FX BOOL Cred_CredReadA( _FX BOOL Cred_CredReadA(
void *TargetName, ULONG Type, ULONG Flags, void **ppCredential) const char *TargetName, ULONG Type, ULONG Flags, void **ppCredential)
{ {
SbieApi_Log(2205, L"CredReadA"); SbieApi_Log(2205, L"CredReadA");
return __sys_CredReadA(TargetName, Type, Flags, ppCredential); return __sys_CredReadA(TargetName, Type, Flags, ppCredential);