2 * Copyright 1999, 2000 Juergen Schmied <juergen.schmied@debitel.net>
3 * Copyright 2003 CodeWeavers Inc. (Ulrich Czekalla)
4 * Copyright 2006 Robert Reif
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define WIN32_NO_STATUS
40 #include "advapi32_misc.h"
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
47 static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes);
48 static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags,
49 PACL pAcl, LPDWORD cBytes);
50 static BYTE ParseAceStringFlags(LPCWSTR* StringAcl);
51 static BYTE ParseAceStringType(LPCWSTR* StringAcl);
52 static DWORD ParseAceStringRights(LPCWSTR* StringAcl);
53 static BOOL ParseStringSecurityDescriptorToSecurityDescriptor(
54 LPCWSTR StringSecurityDescriptor,
55 SECURITY_DESCRIPTOR* SecurityDescriptor,
57 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl);
59 typedef struct _ACEFLAG
63 } ACEFLAG, *LPACEFLAG;
65 typedef struct _MAX_SID
67 /* same fields as struct _SID */
69 BYTE SubAuthorityCount;
70 SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
71 DWORD SubAuthority[SID_MAX_SUB_AUTHORITIES];
74 typedef struct WELLKNOWNSID
77 WELL_KNOWN_SID_TYPE Type;
81 static const WELLKNOWNSID WellKnownSids[] =
83 { {0,0}, WinNullSid, { SID_REVISION, 1, { SECURITY_NULL_SID_AUTHORITY }, { SECURITY_NULL_RID } } },
84 { {'W','D'}, WinWorldSid, { SID_REVISION, 1, { SECURITY_WORLD_SID_AUTHORITY }, { SECURITY_WORLD_RID } } },
85 { {0,0}, WinLocalSid, { SID_REVISION, 1, { SECURITY_LOCAL_SID_AUTHORITY }, { SECURITY_LOCAL_RID } } },
86 { {'C','O'}, WinCreatorOwnerSid, { SID_REVISION, 1, { SECURITY_CREATOR_SID_AUTHORITY }, { SECURITY_CREATOR_OWNER_RID } } },
87 { {'C','G'}, WinCreatorGroupSid, { SID_REVISION, 1, { SECURITY_CREATOR_SID_AUTHORITY }, { SECURITY_CREATOR_GROUP_RID } } },
88 { {0,0}, WinCreatorOwnerServerSid, { SID_REVISION, 1, { SECURITY_CREATOR_SID_AUTHORITY }, { SECURITY_CREATOR_OWNER_SERVER_RID } } },
89 { {0,0}, WinCreatorGroupServerSid, { SID_REVISION, 1, { SECURITY_CREATOR_SID_AUTHORITY }, { SECURITY_CREATOR_GROUP_SERVER_RID } } },
90 { {0,0}, WinNtAuthoritySid, { SID_REVISION, 0, { SECURITY_NT_AUTHORITY }, { SECURITY_NULL_RID } } },
91 { {0,0}, WinDialupSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_DIALUP_RID } } },
92 { {'N','U'}, WinNetworkSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_NETWORK_RID } } },
93 { {0,0}, WinBatchSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_BATCH_RID } } },
94 { {'I','U'}, WinInteractiveSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_INTERACTIVE_RID } } },
95 { {'S','U'}, WinServiceSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_SERVICE_RID } } },
96 { {'A','N'}, WinAnonymousSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_ANONYMOUS_LOGON_RID } } },
97 { {0,0}, WinProxySid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_PROXY_RID } } },
98 { {'E','D'}, WinEnterpriseControllersSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_ENTERPRISE_CONTROLLERS_RID } } },
99 { {'P','S'}, WinSelfSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_PRINCIPAL_SELF_RID } } },
100 { {'A','U'}, WinAuthenticatedUserSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_AUTHENTICATED_USER_RID } } },
101 { {'R','C'}, WinRestrictedCodeSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_RESTRICTED_CODE_RID } } },
102 { {0,0}, WinTerminalServerSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_TERMINAL_SERVER_RID } } },
103 { {0,0}, WinRemoteLogonIdSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_REMOTE_LOGON_RID } } },
104 { {'S','Y'}, WinLocalSystemSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_LOCAL_SYSTEM_RID } } },
105 { {'L','S'}, WinLocalServiceSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_LOCAL_SERVICE_RID } } },
106 { {'N','S'}, WinNetworkServiceSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_NETWORK_SERVICE_RID } } },
107 { {0,0}, WinBuiltinDomainSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID } } },
108 { {'B','A'}, WinBuiltinAdministratorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS } } },
109 { {'B','U'}, WinBuiltinUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_USERS } } },
110 { {'B','G'}, WinBuiltinGuestsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_GUESTS } } },
111 { {'P','U'}, WinBuiltinPowerUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS } } },
112 { {'A','O'}, WinBuiltinAccountOperatorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ACCOUNT_OPS } } },
113 { {'S','O'}, WinBuiltinSystemOperatorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_SYSTEM_OPS } } },
114 { {'P','O'}, WinBuiltinPrintOperatorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_PRINT_OPS } } },
115 { {'B','O'}, WinBuiltinBackupOperatorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_BACKUP_OPS } } },
116 { {'R','E'}, WinBuiltinReplicatorSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_REPLICATOR } } },
117 { {'R','U'}, WinBuiltinPreWindows2000CompatibleAccessSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_PREW2KCOMPACCESS } } },
118 { {'R','D'}, WinBuiltinRemoteDesktopUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS } } },
119 { {'N','O'}, WinBuiltinNetworkConfigurationOperatorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS } } },
120 { {0,0}, WinNTLMAuthenticationSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_PACKAGE_BASE_RID, SECURITY_PACKAGE_NTLM_RID } } },
121 { {0,0}, WinDigestAuthenticationSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_PACKAGE_BASE_RID, SECURITY_PACKAGE_DIGEST_RID } } },
122 { {0,0}, WinSChannelAuthenticationSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_PACKAGE_BASE_RID, SECURITY_PACKAGE_SCHANNEL_RID } } },
123 { {0,0}, WinThisOrganizationSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_THIS_ORGANIZATION_RID } } },
124 { {0,0}, WinOtherOrganizationSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_OTHER_ORGANIZATION_RID } } },
125 { {0,0}, WinBuiltinPerfMonitoringUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_MONITORING_USERS } } },
126 { {0,0}, WinBuiltinPerfLoggingUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_LOGGING_USERS } } },
129 static SID const sidWorld = { SID_REVISION, 1, { SECURITY_WORLD_SID_AUTHORITY} , { SECURITY_WORLD_RID } };
131 typedef struct _AccountSid {
132 WELL_KNOWN_SID_TYPE type;
135 SID_NAME_USE name_use;
138 static const WCHAR Account_Operators[] = { 'A','c','c','o','u','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
139 static const WCHAR Administrator[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0 };
140 static const WCHAR Administrators[] = { 'A','d','m','i','n','i','s','t','r','a','t','o','r','s',0 };
141 static const WCHAR ANONYMOUS_LOGON[] = { 'A','N','O','N','Y','M','O','U','S',' ','L','O','G','O','N',0 };
142 static const WCHAR Authenticated_Users[] = { 'A','u','t','h','e','n','t','i','c','a','t','e','d',' ','U','s','e','r','s',0 };
143 static const WCHAR Backup_Operators[] = { 'B','a','c','k','u','p',' ','O','p','e','r','a','t','o','r','s',0 };
144 static const WCHAR BATCH[] = { 'B','A','T','C','H',0 };
145 static const WCHAR Blank[] = { 0 };
146 static const WCHAR BUILTIN[] = { 'B','U','I','L','T','I','N',0 };
147 static const WCHAR Cert_Publishers[] = { 'C','e','r','t',' ','P','u','b','l','i','s','h','e','r','s',0 };
148 static const WCHAR CREATOR_GROUP[] = { 'C','R','E','A','T','O','R',' ','G','R','O','U','P',0 };
149 static const WCHAR CREATOR_GROUP_SERVER[] = { 'C','R','E','A','T','O','R',' ','G','R','O','U','P',' ','S','E','R','V','E','R',0 };
150 static const WCHAR CREATOR_OWNER[] = { 'C','R','E','A','T','O','R',' ','O','W','N','E','R',0 };
151 static const WCHAR CREATOR_OWNER_SERVER[] = { 'C','R','E','A','T','O','R',' ','O','W','N','E','R',' ','S','E','R','V','E','R',0 };
152 static const WCHAR DIALUP[] = { 'D','I','A','L','U','P',0 };
153 static const WCHAR Digest_Authentication[] = { 'D','i','g','e','s','t',' ','A','u','t','h','e','n','t','i','c','a','t','i','o','n',0 };
154 static const WCHAR DOMAIN[] = {'D','O','M','A','I','N',0};
155 static const WCHAR Domain_Admins[] = { 'D','o','m','a','i','n',' ','A','d','m','i','n','s',0 };
156 static const WCHAR Domain_Computers[] = { 'D','o','m','a','i','n',' ','C','o','m','p','u','t','e','r','s',0 };
157 static const WCHAR Domain_Controllers[] = { 'D','o','m','a','i','n',' ','C','o','n','t','r','o','l','l','e','r','s',0 };
158 static const WCHAR Domain_Guests[] = { 'D','o','m','a','i','n',' ','G','u','e','s','t','s',0 };
159 static const WCHAR Domain_Users[] = { 'D','o','m','a','i','n',' ','U','s','e','r','s',0 };
160 static const WCHAR Enterprise_Admins[] = { 'E','n','t','e','r','p','r','i','s','e',' ','A','d','m','i','n','s',0 };
161 static const WCHAR ENTERPRISE_DOMAIN_CONTROLLERS[] = { 'E','N','T','E','R','P','R','I','S','E',' ','D','O','M','A','I','N',' ','C','O','N','T','R','O','L','L','E','R','S',0 };
162 static const WCHAR Everyone[] = { 'E','v','e','r','y','o','n','e',0 };
163 static const WCHAR Group_Policy_Creator_Owners[] = { 'G','r','o','u','p',' ','P','o','l','i','c','y',' ','C','r','e','a','t','o','r',' ','O','w','n','e','r','s',0 };
164 static const WCHAR Guest[] = { 'G','u','e','s','t',0 };
165 static const WCHAR Guests[] = { 'G','u','e','s','t','s',0 };
166 static const WCHAR INTERACTIVE[] = { 'I','N','T','E','R','A','C','T','I','V','E',0 };
167 static const WCHAR LOCAL[] = { 'L','O','C','A','L',0 };
168 static const WCHAR LOCAL_SERVICE[] = { 'L','O','C','A','L',' ','S','E','R','V','I','C','E',0 };
169 static const WCHAR NETWORK[] = { 'N','E','T','W','O','R','K',0 };
170 static const WCHAR Network_Configuration_Operators[] = { 'N','e','t','w','o','r','k',' ','C','o','n','f','i','g','u','r','a','t','i','o','n',' ','O','p','e','r','a','t','o','r','s',0 };
171 static const WCHAR NETWORK_SERVICE[] = { 'N','E','T','W','O','R','K',' ','S','E','R','V','I','C','E',0 };
172 static const WCHAR NT_AUTHORITY[] = { 'N','T',' ','A','U','T','H','O','R','I','T','Y',0 };
173 static const WCHAR NT_Pseudo_Domain[] = { 'N','T',' ','P','s','e','u','d','o',' ','D','o','m','a','i','n',0 };
174 static const WCHAR NTML_Authentication[] = { 'N','T','M','L',' ','A','u','t','h','e','n','t','i','c','a','t','i','o','n',0 };
175 static const WCHAR NULL_SID[] = { 'N','U','L','L',' ','S','I','D',0 };
176 static const WCHAR Other_Organization[] = { 'O','t','h','e','r',' ','O','r','g','a','n','i','z','a','t','i','o','n',0 };
177 static const WCHAR Performance_Log_Users[] = { 'P','e','r','f','o','r','m','a','n','c','e',' ','L','o','g',' ','U','s','e','r','s',0 };
178 static const WCHAR Performance_Monitor_Users[] = { 'P','e','r','f','o','r','m','a','n','c','e',' ','M','o','n','i','t','o','r',' ','U','s','e','r','s',0 };
179 static const WCHAR Power_Users[] = { 'P','o','w','e','r',' ','U','s','e','r','s',0 };
180 static const WCHAR Pre_Windows_2000_Compatible_Access[] = { 'P','r','e','-','W','i','n','d','o','w','s',' ','2','0','0','0',' ','C','o','m','p','a','t','i','b','l','e',' ','A','c','c','e','s','s',0 };
181 static const WCHAR Print_Operators[] = { 'P','r','i','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
182 static const WCHAR PROXY[] = { 'P','R','O','X','Y',0 };
183 static const WCHAR RAS_and_IAS_Servers[] = { 'R','A','S',' ','a','n','d',' ','I','A','S',' ','S','e','r','v','e','r','s',0 };
184 static const WCHAR Remote_Desktop_Users[] = { 'R','e','m','o','t','e',' ','D','e','s','k','t','o','p',' ','U','s','e','r','s',0 };
185 static const WCHAR REMOTE_INTERACTIVE_LOGON[] = { 'R','E','M','O','T','E',' ','I','N','T','E','R','A','C','T','I','V','E',' ','L','O','G','O','N',0 };
186 static const WCHAR Replicators[] = { 'R','e','p','l','i','c','a','t','o','r','s',0 };
187 static const WCHAR RESTRICTED[] = { 'R','E','S','T','R','I','C','T','E','D',0 };
188 static const WCHAR SChannel_Authentication[] = { 'S','C','h','a','n','n','e','l',' ','A','u','t','h','e','n','t','i','c','a','t','i','o','n',0 };
189 static const WCHAR Schema_Admins[] = { 'S','c','h','e','m','a',' ','A','d','m','i','n','s',0 };
190 static const WCHAR SELF[] = { 'S','E','L','F',0 };
191 static const WCHAR Server_Operators[] = { 'S','e','r','v','e','r',' ','O','p','e','r','a','t','o','r','s',0 };
192 static const WCHAR SERVICE[] = { 'S','E','R','V','I','C','E',0 };
193 static const WCHAR SYSTEM[] = { 'S','Y','S','T','E','M',0 };
194 static const WCHAR TERMINAL_SERVER_USER[] = { 'T','E','R','M','I','N','A','L',' ','S','E','R','V','E','R',' ','U','S','E','R',0 };
195 static const WCHAR This_Organization[] = { 'T','h','i','s',' ','O','r','g','a','n','i','z','a','t','i','o','n',0 };
196 static const WCHAR Users[] = { 'U','s','e','r','s',0 };
198 static const AccountSid ACCOUNT_SIDS[] = {
199 { WinNullSid, NULL_SID, Blank, SidTypeWellKnownGroup },
200 { WinWorldSid, Everyone, Blank, SidTypeWellKnownGroup },
201 { WinLocalSid, LOCAL, Blank, SidTypeWellKnownGroup },
202 { WinCreatorOwnerSid, CREATOR_OWNER, Blank, SidTypeWellKnownGroup },
203 { WinCreatorGroupSid, CREATOR_GROUP, Blank, SidTypeWellKnownGroup },
204 { WinCreatorOwnerServerSid, CREATOR_OWNER_SERVER, Blank, SidTypeWellKnownGroup },
205 { WinCreatorGroupServerSid, CREATOR_GROUP_SERVER, Blank, SidTypeWellKnownGroup },
206 { WinNtAuthoritySid, NT_Pseudo_Domain, NT_Pseudo_Domain, SidTypeDomain },
207 { WinDialupSid, DIALUP, NT_AUTHORITY, SidTypeWellKnownGroup },
208 { WinNetworkSid, NETWORK, NT_AUTHORITY, SidTypeWellKnownGroup },
209 { WinBatchSid, BATCH, NT_AUTHORITY, SidTypeWellKnownGroup },
210 { WinInteractiveSid, INTERACTIVE, NT_AUTHORITY, SidTypeWellKnownGroup },
211 { WinServiceSid, SERVICE, NT_AUTHORITY, SidTypeWellKnownGroup },
212 { WinAnonymousSid, ANONYMOUS_LOGON, NT_AUTHORITY, SidTypeWellKnownGroup },
213 { WinProxySid, PROXY, NT_AUTHORITY, SidTypeWellKnownGroup },
214 { WinEnterpriseControllersSid, ENTERPRISE_DOMAIN_CONTROLLERS, NT_AUTHORITY, SidTypeWellKnownGroup },
215 { WinSelfSid, SELF, NT_AUTHORITY, SidTypeWellKnownGroup },
216 { WinAuthenticatedUserSid, Authenticated_Users, NT_AUTHORITY, SidTypeWellKnownGroup },
217 { WinRestrictedCodeSid, RESTRICTED, NT_AUTHORITY, SidTypeWellKnownGroup },
218 { WinTerminalServerSid, TERMINAL_SERVER_USER, NT_AUTHORITY, SidTypeWellKnownGroup },
219 { WinRemoteLogonIdSid, REMOTE_INTERACTIVE_LOGON, NT_AUTHORITY, SidTypeWellKnownGroup },
220 { WinLocalSystemSid, SYSTEM, NT_AUTHORITY, SidTypeWellKnownGroup },
221 { WinLocalServiceSid, LOCAL_SERVICE, NT_AUTHORITY, SidTypeWellKnownGroup },
222 { WinNetworkServiceSid, NETWORK_SERVICE, NT_AUTHORITY, SidTypeWellKnownGroup },
223 { WinBuiltinDomainSid, BUILTIN, BUILTIN, SidTypeDomain },
224 { WinBuiltinAdministratorsSid, Administrators, BUILTIN, SidTypeAlias },
225 { WinBuiltinUsersSid, Users, BUILTIN, SidTypeAlias },
226 { WinBuiltinGuestsSid, Guests, BUILTIN, SidTypeAlias },
227 { WinBuiltinPowerUsersSid, Power_Users, BUILTIN, SidTypeAlias },
228 { WinBuiltinAccountOperatorsSid, Account_Operators, BUILTIN, SidTypeAlias },
229 { WinBuiltinSystemOperatorsSid, Server_Operators, BUILTIN, SidTypeAlias },
230 { WinBuiltinPrintOperatorsSid, Print_Operators, BUILTIN, SidTypeAlias },
231 { WinBuiltinBackupOperatorsSid, Backup_Operators, BUILTIN, SidTypeAlias },
232 { WinBuiltinReplicatorSid, Replicators, BUILTIN, SidTypeAlias },
233 { WinBuiltinPreWindows2000CompatibleAccessSid, Pre_Windows_2000_Compatible_Access, BUILTIN, SidTypeAlias },
234 { WinBuiltinRemoteDesktopUsersSid, Remote_Desktop_Users, BUILTIN, SidTypeAlias },
235 { WinBuiltinNetworkConfigurationOperatorsSid, Network_Configuration_Operators, BUILTIN, SidTypeAlias },
236 { WinNTLMAuthenticationSid, NTML_Authentication, NT_AUTHORITY, SidTypeWellKnownGroup },
237 { WinDigestAuthenticationSid, Digest_Authentication, NT_AUTHORITY, SidTypeWellKnownGroup },
238 { WinSChannelAuthenticationSid, SChannel_Authentication, NT_AUTHORITY, SidTypeWellKnownGroup },
239 { WinThisOrganizationSid, This_Organization, NT_AUTHORITY, SidTypeWellKnownGroup },
240 { WinOtherOrganizationSid, Other_Organization, NT_AUTHORITY, SidTypeWellKnownGroup },
241 { WinBuiltinPerfMonitoringUsersSid, Performance_Monitor_Users, BUILTIN, SidTypeAlias },
242 { WinBuiltinPerfLoggingUsersSid, Performance_Log_Users, BUILTIN, SidTypeAlias },
247 static const WCHAR SDDL_READ_CONTROL[] = {'R','C',0};
248 static const WCHAR SDDL_WRITE_DAC[] = {'W','D',0};
249 static const WCHAR SDDL_WRITE_OWNER[] = {'W','O',0};
250 static const WCHAR SDDL_STANDARD_DELETE[] = {'S','D',0};
252 static const WCHAR SDDL_READ_PROPERTY[] = {'R','P',0};
253 static const WCHAR SDDL_WRITE_PROPERTY[] = {'W','P',0};
254 static const WCHAR SDDL_CREATE_CHILD[] = {'C','C',0};
255 static const WCHAR SDDL_DELETE_CHILD[] = {'D','C',0};
256 static const WCHAR SDDL_LIST_CHILDREN[] = {'L','C',0};
257 static const WCHAR SDDL_SELF_WRITE[] = {'S','W',0};
258 static const WCHAR SDDL_LIST_OBJECT[] = {'L','O',0};
259 static const WCHAR SDDL_DELETE_TREE[] = {'D','T',0};
260 static const WCHAR SDDL_CONTROL_ACCESS[] = {'C','R',0};
262 static const WCHAR SDDL_FILE_ALL[] = {'F','A',0};
263 static const WCHAR SDDL_FILE_READ[] = {'F','R',0};
264 static const WCHAR SDDL_FILE_WRITE[] = {'F','W',0};
265 static const WCHAR SDDL_FILE_EXECUTE[] = {'F','X',0};
267 static const WCHAR SDDL_KEY_ALL[] = {'K','A',0};
268 static const WCHAR SDDL_KEY_READ[] = {'K','R',0};
269 static const WCHAR SDDL_KEY_WRITE[] = {'K','W',0};
270 static const WCHAR SDDL_KEY_EXECUTE[] = {'K','X',0};
272 static const WCHAR SDDL_GENERIC_ALL[] = {'G','A',0};
273 static const WCHAR SDDL_GENERIC_READ[] = {'G','R',0};
274 static const WCHAR SDDL_GENERIC_WRITE[] = {'G','W',0};
275 static const WCHAR SDDL_GENERIC_EXECUTE[] = {'G','X',0};
280 static const WCHAR SDDL_PROTECTED[] = {'P',0};
281 static const WCHAR SDDL_AUTO_INHERIT_REQ[] = {'A','R',0};
282 static const WCHAR SDDL_AUTO_INHERITED[] = {'A','I',0};
287 static const WCHAR SDDL_ACCESS_ALLOWED[] = {'A',0};
288 static const WCHAR SDDL_ACCESS_DENIED[] = {'D',0};
289 static const WCHAR SDDL_OBJECT_ACCESS_ALLOWED[] = {'O','A',0};
290 static const WCHAR SDDL_OBJECT_ACCESS_DENIED[] = {'O','D',0};
291 static const WCHAR SDDL_AUDIT[] = {'A','U',0};
292 static const WCHAR SDDL_ALARM[] = {'A','L',0};
293 static const WCHAR SDDL_OBJECT_AUDIT[] = {'O','U',0};
294 static const WCHAR SDDL_OBJECT_ALARMp[] = {'O','L',0};
299 static const WCHAR SDDL_CONTAINER_INHERIT[] = {'C','I',0};
300 static const WCHAR SDDL_OBJECT_INHERIT[] = {'O','I',0};
301 static const WCHAR SDDL_NO_PROPAGATE[] = {'N','P',0};
302 static const WCHAR SDDL_INHERIT_ONLY[] = {'I','O',0};
303 static const WCHAR SDDL_INHERITED[] = {'I','D',0};
304 static const WCHAR SDDL_AUDIT_SUCCESS[] = {'S','A',0};
305 static const WCHAR SDDL_AUDIT_FAILURE[] = {'F','A',0};
307 const char * debugstr_sid(PSID sid)
310 SID * psid = (SID *)sid;
315 auth = psid->IdentifierAuthority.Value[5] +
316 (psid->IdentifierAuthority.Value[4] << 8) +
317 (psid->IdentifierAuthority.Value[3] << 16) +
318 (psid->IdentifierAuthority.Value[2] << 24);
320 switch (psid->SubAuthorityCount) {
322 return wine_dbg_sprintf("S-%d-%d", psid->Revision, auth);
324 return wine_dbg_sprintf("S-%d-%d-%u", psid->Revision, auth,
325 psid->SubAuthority[0]);
327 return wine_dbg_sprintf("S-%d-%d-%u-%u", psid->Revision, auth,
328 psid->SubAuthority[0], psid->SubAuthority[1]);
330 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u", psid->Revision, auth,
331 psid->SubAuthority[0], psid->SubAuthority[1], psid->SubAuthority[2]);
333 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u", psid->Revision, auth,
334 psid->SubAuthority[0], psid->SubAuthority[1], psid->SubAuthority[2],
335 psid->SubAuthority[3]);
337 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u", psid->Revision, auth,
338 psid->SubAuthority[0], psid->SubAuthority[1], psid->SubAuthority[2],
339 psid->SubAuthority[3], psid->SubAuthority[4]);
341 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u", psid->Revision, auth,
342 psid->SubAuthority[3], psid->SubAuthority[1], psid->SubAuthority[2],
343 psid->SubAuthority[0], psid->SubAuthority[4], psid->SubAuthority[5]);
345 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u-%u", psid->Revision, auth,
346 psid->SubAuthority[0], psid->SubAuthority[1], psid->SubAuthority[2],
347 psid->SubAuthority[3], psid->SubAuthority[4], psid->SubAuthority[5],
348 psid->SubAuthority[6]);
350 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u-%u-%u", psid->Revision, auth,
351 psid->SubAuthority[0], psid->SubAuthority[1], psid->SubAuthority[2],
352 psid->SubAuthority[3], psid->SubAuthority[4], psid->SubAuthority[5],
353 psid->SubAuthority[6], psid->SubAuthority[7]);
358 /* set last error code from NT status and get the proper boolean return value */
359 /* used for functions that are a simple wrapper around the corresponding ntdll API */
360 static inline BOOL set_ntstatus( NTSTATUS status )
362 if (status) SetLastError( RtlNtStatusToDosError( status ));
366 #define WINE_SIZE_OF_WORLD_ACCESS_ACL (sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD))
368 static void GetWorldAccessACL(PACL pACL)
370 PACCESS_ALLOWED_ACE pACE = (PACCESS_ALLOWED_ACE) (pACL + 1);
372 pACL->AclRevision = ACL_REVISION;
374 pACL->AclSize = WINE_SIZE_OF_WORLD_ACCESS_ACL;
378 pACE->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
379 pACE->Header.AceFlags = CONTAINER_INHERIT_ACE;
380 pACE->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD);
381 pACE->Mask = 0xf3ffffff; /* Everything except reserved bits */
382 memcpy(&pACE->SidStart, &sidWorld, sizeof(sidWorld));
385 /************************************************************
386 * ADVAPI_IsLocalComputer
388 * Checks whether the server name indicates local machine.
390 BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName)
392 DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
396 if (!ServerName || !ServerName[0])
399 buf = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
400 Result = GetComputerNameW(buf, &dwSize);
401 if (Result && (ServerName[0] == '\\') && (ServerName[1] == '\\'))
403 Result = Result && !lstrcmpW(ServerName, buf);
404 HeapFree(GetProcessHeap(), 0, buf);
409 /************************************************************
410 * ADVAPI_GetComputerSid
412 * Reads the computer SID from the registry.
414 BOOL ADVAPI_GetComputerSid(PSID sid)
419 static const WCHAR Account[] = { 'S','E','C','U','R','I','T','Y','\\','S','A','M','\\','D','o','m','a','i','n','s','\\','A','c','c','o','u','n','t',0 };
420 static const WCHAR V[] = { 'V',0 };
422 if ((ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, Account, 0,
423 KEY_READ, &key)) == ERROR_SUCCESS)
426 ret = RegQueryValueExW(key, V, NULL, NULL, NULL, &size);
427 if (ret == ERROR_MORE_DATA || ret == ERROR_SUCCESS)
429 BYTE * data = HeapAlloc(GetProcessHeap(), 0, size);
432 if ((ret = RegQueryValueExW(key, V, NULL, NULL,
433 data, &size)) == ERROR_SUCCESS)
435 /* the SID is in the last 24 bytes of the binary data */
436 CopyMemory(sid, &data[size-24], 24);
439 HeapFree(GetProcessHeap(), 0, data);
445 if(retval == TRUE) return retval;
447 /* create a new random SID */
448 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, Account,
449 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL) == ERROR_SUCCESS)
452 SID_IDENTIFIER_AUTHORITY identifierAuthority = {SECURITY_NT_AUTHORITY};
455 if (RtlGenRandom(&id, sizeof(id)))
457 if (AllocateAndInitializeSid(&identifierAuthority, 4, SECURITY_NT_NON_UNIQUE, id[0], id[1], id[2], 0, 0, 0, 0, &new_sid))
459 if (RegSetValueExW(key, V, 0, REG_BINARY, new_sid, GetLengthSid(new_sid)) == ERROR_SUCCESS)
460 retval = CopySid(GetLengthSid(new_sid), sid, new_sid);
471 /* ##############################
472 ###### TOKEN FUNCTIONS ######
473 ##############################
476 /******************************************************************************
477 * OpenProcessToken [ADVAPI32.@]
478 * Opens the access token associated with a process handle.
481 * ProcessHandle [I] Handle to process
482 * DesiredAccess [I] Desired access to process
483 * TokenHandle [O] Pointer to handle of open access token
486 * Success: TRUE. TokenHandle contains the access token.
490 * See NtOpenProcessToken.
493 OpenProcessToken( HANDLE ProcessHandle, DWORD DesiredAccess,
494 HANDLE *TokenHandle )
496 return set_ntstatus(NtOpenProcessToken( ProcessHandle, DesiredAccess, TokenHandle ));
499 /******************************************************************************
500 * OpenThreadToken [ADVAPI32.@]
502 * Opens the access token associated with a thread handle.
505 * ThreadHandle [I] Handle to process
506 * DesiredAccess [I] Desired access to the thread
508 * TokenHandle [O] Destination for the token handle
511 * Success: TRUE. TokenHandle contains the access token.
515 * See NtOpenThreadToken.
518 OpenThreadToken( HANDLE ThreadHandle, DWORD DesiredAccess,
519 BOOL OpenAsSelf, HANDLE *TokenHandle)
521 return set_ntstatus( NtOpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle));
525 AdjustTokenGroups( HANDLE TokenHandle, BOOL ResetToDefault, PTOKEN_GROUPS NewState,
526 DWORD BufferLength, PTOKEN_GROUPS PreviousState, PDWORD ReturnLength )
528 return set_ntstatus( NtAdjustGroupsToken(TokenHandle, ResetToDefault, NewState, BufferLength,
529 PreviousState, ReturnLength));
532 /******************************************************************************
533 * AdjustTokenPrivileges [ADVAPI32.@]
535 * Adjust the privileges of an open token handle.
538 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
539 * DisableAllPrivileges [I] TRUE=Remove all privileges, FALSE=Use NewState
540 * NewState [I] Desired new privileges of the token
541 * BufferLength [I] Length of NewState
542 * PreviousState [O] Destination for the previous state
543 * ReturnLength [I/O] Size of PreviousState
547 * Success: TRUE. Privileges are set to NewState and PreviousState is updated.
551 * See NtAdjustPrivilegesToken.
554 AdjustTokenPrivileges( HANDLE TokenHandle, BOOL DisableAllPrivileges,
555 LPVOID NewState, DWORD BufferLength,
556 LPVOID PreviousState, LPDWORD ReturnLength )
562 status = NtAdjustPrivilegesToken(TokenHandle, DisableAllPrivileges,
563 NewState, BufferLength, PreviousState,
565 SetLastError( RtlNtStatusToDosError( status ));
566 if ((status == STATUS_SUCCESS) || (status == STATUS_NOT_ALL_ASSIGNED))
572 /******************************************************************************
573 * CheckTokenMembership [ADVAPI32.@]
575 * Determine if an access token is a member of a SID.
578 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
579 * SidToCheck [I] SID that possibly contains the token
580 * IsMember [O] Destination for result.
583 * Success: TRUE. IsMember is TRUE if TokenHandle is a member, FALSE otherwise.
587 CheckTokenMembership( HANDLE TokenHandle, PSID SidToCheck,
590 FIXME("(%p %p %p) stub!\n", TokenHandle, SidToCheck, IsMember);
596 /******************************************************************************
597 * GetTokenInformation [ADVAPI32.@]
599 * Get a type of information about an access token.
602 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
603 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
604 * tokeninfo [O] Destination for token information
605 * tokeninfolength [I] Length of tokeninfo
606 * retlen [O] Destination for returned token information length
609 * Success: TRUE. tokeninfo contains retlen bytes of token information
613 * See NtQueryInformationToken.
616 GetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
617 LPVOID tokeninfo, DWORD tokeninfolength, LPDWORD retlen )
619 TRACE("(%p, %s, %p, %d, %p):\n",
621 (tokeninfoclass == TokenUser) ? "TokenUser" :
622 (tokeninfoclass == TokenGroups) ? "TokenGroups" :
623 (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
624 (tokeninfoclass == TokenOwner) ? "TokenOwner" :
625 (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
626 (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
627 (tokeninfoclass == TokenSource) ? "TokenSource" :
628 (tokeninfoclass == TokenType) ? "TokenType" :
629 (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
630 (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
631 (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
632 (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
633 (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
634 (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
635 (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
637 tokeninfo, tokeninfolength, retlen);
638 return set_ntstatus( NtQueryInformationToken( token, tokeninfoclass, tokeninfo,
639 tokeninfolength, retlen));
642 /******************************************************************************
643 * SetTokenInformation [ADVAPI32.@]
645 * Set information for an access token.
648 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
649 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
650 * tokeninfo [I] Token information to set
651 * tokeninfolength [I] Length of tokeninfo
654 * Success: TRUE. The information for the token is set to tokeninfo.
658 SetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
659 LPVOID tokeninfo, DWORD tokeninfolength )
661 TRACE("(%p, %s, %p, %d): stub\n",
663 (tokeninfoclass == TokenUser) ? "TokenUser" :
664 (tokeninfoclass == TokenGroups) ? "TokenGroups" :
665 (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
666 (tokeninfoclass == TokenOwner) ? "TokenOwner" :
667 (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
668 (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
669 (tokeninfoclass == TokenSource) ? "TokenSource" :
670 (tokeninfoclass == TokenType) ? "TokenType" :
671 (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
672 (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
673 (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
674 (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
675 (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
676 (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
677 (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
679 tokeninfo, tokeninfolength);
681 return set_ntstatus( NtSetInformationToken( token, tokeninfoclass, tokeninfo, tokeninfolength ));
684 /*************************************************************************
685 * SetThreadToken [ADVAPI32.@]
687 * Assigns an 'impersonation token' to a thread so it can assume the
688 * security privileges of another thread or process. Can also remove
689 * a previously assigned token.
692 * thread [O] Handle to thread to set the token for
693 * token [I] Token to set
696 * Success: TRUE. The threads access token is set to token
700 * Only supported on NT or higher. On Win9X this function does nothing.
701 * See SetTokenInformation.
703 BOOL WINAPI SetThreadToken(PHANDLE thread, HANDLE token)
705 return set_ntstatus( NtSetInformationThread( thread ? *thread : GetCurrentThread(),
706 ThreadImpersonationToken, &token, sizeof token ));
709 /* ##############################
710 ###### SID FUNCTIONS ######
711 ##############################
714 /******************************************************************************
715 * AllocateAndInitializeSid [ADVAPI32.@]
718 * pIdentifierAuthority []
719 * nSubAuthorityCount []
731 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
732 BYTE nSubAuthorityCount,
733 DWORD nSubAuthority0, DWORD nSubAuthority1,
734 DWORD nSubAuthority2, DWORD nSubAuthority3,
735 DWORD nSubAuthority4, DWORD nSubAuthority5,
736 DWORD nSubAuthority6, DWORD nSubAuthority7,
739 return set_ntstatus( RtlAllocateAndInitializeSid(
740 pIdentifierAuthority, nSubAuthorityCount,
741 nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3,
742 nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7,
746 /******************************************************************************
747 * FreeSid [ADVAPI32.@]
756 return NULL; /* is documented like this */
759 /******************************************************************************
760 * CopySid [ADVAPI32.@]
763 * nDestinationSidLength []
768 CopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
770 return RtlCopySid(nDestinationSidLength, pDestinationSid, pSourceSid);
773 /******************************************************************************
774 * CreateWellKnownSid [ADVAPI32.@]
777 CreateWellKnownSid( WELL_KNOWN_SID_TYPE WellKnownSidType,
783 TRACE("(%d, %s, %p, %p)\n", WellKnownSidType, debugstr_sid(DomainSid), pSid, cbSid);
785 if (DomainSid != NULL) {
786 FIXME("Only local computer supported!\n");
787 SetLastError(ERROR_INVALID_PARAMETER); /* FIXME */
791 if (cbSid == NULL || pSid == NULL) {
792 SetLastError(ERROR_INVALID_PARAMETER);
796 for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++) {
797 if (WellKnownSids[i].Type == WellKnownSidType) {
798 DWORD length = GetSidLengthRequired(WellKnownSids[i].Sid.SubAuthorityCount);
800 if (*cbSid < length) {
801 SetLastError(ERROR_INSUFFICIENT_BUFFER);
805 CopyMemory(pSid, &WellKnownSids[i].Sid.Revision, length);
811 SetLastError(ERROR_INVALID_PARAMETER);
815 /******************************************************************************
816 * IsWellKnownSid [ADVAPI32.@]
819 IsWellKnownSid( PSID pSid, WELL_KNOWN_SID_TYPE WellKnownSidType )
822 TRACE("(%s, %d)\n", debugstr_sid(pSid), WellKnownSidType);
824 for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++)
825 if (WellKnownSids[i].Type == WellKnownSidType)
826 if (EqualSid(pSid, (PSID)&(WellKnownSids[i].Sid.Revision)))
833 IsTokenRestricted( HANDLE TokenHandle )
835 TOKEN_GROUPS *groups;
840 TRACE("(%p)\n", TokenHandle);
842 status = NtQueryInformationToken(TokenHandle, TokenRestrictedSids, NULL, 0, &size);
843 if (status != STATUS_BUFFER_TOO_SMALL)
846 groups = HeapAlloc(GetProcessHeap(), 0, size);
849 SetLastError(ERROR_OUTOFMEMORY);
853 status = NtQueryInformationToken(TokenHandle, TokenRestrictedSids, groups, size, &size);
854 if (status != STATUS_SUCCESS)
856 HeapFree(GetProcessHeap(), 0, groups);
857 return set_ntstatus(status);
860 if (groups->GroupCount)
865 HeapFree(GetProcessHeap(), 0, groups);
870 /******************************************************************************
871 * IsValidSid [ADVAPI32.@]
877 IsValidSid( PSID pSid )
879 return RtlValidSid( pSid );
882 /******************************************************************************
883 * EqualSid [ADVAPI32.@]
890 EqualSid( PSID pSid1, PSID pSid2 )
892 return RtlEqualSid( pSid1, pSid2 );
895 /******************************************************************************
896 * EqualPrefixSid [ADVAPI32.@]
898 BOOL WINAPI EqualPrefixSid (PSID pSid1, PSID pSid2)
900 return RtlEqualPrefixSid(pSid1, pSid2);
903 /******************************************************************************
904 * GetSidLengthRequired [ADVAPI32.@]
907 * nSubAuthorityCount []
910 GetSidLengthRequired( BYTE nSubAuthorityCount )
912 return RtlLengthRequiredSid(nSubAuthorityCount);
915 /******************************************************************************
916 * InitializeSid [ADVAPI32.@]
919 * pIdentifierAuthority []
924 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
925 BYTE nSubAuthorityCount)
927 return RtlInitializeSid(pSid, pIdentifierAuthority, nSubAuthorityCount);
931 GetEffectiveRightsFromAclA( PACL pacl, PTRUSTEEA pTrustee, PACCESS_MASK pAccessRights )
933 FIXME("%p %p %p - stub\n", pacl, pTrustee, pAccessRights);
939 GetEffectiveRightsFromAclW( PACL pacl, PTRUSTEEW pTrustee, PACCESS_MASK pAccessRights )
941 FIXME("%p %p %p - stub\n", pacl, pTrustee, pAccessRights);
946 /******************************************************************************
947 * GetSidIdentifierAuthority [ADVAPI32.@]
952 PSID_IDENTIFIER_AUTHORITY WINAPI
953 GetSidIdentifierAuthority( PSID pSid )
955 return RtlIdentifierAuthoritySid(pSid);
958 /******************************************************************************
959 * GetSidSubAuthority [ADVAPI32.@]
966 GetSidSubAuthority( PSID pSid, DWORD nSubAuthority )
968 return RtlSubAuthoritySid(pSid, nSubAuthority);
971 /******************************************************************************
972 * GetSidSubAuthorityCount [ADVAPI32.@]
978 GetSidSubAuthorityCount (PSID pSid)
980 return RtlSubAuthorityCountSid(pSid);
983 /******************************************************************************
984 * GetLengthSid [ADVAPI32.@]
990 GetLengthSid (PSID pSid)
992 return RtlLengthSid(pSid);
995 /* ##############################################
996 ###### SECURITY DESCRIPTOR FUNCTIONS ######
997 ##############################################
1000 /******************************************************************************
1001 * BuildSecurityDescriptorA [ADVAPI32.@]
1008 * cCountOfAccessEntries [I]
1009 * pListOfAccessEntries [I]
1010 * cCountOfAuditEntries [I]
1011 * pListofAuditEntries [I]
1013 * lpdwBufferLength [I/O]
1017 * Success: ERROR_SUCCESS
1018 * Failure: nonzero error code from Winerror.h
1020 DWORD WINAPI BuildSecurityDescriptorA(
1021 IN PTRUSTEEA pOwner,
1022 IN PTRUSTEEA pGroup,
1023 IN ULONG cCountOfAccessEntries,
1024 IN PEXPLICIT_ACCESSA pListOfAccessEntries,
1025 IN ULONG cCountOfAuditEntries,
1026 IN PEXPLICIT_ACCESSA pListofAuditEntries,
1027 IN PSECURITY_DESCRIPTOR pOldSD,
1028 IN OUT PULONG lpdwBufferLength,
1029 OUT PSECURITY_DESCRIPTOR* pNewSD)
1031 FIXME("(%p,%p,%d,%p,%d,%p,%p,%p,%p) stub!\n",pOwner,pGroup,
1032 cCountOfAccessEntries,pListOfAccessEntries,cCountOfAuditEntries,
1033 pListofAuditEntries,pOldSD,lpdwBufferLength,pNewSD);
1035 return ERROR_CALL_NOT_IMPLEMENTED;
1038 /******************************************************************************
1039 * BuildSecurityDescriptorW [ADVAPI32.@]
1041 * See BuildSecurityDescriptorA.
1043 DWORD WINAPI BuildSecurityDescriptorW(
1044 IN PTRUSTEEW pOwner,
1045 IN PTRUSTEEW pGroup,
1046 IN ULONG cCountOfAccessEntries,
1047 IN PEXPLICIT_ACCESSW pListOfAccessEntries,
1048 IN ULONG cCountOfAuditEntries,
1049 IN PEXPLICIT_ACCESSW pListofAuditEntries,
1050 IN PSECURITY_DESCRIPTOR pOldSD,
1051 IN OUT PULONG lpdwBufferLength,
1052 OUT PSECURITY_DESCRIPTOR* pNewSD)
1054 FIXME("(%p,%p,%d,%p,%d,%p,%p,%p,%p) stub!\n",pOwner,pGroup,
1055 cCountOfAccessEntries,pListOfAccessEntries,cCountOfAuditEntries,
1056 pListofAuditEntries,pOldSD,lpdwBufferLength,pNewSD);
1058 return ERROR_CALL_NOT_IMPLEMENTED;
1061 /******************************************************************************
1062 * InitializeSecurityDescriptor [ADVAPI32.@]
1069 InitializeSecurityDescriptor( PSECURITY_DESCRIPTOR pDescr, DWORD revision )
1071 return set_ntstatus( RtlCreateSecurityDescriptor(pDescr, revision ));
1075 /******************************************************************************
1076 * MakeAbsoluteSD [ADVAPI32.@]
1078 BOOL WINAPI MakeAbsoluteSD (
1079 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
1080 OUT PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
1081 OUT LPDWORD lpdwAbsoluteSecurityDescriptorSize,
1083 OUT LPDWORD lpdwDaclSize,
1085 OUT LPDWORD lpdwSaclSize,
1087 OUT LPDWORD lpdwOwnerSize,
1088 OUT PSID pPrimaryGroup,
1089 OUT LPDWORD lpdwPrimaryGroupSize)
1091 return set_ntstatus( RtlSelfRelativeToAbsoluteSD(pSelfRelativeSecurityDescriptor,
1092 pAbsoluteSecurityDescriptor,
1093 lpdwAbsoluteSecurityDescriptorSize,
1094 pDacl, lpdwDaclSize, pSacl, lpdwSaclSize,
1095 pOwner, lpdwOwnerSize,
1096 pPrimaryGroup, lpdwPrimaryGroupSize));
1099 /******************************************************************************
1100 * GetKernelObjectSecurity [ADVAPI32.@]
1102 BOOL WINAPI GetKernelObjectSecurity(
1104 SECURITY_INFORMATION RequestedInformation,
1105 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1107 LPDWORD lpnLengthNeeded )
1109 TRACE("(%p,0x%08x,%p,0x%08x,%p)\n", Handle, RequestedInformation,
1110 pSecurityDescriptor, nLength, lpnLengthNeeded);
1112 return set_ntstatus( NtQuerySecurityObject(Handle, RequestedInformation, pSecurityDescriptor,
1113 nLength, lpnLengthNeeded ));
1116 /******************************************************************************
1117 * GetPrivateObjectSecurity [ADVAPI32.@]
1119 BOOL WINAPI GetPrivateObjectSecurity(
1120 PSECURITY_DESCRIPTOR ObjectDescriptor,
1121 SECURITY_INFORMATION SecurityInformation,
1122 PSECURITY_DESCRIPTOR ResultantDescriptor,
1123 DWORD DescriptorLength,
1124 PDWORD ReturnLength )
1126 SECURITY_DESCRIPTOR desc;
1127 BOOL defaulted, present;
1131 TRACE("(%p,0x%08x,%p,0x%08x,%p)\n", ObjectDescriptor, SecurityInformation,
1132 ResultantDescriptor, DescriptorLength, ReturnLength);
1134 if (!InitializeSecurityDescriptor(&desc, SECURITY_DESCRIPTOR_REVISION))
1137 if (SecurityInformation & OWNER_SECURITY_INFORMATION)
1139 if (!GetSecurityDescriptorOwner(ObjectDescriptor, &psid, &defaulted))
1141 SetSecurityDescriptorOwner(&desc, psid, defaulted);
1144 if (SecurityInformation & GROUP_SECURITY_INFORMATION)
1146 if (!GetSecurityDescriptorGroup(ObjectDescriptor, &psid, &defaulted))
1148 SetSecurityDescriptorGroup(&desc, psid, defaulted);
1151 if (SecurityInformation & DACL_SECURITY_INFORMATION)
1153 if (!GetSecurityDescriptorDacl(ObjectDescriptor, &present, &pacl, &defaulted))
1155 SetSecurityDescriptorDacl(&desc, present, pacl, defaulted);
1158 if (SecurityInformation & SACL_SECURITY_INFORMATION)
1160 if (!GetSecurityDescriptorSacl(ObjectDescriptor, &present, &pacl, &defaulted))
1162 SetSecurityDescriptorSacl(&desc, present, pacl, defaulted);
1165 *ReturnLength = DescriptorLength;
1166 if (!MakeSelfRelativeSD(&desc, ResultantDescriptor, ReturnLength))
1168 GetSecurityDescriptorOwner(ResultantDescriptor, &psid, &defaulted);
1169 FIXME("%p, sid=%p\n", &desc, psid);
1173 /******************************************************************************
1174 * GetSecurityDescriptorLength [ADVAPI32.@]
1176 DWORD WINAPI GetSecurityDescriptorLength( PSECURITY_DESCRIPTOR pDescr)
1178 return RtlLengthSecurityDescriptor(pDescr);
1181 /******************************************************************************
1182 * GetSecurityDescriptorOwner [ADVAPI32.@]
1186 * lpbOwnerDefaulted []
1189 GetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pDescr, PSID *pOwner,
1190 LPBOOL lpbOwnerDefaulted )
1193 BOOL ret = set_ntstatus( RtlGetOwnerSecurityDescriptor( pDescr, pOwner, &defaulted ));
1194 *lpbOwnerDefaulted = defaulted;
1198 /******************************************************************************
1199 * SetSecurityDescriptorOwner [ADVAPI32.@]
1203 BOOL WINAPI SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor,
1204 PSID pOwner, BOOL bOwnerDefaulted)
1206 return set_ntstatus( RtlSetOwnerSecurityDescriptor(pSecurityDescriptor, pOwner, bOwnerDefaulted));
1208 /******************************************************************************
1209 * GetSecurityDescriptorGroup [ADVAPI32.@]
1211 BOOL WINAPI GetSecurityDescriptorGroup(
1212 PSECURITY_DESCRIPTOR SecurityDescriptor,
1214 LPBOOL GroupDefaulted)
1217 BOOL ret = set_ntstatus( RtlGetGroupSecurityDescriptor(SecurityDescriptor, Group, &defaulted ));
1218 *GroupDefaulted = defaulted;
1221 /******************************************************************************
1222 * SetSecurityDescriptorGroup [ADVAPI32.@]
1224 BOOL WINAPI SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor,
1225 PSID Group, BOOL GroupDefaulted)
1227 return set_ntstatus( RtlSetGroupSecurityDescriptor( SecurityDescriptor, Group, GroupDefaulted));
1230 /******************************************************************************
1231 * IsValidSecurityDescriptor [ADVAPI32.@]
1237 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor )
1239 return set_ntstatus( RtlValidSecurityDescriptor(SecurityDescriptor));
1242 /******************************************************************************
1243 * GetSecurityDescriptorDacl [ADVAPI32.@]
1245 BOOL WINAPI GetSecurityDescriptorDacl(
1246 IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
1247 OUT LPBOOL lpbDaclPresent,
1249 OUT LPBOOL lpbDaclDefaulted)
1251 BOOLEAN present, defaulted;
1252 BOOL ret = set_ntstatus( RtlGetDaclSecurityDescriptor(pSecurityDescriptor, &present, pDacl, &defaulted));
1253 *lpbDaclPresent = present;
1254 *lpbDaclDefaulted = defaulted;
1258 /******************************************************************************
1259 * SetSecurityDescriptorDacl [ADVAPI32.@]
1262 SetSecurityDescriptorDacl (
1263 PSECURITY_DESCRIPTOR lpsd,
1266 BOOL dacldefaulted )
1268 return set_ntstatus( RtlSetDaclSecurityDescriptor (lpsd, daclpresent, dacl, dacldefaulted ) );
1270 /******************************************************************************
1271 * GetSecurityDescriptorSacl [ADVAPI32.@]
1273 BOOL WINAPI GetSecurityDescriptorSacl(
1274 IN PSECURITY_DESCRIPTOR lpsd,
1275 OUT LPBOOL lpbSaclPresent,
1277 OUT LPBOOL lpbSaclDefaulted)
1279 BOOLEAN present, defaulted;
1280 BOOL ret = set_ntstatus( RtlGetSaclSecurityDescriptor(lpsd, &present, pSacl, &defaulted) );
1281 *lpbSaclPresent = present;
1282 *lpbSaclDefaulted = defaulted;
1286 /**************************************************************************
1287 * SetSecurityDescriptorSacl [ADVAPI32.@]
1289 BOOL WINAPI SetSecurityDescriptorSacl (
1290 PSECURITY_DESCRIPTOR lpsd,
1295 return set_ntstatus (RtlSetSaclSecurityDescriptor(lpsd, saclpresent, lpsacl, sacldefaulted));
1297 /******************************************************************************
1298 * MakeSelfRelativeSD [ADVAPI32.@]
1307 IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
1308 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
1309 IN OUT LPDWORD lpdwBufferLength)
1311 return set_ntstatus( RtlMakeSelfRelativeSD( pAbsoluteSecurityDescriptor,
1312 pSelfRelativeSecurityDescriptor, lpdwBufferLength));
1315 /******************************************************************************
1316 * GetSecurityDescriptorControl [ADVAPI32.@]
1319 BOOL WINAPI GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR pSecurityDescriptor,
1320 PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision)
1322 return set_ntstatus( RtlGetControlSecurityDescriptor(pSecurityDescriptor,pControl,lpdwRevision));
1325 /* ##############################
1326 ###### ACL FUNCTIONS ######
1327 ##############################
1330 /*************************************************************************
1331 * InitializeAcl [ADVAPI32.@]
1333 BOOL WINAPI InitializeAcl(PACL acl, DWORD size, DWORD rev)
1335 return set_ntstatus( RtlCreateAcl(acl, size, rev));
1338 BOOL WINAPI ImpersonateNamedPipeClient( HANDLE hNamedPipe )
1340 IO_STATUS_BLOCK io_block;
1342 TRACE("(%p)\n", hNamedPipe);
1344 return set_ntstatus( NtFsControlFile(hNamedPipe, NULL, NULL, NULL,
1345 &io_block, FSCTL_PIPE_IMPERSONATE, NULL, 0, NULL, 0) );
1348 /******************************************************************************
1349 * AddAccessAllowedAce [ADVAPI32.@]
1351 BOOL WINAPI AddAccessAllowedAce(
1353 IN DWORD dwAceRevision,
1354 IN DWORD AccessMask,
1357 return set_ntstatus(RtlAddAccessAllowedAce(pAcl, dwAceRevision, AccessMask, pSid));
1360 /******************************************************************************
1361 * AddAccessAllowedAceEx [ADVAPI32.@]
1363 BOOL WINAPI AddAccessAllowedAceEx(
1365 IN DWORD dwAceRevision,
1367 IN DWORD AccessMask,
1370 return set_ntstatus(RtlAddAccessAllowedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
1373 /******************************************************************************
1374 * AddAccessDeniedAce [ADVAPI32.@]
1376 BOOL WINAPI AddAccessDeniedAce(
1378 IN DWORD dwAceRevision,
1379 IN DWORD AccessMask,
1382 return set_ntstatus(RtlAddAccessDeniedAce(pAcl, dwAceRevision, AccessMask, pSid));
1385 /******************************************************************************
1386 * AddAccessDeniedAceEx [ADVAPI32.@]
1388 BOOL WINAPI AddAccessDeniedAceEx(
1390 IN DWORD dwAceRevision,
1392 IN DWORD AccessMask,
1395 return set_ntstatus(RtlAddAccessDeniedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
1398 /******************************************************************************
1399 * AddAce [ADVAPI32.@]
1403 IN DWORD dwAceRevision,
1404 IN DWORD dwStartingAceIndex,
1406 DWORD nAceListLength)
1408 return set_ntstatus(RtlAddAce(pAcl, dwAceRevision, dwStartingAceIndex, pAceList, nAceListLength));
1411 /******************************************************************************
1412 * DeleteAce [ADVAPI32.@]
1414 BOOL WINAPI DeleteAce(PACL pAcl, DWORD dwAceIndex)
1416 return set_ntstatus(RtlDeleteAce(pAcl, dwAceIndex));
1419 /******************************************************************************
1420 * FindFirstFreeAce [ADVAPI32.@]
1422 BOOL WINAPI FindFirstFreeAce(IN PACL pAcl, LPVOID * pAce)
1424 return RtlFirstFreeAce(pAcl, (PACE_HEADER *)pAce);
1427 /******************************************************************************
1428 * GetAce [ADVAPI32.@]
1430 BOOL WINAPI GetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce )
1432 return set_ntstatus(RtlGetAce(pAcl, dwAceIndex, pAce));
1435 /******************************************************************************
1436 * GetAclInformation [ADVAPI32.@]
1438 BOOL WINAPI GetAclInformation(
1440 LPVOID pAclInformation,
1441 DWORD nAclInformationLength,
1442 ACL_INFORMATION_CLASS dwAclInformationClass)
1444 return set_ntstatus(RtlQueryInformationAcl(pAcl, pAclInformation,
1445 nAclInformationLength, dwAclInformationClass));
1448 /******************************************************************************
1449 * IsValidAcl [ADVAPI32.@]
1451 BOOL WINAPI IsValidAcl(IN PACL pAcl)
1453 return RtlValidAcl(pAcl);
1456 /* ##############################
1457 ###### MISC FUNCTIONS ######
1458 ##############################
1461 /******************************************************************************
1462 * AllocateLocallyUniqueId [ADVAPI32.@]
1467 BOOL WINAPI AllocateLocallyUniqueId( PLUID lpLuid )
1469 return set_ntstatus(NtAllocateLocallyUniqueId(lpLuid));
1472 static const WCHAR SE_CREATE_TOKEN_NAME_W[] =
1473 { 'S','e','C','r','e','a','t','e','T','o','k','e','n','P','r','i','v','i','l','e','g','e',0 };
1474 static const WCHAR SE_ASSIGNPRIMARYTOKEN_NAME_W[] =
1475 { 'S','e','A','s','s','i','g','n','P','r','i','m','a','r','y','T','o','k','e','n','P','r','i','v','i','l','e','g','e',0 };
1476 static const WCHAR SE_LOCK_MEMORY_NAME_W[] =
1477 { 'S','e','L','o','c','k','M','e','m','o','r','y','P','r','i','v','i','l','e','g','e',0 };
1478 static const WCHAR SE_INCREASE_QUOTA_NAME_W[] =
1479 { 'S','e','I','n','c','r','e','a','s','e','Q','u','o','t','a','P','r','i','v','i','l','e','g','e',0 };
1480 static const WCHAR SE_MACHINE_ACCOUNT_NAME_W[] =
1481 { 'S','e','M','a','c','h','i','n','e','A','c','c','o','u','n','t','P','r','i','v','i','l','e','g','e',0 };
1482 static const WCHAR SE_TCB_NAME_W[] =
1483 { 'S','e','T','c','b','P','r','i','v','i','l','e','g','e',0 };
1484 static const WCHAR SE_SECURITY_NAME_W[] =
1485 { 'S','e','S','e','c','u','r','i','t','y','P','r','i','v','i','l','e','g','e',0 };
1486 static const WCHAR SE_TAKE_OWNERSHIP_NAME_W[] =
1487 { 'S','e','T','a','k','e','O','w','n','e','r','s','h','i','p','P','r','i','v','i','l','e','g','e',0 };
1488 static const WCHAR SE_LOAD_DRIVER_NAME_W[] =
1489 { 'S','e','L','o','a','d','D','r','i','v','e','r','P','r','i','v','i','l','e','g','e',0 };
1490 static const WCHAR SE_SYSTEM_PROFILE_NAME_W[] =
1491 { 'S','e','S','y','s','t','e','m','P','r','o','f','i','l','e','P','r','i','v','i','l','e','g','e',0 };
1492 static const WCHAR SE_SYSTEMTIME_NAME_W[] =
1493 { 'S','e','S','y','s','t','e','m','t','i','m','e','P','r','i','v','i','l','e','g','e',0 };
1494 static const WCHAR SE_PROF_SINGLE_PROCESS_NAME_W[] =
1495 { 'S','e','P','r','o','f','i','l','e','S','i','n','g','l','e','P','r','o','c','e','s','s','P','r','i','v','i','l','e','g','e',0 };
1496 static const WCHAR SE_INC_BASE_PRIORITY_NAME_W[] =
1497 { 'S','e','I','n','c','r','e','a','s','e','B','a','s','e','P','r','i','o','r','i','t','y','P','r','i','v','i','l','e','g','e',0 };
1498 static const WCHAR SE_CREATE_PAGEFILE_NAME_W[] =
1499 { 'S','e','C','r','e','a','t','e','P','a','g','e','f','i','l','e','P','r','i','v','i','l','e','g','e',0 };
1500 static const WCHAR SE_CREATE_PERMANENT_NAME_W[] =
1501 { 'S','e','C','r','e','a','t','e','P','e','r','m','a','n','e','n','t','P','r','i','v','i','l','e','g','e',0 };
1502 static const WCHAR SE_BACKUP_NAME_W[] =
1503 { 'S','e','B','a','c','k','u','p','P','r','i','v','i','l','e','g','e',0 };
1504 static const WCHAR SE_RESTORE_NAME_W[] =
1505 { 'S','e','R','e','s','t','o','r','e','P','r','i','v','i','l','e','g','e',0 };
1506 static const WCHAR SE_SHUTDOWN_NAME_W[] =
1507 { 'S','e','S','h','u','t','d','o','w','n','P','r','i','v','i','l','e','g','e',0 };
1508 static const WCHAR SE_DEBUG_NAME_W[] =
1509 { 'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0 };
1510 static const WCHAR SE_AUDIT_NAME_W[] =
1511 { 'S','e','A','u','d','i','t','P','r','i','v','i','l','e','g','e',0 };
1512 static const WCHAR SE_SYSTEM_ENVIRONMENT_NAME_W[] =
1513 { 'S','e','S','y','s','t','e','m','E','n','v','i','r','o','n','m','e','n','t','P','r','i','v','i','l','e','g','e',0 };
1514 static const WCHAR SE_CHANGE_NOTIFY_NAME_W[] =
1515 { 'S','e','C','h','a','n','g','e','N','o','t','i','f','y','P','r','i','v','i','l','e','g','e',0 };
1516 static const WCHAR SE_REMOTE_SHUTDOWN_NAME_W[] =
1517 { 'S','e','R','e','m','o','t','e','S','h','u','t','d','o','w','n','P','r','i','v','i','l','e','g','e',0 };
1518 static const WCHAR SE_UNDOCK_NAME_W[] =
1519 { 'S','e','U','n','d','o','c','k','P','r','i','v','i','l','e','g','e',0 };
1520 static const WCHAR SE_SYNC_AGENT_NAME_W[] =
1521 { 'S','e','S','y','n','c','A','g','e','n','t','P','r','i','v','i','l','e','g','e',0 };
1522 static const WCHAR SE_ENABLE_DELEGATION_NAME_W[] =
1523 { 'S','e','E','n','a','b','l','e','D','e','l','e','g','a','t','i','o','n','P','r','i','v','i','l','e','g','e',0 };
1524 static const WCHAR SE_MANAGE_VOLUME_NAME_W[] =
1525 { 'S','e','M','a','n','a','g','e','V','o','l','u','m','e','P','r','i','v','i','l','e','g','e',0 };
1526 static const WCHAR SE_IMPERSONATE_NAME_W[] =
1527 { 'S','e','I','m','p','e','r','s','o','n','a','t','e','P','r','i','v','i','l','e','g','e',0 };
1528 static const WCHAR SE_CREATE_GLOBAL_NAME_W[] =
1529 { 'S','e','C','r','e','a','t','e','G','l','o','b','a','l','P','r','i','v','i','l','e','g','e',0 };
1531 static const WCHAR * const WellKnownPrivNames[SE_MAX_WELL_KNOWN_PRIVILEGE + 1] =
1535 SE_CREATE_TOKEN_NAME_W,
1536 SE_ASSIGNPRIMARYTOKEN_NAME_W,
1537 SE_LOCK_MEMORY_NAME_W,
1538 SE_INCREASE_QUOTA_NAME_W,
1539 SE_MACHINE_ACCOUNT_NAME_W,
1542 SE_TAKE_OWNERSHIP_NAME_W,
1543 SE_LOAD_DRIVER_NAME_W,
1544 SE_SYSTEM_PROFILE_NAME_W,
1545 SE_SYSTEMTIME_NAME_W,
1546 SE_PROF_SINGLE_PROCESS_NAME_W,
1547 SE_INC_BASE_PRIORITY_NAME_W,
1548 SE_CREATE_PAGEFILE_NAME_W,
1549 SE_CREATE_PERMANENT_NAME_W,
1555 SE_SYSTEM_ENVIRONMENT_NAME_W,
1556 SE_CHANGE_NOTIFY_NAME_W,
1557 SE_REMOTE_SHUTDOWN_NAME_W,
1559 SE_SYNC_AGENT_NAME_W,
1560 SE_ENABLE_DELEGATION_NAME_W,
1561 SE_MANAGE_VOLUME_NAME_W,
1562 SE_IMPERSONATE_NAME_W,
1563 SE_CREATE_GLOBAL_NAME_W,
1566 /******************************************************************************
1567 * LookupPrivilegeValueW [ADVAPI32.@]
1569 * See LookupPrivilegeValueA.
1572 LookupPrivilegeValueW( LPCWSTR lpSystemName, LPCWSTR lpName, PLUID lpLuid )
1576 TRACE("%s,%s,%p\n",debugstr_w(lpSystemName), debugstr_w(lpName), lpLuid);
1578 if (!ADVAPI_IsLocalComputer(lpSystemName))
1580 SetLastError(RPC_S_SERVER_UNAVAILABLE);
1585 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1588 for( i=SE_MIN_WELL_KNOWN_PRIVILEGE; i<SE_MAX_WELL_KNOWN_PRIVILEGE; i++ )
1590 if( !WellKnownPrivNames[i] )
1592 if( strcmpiW( WellKnownPrivNames[i], lpName) )
1594 lpLuid->LowPart = i;
1595 lpLuid->HighPart = 0;
1596 TRACE( "%s -> %08x-%08x\n",debugstr_w( lpSystemName ),
1597 lpLuid->HighPart, lpLuid->LowPart );
1600 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1604 /******************************************************************************
1605 * LookupPrivilegeValueA [ADVAPI32.@]
1607 * Retrieves LUID used on a system to represent the privilege name.
1610 * lpSystemName [I] Name of the system
1611 * lpName [I] Name of the privilege
1612 * lpLuid [O] Destination for the resulting LUID
1615 * Success: TRUE. lpLuid contains the requested LUID.
1619 LookupPrivilegeValueA( LPCSTR lpSystemName, LPCSTR lpName, PLUID lpLuid )
1621 UNICODE_STRING lpSystemNameW;
1622 UNICODE_STRING lpNameW;
1625 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
1626 RtlCreateUnicodeStringFromAsciiz(&lpNameW,lpName);
1627 ret = LookupPrivilegeValueW(lpSystemNameW.Buffer, lpNameW.Buffer, lpLuid);
1628 RtlFreeUnicodeString(&lpNameW);
1629 RtlFreeUnicodeString(&lpSystemNameW);
1633 BOOL WINAPI LookupPrivilegeDisplayNameA( LPCSTR lpSystemName, LPCSTR lpName, LPSTR lpDisplayName,
1634 LPDWORD cchDisplayName, LPDWORD lpLanguageId )
1636 FIXME("%s %s %s %p %p - stub\n", debugstr_a(lpSystemName), debugstr_a(lpName),
1637 debugstr_a(lpDisplayName), cchDisplayName, lpLanguageId);
1642 BOOL WINAPI LookupPrivilegeDisplayNameW( LPCWSTR lpSystemName, LPCWSTR lpName, LPWSTR lpDisplayName,
1643 LPDWORD cchDisplayName, LPDWORD lpLanguageId )
1645 FIXME("%s %s %s %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpName),
1646 debugstr_w(lpDisplayName), cchDisplayName, lpLanguageId);
1651 /******************************************************************************
1652 * LookupPrivilegeNameA [ADVAPI32.@]
1654 * See LookupPrivilegeNameW.
1657 LookupPrivilegeNameA( LPCSTR lpSystemName, PLUID lpLuid, LPSTR lpName,
1660 UNICODE_STRING lpSystemNameW;
1664 TRACE("%s %p %p %p\n", debugstr_a(lpSystemName), lpLuid, lpName, cchName);
1666 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
1667 ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, NULL, &wLen);
1668 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1670 LPWSTR lpNameW = HeapAlloc(GetProcessHeap(), 0, wLen * sizeof(WCHAR));
1672 ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, lpNameW,
1676 /* Windows crashes if cchName is NULL, so will I */
1677 unsigned int len = WideCharToMultiByte(CP_ACP, 0, lpNameW, -1, lpName,
1678 *cchName, NULL, NULL);
1682 /* WideCharToMultiByte failed */
1685 else if (len > *cchName)
1688 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1693 /* WideCharToMultiByte succeeded, output length needs to be
1694 * length not including NULL terminator
1699 HeapFree(GetProcessHeap(), 0, lpNameW);
1701 RtlFreeUnicodeString(&lpSystemNameW);
1705 /******************************************************************************
1706 * LookupPrivilegeNameW [ADVAPI32.@]
1708 * Retrieves the privilege name referred to by the LUID lpLuid.
1711 * lpSystemName [I] Name of the system
1712 * lpLuid [I] Privilege value
1713 * lpName [O] Name of the privilege
1714 * cchName [I/O] Number of characters in lpName.
1717 * Success: TRUE. lpName contains the name of the privilege whose value is
1722 * Only well-known privilege names (those defined in winnt.h) can be retrieved
1723 * using this function.
1724 * If the length of lpName is too small, on return *cchName will contain the
1725 * number of WCHARs needed to contain the privilege, including the NULL
1726 * terminator, and GetLastError will return ERROR_INSUFFICIENT_BUFFER.
1727 * On success, *cchName will contain the number of characters stored in
1728 * lpName, NOT including the NULL terminator.
1731 LookupPrivilegeNameW( LPCWSTR lpSystemName, PLUID lpLuid, LPWSTR lpName,
1736 TRACE("%s,%p,%p,%p\n",debugstr_w(lpSystemName), lpLuid, lpName, cchName);
1738 if (!ADVAPI_IsLocalComputer(lpSystemName))
1740 SetLastError(RPC_S_SERVER_UNAVAILABLE);
1743 if (lpLuid->HighPart || (lpLuid->LowPart < SE_MIN_WELL_KNOWN_PRIVILEGE ||
1744 lpLuid->LowPart > SE_MAX_WELL_KNOWN_PRIVILEGE))
1746 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1749 privNameLen = strlenW(WellKnownPrivNames[lpLuid->LowPart]);
1750 /* Windows crashes if cchName is NULL, so will I */
1751 if (*cchName <= privNameLen)
1753 *cchName = privNameLen + 1;
1754 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1759 strcpyW(lpName, WellKnownPrivNames[lpLuid->LowPart]);
1760 *cchName = privNameLen;
1765 /******************************************************************************
1766 * GetFileSecurityA [ADVAPI32.@]
1768 * Obtains Specified information about the security of a file or directory.
1771 * lpFileName [I] Name of the file to get info for
1772 * RequestedInformation [I] SE_ flags from "winnt.h"
1773 * pSecurityDescriptor [O] Destination for security information
1774 * nLength [I] Length of pSecurityDescriptor
1775 * lpnLengthNeeded [O] Destination for length of returned security information
1778 * Success: TRUE. pSecurityDescriptor contains the requested information.
1779 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
1782 * The information returned is constrained by the callers access rights and
1786 GetFileSecurityA( LPCSTR lpFileName,
1787 SECURITY_INFORMATION RequestedInformation,
1788 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1789 DWORD nLength, LPDWORD lpnLengthNeeded )
1797 len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 );
1798 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1799 MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len );
1802 r = GetFileSecurityW( name, RequestedInformation, pSecurityDescriptor,
1803 nLength, lpnLengthNeeded );
1804 HeapFree( GetProcessHeap(), 0, name );
1809 /******************************************************************************
1810 * GetFileSecurityW [ADVAPI32.@]
1812 * See GetFileSecurityA.
1815 GetFileSecurityW( LPCWSTR lpFileName,
1816 SECURITY_INFORMATION RequestedInformation,
1817 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1818 DWORD nLength, LPDWORD lpnLengthNeeded )
1824 if (RequestedInformation & (OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|
1825 DACL_SECURITY_INFORMATION))
1826 access |= READ_CONTROL;
1827 if (RequestedInformation & SACL_SECURITY_INFORMATION)
1828 access |= ACCESS_SYSTEM_SECURITY;
1830 hfile = CreateFileW( lpFileName, access, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
1831 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1832 if ( hfile == INVALID_HANDLE_VALUE )
1835 status = NtQuerySecurityObject( hfile, RequestedInformation, pSecurityDescriptor,
1836 nLength, lpnLengthNeeded );
1837 CloseHandle( hfile );
1838 return set_ntstatus( status );
1842 /******************************************************************************
1843 * LookupAccountSidA [ADVAPI32.@]
1850 IN OUT LPDWORD accountSize,
1852 IN OUT LPDWORD domainSize,
1853 OUT PSID_NAME_USE name_use )
1857 LPWSTR systemW = NULL;
1858 LPWSTR accountW = NULL;
1859 LPWSTR domainW = NULL;
1860 DWORD accountSizeW = *accountSize;
1861 DWORD domainSizeW = *domainSize;
1863 TRACE("(%s,sid=%s,%p,%p(%u),%p,%p(%u),%p)\n",
1864 debugstr_a(system),debugstr_sid(sid),
1865 account,accountSize,accountSize?*accountSize:0,
1866 domain,domainSize,domainSize?*domainSize:0,
1870 len = MultiByteToWideChar( CP_ACP, 0, system, -1, NULL, 0 );
1871 systemW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1872 MultiByteToWideChar( CP_ACP, 0, system, -1, systemW, len );
1875 accountW = HeapAlloc( GetProcessHeap(), 0, accountSizeW * sizeof(WCHAR) );
1877 domainW = HeapAlloc( GetProcessHeap(), 0, domainSizeW * sizeof(WCHAR) );
1879 r = LookupAccountSidW( systemW, sid, accountW, &accountSizeW, domainW, &domainSizeW, name_use );
1882 if (accountW && *accountSize) {
1883 len = WideCharToMultiByte( CP_ACP, 0, accountW, -1, NULL, 0, NULL, NULL );
1884 WideCharToMultiByte( CP_ACP, 0, accountW, -1, account, len, NULL, NULL );
1887 *accountSize = accountSizeW + 1;
1889 if (domainW && *domainSize) {
1890 len = WideCharToMultiByte( CP_ACP, 0, domainW, -1, NULL, 0, NULL, NULL );
1891 WideCharToMultiByte( CP_ACP, 0, domainW, -1, domain, len, NULL, NULL );
1894 *domainSize = domainSizeW + 1;
1897 HeapFree( GetProcessHeap(), 0, systemW );
1898 HeapFree( GetProcessHeap(), 0, accountW );
1899 HeapFree( GetProcessHeap(), 0, domainW );
1904 /******************************************************************************
1905 * LookupAccountSidW [ADVAPI32.@]
1922 IN OUT LPDWORD accountSize,
1924 IN OUT LPDWORD domainSize,
1925 OUT PSID_NAME_USE name_use )
1928 const WCHAR * ac = NULL;
1929 const WCHAR * dm = NULL;
1930 SID_NAME_USE use = 0;
1931 LPWSTR computer_name = NULL;
1933 TRACE("(%s,sid=%s,%p,%p(%u),%p,%p(%u),%p)\n",
1934 debugstr_w(system),debugstr_sid(sid),
1935 account,accountSize,accountSize?*accountSize:0,
1936 domain,domainSize,domainSize?*domainSize:0,
1939 if (!ADVAPI_IsLocalComputer(system)) {
1940 FIXME("Only local computer supported!\n");
1941 SetLastError(ERROR_NONE_MAPPED);
1945 /* check the well known SIDs first */
1946 for (i = 0; i <= 60; i++) {
1947 if (IsWellKnownSid(sid, i)) {
1948 for (j = 0; j < (sizeof(ACCOUNT_SIDS) / sizeof(ACCOUNT_SIDS[0])); j++) {
1949 if (ACCOUNT_SIDS[j].type == i) {
1950 ac = ACCOUNT_SIDS[j].account;
1951 dm = ACCOUNT_SIDS[j].domain;
1952 use = ACCOUNT_SIDS[j].name_use;
1962 /* check for the local computer next */
1963 if (ADVAPI_GetComputerSid(&local)) {
1964 DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
1967 computer_name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
1968 result = GetComputerNameW(computer_name, &size);
1971 if (EqualSid(sid, &local)) {
1976 local.SubAuthorityCount++;
1978 if (EqualPrefixSid(sid, &local)) {
1981 switch (((MAX_SID *)sid)->SubAuthority[4]) {
1982 case DOMAIN_USER_RID_ADMIN:
1985 case DOMAIN_USER_RID_GUEST:
1988 case DOMAIN_GROUP_RID_ADMINS:
1991 case DOMAIN_GROUP_RID_USERS:
1994 case DOMAIN_GROUP_RID_GUESTS:
1997 case DOMAIN_GROUP_RID_COMPUTERS:
1998 ac = Domain_Computers;
2000 case DOMAIN_GROUP_RID_CONTROLLERS:
2001 ac = Domain_Controllers;
2003 case DOMAIN_GROUP_RID_CERT_ADMINS:
2004 ac = Cert_Publishers;
2006 case DOMAIN_GROUP_RID_SCHEMA_ADMINS:
2009 case DOMAIN_GROUP_RID_ENTERPRISE_ADMINS:
2010 ac = Enterprise_Admins;
2012 case DOMAIN_GROUP_RID_POLICY_ADMINS:
2013 ac = Group_Policy_Creator_Owners;
2015 case DOMAIN_ALIAS_RID_RAS_SERVERS:
2016 ac = RAS_and_IAS_Servers;
2030 if (*accountSize > lstrlenW(ac)) {
2032 lstrcpyW(account, ac);
2034 if (*domainSize > lstrlenW(dm)) {
2036 lstrcpyW(domain, dm);
2038 if (((*accountSize != 0) && (*accountSize < strlenW(ac))) ||
2039 ((*domainSize != 0) && (*domainSize < strlenW(dm)))) {
2040 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2044 *domainSize = strlenW(dm);
2046 *domainSize = strlenW(dm) + 1;
2048 *accountSize = strlenW(ac);
2050 *accountSize = strlenW(ac) + 1;
2052 HeapFree(GetProcessHeap(), 0, computer_name);
2056 HeapFree(GetProcessHeap(), 0, computer_name);
2057 SetLastError(ERROR_NONE_MAPPED);
2061 /******************************************************************************
2062 * SetFileSecurityA [ADVAPI32.@]
2064 * See SetFileSecurityW.
2066 BOOL WINAPI SetFileSecurityA( LPCSTR lpFileName,
2067 SECURITY_INFORMATION RequestedInformation,
2068 PSECURITY_DESCRIPTOR pSecurityDescriptor)
2076 len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 );
2077 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
2078 MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len );
2081 r = SetFileSecurityW( name, RequestedInformation, pSecurityDescriptor );
2082 HeapFree( GetProcessHeap(), 0, name );
2087 /******************************************************************************
2088 * SetFileSecurityW [ADVAPI32.@]
2090 * Sets the security of a file or directory.
2094 * RequestedInformation []
2095 * pSecurityDescriptor []
2102 SetFileSecurityW( LPCWSTR lpFileName,
2103 SECURITY_INFORMATION RequestedInformation,
2104 PSECURITY_DESCRIPTOR pSecurityDescriptor )
2110 TRACE("(%s, 0x%x, %p)\n", debugstr_w(lpFileName), RequestedInformation,
2111 pSecurityDescriptor );
2113 if (RequestedInformation & OWNER_SECURITY_INFORMATION ||
2114 RequestedInformation & GROUP_SECURITY_INFORMATION)
2115 access |= WRITE_OWNER;
2116 if (RequestedInformation & SACL_SECURITY_INFORMATION)
2117 access |= ACCESS_SYSTEM_SECURITY;
2118 if (RequestedInformation & DACL_SECURITY_INFORMATION)
2119 access |= WRITE_DAC;
2121 file = CreateFileW( lpFileName, access, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2122 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
2123 if (file == INVALID_HANDLE_VALUE)
2126 status = NtSetSecurityObject( file, RequestedInformation, pSecurityDescriptor );
2127 CloseHandle( file );
2128 return set_ntstatus( status );
2131 /******************************************************************************
2132 * QueryWindows31FilesMigration [ADVAPI32.@]
2138 QueryWindows31FilesMigration( DWORD x1 )
2140 FIXME("(%d):stub\n",x1);
2144 /******************************************************************************
2145 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
2154 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
2157 FIXME("(0x%08x,0x%08x,0x%08x,0x%08x):stub\n",x1,x2,x3,x4);
2161 /******************************************************************************
2162 * NotifyBootConfigStatus [ADVAPI32.@]
2168 NotifyBootConfigStatus( BOOL x1 )
2170 FIXME("(0x%08d):stub\n",x1);
2174 /******************************************************************************
2175 * RevertToSelf [ADVAPI32.@]
2177 * Ends the impersonation of a user.
2187 RevertToSelf( void )
2189 HANDLE Token = NULL;
2190 return set_ntstatus( NtSetInformationThread( GetCurrentThread(),
2191 ThreadImpersonationToken, &Token, sizeof(Token) ) );
2194 /******************************************************************************
2195 * ImpersonateSelf [ADVAPI32.@]
2197 * Makes an impersonation token that represents the process user and assigns
2198 * to the current thread.
2201 * ImpersonationLevel [I] Level at which to impersonate.
2208 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
2210 return set_ntstatus( RtlImpersonateSelf( ImpersonationLevel ) );
2213 /******************************************************************************
2214 * ImpersonateLoggedOnUser [ADVAPI32.@]
2216 BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
2220 HANDLE ImpersonationToken;
2223 FIXME( "(%p)\n", hToken );
2225 if (!GetTokenInformation( hToken, TokenType, &Type,
2226 sizeof(TOKEN_TYPE), &size ))
2229 if (Type == TokenPrimary)
2231 OBJECT_ATTRIBUTES ObjectAttributes;
2233 InitializeObjectAttributes( &ObjectAttributes, NULL, 0, NULL, NULL );
2235 Status = NtDuplicateToken( hToken,
2236 TOKEN_IMPERSONATE | TOKEN_QUERY,
2238 SecurityImpersonation,
2240 &ImpersonationToken );
2241 if (Status != STATUS_SUCCESS)
2243 ERR( "NtDuplicateToken failed with error 0x%08x\n", Status );
2244 SetLastError( RtlNtStatusToDosError( Status ) );
2249 ImpersonationToken = hToken;
2251 Status = NtSetInformationThread( GetCurrentThread(),
2252 ThreadImpersonationToken,
2253 &ImpersonationToken,
2254 sizeof(ImpersonationToken) );
2256 if (Type == TokenPrimary)
2257 NtClose( ImpersonationToken );
2259 if (Status != STATUS_SUCCESS)
2261 ERR( "NtSetInformationThread failed with error 0x%08x\n", Status );
2262 SetLastError( RtlNtStatusToDosError( Status ) );
2269 /******************************************************************************
2270 * AccessCheck [ADVAPI32.@]
2274 PSECURITY_DESCRIPTOR SecurityDescriptor,
2276 DWORD DesiredAccess,
2277 PGENERIC_MAPPING GenericMapping,
2278 PPRIVILEGE_SET PrivilegeSet,
2279 LPDWORD PrivilegeSetLength,
2280 LPDWORD GrantedAccess,
2281 LPBOOL AccessStatus)
2283 NTSTATUS access_status;
2284 BOOL ret = set_ntstatus( NtAccessCheck(SecurityDescriptor, ClientToken, DesiredAccess,
2285 GenericMapping, PrivilegeSet, PrivilegeSetLength,
2286 GrantedAccess, &access_status) );
2287 if (ret) *AccessStatus = set_ntstatus( access_status );
2292 /******************************************************************************
2293 * AccessCheckByType [ADVAPI32.@]
2295 BOOL WINAPI AccessCheckByType(
2296 PSECURITY_DESCRIPTOR pSecurityDescriptor,
2297 PSID PrincipalSelfSid,
2299 DWORD DesiredAccess,
2300 POBJECT_TYPE_LIST ObjectTypeList,
2301 DWORD ObjectTypeListLength,
2302 PGENERIC_MAPPING GenericMapping,
2303 PPRIVILEGE_SET PrivilegeSet,
2304 LPDWORD PrivilegeSetLength,
2305 LPDWORD GrantedAccess,
2306 LPBOOL AccessStatus)
2310 *AccessStatus = TRUE;
2312 return !*AccessStatus;
2315 /******************************************************************************
2316 * MapGenericMask [ADVAPI32.@]
2318 * Maps generic access rights into specific access rights according to the
2322 * AccessMask [I/O] Access rights.
2323 * GenericMapping [I] The mapping between generic and specific rights.
2328 VOID WINAPI MapGenericMask( PDWORD AccessMask, PGENERIC_MAPPING GenericMapping )
2330 RtlMapGenericMask( AccessMask, GenericMapping );
2333 /*************************************************************************
2334 * SetKernelObjectSecurity [ADVAPI32.@]
2336 BOOL WINAPI SetKernelObjectSecurity (
2338 IN SECURITY_INFORMATION SecurityInformation,
2339 IN PSECURITY_DESCRIPTOR SecurityDescriptor )
2341 return set_ntstatus (NtSetSecurityObject (Handle, SecurityInformation, SecurityDescriptor));
2345 /******************************************************************************
2346 * AddAuditAccessAce [ADVAPI32.@]
2348 BOOL WINAPI AddAuditAccessAce(
2350 IN DWORD dwAceRevision,
2351 IN DWORD dwAccessMask,
2353 IN BOOL bAuditSuccess,
2354 IN BOOL bAuditFailure)
2356 return set_ntstatus( RtlAddAuditAccessAce(pAcl, dwAceRevision, dwAccessMask, pSid,
2357 bAuditSuccess, bAuditFailure) );
2360 /******************************************************************************
2361 * AddAuditAccessAce [ADVAPI32.@]
2363 BOOL WINAPI AddAuditAccessAceEx(
2365 IN DWORD dwAceRevision,
2366 IN DWORD dwAceFlags,
2367 IN DWORD dwAccessMask,
2369 IN BOOL bAuditSuccess,
2370 IN BOOL bAuditFailure)
2372 return set_ntstatus( RtlAddAuditAccessAceEx(pAcl, dwAceRevision, dwAceFlags, dwAccessMask, pSid,
2373 bAuditSuccess, bAuditFailure) );
2376 /******************************************************************************
2377 * LookupAccountNameA [ADVAPI32.@]
2385 LPSTR ReferencedDomainName,
2386 IN OUT LPDWORD cbReferencedDomainName,
2387 OUT PSID_NAME_USE name_use )
2390 UNICODE_STRING lpSystemW;
2391 UNICODE_STRING lpAccountW;
2392 LPWSTR lpReferencedDomainNameW = NULL;
2394 RtlCreateUnicodeStringFromAsciiz(&lpSystemW, system);
2395 RtlCreateUnicodeStringFromAsciiz(&lpAccountW, account);
2397 if (ReferencedDomainName)
2398 lpReferencedDomainNameW = HeapAlloc(GetProcessHeap(), 0, *cbReferencedDomainName * sizeof(WCHAR));
2400 ret = LookupAccountNameW(lpSystemW.Buffer, lpAccountW.Buffer, sid, cbSid, lpReferencedDomainNameW,
2401 cbReferencedDomainName, name_use);
2403 if (ret && lpReferencedDomainNameW)
2405 WideCharToMultiByte(CP_ACP, 0, lpReferencedDomainNameW, *cbReferencedDomainName,
2406 ReferencedDomainName, *cbReferencedDomainName, NULL, NULL);
2409 RtlFreeUnicodeString(&lpSystemW);
2410 RtlFreeUnicodeString(&lpAccountW);
2411 HeapFree(GetProcessHeap(), 0, lpReferencedDomainNameW);
2416 /******************************************************************************
2417 * LookupAccountNameW [ADVAPI32.@]
2419 BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSID Sid,
2420 LPDWORD cbSid, LPWSTR ReferencedDomainName,
2421 LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse )
2423 /* Default implementation: Always return a default SID */
2424 SID_IDENTIFIER_AUTHORITY identifierAuthority = {SECURITY_NT_AUTHORITY};
2427 static const WCHAR dm[] = {'D','O','M','A','I','N',0};
2429 FIXME("%s %s %p %p %p %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpAccountName),
2430 Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse);
2432 ret = AllocateAndInitializeSid(&identifierAuthority,
2434 SECURITY_BUILTIN_DOMAIN_RID,
2435 DOMAIN_ALIAS_RID_ADMINS,
2442 if (!RtlValidSid(pSid))
2448 if (Sid != NULL && (*cbSid >= GetLengthSid(pSid)))
2449 CopySid(*cbSid, Sid, pSid);
2450 if (*cbSid < GetLengthSid(pSid))
2452 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2455 *cbSid = GetLengthSid(pSid);
2457 if (ReferencedDomainName != NULL && (*cchReferencedDomainName > strlenW(dm)))
2458 strcpyW(ReferencedDomainName, dm);
2460 if (*cchReferencedDomainName <= strlenW(dm))
2462 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2466 *cchReferencedDomainName = strlenW(dm)+1;
2473 /******************************************************************************
2474 * PrivilegeCheck [ADVAPI32.@]
2476 BOOL WINAPI PrivilegeCheck( HANDLE ClientToken, PPRIVILEGE_SET RequiredPrivileges, LPBOOL pfResult)
2481 TRACE("%p %p %p\n", ClientToken, RequiredPrivileges, pfResult);
2483 ret = set_ntstatus (NtPrivilegeCheck (ClientToken, RequiredPrivileges, &Result));
2489 /******************************************************************************
2490 * AccessCheckAndAuditAlarmA [ADVAPI32.@]
2492 BOOL WINAPI AccessCheckAndAuditAlarmA(LPCSTR Subsystem, LPVOID HandleId, LPSTR ObjectTypeName,
2493 LPSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
2494 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
2495 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
2497 FIXME("stub (%s,%p,%s,%s,%p,%08x,%p,%x,%p,%p,%p)\n", debugstr_a(Subsystem),
2498 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName),
2499 SecurityDescriptor, DesiredAccess, GenericMapping,
2500 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
2504 /******************************************************************************
2505 * AccessCheckAndAuditAlarmW [ADVAPI32.@]
2507 BOOL WINAPI AccessCheckAndAuditAlarmW(LPCWSTR Subsystem, LPVOID HandleId, LPWSTR ObjectTypeName,
2508 LPWSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
2509 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
2510 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
2512 FIXME("stub (%s,%p,%s,%s,%p,%08x,%p,%x,%p,%p,%p)\n", debugstr_w(Subsystem),
2513 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName),
2514 SecurityDescriptor, DesiredAccess, GenericMapping,
2515 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
2519 BOOL WINAPI ObjectCloseAuditAlarmA(LPCSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
2521 FIXME("stub (%s,%p,%x)\n", debugstr_a(SubsystemName), HandleId, GenerateOnClose);
2526 BOOL WINAPI ObjectCloseAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
2528 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName), HandleId, GenerateOnClose);
2533 BOOL WINAPI ObjectDeleteAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
2535 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName), HandleId, GenerateOnClose);
2540 BOOL WINAPI ObjectOpenAuditAlarmA(LPCSTR SubsystemName, LPVOID HandleId, LPSTR ObjectTypeName,
2541 LPSTR ObjectName, PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE ClientToken, DWORD DesiredAccess,
2542 DWORD GrantedAccess, PPRIVILEGE_SET Privileges, BOOL ObjectCreation, BOOL AccessGranted,
2543 LPBOOL GenerateOnClose)
2545 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08x,0x%08x,%p,%x,%x,%p)\n", debugstr_a(SubsystemName),
2546 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName), pSecurityDescriptor,
2547 ClientToken, DesiredAccess, GrantedAccess, Privileges, ObjectCreation, AccessGranted,
2553 BOOL WINAPI ObjectOpenAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, LPWSTR ObjectTypeName,
2554 LPWSTR ObjectName, PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE ClientToken, DWORD DesiredAccess,
2555 DWORD GrantedAccess, PPRIVILEGE_SET Privileges, BOOL ObjectCreation, BOOL AccessGranted,
2556 LPBOOL GenerateOnClose)
2558 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08x,0x%08x,%p,%x,%x,%p)\n", debugstr_w(SubsystemName),
2559 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName), pSecurityDescriptor,
2560 ClientToken, DesiredAccess, GrantedAccess, Privileges, ObjectCreation, AccessGranted,
2566 BOOL WINAPI ObjectPrivilegeAuditAlarmA( LPCSTR SubsystemName, LPVOID HandleId, HANDLE ClientToken,
2567 DWORD DesiredAccess, PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2569 FIXME("stub (%s,%p,%p,0x%08x,%p,%x)\n", debugstr_a(SubsystemName), HandleId, ClientToken,
2570 DesiredAccess, Privileges, AccessGranted);
2575 BOOL WINAPI ObjectPrivilegeAuditAlarmW( LPCWSTR SubsystemName, LPVOID HandleId, HANDLE ClientToken,
2576 DWORD DesiredAccess, PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2578 FIXME("stub (%s,%p,%p,0x%08x,%p,%x)\n", debugstr_w(SubsystemName), HandleId, ClientToken,
2579 DesiredAccess, Privileges, AccessGranted);
2584 BOOL WINAPI PrivilegedServiceAuditAlarmA( LPCSTR SubsystemName, LPCSTR ServiceName, HANDLE ClientToken,
2585 PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2587 FIXME("stub (%s,%s,%p,%p,%x)\n", debugstr_a(SubsystemName), debugstr_a(ServiceName),
2588 ClientToken, Privileges, AccessGranted);
2593 BOOL WINAPI PrivilegedServiceAuditAlarmW( LPCWSTR SubsystemName, LPCWSTR ServiceName, HANDLE ClientToken,
2594 PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2596 FIXME("stub %s,%s,%p,%p,%x)\n", debugstr_w(SubsystemName), debugstr_w(ServiceName),
2597 ClientToken, Privileges, AccessGranted);
2602 /******************************************************************************
2603 * GetSecurityInfo [ADVAPI32.@]
2605 DWORD WINAPI GetSecurityInfo(
2606 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
2607 SECURITY_INFORMATION SecurityInfo, PSID *ppsidOwner,
2608 PSID *ppsidGroup, PACL *ppDacl, PACL *ppSacl,
2609 PSECURITY_DESCRIPTOR *ppSecurityDescriptor
2613 return ERROR_BAD_PROVIDER;
2616 /******************************************************************************
2617 * GetSecurityInfoExW [ADVAPI32.@]
2619 DWORD WINAPI GetSecurityInfoExW(
2620 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
2621 SECURITY_INFORMATION SecurityInfo, LPCWSTR lpProvider,
2622 LPCWSTR lpProperty, PACTRL_ACCESSW *ppAccessList,
2623 PACTRL_AUDITW *ppAuditList, LPWSTR *lppOwner, LPWSTR *lppGroup
2627 return ERROR_BAD_PROVIDER;
2630 /******************************************************************************
2631 * BuildExplicitAccessWithNameA [ADVAPI32.@]
2633 VOID WINAPI BuildExplicitAccessWithNameA( PEXPLICIT_ACCESSA pExplicitAccess,
2634 LPSTR pTrusteeName, DWORD AccessPermissions,
2635 ACCESS_MODE AccessMode, DWORD Inheritance )
2637 TRACE("%p %s 0x%08x 0x%08x 0x%08x\n", pExplicitAccess, debugstr_a(pTrusteeName),
2638 AccessPermissions, AccessMode, Inheritance);
2640 pExplicitAccess->grfAccessPermissions = AccessPermissions;
2641 pExplicitAccess->grfAccessMode = AccessMode;
2642 pExplicitAccess->grfInheritance = Inheritance;
2644 pExplicitAccess->Trustee.pMultipleTrustee = NULL;
2645 pExplicitAccess->Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2646 pExplicitAccess->Trustee.TrusteeForm = TRUSTEE_IS_NAME;
2647 pExplicitAccess->Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
2648 pExplicitAccess->Trustee.ptstrName = pTrusteeName;
2651 /******************************************************************************
2652 * BuildExplicitAccessWithNameW [ADVAPI32.@]
2654 VOID WINAPI BuildExplicitAccessWithNameW( PEXPLICIT_ACCESSW pExplicitAccess,
2655 LPWSTR pTrusteeName, DWORD AccessPermissions,
2656 ACCESS_MODE AccessMode, DWORD Inheritance )
2658 TRACE("%p %s 0x%08x 0x%08x 0x%08x\n", pExplicitAccess, debugstr_w(pTrusteeName),
2659 AccessPermissions, AccessMode, Inheritance);
2661 pExplicitAccess->grfAccessPermissions = AccessPermissions;
2662 pExplicitAccess->grfAccessMode = AccessMode;
2663 pExplicitAccess->grfInheritance = Inheritance;
2665 pExplicitAccess->Trustee.pMultipleTrustee = NULL;
2666 pExplicitAccess->Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2667 pExplicitAccess->Trustee.TrusteeForm = TRUSTEE_IS_NAME;
2668 pExplicitAccess->Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
2669 pExplicitAccess->Trustee.ptstrName = pTrusteeName;
2672 /******************************************************************************
2673 * BuildTrusteeWithObjectsAndNameA [ADVAPI32.@]
2675 VOID WINAPI BuildTrusteeWithObjectsAndNameA( PTRUSTEEA pTrustee, POBJECTS_AND_NAME_A pObjName,
2676 SE_OBJECT_TYPE ObjectType, LPSTR ObjectTypeName,
2677 LPSTR InheritedObjectTypeName, LPSTR Name )
2679 DWORD ObjectsPresent = 0;
2681 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee, pObjName,
2682 ObjectType, ObjectTypeName, InheritedObjectTypeName, debugstr_a(Name));
2684 /* Fill the OBJECTS_AND_NAME structure */
2685 pObjName->ObjectType = ObjectType;
2686 if (ObjectTypeName != NULL)
2688 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
2691 pObjName->InheritedObjectTypeName = InheritedObjectTypeName;
2692 if (InheritedObjectTypeName != NULL)
2694 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
2697 pObjName->ObjectsPresent = ObjectsPresent;
2698 pObjName->ptstrName = Name;
2700 /* Fill the TRUSTEE structure */
2701 pTrustee->pMultipleTrustee = NULL;
2702 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2703 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME;
2704 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2705 pTrustee->ptstrName = (LPSTR)pObjName;
2708 /******************************************************************************
2709 * BuildTrusteeWithObjectsAndNameW [ADVAPI32.@]
2711 VOID WINAPI BuildTrusteeWithObjectsAndNameW( PTRUSTEEW pTrustee, POBJECTS_AND_NAME_W pObjName,
2712 SE_OBJECT_TYPE ObjectType, LPWSTR ObjectTypeName,
2713 LPWSTR InheritedObjectTypeName, LPWSTR Name )
2715 DWORD ObjectsPresent = 0;
2717 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee, pObjName,
2718 ObjectType, ObjectTypeName, InheritedObjectTypeName, debugstr_w(Name));
2720 /* Fill the OBJECTS_AND_NAME structure */
2721 pObjName->ObjectType = ObjectType;
2722 if (ObjectTypeName != NULL)
2724 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
2727 pObjName->InheritedObjectTypeName = InheritedObjectTypeName;
2728 if (InheritedObjectTypeName != NULL)
2730 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
2733 pObjName->ObjectsPresent = ObjectsPresent;
2734 pObjName->ptstrName = Name;
2736 /* Fill the TRUSTEE structure */
2737 pTrustee->pMultipleTrustee = NULL;
2738 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2739 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME;
2740 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2741 pTrustee->ptstrName = (LPWSTR)pObjName;
2744 /******************************************************************************
2745 * BuildTrusteeWithObjectsAndSidA [ADVAPI32.@]
2747 VOID WINAPI BuildTrusteeWithObjectsAndSidA( PTRUSTEEA pTrustee, POBJECTS_AND_SID pObjSid,
2748 GUID* pObjectGuid, GUID* pInheritedObjectGuid, PSID pSid )
2750 DWORD ObjectsPresent = 0;
2752 TRACE("%p %p %p %p %p\n", pTrustee, pObjSid, pObjectGuid, pInheritedObjectGuid, pSid);
2754 /* Fill the OBJECTS_AND_SID structure */
2755 if (pObjectGuid != NULL)
2757 pObjSid->ObjectTypeGuid = *pObjectGuid;
2758 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
2762 ZeroMemory(&pObjSid->ObjectTypeGuid,
2766 if (pInheritedObjectGuid != NULL)
2768 pObjSid->InheritedObjectTypeGuid = *pInheritedObjectGuid;
2769 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
2773 ZeroMemory(&pObjSid->InheritedObjectTypeGuid,
2777 pObjSid->ObjectsPresent = ObjectsPresent;
2778 pObjSid->pSid = pSid;
2780 /* Fill the TRUSTEE structure */
2781 pTrustee->pMultipleTrustee = NULL;
2782 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2783 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID;
2784 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2785 pTrustee->ptstrName = (LPSTR) pObjSid;
2788 /******************************************************************************
2789 * BuildTrusteeWithObjectsAndSidW [ADVAPI32.@]
2791 VOID WINAPI BuildTrusteeWithObjectsAndSidW( PTRUSTEEW pTrustee, POBJECTS_AND_SID pObjSid,
2792 GUID* pObjectGuid, GUID* pInheritedObjectGuid, PSID pSid )
2794 DWORD ObjectsPresent = 0;
2796 TRACE("%p %p %p %p %p\n", pTrustee, pObjSid, pObjectGuid, pInheritedObjectGuid, pSid);
2798 /* Fill the OBJECTS_AND_SID structure */
2799 if (pObjectGuid != NULL)
2801 pObjSid->ObjectTypeGuid = *pObjectGuid;
2802 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
2806 ZeroMemory(&pObjSid->ObjectTypeGuid,
2810 if (pInheritedObjectGuid != NULL)
2812 pObjSid->InheritedObjectTypeGuid = *pInheritedObjectGuid;
2813 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
2817 ZeroMemory(&pObjSid->InheritedObjectTypeGuid,
2821 pObjSid->ObjectsPresent = ObjectsPresent;
2822 pObjSid->pSid = pSid;
2824 /* Fill the TRUSTEE structure */
2825 pTrustee->pMultipleTrustee = NULL;
2826 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2827 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID;
2828 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2829 pTrustee->ptstrName = (LPWSTR) pObjSid;
2832 /******************************************************************************
2833 * BuildTrusteeWithSidA [ADVAPI32.@]
2835 VOID WINAPI BuildTrusteeWithSidA(PTRUSTEEA pTrustee, PSID pSid)
2837 TRACE("%p %p\n", pTrustee, pSid);
2839 pTrustee->pMultipleTrustee = NULL;
2840 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2841 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
2842 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2843 pTrustee->ptstrName = (LPSTR) pSid;
2846 /******************************************************************************
2847 * BuildTrusteeWithSidW [ADVAPI32.@]
2849 VOID WINAPI BuildTrusteeWithSidW(PTRUSTEEW pTrustee, PSID pSid)
2851 TRACE("%p %p\n", pTrustee, pSid);
2853 pTrustee->pMultipleTrustee = NULL;
2854 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2855 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
2856 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2857 pTrustee->ptstrName = (LPWSTR) pSid;
2860 /******************************************************************************
2861 * BuildTrusteeWithNameA [ADVAPI32.@]
2863 VOID WINAPI BuildTrusteeWithNameA(PTRUSTEEA pTrustee, LPSTR name)
2865 TRACE("%p %s\n", pTrustee, debugstr_a(name) );
2867 pTrustee->pMultipleTrustee = NULL;
2868 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2869 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
2870 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2871 pTrustee->ptstrName = name;
2874 /******************************************************************************
2875 * BuildTrusteeWithNameW [ADVAPI32.@]
2877 VOID WINAPI BuildTrusteeWithNameW(PTRUSTEEW pTrustee, LPWSTR name)
2879 TRACE("%p %s\n", pTrustee, debugstr_w(name) );
2881 pTrustee->pMultipleTrustee = NULL;
2882 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2883 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
2884 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2885 pTrustee->ptstrName = name;
2888 /******************************************************************************
2889 * GetTrusteeFormA [ADVAPI32.@]
2891 TRUSTEE_FORM WINAPI GetTrusteeFormA(PTRUSTEEA pTrustee)
2893 TRACE("(%p)\n", pTrustee);
2896 return TRUSTEE_BAD_FORM;
2898 return pTrustee->TrusteeForm;
2901 /******************************************************************************
2902 * GetTrusteeFormW [ADVAPI32.@]
2904 TRUSTEE_FORM WINAPI GetTrusteeFormW(PTRUSTEEW pTrustee)
2906 TRACE("(%p)\n", pTrustee);
2909 return TRUSTEE_BAD_FORM;
2911 return pTrustee->TrusteeForm;
2914 /******************************************************************************
2915 * GetTrusteeNameA [ADVAPI32.@]
2917 LPSTR WINAPI GetTrusteeNameA(PTRUSTEEA pTrustee)
2919 TRACE("(%p)\n", pTrustee);
2924 return pTrustee->ptstrName;
2927 /******************************************************************************
2928 * GetTrusteeNameW [ADVAPI32.@]
2930 LPWSTR WINAPI GetTrusteeNameW(PTRUSTEEW pTrustee)
2932 TRACE("(%p)\n", pTrustee);
2937 return pTrustee->ptstrName;
2940 /******************************************************************************
2941 * GetTrusteeTypeA [ADVAPI32.@]
2943 TRUSTEE_TYPE WINAPI GetTrusteeTypeA(PTRUSTEEA pTrustee)
2945 TRACE("(%p)\n", pTrustee);
2948 return TRUSTEE_IS_UNKNOWN;
2950 return pTrustee->TrusteeType;
2953 /******************************************************************************
2954 * GetTrusteeTypeW [ADVAPI32.@]
2956 TRUSTEE_TYPE WINAPI GetTrusteeTypeW(PTRUSTEEW pTrustee)
2958 TRACE("(%p)\n", pTrustee);
2961 return TRUSTEE_IS_UNKNOWN;
2963 return pTrustee->TrusteeType;
2966 BOOL WINAPI SetAclInformation( PACL pAcl, LPVOID pAclInformation,
2967 DWORD nAclInformationLength,
2968 ACL_INFORMATION_CLASS dwAclInformationClass )
2970 FIXME("%p %p 0x%08x 0x%08x - stub\n", pAcl, pAclInformation,
2971 nAclInformationLength, dwAclInformationClass);
2976 /******************************************************************************
2977 * SetEntriesInAclA [ADVAPI32.@]
2979 DWORD WINAPI SetEntriesInAclA( ULONG count, PEXPLICIT_ACCESSA pEntries,
2980 PACL OldAcl, PACL* NewAcl )
2982 FIXME("%d %p %p %p\n",count,pEntries,OldAcl,NewAcl);
2984 return ERROR_SUCCESS;
2987 /******************************************************************************
2988 * SetEntriesInAclW [ADVAPI32.@]
2990 DWORD WINAPI SetEntriesInAclW( ULONG count, PEXPLICIT_ACCESSW pEntries,
2991 PACL OldAcl, PACL* NewAcl )
2993 FIXME("%d %p %p %p\n",count,pEntries,OldAcl,NewAcl);
2995 return ERROR_SUCCESS;
2998 /******************************************************************************
2999 * SetNamedSecurityInfoA [ADVAPI32.@]
3001 DWORD WINAPI SetNamedSecurityInfoA(LPSTR pObjectName,
3002 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
3003 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
3009 TRACE("%s %d %d %p %p %p %p\n", debugstr_a(pObjectName), ObjectType,
3010 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
3014 len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
3015 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
3016 MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
3019 r = SetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, psidOwner,
3020 psidGroup, pDacl, pSacl );
3022 HeapFree( GetProcessHeap(), 0, wstr );
3027 BOOL WINAPI SetPrivateObjectSecurity( SECURITY_INFORMATION SecurityInformation,
3028 PSECURITY_DESCRIPTOR ModificationDescriptor,
3029 PSECURITY_DESCRIPTOR* ObjectsSecurityDescriptor,
3030 PGENERIC_MAPPING GenericMapping,
3033 FIXME("0x%08x %p %p %p %p - stub\n", SecurityInformation, ModificationDescriptor,
3034 ObjectsSecurityDescriptor, GenericMapping, Token);
3039 BOOL WINAPI SetSecurityDescriptorControl( PSECURITY_DESCRIPTOR pSecurityDescriptor,
3040 SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
3041 SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet )
3043 FIXME("%p 0x%08x 0x%08x - stub\n", pSecurityDescriptor, ControlBitsOfInterest,
3049 BOOL WINAPI AreAllAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
3051 return RtlAreAllAccessesGranted( GrantedAccess, DesiredAccess );
3054 /******************************************************************************
3055 * AreAnyAccessesGranted [ADVAPI32.@]
3057 * Determines whether or not any of a set of specified access permissions have
3058 * been granted or not.
3061 * GrantedAccess [I] The permissions that have been granted.
3062 * DesiredAccess [I] The permissions that you want to have.
3065 * Nonzero if any of the permissions have been granted, zero if none of the
3066 * permissions have been granted.
3069 BOOL WINAPI AreAnyAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
3071 return RtlAreAnyAccessesGranted( GrantedAccess, DesiredAccess );
3074 /******************************************************************************
3075 * SetNamedSecurityInfoW [ADVAPI32.@]
3077 DWORD WINAPI SetNamedSecurityInfoW(LPWSTR pObjectName,
3078 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
3079 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
3081 FIXME("%s %d %d %p %p %p %p\n", debugstr_w(pObjectName), ObjectType,
3082 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
3083 return ERROR_SUCCESS;
3086 /******************************************************************************
3087 * GetExplicitEntriesFromAclA [ADVAPI32.@]
3089 DWORD WINAPI GetExplicitEntriesFromAclA( PACL pacl, PULONG pcCountOfExplicitEntries,
3090 PEXPLICIT_ACCESSA* pListOfExplicitEntries)
3092 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
3093 return ERROR_CALL_NOT_IMPLEMENTED;
3096 /******************************************************************************
3097 * GetExplicitEntriesFromAclW [ADVAPI32.@]
3099 DWORD WINAPI GetExplicitEntriesFromAclW( PACL pacl, PULONG pcCountOfExplicitEntries,
3100 PEXPLICIT_ACCESSW* pListOfExplicitEntries)
3102 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
3103 return ERROR_CALL_NOT_IMPLEMENTED;
3107 /******************************************************************************
3108 * ParseAclStringFlags
3110 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl)
3113 LPCWSTR szAcl = *StringAcl;
3115 while (*szAcl != '(')
3119 flags |= SE_DACL_PROTECTED;
3121 else if (*szAcl == 'A')
3125 flags |= SE_DACL_AUTO_INHERIT_REQ;
3126 else if (*szAcl == 'I')
3127 flags |= SE_DACL_AUTO_INHERITED;
3136 /******************************************************************************
3137 * ParseAceStringType
3139 static const ACEFLAG AceType[] =
3141 { SDDL_ALARM, SYSTEM_ALARM_ACE_TYPE },
3142 { SDDL_AUDIT, SYSTEM_AUDIT_ACE_TYPE },
3143 { SDDL_ACCESS_ALLOWED, ACCESS_ALLOWED_ACE_TYPE },
3144 { SDDL_ACCESS_DENIED, ACCESS_DENIED_ACE_TYPE },
3146 { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
3147 { SDDL_OBJECT_ACCESS_DENIED, ACCESS_DENIED_OBJECT_ACE_TYPE },
3148 { SDDL_OBJECT_ALARM, SYSTEM_ALARM_OBJECT_ACE_TYPE },
3149 { SDDL_OBJECT_AUDIT, SYSTEM_AUDIT_OBJECT_ACE_TYPE },
3154 static BYTE ParseAceStringType(LPCWSTR* StringAcl)
3157 LPCWSTR szAcl = *StringAcl;
3158 const ACEFLAG *lpaf = AceType;
3160 while (lpaf->wstr &&
3161 (len = strlenW(lpaf->wstr)) &&
3162 strncmpW(lpaf->wstr, szAcl, len))
3173 /******************************************************************************
3174 * ParseAceStringFlags
3176 static const ACEFLAG AceFlags[] =
3178 { SDDL_CONTAINER_INHERIT, CONTAINER_INHERIT_ACE },
3179 { SDDL_AUDIT_FAILURE, FAILED_ACCESS_ACE_FLAG },
3180 { SDDL_INHERITED, INHERITED_ACE },
3181 { SDDL_INHERIT_ONLY, INHERIT_ONLY_ACE },
3182 { SDDL_NO_PROPAGATE, NO_PROPAGATE_INHERIT_ACE },
3183 { SDDL_OBJECT_INHERIT, OBJECT_INHERIT_ACE },
3184 { SDDL_AUDIT_SUCCESS, SUCCESSFUL_ACCESS_ACE_FLAG },
3188 static BYTE ParseAceStringFlags(LPCWSTR* StringAcl)
3192 LPCWSTR szAcl = *StringAcl;
3194 while (*szAcl != ';')
3196 const ACEFLAG *lpaf = AceFlags;
3198 while (lpaf->wstr &&
3199 (len = strlenW(lpaf->wstr)) &&
3200 strncmpW(lpaf->wstr, szAcl, len))
3206 flags |= lpaf->value;
3215 /******************************************************************************
3216 * ParseAceStringRights
3218 static const ACEFLAG AceRights[] =
3220 { SDDL_GENERIC_ALL, GENERIC_ALL },
3221 { SDDL_GENERIC_READ, GENERIC_READ },
3222 { SDDL_GENERIC_WRITE, GENERIC_WRITE },
3223 { SDDL_GENERIC_EXECUTE, GENERIC_EXECUTE },
3225 { SDDL_READ_CONTROL, READ_CONTROL },
3226 { SDDL_STANDARD_DELETE, DELETE },
3227 { SDDL_WRITE_DAC, WRITE_DAC },
3228 { SDDL_WRITE_OWNER, WRITE_OWNER },
3230 { SDDL_READ_PROPERTY, ADS_RIGHT_DS_READ_PROP},
3231 { SDDL_WRITE_PROPERTY, ADS_RIGHT_DS_WRITE_PROP},
3232 { SDDL_CREATE_CHILD, ADS_RIGHT_DS_CREATE_CHILD},
3233 { SDDL_DELETE_CHILD, ADS_RIGHT_DS_DELETE_CHILD},
3234 { SDDL_LIST_CHILDREN, ADS_RIGHT_ACTRL_DS_LIST},
3235 { SDDL_SELF_WRITE, ADS_RIGHT_DS_SELF},
3236 { SDDL_LIST_OBJECT, ADS_RIGHT_DS_LIST_OBJECT},
3237 { SDDL_DELETE_TREE, ADS_RIGHT_DS_DELETE_TREE},
3238 { SDDL_CONTROL_ACCESS, ADS_RIGHT_DS_CONTROL_ACCESS},
3240 { SDDL_FILE_ALL, FILE_ALL_ACCESS },
3241 { SDDL_FILE_READ, FILE_GENERIC_READ },
3242 { SDDL_FILE_WRITE, FILE_GENERIC_WRITE },
3243 { SDDL_FILE_EXECUTE, FILE_GENERIC_EXECUTE },
3245 { SDDL_KEY_ALL, KEY_ALL_ACCESS },
3246 { SDDL_KEY_READ, KEY_READ },
3247 { SDDL_KEY_WRITE, KEY_WRITE },
3248 { SDDL_KEY_EXECUTE, KEY_EXECUTE },
3252 static DWORD ParseAceStringRights(LPCWSTR* StringAcl)
3256 LPCWSTR szAcl = *StringAcl;
3258 if ((*szAcl == '0') && (*(szAcl + 1) == 'x'))
3262 while (*p && *p != ';')
3265 if (p - szAcl <= 10 /* 8 hex digits + "0x" */ )
3267 rights = strtoulW(szAcl, NULL, 16);
3271 WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl, p - szAcl));
3275 while (*szAcl != ';')
3277 const ACEFLAG *lpaf = AceRights;
3279 while (lpaf->wstr &&
3280 (len = strlenW(lpaf->wstr)) &&
3281 strncmpW(lpaf->wstr, szAcl, len))
3289 rights |= lpaf->value;
3299 /******************************************************************************
3300 * ParseStringAclToAcl
3302 * dacl_flags(string_ace1)(string_ace2)... (string_acen)
3304 static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags,
3305 PACL pAcl, LPDWORD cBytes)
3309 DWORD length = sizeof(ACL);
3312 PACCESS_ALLOWED_ACE pAce = NULL; /* pointer to current ACE */
3314 TRACE("%s\n", debugstr_w(StringAcl));
3319 if (pAcl) /* pAce is only useful if we're setting values */
3320 pAce = (PACCESS_ALLOWED_ACE) (pAcl + 1);
3322 /* Parse ACL flags */
3323 *lpdwFlags = ParseAclStringFlags(&StringAcl);
3326 while (*StringAcl == '(')
3330 /* Parse ACE type */
3331 val = ParseAceStringType(&StringAcl);
3333 pAce->Header.AceType = (BYTE) val;
3334 if (*StringAcl != ';')
3338 /* Parse ACE flags */
3339 val = ParseAceStringFlags(&StringAcl);
3341 pAce->Header.AceFlags = (BYTE) val;
3342 if (*StringAcl != ';')
3346 /* Parse ACE rights */
3347 val = ParseAceStringRights(&StringAcl);
3350 if (*StringAcl != ';')
3354 /* Parse ACE object guid */
3355 if (*StringAcl != ';')
3357 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3362 /* Parse ACE inherit object guid */
3363 if (*StringAcl != ';')
3365 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3370 /* Parse ACE account sid */
3371 if (ParseStringSidToSid(StringAcl, pAce ? (PSID)&pAce->SidStart : NULL, &sidlen))
3373 while (*StringAcl && *StringAcl != ')')
3377 if (*StringAcl != ')')
3381 acesize = sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) + sidlen;
3385 pAce->Header.AceSize = acesize;
3386 pAce = (PACCESS_ALLOWED_ACE)((LPBYTE)pAce + acesize);
3393 if (length > 0xffff)
3395 ERR("ACL too large\n");
3401 pAcl->AclRevision = ACL_REVISION;
3403 pAcl->AclSize = length;
3404 pAcl->AceCount = acecount++;
3410 WARN("Invalid ACE string format\n");
3415 /******************************************************************************
3416 * ParseStringSecurityDescriptorToSecurityDescriptor
3418 static BOOL ParseStringSecurityDescriptorToSecurityDescriptor(
3419 LPCWSTR StringSecurityDescriptor,
3420 SECURITY_DESCRIPTOR* SecurityDescriptor,
3425 WCHAR tok[MAX_PATH];
3427 LPBYTE lpNext = NULL;
3430 *cBytes = sizeof(SECURITY_DESCRIPTOR);
3432 if (SecurityDescriptor)
3433 lpNext = ((LPBYTE) SecurityDescriptor) + sizeof(SECURITY_DESCRIPTOR);
3435 while (*StringSecurityDescriptor)
3437 toktype = *StringSecurityDescriptor;
3439 /* Expect char identifier followed by ':' */
3440 StringSecurityDescriptor++;
3441 if (*StringSecurityDescriptor != ':')
3443 SetLastError(ERROR_INVALID_PARAMETER);
3446 StringSecurityDescriptor++;
3449 lptoken = StringSecurityDescriptor;
3450 while (*lptoken && *lptoken != ':')
3456 len = lptoken - StringSecurityDescriptor;
3457 memcpy( tok, StringSecurityDescriptor, len * sizeof(WCHAR) );
3466 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
3469 if (SecurityDescriptor)
3471 SecurityDescriptor->Owner = (PSID)(lpNext - (LPBYTE)SecurityDescriptor);
3472 lpNext += bytes; /* Advance to next token */
3484 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
3487 if (SecurityDescriptor)
3489 SecurityDescriptor->Group = (PSID)(lpNext - (LPBYTE)SecurityDescriptor);
3490 lpNext += bytes; /* Advance to next token */
3503 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
3506 if (SecurityDescriptor)
3508 SecurityDescriptor->Control |= SE_DACL_PRESENT | flags;
3509 SecurityDescriptor->Dacl = (PACL)(lpNext - (LPBYTE)SecurityDescriptor);
3510 lpNext += bytes; /* Advance to next token */
3523 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
3526 if (SecurityDescriptor)
3528 SecurityDescriptor->Control |= SE_SACL_PRESENT | flags;
3529 SecurityDescriptor->Sacl = (PACL)(lpNext - (LPBYTE)SecurityDescriptor);
3530 lpNext += bytes; /* Advance to next token */
3539 FIXME("Unknown token\n");
3540 SetLastError(ERROR_INVALID_PARAMETER);
3544 StringSecurityDescriptor = lptoken;
3553 /******************************************************************************
3554 * ConvertStringSecurityDescriptorToSecurityDescriptorA [ADVAPI32.@]
3556 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorA(
3557 LPCSTR StringSecurityDescriptor,
3558 DWORD StringSDRevision,
3559 PSECURITY_DESCRIPTOR* SecurityDescriptor,
3560 PULONG SecurityDescriptorSize)
3564 LPWSTR StringSecurityDescriptorW;
3566 len = MultiByteToWideChar(CP_ACP, 0, StringSecurityDescriptor, -1, NULL, 0);
3567 StringSecurityDescriptorW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3569 if (StringSecurityDescriptorW)
3571 MultiByteToWideChar(CP_ACP, 0, StringSecurityDescriptor, -1, StringSecurityDescriptorW, len);
3573 ret = ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptorW,
3574 StringSDRevision, SecurityDescriptor,
3575 SecurityDescriptorSize);
3576 HeapFree(GetProcessHeap(), 0, StringSecurityDescriptorW);
3582 /******************************************************************************
3583 * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
3585 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW(
3586 LPCWSTR StringSecurityDescriptor,
3587 DWORD StringSDRevision,
3588 PSECURITY_DESCRIPTOR* SecurityDescriptor,
3589 PULONG SecurityDescriptorSize)
3592 SECURITY_DESCRIPTOR* psd;
3595 TRACE("%s\n", debugstr_w(StringSecurityDescriptor));
3597 if (GetVersion() & 0x80000000)
3599 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3602 else if (StringSDRevision != SID_REVISION)
3604 SetLastError(ERROR_UNKNOWN_REVISION);
3608 /* Compute security descriptor length */
3609 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
3613 psd = *SecurityDescriptor = (SECURITY_DESCRIPTOR*) LocalAlloc(
3614 GMEM_ZEROINIT, cBytes);
3615 if (!psd) goto lend;
3617 psd->Revision = SID_REVISION;
3618 psd->Control |= SE_SELF_RELATIVE;
3620 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
3627 if (SecurityDescriptorSize)
3628 *SecurityDescriptorSize = cBytes;
3633 TRACE(" ret=%d\n", bret);
3637 static void DumpString(LPCWSTR string, int cch, WCHAR **pwptr, ULONG *plen)
3640 cch = strlenW(string);
3647 memcpy(*pwptr, string, sizeof(WCHAR)*cch);
3652 static BOOL DumpSidNumeric(PSID psid, WCHAR **pwptr, ULONG *plen)
3655 WCHAR fmt[] = { 'S','-','%','u','-','%','d',0 };
3656 WCHAR subauthfmt[] = { '-','%','u',0 };
3660 if( !IsValidSid( psid ) || pisid->Revision != SDDL_REVISION)
3662 SetLastError(ERROR_INVALID_SID);
3666 if (pisid->IdentifierAuthority.Value[0] ||
3667 pisid->IdentifierAuthority.Value[1])
3669 FIXME("not matching MS' bugs\n");
3670 SetLastError(ERROR_INVALID_SID);
3674 sprintfW( buf, fmt, pisid->Revision,
3676 MAKEWORD( pisid->IdentifierAuthority.Value[5],
3677 pisid->IdentifierAuthority.Value[4] ),
3678 MAKEWORD( pisid->IdentifierAuthority.Value[3],
3679 pisid->IdentifierAuthority.Value[2] )
3681 DumpString(buf, -1, pwptr, plen);
3683 for( i=0; i<pisid->SubAuthorityCount; i++ )
3685 sprintfW( buf, subauthfmt, pisid->SubAuthority[i] );
3686 DumpString(buf, -1, pwptr, plen);
3691 static BOOL DumpSid(PSID psid, WCHAR **pwptr, ULONG *plen)
3694 for (i = 0; i < sizeof(WellKnownSids) / sizeof(WellKnownSids[0]); i++)
3696 if (WellKnownSids[i].wstr[0] && EqualSid(psid, (PSID)&(WellKnownSids[i].Sid.Revision)))
3698 DumpString(WellKnownSids[i].wstr, 2, pwptr, plen);
3703 return DumpSidNumeric(psid, pwptr, plen);
3706 static const LPCWSTR AceRightBitNames[32] = {
3707 SDDL_CREATE_CHILD, /* 0 */
3711 SDDL_READ_PROPERTY, /* 4 */
3712 SDDL_WRITE_PROPERTY,
3715 SDDL_CONTROL_ACCESS, /* 8 */
3723 SDDL_STANDARD_DELETE, /* 16 */
3735 SDDL_GENERIC_ALL, /* 28 */
3736 SDDL_GENERIC_EXECUTE,
3741 static void DumpRights(DWORD mask, WCHAR **pwptr, ULONG *plen)
3743 static const WCHAR fmtW[] = {'0','x','%','x',0};
3750 /* first check if the right have name */
3751 for (i = 0; i < sizeof(AceRights)/sizeof(AceRights[0]); i++)
3753 if (AceRights[i].wstr == NULL)
3755 if (mask == AceRights[i].value)
3757 DumpString(AceRights[i].wstr, -1, pwptr, plen);
3762 /* then check if it can be built from bit names */
3763 for (i = 0; i < 32; i++)
3765 if ((mask & (1 << i)) && (AceRightBitNames[i] == NULL))
3767 /* can't be built from bit names */
3768 sprintfW(buf, fmtW, mask);
3769 DumpString(buf, -1, pwptr, plen);
3774 /* build from bit names */
3775 for (i = 0; i < 32; i++)
3776 if (mask & (1 << i))
3777 DumpString(AceRightBitNames[i], -1, pwptr, plen);
3780 static BOOL DumpAce(LPVOID pace, WCHAR **pwptr, ULONG *plen)
3782 ACCESS_ALLOWED_ACE *piace; /* all the supported ACEs have the same memory layout */
3783 static const WCHAR openbr = '(';
3784 static const WCHAR closebr = ')';
3785 static const WCHAR semicolon = ';';
3787 if (((PACE_HEADER)pace)->AceType > SYSTEM_ALARM_ACE_TYPE || ((PACE_HEADER)pace)->AceSize < sizeof(ACCESS_ALLOWED_ACE))
3789 SetLastError(ERROR_INVALID_ACL);
3793 piace = (ACCESS_ALLOWED_ACE *)pace;
3794 DumpString(&openbr, 1, pwptr, plen);
3795 switch (piace->Header.AceType)
3797 case ACCESS_ALLOWED_ACE_TYPE:
3798 DumpString(SDDL_ACCESS_ALLOWED, -1, pwptr, plen);
3800 case ACCESS_DENIED_ACE_TYPE:
3801 DumpString(SDDL_ACCESS_DENIED, -1, pwptr, plen);
3803 case SYSTEM_AUDIT_ACE_TYPE:
3804 DumpString(SDDL_AUDIT, -1, pwptr, plen);
3806 case SYSTEM_ALARM_ACE_TYPE:
3807 DumpString(SDDL_ALARM, -1, pwptr, plen);
3810 DumpString(&semicolon, 1, pwptr, plen);
3812 if (piace->Header.AceFlags & OBJECT_INHERIT_ACE)
3813 DumpString(SDDL_OBJECT_INHERIT, -1, pwptr, plen);
3814 if (piace->Header.AceFlags & CONTAINER_INHERIT_ACE)
3815 DumpString(SDDL_CONTAINER_INHERIT, -1, pwptr, plen);
3816 if (piace->Header.AceFlags & NO_PROPAGATE_INHERIT_ACE)
3817 DumpString(SDDL_NO_PROPAGATE, -1, pwptr, plen);
3818 if (piace->Header.AceFlags & INHERIT_ONLY_ACE)
3819 DumpString(SDDL_INHERIT_ONLY, -1, pwptr, plen);
3820 if (piace->Header.AceFlags & INHERITED_ACE)
3821 DumpString(SDDL_INHERITED, -1, pwptr, plen);
3822 if (piace->Header.AceFlags & SUCCESSFUL_ACCESS_ACE_FLAG)
3823 DumpString(SDDL_AUDIT_SUCCESS, -1, pwptr, plen);
3824 if (piace->Header.AceFlags & FAILED_ACCESS_ACE_FLAG)
3825 DumpString(SDDL_AUDIT_FAILURE, -1, pwptr, plen);
3826 DumpString(&semicolon, 1, pwptr, plen);
3827 DumpRights(piace->Mask, pwptr, plen);
3828 DumpString(&semicolon, 1, pwptr, plen);
3829 /* objects not supported */
3830 DumpString(&semicolon, 1, pwptr, plen);
3831 /* objects not supported */
3832 DumpString(&semicolon, 1, pwptr, plen);
3833 if (!DumpSid((PSID)&piace->SidStart, pwptr, plen))
3835 DumpString(&closebr, 1, pwptr, plen);
3839 static BOOL DumpAcl(PACL pacl, WCHAR **pwptr, ULONG *plen, BOOL protected, BOOL autoInheritReq, BOOL autoInherited)
3845 DumpString(SDDL_PROTECTED, -1, pwptr, plen);
3847 DumpString(SDDL_AUTO_INHERIT_REQ, -1, pwptr, plen);
3849 DumpString(SDDL_AUTO_INHERITED, -1, pwptr, plen);
3854 if (!IsValidAcl(pacl))
3857 count = pacl->AceCount;
3858 for (i = 0; i < count; i++)
3861 if (!GetAce(pacl, i, &ace))
3863 if (!DumpAce(ace, pwptr, plen))
3870 static BOOL DumpOwner(PSECURITY_DESCRIPTOR SecurityDescriptor, WCHAR **pwptr, ULONG *plen)
3872 static const WCHAR prefix[] = {'O',':',0};
3876 if (!GetSecurityDescriptorOwner(SecurityDescriptor, &psid, &bDefaulted))
3882 DumpString(prefix, -1, pwptr, plen);
3883 if (!DumpSid(psid, pwptr, plen))
3888 static BOOL DumpGroup(PSECURITY_DESCRIPTOR SecurityDescriptor, WCHAR **pwptr, ULONG *plen)
3890 static const WCHAR prefix[] = {'G',':',0};
3894 if (!GetSecurityDescriptorGroup(SecurityDescriptor, &psid, &bDefaulted))
3900 DumpString(prefix, -1, pwptr, plen);
3901 if (!DumpSid(psid, pwptr, plen))
3906 static BOOL DumpDacl(PSECURITY_DESCRIPTOR SecurityDescriptor, WCHAR **pwptr, ULONG *plen)
3908 static const WCHAR dacl[] = {'D',':',0};
3909 SECURITY_DESCRIPTOR_CONTROL control;
3910 BOOL present, defaulted;
3914 if (!GetSecurityDescriptorDacl(SecurityDescriptor, &present, &pacl, &defaulted))
3917 if (!GetSecurityDescriptorControl(SecurityDescriptor, &control, &revision))
3923 DumpString(dacl, 2, pwptr, plen);
3924 if (!DumpAcl(pacl, pwptr, plen, control & SE_DACL_PROTECTED, control & SE_DACL_AUTO_INHERIT_REQ, control & SE_DACL_AUTO_INHERITED))
3929 static BOOL DumpSacl(PSECURITY_DESCRIPTOR SecurityDescriptor, WCHAR **pwptr, ULONG *plen)
3931 static const WCHAR sacl[] = {'S',':',0};
3932 SECURITY_DESCRIPTOR_CONTROL control;
3933 BOOL present, defaulted;
3937 if (!GetSecurityDescriptorSacl(SecurityDescriptor, &present, &pacl, &defaulted))
3940 if (!GetSecurityDescriptorControl(SecurityDescriptor, &control, &revision))
3946 DumpString(sacl, 2, pwptr, plen);
3947 if (!DumpAcl(pacl, pwptr, plen, control & SE_SACL_PROTECTED, control & SE_SACL_AUTO_INHERIT_REQ, control & SE_SACL_AUTO_INHERITED))
3952 /******************************************************************************
3953 * ConvertSecurityDescriptorToStringSecurityDescriptorA [ADVAPI32.@]
3955 BOOL WINAPI ConvertSecurityDescriptorToStringSecurityDescriptorW(PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD SDRevision, SECURITY_INFORMATION RequestedInformation, LPWSTR *OutputString, ULONG *OutputLen)
3960 if (SDRevision != SDDL_REVISION_1)
3962 ERR("Pogram requested unknown SDDL revision %d\n", SDRevision);
3963 SetLastError(ERROR_UNKNOWN_REVISION);
3968 if (RequestedInformation & OWNER_SECURITY_INFORMATION)
3969 if (!DumpOwner(SecurityDescriptor, NULL, &len))
3971 if (RequestedInformation & GROUP_SECURITY_INFORMATION)
3972 if (!DumpGroup(SecurityDescriptor, NULL, &len))
3974 if (RequestedInformation & DACL_SECURITY_INFORMATION)
3975 if (!DumpDacl(SecurityDescriptor, NULL, &len))
3977 if (RequestedInformation & SACL_SECURITY_INFORMATION)
3978 if (!DumpSacl(SecurityDescriptor, NULL, &len))
3981 wstr = wptr = LocalAlloc(0, (len + 1)*sizeof(WCHAR));
3982 if (RequestedInformation & OWNER_SECURITY_INFORMATION)
3983 if (!DumpOwner(SecurityDescriptor, &wptr, NULL))
3985 if (RequestedInformation & GROUP_SECURITY_INFORMATION)
3986 if (!DumpGroup(SecurityDescriptor, &wptr, NULL))
3988 if (RequestedInformation & DACL_SECURITY_INFORMATION)
3989 if (!DumpDacl(SecurityDescriptor, &wptr, NULL))
3991 if (RequestedInformation & SACL_SECURITY_INFORMATION)
3992 if (!DumpSacl(SecurityDescriptor, &wptr, NULL))
3996 TRACE("ret: %s, %d\n", wine_dbgstr_w(wstr), len);
3997 *OutputString = wstr;
3999 *OutputLen = strlenW(*OutputString)+1;
4003 /******************************************************************************
4004 * ConvertSecurityDescriptorToStringSecurityDescriptorA [ADVAPI32.@]
4006 BOOL WINAPI ConvertSecurityDescriptorToStringSecurityDescriptorA(PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD SDRevision, SECURITY_INFORMATION Information, LPSTR *OutputString, ULONG *OutputLen)
4010 if (ConvertSecurityDescriptorToStringSecurityDescriptorW(SecurityDescriptor, SDRevision, Information, &wstr, &len))
4014 lenA = WideCharToMultiByte(CP_ACP, 0, wstr, len, NULL, 0, NULL, NULL);
4015 *OutputString = HeapAlloc(GetProcessHeap(), 0, lenA);
4016 WideCharToMultiByte(CP_ACP, 0, wstr, len, *OutputString, lenA, NULL, NULL);
4019 if (OutputLen != NULL)
4025 *OutputString = NULL;
4032 /******************************************************************************
4033 * ConvertStringSidToSidW [ADVAPI32.@]
4035 BOOL WINAPI ConvertStringSidToSidW(LPCWSTR StringSid, PSID* Sid)
4040 TRACE("%s, %p\n", debugstr_w(StringSid), Sid);
4041 if (GetVersion() & 0x80000000)
4042 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
4043 else if (!StringSid || !Sid)
4044 SetLastError(ERROR_INVALID_PARAMETER);
4045 else if (ParseStringSidToSid(StringSid, NULL, &cBytes))
4047 PSID pSid = *Sid = (PSID) LocalAlloc(0, cBytes);
4049 bret = ParseStringSidToSid(StringSid, pSid, &cBytes);
4053 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
4057 /******************************************************************************
4058 * ConvertStringSidToSidA [ADVAPI32.@]
4060 BOOL WINAPI ConvertStringSidToSidA(LPCSTR StringSid, PSID* Sid)
4064 TRACE("%s, %p\n", debugstr_a(StringSid), Sid);
4065 if (GetVersion() & 0x80000000)
4066 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
4067 else if (!StringSid || !Sid)
4068 SetLastError(ERROR_INVALID_PARAMETER);
4071 UINT len = MultiByteToWideChar(CP_ACP, 0, StringSid, -1, NULL, 0);
4072 LPWSTR wStringSid = HeapAlloc(GetProcessHeap(), 0,
4073 len * sizeof(WCHAR));
4075 MultiByteToWideChar(CP_ACP, 0, StringSid, -1, wStringSid, len);
4076 bret = ConvertStringSidToSidW(wStringSid, Sid);
4077 HeapFree(GetProcessHeap(), 0, wStringSid);
4079 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
4083 /******************************************************************************
4084 * ConvertSidToStringSidW [ADVAPI32.@]
4086 * format of SID string is:
4087 * S-<count>-<auth>-<subauth1>-<subauth2>-<subauth3>...
4089 * <rev> is the revision of the SID encoded as decimal
4090 * <auth> is the identifier authority encoded as hex
4091 * <subauthN> is the subauthority id encoded as decimal
4093 BOOL WINAPI ConvertSidToStringSidW( PSID pSid, LPWSTR *pstr )
4098 TRACE("%p %p\n", pSid, pstr );
4101 if (!DumpSidNumeric(pSid, NULL, &len))
4103 wstr = wptr = LocalAlloc(0, (len+1) * sizeof(WCHAR));
4104 DumpSidNumeric(pSid, &wptr, NULL);
4111 /******************************************************************************
4112 * ConvertSidToStringSidA [ADVAPI32.@]
4114 BOOL WINAPI ConvertSidToStringSidA(PSID pSid, LPSTR *pstr)
4120 TRACE("%p %p\n", pSid, pstr );
4122 if( !ConvertSidToStringSidW( pSid, &wstr ) )
4125 len = WideCharToMultiByte( CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL );
4126 str = LocalAlloc( 0, len );
4127 WideCharToMultiByte( CP_ACP, 0, wstr, -1, str, len, NULL, NULL );
4135 BOOL WINAPI CreatePrivateObjectSecurity(
4136 PSECURITY_DESCRIPTOR ParentDescriptor,
4137 PSECURITY_DESCRIPTOR CreatorDescriptor,
4138 PSECURITY_DESCRIPTOR* NewDescriptor,
4139 BOOL IsDirectoryObject,
4141 PGENERIC_MAPPING GenericMapping )
4143 FIXME("%p %p %p %d %p %p - stub\n", ParentDescriptor, CreatorDescriptor,
4144 NewDescriptor, IsDirectoryObject, Token, GenericMapping);
4149 BOOL WINAPI DestroyPrivateObjectSecurity( PSECURITY_DESCRIPTOR* ObjectDescriptor )
4151 FIXME("%p - stub\n", ObjectDescriptor);
4156 BOOL WINAPI CreateProcessAsUserA(
4158 LPCSTR lpApplicationName,
4159 LPSTR lpCommandLine,
4160 LPSECURITY_ATTRIBUTES lpProcessAttributes,
4161 LPSECURITY_ATTRIBUTES lpThreadAttributes,
4162 BOOL bInheritHandles,
4163 DWORD dwCreationFlags,
4164 LPVOID lpEnvironment,
4165 LPCSTR lpCurrentDirectory,
4166 LPSTARTUPINFOA lpStartupInfo,
4167 LPPROCESS_INFORMATION lpProcessInformation )
4169 FIXME("%p %s %s %p %p %d 0x%08x %p %s %p %p - stub\n", hToken, debugstr_a(lpApplicationName),
4170 debugstr_a(lpCommandLine), lpProcessAttributes, lpThreadAttributes, bInheritHandles,
4171 dwCreationFlags, lpEnvironment, debugstr_a(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
4176 BOOL WINAPI CreateProcessAsUserW(
4178 LPCWSTR lpApplicationName,
4179 LPWSTR lpCommandLine,
4180 LPSECURITY_ATTRIBUTES lpProcessAttributes,
4181 LPSECURITY_ATTRIBUTES lpThreadAttributes,
4182 BOOL bInheritHandles,
4183 DWORD dwCreationFlags,
4184 LPVOID lpEnvironment,
4185 LPCWSTR lpCurrentDirectory,
4186 LPSTARTUPINFOW lpStartupInfo,
4187 LPPROCESS_INFORMATION lpProcessInformation )
4189 FIXME("%p %s %s %p %p %d 0x%08x %p %s %p %p - semi- stub\n", hToken,
4190 debugstr_w(lpApplicationName), debugstr_w(lpCommandLine), lpProcessAttributes,
4191 lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment,
4192 debugstr_w(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
4194 /* We should create the process with a suspended main thread */
4195 if (!CreateProcessW (lpApplicationName,
4197 lpProcessAttributes,
4200 dwCreationFlags, /* CREATE_SUSPENDED */
4204 lpProcessInformation))
4212 /******************************************************************************
4213 * DuplicateTokenEx [ADVAPI32.@]
4215 BOOL WINAPI DuplicateTokenEx(
4216 HANDLE ExistingTokenHandle, DWORD dwDesiredAccess,
4217 LPSECURITY_ATTRIBUTES lpTokenAttributes,
4218 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
4219 TOKEN_TYPE TokenType,
4220 PHANDLE DuplicateTokenHandle )
4222 OBJECT_ATTRIBUTES ObjectAttributes;
4224 TRACE("%p 0x%08x 0x%08x 0x%08x %p\n", ExistingTokenHandle, dwDesiredAccess,
4225 ImpersonationLevel, TokenType, DuplicateTokenHandle);
4227 InitializeObjectAttributes(
4230 (lpTokenAttributes && lpTokenAttributes->bInheritHandle) ? OBJ_INHERIT : 0,
4232 lpTokenAttributes ? lpTokenAttributes->lpSecurityDescriptor : NULL );
4234 return set_ntstatus( NtDuplicateToken( ExistingTokenHandle,
4239 DuplicateTokenHandle ) );
4242 BOOL WINAPI DuplicateToken(
4243 HANDLE ExistingTokenHandle,
4244 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
4245 PHANDLE DuplicateTokenHandle )
4247 return DuplicateTokenEx( ExistingTokenHandle, TOKEN_IMPERSONATE | TOKEN_QUERY,
4248 NULL, ImpersonationLevel, TokenImpersonation,
4249 DuplicateTokenHandle );
4252 BOOL WINAPI EnumDependentServicesA(
4254 DWORD dwServiceState,
4255 LPENUM_SERVICE_STATUSA lpServices,
4257 LPDWORD pcbBytesNeeded,
4258 LPDWORD lpServicesReturned )
4260 FIXME("%p 0x%08x %p 0x%08x %p %p - stub\n", hService, dwServiceState,
4261 lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned);
4266 BOOL WINAPI EnumDependentServicesW(
4268 DWORD dwServiceState,
4269 LPENUM_SERVICE_STATUSW lpServices,
4271 LPDWORD pcbBytesNeeded,
4272 LPDWORD lpServicesReturned )
4274 FIXME("%p 0x%08x %p 0x%08x %p %p - stub\n", hService, dwServiceState,
4275 lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned);
4280 /******************************************************************************
4281 * ComputeStringSidSize
4283 static DWORD ComputeStringSidSize(LPCWSTR StringSid)
4285 if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I(-S)+ */
4290 if (*StringSid == '-')
4296 return GetSidLengthRequired(ctok - 2);
4298 else /* String constant format - Only available in winxp and above */
4302 for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++)
4303 if (!strncmpW(WellKnownSids[i].wstr, StringSid, 2))
4304 return GetSidLengthRequired(WellKnownSids[i].Sid.SubAuthorityCount);
4307 return GetSidLengthRequired(0);
4310 /******************************************************************************
4311 * ParseStringSidToSid
4313 static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes)
4318 TRACE("%s, %p, %p\n", debugstr_w(StringSid), pSid, cBytes);
4321 SetLastError(ERROR_INVALID_PARAMETER);
4322 TRACE("StringSid is NULL, returning FALSE\n");
4326 *cBytes = ComputeStringSidSize(StringSid);
4327 if (!pisid) /* Simply compute the size */
4329 TRACE("only size requested, returning TRUE\n");
4333 if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I-S-S */
4335 DWORD i = 0, identAuth;
4336 DWORD csubauth = ((*cBytes - GetSidLengthRequired(0)) / sizeof(DWORD));
4338 StringSid += 2; /* Advance to Revision */
4339 pisid->Revision = atoiW(StringSid);
4341 if (pisid->Revision != SDDL_REVISION)
4343 TRACE("Revision %d is unknown\n", pisid->Revision);
4344 goto lend; /* ERROR_INVALID_SID */
4348 TRACE("SubAuthorityCount is 0\n");
4349 goto lend; /* ERROR_INVALID_SID */
4352 pisid->SubAuthorityCount = csubauth;
4354 /* Advance to identifier authority */
4355 while (*StringSid && *StringSid != '-')
4357 if (*StringSid == '-')
4360 /* MS' implementation can't handle values greater than 2^32 - 1, so
4361 * we don't either; assume most significant bytes are always 0
4363 pisid->IdentifierAuthority.Value[0] = 0;
4364 pisid->IdentifierAuthority.Value[1] = 0;
4365 identAuth = atoiW(StringSid);
4366 pisid->IdentifierAuthority.Value[5] = identAuth & 0xff;
4367 pisid->IdentifierAuthority.Value[4] = (identAuth & 0xff00) >> 8;
4368 pisid->IdentifierAuthority.Value[3] = (identAuth & 0xff0000) >> 16;
4369 pisid->IdentifierAuthority.Value[2] = (identAuth & 0xff000000) >> 24;
4371 /* Advance to first sub authority */
4372 while (*StringSid && *StringSid != '-')
4374 if (*StringSid == '-')
4379 pisid->SubAuthority[i++] = atoiW(StringSid);
4381 while (*StringSid && *StringSid != '-')
4383 if (*StringSid == '-')
4387 if (i != pisid->SubAuthorityCount)
4388 goto lend; /* ERROR_INVALID_SID */
4392 else /* String constant format - Only available in winxp and above */
4395 pisid->Revision = SDDL_REVISION;
4397 for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++)
4398 if (!strncmpW(WellKnownSids[i].wstr, StringSid, 2))
4401 pisid->SubAuthorityCount = WellKnownSids[i].Sid.SubAuthorityCount;
4402 pisid->IdentifierAuthority = WellKnownSids[i].Sid.IdentifierAuthority;
4403 for (j = 0; j < WellKnownSids[i].Sid.SubAuthorityCount; j++)
4404 pisid->SubAuthority[j] = WellKnownSids[i].Sid.SubAuthority[j];
4409 FIXME("String constant not supported: %s\n", debugstr_wn(StringSid, 2));
4414 SetLastError(ERROR_INVALID_SID);
4416 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
4420 /******************************************************************************
4421 * GetNamedSecurityInfoA [ADVAPI32.@]
4423 DWORD WINAPI GetNamedSecurityInfoA(LPSTR pObjectName,
4424 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
4425 PSID* ppsidOwner, PSID* ppsidGroup, PACL* ppDacl, PACL* ppSacl,
4426 PSECURITY_DESCRIPTOR* ppSecurityDescriptor)
4432 TRACE("%s %d %d %p %p %p %p %p\n", pObjectName, ObjectType, SecurityInfo,
4433 ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
4437 len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
4438 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
4439 MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
4442 r = GetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, ppsidOwner,
4443 ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor );
4445 HeapFree( GetProcessHeap(), 0, wstr );
4450 /******************************************************************************
4451 * GetNamedSecurityInfoW [ADVAPI32.@]
4453 DWORD WINAPI GetNamedSecurityInfoW( LPWSTR name, SE_OBJECT_TYPE type,
4454 SECURITY_INFORMATION info, PSID* owner, PSID* group, PACL* dacl,
4455 PACL* sacl, PSECURITY_DESCRIPTOR* descriptor )
4457 DWORD needed, offset;
4458 SECURITY_DESCRIPTOR_RELATIVE *relative;
4461 TRACE( "%s %d %d %p %p %p %p %p\n", debugstr_w(name), type, info, owner,
4462 group, dacl, sacl, descriptor );
4464 if (!name || !descriptor) return ERROR_INVALID_PARAMETER;
4466 needed = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
4467 if (info & OWNER_SECURITY_INFORMATION)
4468 needed += sizeof(sidWorld);
4469 if (info & GROUP_SECURITY_INFORMATION)
4470 needed += sizeof(sidWorld);
4471 if (info & DACL_SECURITY_INFORMATION)
4472 needed += WINE_SIZE_OF_WORLD_ACCESS_ACL;
4473 if (info & SACL_SECURITY_INFORMATION)
4474 needed += WINE_SIZE_OF_WORLD_ACCESS_ACL;
4476 /* must be freed by caller */
4477 *descriptor = HeapAlloc( GetProcessHeap(), 0, needed );
4478 if (!*descriptor) return ERROR_NOT_ENOUGH_MEMORY;
4480 if (!InitializeSecurityDescriptor( *descriptor, SECURITY_DESCRIPTOR_REVISION ))
4482 HeapFree( GetProcessHeap(), 0, *descriptor );
4483 return ERROR_INVALID_SECURITY_DESCR;
4486 relative = (SECURITY_DESCRIPTOR_RELATIVE *)*descriptor;
4487 relative->Control |= SE_SELF_RELATIVE;
4488 buffer = (BYTE *)relative;
4489 offset = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
4491 if (info & OWNER_SECURITY_INFORMATION)
4493 memcpy( buffer + offset, &sidWorld, sizeof(sidWorld) );
4494 relative->Owner = offset;
4496 *owner = buffer + offset;
4497 offset += sizeof(sidWorld);
4499 if (info & GROUP_SECURITY_INFORMATION)
4501 memcpy( buffer + offset, &sidWorld, sizeof(sidWorld) );
4502 relative->Group = offset;
4504 *group = buffer + offset;
4505 offset += sizeof(sidWorld);
4507 if (info & DACL_SECURITY_INFORMATION)
4509 relative->Control |= SE_DACL_PRESENT;
4510 GetWorldAccessACL( (PACL)(buffer + offset) );
4511 relative->Dacl = offset;
4513 *dacl = (PACL)(buffer + offset);
4514 offset += WINE_SIZE_OF_WORLD_ACCESS_ACL;
4516 if (info & SACL_SECURITY_INFORMATION)
4518 relative->Control |= SE_SACL_PRESENT;
4519 GetWorldAccessACL( (PACL)(buffer + offset) );
4520 relative->Sacl = offset;
4522 *sacl = (PACL)(buffer + offset);
4524 return ERROR_SUCCESS;
4527 /******************************************************************************
4528 * DecryptFileW [ADVAPI32.@]
4530 BOOL WINAPI DecryptFileW(LPCWSTR lpFileName, DWORD dwReserved)
4532 FIXME("%s %08x\n", debugstr_w(lpFileName), dwReserved);
4536 /******************************************************************************
4537 * DecryptFileA [ADVAPI32.@]
4539 BOOL WINAPI DecryptFileA(LPCSTR lpFileName, DWORD dwReserved)
4541 FIXME("%s %08x\n", debugstr_a(lpFileName), dwReserved);
4545 /******************************************************************************
4546 * EncryptFileW [ADVAPI32.@]
4548 BOOL WINAPI EncryptFileW(LPCWSTR lpFileName)
4550 FIXME("%s\n", debugstr_w(lpFileName));
4554 /******************************************************************************
4555 * EncryptFileA [ADVAPI32.@]
4557 BOOL WINAPI EncryptFileA(LPCSTR lpFileName)
4559 FIXME("%s\n", debugstr_a(lpFileName));
4563 /******************************************************************************
4564 * FileEncryptionStatusW [ADVAPI32.@]
4566 BOOL WINAPI FileEncryptionStatusW(LPCWSTR lpFileName, LPDWORD lpStatus)
4568 FIXME("(%s %p): stub\n", debugstr_w(lpFileName), lpStatus);
4571 *lpStatus = FILE_SYSTEM_NOT_SUPPORT;
4575 /******************************************************************************
4576 * FileEncryptionStatusA [ADVAPI32.@]
4578 BOOL WINAPI FileEncryptionStatusA(LPCSTR lpFileName, LPDWORD lpStatus)
4580 FIXME("(%s %p): stub\n", debugstr_a(lpFileName), lpStatus);
4583 *lpStatus = FILE_SYSTEM_NOT_SUPPORT;
4587 /******************************************************************************
4588 * SetSecurityInfo [ADVAPI32.@]
4590 DWORD WINAPI SetSecurityInfo(HANDLE handle, SE_OBJECT_TYPE ObjectType,
4591 SECURITY_INFORMATION SecurityInfo, PSID psidOwner,
4592 PSID psidGroup, PACL pDacl, PACL pSacl) {
4594 return ERROR_SUCCESS;