New stubs PrivateExtractIconEx[AW], PrivateExtractIconsW,
[wine] / win32 / security.c
1 #include <stdlib.h>
2 #include <string.h>
3
4 #include "windows.h"
5 #include "winerror.h"
6 #include "ntdll.h"
7 #include "debug.h"
8
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);
21
22 /***********************************************************************
23  *           IsValidSid  (ADVAPI.80)
24  */
25 BOOL32 WINAPI IsValidSid (LPSID pSid) {
26     if (!pSid || pSid->Revision != SID_REVISION)
27         return FALSE;
28
29     return TRUE;
30 }
31
32 /***********************************************************************
33  *           EqualSid  (ADVAPI.40)
34  */
35 BOOL32 WINAPI EqualSid (LPSID pSid1, LPSID pSid2) {
36     if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
37         return FALSE;
38
39     if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
40         return FALSE;
41
42     if (memcmp(pSid1, pSid2, GetLengthSid(pSid1)) != 0)
43         return FALSE;
44
45     return TRUE;
46 }
47
48 /***********************************************************************
49  *           EqualPrefixSid  (ADVAPI.39)
50  */
51 BOOL32 WINAPI EqualPrefixSid (LPSID pSid1, LPSID pSid2) {
52     if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
53         return FALSE;
54
55     if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
56         return FALSE;
57
58     if (memcmp(pSid1, pSid2, GetSidLengthRequired(pSid1->SubAuthorityCount - 1))
59  != 0)
60         return FALSE;
61
62     return TRUE;
63 }
64
65 /***********************************************************************
66  *           GetSidLengthRequired  (ADVAPI.63)
67  */
68 DWORD WINAPI GetSidLengthRequired (BYTE nSubAuthorityCount) {
69     return sizeof (SID) + (nSubAuthorityCount - 1) * sizeof (DWORD);
70 }
71
72 /***********************************************************************
73  *           AllocateAndInitializeSid  (ADVAPI.11)
74  */
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) {
82
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;
91
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;
108
109     return TRUE;
110 }
111
112 /***********************************************************************
113  *           FreeSid  (ADVAPI.42)
114  */
115 VOID* WINAPI FreeSid(LPSID pSid)
116 {
117     HeapFree( GetProcessHeap(), 0, pSid );
118     return NULL;
119 }
120
121 /***********************************************************************
122  *           InitializeSecurityDescriptor  (ADVAPI.73)
123  */
124 BOOL32 WINAPI InitializeSecurityDescriptor( SECURITY_DESCRIPTOR *pDescr,
125                                             DWORD revision )
126 {
127     FIXME(security, "(%p,%#lx): stub\n", pDescr, revision);
128     return TRUE;
129 }
130
131
132 /***********************************************************************
133  *           InitializeSid  (ADVAPI.74)
134  */
135 BOOL32 WINAPI InitializeSid (LPSID pSid, LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
136                     BYTE nSubAuthorityCount)
137 {
138     int i;
139
140     pSid->Revision = SID_REVISION;
141     if (pIdentifierAuthority)
142         memcpy(&pSid->IdentifierAuthority, pIdentifierAuthority,
143                sizeof (SID_IDENTIFIER_AUTHORITY));
144     *GetSidSubAuthorityCount(pSid) = nSubAuthorityCount;
145
146     for (i = 0; i < nSubAuthorityCount; i++)
147         *GetSidSubAuthority(pSid, i) = 0;
148
149     return TRUE;
150 }
151
152 /***********************************************************************
153  *           GetSidIdentifierAuthority  (ADVAPI.62)
154  */
155 LPSID_IDENTIFIER_AUTHORITY WINAPI GetSidIdentifierAuthority (LPSID pSid)
156 {
157     return &pSid->IdentifierAuthority;
158 }
159
160 /***********************************************************************
161  *           GetSidSubAuthority  (ADVAPI.64)
162  */
163 DWORD * WINAPI GetSidSubAuthority (LPSID pSid, DWORD nSubAuthority)
164 {
165     return &pSid->SubAuthority[nSubAuthority];
166 }
167
168 /***********************************************************************
169  *           GetSidSubAuthorityCount  (ADVAPI.65)
170  */
171 BYTE * WINAPI GetSidSubAuthorityCount (LPSID pSid)
172 {
173     return &pSid->SubAuthorityCount;
174 }
175
176 /***********************************************************************
177  *           GetLengthSid  (ADVAPI.48)
178  */
179 DWORD WINAPI GetLengthSid (LPSID pSid)
180 {
181     return GetSidLengthRequired(*GetSidSubAuthorityCount(pSid));
182 }
183
184 /***********************************************************************
185  *           CopySid  (ADVAPI.24)
186  */
187 BOOL32 WINAPI CopySid (DWORD nDestinationSidLength, LPSID pDestinationSid,
188                        LPSID pSourceSid)
189 {
190
191     if (!IsValidSid(pSourceSid))
192         return FALSE;
193
194     if (nDestinationSidLength < GetLengthSid(pSourceSid))
195         return FALSE;
196
197     memcpy(pDestinationSid, pSourceSid, GetLengthSid(pSourceSid));
198
199     return TRUE;
200 }
201
202 /***********************************************************************
203  *           LookupAccountSidA   [ADVAPI32.86]
204  */
205 BOOL32 WINAPI LookupAccountSid32A(LPCSTR system,PSID sid,
206                                   LPCSTR account,LPDWORD accountSize,
207                                   LPCSTR domain, LPDWORD domainSize,
208                                   PSID_NAME_USE name_use)
209 {
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;
214 }
215
216 /***********************************************************************
217  *           LookupAccountSidW   [ADVAPI32.86]
218  */
219 BOOL32 WINAPI LookupAccountSid32W(LPCWSTR system,PSID sid,
220                                   LPCWSTR account,LPDWORD accountSize,
221                                   LPCWSTR domain, LPDWORD domainSize,
222                                   PSID_NAME_USE name_use)
223 {
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;
228 }
229