Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/win32/nt.c view on Meta::CPAN
{
HANDLE hMutex;
HANDLE hOldMutex;
if (bInitialized) return TRUE;
hMutex = CreateMutex(NULL, TRUE, NULL);
if(hMutex == NULL) return FALSE;
hOldMutex = (HANDLE)InterlockedExchangePointer((void *)&hInitMutex,
hMutex);
if (hOldMutex != NULL) {
/* somebody setup the mutex already */
InterlockedExchangePointer((void *)&hInitMutex,
hOldMutex);
CloseHandle(hMutex); /* close new, un-needed mutex */
/* wait for initialization to complete and return status */
WaitForSingleObject(hOldMutex, INFINITE);
ReleaseMutex(hOldMutex);
return bInitialized;
}
if (!bInitialized) {
/* initialize module level resources */
InitializeCriticalSection( &VolumeCapsLock );
memset(&g_VolumeCaps, 0, sizeof(VOLUMECAPS));
InitLocalPrivileges();
bInitialized = TRUE;
}
InterlockedExchangePointer((void *)&hInitMutex,
NULL);
ReleaseMutex(hMutex); /* release correct mutex */
CloseHandle(hMutex); /* free the no longer needed handle resource */
return TRUE;
}
BOOL ValidateSecurity(uch *securitydata)
{
PSECURITY_DESCRIPTOR sd = (PSECURITY_DESCRIPTOR)securitydata;
PACL pAcl;
PSID pSid;
BOOL bAclPresent;
BOOL bDefaulted;
if(!IsWinNT()) return TRUE; /* don't do anything if not on WinNT */
if(!IsValidSecurityDescriptor(sd)) return FALSE;
/* verify Dacl integrity */
if(!GetSecurityDescriptorDacl(sd, &bAclPresent, &pAcl, &bDefaulted))
return FALSE;
if(bAclPresent && pAcl!=NULL) {
if(!IsValidAcl(pAcl)) return FALSE;
}
/* verify Sacl integrity */
if(!GetSecurityDescriptorSacl(sd, &bAclPresent, &pAcl, &bDefaulted))
return FALSE;
if(bAclPresent && pAcl!=NULL) {
if(!IsValidAcl(pAcl)) return FALSE;
}
/* verify owner integrity */
if(!GetSecurityDescriptorOwner(sd, &pSid, &bDefaulted))
return FALSE;
if(pSid != NULL) {
if(!IsValidSid(pSid)) return FALSE;
}
/* verify group integrity */
if(!GetSecurityDescriptorGroup(sd, &pSid, &bDefaulted))
return FALSE;
if(pSid != NULL) {
if(!IsValidSid(pSid)) return FALSE;
}
return TRUE;
}
static VOID GetRemotePrivilegesSet(char *FileName, PDWORD dwRemotePrivileges)
{
HANDLE hFile;
*dwRemotePrivileges = 0;
/* see if we have the SeRestorePrivilege */
hFile = CreateFileA(
FileName,
ACCESS_SYSTEM_SECURITY | WRITE_DAC | WRITE_OWNER | READ_CONTROL,
FILE_SHARE_READ | FILE_SHARE_DELETE, /* no sd updating allowed here */
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
NULL
);
if(hFile != INVALID_HANDLE_VALUE) {
/* no remote way to determine SeRestorePrivilege -- just try a
read/write to simulate it */
SECURITY_INFORMATION si = DACL_SECURITY_INFORMATION |
SACL_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION |
GROUP_SECURITY_INFORMATION;
PSECURITY_DESCRIPTOR sd;
DWORD cbBuf = 0;
GetKernelObjectSecurity(hFile, si, NULL, cbBuf, &cbBuf);
if(ERROR_INSUFFICIENT_BUFFER == GetLastError()) {
if((sd = HeapAlloc(GetProcessHeap(), 0, cbBuf)) != NULL) {
if(GetKernelObjectSecurity(hFile, si, sd, cbBuf, &cbBuf)) {
if(SetKernelObjectSecurity(hFile, si, sd))
*dwRemotePrivileges |= OVERRIDE_RESTORE;
}
HeapFree(GetProcessHeap(), 0, sd);
}
}
CloseHandle(hFile);
} else {
/* see if we have the SeSecurityPrivilege */
/* note we don't need this if we have SeRestorePrivilege */
hFile = CreateFileA(
FileName,
ACCESS_SYSTEM_SECURITY,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, /* max */
( run in 2.566 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )