/** * Convert a string representation of a security identifier (SID) to a * binary format. * * @param sidString * String SID. * @return SID bytes. */ public static byte[] convertStringSidToSid(String sidString) { PSIDByReference pSID = new PSIDByReference(); if (!Advapi32.INSTANCE.ConvertStringSidToSid(sidString, pSID)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } return pSID.getValue().getBytes(); }
/** * Compares a SID to a well known SID and returns TRUE if they match. * * @param sidString * String representation of a SID. * @param wellKnownSidType * 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(String sidString, int wellKnownSidType) { PSIDByReference pSID = new PSIDByReference(); if (!Advapi32.INSTANCE.ConvertStringSidToSid(sidString, pSID)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } return Advapi32.INSTANCE.IsWellKnownSid(pSID.getValue(), wellKnownSidType); }
/** * Compares a SID to a well known SID and returns TRUE if they match. * * @param sidString * String representation of a SID. * @param wellKnownSidType * 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(String sidString, int wellKnownSidType) { PSIDByReference pSID = new PSIDByReference(); if (!Advapi32.INSTANCE.ConvertStringSidToSid(sidString, pSID)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } PSID value = pSID.getValue(); try { return Advapi32.INSTANCE.IsWellKnownSid(value, wellKnownSidType); } finally { Kernel32Util.freeLocalMemory(value.getPointer()); } }
/** * Convert a string representation of a security identifier (SID) to a * binary format. * * @param sidString * String SID. * @return SID bytes. */ public static byte[] convertStringSidToSid(String sidString) { PSIDByReference pSID = new PSIDByReference(); if (!Advapi32.INSTANCE.ConvertStringSidToSid(sidString, pSID)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } PSID value = pSID.getValue(); try { return value.getBytes(); } finally { Kernel32Util.freeLocalMemory(value.getPointer()); } }