Package com.sun.jna.examples.win32.WinNT

Examples of com.sun.jna.examples.win32.WinNT.HANDLEByReference


    }
   
    private FileInfo waitForChange() {
        Kernel32 klib = Kernel32.INSTANCE;
        IntByReference rcount = new IntByReference();
        HANDLEByReference rkey = new HANDLEByReference();
        PointerByReference roverlap = new PointerByReference();
        klib.GetQueuedCompletionStatus(port, rcount, rkey, roverlap, WinBase.INFINITE);
       
        synchronized (this) {
            return (FileInfo)handleMap.get(rkey.getValue());
        }
    }
View Full Code Here


  /**
   * Return the group memberships of the currently logged on user.
   * @return An array of groups.
   */
  public static Account[] getCurrentUserGroups() {   
      HANDLEByReference phToken = new HANDLEByReference();     
      try {
        // open thread or process token
          HANDLE threadHandle = Kernel32.INSTANCE.GetCurrentThread();
          if (! Advapi32.INSTANCE.OpenThreadToken(threadHandle,
              WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, true, phToken)) {
              if (W32Errors.ERROR_NO_TOKEN != Kernel32.INSTANCE.GetLastError()) {
                throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
              }         
              HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
              if (! Advapi32.INSTANCE.OpenProcessToken(processHandle,
                  WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken)) {
                throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
              }
          }
          return getTokenGroups(phToken.getValue());
      } finally {
        if (phToken.getValue() != WinBase.INVALID_HANDLE_VALUE) {
          if (! Kernel32.INSTANCE.CloseHandle(phToken.getValue())) {
            throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
          }
        }
      }   
  }
View Full Code Here

      userInfo.usri1_password = new WString("!JNAP$$Wrd0");
      userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
    try {
        assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserAdd(
            null, 1, userInfo, null));
      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));
        Account[] groups = Advapi32Util.getTokenGroups(phUser.getValue());
        assertTrue(groups.length > 0);
        for(Account group : groups) {
          assertTrue(group.name.length() > 0);
          assertTrue(group.sidString.length() > 0);
          assertTrue(group.sid.length > 0);
        }
      } 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()));     
View Full Code Here

      userInfo.usri1_password = new WString("!JNAP$$Wrd0");
      userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
    try {
        assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserAdd(
            null, 1, userInfo, null));
      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()));     
View Full Code Here

      assertEquals(null, Kernel32.INSTANCE.LocalFree(convertedSidStringPtr.getValue()));
      assertEquals(null, Kernel32.INSTANCE.LocalFree(sid.getValue().getPointer()));
    }
   
    public void testLogonUser() {
      HANDLEByReference phToken = new HANDLEByReference();
      assertFalse(Advapi32.INSTANCE.LogonUser("AccountDoesntExist", ".", "passwordIsInvalid",
          WinBase.LOGON32_LOGON_NETWORK, WinBase.LOGON32_PROVIDER_DEFAULT, phToken));
      assertTrue(W32Errors.ERROR_SUCCESS != Kernel32.INSTANCE.GetLastError());
    }
View Full Code Here

          WinBase.LOGON32_LOGON_NETWORK, WinBase.LOGON32_PROVIDER_DEFAULT, phToken));
      assertTrue(W32Errors.ERROR_SUCCESS != Kernel32.INSTANCE.GetLastError());
    }
   
    public void testOpenThreadTokenNoToken() {
      HANDLEByReference phToken = new HANDLEByReference();
      HANDLE threadHandle = Kernel32.INSTANCE.GetCurrentThread();
      assertNotNull(threadHandle);
      assertFalse(Advapi32.INSTANCE.OpenThreadToken(threadHandle,
          WinNT.TOKEN_READ, false, phToken));
      assertEquals(W32Errors.ERROR_NO_TOKEN, Kernel32.INSTANCE.GetLastError());
View Full Code Here

          WinNT.TOKEN_READ, false, phToken));
      assertEquals(W32Errors.ERROR_NO_TOKEN, Kernel32.INSTANCE.GetLastError());
    }
   
    public void testOpenProcessToken() {
      HANDLEByReference phToken = new HANDLEByReference();
      HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
      assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle,
          WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken));
      assertTrue(Kernel32.INSTANCE.CloseHandle(phToken.getValue()));     
    }
View Full Code Here

          WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken));
      assertTrue(Kernel32.INSTANCE.CloseHandle(phToken.getValue()));     
    }
   
    public void testOpenThreadOrProcessToken() {
      HANDLEByReference phToken = new HANDLEByReference();
      HANDLE threadHandle = Kernel32.INSTANCE.GetCurrentThread();
      if (! Advapi32.INSTANCE.OpenThreadToken(threadHandle,
          WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, true, phToken)) {
          assertEquals(W32Errors.ERROR_NO_TOKEN, Kernel32.INSTANCE.GetLastError());
          HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
          assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle,
              WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken));
      }
      assertTrue(Kernel32.INSTANCE.CloseHandle(phToken.getValue()));
    }
View Full Code Here

      }
      assertTrue(Kernel32.INSTANCE.CloseHandle(phToken.getValue()));
    }
   
    public void testDuplicateToken() {
      HANDLEByReference phToken = new HANDLEByReference();
      HANDLEByReference phTokenDup = new HANDLEByReference();
      HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
        assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle,
            WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken));
        assertTrue(Advapi32.INSTANCE.DuplicateToken(phToken.getValue(),
            WinNT.SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, phTokenDup));
      assertTrue(Kernel32.INSTANCE.CloseHandle(phTokenDup.getValue()));
      assertTrue(Kernel32.INSTANCE.CloseHandle(phToken.getValue()));
    }
View Full Code Here

      assertTrue(Kernel32.INSTANCE.CloseHandle(phTokenDup.getValue()));
      assertTrue(Kernel32.INSTANCE.CloseHandle(phToken.getValue()));
    }
   
    public void testDuplicateTokenEx() {
      HANDLEByReference hExistingToken = new HANDLEByReference();
      HANDLEByReference phNewToken = new HANDLEByReference();
      HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
      assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle,
          WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, hExistingToken));
      assertTrue(Advapi32.INSTANCE.DuplicateTokenEx(hExistingToken.getValue(),
          WinNT.GENERIC_READ, null, SECURITY_IMPERSONATION_LEVEL.SecurityAnonymous,
          TOKEN_TYPE.TokenPrimary, phNewToken));
      assertTrue(Kernel32.INSTANCE.CloseHandle(phNewToken.getValue()));
      assertTrue(Kernel32.INSTANCE.CloseHandle(hExistingToken.getValue()));
    }
View Full Code Here

TOP

Related Classes of com.sun.jna.examples.win32.WinNT.HANDLEByReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.