2 * Copyright 1999, 2000 Juergen Schmied <juergen.schmied@debitel.net>
3 * Copyright 2003 CodeWeavers Inc. (Ulrich Czekalla)
4 * Copyright 2006 Robert Reif
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define WIN32_NO_STATUS
40 #include "advapi32_misc.h"
43 #include "wine/debug.h"
44 #include "wine/unicode.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
48 static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes);
49 static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags,
50 PACL pAcl, LPDWORD cBytes);
51 static BYTE ParseAceStringFlags(LPCWSTR* StringAcl);
52 static BYTE ParseAceStringType(LPCWSTR* StringAcl);
53 static DWORD ParseAceStringRights(LPCWSTR* StringAcl);
54 static BOOL ParseStringSecurityDescriptorToSecurityDescriptor(
55 LPCWSTR StringSecurityDescriptor,
56 SECURITY_DESCRIPTOR_RELATIVE* SecurityDescriptor,
58 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl);
60 typedef struct _ACEFLAG
64 } ACEFLAG, *LPACEFLAG;
66 typedef struct _MAX_SID
68 /* same fields as struct _SID */
70 BYTE SubAuthorityCount;
71 SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
72 DWORD SubAuthority[SID_MAX_SUB_AUTHORITIES];
75 typedef struct WELLKNOWNSID
78 WELL_KNOWN_SID_TYPE Type;
82 static const WELLKNOWNSID WellKnownSids[] =
84 { {0,0}, WinNullSid, { SID_REVISION, 1, { SECURITY_NULL_SID_AUTHORITY }, { SECURITY_NULL_RID } } },
85 { {'W','D'}, WinWorldSid, { SID_REVISION, 1, { SECURITY_WORLD_SID_AUTHORITY }, { SECURITY_WORLD_RID } } },
86 { {0,0}, WinLocalSid, { SID_REVISION, 1, { SECURITY_LOCAL_SID_AUTHORITY }, { SECURITY_LOCAL_RID } } },
87 { {'C','O'}, WinCreatorOwnerSid, { SID_REVISION, 1, { SECURITY_CREATOR_SID_AUTHORITY }, { SECURITY_CREATOR_OWNER_RID } } },
88 { {'C','G'}, WinCreatorGroupSid, { SID_REVISION, 1, { SECURITY_CREATOR_SID_AUTHORITY }, { SECURITY_CREATOR_GROUP_RID } } },
89 { {0,0}, WinCreatorOwnerServerSid, { SID_REVISION, 1, { SECURITY_CREATOR_SID_AUTHORITY }, { SECURITY_CREATOR_OWNER_SERVER_RID } } },
90 { {0,0}, WinCreatorGroupServerSid, { SID_REVISION, 1, { SECURITY_CREATOR_SID_AUTHORITY }, { SECURITY_CREATOR_GROUP_SERVER_RID } } },
91 { {0,0}, WinNtAuthoritySid, { SID_REVISION, 0, { SECURITY_NT_AUTHORITY }, { SECURITY_NULL_RID } } },
92 { {0,0}, WinDialupSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_DIALUP_RID } } },
93 { {'N','U'}, WinNetworkSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_NETWORK_RID } } },
94 { {0,0}, WinBatchSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_BATCH_RID } } },
95 { {'I','U'}, WinInteractiveSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_INTERACTIVE_RID } } },
96 { {'S','U'}, WinServiceSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_SERVICE_RID } } },
97 { {'A','N'}, WinAnonymousSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_ANONYMOUS_LOGON_RID } } },
98 { {0,0}, WinProxySid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_PROXY_RID } } },
99 { {'E','D'}, WinEnterpriseControllersSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_ENTERPRISE_CONTROLLERS_RID } } },
100 { {'P','S'}, WinSelfSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_PRINCIPAL_SELF_RID } } },
101 { {'A','U'}, WinAuthenticatedUserSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_AUTHENTICATED_USER_RID } } },
102 { {'R','C'}, WinRestrictedCodeSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_RESTRICTED_CODE_RID } } },
103 { {0,0}, WinTerminalServerSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_TERMINAL_SERVER_RID } } },
104 { {0,0}, WinRemoteLogonIdSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_REMOTE_LOGON_RID } } },
105 { {'S','Y'}, WinLocalSystemSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_LOCAL_SYSTEM_RID } } },
106 { {'L','S'}, WinLocalServiceSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_LOCAL_SERVICE_RID } } },
107 { {'N','S'}, WinNetworkServiceSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_NETWORK_SERVICE_RID } } },
108 { {0,0}, WinBuiltinDomainSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID } } },
109 { {'B','A'}, WinBuiltinAdministratorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS } } },
110 { {'B','U'}, WinBuiltinUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_USERS } } },
111 { {'B','G'}, WinBuiltinGuestsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_GUESTS } } },
112 { {'P','U'}, WinBuiltinPowerUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS } } },
113 { {'A','O'}, WinBuiltinAccountOperatorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ACCOUNT_OPS } } },
114 { {'S','O'}, WinBuiltinSystemOperatorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_SYSTEM_OPS } } },
115 { {'P','O'}, WinBuiltinPrintOperatorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_PRINT_OPS } } },
116 { {'B','O'}, WinBuiltinBackupOperatorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_BACKUP_OPS } } },
117 { {'R','E'}, WinBuiltinReplicatorSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_REPLICATOR } } },
118 { {'R','U'}, WinBuiltinPreWindows2000CompatibleAccessSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_PREW2KCOMPACCESS } } },
119 { {'R','D'}, WinBuiltinRemoteDesktopUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS } } },
120 { {'N','O'}, WinBuiltinNetworkConfigurationOperatorsSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS } } },
121 { {0,0}, WinNTLMAuthenticationSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_PACKAGE_BASE_RID, SECURITY_PACKAGE_NTLM_RID } } },
122 { {0,0}, WinDigestAuthenticationSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_PACKAGE_BASE_RID, SECURITY_PACKAGE_DIGEST_RID } } },
123 { {0,0}, WinSChannelAuthenticationSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_PACKAGE_BASE_RID, SECURITY_PACKAGE_SCHANNEL_RID } } },
124 { {0,0}, WinThisOrganizationSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_THIS_ORGANIZATION_RID } } },
125 { {0,0}, WinOtherOrganizationSid, { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_OTHER_ORGANIZATION_RID } } },
126 { {0,0}, WinBuiltinIncomingForestTrustBuildersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_INCOMING_FOREST_TRUST_BUILDERS } } },
127 { {0,0}, WinBuiltinPerfMonitoringUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_MONITORING_USERS } } },
128 { {0,0}, WinBuiltinPerfLoggingUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_LOGGING_USERS } } },
129 { {0,0}, WinBuiltinAuthorizationAccessSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_AUTHORIZATIONACCESS } } },
130 { {0,0}, WinBuiltinTerminalServerLicenseServersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_TS_LICENSE_SERVERS } } },
131 { {0,0}, WinBuiltinDCOMUsersSid, { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_DCOM_USERS } } },
132 { {'L','W'}, WinLowLabelSid, { SID_REVISION, 1, { SECURITY_MANDATORY_LABEL_AUTHORITY}, { SECURITY_MANDATORY_LOW_RID} } },
133 { {'M','E'}, WinMediumLabelSid, { SID_REVISION, 1, { SECURITY_MANDATORY_LABEL_AUTHORITY}, { SECURITY_MANDATORY_MEDIUM_RID } } },
134 { {'H','I'}, WinHighLabelSid, { SID_REVISION, 1, { SECURITY_MANDATORY_LABEL_AUTHORITY}, { SECURITY_MANDATORY_HIGH_RID } } },
135 { {'S','I'}, WinSystemLabelSid, { SID_REVISION, 1, { SECURITY_MANDATORY_LABEL_AUTHORITY}, { SECURITY_MANDATORY_SYSTEM_RID } } },
138 /* these SIDs must be constructed as relative to some domain - only the RID is well-known */
139 typedef struct WELLKNOWNRID
141 WELL_KNOWN_SID_TYPE Type;
145 static const WELLKNOWNRID WellKnownRids[] = {
146 { WinAccountAdministratorSid, DOMAIN_USER_RID_ADMIN },
147 { WinAccountGuestSid, DOMAIN_USER_RID_GUEST },
148 { WinAccountKrbtgtSid, DOMAIN_USER_RID_KRBTGT },
149 { WinAccountDomainAdminsSid, DOMAIN_GROUP_RID_ADMINS },
150 { WinAccountDomainUsersSid, DOMAIN_GROUP_RID_USERS },
151 { WinAccountDomainGuestsSid, DOMAIN_GROUP_RID_GUESTS },
152 { WinAccountComputersSid, DOMAIN_GROUP_RID_COMPUTERS },
153 { WinAccountControllersSid, DOMAIN_GROUP_RID_CONTROLLERS },
154 { WinAccountCertAdminsSid, DOMAIN_GROUP_RID_CERT_ADMINS },
155 { WinAccountSchemaAdminsSid, DOMAIN_GROUP_RID_SCHEMA_ADMINS },
156 { WinAccountEnterpriseAdminsSid, DOMAIN_GROUP_RID_ENTERPRISE_ADMINS },
157 { WinAccountPolicyAdminsSid, DOMAIN_GROUP_RID_POLICY_ADMINS },
158 { WinAccountRasAndIasServersSid, DOMAIN_ALIAS_RID_RAS_SERVERS },
162 static SID const sidWorld = { SID_REVISION, 1, { SECURITY_WORLD_SID_AUTHORITY} , { SECURITY_WORLD_RID } };
164 typedef struct _AccountSid {
165 WELL_KNOWN_SID_TYPE type;
168 SID_NAME_USE name_use;
172 static const WCHAR Account_Operators[] = { 'A','c','c','o','u','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
173 static const WCHAR Administrator[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0 };
174 static const WCHAR Administrators[] = { 'A','d','m','i','n','i','s','t','r','a','t','o','r','s',0 };
175 static const WCHAR ANONYMOUS_LOGON[] = { 'A','N','O','N','Y','M','O','U','S',' ','L','O','G','O','N',0 };
176 static const WCHAR Authenticated_Users[] = { 'A','u','t','h','e','n','t','i','c','a','t','e','d',' ','U','s','e','r','s',0 };
177 static const WCHAR Backup_Operators[] = { 'B','a','c','k','u','p',' ','O','p','e','r','a','t','o','r','s',0 };
178 static const WCHAR BATCH[] = { 'B','A','T','C','H',0 };
179 static const WCHAR Blank[] = { 0 };
180 static const WCHAR BUILTIN[] = { 'B','U','I','L','T','I','N',0 };
181 static const WCHAR Cert_Publishers[] = { 'C','e','r','t',' ','P','u','b','l','i','s','h','e','r','s',0 };
182 static const WCHAR CREATOR_GROUP[] = { 'C','R','E','A','T','O','R',' ','G','R','O','U','P',0 };
183 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 };
184 static const WCHAR CREATOR_OWNER[] = { 'C','R','E','A','T','O','R',' ','O','W','N','E','R',0 };
185 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 };
186 static const WCHAR CURRENT_USER[] = { 'C','U','R','R','E','N','T','_','U','S','E','R',0 };
187 static const WCHAR DIALUP[] = { 'D','I','A','L','U','P',0 };
188 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 };
189 static const WCHAR DOMAIN[] = {'D','O','M','A','I','N',0};
190 static const WCHAR Domain_Admins[] = { 'D','o','m','a','i','n',' ','A','d','m','i','n','s',0 };
191 static const WCHAR Domain_Computers[] = { 'D','o','m','a','i','n',' ','C','o','m','p','u','t','e','r','s',0 };
192 static const WCHAR Domain_Controllers[] = { 'D','o','m','a','i','n',' ','C','o','n','t','r','o','l','l','e','r','s',0 };
193 static const WCHAR Domain_Guests[] = { 'D','o','m','a','i','n',' ','G','u','e','s','t','s',0 };
194 static const WCHAR Domain_Users[] = { 'D','o','m','a','i','n',' ','U','s','e','r','s',0 };
195 static const WCHAR Enterprise_Admins[] = { 'E','n','t','e','r','p','r','i','s','e',' ','A','d','m','i','n','s',0 };
196 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 };
197 static const WCHAR Everyone[] = { 'E','v','e','r','y','o','n','e',0 };
198 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 };
199 static const WCHAR Guest[] = { 'G','u','e','s','t',0 };
200 static const WCHAR Guests[] = { 'G','u','e','s','t','s',0 };
201 static const WCHAR INTERACTIVE[] = { 'I','N','T','E','R','A','C','T','I','V','E',0 };
202 static const WCHAR LOCAL[] = { 'L','O','C','A','L',0 };
203 static const WCHAR LOCAL_SERVICE[] = { 'L','O','C','A','L',' ','S','E','R','V','I','C','E',0 };
204 static const WCHAR LOCAL_SERVICE2[] = { 'L','O','C','A','L','S','E','R','V','I','C','E',0 };
205 static const WCHAR NETWORK[] = { 'N','E','T','W','O','R','K',0 };
206 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 };
207 static const WCHAR NETWORK_SERVICE[] = { 'N','E','T','W','O','R','K',' ','S','E','R','V','I','C','E',0 };
208 static const WCHAR NETWORK_SERVICE2[] = { 'N','E','T','W','O','R','K','S','E','R','V','I','C','E',0 };
209 static const WCHAR NT_AUTHORITY[] = { 'N','T',' ','A','U','T','H','O','R','I','T','Y',0 };
210 static const WCHAR NT_Pseudo_Domain[] = { 'N','T',' ','P','s','e','u','d','o',' ','D','o','m','a','i','n',0 };
211 static const WCHAR NTML_Authentication[] = { 'N','T','M','L',' ','A','u','t','h','e','n','t','i','c','a','t','i','o','n',0 };
212 static const WCHAR NULL_SID[] = { 'N','U','L','L',' ','S','I','D',0 };
213 static const WCHAR Other_Organization[] = { 'O','t','h','e','r',' ','O','r','g','a','n','i','z','a','t','i','o','n',0 };
214 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 };
215 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 };
216 static const WCHAR Power_Users[] = { 'P','o','w','e','r',' ','U','s','e','r','s',0 };
217 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 };
218 static const WCHAR Print_Operators[] = { 'P','r','i','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
219 static const WCHAR PROXY[] = { 'P','R','O','X','Y',0 };
220 static const WCHAR RAS_and_IAS_Servers[] = { 'R','A','S',' ','a','n','d',' ','I','A','S',' ','S','e','r','v','e','r','s',0 };
221 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 };
222 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 };
223 static const WCHAR Replicators[] = { 'R','e','p','l','i','c','a','t','o','r','s',0 };
224 static const WCHAR RESTRICTED[] = { 'R','E','S','T','R','I','C','T','E','D',0 };
225 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 };
226 static const WCHAR Schema_Admins[] = { 'S','c','h','e','m','a',' ','A','d','m','i','n','s',0 };
227 static const WCHAR SELF[] = { 'S','E','L','F',0 };
228 static const WCHAR Server_Operators[] = { 'S','e','r','v','e','r',' ','O','p','e','r','a','t','o','r','s',0 };
229 static const WCHAR SERVICE[] = { 'S','E','R','V','I','C','E',0 };
230 static const WCHAR SYSTEM[] = { 'S','Y','S','T','E','M',0 };
231 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 };
232 static const WCHAR This_Organization[] = { 'T','h','i','s',' ','O','r','g','a','n','i','z','a','t','i','o','n',0 };
233 static const WCHAR Users[] = { 'U','s','e','r','s',0 };
235 static const AccountSid ACCOUNT_SIDS[] = {
236 { WinNullSid, NULL_SID, Blank, SidTypeWellKnownGroup },
237 { WinWorldSid, Everyone, Blank, SidTypeWellKnownGroup },
238 { WinLocalSid, LOCAL, Blank, SidTypeWellKnownGroup },
239 { WinCreatorOwnerSid, CREATOR_OWNER, Blank, SidTypeWellKnownGroup },
240 { WinCreatorGroupSid, CREATOR_GROUP, Blank, SidTypeWellKnownGroup },
241 { WinCreatorOwnerServerSid, CREATOR_OWNER_SERVER, Blank, SidTypeWellKnownGroup },
242 { WinCreatorGroupServerSid, CREATOR_GROUP_SERVER, Blank, SidTypeWellKnownGroup },
243 { WinNtAuthoritySid, NT_Pseudo_Domain, NT_Pseudo_Domain, SidTypeDomain },
244 { WinDialupSid, DIALUP, NT_AUTHORITY, SidTypeWellKnownGroup },
245 { WinNetworkSid, NETWORK, NT_AUTHORITY, SidTypeWellKnownGroup },
246 { WinBatchSid, BATCH, NT_AUTHORITY, SidTypeWellKnownGroup },
247 { WinInteractiveSid, INTERACTIVE, NT_AUTHORITY, SidTypeWellKnownGroup },
248 { WinServiceSid, SERVICE, NT_AUTHORITY, SidTypeWellKnownGroup },
249 { WinAnonymousSid, ANONYMOUS_LOGON, NT_AUTHORITY, SidTypeWellKnownGroup },
250 { WinProxySid, PROXY, NT_AUTHORITY, SidTypeWellKnownGroup },
251 { WinEnterpriseControllersSid, ENTERPRISE_DOMAIN_CONTROLLERS, NT_AUTHORITY, SidTypeWellKnownGroup },
252 { WinSelfSid, SELF, NT_AUTHORITY, SidTypeWellKnownGroup },
253 { WinAuthenticatedUserSid, Authenticated_Users, NT_AUTHORITY, SidTypeWellKnownGroup },
254 { WinRestrictedCodeSid, RESTRICTED, NT_AUTHORITY, SidTypeWellKnownGroup },
255 { WinTerminalServerSid, TERMINAL_SERVER_USER, NT_AUTHORITY, SidTypeWellKnownGroup },
256 { WinRemoteLogonIdSid, REMOTE_INTERACTIVE_LOGON, NT_AUTHORITY, SidTypeWellKnownGroup },
257 { WinLocalSystemSid, SYSTEM, NT_AUTHORITY, SidTypeWellKnownGroup },
258 { WinLocalServiceSid, LOCAL_SERVICE, NT_AUTHORITY, SidTypeWellKnownGroup, LOCAL_SERVICE2 },
259 { WinNetworkServiceSid, NETWORK_SERVICE, NT_AUTHORITY, SidTypeWellKnownGroup , NETWORK_SERVICE2},
260 { WinBuiltinDomainSid, BUILTIN, BUILTIN, SidTypeDomain },
261 { WinBuiltinAdministratorsSid, Administrators, BUILTIN, SidTypeAlias },
262 { WinBuiltinUsersSid, Users, BUILTIN, SidTypeAlias },
263 { WinBuiltinGuestsSid, Guests, BUILTIN, SidTypeAlias },
264 { WinBuiltinPowerUsersSid, Power_Users, BUILTIN, SidTypeAlias },
265 { WinBuiltinAccountOperatorsSid, Account_Operators, BUILTIN, SidTypeAlias },
266 { WinBuiltinSystemOperatorsSid, Server_Operators, BUILTIN, SidTypeAlias },
267 { WinBuiltinPrintOperatorsSid, Print_Operators, BUILTIN, SidTypeAlias },
268 { WinBuiltinBackupOperatorsSid, Backup_Operators, BUILTIN, SidTypeAlias },
269 { WinBuiltinReplicatorSid, Replicators, BUILTIN, SidTypeAlias },
270 { WinBuiltinPreWindows2000CompatibleAccessSid, Pre_Windows_2000_Compatible_Access, BUILTIN, SidTypeAlias },
271 { WinBuiltinRemoteDesktopUsersSid, Remote_Desktop_Users, BUILTIN, SidTypeAlias },
272 { WinBuiltinNetworkConfigurationOperatorsSid, Network_Configuration_Operators, BUILTIN, SidTypeAlias },
273 { WinNTLMAuthenticationSid, NTML_Authentication, NT_AUTHORITY, SidTypeWellKnownGroup },
274 { WinDigestAuthenticationSid, Digest_Authentication, NT_AUTHORITY, SidTypeWellKnownGroup },
275 { WinSChannelAuthenticationSid, SChannel_Authentication, NT_AUTHORITY, SidTypeWellKnownGroup },
276 { WinThisOrganizationSid, This_Organization, NT_AUTHORITY, SidTypeWellKnownGroup },
277 { WinOtherOrganizationSid, Other_Organization, NT_AUTHORITY, SidTypeWellKnownGroup },
278 { WinBuiltinPerfMonitoringUsersSid, Performance_Monitor_Users, BUILTIN, SidTypeAlias },
279 { WinBuiltinPerfLoggingUsersSid, Performance_Log_Users, BUILTIN, SidTypeAlias },
284 static const WCHAR SDDL_READ_CONTROL[] = {'R','C',0};
285 static const WCHAR SDDL_WRITE_DAC[] = {'W','D',0};
286 static const WCHAR SDDL_WRITE_OWNER[] = {'W','O',0};
287 static const WCHAR SDDL_STANDARD_DELETE[] = {'S','D',0};
289 static const WCHAR SDDL_READ_PROPERTY[] = {'R','P',0};
290 static const WCHAR SDDL_WRITE_PROPERTY[] = {'W','P',0};
291 static const WCHAR SDDL_CREATE_CHILD[] = {'C','C',0};
292 static const WCHAR SDDL_DELETE_CHILD[] = {'D','C',0};
293 static const WCHAR SDDL_LIST_CHILDREN[] = {'L','C',0};
294 static const WCHAR SDDL_SELF_WRITE[] = {'S','W',0};
295 static const WCHAR SDDL_LIST_OBJECT[] = {'L','O',0};
296 static const WCHAR SDDL_DELETE_TREE[] = {'D','T',0};
297 static const WCHAR SDDL_CONTROL_ACCESS[] = {'C','R',0};
299 static const WCHAR SDDL_FILE_ALL[] = {'F','A',0};
300 static const WCHAR SDDL_FILE_READ[] = {'F','R',0};
301 static const WCHAR SDDL_FILE_WRITE[] = {'F','W',0};
302 static const WCHAR SDDL_FILE_EXECUTE[] = {'F','X',0};
304 static const WCHAR SDDL_KEY_ALL[] = {'K','A',0};
305 static const WCHAR SDDL_KEY_READ[] = {'K','R',0};
306 static const WCHAR SDDL_KEY_WRITE[] = {'K','W',0};
307 static const WCHAR SDDL_KEY_EXECUTE[] = {'K','X',0};
309 static const WCHAR SDDL_GENERIC_ALL[] = {'G','A',0};
310 static const WCHAR SDDL_GENERIC_READ[] = {'G','R',0};
311 static const WCHAR SDDL_GENERIC_WRITE[] = {'G','W',0};
312 static const WCHAR SDDL_GENERIC_EXECUTE[] = {'G','X',0};
317 static const WCHAR SDDL_PROTECTED[] = {'P',0};
318 static const WCHAR SDDL_AUTO_INHERIT_REQ[] = {'A','R',0};
319 static const WCHAR SDDL_AUTO_INHERITED[] = {'A','I',0};
324 static const WCHAR SDDL_ACCESS_ALLOWED[] = {'A',0};
325 static const WCHAR SDDL_ACCESS_DENIED[] = {'D',0};
326 static const WCHAR SDDL_OBJECT_ACCESS_ALLOWED[] = {'O','A',0};
327 static const WCHAR SDDL_OBJECT_ACCESS_DENIED[] = {'O','D',0};
328 static const WCHAR SDDL_AUDIT[] = {'A','U',0};
329 static const WCHAR SDDL_ALARM[] = {'A','L',0};
330 static const WCHAR SDDL_OBJECT_AUDIT[] = {'O','U',0};
331 static const WCHAR SDDL_OBJECT_ALARMp[] = {'O','L',0};
336 static const WCHAR SDDL_CONTAINER_INHERIT[] = {'C','I',0};
337 static const WCHAR SDDL_OBJECT_INHERIT[] = {'O','I',0};
338 static const WCHAR SDDL_NO_PROPAGATE[] = {'N','P',0};
339 static const WCHAR SDDL_INHERIT_ONLY[] = {'I','O',0};
340 static const WCHAR SDDL_INHERITED[] = {'I','D',0};
341 static const WCHAR SDDL_AUDIT_SUCCESS[] = {'S','A',0};
342 static const WCHAR SDDL_AUDIT_FAILURE[] = {'F','A',0};
344 const char * debugstr_sid(PSID sid)
352 auth = psid->IdentifierAuthority.Value[5] +
353 (psid->IdentifierAuthority.Value[4] << 8) +
354 (psid->IdentifierAuthority.Value[3] << 16) +
355 (psid->IdentifierAuthority.Value[2] << 24);
357 switch (psid->SubAuthorityCount) {
359 return wine_dbg_sprintf("S-%d-%d", psid->Revision, auth);
361 return wine_dbg_sprintf("S-%d-%d-%u", psid->Revision, auth,
362 psid->SubAuthority[0]);
364 return wine_dbg_sprintf("S-%d-%d-%u-%u", psid->Revision, auth,
365 psid->SubAuthority[0], psid->SubAuthority[1]);
367 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u", psid->Revision, auth,
368 psid->SubAuthority[0], psid->SubAuthority[1], psid->SubAuthority[2]);
370 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u", psid->Revision, auth,
371 psid->SubAuthority[0], psid->SubAuthority[1], psid->SubAuthority[2],
372 psid->SubAuthority[3]);
374 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u", psid->Revision, auth,
375 psid->SubAuthority[0], psid->SubAuthority[1], psid->SubAuthority[2],
376 psid->SubAuthority[3], psid->SubAuthority[4]);
378 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u", psid->Revision, auth,
379 psid->SubAuthority[3], psid->SubAuthority[1], psid->SubAuthority[2],
380 psid->SubAuthority[0], psid->SubAuthority[4], psid->SubAuthority[5]);
382 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u-%u", psid->Revision, auth,
383 psid->SubAuthority[0], psid->SubAuthority[1], psid->SubAuthority[2],
384 psid->SubAuthority[3], psid->SubAuthority[4], psid->SubAuthority[5],
385 psid->SubAuthority[6]);
387 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u-%u-%u", psid->Revision, auth,
388 psid->SubAuthority[0], psid->SubAuthority[1], psid->SubAuthority[2],
389 psid->SubAuthority[3], psid->SubAuthority[4], psid->SubAuthority[5],
390 psid->SubAuthority[6], psid->SubAuthority[7]);
395 /* set last error code from NT status and get the proper boolean return value */
396 /* used for functions that are a simple wrapper around the corresponding ntdll API */
397 static inline BOOL set_ntstatus( NTSTATUS status )
399 if (status) SetLastError( RtlNtStatusToDosError( status ));
403 #define WINE_SIZE_OF_WORLD_ACCESS_ACL (sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD))
405 static void GetWorldAccessACL(PACL pACL)
407 PACCESS_ALLOWED_ACE pACE = (PACCESS_ALLOWED_ACE) (pACL + 1);
409 pACL->AclRevision = ACL_REVISION;
411 pACL->AclSize = WINE_SIZE_OF_WORLD_ACCESS_ACL;
415 pACE->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
416 pACE->Header.AceFlags = CONTAINER_INHERIT_ACE;
417 pACE->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD);
418 pACE->Mask = 0xf3ffffff; /* Everything except reserved bits */
419 memcpy(&pACE->SidStart, &sidWorld, sizeof(sidWorld));
422 /************************************************************
423 * ADVAPI_IsLocalComputer
425 * Checks whether the server name indicates local machine.
427 BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName)
429 DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
433 if (!ServerName || !ServerName[0])
436 buf = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
437 Result = GetComputerNameW(buf, &dwSize);
438 if (Result && (ServerName[0] == '\\') && (ServerName[1] == '\\'))
440 Result = Result && !lstrcmpW(ServerName, buf);
441 HeapFree(GetProcessHeap(), 0, buf);
446 /************************************************************
447 * ADVAPI_GetComputerSid
449 BOOL ADVAPI_GetComputerSid(PSID sid)
451 static const struct /* same fields as struct SID */
454 BYTE SubAuthorityCount;
455 SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
456 DWORD SubAuthority[4];
458 { SID_REVISION, 4, { SECURITY_NT_AUTHORITY }, { SECURITY_NT_NON_UNIQUE, 0, 0, 0 } };
460 memcpy( sid, &computer_sid, sizeof(computer_sid) );
464 /* ##############################
465 ###### TOKEN FUNCTIONS ######
466 ##############################
469 /******************************************************************************
470 * OpenProcessToken [ADVAPI32.@]
471 * Opens the access token associated with a process handle.
474 * ProcessHandle [I] Handle to process
475 * DesiredAccess [I] Desired access to process
476 * TokenHandle [O] Pointer to handle of open access token
479 * Success: TRUE. TokenHandle contains the access token.
483 * See NtOpenProcessToken.
486 OpenProcessToken( HANDLE ProcessHandle, DWORD DesiredAccess,
487 HANDLE *TokenHandle )
489 return set_ntstatus(NtOpenProcessToken( ProcessHandle, DesiredAccess, TokenHandle ));
492 /******************************************************************************
493 * OpenThreadToken [ADVAPI32.@]
495 * Opens the access token associated with a thread handle.
498 * ThreadHandle [I] Handle to process
499 * DesiredAccess [I] Desired access to the thread
501 * TokenHandle [O] Destination for the token handle
504 * Success: TRUE. TokenHandle contains the access token.
508 * See NtOpenThreadToken.
511 OpenThreadToken( HANDLE ThreadHandle, DWORD DesiredAccess,
512 BOOL OpenAsSelf, HANDLE *TokenHandle)
514 return set_ntstatus( NtOpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle));
518 AdjustTokenGroups( HANDLE TokenHandle, BOOL ResetToDefault, PTOKEN_GROUPS NewState,
519 DWORD BufferLength, PTOKEN_GROUPS PreviousState, PDWORD ReturnLength )
521 return set_ntstatus( NtAdjustGroupsToken(TokenHandle, ResetToDefault, NewState, BufferLength,
522 PreviousState, ReturnLength));
525 /******************************************************************************
526 * AdjustTokenPrivileges [ADVAPI32.@]
528 * Adjust the privileges of an open token handle.
531 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
532 * DisableAllPrivileges [I] TRUE=Remove all privileges, FALSE=Use NewState
533 * NewState [I] Desired new privileges of the token
534 * BufferLength [I] Length of NewState
535 * PreviousState [O] Destination for the previous state
536 * ReturnLength [I/O] Size of PreviousState
540 * Success: TRUE. Privileges are set to NewState and PreviousState is updated.
544 * See NtAdjustPrivilegesToken.
547 AdjustTokenPrivileges( HANDLE TokenHandle, BOOL DisableAllPrivileges,
548 PTOKEN_PRIVILEGES NewState, DWORD BufferLength,
549 PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength )
555 status = NtAdjustPrivilegesToken(TokenHandle, DisableAllPrivileges,
556 NewState, BufferLength, PreviousState,
558 SetLastError( RtlNtStatusToDosError( status ));
559 if ((status == STATUS_SUCCESS) || (status == STATUS_NOT_ALL_ASSIGNED))
565 /******************************************************************************
566 * CheckTokenMembership [ADVAPI32.@]
568 * Determine if an access token is a member of a SID.
571 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
572 * SidToCheck [I] SID that possibly contains the token
573 * IsMember [O] Destination for result.
576 * Success: TRUE. IsMember is TRUE if TokenHandle is a member, FALSE otherwise.
580 CheckTokenMembership( HANDLE token, PSID sid_to_check,
583 PTOKEN_GROUPS token_groups = NULL;
584 HANDLE thread_token = NULL;
588 TRACE("(%p %s %p)\n", token, debugstr_sid(sid_to_check), is_member);
594 if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, TRUE, &thread_token))
596 HANDLE process_token;
597 ret = OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE, &process_token);
600 ret = DuplicateTokenEx(process_token, TOKEN_QUERY,
601 NULL, SecurityImpersonation, TokenImpersonation,
603 CloseHandle(process_token);
607 token = thread_token;
613 ret = GetTokenInformation(token, TokenType, &type, sizeof(TOKEN_TYPE), &size);
616 if (type == TokenPrimary)
618 SetLastError(ERROR_NO_IMPERSONATION_TOKEN);
623 ret = GetTokenInformation(token, TokenGroups, NULL, 0, &size);
624 if (!ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
627 token_groups = HeapAlloc(GetProcessHeap(), 0, size);
634 ret = GetTokenInformation(token, TokenGroups, token_groups, size, &size);
638 for (i = 0; i < token_groups->GroupCount; i++)
640 TRACE("Groups[%d]: {0x%x, %s}\n", i,
641 token_groups->Groups[i].Attributes,
642 debugstr_sid(token_groups->Groups[i].Sid));
643 if ((token_groups->Groups[i].Attributes & SE_GROUP_ENABLED) &&
644 EqualSid(sid_to_check, token_groups->Groups[i].Sid))
647 TRACE("sid enabled and found in token\n");
653 HeapFree(GetProcessHeap(), 0, token_groups);
654 if (thread_token != NULL) CloseHandle(thread_token);
659 /******************************************************************************
660 * GetTokenInformation [ADVAPI32.@]
662 * Get a type of information about an access token.
665 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
666 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
667 * tokeninfo [O] Destination for token information
668 * tokeninfolength [I] Length of tokeninfo
669 * retlen [O] Destination for returned token information length
672 * Success: TRUE. tokeninfo contains retlen bytes of token information
676 * See NtQueryInformationToken.
679 GetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
680 LPVOID tokeninfo, DWORD tokeninfolength, LPDWORD retlen )
682 TRACE("(%p, %s, %p, %d, %p):\n",
684 (tokeninfoclass == TokenUser) ? "TokenUser" :
685 (tokeninfoclass == TokenGroups) ? "TokenGroups" :
686 (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
687 (tokeninfoclass == TokenOwner) ? "TokenOwner" :
688 (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
689 (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
690 (tokeninfoclass == TokenSource) ? "TokenSource" :
691 (tokeninfoclass == TokenType) ? "TokenType" :
692 (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
693 (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
694 (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
695 (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
696 (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
697 (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
698 (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
700 tokeninfo, tokeninfolength, retlen);
701 return set_ntstatus( NtQueryInformationToken( token, tokeninfoclass, tokeninfo,
702 tokeninfolength, retlen));
705 /******************************************************************************
706 * SetTokenInformation [ADVAPI32.@]
708 * Set information for an access token.
711 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
712 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
713 * tokeninfo [I] Token information to set
714 * tokeninfolength [I] Length of tokeninfo
717 * Success: TRUE. The information for the token is set to tokeninfo.
721 SetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
722 LPVOID tokeninfo, DWORD tokeninfolength )
724 TRACE("(%p, %s, %p, %d): stub\n",
726 (tokeninfoclass == TokenUser) ? "TokenUser" :
727 (tokeninfoclass == TokenGroups) ? "TokenGroups" :
728 (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
729 (tokeninfoclass == TokenOwner) ? "TokenOwner" :
730 (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
731 (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
732 (tokeninfoclass == TokenSource) ? "TokenSource" :
733 (tokeninfoclass == TokenType) ? "TokenType" :
734 (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
735 (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
736 (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
737 (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
738 (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
739 (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
740 (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
742 tokeninfo, tokeninfolength);
744 return set_ntstatus( NtSetInformationToken( token, tokeninfoclass, tokeninfo, tokeninfolength ));
747 /*************************************************************************
748 * SetThreadToken [ADVAPI32.@]
750 * Assigns an 'impersonation token' to a thread so it can assume the
751 * security privileges of another thread or process. Can also remove
752 * a previously assigned token.
755 * thread [O] Handle to thread to set the token for
756 * token [I] Token to set
759 * Success: TRUE. The threads access token is set to token
763 * Only supported on NT or higher. On Win9X this function does nothing.
764 * See SetTokenInformation.
766 BOOL WINAPI SetThreadToken(PHANDLE thread, HANDLE token)
768 return set_ntstatus( NtSetInformationThread( thread ? *thread : GetCurrentThread(),
769 ThreadImpersonationToken, &token, sizeof token ));
772 /*************************************************************************
773 * CreateRestrictedToken [ADVAPI32.@]
775 * Create a new more restricted token from an existing token.
778 * baseToken [I] Token to base the new restricted token on
780 * nDisableSids [I] Length of disableSids array
781 * disableSids [I] Array of SIDs to disable in the new token
782 * nDeletePrivs [I] Length of deletePrivs array
783 * deletePrivs [I] Array of privileges to delete in the new token
784 * nRestrictSids [I] Length of restrictSids array
785 * restrictSids [I] Array of SIDs to restrict in the new token
786 * newToken [O] Address where the new token is stored
792 BOOL WINAPI CreateRestrictedToken(
796 PSID_AND_ATTRIBUTES disableSids,
798 PLUID_AND_ATTRIBUTES deletePrivs,
800 PSID_AND_ATTRIBUTES restrictSids,
803 FIXME("(%p, 0x%x, %u, %p, %u, %p, %u, %p, %p): stub\n",
804 baseToken, flags, nDisableSids, disableSids,
805 nDeletePrivs, deletePrivs,
806 nRestrictSids, restrictSids,
808 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
812 /* ##############################
813 ###### SID FUNCTIONS ######
814 ##############################
817 /******************************************************************************
818 * AllocateAndInitializeSid [ADVAPI32.@]
821 * pIdentifierAuthority []
822 * nSubAuthorityCount []
834 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
835 BYTE nSubAuthorityCount,
836 DWORD nSubAuthority0, DWORD nSubAuthority1,
837 DWORD nSubAuthority2, DWORD nSubAuthority3,
838 DWORD nSubAuthority4, DWORD nSubAuthority5,
839 DWORD nSubAuthority6, DWORD nSubAuthority7,
842 return set_ntstatus( RtlAllocateAndInitializeSid(
843 pIdentifierAuthority, nSubAuthorityCount,
844 nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3,
845 nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7,
849 /******************************************************************************
850 * FreeSid [ADVAPI32.@]
859 return NULL; /* is documented like this */
862 /******************************************************************************
863 * CopySid [ADVAPI32.@]
866 * nDestinationSidLength []
871 CopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
873 return RtlCopySid(nDestinationSidLength, pDestinationSid, pSourceSid);
876 /******************************************************************************
877 * CreateWellKnownSid [ADVAPI32.@]
880 CreateWellKnownSid( WELL_KNOWN_SID_TYPE WellKnownSidType,
886 TRACE("(%d, %s, %p, %p)\n", WellKnownSidType, debugstr_sid(DomainSid), pSid, cbSid);
888 if (cbSid == NULL || (DomainSid && !IsValidSid(DomainSid)))
890 SetLastError(ERROR_INVALID_PARAMETER);
894 for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++) {
895 if (WellKnownSids[i].Type == WellKnownSidType) {
896 DWORD length = GetSidLengthRequired(WellKnownSids[i].Sid.SubAuthorityCount);
901 SetLastError(ERROR_INSUFFICIENT_BUFFER);
906 SetLastError(ERROR_INVALID_PARAMETER);
909 CopyMemory(pSid, &WellKnownSids[i].Sid.Revision, length);
915 if (DomainSid == NULL || *GetSidSubAuthorityCount(DomainSid) == SID_MAX_SUB_AUTHORITIES)
917 SetLastError(ERROR_INVALID_PARAMETER);
921 for (i = 0; i < sizeof(WellKnownRids)/sizeof(WellKnownRids[0]); i++)
922 if (WellKnownRids[i].Type == WellKnownSidType) {
923 UCHAR domain_subauth = *GetSidSubAuthorityCount(DomainSid);
924 DWORD domain_sid_length = GetSidLengthRequired(domain_subauth);
925 DWORD output_sid_length = GetSidLengthRequired(domain_subauth + 1);
927 if (*cbSid < output_sid_length)
929 *cbSid = output_sid_length;
930 SetLastError(ERROR_INSUFFICIENT_BUFFER);
935 SetLastError(ERROR_INVALID_PARAMETER);
938 CopyMemory(pSid, DomainSid, domain_sid_length);
939 (*GetSidSubAuthorityCount(pSid))++;
940 (*GetSidSubAuthority(pSid, domain_subauth)) = WellKnownRids[i].Rid;
941 *cbSid = output_sid_length;
945 SetLastError(ERROR_INVALID_PARAMETER);
949 /******************************************************************************
950 * IsWellKnownSid [ADVAPI32.@]
953 IsWellKnownSid( PSID pSid, WELL_KNOWN_SID_TYPE WellKnownSidType )
956 TRACE("(%s, %d)\n", debugstr_sid(pSid), WellKnownSidType);
958 for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++)
959 if (WellKnownSids[i].Type == WellKnownSidType)
960 if (EqualSid(pSid, (PSID)&(WellKnownSids[i].Sid.Revision)))
967 IsTokenRestricted( HANDLE TokenHandle )
969 TOKEN_GROUPS *groups;
974 TRACE("(%p)\n", TokenHandle);
976 status = NtQueryInformationToken(TokenHandle, TokenRestrictedSids, NULL, 0, &size);
977 if (status != STATUS_BUFFER_TOO_SMALL)
980 groups = HeapAlloc(GetProcessHeap(), 0, size);
983 SetLastError(ERROR_OUTOFMEMORY);
987 status = NtQueryInformationToken(TokenHandle, TokenRestrictedSids, groups, size, &size);
988 if (status != STATUS_SUCCESS)
990 HeapFree(GetProcessHeap(), 0, groups);
991 return set_ntstatus(status);
994 if (groups->GroupCount)
999 HeapFree(GetProcessHeap(), 0, groups);
1004 /******************************************************************************
1005 * IsValidSid [ADVAPI32.@]
1011 IsValidSid( PSID pSid )
1013 return RtlValidSid( pSid );
1016 /******************************************************************************
1017 * EqualSid [ADVAPI32.@]
1024 EqualSid( PSID pSid1, PSID pSid2 )
1026 BOOL ret = RtlEqualSid( pSid1, pSid2 );
1027 SetLastError(ERROR_SUCCESS);
1031 /******************************************************************************
1032 * EqualPrefixSid [ADVAPI32.@]
1034 BOOL WINAPI EqualPrefixSid (PSID pSid1, PSID pSid2)
1036 return RtlEqualPrefixSid(pSid1, pSid2);
1039 /******************************************************************************
1040 * GetSidLengthRequired [ADVAPI32.@]
1043 * nSubAuthorityCount []
1046 GetSidLengthRequired( BYTE nSubAuthorityCount )
1048 return RtlLengthRequiredSid(nSubAuthorityCount);
1051 /******************************************************************************
1052 * InitializeSid [ADVAPI32.@]
1055 * pIdentifierAuthority []
1060 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
1061 BYTE nSubAuthorityCount)
1063 return RtlInitializeSid(pSid, pIdentifierAuthority, nSubAuthorityCount);
1067 GetEffectiveRightsFromAclA( PACL pacl, PTRUSTEEA pTrustee, PACCESS_MASK pAccessRights )
1069 FIXME("%p %p %p - stub\n", pacl, pTrustee, pAccessRights);
1071 *pAccessRights = STANDARD_RIGHTS_ALL | SPECIFIC_RIGHTS_ALL;
1076 GetEffectiveRightsFromAclW( PACL pacl, PTRUSTEEW pTrustee, PACCESS_MASK pAccessRights )
1078 FIXME("%p %p %p - stub\n", pacl, pTrustee, pAccessRights);
1083 /******************************************************************************
1084 * GetSidIdentifierAuthority [ADVAPI32.@]
1089 PSID_IDENTIFIER_AUTHORITY WINAPI
1090 GetSidIdentifierAuthority( PSID pSid )
1092 return RtlIdentifierAuthoritySid(pSid);
1095 /******************************************************************************
1096 * GetSidSubAuthority [ADVAPI32.@]
1103 GetSidSubAuthority( PSID pSid, DWORD nSubAuthority )
1105 SetLastError(ERROR_SUCCESS);
1106 return RtlSubAuthoritySid(pSid, nSubAuthority);
1109 /******************************************************************************
1110 * GetSidSubAuthorityCount [ADVAPI32.@]
1116 GetSidSubAuthorityCount (PSID pSid)
1118 SetLastError(ERROR_SUCCESS);
1119 return RtlSubAuthorityCountSid(pSid);
1122 /******************************************************************************
1123 * GetLengthSid [ADVAPI32.@]
1129 GetLengthSid (PSID pSid)
1131 return RtlLengthSid(pSid);
1134 /* ##############################################
1135 ###### SECURITY DESCRIPTOR FUNCTIONS ######
1136 ##############################################
1139 /******************************************************************************
1140 * BuildSecurityDescriptorA [ADVAPI32.@]
1147 * cCountOfAccessEntries [I]
1148 * pListOfAccessEntries [I]
1149 * cCountOfAuditEntries [I]
1150 * pListofAuditEntries [I]
1152 * lpdwBufferLength [I/O]
1156 * Success: ERROR_SUCCESS
1157 * Failure: nonzero error code from Winerror.h
1159 DWORD WINAPI BuildSecurityDescriptorA(
1160 IN PTRUSTEEA pOwner,
1161 IN PTRUSTEEA pGroup,
1162 IN ULONG cCountOfAccessEntries,
1163 IN PEXPLICIT_ACCESSA pListOfAccessEntries,
1164 IN ULONG cCountOfAuditEntries,
1165 IN PEXPLICIT_ACCESSA pListofAuditEntries,
1166 IN PSECURITY_DESCRIPTOR pOldSD,
1167 IN OUT PULONG lpdwBufferLength,
1168 OUT PSECURITY_DESCRIPTOR* pNewSD)
1170 FIXME("(%p,%p,%d,%p,%d,%p,%p,%p,%p) stub!\n",pOwner,pGroup,
1171 cCountOfAccessEntries,pListOfAccessEntries,cCountOfAuditEntries,
1172 pListofAuditEntries,pOldSD,lpdwBufferLength,pNewSD);
1174 return ERROR_CALL_NOT_IMPLEMENTED;
1177 /******************************************************************************
1178 * BuildSecurityDescriptorW [ADVAPI32.@]
1180 * See BuildSecurityDescriptorA.
1182 DWORD WINAPI BuildSecurityDescriptorW(
1183 IN PTRUSTEEW pOwner,
1184 IN PTRUSTEEW pGroup,
1185 IN ULONG cCountOfAccessEntries,
1186 IN PEXPLICIT_ACCESSW pListOfAccessEntries,
1187 IN ULONG cCountOfAuditEntries,
1188 IN PEXPLICIT_ACCESSW pListofAuditEntries,
1189 IN PSECURITY_DESCRIPTOR pOldSD,
1190 IN OUT PULONG lpdwBufferLength,
1191 OUT PSECURITY_DESCRIPTOR* pNewSD)
1193 FIXME("(%p,%p,%d,%p,%d,%p,%p,%p,%p) stub!\n",pOwner,pGroup,
1194 cCountOfAccessEntries,pListOfAccessEntries,cCountOfAuditEntries,
1195 pListofAuditEntries,pOldSD,lpdwBufferLength,pNewSD);
1197 return ERROR_CALL_NOT_IMPLEMENTED;
1200 /******************************************************************************
1201 * InitializeSecurityDescriptor [ADVAPI32.@]
1208 InitializeSecurityDescriptor( PSECURITY_DESCRIPTOR pDescr, DWORD revision )
1210 return set_ntstatus( RtlCreateSecurityDescriptor(pDescr, revision ));
1214 /******************************************************************************
1215 * MakeAbsoluteSD [ADVAPI32.@]
1217 BOOL WINAPI MakeAbsoluteSD (
1218 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
1219 OUT PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
1220 OUT LPDWORD lpdwAbsoluteSecurityDescriptorSize,
1222 OUT LPDWORD lpdwDaclSize,
1224 OUT LPDWORD lpdwSaclSize,
1226 OUT LPDWORD lpdwOwnerSize,
1227 OUT PSID pPrimaryGroup,
1228 OUT LPDWORD lpdwPrimaryGroupSize)
1230 return set_ntstatus( RtlSelfRelativeToAbsoluteSD(pSelfRelativeSecurityDescriptor,
1231 pAbsoluteSecurityDescriptor,
1232 lpdwAbsoluteSecurityDescriptorSize,
1233 pDacl, lpdwDaclSize, pSacl, lpdwSaclSize,
1234 pOwner, lpdwOwnerSize,
1235 pPrimaryGroup, lpdwPrimaryGroupSize));
1238 /******************************************************************************
1239 * GetKernelObjectSecurity [ADVAPI32.@]
1241 BOOL WINAPI GetKernelObjectSecurity(
1243 SECURITY_INFORMATION RequestedInformation,
1244 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1246 LPDWORD lpnLengthNeeded )
1248 TRACE("(%p,0x%08x,%p,0x%08x,%p)\n", Handle, RequestedInformation,
1249 pSecurityDescriptor, nLength, lpnLengthNeeded);
1251 return set_ntstatus( NtQuerySecurityObject(Handle, RequestedInformation, pSecurityDescriptor,
1252 nLength, lpnLengthNeeded ));
1255 /******************************************************************************
1256 * GetPrivateObjectSecurity [ADVAPI32.@]
1258 BOOL WINAPI GetPrivateObjectSecurity(
1259 PSECURITY_DESCRIPTOR ObjectDescriptor,
1260 SECURITY_INFORMATION SecurityInformation,
1261 PSECURITY_DESCRIPTOR ResultantDescriptor,
1262 DWORD DescriptorLength,
1263 PDWORD ReturnLength )
1265 SECURITY_DESCRIPTOR desc;
1266 BOOL defaulted, present;
1270 TRACE("(%p,0x%08x,%p,0x%08x,%p)\n", ObjectDescriptor, SecurityInformation,
1271 ResultantDescriptor, DescriptorLength, ReturnLength);
1273 if (!InitializeSecurityDescriptor(&desc, SECURITY_DESCRIPTOR_REVISION))
1276 if (SecurityInformation & OWNER_SECURITY_INFORMATION)
1278 if (!GetSecurityDescriptorOwner(ObjectDescriptor, &psid, &defaulted))
1280 SetSecurityDescriptorOwner(&desc, psid, defaulted);
1283 if (SecurityInformation & GROUP_SECURITY_INFORMATION)
1285 if (!GetSecurityDescriptorGroup(ObjectDescriptor, &psid, &defaulted))
1287 SetSecurityDescriptorGroup(&desc, psid, defaulted);
1290 if (SecurityInformation & DACL_SECURITY_INFORMATION)
1292 if (!GetSecurityDescriptorDacl(ObjectDescriptor, &present, &pacl, &defaulted))
1294 SetSecurityDescriptorDacl(&desc, present, pacl, defaulted);
1297 if (SecurityInformation & SACL_SECURITY_INFORMATION)
1299 if (!GetSecurityDescriptorSacl(ObjectDescriptor, &present, &pacl, &defaulted))
1301 SetSecurityDescriptorSacl(&desc, present, pacl, defaulted);
1304 *ReturnLength = DescriptorLength;
1305 return MakeSelfRelativeSD(&desc, ResultantDescriptor, ReturnLength);
1308 /******************************************************************************
1309 * GetSecurityDescriptorLength [ADVAPI32.@]
1311 DWORD WINAPI GetSecurityDescriptorLength( PSECURITY_DESCRIPTOR pDescr)
1313 return RtlLengthSecurityDescriptor(pDescr);
1316 /******************************************************************************
1317 * GetSecurityDescriptorOwner [ADVAPI32.@]
1321 * lpbOwnerDefaulted []
1324 GetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pDescr, PSID *pOwner,
1325 LPBOOL lpbOwnerDefaulted )
1328 BOOL ret = set_ntstatus( RtlGetOwnerSecurityDescriptor( pDescr, pOwner, &defaulted ));
1329 *lpbOwnerDefaulted = defaulted;
1333 /******************************************************************************
1334 * SetSecurityDescriptorOwner [ADVAPI32.@]
1338 BOOL WINAPI SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor,
1339 PSID pOwner, BOOL bOwnerDefaulted)
1341 return set_ntstatus( RtlSetOwnerSecurityDescriptor(pSecurityDescriptor, pOwner, bOwnerDefaulted));
1343 /******************************************************************************
1344 * GetSecurityDescriptorGroup [ADVAPI32.@]
1346 BOOL WINAPI GetSecurityDescriptorGroup(
1347 PSECURITY_DESCRIPTOR SecurityDescriptor,
1349 LPBOOL GroupDefaulted)
1352 BOOL ret = set_ntstatus( RtlGetGroupSecurityDescriptor(SecurityDescriptor, Group, &defaulted ));
1353 *GroupDefaulted = defaulted;
1356 /******************************************************************************
1357 * SetSecurityDescriptorGroup [ADVAPI32.@]
1359 BOOL WINAPI SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor,
1360 PSID Group, BOOL GroupDefaulted)
1362 return set_ntstatus( RtlSetGroupSecurityDescriptor( SecurityDescriptor, Group, GroupDefaulted));
1365 /******************************************************************************
1366 * IsValidSecurityDescriptor [ADVAPI32.@]
1372 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor )
1374 return set_ntstatus( RtlValidSecurityDescriptor(SecurityDescriptor));
1377 /******************************************************************************
1378 * GetSecurityDescriptorDacl [ADVAPI32.@]
1380 BOOL WINAPI GetSecurityDescriptorDacl(
1381 IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
1382 OUT LPBOOL lpbDaclPresent,
1384 OUT LPBOOL lpbDaclDefaulted)
1386 BOOLEAN present, defaulted;
1387 BOOL ret = set_ntstatus( RtlGetDaclSecurityDescriptor(pSecurityDescriptor, &present, pDacl, &defaulted));
1388 *lpbDaclPresent = present;
1389 *lpbDaclDefaulted = defaulted;
1393 /******************************************************************************
1394 * SetSecurityDescriptorDacl [ADVAPI32.@]
1397 SetSecurityDescriptorDacl (
1398 PSECURITY_DESCRIPTOR lpsd,
1401 BOOL dacldefaulted )
1403 return set_ntstatus( RtlSetDaclSecurityDescriptor (lpsd, daclpresent, dacl, dacldefaulted ) );
1405 /******************************************************************************
1406 * GetSecurityDescriptorSacl [ADVAPI32.@]
1408 BOOL WINAPI GetSecurityDescriptorSacl(
1409 IN PSECURITY_DESCRIPTOR lpsd,
1410 OUT LPBOOL lpbSaclPresent,
1412 OUT LPBOOL lpbSaclDefaulted)
1414 BOOLEAN present, defaulted;
1415 BOOL ret = set_ntstatus( RtlGetSaclSecurityDescriptor(lpsd, &present, pSacl, &defaulted) );
1416 *lpbSaclPresent = present;
1417 *lpbSaclDefaulted = defaulted;
1421 /**************************************************************************
1422 * SetSecurityDescriptorSacl [ADVAPI32.@]
1424 BOOL WINAPI SetSecurityDescriptorSacl (
1425 PSECURITY_DESCRIPTOR lpsd,
1430 return set_ntstatus (RtlSetSaclSecurityDescriptor(lpsd, saclpresent, lpsacl, sacldefaulted));
1432 /******************************************************************************
1433 * MakeSelfRelativeSD [ADVAPI32.@]
1442 IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
1443 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
1444 IN OUT LPDWORD lpdwBufferLength)
1446 return set_ntstatus( RtlMakeSelfRelativeSD( pAbsoluteSecurityDescriptor,
1447 pSelfRelativeSecurityDescriptor, lpdwBufferLength));
1450 /******************************************************************************
1451 * GetSecurityDescriptorControl [ADVAPI32.@]
1454 BOOL WINAPI GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR pSecurityDescriptor,
1455 PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision)
1457 return set_ntstatus( RtlGetControlSecurityDescriptor(pSecurityDescriptor,pControl,lpdwRevision));
1460 /******************************************************************************
1461 * SetSecurityDescriptorControl [ADVAPI32.@]
1463 BOOL WINAPI SetSecurityDescriptorControl( PSECURITY_DESCRIPTOR pSecurityDescriptor,
1464 SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
1465 SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet )
1467 return set_ntstatus( RtlSetControlSecurityDescriptor(
1468 pSecurityDescriptor, ControlBitsOfInterest, ControlBitsToSet ) );
1471 /* ##############################
1472 ###### ACL FUNCTIONS ######
1473 ##############################
1476 /*************************************************************************
1477 * InitializeAcl [ADVAPI32.@]
1479 BOOL WINAPI InitializeAcl(PACL acl, DWORD size, DWORD rev)
1481 return set_ntstatus( RtlCreateAcl(acl, size, rev));
1484 BOOL WINAPI ImpersonateNamedPipeClient( HANDLE hNamedPipe )
1486 IO_STATUS_BLOCK io_block;
1488 TRACE("(%p)\n", hNamedPipe);
1490 return set_ntstatus( NtFsControlFile(hNamedPipe, NULL, NULL, NULL,
1491 &io_block, FSCTL_PIPE_IMPERSONATE, NULL, 0, NULL, 0) );
1494 /******************************************************************************
1495 * AddAccessAllowedAce [ADVAPI32.@]
1497 BOOL WINAPI AddAccessAllowedAce(
1499 IN DWORD dwAceRevision,
1500 IN DWORD AccessMask,
1503 return set_ntstatus(RtlAddAccessAllowedAce(pAcl, dwAceRevision, AccessMask, pSid));
1506 /******************************************************************************
1507 * AddAccessAllowedAceEx [ADVAPI32.@]
1509 BOOL WINAPI AddAccessAllowedAceEx(
1511 IN DWORD dwAceRevision,
1513 IN DWORD AccessMask,
1516 return set_ntstatus(RtlAddAccessAllowedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
1519 /******************************************************************************
1520 * AddAccessDeniedAce [ADVAPI32.@]
1522 BOOL WINAPI AddAccessDeniedAce(
1524 IN DWORD dwAceRevision,
1525 IN DWORD AccessMask,
1528 return set_ntstatus(RtlAddAccessDeniedAce(pAcl, dwAceRevision, AccessMask, pSid));
1531 /******************************************************************************
1532 * AddAccessDeniedAceEx [ADVAPI32.@]
1534 BOOL WINAPI AddAccessDeniedAceEx(
1536 IN DWORD dwAceRevision,
1538 IN DWORD AccessMask,
1541 return set_ntstatus(RtlAddAccessDeniedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
1544 /******************************************************************************
1545 * AddAce [ADVAPI32.@]
1549 IN DWORD dwAceRevision,
1550 IN DWORD dwStartingAceIndex,
1552 DWORD nAceListLength)
1554 return set_ntstatus(RtlAddAce(pAcl, dwAceRevision, dwStartingAceIndex, pAceList, nAceListLength));
1557 /******************************************************************************
1558 * DeleteAce [ADVAPI32.@]
1560 BOOL WINAPI DeleteAce(PACL pAcl, DWORD dwAceIndex)
1562 return set_ntstatus(RtlDeleteAce(pAcl, dwAceIndex));
1565 /******************************************************************************
1566 * FindFirstFreeAce [ADVAPI32.@]
1568 BOOL WINAPI FindFirstFreeAce(IN PACL pAcl, LPVOID * pAce)
1570 return RtlFirstFreeAce(pAcl, (PACE_HEADER *)pAce);
1573 /******************************************************************************
1574 * GetAce [ADVAPI32.@]
1576 BOOL WINAPI GetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce )
1578 return set_ntstatus(RtlGetAce(pAcl, dwAceIndex, pAce));
1581 /******************************************************************************
1582 * GetAclInformation [ADVAPI32.@]
1584 BOOL WINAPI GetAclInformation(
1586 LPVOID pAclInformation,
1587 DWORD nAclInformationLength,
1588 ACL_INFORMATION_CLASS dwAclInformationClass)
1590 return set_ntstatus(RtlQueryInformationAcl(pAcl, pAclInformation,
1591 nAclInformationLength, dwAclInformationClass));
1594 /******************************************************************************
1595 * IsValidAcl [ADVAPI32.@]
1597 BOOL WINAPI IsValidAcl(IN PACL pAcl)
1599 return RtlValidAcl(pAcl);
1602 /* ##############################
1603 ###### MISC FUNCTIONS ######
1604 ##############################
1607 /******************************************************************************
1608 * AllocateLocallyUniqueId [ADVAPI32.@]
1613 BOOL WINAPI AllocateLocallyUniqueId( PLUID lpLuid )
1615 return set_ntstatus(NtAllocateLocallyUniqueId(lpLuid));
1618 static const WCHAR SE_CREATE_TOKEN_NAME_W[] =
1619 { 'S','e','C','r','e','a','t','e','T','o','k','e','n','P','r','i','v','i','l','e','g','e',0 };
1620 static const WCHAR SE_ASSIGNPRIMARYTOKEN_NAME_W[] =
1621 { '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 };
1622 static const WCHAR SE_LOCK_MEMORY_NAME_W[] =
1623 { 'S','e','L','o','c','k','M','e','m','o','r','y','P','r','i','v','i','l','e','g','e',0 };
1624 static const WCHAR SE_INCREASE_QUOTA_NAME_W[] =
1625 { '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 };
1626 static const WCHAR SE_MACHINE_ACCOUNT_NAME_W[] =
1627 { '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 };
1628 static const WCHAR SE_TCB_NAME_W[] =
1629 { 'S','e','T','c','b','P','r','i','v','i','l','e','g','e',0 };
1630 static const WCHAR SE_SECURITY_NAME_W[] =
1631 { 'S','e','S','e','c','u','r','i','t','y','P','r','i','v','i','l','e','g','e',0 };
1632 static const WCHAR SE_TAKE_OWNERSHIP_NAME_W[] =
1633 { '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 };
1634 static const WCHAR SE_LOAD_DRIVER_NAME_W[] =
1635 { 'S','e','L','o','a','d','D','r','i','v','e','r','P','r','i','v','i','l','e','g','e',0 };
1636 static const WCHAR SE_SYSTEM_PROFILE_NAME_W[] =
1637 { '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 };
1638 static const WCHAR SE_SYSTEMTIME_NAME_W[] =
1639 { 'S','e','S','y','s','t','e','m','t','i','m','e','P','r','i','v','i','l','e','g','e',0 };
1640 static const WCHAR SE_PROF_SINGLE_PROCESS_NAME_W[] =
1641 { '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 };
1642 static const WCHAR SE_INC_BASE_PRIORITY_NAME_W[] =
1643 { '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 };
1644 static const WCHAR SE_CREATE_PAGEFILE_NAME_W[] =
1645 { '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 };
1646 static const WCHAR SE_CREATE_PERMANENT_NAME_W[] =
1647 { '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 };
1648 static const WCHAR SE_BACKUP_NAME_W[] =
1649 { 'S','e','B','a','c','k','u','p','P','r','i','v','i','l','e','g','e',0 };
1650 static const WCHAR SE_RESTORE_NAME_W[] =
1651 { 'S','e','R','e','s','t','o','r','e','P','r','i','v','i','l','e','g','e',0 };
1652 static const WCHAR SE_SHUTDOWN_NAME_W[] =
1653 { 'S','e','S','h','u','t','d','o','w','n','P','r','i','v','i','l','e','g','e',0 };
1654 static const WCHAR SE_DEBUG_NAME_W[] =
1655 { 'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0 };
1656 static const WCHAR SE_AUDIT_NAME_W[] =
1657 { 'S','e','A','u','d','i','t','P','r','i','v','i','l','e','g','e',0 };
1658 static const WCHAR SE_SYSTEM_ENVIRONMENT_NAME_W[] =
1659 { '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 };
1660 static const WCHAR SE_CHANGE_NOTIFY_NAME_W[] =
1661 { 'S','e','C','h','a','n','g','e','N','o','t','i','f','y','P','r','i','v','i','l','e','g','e',0 };
1662 static const WCHAR SE_REMOTE_SHUTDOWN_NAME_W[] =
1663 { '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 };
1664 static const WCHAR SE_UNDOCK_NAME_W[] =
1665 { 'S','e','U','n','d','o','c','k','P','r','i','v','i','l','e','g','e',0 };
1666 static const WCHAR SE_SYNC_AGENT_NAME_W[] =
1667 { 'S','e','S','y','n','c','A','g','e','n','t','P','r','i','v','i','l','e','g','e',0 };
1668 static const WCHAR SE_ENABLE_DELEGATION_NAME_W[] =
1669 { '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 };
1670 static const WCHAR SE_MANAGE_VOLUME_NAME_W[] =
1671 { 'S','e','M','a','n','a','g','e','V','o','l','u','m','e','P','r','i','v','i','l','e','g','e',0 };
1672 static const WCHAR SE_IMPERSONATE_NAME_W[] =
1673 { 'S','e','I','m','p','e','r','s','o','n','a','t','e','P','r','i','v','i','l','e','g','e',0 };
1674 static const WCHAR SE_CREATE_GLOBAL_NAME_W[] =
1675 { 'S','e','C','r','e','a','t','e','G','l','o','b','a','l','P','r','i','v','i','l','e','g','e',0 };
1677 static const WCHAR * const WellKnownPrivNames[SE_MAX_WELL_KNOWN_PRIVILEGE + 1] =
1681 SE_CREATE_TOKEN_NAME_W,
1682 SE_ASSIGNPRIMARYTOKEN_NAME_W,
1683 SE_LOCK_MEMORY_NAME_W,
1684 SE_INCREASE_QUOTA_NAME_W,
1685 SE_MACHINE_ACCOUNT_NAME_W,
1688 SE_TAKE_OWNERSHIP_NAME_W,
1689 SE_LOAD_DRIVER_NAME_W,
1690 SE_SYSTEM_PROFILE_NAME_W,
1691 SE_SYSTEMTIME_NAME_W,
1692 SE_PROF_SINGLE_PROCESS_NAME_W,
1693 SE_INC_BASE_PRIORITY_NAME_W,
1694 SE_CREATE_PAGEFILE_NAME_W,
1695 SE_CREATE_PERMANENT_NAME_W,
1701 SE_SYSTEM_ENVIRONMENT_NAME_W,
1702 SE_CHANGE_NOTIFY_NAME_W,
1703 SE_REMOTE_SHUTDOWN_NAME_W,
1705 SE_SYNC_AGENT_NAME_W,
1706 SE_ENABLE_DELEGATION_NAME_W,
1707 SE_MANAGE_VOLUME_NAME_W,
1708 SE_IMPERSONATE_NAME_W,
1709 SE_CREATE_GLOBAL_NAME_W,
1712 /******************************************************************************
1713 * LookupPrivilegeValueW [ADVAPI32.@]
1715 * See LookupPrivilegeValueA.
1718 LookupPrivilegeValueW( LPCWSTR lpSystemName, LPCWSTR lpName, PLUID lpLuid )
1722 TRACE("%s,%s,%p\n",debugstr_w(lpSystemName), debugstr_w(lpName), lpLuid);
1724 if (!ADVAPI_IsLocalComputer(lpSystemName))
1726 SetLastError(RPC_S_SERVER_UNAVAILABLE);
1731 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1734 for( i=SE_MIN_WELL_KNOWN_PRIVILEGE; i<=SE_MAX_WELL_KNOWN_PRIVILEGE; i++ )
1736 if( !WellKnownPrivNames[i] )
1738 if( strcmpiW( WellKnownPrivNames[i], lpName) )
1740 lpLuid->LowPart = i;
1741 lpLuid->HighPart = 0;
1742 TRACE( "%s -> %08x-%08x\n",debugstr_w( lpSystemName ),
1743 lpLuid->HighPart, lpLuid->LowPart );
1746 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1750 /******************************************************************************
1751 * LookupPrivilegeValueA [ADVAPI32.@]
1753 * Retrieves LUID used on a system to represent the privilege name.
1756 * lpSystemName [I] Name of the system
1757 * lpName [I] Name of the privilege
1758 * lpLuid [O] Destination for the resulting LUID
1761 * Success: TRUE. lpLuid contains the requested LUID.
1765 LookupPrivilegeValueA( LPCSTR lpSystemName, LPCSTR lpName, PLUID lpLuid )
1767 UNICODE_STRING lpSystemNameW;
1768 UNICODE_STRING lpNameW;
1771 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
1772 RtlCreateUnicodeStringFromAsciiz(&lpNameW,lpName);
1773 ret = LookupPrivilegeValueW(lpSystemNameW.Buffer, lpNameW.Buffer, lpLuid);
1774 RtlFreeUnicodeString(&lpNameW);
1775 RtlFreeUnicodeString(&lpSystemNameW);
1779 BOOL WINAPI LookupPrivilegeDisplayNameA( LPCSTR lpSystemName, LPCSTR lpName, LPSTR lpDisplayName,
1780 LPDWORD cchDisplayName, LPDWORD lpLanguageId )
1782 FIXME("%s %s %s %p %p - stub\n", debugstr_a(lpSystemName), debugstr_a(lpName),
1783 debugstr_a(lpDisplayName), cchDisplayName, lpLanguageId);
1788 BOOL WINAPI LookupPrivilegeDisplayNameW( LPCWSTR lpSystemName, LPCWSTR lpName, LPWSTR lpDisplayName,
1789 LPDWORD cchDisplayName, LPDWORD lpLanguageId )
1791 FIXME("%s %s %s %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpName),
1792 debugstr_w(lpDisplayName), cchDisplayName, lpLanguageId);
1797 /******************************************************************************
1798 * LookupPrivilegeNameA [ADVAPI32.@]
1800 * See LookupPrivilegeNameW.
1803 LookupPrivilegeNameA( LPCSTR lpSystemName, PLUID lpLuid, LPSTR lpName,
1806 UNICODE_STRING lpSystemNameW;
1810 TRACE("%s %p %p %p\n", debugstr_a(lpSystemName), lpLuid, lpName, cchName);
1812 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
1813 ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, NULL, &wLen);
1814 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1816 LPWSTR lpNameW = HeapAlloc(GetProcessHeap(), 0, wLen * sizeof(WCHAR));
1818 ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, lpNameW,
1822 /* Windows crashes if cchName is NULL, so will I */
1823 unsigned int len = WideCharToMultiByte(CP_ACP, 0, lpNameW, -1, lpName,
1824 *cchName, NULL, NULL);
1828 /* WideCharToMultiByte failed */
1831 else if (len > *cchName)
1834 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1839 /* WideCharToMultiByte succeeded, output length needs to be
1840 * length not including NULL terminator
1845 HeapFree(GetProcessHeap(), 0, lpNameW);
1847 RtlFreeUnicodeString(&lpSystemNameW);
1851 /******************************************************************************
1852 * LookupPrivilegeNameW [ADVAPI32.@]
1854 * Retrieves the privilege name referred to by the LUID lpLuid.
1857 * lpSystemName [I] Name of the system
1858 * lpLuid [I] Privilege value
1859 * lpName [O] Name of the privilege
1860 * cchName [I/O] Number of characters in lpName.
1863 * Success: TRUE. lpName contains the name of the privilege whose value is
1868 * Only well-known privilege names (those defined in winnt.h) can be retrieved
1869 * using this function.
1870 * If the length of lpName is too small, on return *cchName will contain the
1871 * number of WCHARs needed to contain the privilege, including the NULL
1872 * terminator, and GetLastError will return ERROR_INSUFFICIENT_BUFFER.
1873 * On success, *cchName will contain the number of characters stored in
1874 * lpName, NOT including the NULL terminator.
1877 LookupPrivilegeNameW( LPCWSTR lpSystemName, PLUID lpLuid, LPWSTR lpName,
1882 TRACE("%s,%p,%p,%p\n",debugstr_w(lpSystemName), lpLuid, lpName, cchName);
1884 if (!ADVAPI_IsLocalComputer(lpSystemName))
1886 SetLastError(RPC_S_SERVER_UNAVAILABLE);
1889 if (lpLuid->HighPart || (lpLuid->LowPart < SE_MIN_WELL_KNOWN_PRIVILEGE ||
1890 lpLuid->LowPart > SE_MAX_WELL_KNOWN_PRIVILEGE))
1892 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1895 privNameLen = strlenW(WellKnownPrivNames[lpLuid->LowPart]);
1896 /* Windows crashes if cchName is NULL, so will I */
1897 if (*cchName <= privNameLen)
1899 *cchName = privNameLen + 1;
1900 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1905 strcpyW(lpName, WellKnownPrivNames[lpLuid->LowPart]);
1906 *cchName = privNameLen;
1911 /******************************************************************************
1912 * GetFileSecurityA [ADVAPI32.@]
1914 * Obtains Specified information about the security of a file or directory.
1917 * lpFileName [I] Name of the file to get info for
1918 * RequestedInformation [I] SE_ flags from "winnt.h"
1919 * pSecurityDescriptor [O] Destination for security information
1920 * nLength [I] Length of pSecurityDescriptor
1921 * lpnLengthNeeded [O] Destination for length of returned security information
1924 * Success: TRUE. pSecurityDescriptor contains the requested information.
1925 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
1928 * The information returned is constrained by the callers access rights and
1932 GetFileSecurityA( LPCSTR lpFileName,
1933 SECURITY_INFORMATION RequestedInformation,
1934 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1935 DWORD nLength, LPDWORD lpnLengthNeeded )
1940 name = SERV_dup(lpFileName);
1941 r = GetFileSecurityW( name, RequestedInformation, pSecurityDescriptor,
1942 nLength, lpnLengthNeeded );
1943 HeapFree( GetProcessHeap(), 0, name );
1948 /******************************************************************************
1949 * GetFileSecurityW [ADVAPI32.@]
1951 * See GetFileSecurityA.
1954 GetFileSecurityW( LPCWSTR lpFileName,
1955 SECURITY_INFORMATION RequestedInformation,
1956 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1957 DWORD nLength, LPDWORD lpnLengthNeeded )
1963 TRACE("(%s,%d,%p,%d,%p)\n", debugstr_w(lpFileName),
1964 RequestedInformation, pSecurityDescriptor,
1965 nLength, lpnLengthNeeded);
1967 if (RequestedInformation & (OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|
1968 DACL_SECURITY_INFORMATION))
1969 access |= READ_CONTROL;
1970 if (RequestedInformation & SACL_SECURITY_INFORMATION)
1971 access |= ACCESS_SYSTEM_SECURITY;
1973 hfile = CreateFileW( lpFileName, access, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
1974 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1975 if ( hfile == INVALID_HANDLE_VALUE )
1978 status = NtQuerySecurityObject( hfile, RequestedInformation, pSecurityDescriptor,
1979 nLength, lpnLengthNeeded );
1980 CloseHandle( hfile );
1981 return set_ntstatus( status );
1985 /******************************************************************************
1986 * LookupAccountSidA [ADVAPI32.@]
1993 IN OUT LPDWORD accountSize,
1995 IN OUT LPDWORD domainSize,
1996 OUT PSID_NAME_USE name_use )
2001 LPWSTR accountW = NULL;
2002 LPWSTR domainW = NULL;
2003 DWORD accountSizeW = *accountSize;
2004 DWORD domainSizeW = *domainSize;
2006 systemW = SERV_dup(system);
2008 accountW = HeapAlloc( GetProcessHeap(), 0, accountSizeW * sizeof(WCHAR) );
2010 domainW = HeapAlloc( GetProcessHeap(), 0, domainSizeW * sizeof(WCHAR) );
2012 r = LookupAccountSidW( systemW, sid, accountW, &accountSizeW, domainW, &domainSizeW, name_use );
2015 if (accountW && *accountSize) {
2016 len = WideCharToMultiByte( CP_ACP, 0, accountW, -1, NULL, 0, NULL, NULL );
2017 WideCharToMultiByte( CP_ACP, 0, accountW, -1, account, len, NULL, NULL );
2020 *accountSize = accountSizeW + 1;
2022 if (domainW && *domainSize) {
2023 len = WideCharToMultiByte( CP_ACP, 0, domainW, -1, NULL, 0, NULL, NULL );
2024 WideCharToMultiByte( CP_ACP, 0, domainW, -1, domain, len, NULL, NULL );
2027 *domainSize = domainSizeW + 1;
2031 *accountSize = accountSizeW + 1;
2032 *domainSize = domainSizeW + 1;
2035 HeapFree( GetProcessHeap(), 0, systemW );
2036 HeapFree( GetProcessHeap(), 0, accountW );
2037 HeapFree( GetProcessHeap(), 0, domainW );
2042 /******************************************************************************
2043 * LookupAccountSidW [ADVAPI32.@]
2060 IN OUT LPDWORD accountSize,
2062 IN OUT LPDWORD domainSize,
2063 OUT PSID_NAME_USE name_use )
2066 const WCHAR * ac = NULL;
2067 const WCHAR * dm = NULL;
2068 SID_NAME_USE use = 0;
2069 LPWSTR computer_name = NULL;
2070 LPWSTR account_name = NULL;
2072 TRACE("(%s,sid=%s,%p,%p(%u),%p,%p(%u),%p)\n",
2073 debugstr_w(system),debugstr_sid(sid),
2074 account,accountSize,accountSize?*accountSize:0,
2075 domain,domainSize,domainSize?*domainSize:0,
2078 if (!ADVAPI_IsLocalComputer(system)) {
2079 FIXME("Only local computer supported!\n");
2080 SetLastError(RPC_S_SERVER_UNAVAILABLE);
2084 /* check the well known SIDs first */
2085 for (i = 0; i <= 60; i++) {
2086 if (IsWellKnownSid(sid, i)) {
2087 for (j = 0; j < (sizeof(ACCOUNT_SIDS) / sizeof(ACCOUNT_SIDS[0])); j++) {
2088 if (ACCOUNT_SIDS[j].type == i) {
2089 ac = ACCOUNT_SIDS[j].account;
2090 dm = ACCOUNT_SIDS[j].domain;
2091 use = ACCOUNT_SIDS[j].name_use;
2101 /* check for the local computer next */
2102 if (ADVAPI_GetComputerSid(&local)) {
2103 DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
2106 computer_name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
2107 result = GetComputerNameW(computer_name, &size);
2110 if (EqualSid(sid, &local)) {
2115 local.SubAuthorityCount++;
2117 if (EqualPrefixSid(sid, &local)) {
2120 switch (((MAX_SID *)sid)->SubAuthority[4]) {
2121 case DOMAIN_USER_RID_ADMIN:
2124 case DOMAIN_USER_RID_GUEST:
2127 case DOMAIN_GROUP_RID_ADMINS:
2130 case DOMAIN_GROUP_RID_USERS:
2133 case DOMAIN_GROUP_RID_GUESTS:
2136 case DOMAIN_GROUP_RID_COMPUTERS:
2137 ac = Domain_Computers;
2139 case DOMAIN_GROUP_RID_CONTROLLERS:
2140 ac = Domain_Controllers;
2142 case DOMAIN_GROUP_RID_CERT_ADMINS:
2143 ac = Cert_Publishers;
2145 case DOMAIN_GROUP_RID_SCHEMA_ADMINS:
2148 case DOMAIN_GROUP_RID_ENTERPRISE_ADMINS:
2149 ac = Enterprise_Admins;
2151 case DOMAIN_GROUP_RID_POLICY_ADMINS:
2152 ac = Group_Policy_Creator_Owners;
2154 case DOMAIN_ALIAS_RID_RAS_SERVERS:
2155 ac = RAS_and_IAS_Servers;
2157 case 1000: /* first user account */
2159 account_name = HeapAlloc(
2160 GetProcessHeap(), 0, size * sizeof(WCHAR));
2161 if (GetUserNameW(account_name, &size))
2178 DWORD ac_len = lstrlenW(ac);
2179 DWORD dm_len = lstrlenW(dm);
2182 if (*accountSize > ac_len) {
2184 lstrcpyW(account, ac);
2186 if (*domainSize > dm_len) {
2188 lstrcpyW(domain, dm);
2190 if ((*accountSize && *accountSize < ac_len) ||
2191 (!account && !*accountSize && ac_len) ||
2192 (*domainSize && *domainSize < dm_len) ||
2193 (!domain && !*domainSize && dm_len))
2195 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2199 *domainSize = dm_len;
2201 *domainSize = dm_len + 1;
2203 *accountSize = ac_len;
2205 *accountSize = ac_len + 1;
2207 HeapFree(GetProcessHeap(), 0, account_name);
2208 HeapFree(GetProcessHeap(), 0, computer_name);
2209 if (status) *name_use = use;
2213 HeapFree(GetProcessHeap(), 0, account_name);
2214 HeapFree(GetProcessHeap(), 0, computer_name);
2215 SetLastError(ERROR_NONE_MAPPED);
2219 /******************************************************************************
2220 * SetFileSecurityA [ADVAPI32.@]
2222 * See SetFileSecurityW.
2224 BOOL WINAPI SetFileSecurityA( LPCSTR lpFileName,
2225 SECURITY_INFORMATION RequestedInformation,
2226 PSECURITY_DESCRIPTOR pSecurityDescriptor)
2231 name = SERV_dup(lpFileName);
2232 r = SetFileSecurityW( name, RequestedInformation, pSecurityDescriptor );
2233 HeapFree( GetProcessHeap(), 0, name );
2238 /******************************************************************************
2239 * SetFileSecurityW [ADVAPI32.@]
2241 * Sets the security of a file or directory.
2245 * RequestedInformation []
2246 * pSecurityDescriptor []
2253 SetFileSecurityW( LPCWSTR lpFileName,
2254 SECURITY_INFORMATION RequestedInformation,
2255 PSECURITY_DESCRIPTOR pSecurityDescriptor )
2261 TRACE("(%s, 0x%x, %p)\n", debugstr_w(lpFileName), RequestedInformation,
2262 pSecurityDescriptor );
2264 if (RequestedInformation & OWNER_SECURITY_INFORMATION ||
2265 RequestedInformation & GROUP_SECURITY_INFORMATION)
2266 access |= WRITE_OWNER;
2267 if (RequestedInformation & SACL_SECURITY_INFORMATION)
2268 access |= ACCESS_SYSTEM_SECURITY;
2269 if (RequestedInformation & DACL_SECURITY_INFORMATION)
2270 access |= WRITE_DAC;
2272 file = CreateFileW( lpFileName, access, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2273 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
2274 if (file == INVALID_HANDLE_VALUE)
2277 status = NtSetSecurityObject( file, RequestedInformation, pSecurityDescriptor );
2278 CloseHandle( file );
2279 return set_ntstatus( status );
2282 /******************************************************************************
2283 * QueryWindows31FilesMigration [ADVAPI32.@]
2289 QueryWindows31FilesMigration( DWORD x1 )
2291 FIXME("(%d):stub\n",x1);
2295 /******************************************************************************
2296 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
2305 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
2308 FIXME("(0x%08x,0x%08x,0x%08x,0x%08x):stub\n",x1,x2,x3,x4);
2312 /******************************************************************************
2313 * NotifyBootConfigStatus [ADVAPI32.@]
2319 NotifyBootConfigStatus( BOOL x1 )
2321 FIXME("(0x%08d):stub\n",x1);
2325 /******************************************************************************
2326 * RevertToSelf [ADVAPI32.@]
2328 * Ends the impersonation of a user.
2338 RevertToSelf( void )
2340 HANDLE Token = NULL;
2341 return set_ntstatus( NtSetInformationThread( GetCurrentThread(),
2342 ThreadImpersonationToken, &Token, sizeof(Token) ) );
2345 /******************************************************************************
2346 * ImpersonateSelf [ADVAPI32.@]
2348 * Makes an impersonation token that represents the process user and assigns
2349 * to the current thread.
2352 * ImpersonationLevel [I] Level at which to impersonate.
2359 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
2361 return set_ntstatus( RtlImpersonateSelf( ImpersonationLevel ) );
2364 /******************************************************************************
2365 * ImpersonateLoggedOnUser [ADVAPI32.@]
2367 BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
2371 HANDLE ImpersonationToken;
2373 static BOOL warn = TRUE;
2377 FIXME( "(%p)\n", hToken );
2380 if (!GetTokenInformation( hToken, TokenType, &Type,
2381 sizeof(TOKEN_TYPE), &size ))
2384 if (Type == TokenPrimary)
2386 OBJECT_ATTRIBUTES ObjectAttributes;
2388 InitializeObjectAttributes( &ObjectAttributes, NULL, 0, NULL, NULL );
2390 Status = NtDuplicateToken( hToken,
2391 TOKEN_IMPERSONATE | TOKEN_QUERY,
2393 SecurityImpersonation,
2395 &ImpersonationToken );
2396 if (Status != STATUS_SUCCESS)
2398 ERR( "NtDuplicateToken failed with error 0x%08x\n", Status );
2399 SetLastError( RtlNtStatusToDosError( Status ) );
2404 ImpersonationToken = hToken;
2406 Status = NtSetInformationThread( GetCurrentThread(),
2407 ThreadImpersonationToken,
2408 &ImpersonationToken,
2409 sizeof(ImpersonationToken) );
2411 if (Type == TokenPrimary)
2412 NtClose( ImpersonationToken );
2414 if (Status != STATUS_SUCCESS)
2416 ERR( "NtSetInformationThread failed with error 0x%08x\n", Status );
2417 SetLastError( RtlNtStatusToDosError( Status ) );
2424 /******************************************************************************
2425 * AccessCheck [ADVAPI32.@]
2429 PSECURITY_DESCRIPTOR SecurityDescriptor,
2431 DWORD DesiredAccess,
2432 PGENERIC_MAPPING GenericMapping,
2433 PPRIVILEGE_SET PrivilegeSet,
2434 LPDWORD PrivilegeSetLength,
2435 LPDWORD GrantedAccess,
2436 LPBOOL AccessStatus)
2438 NTSTATUS access_status;
2439 BOOL ret = set_ntstatus( NtAccessCheck(SecurityDescriptor, ClientToken, DesiredAccess,
2440 GenericMapping, PrivilegeSet, PrivilegeSetLength,
2441 GrantedAccess, &access_status) );
2442 if (ret) *AccessStatus = set_ntstatus( access_status );
2447 /******************************************************************************
2448 * AccessCheckByType [ADVAPI32.@]
2450 BOOL WINAPI AccessCheckByType(
2451 PSECURITY_DESCRIPTOR pSecurityDescriptor,
2452 PSID PrincipalSelfSid,
2454 DWORD DesiredAccess,
2455 POBJECT_TYPE_LIST ObjectTypeList,
2456 DWORD ObjectTypeListLength,
2457 PGENERIC_MAPPING GenericMapping,
2458 PPRIVILEGE_SET PrivilegeSet,
2459 LPDWORD PrivilegeSetLength,
2460 LPDWORD GrantedAccess,
2461 LPBOOL AccessStatus)
2465 *AccessStatus = TRUE;
2467 return !*AccessStatus;
2470 /******************************************************************************
2471 * MapGenericMask [ADVAPI32.@]
2473 * Maps generic access rights into specific access rights according to the
2477 * AccessMask [I/O] Access rights.
2478 * GenericMapping [I] The mapping between generic and specific rights.
2483 VOID WINAPI MapGenericMask( PDWORD AccessMask, PGENERIC_MAPPING GenericMapping )
2485 RtlMapGenericMask( AccessMask, GenericMapping );
2488 /*************************************************************************
2489 * SetKernelObjectSecurity [ADVAPI32.@]
2491 BOOL WINAPI SetKernelObjectSecurity (
2493 IN SECURITY_INFORMATION SecurityInformation,
2494 IN PSECURITY_DESCRIPTOR SecurityDescriptor )
2496 return set_ntstatus (NtSetSecurityObject (Handle, SecurityInformation, SecurityDescriptor));
2500 /******************************************************************************
2501 * AddAuditAccessAce [ADVAPI32.@]
2503 BOOL WINAPI AddAuditAccessAce(
2505 IN DWORD dwAceRevision,
2506 IN DWORD dwAccessMask,
2508 IN BOOL bAuditSuccess,
2509 IN BOOL bAuditFailure)
2511 return set_ntstatus( RtlAddAuditAccessAce(pAcl, dwAceRevision, dwAccessMask, pSid,
2512 bAuditSuccess, bAuditFailure) );
2515 /******************************************************************************
2516 * AddAuditAccessAce [ADVAPI32.@]
2518 BOOL WINAPI AddAuditAccessAceEx(
2520 IN DWORD dwAceRevision,
2521 IN DWORD dwAceFlags,
2522 IN DWORD dwAccessMask,
2524 IN BOOL bAuditSuccess,
2525 IN BOOL bAuditFailure)
2527 return set_ntstatus( RtlAddAuditAccessAceEx(pAcl, dwAceRevision, dwAceFlags, dwAccessMask, pSid,
2528 bAuditSuccess, bAuditFailure) );
2531 /******************************************************************************
2532 * LookupAccountNameA [ADVAPI32.@]
2540 LPSTR ReferencedDomainName,
2541 IN OUT LPDWORD cbReferencedDomainName,
2542 OUT PSID_NAME_USE name_use )
2545 UNICODE_STRING lpSystemW;
2546 UNICODE_STRING lpAccountW;
2547 LPWSTR lpReferencedDomainNameW = NULL;
2549 RtlCreateUnicodeStringFromAsciiz(&lpSystemW, system);
2550 RtlCreateUnicodeStringFromAsciiz(&lpAccountW, account);
2552 if (ReferencedDomainName)
2553 lpReferencedDomainNameW = HeapAlloc(GetProcessHeap(), 0, *cbReferencedDomainName * sizeof(WCHAR));
2555 ret = LookupAccountNameW(lpSystemW.Buffer, lpAccountW.Buffer, sid, cbSid, lpReferencedDomainNameW,
2556 cbReferencedDomainName, name_use);
2558 if (ret && lpReferencedDomainNameW)
2560 WideCharToMultiByte(CP_ACP, 0, lpReferencedDomainNameW, -1,
2561 ReferencedDomainName, *cbReferencedDomainName+1, NULL, NULL);
2564 RtlFreeUnicodeString(&lpSystemW);
2565 RtlFreeUnicodeString(&lpAccountW);
2566 HeapFree(GetProcessHeap(), 0, lpReferencedDomainNameW);
2571 /******************************************************************************
2572 * lookup_user_account_name
2574 static BOOL lookup_user_account_name(PSID Sid, PDWORD cbSid, LPWSTR ReferencedDomainName,
2575 LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse )
2577 char buffer[sizeof(TOKEN_USER) + sizeof(SID) + sizeof(DWORD)*SID_MAX_SUB_AUTHORITIES];
2578 DWORD len = sizeof(buffer);
2582 WCHAR domainName[MAX_COMPUTERNAME_LENGTH + 1];
2585 if (!OpenThreadToken(GetCurrentThread(), TOKEN_READ, TRUE, &token))
2587 if (GetLastError() != ERROR_NO_TOKEN) return FALSE;
2588 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token)) return FALSE;
2591 ret = GetTokenInformation(token, TokenUser, buffer, len, &len);
2592 CloseHandle( token );
2594 if (!ret) return FALSE;
2596 pSid = ((TOKEN_USER *)buffer)->User.Sid;
2598 if (Sid != NULL && (*cbSid >= GetLengthSid(pSid)))
2599 CopySid(*cbSid, Sid, pSid);
2600 if (*cbSid < GetLengthSid(pSid))
2602 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2605 *cbSid = GetLengthSid(pSid);
2607 nameLen = MAX_COMPUTERNAME_LENGTH + 1;
2608 if (!GetComputerNameW(domainName, &nameLen))
2613 if (*cchReferencedDomainName <= nameLen || !ret)
2615 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2619 else if (ReferencedDomainName)
2620 strcpyW(ReferencedDomainName, domainName);
2622 *cchReferencedDomainName = nameLen;
2625 *peUse = SidTypeUser;
2630 /******************************************************************************
2631 * lookup_computer_account_name
2633 static BOOL lookup_computer_account_name(PSID Sid, PDWORD cbSid, LPWSTR ReferencedDomainName,
2634 LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse )
2638 WCHAR domainName[MAX_COMPUTERNAME_LENGTH + 1];
2641 if ((ret = ADVAPI_GetComputerSid(&local)))
2643 if (Sid != NULL && (*cbSid >= GetLengthSid(&local)))
2644 CopySid(*cbSid, Sid, &local);
2645 if (*cbSid < GetLengthSid(&local))
2647 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2650 *cbSid = GetLengthSid(&local);
2653 nameLen = MAX_COMPUTERNAME_LENGTH + 1;
2654 if (!GetComputerNameW(domainName, &nameLen))
2659 if (*cchReferencedDomainName <= nameLen || !ret)
2661 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2665 else if (ReferencedDomainName)
2666 strcpyW(ReferencedDomainName, domainName);
2668 *cchReferencedDomainName = nameLen;
2671 *peUse = SidTypeDomain;
2676 static void split_domain_account( const LSA_UNICODE_STRING *str, LSA_UNICODE_STRING *account,
2677 LSA_UNICODE_STRING *domain )
2679 WCHAR *p = str->Buffer + str->Length / sizeof(WCHAR) - 1;
2681 while (p > str->Buffer && *p != '\\') p--;
2685 domain->Buffer = str->Buffer;
2686 domain->Length = (p - str->Buffer) * sizeof(WCHAR);
2688 account->Buffer = p + 1;
2689 account->Length = str->Length - ((p - str->Buffer + 1) * sizeof(WCHAR));
2693 domain->Buffer = NULL;
2696 account->Buffer = str->Buffer;
2697 account->Length = str->Length;
2701 static BOOL match_domain( ULONG idx, const LSA_UNICODE_STRING *domain )
2703 ULONG len = strlenW( ACCOUNT_SIDS[idx].domain );
2705 if (len == domain->Length / sizeof(WCHAR) && !strncmpiW( domain->Buffer, ACCOUNT_SIDS[idx].domain, len ))
2711 static BOOL match_account( ULONG idx, const LSA_UNICODE_STRING *account )
2713 ULONG len = strlenW( ACCOUNT_SIDS[idx].account );
2715 if (len == account->Length / sizeof(WCHAR) && !strncmpiW( account->Buffer, ACCOUNT_SIDS[idx].account, len ))
2718 if (ACCOUNT_SIDS[idx].alias)
2720 len = strlenW( ACCOUNT_SIDS[idx].alias );
2721 if (len == account->Length / sizeof(WCHAR) && !strncmpiW( account->Buffer, ACCOUNT_SIDS[idx].alias, len ))
2728 * Helper function for LookupAccountNameW
2730 BOOL lookup_local_wellknown_name( const LSA_UNICODE_STRING *account_and_domain,
2731 PSID Sid, LPDWORD cbSid,
2732 LPWSTR ReferencedDomainName,
2733 LPDWORD cchReferencedDomainName,
2734 PSID_NAME_USE peUse, BOOL *handled )
2737 LSA_UNICODE_STRING account, domain;
2742 split_domain_account( account_and_domain, &account, &domain );
2744 for (i = 0; i < sizeof(ACCOUNT_SIDS) / sizeof(ACCOUNT_SIDS[0]); i++)
2746 /* check domain first */
2747 if (domain.Buffer && !match_domain( i, &domain )) continue;
2749 if (match_account( i, &account ))
2751 DWORD len, sidLen = SECURITY_MAX_SID_SIZE;
2753 if (!(pSid = HeapAlloc( GetProcessHeap(), 0, sidLen ))) return FALSE;
2755 if ((ret = CreateWellKnownSid( ACCOUNT_SIDS[i].type, NULL, pSid, &sidLen )))
2757 if (*cbSid < sidLen)
2759 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2764 CopySid(*cbSid, Sid, pSid);
2769 len = strlenW( ACCOUNT_SIDS[i].domain );
2770 if (*cchReferencedDomainName <= len || !ret)
2772 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2776 else if (ReferencedDomainName)
2778 strcpyW( ReferencedDomainName, ACCOUNT_SIDS[i].domain );
2781 *cchReferencedDomainName = len;
2783 *peUse = ACCOUNT_SIDS[i].name_use;
2785 HeapFree(GetProcessHeap(), 0, pSid);
2793 BOOL lookup_local_user_name( const LSA_UNICODE_STRING *account_and_domain,
2794 PSID Sid, LPDWORD cbSid,
2795 LPWSTR ReferencedDomainName,
2796 LPDWORD cchReferencedDomainName,
2797 PSID_NAME_USE peUse, BOOL *handled )
2800 LPWSTR userName = NULL;
2801 LSA_UNICODE_STRING account, domain;
2805 split_domain_account( account_and_domain, &account, &domain );
2807 /* Let the current Unix user id masquerade as first Windows user account */
2809 nameLen = UNLEN + 1;
2810 if (!(userName = HeapAlloc( GetProcessHeap(), 0, nameLen * sizeof(WCHAR) ))) return FALSE;
2814 /* check to make sure this account is on this computer */
2815 if (GetComputerNameW( userName, &nameLen ) &&
2816 (domain.Length / sizeof(WCHAR) != nameLen || strncmpW( domain.Buffer, userName, nameLen )))
2818 SetLastError(ERROR_NONE_MAPPED);
2821 nameLen = UNLEN + 1;
2824 if (GetUserNameW( userName, &nameLen ) &&
2825 account.Length / sizeof(WCHAR) == nameLen - 1 && !strncmpW( account.Buffer, userName, nameLen - 1 ))
2827 ret = lookup_user_account_name( Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse );
2832 nameLen = UNLEN + 1;
2833 if (GetComputerNameW( userName, &nameLen ) &&
2834 account.Length / sizeof(WCHAR) == nameLen && !strncmpW( account.Buffer, userName , nameLen ))
2836 ret = lookup_computer_account_name( Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse );
2841 HeapFree(GetProcessHeap(), 0, userName);
2845 /******************************************************************************
2846 * LookupAccountNameW [ADVAPI32.@]
2848 BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSID Sid,
2849 LPDWORD cbSid, LPWSTR ReferencedDomainName,
2850 LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse )
2853 LSA_UNICODE_STRING account;
2855 TRACE("%s %s %p %p %p %p %p\n", debugstr_w(lpSystemName), debugstr_w(lpAccountName),
2856 Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse);
2858 if (!ADVAPI_IsLocalComputer( lpSystemName ))
2860 FIXME("remote computer not supported\n");
2861 SetLastError( RPC_S_SERVER_UNAVAILABLE );
2865 if (!lpAccountName || !strcmpW( lpAccountName, Blank ))
2867 lpAccountName = BUILTIN;
2870 RtlInitUnicodeString( &account, lpAccountName );
2872 /* Check well known SIDs first */
2873 ret = lookup_local_wellknown_name( &account, Sid, cbSid, ReferencedDomainName,
2874 cchReferencedDomainName, peUse, &handled );
2878 /* Check user names */
2879 ret = lookup_local_user_name( &account, Sid, cbSid, ReferencedDomainName,
2880 cchReferencedDomainName, peUse, &handled);
2884 SetLastError( ERROR_NONE_MAPPED );
2888 /******************************************************************************
2889 * PrivilegeCheck [ADVAPI32.@]
2891 BOOL WINAPI PrivilegeCheck( HANDLE ClientToken, PPRIVILEGE_SET RequiredPrivileges, LPBOOL pfResult)
2896 TRACE("%p %p %p\n", ClientToken, RequiredPrivileges, pfResult);
2898 ret = set_ntstatus (NtPrivilegeCheck (ClientToken, RequiredPrivileges, &Result));
2904 /******************************************************************************
2905 * AccessCheckAndAuditAlarmA [ADVAPI32.@]
2907 BOOL WINAPI AccessCheckAndAuditAlarmA(LPCSTR Subsystem, LPVOID HandleId, LPSTR ObjectTypeName,
2908 LPSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
2909 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
2910 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
2912 FIXME("stub (%s,%p,%s,%s,%p,%08x,%p,%x,%p,%p,%p)\n", debugstr_a(Subsystem),
2913 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName),
2914 SecurityDescriptor, DesiredAccess, GenericMapping,
2915 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
2919 /******************************************************************************
2920 * AccessCheckAndAuditAlarmW [ADVAPI32.@]
2922 BOOL WINAPI AccessCheckAndAuditAlarmW(LPCWSTR Subsystem, LPVOID HandleId, LPWSTR ObjectTypeName,
2923 LPWSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
2924 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
2925 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
2927 FIXME("stub (%s,%p,%s,%s,%p,%08x,%p,%x,%p,%p,%p)\n", debugstr_w(Subsystem),
2928 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName),
2929 SecurityDescriptor, DesiredAccess, GenericMapping,
2930 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
2934 BOOL WINAPI ObjectCloseAuditAlarmA(LPCSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
2936 FIXME("stub (%s,%p,%x)\n", debugstr_a(SubsystemName), HandleId, GenerateOnClose);
2941 BOOL WINAPI ObjectCloseAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
2943 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName), HandleId, GenerateOnClose);
2948 BOOL WINAPI ObjectDeleteAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
2950 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName), HandleId, GenerateOnClose);
2955 BOOL WINAPI ObjectOpenAuditAlarmA(LPCSTR SubsystemName, LPVOID HandleId, LPSTR ObjectTypeName,
2956 LPSTR ObjectName, PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE ClientToken, DWORD DesiredAccess,
2957 DWORD GrantedAccess, PPRIVILEGE_SET Privileges, BOOL ObjectCreation, BOOL AccessGranted,
2958 LPBOOL GenerateOnClose)
2960 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08x,0x%08x,%p,%x,%x,%p)\n", debugstr_a(SubsystemName),
2961 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName), pSecurityDescriptor,
2962 ClientToken, DesiredAccess, GrantedAccess, Privileges, ObjectCreation, AccessGranted,
2968 BOOL WINAPI ObjectOpenAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, LPWSTR ObjectTypeName,
2969 LPWSTR ObjectName, PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE ClientToken, DWORD DesiredAccess,
2970 DWORD GrantedAccess, PPRIVILEGE_SET Privileges, BOOL ObjectCreation, BOOL AccessGranted,
2971 LPBOOL GenerateOnClose)
2973 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08x,0x%08x,%p,%x,%x,%p)\n", debugstr_w(SubsystemName),
2974 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName), pSecurityDescriptor,
2975 ClientToken, DesiredAccess, GrantedAccess, Privileges, ObjectCreation, AccessGranted,
2981 BOOL WINAPI ObjectPrivilegeAuditAlarmA( LPCSTR SubsystemName, LPVOID HandleId, HANDLE ClientToken,
2982 DWORD DesiredAccess, PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2984 FIXME("stub (%s,%p,%p,0x%08x,%p,%x)\n", debugstr_a(SubsystemName), HandleId, ClientToken,
2985 DesiredAccess, Privileges, AccessGranted);
2990 BOOL WINAPI ObjectPrivilegeAuditAlarmW( LPCWSTR SubsystemName, LPVOID HandleId, HANDLE ClientToken,
2991 DWORD DesiredAccess, PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2993 FIXME("stub (%s,%p,%p,0x%08x,%p,%x)\n", debugstr_w(SubsystemName), HandleId, ClientToken,
2994 DesiredAccess, Privileges, AccessGranted);
2999 BOOL WINAPI PrivilegedServiceAuditAlarmA( LPCSTR SubsystemName, LPCSTR ServiceName, HANDLE ClientToken,
3000 PPRIVILEGE_SET Privileges, BOOL AccessGranted)
3002 FIXME("stub (%s,%s,%p,%p,%x)\n", debugstr_a(SubsystemName), debugstr_a(ServiceName),
3003 ClientToken, Privileges, AccessGranted);
3008 BOOL WINAPI PrivilegedServiceAuditAlarmW( LPCWSTR SubsystemName, LPCWSTR ServiceName, HANDLE ClientToken,
3009 PPRIVILEGE_SET Privileges, BOOL AccessGranted)
3011 FIXME("stub %s,%s,%p,%p,%x)\n", debugstr_w(SubsystemName), debugstr_w(ServiceName),
3012 ClientToken, Privileges, AccessGranted);
3017 /******************************************************************************
3018 * GetSecurityInfo [ADVAPI32.@]
3020 * Retrieves a copy of the security descriptor associated with an object.
3023 * hObject [I] A handle for the object.
3024 * ObjectType [I] The type of object.
3025 * SecurityInfo [I] A bitmask indicating what info to retrieve.
3026 * ppsidOwner [O] If non-null, receives a pointer to the owner SID.
3027 * ppsidGroup [O] If non-null, receives a pointer to the group SID.
3028 * ppDacl [O] If non-null, receives a pointer to the DACL.
3029 * ppSacl [O] If non-null, receives a pointer to the SACL.
3030 * ppSecurityDescriptor [O] Receives a pointer to the security descriptor,
3031 * which must be freed with LocalFree.
3034 * ERROR_SUCCESS if all's well, and a WIN32 error code otherwise.
3036 DWORD WINAPI GetSecurityInfo(
3037 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
3038 SECURITY_INFORMATION SecurityInfo, PSID *ppsidOwner,
3039 PSID *ppsidGroup, PACL *ppDacl, PACL *ppSacl,
3040 PSECURITY_DESCRIPTOR *ppSecurityDescriptor
3043 PSECURITY_DESCRIPTOR sd;
3046 BOOL present, defaulted;
3048 status = NtQuerySecurityObject(hObject, SecurityInfo, NULL, 0, &n1);
3049 if (status != STATUS_BUFFER_TOO_SMALL && status != STATUS_SUCCESS)
3050 return RtlNtStatusToDosError(status);
3052 sd = LocalAlloc(0, n1);
3054 return ERROR_NOT_ENOUGH_MEMORY;
3056 status = NtQuerySecurityObject(hObject, SecurityInfo, sd, n1, &n2);
3057 if (status != STATUS_SUCCESS)
3060 return RtlNtStatusToDosError(status);
3066 GetSecurityDescriptorOwner(sd, ppsidOwner, &defaulted);
3071 GetSecurityDescriptorGroup(sd, ppsidGroup, &defaulted);
3076 GetSecurityDescriptorDacl(sd, &present, ppDacl, &defaulted);
3081 GetSecurityDescriptorSacl(sd, &present, ppSacl, &defaulted);
3083 if (ppSecurityDescriptor)
3084 *ppSecurityDescriptor = sd;
3086 /* The security descriptor (sd) cannot be freed if ppSecurityDescriptor is
3087 * NULL, because native happily returns the SIDs and ACLs that are requested
3091 return ERROR_SUCCESS;
3094 /******************************************************************************
3095 * GetSecurityInfoExA [ADVAPI32.@]
3097 DWORD WINAPI GetSecurityInfoExA(
3098 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
3099 SECURITY_INFORMATION SecurityInfo, LPCSTR lpProvider,
3100 LPCSTR lpProperty, PACTRL_ACCESSA *ppAccessList,
3101 PACTRL_AUDITA *ppAuditList, LPSTR *lppOwner, LPSTR *lppGroup
3105 return ERROR_BAD_PROVIDER;
3108 /******************************************************************************
3109 * GetSecurityInfoExW [ADVAPI32.@]
3111 DWORD WINAPI GetSecurityInfoExW(
3112 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
3113 SECURITY_INFORMATION SecurityInfo, LPCWSTR lpProvider,
3114 LPCWSTR lpProperty, PACTRL_ACCESSW *ppAccessList,
3115 PACTRL_AUDITW *ppAuditList, LPWSTR *lppOwner, LPWSTR *lppGroup
3119 return ERROR_BAD_PROVIDER;
3122 /******************************************************************************
3123 * BuildExplicitAccessWithNameA [ADVAPI32.@]
3125 VOID WINAPI BuildExplicitAccessWithNameA( PEXPLICIT_ACCESSA pExplicitAccess,
3126 LPSTR pTrusteeName, DWORD AccessPermissions,
3127 ACCESS_MODE AccessMode, DWORD Inheritance )
3129 TRACE("%p %s 0x%08x 0x%08x 0x%08x\n", pExplicitAccess, debugstr_a(pTrusteeName),
3130 AccessPermissions, AccessMode, Inheritance);
3132 pExplicitAccess->grfAccessPermissions = AccessPermissions;
3133 pExplicitAccess->grfAccessMode = AccessMode;
3134 pExplicitAccess->grfInheritance = Inheritance;
3136 pExplicitAccess->Trustee.pMultipleTrustee = NULL;
3137 pExplicitAccess->Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
3138 pExplicitAccess->Trustee.TrusteeForm = TRUSTEE_IS_NAME;
3139 pExplicitAccess->Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
3140 pExplicitAccess->Trustee.ptstrName = pTrusteeName;
3143 /******************************************************************************
3144 * BuildExplicitAccessWithNameW [ADVAPI32.@]
3146 VOID WINAPI BuildExplicitAccessWithNameW( PEXPLICIT_ACCESSW pExplicitAccess,
3147 LPWSTR pTrusteeName, DWORD AccessPermissions,
3148 ACCESS_MODE AccessMode, DWORD Inheritance )
3150 TRACE("%p %s 0x%08x 0x%08x 0x%08x\n", pExplicitAccess, debugstr_w(pTrusteeName),
3151 AccessPermissions, AccessMode, Inheritance);
3153 pExplicitAccess->grfAccessPermissions = AccessPermissions;
3154 pExplicitAccess->grfAccessMode = AccessMode;
3155 pExplicitAccess->grfInheritance = Inheritance;
3157 pExplicitAccess->Trustee.pMultipleTrustee = NULL;
3158 pExplicitAccess->Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
3159 pExplicitAccess->Trustee.TrusteeForm = TRUSTEE_IS_NAME;
3160 pExplicitAccess->Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
3161 pExplicitAccess->Trustee.ptstrName = pTrusteeName;
3164 /******************************************************************************
3165 * BuildTrusteeWithObjectsAndNameA [ADVAPI32.@]
3167 VOID WINAPI BuildTrusteeWithObjectsAndNameA( PTRUSTEEA pTrustee, POBJECTS_AND_NAME_A pObjName,
3168 SE_OBJECT_TYPE ObjectType, LPSTR ObjectTypeName,
3169 LPSTR InheritedObjectTypeName, LPSTR Name )
3171 DWORD ObjectsPresent = 0;
3173 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee, pObjName,
3174 ObjectType, ObjectTypeName, InheritedObjectTypeName, debugstr_a(Name));
3176 /* Fill the OBJECTS_AND_NAME structure */
3177 pObjName->ObjectType = ObjectType;
3178 if (ObjectTypeName != NULL)
3180 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
3183 pObjName->InheritedObjectTypeName = InheritedObjectTypeName;
3184 if (InheritedObjectTypeName != NULL)
3186 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
3189 pObjName->ObjectsPresent = ObjectsPresent;
3190 pObjName->ptstrName = Name;
3192 /* Fill the TRUSTEE structure */
3193 pTrustee->pMultipleTrustee = NULL;
3194 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
3195 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME;
3196 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
3197 pTrustee->ptstrName = (LPSTR)pObjName;
3200 /******************************************************************************
3201 * BuildTrusteeWithObjectsAndNameW [ADVAPI32.@]
3203 VOID WINAPI BuildTrusteeWithObjectsAndNameW( PTRUSTEEW pTrustee, POBJECTS_AND_NAME_W pObjName,
3204 SE_OBJECT_TYPE ObjectType, LPWSTR ObjectTypeName,
3205 LPWSTR InheritedObjectTypeName, LPWSTR Name )
3207 DWORD ObjectsPresent = 0;
3209 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee, pObjName,
3210 ObjectType, ObjectTypeName, InheritedObjectTypeName, debugstr_w(Name));
3212 /* Fill the OBJECTS_AND_NAME structure */
3213 pObjName->ObjectType = ObjectType;
3214 if (ObjectTypeName != NULL)
3216 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
3219 pObjName->InheritedObjectTypeName = InheritedObjectTypeName;
3220 if (InheritedObjectTypeName != NULL)
3222 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
3225 pObjName->ObjectsPresent = ObjectsPresent;
3226 pObjName->ptstrName = Name;
3228 /* Fill the TRUSTEE structure */
3229 pTrustee->pMultipleTrustee = NULL;
3230 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
3231 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME;
3232 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
3233 pTrustee->ptstrName = (LPWSTR)pObjName;
3236 /******************************************************************************
3237 * BuildTrusteeWithObjectsAndSidA [ADVAPI32.@]
3239 VOID WINAPI BuildTrusteeWithObjectsAndSidA( PTRUSTEEA pTrustee, POBJECTS_AND_SID pObjSid,
3240 GUID* pObjectGuid, GUID* pInheritedObjectGuid, PSID pSid )
3242 DWORD ObjectsPresent = 0;
3244 TRACE("%p %p %p %p %p\n", pTrustee, pObjSid, pObjectGuid, pInheritedObjectGuid, pSid);
3246 /* Fill the OBJECTS_AND_SID structure */
3247 if (pObjectGuid != NULL)
3249 pObjSid->ObjectTypeGuid = *pObjectGuid;
3250 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
3254 ZeroMemory(&pObjSid->ObjectTypeGuid,
3258 if (pInheritedObjectGuid != NULL)
3260 pObjSid->InheritedObjectTypeGuid = *pInheritedObjectGuid;
3261 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
3265 ZeroMemory(&pObjSid->InheritedObjectTypeGuid,
3269 pObjSid->ObjectsPresent = ObjectsPresent;
3270 pObjSid->pSid = pSid;
3272 /* Fill the TRUSTEE structure */
3273 pTrustee->pMultipleTrustee = NULL;
3274 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
3275 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID;
3276 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
3277 pTrustee->ptstrName = (LPSTR) pObjSid;
3280 /******************************************************************************
3281 * BuildTrusteeWithObjectsAndSidW [ADVAPI32.@]
3283 VOID WINAPI BuildTrusteeWithObjectsAndSidW( PTRUSTEEW pTrustee, POBJECTS_AND_SID pObjSid,
3284 GUID* pObjectGuid, GUID* pInheritedObjectGuid, PSID pSid )
3286 DWORD ObjectsPresent = 0;
3288 TRACE("%p %p %p %p %p\n", pTrustee, pObjSid, pObjectGuid, pInheritedObjectGuid, pSid);
3290 /* Fill the OBJECTS_AND_SID structure */
3291 if (pObjectGuid != NULL)
3293 pObjSid->ObjectTypeGuid = *pObjectGuid;
3294 ObjectsPresent |= ACE_OBJECT_TYPE_PRESENT;
3298 ZeroMemory(&pObjSid->ObjectTypeGuid,
3302 if (pInheritedObjectGuid != NULL)
3304 pObjSid->InheritedObjectTypeGuid = *pInheritedObjectGuid;
3305 ObjectsPresent |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
3309 ZeroMemory(&pObjSid->InheritedObjectTypeGuid,
3313 pObjSid->ObjectsPresent = ObjectsPresent;
3314 pObjSid->pSid = pSid;
3316 /* Fill the TRUSTEE structure */
3317 pTrustee->pMultipleTrustee = NULL;
3318 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
3319 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID;
3320 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
3321 pTrustee->ptstrName = (LPWSTR) pObjSid;
3324 /******************************************************************************
3325 * BuildTrusteeWithSidA [ADVAPI32.@]
3327 VOID WINAPI BuildTrusteeWithSidA(PTRUSTEEA pTrustee, PSID pSid)
3329 TRACE("%p %p\n", pTrustee, pSid);
3331 pTrustee->pMultipleTrustee = NULL;
3332 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
3333 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
3334 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
3335 pTrustee->ptstrName = pSid;
3338 /******************************************************************************
3339 * BuildTrusteeWithSidW [ADVAPI32.@]
3341 VOID WINAPI BuildTrusteeWithSidW(PTRUSTEEW pTrustee, PSID pSid)
3343 TRACE("%p %p\n", pTrustee, pSid);
3345 pTrustee->pMultipleTrustee = NULL;
3346 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
3347 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
3348 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
3349 pTrustee->ptstrName = pSid;
3352 /******************************************************************************
3353 * BuildTrusteeWithNameA [ADVAPI32.@]
3355 VOID WINAPI BuildTrusteeWithNameA(PTRUSTEEA pTrustee, LPSTR name)
3357 TRACE("%p %s\n", pTrustee, debugstr_a(name) );
3359 pTrustee->pMultipleTrustee = NULL;
3360 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
3361 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
3362 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
3363 pTrustee->ptstrName = name;
3366 /******************************************************************************
3367 * BuildTrusteeWithNameW [ADVAPI32.@]
3369 VOID WINAPI BuildTrusteeWithNameW(PTRUSTEEW pTrustee, LPWSTR name)
3371 TRACE("%p %s\n", pTrustee, debugstr_w(name) );
3373 pTrustee->pMultipleTrustee = NULL;
3374 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
3375 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
3376 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
3377 pTrustee->ptstrName = name;
3380 /******************************************************************************
3381 * GetTrusteeFormA [ADVAPI32.@]
3383 TRUSTEE_FORM WINAPI GetTrusteeFormA(PTRUSTEEA pTrustee)
3385 TRACE("(%p)\n", pTrustee);
3388 return TRUSTEE_BAD_FORM;
3390 return pTrustee->TrusteeForm;
3393 /******************************************************************************
3394 * GetTrusteeFormW [ADVAPI32.@]
3396 TRUSTEE_FORM WINAPI GetTrusteeFormW(PTRUSTEEW pTrustee)
3398 TRACE("(%p)\n", pTrustee);
3401 return TRUSTEE_BAD_FORM;
3403 return pTrustee->TrusteeForm;
3406 /******************************************************************************
3407 * GetTrusteeNameA [ADVAPI32.@]
3409 LPSTR WINAPI GetTrusteeNameA(PTRUSTEEA pTrustee)
3411 TRACE("(%p)\n", pTrustee);
3416 return pTrustee->ptstrName;
3419 /******************************************************************************
3420 * GetTrusteeNameW [ADVAPI32.@]
3422 LPWSTR WINAPI GetTrusteeNameW(PTRUSTEEW pTrustee)
3424 TRACE("(%p)\n", pTrustee);
3429 return pTrustee->ptstrName;
3432 /******************************************************************************
3433 * GetTrusteeTypeA [ADVAPI32.@]
3435 TRUSTEE_TYPE WINAPI GetTrusteeTypeA(PTRUSTEEA pTrustee)
3437 TRACE("(%p)\n", pTrustee);
3440 return TRUSTEE_IS_UNKNOWN;
3442 return pTrustee->TrusteeType;
3445 /******************************************************************************
3446 * GetTrusteeTypeW [ADVAPI32.@]
3448 TRUSTEE_TYPE WINAPI GetTrusteeTypeW(PTRUSTEEW pTrustee)
3450 TRACE("(%p)\n", pTrustee);
3453 return TRUSTEE_IS_UNKNOWN;
3455 return pTrustee->TrusteeType;
3458 BOOL WINAPI SetAclInformation( PACL pAcl, LPVOID pAclInformation,
3459 DWORD nAclInformationLength,
3460 ACL_INFORMATION_CLASS dwAclInformationClass )
3462 FIXME("%p %p 0x%08x 0x%08x - stub\n", pAcl, pAclInformation,
3463 nAclInformationLength, dwAclInformationClass);
3468 static DWORD trustee_name_A_to_W(TRUSTEE_FORM form, char *trustee_nameA, WCHAR **ptrustee_nameW)
3472 case TRUSTEE_IS_NAME:
3474 *ptrustee_nameW = SERV_dup(trustee_nameA);
3475 return ERROR_SUCCESS;
3477 case TRUSTEE_IS_OBJECTS_AND_NAME:
3479 OBJECTS_AND_NAME_A *objA = (OBJECTS_AND_NAME_A *)trustee_nameA;
3480 OBJECTS_AND_NAME_W *objW = NULL;
3484 if (!(objW = HeapAlloc( GetProcessHeap(), 0, sizeof(OBJECTS_AND_NAME_W) )))
3485 return ERROR_NOT_ENOUGH_MEMORY;
3487 objW->ObjectsPresent = objA->ObjectsPresent;
3488 objW->ObjectType = objA->ObjectType;
3489 objW->ObjectTypeName = SERV_dup(objA->ObjectTypeName);
3490 objW->InheritedObjectTypeName = SERV_dup(objA->InheritedObjectTypeName);
3491 objW->ptstrName = SERV_dup(objA->ptstrName);
3494 *ptrustee_nameW = (WCHAR *)objW;
3495 return ERROR_SUCCESS;
3497 /* These forms do not require conversion. */
3498 case TRUSTEE_IS_SID:
3499 case TRUSTEE_IS_OBJECTS_AND_SID:
3500 *ptrustee_nameW = (WCHAR *)trustee_nameA;
3501 return ERROR_SUCCESS;
3503 return ERROR_INVALID_PARAMETER;
3507 static void free_trustee_name(TRUSTEE_FORM form, WCHAR *trustee_nameW)
3511 case TRUSTEE_IS_NAME:
3512 HeapFree( GetProcessHeap(), 0, trustee_nameW );
3514 case TRUSTEE_IS_OBJECTS_AND_NAME:
3516 OBJECTS_AND_NAME_W *objW = (OBJECTS_AND_NAME_W *)trustee_nameW;
3520 HeapFree( GetProcessHeap(), 0, objW->ptstrName );
3521 HeapFree( GetProcessHeap(), 0, objW->InheritedObjectTypeName );
3522 HeapFree( GetProcessHeap(), 0, objW->ObjectTypeName );
3523 HeapFree( GetProcessHeap(), 0, objW );
3528 /* Other forms did not require allocation, so no freeing is necessary. */
3534 /******************************************************************************
3535 * SetEntriesInAclA [ADVAPI32.@]
3537 DWORD WINAPI SetEntriesInAclA( ULONG count, PEXPLICIT_ACCESSA pEntries,
3538 PACL OldAcl, PACL* NewAcl )
3540 DWORD err = ERROR_SUCCESS;
3541 EXPLICIT_ACCESSW *pEntriesW;
3542 UINT alloc_index, free_index;
3544 TRACE("%d %p %p %p\n", count, pEntries, OldAcl, NewAcl);
3549 if (!count && !OldAcl)
3550 return ERROR_SUCCESS;
3552 pEntriesW = HeapAlloc( GetProcessHeap(), 0, count * sizeof(EXPLICIT_ACCESSW) );
3554 return ERROR_NOT_ENOUGH_MEMORY;
3556 for (alloc_index = 0; alloc_index < count; ++alloc_index)
3558 pEntriesW[alloc_index].grfAccessPermissions = pEntries[alloc_index].grfAccessPermissions;
3559 pEntriesW[alloc_index].grfAccessMode = pEntries[alloc_index].grfAccessMode;
3560 pEntriesW[alloc_index].grfInheritance = pEntries[alloc_index].grfInheritance;
3561 pEntriesW[alloc_index].Trustee.pMultipleTrustee = NULL; /* currently not supported */
3562 pEntriesW[alloc_index].Trustee.MultipleTrusteeOperation = pEntries[alloc_index].Trustee.MultipleTrusteeOperation;
3563 pEntriesW[alloc_index].Trustee.TrusteeForm = pEntries[alloc_index].Trustee.TrusteeForm;
3564 pEntriesW[alloc_index].Trustee.TrusteeType = pEntries[alloc_index].Trustee.TrusteeType;
3566 err = trustee_name_A_to_W( pEntries[alloc_index].Trustee.TrusteeForm,
3567 pEntries[alloc_index].Trustee.ptstrName,
3568 &pEntriesW[alloc_index].Trustee.ptstrName );
3569 if (err != ERROR_SUCCESS)
3571 if (err == ERROR_INVALID_PARAMETER)
3572 WARN("bad trustee form %d for trustee %d\n",
3573 pEntries[alloc_index].Trustee.TrusteeForm, alloc_index);
3579 err = SetEntriesInAclW( count, pEntriesW, OldAcl, NewAcl );
3582 /* Free any previously allocated trustee name buffers, taking into account
3583 * a possible out-of-memory condition while building the EXPLICIT_ACCESSW
3585 for (free_index = 0; free_index < alloc_index; ++free_index)
3586 free_trustee_name( pEntriesW[free_index].Trustee.TrusteeForm, pEntriesW[free_index].Trustee.ptstrName );
3588 HeapFree( GetProcessHeap(), 0, pEntriesW );
3592 /******************************************************************************
3593 * SetEntriesInAclW [ADVAPI32.@]
3595 DWORD WINAPI SetEntriesInAclW( ULONG count, PEXPLICIT_ACCESSW pEntries,
3596 PACL OldAcl, PACL* NewAcl )
3600 DWORD ret = ERROR_SUCCESS;
3601 DWORD acl_size = sizeof(ACL);
3604 TRACE("%d %p %p %p\n", count, pEntries, OldAcl, NewAcl);
3609 if (!count && !OldAcl)
3610 return ERROR_SUCCESS;
3612 /* allocate array of maximum sized sids allowed */
3613 ppsid = HeapAlloc(GetProcessHeap(), 0, count * (sizeof(SID *) + FIELD_OFFSET(SID, SubAuthority[SID_MAX_SUB_AUTHORITIES])));
3615 return ERROR_OUTOFMEMORY;
3617 for (i = 0; i < count; i++)
3619 ppsid[i] = (char *)&ppsid[count] + i * FIELD_OFFSET(SID, SubAuthority[SID_MAX_SUB_AUTHORITIES]);
3621 TRACE("[%d]:\n\tgrfAccessPermissions = 0x%x\n\tgrfAccessMode = %d\n\tgrfInheritance = 0x%x\n\t"
3622 "Trustee.pMultipleTrustee = %p\n\tMultipleTrusteeOperation = %d\n\tTrusteeForm = %d\n\t"
3623 "Trustee.TrusteeType = %d\n\tptstrName = %p\n", i,
3624 pEntries[i].grfAccessPermissions, pEntries[i].grfAccessMode, pEntries[i].grfInheritance,
3625 pEntries[i].Trustee.pMultipleTrustee, pEntries[i].Trustee.MultipleTrusteeOperation,
3626 pEntries[i].Trustee.TrusteeForm, pEntries[i].Trustee.TrusteeType,
3627 pEntries[i].Trustee.ptstrName);
3629 if (pEntries[i].Trustee.MultipleTrusteeOperation == TRUSTEE_IS_IMPERSONATE)
3631 WARN("bad multiple trustee operation %d for trustee %d\n", pEntries[i].Trustee.MultipleTrusteeOperation, i);
3632 ret = ERROR_INVALID_PARAMETER;
3636 switch (pEntries[i].Trustee.TrusteeForm)
3638 case TRUSTEE_IS_SID:
3639 if (!CopySid(FIELD_OFFSET(SID, SubAuthority[SID_MAX_SUB_AUTHORITIES]),
3640 ppsid[i], pEntries[i].Trustee.ptstrName))
3642 WARN("bad sid %p for trustee %d\n", pEntries[i].Trustee.ptstrName, i);
3643 ret = ERROR_INVALID_PARAMETER;
3647 case TRUSTEE_IS_NAME:
3649 DWORD sid_size = FIELD_OFFSET(SID, SubAuthority[SID_MAX_SUB_AUTHORITIES]);
3650 DWORD domain_size = MAX_COMPUTERNAME_LENGTH + 1;
3652 if (!strcmpW( pEntries[i].Trustee.ptstrName, CURRENT_USER ))
3654 if (!lookup_user_account_name( ppsid[i], &sid_size, NULL, &domain_size, &use ))
3656 ret = GetLastError();
3660 else if (!LookupAccountNameW(NULL, pEntries[i].Trustee.ptstrName, ppsid[i], &sid_size, NULL, &domain_size, &use))
3662 WARN("bad user name %s for trustee %d\n", debugstr_w(pEntries[i].Trustee.ptstrName), i);
3663 ret = ERROR_INVALID_PARAMETER;
3668 case TRUSTEE_IS_OBJECTS_AND_SID:
3669 FIXME("TRUSTEE_IS_OBJECTS_AND_SID unimplemented\n");
3671 case TRUSTEE_IS_OBJECTS_AND_NAME:
3672 FIXME("TRUSTEE_IS_OBJECTS_AND_NAME unimplemented\n");
3675 WARN("bad trustee form %d for trustee %d\n", pEntries[i].Trustee.TrusteeForm, i);
3676 ret = ERROR_INVALID_PARAMETER;
3680 /* Note: we overestimate the ACL size here as a tradeoff between
3681 * instructions (simplicity) and memory */
3682 switch (pEntries[i].grfAccessMode)
3686 acl_size += FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart) + GetLengthSid(ppsid[i]);
3689 acl_size += FIELD_OFFSET(ACCESS_DENIED_ACE, SidStart) + GetLengthSid(ppsid[i]);
3691 case SET_AUDIT_SUCCESS:
3692 case SET_AUDIT_FAILURE:
3693 acl_size += FIELD_OFFSET(SYSTEM_AUDIT_ACE, SidStart) + GetLengthSid(ppsid[i]);
3698 WARN("bad access mode %d for trustee %d\n", pEntries[i].grfAccessMode, i);
3699 ret = ERROR_INVALID_PARAMETER;
3706 ACL_SIZE_INFORMATION size_info;
3708 status = RtlQueryInformationAcl(OldAcl, &size_info, sizeof(size_info), AclSizeInformation);
3709 if (status != STATUS_SUCCESS)
3711 ret = RtlNtStatusToDosError(status);
3714 acl_size += size_info.AclBytesInUse - sizeof(ACL);
3717 *NewAcl = LocalAlloc(0, acl_size);
3720 ret = ERROR_OUTOFMEMORY;
3724 status = RtlCreateAcl( *NewAcl, acl_size, ACL_REVISION );
3725 if (status != STATUS_SUCCESS)
3727 ret = RtlNtStatusToDosError(status);
3731 for (i = 0; i < count; i++)
3733 switch (pEntries[i].grfAccessMode)
3736 status = RtlAddAccessAllowedAceEx(*NewAcl, ACL_REVISION,
3737 pEntries[i].grfInheritance,
3738 pEntries[i].grfAccessPermissions,
3749 const ACE_HEADER *existing_ace_header;
3750 status = RtlGetAce(OldAcl, j, (LPVOID *)&existing_ace_header);
3751 if (status != STATUS_SUCCESS)
3753 if (pEntries[i].grfAccessMode == SET_ACCESS &&
3754 existing_ace_header->AceType == ACCESS_ALLOWED_ACE_TYPE &&
3755 EqualSid(ppsid[i], &((ACCESS_ALLOWED_ACE *)existing_ace_header)->SidStart))
3763 status = RtlAddAccessAllowedAceEx(*NewAcl, ACL_REVISION,
3764 pEntries[i].grfInheritance,
3765 pEntries[i].grfAccessPermissions,
3770 status = RtlAddAccessDeniedAceEx(*NewAcl, ACL_REVISION,
3771 pEntries[i].grfInheritance,
3772 pEntries[i].grfAccessPermissions,
3775 case SET_AUDIT_SUCCESS:
3776 status = RtlAddAuditAccessAceEx(*NewAcl, ACL_REVISION,
3777 pEntries[i].grfInheritance,
3778 pEntries[i].grfAccessPermissions,
3779 ppsid[i], TRUE, FALSE);
3781 case SET_AUDIT_FAILURE:
3782 status = RtlAddAuditAccessAceEx(*NewAcl, ACL_REVISION,
3783 pEntries[i].grfInheritance,
3784 pEntries[i].grfAccessPermissions,
3785 ppsid[i], FALSE, TRUE);
3788 FIXME("unhandled access mode %d\n", pEntries[i].grfAccessMode);
3798 const ACE_HEADER *old_ace_header;
3799 status = RtlGetAce(OldAcl, i, (LPVOID *)&old_ace_header);
3800 if (status != STATUS_SUCCESS) break;
3801 for (j = 0; j < count; j++)
3803 if (pEntries[j].grfAccessMode == SET_ACCESS &&
3804 old_ace_header->AceType == ACCESS_ALLOWED_ACE_TYPE &&
3805 EqualSid(ppsid[j], &((ACCESS_ALLOWED_ACE *)old_ace_header)->SidStart))
3807 status = RtlAddAccessAllowedAceEx(*NewAcl, ACL_REVISION, pEntries[j].grfInheritance, pEntries[j].grfAccessPermissions, ppsid[j]);
3811 else if (pEntries[j].grfAccessMode == REVOKE_ACCESS)
3813 switch (old_ace_header->AceType)
3815 case ACCESS_ALLOWED_ACE_TYPE:
3816 if (EqualSid(ppsid[j], &((ACCESS_ALLOWED_ACE *)old_ace_header)->SidStart))
3819 case ACCESS_DENIED_ACE_TYPE:
3820 if (EqualSid(ppsid[j], &((ACCESS_DENIED_ACE *)old_ace_header)->SidStart))
3823 case SYSTEM_AUDIT_ACE_TYPE:
3824 if (EqualSid(ppsid[j], &((SYSTEM_AUDIT_ACE *)old_ace_header)->SidStart))
3827 case SYSTEM_ALARM_ACE_TYPE:
3828 if (EqualSid(ppsid[j], &((SYSTEM_ALARM_ACE *)old_ace_header)->SidStart))
3832 FIXME("unhandled ace type %d\n", old_ace_header->AceType);
3840 status = RtlAddAce(*NewAcl, ACL_REVISION, 1, (PACE_HEADER)old_ace_header, old_ace_header->AceSize);
3841 if (status != STATUS_SUCCESS)
3843 WARN("RtlAddAce failed with error 0x%08x\n", status);
3844 ret = RtlNtStatusToDosError(status);
3851 HeapFree(GetProcessHeap(), 0, ppsid);
3855 /******************************************************************************
3856 * SetNamedSecurityInfoA [ADVAPI32.@]
3858 DWORD WINAPI SetNamedSecurityInfoA(LPSTR pObjectName,
3859 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
3860 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
3865 TRACE("%s %d %d %p %p %p %p\n", debugstr_a(pObjectName), ObjectType,
3866 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
3868 wstr = SERV_dup(pObjectName);
3869 r = SetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, psidOwner,
3870 psidGroup, pDacl, pSacl );
3872 HeapFree( GetProcessHeap(), 0, wstr );
3877 BOOL WINAPI SetPrivateObjectSecurity( SECURITY_INFORMATION SecurityInformation,
3878 PSECURITY_DESCRIPTOR ModificationDescriptor,
3879 PSECURITY_DESCRIPTOR* ObjectsSecurityDescriptor,
3880 PGENERIC_MAPPING GenericMapping,
3883 FIXME("0x%08x %p %p %p %p - stub\n", SecurityInformation, ModificationDescriptor,
3884 ObjectsSecurityDescriptor, GenericMapping, Token);
3889 BOOL WINAPI AreAllAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
3891 return RtlAreAllAccessesGranted( GrantedAccess, DesiredAccess );
3894 /******************************************************************************
3895 * AreAnyAccessesGranted [ADVAPI32.@]
3897 * Determines whether or not any of a set of specified access permissions have
3898 * been granted or not.
3901 * GrantedAccess [I] The permissions that have been granted.
3902 * DesiredAccess [I] The permissions that you want to have.
3905 * Nonzero if any of the permissions have been granted, zero if none of the
3906 * permissions have been granted.
3909 BOOL WINAPI AreAnyAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
3911 return RtlAreAnyAccessesGranted( GrantedAccess, DesiredAccess );
3914 /******************************************************************************
3915 * SetNamedSecurityInfoW [ADVAPI32.@]
3917 DWORD WINAPI SetNamedSecurityInfoW(LPWSTR pObjectName,
3918 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
3919 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
3921 FIXME("%s %d %d %p %p %p %p\n", debugstr_w(pObjectName), ObjectType,
3922 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
3923 return ERROR_SUCCESS;
3926 /******************************************************************************
3927 * GetExplicitEntriesFromAclA [ADVAPI32.@]
3929 DWORD WINAPI GetExplicitEntriesFromAclA( PACL pacl, PULONG pcCountOfExplicitEntries,
3930 PEXPLICIT_ACCESSA* pListOfExplicitEntries)
3932 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
3933 return ERROR_CALL_NOT_IMPLEMENTED;
3936 /******************************************************************************
3937 * GetExplicitEntriesFromAclW [ADVAPI32.@]
3939 DWORD WINAPI GetExplicitEntriesFromAclW( PACL pacl, PULONG pcCountOfExplicitEntries,
3940 PEXPLICIT_ACCESSW* pListOfExplicitEntries)
3942 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
3943 return ERROR_CALL_NOT_IMPLEMENTED;
3946 /******************************************************************************
3947 * GetAuditedPermissionsFromAclA [ADVAPI32.@]
3949 DWORD WINAPI GetAuditedPermissionsFromAclA( PACL pacl, PTRUSTEEA pTrustee, PACCESS_MASK pSuccessfulAuditedRights,
3950 PACCESS_MASK pFailedAuditRights)
3952 FIXME("%p %p %p %p\n",pacl, pTrustee, pSuccessfulAuditedRights, pFailedAuditRights);
3953 return ERROR_CALL_NOT_IMPLEMENTED;
3957 /******************************************************************************
3958 * GetAuditedPermissionsFromAclW [ADVAPI32.@]
3960 DWORD WINAPI GetAuditedPermissionsFromAclW( PACL pacl, PTRUSTEEW pTrustee, PACCESS_MASK pSuccessfulAuditedRights,
3961 PACCESS_MASK pFailedAuditRights)
3963 FIXME("%p %p %p %p\n",pacl, pTrustee, pSuccessfulAuditedRights, pFailedAuditRights);
3964 return ERROR_CALL_NOT_IMPLEMENTED;
3968 /******************************************************************************
3969 * ParseAclStringFlags
3971 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl)
3974 LPCWSTR szAcl = *StringAcl;
3976 while (*szAcl != '(')
3980 flags |= SE_DACL_PROTECTED;
3982 else if (*szAcl == 'A')
3986 flags |= SE_DACL_AUTO_INHERIT_REQ;
3987 else if (*szAcl == 'I')
3988 flags |= SE_DACL_AUTO_INHERITED;
3997 /******************************************************************************
3998 * ParseAceStringType
4000 static const ACEFLAG AceType[] =
4002 { SDDL_ALARM, SYSTEM_ALARM_ACE_TYPE },
4003 { SDDL_AUDIT, SYSTEM_AUDIT_ACE_TYPE },
4004 { SDDL_ACCESS_ALLOWED, ACCESS_ALLOWED_ACE_TYPE },
4005 { SDDL_ACCESS_DENIED, ACCESS_DENIED_ACE_TYPE },
4007 { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
4008 { SDDL_OBJECT_ACCESS_DENIED, ACCESS_DENIED_OBJECT_ACE_TYPE },
4009 { SDDL_OBJECT_ALARM, SYSTEM_ALARM_OBJECT_ACE_TYPE },
4010 { SDDL_OBJECT_AUDIT, SYSTEM_AUDIT_OBJECT_ACE_TYPE },
4015 static BYTE ParseAceStringType(LPCWSTR* StringAcl)
4018 LPCWSTR szAcl = *StringAcl;
4019 const ACEFLAG *lpaf = AceType;
4021 while (*szAcl == ' ')
4024 while (lpaf->wstr &&
4025 (len = strlenW(lpaf->wstr)) &&
4026 strncmpW(lpaf->wstr, szAcl, len))
4032 *StringAcl = szAcl + len;
4037 /******************************************************************************
4038 * ParseAceStringFlags
4040 static const ACEFLAG AceFlags[] =
4042 { SDDL_CONTAINER_INHERIT, CONTAINER_INHERIT_ACE },
4043 { SDDL_AUDIT_FAILURE, FAILED_ACCESS_ACE_FLAG },
4044 { SDDL_INHERITED, INHERITED_ACE },
4045 { SDDL_INHERIT_ONLY, INHERIT_ONLY_ACE },
4046 { SDDL_NO_PROPAGATE, NO_PROPAGATE_INHERIT_ACE },
4047 { SDDL_OBJECT_INHERIT, OBJECT_INHERIT_ACE },
4048 { SDDL_AUDIT_SUCCESS, SUCCESSFUL_ACCESS_ACE_FLAG },
4052 static BYTE ParseAceStringFlags(LPCWSTR* StringAcl)
4056 LPCWSTR szAcl = *StringAcl;
4058 while (*szAcl == ' ')
4061 while (*szAcl != ';')
4063 const ACEFLAG *lpaf = AceFlags;
4065 while (lpaf->wstr &&
4066 (len = strlenW(lpaf->wstr)) &&
4067 strncmpW(lpaf->wstr, szAcl, len))
4073 flags |= lpaf->value;
4082 /******************************************************************************
4083 * ParseAceStringRights
4085 static const ACEFLAG AceRights[] =
4087 { SDDL_GENERIC_ALL, GENERIC_ALL },
4088 { SDDL_GENERIC_READ, GENERIC_READ },
4089 { SDDL_GENERIC_WRITE, GENERIC_WRITE },
4090 { SDDL_GENERIC_EXECUTE, GENERIC_EXECUTE },
4092 { SDDL_READ_CONTROL, READ_CONTROL },
4093 { SDDL_STANDARD_DELETE, DELETE },
4094 { SDDL_WRITE_DAC, WRITE_DAC },
4095 { SDDL_WRITE_OWNER, WRITE_OWNER },
4097 { SDDL_READ_PROPERTY, ADS_RIGHT_DS_READ_PROP},
4098 { SDDL_WRITE_PROPERTY, ADS_RIGHT_DS_WRITE_PROP},
4099 { SDDL_CREATE_CHILD, ADS_RIGHT_DS_CREATE_CHILD},
4100 { SDDL_DELETE_CHILD, ADS_RIGHT_DS_DELETE_CHILD},
4101 { SDDL_LIST_CHILDREN, ADS_RIGHT_ACTRL_DS_LIST},
4102 { SDDL_SELF_WRITE, ADS_RIGHT_DS_SELF},
4103 { SDDL_LIST_OBJECT, ADS_RIGHT_DS_LIST_OBJECT},
4104 { SDDL_DELETE_TREE, ADS_RIGHT_DS_DELETE_TREE},
4105 { SDDL_CONTROL_ACCESS, ADS_RIGHT_DS_CONTROL_ACCESS},
4107 { SDDL_FILE_ALL, FILE_ALL_ACCESS },
4108 { SDDL_FILE_READ, FILE_GENERIC_READ },
4109 { SDDL_FILE_WRITE, FILE_GENERIC_WRITE },
4110 { SDDL_FILE_EXECUTE, FILE_GENERIC_EXECUTE },
4112 { SDDL_KEY_ALL, KEY_ALL_ACCESS },
4113 { SDDL_KEY_READ, KEY_READ },
4114 { SDDL_KEY_WRITE, KEY_WRITE },
4115 { SDDL_KEY_EXECUTE, KEY_EXECUTE },
4119 static DWORD ParseAceStringRights(LPCWSTR* StringAcl)
4123 LPCWSTR szAcl = *StringAcl;
4125 while (*szAcl == ' ')
4128 if ((*szAcl == '0') && (*(szAcl + 1) == 'x'))
4132 while (*p && *p != ';')
4135 if (p - szAcl <= 10 /* 8 hex digits + "0x" */ )
4137 rights = strtoulW(szAcl, NULL, 16);
4141 WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl, p - szAcl));
4145 while (*szAcl != ';')
4147 const ACEFLAG *lpaf = AceRights;
4149 while (lpaf->wstr &&
4150 (len = strlenW(lpaf->wstr)) &&
4151 strncmpW(lpaf->wstr, szAcl, len))
4159 rights |= lpaf->value;
4169 /******************************************************************************
4170 * ParseStringAclToAcl
4172 * dacl_flags(string_ace1)(string_ace2)... (string_acen)
4174 static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags,
4175 PACL pAcl, LPDWORD cBytes)
4179 DWORD length = sizeof(ACL);
4182 PACCESS_ALLOWED_ACE pAce = NULL; /* pointer to current ACE */
4183 DWORD error = ERROR_INVALID_ACL;
4185 TRACE("%s\n", debugstr_w(StringAcl));
4190 if (pAcl) /* pAce is only useful if we're setting values */
4191 pAce = (PACCESS_ALLOWED_ACE) (pAcl + 1);
4193 /* Parse ACL flags */
4194 *lpdwFlags = ParseAclStringFlags(&StringAcl);
4197 while (*StringAcl == '(')
4201 /* Parse ACE type */
4202 val = ParseAceStringType(&StringAcl);
4204 pAce->Header.AceType = (BYTE) val;
4205 if (*StringAcl != ';')
4207 error = RPC_S_INVALID_STRING_UUID;
4212 /* Parse ACE flags */
4213 val = ParseAceStringFlags(&StringAcl);
4215 pAce->Header.AceFlags = (BYTE) val;
4216 if (*StringAcl != ';')
4220 /* Parse ACE rights */
4221 val = ParseAceStringRights(&StringAcl);
4224 if (*StringAcl != ';')
4228 /* Parse ACE object guid */
4229 while (*StringAcl == ' ')
4231 if (*StringAcl != ';')
4233 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
4238 /* Parse ACE inherit object guid */
4239 while (*StringAcl == ' ')
4241 if (*StringAcl != ';')
4243 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
4248 /* Parse ACE account sid */
4249 if (ParseStringSidToSid(StringAcl, pAce ? &pAce->SidStart : NULL, &sidlen))
4251 while (*StringAcl && *StringAcl != ')')
4255 if (*StringAcl != ')')
4259 acesize = sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) + sidlen;
4263 pAce->Header.AceSize = acesize;
4264 pAce = (PACCESS_ALLOWED_ACE)((LPBYTE)pAce + acesize);
4271 if (length > 0xffff)
4273 ERR("ACL too large\n");
4279 pAcl->AclRevision = ACL_REVISION;
4281 pAcl->AclSize = length;
4282 pAcl->AceCount = acecount++;
4288 SetLastError(error);
4289 WARN("Invalid ACE string format\n");
4294 /******************************************************************************
4295 * ParseStringSecurityDescriptorToSecurityDescriptor
4297 static BOOL ParseStringSecurityDescriptorToSecurityDescriptor(
4298 LPCWSTR StringSecurityDescriptor,
4299 SECURITY_DESCRIPTOR_RELATIVE* SecurityDescriptor,
4304 WCHAR tok[MAX_PATH];
4306 LPBYTE lpNext = NULL;
4309 *cBytes = sizeof(SECURITY_DESCRIPTOR);
4311 if (SecurityDescriptor)
4312 lpNext = (LPBYTE)(SecurityDescriptor + 1);
4314 while (*StringSecurityDescriptor == ' ')
4315 StringSecurityDescriptor++;
4317 while (*StringSecurityDescriptor)
4319 toktype = *StringSecurityDescriptor;
4321 /* Expect char identifier followed by ':' */
4322 StringSecurityDescriptor++;
4323 if (*StringSecurityDescriptor != ':')
4325 SetLastError(ERROR_INVALID_PARAMETER);
4328 StringSecurityDescriptor++;
4331 lptoken = StringSecurityDescriptor;
4332 while (*lptoken && *lptoken != ':')
4338 len = lptoken - StringSecurityDescriptor;
4339 memcpy( tok, StringSecurityDescriptor, len * sizeof(WCHAR) );
4348 if (!ParseStringSidToSid(tok, lpNext, &bytes))
4351 if (SecurityDescriptor)
4353 SecurityDescriptor->Owner = lpNext - (LPBYTE)SecurityDescriptor;
4354 lpNext += bytes; /* Advance to next token */
4366 if (!ParseStringSidToSid(tok, lpNext, &bytes))
4369 if (SecurityDescriptor)
4371 SecurityDescriptor->Group = lpNext - (LPBYTE)SecurityDescriptor;
4372 lpNext += bytes; /* Advance to next token */
4385 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
4388 if (SecurityDescriptor)
4390 SecurityDescriptor->Control |= SE_DACL_PRESENT | flags;
4391 SecurityDescriptor->Dacl = lpNext - (LPBYTE)SecurityDescriptor;
4392 lpNext += bytes; /* Advance to next token */
4405 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
4408 if (SecurityDescriptor)
4410 SecurityDescriptor->Control |= SE_SACL_PRESENT | flags;
4411 SecurityDescriptor->Sacl = lpNext - (LPBYTE)SecurityDescriptor;
4412 lpNext += bytes; /* Advance to next token */
4421 FIXME("Unknown token\n");
4422 SetLastError(ERROR_INVALID_PARAMETER);
4426 StringSecurityDescriptor = lptoken;
4435 /******************************************************************************
4436 * ConvertStringSecurityDescriptorToSecurityDescriptorA [ADVAPI32.@]
4438 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorA(
4439 LPCSTR StringSecurityDescriptor,
4440 DWORD StringSDRevision,
4441 PSECURITY_DESCRIPTOR* SecurityDescriptor,
4442 PULONG SecurityDescriptorSize)
4445 LPWSTR StringSecurityDescriptorW;
4447 if(!StringSecurityDescriptor)
4450 StringSecurityDescriptorW = SERV_dup(StringSecurityDescriptor);
4451 ret = ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptorW,
4452 StringSDRevision, SecurityDescriptor,
4453 SecurityDescriptorSize);
4454 HeapFree(GetProcessHeap(), 0, StringSecurityDescriptorW);
4459 /******************************************************************************
4460 * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
4462 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW(
4463 LPCWSTR StringSecurityDescriptor,
4464 DWORD StringSDRevision,
4465 PSECURITY_DESCRIPTOR* SecurityDescriptor,
4466 PULONG SecurityDescriptorSize)
4469 SECURITY_DESCRIPTOR* psd;
4472 TRACE("%s\n", debugstr_w(StringSecurityDescriptor));
4474 if (GetVersion() & 0x80000000)
4476 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
4479 else if (!StringSecurityDescriptor || !SecurityDescriptor)
4481 SetLastError(ERROR_INVALID_PARAMETER);
4484 else if (StringSDRevision != SID_REVISION)
4486 SetLastError(ERROR_UNKNOWN_REVISION);
4490 /* Compute security descriptor length */
4491 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
4495 psd = *SecurityDescriptor = LocalAlloc(GMEM_ZEROINIT, cBytes);
4496 if (!psd) goto lend;
4498 psd->Revision = SID_REVISION;
4499 psd->Control |= SE_SELF_RELATIVE;
4501 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
4502 (SECURITY_DESCRIPTOR_RELATIVE *)psd, &cBytes))
4508 if (SecurityDescriptorSize)
4509 *SecurityDescriptorSize = cBytes;
4514 TRACE(" ret=%d\n", bret);
4518 static void DumpString(LPCWSTR string, int cch, WCHAR **pwptr, ULONG *plen)
4521 cch = strlenW(string);
4528 memcpy(*pwptr, string, sizeof(WCHAR)*cch);
4533 static BOOL DumpSidNumeric(PSID psid, WCHAR **pwptr, ULONG *plen)
4536 WCHAR fmt[] = { 'S','-','%','u','-','%','d',0 };
4537 WCHAR subauthfmt[] = { '-','%','u',0 };
4541 if( !IsValidSid( psid ) || pisid->Revision != SDDL_REVISION)
4543 SetLastError(ERROR_INVALID_SID);
4547 if (pisid->IdentifierAuthority.Value[0] ||
4548 pisid->IdentifierAuthority.Value[1])
4550 FIXME("not matching MS' bugs\n");
4551 SetLastError(ERROR_INVALID_SID);
4555 sprintfW( buf, fmt, pisid->Revision,
4557 MAKEWORD( pisid->IdentifierAuthority.Value[5],
4558 pisid->IdentifierAuthority.Value[4] ),
4559 MAKEWORD( pisid->IdentifierAuthority.Value[3],
4560 pisid->IdentifierAuthority.Value[2] )
4562 DumpString(buf, -1, pwptr, plen);
4564 for( i=0; i<pisid->SubAuthorityCount; i++ )
4566 sprintfW( buf, subauthfmt, pisid->SubAuthority[i] );
4567 DumpString(buf, -1, pwptr, plen);
4572 static BOOL DumpSid(PSID psid, WCHAR **pwptr, ULONG *plen)
4575 for (i = 0; i < sizeof(WellKnownSids) / sizeof(WellKnownSids[0]); i++)
4577 if (WellKnownSids[i].wstr[0] && EqualSid(psid, (PSID)&(WellKnownSids[i].Sid.Revision)))
4579 DumpString(WellKnownSids[i].wstr, 2, pwptr, plen);
4584 return DumpSidNumeric(psid, pwptr, plen);
4587 static const LPCWSTR AceRightBitNames[32] = {
4588 SDDL_CREATE_CHILD, /* 0 */
4592 SDDL_READ_PROPERTY, /* 4 */
4593 SDDL_WRITE_PROPERTY,
4596 SDDL_CONTROL_ACCESS, /* 8 */
4604 SDDL_STANDARD_DELETE, /* 16 */
4616 SDDL_GENERIC_ALL, /* 28 */
4617 SDDL_GENERIC_EXECUTE,
4622 static void DumpRights(DWORD mask, WCHAR **pwptr, ULONG *plen)
4624 static const WCHAR fmtW[] = {'0','x','%','x',0};
4631 /* first check if the right have name */
4632 for (i = 0; i < sizeof(AceRights)/sizeof(AceRights[0]); i++)
4634 if (AceRights[i].wstr == NULL)
4636 if (mask == AceRights[i].value)
4638 DumpString(AceRights[i].wstr, -1, pwptr, plen);
4643 /* then check if it can be built from bit names */
4644 for (i = 0; i < 32; i++)
4646 if ((mask & (1 << i)) && (AceRightBitNames[i] == NULL))
4648 /* can't be built from bit names */
4649 sprintfW(buf, fmtW, mask);
4650 DumpString(buf, -1, pwptr, plen);
4655 /* build from bit names */
4656 for (i = 0; i < 32; i++)
4657 if (mask & (1 << i))
4658 DumpString(AceRightBitNames[i], -1, pwptr, plen);
4661 static BOOL DumpAce(LPVOID pace, WCHAR **pwptr, ULONG *plen)
4663 ACCESS_ALLOWED_ACE *piace; /* all the supported ACEs have the same memory layout */
4664 static const WCHAR openbr = '(';
4665 static const WCHAR closebr = ')';
4666 static const WCHAR semicolon = ';';
4668 if (((PACE_HEADER)pace)->AceType > SYSTEM_ALARM_ACE_TYPE || ((PACE_HEADER)pace)->AceSize < sizeof(ACCESS_ALLOWED_ACE))
4670 SetLastError(ERROR_INVALID_ACL);
4675 DumpString(&openbr, 1, pwptr, plen);
4676 switch (piace->Header.AceType)
4678 case ACCESS_ALLOWED_ACE_TYPE:
4679 DumpString(SDDL_ACCESS_ALLOWED, -1, pwptr, plen);
4681 case ACCESS_DENIED_ACE_TYPE:
4682 DumpString(SDDL_ACCESS_DENIED, -1, pwptr, plen);
4684 case SYSTEM_AUDIT_ACE_TYPE:
4685 DumpString(SDDL_AUDIT, -1, pwptr, plen);
4687 case SYSTEM_ALARM_ACE_TYPE:
4688 DumpString(SDDL_ALARM, -1, pwptr, plen);
4691 DumpString(&semicolon, 1, pwptr, plen);
4693 if (piace->Header.AceFlags & OBJECT_INHERIT_ACE)
4694 DumpString(SDDL_OBJECT_INHERIT, -1, pwptr, plen);
4695 if (piace->Header.AceFlags & CONTAINER_INHERIT_ACE)
4696 DumpString(SDDL_CONTAINER_INHERIT, -1, pwptr, plen);
4697 if (piace->Header.AceFlags & NO_PROPAGATE_INHERIT_ACE)
4698 DumpString(SDDL_NO_PROPAGATE, -1, pwptr, plen);
4699 if (piace->Header.AceFlags & INHERIT_ONLY_ACE)
4700 DumpString(SDDL_INHERIT_ONLY, -1, pwptr, plen);
4701 if (piace->Header.AceFlags & INHERITED_ACE)
4702 DumpString(SDDL_INHERITED, -1, pwptr, plen);
4703 if (piace->Header.AceFlags & SUCCESSFUL_ACCESS_ACE_FLAG)
4704 DumpString(SDDL_AUDIT_SUCCESS, -1, pwptr, plen);
4705 if (piace->Header.AceFlags & FAILED_ACCESS_ACE_FLAG)
4706 DumpString(SDDL_AUDIT_FAILURE, -1, pwptr, plen);
4707 DumpString(&semicolon, 1, pwptr, plen);
4708 DumpRights(piace->Mask, pwptr, plen);
4709 DumpString(&semicolon, 1, pwptr, plen);
4710 /* objects not supported */
4711 DumpString(&semicolon, 1, pwptr, plen);
4712 /* objects not supported */
4713 DumpString(&semicolon, 1, pwptr, plen);
4714 if (!DumpSid(&piace->SidStart, pwptr, plen))
4716 DumpString(&closebr, 1, pwptr, plen);
4720 static BOOL DumpAcl(PACL pacl, WCHAR **pwptr, ULONG *plen, BOOL protected, BOOL autoInheritReq, BOOL autoInherited)
4726 DumpString(SDDL_PROTECTED, -1, pwptr, plen);
4728 DumpString(SDDL_AUTO_INHERIT_REQ, -1, pwptr, plen);
4730 DumpString(SDDL_AUTO_INHERITED, -1, pwptr, plen);
4735 if (!IsValidAcl(pacl))
4738 count = pacl->AceCount;
4739 for (i = 0; i < count; i++)
4742 if (!GetAce(pacl, i, &ace))
4744 if (!DumpAce(ace, pwptr, plen))
4751 static BOOL DumpOwner(PSECURITY_DESCRIPTOR SecurityDescriptor, WCHAR **pwptr, ULONG *plen)
4753 static const WCHAR prefix[] = {'O',':',0};
4757 if (!GetSecurityDescriptorOwner(SecurityDescriptor, &psid, &bDefaulted))
4763 DumpString(prefix, -1, pwptr, plen);
4764 if (!DumpSid(psid, pwptr, plen))
4769 static BOOL DumpGroup(PSECURITY_DESCRIPTOR SecurityDescriptor, WCHAR **pwptr, ULONG *plen)
4771 static const WCHAR prefix[] = {'G',':',0};
4775 if (!GetSecurityDescriptorGroup(SecurityDescriptor, &psid, &bDefaulted))
4781 DumpString(prefix, -1, pwptr, plen);
4782 if (!DumpSid(psid, pwptr, plen))
4787 static BOOL DumpDacl(PSECURITY_DESCRIPTOR SecurityDescriptor, WCHAR **pwptr, ULONG *plen)
4789 static const WCHAR dacl[] = {'D',':',0};
4790 SECURITY_DESCRIPTOR_CONTROL control;
4791 BOOL present, defaulted;
4795 if (!GetSecurityDescriptorDacl(SecurityDescriptor, &present, &pacl, &defaulted))
4798 if (!GetSecurityDescriptorControl(SecurityDescriptor, &control, &revision))
4804 DumpString(dacl, 2, pwptr, plen);
4805 if (!DumpAcl(pacl, pwptr, plen, control & SE_DACL_PROTECTED, control & SE_DACL_AUTO_INHERIT_REQ, control & SE_DACL_AUTO_INHERITED))
4810 static BOOL DumpSacl(PSECURITY_DESCRIPTOR SecurityDescriptor, WCHAR **pwptr, ULONG *plen)
4812 static const WCHAR sacl[] = {'S',':',0};
4813 SECURITY_DESCRIPTOR_CONTROL control;
4814 BOOL present, defaulted;
4818 if (!GetSecurityDescriptorSacl(SecurityDescriptor, &present, &pacl, &defaulted))
4821 if (!GetSecurityDescriptorControl(SecurityDescriptor, &control, &revision))
4827 DumpString(sacl, 2, pwptr, plen);
4828 if (!DumpAcl(pacl, pwptr, plen, control & SE_SACL_PROTECTED, control & SE_SACL_AUTO_INHERIT_REQ, control & SE_SACL_AUTO_INHERITED))
4833 /******************************************************************************
4834 * ConvertSecurityDescriptorToStringSecurityDescriptorA [ADVAPI32.@]
4836 BOOL WINAPI ConvertSecurityDescriptorToStringSecurityDescriptorW(PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD SDRevision, SECURITY_INFORMATION RequestedInformation, LPWSTR *OutputString, PULONG OutputLen)
4841 if (SDRevision != SDDL_REVISION_1)
4843 ERR("Pogram requested unknown SDDL revision %d\n", SDRevision);
4844 SetLastError(ERROR_UNKNOWN_REVISION);
4849 if (RequestedInformation & OWNER_SECURITY_INFORMATION)
4850 if (!DumpOwner(SecurityDescriptor, NULL, &len))
4852 if (RequestedInformation & GROUP_SECURITY_INFORMATION)
4853 if (!DumpGroup(SecurityDescriptor, NULL, &len))
4855 if (RequestedInformation & DACL_SECURITY_INFORMATION)
4856 if (!DumpDacl(SecurityDescriptor, NULL, &len))
4858 if (RequestedInformation & SACL_SECURITY_INFORMATION)
4859 if (!DumpSacl(SecurityDescriptor, NULL, &len))
4862 wstr = wptr = LocalAlloc(0, (len + 1)*sizeof(WCHAR));
4863 if (RequestedInformation & OWNER_SECURITY_INFORMATION)
4864 if (!DumpOwner(SecurityDescriptor, &wptr, NULL)) {
4868 if (RequestedInformation & GROUP_SECURITY_INFORMATION)
4869 if (!DumpGroup(SecurityDescriptor, &wptr, NULL)) {
4873 if (RequestedInformation & DACL_SECURITY_INFORMATION)
4874 if (!DumpDacl(SecurityDescriptor, &wptr, NULL)) {
4878 if (RequestedInformation & SACL_SECURITY_INFORMATION)
4879 if (!DumpSacl(SecurityDescriptor, &wptr, NULL)) {
4885 TRACE("ret: %s, %d\n", wine_dbgstr_w(wstr), len);
4886 *OutputString = wstr;
4888 *OutputLen = strlenW(*OutputString)+1;
4892 /******************************************************************************
4893 * ConvertSecurityDescriptorToStringSecurityDescriptorA [ADVAPI32.@]
4895 BOOL WINAPI ConvertSecurityDescriptorToStringSecurityDescriptorA(PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD SDRevision, SECURITY_INFORMATION Information, LPSTR *OutputString, PULONG OutputLen)
4899 if (ConvertSecurityDescriptorToStringSecurityDescriptorW(SecurityDescriptor, SDRevision, Information, &wstr, &len))
4903 lenA = WideCharToMultiByte(CP_ACP, 0, wstr, len, NULL, 0, NULL, NULL);
4904 *OutputString = HeapAlloc(GetProcessHeap(), 0, lenA);
4905 WideCharToMultiByte(CP_ACP, 0, wstr, len, *OutputString, lenA, NULL, NULL);
4908 if (OutputLen != NULL)
4914 *OutputString = NULL;
4921 /******************************************************************************
4922 * ConvertStringSidToSidW [ADVAPI32.@]
4924 BOOL WINAPI ConvertStringSidToSidW(LPCWSTR StringSid, PSID* Sid)
4929 TRACE("%s, %p\n", debugstr_w(StringSid), Sid);
4930 if (GetVersion() & 0x80000000)
4931 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
4932 else if (!StringSid || !Sid)
4933 SetLastError(ERROR_INVALID_PARAMETER);
4934 else if (ParseStringSidToSid(StringSid, NULL, &cBytes))
4936 PSID pSid = *Sid = LocalAlloc(0, cBytes);
4938 bret = ParseStringSidToSid(StringSid, pSid, &cBytes);
4945 /******************************************************************************
4946 * ConvertStringSidToSidA [ADVAPI32.@]
4948 BOOL WINAPI ConvertStringSidToSidA(LPCSTR StringSid, PSID* Sid)
4952 TRACE("%s, %p\n", debugstr_a(StringSid), Sid);
4953 if (GetVersion() & 0x80000000)
4954 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
4955 else if (!StringSid || !Sid)
4956 SetLastError(ERROR_INVALID_PARAMETER);
4959 WCHAR *wStringSid = SERV_dup(StringSid);
4960 bret = ConvertStringSidToSidW(wStringSid, Sid);
4961 HeapFree(GetProcessHeap(), 0, wStringSid);
4966 /******************************************************************************
4967 * ConvertSidToStringSidW [ADVAPI32.@]
4969 * format of SID string is:
4970 * S-<count>-<auth>-<subauth1>-<subauth2>-<subauth3>...
4972 * <rev> is the revision of the SID encoded as decimal
4973 * <auth> is the identifier authority encoded as hex
4974 * <subauthN> is the subauthority id encoded as decimal
4976 BOOL WINAPI ConvertSidToStringSidW( PSID pSid, LPWSTR *pstr )
4981 TRACE("%p %p\n", pSid, pstr );
4984 if (!DumpSidNumeric(pSid, NULL, &len))
4986 wstr = wptr = LocalAlloc(0, (len+1) * sizeof(WCHAR));
4987 DumpSidNumeric(pSid, &wptr, NULL);
4994 /******************************************************************************
4995 * ConvertSidToStringSidA [ADVAPI32.@]
4997 BOOL WINAPI ConvertSidToStringSidA(PSID pSid, LPSTR *pstr)
5003 TRACE("%p %p\n", pSid, pstr );
5005 if( !ConvertSidToStringSidW( pSid, &wstr ) )
5008 len = WideCharToMultiByte( CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL );
5009 str = LocalAlloc( 0, len );
5010 WideCharToMultiByte( CP_ACP, 0, wstr, -1, str, len, NULL, NULL );
5018 BOOL WINAPI ConvertToAutoInheritPrivateObjectSecurity(
5019 PSECURITY_DESCRIPTOR pdesc,
5020 PSECURITY_DESCRIPTOR cdesc,
5021 PSECURITY_DESCRIPTOR* ndesc,
5024 PGENERIC_MAPPING genmap )
5026 FIXME("%p %p %p %p %d %p - stub\n", pdesc, cdesc, ndesc, objtype, isdir, genmap);
5031 BOOL WINAPI CreatePrivateObjectSecurity(
5032 PSECURITY_DESCRIPTOR ParentDescriptor,
5033 PSECURITY_DESCRIPTOR CreatorDescriptor,
5034 PSECURITY_DESCRIPTOR* NewDescriptor,
5035 BOOL IsDirectoryObject,
5037 PGENERIC_MAPPING GenericMapping )
5039 SECURITY_DESCRIPTOR_RELATIVE *relative;
5040 DWORD needed, offset;
5043 FIXME("%p %p %p %d %p %p - returns fake SECURITY_DESCRIPTOR\n", ParentDescriptor,
5044 CreatorDescriptor, NewDescriptor, IsDirectoryObject, Token, GenericMapping);
5046 needed = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
5047 needed += sizeof(sidWorld);
5048 needed += sizeof(sidWorld);
5049 needed += WINE_SIZE_OF_WORLD_ACCESS_ACL;
5050 needed += WINE_SIZE_OF_WORLD_ACCESS_ACL;
5052 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, needed ))) return FALSE;
5053 relative = (SECURITY_DESCRIPTOR_RELATIVE *)buffer;
5054 if (!InitializeSecurityDescriptor( relative, SECURITY_DESCRIPTOR_REVISION ))
5056 HeapFree( GetProcessHeap(), 0, buffer );
5059 relative->Control |= SE_SELF_RELATIVE;
5060 offset = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
5062 memcpy( buffer + offset, &sidWorld, sizeof(sidWorld) );
5063 relative->Owner = offset;
5064 offset += sizeof(sidWorld);
5066 memcpy( buffer + offset, &sidWorld, sizeof(sidWorld) );
5067 relative->Group = offset;
5068 offset += sizeof(sidWorld);
5070 GetWorldAccessACL( (ACL *)(buffer + offset) );
5071 relative->Dacl = offset;
5072 offset += WINE_SIZE_OF_WORLD_ACCESS_ACL;
5074 GetWorldAccessACL( (ACL *)(buffer + offset) );
5075 relative->Sacl = offset;
5077 *NewDescriptor = relative;
5081 BOOL WINAPI DestroyPrivateObjectSecurity( PSECURITY_DESCRIPTOR* ObjectDescriptor )
5083 FIXME("%p - stub\n", ObjectDescriptor);
5085 HeapFree( GetProcessHeap(), 0, *ObjectDescriptor );
5089 BOOL WINAPI CreateProcessAsUserA(
5091 LPCSTR lpApplicationName,
5092 LPSTR lpCommandLine,
5093 LPSECURITY_ATTRIBUTES lpProcessAttributes,
5094 LPSECURITY_ATTRIBUTES lpThreadAttributes,
5095 BOOL bInheritHandles,
5096 DWORD dwCreationFlags,
5097 LPVOID lpEnvironment,
5098 LPCSTR lpCurrentDirectory,
5099 LPSTARTUPINFOA lpStartupInfo,
5100 LPPROCESS_INFORMATION lpProcessInformation )
5103 WCHAR *appW, *cmdlnW, *cwdW;
5106 TRACE("%p %s %s %p %p %d 0x%08x %p %s %p %p\n", hToken, debugstr_a(lpApplicationName),
5107 debugstr_a(lpCommandLine), lpProcessAttributes, lpThreadAttributes, bInheritHandles,
5108 dwCreationFlags, lpEnvironment, debugstr_a(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
5110 appW = SERV_dup(lpApplicationName);
5111 cmdlnW = SERV_dup(lpCommandLine);
5112 cwdW = SERV_dup(lpCurrentDirectory);
5113 sinfo.cb = sizeof(sinfo);
5114 sinfo.lpReserved = SERV_dup(lpStartupInfo->lpReserved);
5115 sinfo.lpDesktop = SERV_dup(lpStartupInfo->lpDesktop);
5116 sinfo.lpTitle = SERV_dup(lpStartupInfo->lpTitle);
5117 sinfo.dwX = lpStartupInfo->dwX;
5118 sinfo.dwY = lpStartupInfo->dwY;
5119 sinfo.dwXSize = lpStartupInfo->dwXSize;
5120 sinfo.dwYSize = lpStartupInfo->dwYSize;
5121 sinfo.dwXCountChars = lpStartupInfo->dwXCountChars;
5122 sinfo.dwYCountChars = lpStartupInfo->dwYCountChars;
5123 sinfo.dwFillAttribute = lpStartupInfo->dwFillAttribute;
5124 sinfo.dwFlags = lpStartupInfo->dwFlags;
5125 sinfo.wShowWindow = lpStartupInfo->wShowWindow;
5126 sinfo.cbReserved2 = lpStartupInfo->cbReserved2;
5127 sinfo.lpReserved2 = lpStartupInfo->lpReserved2;
5128 sinfo.hStdInput = lpStartupInfo->hStdInput;
5129 sinfo.hStdOutput = lpStartupInfo->hStdOutput;
5130 sinfo.hStdError = lpStartupInfo->hStdError;
5131 ret = CreateProcessAsUserW(hToken, appW, cmdlnW, lpProcessAttributes,
5132 lpThreadAttributes, bInheritHandles, dwCreationFlags,
5133 lpEnvironment, cwdW, &sinfo, lpProcessInformation);
5134 HeapFree(GetProcessHeap(), 0, appW);
5135 HeapFree(GetProcessHeap(), 0, cmdlnW);
5136 HeapFree(GetProcessHeap(), 0, cwdW);
5137 HeapFree(GetProcessHeap(), 0, sinfo.lpReserved);
5138 HeapFree(GetProcessHeap(), 0, sinfo.lpDesktop);
5139 HeapFree(GetProcessHeap(), 0, sinfo.lpTitle);
5144 BOOL WINAPI CreateProcessAsUserW(
5146 LPCWSTR lpApplicationName,
5147 LPWSTR lpCommandLine,
5148 LPSECURITY_ATTRIBUTES lpProcessAttributes,
5149 LPSECURITY_ATTRIBUTES lpThreadAttributes,
5150 BOOL bInheritHandles,
5151 DWORD dwCreationFlags,
5152 LPVOID lpEnvironment,
5153 LPCWSTR lpCurrentDirectory,
5154 LPSTARTUPINFOW lpStartupInfo,
5155 LPPROCESS_INFORMATION lpProcessInformation )
5157 FIXME("%p %s %s %p %p %d 0x%08x %p %s %p %p - semi- stub\n", hToken,
5158 debugstr_w(lpApplicationName), debugstr_w(lpCommandLine), lpProcessAttributes,
5159 lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment,
5160 debugstr_w(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
5162 /* We should create the process with a suspended main thread */
5163 if (!CreateProcessW (lpApplicationName,
5165 lpProcessAttributes,
5168 dwCreationFlags, /* CREATE_SUSPENDED */
5172 lpProcessInformation))
5180 /******************************************************************************
5181 * CreateProcessWithLogonW
5183 BOOL WINAPI CreateProcessWithLogonW( LPCWSTR lpUsername, LPCWSTR lpDomain, LPCWSTR lpPassword, DWORD dwLogonFlags,
5184 LPCWSTR lpApplicationName, LPWSTR lpCommandLine, DWORD dwCreationFlags, LPVOID lpEnvironment,
5185 LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation )
5187 FIXME("%s %s %s 0x%08x %s %s 0x%08x %p %s %p %p stub\n", debugstr_w(lpUsername), debugstr_w(lpDomain),
5188 debugstr_w(lpPassword), dwLogonFlags, debugstr_w(lpApplicationName),
5189 debugstr_w(lpCommandLine), dwCreationFlags, lpEnvironment, debugstr_w(lpCurrentDirectory),
5190 lpStartupInfo, lpProcessInformation);
5195 /******************************************************************************
5196 * DuplicateTokenEx [ADVAPI32.@]
5198 BOOL WINAPI DuplicateTokenEx(
5199 HANDLE ExistingTokenHandle, DWORD dwDesiredAccess,
5200 LPSECURITY_ATTRIBUTES lpTokenAttributes,
5201 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
5202 TOKEN_TYPE TokenType,
5203 PHANDLE DuplicateTokenHandle )
5205 OBJECT_ATTRIBUTES ObjectAttributes;
5207 TRACE("%p 0x%08x 0x%08x 0x%08x %p\n", ExistingTokenHandle, dwDesiredAccess,
5208 ImpersonationLevel, TokenType, DuplicateTokenHandle);
5210 InitializeObjectAttributes(
5213 (lpTokenAttributes && lpTokenAttributes->bInheritHandle) ? OBJ_INHERIT : 0,
5215 lpTokenAttributes ? lpTokenAttributes->lpSecurityDescriptor : NULL );
5217 return set_ntstatus( NtDuplicateToken( ExistingTokenHandle,
5222 DuplicateTokenHandle ) );
5225 BOOL WINAPI DuplicateToken(
5226 HANDLE ExistingTokenHandle,
5227 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
5228 PHANDLE DuplicateTokenHandle )
5230 return DuplicateTokenEx( ExistingTokenHandle, TOKEN_IMPERSONATE | TOKEN_QUERY,
5231 NULL, ImpersonationLevel, TokenImpersonation,
5232 DuplicateTokenHandle );
5235 /******************************************************************************
5236 * ComputeStringSidSize
5238 static DWORD ComputeStringSidSize(LPCWSTR StringSid)
5240 if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I(-S)+ */
5245 if (*StringSid == '-')
5251 return GetSidLengthRequired(ctok - 2);
5253 else /* String constant format - Only available in winxp and above */
5257 for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++)
5258 if (!strncmpW(WellKnownSids[i].wstr, StringSid, 2))
5259 return GetSidLengthRequired(WellKnownSids[i].Sid.SubAuthorityCount);
5262 return GetSidLengthRequired(0);
5265 /******************************************************************************
5266 * ParseStringSidToSid
5268 static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes)
5273 TRACE("%s, %p, %p\n", debugstr_w(StringSid), pSid, cBytes);
5276 SetLastError(ERROR_INVALID_PARAMETER);
5277 TRACE("StringSid is NULL, returning FALSE\n");
5281 while (*StringSid == ' ')
5284 *cBytes = ComputeStringSidSize(StringSid);
5285 if (!pisid) /* Simply compute the size */
5287 TRACE("only size requested, returning TRUE\n");
5291 if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I-S-S */
5293 DWORD i = 0, identAuth;
5294 DWORD csubauth = ((*cBytes - GetSidLengthRequired(0)) / sizeof(DWORD));
5296 StringSid += 2; /* Advance to Revision */
5297 pisid->Revision = atoiW(StringSid);
5299 if (pisid->Revision != SDDL_REVISION)
5301 TRACE("Revision %d is unknown\n", pisid->Revision);
5302 goto lend; /* ERROR_INVALID_SID */
5306 TRACE("SubAuthorityCount is 0\n");
5307 goto lend; /* ERROR_INVALID_SID */
5310 pisid->SubAuthorityCount = csubauth;
5312 /* Advance to identifier authority */
5313 while (*StringSid && *StringSid != '-')
5315 if (*StringSid == '-')
5318 /* MS' implementation can't handle values greater than 2^32 - 1, so
5319 * we don't either; assume most significant bytes are always 0
5321 pisid->IdentifierAuthority.Value[0] = 0;
5322 pisid->IdentifierAuthority.Value[1] = 0;
5323 identAuth = atoiW(StringSid);
5324 pisid->IdentifierAuthority.Value[5] = identAuth & 0xff;
5325 pisid->IdentifierAuthority.Value[4] = (identAuth & 0xff00) >> 8;
5326 pisid->IdentifierAuthority.Value[3] = (identAuth & 0xff0000) >> 16;
5327 pisid->IdentifierAuthority.Value[2] = (identAuth & 0xff000000) >> 24;
5329 /* Advance to first sub authority */
5330 while (*StringSid && *StringSid != '-')
5332 if (*StringSid == '-')
5337 pisid->SubAuthority[i++] = atoiW(StringSid);
5339 while (*StringSid && *StringSid != '-')
5341 if (*StringSid == '-')
5345 if (i != pisid->SubAuthorityCount)
5346 goto lend; /* ERROR_INVALID_SID */
5350 else /* String constant format - Only available in winxp and above */
5353 pisid->Revision = SDDL_REVISION;
5355 for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++)
5356 if (!strncmpW(WellKnownSids[i].wstr, StringSid, 2))
5359 pisid->SubAuthorityCount = WellKnownSids[i].Sid.SubAuthorityCount;
5360 pisid->IdentifierAuthority = WellKnownSids[i].Sid.IdentifierAuthority;
5361 for (j = 0; j < WellKnownSids[i].Sid.SubAuthorityCount; j++)
5362 pisid->SubAuthority[j] = WellKnownSids[i].Sid.SubAuthority[j];
5367 FIXME("String constant not supported: %s\n", debugstr_wn(StringSid, 2));
5372 SetLastError(ERROR_INVALID_SID);
5374 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
5378 /******************************************************************************
5379 * GetNamedSecurityInfoA [ADVAPI32.@]
5381 DWORD WINAPI GetNamedSecurityInfoA(LPSTR pObjectName,
5382 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
5383 PSID* ppsidOwner, PSID* ppsidGroup, PACL* ppDacl, PACL* ppSacl,
5384 PSECURITY_DESCRIPTOR* ppSecurityDescriptor)
5389 TRACE("%s %d %d %p %p %p %p %p\n", pObjectName, ObjectType, SecurityInfo,
5390 ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
5392 wstr = SERV_dup(pObjectName);
5393 r = GetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, ppsidOwner,
5394 ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor );
5396 HeapFree( GetProcessHeap(), 0, wstr );
5401 /******************************************************************************
5402 * GetNamedSecurityInfoW [ADVAPI32.@]
5404 DWORD WINAPI GetNamedSecurityInfoW( LPWSTR name, SE_OBJECT_TYPE type,
5405 SECURITY_INFORMATION info, PSID* owner, PSID* group, PACL* dacl,
5406 PACL* sacl, PSECURITY_DESCRIPTOR* descriptor )
5408 DWORD needed, offset;
5409 SECURITY_DESCRIPTOR_RELATIVE *relative = NULL;
5412 TRACE( "%s %d %d %p %p %p %p %p\n", debugstr_w(name), type, info, owner,
5413 group, dacl, sacl, descriptor );
5415 /* A NULL descriptor is allowed if any one of the other pointers is not NULL */
5416 if (!name || !(owner||group||dacl||sacl||descriptor) ) return ERROR_INVALID_PARAMETER;
5418 /* If no descriptor, we have to check that there's a pointer for the requested information */
5419 if( !descriptor && (
5420 ((info & OWNER_SECURITY_INFORMATION) && !owner)
5421 || ((info & GROUP_SECURITY_INFORMATION) && !group)
5422 || ((info & DACL_SECURITY_INFORMATION) && !dacl)
5423 || ((info & SACL_SECURITY_INFORMATION) && !sacl) ))
5424 return ERROR_INVALID_PARAMETER;
5426 needed = !descriptor ? 0 : sizeof(SECURITY_DESCRIPTOR_RELATIVE);
5427 if (info & OWNER_SECURITY_INFORMATION)
5428 needed += sizeof(sidWorld);
5429 if (info & GROUP_SECURITY_INFORMATION)
5430 needed += sizeof(sidWorld);
5431 if (info & DACL_SECURITY_INFORMATION)
5432 needed += WINE_SIZE_OF_WORLD_ACCESS_ACL;
5433 if (info & SACL_SECURITY_INFORMATION)
5434 needed += WINE_SIZE_OF_WORLD_ACCESS_ACL;
5438 /* must be freed by caller */
5439 *descriptor = HeapAlloc( GetProcessHeap(), 0, needed );
5440 if (!*descriptor) return ERROR_NOT_ENOUGH_MEMORY;
5442 if (!InitializeSecurityDescriptor( *descriptor, SECURITY_DESCRIPTOR_REVISION ))
5444 HeapFree( GetProcessHeap(), 0, *descriptor );
5445 return ERROR_INVALID_SECURITY_DESCR;
5448 relative = *descriptor;
5449 relative->Control |= SE_SELF_RELATIVE;
5451 buffer = (BYTE *)relative;
5452 offset = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
5456 buffer = HeapAlloc( GetProcessHeap(), 0, needed );
5457 if (!buffer) return ERROR_NOT_ENOUGH_MEMORY;
5461 if (info & OWNER_SECURITY_INFORMATION)
5463 memcpy( buffer + offset, &sidWorld, sizeof(sidWorld) );
5465 relative->Owner = offset;
5467 *owner = buffer + offset;
5468 offset += sizeof(sidWorld);
5470 if (info & GROUP_SECURITY_INFORMATION)
5472 memcpy( buffer + offset, &sidWorld, sizeof(sidWorld) );
5474 relative->Group = offset;
5476 *group = buffer + offset;
5477 offset += sizeof(sidWorld);
5479 if (info & DACL_SECURITY_INFORMATION)
5481 GetWorldAccessACL( (PACL)(buffer + offset) );
5484 relative->Control |= SE_DACL_PRESENT;
5485 relative->Dacl = offset;
5488 *dacl = (PACL)(buffer + offset);
5489 offset += WINE_SIZE_OF_WORLD_ACCESS_ACL;
5491 if (info & SACL_SECURITY_INFORMATION)
5493 GetWorldAccessACL( (PACL)(buffer + offset) );
5496 relative->Control |= SE_SACL_PRESENT;
5497 relative->Sacl = offset;
5500 *sacl = (PACL)(buffer + offset);
5503 return ERROR_SUCCESS;
5506 /******************************************************************************
5507 * GetNamedSecurityInfoExW [ADVAPI32.@]
5509 DWORD WINAPI GetNamedSecurityInfoExW( LPCWSTR object, SE_OBJECT_TYPE type,
5510 SECURITY_INFORMATION info, LPCWSTR provider, LPCWSTR property,
5511 PACTRL_ACCESSW* access_list, PACTRL_AUDITW* audit_list, LPWSTR* owner, LPWSTR* group )
5513 FIXME("(%s, %d, %d, %s, %s, %p, %p, %p, %p) stub\n", debugstr_w(object), type, info,
5514 debugstr_w(provider), debugstr_w(property), access_list, audit_list, owner, group);
5515 return ERROR_CALL_NOT_IMPLEMENTED;
5518 /******************************************************************************
5519 * GetNamedSecurityInfoExA [ADVAPI32.@]
5521 DWORD WINAPI GetNamedSecurityInfoExA( LPCSTR object, SE_OBJECT_TYPE type,
5522 SECURITY_INFORMATION info, LPCSTR provider, LPCSTR property,
5523 PACTRL_ACCESSA* access_list, PACTRL_AUDITA* audit_list, LPSTR* owner, LPSTR* group )
5525 FIXME("(%s, %d, %d, %s, %s, %p, %p, %p, %p) stub\n", debugstr_a(object), type, info,
5526 debugstr_a(provider), debugstr_a(property), access_list, audit_list, owner, group);
5527 return ERROR_CALL_NOT_IMPLEMENTED;
5530 /******************************************************************************
5531 * DecryptFileW [ADVAPI32.@]
5533 BOOL WINAPI DecryptFileW(LPCWSTR lpFileName, DWORD dwReserved)
5535 FIXME("%s %08x\n", debugstr_w(lpFileName), dwReserved);
5539 /******************************************************************************
5540 * DecryptFileA [ADVAPI32.@]
5542 BOOL WINAPI DecryptFileA(LPCSTR lpFileName, DWORD dwReserved)
5544 FIXME("%s %08x\n", debugstr_a(lpFileName), dwReserved);
5548 /******************************************************************************
5549 * EncryptFileW [ADVAPI32.@]
5551 BOOL WINAPI EncryptFileW(LPCWSTR lpFileName)
5553 FIXME("%s\n", debugstr_w(lpFileName));
5557 /******************************************************************************
5558 * EncryptFileA [ADVAPI32.@]
5560 BOOL WINAPI EncryptFileA(LPCSTR lpFileName)
5562 FIXME("%s\n", debugstr_a(lpFileName));
5566 /******************************************************************************
5567 * FileEncryptionStatusW [ADVAPI32.@]
5569 BOOL WINAPI FileEncryptionStatusW(LPCWSTR lpFileName, LPDWORD lpStatus)
5571 FIXME("(%s %p): stub\n", debugstr_w(lpFileName), lpStatus);
5574 *lpStatus = FILE_SYSTEM_NOT_SUPPORT;
5578 /******************************************************************************
5579 * FileEncryptionStatusA [ADVAPI32.@]
5581 BOOL WINAPI FileEncryptionStatusA(LPCSTR lpFileName, LPDWORD lpStatus)
5583 FIXME("(%s %p): stub\n", debugstr_a(lpFileName), lpStatus);
5586 *lpStatus = FILE_SYSTEM_NOT_SUPPORT;
5590 /******************************************************************************
5591 * SetSecurityInfo [ADVAPI32.@]
5593 DWORD WINAPI SetSecurityInfo(HANDLE handle, SE_OBJECT_TYPE ObjectType,
5594 SECURITY_INFORMATION SecurityInfo, PSID psidOwner,
5595 PSID psidGroup, PACL pDacl, PACL pSacl) {
5597 return ERROR_SUCCESS;
5600 /******************************************************************************
5601 * SaferCreateLevel [ADVAPI32.@]
5603 BOOL WINAPI SaferCreateLevel(DWORD ScopeId, DWORD LevelId, DWORD OpenFlags,
5604 SAFER_LEVEL_HANDLE* LevelHandle, LPVOID lpReserved)
5606 FIXME("(%u, %x, %u, %p, %p) stub\n", ScopeId, LevelId, OpenFlags, LevelHandle, lpReserved);
5608 *LevelHandle = (SAFER_LEVEL_HANDLE)0xdeadbeef;
5612 /******************************************************************************
5613 * SaferComputeTokenFromLevel [ADVAPI32.@]
5615 BOOL WINAPI SaferComputeTokenFromLevel(SAFER_LEVEL_HANDLE handle, HANDLE token, PHANDLE access_token,
5616 DWORD flags, LPVOID reserved)
5618 FIXME("(%p, %p, %p, %x, %p) stub\n", handle, token, access_token, flags, reserved);
5620 *access_token = (HANDLE)0xdeadbeef;
5624 /******************************************************************************
5625 * SaferCloseLevel [ADVAPI32.@]
5627 BOOL WINAPI SaferCloseLevel(SAFER_LEVEL_HANDLE handle)
5629 FIXME("(%p) stub\n", handle);
5633 DWORD WINAPI TreeResetNamedSecurityInfoW( LPWSTR pObjectName,
5634 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
5635 PSID pOwner, PSID pGroup, PACL pDacl, PACL pSacl,
5636 BOOL KeepExplicit, FN_PROGRESS fnProgress,
5637 PROG_INVOKE_SETTING ProgressInvokeSetting, PVOID Args)
5639 FIXME("(%s, %i, %i, %p, %p, %p, %p, %i, %p, %i, %p Stub\n",
5640 debugstr_w(pObjectName), ObjectType, SecurityInfo, pOwner, pGroup,
5641 pDacl, pSacl, KeepExplicit, fnProgress, ProgressInvokeSetting, Args);
5643 return ERROR_SUCCESS;
5646 /******************************************************************************
5647 * SaferGetPolicyInformation [ADVAPI32.@]
5649 BOOL WINAPI SaferGetPolicyInformation(DWORD scope, SAFER_POLICY_INFO_CLASS class, DWORD size,
5650 PVOID buffer, PDWORD required, LPVOID lpReserved)
5652 FIXME("(%u %u %u %p %p %p) stub\n", scope, class, size, buffer, required, lpReserved);
5656 /******************************************************************************
5657 * SaferSetLevelInformation [ADVAPI32.@]
5659 BOOL WINAPI SaferSetLevelInformation(SAFER_LEVEL_HANDLE handle, SAFER_OBJECT_INFO_CLASS infotype,
5660 LPVOID buffer, DWORD size)
5662 FIXME("(%p %u %p %u) stub\n", handle, infotype, buffer, size);