void ExtractACLNew(Archive &Arc,char *FileName,wchar *FileNameW) { if (!WinNT()) return; Array<byte> SubData; if (!Arc.ReadSubData(&SubData,(File *) NULL)) return; SetPrivileges(); SECURITY_INFORMATION si=OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION| DACL_SECURITY_INFORMATION; if (ReadSacl) si|=SACL_SECURITY_INFORMATION; SECURITY_DESCRIPTOR *sd=(SECURITY_DESCRIPTOR *)&SubData[0]; int SetCode; if (FileNameW!=NULL) SetCode=SetFileSecurityW(FileNameW,si,sd); else SetCode=SetFileSecurityA(FileName,si,sd); if (!SetCode) { Log(Arc.FileName,St(MACLSetError),FileName); ErrHandler.SysErrMsg(); ErrHandler.SetErrorCode(WARNING); } }
void ExtractACL(Archive &Arc,char *FileName,wchar *FileNameW) { if (!WinNT()) return; SetPrivileges(); if (Arc.HeaderCRC!=Arc.EAHead.HeadCRC) { Log(Arc.FileName,St(MACLBroken),FileName); ErrHandler.SetErrorCode(CRC_ERROR); return; } if (Arc.EAHead.Method<0x31 || Arc.EAHead.Method>0x35 || Arc.EAHead.UnpVer>PACK_VER) { Log(Arc.FileName,St(MACLUnknown),FileName); ErrHandler.SetErrorCode(WARNING); return; } ComprDataIO DataIO; Unpack Unpack(&DataIO); Unpack.Init(); Array<byte> UnpData(Arc.EAHead.UnpSize); DataIO.SetUnpackToMemory(&UnpData[0],Arc.EAHead.UnpSize); DataIO.SetPackedSizeToRead(Arc.EAHead.DataSize); DataIO.EnableShowProgress(false); DataIO.SetFiles(&Arc,NULL); Unpack.SetDestSize(Arc.EAHead.UnpSize); Unpack.DoUnpack(Arc.EAHead.UnpVer,false); if (Arc.EAHead.EACRC!=~DataIO.UnpFileCRC) { Log(Arc.FileName,St(MACLBroken),FileName); ErrHandler.SetErrorCode(CRC_ERROR); return; } SECURITY_INFORMATION si=OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION| DACL_SECURITY_INFORMATION; if (ReadSacl) si|=SACL_SECURITY_INFORMATION; SECURITY_DESCRIPTOR *sd=(SECURITY_DESCRIPTOR *)&UnpData[0]; int SetCode; if (FileNameW!=NULL) SetCode=SetFileSecurityW(FileNameW,si,sd); else SetCode=SetFileSecurityA(FileName,si,sd); if (!SetCode) { Log(Arc.FileName,St(MACLSetError),FileName); ErrHandler.SysErrMsg(); ErrHandler.SetErrorCode(WARNING); } }
JNIEXPORT void JNICALL Java_org_gudy_azureus2_platform_win32_access_impl_AEWin32AccessInterface_copyPermissionA( JNIEnv *env, jclass cla, jstring _fileNameIn, jstring _fileNameOut ) { char file_name_in[2048]; char file_name_out[2048]; if ( !jstringToCharsA( env, _fileNameIn, file_name_in, sizeof( file_name_in )-1)){ return; } if ( !jstringToCharsA( env, _fileNameOut, file_name_out, sizeof( file_name_out )-1)){ return; } SECURITY_INFORMATION secInfo = DACL_SECURITY_INFORMATION; DWORD cbFileSD = 0; PSECURITY_DESCRIPTOR pFileSD = NULL; BOOL ok = GetFileSecurityA(file_name_in, secInfo, pFileSD, 0, &cbFileSD); // API should have failed with insufficient buffer. if ( ok ){ throwException( env, "copyPermission", "GetFileSecurity ok" ); return; }else if (GetLastError() == ERROR_FILE_NOT_FOUND) { throwException( env, "copyPermission", "from file not found" ); return; }else if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { throwException( env, "copyPermission", "GetFileSecurity unexpected response", GetLastError() ); return; }else{ pFileSD = myheapalloc( cbFileSD ); if (!pFileSD) { throwException( env, "copyPermission", "no memory" ); return; } ok = GetFileSecurityA(file_name_in, secInfo, pFileSD, cbFileSD, &cbFileSD ); if (!ok) { myheapfree( pFileSD ); throwException( env, "copyPermission", "GetFileSecurity", GetLastError()); return; } ok = SetFileSecurityA( file_name_out, secInfo, pFileSD ); myheapfree( pFileSD ); if ( !ok ){ if (GetLastError() == ERROR_FILE_NOT_FOUND) { throwException( env, "copyPermission", "to file not found" ); }else{ throwException( env, "copyPermission", "SetFileSecurity unexpected response", GetLastError() ); } } } }