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
39 #include "advapi32_misc.h"
41 #include "wine/debug.h"
42 #include "wine/unicode.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
46 static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes);
47 static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags,
48 PACL pAcl, LPDWORD cBytes);
49 static BYTE ParseAceStringFlags(LPCWSTR* StringAcl);
50 static BYTE ParseAceStringType(LPCWSTR* StringAcl);
51 static DWORD ParseAceStringRights(LPCWSTR* StringAcl);
52 static BOOL ParseStringSecurityDescriptorToSecurityDescriptor(
53 LPCWSTR StringSecurityDescriptor,
54 SECURITY_DESCRIPTOR* SecurityDescriptor,
56 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl);
58 typedef struct _ACEFLAG
62 } ACEFLAG, *LPACEFLAG;
64 typedef struct _MAX_SID
66 /* same fields as struct _SID */
68 BYTE SubAuthorityCount;
69 SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
70 DWORD SubAuthority[SID_MAX_SUB_AUTHORITIES];
73 typedef struct WELLKNOWNSID
76 WELL_KNOWN_SID_TYPE Type;
80 static const WELLKNOWNSID WellKnownSids[] =
82 { {0,0}, WinNullSid, { SID_REVISION, 1, { SECURITY_NULL_SID_AUTHORITY }, { SECURITY_NULL_RID } } },
83 { {'W','D'}, WinWorldSid, { SID_REVISION, 1, { SECURITY_WORLD_SID_AUTHORITY }, { SECURITY_WORLD_RID } } },
84 { {0,0}, WinLocalSid, { SID_REVISION, 1, { SECURITY_LOCAL_SID_AUTHORITY }, { SECURITY_LOCAL_RID } } },
85 { {'C','O'}, WinCreatorOwnerSid, { SID_REVISION, 1, { SECURITY_CREATOR_SID_AUTHORITY }, { SECURITY_CREATOR_OWNER_RID } } },
86 { {'C','G'}, WinCreatorGroupSid, { SID_REVISION, 1, { SECURITY_CREATOR_SID_AUTHORITY }, { SECURITY_CREATOR_GROUP_RID } } },
87 { {0,0}, WinCreatorOwnerServerSid, { SID_REVISION, 1, { SECURITY_CREATOR_SID_AUTHORITY }, { SECURITY_CREATOR_OWNER_SERVER_RID } } },
88 { {0,0}, WinCreatorGroupServerSid, { SID_REVISION, 1, { SECURITY_CREATOR_SID_AUTHORITY }, { SECURITY_CREATOR_GROUP_SERVER_RID } } },
89 { {0,0}, WinNtAuthoritySid, { SID_REVISION, 0, { SECURITY_NT_AUTHORITY }, { } } },
90 { {0,0}, WinDialupSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_DIALUP_RID } } },
91 { {'N','U'}, WinNetworkSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_NETWORK_RID } } },
92 { {0,0}, WinBatchSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_BATCH_RID } } },
93 { {'I','U'}, WinInteractiveSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_INTERACTIVE_RID } } },
94 { {'S','U'}, WinServiceSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_SERVICE_RID } } },
95 { {'A','N'}, WinAnonymousSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_ANONYMOUS_LOGON_RID } } },
96 { {0,0}, WinProxySid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_PROXY_RID } } },
97 { {'E','D'}, WinEnterpriseControllersSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_ENTERPRISE_CONTROLLERS_RID } } },
98 { {'P','S'}, WinSelfSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_PRINCIPAL_SELF_RID } } },
99 { {'A','U'}, WinAuthenticatedUserSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_AUTHENTICATED_USER_RID } } },
100 { {'R','C'}, WinRestrictedCodeSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_RESTRICTED_CODE_RID } } },
101 { {0,0}, WinTerminalServerSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_TERMINAL_SERVER_RID } } },
102 { {0,0}, WinRemoteLogonIdSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_REMOTE_LOGON_RID } } },
103 { {'S','Y'}, WinLocalSystemSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_LOCAL_SYSTEM_RID } } },
104 { {'L','S'}, WinLocalServiceSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_LOCAL_SERVICE_RID } } },
105 { {'N','S'}, WinNetworkServiceSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_NETWORK_SERVICE_RID } } },
106 { {0,0}, WinBuiltinDomainSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID } } },
107 { {'B','A'}, WinBuiltinAdministratorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS } } },
108 { {'B','U'}, WinBuiltinUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_USERS } } },
109 { {'B','G'}, WinBuiltinGuestsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_GUESTS } } },
110 { {'P','U'}, WinBuiltinPowerUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS } } },
111 { {'A','O'}, WinBuiltinAccountOperatorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ACCOUNT_OPS } } },
112 { {'S','O'}, WinBuiltinSystemOperatorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_SYSTEM_OPS } } },
113 { {'P','O'}, WinBuiltinPrintOperatorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_PRINT_OPS } } },
114 { {'B','O'}, WinBuiltinBackupOperatorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_BACKUP_OPS } } },
115 { {'R','E'}, WinBuiltinReplicatorSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_REPLICATOR } } },
116 { {'R','U'}, WinBuiltinPreWindows2000CompatibleAccessSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_PREW2KCOMPACCESS } } },
117 { {'R','D'}, WinBuiltinRemoteDesktopUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS } } },
118 { {'N','O'}, WinBuiltinNetworkConfigurationOperatorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS } } },
119 { {0,0}, WinNTLMAuthenticationSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_PACKAGE_BASE_RID, SECURITY_PACKAGE_NTLM_RID } } },
120 { {0,0}, WinDigestAuthenticationSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_PACKAGE_BASE_RID, SECURITY_PACKAGE_DIGEST_RID } } },
121 { {0,0}, WinSChannelAuthenticationSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_PACKAGE_BASE_RID, SECURITY_PACKAGE_SCHANNEL_RID } } },
122 { {0,0}, WinThisOrganizationSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_THIS_ORGANIZATION_RID } } },
123 { {0,0}, WinOtherOrganizationSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_OTHER_ORGANIZATION_RID } } },
124 { {0,0}, WinBuiltinPerfMonitoringUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_MONITORING_USERS } } },
125 { {0,0}, WinBuiltinPerfLoggingUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_LOGGING_USERS } } },
128 static SID const sidWorld = { SID_REVISION, 1, { SECURITY_WORLD_SID_AUTHORITY} , { SECURITY_WORLD_RID } };
130 typedef struct _AccountSid {
131 WELL_KNOWN_SID_TYPE type;
134 SID_NAME_USE name_use;
137 static const WCHAR Account_Operators[] = { 'A','c','c','o','u','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
138 static const WCHAR Administrator[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0 };
139 static const WCHAR Administrators[] = { 'A','d','m','i','n','i','s','t','r','a','t','o','r','s',0 };
140 static const WCHAR ANONYMOUS_LOGON[] = { 'A','N','O','N','Y','M','O','U','S',' ','L','O','G','O','N',0 };
141 static const WCHAR Authenticated_Users[] = { 'A','u','t','h','e','n','t','i','c','a','t','e','d',' ','U','s','e','r','s',0 };
142 static const WCHAR Backup_Operators[] = { 'B','a','c','k','u','p',' ','O','p','e','r','a','t','o','r','s',0 };
143 static const WCHAR BATCH[] = { 'B','A','T','C','H',0 };
144 static const WCHAR Blank[] = { 0 };
145 static const WCHAR BUILTIN[] = { 'B','U','I','L','T','I','N',0 };
146 static const WCHAR Cert_Publishers[] = { 'C','e','r','t',' ','P','u','b','l','i','s','h','e','r','s',0 };
147 static const WCHAR CREATOR_GROUP[] = { 'C','R','E','A','T','O','R',' ','G','R','O','U','P',0 };
148 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 };
149 static const WCHAR CREATOR_OWNER[] = { 'C','R','E','A','T','O','R',' ','O','W','N','E','R',0 };
150 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 };
151 static const WCHAR DIALUP[] = { 'D','I','A','L','U','P',0 };
152 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 };
153 static const WCHAR DOMAIN[] = {'D','O','M','A','I','N',0};
154 static const WCHAR Domain_Admins[] = { 'D','o','m','a','i','n',' ','A','d','m','i','n','s',0 };
155 static const WCHAR Domain_Computers[] = { 'D','o','m','a','i','n',' ','C','o','m','p','u','t','e','r','s',0 };
156 static const WCHAR Domain_Controllers[] = { 'D','o','m','a','i','n',' ','C','o','n','t','r','o','l','l','e','r','s',0 };
157 static const WCHAR Domain_Guests[] = { 'D','o','m','a','i','n',' ','G','u','e','s','t','s',0 };
158 static const WCHAR Domain_Users[] = { 'D','o','m','a','i','n',' ','U','s','e','r','s',0 };
159 static const WCHAR Enterprise_Admins[] = { 'E','n','t','e','r','p','r','i','s','e',' ','A','d','m','i','n','s',0 };
160 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 };
161 static const WCHAR Everyone[] = { 'E','v','e','r','y','o','n','e',0 };
162 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 };
163 static const WCHAR Guest[] = { 'G','u','e','s','t',0 };
164 static const WCHAR Guests[] = { 'G','u','e','s','t','s',0 };
165 static const WCHAR INTERACTIVE[] = { 'I','N','T','E','R','A','C','T','I','V','E',0 };
166 static const WCHAR LOCAL[] = { 'L','O','C','A','L',0 };
167 static const WCHAR LOCAL_SERVICE[] = { 'L','O','C','A','L',' ','S','E','R','V','I','C','E',0 };
168 static const WCHAR NETWORK[] = { 'N','E','T','W','O','R','K',0 };
169 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 };
170 static const WCHAR NETWORK_SERVICE[] = { 'N','E','T','W','O','R','K',' ','S','E','R','V','I','C','E',0 };
171 static const WCHAR NT_AUTHORITY[] = { 'N','T',' ','A','U','T','H','O','R','I','T','Y',0 };
172 static const WCHAR NT_Pseudo_Domain[] = { 'N','T',' ','P','s','e','u','d','o',' ','D','o','m','a','i','n',0 };
173 static const WCHAR NTML_Authentication[] = { 'N','T','M','L',' ','A','u','t','h','e','n','t','i','c','a','t','i','o','n',0 };
174 static const WCHAR NULL_SID[] = { 'N','U','L','L',' ','S','I','D',0 };
175 static const WCHAR Other_Organization[] = { 'O','t','h','e','r',' ','O','r','g','a','n','i','z','a','t','i','o','n',0 };
176 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 };
177 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 };
178 static const WCHAR Power_Users[] = { 'P','o','w','e','r',' ','U','s','e','r','s',0 };
179 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 };
180 static const WCHAR Print_Operators[] = { 'P','r','i','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
181 static const WCHAR PROXY[] = { 'P','R','O','X','Y',0 };
182 static const WCHAR RAS_and_IAS_Servers[] = { 'R','A','S',' ','a','n','d',' ','I','A','S',' ','S','e','r','v','e','r','s',0 };
183 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 };
184 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 };
185 static const WCHAR Replicators[] = { 'R','e','p','l','i','c','a','t','o','r','s',0 };
186 static const WCHAR RESTRICTED[] = { 'R','E','S','T','R','I','C','T','E','D',0 };
187 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 };
188 static const WCHAR Schema_Admins[] = { 'S','c','h','e','m','a',' ','A','d','m','i','n','s',0 };
189 static const WCHAR SELF[] = { 'S','E','L','F',0 };
190 static const WCHAR Server_Operators[] = { 'S','e','r','v','e','r',' ','O','p','e','r','a','t','o','r','s',0 };
191 static const WCHAR SERVICE[] = { 'S','E','R','V','I','C','E',0 };
192 static const WCHAR SYSTEM[] = { 'S','Y','S','T','E','M',0 };
193 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 };
194 static const WCHAR This_Organization[] = { 'T','h','i','s',' ','O','r','g','a','n','i','z','a','t','i','o','n',0 };
195 static const WCHAR Users[] = { 'U','s','e','r','s',0 };
197 static const AccountSid ACCOUNT_SIDS[] = {
198 { WinNullSid, NULL_SID, Blank, SidTypeWellKnownGroup },
199 { WinWorldSid, Everyone, Blank, SidTypeWellKnownGroup },
200 { WinLocalSid, LOCAL, Blank, SidTypeWellKnownGroup },
201 { WinCreatorOwnerSid, CREATOR_OWNER, Blank, SidTypeWellKnownGroup },
202 { WinCreatorGroupSid, CREATOR_GROUP, Blank, SidTypeWellKnownGroup },
203 { WinCreatorOwnerServerSid, CREATOR_OWNER_SERVER, Blank, SidTypeWellKnownGroup },
204 { WinCreatorGroupServerSid, CREATOR_GROUP_SERVER, Blank, SidTypeWellKnownGroup },
205 { WinNtAuthoritySid, NT_Pseudo_Domain, NT_Pseudo_Domain, SidTypeDomain },
206 { WinDialupSid, DIALUP, NT_AUTHORITY, SidTypeWellKnownGroup },
207 { WinNetworkSid, NETWORK, NT_AUTHORITY, SidTypeWellKnownGroup },
208 { WinBatchSid, BATCH, NT_AUTHORITY, SidTypeWellKnownGroup },
209 { WinInteractiveSid, INTERACTIVE, NT_AUTHORITY, SidTypeWellKnownGroup },
210 { WinServiceSid, SERVICE, NT_AUTHORITY, SidTypeWellKnownGroup },
211 { WinAnonymousSid, ANONYMOUS_LOGON, NT_AUTHORITY, SidTypeWellKnownGroup },
212 { WinProxySid, PROXY, NT_AUTHORITY, SidTypeWellKnownGroup },
213 { WinEnterpriseControllersSid, ENTERPRISE_DOMAIN_CONTROLLERS, NT_AUTHORITY, SidTypeWellKnownGroup },
214 { WinSelfSid, SELF, NT_AUTHORITY, SidTypeWellKnownGroup },
215 { WinAuthenticatedUserSid, Authenticated_Users, NT_AUTHORITY, SidTypeWellKnownGroup },
216 { WinRestrictedCodeSid, RESTRICTED, NT_AUTHORITY, SidTypeWellKnownGroup },
217 { WinTerminalServerSid, TERMINAL_SERVER_USER, NT_AUTHORITY, SidTypeWellKnownGroup },
218 { WinRemoteLogonIdSid, REMOTE_INTERACTIVE_LOGON, NT_AUTHORITY, SidTypeWellKnownGroup },
219 { WinLocalSystemSid, SYSTEM, NT_AUTHORITY, SidTypeWellKnownGroup },
220 { WinLocalServiceSid, LOCAL_SERVICE, NT_AUTHORITY, SidTypeWellKnownGroup },
221 { WinNetworkServiceSid, NETWORK_SERVICE, NT_AUTHORITY, SidTypeWellKnownGroup },
222 { WinBuiltinDomainSid, BUILTIN, BUILTIN, SidTypeDomain },
223 { WinBuiltinAdministratorsSid, Administrators, BUILTIN, SidTypeAlias },
224 { WinBuiltinUsersSid, Users, BUILTIN, SidTypeAlias },
225 { WinBuiltinGuestsSid, Guests, BUILTIN, SidTypeAlias },
226 { WinBuiltinPowerUsersSid, Power_Users, BUILTIN, SidTypeAlias },
227 { WinBuiltinAccountOperatorsSid, Account_Operators, BUILTIN, SidTypeAlias },
228 { WinBuiltinSystemOperatorsSid, Server_Operators, BUILTIN, SidTypeAlias },
229 { WinBuiltinPrintOperatorsSid, Print_Operators, BUILTIN, SidTypeAlias },
230 { WinBuiltinBackupOperatorsSid, Backup_Operators, BUILTIN, SidTypeAlias },
231 { WinBuiltinReplicatorSid, Replicators, BUILTIN, SidTypeAlias },
232 { WinBuiltinPreWindows2000CompatibleAccessSid, Pre_Windows_2000_Compatible_Access, BUILTIN, SidTypeAlias },
233 { WinBuiltinRemoteDesktopUsersSid, Remote_Desktop_Users, BUILTIN, SidTypeAlias },
234 { WinBuiltinNetworkConfigurationOperatorsSid, Network_Configuration_Operators, BUILTIN, SidTypeAlias },
235 { WinNTLMAuthenticationSid, NTML_Authentication, NT_AUTHORITY, SidTypeWellKnownGroup },
236 { WinDigestAuthenticationSid, Digest_Authentication, NT_AUTHORITY, SidTypeWellKnownGroup },
237 { WinSChannelAuthenticationSid, SChannel_Authentication, NT_AUTHORITY, SidTypeWellKnownGroup },
238 { WinThisOrganizationSid, This_Organization, NT_AUTHORITY, SidTypeWellKnownGroup },
239 { WinOtherOrganizationSid, Other_Organization, NT_AUTHORITY, SidTypeWellKnownGroup },
240 { WinBuiltinPerfMonitoringUsersSid, Performance_Monitor_Users, BUILTIN, SidTypeAlias },
241 { WinBuiltinPerfLoggingUsersSid, Performance_Log_Users, BUILTIN, SidTypeAlias },
246 static const WCHAR SDDL_READ_CONTROL[] = {'R','C',0};
247 static const WCHAR SDDL_WRITE_DAC[] = {'W','D',0};
248 static const WCHAR SDDL_WRITE_OWNER[] = {'W','O',0};
249 static const WCHAR SDDL_STANDARD_DELETE[] = {'S','D',0};
250 static const WCHAR SDDL_GENERIC_ALL[] = {'G','A',0};
251 static const WCHAR SDDL_GENERIC_READ[] = {'G','R',0};
252 static const WCHAR SDDL_GENERIC_WRITE[] = {'G','W',0};
253 static const WCHAR SDDL_GENERIC_EXECUTE[] = {'G','X',0};
258 static const WCHAR SDDL_ACCESS_ALLOWED[] = {'A',0};
259 static const WCHAR SDDL_ACCESS_DENIED[] = {'D',0};
260 static const WCHAR SDDL_OBJECT_ACCESS_ALLOWED[] = {'O','A',0};
261 static const WCHAR SDDL_OBJECT_ACCESS_DENIED[] = {'O','D',0};
262 static const WCHAR SDDL_AUDIT[] = {'A','U',0};
263 static const WCHAR SDDL_ALARM[] = {'A','L',0};
264 static const WCHAR SDDL_OBJECT_AUDIT[] = {'O','U',0};
265 static const WCHAR SDDL_OBJECT_ALARMp[] = {'O','L',0};
270 static const WCHAR SDDL_CONTAINER_INHERIT[] = {'C','I',0};
271 static const WCHAR SDDL_OBJECT_INHERIT[] = {'O','I',0};
272 static const WCHAR SDDL_NO_PROPAGATE[] = {'N','P',0};
273 static const WCHAR SDDL_INHERIT_ONLY[] = {'I','O',0};
274 static const WCHAR SDDL_INHERITED[] = {'I','D',0};
275 static const WCHAR SDDL_AUDIT_SUCCESS[] = {'S','A',0};
276 static const WCHAR SDDL_AUDIT_FAILURE[] = {'F','A',0};
278 const char * debugstr_sid(PSID sid)
281 SID * psid = (SID *)sid;
286 auth = psid->IdentifierAuthority.Value[5] +
287 (psid->IdentifierAuthority.Value[4] << 8) +
288 (psid->IdentifierAuthority.Value[3] << 16) +
289 (psid->IdentifierAuthority.Value[2] << 24);
291 switch (psid->SubAuthorityCount) {
293 return wine_dbg_sprintf("S-%d-%d", psid->Revision, auth);
295 return wine_dbg_sprintf("S-%d-%d-%lu", psid->Revision, auth,
296 psid->SubAuthority[0]);
298 return wine_dbg_sprintf("S-%d-%d-%lu-%lu", psid->Revision, auth,
299 psid->SubAuthority[0], psid->SubAuthority[1]);
301 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu", psid->Revision, auth,
302 psid->SubAuthority[0], psid->SubAuthority[1], psid->SubAuthority[2]);
304 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu-%lu", psid->Revision, auth,
305 psid->SubAuthority[0], psid->SubAuthority[1], psid->SubAuthority[2],
306 psid->SubAuthority[3]);
308 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu-%lu-%lu", psid->Revision, auth,
309 psid->SubAuthority[0], psid->SubAuthority[1], psid->SubAuthority[2],
310 psid->SubAuthority[3], psid->SubAuthority[4]);
312 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu-%lu-%lu-%lu", psid->Revision, auth,
313 psid->SubAuthority[3], psid->SubAuthority[1], psid->SubAuthority[2],
314 psid->SubAuthority[0], psid->SubAuthority[4], psid->SubAuthority[5]);
316 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu-%lu-%lu-%lu-%lu", psid->Revision, auth,
317 psid->SubAuthority[0], psid->SubAuthority[1], psid->SubAuthority[2],
318 psid->SubAuthority[3], psid->SubAuthority[4], psid->SubAuthority[5],
319 psid->SubAuthority[6]);
321 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu-%lu-%lu-%lu-%lu-%lu", psid->Revision, auth,
322 psid->SubAuthority[0], psid->SubAuthority[1], psid->SubAuthority[2],
323 psid->SubAuthority[3], psid->SubAuthority[4], psid->SubAuthority[5],
324 psid->SubAuthority[6], psid->SubAuthority[7]);
329 /* set last error code from NT status and get the proper boolean return value */
330 /* used for functions that are a simple wrapper around the corresponding ntdll API */
331 static inline BOOL set_ntstatus( NTSTATUS status )
333 if (status) SetLastError( RtlNtStatusToDosError( status ));
337 #define WINE_SIZE_OF_WORLD_ACCESS_ACL (sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD))
339 static void GetWorldAccessACL(PACL pACL)
341 PACCESS_ALLOWED_ACE pACE = (PACCESS_ALLOWED_ACE) (pACL + 1);
343 pACL->AclRevision = ACL_REVISION;
345 pACL->AclSize = WINE_SIZE_OF_WORLD_ACCESS_ACL;
349 pACE->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
350 pACE->Header.AceFlags = CONTAINER_INHERIT_ACE;
351 pACE->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD);
352 pACE->Mask = 0xf3ffffff; /* Everything except reserved bits */
353 memcpy(&pACE->SidStart, &sidWorld, sizeof(sidWorld));
356 /************************************************************
357 * ADVAPI_IsLocalComputer
359 * Checks whether the server name indicates local machine.
361 BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName)
363 DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
367 if (!ServerName || !ServerName[0])
370 buf = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
371 Result = GetComputerNameW(buf, &dwSize);
372 if (Result && (ServerName[0] == '\\') && (ServerName[1] == '\\'))
374 Result = Result && !lstrcmpW(ServerName, buf);
375 HeapFree(GetProcessHeap(), 0, buf);
380 /************************************************************
381 * ADVAPI_GetComputerSid
383 * Reads the computer SID from the registry.
385 BOOL ADVAPI_GetComputerSid(PSID sid)
389 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 };
390 static const WCHAR V[] = { 'V',0 };
392 if ((ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, Account, 0,
393 KEY_READ, &key)) == ERROR_SUCCESS)
396 ret = RegQueryValueExW(key, V, NULL, NULL, NULL, &size);
397 if (ret == ERROR_MORE_DATA || ret == ERROR_SUCCESS)
399 BYTE * data = HeapAlloc(GetProcessHeap(), 0, size);
402 if ((ret = RegQueryValueExW(key, V, NULL, NULL,
403 data, &size)) == ERROR_SUCCESS)
405 /* the SID is in the last 24 bytes of the binary data */
406 CopyMemory(sid, &data[size-24], 24);
407 HeapFree(GetProcessHeap(), 0, data);
411 HeapFree(GetProcessHeap(), 0, data);
417 /* create a new random SID */
418 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, Account,
419 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL) == ERROR_SUCCESS)
422 SID_IDENTIFIER_AUTHORITY identifierAuthority = {SECURITY_NT_AUTHORITY};
425 if (RtlGenRandom(&id, sizeof(id)))
427 if (AllocateAndInitializeSid(&identifierAuthority, 4, SECURITY_NT_NON_UNIQUE, id[0], id[1], id[2], 0, 0, 0, 0, &new_sid))
429 if (RegSetValueExW(key, V, 0, REG_BINARY, new_sid, GetLengthSid(new_sid)) == ERROR_SUCCESS)
433 return CopySid(GetLengthSid(new_sid), sid, &new_sid);
444 /* ##############################
445 ###### TOKEN FUNCTIONS ######
446 ##############################
449 /******************************************************************************
450 * OpenProcessToken [ADVAPI32.@]
451 * Opens the access token associated with a process handle.
454 * ProcessHandle [I] Handle to process
455 * DesiredAccess [I] Desired access to process
456 * TokenHandle [O] Pointer to handle of open access token
459 * Success: TRUE. TokenHandle contains the access token.
463 * See NtOpenProcessToken.
466 OpenProcessToken( HANDLE ProcessHandle, DWORD DesiredAccess,
467 HANDLE *TokenHandle )
469 return set_ntstatus(NtOpenProcessToken( ProcessHandle, DesiredAccess, TokenHandle ));
472 /******************************************************************************
473 * OpenThreadToken [ADVAPI32.@]
475 * Opens the access token associated with a thread handle.
478 * ThreadHandle [I] Handle to process
479 * DesiredAccess [I] Desired access to the thread
481 * TokenHandle [O] Destination for the token handle
484 * Success: TRUE. TokenHandle contains the access token.
488 * See NtOpenThreadToken.
491 OpenThreadToken( HANDLE ThreadHandle, DWORD DesiredAccess,
492 BOOL OpenAsSelf, HANDLE *TokenHandle)
494 return set_ntstatus( NtOpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle));
498 AdjustTokenGroups( HANDLE TokenHandle, BOOL ResetToDefault, PTOKEN_GROUPS NewState,
499 DWORD BufferLength, PTOKEN_GROUPS PreviousState, PDWORD ReturnLength )
501 return set_ntstatus( NtAdjustGroupsToken(TokenHandle, ResetToDefault, NewState, BufferLength,
502 PreviousState, ReturnLength));
505 /******************************************************************************
506 * AdjustTokenPrivileges [ADVAPI32.@]
508 * Adjust the privileges of an open token handle.
511 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
512 * DisableAllPrivileges [I] TRUE=Remove all privileges, FALSE=Use NewState
513 * NewState [I] Desired new privileges of the token
514 * BufferLength [I] Length of NewState
515 * PreviousState [O] Destination for the previous state
516 * ReturnLength [I/O] Size of PreviousState
520 * Success: TRUE. Privileges are set to NewState and PreviousState is updated.
524 * See NtAdjustPrivilegesToken.
527 AdjustTokenPrivileges( HANDLE TokenHandle, BOOL DisableAllPrivileges,
528 LPVOID NewState, DWORD BufferLength,
529 LPVOID PreviousState, LPDWORD ReturnLength )
535 status = NtAdjustPrivilegesToken(TokenHandle, DisableAllPrivileges,
536 NewState, BufferLength, PreviousState,
538 SetLastError( RtlNtStatusToDosError( status ));
539 if ((status == STATUS_SUCCESS) || (status == STATUS_NOT_ALL_ASSIGNED))
545 /******************************************************************************
546 * CheckTokenMembership [ADVAPI32.@]
548 * Determine if an access token is a member of a SID.
551 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
552 * SidToCheck [I] SID that possibly contains the token
553 * IsMember [O] Destination for result.
556 * Success: TRUE. IsMember is TRUE if TokenHandle is a member, FALSE otherwise.
560 CheckTokenMembership( HANDLE TokenHandle, PSID SidToCheck,
563 FIXME("(%p %p %p) stub!\n", TokenHandle, SidToCheck, IsMember);
569 /******************************************************************************
570 * GetTokenInformation [ADVAPI32.@]
572 * Get a type of information about an access token.
575 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
576 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
577 * tokeninfo [O] Destination for token information
578 * tokeninfolength [I] Length of tokeninfo
579 * retlen [O] Destination for returned token information length
582 * Success: TRUE. tokeninfo contains retlen bytes of token information
586 * See NtQueryInformationToken.
589 GetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
590 LPVOID tokeninfo, DWORD tokeninfolength, LPDWORD retlen )
592 TRACE("(%p, %s, %p, %ld, %p):\n",
594 (tokeninfoclass == TokenUser) ? "TokenUser" :
595 (tokeninfoclass == TokenGroups) ? "TokenGroups" :
596 (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
597 (tokeninfoclass == TokenOwner) ? "TokenOwner" :
598 (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
599 (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
600 (tokeninfoclass == TokenSource) ? "TokenSource" :
601 (tokeninfoclass == TokenType) ? "TokenType" :
602 (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
603 (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
604 (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
605 (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
606 (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
607 (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
608 (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
610 tokeninfo, tokeninfolength, retlen);
611 return set_ntstatus( NtQueryInformationToken( token, tokeninfoclass, tokeninfo,
612 tokeninfolength, retlen));
615 /******************************************************************************
616 * SetTokenInformation [ADVAPI32.@]
618 * Set information for an access token.
621 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
622 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
623 * tokeninfo [I] Token information to set
624 * tokeninfolength [I] Length of tokeninfo
627 * Success: TRUE. The information for the token is set to tokeninfo.
631 SetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
632 LPVOID tokeninfo, DWORD tokeninfolength )
634 TRACE("(%p, %s, %p, %ld): stub\n",
636 (tokeninfoclass == TokenUser) ? "TokenUser" :
637 (tokeninfoclass == TokenGroups) ? "TokenGroups" :
638 (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
639 (tokeninfoclass == TokenOwner) ? "TokenOwner" :
640 (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
641 (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
642 (tokeninfoclass == TokenSource) ? "TokenSource" :
643 (tokeninfoclass == TokenType) ? "TokenType" :
644 (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
645 (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
646 (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
647 (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
648 (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
649 (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
650 (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
652 tokeninfo, tokeninfolength);
654 return set_ntstatus( NtSetInformationToken( token, tokeninfoclass, tokeninfo, tokeninfolength ));
657 /*************************************************************************
658 * SetThreadToken [ADVAPI32.@]
660 * Assigns an 'impersonation token' to a thread so it can assume the
661 * security privileges of another thread or process. Can also remove
662 * a previously assigned token.
665 * thread [O] Handle to thread to set the token for
666 * token [I] Token to set
669 * Success: TRUE. The threads access token is set to token
673 * Only supported on NT or higher. On Win9X this function does nothing.
674 * See SetTokenInformation.
676 BOOL WINAPI SetThreadToken(PHANDLE thread, HANDLE token)
678 return set_ntstatus( NtSetInformationThread( thread ? *thread : GetCurrentThread(),
679 ThreadImpersonationToken, &token, sizeof token ));
682 /* ##############################
683 ###### SID FUNCTIONS ######
684 ##############################
687 /******************************************************************************
688 * AllocateAndInitializeSid [ADVAPI32.@]
691 * pIdentifierAuthority []
692 * nSubAuthorityCount []
704 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
705 BYTE nSubAuthorityCount,
706 DWORD nSubAuthority0, DWORD nSubAuthority1,
707 DWORD nSubAuthority2, DWORD nSubAuthority3,
708 DWORD nSubAuthority4, DWORD nSubAuthority5,
709 DWORD nSubAuthority6, DWORD nSubAuthority7,
712 return set_ntstatus( RtlAllocateAndInitializeSid(
713 pIdentifierAuthority, nSubAuthorityCount,
714 nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3,
715 nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7,
719 /******************************************************************************
720 * FreeSid [ADVAPI32.@]
729 return NULL; /* is documented like this */
732 /******************************************************************************
733 * CopySid [ADVAPI32.@]
736 * nDestinationSidLength []
741 CopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
743 return RtlCopySid(nDestinationSidLength, pDestinationSid, pSourceSid);
746 /******************************************************************************
747 * CreateWellKnownSid [ADVAPI32.@]
750 CreateWellKnownSid( WELL_KNOWN_SID_TYPE WellKnownSidType,
756 TRACE("(%d, %s, %p, %p)\n", WellKnownSidType, debugstr_sid(DomainSid), pSid, cbSid);
758 if (DomainSid != NULL) {
759 FIXME("Only local computer supported!\n");
760 SetLastError(ERROR_INVALID_PARAMETER); /* FIXME */
764 if (cbSid == NULL || pSid == NULL) {
765 SetLastError(ERROR_INVALID_PARAMETER);
769 for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++) {
770 if (WellKnownSids[i].Type == WellKnownSidType) {
771 DWORD length = GetSidLengthRequired(WellKnownSids[i].Sid.SubAuthorityCount);
773 if (*cbSid < length) {
774 SetLastError(ERROR_INSUFFICIENT_BUFFER);
778 CopyMemory(pSid, &WellKnownSids[i].Sid.Revision, length);
784 SetLastError(ERROR_INVALID_PARAMETER);
788 /******************************************************************************
789 * IsWellKnownSid [ADVAPI32.@]
792 IsWellKnownSid( PSID pSid, WELL_KNOWN_SID_TYPE WellKnownSidType )
795 TRACE("(%s, %d)\n", debugstr_sid(pSid), WellKnownSidType);
797 for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++)
798 if (WellKnownSids[i].Type == WellKnownSidType)
799 if (EqualSid(pSid, (PSID)&(WellKnownSids[i].Sid.Revision)))
806 IsTokenRestricted( HANDLE TokenHandle )
808 TOKEN_GROUPS *groups;
813 TRACE("(%p)\n", TokenHandle);
815 status = NtQueryInformationToken(TokenHandle, TokenRestrictedSids, NULL, 0, &size);
816 if (status != STATUS_BUFFER_TOO_SMALL)
819 groups = HeapAlloc(GetProcessHeap(), 0, size);
822 SetLastError(ERROR_OUTOFMEMORY);
826 status = NtQueryInformationToken(TokenHandle, TokenRestrictedSids, groups, size, &size);
827 if (status != STATUS_SUCCESS)
829 HeapFree(GetProcessHeap(), 0, groups);
830 return set_ntstatus(status);
833 if (groups->GroupCount)
838 HeapFree(GetProcessHeap(), 0, groups);
843 /******************************************************************************
844 * IsValidSid [ADVAPI32.@]
850 IsValidSid( PSID pSid )
852 return RtlValidSid( pSid );
855 /******************************************************************************
856 * EqualSid [ADVAPI32.@]
863 EqualSid( PSID pSid1, PSID pSid2 )
865 return RtlEqualSid( pSid1, pSid2 );
868 /******************************************************************************
869 * EqualPrefixSid [ADVAPI32.@]
871 BOOL WINAPI EqualPrefixSid (PSID pSid1, PSID pSid2)
873 return RtlEqualPrefixSid(pSid1, pSid2);
876 /******************************************************************************
877 * GetSidLengthRequired [ADVAPI32.@]
880 * nSubAuthorityCount []
883 GetSidLengthRequired( BYTE nSubAuthorityCount )
885 return RtlLengthRequiredSid(nSubAuthorityCount);
888 /******************************************************************************
889 * InitializeSid [ADVAPI32.@]
892 * pIdentifierAuthority []
897 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
898 BYTE nSubAuthorityCount)
900 return RtlInitializeSid(pSid, pIdentifierAuthority, nSubAuthorityCount);
904 GetEffectiveRightsFromAclA( PACL pacl, PTRUSTEEA pTrustee, PACCESS_MASK pAccessRights )
906 FIXME("%p %p %p - stub\n", pacl, pTrustee, pAccessRights);
912 GetEffectiveRightsFromAclW( PACL pacl, PTRUSTEEW pTrustee, PACCESS_MASK pAccessRights )
914 FIXME("%p %p %p - stub\n", pacl, pTrustee, pAccessRights);
919 /******************************************************************************
920 * GetSidIdentifierAuthority [ADVAPI32.@]
925 PSID_IDENTIFIER_AUTHORITY WINAPI
926 GetSidIdentifierAuthority( PSID pSid )
928 return RtlIdentifierAuthoritySid(pSid);
931 /******************************************************************************
932 * GetSidSubAuthority [ADVAPI32.@]
939 GetSidSubAuthority( PSID pSid, DWORD nSubAuthority )
941 return RtlSubAuthoritySid(pSid, nSubAuthority);
944 /******************************************************************************
945 * GetSidSubAuthorityCount [ADVAPI32.@]
951 GetSidSubAuthorityCount (PSID pSid)
953 return RtlSubAuthorityCountSid(pSid);
956 /******************************************************************************
957 * GetLengthSid [ADVAPI32.@]
963 GetLengthSid (PSID pSid)
965 return RtlLengthSid(pSid);
968 /* ##############################################
969 ###### SECURITY DESCRIPTOR FUNCTIONS ######
970 ##############################################
973 /******************************************************************************
974 * BuildSecurityDescriptorA [ADVAPI32.@]
981 * cCountOfAccessEntries [I]
982 * pListOfAccessEntries [I]
983 * cCountOfAuditEntries [I]
984 * pListofAuditEntries [I]
986 * lpdwBufferLength [I/O]
990 * Success: ERROR_SUCCESS
991 * Failure: nonzero error code from Winerror.h
993 DWORD WINAPI BuildSecurityDescriptorA(
996 IN ULONG cCountOfAccessEntries,
997 IN PEXPLICIT_ACCESSA pListOfAccessEntries,
998 IN ULONG cCountOfAuditEntries,
999 IN PEXPLICIT_ACCESSA pListofAuditEntries,
1000 IN PSECURITY_DESCRIPTOR pOldSD,
1001 IN OUT PULONG lpdwBufferLength,
1002 OUT PSECURITY_DESCRIPTOR* pNewSD)
1004 FIXME("(%p,%p,%ld,%p,%ld,%p,%p,%p,%p) stub!\n",pOwner,pGroup,
1005 cCountOfAccessEntries,pListOfAccessEntries,cCountOfAuditEntries,
1006 pListofAuditEntries,pOldSD,lpdwBufferLength,pNewSD);
1008 return ERROR_CALL_NOT_IMPLEMENTED;
1011 /******************************************************************************
1012 * BuildSecurityDescriptorW [ADVAPI32.@]
1014 * See BuildSecurityDescriptorA.
1016 DWORD WINAPI BuildSecurityDescriptorW(
1017 IN PTRUSTEEW pOwner,
1018 IN PTRUSTEEW pGroup,
1019 IN ULONG cCountOfAccessEntries,
1020 IN PEXPLICIT_ACCESSW pListOfAccessEntries,
1021 IN ULONG cCountOfAuditEntries,
1022 IN PEXPLICIT_ACCESSW pListofAuditEntries,
1023 IN PSECURITY_DESCRIPTOR pOldSD,
1024 IN OUT PULONG lpdwBufferLength,
1025 OUT PSECURITY_DESCRIPTOR* pNewSD)
1027 FIXME("(%p,%p,%ld,%p,%ld,%p,%p,%p,%p) stub!\n",pOwner,pGroup,
1028 cCountOfAccessEntries,pListOfAccessEntries,cCountOfAuditEntries,
1029 pListofAuditEntries,pOldSD,lpdwBufferLength,pNewSD);
1031 return ERROR_CALL_NOT_IMPLEMENTED;
1034 /******************************************************************************
1035 * InitializeSecurityDescriptor [ADVAPI32.@]
1042 InitializeSecurityDescriptor( PSECURITY_DESCRIPTOR pDescr, DWORD revision )
1044 return set_ntstatus( RtlCreateSecurityDescriptor(pDescr, revision ));
1048 /******************************************************************************
1049 * MakeAbsoluteSD [ADVAPI32.@]
1051 BOOL WINAPI MakeAbsoluteSD (
1052 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
1053 OUT PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
1054 OUT LPDWORD lpdwAbsoluteSecurityDescriptorSize,
1056 OUT LPDWORD lpdwDaclSize,
1058 OUT LPDWORD lpdwSaclSize,
1060 OUT LPDWORD lpdwOwnerSize,
1061 OUT PSID pPrimaryGroup,
1062 OUT LPDWORD lpdwPrimaryGroupSize)
1064 return set_ntstatus( RtlSelfRelativeToAbsoluteSD(pSelfRelativeSecurityDescriptor,
1065 pAbsoluteSecurityDescriptor,
1066 lpdwAbsoluteSecurityDescriptorSize,
1067 pDacl, lpdwDaclSize, pSacl, lpdwSaclSize,
1068 pOwner, lpdwOwnerSize,
1069 pPrimaryGroup, lpdwPrimaryGroupSize));
1072 /******************************************************************************
1073 * GetKernelObjectSecurity [ADVAPI32.@]
1075 BOOL WINAPI GetKernelObjectSecurity(
1077 SECURITY_INFORMATION RequestedInformation,
1078 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1080 LPDWORD lpnLengthNeeded )
1082 TRACE("(%p,0x%08lx,%p,0x%08lx,%p)\n", Handle, RequestedInformation,
1083 pSecurityDescriptor, nLength, lpnLengthNeeded);
1085 return set_ntstatus( NtQuerySecurityObject(Handle, RequestedInformation, pSecurityDescriptor,
1086 nLength, lpnLengthNeeded ));
1089 /******************************************************************************
1090 * GetPrivateObjectSecurity [ADVAPI32.@]
1092 BOOL WINAPI GetPrivateObjectSecurity(
1093 PSECURITY_DESCRIPTOR ObjectDescriptor,
1094 SECURITY_INFORMATION SecurityInformation,
1095 PSECURITY_DESCRIPTOR ResultantDescriptor,
1096 DWORD DescriptorLength,
1097 PDWORD ReturnLength )
1099 TRACE("(%p,0x%08lx,%p,0x%08lx,%p)\n", ObjectDescriptor, SecurityInformation,
1100 ResultantDescriptor, DescriptorLength, ReturnLength);
1102 return set_ntstatus( NtQuerySecurityObject(ObjectDescriptor, SecurityInformation,
1103 ResultantDescriptor, DescriptorLength, ReturnLength ));
1106 /******************************************************************************
1107 * GetSecurityDescriptorLength [ADVAPI32.@]
1109 DWORD WINAPI GetSecurityDescriptorLength( PSECURITY_DESCRIPTOR pDescr)
1111 return RtlLengthSecurityDescriptor(pDescr);
1114 /******************************************************************************
1115 * GetSecurityDescriptorOwner [ADVAPI32.@]
1119 * lpbOwnerDefaulted []
1122 GetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pDescr, PSID *pOwner,
1123 LPBOOL lpbOwnerDefaulted )
1126 BOOL ret = set_ntstatus( RtlGetOwnerSecurityDescriptor( pDescr, pOwner, &defaulted ));
1127 *lpbOwnerDefaulted = defaulted;
1131 /******************************************************************************
1132 * SetSecurityDescriptorOwner [ADVAPI32.@]
1136 BOOL WINAPI SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor,
1137 PSID pOwner, BOOL bOwnerDefaulted)
1139 return set_ntstatus( RtlSetOwnerSecurityDescriptor(pSecurityDescriptor, pOwner, bOwnerDefaulted));
1141 /******************************************************************************
1142 * GetSecurityDescriptorGroup [ADVAPI32.@]
1144 BOOL WINAPI GetSecurityDescriptorGroup(
1145 PSECURITY_DESCRIPTOR SecurityDescriptor,
1147 LPBOOL GroupDefaulted)
1150 BOOL ret = set_ntstatus( RtlGetGroupSecurityDescriptor(SecurityDescriptor, Group, &defaulted ));
1151 *GroupDefaulted = defaulted;
1154 /******************************************************************************
1155 * SetSecurityDescriptorGroup [ADVAPI32.@]
1157 BOOL WINAPI SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor,
1158 PSID Group, BOOL GroupDefaulted)
1160 return set_ntstatus( RtlSetGroupSecurityDescriptor( SecurityDescriptor, Group, GroupDefaulted));
1163 /******************************************************************************
1164 * IsValidSecurityDescriptor [ADVAPI32.@]
1170 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor )
1172 return set_ntstatus( RtlValidSecurityDescriptor(SecurityDescriptor));
1175 /******************************************************************************
1176 * GetSecurityDescriptorDacl [ADVAPI32.@]
1178 BOOL WINAPI GetSecurityDescriptorDacl(
1179 IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
1180 OUT LPBOOL lpbDaclPresent,
1182 OUT LPBOOL lpbDaclDefaulted)
1184 BOOLEAN present, defaulted;
1185 BOOL ret = set_ntstatus( RtlGetDaclSecurityDescriptor(pSecurityDescriptor, &present, pDacl, &defaulted));
1186 *lpbDaclPresent = present;
1187 *lpbDaclDefaulted = defaulted;
1191 /******************************************************************************
1192 * SetSecurityDescriptorDacl [ADVAPI32.@]
1195 SetSecurityDescriptorDacl (
1196 PSECURITY_DESCRIPTOR lpsd,
1199 BOOL dacldefaulted )
1201 return set_ntstatus( RtlSetDaclSecurityDescriptor (lpsd, daclpresent, dacl, dacldefaulted ) );
1203 /******************************************************************************
1204 * GetSecurityDescriptorSacl [ADVAPI32.@]
1206 BOOL WINAPI GetSecurityDescriptorSacl(
1207 IN PSECURITY_DESCRIPTOR lpsd,
1208 OUT LPBOOL lpbSaclPresent,
1210 OUT LPBOOL lpbSaclDefaulted)
1212 BOOLEAN present, defaulted;
1213 BOOL ret = set_ntstatus( RtlGetSaclSecurityDescriptor(lpsd, &present, pSacl, &defaulted) );
1214 *lpbSaclPresent = present;
1215 *lpbSaclDefaulted = defaulted;
1219 /**************************************************************************
1220 * SetSecurityDescriptorSacl [ADVAPI32.@]
1222 BOOL WINAPI SetSecurityDescriptorSacl (
1223 PSECURITY_DESCRIPTOR lpsd,
1228 return set_ntstatus (RtlSetSaclSecurityDescriptor(lpsd, saclpresent, lpsacl, sacldefaulted));
1230 /******************************************************************************
1231 * MakeSelfRelativeSD [ADVAPI32.@]
1240 IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
1241 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
1242 IN OUT LPDWORD lpdwBufferLength)
1244 return set_ntstatus( RtlMakeSelfRelativeSD( pAbsoluteSecurityDescriptor,
1245 pSelfRelativeSecurityDescriptor, lpdwBufferLength));
1248 /******************************************************************************
1249 * GetSecurityDescriptorControl [ADVAPI32.@]
1252 BOOL WINAPI GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR pSecurityDescriptor,
1253 PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision)
1255 return set_ntstatus( RtlGetControlSecurityDescriptor(pSecurityDescriptor,pControl,lpdwRevision));
1258 /* ##############################
1259 ###### ACL FUNCTIONS ######
1260 ##############################
1263 /*************************************************************************
1264 * InitializeAcl [ADVAPI32.@]
1266 BOOL WINAPI InitializeAcl(PACL acl, DWORD size, DWORD rev)
1268 return set_ntstatus( RtlCreateAcl(acl, size, rev));
1271 BOOL WINAPI ImpersonateNamedPipeClient( HANDLE hNamedPipe )
1273 TRACE("(%p)\n", hNamedPipe);
1275 return set_ntstatus( NtFsControlFile(hNamedPipe, NULL, NULL, NULL, NULL,
1276 FSCTL_PIPE_IMPERSONATE, NULL, 0, NULL, 0) );
1279 /******************************************************************************
1280 * AddAccessAllowedAce [ADVAPI32.@]
1282 BOOL WINAPI AddAccessAllowedAce(
1284 IN DWORD dwAceRevision,
1285 IN DWORD AccessMask,
1288 return set_ntstatus(RtlAddAccessAllowedAce(pAcl, dwAceRevision, AccessMask, pSid));
1291 /******************************************************************************
1292 * AddAccessAllowedAceEx [ADVAPI32.@]
1294 BOOL WINAPI AddAccessAllowedAceEx(
1296 IN DWORD dwAceRevision,
1298 IN DWORD AccessMask,
1301 return set_ntstatus(RtlAddAccessAllowedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
1304 /******************************************************************************
1305 * AddAccessDeniedAce [ADVAPI32.@]
1307 BOOL WINAPI AddAccessDeniedAce(
1309 IN DWORD dwAceRevision,
1310 IN DWORD AccessMask,
1313 return set_ntstatus(RtlAddAccessDeniedAce(pAcl, dwAceRevision, AccessMask, pSid));
1316 /******************************************************************************
1317 * AddAccessDeniedAceEx [ADVAPI32.@]
1319 BOOL WINAPI AddAccessDeniedAceEx(
1321 IN DWORD dwAceRevision,
1323 IN DWORD AccessMask,
1326 return set_ntstatus(RtlAddAccessDeniedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
1329 /******************************************************************************
1330 * AddAce [ADVAPI32.@]
1334 IN DWORD dwAceRevision,
1335 IN DWORD dwStartingAceIndex,
1337 DWORD nAceListLength)
1339 return set_ntstatus(RtlAddAce(pAcl, dwAceRevision, dwStartingAceIndex, pAceList, nAceListLength));
1342 /******************************************************************************
1343 * DeleteAce [ADVAPI32.@]
1345 BOOL WINAPI DeleteAce(PACL pAcl, DWORD dwAceIndex)
1347 return set_ntstatus(RtlDeleteAce(pAcl, dwAceIndex));
1350 /******************************************************************************
1351 * FindFirstFreeAce [ADVAPI32.@]
1353 BOOL WINAPI FindFirstFreeAce(IN PACL pAcl, LPVOID * pAce)
1355 return RtlFirstFreeAce(pAcl, (PACE_HEADER *)pAce);
1358 /******************************************************************************
1359 * GetAce [ADVAPI32.@]
1361 BOOL WINAPI GetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce )
1363 return set_ntstatus(RtlGetAce(pAcl, dwAceIndex, pAce));
1366 /******************************************************************************
1367 * GetAclInformation [ADVAPI32.@]
1369 BOOL WINAPI GetAclInformation(
1371 LPVOID pAclInformation,
1372 DWORD nAclInformationLength,
1373 ACL_INFORMATION_CLASS dwAclInformationClass)
1375 return set_ntstatus(RtlQueryInformationAcl(pAcl, pAclInformation,
1376 nAclInformationLength, dwAclInformationClass));
1379 /******************************************************************************
1380 * IsValidAcl [ADVAPI32.@]
1382 BOOL WINAPI IsValidAcl(IN PACL pAcl)
1384 return RtlValidAcl(pAcl);
1387 /* ##############################
1388 ###### MISC FUNCTIONS ######
1389 ##############################
1392 /******************************************************************************
1393 * AllocateLocallyUniqueId [ADVAPI32.@]
1398 BOOL WINAPI AllocateLocallyUniqueId( PLUID lpLuid )
1400 return set_ntstatus(NtAllocateLocallyUniqueId(lpLuid));
1403 static const WCHAR SE_CREATE_TOKEN_NAME_W[] =
1404 { 'S','e','C','r','e','a','t','e','T','o','k','e','n','P','r','i','v','i','l','e','g','e',0 };
1405 static const WCHAR SE_ASSIGNPRIMARYTOKEN_NAME_W[] =
1406 { '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 };
1407 static const WCHAR SE_LOCK_MEMORY_NAME_W[] =
1408 { 'S','e','L','o','c','k','M','e','m','o','r','y','P','r','i','v','i','l','e','g','e',0 };
1409 static const WCHAR SE_INCREASE_QUOTA_NAME_W[] =
1410 { '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 };
1411 static const WCHAR SE_MACHINE_ACCOUNT_NAME_W[] =
1412 { '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 };
1413 static const WCHAR SE_TCB_NAME_W[] =
1414 { 'S','e','T','c','b','P','r','i','v','i','l','e','g','e',0 };
1415 static const WCHAR SE_SECURITY_NAME_W[] =
1416 { 'S','e','S','e','c','u','r','i','t','y','P','r','i','v','i','l','e','g','e',0 };
1417 static const WCHAR SE_TAKE_OWNERSHIP_NAME_W[] =
1418 { '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 };
1419 static const WCHAR SE_LOAD_DRIVER_NAME_W[] =
1420 { 'S','e','L','o','a','d','D','r','i','v','e','r','P','r','i','v','i','l','e','g','e',0 };
1421 static const WCHAR SE_SYSTEM_PROFILE_NAME_W[] =
1422 { '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 };
1423 static const WCHAR SE_SYSTEMTIME_NAME_W[] =
1424 { 'S','e','S','y','s','t','e','m','t','i','m','e','P','r','i','v','i','l','e','g','e',0 };
1425 static const WCHAR SE_PROF_SINGLE_PROCESS_NAME_W[] =
1426 { '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 };
1427 static const WCHAR SE_INC_BASE_PRIORITY_NAME_W[] =
1428 { '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 };
1429 static const WCHAR SE_CREATE_PAGEFILE_NAME_W[] =
1430 { '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 };
1431 static const WCHAR SE_CREATE_PERMANENT_NAME_W[] =
1432 { '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 };
1433 static const WCHAR SE_BACKUP_NAME_W[] =
1434 { 'S','e','B','a','c','k','u','p','P','r','i','v','i','l','e','g','e',0 };
1435 static const WCHAR SE_RESTORE_NAME_W[] =
1436 { 'S','e','R','e','s','t','o','r','e','P','r','i','v','i','l','e','g','e',0 };
1437 static const WCHAR SE_SHUTDOWN_NAME_W[] =
1438 { 'S','e','S','h','u','t','d','o','w','n','P','r','i','v','i','l','e','g','e',0 };
1439 static const WCHAR SE_DEBUG_NAME_W[] =
1440 { 'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0 };
1441 static const WCHAR SE_AUDIT_NAME_W[] =
1442 { 'S','e','A','u','d','i','t','P','r','i','v','i','l','e','g','e',0 };
1443 static const WCHAR SE_SYSTEM_ENVIRONMENT_NAME_W[] =
1444 { '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 };
1445 static const WCHAR SE_CHANGE_NOTIFY_NAME_W[] =
1446 { 'S','e','C','h','a','n','g','e','N','o','t','i','f','y','P','r','i','v','i','l','e','g','e',0 };
1447 static const WCHAR SE_REMOTE_SHUTDOWN_NAME_W[] =
1448 { '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 };
1449 static const WCHAR SE_UNDOCK_NAME_W[] =
1450 { 'S','e','U','n','d','o','c','k','P','r','i','v','i','l','e','g','e',0 };
1451 static const WCHAR SE_SYNC_AGENT_NAME_W[] =
1452 { 'S','e','S','y','n','c','A','g','e','n','t','P','r','i','v','i','l','e','g','e',0 };
1453 static const WCHAR SE_ENABLE_DELEGATION_NAME_W[] =
1454 { '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 };
1455 static const WCHAR SE_MANAGE_VOLUME_NAME_W[] =
1456 { 'S','e','M','a','n','a','g','e','V','o','l','u','m','e','P','r','i','v','i','l','e','g','e',0 };
1457 static const WCHAR SE_IMPERSONATE_NAME_W[] =
1458 { 'S','e','I','m','p','e','r','s','o','n','a','t','e','P','r','i','v','i','l','e','g','e',0 };
1459 static const WCHAR SE_CREATE_GLOBAL_NAME_W[] =
1460 { 'S','e','C','r','e','a','t','e','G','l','o','b','a','l','P','r','i','v','i','l','e','g','e',0 };
1462 static const WCHAR * const WellKnownPrivNames[SE_MAX_WELL_KNOWN_PRIVILEGE + 1] =
1466 SE_CREATE_TOKEN_NAME_W,
1467 SE_ASSIGNPRIMARYTOKEN_NAME_W,
1468 SE_LOCK_MEMORY_NAME_W,
1469 SE_INCREASE_QUOTA_NAME_W,
1470 SE_MACHINE_ACCOUNT_NAME_W,
1473 SE_TAKE_OWNERSHIP_NAME_W,
1474 SE_LOAD_DRIVER_NAME_W,
1475 SE_SYSTEM_PROFILE_NAME_W,
1476 SE_SYSTEMTIME_NAME_W,
1477 SE_PROF_SINGLE_PROCESS_NAME_W,
1478 SE_INC_BASE_PRIORITY_NAME_W,
1479 SE_CREATE_PAGEFILE_NAME_W,
1480 SE_CREATE_PERMANENT_NAME_W,
1486 SE_SYSTEM_ENVIRONMENT_NAME_W,
1487 SE_CHANGE_NOTIFY_NAME_W,
1488 SE_REMOTE_SHUTDOWN_NAME_W,
1490 SE_SYNC_AGENT_NAME_W,
1491 SE_ENABLE_DELEGATION_NAME_W,
1492 SE_MANAGE_VOLUME_NAME_W,
1493 SE_IMPERSONATE_NAME_W,
1494 SE_CREATE_GLOBAL_NAME_W,
1497 /******************************************************************************
1498 * LookupPrivilegeValueW [ADVAPI32.@]
1500 * See LookupPrivilegeValueA.
1503 LookupPrivilegeValueW( LPCWSTR lpSystemName, LPCWSTR lpName, PLUID lpLuid )
1507 TRACE("%s,%s,%p\n",debugstr_w(lpSystemName), debugstr_w(lpName), lpLuid);
1509 if (!ADVAPI_IsLocalComputer(lpSystemName))
1511 SetLastError(RPC_S_SERVER_UNAVAILABLE);
1516 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1519 for( i=SE_MIN_WELL_KNOWN_PRIVILEGE; i<SE_MAX_WELL_KNOWN_PRIVILEGE; i++ )
1521 if( !WellKnownPrivNames[i] )
1523 if( strcmpiW( WellKnownPrivNames[i], lpName) )
1525 lpLuid->LowPart = i;
1526 lpLuid->HighPart = 0;
1527 TRACE( "%s -> %08lx-%08lx\n",debugstr_w( lpSystemName ),
1528 lpLuid->HighPart, lpLuid->LowPart );
1531 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1535 /******************************************************************************
1536 * LookupPrivilegeValueA [ADVAPI32.@]
1538 * Retrieves LUID used on a system to represent the privilege name.
1541 * lpSystemName [I] Name of the system
1542 * lpName [I] Name of the privilege
1543 * lpLuid [O] Destination for the resulting LUID
1546 * Success: TRUE. lpLuid contains the requested LUID.
1550 LookupPrivilegeValueA( LPCSTR lpSystemName, LPCSTR lpName, PLUID lpLuid )
1552 UNICODE_STRING lpSystemNameW;
1553 UNICODE_STRING lpNameW;
1556 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
1557 RtlCreateUnicodeStringFromAsciiz(&lpNameW,lpName);
1558 ret = LookupPrivilegeValueW(lpSystemNameW.Buffer, lpNameW.Buffer, lpLuid);
1559 RtlFreeUnicodeString(&lpNameW);
1560 RtlFreeUnicodeString(&lpSystemNameW);
1564 BOOL WINAPI LookupPrivilegeDisplayNameA( LPCSTR lpSystemName, LPCSTR lpName, LPSTR lpDisplayName,
1565 LPDWORD cchDisplayName, LPDWORD lpLanguageId )
1567 FIXME("%s %s %s %p %p - stub\n", debugstr_a(lpSystemName), debugstr_a(lpName),
1568 debugstr_a(lpDisplayName), cchDisplayName, lpLanguageId);
1573 BOOL WINAPI LookupPrivilegeDisplayNameW( LPCWSTR lpSystemName, LPCWSTR lpName, LPWSTR lpDisplayName,
1574 LPDWORD cchDisplayName, LPDWORD lpLanguageId )
1576 FIXME("%s %s %s %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpName),
1577 debugstr_w(lpDisplayName), cchDisplayName, lpLanguageId);
1582 /******************************************************************************
1583 * LookupPrivilegeNameA [ADVAPI32.@]
1585 * See LookupPrivilegeNameW.
1588 LookupPrivilegeNameA( LPCSTR lpSystemName, PLUID lpLuid, LPSTR lpName,
1591 UNICODE_STRING lpSystemNameW;
1595 TRACE("%s %p %p %p\n", debugstr_a(lpSystemName), lpLuid, lpName, cchName);
1597 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
1598 ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, NULL, &wLen);
1599 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1601 LPWSTR lpNameW = HeapAlloc(GetProcessHeap(), 0, wLen * sizeof(WCHAR));
1603 ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, lpNameW,
1607 /* Windows crashes if cchName is NULL, so will I */
1608 int len = WideCharToMultiByte(CP_ACP, 0, lpNameW, -1, lpName,
1609 *cchName, NULL, NULL);
1613 /* WideCharToMultiByte failed */
1616 else if (len > *cchName)
1619 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1624 /* WideCharToMultiByte succeeded, output length needs to be
1625 * length not including NULL terminator
1630 HeapFree(GetProcessHeap(), 0, lpNameW);
1632 RtlFreeUnicodeString(&lpSystemNameW);
1636 /******************************************************************************
1637 * LookupPrivilegeNameW [ADVAPI32.@]
1639 * Retrieves the privilege name referred to by the LUID lpLuid.
1642 * lpSystemName [I] Name of the system
1643 * lpLuid [I] Privilege value
1644 * lpName [O] Name of the privilege
1645 * cchName [I/O] Number of characters in lpName.
1648 * Success: TRUE. lpName contains the name of the privilege whose value is
1653 * Only well-known privilege names (those defined in winnt.h) can be retrieved
1654 * using this function.
1655 * If the length of lpName is too small, on return *cchName will contain the
1656 * number of WCHARs needed to contain the privilege, including the NULL
1657 * terminator, and GetLastError will return ERROR_INSUFFICIENT_BUFFER.
1658 * On success, *cchName will contain the number of characters stored in
1659 * lpName, NOT including the NULL terminator.
1662 LookupPrivilegeNameW( LPCWSTR lpSystemName, PLUID lpLuid, LPWSTR lpName,
1667 TRACE("%s,%p,%p,%p\n",debugstr_w(lpSystemName), lpLuid, lpName, cchName);
1669 if (!ADVAPI_IsLocalComputer(lpSystemName))
1671 SetLastError(RPC_S_SERVER_UNAVAILABLE);
1674 if (lpLuid->HighPart || (lpLuid->LowPart < SE_MIN_WELL_KNOWN_PRIVILEGE ||
1675 lpLuid->LowPart > SE_MAX_WELL_KNOWN_PRIVILEGE))
1677 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1680 privNameLen = strlenW(WellKnownPrivNames[lpLuid->LowPart]);
1681 /* Windows crashes if cchName is NULL, so will I */
1682 if (*cchName <= privNameLen)
1684 *cchName = privNameLen + 1;
1685 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1690 strcpyW(lpName, WellKnownPrivNames[lpLuid->LowPart]);
1691 *cchName = privNameLen;
1696 /******************************************************************************
1697 * GetFileSecurityA [ADVAPI32.@]
1699 * Obtains Specified information about the security of a file or directory.
1702 * lpFileName [I] Name of the file to get info for
1703 * RequestedInformation [I] SE_ flags from "winnt.h"
1704 * pSecurityDescriptor [O] Destination for security information
1705 * nLength [I] Length of pSecurityDescriptor
1706 * lpnLengthNeeded [O] Destination for length of returned security information
1709 * Success: TRUE. pSecurityDescriptor contains the requested information.
1710 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
1713 * The information returned is constrained by the callers access rights and
1717 GetFileSecurityA( LPCSTR lpFileName,
1718 SECURITY_INFORMATION RequestedInformation,
1719 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1720 DWORD nLength, LPDWORD lpnLengthNeeded )
1728 len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 );
1729 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1730 MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len );
1733 r = GetFileSecurityW( name, RequestedInformation, pSecurityDescriptor,
1734 nLength, lpnLengthNeeded );
1735 HeapFree( GetProcessHeap(), 0, name );
1740 /******************************************************************************
1741 * GetFileSecurityW [ADVAPI32.@]
1743 * See GetFileSecurityA.
1746 GetFileSecurityW( LPCWSTR lpFileName,
1747 SECURITY_INFORMATION RequestedInformation,
1748 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1749 DWORD nLength, LPDWORD lpnLengthNeeded )
1754 SECURITY_DESCRIPTOR_RELATIVE *pSDRelative;
1756 if(INVALID_FILE_ATTRIBUTES == GetFileAttributesW(lpFileName))
1759 FIXME("(%s) : returns fake SECURITY_DESCRIPTOR\n", debugstr_w(lpFileName) );
1761 nNeeded = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
1762 if (RequestedInformation & OWNER_SECURITY_INFORMATION)
1763 nNeeded += sizeof(sidWorld);
1764 if (RequestedInformation & GROUP_SECURITY_INFORMATION)
1765 nNeeded += sizeof(sidWorld);
1766 if (RequestedInformation & DACL_SECURITY_INFORMATION)
1767 nNeeded += WINE_SIZE_OF_WORLD_ACCESS_ACL;
1768 if (RequestedInformation & SACL_SECURITY_INFORMATION)
1769 nNeeded += WINE_SIZE_OF_WORLD_ACCESS_ACL;
1771 *lpnLengthNeeded = nNeeded;
1773 if (nNeeded > nLength)
1776 if (!InitializeSecurityDescriptor(pSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION))
1779 pSDRelative = (PISECURITY_DESCRIPTOR_RELATIVE) pSecurityDescriptor;
1780 pSDRelative->Control |= SE_SELF_RELATIVE;
1781 pBuffer = (LPBYTE) pSDRelative;
1782 iLocNow = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
1784 if (RequestedInformation & OWNER_SECURITY_INFORMATION)
1786 memcpy(pBuffer + iLocNow, &sidWorld, sizeof(sidWorld));
1787 pSDRelative->Owner = iLocNow;
1788 iLocNow += sizeof(sidWorld);
1790 if (RequestedInformation & GROUP_SECURITY_INFORMATION)
1792 memcpy(pBuffer + iLocNow, &sidWorld, sizeof(sidWorld));
1793 pSDRelative->Group = iLocNow;
1794 iLocNow += sizeof(sidWorld);
1796 if (RequestedInformation & DACL_SECURITY_INFORMATION)
1798 GetWorldAccessACL((PACL) (pBuffer + iLocNow));
1799 pSDRelative->Dacl = iLocNow;
1800 iLocNow += WINE_SIZE_OF_WORLD_ACCESS_ACL;
1802 if (RequestedInformation & SACL_SECURITY_INFORMATION)
1804 GetWorldAccessACL((PACL) (pBuffer + iLocNow));
1805 pSDRelative->Sacl = iLocNow;
1806 /* iLocNow += WINE_SIZE_OF_WORLD_ACCESS_ACL; */
1812 /******************************************************************************
1813 * LookupAccountSidA [ADVAPI32.@]
1820 IN OUT LPDWORD accountSize,
1822 IN OUT LPDWORD domainSize,
1823 OUT PSID_NAME_USE name_use )
1827 LPWSTR systemW = NULL;
1828 LPWSTR accountW = NULL;
1829 LPWSTR domainW = NULL;
1830 DWORD accountSizeW = *accountSize;
1831 DWORD domainSizeW = *domainSize;
1833 TRACE("(%s,sid=%s,%p,%p(%lu),%p,%p(%lu),%p)\n",
1834 debugstr_a(system),debugstr_sid(sid),
1835 account,accountSize,accountSize?*accountSize:0,
1836 domain,domainSize,domainSize?*domainSize:0,
1840 len = MultiByteToWideChar( CP_ACP, 0, system, -1, NULL, 0 );
1841 systemW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1842 MultiByteToWideChar( CP_ACP, 0, system, -1, systemW, len );
1845 accountW = HeapAlloc( GetProcessHeap(), 0, accountSizeW * sizeof(WCHAR) );
1847 domainW = HeapAlloc( GetProcessHeap(), 0, domainSizeW * sizeof(WCHAR) );
1849 r = LookupAccountSidW( systemW, sid, accountW, &accountSizeW, domainW, &domainSizeW, name_use );
1852 if (accountW && *accountSize) {
1853 len = WideCharToMultiByte( CP_ACP, 0, accountW, -1, NULL, 0, NULL, NULL );
1854 WideCharToMultiByte( CP_ACP, 0, accountW, -1, account, len, NULL, NULL );
1857 *accountSize = accountSizeW + 1;
1859 if (domainW && *domainSize) {
1860 len = WideCharToMultiByte( CP_ACP, 0, domainW, -1, NULL, 0, NULL, NULL );
1861 WideCharToMultiByte( CP_ACP, 0, domainW, -1, domain, len, NULL, NULL );
1864 *domainSize = domainSizeW + 1;
1867 HeapFree( GetProcessHeap(), 0, systemW );
1868 HeapFree( GetProcessHeap(), 0, accountW );
1869 HeapFree( GetProcessHeap(), 0, domainW );
1874 /******************************************************************************
1875 * LookupAccountSidW [ADVAPI32.@]
1892 IN OUT LPDWORD accountSize,
1894 IN OUT LPDWORD domainSize,
1895 OUT PSID_NAME_USE name_use )
1898 const WCHAR * ac = NULL;
1899 const WCHAR * dm = NULL;
1900 SID_NAME_USE use = 0;
1901 LPWSTR computer_name = NULL;
1903 TRACE("(%s,sid=%s,%p,%p(%lu),%p,%p(%lu),%p)\n",
1904 debugstr_w(system),debugstr_sid(sid),
1905 account,accountSize,accountSize?*accountSize:0,
1906 domain,domainSize,domainSize?*domainSize:0,
1909 if (!ADVAPI_IsLocalComputer(system)) {
1910 FIXME("Only local computer supported!\n");
1911 SetLastError(ERROR_NONE_MAPPED);
1915 /* check the well known SIDs first */
1916 for (i = 0; i <= 60; i++) {
1917 if (IsWellKnownSid(sid, i)) {
1918 for (j = 0; j < (sizeof(ACCOUNT_SIDS) / sizeof(ACCOUNT_SIDS[0])); j++) {
1919 if (ACCOUNT_SIDS[j].type == i) {
1920 ac = ACCOUNT_SIDS[j].account;
1921 dm = ACCOUNT_SIDS[j].domain;
1922 use = ACCOUNT_SIDS[j].name_use;
1932 /* check for the local computer next */
1933 if (ADVAPI_GetComputerSid(&local)) {
1934 DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
1937 computer_name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
1938 result = GetComputerNameW(computer_name, &size);
1941 if (EqualSid(sid, &local)) {
1946 local.SubAuthorityCount++;
1948 if (EqualPrefixSid(sid, &local)) {
1951 switch (((MAX_SID *)sid)->SubAuthority[4]) {
1952 case DOMAIN_USER_RID_ADMIN:
1955 case DOMAIN_USER_RID_GUEST:
1958 case DOMAIN_GROUP_RID_ADMINS:
1961 case DOMAIN_GROUP_RID_USERS:
1964 case DOMAIN_GROUP_RID_GUESTS:
1967 case DOMAIN_GROUP_RID_COMPUTERS:
1968 ac = Domain_Computers;
1970 case DOMAIN_GROUP_RID_CONTROLLERS:
1971 ac = Domain_Controllers;
1973 case DOMAIN_GROUP_RID_CERT_ADMINS:
1974 ac = Cert_Publishers;
1976 case DOMAIN_GROUP_RID_SCHEMA_ADMINS:
1979 case DOMAIN_GROUP_RID_ENTERPRISE_ADMINS:
1980 ac = Enterprise_Admins;
1982 case DOMAIN_GROUP_RID_POLICY_ADMINS:
1983 ac = Group_Policy_Creator_Owners;
1985 case DOMAIN_ALIAS_RID_RAS_SERVERS:
1986 ac = RAS_and_IAS_Servers;
2000 if (*accountSize > lstrlenW(ac)) {
2002 lstrcpyW(account, ac);
2004 if (*domainSize > lstrlenW(dm)) {
2006 lstrcpyW(domain, dm);
2008 if (((*accountSize != 0) && (*accountSize < strlenW(ac))) ||
2009 ((*domainSize != 0) && (*domainSize < strlenW(dm)))) {
2010 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2014 *domainSize = strlenW(dm);
2016 *domainSize = strlenW(dm) + 1;
2018 *accountSize = strlenW(ac);
2020 *accountSize = strlenW(ac) + 1;
2022 HeapFree(GetProcessHeap(), 0, computer_name);
2026 HeapFree(GetProcessHeap(), 0, computer_name);
2027 SetLastError(ERROR_NONE_MAPPED);
2031 /******************************************************************************
2032 * SetFileSecurityA [ADVAPI32.@]
2034 * See SetFileSecurityW.
2036 BOOL WINAPI SetFileSecurityA( LPCSTR lpFileName,
2037 SECURITY_INFORMATION RequestedInformation,
2038 PSECURITY_DESCRIPTOR pSecurityDescriptor)
2046 len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 );
2047 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
2048 MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len );
2051 r = SetFileSecurityW( name, RequestedInformation, pSecurityDescriptor );
2052 HeapFree( GetProcessHeap(), 0, name );
2057 /******************************************************************************
2058 * SetFileSecurityW [ADVAPI32.@]
2060 * Sets the security of a file or directory.
2064 * RequestedInformation []
2065 * pSecurityDescriptor []
2072 SetFileSecurityW( LPCWSTR lpFileName,
2073 SECURITY_INFORMATION RequestedInformation,
2074 PSECURITY_DESCRIPTOR pSecurityDescriptor )
2076 FIXME("(%s) : stub\n", debugstr_w(lpFileName) );
2080 /******************************************************************************
2081 * QueryWindows31FilesMigration [ADVAPI32.@]
2087 QueryWindows31FilesMigration( DWORD x1 )
2089 FIXME("(%ld):stub\n",x1);
2093 /******************************************************************************
2094 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
2103 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
2106 FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1,x2,x3,x4);
2110 /******************************************************************************
2111 * NotifyBootConfigStatus [ADVAPI32.@]
2117 NotifyBootConfigStatus( BOOL x1 )
2119 FIXME("(0x%08d):stub\n",x1);
2123 /******************************************************************************
2124 * RevertToSelf [ADVAPI32.@]
2126 * Ends the impersonation of a user.
2136 RevertToSelf( void )
2138 HANDLE Token = NULL;
2139 return set_ntstatus( NtSetInformationThread( GetCurrentThread(),
2140 ThreadImpersonationToken, &Token, sizeof(Token) ) );
2143 /******************************************************************************
2144 * ImpersonateSelf [ADVAPI32.@]
2146 * Makes an impersonation token that represents the process user and assigns
2147 * to the current thread.
2150 * ImpersonationLevel [I] Level at which to impersonate.
2157 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
2159 return set_ntstatus( RtlImpersonateSelf( ImpersonationLevel ) );
2162 /******************************************************************************
2163 * ImpersonateLoggedOnUser [ADVAPI32.@]
2165 BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
2169 HANDLE ImpersonationToken;
2172 FIXME( "(%p)\n", hToken );
2174 if (!GetTokenInformation( hToken, TokenType, &Type,
2175 sizeof(TOKEN_TYPE), &size ))
2178 if (Type == TokenPrimary)
2180 OBJECT_ATTRIBUTES ObjectAttributes;
2182 InitializeObjectAttributes( &ObjectAttributes, NULL, 0, NULL, NULL );
2184 Status = NtDuplicateToken( hToken,
2185 TOKEN_IMPERSONATE | TOKEN_QUERY,
2187 SecurityImpersonation,
2189 &ImpersonationToken );
2190 if (Status != STATUS_SUCCESS)
2192 ERR( "NtDuplicateToken failed with error 0x%08lx\n", Status );
2193 SetLastError( RtlNtStatusToDosError( Status ) );
2198 ImpersonationToken = hToken;
2200 Status = NtSetInformationThread( GetCurrentThread(),
2201 ThreadImpersonationToken,
2202 &ImpersonationToken,
2203 sizeof(ImpersonationToken) );
2205 if (Type == TokenPrimary)
2206 NtClose( ImpersonationToken );
2208 if (Status != STATUS_SUCCESS)
2210 ERR( "NtSetInformationThread failed with error 0x%08lx\n", Status );
2211 SetLastError( RtlNtStatusToDosError( Status ) );
2218 /******************************************************************************
2219 * AccessCheck [ADVAPI32.@]
2223 PSECURITY_DESCRIPTOR SecurityDescriptor,
2225 DWORD DesiredAccess,
2226 PGENERIC_MAPPING GenericMapping,
2227 PPRIVILEGE_SET PrivilegeSet,
2228 LPDWORD PrivilegeSetLength,
2229 LPDWORD GrantedAccess,
2230 LPBOOL AccessStatus)
2232 NTSTATUS access_status;
2233 BOOL ret = set_ntstatus( NtAccessCheck(SecurityDescriptor, ClientToken, DesiredAccess,
2234 GenericMapping, PrivilegeSet, PrivilegeSetLength,
2235 GrantedAccess, &access_status) );
2236 if (ret) *AccessStatus = set_ntstatus( access_status );
2241 /******************************************************************************
2242 * AccessCheckByType [ADVAPI32.@]
2244 BOOL WINAPI AccessCheckByType(
2245 PSECURITY_DESCRIPTOR pSecurityDescriptor,
2246 PSID PrincipalSelfSid,
2248 DWORD DesiredAccess,
2249 POBJECT_TYPE_LIST ObjectTypeList,
2250 DWORD ObjectTypeListLength,
2251 PGENERIC_MAPPING GenericMapping,
2252 PPRIVILEGE_SET PrivilegeSet,
2253 LPDWORD PrivilegeSetLength,
2254 LPDWORD GrantedAccess,
2255 LPBOOL AccessStatus)
2259 *AccessStatus = TRUE;
2261 return !*AccessStatus;
2264 /******************************************************************************
2265 * MapGenericMask [ADVAPI32.@]
2267 * Maps generic access rights into specific access rights according to the
2271 * AccessMask [I/O] Access rights.
2272 * GenericMapping [I] The mapping between generic and specific rights.
2277 VOID WINAPI MapGenericMask( PDWORD AccessMask, PGENERIC_MAPPING GenericMapping )
2279 RtlMapGenericMask( AccessMask, GenericMapping );
2282 /*************************************************************************
2283 * SetKernelObjectSecurity [ADVAPI32.@]
2285 BOOL WINAPI SetKernelObjectSecurity (
2287 IN SECURITY_INFORMATION SecurityInformation,
2288 IN PSECURITY_DESCRIPTOR SecurityDescriptor )
2290 return set_ntstatus (NtSetSecurityObject (Handle, SecurityInformation, SecurityDescriptor));
2294 /******************************************************************************
2295 * AddAuditAccessAce [ADVAPI32.@]
2297 BOOL WINAPI AddAuditAccessAce(
2299 IN DWORD dwAceRevision,
2300 IN DWORD dwAccessMask,
2302 IN BOOL bAuditSuccess,
2303 IN BOOL bAuditFailure)
2305 return set_ntstatus( RtlAddAuditAccessAce(pAcl, dwAceRevision, dwAccessMask, pSid,
2306 bAuditSuccess, bAuditFailure) );
2309 /******************************************************************************
2310 * LookupAccountNameA [ADVAPI32.@]
2318 LPSTR ReferencedDomainName,
2319 IN OUT LPDWORD cbReferencedDomainName,
2320 OUT PSID_NAME_USE name_use )
2323 UNICODE_STRING lpSystemW;
2324 UNICODE_STRING lpAccountW;
2325 LPWSTR lpReferencedDomainNameW = NULL;
2327 RtlCreateUnicodeStringFromAsciiz(&lpSystemW, system);
2328 RtlCreateUnicodeStringFromAsciiz(&lpAccountW, account);
2330 if (ReferencedDomainName)
2331 lpReferencedDomainNameW = HeapAlloc(GetProcessHeap(), 0, *cbReferencedDomainName * sizeof(WCHAR));
2333 ret = LookupAccountNameW(lpSystemW.Buffer, lpAccountW.Buffer, sid, cbSid, lpReferencedDomainNameW,
2334 cbReferencedDomainName, name_use);
2336 if (ret && lpReferencedDomainNameW)
2338 WideCharToMultiByte(CP_ACP, 0, lpReferencedDomainNameW, *cbReferencedDomainName,
2339 ReferencedDomainName, *cbReferencedDomainName, NULL, NULL);
2342 RtlFreeUnicodeString(&lpSystemW);
2343 RtlFreeUnicodeString(&lpAccountW);
2344 HeapFree(GetProcessHeap(), 0, lpReferencedDomainNameW);
2349 /******************************************************************************
2350 * LookupAccountNameW [ADVAPI32.@]
2352 BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSID Sid,
2353 LPDWORD cbSid, LPWSTR ReferencedDomainName,
2354 LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse )
2356 /* Default implementation: Always return a default SID */
2357 SID_IDENTIFIER_AUTHORITY identifierAuthority = {SECURITY_NT_AUTHORITY};
2360 static const WCHAR dm[] = {'D','O','M','A','I','N',0};
2362 FIXME("%s %s %p %p %p %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpAccountName),
2363 Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse);
2365 ret = AllocateAndInitializeSid(&identifierAuthority,
2367 SECURITY_BUILTIN_DOMAIN_RID,
2368 DOMAIN_ALIAS_RID_ADMINS,
2375 if (!RtlValidSid(pSid))
2381 if (Sid != NULL && (*cbSid >= GetLengthSid(pSid)))
2382 CopySid(*cbSid, Sid, pSid);
2383 if (*cbSid < GetLengthSid(pSid))
2385 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2388 *cbSid = GetLengthSid(pSid);
2390 if (ReferencedDomainName != NULL && (*cchReferencedDomainName > strlenW(dm)))
2391 strcpyW(ReferencedDomainName, dm);
2393 if (*cchReferencedDomainName <= strlenW(dm))
2395 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2399 *cchReferencedDomainName = strlenW(dm)+1;
2406 /******************************************************************************
2407 * PrivilegeCheck [ADVAPI32.@]
2409 BOOL WINAPI PrivilegeCheck( HANDLE ClientToken, PPRIVILEGE_SET RequiredPrivileges, LPBOOL pfResult)
2414 TRACE("%p %p %p\n", ClientToken, RequiredPrivileges, pfResult);
2416 ret = set_ntstatus (NtPrivilegeCheck (ClientToken, RequiredPrivileges, &Result));
2422 /******************************************************************************
2423 * AccessCheckAndAuditAlarmA [ADVAPI32.@]
2425 BOOL WINAPI AccessCheckAndAuditAlarmA(LPCSTR Subsystem, LPVOID HandleId, LPSTR ObjectTypeName,
2426 LPSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
2427 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
2428 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
2430 FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_a(Subsystem),
2431 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName),
2432 SecurityDescriptor, DesiredAccess, GenericMapping,
2433 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
2437 /******************************************************************************
2438 * AccessCheckAndAuditAlarmW [ADVAPI32.@]
2440 BOOL WINAPI AccessCheckAndAuditAlarmW(LPCWSTR Subsystem, LPVOID HandleId, LPWSTR ObjectTypeName,
2441 LPWSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
2442 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
2443 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
2445 FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_w(Subsystem),
2446 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName),
2447 SecurityDescriptor, DesiredAccess, GenericMapping,
2448 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
2452 BOOL WINAPI ObjectCloseAuditAlarmA(LPCSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
2454 FIXME("stub (%s,%p,%x)\n", debugstr_a(SubsystemName), HandleId, GenerateOnClose);
2459 BOOL WINAPI ObjectCloseAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
2461 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName), HandleId, GenerateOnClose);
2466 BOOL WINAPI ObjectDeleteAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
2468 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName), HandleId, GenerateOnClose);
2473 BOOL WINAPI ObjectOpenAuditAlarmA(LPCSTR SubsystemName, LPVOID HandleId, LPSTR ObjectTypeName,
2474 LPSTR ObjectName, PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE ClientToken, DWORD DesiredAccess,
2475 DWORD GrantedAccess, PPRIVILEGE_SET Privileges, BOOL ObjectCreation, BOOL AccessGranted,
2476 LPBOOL GenerateOnClose)
2478 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08lx,0x%08lx,%p,%x,%x,%p)\n", debugstr_a(SubsystemName),
2479 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName), pSecurityDescriptor,
2480 ClientToken, DesiredAccess, GrantedAccess, Privileges, ObjectCreation, AccessGranted,
2486 BOOL WINAPI ObjectOpenAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, LPWSTR ObjectTypeName,
2487 LPWSTR ObjectName, PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE ClientToken, DWORD DesiredAccess,
2488 DWORD GrantedAccess, PPRIVILEGE_SET Privileges, BOOL ObjectCreation, BOOL AccessGranted,
2489 LPBOOL GenerateOnClose)
2491 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08lx,0x%08lx,%p,%x,%x,%p)\n", debugstr_w(SubsystemName),
2492 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName), pSecurityDescriptor,
2493 ClientToken, DesiredAccess, GrantedAccess, Privileges, ObjectCreation, AccessGranted,
2499 BOOL WINAPI ObjectPrivilegeAuditAlarmA( LPCSTR SubsystemName, LPVOID HandleId, HANDLE ClientToken,
2500 DWORD DesiredAccess, PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2502 FIXME("stub (%s,%p,%p,0x%08lx,%p,%x)\n", debugstr_a(SubsystemName), HandleId, ClientToken,
2503 DesiredAccess, Privileges, AccessGranted);
2508 BOOL WINAPI ObjectPrivilegeAuditAlarmW( LPCWSTR SubsystemName, LPVOID HandleId, HANDLE ClientToken,
2509 DWORD DesiredAccess, PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2511 FIXME("stub (%s,%p,%p,0x%08lx,%p,%x)\n", debugstr_w(SubsystemName), HandleId, ClientToken,
2512 DesiredAccess, Privileges, AccessGranted);
2517 BOOL WINAPI PrivilegedServiceAuditAlarmA( LPCSTR SubsystemName, LPCSTR ServiceName, HANDLE ClientToken,
2518 PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2520 FIXME("stub (%s,%s,%p,%p,%x)\n", debugstr_a(SubsystemName), debugstr_a(ServiceName),
2521 ClientToken, Privileges, AccessGranted);
2526 BOOL WINAPI PrivilegedServiceAuditAlarmW( LPCWSTR SubsystemName, LPCWSTR ServiceName, HANDLE ClientToken,
2527 PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2529 FIXME("stub %s,%s,%p,%p,%x)\n", debugstr_w(SubsystemName), debugstr_w(ServiceName),
2530 ClientToken, Privileges, AccessGranted);
2535 /******************************************************************************
2536 * GetSecurityInfo [ADVAPI32.@]
2538 DWORD WINAPI GetSecurityInfo(
2539 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
2540 SECURITY_INFORMATION SecurityInfo, PSID *ppsidOwner,
2541 PSID *ppsidGroup, PACL *ppDacl, PACL *ppSacl,
2542 PSECURITY_DESCRIPTOR *ppSecurityDescriptor
2546 return ERROR_BAD_PROVIDER;
2549 /******************************************************************************
2550 * GetSecurityInfoExW [ADVAPI32.@]
2552 DWORD WINAPI GetSecurityInfoExW(
2553 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
2554 SECURITY_INFORMATION SecurityInfo, LPCWSTR lpProvider,
2555 LPCWSTR lpProperty, PACTRL_ACCESSW *ppAccessList,
2556 PACTRL_AUDITW *ppAuditList, LPWSTR *lppOwner, LPWSTR *lppGroup
2560 return ERROR_BAD_PROVIDER;
2563 /******************************************************************************
2564 * BuildExplicitAccessWithNameA [ADVAPI32.@]
2566 VOID WINAPI BuildExplicitAccessWithNameA( PEXPLICIT_ACCESSA pExplicitAccess,
2567 LPSTR pTrusteeName, DWORD AccessPermissions,
2568 ACCESS_MODE AccessMode, DWORD Inheritance )
2570 TRACE("%p %s 0x%08lx 0x%08x 0x%08lx\n", pExplicitAccess, debugstr_a(pTrusteeName),
2571 AccessPermissions, AccessMode, Inheritance);
2573 pExplicitAccess->grfAccessPermissions = AccessPermissions;
2574 pExplicitAccess->grfAccessMode = AccessMode;
2575 pExplicitAccess->grfInheritance = Inheritance;
2577 pExplicitAccess->Trustee.pMultipleTrustee = NULL;
2578 pExplicitAccess->Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2579 pExplicitAccess->Trustee.TrusteeForm = TRUSTEE_IS_NAME;
2580 pExplicitAccess->Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
2581 pExplicitAccess->Trustee.ptstrName = pTrusteeName;
2584 /******************************************************************************
2585 * BuildExplicitAccessWithNameW [ADVAPI32.@]
2587 VOID WINAPI BuildExplicitAccessWithNameW( PEXPLICIT_ACCESSW pExplicitAccess,
2588 LPWSTR pTrusteeName, DWORD AccessPermissions,
2589 ACCESS_MODE AccessMode, DWORD Inheritance )
2591 TRACE("%p %s 0x%08lx 0x%08x 0x%08lx\n", pExplicitAccess, debugstr_w(pTrusteeName),
2592 AccessPermissions, AccessMode, Inheritance);
2594 pExplicitAccess->grfAccessPermissions = AccessPermissions;
2595 pExplicitAccess->grfAccessMode = AccessMode;
2596 pExplicitAccess->grfInheritance = Inheritance;
2598 pExplicitAccess->Trustee.pMultipleTrustee = NULL;
2599 pExplicitAccess->Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2600 pExplicitAccess->Trustee.TrusteeForm = TRUSTEE_IS_NAME;
2601 pExplicitAccess->Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
2602 pExplicitAccess->Trustee.ptstrName = pTrusteeName;
2605 /******************************************************************************
2606 * BuildTrusteeWithObjectsAndNameA [ADVAPI32.@]
2608 VOID WINAPI BuildTrusteeWithObjectsAndNameA( PTRUSTEEA pTrustee, POBJECTS_AND_NAME_A pObjName,
2609 SE_OBJECT_TYPE ObjectType, LPSTR ObjectTypeName,
2610 LPSTR InheritedObjectTypeName, LPSTR Name )
2612 DWORD ObjectsPresent = 0;
2614 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee, pObjName,
2615 ObjectType, ObjectTypeName, InheritedObjectTypeName, debugstr_a(Name));
2617 /* Fill the OBJECTS_AND_NAME structure */
2618 pObjName->ObjectType = ObjectType;
2619 if (ObjectTypeName != NULL)
2621 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
2624 pObjName->InheritedObjectTypeName = InheritedObjectTypeName;
2625 if (InheritedObjectTypeName != NULL)
2627 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
2630 pObjName->ObjectsPresent = ObjectsPresent;
2631 pObjName->ptstrName = Name;
2633 /* Fill the TRUSTEE structure */
2634 pTrustee->pMultipleTrustee = NULL;
2635 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2636 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME;
2637 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2638 pTrustee->ptstrName = (LPSTR)pObjName;
2641 /******************************************************************************
2642 * BuildTrusteeWithObjectsAndNameW [ADVAPI32.@]
2644 VOID WINAPI BuildTrusteeWithObjectsAndNameW( PTRUSTEEW pTrustee, POBJECTS_AND_NAME_W pObjName,
2645 SE_OBJECT_TYPE ObjectType, LPWSTR ObjectTypeName,
2646 LPWSTR InheritedObjectTypeName, LPWSTR Name )
2648 DWORD ObjectsPresent = 0;
2650 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee, pObjName,
2651 ObjectType, ObjectTypeName, InheritedObjectTypeName, debugstr_w(Name));
2653 /* Fill the OBJECTS_AND_NAME structure */
2654 pObjName->ObjectType = ObjectType;
2655 if (ObjectTypeName != NULL)
2657 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
2660 pObjName->InheritedObjectTypeName = InheritedObjectTypeName;
2661 if (InheritedObjectTypeName != NULL)
2663 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
2666 pObjName->ObjectsPresent = ObjectsPresent;
2667 pObjName->ptstrName = Name;
2669 /* Fill the TRUSTEE structure */
2670 pTrustee->pMultipleTrustee = NULL;
2671 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2672 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME;
2673 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2674 pTrustee->ptstrName = (LPWSTR)pObjName;
2677 /******************************************************************************
2678 * BuildTrusteeWithObjectsAndSidA [ADVAPI32.@]
2680 VOID WINAPI BuildTrusteeWithObjectsAndSidA( PTRUSTEEA pTrustee, POBJECTS_AND_SID pObjSid,
2681 GUID* pObjectGuid, GUID* pInheritedObjectGuid, PSID pSid )
2683 DWORD ObjectsPresent = 0;
2685 TRACE("%p %p %p %p %p\n", pTrustee, pObjSid, pObjectGuid, pInheritedObjectGuid, pSid);
2687 /* Fill the OBJECTS_AND_SID structure */
2688 if (pObjectGuid != NULL)
2690 pObjSid->ObjectTypeGuid = *pObjectGuid;
2691 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
2695 ZeroMemory(&pObjSid->ObjectTypeGuid,
2699 if (pInheritedObjectGuid != NULL)
2701 pObjSid->InheritedObjectTypeGuid = *pInheritedObjectGuid;
2702 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
2706 ZeroMemory(&pObjSid->InheritedObjectTypeGuid,
2710 pObjSid->ObjectsPresent = ObjectsPresent;
2711 pObjSid->pSid = pSid;
2713 /* Fill the TRUSTEE structure */
2714 pTrustee->pMultipleTrustee = NULL;
2715 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2716 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID;
2717 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2718 pTrustee->ptstrName = (LPSTR) pObjSid;
2721 /******************************************************************************
2722 * BuildTrusteeWithObjectsAndSidW [ADVAPI32.@]
2724 VOID WINAPI BuildTrusteeWithObjectsAndSidW( PTRUSTEEW pTrustee, POBJECTS_AND_SID pObjSid,
2725 GUID* pObjectGuid, GUID* pInheritedObjectGuid, PSID pSid )
2727 DWORD ObjectsPresent = 0;
2729 TRACE("%p %p %p %p %p\n", pTrustee, pObjSid, pObjectGuid, pInheritedObjectGuid, pSid);
2731 /* Fill the OBJECTS_AND_SID structure */
2732 if (pObjectGuid != NULL)
2734 pObjSid->ObjectTypeGuid = *pObjectGuid;
2735 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
2739 ZeroMemory(&pObjSid->ObjectTypeGuid,
2743 if (pInheritedObjectGuid != NULL)
2745 pObjSid->InheritedObjectTypeGuid = *pInheritedObjectGuid;
2746 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
2750 ZeroMemory(&pObjSid->InheritedObjectTypeGuid,
2754 pObjSid->ObjectsPresent = ObjectsPresent;
2755 pObjSid->pSid = pSid;
2757 /* Fill the TRUSTEE structure */
2758 pTrustee->pMultipleTrustee = NULL;
2759 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2760 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID;
2761 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2762 pTrustee->ptstrName = (LPWSTR) pObjSid;
2765 /******************************************************************************
2766 * BuildTrusteeWithSidA [ADVAPI32.@]
2768 VOID WINAPI BuildTrusteeWithSidA(PTRUSTEEA pTrustee, PSID pSid)
2770 TRACE("%p %p\n", pTrustee, pSid);
2772 pTrustee->pMultipleTrustee = NULL;
2773 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2774 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
2775 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2776 pTrustee->ptstrName = (LPSTR) pSid;
2779 /******************************************************************************
2780 * BuildTrusteeWithSidW [ADVAPI32.@]
2782 VOID WINAPI BuildTrusteeWithSidW(PTRUSTEEW pTrustee, PSID pSid)
2784 TRACE("%p %p\n", pTrustee, pSid);
2786 pTrustee->pMultipleTrustee = NULL;
2787 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2788 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
2789 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2790 pTrustee->ptstrName = (LPWSTR) pSid;
2793 /******************************************************************************
2794 * BuildTrusteeWithNameA [ADVAPI32.@]
2796 VOID WINAPI BuildTrusteeWithNameA(PTRUSTEEA pTrustee, LPSTR name)
2798 TRACE("%p %s\n", pTrustee, debugstr_a(name) );
2800 pTrustee->pMultipleTrustee = NULL;
2801 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2802 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
2803 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2804 pTrustee->ptstrName = name;
2807 /******************************************************************************
2808 * BuildTrusteeWithNameW [ADVAPI32.@]
2810 VOID WINAPI BuildTrusteeWithNameW(PTRUSTEEW pTrustee, LPWSTR name)
2812 TRACE("%p %s\n", pTrustee, debugstr_w(name) );
2814 pTrustee->pMultipleTrustee = NULL;
2815 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2816 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
2817 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2818 pTrustee->ptstrName = name;
2821 /******************************************************************************
2822 * GetTrusteeFormA [ADVAPI32.@]
2824 TRUSTEE_FORM WINAPI GetTrusteeFormA(PTRUSTEEA pTrustee)
2826 TRACE("(%p)\n", pTrustee);
2829 return TRUSTEE_BAD_FORM;
2831 return pTrustee->TrusteeForm;
2834 /******************************************************************************
2835 * GetTrusteeFormW [ADVAPI32.@]
2837 TRUSTEE_FORM WINAPI GetTrusteeFormW(PTRUSTEEW pTrustee)
2839 TRACE("(%p)\n", pTrustee);
2842 return TRUSTEE_BAD_FORM;
2844 return pTrustee->TrusteeForm;
2847 /******************************************************************************
2848 * GetTrusteeNameA [ADVAPI32.@]
2850 LPSTR WINAPI GetTrusteeNameA(PTRUSTEEA pTrustee)
2852 TRACE("(%p)\n", pTrustee);
2857 return pTrustee->ptstrName;
2860 /******************************************************************************
2861 * GetTrusteeNameW [ADVAPI32.@]
2863 LPWSTR WINAPI GetTrusteeNameW(PTRUSTEEW pTrustee)
2865 TRACE("(%p)\n", pTrustee);
2870 return pTrustee->ptstrName;
2873 /******************************************************************************
2874 * GetTrusteeTypeA [ADVAPI32.@]
2876 TRUSTEE_TYPE WINAPI GetTrusteeTypeA(PTRUSTEEA pTrustee)
2878 TRACE("(%p)\n", pTrustee);
2881 return TRUSTEE_IS_UNKNOWN;
2883 return pTrustee->TrusteeType;
2886 /******************************************************************************
2887 * GetTrusteeTypeW [ADVAPI32.@]
2889 TRUSTEE_TYPE WINAPI GetTrusteeTypeW(PTRUSTEEW pTrustee)
2891 TRACE("(%p)\n", pTrustee);
2894 return TRUSTEE_IS_UNKNOWN;
2896 return pTrustee->TrusteeType;
2899 BOOL WINAPI SetAclInformation( PACL pAcl, LPVOID pAclInformation,
2900 DWORD nAclInformationLength,
2901 ACL_INFORMATION_CLASS dwAclInformationClass )
2903 FIXME("%p %p 0x%08lx 0x%08x - stub\n", pAcl, pAclInformation,
2904 nAclInformationLength, dwAclInformationClass);
2909 /******************************************************************************
2910 * SetEntriesInAclA [ADVAPI32.@]
2912 DWORD WINAPI SetEntriesInAclA( ULONG count, PEXPLICIT_ACCESSA pEntries,
2913 PACL OldAcl, PACL* NewAcl )
2915 FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
2916 return ERROR_CALL_NOT_IMPLEMENTED;
2919 /******************************************************************************
2920 * SetEntriesInAclW [ADVAPI32.@]
2922 DWORD WINAPI SetEntriesInAclW( ULONG count, PEXPLICIT_ACCESSW pEntries,
2923 PACL OldAcl, PACL* NewAcl )
2925 FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
2926 return ERROR_CALL_NOT_IMPLEMENTED;
2929 /******************************************************************************
2930 * SetNamedSecurityInfoA [ADVAPI32.@]
2932 DWORD WINAPI SetNamedSecurityInfoA(LPSTR pObjectName,
2933 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
2934 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
2940 TRACE("%s %d %ld %p %p %p %p\n", debugstr_a(pObjectName), ObjectType,
2941 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
2945 len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
2946 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
2947 MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
2950 r = SetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, psidOwner,
2951 psidGroup, pDacl, pSacl );
2953 HeapFree( GetProcessHeap(), 0, wstr );
2958 BOOL WINAPI SetPrivateObjectSecurity( SECURITY_INFORMATION SecurityInformation,
2959 PSECURITY_DESCRIPTOR ModificationDescriptor,
2960 PSECURITY_DESCRIPTOR* ObjectsSecurityDescriptor,
2961 PGENERIC_MAPPING GenericMapping,
2964 FIXME("0x%08lx %p %p %p %p - stub\n", SecurityInformation, ModificationDescriptor,
2965 ObjectsSecurityDescriptor, GenericMapping, Token);
2970 BOOL WINAPI SetSecurityDescriptorControl( PSECURITY_DESCRIPTOR pSecurityDescriptor,
2971 SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
2972 SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet )
2974 FIXME("%p 0x%08x 0x%08x - stub\n", pSecurityDescriptor, ControlBitsOfInterest,
2980 BOOL WINAPI AreAllAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
2982 return RtlAreAllAccessesGranted( GrantedAccess, DesiredAccess );
2985 /******************************************************************************
2986 * AreAnyAccessesGranted [ADVAPI32.@]
2988 * Determines whether or not any of a set of specified access permissions have
2989 * been granted or not.
2992 * GrantedAccess [I] The permissions that have been granted.
2993 * DesiredAccess [I] The permissions that you want to have.
2996 * Nonzero if any of the permissions have been granted, zero if none of the
2997 * permissions have been granted.
3000 BOOL WINAPI AreAnyAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
3002 return RtlAreAnyAccessesGranted( GrantedAccess, DesiredAccess );
3005 /******************************************************************************
3006 * SetNamedSecurityInfoW [ADVAPI32.@]
3008 DWORD WINAPI SetNamedSecurityInfoW(LPWSTR pObjectName,
3009 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
3010 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
3012 FIXME("%s %d %ld %p %p %p %p\n", debugstr_w(pObjectName), ObjectType,
3013 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
3014 return ERROR_SUCCESS;
3017 /******************************************************************************
3018 * GetExplicitEntriesFromAclA [ADVAPI32.@]
3020 DWORD WINAPI GetExplicitEntriesFromAclA( PACL pacl, PULONG pcCountOfExplicitEntries,
3021 PEXPLICIT_ACCESSA* pListOfExplicitEntries)
3023 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
3024 return ERROR_CALL_NOT_IMPLEMENTED;
3027 /******************************************************************************
3028 * GetExplicitEntriesFromAclW [ADVAPI32.@]
3030 DWORD WINAPI GetExplicitEntriesFromAclW( PACL pacl, PULONG pcCountOfExplicitEntries,
3031 PEXPLICIT_ACCESSW* pListOfExplicitEntries)
3033 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
3034 return ERROR_CALL_NOT_IMPLEMENTED;
3038 /******************************************************************************
3039 * ParseAclStringFlags
3041 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl)
3044 LPCWSTR szAcl = *StringAcl;
3046 while (*szAcl != '(')
3050 flags |= SE_DACL_PROTECTED;
3052 else if (*szAcl == 'A')
3056 flags |= SE_DACL_AUTO_INHERIT_REQ;
3057 else if (*szAcl == 'I')
3058 flags |= SE_DACL_AUTO_INHERITED;
3067 /******************************************************************************
3068 * ParseAceStringType
3070 static const ACEFLAG AceType[] =
3072 { SDDL_ACCESS_ALLOWED, ACCESS_ALLOWED_ACE_TYPE },
3073 { SDDL_ALARM, SYSTEM_ALARM_ACE_TYPE },
3074 { SDDL_AUDIT, SYSTEM_AUDIT_ACE_TYPE },
3075 { SDDL_ACCESS_DENIED, ACCESS_DENIED_ACE_TYPE },
3077 { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
3078 { SDDL_OBJECT_ACCESS_DENIED, ACCESS_DENIED_OBJECT_ACE_TYPE },
3079 { SDDL_OBJECT_ALARM, SYSTEM_ALARM_OBJECT_ACE_TYPE },
3080 { SDDL_OBJECT_AUDIT, SYSTEM_AUDIT_OBJECT_ACE_TYPE },
3085 static BYTE ParseAceStringType(LPCWSTR* StringAcl)
3088 LPCWSTR szAcl = *StringAcl;
3089 const ACEFLAG *lpaf = AceType;
3091 while (lpaf->wstr &&
3092 (len = strlenW(lpaf->wstr)) &&
3093 strncmpW(lpaf->wstr, szAcl, len))
3104 /******************************************************************************
3105 * ParseAceStringFlags
3107 static const ACEFLAG AceFlags[] =
3109 { SDDL_CONTAINER_INHERIT, CONTAINER_INHERIT_ACE },
3110 { SDDL_AUDIT_FAILURE, FAILED_ACCESS_ACE_FLAG },
3111 { SDDL_INHERITED, INHERITED_ACE },
3112 { SDDL_INHERIT_ONLY, INHERIT_ONLY_ACE },
3113 { SDDL_NO_PROPAGATE, NO_PROPAGATE_INHERIT_ACE },
3114 { SDDL_OBJECT_INHERIT, OBJECT_INHERIT_ACE },
3115 { SDDL_AUDIT_SUCCESS, SUCCESSFUL_ACCESS_ACE_FLAG },
3119 static BYTE ParseAceStringFlags(LPCWSTR* StringAcl)
3123 LPCWSTR szAcl = *StringAcl;
3125 while (*szAcl != ';')
3127 const ACEFLAG *lpaf = AceFlags;
3129 while (lpaf->wstr &&
3130 (len = strlenW(lpaf->wstr)) &&
3131 strncmpW(lpaf->wstr, szAcl, len))
3137 flags |= lpaf->value;
3146 /******************************************************************************
3147 * ParseAceStringRights
3149 static const ACEFLAG AceRights[] =
3151 { SDDL_GENERIC_ALL, GENERIC_ALL },
3152 { SDDL_GENERIC_READ, GENERIC_READ },
3153 { SDDL_GENERIC_WRITE, GENERIC_WRITE },
3154 { SDDL_GENERIC_EXECUTE, GENERIC_EXECUTE },
3155 { SDDL_READ_CONTROL, READ_CONTROL },
3156 { SDDL_STANDARD_DELETE, DELETE },
3157 { SDDL_WRITE_DAC, WRITE_DAC },
3158 { SDDL_WRITE_OWNER, WRITE_OWNER },
3162 static DWORD ParseAceStringRights(LPCWSTR* StringAcl)
3166 LPCWSTR szAcl = *StringAcl;
3168 if ((*szAcl == '0') && (*(szAcl + 1) == 'x'))
3172 while (*p && *p != ';')
3177 rights = strtoulW(szAcl, NULL, 16);
3181 WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl, p - szAcl));
3185 while (*szAcl != ';')
3187 const ACEFLAG *lpaf = AceRights;
3189 while (lpaf->wstr &&
3190 (len = strlenW(lpaf->wstr)) &&
3191 strncmpW(lpaf->wstr, szAcl, len))
3199 rights |= lpaf->value;
3209 /******************************************************************************
3210 * ParseStringAclToAcl
3212 * dacl_flags(string_ace1)(string_ace2)... (string_acen)
3214 static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags,
3215 PACL pAcl, LPDWORD cBytes)
3219 DWORD length = sizeof(ACL);
3220 PACCESS_ALLOWED_ACE pAce = NULL; /* pointer to current ACE */
3222 TRACE("%s\n", debugstr_w(StringAcl));
3227 if (pAcl) /* pAce is only useful if we're setting values */
3228 pAce = (PACCESS_ALLOWED_ACE) ((LPBYTE)pAcl + sizeof(PACL));
3230 /* Parse ACL flags */
3231 *lpdwFlags = ParseAclStringFlags(&StringAcl);
3234 while (*StringAcl == '(')
3238 /* Parse ACE type */
3239 val = ParseAceStringType(&StringAcl);
3241 pAce->Header.AceType = (BYTE) val;
3242 if (*StringAcl != ';')
3246 /* Parse ACE flags */
3247 val = ParseAceStringFlags(&StringAcl);
3249 pAce->Header.AceFlags = (BYTE) val;
3250 if (*StringAcl != ';')
3254 /* Parse ACE rights */
3255 val = ParseAceStringRights(&StringAcl);
3258 if (*StringAcl != ';')
3262 /* Parse ACE object guid */
3263 if (*StringAcl != ';')
3265 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3270 /* Parse ACE inherit object guid */
3271 if (*StringAcl != ';')
3273 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3278 /* Parse ACE account sid */
3279 if (ParseStringSidToSid(StringAcl, pAce ? (PSID)&pAce->SidStart : NULL, &sidlen))
3281 while (*StringAcl && *StringAcl != ')')
3285 if (*StringAcl != ')')
3289 length += sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) + sidlen;
3296 WARN("Invalid ACE string format\n");
3301 /******************************************************************************
3302 * ParseStringSecurityDescriptorToSecurityDescriptor
3304 static BOOL ParseStringSecurityDescriptorToSecurityDescriptor(
3305 LPCWSTR StringSecurityDescriptor,
3306 SECURITY_DESCRIPTOR* SecurityDescriptor,
3311 WCHAR tok[MAX_PATH];
3313 LPBYTE lpNext = NULL;
3318 if (SecurityDescriptor)
3319 lpNext = ((LPBYTE) SecurityDescriptor) + sizeof(SECURITY_DESCRIPTOR);
3321 while (*StringSecurityDescriptor)
3323 toktype = *StringSecurityDescriptor;
3325 /* Expect char identifier followed by ':' */
3326 StringSecurityDescriptor++;
3327 if (*StringSecurityDescriptor != ':')
3329 SetLastError(ERROR_INVALID_PARAMETER);
3332 StringSecurityDescriptor++;
3335 lptoken = StringSecurityDescriptor;
3336 while (*lptoken && *lptoken != ':')
3342 len = lptoken - StringSecurityDescriptor;
3343 memcpy( tok, StringSecurityDescriptor, len * sizeof(WCHAR) );
3352 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
3355 if (SecurityDescriptor)
3357 SecurityDescriptor->Owner = (PSID)(lpNext - (LPBYTE)SecurityDescriptor);
3358 lpNext += bytes; /* Advance to next token */
3370 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
3373 if (SecurityDescriptor)
3375 SecurityDescriptor->Group = (PSID)(lpNext - (LPBYTE)SecurityDescriptor);
3376 lpNext += bytes; /* Advance to next token */
3389 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
3392 if (SecurityDescriptor)
3394 SecurityDescriptor->Control |= SE_DACL_PRESENT | flags;
3395 SecurityDescriptor->Dacl = (PACL)(lpNext - (LPBYTE)SecurityDescriptor);
3396 lpNext += bytes; /* Advance to next token */
3409 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
3412 if (SecurityDescriptor)
3414 SecurityDescriptor->Control |= SE_SACL_PRESENT | flags;
3415 SecurityDescriptor->Sacl = (PACL)(lpNext - (LPBYTE)SecurityDescriptor);
3416 lpNext += bytes; /* Advance to next token */
3425 FIXME("Unknown token\n");
3426 SetLastError(ERROR_INVALID_PARAMETER);
3430 StringSecurityDescriptor = lptoken;
3439 /******************************************************************************
3440 * ConvertStringSecurityDescriptorToSecurityDescriptorA [ADVAPI32.@]
3442 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorA(
3443 LPCSTR StringSecurityDescriptor,
3444 DWORD StringSDRevision,
3445 PSECURITY_DESCRIPTOR* SecurityDescriptor,
3446 PULONG SecurityDescriptorSize)
3450 LPWSTR StringSecurityDescriptorW;
3452 len = MultiByteToWideChar(CP_ACP, 0, StringSecurityDescriptor, -1, NULL, 0);
3453 StringSecurityDescriptorW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3455 if (StringSecurityDescriptorW)
3457 MultiByteToWideChar(CP_ACP, 0, StringSecurityDescriptor, -1, StringSecurityDescriptorW, len);
3459 ret = ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptorW,
3460 StringSDRevision, SecurityDescriptor,
3461 SecurityDescriptorSize);
3462 HeapFree(GetProcessHeap(), 0, StringSecurityDescriptorW);
3468 /******************************************************************************
3469 * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
3471 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW(
3472 LPCWSTR StringSecurityDescriptor,
3473 DWORD StringSDRevision,
3474 PSECURITY_DESCRIPTOR* SecurityDescriptor,
3475 PULONG SecurityDescriptorSize)
3478 SECURITY_DESCRIPTOR* psd;
3481 TRACE("%s\n", debugstr_w(StringSecurityDescriptor));
3483 if (GetVersion() & 0x80000000)
3485 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3488 else if (StringSDRevision != SID_REVISION)
3490 SetLastError(ERROR_UNKNOWN_REVISION);
3494 /* Compute security descriptor length */
3495 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
3499 psd = *SecurityDescriptor = (SECURITY_DESCRIPTOR*) LocalAlloc(
3500 GMEM_ZEROINIT, cBytes);
3502 psd->Revision = SID_REVISION;
3503 psd->Control |= SE_SELF_RELATIVE;
3505 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
3512 if (SecurityDescriptorSize)
3513 *SecurityDescriptorSize = cBytes;
3518 TRACE(" ret=%d\n", bret);
3522 /******************************************************************************
3523 * ConvertStringSidToSidW [ADVAPI32.@]
3525 BOOL WINAPI ConvertStringSidToSidW(LPCWSTR StringSid, PSID* Sid)
3530 TRACE("%s, %p\n", debugstr_w(StringSid), Sid);
3531 if (GetVersion() & 0x80000000)
3532 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3533 else if (!StringSid || !Sid)
3534 SetLastError(ERROR_INVALID_PARAMETER);
3535 else if (ParseStringSidToSid(StringSid, NULL, &cBytes))
3537 PSID pSid = *Sid = (PSID) LocalAlloc(0, cBytes);
3539 bret = ParseStringSidToSid(StringSid, pSid, &cBytes);
3543 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
3547 /******************************************************************************
3548 * ConvertStringSidToSidA [ADVAPI32.@]
3550 BOOL WINAPI ConvertStringSidToSidA(LPCSTR StringSid, PSID* Sid)
3554 TRACE("%s, %p\n", debugstr_a(StringSid), Sid);
3555 if (GetVersion() & 0x80000000)
3556 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3557 else if (!StringSid || !Sid)
3558 SetLastError(ERROR_INVALID_PARAMETER);
3561 UINT len = MultiByteToWideChar(CP_ACP, 0, StringSid, -1, NULL, 0);
3562 LPWSTR wStringSid = HeapAlloc(GetProcessHeap(), 0,
3563 len * sizeof(WCHAR));
3565 MultiByteToWideChar(CP_ACP, 0, StringSid, -1, wStringSid, len);
3566 bret = ConvertStringSidToSidW(wStringSid, Sid);
3567 HeapFree(GetProcessHeap(), 0, wStringSid);
3569 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
3573 /******************************************************************************
3574 * ConvertSidToStringSidW [ADVAPI32.@]
3576 * format of SID string is:
3577 * S-<count>-<auth>-<subauth1>-<subauth2>-<subauth3>...
3579 * <rev> is the revision of the SID encoded as decimal
3580 * <auth> is the identifier authority encoded as hex
3581 * <subauthN> is the subauthority id encoded as decimal
3583 BOOL WINAPI ConvertSidToStringSidW( PSID pSid, LPWSTR *pstr )
3587 WCHAR fmt[] = { 'S','-','%','u','-','%','d',0 };
3588 WCHAR subauthfmt[] = { '-','%','u',0 };
3591 TRACE("%p %p\n", pSid, pstr );
3593 if( !IsValidSid( pSid ) )
3596 if (pisid->Revision != SDDL_REVISION)
3598 if (pisid->IdentifierAuthority.Value[0] ||
3599 pisid->IdentifierAuthority.Value[1])
3601 FIXME("not matching MS' bugs\n");
3605 sz = 14 + pisid->SubAuthorityCount * 11;
3606 str = LocalAlloc( 0, sz*sizeof(WCHAR) );
3607 sprintfW( str, fmt, pisid->Revision, MAKELONG(
3608 MAKEWORD( pisid->IdentifierAuthority.Value[5],
3609 pisid->IdentifierAuthority.Value[4] ),
3610 MAKEWORD( pisid->IdentifierAuthority.Value[3],
3611 pisid->IdentifierAuthority.Value[2] ) ) );
3612 for( i=0; i<pisid->SubAuthorityCount; i++ )
3613 sprintfW( str + strlenW(str), subauthfmt, pisid->SubAuthority[i] );
3619 /******************************************************************************
3620 * ConvertSidToStringSidA [ADVAPI32.@]
3622 BOOL WINAPI ConvertSidToStringSidA(PSID pSid, LPSTR *pstr)
3628 TRACE("%p %p\n", pSid, pstr );
3630 if( !ConvertSidToStringSidW( pSid, &wstr ) )
3633 len = WideCharToMultiByte( CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL );
3634 str = LocalAlloc( 0, len );
3635 WideCharToMultiByte( CP_ACP, 0, wstr, -1, str, len, NULL, NULL );
3643 BOOL WINAPI CreatePrivateObjectSecurity(
3644 PSECURITY_DESCRIPTOR ParentDescriptor,
3645 PSECURITY_DESCRIPTOR CreatorDescriptor,
3646 PSECURITY_DESCRIPTOR* NewDescriptor,
3647 BOOL IsDirectoryObject,
3649 PGENERIC_MAPPING GenericMapping )
3651 FIXME("%p %p %p %d %p %p - stub\n", ParentDescriptor, CreatorDescriptor,
3652 NewDescriptor, IsDirectoryObject, Token, GenericMapping);
3657 BOOL WINAPI DestroyPrivateObjectSecurity( PSECURITY_DESCRIPTOR* ObjectDescriptor )
3659 FIXME("%p - stub\n", ObjectDescriptor);
3664 BOOL WINAPI CreateProcessAsUserA(
3666 LPCSTR lpApplicationName,
3667 LPSTR lpCommandLine,
3668 LPSECURITY_ATTRIBUTES lpProcessAttributes,
3669 LPSECURITY_ATTRIBUTES lpThreadAttributes,
3670 BOOL bInheritHandles,
3671 DWORD dwCreationFlags,
3672 LPVOID lpEnvironment,
3673 LPCSTR lpCurrentDirectory,
3674 LPSTARTUPINFOA lpStartupInfo,
3675 LPPROCESS_INFORMATION lpProcessInformation )
3677 FIXME("%p %s %s %p %p %d 0x%08lx %p %s %p %p - stub\n", hToken, debugstr_a(lpApplicationName),
3678 debugstr_a(lpCommandLine), lpProcessAttributes, lpThreadAttributes, bInheritHandles,
3679 dwCreationFlags, lpEnvironment, debugstr_a(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
3684 BOOL WINAPI CreateProcessAsUserW(
3686 LPCWSTR lpApplicationName,
3687 LPWSTR lpCommandLine,
3688 LPSECURITY_ATTRIBUTES lpProcessAttributes,
3689 LPSECURITY_ATTRIBUTES lpThreadAttributes,
3690 BOOL bInheritHandles,
3691 DWORD dwCreationFlags,
3692 LPVOID lpEnvironment,
3693 LPCWSTR lpCurrentDirectory,
3694 LPSTARTUPINFOW lpStartupInfo,
3695 LPPROCESS_INFORMATION lpProcessInformation )
3697 FIXME("%p %s %s %p %p %d 0x%08lx %p %s %p %p - semi- stub\n", hToken,
3698 debugstr_w(lpApplicationName), debugstr_w(lpCommandLine), lpProcessAttributes,
3699 lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment,
3700 debugstr_w(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
3702 /* We should create the process with a suspended main thread */
3703 if (!CreateProcessW (lpApplicationName,
3705 lpProcessAttributes,
3708 dwCreationFlags, /* CREATE_SUSPENDED */
3712 lpProcessInformation))
3720 BOOL WINAPI DuplicateTokenEx(
3721 HANDLE ExistingTokenHandle, DWORD dwDesiredAccess,
3722 LPSECURITY_ATTRIBUTES lpTokenAttributes,
3723 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
3724 TOKEN_TYPE TokenType,
3725 PHANDLE DuplicateTokenHandle )
3727 OBJECT_ATTRIBUTES ObjectAttributes;
3729 TRACE("%p 0x%08lx 0x%08x 0x%08x %p\n", ExistingTokenHandle, dwDesiredAccess,
3730 ImpersonationLevel, TokenType, DuplicateTokenHandle);
3732 InitializeObjectAttributes(
3735 (lpTokenAttributes && lpTokenAttributes->bInheritHandle) ? OBJ_INHERIT : 0,
3737 lpTokenAttributes ? lpTokenAttributes->lpSecurityDescriptor : NULL );
3739 return set_ntstatus( NtDuplicateToken( ExistingTokenHandle,
3744 DuplicateTokenHandle ) );
3747 BOOL WINAPI DuplicateToken(
3748 HANDLE ExistingTokenHandle,
3749 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
3750 PHANDLE DuplicateTokenHandle )
3752 return DuplicateTokenEx( ExistingTokenHandle, TOKEN_IMPERSONATE | TOKEN_QUERY,
3753 NULL, ImpersonationLevel, TokenImpersonation,
3754 DuplicateTokenHandle );
3757 BOOL WINAPI EnumDependentServicesA(
3759 DWORD dwServiceState,
3760 LPENUM_SERVICE_STATUSA lpServices,
3762 LPDWORD pcbBytesNeeded,
3763 LPDWORD lpServicesReturned )
3765 FIXME("%p 0x%08lx %p 0x%08lx %p %p - stub\n", hService, dwServiceState,
3766 lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned);
3771 BOOL WINAPI EnumDependentServicesW(
3773 DWORD dwServiceState,
3774 LPENUM_SERVICE_STATUSW lpServices,
3776 LPDWORD pcbBytesNeeded,
3777 LPDWORD lpServicesReturned )
3779 FIXME("%p 0x%08lx %p 0x%08lx %p %p - stub\n", hService, dwServiceState,
3780 lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned);
3785 /******************************************************************************
3786 * ComputeStringSidSize
3788 static DWORD ComputeStringSidSize(LPCWSTR StringSid)
3790 DWORD size = sizeof(SID);
3792 if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I-S-S */
3797 if (*StringSid == '-')
3803 size += (ctok - 3) * sizeof(DWORD);
3805 else /* String constant format - Only available in winxp and above */
3809 for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++)
3810 if (!strncmpW(WellKnownSids[i].wstr, StringSid, 2))
3811 size += (WellKnownSids[i].Sid.SubAuthorityCount - 1) * sizeof(DWORD);
3817 /******************************************************************************
3818 * ParseStringSidToSid
3820 static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes)
3825 TRACE("%s, %p, %p\n", debugstr_w(StringSid), pSid, cBytes);
3828 SetLastError(ERROR_INVALID_PARAMETER);
3829 TRACE("StringSid is NULL, returning FALSE\n");
3833 *cBytes = ComputeStringSidSize(StringSid);
3834 if (!pisid) /* Simply compute the size */
3836 TRACE("only size requested, returning TRUE\n");
3840 if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I-S-S */
3842 DWORD i = 0, identAuth;
3843 DWORD csubauth = ((*cBytes - sizeof(SID)) / sizeof(DWORD)) + 1;
3845 StringSid += 2; /* Advance to Revision */
3846 pisid->Revision = atoiW(StringSid);
3848 if (pisid->Revision != SDDL_REVISION)
3850 TRACE("Revision %d is unknown\n", pisid->Revision);
3851 goto lend; /* ERROR_INVALID_SID */
3855 TRACE("SubAuthorityCount is 0\n");
3856 goto lend; /* ERROR_INVALID_SID */
3859 pisid->SubAuthorityCount = csubauth;
3861 /* Advance to identifier authority */
3862 while (*StringSid && *StringSid != '-')
3864 if (*StringSid == '-')
3867 /* MS' implementation can't handle values greater than 2^32 - 1, so
3868 * we don't either; assume most significant bytes are always 0
3870 pisid->IdentifierAuthority.Value[0] = 0;
3871 pisid->IdentifierAuthority.Value[1] = 0;
3872 identAuth = atoiW(StringSid);
3873 pisid->IdentifierAuthority.Value[5] = identAuth & 0xff;
3874 pisid->IdentifierAuthority.Value[4] = (identAuth & 0xff00) >> 8;
3875 pisid->IdentifierAuthority.Value[3] = (identAuth & 0xff0000) >> 16;
3876 pisid->IdentifierAuthority.Value[2] = (identAuth & 0xff000000) >> 24;
3878 /* Advance to first sub authority */
3879 while (*StringSid && *StringSid != '-')
3881 if (*StringSid == '-')
3886 while (*StringSid && *StringSid != '-')
3888 if (*StringSid == '-')
3891 pisid->SubAuthority[i++] = atoiW(StringSid);
3894 if (i != pisid->SubAuthorityCount)
3895 goto lend; /* ERROR_INVALID_SID */
3899 else /* String constant format - Only available in winxp and above */
3902 pisid->Revision = SDDL_REVISION;
3904 for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++)
3905 if (!strncmpW(WellKnownSids[i].wstr, StringSid, 2))
3908 pisid->SubAuthorityCount = WellKnownSids[i].Sid.SubAuthorityCount;
3909 pisid->IdentifierAuthority = WellKnownSids[i].Sid.IdentifierAuthority;
3910 for (j = 0; j < WellKnownSids[i].Sid.SubAuthorityCount; j++)
3911 pisid->SubAuthority[j] = WellKnownSids[i].Sid.SubAuthority[j];
3916 FIXME("String constant not supported: %s\n", debugstr_wn(StringSid, 2));
3921 SetLastError(ERROR_INVALID_SID);
3923 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
3927 /******************************************************************************
3928 * GetNamedSecurityInfoA [ADVAPI32.@]
3930 DWORD WINAPI GetNamedSecurityInfoA(LPSTR pObjectName,
3931 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
3932 PSID* ppsidOwner, PSID* ppsidGroup, PACL* ppDacl, PACL* ppSacl,
3933 PSECURITY_DESCRIPTOR* ppSecurityDescriptor)
3939 TRACE("%s %d %ld %p %p %p %p %p\n", pObjectName, ObjectType, SecurityInfo,
3940 ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
3944 len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
3945 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
3946 MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
3949 r = GetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, ppsidOwner,
3950 ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor );
3952 HeapFree( GetProcessHeap(), 0, wstr );
3957 /******************************************************************************
3958 * GetNamedSecurityInfoW [ADVAPI32.@]
3960 DWORD WINAPI GetNamedSecurityInfoW( LPWSTR name, SE_OBJECT_TYPE type,
3961 SECURITY_INFORMATION info, PSID* owner, PSID* group, PACL* dacl,
3962 PACL* sacl, PSECURITY_DESCRIPTOR* descriptor )
3964 DWORD needed, offset;
3965 SECURITY_DESCRIPTOR_RELATIVE *relative;
3968 TRACE( "%s %d %ld %p %p %p %p %p\n", debugstr_w(name), type, info, owner,
3969 group, dacl, sacl, descriptor );
3971 if (!name || !descriptor) return ERROR_INVALID_PARAMETER;
3973 needed = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
3974 if (info & OWNER_SECURITY_INFORMATION)
3975 needed += sizeof(sidWorld);
3976 if (info & GROUP_SECURITY_INFORMATION)
3977 needed += sizeof(sidWorld);
3978 if (info & DACL_SECURITY_INFORMATION)
3979 needed += WINE_SIZE_OF_WORLD_ACCESS_ACL;
3980 if (info & SACL_SECURITY_INFORMATION)
3981 needed += WINE_SIZE_OF_WORLD_ACCESS_ACL;
3983 /* must be freed by caller */
3984 *descriptor = HeapAlloc( GetProcessHeap(), 0, needed );
3985 if (!*descriptor) return ERROR_NOT_ENOUGH_MEMORY;
3987 if (!InitializeSecurityDescriptor( *descriptor, SECURITY_DESCRIPTOR_REVISION ))
3989 HeapFree( GetProcessHeap(), 0, *descriptor );
3990 return ERROR_INVALID_SECURITY_DESCR;
3993 relative = (SECURITY_DESCRIPTOR_RELATIVE *)*descriptor;
3994 relative->Control |= SE_SELF_RELATIVE;
3995 buffer = (BYTE *)relative;
3996 offset = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
3998 if (owner && (info & OWNER_SECURITY_INFORMATION))
4000 memcpy( buffer + offset, &sidWorld, sizeof(sidWorld) );
4001 relative->Owner = offset;
4002 *owner = buffer + offset;
4003 offset += sizeof(sidWorld);
4005 if (group && (info & GROUP_SECURITY_INFORMATION))
4007 memcpy( buffer + offset, &sidWorld, sizeof(sidWorld) );
4008 relative->Group = offset;
4009 *group = buffer + offset;
4010 offset += sizeof(sidWorld);
4012 if (dacl && (info & DACL_SECURITY_INFORMATION))
4014 GetWorldAccessACL( (PACL)(buffer + offset) );
4015 relative->Dacl = offset;
4016 *dacl = (PACL)(buffer + offset);
4017 offset += WINE_SIZE_OF_WORLD_ACCESS_ACL;
4019 if (sacl && (info & SACL_SECURITY_INFORMATION))
4021 GetWorldAccessACL( (PACL)(buffer + offset) );
4022 relative->Sacl = offset;
4023 *sacl = (PACL)(buffer + offset);
4025 return ERROR_SUCCESS;
4028 /******************************************************************************
4029 * DecryptFileW [ADVAPI32.@]
4031 BOOL WINAPI DecryptFileW(LPCWSTR lpFileName, DWORD dwReserved)
4033 FIXME("%s %08lx\n", debugstr_w(lpFileName), dwReserved);
4037 /******************************************************************************
4038 * DecryptFileA [ADVAPI32.@]
4040 BOOL WINAPI DecryptFileA(LPCSTR lpFileName, DWORD dwReserved)
4042 FIXME("%s %08lx\n", debugstr_a(lpFileName), dwReserved);
4046 /******************************************************************************
4047 * EncryptFileW [ADVAPI32.@]
4049 BOOL WINAPI EncryptFileW(LPCWSTR lpFileName)
4051 FIXME("%s\n", debugstr_w(lpFileName));
4055 /******************************************************************************
4056 * EncryptFileA [ADVAPI32.@]
4058 BOOL WINAPI EncryptFileA(LPCSTR lpFileName)
4060 FIXME("%s\n", debugstr_a(lpFileName));
4064 /******************************************************************************
4065 * FileEncryptionStatusW [ADVAPI32.@]
4067 BOOL WINAPI FileEncryptionStatusW(LPCWSTR lpFileName, LPDWORD lpStatus)
4069 FIXME("(%s %p): stub\n", debugstr_w(lpFileName), lpStatus);
4072 *lpStatus = FILE_SYSTEM_NOT_SUPPORT;
4076 /******************************************************************************
4077 * FileEncryptionStatusA [ADVAPI32.@]
4079 BOOL WINAPI FileEncryptionStatusA(LPCSTR lpFileName, LPDWORD lpStatus)
4081 FIXME("(%s %p): stub\n", debugstr_a(lpFileName), lpStatus);
4084 *lpStatus = FILE_SYSTEM_NOT_SUPPORT;
4088 /******************************************************************************
4089 * SetSecurityInfo [ADVAPI32.@]
4091 DWORD WINAPI SetSecurityInfo(HANDLE handle, SE_OBJECT_TYPE ObjectType,
4092 SECURITY_INFORMATION SecurityInfo, PSID psidOwner,
4093 PSID psidGroup, PACL pDacl, PACL pSacl) {
4095 return ERROR_SUCCESS;