Beispiel #1
0
 public void testGetUserAccount() {
   USER_INFO_1 userInfo = new USER_INFO_1();
   userInfo.usri1_name = "JNANetapi32TestUser";
   userInfo.usri1_password = "******";
   userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
   // ignore test if not able to add user (need to be administrator to do this).
   if (LMErr.NERR_Success != Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null)) {
     return;
   }
   try {
     HANDLEByReference phUser = new HANDLEByReference();
     try {
       assertTrue(
           Advapi32.INSTANCE.LogonUser(
               userInfo.usri1_name.toString(),
               null,
               userInfo.usri1_password.toString(),
               WinBase.LOGON32_LOGON_NETWORK,
               WinBase.LOGON32_PROVIDER_DEFAULT,
               phUser));
       Advapi32Util.Account account = Advapi32Util.getTokenAccount(phUser.getValue());
       assertTrue(account.name.length() > 0);
       assertEquals(userInfo.usri1_name.toString(), account.name);
     } finally {
       if (phUser.getValue() != WinBase.INVALID_HANDLE_VALUE) {
         Kernel32.INSTANCE.CloseHandle(phUser.getValue());
       }
     }
   } finally {
     assertEquals(
         LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name.toString()));
   }
 }
Beispiel #2
0
 public void testSetFileSecurityDescriptor() throws Exception {
   File file = createTempFile();
   SECURITY_DESCRIPTOR_RELATIVE sdr = Advapi32Util.getFileSecurityDescriptor(file, false);
   Advapi32Util.setFileSecurityDescriptor(file, sdr, false, true, true, false, true, false);
   sdr = Advapi32Util.getFileSecurityDescriptor(file, false);
   assertTrue(Advapi32.INSTANCE.IsValidSecurityDescriptor(sdr.getPointer()));
   file.delete();
 }
Beispiel #3
0
 private static void registrySetEmptyValue(
     HKEY root, String keyPath, String name, final int valueType) {
   HKEYByReference phkKey = new HKEYByReference();
   int rc =
       Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey);
   if (rc != W32Errors.ERROR_SUCCESS) {
     throw new Win32Exception(rc);
   }
   try {
     char[] data = new char[0];
     rc = Advapi32.INSTANCE.RegSetValueEx(phkKey.getValue(), name, 0, valueType, data, 0);
     if (rc != W32Errors.ERROR_SUCCESS) {
       throw new Win32Exception(rc);
     }
   } finally {
     rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
     if (rc != W32Errors.ERROR_SUCCESS) {
       throw new Win32Exception(rc);
     }
   }
 }