Release 980329
[wine/multimedia.git] / win32 / security.c
blobacfec874fdda190be03b2221369b556a4bc2a87a
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include "windows.h"
6 #include "winerror.h"
7 #include "ntdll.h"
8 #include "debug.h"
10 BOOL32 WINAPI IsValidSid (LPSID pSid);
11 BOOL32 WINAPI EqualSid (LPSID pSid1, LPSID pSid2);
12 BOOL32 WINAPI EqualPrefixSid (LPSID pSid1, LPSID pSid2);
13 DWORD WINAPI GetSidLengthRequired (BYTE nSubAuthorityCount);
14 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);
15 VOID* WINAPI FreeSid(LPSID pSid);
16 BOOL32 WINAPI InitializeSid (LPSID pSid, LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount);
17 LPSID_IDENTIFIER_AUTHORITY WINAPI GetSidIdentifierAuthority(LPSID pSid);
18 DWORD* WINAPI GetSidSubAuthority(LPSID pSid, DWORD nSubAuthority);
19 BYTE* WINAPI GetSidSubAuthorityCount(LPSID pSid);
20 DWORD WINAPI GetLengthSid(LPSID pSid);
21 BOOL32 WINAPI CopySid(DWORD nDestinationSidLength, LPSID pDestinationSid, LPSID pSourceSid);
23 /***********************************************************************
24 * IsValidSid (ADVAPI.80)
26 BOOL32 WINAPI IsValidSid (LPSID pSid) {
27 if (!pSid || pSid->Revision != SID_REVISION)
28 return FALSE;
30 return TRUE;
33 /***********************************************************************
34 * EqualSid (ADVAPI.40)
36 BOOL32 WINAPI EqualSid (LPSID pSid1, LPSID pSid2) {
37 if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
38 return FALSE;
40 if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
41 return FALSE;
43 if (memcmp(pSid1, pSid2, GetLengthSid(pSid1)) != 0)
44 return FALSE;
46 return TRUE;
49 /***********************************************************************
50 * EqualPrefixSid (ADVAPI.39)
52 BOOL32 WINAPI EqualPrefixSid (LPSID pSid1, LPSID pSid2) {
53 if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
54 return FALSE;
56 if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
57 return FALSE;
59 if (memcmp(pSid1, pSid2, GetSidLengthRequired(pSid1->SubAuthorityCount - 1))
60 != 0)
61 return FALSE;
63 return TRUE;
66 /***********************************************************************
67 * GetSidLengthRequired (ADVAPI.63)
69 DWORD WINAPI GetSidLengthRequired (BYTE nSubAuthorityCount) {
70 return sizeof (SID) + (nSubAuthorityCount - 1 * sizeof (DWORD));
73 /***********************************************************************
74 * AllocateAndInitializeSid (ADVAPI.11)
76 BOOL32 WINAPI AllocateAndInitializeSid(LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
77 BYTE nSubAuthorityCount,
78 DWORD nSubAuthority0, DWORD nSubAuthority1,
79 DWORD nSubAuthority2, DWORD nSubAuthority3,
80 DWORD nSubAuthority4, DWORD nSubAuthority5,
81 DWORD nSubAuthority6, DWORD nSubAuthority7,
82 LPSID *pSid) {
84 if (!(*pSid = HeapAlloc( GetProcessHeap(), 0,
85 GetSidLengthRequired(nSubAuthorityCount))))
86 return FALSE;
87 (*pSid)->Revision = SID_REVISION;
88 if (pIdentifierAuthority)
89 memcpy(&(*pSid)->IdentifierAuthority, pIdentifierAuthority,
90 sizeof (SID_IDENTIFIER_AUTHORITY));
91 *GetSidSubAuthorityCount(*pSid) = nSubAuthorityCount;
93 if (nSubAuthorityCount > 0)
94 *GetSidSubAuthority(*pSid, 0) = nSubAuthority0;
95 if (nSubAuthorityCount > 1)
96 *GetSidSubAuthority(*pSid, 1) = nSubAuthority1;
97 if (nSubAuthorityCount > 2)
98 *GetSidSubAuthority(*pSid, 2) = nSubAuthority2;
99 if (nSubAuthorityCount > 3)
100 *GetSidSubAuthority(*pSid, 3) = nSubAuthority3;
101 if (nSubAuthorityCount > 4)
102 *GetSidSubAuthority(*pSid, 4) = nSubAuthority4;
103 if (nSubAuthorityCount > 5)
104 *GetSidSubAuthority(*pSid, 5) = nSubAuthority5;
105 if (nSubAuthorityCount > 6)
106 *GetSidSubAuthority(*pSid, 6) = nSubAuthority6;
107 if (nSubAuthorityCount > 7)
108 *GetSidSubAuthority(*pSid, 7) = nSubAuthority7;
110 return TRUE;
113 /***********************************************************************
114 * FreeSid (ADVAPI.42)
116 VOID* WINAPI FreeSid(LPSID pSid)
118 HeapFree( GetProcessHeap(), 0, pSid );
119 return NULL;
122 /***********************************************************************
123 * InitializeSecurityDescriptor (ADVAPI.73)
125 BOOL32 WINAPI InitializeSecurityDescriptor( SECURITY_DESCRIPTOR *pDescr,
126 DWORD revision )
128 FIXME(security, "(%p,%#lx): empty stub\n", pDescr, revision);
129 return TRUE;
133 /***********************************************************************
134 * InitializeSid (ADVAPI.74)
136 BOOL32 WINAPI InitializeSid (LPSID pSid, LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
137 BYTE nSubAuthorityCount)
139 int i;
141 pSid->Revision = SID_REVISION;
142 if (pIdentifierAuthority)
143 memcpy(&pSid->IdentifierAuthority, pIdentifierAuthority,
144 sizeof (SID_IDENTIFIER_AUTHORITY));
145 *GetSidSubAuthorityCount(pSid) = nSubAuthorityCount;
147 for (i = 0; i < nSubAuthorityCount; i++)
148 *GetSidSubAuthority(pSid, i) = 0;
150 return TRUE;
153 /***********************************************************************
154 * GetSidIdentifierAuthority (ADVAPI.62)
156 LPSID_IDENTIFIER_AUTHORITY WINAPI GetSidIdentifierAuthority (LPSID pSid)
158 return &pSid->IdentifierAuthority;
161 /***********************************************************************
162 * GetSidSubAuthority (ADVAPI.64)
164 DWORD * WINAPI GetSidSubAuthority (LPSID pSid, DWORD nSubAuthority)
166 return &pSid->SubAuthority[nSubAuthority];
169 /***********************************************************************
170 * GetSidSubAuthorityCount (ADVAPI.65)
172 BYTE * WINAPI GetSidSubAuthorityCount (LPSID pSid)
174 return &pSid->SubAuthorityCount;
177 /***********************************************************************
178 * GetLengthSid (ADVAPI.48)
180 DWORD WINAPI GetLengthSid (LPSID pSid)
182 return GetSidLengthRequired(*GetSidSubAuthorityCount(pSid));
185 /***********************************************************************
186 * CopySid (ADVAPI.24)
188 BOOL32 WINAPI CopySid (DWORD nDestinationSidLength, LPSID pDestinationSid,
189 LPSID pSourceSid)
192 if (!IsValidSid(pSourceSid))
193 return FALSE;
195 if (nDestinationSidLength < GetLengthSid(pSourceSid))
196 return FALSE;
198 memcpy(pDestinationSid, pSourceSid, GetLengthSid(pSourceSid));
200 return TRUE;
203 /***********************************************************************
204 * LookupAccountSidA [ADVAPI32.86]
206 BOOL32 WINAPI LookupAccountSid32A(LPCSTR system,PSID sid,
207 LPCSTR account,LPDWORD accountSize,
208 LPCSTR domain, LPDWORD domainSize,
209 PSID_NAME_USE name_use)
211 FIXME(security,"(%s,%p,%p,%p,%p,%p,%p): stub\n",
212 system,sid,account,accountSize,domain,domainSize,name_use);
213 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
214 return FALSE;
217 /***********************************************************************
218 * LookupAccountSidW [ADVAPI32.86]
220 BOOL32 WINAPI LookupAccountSid32W(LPCWSTR system,PSID sid,
221 LPCWSTR account,LPDWORD accountSize,
222 LPCWSTR domain, LPDWORD domainSize,
223 PSID_NAME_USE name_use)
225 FIXME(security,"(%p,%p,%p,%p,%p,%p,%p): stub\n",
226 system,sid,account,accountSize,domain,domainSize,name_use);
227 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
228 return FALSE;