Examples of PSID


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

    if (pSid.getValue() == 0 || rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
      throw new Win32Exception(rc);
    }

    Memory sidMemory = new Memory(pSid.getValue());
    PSID result = new PSID(sidMemory);
    char[] referencedDomainName = new char[cchDomainName.getValue() + 1];

    if (!Advapi32.INSTANCE.LookupAccountName(systemName, accountName,
        result, pSid, referencedDomainName, cchDomainName, peUse)) {
      throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
    }

    Account account = new Account();
    account.accountType = peUse.getPointer().getInt(0);
    account.name = accountName;

    String[] accountNamePartsBs = accountName.split("\\\\", 2);
    String[] accountNamePartsAt = accountName.split("@", 2);

    if (accountNamePartsBs.length == 2) {
      account.name = accountNamePartsBs[1];
    } else if (accountNamePartsAt.length == 2) {
      account.name = accountNamePartsAt[0];
    } else {
      account.name = accountName;
    }

    if (cchDomainName.getValue() > 0) {
      account.domain = Native.toString(referencedDomainName);
      account.fqn = account.domain + "\\" + account.name;
    } else {
      account.fqn = account.name;
    }

    account.sid = result.getBytes();
    account.sidString = convertSidToStringSid(new PSID(account.sid));
    return account;
  }
View Full Code Here

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

   *            Member of the WELL_KNOWN_SID_TYPE enumeration to compare with
   *            the SID at pSid.
   * @return True if the SID is of the well-known type, false otherwise.
   */
  public static boolean isWellKnownSid(byte[] sidBytes, int wellKnownSidType) {
    PSID pSID = new PSID(sidBytes);
    return Advapi32.INSTANCE.IsWellKnownSid(pSID, wellKnownSidType);
  }
View Full Code Here

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

   * @param sidString
   *            SID.
   * @return Account.
   */
  public static Account getAccountBySid(String systemName, String sidString) {
    return getAccountBySid(systemName, new PSID(
        convertStringSidToSid(sidString)));
  }
View Full Code Here

Examples of com.sun.jna.platform.win32.WinNT.PSID

        System.out.println("AccountByName: " + currentUserName);
        System.out.println(" Fqn: " + accountByName.fqn);
        System.out.println(" Domain: " + accountByName.domain);
        System.out.println(" Sid: " + accountByName.sidString);
       
        Account accountBySid = Advapi32Util.getAccountBySid(new PSID(accountByName.sid));
        System.out.println("AccountBySid: " + accountByName.sidString);
        System.out.println(" Fqn: " + accountBySid.fqn);
        System.out.println(" Name: " + accountBySid.name);
        System.out.println(" Domain: " + accountBySid.domain);
    }
View Full Code Here

Examples of com.sun.jna.platform.win32.WinNT.PSID

    }
 
    public void testGetAccountBySid() {   
        String accountName = Advapi32Util.getUserName();
        Account currentUser = Advapi32Util.getAccountByName(accountName);
        Account account = Advapi32Util.getAccountBySid(new PSID(currentUser.sid));
        assertEquals(SID_NAME_USE.SidTypeUser, account.accountType);
        assertEquals(currentUser.fqn.toLowerCase(), account.fqn.toLowerCase());
        assertEquals(currentUser.name.toLowerCase(), account.name.toLowerCase());
        assertEquals(currentUser.domain.toLowerCase(), account.domain.toLowerCase());
        assertEquals(currentUser.sidString, account.sidString);   
View Full Code Here

Examples of com.sun.jna.platform.win32.WinNT.PSID

 
    public void testConvertSid() {
      String sidString = "S-1-1-0"; // Everyone
      byte[] sidBytes = Advapi32Util.convertStringSidToSid(sidString);
      assertTrue(sidBytes.length > 0);
      String convertedSidString = Advapi32Util.convertSidToStringSid(new PSID(sidBytes));
      assertEquals(convertedSidString, sidString);
    }
View Full Code Here

Examples of com.sun.jna.platform.win32.WinNT.PSID

    assertFalse(Advapi32.INSTANCE.LookupAccountName(
        null, accountName, null, pSid, null, pDomain, peUse));
    assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
    assertTrue(pSid.getValue() > 0);
    Memory sidMemory = new Memory(pSid.getValue());
    PSID pSidMemory = new PSID(sidMemory);
    char[] referencedDomainName = new char[pDomain.getValue() + 1];
    assertTrue(Advapi32.INSTANCE.LookupAccountName(
        null, accountName, pSidMemory, pSid, referencedDomainName, pDomain, peUse));
    assertEquals(SID_NAME_USE.SidTypeUser, peUse.getPointer().getInt(0));
    assertTrue(Native.toString(referencedDomainName).length() > 0);
View Full Code Here

Examples of com.sun.jna.platform.win32.WinNT.PSID

      assertFalse(Advapi32.INSTANCE.IsWellKnownSid(sid.getValue(),
          WELL_KNOWN_SID_TYPE.WinAccountAdministratorSid));
    }
   
    public void testCreateWellKnownSid() {
      PSID pSid = new PSID(WinNT.SECURITY_MAX_SID_SIZE);
      IntByReference cbSid = new IntByReference(WinNT.SECURITY_MAX_SID_SIZE);
      assertTrue(Advapi32.INSTANCE.CreateWellKnownSid(WELL_KNOWN_SID_TYPE.WinWorldSid,
          null, pSid, cbSid));
      assertTrue(Advapi32.INSTANCE.IsWellKnownSid(pSid,
          WELL_KNOWN_SID_TYPE.WinWorldSid));
View Full Code Here

Examples of com.sun.jna.platform.win32.WinNT.PSID

    if (pSid.getValue() == 0 || rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
      throw new Win32Exception(rc);
    }

    Memory sidMemory = new Memory(pSid.getValue());
    PSID result = new PSID(sidMemory);
    char[] referencedDomainName = new char[cchDomainName.getValue() + 1];

    if (!Advapi32.INSTANCE.LookupAccountName(systemName, accountName,
        result, pSid, referencedDomainName, cchDomainName, peUse)) {
      throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
    }

    Account account = new Account();
    account.accountType = peUse.getPointer().getInt(0);
    account.name = accountName;

    String[] accountNamePartsBs = accountName.split("\\\\", 2);
    String[] accountNamePartsAt = accountName.split("@", 2);

    if (accountNamePartsBs.length == 2) {
      account.name = accountNamePartsBs[1];
    } else if (accountNamePartsAt.length == 2) {
      account.name = accountNamePartsAt[0];
    } else {
      account.name = accountName;
    }

    if (cchDomainName.getValue() > 0) {
      account.domain = Native.toString(referencedDomainName);
      account.fqn = account.domain + "\\" + account.name;
    } else {
      account.fqn = account.name;
    }

    account.sid = result.getBytes();
    account.sidString = convertSidToStringSid(new PSID(account.sid));
    return account;
  }
View Full Code Here

Examples of com.sun.jna.platform.win32.WinNT.PSID

   *            Member of the WELL_KNOWN_SID_TYPE enumeration to compare with
   *            the SID at pSid.
   * @return True if the SID is of the well-known type, false otherwise.
   */
  public static boolean isWellKnownSid(byte[] sidBytes, int wellKnownSidType) {
    PSID pSID = new PSID(sidBytes);
    return Advapi32.INSTANCE.IsWellKnownSid(pSID, wellKnownSidType);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.