나는 문제가 있으며 거기에 누군가가 조언을 해줄 수 있기를 바랍니다! 기본적으로 내 프로그램에서 내가 사용이 그것의 꽤 바닐라 자바 등 액세스 제어 규칙을 설정, 소유권을 변경, 윈도우 폴더를 복용됩니다JNA를 사용하여 Java를 통해 Windows 디렉토리에 상속 복원
내가 디렉토리에 대해 잊지 할 때 문제가 발생 Files.getFileAttributeView(target, AclFileAttributeView.class);
, 이렇게하려면 상속을 상위 디렉터리로 다시 설정하고 모든 ACL 규칙을 제거하고 싶습니다.
: 나는이 같은 보안 설명자에 대한 포인터를 얻을 수 있다고 생각 ...을 규칙을 제거하고 다시 내가 상속 플래그를 설정하는 기본 가야처럼 자바 그러나 보이는 사용하여 다시 소유자를 설정할 수 있습니다
Advapi32 advapi32 = Advapi32.INSTANCE;
PointerByReference ppsidOwner = new PointerByReference();
PointerByReference ppsidGroup = new PointerByReference();
PointerByReference ppDacl = new PointerByReference();
PointerByReference ppSacl = new PointerByReference();
PointerByReference ppSecurityDescriptor = new PointerByReference();
int reqSecurityInfo = Advapi32.OWNER_SECURITY_INFORMATION |
Advapi32.DACL_SECURITY_INFORMATION |
Advapi32.SACL_SECURITY_INFORMATION |
Advapi32.GROUP_SECURITY_INFORMATION;
int ret = advapi32.GetNamedSecurityInfo("c:\\\\testpaths", Advapi32.SE_FILE_OBJECT,
reqSecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
if(ret != 0){
throw new Win32Exception(ret);
}
Advapi32.java 포함
: Advapi32 INSTANCE = (Advapi32) Native.loadLibrary("Advapi32", Advapi32.class, W32APIOptions.UNICODE_OPTIONS);
하지만 난 정말 여기에 약간의 몸부림하고는 바른 길에 I AM 또는 내가 바보가되는 건가요? 그것은 나를 위해 생소한 근거입니다, 제발 도와주세요!
[RGiesecke.DllExport.DllExport]
static void ReEnableInheretance(String dirPath)
{
DirectorySecurity dirSecurity = new DirectorySecurity();
dirSecurity.SetAccessRuleProtection(false, false);
Directory.SetAccessControl(dirPath, dirSecurity);
}
그리고 자바 :
public interface MyNewLib extends Library {
public void ReEnableInheretance(String dirPath);
}
MyNewLib myNewLib = (MyNewLib)Native.loadLibrary("MyNewLib ",MyNewLib.class);
myNewLib .ReEnableInheretance(path.toString());
참고 : Windows에서 파일 경로 구분 기호로 슬래시를 사용하는 것이 완전히 유효하며 문자열을 읽기 쉽도록 만듭니다. – technomage
실제로 이것을 사용해 보셨습니까? 결과는 무엇입니까? – technomage
그래, 나는 이것을 시도했지만, ppsidOwner 등에서 업데이트 된 포인터를 얻지 만, WinNT.dll에 속한 보안 객체로 변환하려고 할 때 손실되었다. WinNT.dll 인터페이스를 인스턴스화하려고하면 실제 dll을 찾을 수 없기 때문에 실패합니다. 그러나 WinNT.dll에서 메서드를 복사하면 인스턴스화되지 않은 배열이됩니다. 기본적으로 나는이 비트를 잘못하고 있으며 JNA 경험이있는 사람이 올바른 방향으로 나를 가리킬 수 있기를 바라고 있다고 생각합니다. – GavinF