11 BOOL32 WINAPI IsValidSid (LPSID pSid);
12 BOOL32 WINAPI EqualSid (LPSID pSid1, LPSID pSid2);
13 BOOL32 WINAPI EqualPrefixSid (LPSID pSid1, LPSID pSid2);
14 DWORD WINAPI GetSidLengthRequired (BYTE nSubAuthorityCount);
15 BOOL32 WINAPI AllocateAndInitializeSid(LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount, DWORD nSubAuthority0, DWORD nSubAuthority1, DWORD nSubAuthority2, DWORD nSubAuthority3, DWORD nSubAuthority4, DWORD nSubAuthority5, DWORD nSubAuthority6, DWORD nSubAuthority7, LPSID *pSid);
16 VOID* WINAPI FreeSid(LPSID pSid);
17 BOOL32 WINAPI InitializeSid (LPSID pSid, LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount);
18 LPSID_IDENTIFIER_AUTHORITY WINAPI GetSidIdentifierAuthority(LPSID pSid);
19 DWORD* WINAPI GetSidSubAuthority(LPSID pSid, DWORD nSubAuthority);
20 BYTE* WINAPI GetSidSubAuthorityCount(LPSID pSid);
21 DWORD WINAPI GetLengthSid(LPSID pSid);
22 BOOL32 WINAPI CopySid(DWORD nDestinationSidLength, LPSID pDestinationSid, LPSID pSourceSid);
24 /***********************************************************************
25 * IsValidSid (ADVAPI.80)
27 BOOL32 WINAPI IsValidSid (LPSID pSid) {
28 if (!pSid || pSid->Revision != SID_REVISION)
34 /***********************************************************************
35 * EqualSid (ADVAPI.40)
37 BOOL32 WINAPI EqualSid (LPSID pSid1, LPSID pSid2) {
38 if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
41 if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
44 if (memcmp(pSid1, pSid2, GetLengthSid(pSid1)) != 0)
50 /***********************************************************************
51 * EqualPrefixSid (ADVAPI.39)
53 BOOL32 WINAPI EqualPrefixSid (LPSID pSid1, LPSID pSid2) {
54 if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
57 if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
60 if (memcmp(pSid1, pSid2, GetSidLengthRequired(pSid1->SubAuthorityCount - 1))
67 /***********************************************************************
68 * GetSidLengthRequired (ADVAPI.63)
70 DWORD WINAPI GetSidLengthRequired (BYTE nSubAuthorityCount) {
71 return sizeof (SID) + (nSubAuthorityCount - 1 * sizeof (DWORD));
74 /***********************************************************************
75 * AllocateAndInitializeSid (ADVAPI.11)
77 BOOL32 WINAPI AllocateAndInitializeSid(LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
78 BYTE nSubAuthorityCount,
79 DWORD nSubAuthority0, DWORD nSubAuthority1,
80 DWORD nSubAuthority2, DWORD nSubAuthority3,
81 DWORD nSubAuthority4, DWORD nSubAuthority5,
82 DWORD nSubAuthority6, DWORD nSubAuthority7,
85 *pSid = xmalloc(GetSidLengthRequired(nSubAuthorityCount));
86 (*pSid)->Revision = SID_REVISION;
87 if (pIdentifierAuthority)
88 memcpy(&(*pSid)->IdentifierAuthority, pIdentifierAuthority,
89 sizeof (SID_IDENTIFIER_AUTHORITY));
90 *GetSidSubAuthorityCount(*pSid) = nSubAuthorityCount;
92 if (nSubAuthorityCount > 0)
93 *GetSidSubAuthority(*pSid, 0) = nSubAuthority0;
94 if (nSubAuthorityCount > 1)
95 *GetSidSubAuthority(*pSid, 1) = nSubAuthority1;
96 if (nSubAuthorityCount > 2)
97 *GetSidSubAuthority(*pSid, 2) = nSubAuthority2;
98 if (nSubAuthorityCount > 3)
99 *GetSidSubAuthority(*pSid, 3) = nSubAuthority3;
100 if (nSubAuthorityCount > 4)
101 *GetSidSubAuthority(*pSid, 4) = nSubAuthority4;
102 if (nSubAuthorityCount > 5)
103 *GetSidSubAuthority(*pSid, 5) = nSubAuthority5;
104 if (nSubAuthorityCount > 6)
105 *GetSidSubAuthority(*pSid, 6) = nSubAuthority6;
106 if (nSubAuthorityCount > 7)
107 *GetSidSubAuthority(*pSid, 7) = nSubAuthority7;
112 /***********************************************************************
113 * FreeSid (ADVAPI.42)
115 VOID* WINAPI FreeSid(LPSID pSid) {
120 /***********************************************************************
121 * InitializeSid (ADVAPI.74)
123 BOOL32 WINAPI InitializeSid (LPSID pSid, LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
124 BYTE nSubAuthorityCount)
128 pSid->Revision = SID_REVISION;
129 if (pIdentifierAuthority)
130 memcpy(&pSid->IdentifierAuthority, pIdentifierAuthority,
131 sizeof (SID_IDENTIFIER_AUTHORITY));
132 *GetSidSubAuthorityCount(pSid) = nSubAuthorityCount;
134 for (i = 0; i < nSubAuthorityCount; i++)
135 *GetSidSubAuthority(pSid, i) = 0;
140 /***********************************************************************
141 * GetSidIdentifierAuthority (ADVAPI.62)
143 LPSID_IDENTIFIER_AUTHORITY WINAPI GetSidIdentifierAuthority (LPSID pSid)
145 return &pSid->IdentifierAuthority;
148 /***********************************************************************
149 * GetSidSubAuthority (ADVAPI.64)
151 DWORD * WINAPI GetSidSubAuthority (LPSID pSid, DWORD nSubAuthority)
153 return &pSid->SubAuthority[nSubAuthority];
156 /***********************************************************************
157 * GetSidSubAuthorityCount (ADVAPI.65)
159 BYTE * WINAPI GetSidSubAuthorityCount (LPSID pSid)
161 return &pSid->SubAuthorityCount;
164 /***********************************************************************
165 * GetLengthSid (ADVAPI.48)
167 DWORD WINAPI GetLengthSid (LPSID pSid)
169 return GetSidLengthRequired(*GetSidSubAuthorityCount(pSid));
172 /***********************************************************************
173 * CopySid (ADVAPI.24)
175 BOOL32 WINAPI CopySid (DWORD nDestinationSidLength, LPSID pDestinationSid,
179 if (!IsValidSid(pSourceSid))
182 if (nDestinationSidLength < GetLengthSid(pSourceSid))
185 memcpy(pDestinationSid, pSourceSid, GetLengthSid(pSourceSid));