Module jcifs

Class SID


public class SID extends rpc.sid_t
A Windows SID is a numeric identifier used to represent Windows accounts. SIDs are commonly represented using a textual format such as S-1-5-21-1496946806-2192648263-3843101252-1029 but they may also be resolved to yield the name of the associated Windows account such as Administrators or MYDOM\alice.

Consider the following output of examples/SidLookup.java:

        toString: S-1-5-21-4133388617-793952518-2001621813-512
 toDisplayString: WNET\Domain Admins
         getType: 2
     getTypeText: Domain group
   getDomainName: WNET
  getAccountName: Domain Admins
 
  • Field Details

    • SID_TYPE_USE_NONE

      public static final int SID_TYPE_USE_NONE
      SID type indicating no type information.
      See Also:
    • SID_TYPE_USER

      public static final int SID_TYPE_USER
      SID type indicating a user account.
      See Also:
    • SID_TYPE_DOM_GRP

      public static final int SID_TYPE_DOM_GRP
      SID type indicating a domain group.
      See Also:
    • SID_TYPE_DOMAIN

      public static final int SID_TYPE_DOMAIN
      SID type indicating a domain.
      See Also:
    • SID_TYPE_ALIAS

      public static final int SID_TYPE_ALIAS
      SID type indicating a local group or alias.
      See Also:
    • SID_TYPE_WKN_GRP

      public static final int SID_TYPE_WKN_GRP
      SID type indicating a well-known group.
      See Also:
    • SID_TYPE_DELETED

      public static final int SID_TYPE_DELETED
      SID type indicating a deleted account.
      See Also:
    • SID_TYPE_INVALID

      public static final int SID_TYPE_INVALID
      SID type indicating an invalid SID.
      See Also:
    • SID_TYPE_UNKNOWN

      public static final int SID_TYPE_UNKNOWN
      SID type indicating an unknown account type.
      See Also:
    • SID_FLAG_RESOLVE_SIDS

      public static final int SID_FLAG_RESOLVE_SIDS
      Flag indicating that SIDs should be resolved to names.
      See Also:
    • EVERYONE

      public static SID EVERYONE
      Well known SID: EVERYONE (S-1-1-0).
    • CREATOR_OWNER

      public static SID CREATOR_OWNER
      Well known SID: CREATOR_OWNER (S-1-3-0).
    • SYSTEM

      public static SID SYSTEM
      Well known SID: SYSTEM (S-1-5-18).
  • Constructor Details

    • SID

      public SID(byte[] src, int si)
      Construct a SID from it's binary representation.
      Parameters:
      src - the byte array containing the SID
      si - the starting index in the array
    • SID

      public SID(String textual) throws SmbException
      Construct a SID from it's textual representation such as S-1-5-21-1496946806-2192648263-3843101252-1029.
      Parameters:
      textual - the textual representation of the SID
      Throws:
      SmbException - if the textual format is invalid
    • SID

      public SID(SID domsid, int rid)
      Construct a SID from a domain SID and an RID (relative identifier).
      Parameters:
      domsid - the domain SID
      rid - the relative identifier
    • SID

      public SID(rpc.sid_t sid, int type, String domainName, String acctName, boolean decrementAuthority)
      Constructs a SID from an RPC sid_t structure.
      Parameters:
      sid - the RPC sid_t structure
      type - the SID type
      domainName - the domain name for this SID
      acctName - the account name for this SID
      decrementAuthority - whether to decrement the authority count
  • Method Details

    • resolveSids

      public static void resolveSids(String authorityServerName, NtlmPasswordAuthentication auth, SID[] sids, int offset, int length) throws IOException
      Resolves an array of SIDs to obtain their account and domain names.
      Parameters:
      authorityServerName - the server to use for SID resolution
      auth - the authentication credentials to use
      sids - the array of SIDs to resolve
      offset - the starting offset in the array
      length - the number of SIDs to resolve
      Throws:
      IOException - if there is an error resolving the SIDs
    • resolveSids

      public static void resolveSids(String authorityServerName, NtlmPasswordAuthentication auth, SID[] sids) throws IOException
      Resolves an array of SIDs to obtain their account and domain names.
      Parameters:
      authorityServerName - the server to use for SID resolution
      auth - the authentication credentials to use
      sids - the array of SIDs to resolve
      Throws:
      IOException - if there is an error resolving the SIDs
    • getServerSid

      public static SID getServerSid(String server, NtlmPasswordAuthentication auth) throws IOException
      Gets the domain SID for the specified server.
      Parameters:
      server - the server name
      auth - the authentication credentials to use
      Returns:
      the domain SID for the server
      Throws:
      IOException - if there is an error retrieving the server SID
    • toByteArray

      public static byte[] toByteArray(rpc.sid_t sid)
      Converts an RPC sid_t structure to a byte array.
      Parameters:
      sid - the RPC sid_t structure to convert
      Returns:
      byte array representation of the SID
    • getDomainSid

      public SID getDomainSid()
      Gets the domain SID for this SID.
      Returns:
      domain SID
    • getRid

      public int getRid()
      Gets the RID (relative identifier) of this SID.
      Returns:
      the RID
    • getType

      public int getType()
      Gets the type of this SID.
      Returns:
      the SID type code
    • getTypeText

      public String getTypeText()
      Gets a textual representation of the SID type.
      Returns:
      textual representation of the SID type
    • getDomainName

      public String getDomainName()
      Gets the domain name for this SID.
      Returns:
      the domain name
    • getAccountName

      public String getAccountName()
      Gets the account name for this SID.
      Returns:
      the account name
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Return the numeric representation of this sid such as S-1-5-21-1496946806-2192648263-3843101252-1029.
      Overrides:
      toString in class Object
    • toDisplayString

      public String toDisplayString()
      Returns a string representation of this SID suitable for display to users.
      Returns:
      display string representation of the SID
    • resolve

      public void resolve(String authorityServerName, NtlmPasswordAuthentication auth) throws IOException
      Resolves this SID to obtain its account and domain names.
      Parameters:
      authorityServerName - the server to use for SID resolution
      auth - the authentication credentials to use
      Throws:
      IOException - if there is an error resolving the SID
    • getGroupMemberSids

      public SID[] getGroupMemberSids(String authorityServerName, NtlmPasswordAuthentication auth, int flags) throws IOException
      Gets the members of the group represented by this SID.
      Parameters:
      authorityServerName - the server to use for resolution
      auth - the authentication credentials to use
      flags - resolution flags
      Returns:
      array of SIDs representing group members
      Throws:
      IOException - if there is an error retrieving group members