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;
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;
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_NOT_ENOUGH_MEMORY);
2013 *domainSize = strlenW(dm) + 1;
2014 *accountSize = strlenW(ac) + 1;
2016 HeapFree(GetProcessHeap(), 0, computer_name);
2020 HeapFree(GetProcessHeap(), 0, computer_name);
2021 SetLastError(ERROR_NONE_MAPPED);
2025 /******************************************************************************
2026 * SetFileSecurityA [ADVAPI32.@]
2028 * See SetFileSecurityW.
2030 BOOL WINAPI SetFileSecurityA( LPCSTR lpFileName,
2031 SECURITY_INFORMATION RequestedInformation,
2032 PSECURITY_DESCRIPTOR pSecurityDescriptor)
2040 len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 );
2041 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
2042 MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len );
2045 r = SetFileSecurityW( name, RequestedInformation, pSecurityDescriptor );
2046 HeapFree( GetProcessHeap(), 0, name );
2051 /******************************************************************************
2052 * SetFileSecurityW [ADVAPI32.@]
2054 * Sets the security of a file or directory.
2058 * RequestedInformation []
2059 * pSecurityDescriptor []
2066 SetFileSecurityW( LPCWSTR lpFileName,
2067 SECURITY_INFORMATION RequestedInformation,
2068 PSECURITY_DESCRIPTOR pSecurityDescriptor )
2070 FIXME("(%s) : stub\n", debugstr_w(lpFileName) );
2074 /******************************************************************************
2075 * QueryWindows31FilesMigration [ADVAPI32.@]
2081 QueryWindows31FilesMigration( DWORD x1 )
2083 FIXME("(%ld):stub\n",x1);
2087 /******************************************************************************
2088 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
2097 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
2100 FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1,x2,x3,x4);
2104 /******************************************************************************
2105 * NotifyBootConfigStatus [ADVAPI32.@]
2111 NotifyBootConfigStatus( BOOL x1 )
2113 FIXME("(0x%08d):stub\n",x1);
2117 /******************************************************************************
2118 * RevertToSelf [ADVAPI32.@]
2120 * Ends the impersonation of a user.
2130 RevertToSelf( void )
2132 HANDLE Token = NULL;
2133 return set_ntstatus( NtSetInformationThread( GetCurrentThread(),
2134 ThreadImpersonationToken, &Token, sizeof(Token) ) );
2137 /******************************************************************************
2138 * ImpersonateSelf [ADVAPI32.@]
2140 * Makes an impersonation token that represents the process user and assigns
2141 * to the current thread.
2144 * ImpersonationLevel [I] Level at which to impersonate.
2151 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
2153 return set_ntstatus( RtlImpersonateSelf( ImpersonationLevel ) );
2156 /******************************************************************************
2157 * ImpersonateLoggedOnUser [ADVAPI32.@]
2159 BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
2163 HANDLE ImpersonationToken;
2166 FIXME( "(%p)\n", hToken );
2168 if (!GetTokenInformation( hToken, TokenType, &Type,
2169 sizeof(TOKEN_TYPE), &size ))
2172 if (Type == TokenPrimary)
2174 OBJECT_ATTRIBUTES ObjectAttributes;
2176 InitializeObjectAttributes( &ObjectAttributes, NULL, 0, NULL, NULL );
2178 Status = NtDuplicateToken( hToken,
2179 TOKEN_IMPERSONATE | TOKEN_QUERY,
2181 SecurityImpersonation,
2183 &ImpersonationToken );
2184 if (Status != STATUS_SUCCESS)
2186 ERR( "NtDuplicateToken failed with error 0x%08lx\n", Status );
2187 SetLastError( RtlNtStatusToDosError( Status ) );
2192 ImpersonationToken = hToken;
2194 Status = NtSetInformationThread( GetCurrentThread(),
2195 ThreadImpersonationToken,
2196 &ImpersonationToken,
2197 sizeof(ImpersonationToken) );
2199 if (Type == TokenPrimary)
2200 NtClose( ImpersonationToken );
2202 if (Status != STATUS_SUCCESS)
2204 ERR( "NtSetInformationThread failed with error 0x%08lx\n", Status );
2205 SetLastError( RtlNtStatusToDosError( Status ) );
2212 /******************************************************************************
2213 * AccessCheck [ADVAPI32.@]
2217 PSECURITY_DESCRIPTOR SecurityDescriptor,
2219 DWORD DesiredAccess,
2220 PGENERIC_MAPPING GenericMapping,
2221 PPRIVILEGE_SET PrivilegeSet,
2222 LPDWORD PrivilegeSetLength,
2223 LPDWORD GrantedAccess,
2224 LPBOOL AccessStatus)
2226 NTSTATUS access_status;
2227 BOOL ret = set_ntstatus( NtAccessCheck(SecurityDescriptor, ClientToken, DesiredAccess,
2228 GenericMapping, PrivilegeSet, PrivilegeSetLength,
2229 GrantedAccess, &access_status) );
2230 if (ret) *AccessStatus = set_ntstatus( access_status );
2235 /******************************************************************************
2236 * AccessCheckByType [ADVAPI32.@]
2238 BOOL WINAPI AccessCheckByType(
2239 PSECURITY_DESCRIPTOR pSecurityDescriptor,
2240 PSID PrincipalSelfSid,
2242 DWORD DesiredAccess,
2243 POBJECT_TYPE_LIST ObjectTypeList,
2244 DWORD ObjectTypeListLength,
2245 PGENERIC_MAPPING GenericMapping,
2246 PPRIVILEGE_SET PrivilegeSet,
2247 LPDWORD PrivilegeSetLength,
2248 LPDWORD GrantedAccess,
2249 LPBOOL AccessStatus)
2253 *AccessStatus = TRUE;
2255 return !*AccessStatus;
2258 /******************************************************************************
2259 * MapGenericMask [ADVAPI32.@]
2261 * Maps generic access rights into specific access rights according to the
2265 * AccessMask [I/O] Access rights.
2266 * GenericMapping [I] The mapping between generic and specific rights.
2271 VOID WINAPI MapGenericMask( PDWORD AccessMask, PGENERIC_MAPPING GenericMapping )
2273 RtlMapGenericMask( AccessMask, GenericMapping );
2276 /*************************************************************************
2277 * SetKernelObjectSecurity [ADVAPI32.@]
2279 BOOL WINAPI SetKernelObjectSecurity (
2281 IN SECURITY_INFORMATION SecurityInformation,
2282 IN PSECURITY_DESCRIPTOR SecurityDescriptor )
2284 return set_ntstatus (NtSetSecurityObject (Handle, SecurityInformation, SecurityDescriptor));
2288 /******************************************************************************
2289 * AddAuditAccessAce [ADVAPI32.@]
2291 BOOL WINAPI AddAuditAccessAce(
2293 IN DWORD dwAceRevision,
2294 IN DWORD dwAccessMask,
2296 IN BOOL bAuditSuccess,
2297 IN BOOL bAuditFailure)
2299 return set_ntstatus( RtlAddAuditAccessAce(pAcl, dwAceRevision, dwAccessMask, pSid,
2300 bAuditSuccess, bAuditFailure) );
2303 /******************************************************************************
2304 * LookupAccountNameA [ADVAPI32.@]
2312 LPSTR ReferencedDomainName,
2313 IN OUT LPDWORD cbReferencedDomainName,
2314 OUT PSID_NAME_USE name_use )
2317 UNICODE_STRING lpSystemW;
2318 UNICODE_STRING lpAccountW;
2319 LPWSTR lpReferencedDomainNameW = NULL;
2321 RtlCreateUnicodeStringFromAsciiz(&lpSystemW, system);
2322 RtlCreateUnicodeStringFromAsciiz(&lpAccountW, account);
2324 if (ReferencedDomainName)
2325 lpReferencedDomainNameW = HeapAlloc(GetProcessHeap(), 0, *cbReferencedDomainName * sizeof(WCHAR));
2327 ret = LookupAccountNameW(lpSystemW.Buffer, lpAccountW.Buffer, sid, cbSid, lpReferencedDomainNameW,
2328 cbReferencedDomainName, name_use);
2330 if (ret && lpReferencedDomainNameW)
2332 WideCharToMultiByte(CP_ACP, 0, lpReferencedDomainNameW, *cbReferencedDomainName,
2333 ReferencedDomainName, *cbReferencedDomainName, NULL, NULL);
2336 RtlFreeUnicodeString(&lpSystemW);
2337 RtlFreeUnicodeString(&lpAccountW);
2338 HeapFree(GetProcessHeap(), 0, lpReferencedDomainNameW);
2343 /******************************************************************************
2344 * LookupAccountNameW [ADVAPI32.@]
2346 BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSID Sid,
2347 LPDWORD cbSid, LPWSTR ReferencedDomainName,
2348 LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse )
2350 /* Default implementation: Always return a default SID */
2351 SID_IDENTIFIER_AUTHORITY identifierAuthority = {SECURITY_NT_AUTHORITY};
2354 static const WCHAR dm[] = {'D','O','M','A','I','N',0};
2356 FIXME("%s %s %p %p %p %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpAccountName),
2357 Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse);
2359 ret = AllocateAndInitializeSid(&identifierAuthority,
2361 SECURITY_BUILTIN_DOMAIN_RID,
2362 DOMAIN_ALIAS_RID_ADMINS,
2369 if (!RtlValidSid(pSid))
2375 if (Sid != NULL && (*cbSid >= GetLengthSid(pSid)))
2376 CopySid(*cbSid, Sid, pSid);
2377 if (*cbSid < GetLengthSid(pSid))
2379 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2382 *cbSid = GetLengthSid(pSid);
2384 if (ReferencedDomainName != NULL && (*cchReferencedDomainName > strlenW(dm)))
2385 strcpyW(ReferencedDomainName, dm);
2387 if (*cchReferencedDomainName <= strlenW(dm))
2389 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2393 *cchReferencedDomainName = strlenW(dm)+1;
2400 /******************************************************************************
2401 * PrivilegeCheck [ADVAPI32.@]
2403 BOOL WINAPI PrivilegeCheck( HANDLE ClientToken, PPRIVILEGE_SET RequiredPrivileges, LPBOOL pfResult)
2408 TRACE("%p %p %p\n", ClientToken, RequiredPrivileges, pfResult);
2410 ret = set_ntstatus (NtPrivilegeCheck (ClientToken, RequiredPrivileges, &Result));
2416 /******************************************************************************
2417 * AccessCheckAndAuditAlarmA [ADVAPI32.@]
2419 BOOL WINAPI AccessCheckAndAuditAlarmA(LPCSTR Subsystem, LPVOID HandleId, LPSTR ObjectTypeName,
2420 LPSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
2421 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
2422 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
2424 FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_a(Subsystem),
2425 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName),
2426 SecurityDescriptor, DesiredAccess, GenericMapping,
2427 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
2431 /******************************************************************************
2432 * AccessCheckAndAuditAlarmW [ADVAPI32.@]
2434 BOOL WINAPI AccessCheckAndAuditAlarmW(LPCWSTR Subsystem, LPVOID HandleId, LPWSTR ObjectTypeName,
2435 LPWSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
2436 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
2437 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
2439 FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_w(Subsystem),
2440 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName),
2441 SecurityDescriptor, DesiredAccess, GenericMapping,
2442 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
2446 BOOL WINAPI ObjectCloseAuditAlarmA(LPCSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
2448 FIXME("stub (%s,%p,%x)\n", debugstr_a(SubsystemName), HandleId, GenerateOnClose);
2453 BOOL WINAPI ObjectCloseAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
2455 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName), HandleId, GenerateOnClose);
2460 BOOL WINAPI ObjectDeleteAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
2462 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName), HandleId, GenerateOnClose);
2467 BOOL WINAPI ObjectOpenAuditAlarmA(LPCSTR SubsystemName, LPVOID HandleId, LPSTR ObjectTypeName,
2468 LPSTR ObjectName, PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE ClientToken, DWORD DesiredAccess,
2469 DWORD GrantedAccess, PPRIVILEGE_SET Privileges, BOOL ObjectCreation, BOOL AccessGranted,
2470 LPBOOL GenerateOnClose)
2472 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08lx,0x%08lx,%p,%x,%x,%p)\n", debugstr_a(SubsystemName),
2473 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName), pSecurityDescriptor,
2474 ClientToken, DesiredAccess, GrantedAccess, Privileges, ObjectCreation, AccessGranted,
2480 BOOL WINAPI ObjectOpenAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, LPWSTR ObjectTypeName,
2481 LPWSTR ObjectName, PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE ClientToken, DWORD DesiredAccess,
2482 DWORD GrantedAccess, PPRIVILEGE_SET Privileges, BOOL ObjectCreation, BOOL AccessGranted,
2483 LPBOOL GenerateOnClose)
2485 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08lx,0x%08lx,%p,%x,%x,%p)\n", debugstr_w(SubsystemName),
2486 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName), pSecurityDescriptor,
2487 ClientToken, DesiredAccess, GrantedAccess, Privileges, ObjectCreation, AccessGranted,
2493 BOOL WINAPI ObjectPrivilegeAuditAlarmA( LPCSTR SubsystemName, LPVOID HandleId, HANDLE ClientToken,
2494 DWORD DesiredAccess, PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2496 FIXME("stub (%s,%p,%p,0x%08lx,%p,%x)\n", debugstr_a(SubsystemName), HandleId, ClientToken,
2497 DesiredAccess, Privileges, AccessGranted);
2502 BOOL WINAPI ObjectPrivilegeAuditAlarmW( LPCWSTR SubsystemName, LPVOID HandleId, HANDLE ClientToken,
2503 DWORD DesiredAccess, PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2505 FIXME("stub (%s,%p,%p,0x%08lx,%p,%x)\n", debugstr_w(SubsystemName), HandleId, ClientToken,
2506 DesiredAccess, Privileges, AccessGranted);
2511 BOOL WINAPI PrivilegedServiceAuditAlarmA( LPCSTR SubsystemName, LPCSTR ServiceName, HANDLE ClientToken,
2512 PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2514 FIXME("stub (%s,%s,%p,%p,%x)\n", debugstr_a(SubsystemName), debugstr_a(ServiceName),
2515 ClientToken, Privileges, AccessGranted);
2520 BOOL WINAPI PrivilegedServiceAuditAlarmW( LPCWSTR SubsystemName, LPCWSTR ServiceName, HANDLE ClientToken,
2521 PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2523 FIXME("stub %s,%s,%p,%p,%x)\n", debugstr_w(SubsystemName), debugstr_w(ServiceName),
2524 ClientToken, Privileges, AccessGranted);
2529 /******************************************************************************
2530 * GetSecurityInfo [ADVAPI32.@]
2532 DWORD WINAPI GetSecurityInfo(
2533 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
2534 SECURITY_INFORMATION SecurityInfo, PSID *ppsidOwner,
2535 PSID *ppsidGroup, PACL *ppDacl, PACL *ppSacl,
2536 PSECURITY_DESCRIPTOR *ppSecurityDescriptor
2540 return ERROR_BAD_PROVIDER;
2543 /******************************************************************************
2544 * GetSecurityInfoExW [ADVAPI32.@]
2546 DWORD WINAPI GetSecurityInfoExW(
2547 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
2548 SECURITY_INFORMATION SecurityInfo, LPCWSTR lpProvider,
2549 LPCWSTR lpProperty, PACTRL_ACCESSW *ppAccessList,
2550 PACTRL_AUDITW *ppAuditList, LPWSTR *lppOwner, LPWSTR *lppGroup
2554 return ERROR_BAD_PROVIDER;
2557 /******************************************************************************
2558 * BuildExplicitAccessWithNameA [ADVAPI32.@]
2560 VOID WINAPI BuildExplicitAccessWithNameA( PEXPLICIT_ACCESSA pExplicitAccess,
2561 LPSTR pTrusteeName, DWORD AccessPermissions,
2562 ACCESS_MODE AccessMode, DWORD Inheritance )
2564 TRACE("%p %s 0x%08lx 0x%08x 0x%08lx\n", pExplicitAccess, debugstr_a(pTrusteeName),
2565 AccessPermissions, AccessMode, Inheritance);
2567 pExplicitAccess->grfAccessPermissions = AccessPermissions;
2568 pExplicitAccess->grfAccessMode = AccessMode;
2569 pExplicitAccess->grfInheritance = Inheritance;
2571 pExplicitAccess->Trustee.pMultipleTrustee = NULL;
2572 pExplicitAccess->Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2573 pExplicitAccess->Trustee.TrusteeForm = TRUSTEE_IS_NAME;
2574 pExplicitAccess->Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
2575 pExplicitAccess->Trustee.ptstrName = pTrusteeName;
2578 /******************************************************************************
2579 * BuildExplicitAccessWithNameW [ADVAPI32.@]
2581 VOID WINAPI BuildExplicitAccessWithNameW( PEXPLICIT_ACCESSW pExplicitAccess,
2582 LPWSTR pTrusteeName, DWORD AccessPermissions,
2583 ACCESS_MODE AccessMode, DWORD Inheritance )
2585 TRACE("%p %s 0x%08lx 0x%08x 0x%08lx\n", pExplicitAccess, debugstr_w(pTrusteeName),
2586 AccessPermissions, AccessMode, Inheritance);
2588 pExplicitAccess->grfAccessPermissions = AccessPermissions;
2589 pExplicitAccess->grfAccessMode = AccessMode;
2590 pExplicitAccess->grfInheritance = Inheritance;
2592 pExplicitAccess->Trustee.pMultipleTrustee = NULL;
2593 pExplicitAccess->Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2594 pExplicitAccess->Trustee.TrusteeForm = TRUSTEE_IS_NAME;
2595 pExplicitAccess->Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
2596 pExplicitAccess->Trustee.ptstrName = pTrusteeName;
2599 /******************************************************************************
2600 * BuildTrusteeWithObjectsAndNameA [ADVAPI32.@]
2602 VOID WINAPI BuildTrusteeWithObjectsAndNameA( PTRUSTEEA pTrustee, POBJECTS_AND_NAME_A pObjName,
2603 SE_OBJECT_TYPE ObjectType, LPSTR ObjectTypeName,
2604 LPSTR InheritedObjectTypeName, LPSTR Name )
2606 DWORD ObjectsPresent = 0;
2608 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee, pObjName,
2609 ObjectType, ObjectTypeName, InheritedObjectTypeName, debugstr_a(Name));
2611 /* Fill the OBJECTS_AND_NAME structure */
2612 pObjName->ObjectType = ObjectType;
2613 if (ObjectTypeName != NULL)
2615 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
2618 pObjName->InheritedObjectTypeName = InheritedObjectTypeName;
2619 if (InheritedObjectTypeName != NULL)
2621 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
2624 pObjName->ObjectsPresent = ObjectsPresent;
2625 pObjName->ptstrName = Name;
2627 /* Fill the TRUSTEE structure */
2628 pTrustee->pMultipleTrustee = NULL;
2629 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2630 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME;
2631 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2632 pTrustee->ptstrName = (LPSTR)pObjName;
2635 /******************************************************************************
2636 * BuildTrusteeWithObjectsAndNameW [ADVAPI32.@]
2638 VOID WINAPI BuildTrusteeWithObjectsAndNameW( PTRUSTEEW pTrustee, POBJECTS_AND_NAME_W pObjName,
2639 SE_OBJECT_TYPE ObjectType, LPWSTR ObjectTypeName,
2640 LPWSTR InheritedObjectTypeName, LPWSTR Name )
2642 DWORD ObjectsPresent = 0;
2644 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee, pObjName,
2645 ObjectType, ObjectTypeName, InheritedObjectTypeName, debugstr_w(Name));
2647 /* Fill the OBJECTS_AND_NAME structure */
2648 pObjName->ObjectType = ObjectType;
2649 if (ObjectTypeName != NULL)
2651 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
2654 pObjName->InheritedObjectTypeName = InheritedObjectTypeName;
2655 if (InheritedObjectTypeName != NULL)
2657 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
2660 pObjName->ObjectsPresent = ObjectsPresent;
2661 pObjName->ptstrName = Name;
2663 /* Fill the TRUSTEE structure */
2664 pTrustee->pMultipleTrustee = NULL;
2665 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2666 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME;
2667 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2668 pTrustee->ptstrName = (LPWSTR)pObjName;
2671 /******************************************************************************
2672 * BuildTrusteeWithObjectsAndSidA [ADVAPI32.@]
2674 VOID WINAPI BuildTrusteeWithObjectsAndSidA( PTRUSTEEA pTrustee, POBJECTS_AND_SID pObjSid,
2675 GUID* pObjectGuid, GUID* pInheritedObjectGuid, PSID pSid )
2677 DWORD ObjectsPresent = 0;
2679 TRACE("%p %p %p %p %p\n", pTrustee, pObjSid, pObjectGuid, pInheritedObjectGuid, pSid);
2681 /* Fill the OBJECTS_AND_SID structure */
2682 if (pObjectGuid != NULL)
2684 pObjSid->ObjectTypeGuid = *pObjectGuid;
2685 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
2689 ZeroMemory(&pObjSid->ObjectTypeGuid,
2693 if (pInheritedObjectGuid != NULL)
2695 pObjSid->InheritedObjectTypeGuid = *pInheritedObjectGuid;
2696 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
2700 ZeroMemory(&pObjSid->InheritedObjectTypeGuid,
2704 pObjSid->ObjectsPresent = ObjectsPresent;
2705 pObjSid->pSid = pSid;
2707 /* Fill the TRUSTEE structure */
2708 pTrustee->pMultipleTrustee = NULL;
2709 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2710 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID;
2711 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2712 pTrustee->ptstrName = (LPSTR) pObjSid;
2715 /******************************************************************************
2716 * BuildTrusteeWithObjectsAndSidW [ADVAPI32.@]
2718 VOID WINAPI BuildTrusteeWithObjectsAndSidW( PTRUSTEEW pTrustee, POBJECTS_AND_SID pObjSid,
2719 GUID* pObjectGuid, GUID* pInheritedObjectGuid, PSID pSid )
2721 DWORD ObjectsPresent = 0;
2723 TRACE("%p %p %p %p %p\n", pTrustee, pObjSid, pObjectGuid, pInheritedObjectGuid, pSid);
2725 /* Fill the OBJECTS_AND_SID structure */
2726 if (pObjectGuid != NULL)
2728 pObjSid->ObjectTypeGuid = *pObjectGuid;
2729 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
2733 ZeroMemory(&pObjSid->ObjectTypeGuid,
2737 if (pInheritedObjectGuid != NULL)
2739 pObjSid->InheritedObjectTypeGuid = *pInheritedObjectGuid;
2740 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
2744 ZeroMemory(&pObjSid->InheritedObjectTypeGuid,
2748 pObjSid->ObjectsPresent = ObjectsPresent;
2749 pObjSid->pSid = pSid;
2751 /* Fill the TRUSTEE structure */
2752 pTrustee->pMultipleTrustee = NULL;
2753 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2754 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID;
2755 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2756 pTrustee->ptstrName = (LPWSTR) pObjSid;
2759 /******************************************************************************
2760 * BuildTrusteeWithSidA [ADVAPI32.@]
2762 VOID WINAPI BuildTrusteeWithSidA(PTRUSTEEA pTrustee, PSID pSid)
2764 TRACE("%p %p\n", pTrustee, pSid);
2766 pTrustee->pMultipleTrustee = NULL;
2767 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2768 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
2769 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2770 pTrustee->ptstrName = (LPSTR) pSid;
2773 /******************************************************************************
2774 * BuildTrusteeWithSidW [ADVAPI32.@]
2776 VOID WINAPI BuildTrusteeWithSidW(PTRUSTEEW pTrustee, PSID pSid)
2778 TRACE("%p %p\n", pTrustee, pSid);
2780 pTrustee->pMultipleTrustee = NULL;
2781 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2782 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
2783 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2784 pTrustee->ptstrName = (LPWSTR) pSid;
2787 /******************************************************************************
2788 * BuildTrusteeWithNameA [ADVAPI32.@]
2790 VOID WINAPI BuildTrusteeWithNameA(PTRUSTEEA pTrustee, LPSTR name)
2792 TRACE("%p %s\n", pTrustee, debugstr_a(name) );
2794 pTrustee->pMultipleTrustee = NULL;
2795 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2796 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
2797 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2798 pTrustee->ptstrName = name;
2801 /******************************************************************************
2802 * BuildTrusteeWithNameW [ADVAPI32.@]
2804 VOID WINAPI BuildTrusteeWithNameW(PTRUSTEEW pTrustee, LPWSTR name)
2806 TRACE("%p %s\n", pTrustee, debugstr_w(name) );
2808 pTrustee->pMultipleTrustee = NULL;
2809 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2810 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
2811 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2812 pTrustee->ptstrName = name;
2815 /******************************************************************************
2816 * GetTrusteeFormA [ADVAPI32.@]
2818 TRUSTEE_FORM WINAPI GetTrusteeFormA(PTRUSTEEA pTrustee)
2820 TRACE("(%p)\n", pTrustee);
2823 return TRUSTEE_BAD_FORM;
2825 return pTrustee->TrusteeForm;
2828 /******************************************************************************
2829 * GetTrusteeFormW [ADVAPI32.@]
2831 TRUSTEE_FORM WINAPI GetTrusteeFormW(PTRUSTEEW pTrustee)
2833 TRACE("(%p)\n", pTrustee);
2836 return TRUSTEE_BAD_FORM;
2838 return pTrustee->TrusteeForm;
2841 /******************************************************************************
2842 * GetTrusteeNameA [ADVAPI32.@]
2844 LPSTR WINAPI GetTrusteeNameA(PTRUSTEEA pTrustee)
2846 TRACE("(%p)\n", pTrustee);
2851 return pTrustee->ptstrName;
2854 /******************************************************************************
2855 * GetTrusteeNameW [ADVAPI32.@]
2857 LPWSTR WINAPI GetTrusteeNameW(PTRUSTEEW pTrustee)
2859 TRACE("(%p)\n", pTrustee);
2864 return pTrustee->ptstrName;
2867 /******************************************************************************
2868 * GetTrusteeTypeA [ADVAPI32.@]
2870 TRUSTEE_TYPE WINAPI GetTrusteeTypeA(PTRUSTEEA pTrustee)
2872 TRACE("(%p)\n", pTrustee);
2875 return TRUSTEE_IS_UNKNOWN;
2877 return pTrustee->TrusteeType;
2880 /******************************************************************************
2881 * GetTrusteeTypeW [ADVAPI32.@]
2883 TRUSTEE_TYPE WINAPI GetTrusteeTypeW(PTRUSTEEW pTrustee)
2885 TRACE("(%p)\n", pTrustee);
2888 return TRUSTEE_IS_UNKNOWN;
2890 return pTrustee->TrusteeType;
2893 BOOL WINAPI SetAclInformation( PACL pAcl, LPVOID pAclInformation,
2894 DWORD nAclInformationLength,
2895 ACL_INFORMATION_CLASS dwAclInformationClass )
2897 FIXME("%p %p 0x%08lx 0x%08x - stub\n", pAcl, pAclInformation,
2898 nAclInformationLength, dwAclInformationClass);
2903 /******************************************************************************
2904 * SetEntriesInAclA [ADVAPI32.@]
2906 DWORD WINAPI SetEntriesInAclA( ULONG count, PEXPLICIT_ACCESSA pEntries,
2907 PACL OldAcl, PACL* NewAcl )
2909 FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
2910 return ERROR_CALL_NOT_IMPLEMENTED;
2913 /******************************************************************************
2914 * SetEntriesInAclW [ADVAPI32.@]
2916 DWORD WINAPI SetEntriesInAclW( ULONG count, PEXPLICIT_ACCESSW pEntries,
2917 PACL OldAcl, PACL* NewAcl )
2919 FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
2920 return ERROR_CALL_NOT_IMPLEMENTED;
2923 /******************************************************************************
2924 * SetNamedSecurityInfoA [ADVAPI32.@]
2926 DWORD WINAPI SetNamedSecurityInfoA(LPSTR pObjectName,
2927 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
2928 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
2934 TRACE("%s %d %ld %p %p %p %p\n", debugstr_a(pObjectName), ObjectType,
2935 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
2939 len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
2940 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
2941 MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
2944 r = SetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, psidOwner,
2945 psidGroup, pDacl, pSacl );
2947 HeapFree( GetProcessHeap(), 0, wstr );
2952 BOOL WINAPI SetPrivateObjectSecurity( SECURITY_INFORMATION SecurityInformation,
2953 PSECURITY_DESCRIPTOR ModificationDescriptor,
2954 PSECURITY_DESCRIPTOR* ObjectsSecurityDescriptor,
2955 PGENERIC_MAPPING GenericMapping,
2958 FIXME("0x%08lx %p %p %p %p - stub\n", SecurityInformation, ModificationDescriptor,
2959 ObjectsSecurityDescriptor, GenericMapping, Token);
2964 BOOL WINAPI SetSecurityDescriptorControl( PSECURITY_DESCRIPTOR pSecurityDescriptor,
2965 SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
2966 SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet )
2968 FIXME("%p 0x%08x 0x%08x - stub\n", pSecurityDescriptor, ControlBitsOfInterest,
2974 BOOL WINAPI AreAllAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
2976 return RtlAreAllAccessesGranted( GrantedAccess, DesiredAccess );
2979 /******************************************************************************
2980 * AreAnyAccessesGranted [ADVAPI32.@]
2982 * Determines whether or not any of a set of specified access permissions have
2983 * been granted or not.
2986 * GrantedAccess [I] The permissions that have been granted.
2987 * DesiredAccess [I] The permissions that you want to have.
2990 * Nonzero if any of the permissions have been granted, zero if none of the
2991 * permissions have been granted.
2994 BOOL WINAPI AreAnyAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
2996 return RtlAreAnyAccessesGranted( GrantedAccess, DesiredAccess );
2999 /******************************************************************************
3000 * SetNamedSecurityInfoW [ADVAPI32.@]
3002 DWORD WINAPI SetNamedSecurityInfoW(LPWSTR pObjectName,
3003 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
3004 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
3006 FIXME("%s %d %ld %p %p %p %p\n", debugstr_w(pObjectName), ObjectType,
3007 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
3008 return ERROR_SUCCESS;
3011 /******************************************************************************
3012 * GetExplicitEntriesFromAclA [ADVAPI32.@]
3014 DWORD WINAPI GetExplicitEntriesFromAclA( PACL pacl, PULONG pcCountOfExplicitEntries,
3015 PEXPLICIT_ACCESSA* pListOfExplicitEntries)
3017 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
3018 return ERROR_CALL_NOT_IMPLEMENTED;
3021 /******************************************************************************
3022 * GetExplicitEntriesFromAclW [ADVAPI32.@]
3024 DWORD WINAPI GetExplicitEntriesFromAclW( PACL pacl, PULONG pcCountOfExplicitEntries,
3025 PEXPLICIT_ACCESSW* pListOfExplicitEntries)
3027 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
3028 return ERROR_CALL_NOT_IMPLEMENTED;
3032 /******************************************************************************
3033 * ParseAclStringFlags
3035 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl)
3038 LPCWSTR szAcl = *StringAcl;
3040 while (*szAcl != '(')
3044 flags |= SE_DACL_PROTECTED;
3046 else if (*szAcl == 'A')
3050 flags |= SE_DACL_AUTO_INHERIT_REQ;
3051 else if (*szAcl == 'I')
3052 flags |= SE_DACL_AUTO_INHERITED;
3061 /******************************************************************************
3062 * ParseAceStringType
3064 static const ACEFLAG AceType[] =
3066 { SDDL_ACCESS_ALLOWED, ACCESS_ALLOWED_ACE_TYPE },
3067 { SDDL_ALARM, SYSTEM_ALARM_ACE_TYPE },
3068 { SDDL_AUDIT, SYSTEM_AUDIT_ACE_TYPE },
3069 { SDDL_ACCESS_DENIED, ACCESS_DENIED_ACE_TYPE },
3071 { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
3072 { SDDL_OBJECT_ACCESS_DENIED, ACCESS_DENIED_OBJECT_ACE_TYPE },
3073 { SDDL_OBJECT_ALARM, SYSTEM_ALARM_OBJECT_ACE_TYPE },
3074 { SDDL_OBJECT_AUDIT, SYSTEM_AUDIT_OBJECT_ACE_TYPE },
3079 static BYTE ParseAceStringType(LPCWSTR* StringAcl)
3082 LPCWSTR szAcl = *StringAcl;
3083 const ACEFLAG *lpaf = AceType;
3085 while (lpaf->wstr &&
3086 (len = strlenW(lpaf->wstr)) &&
3087 strncmpW(lpaf->wstr, szAcl, len))
3098 /******************************************************************************
3099 * ParseAceStringFlags
3101 static const ACEFLAG AceFlags[] =
3103 { SDDL_CONTAINER_INHERIT, CONTAINER_INHERIT_ACE },
3104 { SDDL_AUDIT_FAILURE, FAILED_ACCESS_ACE_FLAG },
3105 { SDDL_INHERITED, INHERITED_ACE },
3106 { SDDL_INHERIT_ONLY, INHERIT_ONLY_ACE },
3107 { SDDL_NO_PROPAGATE, NO_PROPAGATE_INHERIT_ACE },
3108 { SDDL_OBJECT_INHERIT, OBJECT_INHERIT_ACE },
3109 { SDDL_AUDIT_SUCCESS, SUCCESSFUL_ACCESS_ACE_FLAG },
3113 static BYTE ParseAceStringFlags(LPCWSTR* StringAcl)
3117 LPCWSTR szAcl = *StringAcl;
3119 while (*szAcl != ';')
3121 const ACEFLAG *lpaf = AceFlags;
3123 while (lpaf->wstr &&
3124 (len = strlenW(lpaf->wstr)) &&
3125 strncmpW(lpaf->wstr, szAcl, len))
3131 flags |= lpaf->value;
3140 /******************************************************************************
3141 * ParseAceStringRights
3143 static const ACEFLAG AceRights[] =
3145 { SDDL_GENERIC_ALL, GENERIC_ALL },
3146 { SDDL_GENERIC_READ, GENERIC_READ },
3147 { SDDL_GENERIC_WRITE, GENERIC_WRITE },
3148 { SDDL_GENERIC_EXECUTE, GENERIC_EXECUTE },
3149 { SDDL_READ_CONTROL, READ_CONTROL },
3150 { SDDL_STANDARD_DELETE, DELETE },
3151 { SDDL_WRITE_DAC, WRITE_DAC },
3152 { SDDL_WRITE_OWNER, WRITE_OWNER },
3156 static DWORD ParseAceStringRights(LPCWSTR* StringAcl)
3160 LPCWSTR szAcl = *StringAcl;
3162 if ((*szAcl == '0') && (*(szAcl + 1) == 'x'))
3166 while (*p && *p != ';')
3171 rights = strtoulW(szAcl, NULL, 16);
3175 WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl, p - szAcl));
3179 while (*szAcl != ';')
3181 const ACEFLAG *lpaf = AceRights;
3183 while (lpaf->wstr &&
3184 (len = strlenW(lpaf->wstr)) &&
3185 strncmpW(lpaf->wstr, szAcl, len))
3193 rights |= lpaf->value;
3203 /******************************************************************************
3204 * ParseStringAclToAcl
3206 * dacl_flags(string_ace1)(string_ace2)... (string_acen)
3208 static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags,
3209 PACL pAcl, LPDWORD cBytes)
3213 DWORD length = sizeof(ACL);
3214 PACCESS_ALLOWED_ACE pAce = NULL; /* pointer to current ACE */
3216 TRACE("%s\n", debugstr_w(StringAcl));
3221 if (pAcl) /* pAce is only useful if we're setting values */
3222 pAce = (PACCESS_ALLOWED_ACE) ((LPBYTE)pAcl + sizeof(PACL));
3224 /* Parse ACL flags */
3225 *lpdwFlags = ParseAclStringFlags(&StringAcl);
3228 while (*StringAcl == '(')
3232 /* Parse ACE type */
3233 val = ParseAceStringType(&StringAcl);
3235 pAce->Header.AceType = (BYTE) val;
3236 if (*StringAcl != ';')
3240 /* Parse ACE flags */
3241 val = ParseAceStringFlags(&StringAcl);
3243 pAce->Header.AceFlags = (BYTE) val;
3244 if (*StringAcl != ';')
3248 /* Parse ACE rights */
3249 val = ParseAceStringRights(&StringAcl);
3252 if (*StringAcl != ';')
3256 /* Parse ACE object guid */
3257 if (*StringAcl != ';')
3259 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3264 /* Parse ACE inherit object guid */
3265 if (*StringAcl != ';')
3267 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3272 /* Parse ACE account sid */
3273 if (ParseStringSidToSid(StringAcl, pAce ? (PSID)&pAce->SidStart : NULL, &sidlen))
3275 while (*StringAcl && *StringAcl != ')')
3279 if (*StringAcl != ')')
3283 length += sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) + sidlen;
3290 WARN("Invalid ACE string format\n");
3295 /******************************************************************************
3296 * ParseStringSecurityDescriptorToSecurityDescriptor
3298 static BOOL ParseStringSecurityDescriptorToSecurityDescriptor(
3299 LPCWSTR StringSecurityDescriptor,
3300 SECURITY_DESCRIPTOR* SecurityDescriptor,
3305 WCHAR tok[MAX_PATH];
3307 LPBYTE lpNext = NULL;
3312 if (SecurityDescriptor)
3313 lpNext = ((LPBYTE) SecurityDescriptor) + sizeof(SECURITY_DESCRIPTOR);
3315 while (*StringSecurityDescriptor)
3317 toktype = *StringSecurityDescriptor;
3319 /* Expect char identifier followed by ':' */
3320 StringSecurityDescriptor++;
3321 if (*StringSecurityDescriptor != ':')
3323 SetLastError(ERROR_INVALID_PARAMETER);
3326 StringSecurityDescriptor++;
3329 lptoken = StringSecurityDescriptor;
3330 while (*lptoken && *lptoken != ':')
3336 len = lptoken - StringSecurityDescriptor;
3337 memcpy( tok, StringSecurityDescriptor, len * sizeof(WCHAR) );
3346 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
3349 if (SecurityDescriptor)
3351 SecurityDescriptor->Owner = (PSID)(lpNext - (LPBYTE)SecurityDescriptor);
3352 lpNext += bytes; /* Advance to next token */
3364 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
3367 if (SecurityDescriptor)
3369 SecurityDescriptor->Group = (PSID)(lpNext - (LPBYTE)SecurityDescriptor);
3370 lpNext += bytes; /* Advance to next token */
3383 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
3386 if (SecurityDescriptor)
3388 SecurityDescriptor->Control |= SE_DACL_PRESENT | flags;
3389 SecurityDescriptor->Dacl = (PACL)(lpNext - (LPBYTE)SecurityDescriptor);
3390 lpNext += bytes; /* Advance to next token */
3403 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
3406 if (SecurityDescriptor)
3408 SecurityDescriptor->Control |= SE_SACL_PRESENT | flags;
3409 SecurityDescriptor->Sacl = (PACL)(lpNext - (LPBYTE)SecurityDescriptor);
3410 lpNext += bytes; /* Advance to next token */
3419 FIXME("Unknown token\n");
3420 SetLastError(ERROR_INVALID_PARAMETER);
3424 StringSecurityDescriptor = lptoken;
3433 /******************************************************************************
3434 * ConvertStringSecurityDescriptorToSecurityDescriptorA [ADVAPI32.@]
3436 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorA(
3437 LPCSTR StringSecurityDescriptor,
3438 DWORD StringSDRevision,
3439 PSECURITY_DESCRIPTOR* SecurityDescriptor,
3440 PULONG SecurityDescriptorSize)
3444 LPWSTR StringSecurityDescriptorW;
3446 len = MultiByteToWideChar(CP_ACP, 0, StringSecurityDescriptor, -1, NULL, 0);
3447 StringSecurityDescriptorW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3449 if (StringSecurityDescriptorW)
3451 MultiByteToWideChar(CP_ACP, 0, StringSecurityDescriptor, -1, StringSecurityDescriptorW, len);
3453 ret = ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptorW,
3454 StringSDRevision, SecurityDescriptor,
3455 SecurityDescriptorSize);
3456 HeapFree(GetProcessHeap(), 0, StringSecurityDescriptorW);
3462 /******************************************************************************
3463 * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
3465 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW(
3466 LPCWSTR StringSecurityDescriptor,
3467 DWORD StringSDRevision,
3468 PSECURITY_DESCRIPTOR* SecurityDescriptor,
3469 PULONG SecurityDescriptorSize)
3472 SECURITY_DESCRIPTOR* psd;
3475 TRACE("%s\n", debugstr_w(StringSecurityDescriptor));
3477 if (GetVersion() & 0x80000000)
3479 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3482 else if (StringSDRevision != SID_REVISION)
3484 SetLastError(ERROR_UNKNOWN_REVISION);
3488 /* Compute security descriptor length */
3489 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
3493 psd = *SecurityDescriptor = (SECURITY_DESCRIPTOR*) LocalAlloc(
3494 GMEM_ZEROINIT, cBytes);
3496 psd->Revision = SID_REVISION;
3497 psd->Control |= SE_SELF_RELATIVE;
3499 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
3506 if (SecurityDescriptorSize)
3507 *SecurityDescriptorSize = cBytes;
3512 TRACE(" ret=%d\n", bret);
3516 /******************************************************************************
3517 * ConvertStringSidToSidW [ADVAPI32.@]
3519 BOOL WINAPI ConvertStringSidToSidW(LPCWSTR StringSid, PSID* Sid)
3524 TRACE("%s, %p\n", debugstr_w(StringSid), Sid);
3525 if (GetVersion() & 0x80000000)
3526 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3527 else if (!StringSid || !Sid)
3528 SetLastError(ERROR_INVALID_PARAMETER);
3529 else if (ParseStringSidToSid(StringSid, NULL, &cBytes))
3531 PSID pSid = *Sid = (PSID) LocalAlloc(0, cBytes);
3533 bret = ParseStringSidToSid(StringSid, pSid, &cBytes);
3537 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
3541 /******************************************************************************
3542 * ConvertStringSidToSidA [ADVAPI32.@]
3544 BOOL WINAPI ConvertStringSidToSidA(LPCSTR StringSid, PSID* Sid)
3548 TRACE("%s, %p\n", debugstr_a(StringSid), Sid);
3549 if (GetVersion() & 0x80000000)
3550 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3551 else if (!StringSid || !Sid)
3552 SetLastError(ERROR_INVALID_PARAMETER);
3555 UINT len = MultiByteToWideChar(CP_ACP, 0, StringSid, -1, NULL, 0);
3556 LPWSTR wStringSid = HeapAlloc(GetProcessHeap(), 0,
3557 len * sizeof(WCHAR));
3559 MultiByteToWideChar(CP_ACP, 0, StringSid, -1, wStringSid, len);
3560 bret = ConvertStringSidToSidW(wStringSid, Sid);
3561 HeapFree(GetProcessHeap(), 0, wStringSid);
3563 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
3567 /******************************************************************************
3568 * ConvertSidToStringSidW [ADVAPI32.@]
3570 * format of SID string is:
3571 * S-<count>-<auth>-<subauth1>-<subauth2>-<subauth3>...
3573 * <rev> is the revision of the SID encoded as decimal
3574 * <auth> is the identifier authority encoded as hex
3575 * <subauthN> is the subauthority id encoded as decimal
3577 BOOL WINAPI ConvertSidToStringSidW( PSID pSid, LPWSTR *pstr )
3581 WCHAR fmt[] = { 'S','-','%','u','-','%','d',0 };
3582 WCHAR subauthfmt[] = { '-','%','u',0 };
3585 TRACE("%p %p\n", pSid, pstr );
3587 if( !IsValidSid( pSid ) )
3590 if (pisid->Revision != SDDL_REVISION)
3592 if (pisid->IdentifierAuthority.Value[0] ||
3593 pisid->IdentifierAuthority.Value[1])
3595 FIXME("not matching MS' bugs\n");
3599 sz = 14 + pisid->SubAuthorityCount * 11;
3600 str = LocalAlloc( 0, sz*sizeof(WCHAR) );
3601 sprintfW( str, fmt, pisid->Revision, MAKELONG(
3602 MAKEWORD( pisid->IdentifierAuthority.Value[5],
3603 pisid->IdentifierAuthority.Value[4] ),
3604 MAKEWORD( pisid->IdentifierAuthority.Value[3],
3605 pisid->IdentifierAuthority.Value[2] ) ) );
3606 for( i=0; i<pisid->SubAuthorityCount; i++ )
3607 sprintfW( str + strlenW(str), subauthfmt, pisid->SubAuthority[i] );
3613 /******************************************************************************
3614 * ConvertSidToStringSidA [ADVAPI32.@]
3616 BOOL WINAPI ConvertSidToStringSidA(PSID pSid, LPSTR *pstr)
3622 TRACE("%p %p\n", pSid, pstr );
3624 if( !ConvertSidToStringSidW( pSid, &wstr ) )
3627 len = WideCharToMultiByte( CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL );
3628 str = LocalAlloc( 0, len );
3629 WideCharToMultiByte( CP_ACP, 0, wstr, -1, str, len, NULL, NULL );
3637 BOOL WINAPI CreatePrivateObjectSecurity(
3638 PSECURITY_DESCRIPTOR ParentDescriptor,
3639 PSECURITY_DESCRIPTOR CreatorDescriptor,
3640 PSECURITY_DESCRIPTOR* NewDescriptor,
3641 BOOL IsDirectoryObject,
3643 PGENERIC_MAPPING GenericMapping )
3645 FIXME("%p %p %p %d %p %p - stub\n", ParentDescriptor, CreatorDescriptor,
3646 NewDescriptor, IsDirectoryObject, Token, GenericMapping);
3651 BOOL WINAPI DestroyPrivateObjectSecurity( PSECURITY_DESCRIPTOR* ObjectDescriptor )
3653 FIXME("%p - stub\n", ObjectDescriptor);
3658 BOOL WINAPI CreateProcessAsUserA(
3660 LPCSTR lpApplicationName,
3661 LPSTR lpCommandLine,
3662 LPSECURITY_ATTRIBUTES lpProcessAttributes,
3663 LPSECURITY_ATTRIBUTES lpThreadAttributes,
3664 BOOL bInheritHandles,
3665 DWORD dwCreationFlags,
3666 LPVOID lpEnvironment,
3667 LPCSTR lpCurrentDirectory,
3668 LPSTARTUPINFOA lpStartupInfo,
3669 LPPROCESS_INFORMATION lpProcessInformation )
3671 FIXME("%p %s %s %p %p %d 0x%08lx %p %s %p %p - stub\n", hToken, debugstr_a(lpApplicationName),
3672 debugstr_a(lpCommandLine), lpProcessAttributes, lpThreadAttributes, bInheritHandles,
3673 dwCreationFlags, lpEnvironment, debugstr_a(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
3678 BOOL WINAPI CreateProcessAsUserW(
3680 LPCWSTR lpApplicationName,
3681 LPWSTR lpCommandLine,
3682 LPSECURITY_ATTRIBUTES lpProcessAttributes,
3683 LPSECURITY_ATTRIBUTES lpThreadAttributes,
3684 BOOL bInheritHandles,
3685 DWORD dwCreationFlags,
3686 LPVOID lpEnvironment,
3687 LPCWSTR lpCurrentDirectory,
3688 LPSTARTUPINFOW lpStartupInfo,
3689 LPPROCESS_INFORMATION lpProcessInformation )
3691 FIXME("%p %s %s %p %p %d 0x%08lx %p %s %p %p - semi- stub\n", hToken,
3692 debugstr_w(lpApplicationName), debugstr_w(lpCommandLine), lpProcessAttributes,
3693 lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment,
3694 debugstr_w(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
3696 /* We should create the process with a suspended main thread */
3697 if (!CreateProcessW (lpApplicationName,
3699 lpProcessAttributes,
3702 dwCreationFlags, /* CREATE_SUSPENDED */
3706 lpProcessInformation))
3714 BOOL WINAPI DuplicateTokenEx(
3715 HANDLE ExistingTokenHandle, DWORD dwDesiredAccess,
3716 LPSECURITY_ATTRIBUTES lpTokenAttributes,
3717 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
3718 TOKEN_TYPE TokenType,
3719 PHANDLE DuplicateTokenHandle )
3721 OBJECT_ATTRIBUTES ObjectAttributes;
3723 TRACE("%p 0x%08lx 0x%08x 0x%08x %p\n", ExistingTokenHandle, dwDesiredAccess,
3724 ImpersonationLevel, TokenType, DuplicateTokenHandle);
3726 InitializeObjectAttributes(
3729 (lpTokenAttributes && lpTokenAttributes->bInheritHandle) ? OBJ_INHERIT : 0,
3731 lpTokenAttributes ? lpTokenAttributes->lpSecurityDescriptor : NULL );
3733 return set_ntstatus( NtDuplicateToken( ExistingTokenHandle,
3738 DuplicateTokenHandle ) );
3741 BOOL WINAPI DuplicateToken(
3742 HANDLE ExistingTokenHandle,
3743 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
3744 PHANDLE DuplicateTokenHandle )
3746 return DuplicateTokenEx( ExistingTokenHandle, TOKEN_IMPERSONATE | TOKEN_QUERY,
3747 NULL, ImpersonationLevel, TokenImpersonation,
3748 DuplicateTokenHandle );
3751 BOOL WINAPI EnumDependentServicesA(
3753 DWORD dwServiceState,
3754 LPENUM_SERVICE_STATUSA lpServices,
3756 LPDWORD pcbBytesNeeded,
3757 LPDWORD lpServicesReturned )
3759 FIXME("%p 0x%08lx %p 0x%08lx %p %p - stub\n", hService, dwServiceState,
3760 lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned);
3765 BOOL WINAPI EnumDependentServicesW(
3767 DWORD dwServiceState,
3768 LPENUM_SERVICE_STATUSW lpServices,
3770 LPDWORD pcbBytesNeeded,
3771 LPDWORD lpServicesReturned )
3773 FIXME("%p 0x%08lx %p 0x%08lx %p %p - stub\n", hService, dwServiceState,
3774 lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned);
3779 /******************************************************************************
3780 * ComputeStringSidSize
3782 static DWORD ComputeStringSidSize(LPCWSTR StringSid)
3784 DWORD size = sizeof(SID);
3786 if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I-S-S */
3791 if (*StringSid == '-')
3797 size += (ctok - 3) * sizeof(DWORD);
3799 else /* String constant format - Only available in winxp and above */
3803 for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++)
3804 if (!strncmpW(WellKnownSids[i].wstr, StringSid, 2))
3805 size += (WellKnownSids[i].Sid.SubAuthorityCount - 1) * sizeof(DWORD);
3811 /******************************************************************************
3812 * ParseStringSidToSid
3814 static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes)
3819 TRACE("%s, %p, %p\n", debugstr_w(StringSid), pSid, cBytes);
3822 SetLastError(ERROR_INVALID_PARAMETER);
3823 TRACE("StringSid is NULL, returning FALSE\n");
3827 *cBytes = ComputeStringSidSize(StringSid);
3828 if (!pisid) /* Simply compute the size */
3830 TRACE("only size requested, returning TRUE\n");
3834 if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I-S-S */
3836 DWORD i = 0, identAuth;
3837 DWORD csubauth = ((*cBytes - sizeof(SID)) / sizeof(DWORD)) + 1;
3839 StringSid += 2; /* Advance to Revision */
3840 pisid->Revision = atoiW(StringSid);
3842 if (pisid->Revision != SDDL_REVISION)
3844 TRACE("Revision %d is unknown\n", pisid->Revision);
3845 goto lend; /* ERROR_INVALID_SID */
3849 TRACE("SubAuthorityCount is 0\n");
3850 goto lend; /* ERROR_INVALID_SID */
3853 pisid->SubAuthorityCount = csubauth;
3855 /* Advance to identifier authority */
3856 while (*StringSid && *StringSid != '-')
3858 if (*StringSid == '-')
3861 /* MS' implementation can't handle values greater than 2^32 - 1, so
3862 * we don't either; assume most significant bytes are always 0
3864 pisid->IdentifierAuthority.Value[0] = 0;
3865 pisid->IdentifierAuthority.Value[1] = 0;
3866 identAuth = atoiW(StringSid);
3867 pisid->IdentifierAuthority.Value[5] = identAuth & 0xff;
3868 pisid->IdentifierAuthority.Value[4] = (identAuth & 0xff00) >> 8;
3869 pisid->IdentifierAuthority.Value[3] = (identAuth & 0xff0000) >> 16;
3870 pisid->IdentifierAuthority.Value[2] = (identAuth & 0xff000000) >> 24;
3872 /* Advance to first sub authority */
3873 while (*StringSid && *StringSid != '-')
3875 if (*StringSid == '-')
3880 while (*StringSid && *StringSid != '-')
3882 if (*StringSid == '-')
3885 pisid->SubAuthority[i++] = atoiW(StringSid);
3888 if (i != pisid->SubAuthorityCount)
3889 goto lend; /* ERROR_INVALID_SID */
3893 else /* String constant format - Only available in winxp and above */
3896 pisid->Revision = SDDL_REVISION;
3898 for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++)
3899 if (!strncmpW(WellKnownSids[i].wstr, StringSid, 2))
3902 pisid->SubAuthorityCount = WellKnownSids[i].Sid.SubAuthorityCount;
3903 pisid->IdentifierAuthority = WellKnownSids[i].Sid.IdentifierAuthority;
3904 for (j = 0; j < WellKnownSids[i].Sid.SubAuthorityCount; j++)
3905 pisid->SubAuthority[j] = WellKnownSids[i].Sid.SubAuthority[j];
3910 FIXME("String constant not supported: %s\n", debugstr_wn(StringSid, 2));
3915 SetLastError(ERROR_INVALID_SID);
3917 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
3921 /******************************************************************************
3922 * GetNamedSecurityInfoA [ADVAPI32.@]
3924 DWORD WINAPI GetNamedSecurityInfoA(LPSTR pObjectName,
3925 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
3926 PSID* ppsidOwner, PSID* ppsidGroup, PACL* ppDacl, PACL* ppSacl,
3927 PSECURITY_DESCRIPTOR* ppSecurityDescriptor)
3933 TRACE("%s %d %ld %p %p %p %p %p\n", pObjectName, ObjectType, SecurityInfo,
3934 ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
3938 len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
3939 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
3940 MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
3943 r = GetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, ppsidOwner,
3944 ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor );
3946 HeapFree( GetProcessHeap(), 0, wstr );
3951 /******************************************************************************
3952 * GetNamedSecurityInfoW [ADVAPI32.@]
3954 DWORD WINAPI GetNamedSecurityInfoW( LPWSTR name, SE_OBJECT_TYPE type,
3955 SECURITY_INFORMATION info, PSID* owner, PSID* group, PACL* dacl,
3956 PACL* sacl, PSECURITY_DESCRIPTOR* descriptor )
3958 DWORD needed, offset;
3959 SECURITY_DESCRIPTOR_RELATIVE *relative;
3962 TRACE( "%s %d %ld %p %p %p %p %p\n", debugstr_w(name), type, info, owner,
3963 group, dacl, sacl, descriptor );
3965 if (!name || !descriptor) return ERROR_INVALID_PARAMETER;
3967 needed = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
3968 if (info & OWNER_SECURITY_INFORMATION)
3969 needed += sizeof(sidWorld);
3970 if (info & GROUP_SECURITY_INFORMATION)
3971 needed += sizeof(sidWorld);
3972 if (info & DACL_SECURITY_INFORMATION)
3973 needed += WINE_SIZE_OF_WORLD_ACCESS_ACL;
3974 if (info & SACL_SECURITY_INFORMATION)
3975 needed += WINE_SIZE_OF_WORLD_ACCESS_ACL;
3977 /* must be freed by caller */
3978 *descriptor = HeapAlloc( GetProcessHeap(), 0, needed );
3979 if (!*descriptor) return ERROR_NOT_ENOUGH_MEMORY;
3981 if (!InitializeSecurityDescriptor( *descriptor, SECURITY_DESCRIPTOR_REVISION ))
3983 HeapFree( GetProcessHeap(), 0, *descriptor );
3984 return ERROR_INVALID_SECURITY_DESCR;
3987 relative = (SECURITY_DESCRIPTOR_RELATIVE *)*descriptor;
3988 relative->Control |= SE_SELF_RELATIVE;
3989 buffer = (BYTE *)relative;
3990 offset = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
3992 if (owner && (info & OWNER_SECURITY_INFORMATION))
3994 memcpy( buffer + offset, &sidWorld, sizeof(sidWorld) );
3995 relative->Owner = offset;
3996 *owner = buffer + offset;
3997 offset += sizeof(sidWorld);
3999 if (group && (info & GROUP_SECURITY_INFORMATION))
4001 memcpy( buffer + offset, &sidWorld, sizeof(sidWorld) );
4002 relative->Group = offset;
4003 *group = buffer + offset;
4004 offset += sizeof(sidWorld);
4006 if (dacl && (info & DACL_SECURITY_INFORMATION))
4008 GetWorldAccessACL( (PACL)(buffer + offset) );
4009 relative->Dacl = offset;
4010 *dacl = (PACL)(buffer + offset);
4011 offset += WINE_SIZE_OF_WORLD_ACCESS_ACL;
4013 if (sacl && (info & SACL_SECURITY_INFORMATION))
4015 GetWorldAccessACL( (PACL)(buffer + offset) );
4016 relative->Sacl = offset;
4017 *sacl = (PACL)(buffer + offset);
4019 return ERROR_SUCCESS;
4022 /******************************************************************************
4023 * DecryptFileW [ADVAPI32.@]
4025 BOOL WINAPI DecryptFileW(LPCWSTR lpFileName, DWORD dwReserved)
4027 FIXME("%s %08lx\n", debugstr_w(lpFileName), dwReserved);
4031 /******************************************************************************
4032 * DecryptFileA [ADVAPI32.@]
4034 BOOL WINAPI DecryptFileA(LPCSTR lpFileName, DWORD dwReserved)
4036 FIXME("%s %08lx\n", debugstr_a(lpFileName), dwReserved);
4040 /******************************************************************************
4041 * EncryptFileW [ADVAPI32.@]
4043 BOOL WINAPI EncryptFileW(LPCWSTR lpFileName)
4045 FIXME("%s\n", debugstr_w(lpFileName));
4049 /******************************************************************************
4050 * EncryptFileA [ADVAPI32.@]
4052 BOOL WINAPI EncryptFileA(LPCSTR lpFileName)
4054 FIXME("%s\n", debugstr_a(lpFileName));
4058 /******************************************************************************
4059 * FileEncryptionStatusW [ADVAPI32.@]
4061 BOOL WINAPI FileEncryptionStatusW(LPCWSTR lpFileName, LPDWORD lpStatus)
4063 FIXME("(%s %p): stub\n", debugstr_w(lpFileName), lpStatus);
4066 *lpStatus = FILE_SYSTEM_NOT_SUPPORT;
4070 /******************************************************************************
4071 * FileEncryptionStatusA [ADVAPI32.@]
4073 BOOL WINAPI FileEncryptionStatusA(LPCSTR lpFileName, LPDWORD lpStatus)
4075 FIXME("(%s %p): stub\n", debugstr_a(lpFileName), lpStatus);
4078 *lpStatus = FILE_SYSTEM_NOT_SUPPORT;
4082 /******************************************************************************
4083 * SetSecurityInfo [ADVAPI32.@]
4085 DWORD WINAPI SetSecurityInfo(HANDLE handle, SE_OBJECT_TYPE ObjectType,
4086 SECURITY_INFORMATION SecurityInfo, PSID psidOwner,
4087 PSID psidGroup, PACL pDacl, PACL pSacl) {
4089 return ERROR_SUCCESS;