Bugfix: Set the TEBF_WIN32 flag in teb.flags for 32-bit threads.
[wine/multimedia.git] / win32 / security.c
blob8b10607f629c69ec22f4bb606911a61a353b1d7a
1 #include <stdlib.h>
2 #include <string.h>
4 #include "windows.h"
5 #include "winerror.h"
6 #include "ntdll.h"
7 #include "debug.h"
9 BOOL32 WINAPI IsValidSid (LPSID pSid);
10 BOOL32 WINAPI EqualSid (LPSID pSid1, LPSID pSid2);
11 BOOL32 WINAPI EqualPrefixSid (LPSID pSid1, LPSID pSid2);
12 DWORD WINAPI GetSidLengthRequired (BYTE nSubAuthorityCount);
13 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);
14 VOID* WINAPI FreeSid(LPSID pSid);
15 BOOL32 WINAPI InitializeSid (LPSID pSid, LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount);
16 LPSID_IDENTIFIER_AUTHORITY WINAPI GetSidIdentifierAuthority(LPSID pSid);
17 DWORD* WINAPI GetSidSubAuthority(LPSID pSid, DWORD nSubAuthority);
18 BYTE* WINAPI GetSidSubAuthorityCount(LPSID pSid);
19 DWORD WINAPI GetLengthSid(LPSID pSid);
20 BOOL32 WINAPI CopySid(DWORD nDestinationSidLength, LPSID pDestinationSid, LPSID pSourceSid);
22 /***********************************************************************
23 * IsValidSid (ADVAPI.80)
25 BOOL32 WINAPI IsValidSid (LPSID pSid) {
26 if (!pSid || pSid->Revision != SID_REVISION)
27 return FALSE;
29 return TRUE;
32 /***********************************************************************
33 * EqualSid (ADVAPI.40)
35 BOOL32 WINAPI EqualSid (LPSID pSid1, LPSID pSid2) {
36 if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
37 return FALSE;
39 if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
40 return FALSE;
42 if (memcmp(pSid1, pSid2, GetLengthSid(pSid1)) != 0)
43 return FALSE;
45 return TRUE;
48 /***********************************************************************
49 * EqualPrefixSid (ADVAPI.39)
51 BOOL32 WINAPI EqualPrefixSid (LPSID pSid1, LPSID pSid2) {
52 if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
53 return FALSE;
55 if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
56 return FALSE;
58 if (memcmp(pSid1, pSid2, GetSidLengthRequired(pSid1->SubAuthorityCount - 1))
59 != 0)
60 return FALSE;
62 return TRUE;
65 /***********************************************************************
66 * GetSidLengthRequired (ADVAPI.63)
68 DWORD WINAPI GetSidLengthRequired (BYTE nSubAuthorityCount) {
69 return sizeof (SID) + (nSubAuthorityCount - 1) * sizeof (DWORD);
72 /***********************************************************************
73 * AllocateAndInitializeSid (ADVAPI.11)
75 BOOL32 WINAPI AllocateAndInitializeSid(LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
76 BYTE nSubAuthorityCount,
77 DWORD nSubAuthority0, DWORD nSubAuthority1,
78 DWORD nSubAuthority2, DWORD nSubAuthority3,
79 DWORD nSubAuthority4, DWORD nSubAuthority5,
80 DWORD nSubAuthority6, DWORD nSubAuthority7,
81 LPSID *pSid) {
83 if (!(*pSid = HeapAlloc( GetProcessHeap(), 0,
84 GetSidLengthRequired(nSubAuthorityCount))))
85 return FALSE;
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;
109 return TRUE;
112 /***********************************************************************
113 * FreeSid (ADVAPI.42)
115 VOID* WINAPI FreeSid(LPSID pSid)
117 HeapFree( GetProcessHeap(), 0, pSid );
118 return NULL;
121 /***********************************************************************
122 * InitializeSecurityDescriptor (ADVAPI.73)
124 BOOL32 WINAPI InitializeSecurityDescriptor( SECURITY_DESCRIPTOR *pDescr,
125 DWORD revision )
127 FIXME(security, "(%p,%#lx): stub\n", pDescr, revision);
128 return TRUE;
132 /***********************************************************************
133 * InitializeSid (ADVAPI.74)
135 BOOL32 WINAPI InitializeSid (LPSID pSid, LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
136 BYTE nSubAuthorityCount)
138 int i;
140 pSid->Revision = SID_REVISION;
141 if (pIdentifierAuthority)
142 memcpy(&pSid->IdentifierAuthority, pIdentifierAuthority,
143 sizeof (SID_IDENTIFIER_AUTHORITY));
144 *GetSidSubAuthorityCount(pSid) = nSubAuthorityCount;
146 for (i = 0; i < nSubAuthorityCount; i++)
147 *GetSidSubAuthority(pSid, i) = 0;
149 return TRUE;
152 /***********************************************************************
153 * GetSidIdentifierAuthority (ADVAPI.62)
155 LPSID_IDENTIFIER_AUTHORITY WINAPI GetSidIdentifierAuthority (LPSID pSid)
157 return &pSid->IdentifierAuthority;
160 /***********************************************************************
161 * GetSidSubAuthority (ADVAPI.64)
163 DWORD * WINAPI GetSidSubAuthority (LPSID pSid, DWORD nSubAuthority)
165 return &pSid->SubAuthority[nSubAuthority];
168 /***********************************************************************
169 * GetSidSubAuthorityCount (ADVAPI.65)
171 BYTE * WINAPI GetSidSubAuthorityCount (LPSID pSid)
173 return &pSid->SubAuthorityCount;
176 /***********************************************************************
177 * GetLengthSid (ADVAPI.48)
179 DWORD WINAPI GetLengthSid (LPSID pSid)
181 return GetSidLengthRequired(*GetSidSubAuthorityCount(pSid));
184 /***********************************************************************
185 * CopySid (ADVAPI.24)
187 BOOL32 WINAPI CopySid (DWORD nDestinationSidLength, LPSID pDestinationSid,
188 LPSID pSourceSid)
191 if (!IsValidSid(pSourceSid))
192 return FALSE;
194 if (nDestinationSidLength < GetLengthSid(pSourceSid))
195 return FALSE;
197 memcpy(pDestinationSid, pSourceSid, GetLengthSid(pSourceSid));
199 return TRUE;
202 /***********************************************************************
203 * LookupAccountSidA [ADVAPI32.86]
205 BOOL32 WINAPI LookupAccountSid32A(LPCSTR system,PSID sid,
206 LPCSTR account,LPDWORD accountSize,
207 LPCSTR domain, LPDWORD domainSize,
208 PSID_NAME_USE name_use)
210 FIXME(security,"(%s,%p,%p,%p,%p,%p,%p): stub\n",
211 system,sid,account,accountSize,domain,domainSize,name_use);
212 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
213 return FALSE;
216 /***********************************************************************
217 * LookupAccountSidW [ADVAPI32.86]
219 BOOL32 WINAPI LookupAccountSid32W(LPCWSTR system,PSID sid,
220 LPCWSTR account,LPDWORD accountSize,
221 LPCWSTR domain, LPDWORD domainSize,
222 PSID_NAME_USE name_use)
224 FIXME(security,"(%p,%p,%p,%p,%p,%p,%p): stub\n",
225 system,sid,account,accountSize,domain,domainSize,name_use);
226 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
227 return FALSE;