2 * Copyright 1999, 2000 Juergen Schmied <juergen.schmied@debitel.net>
3 * Copyright 2003 CodeWeavers Inc. (Ulrich Czekalla)
4 * Copyright 2006 Robert Reif
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define WIN32_NO_STATUS
40 #include "advapi32_misc.h"
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
47 static BOOL
ParseStringSidToSid(LPCWSTR StringSid
, PSID pSid
, LPDWORD cBytes
);
48 static BOOL
ParseStringAclToAcl(LPCWSTR StringAcl
, LPDWORD lpdwFlags
,
49 PACL pAcl
, LPDWORD cBytes
);
50 static BYTE
ParseAceStringFlags(LPCWSTR
* StringAcl
);
51 static BYTE
ParseAceStringType(LPCWSTR
* StringAcl
);
52 static DWORD
ParseAceStringRights(LPCWSTR
* StringAcl
);
53 static BOOL
ParseStringSecurityDescriptorToSecurityDescriptor(
54 LPCWSTR StringSecurityDescriptor
,
55 SECURITY_DESCRIPTOR
* SecurityDescriptor
,
57 static DWORD
ParseAclStringFlags(LPCWSTR
* StringAcl
);
59 typedef struct _ACEFLAG
63 } ACEFLAG
, *LPACEFLAG
;
65 typedef struct _MAX_SID
67 /* same fields as struct _SID */
69 BYTE SubAuthorityCount
;
70 SID_IDENTIFIER_AUTHORITY IdentifierAuthority
;
71 DWORD SubAuthority
[SID_MAX_SUB_AUTHORITIES
];
74 typedef struct WELLKNOWNSID
77 WELL_KNOWN_SID_TYPE Type
;
81 static const WELLKNOWNSID WellKnownSids
[] =
83 { {0,0}, WinNullSid
, { SID_REVISION
, 1, { SECURITY_NULL_SID_AUTHORITY
}, { SECURITY_NULL_RID
} } },
84 { {'W','D'}, WinWorldSid
, { SID_REVISION
, 1, { SECURITY_WORLD_SID_AUTHORITY
}, { SECURITY_WORLD_RID
} } },
85 { {0,0}, WinLocalSid
, { SID_REVISION
, 1, { SECURITY_LOCAL_SID_AUTHORITY
}, { SECURITY_LOCAL_RID
} } },
86 { {'C','O'}, WinCreatorOwnerSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_OWNER_RID
} } },
87 { {'C','G'}, WinCreatorGroupSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_GROUP_RID
} } },
88 { {0,0}, WinCreatorOwnerServerSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_OWNER_SERVER_RID
} } },
89 { {0,0}, WinCreatorGroupServerSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_GROUP_SERVER_RID
} } },
90 { {0,0}, WinNtAuthoritySid
, { SID_REVISION
, 0, { SECURITY_NT_AUTHORITY
}, { SECURITY_NULL_RID
} } },
91 { {0,0}, WinDialupSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_DIALUP_RID
} } },
92 { {'N','U'}, WinNetworkSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_NETWORK_RID
} } },
93 { {0,0}, WinBatchSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_BATCH_RID
} } },
94 { {'I','U'}, WinInteractiveSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_INTERACTIVE_RID
} } },
95 { {'S','U'}, WinServiceSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_SERVICE_RID
} } },
96 { {'A','N'}, WinAnonymousSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_ANONYMOUS_LOGON_RID
} } },
97 { {0,0}, WinProxySid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_PROXY_RID
} } },
98 { {'E','D'}, WinEnterpriseControllersSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_ENTERPRISE_CONTROLLERS_RID
} } },
99 { {'P','S'}, WinSelfSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_PRINCIPAL_SELF_RID
} } },
100 { {'A','U'}, WinAuthenticatedUserSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_AUTHENTICATED_USER_RID
} } },
101 { {'R','C'}, WinRestrictedCodeSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_RESTRICTED_CODE_RID
} } },
102 { {0,0}, WinTerminalServerSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_TERMINAL_SERVER_RID
} } },
103 { {0,0}, WinRemoteLogonIdSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_REMOTE_LOGON_RID
} } },
104 { {'S','Y'}, WinLocalSystemSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_LOCAL_SYSTEM_RID
} } },
105 { {'L','S'}, WinLocalServiceSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_LOCAL_SERVICE_RID
} } },
106 { {'N','S'}, WinNetworkServiceSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_NETWORK_SERVICE_RID
} } },
107 { {0,0}, WinBuiltinDomainSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
} } },
108 { {'B','A'}, WinBuiltinAdministratorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_ADMINS
} } },
109 { {'B','U'}, WinBuiltinUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_USERS
} } },
110 { {'B','G'}, WinBuiltinGuestsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_GUESTS
} } },
111 { {'P','U'}, WinBuiltinPowerUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_POWER_USERS
} } },
112 { {'A','O'}, WinBuiltinAccountOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_ACCOUNT_OPS
} } },
113 { {'S','O'}, WinBuiltinSystemOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_SYSTEM_OPS
} } },
114 { {'P','O'}, WinBuiltinPrintOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_PRINT_OPS
} } },
115 { {'B','O'}, WinBuiltinBackupOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_BACKUP_OPS
} } },
116 { {'R','E'}, WinBuiltinReplicatorSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_REPLICATOR
} } },
117 { {'R','U'}, WinBuiltinPreWindows2000CompatibleAccessSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_PREW2KCOMPACCESS
} } },
118 { {'R','D'}, WinBuiltinRemoteDesktopUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS
} } },
119 { {'N','O'}, WinBuiltinNetworkConfigurationOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS
} } },
120 { {0,0}, WinNTLMAuthenticationSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_PACKAGE_BASE_RID
, SECURITY_PACKAGE_NTLM_RID
} } },
121 { {0,0}, WinDigestAuthenticationSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_PACKAGE_BASE_RID
, SECURITY_PACKAGE_DIGEST_RID
} } },
122 { {0,0}, WinSChannelAuthenticationSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_PACKAGE_BASE_RID
, SECURITY_PACKAGE_SCHANNEL_RID
} } },
123 { {0,0}, WinThisOrganizationSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_THIS_ORGANIZATION_RID
} } },
124 { {0,0}, WinOtherOrganizationSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_OTHER_ORGANIZATION_RID
} } },
125 { {0,0}, WinBuiltinIncomingForestTrustBuildersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_INCOMING_FOREST_TRUST_BUILDERS
} } },
126 { {0,0}, WinBuiltinPerfMonitoringUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_MONITORING_USERS
} } },
127 { {0,0}, WinBuiltinPerfLoggingUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_LOGGING_USERS
} } },
128 { {0,0}, WinBuiltinAuthorizationAccessSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_AUTHORIZATIONACCESS
} } },
129 { {0,0}, WinBuiltinTerminalServerLicenseServersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_TS_LICENSE_SERVERS
} } },
132 /* these SIDs must be constructed as relative to some domain - only the RID is well-kown */
133 typedef struct WELLKOWNRID
135 WELL_KNOWN_SID_TYPE Type
;
139 WELLKNOWNRID WellKnownRids
[] = {
140 { WinAccountAdministratorSid
, DOMAIN_USER_RID_ADMIN
},
141 { WinAccountGuestSid
, DOMAIN_USER_RID_GUEST
},
142 { WinAccountKrbtgtSid
, DOMAIN_USER_RID_KRBTGT
},
143 { WinAccountDomainAdminsSid
, DOMAIN_GROUP_RID_ADMINS
},
144 { WinAccountDomainUsersSid
, DOMAIN_GROUP_RID_USERS
},
145 { WinAccountDomainGuestsSid
, DOMAIN_GROUP_RID_GUESTS
},
146 { WinAccountComputersSid
, DOMAIN_GROUP_RID_COMPUTERS
},
147 { WinAccountControllersSid
, DOMAIN_GROUP_RID_CONTROLLERS
},
148 { WinAccountCertAdminsSid
, DOMAIN_GROUP_RID_CERT_ADMINS
},
149 { WinAccountSchemaAdminsSid
, DOMAIN_GROUP_RID_SCHEMA_ADMINS
},
150 { WinAccountEnterpriseAdminsSid
, DOMAIN_GROUP_RID_ENTERPRISE_ADMINS
},
151 { WinAccountPolicyAdminsSid
, DOMAIN_GROUP_RID_POLICY_ADMINS
},
152 { WinAccountRasAndIasServersSid
, DOMAIN_ALIAS_RID_RAS_SERVERS
},
156 static SID
const sidWorld
= { SID_REVISION
, 1, { SECURITY_WORLD_SID_AUTHORITY
} , { SECURITY_WORLD_RID
} };
158 typedef struct _AccountSid
{
159 WELL_KNOWN_SID_TYPE type
;
162 SID_NAME_USE name_use
;
165 static const WCHAR Account_Operators
[] = { 'A','c','c','o','u','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
166 static const WCHAR Administrator
[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0 };
167 static const WCHAR Administrators
[] = { 'A','d','m','i','n','i','s','t','r','a','t','o','r','s',0 };
168 static const WCHAR ANONYMOUS_LOGON
[] = { 'A','N','O','N','Y','M','O','U','S',' ','L','O','G','O','N',0 };
169 static const WCHAR Authenticated_Users
[] = { 'A','u','t','h','e','n','t','i','c','a','t','e','d',' ','U','s','e','r','s',0 };
170 static const WCHAR Backup_Operators
[] = { 'B','a','c','k','u','p',' ','O','p','e','r','a','t','o','r','s',0 };
171 static const WCHAR BATCH
[] = { 'B','A','T','C','H',0 };
172 static const WCHAR Blank
[] = { 0 };
173 static const WCHAR BUILTIN
[] = { 'B','U','I','L','T','I','N',0 };
174 static const WCHAR Cert_Publishers
[] = { 'C','e','r','t',' ','P','u','b','l','i','s','h','e','r','s',0 };
175 static const WCHAR CREATOR_GROUP
[] = { 'C','R','E','A','T','O','R',' ','G','R','O','U','P',0 };
176 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 };
177 static const WCHAR CREATOR_OWNER
[] = { 'C','R','E','A','T','O','R',' ','O','W','N','E','R',0 };
178 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 };
179 static const WCHAR DIALUP
[] = { 'D','I','A','L','U','P',0 };
180 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 };
181 static const WCHAR DOMAIN
[] = {'D','O','M','A','I','N',0};
182 static const WCHAR Domain_Admins
[] = { 'D','o','m','a','i','n',' ','A','d','m','i','n','s',0 };
183 static const WCHAR Domain_Computers
[] = { 'D','o','m','a','i','n',' ','C','o','m','p','u','t','e','r','s',0 };
184 static const WCHAR Domain_Controllers
[] = { 'D','o','m','a','i','n',' ','C','o','n','t','r','o','l','l','e','r','s',0 };
185 static const WCHAR Domain_Guests
[] = { 'D','o','m','a','i','n',' ','G','u','e','s','t','s',0 };
186 static const WCHAR Domain_Users
[] = { 'D','o','m','a','i','n',' ','U','s','e','r','s',0 };
187 static const WCHAR Enterprise_Admins
[] = { 'E','n','t','e','r','p','r','i','s','e',' ','A','d','m','i','n','s',0 };
188 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 };
189 static const WCHAR Everyone
[] = { 'E','v','e','r','y','o','n','e',0 };
190 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 };
191 static const WCHAR Guest
[] = { 'G','u','e','s','t',0 };
192 static const WCHAR Guests
[] = { 'G','u','e','s','t','s',0 };
193 static const WCHAR INTERACTIVE
[] = { 'I','N','T','E','R','A','C','T','I','V','E',0 };
194 static const WCHAR LOCAL
[] = { 'L','O','C','A','L',0 };
195 static const WCHAR LOCAL_SERVICE
[] = { 'L','O','C','A','L',' ','S','E','R','V','I','C','E',0 };
196 static const WCHAR NETWORK
[] = { 'N','E','T','W','O','R','K',0 };
197 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 };
198 static const WCHAR NETWORK_SERVICE
[] = { 'N','E','T','W','O','R','K',' ','S','E','R','V','I','C','E',0 };
199 static const WCHAR NT_AUTHORITY
[] = { 'N','T',' ','A','U','T','H','O','R','I','T','Y',0 };
200 static const WCHAR NT_Pseudo_Domain
[] = { 'N','T',' ','P','s','e','u','d','o',' ','D','o','m','a','i','n',0 };
201 static const WCHAR NTML_Authentication
[] = { 'N','T','M','L',' ','A','u','t','h','e','n','t','i','c','a','t','i','o','n',0 };
202 static const WCHAR NULL_SID
[] = { 'N','U','L','L',' ','S','I','D',0 };
203 static const WCHAR Other_Organization
[] = { 'O','t','h','e','r',' ','O','r','g','a','n','i','z','a','t','i','o','n',0 };
204 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 };
205 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 };
206 static const WCHAR Power_Users
[] = { 'P','o','w','e','r',' ','U','s','e','r','s',0 };
207 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 };
208 static const WCHAR Print_Operators
[] = { 'P','r','i','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
209 static const WCHAR PROXY
[] = { 'P','R','O','X','Y',0 };
210 static const WCHAR RAS_and_IAS_Servers
[] = { 'R','A','S',' ','a','n','d',' ','I','A','S',' ','S','e','r','v','e','r','s',0 };
211 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 };
212 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 };
213 static const WCHAR Replicators
[] = { 'R','e','p','l','i','c','a','t','o','r','s',0 };
214 static const WCHAR RESTRICTED
[] = { 'R','E','S','T','R','I','C','T','E','D',0 };
215 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 };
216 static const WCHAR Schema_Admins
[] = { 'S','c','h','e','m','a',' ','A','d','m','i','n','s',0 };
217 static const WCHAR SELF
[] = { 'S','E','L','F',0 };
218 static const WCHAR Server_Operators
[] = { 'S','e','r','v','e','r',' ','O','p','e','r','a','t','o','r','s',0 };
219 static const WCHAR SERVICE
[] = { 'S','E','R','V','I','C','E',0 };
220 static const WCHAR SYSTEM
[] = { 'S','Y','S','T','E','M',0 };
221 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 };
222 static const WCHAR This_Organization
[] = { 'T','h','i','s',' ','O','r','g','a','n','i','z','a','t','i','o','n',0 };
223 static const WCHAR Users
[] = { 'U','s','e','r','s',0 };
225 static const AccountSid ACCOUNT_SIDS
[] = {
226 { WinNullSid
, NULL_SID
, Blank
, SidTypeWellKnownGroup
},
227 { WinWorldSid
, Everyone
, Blank
, SidTypeWellKnownGroup
},
228 { WinLocalSid
, LOCAL
, Blank
, SidTypeWellKnownGroup
},
229 { WinCreatorOwnerSid
, CREATOR_OWNER
, Blank
, SidTypeWellKnownGroup
},
230 { WinCreatorGroupSid
, CREATOR_GROUP
, Blank
, SidTypeWellKnownGroup
},
231 { WinCreatorOwnerServerSid
, CREATOR_OWNER_SERVER
, Blank
, SidTypeWellKnownGroup
},
232 { WinCreatorGroupServerSid
, CREATOR_GROUP_SERVER
, Blank
, SidTypeWellKnownGroup
},
233 { WinNtAuthoritySid
, NT_Pseudo_Domain
, NT_Pseudo_Domain
, SidTypeDomain
},
234 { WinDialupSid
, DIALUP
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
235 { WinNetworkSid
, NETWORK
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
236 { WinBatchSid
, BATCH
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
237 { WinInteractiveSid
, INTERACTIVE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
238 { WinServiceSid
, SERVICE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
239 { WinAnonymousSid
, ANONYMOUS_LOGON
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
240 { WinProxySid
, PROXY
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
241 { WinEnterpriseControllersSid
, ENTERPRISE_DOMAIN_CONTROLLERS
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
242 { WinSelfSid
, SELF
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
243 { WinAuthenticatedUserSid
, Authenticated_Users
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
244 { WinRestrictedCodeSid
, RESTRICTED
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
245 { WinTerminalServerSid
, TERMINAL_SERVER_USER
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
246 { WinRemoteLogonIdSid
, REMOTE_INTERACTIVE_LOGON
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
247 { WinLocalSystemSid
, SYSTEM
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
248 { WinLocalServiceSid
, LOCAL_SERVICE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
249 { WinNetworkServiceSid
, NETWORK_SERVICE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
250 { WinBuiltinDomainSid
, BUILTIN
, BUILTIN
, SidTypeDomain
},
251 { WinBuiltinAdministratorsSid
, Administrators
, BUILTIN
, SidTypeAlias
},
252 { WinBuiltinUsersSid
, Users
, BUILTIN
, SidTypeAlias
},
253 { WinBuiltinGuestsSid
, Guests
, BUILTIN
, SidTypeAlias
},
254 { WinBuiltinPowerUsersSid
, Power_Users
, BUILTIN
, SidTypeAlias
},
255 { WinBuiltinAccountOperatorsSid
, Account_Operators
, BUILTIN
, SidTypeAlias
},
256 { WinBuiltinSystemOperatorsSid
, Server_Operators
, BUILTIN
, SidTypeAlias
},
257 { WinBuiltinPrintOperatorsSid
, Print_Operators
, BUILTIN
, SidTypeAlias
},
258 { WinBuiltinBackupOperatorsSid
, Backup_Operators
, BUILTIN
, SidTypeAlias
},
259 { WinBuiltinReplicatorSid
, Replicators
, BUILTIN
, SidTypeAlias
},
260 { WinBuiltinPreWindows2000CompatibleAccessSid
, Pre_Windows_2000_Compatible_Access
, BUILTIN
, SidTypeAlias
},
261 { WinBuiltinRemoteDesktopUsersSid
, Remote_Desktop_Users
, BUILTIN
, SidTypeAlias
},
262 { WinBuiltinNetworkConfigurationOperatorsSid
, Network_Configuration_Operators
, BUILTIN
, SidTypeAlias
},
263 { WinNTLMAuthenticationSid
, NTML_Authentication
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
264 { WinDigestAuthenticationSid
, Digest_Authentication
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
265 { WinSChannelAuthenticationSid
, SChannel_Authentication
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
266 { WinThisOrganizationSid
, This_Organization
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
267 { WinOtherOrganizationSid
, Other_Organization
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
268 { WinBuiltinPerfMonitoringUsersSid
, Performance_Monitor_Users
, BUILTIN
, SidTypeAlias
},
269 { WinBuiltinPerfLoggingUsersSid
, Performance_Log_Users
, BUILTIN
, SidTypeAlias
},
274 static const WCHAR SDDL_READ_CONTROL
[] = {'R','C',0};
275 static const WCHAR SDDL_WRITE_DAC
[] = {'W','D',0};
276 static const WCHAR SDDL_WRITE_OWNER
[] = {'W','O',0};
277 static const WCHAR SDDL_STANDARD_DELETE
[] = {'S','D',0};
279 static const WCHAR SDDL_READ_PROPERTY
[] = {'R','P',0};
280 static const WCHAR SDDL_WRITE_PROPERTY
[] = {'W','P',0};
281 static const WCHAR SDDL_CREATE_CHILD
[] = {'C','C',0};
282 static const WCHAR SDDL_DELETE_CHILD
[] = {'D','C',0};
283 static const WCHAR SDDL_LIST_CHILDREN
[] = {'L','C',0};
284 static const WCHAR SDDL_SELF_WRITE
[] = {'S','W',0};
285 static const WCHAR SDDL_LIST_OBJECT
[] = {'L','O',0};
286 static const WCHAR SDDL_DELETE_TREE
[] = {'D','T',0};
287 static const WCHAR SDDL_CONTROL_ACCESS
[] = {'C','R',0};
289 static const WCHAR SDDL_FILE_ALL
[] = {'F','A',0};
290 static const WCHAR SDDL_FILE_READ
[] = {'F','R',0};
291 static const WCHAR SDDL_FILE_WRITE
[] = {'F','W',0};
292 static const WCHAR SDDL_FILE_EXECUTE
[] = {'F','X',0};
294 static const WCHAR SDDL_KEY_ALL
[] = {'K','A',0};
295 static const WCHAR SDDL_KEY_READ
[] = {'K','R',0};
296 static const WCHAR SDDL_KEY_WRITE
[] = {'K','W',0};
297 static const WCHAR SDDL_KEY_EXECUTE
[] = {'K','X',0};
299 static const WCHAR SDDL_GENERIC_ALL
[] = {'G','A',0};
300 static const WCHAR SDDL_GENERIC_READ
[] = {'G','R',0};
301 static const WCHAR SDDL_GENERIC_WRITE
[] = {'G','W',0};
302 static const WCHAR SDDL_GENERIC_EXECUTE
[] = {'G','X',0};
307 static const WCHAR SDDL_PROTECTED
[] = {'P',0};
308 static const WCHAR SDDL_AUTO_INHERIT_REQ
[] = {'A','R',0};
309 static const WCHAR SDDL_AUTO_INHERITED
[] = {'A','I',0};
314 static const WCHAR SDDL_ACCESS_ALLOWED
[] = {'A',0};
315 static const WCHAR SDDL_ACCESS_DENIED
[] = {'D',0};
316 static const WCHAR SDDL_OBJECT_ACCESS_ALLOWED
[] = {'O','A',0};
317 static const WCHAR SDDL_OBJECT_ACCESS_DENIED
[] = {'O','D',0};
318 static const WCHAR SDDL_AUDIT
[] = {'A','U',0};
319 static const WCHAR SDDL_ALARM
[] = {'A','L',0};
320 static const WCHAR SDDL_OBJECT_AUDIT
[] = {'O','U',0};
321 static const WCHAR SDDL_OBJECT_ALARMp
[] = {'O','L',0};
326 static const WCHAR SDDL_CONTAINER_INHERIT
[] = {'C','I',0};
327 static const WCHAR SDDL_OBJECT_INHERIT
[] = {'O','I',0};
328 static const WCHAR SDDL_NO_PROPAGATE
[] = {'N','P',0};
329 static const WCHAR SDDL_INHERIT_ONLY
[] = {'I','O',0};
330 static const WCHAR SDDL_INHERITED
[] = {'I','D',0};
331 static const WCHAR SDDL_AUDIT_SUCCESS
[] = {'S','A',0};
332 static const WCHAR SDDL_AUDIT_FAILURE
[] = {'F','A',0};
334 const char * debugstr_sid(PSID sid
)
337 SID
* psid
= (SID
*)sid
;
342 auth
= psid
->IdentifierAuthority
.Value
[5] +
343 (psid
->IdentifierAuthority
.Value
[4] << 8) +
344 (psid
->IdentifierAuthority
.Value
[3] << 16) +
345 (psid
->IdentifierAuthority
.Value
[2] << 24);
347 switch (psid
->SubAuthorityCount
) {
349 return wine_dbg_sprintf("S-%d-%d", psid
->Revision
, auth
);
351 return wine_dbg_sprintf("S-%d-%d-%u", psid
->Revision
, auth
,
352 psid
->SubAuthority
[0]);
354 return wine_dbg_sprintf("S-%d-%d-%u-%u", psid
->Revision
, auth
,
355 psid
->SubAuthority
[0], psid
->SubAuthority
[1]);
357 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u", psid
->Revision
, auth
,
358 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2]);
360 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u", psid
->Revision
, auth
,
361 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
362 psid
->SubAuthority
[3]);
364 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
365 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
366 psid
->SubAuthority
[3], psid
->SubAuthority
[4]);
368 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
369 psid
->SubAuthority
[3], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
370 psid
->SubAuthority
[0], psid
->SubAuthority
[4], psid
->SubAuthority
[5]);
372 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
373 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
374 psid
->SubAuthority
[3], psid
->SubAuthority
[4], psid
->SubAuthority
[5],
375 psid
->SubAuthority
[6]);
377 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
378 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
379 psid
->SubAuthority
[3], psid
->SubAuthority
[4], psid
->SubAuthority
[5],
380 psid
->SubAuthority
[6], psid
->SubAuthority
[7]);
385 /* set last error code from NT status and get the proper boolean return value */
386 /* used for functions that are a simple wrapper around the corresponding ntdll API */
387 static inline BOOL
set_ntstatus( NTSTATUS status
)
389 if (status
) SetLastError( RtlNtStatusToDosError( status
));
393 #define WINE_SIZE_OF_WORLD_ACCESS_ACL (sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD))
395 static void GetWorldAccessACL(PACL pACL
)
397 PACCESS_ALLOWED_ACE pACE
= (PACCESS_ALLOWED_ACE
) (pACL
+ 1);
399 pACL
->AclRevision
= ACL_REVISION
;
401 pACL
->AclSize
= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
405 pACE
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
406 pACE
->Header
.AceFlags
= CONTAINER_INHERIT_ACE
;
407 pACE
->Header
.AceSize
= sizeof(ACCESS_ALLOWED_ACE
) + sizeof(sidWorld
) - sizeof(DWORD
);
408 pACE
->Mask
= 0xf3ffffff; /* Everything except reserved bits */
409 memcpy(&pACE
->SidStart
, &sidWorld
, sizeof(sidWorld
));
412 /************************************************************
413 * ADVAPI_IsLocalComputer
415 * Checks whether the server name indicates local machine.
417 BOOL
ADVAPI_IsLocalComputer(LPCWSTR ServerName
)
419 DWORD dwSize
= MAX_COMPUTERNAME_LENGTH
+ 1;
423 if (!ServerName
|| !ServerName
[0])
426 buf
= HeapAlloc(GetProcessHeap(), 0, dwSize
* sizeof(WCHAR
));
427 Result
= GetComputerNameW(buf
, &dwSize
);
428 if (Result
&& (ServerName
[0] == '\\') && (ServerName
[1] == '\\'))
430 Result
= Result
&& !lstrcmpW(ServerName
, buf
);
431 HeapFree(GetProcessHeap(), 0, buf
);
436 /************************************************************
437 * ADVAPI_GetComputerSid
439 * Reads the computer SID from the registry.
441 BOOL
ADVAPI_GetComputerSid(PSID sid
)
446 static const WCHAR Account
[] = { 'S','E','C','U','R','I','T','Y','\\','S','A','M','\\','D','o','m','a','i','n','s','\\','A','c','c','o','u','n','t',0 };
447 static const WCHAR V
[] = { 'V',0 };
449 if ((ret
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, Account
, 0,
450 KEY_READ
, &key
)) == ERROR_SUCCESS
)
453 ret
= RegQueryValueExW(key
, V
, NULL
, NULL
, NULL
, &size
);
454 if (ret
== ERROR_MORE_DATA
|| ret
== ERROR_SUCCESS
)
456 BYTE
* data
= HeapAlloc(GetProcessHeap(), 0, size
);
459 if ((ret
= RegQueryValueExW(key
, V
, NULL
, NULL
,
460 data
, &size
)) == ERROR_SUCCESS
)
462 /* the SID is in the last 24 bytes of the binary data */
463 CopyMemory(sid
, &data
[size
-24], 24);
466 HeapFree(GetProcessHeap(), 0, data
);
472 if(retval
== TRUE
) return retval
;
474 /* create a new random SID */
475 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Account
,
476 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
) == ERROR_SUCCESS
)
479 SID_IDENTIFIER_AUTHORITY identifierAuthority
= {SECURITY_NT_AUTHORITY
};
482 if (RtlGenRandom(&id
, sizeof(id
)))
484 if (AllocateAndInitializeSid(&identifierAuthority
, 4, SECURITY_NT_NON_UNIQUE
, id
[0], id
[1], id
[2], 0, 0, 0, 0, &new_sid
))
486 if (RegSetValueExW(key
, V
, 0, REG_BINARY
, new_sid
, GetLengthSid(new_sid
)) == ERROR_SUCCESS
)
487 retval
= CopySid(GetLengthSid(new_sid
), sid
, new_sid
);
498 /* ##############################
499 ###### TOKEN FUNCTIONS ######
500 ##############################
503 /******************************************************************************
504 * OpenProcessToken [ADVAPI32.@]
505 * Opens the access token associated with a process handle.
508 * ProcessHandle [I] Handle to process
509 * DesiredAccess [I] Desired access to process
510 * TokenHandle [O] Pointer to handle of open access token
513 * Success: TRUE. TokenHandle contains the access token.
517 * See NtOpenProcessToken.
520 OpenProcessToken( HANDLE ProcessHandle
, DWORD DesiredAccess
,
521 HANDLE
*TokenHandle
)
523 return set_ntstatus(NtOpenProcessToken( ProcessHandle
, DesiredAccess
, TokenHandle
));
526 /******************************************************************************
527 * OpenThreadToken [ADVAPI32.@]
529 * Opens the access token associated with a thread handle.
532 * ThreadHandle [I] Handle to process
533 * DesiredAccess [I] Desired access to the thread
535 * TokenHandle [O] Destination for the token handle
538 * Success: TRUE. TokenHandle contains the access token.
542 * See NtOpenThreadToken.
545 OpenThreadToken( HANDLE ThreadHandle
, DWORD DesiredAccess
,
546 BOOL OpenAsSelf
, HANDLE
*TokenHandle
)
548 return set_ntstatus( NtOpenThreadToken(ThreadHandle
, DesiredAccess
, OpenAsSelf
, TokenHandle
));
552 AdjustTokenGroups( HANDLE TokenHandle
, BOOL ResetToDefault
, PTOKEN_GROUPS NewState
,
553 DWORD BufferLength
, PTOKEN_GROUPS PreviousState
, PDWORD ReturnLength
)
555 return set_ntstatus( NtAdjustGroupsToken(TokenHandle
, ResetToDefault
, NewState
, BufferLength
,
556 PreviousState
, ReturnLength
));
559 /******************************************************************************
560 * AdjustTokenPrivileges [ADVAPI32.@]
562 * Adjust the privileges of an open token handle.
565 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
566 * DisableAllPrivileges [I] TRUE=Remove all privileges, FALSE=Use NewState
567 * NewState [I] Desired new privileges of the token
568 * BufferLength [I] Length of NewState
569 * PreviousState [O] Destination for the previous state
570 * ReturnLength [I/O] Size of PreviousState
574 * Success: TRUE. Privileges are set to NewState and PreviousState is updated.
578 * See NtAdjustPrivilegesToken.
581 AdjustTokenPrivileges( HANDLE TokenHandle
, BOOL DisableAllPrivileges
,
582 PTOKEN_PRIVILEGES NewState
, DWORD BufferLength
,
583 PTOKEN_PRIVILEGES PreviousState
, PDWORD ReturnLength
)
589 status
= NtAdjustPrivilegesToken(TokenHandle
, DisableAllPrivileges
,
590 NewState
, BufferLength
, PreviousState
,
592 SetLastError( RtlNtStatusToDosError( status
));
593 if ((status
== STATUS_SUCCESS
) || (status
== STATUS_NOT_ALL_ASSIGNED
))
599 /******************************************************************************
600 * CheckTokenMembership [ADVAPI32.@]
602 * Determine if an access token is a member of a SID.
605 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
606 * SidToCheck [I] SID that possibly contains the token
607 * IsMember [O] Destination for result.
610 * Success: TRUE. IsMember is TRUE if TokenHandle is a member, FALSE otherwise.
614 CheckTokenMembership( HANDLE TokenHandle
, PSID SidToCheck
,
617 FIXME("(%p %p %p) stub!\n", TokenHandle
, SidToCheck
, IsMember
);
623 /******************************************************************************
624 * GetTokenInformation [ADVAPI32.@]
626 * Get a type of information about an access token.
629 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
630 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
631 * tokeninfo [O] Destination for token information
632 * tokeninfolength [I] Length of tokeninfo
633 * retlen [O] Destination for returned token information length
636 * Success: TRUE. tokeninfo contains retlen bytes of token information
640 * See NtQueryInformationToken.
643 GetTokenInformation( HANDLE token
, TOKEN_INFORMATION_CLASS tokeninfoclass
,
644 LPVOID tokeninfo
, DWORD tokeninfolength
, LPDWORD retlen
)
646 TRACE("(%p, %s, %p, %d, %p):\n",
648 (tokeninfoclass
== TokenUser
) ? "TokenUser" :
649 (tokeninfoclass
== TokenGroups
) ? "TokenGroups" :
650 (tokeninfoclass
== TokenPrivileges
) ? "TokenPrivileges" :
651 (tokeninfoclass
== TokenOwner
) ? "TokenOwner" :
652 (tokeninfoclass
== TokenPrimaryGroup
) ? "TokenPrimaryGroup" :
653 (tokeninfoclass
== TokenDefaultDacl
) ? "TokenDefaultDacl" :
654 (tokeninfoclass
== TokenSource
) ? "TokenSource" :
655 (tokeninfoclass
== TokenType
) ? "TokenType" :
656 (tokeninfoclass
== TokenImpersonationLevel
) ? "TokenImpersonationLevel" :
657 (tokeninfoclass
== TokenStatistics
) ? "TokenStatistics" :
658 (tokeninfoclass
== TokenRestrictedSids
) ? "TokenRestrictedSids" :
659 (tokeninfoclass
== TokenSessionId
) ? "TokenSessionId" :
660 (tokeninfoclass
== TokenGroupsAndPrivileges
) ? "TokenGroupsAndPrivileges" :
661 (tokeninfoclass
== TokenSessionReference
) ? "TokenSessionReference" :
662 (tokeninfoclass
== TokenSandBoxInert
) ? "TokenSandBoxInert" :
664 tokeninfo
, tokeninfolength
, retlen
);
665 return set_ntstatus( NtQueryInformationToken( token
, tokeninfoclass
, tokeninfo
,
666 tokeninfolength
, retlen
));
669 /******************************************************************************
670 * SetTokenInformation [ADVAPI32.@]
672 * Set information for an access token.
675 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
676 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
677 * tokeninfo [I] Token information to set
678 * tokeninfolength [I] Length of tokeninfo
681 * Success: TRUE. The information for the token is set to tokeninfo.
685 SetTokenInformation( HANDLE token
, TOKEN_INFORMATION_CLASS tokeninfoclass
,
686 LPVOID tokeninfo
, DWORD tokeninfolength
)
688 TRACE("(%p, %s, %p, %d): stub\n",
690 (tokeninfoclass
== TokenUser
) ? "TokenUser" :
691 (tokeninfoclass
== TokenGroups
) ? "TokenGroups" :
692 (tokeninfoclass
== TokenPrivileges
) ? "TokenPrivileges" :
693 (tokeninfoclass
== TokenOwner
) ? "TokenOwner" :
694 (tokeninfoclass
== TokenPrimaryGroup
) ? "TokenPrimaryGroup" :
695 (tokeninfoclass
== TokenDefaultDacl
) ? "TokenDefaultDacl" :
696 (tokeninfoclass
== TokenSource
) ? "TokenSource" :
697 (tokeninfoclass
== TokenType
) ? "TokenType" :
698 (tokeninfoclass
== TokenImpersonationLevel
) ? "TokenImpersonationLevel" :
699 (tokeninfoclass
== TokenStatistics
) ? "TokenStatistics" :
700 (tokeninfoclass
== TokenRestrictedSids
) ? "TokenRestrictedSids" :
701 (tokeninfoclass
== TokenSessionId
) ? "TokenSessionId" :
702 (tokeninfoclass
== TokenGroupsAndPrivileges
) ? "TokenGroupsAndPrivileges" :
703 (tokeninfoclass
== TokenSessionReference
) ? "TokenSessionReference" :
704 (tokeninfoclass
== TokenSandBoxInert
) ? "TokenSandBoxInert" :
706 tokeninfo
, tokeninfolength
);
708 return set_ntstatus( NtSetInformationToken( token
, tokeninfoclass
, tokeninfo
, tokeninfolength
));
711 /*************************************************************************
712 * SetThreadToken [ADVAPI32.@]
714 * Assigns an 'impersonation token' to a thread so it can assume the
715 * security privileges of another thread or process. Can also remove
716 * a previously assigned token.
719 * thread [O] Handle to thread to set the token for
720 * token [I] Token to set
723 * Success: TRUE. The threads access token is set to token
727 * Only supported on NT or higher. On Win9X this function does nothing.
728 * See SetTokenInformation.
730 BOOL WINAPI
SetThreadToken(PHANDLE thread
, HANDLE token
)
732 return set_ntstatus( NtSetInformationThread( thread
? *thread
: GetCurrentThread(),
733 ThreadImpersonationToken
, &token
, sizeof token
));
736 /* ##############################
737 ###### SID FUNCTIONS ######
738 ##############################
741 /******************************************************************************
742 * AllocateAndInitializeSid [ADVAPI32.@]
745 * pIdentifierAuthority []
746 * nSubAuthorityCount []
758 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
759 BYTE nSubAuthorityCount
,
760 DWORD nSubAuthority0
, DWORD nSubAuthority1
,
761 DWORD nSubAuthority2
, DWORD nSubAuthority3
,
762 DWORD nSubAuthority4
, DWORD nSubAuthority5
,
763 DWORD nSubAuthority6
, DWORD nSubAuthority7
,
766 return set_ntstatus( RtlAllocateAndInitializeSid(
767 pIdentifierAuthority
, nSubAuthorityCount
,
768 nSubAuthority0
, nSubAuthority1
, nSubAuthority2
, nSubAuthority3
,
769 nSubAuthority4
, nSubAuthority5
, nSubAuthority6
, nSubAuthority7
,
773 /******************************************************************************
774 * FreeSid [ADVAPI32.@]
783 return NULL
; /* is documented like this */
786 /******************************************************************************
787 * CopySid [ADVAPI32.@]
790 * nDestinationSidLength []
795 CopySid( DWORD nDestinationSidLength
, PSID pDestinationSid
, PSID pSourceSid
)
797 return RtlCopySid(nDestinationSidLength
, pDestinationSid
, pSourceSid
);
800 /******************************************************************************
801 * CreateWellKnownSid [ADVAPI32.@]
804 CreateWellKnownSid( WELL_KNOWN_SID_TYPE WellKnownSidType
,
810 TRACE("(%d, %s, %p, %p)\n", WellKnownSidType
, debugstr_sid(DomainSid
), pSid
, cbSid
);
812 if (cbSid
== NULL
|| pSid
== NULL
|| (DomainSid
&& !IsValidSid(DomainSid
))) {
813 SetLastError(ERROR_INVALID_PARAMETER
);
817 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++) {
818 if (WellKnownSids
[i
].Type
== WellKnownSidType
) {
819 DWORD length
= GetSidLengthRequired(WellKnownSids
[i
].Sid
.SubAuthorityCount
);
821 if (*cbSid
< length
) {
822 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
826 CopyMemory(pSid
, &WellKnownSids
[i
].Sid
.Revision
, length
);
832 if (DomainSid
== NULL
|| *GetSidSubAuthorityCount(DomainSid
) == SID_MAX_SUB_AUTHORITIES
)
834 SetLastError(ERROR_INVALID_PARAMETER
);
838 for (i
= 0; i
< sizeof(WellKnownRids
)/sizeof(WellKnownRids
[0]); i
++)
839 if (WellKnownRids
[i
].Type
== WellKnownSidType
) {
840 UCHAR domain_subauth
= *GetSidSubAuthorityCount(DomainSid
);
841 DWORD domain_sid_length
= GetSidLengthRequired(domain_subauth
);
842 DWORD output_sid_length
= GetSidLengthRequired(domain_subauth
+ 1);
844 if (*cbSid
< output_sid_length
) {
845 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
849 CopyMemory(pSid
, DomainSid
, domain_sid_length
);
850 (*GetSidSubAuthorityCount(pSid
))++;
851 (*GetSidSubAuthority(pSid
, domain_subauth
)) = WellKnownRids
[i
].Rid
;
852 *cbSid
= output_sid_length
;
856 SetLastError(ERROR_INVALID_PARAMETER
);
860 /******************************************************************************
861 * IsWellKnownSid [ADVAPI32.@]
864 IsWellKnownSid( PSID pSid
, WELL_KNOWN_SID_TYPE WellKnownSidType
)
867 TRACE("(%s, %d)\n", debugstr_sid(pSid
), WellKnownSidType
);
869 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
870 if (WellKnownSids
[i
].Type
== WellKnownSidType
)
871 if (EqualSid(pSid
, (PSID
)&(WellKnownSids
[i
].Sid
.Revision
)))
878 IsTokenRestricted( HANDLE TokenHandle
)
880 TOKEN_GROUPS
*groups
;
885 TRACE("(%p)\n", TokenHandle
);
887 status
= NtQueryInformationToken(TokenHandle
, TokenRestrictedSids
, NULL
, 0, &size
);
888 if (status
!= STATUS_BUFFER_TOO_SMALL
)
891 groups
= HeapAlloc(GetProcessHeap(), 0, size
);
894 SetLastError(ERROR_OUTOFMEMORY
);
898 status
= NtQueryInformationToken(TokenHandle
, TokenRestrictedSids
, groups
, size
, &size
);
899 if (status
!= STATUS_SUCCESS
)
901 HeapFree(GetProcessHeap(), 0, groups
);
902 return set_ntstatus(status
);
905 if (groups
->GroupCount
)
910 HeapFree(GetProcessHeap(), 0, groups
);
915 /******************************************************************************
916 * IsValidSid [ADVAPI32.@]
922 IsValidSid( PSID pSid
)
924 return RtlValidSid( pSid
);
927 /******************************************************************************
928 * EqualSid [ADVAPI32.@]
935 EqualSid( PSID pSid1
, PSID pSid2
)
937 return RtlEqualSid( pSid1
, pSid2
);
940 /******************************************************************************
941 * EqualPrefixSid [ADVAPI32.@]
943 BOOL WINAPI
EqualPrefixSid (PSID pSid1
, PSID pSid2
)
945 return RtlEqualPrefixSid(pSid1
, pSid2
);
948 /******************************************************************************
949 * GetSidLengthRequired [ADVAPI32.@]
952 * nSubAuthorityCount []
955 GetSidLengthRequired( BYTE nSubAuthorityCount
)
957 return RtlLengthRequiredSid(nSubAuthorityCount
);
960 /******************************************************************************
961 * InitializeSid [ADVAPI32.@]
964 * pIdentifierAuthority []
969 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
970 BYTE nSubAuthorityCount
)
972 return RtlInitializeSid(pSid
, pIdentifierAuthority
, nSubAuthorityCount
);
976 GetEffectiveRightsFromAclA( PACL pacl
, PTRUSTEEA pTrustee
, PACCESS_MASK pAccessRights
)
978 FIXME("%p %p %p - stub\n", pacl
, pTrustee
, pAccessRights
);
984 GetEffectiveRightsFromAclW( PACL pacl
, PTRUSTEEW pTrustee
, PACCESS_MASK pAccessRights
)
986 FIXME("%p %p %p - stub\n", pacl
, pTrustee
, pAccessRights
);
991 /******************************************************************************
992 * GetSidIdentifierAuthority [ADVAPI32.@]
997 PSID_IDENTIFIER_AUTHORITY WINAPI
998 GetSidIdentifierAuthority( PSID pSid
)
1000 return RtlIdentifierAuthoritySid(pSid
);
1003 /******************************************************************************
1004 * GetSidSubAuthority [ADVAPI32.@]
1011 GetSidSubAuthority( PSID pSid
, DWORD nSubAuthority
)
1013 return RtlSubAuthoritySid(pSid
, nSubAuthority
);
1016 /******************************************************************************
1017 * GetSidSubAuthorityCount [ADVAPI32.@]
1023 GetSidSubAuthorityCount (PSID pSid
)
1025 return RtlSubAuthorityCountSid(pSid
);
1028 /******************************************************************************
1029 * GetLengthSid [ADVAPI32.@]
1035 GetLengthSid (PSID pSid
)
1037 return RtlLengthSid(pSid
);
1040 /* ##############################################
1041 ###### SECURITY DESCRIPTOR FUNCTIONS ######
1042 ##############################################
1045 /******************************************************************************
1046 * BuildSecurityDescriptorA [ADVAPI32.@]
1053 * cCountOfAccessEntries [I]
1054 * pListOfAccessEntries [I]
1055 * cCountOfAuditEntries [I]
1056 * pListofAuditEntries [I]
1058 * lpdwBufferLength [I/O]
1062 * Success: ERROR_SUCCESS
1063 * Failure: nonzero error code from Winerror.h
1065 DWORD WINAPI
BuildSecurityDescriptorA(
1066 IN PTRUSTEEA pOwner
,
1067 IN PTRUSTEEA pGroup
,
1068 IN ULONG cCountOfAccessEntries
,
1069 IN PEXPLICIT_ACCESSA pListOfAccessEntries
,
1070 IN ULONG cCountOfAuditEntries
,
1071 IN PEXPLICIT_ACCESSA pListofAuditEntries
,
1072 IN PSECURITY_DESCRIPTOR pOldSD
,
1073 IN OUT PULONG lpdwBufferLength
,
1074 OUT PSECURITY_DESCRIPTOR
* pNewSD
)
1076 FIXME("(%p,%p,%d,%p,%d,%p,%p,%p,%p) stub!\n",pOwner
,pGroup
,
1077 cCountOfAccessEntries
,pListOfAccessEntries
,cCountOfAuditEntries
,
1078 pListofAuditEntries
,pOldSD
,lpdwBufferLength
,pNewSD
);
1080 return ERROR_CALL_NOT_IMPLEMENTED
;
1083 /******************************************************************************
1084 * BuildSecurityDescriptorW [ADVAPI32.@]
1086 * See BuildSecurityDescriptorA.
1088 DWORD WINAPI
BuildSecurityDescriptorW(
1089 IN PTRUSTEEW pOwner
,
1090 IN PTRUSTEEW pGroup
,
1091 IN ULONG cCountOfAccessEntries
,
1092 IN PEXPLICIT_ACCESSW pListOfAccessEntries
,
1093 IN ULONG cCountOfAuditEntries
,
1094 IN PEXPLICIT_ACCESSW pListofAuditEntries
,
1095 IN PSECURITY_DESCRIPTOR pOldSD
,
1096 IN OUT PULONG lpdwBufferLength
,
1097 OUT PSECURITY_DESCRIPTOR
* pNewSD
)
1099 FIXME("(%p,%p,%d,%p,%d,%p,%p,%p,%p) stub!\n",pOwner
,pGroup
,
1100 cCountOfAccessEntries
,pListOfAccessEntries
,cCountOfAuditEntries
,
1101 pListofAuditEntries
,pOldSD
,lpdwBufferLength
,pNewSD
);
1103 return ERROR_CALL_NOT_IMPLEMENTED
;
1106 /******************************************************************************
1107 * InitializeSecurityDescriptor [ADVAPI32.@]
1114 InitializeSecurityDescriptor( PSECURITY_DESCRIPTOR pDescr
, DWORD revision
)
1116 return set_ntstatus( RtlCreateSecurityDescriptor(pDescr
, revision
));
1120 /******************************************************************************
1121 * MakeAbsoluteSD [ADVAPI32.@]
1123 BOOL WINAPI
MakeAbsoluteSD (
1124 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor
,
1125 OUT PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor
,
1126 OUT LPDWORD lpdwAbsoluteSecurityDescriptorSize
,
1128 OUT LPDWORD lpdwDaclSize
,
1130 OUT LPDWORD lpdwSaclSize
,
1132 OUT LPDWORD lpdwOwnerSize
,
1133 OUT PSID pPrimaryGroup
,
1134 OUT LPDWORD lpdwPrimaryGroupSize
)
1136 return set_ntstatus( RtlSelfRelativeToAbsoluteSD(pSelfRelativeSecurityDescriptor
,
1137 pAbsoluteSecurityDescriptor
,
1138 lpdwAbsoluteSecurityDescriptorSize
,
1139 pDacl
, lpdwDaclSize
, pSacl
, lpdwSaclSize
,
1140 pOwner
, lpdwOwnerSize
,
1141 pPrimaryGroup
, lpdwPrimaryGroupSize
));
1144 /******************************************************************************
1145 * GetKernelObjectSecurity [ADVAPI32.@]
1147 BOOL WINAPI
GetKernelObjectSecurity(
1149 SECURITY_INFORMATION RequestedInformation
,
1150 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1152 LPDWORD lpnLengthNeeded
)
1154 TRACE("(%p,0x%08x,%p,0x%08x,%p)\n", Handle
, RequestedInformation
,
1155 pSecurityDescriptor
, nLength
, lpnLengthNeeded
);
1157 return set_ntstatus( NtQuerySecurityObject(Handle
, RequestedInformation
, pSecurityDescriptor
,
1158 nLength
, lpnLengthNeeded
));
1161 /******************************************************************************
1162 * GetPrivateObjectSecurity [ADVAPI32.@]
1164 BOOL WINAPI
GetPrivateObjectSecurity(
1165 PSECURITY_DESCRIPTOR ObjectDescriptor
,
1166 SECURITY_INFORMATION SecurityInformation
,
1167 PSECURITY_DESCRIPTOR ResultantDescriptor
,
1168 DWORD DescriptorLength
,
1169 PDWORD ReturnLength
)
1171 SECURITY_DESCRIPTOR desc
;
1172 BOOL defaulted
, present
;
1176 TRACE("(%p,0x%08x,%p,0x%08x,%p)\n", ObjectDescriptor
, SecurityInformation
,
1177 ResultantDescriptor
, DescriptorLength
, ReturnLength
);
1179 if (!InitializeSecurityDescriptor(&desc
, SECURITY_DESCRIPTOR_REVISION
))
1182 if (SecurityInformation
& OWNER_SECURITY_INFORMATION
)
1184 if (!GetSecurityDescriptorOwner(ObjectDescriptor
, &psid
, &defaulted
))
1186 SetSecurityDescriptorOwner(&desc
, psid
, defaulted
);
1189 if (SecurityInformation
& GROUP_SECURITY_INFORMATION
)
1191 if (!GetSecurityDescriptorGroup(ObjectDescriptor
, &psid
, &defaulted
))
1193 SetSecurityDescriptorGroup(&desc
, psid
, defaulted
);
1196 if (SecurityInformation
& DACL_SECURITY_INFORMATION
)
1198 if (!GetSecurityDescriptorDacl(ObjectDescriptor
, &present
, &pacl
, &defaulted
))
1200 SetSecurityDescriptorDacl(&desc
, present
, pacl
, defaulted
);
1203 if (SecurityInformation
& SACL_SECURITY_INFORMATION
)
1205 if (!GetSecurityDescriptorSacl(ObjectDescriptor
, &present
, &pacl
, &defaulted
))
1207 SetSecurityDescriptorSacl(&desc
, present
, pacl
, defaulted
);
1210 *ReturnLength
= DescriptorLength
;
1211 return MakeSelfRelativeSD(&desc
, ResultantDescriptor
, ReturnLength
);
1214 /******************************************************************************
1215 * GetSecurityDescriptorLength [ADVAPI32.@]
1217 DWORD WINAPI
GetSecurityDescriptorLength( PSECURITY_DESCRIPTOR pDescr
)
1219 return RtlLengthSecurityDescriptor(pDescr
);
1222 /******************************************************************************
1223 * GetSecurityDescriptorOwner [ADVAPI32.@]
1227 * lpbOwnerDefaulted []
1230 GetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pDescr
, PSID
*pOwner
,
1231 LPBOOL lpbOwnerDefaulted
)
1234 BOOL ret
= set_ntstatus( RtlGetOwnerSecurityDescriptor( pDescr
, pOwner
, &defaulted
));
1235 *lpbOwnerDefaulted
= defaulted
;
1239 /******************************************************************************
1240 * SetSecurityDescriptorOwner [ADVAPI32.@]
1244 BOOL WINAPI
SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1245 PSID pOwner
, BOOL bOwnerDefaulted
)
1247 return set_ntstatus( RtlSetOwnerSecurityDescriptor(pSecurityDescriptor
, pOwner
, bOwnerDefaulted
));
1249 /******************************************************************************
1250 * GetSecurityDescriptorGroup [ADVAPI32.@]
1252 BOOL WINAPI
GetSecurityDescriptorGroup(
1253 PSECURITY_DESCRIPTOR SecurityDescriptor
,
1255 LPBOOL GroupDefaulted
)
1258 BOOL ret
= set_ntstatus( RtlGetGroupSecurityDescriptor(SecurityDescriptor
, Group
, &defaulted
));
1259 *GroupDefaulted
= defaulted
;
1262 /******************************************************************************
1263 * SetSecurityDescriptorGroup [ADVAPI32.@]
1265 BOOL WINAPI
SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor
,
1266 PSID Group
, BOOL GroupDefaulted
)
1268 return set_ntstatus( RtlSetGroupSecurityDescriptor( SecurityDescriptor
, Group
, GroupDefaulted
));
1271 /******************************************************************************
1272 * IsValidSecurityDescriptor [ADVAPI32.@]
1278 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor
)
1280 return set_ntstatus( RtlValidSecurityDescriptor(SecurityDescriptor
));
1283 /******************************************************************************
1284 * GetSecurityDescriptorDacl [ADVAPI32.@]
1286 BOOL WINAPI
GetSecurityDescriptorDacl(
1287 IN PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1288 OUT LPBOOL lpbDaclPresent
,
1290 OUT LPBOOL lpbDaclDefaulted
)
1292 BOOLEAN present
, defaulted
;
1293 BOOL ret
= set_ntstatus( RtlGetDaclSecurityDescriptor(pSecurityDescriptor
, &present
, pDacl
, &defaulted
));
1294 *lpbDaclPresent
= present
;
1295 *lpbDaclDefaulted
= defaulted
;
1299 /******************************************************************************
1300 * SetSecurityDescriptorDacl [ADVAPI32.@]
1303 SetSecurityDescriptorDacl (
1304 PSECURITY_DESCRIPTOR lpsd
,
1307 BOOL dacldefaulted
)
1309 return set_ntstatus( RtlSetDaclSecurityDescriptor (lpsd
, daclpresent
, dacl
, dacldefaulted
) );
1311 /******************************************************************************
1312 * GetSecurityDescriptorSacl [ADVAPI32.@]
1314 BOOL WINAPI
GetSecurityDescriptorSacl(
1315 IN PSECURITY_DESCRIPTOR lpsd
,
1316 OUT LPBOOL lpbSaclPresent
,
1318 OUT LPBOOL lpbSaclDefaulted
)
1320 BOOLEAN present
, defaulted
;
1321 BOOL ret
= set_ntstatus( RtlGetSaclSecurityDescriptor(lpsd
, &present
, pSacl
, &defaulted
) );
1322 *lpbSaclPresent
= present
;
1323 *lpbSaclDefaulted
= defaulted
;
1327 /**************************************************************************
1328 * SetSecurityDescriptorSacl [ADVAPI32.@]
1330 BOOL WINAPI
SetSecurityDescriptorSacl (
1331 PSECURITY_DESCRIPTOR lpsd
,
1336 return set_ntstatus (RtlSetSaclSecurityDescriptor(lpsd
, saclpresent
, lpsacl
, sacldefaulted
));
1338 /******************************************************************************
1339 * MakeSelfRelativeSD [ADVAPI32.@]
1348 IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor
,
1349 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor
,
1350 IN OUT LPDWORD lpdwBufferLength
)
1352 return set_ntstatus( RtlMakeSelfRelativeSD( pAbsoluteSecurityDescriptor
,
1353 pSelfRelativeSecurityDescriptor
, lpdwBufferLength
));
1356 /******************************************************************************
1357 * GetSecurityDescriptorControl [ADVAPI32.@]
1360 BOOL WINAPI
GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1361 PSECURITY_DESCRIPTOR_CONTROL pControl
, LPDWORD lpdwRevision
)
1363 return set_ntstatus( RtlGetControlSecurityDescriptor(pSecurityDescriptor
,pControl
,lpdwRevision
));
1366 /******************************************************************************
1367 * SetSecurityDescriptorControl [ADVAPI32.@]
1369 BOOL WINAPI
SetSecurityDescriptorControl( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1370 SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest
,
1371 SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet
)
1373 return set_ntstatus( RtlSetControlSecurityDescriptor(
1374 pSecurityDescriptor
, ControlBitsOfInterest
, ControlBitsToSet
) );
1377 /* ##############################
1378 ###### ACL FUNCTIONS ######
1379 ##############################
1382 /*************************************************************************
1383 * InitializeAcl [ADVAPI32.@]
1385 BOOL WINAPI
InitializeAcl(PACL acl
, DWORD size
, DWORD rev
)
1387 return set_ntstatus( RtlCreateAcl(acl
, size
, rev
));
1390 BOOL WINAPI
ImpersonateNamedPipeClient( HANDLE hNamedPipe
)
1392 IO_STATUS_BLOCK io_block
;
1394 TRACE("(%p)\n", hNamedPipe
);
1396 return set_ntstatus( NtFsControlFile(hNamedPipe
, NULL
, NULL
, NULL
,
1397 &io_block
, FSCTL_PIPE_IMPERSONATE
, NULL
, 0, NULL
, 0) );
1400 /******************************************************************************
1401 * AddAccessAllowedAce [ADVAPI32.@]
1403 BOOL WINAPI
AddAccessAllowedAce(
1405 IN DWORD dwAceRevision
,
1406 IN DWORD AccessMask
,
1409 return set_ntstatus(RtlAddAccessAllowedAce(pAcl
, dwAceRevision
, AccessMask
, pSid
));
1412 /******************************************************************************
1413 * AddAccessAllowedAceEx [ADVAPI32.@]
1415 BOOL WINAPI
AddAccessAllowedAceEx(
1417 IN DWORD dwAceRevision
,
1419 IN DWORD AccessMask
,
1422 return set_ntstatus(RtlAddAccessAllowedAceEx(pAcl
, dwAceRevision
, AceFlags
, AccessMask
, pSid
));
1425 /******************************************************************************
1426 * AddAccessDeniedAce [ADVAPI32.@]
1428 BOOL WINAPI
AddAccessDeniedAce(
1430 IN DWORD dwAceRevision
,
1431 IN DWORD AccessMask
,
1434 return set_ntstatus(RtlAddAccessDeniedAce(pAcl
, dwAceRevision
, AccessMask
, pSid
));
1437 /******************************************************************************
1438 * AddAccessDeniedAceEx [ADVAPI32.@]
1440 BOOL WINAPI
AddAccessDeniedAceEx(
1442 IN DWORD dwAceRevision
,
1444 IN DWORD AccessMask
,
1447 return set_ntstatus(RtlAddAccessDeniedAceEx(pAcl
, dwAceRevision
, AceFlags
, AccessMask
, pSid
));
1450 /******************************************************************************
1451 * AddAce [ADVAPI32.@]
1455 IN DWORD dwAceRevision
,
1456 IN DWORD dwStartingAceIndex
,
1458 DWORD nAceListLength
)
1460 return set_ntstatus(RtlAddAce(pAcl
, dwAceRevision
, dwStartingAceIndex
, pAceList
, nAceListLength
));
1463 /******************************************************************************
1464 * DeleteAce [ADVAPI32.@]
1466 BOOL WINAPI
DeleteAce(PACL pAcl
, DWORD dwAceIndex
)
1468 return set_ntstatus(RtlDeleteAce(pAcl
, dwAceIndex
));
1471 /******************************************************************************
1472 * FindFirstFreeAce [ADVAPI32.@]
1474 BOOL WINAPI
FindFirstFreeAce(IN PACL pAcl
, LPVOID
* pAce
)
1476 return RtlFirstFreeAce(pAcl
, (PACE_HEADER
*)pAce
);
1479 /******************************************************************************
1480 * GetAce [ADVAPI32.@]
1482 BOOL WINAPI
GetAce(PACL pAcl
,DWORD dwAceIndex
,LPVOID
*pAce
)
1484 return set_ntstatus(RtlGetAce(pAcl
, dwAceIndex
, pAce
));
1487 /******************************************************************************
1488 * GetAclInformation [ADVAPI32.@]
1490 BOOL WINAPI
GetAclInformation(
1492 LPVOID pAclInformation
,
1493 DWORD nAclInformationLength
,
1494 ACL_INFORMATION_CLASS dwAclInformationClass
)
1496 return set_ntstatus(RtlQueryInformationAcl(pAcl
, pAclInformation
,
1497 nAclInformationLength
, dwAclInformationClass
));
1500 /******************************************************************************
1501 * IsValidAcl [ADVAPI32.@]
1503 BOOL WINAPI
IsValidAcl(IN PACL pAcl
)
1505 return RtlValidAcl(pAcl
);
1508 /* ##############################
1509 ###### MISC FUNCTIONS ######
1510 ##############################
1513 /******************************************************************************
1514 * AllocateLocallyUniqueId [ADVAPI32.@]
1519 BOOL WINAPI
AllocateLocallyUniqueId( PLUID lpLuid
)
1521 return set_ntstatus(NtAllocateLocallyUniqueId(lpLuid
));
1524 static const WCHAR SE_CREATE_TOKEN_NAME_W
[] =
1525 { 'S','e','C','r','e','a','t','e','T','o','k','e','n','P','r','i','v','i','l','e','g','e',0 };
1526 static const WCHAR SE_ASSIGNPRIMARYTOKEN_NAME_W
[] =
1527 { '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 };
1528 static const WCHAR SE_LOCK_MEMORY_NAME_W
[] =
1529 { 'S','e','L','o','c','k','M','e','m','o','r','y','P','r','i','v','i','l','e','g','e',0 };
1530 static const WCHAR SE_INCREASE_QUOTA_NAME_W
[] =
1531 { '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 };
1532 static const WCHAR SE_MACHINE_ACCOUNT_NAME_W
[] =
1533 { '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 };
1534 static const WCHAR SE_TCB_NAME_W
[] =
1535 { 'S','e','T','c','b','P','r','i','v','i','l','e','g','e',0 };
1536 static const WCHAR SE_SECURITY_NAME_W
[] =
1537 { 'S','e','S','e','c','u','r','i','t','y','P','r','i','v','i','l','e','g','e',0 };
1538 static const WCHAR SE_TAKE_OWNERSHIP_NAME_W
[] =
1539 { '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 };
1540 static const WCHAR SE_LOAD_DRIVER_NAME_W
[] =
1541 { 'S','e','L','o','a','d','D','r','i','v','e','r','P','r','i','v','i','l','e','g','e',0 };
1542 static const WCHAR SE_SYSTEM_PROFILE_NAME_W
[] =
1543 { '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 };
1544 static const WCHAR SE_SYSTEMTIME_NAME_W
[] =
1545 { 'S','e','S','y','s','t','e','m','t','i','m','e','P','r','i','v','i','l','e','g','e',0 };
1546 static const WCHAR SE_PROF_SINGLE_PROCESS_NAME_W
[] =
1547 { '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 };
1548 static const WCHAR SE_INC_BASE_PRIORITY_NAME_W
[] =
1549 { '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 };
1550 static const WCHAR SE_CREATE_PAGEFILE_NAME_W
[] =
1551 { '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 };
1552 static const WCHAR SE_CREATE_PERMANENT_NAME_W
[] =
1553 { '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 };
1554 static const WCHAR SE_BACKUP_NAME_W
[] =
1555 { 'S','e','B','a','c','k','u','p','P','r','i','v','i','l','e','g','e',0 };
1556 static const WCHAR SE_RESTORE_NAME_W
[] =
1557 { 'S','e','R','e','s','t','o','r','e','P','r','i','v','i','l','e','g','e',0 };
1558 static const WCHAR SE_SHUTDOWN_NAME_W
[] =
1559 { 'S','e','S','h','u','t','d','o','w','n','P','r','i','v','i','l','e','g','e',0 };
1560 static const WCHAR SE_DEBUG_NAME_W
[] =
1561 { 'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0 };
1562 static const WCHAR SE_AUDIT_NAME_W
[] =
1563 { 'S','e','A','u','d','i','t','P','r','i','v','i','l','e','g','e',0 };
1564 static const WCHAR SE_SYSTEM_ENVIRONMENT_NAME_W
[] =
1565 { '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 };
1566 static const WCHAR SE_CHANGE_NOTIFY_NAME_W
[] =
1567 { 'S','e','C','h','a','n','g','e','N','o','t','i','f','y','P','r','i','v','i','l','e','g','e',0 };
1568 static const WCHAR SE_REMOTE_SHUTDOWN_NAME_W
[] =
1569 { '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 };
1570 static const WCHAR SE_UNDOCK_NAME_W
[] =
1571 { 'S','e','U','n','d','o','c','k','P','r','i','v','i','l','e','g','e',0 };
1572 static const WCHAR SE_SYNC_AGENT_NAME_W
[] =
1573 { 'S','e','S','y','n','c','A','g','e','n','t','P','r','i','v','i','l','e','g','e',0 };
1574 static const WCHAR SE_ENABLE_DELEGATION_NAME_W
[] =
1575 { '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 };
1576 static const WCHAR SE_MANAGE_VOLUME_NAME_W
[] =
1577 { 'S','e','M','a','n','a','g','e','V','o','l','u','m','e','P','r','i','v','i','l','e','g','e',0 };
1578 static const WCHAR SE_IMPERSONATE_NAME_W
[] =
1579 { 'S','e','I','m','p','e','r','s','o','n','a','t','e','P','r','i','v','i','l','e','g','e',0 };
1580 static const WCHAR SE_CREATE_GLOBAL_NAME_W
[] =
1581 { 'S','e','C','r','e','a','t','e','G','l','o','b','a','l','P','r','i','v','i','l','e','g','e',0 };
1583 static const WCHAR
* const WellKnownPrivNames
[SE_MAX_WELL_KNOWN_PRIVILEGE
+ 1] =
1587 SE_CREATE_TOKEN_NAME_W
,
1588 SE_ASSIGNPRIMARYTOKEN_NAME_W
,
1589 SE_LOCK_MEMORY_NAME_W
,
1590 SE_INCREASE_QUOTA_NAME_W
,
1591 SE_MACHINE_ACCOUNT_NAME_W
,
1594 SE_TAKE_OWNERSHIP_NAME_W
,
1595 SE_LOAD_DRIVER_NAME_W
,
1596 SE_SYSTEM_PROFILE_NAME_W
,
1597 SE_SYSTEMTIME_NAME_W
,
1598 SE_PROF_SINGLE_PROCESS_NAME_W
,
1599 SE_INC_BASE_PRIORITY_NAME_W
,
1600 SE_CREATE_PAGEFILE_NAME_W
,
1601 SE_CREATE_PERMANENT_NAME_W
,
1607 SE_SYSTEM_ENVIRONMENT_NAME_W
,
1608 SE_CHANGE_NOTIFY_NAME_W
,
1609 SE_REMOTE_SHUTDOWN_NAME_W
,
1611 SE_SYNC_AGENT_NAME_W
,
1612 SE_ENABLE_DELEGATION_NAME_W
,
1613 SE_MANAGE_VOLUME_NAME_W
,
1614 SE_IMPERSONATE_NAME_W
,
1615 SE_CREATE_GLOBAL_NAME_W
,
1618 /******************************************************************************
1619 * LookupPrivilegeValueW [ADVAPI32.@]
1621 * See LookupPrivilegeValueA.
1624 LookupPrivilegeValueW( LPCWSTR lpSystemName
, LPCWSTR lpName
, PLUID lpLuid
)
1628 TRACE("%s,%s,%p\n",debugstr_w(lpSystemName
), debugstr_w(lpName
), lpLuid
);
1630 if (!ADVAPI_IsLocalComputer(lpSystemName
))
1632 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
1637 SetLastError(ERROR_NO_SUCH_PRIVILEGE
);
1640 for( i
=SE_MIN_WELL_KNOWN_PRIVILEGE
; i
<SE_MAX_WELL_KNOWN_PRIVILEGE
; i
++ )
1642 if( !WellKnownPrivNames
[i
] )
1644 if( strcmpiW( WellKnownPrivNames
[i
], lpName
) )
1646 lpLuid
->LowPart
= i
;
1647 lpLuid
->HighPart
= 0;
1648 TRACE( "%s -> %08x-%08x\n",debugstr_w( lpSystemName
),
1649 lpLuid
->HighPart
, lpLuid
->LowPart
);
1652 SetLastError(ERROR_NO_SUCH_PRIVILEGE
);
1656 /******************************************************************************
1657 * LookupPrivilegeValueA [ADVAPI32.@]
1659 * Retrieves LUID used on a system to represent the privilege name.
1662 * lpSystemName [I] Name of the system
1663 * lpName [I] Name of the privilege
1664 * lpLuid [O] Destination for the resulting LUID
1667 * Success: TRUE. lpLuid contains the requested LUID.
1671 LookupPrivilegeValueA( LPCSTR lpSystemName
, LPCSTR lpName
, PLUID lpLuid
)
1673 UNICODE_STRING lpSystemNameW
;
1674 UNICODE_STRING lpNameW
;
1677 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW
, lpSystemName
);
1678 RtlCreateUnicodeStringFromAsciiz(&lpNameW
,lpName
);
1679 ret
= LookupPrivilegeValueW(lpSystemNameW
.Buffer
, lpNameW
.Buffer
, lpLuid
);
1680 RtlFreeUnicodeString(&lpNameW
);
1681 RtlFreeUnicodeString(&lpSystemNameW
);
1685 BOOL WINAPI
LookupPrivilegeDisplayNameA( LPCSTR lpSystemName
, LPCSTR lpName
, LPSTR lpDisplayName
,
1686 LPDWORD cchDisplayName
, LPDWORD lpLanguageId
)
1688 FIXME("%s %s %s %p %p - stub\n", debugstr_a(lpSystemName
), debugstr_a(lpName
),
1689 debugstr_a(lpDisplayName
), cchDisplayName
, lpLanguageId
);
1694 BOOL WINAPI
LookupPrivilegeDisplayNameW( LPCWSTR lpSystemName
, LPCWSTR lpName
, LPWSTR lpDisplayName
,
1695 LPDWORD cchDisplayName
, LPDWORD lpLanguageId
)
1697 FIXME("%s %s %s %p %p - stub\n", debugstr_w(lpSystemName
), debugstr_w(lpName
),
1698 debugstr_w(lpDisplayName
), cchDisplayName
, lpLanguageId
);
1703 /******************************************************************************
1704 * LookupPrivilegeNameA [ADVAPI32.@]
1706 * See LookupPrivilegeNameW.
1709 LookupPrivilegeNameA( LPCSTR lpSystemName
, PLUID lpLuid
, LPSTR lpName
,
1712 UNICODE_STRING lpSystemNameW
;
1716 TRACE("%s %p %p %p\n", debugstr_a(lpSystemName
), lpLuid
, lpName
, cchName
);
1718 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW
, lpSystemName
);
1719 ret
= LookupPrivilegeNameW(lpSystemNameW
.Buffer
, lpLuid
, NULL
, &wLen
);
1720 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1722 LPWSTR lpNameW
= HeapAlloc(GetProcessHeap(), 0, wLen
* sizeof(WCHAR
));
1724 ret
= LookupPrivilegeNameW(lpSystemNameW
.Buffer
, lpLuid
, lpNameW
,
1728 /* Windows crashes if cchName is NULL, so will I */
1729 unsigned int len
= WideCharToMultiByte(CP_ACP
, 0, lpNameW
, -1, lpName
,
1730 *cchName
, NULL
, NULL
);
1734 /* WideCharToMultiByte failed */
1737 else if (len
> *cchName
)
1740 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1745 /* WideCharToMultiByte succeeded, output length needs to be
1746 * length not including NULL terminator
1751 HeapFree(GetProcessHeap(), 0, lpNameW
);
1753 RtlFreeUnicodeString(&lpSystemNameW
);
1757 /******************************************************************************
1758 * LookupPrivilegeNameW [ADVAPI32.@]
1760 * Retrieves the privilege name referred to by the LUID lpLuid.
1763 * lpSystemName [I] Name of the system
1764 * lpLuid [I] Privilege value
1765 * lpName [O] Name of the privilege
1766 * cchName [I/O] Number of characters in lpName.
1769 * Success: TRUE. lpName contains the name of the privilege whose value is
1774 * Only well-known privilege names (those defined in winnt.h) can be retrieved
1775 * using this function.
1776 * If the length of lpName is too small, on return *cchName will contain the
1777 * number of WCHARs needed to contain the privilege, including the NULL
1778 * terminator, and GetLastError will return ERROR_INSUFFICIENT_BUFFER.
1779 * On success, *cchName will contain the number of characters stored in
1780 * lpName, NOT including the NULL terminator.
1783 LookupPrivilegeNameW( LPCWSTR lpSystemName
, PLUID lpLuid
, LPWSTR lpName
,
1788 TRACE("%s,%p,%p,%p\n",debugstr_w(lpSystemName
), lpLuid
, lpName
, cchName
);
1790 if (!ADVAPI_IsLocalComputer(lpSystemName
))
1792 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
1795 if (lpLuid
->HighPart
|| (lpLuid
->LowPart
< SE_MIN_WELL_KNOWN_PRIVILEGE
||
1796 lpLuid
->LowPart
> SE_MAX_WELL_KNOWN_PRIVILEGE
))
1798 SetLastError(ERROR_NO_SUCH_PRIVILEGE
);
1801 privNameLen
= strlenW(WellKnownPrivNames
[lpLuid
->LowPart
]);
1802 /* Windows crashes if cchName is NULL, so will I */
1803 if (*cchName
<= privNameLen
)
1805 *cchName
= privNameLen
+ 1;
1806 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1811 strcpyW(lpName
, WellKnownPrivNames
[lpLuid
->LowPart
]);
1812 *cchName
= privNameLen
;
1817 /******************************************************************************
1818 * GetFileSecurityA [ADVAPI32.@]
1820 * Obtains Specified information about the security of a file or directory.
1823 * lpFileName [I] Name of the file to get info for
1824 * RequestedInformation [I] SE_ flags from "winnt.h"
1825 * pSecurityDescriptor [O] Destination for security information
1826 * nLength [I] Length of pSecurityDescriptor
1827 * lpnLengthNeeded [O] Destination for length of returned security information
1830 * Success: TRUE. pSecurityDescriptor contains the requested information.
1831 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
1834 * The information returned is constrained by the callers access rights and
1838 GetFileSecurityA( LPCSTR lpFileName
,
1839 SECURITY_INFORMATION RequestedInformation
,
1840 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1841 DWORD nLength
, LPDWORD lpnLengthNeeded
)
1849 len
= MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, NULL
, 0 );
1850 name
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
1851 MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, name
, len
);
1854 r
= GetFileSecurityW( name
, RequestedInformation
, pSecurityDescriptor
,
1855 nLength
, lpnLengthNeeded
);
1856 HeapFree( GetProcessHeap(), 0, name
);
1861 /******************************************************************************
1862 * GetFileSecurityW [ADVAPI32.@]
1864 * See GetFileSecurityA.
1867 GetFileSecurityW( LPCWSTR lpFileName
,
1868 SECURITY_INFORMATION RequestedInformation
,
1869 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1870 DWORD nLength
, LPDWORD lpnLengthNeeded
)
1876 if (RequestedInformation
& (OWNER_SECURITY_INFORMATION
|GROUP_SECURITY_INFORMATION
|
1877 DACL_SECURITY_INFORMATION
))
1878 access
|= READ_CONTROL
;
1879 if (RequestedInformation
& SACL_SECURITY_INFORMATION
)
1880 access
|= ACCESS_SYSTEM_SECURITY
;
1882 hfile
= CreateFileW( lpFileName
, access
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
1883 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1884 if ( hfile
== INVALID_HANDLE_VALUE
)
1887 status
= NtQuerySecurityObject( hfile
, RequestedInformation
, pSecurityDescriptor
,
1888 nLength
, lpnLengthNeeded
);
1889 CloseHandle( hfile
);
1890 return set_ntstatus( status
);
1894 /******************************************************************************
1895 * LookupAccountSidA [ADVAPI32.@]
1902 IN OUT LPDWORD accountSize
,
1904 IN OUT LPDWORD domainSize
,
1905 OUT PSID_NAME_USE name_use
)
1909 LPWSTR systemW
= NULL
;
1910 LPWSTR accountW
= NULL
;
1911 LPWSTR domainW
= NULL
;
1912 DWORD accountSizeW
= *accountSize
;
1913 DWORD domainSizeW
= *domainSize
;
1915 TRACE("(%s,sid=%s,%p,%p(%u),%p,%p(%u),%p)\n",
1916 debugstr_a(system
),debugstr_sid(sid
),
1917 account
,accountSize
,accountSize
?*accountSize
:0,
1918 domain
,domainSize
,domainSize
?*domainSize
:0,
1922 len
= MultiByteToWideChar( CP_ACP
, 0, system
, -1, NULL
, 0 );
1923 systemW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1924 MultiByteToWideChar( CP_ACP
, 0, system
, -1, systemW
, len
);
1927 accountW
= HeapAlloc( GetProcessHeap(), 0, accountSizeW
* sizeof(WCHAR
) );
1929 domainW
= HeapAlloc( GetProcessHeap(), 0, domainSizeW
* sizeof(WCHAR
) );
1931 r
= LookupAccountSidW( systemW
, sid
, accountW
, &accountSizeW
, domainW
, &domainSizeW
, name_use
);
1934 if (accountW
&& *accountSize
) {
1935 len
= WideCharToMultiByte( CP_ACP
, 0, accountW
, -1, NULL
, 0, NULL
, NULL
);
1936 WideCharToMultiByte( CP_ACP
, 0, accountW
, -1, account
, len
, NULL
, NULL
);
1939 *accountSize
= accountSizeW
+ 1;
1941 if (domainW
&& *domainSize
) {
1942 len
= WideCharToMultiByte( CP_ACP
, 0, domainW
, -1, NULL
, 0, NULL
, NULL
);
1943 WideCharToMultiByte( CP_ACP
, 0, domainW
, -1, domain
, len
, NULL
, NULL
);
1946 *domainSize
= domainSizeW
+ 1;
1949 HeapFree( GetProcessHeap(), 0, systemW
);
1950 HeapFree( GetProcessHeap(), 0, accountW
);
1951 HeapFree( GetProcessHeap(), 0, domainW
);
1956 /******************************************************************************
1957 * LookupAccountSidW [ADVAPI32.@]
1974 IN OUT LPDWORD accountSize
,
1976 IN OUT LPDWORD domainSize
,
1977 OUT PSID_NAME_USE name_use
)
1980 const WCHAR
* ac
= NULL
;
1981 const WCHAR
* dm
= NULL
;
1982 SID_NAME_USE use
= 0;
1983 LPWSTR computer_name
= NULL
;
1985 TRACE("(%s,sid=%s,%p,%p(%u),%p,%p(%u),%p)\n",
1986 debugstr_w(system
),debugstr_sid(sid
),
1987 account
,accountSize
,accountSize
?*accountSize
:0,
1988 domain
,domainSize
,domainSize
?*domainSize
:0,
1991 if (!ADVAPI_IsLocalComputer(system
)) {
1992 FIXME("Only local computer supported!\n");
1993 SetLastError(ERROR_NONE_MAPPED
);
1997 /* check the well known SIDs first */
1998 for (i
= 0; i
<= 60; i
++) {
1999 if (IsWellKnownSid(sid
, i
)) {
2000 for (j
= 0; j
< (sizeof(ACCOUNT_SIDS
) / sizeof(ACCOUNT_SIDS
[0])); j
++) {
2001 if (ACCOUNT_SIDS
[j
].type
== i
) {
2002 ac
= ACCOUNT_SIDS
[j
].account
;
2003 dm
= ACCOUNT_SIDS
[j
].domain
;
2004 use
= ACCOUNT_SIDS
[j
].name_use
;
2014 /* check for the local computer next */
2015 if (ADVAPI_GetComputerSid(&local
)) {
2016 DWORD size
= MAX_COMPUTERNAME_LENGTH
+ 1;
2019 computer_name
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
2020 result
= GetComputerNameW(computer_name
, &size
);
2023 if (EqualSid(sid
, &local
)) {
2028 local
.SubAuthorityCount
++;
2030 if (EqualPrefixSid(sid
, &local
)) {
2033 switch (((MAX_SID
*)sid
)->SubAuthority
[4]) {
2034 case DOMAIN_USER_RID_ADMIN
:
2037 case DOMAIN_USER_RID_GUEST
:
2040 case DOMAIN_GROUP_RID_ADMINS
:
2043 case DOMAIN_GROUP_RID_USERS
:
2046 case DOMAIN_GROUP_RID_GUESTS
:
2049 case DOMAIN_GROUP_RID_COMPUTERS
:
2050 ac
= Domain_Computers
;
2052 case DOMAIN_GROUP_RID_CONTROLLERS
:
2053 ac
= Domain_Controllers
;
2055 case DOMAIN_GROUP_RID_CERT_ADMINS
:
2056 ac
= Cert_Publishers
;
2058 case DOMAIN_GROUP_RID_SCHEMA_ADMINS
:
2061 case DOMAIN_GROUP_RID_ENTERPRISE_ADMINS
:
2062 ac
= Enterprise_Admins
;
2064 case DOMAIN_GROUP_RID_POLICY_ADMINS
:
2065 ac
= Group_Policy_Creator_Owners
;
2067 case DOMAIN_ALIAS_RID_RAS_SERVERS
:
2068 ac
= RAS_and_IAS_Servers
;
2082 if (*accountSize
> lstrlenW(ac
)) {
2084 lstrcpyW(account
, ac
);
2086 if (*domainSize
> lstrlenW(dm
)) {
2088 lstrcpyW(domain
, dm
);
2090 if (((*accountSize
!= 0) && (*accountSize
< strlenW(ac
))) ||
2091 ((*domainSize
!= 0) && (*domainSize
< strlenW(dm
)))) {
2092 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2096 *domainSize
= strlenW(dm
);
2098 *domainSize
= strlenW(dm
) + 1;
2100 *accountSize
= strlenW(ac
);
2102 *accountSize
= strlenW(ac
) + 1;
2104 HeapFree(GetProcessHeap(), 0, computer_name
);
2108 HeapFree(GetProcessHeap(), 0, computer_name
);
2109 SetLastError(ERROR_NONE_MAPPED
);
2113 /******************************************************************************
2114 * SetFileSecurityA [ADVAPI32.@]
2116 * See SetFileSecurityW.
2118 BOOL WINAPI
SetFileSecurityA( LPCSTR lpFileName
,
2119 SECURITY_INFORMATION RequestedInformation
,
2120 PSECURITY_DESCRIPTOR pSecurityDescriptor
)
2128 len
= MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, NULL
, 0 );
2129 name
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
2130 MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, name
, len
);
2133 r
= SetFileSecurityW( name
, RequestedInformation
, pSecurityDescriptor
);
2134 HeapFree( GetProcessHeap(), 0, name
);
2139 /******************************************************************************
2140 * SetFileSecurityW [ADVAPI32.@]
2142 * Sets the security of a file or directory.
2146 * RequestedInformation []
2147 * pSecurityDescriptor []
2154 SetFileSecurityW( LPCWSTR lpFileName
,
2155 SECURITY_INFORMATION RequestedInformation
,
2156 PSECURITY_DESCRIPTOR pSecurityDescriptor
)
2162 TRACE("(%s, 0x%x, %p)\n", debugstr_w(lpFileName
), RequestedInformation
,
2163 pSecurityDescriptor
);
2165 if (RequestedInformation
& OWNER_SECURITY_INFORMATION
||
2166 RequestedInformation
& GROUP_SECURITY_INFORMATION
)
2167 access
|= WRITE_OWNER
;
2168 if (RequestedInformation
& SACL_SECURITY_INFORMATION
)
2169 access
|= ACCESS_SYSTEM_SECURITY
;
2170 if (RequestedInformation
& DACL_SECURITY_INFORMATION
)
2171 access
|= WRITE_DAC
;
2173 file
= CreateFileW( lpFileName
, access
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
2174 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, NULL
);
2175 if (file
== INVALID_HANDLE_VALUE
)
2178 status
= NtSetSecurityObject( file
, RequestedInformation
, pSecurityDescriptor
);
2179 CloseHandle( file
);
2180 return set_ntstatus( status
);
2183 /******************************************************************************
2184 * QueryWindows31FilesMigration [ADVAPI32.@]
2190 QueryWindows31FilesMigration( DWORD x1
)
2192 FIXME("(%d):stub\n",x1
);
2196 /******************************************************************************
2197 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
2206 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1
, DWORD x2
, DWORD x3
,
2209 FIXME("(0x%08x,0x%08x,0x%08x,0x%08x):stub\n",x1
,x2
,x3
,x4
);
2213 /******************************************************************************
2214 * NotifyBootConfigStatus [ADVAPI32.@]
2220 NotifyBootConfigStatus( BOOL x1
)
2222 FIXME("(0x%08d):stub\n",x1
);
2226 /******************************************************************************
2227 * RevertToSelf [ADVAPI32.@]
2229 * Ends the impersonation of a user.
2239 RevertToSelf( void )
2241 HANDLE Token
= NULL
;
2242 return set_ntstatus( NtSetInformationThread( GetCurrentThread(),
2243 ThreadImpersonationToken
, &Token
, sizeof(Token
) ) );
2246 /******************************************************************************
2247 * ImpersonateSelf [ADVAPI32.@]
2249 * Makes an impersonation token that represents the process user and assigns
2250 * to the current thread.
2253 * ImpersonationLevel [I] Level at which to impersonate.
2260 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
)
2262 return set_ntstatus( RtlImpersonateSelf( ImpersonationLevel
) );
2265 /******************************************************************************
2266 * ImpersonateLoggedOnUser [ADVAPI32.@]
2268 BOOL WINAPI
ImpersonateLoggedOnUser(HANDLE hToken
)
2272 HANDLE ImpersonationToken
;
2275 FIXME( "(%p)\n", hToken
);
2277 if (!GetTokenInformation( hToken
, TokenType
, &Type
,
2278 sizeof(TOKEN_TYPE
), &size
))
2281 if (Type
== TokenPrimary
)
2283 OBJECT_ATTRIBUTES ObjectAttributes
;
2285 InitializeObjectAttributes( &ObjectAttributes
, NULL
, 0, NULL
, NULL
);
2287 Status
= NtDuplicateToken( hToken
,
2288 TOKEN_IMPERSONATE
| TOKEN_QUERY
,
2290 SecurityImpersonation
,
2292 &ImpersonationToken
);
2293 if (Status
!= STATUS_SUCCESS
)
2295 ERR( "NtDuplicateToken failed with error 0x%08x\n", Status
);
2296 SetLastError( RtlNtStatusToDosError( Status
) );
2301 ImpersonationToken
= hToken
;
2303 Status
= NtSetInformationThread( GetCurrentThread(),
2304 ThreadImpersonationToken
,
2305 &ImpersonationToken
,
2306 sizeof(ImpersonationToken
) );
2308 if (Type
== TokenPrimary
)
2309 NtClose( ImpersonationToken
);
2311 if (Status
!= STATUS_SUCCESS
)
2313 ERR( "NtSetInformationThread failed with error 0x%08x\n", Status
);
2314 SetLastError( RtlNtStatusToDosError( Status
) );
2321 /******************************************************************************
2322 * AccessCheck [ADVAPI32.@]
2326 PSECURITY_DESCRIPTOR SecurityDescriptor
,
2328 DWORD DesiredAccess
,
2329 PGENERIC_MAPPING GenericMapping
,
2330 PPRIVILEGE_SET PrivilegeSet
,
2331 LPDWORD PrivilegeSetLength
,
2332 LPDWORD GrantedAccess
,
2333 LPBOOL AccessStatus
)
2335 NTSTATUS access_status
;
2336 BOOL ret
= set_ntstatus( NtAccessCheck(SecurityDescriptor
, ClientToken
, DesiredAccess
,
2337 GenericMapping
, PrivilegeSet
, PrivilegeSetLength
,
2338 GrantedAccess
, &access_status
) );
2339 if (ret
) *AccessStatus
= set_ntstatus( access_status
);
2344 /******************************************************************************
2345 * AccessCheckByType [ADVAPI32.@]
2347 BOOL WINAPI
AccessCheckByType(
2348 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
2349 PSID PrincipalSelfSid
,
2351 DWORD DesiredAccess
,
2352 POBJECT_TYPE_LIST ObjectTypeList
,
2353 DWORD ObjectTypeListLength
,
2354 PGENERIC_MAPPING GenericMapping
,
2355 PPRIVILEGE_SET PrivilegeSet
,
2356 LPDWORD PrivilegeSetLength
,
2357 LPDWORD GrantedAccess
,
2358 LPBOOL AccessStatus
)
2362 *AccessStatus
= TRUE
;
2364 return !*AccessStatus
;
2367 /******************************************************************************
2368 * MapGenericMask [ADVAPI32.@]
2370 * Maps generic access rights into specific access rights according to the
2374 * AccessMask [I/O] Access rights.
2375 * GenericMapping [I] The mapping between generic and specific rights.
2380 VOID WINAPI
MapGenericMask( PDWORD AccessMask
, PGENERIC_MAPPING GenericMapping
)
2382 RtlMapGenericMask( AccessMask
, GenericMapping
);
2385 /*************************************************************************
2386 * SetKernelObjectSecurity [ADVAPI32.@]
2388 BOOL WINAPI
SetKernelObjectSecurity (
2390 IN SECURITY_INFORMATION SecurityInformation
,
2391 IN PSECURITY_DESCRIPTOR SecurityDescriptor
)
2393 return set_ntstatus (NtSetSecurityObject (Handle
, SecurityInformation
, SecurityDescriptor
));
2397 /******************************************************************************
2398 * AddAuditAccessAce [ADVAPI32.@]
2400 BOOL WINAPI
AddAuditAccessAce(
2402 IN DWORD dwAceRevision
,
2403 IN DWORD dwAccessMask
,
2405 IN BOOL bAuditSuccess
,
2406 IN BOOL bAuditFailure
)
2408 return set_ntstatus( RtlAddAuditAccessAce(pAcl
, dwAceRevision
, dwAccessMask
, pSid
,
2409 bAuditSuccess
, bAuditFailure
) );
2412 /******************************************************************************
2413 * AddAuditAccessAce [ADVAPI32.@]
2415 BOOL WINAPI
AddAuditAccessAceEx(
2417 IN DWORD dwAceRevision
,
2418 IN DWORD dwAceFlags
,
2419 IN DWORD dwAccessMask
,
2421 IN BOOL bAuditSuccess
,
2422 IN BOOL bAuditFailure
)
2424 return set_ntstatus( RtlAddAuditAccessAceEx(pAcl
, dwAceRevision
, dwAceFlags
, dwAccessMask
, pSid
,
2425 bAuditSuccess
, bAuditFailure
) );
2428 /******************************************************************************
2429 * LookupAccountNameA [ADVAPI32.@]
2437 LPSTR ReferencedDomainName
,
2438 IN OUT LPDWORD cbReferencedDomainName
,
2439 OUT PSID_NAME_USE name_use
)
2442 UNICODE_STRING lpSystemW
;
2443 UNICODE_STRING lpAccountW
;
2444 LPWSTR lpReferencedDomainNameW
= NULL
;
2446 RtlCreateUnicodeStringFromAsciiz(&lpSystemW
, system
);
2447 RtlCreateUnicodeStringFromAsciiz(&lpAccountW
, account
);
2449 if (ReferencedDomainName
)
2450 lpReferencedDomainNameW
= HeapAlloc(GetProcessHeap(), 0, *cbReferencedDomainName
* sizeof(WCHAR
));
2452 ret
= LookupAccountNameW(lpSystemW
.Buffer
, lpAccountW
.Buffer
, sid
, cbSid
, lpReferencedDomainNameW
,
2453 cbReferencedDomainName
, name_use
);
2455 if (ret
&& lpReferencedDomainNameW
)
2457 WideCharToMultiByte(CP_ACP
, 0, lpReferencedDomainNameW
, *cbReferencedDomainName
,
2458 ReferencedDomainName
, *cbReferencedDomainName
, NULL
, NULL
);
2461 RtlFreeUnicodeString(&lpSystemW
);
2462 RtlFreeUnicodeString(&lpAccountW
);
2463 HeapFree(GetProcessHeap(), 0, lpReferencedDomainNameW
);
2468 /******************************************************************************
2469 * LookupAccountNameW [ADVAPI32.@]
2471 BOOL WINAPI
LookupAccountNameW( LPCWSTR lpSystemName
, LPCWSTR lpAccountName
, PSID Sid
,
2472 LPDWORD cbSid
, LPWSTR ReferencedDomainName
,
2473 LPDWORD cchReferencedDomainName
, PSID_NAME_USE peUse
)
2475 /* Default implementation: Always return a default SID */
2476 SID_IDENTIFIER_AUTHORITY identifierAuthority
= {SECURITY_NT_AUTHORITY
};
2479 static const WCHAR dm
[] = {'D','O','M','A','I','N',0};
2481 FIXME("%s %s %p %p %p %p %p - stub\n", debugstr_w(lpSystemName
), debugstr_w(lpAccountName
),
2482 Sid
, cbSid
, ReferencedDomainName
, cchReferencedDomainName
, peUse
);
2484 ret
= AllocateAndInitializeSid(&identifierAuthority
,
2486 SECURITY_BUILTIN_DOMAIN_RID
,
2487 DOMAIN_ALIAS_RID_ADMINS
,
2494 if (!RtlValidSid(pSid
))
2500 if (Sid
!= NULL
&& (*cbSid
>= GetLengthSid(pSid
)))
2501 CopySid(*cbSid
, Sid
, pSid
);
2502 if (*cbSid
< GetLengthSid(pSid
))
2504 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2507 *cbSid
= GetLengthSid(pSid
);
2509 if (ReferencedDomainName
!= NULL
&& (*cchReferencedDomainName
> strlenW(dm
)))
2510 strcpyW(ReferencedDomainName
, dm
);
2512 if (*cchReferencedDomainName
<= strlenW(dm
))
2514 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2518 *cchReferencedDomainName
= strlenW(dm
)+1;
2525 /******************************************************************************
2526 * PrivilegeCheck [ADVAPI32.@]
2528 BOOL WINAPI
PrivilegeCheck( HANDLE ClientToken
, PPRIVILEGE_SET RequiredPrivileges
, LPBOOL pfResult
)
2533 TRACE("%p %p %p\n", ClientToken
, RequiredPrivileges
, pfResult
);
2535 ret
= set_ntstatus (NtPrivilegeCheck (ClientToken
, RequiredPrivileges
, &Result
));
2541 /******************************************************************************
2542 * AccessCheckAndAuditAlarmA [ADVAPI32.@]
2544 BOOL WINAPI
AccessCheckAndAuditAlarmA(LPCSTR Subsystem
, LPVOID HandleId
, LPSTR ObjectTypeName
,
2545 LPSTR ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
, DWORD DesiredAccess
,
2546 PGENERIC_MAPPING GenericMapping
, BOOL ObjectCreation
, LPDWORD GrantedAccess
,
2547 LPBOOL AccessStatus
, LPBOOL pfGenerateOnClose
)
2549 FIXME("stub (%s,%p,%s,%s,%p,%08x,%p,%x,%p,%p,%p)\n", debugstr_a(Subsystem
),
2550 HandleId
, debugstr_a(ObjectTypeName
), debugstr_a(ObjectName
),
2551 SecurityDescriptor
, DesiredAccess
, GenericMapping
,
2552 ObjectCreation
, GrantedAccess
, AccessStatus
, pfGenerateOnClose
);
2556 /******************************************************************************
2557 * AccessCheckAndAuditAlarmW [ADVAPI32.@]
2559 BOOL WINAPI
AccessCheckAndAuditAlarmW(LPCWSTR Subsystem
, LPVOID HandleId
, LPWSTR ObjectTypeName
,
2560 LPWSTR ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
, DWORD DesiredAccess
,
2561 PGENERIC_MAPPING GenericMapping
, BOOL ObjectCreation
, LPDWORD GrantedAccess
,
2562 LPBOOL AccessStatus
, LPBOOL pfGenerateOnClose
)
2564 FIXME("stub (%s,%p,%s,%s,%p,%08x,%p,%x,%p,%p,%p)\n", debugstr_w(Subsystem
),
2565 HandleId
, debugstr_w(ObjectTypeName
), debugstr_w(ObjectName
),
2566 SecurityDescriptor
, DesiredAccess
, GenericMapping
,
2567 ObjectCreation
, GrantedAccess
, AccessStatus
, pfGenerateOnClose
);
2571 BOOL WINAPI
ObjectCloseAuditAlarmA(LPCSTR SubsystemName
, LPVOID HandleId
, BOOL GenerateOnClose
)
2573 FIXME("stub (%s,%p,%x)\n", debugstr_a(SubsystemName
), HandleId
, GenerateOnClose
);
2578 BOOL WINAPI
ObjectCloseAuditAlarmW(LPCWSTR SubsystemName
, LPVOID HandleId
, BOOL GenerateOnClose
)
2580 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName
), HandleId
, GenerateOnClose
);
2585 BOOL WINAPI
ObjectDeleteAuditAlarmW(LPCWSTR SubsystemName
, LPVOID HandleId
, BOOL GenerateOnClose
)
2587 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName
), HandleId
, GenerateOnClose
);
2592 BOOL WINAPI
ObjectOpenAuditAlarmA(LPCSTR SubsystemName
, LPVOID HandleId
, LPSTR ObjectTypeName
,
2593 LPSTR ObjectName
, PSECURITY_DESCRIPTOR pSecurityDescriptor
, HANDLE ClientToken
, DWORD DesiredAccess
,
2594 DWORD GrantedAccess
, PPRIVILEGE_SET Privileges
, BOOL ObjectCreation
, BOOL AccessGranted
,
2595 LPBOOL GenerateOnClose
)
2597 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08x,0x%08x,%p,%x,%x,%p)\n", debugstr_a(SubsystemName
),
2598 HandleId
, debugstr_a(ObjectTypeName
), debugstr_a(ObjectName
), pSecurityDescriptor
,
2599 ClientToken
, DesiredAccess
, GrantedAccess
, Privileges
, ObjectCreation
, AccessGranted
,
2605 BOOL WINAPI
ObjectOpenAuditAlarmW(LPCWSTR SubsystemName
, LPVOID HandleId
, LPWSTR ObjectTypeName
,
2606 LPWSTR ObjectName
, PSECURITY_DESCRIPTOR pSecurityDescriptor
, HANDLE ClientToken
, DWORD DesiredAccess
,
2607 DWORD GrantedAccess
, PPRIVILEGE_SET Privileges
, BOOL ObjectCreation
, BOOL AccessGranted
,
2608 LPBOOL GenerateOnClose
)
2610 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08x,0x%08x,%p,%x,%x,%p)\n", debugstr_w(SubsystemName
),
2611 HandleId
, debugstr_w(ObjectTypeName
), debugstr_w(ObjectName
), pSecurityDescriptor
,
2612 ClientToken
, DesiredAccess
, GrantedAccess
, Privileges
, ObjectCreation
, AccessGranted
,
2618 BOOL WINAPI
ObjectPrivilegeAuditAlarmA( LPCSTR SubsystemName
, LPVOID HandleId
, HANDLE ClientToken
,
2619 DWORD DesiredAccess
, PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2621 FIXME("stub (%s,%p,%p,0x%08x,%p,%x)\n", debugstr_a(SubsystemName
), HandleId
, ClientToken
,
2622 DesiredAccess
, Privileges
, AccessGranted
);
2627 BOOL WINAPI
ObjectPrivilegeAuditAlarmW( LPCWSTR SubsystemName
, LPVOID HandleId
, HANDLE ClientToken
,
2628 DWORD DesiredAccess
, PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2630 FIXME("stub (%s,%p,%p,0x%08x,%p,%x)\n", debugstr_w(SubsystemName
), HandleId
, ClientToken
,
2631 DesiredAccess
, Privileges
, AccessGranted
);
2636 BOOL WINAPI
PrivilegedServiceAuditAlarmA( LPCSTR SubsystemName
, LPCSTR ServiceName
, HANDLE ClientToken
,
2637 PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2639 FIXME("stub (%s,%s,%p,%p,%x)\n", debugstr_a(SubsystemName
), debugstr_a(ServiceName
),
2640 ClientToken
, Privileges
, AccessGranted
);
2645 BOOL WINAPI
PrivilegedServiceAuditAlarmW( LPCWSTR SubsystemName
, LPCWSTR ServiceName
, HANDLE ClientToken
,
2646 PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2648 FIXME("stub %s,%s,%p,%p,%x)\n", debugstr_w(SubsystemName
), debugstr_w(ServiceName
),
2649 ClientToken
, Privileges
, AccessGranted
);
2654 /******************************************************************************
2655 * GetSecurityInfo [ADVAPI32.@]
2657 DWORD WINAPI
GetSecurityInfo(
2658 HANDLE hObject
, SE_OBJECT_TYPE ObjectType
,
2659 SECURITY_INFORMATION SecurityInfo
, PSID
*ppsidOwner
,
2660 PSID
*ppsidGroup
, PACL
*ppDacl
, PACL
*ppSacl
,
2661 PSECURITY_DESCRIPTOR
*ppSecurityDescriptor
2665 return ERROR_BAD_PROVIDER
;
2668 /******************************************************************************
2669 * GetSecurityInfoExW [ADVAPI32.@]
2671 DWORD WINAPI
GetSecurityInfoExW(
2672 HANDLE hObject
, SE_OBJECT_TYPE ObjectType
,
2673 SECURITY_INFORMATION SecurityInfo
, LPCWSTR lpProvider
,
2674 LPCWSTR lpProperty
, PACTRL_ACCESSW
*ppAccessList
,
2675 PACTRL_AUDITW
*ppAuditList
, LPWSTR
*lppOwner
, LPWSTR
*lppGroup
2679 return ERROR_BAD_PROVIDER
;
2682 /******************************************************************************
2683 * BuildExplicitAccessWithNameA [ADVAPI32.@]
2685 VOID WINAPI
BuildExplicitAccessWithNameA( PEXPLICIT_ACCESSA pExplicitAccess
,
2686 LPSTR pTrusteeName
, DWORD AccessPermissions
,
2687 ACCESS_MODE AccessMode
, DWORD Inheritance
)
2689 TRACE("%p %s 0x%08x 0x%08x 0x%08x\n", pExplicitAccess
, debugstr_a(pTrusteeName
),
2690 AccessPermissions
, AccessMode
, Inheritance
);
2692 pExplicitAccess
->grfAccessPermissions
= AccessPermissions
;
2693 pExplicitAccess
->grfAccessMode
= AccessMode
;
2694 pExplicitAccess
->grfInheritance
= Inheritance
;
2696 pExplicitAccess
->Trustee
.pMultipleTrustee
= NULL
;
2697 pExplicitAccess
->Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2698 pExplicitAccess
->Trustee
.TrusteeForm
= TRUSTEE_IS_NAME
;
2699 pExplicitAccess
->Trustee
.TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2700 pExplicitAccess
->Trustee
.ptstrName
= pTrusteeName
;
2703 /******************************************************************************
2704 * BuildExplicitAccessWithNameW [ADVAPI32.@]
2706 VOID WINAPI
BuildExplicitAccessWithNameW( PEXPLICIT_ACCESSW pExplicitAccess
,
2707 LPWSTR pTrusteeName
, DWORD AccessPermissions
,
2708 ACCESS_MODE AccessMode
, DWORD Inheritance
)
2710 TRACE("%p %s 0x%08x 0x%08x 0x%08x\n", pExplicitAccess
, debugstr_w(pTrusteeName
),
2711 AccessPermissions
, AccessMode
, Inheritance
);
2713 pExplicitAccess
->grfAccessPermissions
= AccessPermissions
;
2714 pExplicitAccess
->grfAccessMode
= AccessMode
;
2715 pExplicitAccess
->grfInheritance
= Inheritance
;
2717 pExplicitAccess
->Trustee
.pMultipleTrustee
= NULL
;
2718 pExplicitAccess
->Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2719 pExplicitAccess
->Trustee
.TrusteeForm
= TRUSTEE_IS_NAME
;
2720 pExplicitAccess
->Trustee
.TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2721 pExplicitAccess
->Trustee
.ptstrName
= pTrusteeName
;
2724 /******************************************************************************
2725 * BuildTrusteeWithObjectsAndNameA [ADVAPI32.@]
2727 VOID WINAPI
BuildTrusteeWithObjectsAndNameA( PTRUSTEEA pTrustee
, POBJECTS_AND_NAME_A pObjName
,
2728 SE_OBJECT_TYPE ObjectType
, LPSTR ObjectTypeName
,
2729 LPSTR InheritedObjectTypeName
, LPSTR Name
)
2731 DWORD ObjectsPresent
= 0;
2733 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee
, pObjName
,
2734 ObjectType
, ObjectTypeName
, InheritedObjectTypeName
, debugstr_a(Name
));
2736 /* Fill the OBJECTS_AND_NAME structure */
2737 pObjName
->ObjectType
= ObjectType
;
2738 if (ObjectTypeName
!= NULL
)
2740 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2743 pObjName
->InheritedObjectTypeName
= InheritedObjectTypeName
;
2744 if (InheritedObjectTypeName
!= NULL
)
2746 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2749 pObjName
->ObjectsPresent
= ObjectsPresent
;
2750 pObjName
->ptstrName
= Name
;
2752 /* Fill the TRUSTEE structure */
2753 pTrustee
->pMultipleTrustee
= NULL
;
2754 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2755 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_NAME
;
2756 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2757 pTrustee
->ptstrName
= (LPSTR
)pObjName
;
2760 /******************************************************************************
2761 * BuildTrusteeWithObjectsAndNameW [ADVAPI32.@]
2763 VOID WINAPI
BuildTrusteeWithObjectsAndNameW( PTRUSTEEW pTrustee
, POBJECTS_AND_NAME_W pObjName
,
2764 SE_OBJECT_TYPE ObjectType
, LPWSTR ObjectTypeName
,
2765 LPWSTR InheritedObjectTypeName
, LPWSTR Name
)
2767 DWORD ObjectsPresent
= 0;
2769 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee
, pObjName
,
2770 ObjectType
, ObjectTypeName
, InheritedObjectTypeName
, debugstr_w(Name
));
2772 /* Fill the OBJECTS_AND_NAME structure */
2773 pObjName
->ObjectType
= ObjectType
;
2774 if (ObjectTypeName
!= NULL
)
2776 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2779 pObjName
->InheritedObjectTypeName
= InheritedObjectTypeName
;
2780 if (InheritedObjectTypeName
!= NULL
)
2782 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2785 pObjName
->ObjectsPresent
= ObjectsPresent
;
2786 pObjName
->ptstrName
= Name
;
2788 /* Fill the TRUSTEE structure */
2789 pTrustee
->pMultipleTrustee
= NULL
;
2790 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2791 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_NAME
;
2792 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2793 pTrustee
->ptstrName
= (LPWSTR
)pObjName
;
2796 /******************************************************************************
2797 * BuildTrusteeWithObjectsAndSidA [ADVAPI32.@]
2799 VOID WINAPI
BuildTrusteeWithObjectsAndSidA( PTRUSTEEA pTrustee
, POBJECTS_AND_SID pObjSid
,
2800 GUID
* pObjectGuid
, GUID
* pInheritedObjectGuid
, PSID pSid
)
2802 DWORD ObjectsPresent
= 0;
2804 TRACE("%p %p %p %p %p\n", pTrustee
, pObjSid
, pObjectGuid
, pInheritedObjectGuid
, pSid
);
2806 /* Fill the OBJECTS_AND_SID structure */
2807 if (pObjectGuid
!= NULL
)
2809 pObjSid
->ObjectTypeGuid
= *pObjectGuid
;
2810 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2814 ZeroMemory(&pObjSid
->ObjectTypeGuid
,
2818 if (pInheritedObjectGuid
!= NULL
)
2820 pObjSid
->InheritedObjectTypeGuid
= *pInheritedObjectGuid
;
2821 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2825 ZeroMemory(&pObjSid
->InheritedObjectTypeGuid
,
2829 pObjSid
->ObjectsPresent
= ObjectsPresent
;
2830 pObjSid
->pSid
= pSid
;
2832 /* Fill the TRUSTEE structure */
2833 pTrustee
->pMultipleTrustee
= NULL
;
2834 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2835 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_SID
;
2836 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2837 pTrustee
->ptstrName
= (LPSTR
) pObjSid
;
2840 /******************************************************************************
2841 * BuildTrusteeWithObjectsAndSidW [ADVAPI32.@]
2843 VOID WINAPI
BuildTrusteeWithObjectsAndSidW( PTRUSTEEW pTrustee
, POBJECTS_AND_SID pObjSid
,
2844 GUID
* pObjectGuid
, GUID
* pInheritedObjectGuid
, PSID pSid
)
2846 DWORD ObjectsPresent
= 0;
2848 TRACE("%p %p %p %p %p\n", pTrustee
, pObjSid
, pObjectGuid
, pInheritedObjectGuid
, pSid
);
2850 /* Fill the OBJECTS_AND_SID structure */
2851 if (pObjectGuid
!= NULL
)
2853 pObjSid
->ObjectTypeGuid
= *pObjectGuid
;
2854 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2858 ZeroMemory(&pObjSid
->ObjectTypeGuid
,
2862 if (pInheritedObjectGuid
!= NULL
)
2864 pObjSid
->InheritedObjectTypeGuid
= *pInheritedObjectGuid
;
2865 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2869 ZeroMemory(&pObjSid
->InheritedObjectTypeGuid
,
2873 pObjSid
->ObjectsPresent
= ObjectsPresent
;
2874 pObjSid
->pSid
= pSid
;
2876 /* Fill the TRUSTEE structure */
2877 pTrustee
->pMultipleTrustee
= NULL
;
2878 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2879 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_SID
;
2880 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2881 pTrustee
->ptstrName
= (LPWSTR
) pObjSid
;
2884 /******************************************************************************
2885 * BuildTrusteeWithSidA [ADVAPI32.@]
2887 VOID WINAPI
BuildTrusteeWithSidA(PTRUSTEEA pTrustee
, PSID pSid
)
2889 TRACE("%p %p\n", pTrustee
, pSid
);
2891 pTrustee
->pMultipleTrustee
= NULL
;
2892 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2893 pTrustee
->TrusteeForm
= TRUSTEE_IS_SID
;
2894 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2895 pTrustee
->ptstrName
= (LPSTR
) pSid
;
2898 /******************************************************************************
2899 * BuildTrusteeWithSidW [ADVAPI32.@]
2901 VOID WINAPI
BuildTrusteeWithSidW(PTRUSTEEW pTrustee
, PSID pSid
)
2903 TRACE("%p %p\n", pTrustee
, pSid
);
2905 pTrustee
->pMultipleTrustee
= NULL
;
2906 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2907 pTrustee
->TrusteeForm
= TRUSTEE_IS_SID
;
2908 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2909 pTrustee
->ptstrName
= (LPWSTR
) pSid
;
2912 /******************************************************************************
2913 * BuildTrusteeWithNameA [ADVAPI32.@]
2915 VOID WINAPI
BuildTrusteeWithNameA(PTRUSTEEA pTrustee
, LPSTR name
)
2917 TRACE("%p %s\n", pTrustee
, debugstr_a(name
) );
2919 pTrustee
->pMultipleTrustee
= NULL
;
2920 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2921 pTrustee
->TrusteeForm
= TRUSTEE_IS_NAME
;
2922 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2923 pTrustee
->ptstrName
= name
;
2926 /******************************************************************************
2927 * BuildTrusteeWithNameW [ADVAPI32.@]
2929 VOID WINAPI
BuildTrusteeWithNameW(PTRUSTEEW pTrustee
, LPWSTR name
)
2931 TRACE("%p %s\n", pTrustee
, debugstr_w(name
) );
2933 pTrustee
->pMultipleTrustee
= NULL
;
2934 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2935 pTrustee
->TrusteeForm
= TRUSTEE_IS_NAME
;
2936 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2937 pTrustee
->ptstrName
= name
;
2940 /******************************************************************************
2941 * GetTrusteeFormA [ADVAPI32.@]
2943 TRUSTEE_FORM WINAPI
GetTrusteeFormA(PTRUSTEEA pTrustee
)
2945 TRACE("(%p)\n", pTrustee
);
2948 return TRUSTEE_BAD_FORM
;
2950 return pTrustee
->TrusteeForm
;
2953 /******************************************************************************
2954 * GetTrusteeFormW [ADVAPI32.@]
2956 TRUSTEE_FORM WINAPI
GetTrusteeFormW(PTRUSTEEW pTrustee
)
2958 TRACE("(%p)\n", pTrustee
);
2961 return TRUSTEE_BAD_FORM
;
2963 return pTrustee
->TrusteeForm
;
2966 /******************************************************************************
2967 * GetTrusteeNameA [ADVAPI32.@]
2969 LPSTR WINAPI
GetTrusteeNameA(PTRUSTEEA pTrustee
)
2971 TRACE("(%p)\n", pTrustee
);
2976 return pTrustee
->ptstrName
;
2979 /******************************************************************************
2980 * GetTrusteeNameW [ADVAPI32.@]
2982 LPWSTR WINAPI
GetTrusteeNameW(PTRUSTEEW pTrustee
)
2984 TRACE("(%p)\n", pTrustee
);
2989 return pTrustee
->ptstrName
;
2992 /******************************************************************************
2993 * GetTrusteeTypeA [ADVAPI32.@]
2995 TRUSTEE_TYPE WINAPI
GetTrusteeTypeA(PTRUSTEEA pTrustee
)
2997 TRACE("(%p)\n", pTrustee
);
3000 return TRUSTEE_IS_UNKNOWN
;
3002 return pTrustee
->TrusteeType
;
3005 /******************************************************************************
3006 * GetTrusteeTypeW [ADVAPI32.@]
3008 TRUSTEE_TYPE WINAPI
GetTrusteeTypeW(PTRUSTEEW pTrustee
)
3010 TRACE("(%p)\n", pTrustee
);
3013 return TRUSTEE_IS_UNKNOWN
;
3015 return pTrustee
->TrusteeType
;
3018 BOOL WINAPI
SetAclInformation( PACL pAcl
, LPVOID pAclInformation
,
3019 DWORD nAclInformationLength
,
3020 ACL_INFORMATION_CLASS dwAclInformationClass
)
3022 FIXME("%p %p 0x%08x 0x%08x - stub\n", pAcl
, pAclInformation
,
3023 nAclInformationLength
, dwAclInformationClass
);
3028 /******************************************************************************
3029 * SetEntriesInAclA [ADVAPI32.@]
3031 DWORD WINAPI
SetEntriesInAclA( ULONG count
, PEXPLICIT_ACCESSA pEntries
,
3032 PACL OldAcl
, PACL
* NewAcl
)
3034 FIXME("%d %p %p %p\n",count
,pEntries
,OldAcl
,NewAcl
);
3036 return ERROR_SUCCESS
;
3039 /******************************************************************************
3040 * SetEntriesInAclW [ADVAPI32.@]
3042 DWORD WINAPI
SetEntriesInAclW( ULONG count
, PEXPLICIT_ACCESSW pEntries
,
3043 PACL OldAcl
, PACL
* NewAcl
)
3045 FIXME("%d %p %p %p\n",count
,pEntries
,OldAcl
,NewAcl
);
3047 return ERROR_SUCCESS
;
3050 /******************************************************************************
3051 * SetNamedSecurityInfoA [ADVAPI32.@]
3053 DWORD WINAPI
SetNamedSecurityInfoA(LPSTR pObjectName
,
3054 SE_OBJECT_TYPE ObjectType
, SECURITY_INFORMATION SecurityInfo
,
3055 PSID psidOwner
, PSID psidGroup
, PACL pDacl
, PACL pSacl
)
3061 TRACE("%s %d %d %p %p %p %p\n", debugstr_a(pObjectName
), ObjectType
,
3062 SecurityInfo
, psidOwner
, psidGroup
, pDacl
, pSacl
);
3066 len
= MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, NULL
, 0 );
3067 wstr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
3068 MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, wstr
, len
);
3071 r
= SetNamedSecurityInfoW( wstr
, ObjectType
, SecurityInfo
, psidOwner
,
3072 psidGroup
, pDacl
, pSacl
);
3074 HeapFree( GetProcessHeap(), 0, wstr
);
3079 BOOL WINAPI
SetPrivateObjectSecurity( SECURITY_INFORMATION SecurityInformation
,
3080 PSECURITY_DESCRIPTOR ModificationDescriptor
,
3081 PSECURITY_DESCRIPTOR
* ObjectsSecurityDescriptor
,
3082 PGENERIC_MAPPING GenericMapping
,
3085 FIXME("0x%08x %p %p %p %p - stub\n", SecurityInformation
, ModificationDescriptor
,
3086 ObjectsSecurityDescriptor
, GenericMapping
, Token
);
3091 BOOL WINAPI
AreAllAccessesGranted( DWORD GrantedAccess
, DWORD DesiredAccess
)
3093 return RtlAreAllAccessesGranted( GrantedAccess
, DesiredAccess
);
3096 /******************************************************************************
3097 * AreAnyAccessesGranted [ADVAPI32.@]
3099 * Determines whether or not any of a set of specified access permissions have
3100 * been granted or not.
3103 * GrantedAccess [I] The permissions that have been granted.
3104 * DesiredAccess [I] The permissions that you want to have.
3107 * Nonzero if any of the permissions have been granted, zero if none of the
3108 * permissions have been granted.
3111 BOOL WINAPI
AreAnyAccessesGranted( DWORD GrantedAccess
, DWORD DesiredAccess
)
3113 return RtlAreAnyAccessesGranted( GrantedAccess
, DesiredAccess
);
3116 /******************************************************************************
3117 * SetNamedSecurityInfoW [ADVAPI32.@]
3119 DWORD WINAPI
SetNamedSecurityInfoW(LPWSTR pObjectName
,
3120 SE_OBJECT_TYPE ObjectType
, SECURITY_INFORMATION SecurityInfo
,
3121 PSID psidOwner
, PSID psidGroup
, PACL pDacl
, PACL pSacl
)
3123 FIXME("%s %d %d %p %p %p %p\n", debugstr_w(pObjectName
), ObjectType
,
3124 SecurityInfo
, psidOwner
, psidGroup
, pDacl
, pSacl
);
3125 return ERROR_SUCCESS
;
3128 /******************************************************************************
3129 * GetExplicitEntriesFromAclA [ADVAPI32.@]
3131 DWORD WINAPI
GetExplicitEntriesFromAclA( PACL pacl
, PULONG pcCountOfExplicitEntries
,
3132 PEXPLICIT_ACCESSA
* pListOfExplicitEntries
)
3134 FIXME("%p %p %p\n",pacl
, pcCountOfExplicitEntries
, pListOfExplicitEntries
);
3135 return ERROR_CALL_NOT_IMPLEMENTED
;
3138 /******************************************************************************
3139 * GetExplicitEntriesFromAclW [ADVAPI32.@]
3141 DWORD WINAPI
GetExplicitEntriesFromAclW( PACL pacl
, PULONG pcCountOfExplicitEntries
,
3142 PEXPLICIT_ACCESSW
* pListOfExplicitEntries
)
3144 FIXME("%p %p %p\n",pacl
, pcCountOfExplicitEntries
, pListOfExplicitEntries
);
3145 return ERROR_CALL_NOT_IMPLEMENTED
;
3149 /******************************************************************************
3150 * ParseAclStringFlags
3152 static DWORD
ParseAclStringFlags(LPCWSTR
* StringAcl
)
3155 LPCWSTR szAcl
= *StringAcl
;
3157 while (*szAcl
!= '(')
3161 flags
|= SE_DACL_PROTECTED
;
3163 else if (*szAcl
== 'A')
3167 flags
|= SE_DACL_AUTO_INHERIT_REQ
;
3168 else if (*szAcl
== 'I')
3169 flags
|= SE_DACL_AUTO_INHERITED
;
3178 /******************************************************************************
3179 * ParseAceStringType
3181 static const ACEFLAG AceType
[] =
3183 { SDDL_ALARM
, SYSTEM_ALARM_ACE_TYPE
},
3184 { SDDL_AUDIT
, SYSTEM_AUDIT_ACE_TYPE
},
3185 { SDDL_ACCESS_ALLOWED
, ACCESS_ALLOWED_ACE_TYPE
},
3186 { SDDL_ACCESS_DENIED
, ACCESS_DENIED_ACE_TYPE
},
3188 { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
3189 { SDDL_OBJECT_ACCESS_DENIED, ACCESS_DENIED_OBJECT_ACE_TYPE },
3190 { SDDL_OBJECT_ALARM, SYSTEM_ALARM_OBJECT_ACE_TYPE },
3191 { SDDL_OBJECT_AUDIT, SYSTEM_AUDIT_OBJECT_ACE_TYPE },
3196 static BYTE
ParseAceStringType(LPCWSTR
* StringAcl
)
3199 LPCWSTR szAcl
= *StringAcl
;
3200 const ACEFLAG
*lpaf
= AceType
;
3202 while (lpaf
->wstr
&&
3203 (len
= strlenW(lpaf
->wstr
)) &&
3204 strncmpW(lpaf
->wstr
, szAcl
, len
))
3215 /******************************************************************************
3216 * ParseAceStringFlags
3218 static const ACEFLAG AceFlags
[] =
3220 { SDDL_CONTAINER_INHERIT
, CONTAINER_INHERIT_ACE
},
3221 { SDDL_AUDIT_FAILURE
, FAILED_ACCESS_ACE_FLAG
},
3222 { SDDL_INHERITED
, INHERITED_ACE
},
3223 { SDDL_INHERIT_ONLY
, INHERIT_ONLY_ACE
},
3224 { SDDL_NO_PROPAGATE
, NO_PROPAGATE_INHERIT_ACE
},
3225 { SDDL_OBJECT_INHERIT
, OBJECT_INHERIT_ACE
},
3226 { SDDL_AUDIT_SUCCESS
, SUCCESSFUL_ACCESS_ACE_FLAG
},
3230 static BYTE
ParseAceStringFlags(LPCWSTR
* StringAcl
)
3234 LPCWSTR szAcl
= *StringAcl
;
3236 while (*szAcl
!= ';')
3238 const ACEFLAG
*lpaf
= AceFlags
;
3240 while (lpaf
->wstr
&&
3241 (len
= strlenW(lpaf
->wstr
)) &&
3242 strncmpW(lpaf
->wstr
, szAcl
, len
))
3248 flags
|= lpaf
->value
;
3257 /******************************************************************************
3258 * ParseAceStringRights
3260 static const ACEFLAG AceRights
[] =
3262 { SDDL_GENERIC_ALL
, GENERIC_ALL
},
3263 { SDDL_GENERIC_READ
, GENERIC_READ
},
3264 { SDDL_GENERIC_WRITE
, GENERIC_WRITE
},
3265 { SDDL_GENERIC_EXECUTE
, GENERIC_EXECUTE
},
3267 { SDDL_READ_CONTROL
, READ_CONTROL
},
3268 { SDDL_STANDARD_DELETE
, DELETE
},
3269 { SDDL_WRITE_DAC
, WRITE_DAC
},
3270 { SDDL_WRITE_OWNER
, WRITE_OWNER
},
3272 { SDDL_READ_PROPERTY
, ADS_RIGHT_DS_READ_PROP
},
3273 { SDDL_WRITE_PROPERTY
, ADS_RIGHT_DS_WRITE_PROP
},
3274 { SDDL_CREATE_CHILD
, ADS_RIGHT_DS_CREATE_CHILD
},
3275 { SDDL_DELETE_CHILD
, ADS_RIGHT_DS_DELETE_CHILD
},
3276 { SDDL_LIST_CHILDREN
, ADS_RIGHT_ACTRL_DS_LIST
},
3277 { SDDL_SELF_WRITE
, ADS_RIGHT_DS_SELF
},
3278 { SDDL_LIST_OBJECT
, ADS_RIGHT_DS_LIST_OBJECT
},
3279 { SDDL_DELETE_TREE
, ADS_RIGHT_DS_DELETE_TREE
},
3280 { SDDL_CONTROL_ACCESS
, ADS_RIGHT_DS_CONTROL_ACCESS
},
3282 { SDDL_FILE_ALL
, FILE_ALL_ACCESS
},
3283 { SDDL_FILE_READ
, FILE_GENERIC_READ
},
3284 { SDDL_FILE_WRITE
, FILE_GENERIC_WRITE
},
3285 { SDDL_FILE_EXECUTE
, FILE_GENERIC_EXECUTE
},
3287 { SDDL_KEY_ALL
, KEY_ALL_ACCESS
},
3288 { SDDL_KEY_READ
, KEY_READ
},
3289 { SDDL_KEY_WRITE
, KEY_WRITE
},
3290 { SDDL_KEY_EXECUTE
, KEY_EXECUTE
},
3294 static DWORD
ParseAceStringRights(LPCWSTR
* StringAcl
)
3298 LPCWSTR szAcl
= *StringAcl
;
3300 if ((*szAcl
== '0') && (*(szAcl
+ 1) == 'x'))
3304 while (*p
&& *p
!= ';')
3307 if (p
- szAcl
<= 10 /* 8 hex digits + "0x" */ )
3309 rights
= strtoulW(szAcl
, NULL
, 16);
3313 WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl
, p
- szAcl
));
3317 while (*szAcl
!= ';')
3319 const ACEFLAG
*lpaf
= AceRights
;
3321 while (lpaf
->wstr
&&
3322 (len
= strlenW(lpaf
->wstr
)) &&
3323 strncmpW(lpaf
->wstr
, szAcl
, len
))
3331 rights
|= lpaf
->value
;
3341 /******************************************************************************
3342 * ParseStringAclToAcl
3344 * dacl_flags(string_ace1)(string_ace2)... (string_acen)
3346 static BOOL
ParseStringAclToAcl(LPCWSTR StringAcl
, LPDWORD lpdwFlags
,
3347 PACL pAcl
, LPDWORD cBytes
)
3351 DWORD length
= sizeof(ACL
);
3354 PACCESS_ALLOWED_ACE pAce
= NULL
; /* pointer to current ACE */
3356 TRACE("%s\n", debugstr_w(StringAcl
));
3361 if (pAcl
) /* pAce is only useful if we're setting values */
3362 pAce
= (PACCESS_ALLOWED_ACE
) (pAcl
+ 1);
3364 /* Parse ACL flags */
3365 *lpdwFlags
= ParseAclStringFlags(&StringAcl
);
3368 while (*StringAcl
== '(')
3372 /* Parse ACE type */
3373 val
= ParseAceStringType(&StringAcl
);
3375 pAce
->Header
.AceType
= (BYTE
) val
;
3376 if (*StringAcl
!= ';')
3380 /* Parse ACE flags */
3381 val
= ParseAceStringFlags(&StringAcl
);
3383 pAce
->Header
.AceFlags
= (BYTE
) val
;
3384 if (*StringAcl
!= ';')
3388 /* Parse ACE rights */
3389 val
= ParseAceStringRights(&StringAcl
);
3392 if (*StringAcl
!= ';')
3396 /* Parse ACE object guid */
3397 if (*StringAcl
!= ';')
3399 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3404 /* Parse ACE inherit object guid */
3405 if (*StringAcl
!= ';')
3407 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3412 /* Parse ACE account sid */
3413 if (ParseStringSidToSid(StringAcl
, pAce
? (PSID
)&pAce
->SidStart
: NULL
, &sidlen
))
3415 while (*StringAcl
&& *StringAcl
!= ')')
3419 if (*StringAcl
!= ')')
3423 acesize
= sizeof(ACCESS_ALLOWED_ACE
) - sizeof(DWORD
) + sidlen
;
3427 pAce
->Header
.AceSize
= acesize
;
3428 pAce
= (PACCESS_ALLOWED_ACE
)((LPBYTE
)pAce
+ acesize
);
3435 if (length
> 0xffff)
3437 ERR("ACL too large\n");
3443 pAcl
->AclRevision
= ACL_REVISION
;
3445 pAcl
->AclSize
= length
;
3446 pAcl
->AceCount
= acecount
++;
3452 WARN("Invalid ACE string format\n");
3457 /******************************************************************************
3458 * ParseStringSecurityDescriptorToSecurityDescriptor
3460 static BOOL
ParseStringSecurityDescriptorToSecurityDescriptor(
3461 LPCWSTR StringSecurityDescriptor
,
3462 SECURITY_DESCRIPTOR
* SecurityDescriptor
,
3467 WCHAR tok
[MAX_PATH
];
3469 LPBYTE lpNext
= NULL
;
3472 *cBytes
= sizeof(SECURITY_DESCRIPTOR
);
3474 if (SecurityDescriptor
)
3475 lpNext
= ((LPBYTE
) SecurityDescriptor
) + sizeof(SECURITY_DESCRIPTOR
);
3477 while (*StringSecurityDescriptor
)
3479 toktype
= *StringSecurityDescriptor
;
3481 /* Expect char identifier followed by ':' */
3482 StringSecurityDescriptor
++;
3483 if (*StringSecurityDescriptor
!= ':')
3485 SetLastError(ERROR_INVALID_PARAMETER
);
3488 StringSecurityDescriptor
++;
3491 lptoken
= StringSecurityDescriptor
;
3492 while (*lptoken
&& *lptoken
!= ':')
3498 len
= lptoken
- StringSecurityDescriptor
;
3499 memcpy( tok
, StringSecurityDescriptor
, len
* sizeof(WCHAR
) );
3508 if (!ParseStringSidToSid(tok
, (PSID
)lpNext
, &bytes
))
3511 if (SecurityDescriptor
)
3513 SecurityDescriptor
->Owner
= (PSID
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3514 lpNext
+= bytes
; /* Advance to next token */
3526 if (!ParseStringSidToSid(tok
, (PSID
)lpNext
, &bytes
))
3529 if (SecurityDescriptor
)
3531 SecurityDescriptor
->Group
= (PSID
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3532 lpNext
+= bytes
; /* Advance to next token */
3545 if (!ParseStringAclToAcl(tok
, &flags
, (PACL
)lpNext
, &bytes
))
3548 if (SecurityDescriptor
)
3550 SecurityDescriptor
->Control
|= SE_DACL_PRESENT
| flags
;
3551 SecurityDescriptor
->Dacl
= (PACL
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3552 lpNext
+= bytes
; /* Advance to next token */
3565 if (!ParseStringAclToAcl(tok
, &flags
, (PACL
)lpNext
, &bytes
))
3568 if (SecurityDescriptor
)
3570 SecurityDescriptor
->Control
|= SE_SACL_PRESENT
| flags
;
3571 SecurityDescriptor
->Sacl
= (PACL
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3572 lpNext
+= bytes
; /* Advance to next token */
3581 FIXME("Unknown token\n");
3582 SetLastError(ERROR_INVALID_PARAMETER
);
3586 StringSecurityDescriptor
= lptoken
;
3595 /******************************************************************************
3596 * ConvertStringSecurityDescriptorToSecurityDescriptorA [ADVAPI32.@]
3598 BOOL WINAPI
ConvertStringSecurityDescriptorToSecurityDescriptorA(
3599 LPCSTR StringSecurityDescriptor
,
3600 DWORD StringSDRevision
,
3601 PSECURITY_DESCRIPTOR
* SecurityDescriptor
,
3602 PULONG SecurityDescriptorSize
)
3606 LPWSTR StringSecurityDescriptorW
;
3608 len
= MultiByteToWideChar(CP_ACP
, 0, StringSecurityDescriptor
, -1, NULL
, 0);
3609 StringSecurityDescriptorW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3611 if (StringSecurityDescriptorW
)
3613 MultiByteToWideChar(CP_ACP
, 0, StringSecurityDescriptor
, -1, StringSecurityDescriptorW
, len
);
3615 ret
= ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptorW
,
3616 StringSDRevision
, SecurityDescriptor
,
3617 SecurityDescriptorSize
);
3618 HeapFree(GetProcessHeap(), 0, StringSecurityDescriptorW
);
3624 /******************************************************************************
3625 * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
3627 BOOL WINAPI
ConvertStringSecurityDescriptorToSecurityDescriptorW(
3628 LPCWSTR StringSecurityDescriptor
,
3629 DWORD StringSDRevision
,
3630 PSECURITY_DESCRIPTOR
* SecurityDescriptor
,
3631 PULONG SecurityDescriptorSize
)
3634 SECURITY_DESCRIPTOR
* psd
;
3637 TRACE("%s\n", debugstr_w(StringSecurityDescriptor
));
3639 if (GetVersion() & 0x80000000)
3641 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3644 else if (StringSDRevision
!= SID_REVISION
)
3646 SetLastError(ERROR_UNKNOWN_REVISION
);
3650 /* Compute security descriptor length */
3651 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor
,
3655 psd
= *SecurityDescriptor
= (SECURITY_DESCRIPTOR
*) LocalAlloc(
3656 GMEM_ZEROINIT
, cBytes
);
3657 if (!psd
) goto lend
;
3659 psd
->Revision
= SID_REVISION
;
3660 psd
->Control
|= SE_SELF_RELATIVE
;
3662 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor
,
3669 if (SecurityDescriptorSize
)
3670 *SecurityDescriptorSize
= cBytes
;
3675 TRACE(" ret=%d\n", bret
);
3679 static void DumpString(LPCWSTR string
, int cch
, WCHAR
**pwptr
, ULONG
*plen
)
3682 cch
= strlenW(string
);
3689 memcpy(*pwptr
, string
, sizeof(WCHAR
)*cch
);
3694 static BOOL
DumpSidNumeric(PSID psid
, WCHAR
**pwptr
, ULONG
*plen
)
3697 WCHAR fmt
[] = { 'S','-','%','u','-','%','d',0 };
3698 WCHAR subauthfmt
[] = { '-','%','u',0 };
3702 if( !IsValidSid( psid
) || pisid
->Revision
!= SDDL_REVISION
)
3704 SetLastError(ERROR_INVALID_SID
);
3708 if (pisid
->IdentifierAuthority
.Value
[0] ||
3709 pisid
->IdentifierAuthority
.Value
[1])
3711 FIXME("not matching MS' bugs\n");
3712 SetLastError(ERROR_INVALID_SID
);
3716 sprintfW( buf
, fmt
, pisid
->Revision
,
3718 MAKEWORD( pisid
->IdentifierAuthority
.Value
[5],
3719 pisid
->IdentifierAuthority
.Value
[4] ),
3720 MAKEWORD( pisid
->IdentifierAuthority
.Value
[3],
3721 pisid
->IdentifierAuthority
.Value
[2] )
3723 DumpString(buf
, -1, pwptr
, plen
);
3725 for( i
=0; i
<pisid
->SubAuthorityCount
; i
++ )
3727 sprintfW( buf
, subauthfmt
, pisid
->SubAuthority
[i
] );
3728 DumpString(buf
, -1, pwptr
, plen
);
3733 static BOOL
DumpSid(PSID psid
, WCHAR
**pwptr
, ULONG
*plen
)
3736 for (i
= 0; i
< sizeof(WellKnownSids
) / sizeof(WellKnownSids
[0]); i
++)
3738 if (WellKnownSids
[i
].wstr
[0] && EqualSid(psid
, (PSID
)&(WellKnownSids
[i
].Sid
.Revision
)))
3740 DumpString(WellKnownSids
[i
].wstr
, 2, pwptr
, plen
);
3745 return DumpSidNumeric(psid
, pwptr
, plen
);
3748 static const LPCWSTR AceRightBitNames
[32] = {
3749 SDDL_CREATE_CHILD
, /* 0 */
3753 SDDL_READ_PROPERTY
, /* 4 */
3754 SDDL_WRITE_PROPERTY
,
3757 SDDL_CONTROL_ACCESS
, /* 8 */
3765 SDDL_STANDARD_DELETE
, /* 16 */
3777 SDDL_GENERIC_ALL
, /* 28 */
3778 SDDL_GENERIC_EXECUTE
,
3783 static void DumpRights(DWORD mask
, WCHAR
**pwptr
, ULONG
*plen
)
3785 static const WCHAR fmtW
[] = {'0','x','%','x',0};
3792 /* first check if the right have name */
3793 for (i
= 0; i
< sizeof(AceRights
)/sizeof(AceRights
[0]); i
++)
3795 if (AceRights
[i
].wstr
== NULL
)
3797 if (mask
== AceRights
[i
].value
)
3799 DumpString(AceRights
[i
].wstr
, -1, pwptr
, plen
);
3804 /* then check if it can be built from bit names */
3805 for (i
= 0; i
< 32; i
++)
3807 if ((mask
& (1 << i
)) && (AceRightBitNames
[i
] == NULL
))
3809 /* can't be built from bit names */
3810 sprintfW(buf
, fmtW
, mask
);
3811 DumpString(buf
, -1, pwptr
, plen
);
3816 /* build from bit names */
3817 for (i
= 0; i
< 32; i
++)
3818 if (mask
& (1 << i
))
3819 DumpString(AceRightBitNames
[i
], -1, pwptr
, plen
);
3822 static BOOL
DumpAce(LPVOID pace
, WCHAR
**pwptr
, ULONG
*plen
)
3824 ACCESS_ALLOWED_ACE
*piace
; /* all the supported ACEs have the same memory layout */
3825 static const WCHAR openbr
= '(';
3826 static const WCHAR closebr
= ')';
3827 static const WCHAR semicolon
= ';';
3829 if (((PACE_HEADER
)pace
)->AceType
> SYSTEM_ALARM_ACE_TYPE
|| ((PACE_HEADER
)pace
)->AceSize
< sizeof(ACCESS_ALLOWED_ACE
))
3831 SetLastError(ERROR_INVALID_ACL
);
3835 piace
= (ACCESS_ALLOWED_ACE
*)pace
;
3836 DumpString(&openbr
, 1, pwptr
, plen
);
3837 switch (piace
->Header
.AceType
)
3839 case ACCESS_ALLOWED_ACE_TYPE
:
3840 DumpString(SDDL_ACCESS_ALLOWED
, -1, pwptr
, plen
);
3842 case ACCESS_DENIED_ACE_TYPE
:
3843 DumpString(SDDL_ACCESS_DENIED
, -1, pwptr
, plen
);
3845 case SYSTEM_AUDIT_ACE_TYPE
:
3846 DumpString(SDDL_AUDIT
, -1, pwptr
, plen
);
3848 case SYSTEM_ALARM_ACE_TYPE
:
3849 DumpString(SDDL_ALARM
, -1, pwptr
, plen
);
3852 DumpString(&semicolon
, 1, pwptr
, plen
);
3854 if (piace
->Header
.AceFlags
& OBJECT_INHERIT_ACE
)
3855 DumpString(SDDL_OBJECT_INHERIT
, -1, pwptr
, plen
);
3856 if (piace
->Header
.AceFlags
& CONTAINER_INHERIT_ACE
)
3857 DumpString(SDDL_CONTAINER_INHERIT
, -1, pwptr
, plen
);
3858 if (piace
->Header
.AceFlags
& NO_PROPAGATE_INHERIT_ACE
)
3859 DumpString(SDDL_NO_PROPAGATE
, -1, pwptr
, plen
);
3860 if (piace
->Header
.AceFlags
& INHERIT_ONLY_ACE
)
3861 DumpString(SDDL_INHERIT_ONLY
, -1, pwptr
, plen
);
3862 if (piace
->Header
.AceFlags
& INHERITED_ACE
)
3863 DumpString(SDDL_INHERITED
, -1, pwptr
, plen
);
3864 if (piace
->Header
.AceFlags
& SUCCESSFUL_ACCESS_ACE_FLAG
)
3865 DumpString(SDDL_AUDIT_SUCCESS
, -1, pwptr
, plen
);
3866 if (piace
->Header
.AceFlags
& FAILED_ACCESS_ACE_FLAG
)
3867 DumpString(SDDL_AUDIT_FAILURE
, -1, pwptr
, plen
);
3868 DumpString(&semicolon
, 1, pwptr
, plen
);
3869 DumpRights(piace
->Mask
, pwptr
, plen
);
3870 DumpString(&semicolon
, 1, pwptr
, plen
);
3871 /* objects not supported */
3872 DumpString(&semicolon
, 1, pwptr
, plen
);
3873 /* objects not supported */
3874 DumpString(&semicolon
, 1, pwptr
, plen
);
3875 if (!DumpSid((PSID
)&piace
->SidStart
, pwptr
, plen
))
3877 DumpString(&closebr
, 1, pwptr
, plen
);
3881 static BOOL
DumpAcl(PACL pacl
, WCHAR
**pwptr
, ULONG
*plen
, BOOL
protected, BOOL autoInheritReq
, BOOL autoInherited
)
3887 DumpString(SDDL_PROTECTED
, -1, pwptr
, plen
);
3889 DumpString(SDDL_AUTO_INHERIT_REQ
, -1, pwptr
, plen
);
3891 DumpString(SDDL_AUTO_INHERITED
, -1, pwptr
, plen
);
3896 if (!IsValidAcl(pacl
))
3899 count
= pacl
->AceCount
;
3900 for (i
= 0; i
< count
; i
++)
3903 if (!GetAce(pacl
, i
, &ace
))
3905 if (!DumpAce(ace
, pwptr
, plen
))
3912 static BOOL
DumpOwner(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
3914 static const WCHAR prefix
[] = {'O',':',0};
3918 if (!GetSecurityDescriptorOwner(SecurityDescriptor
, &psid
, &bDefaulted
))
3924 DumpString(prefix
, -1, pwptr
, plen
);
3925 if (!DumpSid(psid
, pwptr
, plen
))
3930 static BOOL
DumpGroup(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
3932 static const WCHAR prefix
[] = {'G',':',0};
3936 if (!GetSecurityDescriptorGroup(SecurityDescriptor
, &psid
, &bDefaulted
))
3942 DumpString(prefix
, -1, pwptr
, plen
);
3943 if (!DumpSid(psid
, pwptr
, plen
))
3948 static BOOL
DumpDacl(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
3950 static const WCHAR dacl
[] = {'D',':',0};
3951 SECURITY_DESCRIPTOR_CONTROL control
;
3952 BOOL present
, defaulted
;
3956 if (!GetSecurityDescriptorDacl(SecurityDescriptor
, &present
, &pacl
, &defaulted
))
3959 if (!GetSecurityDescriptorControl(SecurityDescriptor
, &control
, &revision
))
3965 DumpString(dacl
, 2, pwptr
, plen
);
3966 if (!DumpAcl(pacl
, pwptr
, plen
, control
& SE_DACL_PROTECTED
, control
& SE_DACL_AUTO_INHERIT_REQ
, control
& SE_DACL_AUTO_INHERITED
))
3971 static BOOL
DumpSacl(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
3973 static const WCHAR sacl
[] = {'S',':',0};
3974 SECURITY_DESCRIPTOR_CONTROL control
;
3975 BOOL present
, defaulted
;
3979 if (!GetSecurityDescriptorSacl(SecurityDescriptor
, &present
, &pacl
, &defaulted
))
3982 if (!GetSecurityDescriptorControl(SecurityDescriptor
, &control
, &revision
))
3988 DumpString(sacl
, 2, pwptr
, plen
);
3989 if (!DumpAcl(pacl
, pwptr
, plen
, control
& SE_SACL_PROTECTED
, control
& SE_SACL_AUTO_INHERIT_REQ
, control
& SE_SACL_AUTO_INHERITED
))
3994 /******************************************************************************
3995 * ConvertSecurityDescriptorToStringSecurityDescriptorA [ADVAPI32.@]
3997 BOOL WINAPI
ConvertSecurityDescriptorToStringSecurityDescriptorW(PSECURITY_DESCRIPTOR SecurityDescriptor
, DWORD SDRevision
, SECURITY_INFORMATION RequestedInformation
, LPWSTR
*OutputString
, PULONG OutputLen
)
4002 if (SDRevision
!= SDDL_REVISION_1
)
4004 ERR("Pogram requested unknown SDDL revision %d\n", SDRevision
);
4005 SetLastError(ERROR_UNKNOWN_REVISION
);
4010 if (RequestedInformation
& OWNER_SECURITY_INFORMATION
)
4011 if (!DumpOwner(SecurityDescriptor
, NULL
, &len
))
4013 if (RequestedInformation
& GROUP_SECURITY_INFORMATION
)
4014 if (!DumpGroup(SecurityDescriptor
, NULL
, &len
))
4016 if (RequestedInformation
& DACL_SECURITY_INFORMATION
)
4017 if (!DumpDacl(SecurityDescriptor
, NULL
, &len
))
4019 if (RequestedInformation
& SACL_SECURITY_INFORMATION
)
4020 if (!DumpSacl(SecurityDescriptor
, NULL
, &len
))
4023 wstr
= wptr
= LocalAlloc(0, (len
+ 1)*sizeof(WCHAR
));
4024 if (RequestedInformation
& OWNER_SECURITY_INFORMATION
)
4025 if (!DumpOwner(SecurityDescriptor
, &wptr
, NULL
))
4027 if (RequestedInformation
& GROUP_SECURITY_INFORMATION
)
4028 if (!DumpGroup(SecurityDescriptor
, &wptr
, NULL
))
4030 if (RequestedInformation
& DACL_SECURITY_INFORMATION
)
4031 if (!DumpDacl(SecurityDescriptor
, &wptr
, NULL
))
4033 if (RequestedInformation
& SACL_SECURITY_INFORMATION
)
4034 if (!DumpSacl(SecurityDescriptor
, &wptr
, NULL
))
4038 TRACE("ret: %s, %d\n", wine_dbgstr_w(wstr
), len
);
4039 *OutputString
= wstr
;
4041 *OutputLen
= strlenW(*OutputString
)+1;
4045 /******************************************************************************
4046 * ConvertSecurityDescriptorToStringSecurityDescriptorA [ADVAPI32.@]
4048 BOOL WINAPI
ConvertSecurityDescriptorToStringSecurityDescriptorA(PSECURITY_DESCRIPTOR SecurityDescriptor
, DWORD SDRevision
, SECURITY_INFORMATION Information
, LPSTR
*OutputString
, PULONG OutputLen
)
4052 if (ConvertSecurityDescriptorToStringSecurityDescriptorW(SecurityDescriptor
, SDRevision
, Information
, &wstr
, &len
))
4056 lenA
= WideCharToMultiByte(CP_ACP
, 0, wstr
, len
, NULL
, 0, NULL
, NULL
);
4057 *OutputString
= HeapAlloc(GetProcessHeap(), 0, lenA
);
4058 WideCharToMultiByte(CP_ACP
, 0, wstr
, len
, *OutputString
, lenA
, NULL
, NULL
);
4061 if (OutputLen
!= NULL
)
4067 *OutputString
= NULL
;
4074 /******************************************************************************
4075 * ConvertStringSidToSidW [ADVAPI32.@]
4077 BOOL WINAPI
ConvertStringSidToSidW(LPCWSTR StringSid
, PSID
* Sid
)
4082 TRACE("%s, %p\n", debugstr_w(StringSid
), Sid
);
4083 if (GetVersion() & 0x80000000)
4084 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4085 else if (!StringSid
|| !Sid
)
4086 SetLastError(ERROR_INVALID_PARAMETER
);
4087 else if (ParseStringSidToSid(StringSid
, NULL
, &cBytes
))
4089 PSID pSid
= *Sid
= (PSID
) LocalAlloc(0, cBytes
);
4091 bret
= ParseStringSidToSid(StringSid
, pSid
, &cBytes
);
4095 TRACE("returning %s\n", bret
? "TRUE" : "FALSE");
4099 /******************************************************************************
4100 * ConvertStringSidToSidA [ADVAPI32.@]
4102 BOOL WINAPI
ConvertStringSidToSidA(LPCSTR StringSid
, PSID
* Sid
)
4106 TRACE("%s, %p\n", debugstr_a(StringSid
), Sid
);
4107 if (GetVersion() & 0x80000000)
4108 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4109 else if (!StringSid
|| !Sid
)
4110 SetLastError(ERROR_INVALID_PARAMETER
);
4113 UINT len
= MultiByteToWideChar(CP_ACP
, 0, StringSid
, -1, NULL
, 0);
4114 LPWSTR wStringSid
= HeapAlloc(GetProcessHeap(), 0,
4115 len
* sizeof(WCHAR
));
4117 MultiByteToWideChar(CP_ACP
, 0, StringSid
, -1, wStringSid
, len
);
4118 bret
= ConvertStringSidToSidW(wStringSid
, Sid
);
4119 HeapFree(GetProcessHeap(), 0, wStringSid
);
4121 TRACE("returning %s\n", bret
? "TRUE" : "FALSE");
4125 /******************************************************************************
4126 * ConvertSidToStringSidW [ADVAPI32.@]
4128 * format of SID string is:
4129 * S-<count>-<auth>-<subauth1>-<subauth2>-<subauth3>...
4131 * <rev> is the revision of the SID encoded as decimal
4132 * <auth> is the identifier authority encoded as hex
4133 * <subauthN> is the subauthority id encoded as decimal
4135 BOOL WINAPI
ConvertSidToStringSidW( PSID pSid
, LPWSTR
*pstr
)
4140 TRACE("%p %p\n", pSid
, pstr
);
4143 if (!DumpSidNumeric(pSid
, NULL
, &len
))
4145 wstr
= wptr
= LocalAlloc(0, (len
+1) * sizeof(WCHAR
));
4146 DumpSidNumeric(pSid
, &wptr
, NULL
);
4153 /******************************************************************************
4154 * ConvertSidToStringSidA [ADVAPI32.@]
4156 BOOL WINAPI
ConvertSidToStringSidA(PSID pSid
, LPSTR
*pstr
)
4162 TRACE("%p %p\n", pSid
, pstr
);
4164 if( !ConvertSidToStringSidW( pSid
, &wstr
) )
4167 len
= WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
4168 str
= LocalAlloc( 0, len
);
4169 WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, str
, len
, NULL
, NULL
);
4177 BOOL WINAPI
CreatePrivateObjectSecurity(
4178 PSECURITY_DESCRIPTOR ParentDescriptor
,
4179 PSECURITY_DESCRIPTOR CreatorDescriptor
,
4180 PSECURITY_DESCRIPTOR
* NewDescriptor
,
4181 BOOL IsDirectoryObject
,
4183 PGENERIC_MAPPING GenericMapping
)
4185 FIXME("%p %p %p %d %p %p - stub\n", ParentDescriptor
, CreatorDescriptor
,
4186 NewDescriptor
, IsDirectoryObject
, Token
, GenericMapping
);
4191 BOOL WINAPI
DestroyPrivateObjectSecurity( PSECURITY_DESCRIPTOR
* ObjectDescriptor
)
4193 FIXME("%p - stub\n", ObjectDescriptor
);
4198 BOOL WINAPI
CreateProcessAsUserA(
4200 LPCSTR lpApplicationName
,
4201 LPSTR lpCommandLine
,
4202 LPSECURITY_ATTRIBUTES lpProcessAttributes
,
4203 LPSECURITY_ATTRIBUTES lpThreadAttributes
,
4204 BOOL bInheritHandles
,
4205 DWORD dwCreationFlags
,
4206 LPVOID lpEnvironment
,
4207 LPCSTR lpCurrentDirectory
,
4208 LPSTARTUPINFOA lpStartupInfo
,
4209 LPPROCESS_INFORMATION lpProcessInformation
)
4211 FIXME("%p %s %s %p %p %d 0x%08x %p %s %p %p - stub\n", hToken
, debugstr_a(lpApplicationName
),
4212 debugstr_a(lpCommandLine
), lpProcessAttributes
, lpThreadAttributes
, bInheritHandles
,
4213 dwCreationFlags
, lpEnvironment
, debugstr_a(lpCurrentDirectory
), lpStartupInfo
, lpProcessInformation
);
4218 BOOL WINAPI
CreateProcessAsUserW(
4220 LPCWSTR lpApplicationName
,
4221 LPWSTR lpCommandLine
,
4222 LPSECURITY_ATTRIBUTES lpProcessAttributes
,
4223 LPSECURITY_ATTRIBUTES lpThreadAttributes
,
4224 BOOL bInheritHandles
,
4225 DWORD dwCreationFlags
,
4226 LPVOID lpEnvironment
,
4227 LPCWSTR lpCurrentDirectory
,
4228 LPSTARTUPINFOW lpStartupInfo
,
4229 LPPROCESS_INFORMATION lpProcessInformation
)
4231 FIXME("%p %s %s %p %p %d 0x%08x %p %s %p %p - semi- stub\n", hToken
,
4232 debugstr_w(lpApplicationName
), debugstr_w(lpCommandLine
), lpProcessAttributes
,
4233 lpThreadAttributes
, bInheritHandles
, dwCreationFlags
, lpEnvironment
,
4234 debugstr_w(lpCurrentDirectory
), lpStartupInfo
, lpProcessInformation
);
4236 /* We should create the process with a suspended main thread */
4237 if (!CreateProcessW (lpApplicationName
,
4239 lpProcessAttributes
,
4242 dwCreationFlags
, /* CREATE_SUSPENDED */
4246 lpProcessInformation
))
4254 /******************************************************************************
4255 * DuplicateTokenEx [ADVAPI32.@]
4257 BOOL WINAPI
DuplicateTokenEx(
4258 HANDLE ExistingTokenHandle
, DWORD dwDesiredAccess
,
4259 LPSECURITY_ATTRIBUTES lpTokenAttributes
,
4260 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
4261 TOKEN_TYPE TokenType
,
4262 PHANDLE DuplicateTokenHandle
)
4264 OBJECT_ATTRIBUTES ObjectAttributes
;
4266 TRACE("%p 0x%08x 0x%08x 0x%08x %p\n", ExistingTokenHandle
, dwDesiredAccess
,
4267 ImpersonationLevel
, TokenType
, DuplicateTokenHandle
);
4269 InitializeObjectAttributes(
4272 (lpTokenAttributes
&& lpTokenAttributes
->bInheritHandle
) ? OBJ_INHERIT
: 0,
4274 lpTokenAttributes
? lpTokenAttributes
->lpSecurityDescriptor
: NULL
);
4276 return set_ntstatus( NtDuplicateToken( ExistingTokenHandle
,
4281 DuplicateTokenHandle
) );
4284 BOOL WINAPI
DuplicateToken(
4285 HANDLE ExistingTokenHandle
,
4286 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
4287 PHANDLE DuplicateTokenHandle
)
4289 return DuplicateTokenEx( ExistingTokenHandle
, TOKEN_IMPERSONATE
| TOKEN_QUERY
,
4290 NULL
, ImpersonationLevel
, TokenImpersonation
,
4291 DuplicateTokenHandle
);
4294 BOOL WINAPI
EnumDependentServicesA(
4296 DWORD dwServiceState
,
4297 LPENUM_SERVICE_STATUSA lpServices
,
4299 LPDWORD pcbBytesNeeded
,
4300 LPDWORD lpServicesReturned
)
4302 FIXME("%p 0x%08x %p 0x%08x %p %p - stub\n", hService
, dwServiceState
,
4303 lpServices
, cbBufSize
, pcbBytesNeeded
, lpServicesReturned
);
4308 BOOL WINAPI
EnumDependentServicesW(
4310 DWORD dwServiceState
,
4311 LPENUM_SERVICE_STATUSW lpServices
,
4313 LPDWORD pcbBytesNeeded
,
4314 LPDWORD lpServicesReturned
)
4316 FIXME("%p 0x%08x %p 0x%08x %p %p - stub\n", hService
, dwServiceState
,
4317 lpServices
, cbBufSize
, pcbBytesNeeded
, lpServicesReturned
);
4322 /******************************************************************************
4323 * ComputeStringSidSize
4325 static DWORD
ComputeStringSidSize(LPCWSTR StringSid
)
4327 if (StringSid
[0] == 'S' && StringSid
[1] == '-') /* S-R-I(-S)+ */
4332 if (*StringSid
== '-')
4338 return GetSidLengthRequired(ctok
- 2);
4340 else /* String constant format - Only available in winxp and above */
4344 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
4345 if (!strncmpW(WellKnownSids
[i
].wstr
, StringSid
, 2))
4346 return GetSidLengthRequired(WellKnownSids
[i
].Sid
.SubAuthorityCount
);
4349 return GetSidLengthRequired(0);
4352 /******************************************************************************
4353 * ParseStringSidToSid
4355 static BOOL
ParseStringSidToSid(LPCWSTR StringSid
, PSID pSid
, LPDWORD cBytes
)
4360 TRACE("%s, %p, %p\n", debugstr_w(StringSid
), pSid
, cBytes
);
4363 SetLastError(ERROR_INVALID_PARAMETER
);
4364 TRACE("StringSid is NULL, returning FALSE\n");
4368 *cBytes
= ComputeStringSidSize(StringSid
);
4369 if (!pisid
) /* Simply compute the size */
4371 TRACE("only size requested, returning TRUE\n");
4375 if (StringSid
[0] == 'S' && StringSid
[1] == '-') /* S-R-I-S-S */
4377 DWORD i
= 0, identAuth
;
4378 DWORD csubauth
= ((*cBytes
- GetSidLengthRequired(0)) / sizeof(DWORD
));
4380 StringSid
+= 2; /* Advance to Revision */
4381 pisid
->Revision
= atoiW(StringSid
);
4383 if (pisid
->Revision
!= SDDL_REVISION
)
4385 TRACE("Revision %d is unknown\n", pisid
->Revision
);
4386 goto lend
; /* ERROR_INVALID_SID */
4390 TRACE("SubAuthorityCount is 0\n");
4391 goto lend
; /* ERROR_INVALID_SID */
4394 pisid
->SubAuthorityCount
= csubauth
;
4396 /* Advance to identifier authority */
4397 while (*StringSid
&& *StringSid
!= '-')
4399 if (*StringSid
== '-')
4402 /* MS' implementation can't handle values greater than 2^32 - 1, so
4403 * we don't either; assume most significant bytes are always 0
4405 pisid
->IdentifierAuthority
.Value
[0] = 0;
4406 pisid
->IdentifierAuthority
.Value
[1] = 0;
4407 identAuth
= atoiW(StringSid
);
4408 pisid
->IdentifierAuthority
.Value
[5] = identAuth
& 0xff;
4409 pisid
->IdentifierAuthority
.Value
[4] = (identAuth
& 0xff00) >> 8;
4410 pisid
->IdentifierAuthority
.Value
[3] = (identAuth
& 0xff0000) >> 16;
4411 pisid
->IdentifierAuthority
.Value
[2] = (identAuth
& 0xff000000) >> 24;
4413 /* Advance to first sub authority */
4414 while (*StringSid
&& *StringSid
!= '-')
4416 if (*StringSid
== '-')
4421 pisid
->SubAuthority
[i
++] = atoiW(StringSid
);
4423 while (*StringSid
&& *StringSid
!= '-')
4425 if (*StringSid
== '-')
4429 if (i
!= pisid
->SubAuthorityCount
)
4430 goto lend
; /* ERROR_INVALID_SID */
4434 else /* String constant format - Only available in winxp and above */
4437 pisid
->Revision
= SDDL_REVISION
;
4439 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
4440 if (!strncmpW(WellKnownSids
[i
].wstr
, StringSid
, 2))
4443 pisid
->SubAuthorityCount
= WellKnownSids
[i
].Sid
.SubAuthorityCount
;
4444 pisid
->IdentifierAuthority
= WellKnownSids
[i
].Sid
.IdentifierAuthority
;
4445 for (j
= 0; j
< WellKnownSids
[i
].Sid
.SubAuthorityCount
; j
++)
4446 pisid
->SubAuthority
[j
] = WellKnownSids
[i
].Sid
.SubAuthority
[j
];
4451 FIXME("String constant not supported: %s\n", debugstr_wn(StringSid
, 2));
4456 SetLastError(ERROR_INVALID_SID
);
4458 TRACE("returning %s\n", bret
? "TRUE" : "FALSE");
4462 /******************************************************************************
4463 * GetNamedSecurityInfoA [ADVAPI32.@]
4465 DWORD WINAPI
GetNamedSecurityInfoA(LPSTR pObjectName
,
4466 SE_OBJECT_TYPE ObjectType
, SECURITY_INFORMATION SecurityInfo
,
4467 PSID
* ppsidOwner
, PSID
* ppsidGroup
, PACL
* ppDacl
, PACL
* ppSacl
,
4468 PSECURITY_DESCRIPTOR
* ppSecurityDescriptor
)
4474 TRACE("%s %d %d %p %p %p %p %p\n", pObjectName
, ObjectType
, SecurityInfo
,
4475 ppsidOwner
, ppsidGroup
, ppDacl
, ppSacl
, ppSecurityDescriptor
);
4479 len
= MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, NULL
, 0 );
4480 wstr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
4481 MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, wstr
, len
);
4484 r
= GetNamedSecurityInfoW( wstr
, ObjectType
, SecurityInfo
, ppsidOwner
,
4485 ppsidGroup
, ppDacl
, ppSacl
, ppSecurityDescriptor
);
4487 HeapFree( GetProcessHeap(), 0, wstr
);
4492 /******************************************************************************
4493 * GetNamedSecurityInfoW [ADVAPI32.@]
4495 DWORD WINAPI
GetNamedSecurityInfoW( LPWSTR name
, SE_OBJECT_TYPE type
,
4496 SECURITY_INFORMATION info
, PSID
* owner
, PSID
* group
, PACL
* dacl
,
4497 PACL
* sacl
, PSECURITY_DESCRIPTOR
* descriptor
)
4499 DWORD needed
, offset
;
4500 SECURITY_DESCRIPTOR_RELATIVE
*relative
;
4503 TRACE( "%s %d %d %p %p %p %p %p\n", debugstr_w(name
), type
, info
, owner
,
4504 group
, dacl
, sacl
, descriptor
);
4506 if (!name
|| !descriptor
) return ERROR_INVALID_PARAMETER
;
4508 needed
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
4509 if (info
& OWNER_SECURITY_INFORMATION
)
4510 needed
+= sizeof(sidWorld
);
4511 if (info
& GROUP_SECURITY_INFORMATION
)
4512 needed
+= sizeof(sidWorld
);
4513 if (info
& DACL_SECURITY_INFORMATION
)
4514 needed
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
4515 if (info
& SACL_SECURITY_INFORMATION
)
4516 needed
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
4518 /* must be freed by caller */
4519 *descriptor
= HeapAlloc( GetProcessHeap(), 0, needed
);
4520 if (!*descriptor
) return ERROR_NOT_ENOUGH_MEMORY
;
4522 if (!InitializeSecurityDescriptor( *descriptor
, SECURITY_DESCRIPTOR_REVISION
))
4524 HeapFree( GetProcessHeap(), 0, *descriptor
);
4525 return ERROR_INVALID_SECURITY_DESCR
;
4528 relative
= (SECURITY_DESCRIPTOR_RELATIVE
*)*descriptor
;
4529 relative
->Control
|= SE_SELF_RELATIVE
;
4530 buffer
= (BYTE
*)relative
;
4531 offset
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
4533 if (info
& OWNER_SECURITY_INFORMATION
)
4535 memcpy( buffer
+ offset
, &sidWorld
, sizeof(sidWorld
) );
4536 relative
->Owner
= offset
;
4538 *owner
= buffer
+ offset
;
4539 offset
+= sizeof(sidWorld
);
4541 if (info
& GROUP_SECURITY_INFORMATION
)
4543 memcpy( buffer
+ offset
, &sidWorld
, sizeof(sidWorld
) );
4544 relative
->Group
= offset
;
4546 *group
= buffer
+ offset
;
4547 offset
+= sizeof(sidWorld
);
4549 if (info
& DACL_SECURITY_INFORMATION
)
4551 relative
->Control
|= SE_DACL_PRESENT
;
4552 GetWorldAccessACL( (PACL
)(buffer
+ offset
) );
4553 relative
->Dacl
= offset
;
4555 *dacl
= (PACL
)(buffer
+ offset
);
4556 offset
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
4558 if (info
& SACL_SECURITY_INFORMATION
)
4560 relative
->Control
|= SE_SACL_PRESENT
;
4561 GetWorldAccessACL( (PACL
)(buffer
+ offset
) );
4562 relative
->Sacl
= offset
;
4564 *sacl
= (PACL
)(buffer
+ offset
);
4566 return ERROR_SUCCESS
;
4569 /******************************************************************************
4570 * DecryptFileW [ADVAPI32.@]
4572 BOOL WINAPI
DecryptFileW(LPCWSTR lpFileName
, DWORD dwReserved
)
4574 FIXME("%s %08x\n", debugstr_w(lpFileName
), dwReserved
);
4578 /******************************************************************************
4579 * DecryptFileA [ADVAPI32.@]
4581 BOOL WINAPI
DecryptFileA(LPCSTR lpFileName
, DWORD dwReserved
)
4583 FIXME("%s %08x\n", debugstr_a(lpFileName
), dwReserved
);
4587 /******************************************************************************
4588 * EncryptFileW [ADVAPI32.@]
4590 BOOL WINAPI
EncryptFileW(LPCWSTR lpFileName
)
4592 FIXME("%s\n", debugstr_w(lpFileName
));
4596 /******************************************************************************
4597 * EncryptFileA [ADVAPI32.@]
4599 BOOL WINAPI
EncryptFileA(LPCSTR lpFileName
)
4601 FIXME("%s\n", debugstr_a(lpFileName
));
4605 /******************************************************************************
4606 * FileEncryptionStatusW [ADVAPI32.@]
4608 BOOL WINAPI
FileEncryptionStatusW(LPCWSTR lpFileName
, LPDWORD lpStatus
)
4610 FIXME("(%s %p): stub\n", debugstr_w(lpFileName
), lpStatus
);
4613 *lpStatus
= FILE_SYSTEM_NOT_SUPPORT
;
4617 /******************************************************************************
4618 * FileEncryptionStatusA [ADVAPI32.@]
4620 BOOL WINAPI
FileEncryptionStatusA(LPCSTR lpFileName
, LPDWORD lpStatus
)
4622 FIXME("(%s %p): stub\n", debugstr_a(lpFileName
), lpStatus
);
4625 *lpStatus
= FILE_SYSTEM_NOT_SUPPORT
;
4629 /******************************************************************************
4630 * SetSecurityInfo [ADVAPI32.@]
4632 DWORD WINAPI
SetSecurityInfo(HANDLE handle
, SE_OBJECT_TYPE ObjectType
,
4633 SECURITY_INFORMATION SecurityInfo
, PSID psidOwner
,
4634 PSID psidGroup
, PACL pDacl
, PACL pSacl
) {
4636 return ERROR_SUCCESS
;