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
} } },
130 { {0,0}, WinBuiltinDCOMUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_DCOM_USERS
} } },
133 /* these SIDs must be constructed as relative to some domain - only the RID is well-known */
134 typedef struct WELLKNOWNRID
136 WELL_KNOWN_SID_TYPE Type
;
140 static const WELLKNOWNRID WellKnownRids
[] = {
141 { WinAccountAdministratorSid
, DOMAIN_USER_RID_ADMIN
},
142 { WinAccountGuestSid
, DOMAIN_USER_RID_GUEST
},
143 { WinAccountKrbtgtSid
, DOMAIN_USER_RID_KRBTGT
},
144 { WinAccountDomainAdminsSid
, DOMAIN_GROUP_RID_ADMINS
},
145 { WinAccountDomainUsersSid
, DOMAIN_GROUP_RID_USERS
},
146 { WinAccountDomainGuestsSid
, DOMAIN_GROUP_RID_GUESTS
},
147 { WinAccountComputersSid
, DOMAIN_GROUP_RID_COMPUTERS
},
148 { WinAccountControllersSid
, DOMAIN_GROUP_RID_CONTROLLERS
},
149 { WinAccountCertAdminsSid
, DOMAIN_GROUP_RID_CERT_ADMINS
},
150 { WinAccountSchemaAdminsSid
, DOMAIN_GROUP_RID_SCHEMA_ADMINS
},
151 { WinAccountEnterpriseAdminsSid
, DOMAIN_GROUP_RID_ENTERPRISE_ADMINS
},
152 { WinAccountPolicyAdminsSid
, DOMAIN_GROUP_RID_POLICY_ADMINS
},
153 { WinAccountRasAndIasServersSid
, DOMAIN_ALIAS_RID_RAS_SERVERS
},
157 static SID
const sidWorld
= { SID_REVISION
, 1, { SECURITY_WORLD_SID_AUTHORITY
} , { SECURITY_WORLD_RID
} };
159 typedef struct _AccountSid
{
160 WELL_KNOWN_SID_TYPE type
;
163 SID_NAME_USE name_use
;
166 static const WCHAR Account_Operators
[] = { 'A','c','c','o','u','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
167 static const WCHAR Administrator
[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0 };
168 static const WCHAR Administrators
[] = { 'A','d','m','i','n','i','s','t','r','a','t','o','r','s',0 };
169 static const WCHAR ANONYMOUS_LOGON
[] = { 'A','N','O','N','Y','M','O','U','S',' ','L','O','G','O','N',0 };
170 static const WCHAR Authenticated_Users
[] = { 'A','u','t','h','e','n','t','i','c','a','t','e','d',' ','U','s','e','r','s',0 };
171 static const WCHAR Backup_Operators
[] = { 'B','a','c','k','u','p',' ','O','p','e','r','a','t','o','r','s',0 };
172 static const WCHAR BATCH
[] = { 'B','A','T','C','H',0 };
173 static const WCHAR Blank
[] = { 0 };
174 static const WCHAR BUILTIN
[] = { 'B','U','I','L','T','I','N',0 };
175 static const WCHAR Cert_Publishers
[] = { 'C','e','r','t',' ','P','u','b','l','i','s','h','e','r','s',0 };
176 static const WCHAR CREATOR_GROUP
[] = { 'C','R','E','A','T','O','R',' ','G','R','O','U','P',0 };
177 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 };
178 static const WCHAR CREATOR_OWNER
[] = { 'C','R','E','A','T','O','R',' ','O','W','N','E','R',0 };
179 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 };
180 static const WCHAR DIALUP
[] = { 'D','I','A','L','U','P',0 };
181 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 };
182 static const WCHAR DOMAIN
[] = {'D','O','M','A','I','N',0};
183 static const WCHAR Domain_Admins
[] = { 'D','o','m','a','i','n',' ','A','d','m','i','n','s',0 };
184 static const WCHAR Domain_Computers
[] = { 'D','o','m','a','i','n',' ','C','o','m','p','u','t','e','r','s',0 };
185 static const WCHAR Domain_Controllers
[] = { 'D','o','m','a','i','n',' ','C','o','n','t','r','o','l','l','e','r','s',0 };
186 static const WCHAR Domain_Guests
[] = { 'D','o','m','a','i','n',' ','G','u','e','s','t','s',0 };
187 static const WCHAR Domain_Users
[] = { 'D','o','m','a','i','n',' ','U','s','e','r','s',0 };
188 static const WCHAR Enterprise_Admins
[] = { 'E','n','t','e','r','p','r','i','s','e',' ','A','d','m','i','n','s',0 };
189 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 };
190 static const WCHAR Everyone
[] = { 'E','v','e','r','y','o','n','e',0 };
191 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 };
192 static const WCHAR Guest
[] = { 'G','u','e','s','t',0 };
193 static const WCHAR Guests
[] = { 'G','u','e','s','t','s',0 };
194 static const WCHAR INTERACTIVE
[] = { 'I','N','T','E','R','A','C','T','I','V','E',0 };
195 static const WCHAR LOCAL
[] = { 'L','O','C','A','L',0 };
196 static const WCHAR LOCAL_SERVICE
[] = { 'L','O','C','A','L',' ','S','E','R','V','I','C','E',0 };
197 static const WCHAR NETWORK
[] = { 'N','E','T','W','O','R','K',0 };
198 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 };
199 static const WCHAR NETWORK_SERVICE
[] = { 'N','E','T','W','O','R','K',' ','S','E','R','V','I','C','E',0 };
200 static const WCHAR NT_AUTHORITY
[] = { 'N','T',' ','A','U','T','H','O','R','I','T','Y',0 };
201 static const WCHAR NT_Pseudo_Domain
[] = { 'N','T',' ','P','s','e','u','d','o',' ','D','o','m','a','i','n',0 };
202 static const WCHAR NTML_Authentication
[] = { 'N','T','M','L',' ','A','u','t','h','e','n','t','i','c','a','t','i','o','n',0 };
203 static const WCHAR NULL_SID
[] = { 'N','U','L','L',' ','S','I','D',0 };
204 static const WCHAR Other_Organization
[] = { 'O','t','h','e','r',' ','O','r','g','a','n','i','z','a','t','i','o','n',0 };
205 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 };
206 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 };
207 static const WCHAR Power_Users
[] = { 'P','o','w','e','r',' ','U','s','e','r','s',0 };
208 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 };
209 static const WCHAR Print_Operators
[] = { 'P','r','i','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
210 static const WCHAR PROXY
[] = { 'P','R','O','X','Y',0 };
211 static const WCHAR RAS_and_IAS_Servers
[] = { 'R','A','S',' ','a','n','d',' ','I','A','S',' ','S','e','r','v','e','r','s',0 };
212 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 };
213 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 };
214 static const WCHAR Replicators
[] = { 'R','e','p','l','i','c','a','t','o','r','s',0 };
215 static const WCHAR RESTRICTED
[] = { 'R','E','S','T','R','I','C','T','E','D',0 };
216 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 };
217 static const WCHAR Schema_Admins
[] = { 'S','c','h','e','m','a',' ','A','d','m','i','n','s',0 };
218 static const WCHAR SELF
[] = { 'S','E','L','F',0 };
219 static const WCHAR Server_Operators
[] = { 'S','e','r','v','e','r',' ','O','p','e','r','a','t','o','r','s',0 };
220 static const WCHAR SERVICE
[] = { 'S','E','R','V','I','C','E',0 };
221 static const WCHAR SYSTEM
[] = { 'S','Y','S','T','E','M',0 };
222 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 };
223 static const WCHAR This_Organization
[] = { 'T','h','i','s',' ','O','r','g','a','n','i','z','a','t','i','o','n',0 };
224 static const WCHAR Users
[] = { 'U','s','e','r','s',0 };
226 static const AccountSid ACCOUNT_SIDS
[] = {
227 { WinNullSid
, NULL_SID
, Blank
, SidTypeWellKnownGroup
},
228 { WinWorldSid
, Everyone
, Blank
, SidTypeWellKnownGroup
},
229 { WinLocalSid
, LOCAL
, Blank
, SidTypeWellKnownGroup
},
230 { WinCreatorOwnerSid
, CREATOR_OWNER
, Blank
, SidTypeWellKnownGroup
},
231 { WinCreatorGroupSid
, CREATOR_GROUP
, Blank
, SidTypeWellKnownGroup
},
232 { WinCreatorOwnerServerSid
, CREATOR_OWNER_SERVER
, Blank
, SidTypeWellKnownGroup
},
233 { WinCreatorGroupServerSid
, CREATOR_GROUP_SERVER
, Blank
, SidTypeWellKnownGroup
},
234 { WinNtAuthoritySid
, NT_Pseudo_Domain
, NT_Pseudo_Domain
, SidTypeDomain
},
235 { WinDialupSid
, DIALUP
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
236 { WinNetworkSid
, NETWORK
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
237 { WinBatchSid
, BATCH
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
238 { WinInteractiveSid
, INTERACTIVE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
239 { WinServiceSid
, SERVICE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
240 { WinAnonymousSid
, ANONYMOUS_LOGON
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
241 { WinProxySid
, PROXY
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
242 { WinEnterpriseControllersSid
, ENTERPRISE_DOMAIN_CONTROLLERS
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
243 { WinSelfSid
, SELF
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
244 { WinAuthenticatedUserSid
, Authenticated_Users
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
245 { WinRestrictedCodeSid
, RESTRICTED
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
246 { WinTerminalServerSid
, TERMINAL_SERVER_USER
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
247 { WinRemoteLogonIdSid
, REMOTE_INTERACTIVE_LOGON
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
248 { WinLocalSystemSid
, SYSTEM
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
249 { WinLocalServiceSid
, LOCAL_SERVICE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
250 { WinNetworkServiceSid
, NETWORK_SERVICE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
251 { WinBuiltinDomainSid
, BUILTIN
, BUILTIN
, SidTypeDomain
},
252 { WinBuiltinAdministratorsSid
, Administrators
, BUILTIN
, SidTypeAlias
},
253 { WinBuiltinUsersSid
, Users
, BUILTIN
, SidTypeAlias
},
254 { WinBuiltinGuestsSid
, Guests
, BUILTIN
, SidTypeAlias
},
255 { WinBuiltinPowerUsersSid
, Power_Users
, BUILTIN
, SidTypeAlias
},
256 { WinBuiltinAccountOperatorsSid
, Account_Operators
, BUILTIN
, SidTypeAlias
},
257 { WinBuiltinSystemOperatorsSid
, Server_Operators
, BUILTIN
, SidTypeAlias
},
258 { WinBuiltinPrintOperatorsSid
, Print_Operators
, BUILTIN
, SidTypeAlias
},
259 { WinBuiltinBackupOperatorsSid
, Backup_Operators
, BUILTIN
, SidTypeAlias
},
260 { WinBuiltinReplicatorSid
, Replicators
, BUILTIN
, SidTypeAlias
},
261 { WinBuiltinPreWindows2000CompatibleAccessSid
, Pre_Windows_2000_Compatible_Access
, BUILTIN
, SidTypeAlias
},
262 { WinBuiltinRemoteDesktopUsersSid
, Remote_Desktop_Users
, BUILTIN
, SidTypeAlias
},
263 { WinBuiltinNetworkConfigurationOperatorsSid
, Network_Configuration_Operators
, BUILTIN
, SidTypeAlias
},
264 { WinNTLMAuthenticationSid
, NTML_Authentication
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
265 { WinDigestAuthenticationSid
, Digest_Authentication
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
266 { WinSChannelAuthenticationSid
, SChannel_Authentication
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
267 { WinThisOrganizationSid
, This_Organization
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
268 { WinOtherOrganizationSid
, Other_Organization
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
269 { WinBuiltinPerfMonitoringUsersSid
, Performance_Monitor_Users
, BUILTIN
, SidTypeAlias
},
270 { WinBuiltinPerfLoggingUsersSid
, Performance_Log_Users
, BUILTIN
, SidTypeAlias
},
275 static const WCHAR SDDL_READ_CONTROL
[] = {'R','C',0};
276 static const WCHAR SDDL_WRITE_DAC
[] = {'W','D',0};
277 static const WCHAR SDDL_WRITE_OWNER
[] = {'W','O',0};
278 static const WCHAR SDDL_STANDARD_DELETE
[] = {'S','D',0};
280 static const WCHAR SDDL_READ_PROPERTY
[] = {'R','P',0};
281 static const WCHAR SDDL_WRITE_PROPERTY
[] = {'W','P',0};
282 static const WCHAR SDDL_CREATE_CHILD
[] = {'C','C',0};
283 static const WCHAR SDDL_DELETE_CHILD
[] = {'D','C',0};
284 static const WCHAR SDDL_LIST_CHILDREN
[] = {'L','C',0};
285 static const WCHAR SDDL_SELF_WRITE
[] = {'S','W',0};
286 static const WCHAR SDDL_LIST_OBJECT
[] = {'L','O',0};
287 static const WCHAR SDDL_DELETE_TREE
[] = {'D','T',0};
288 static const WCHAR SDDL_CONTROL_ACCESS
[] = {'C','R',0};
290 static const WCHAR SDDL_FILE_ALL
[] = {'F','A',0};
291 static const WCHAR SDDL_FILE_READ
[] = {'F','R',0};
292 static const WCHAR SDDL_FILE_WRITE
[] = {'F','W',0};
293 static const WCHAR SDDL_FILE_EXECUTE
[] = {'F','X',0};
295 static const WCHAR SDDL_KEY_ALL
[] = {'K','A',0};
296 static const WCHAR SDDL_KEY_READ
[] = {'K','R',0};
297 static const WCHAR SDDL_KEY_WRITE
[] = {'K','W',0};
298 static const WCHAR SDDL_KEY_EXECUTE
[] = {'K','X',0};
300 static const WCHAR SDDL_GENERIC_ALL
[] = {'G','A',0};
301 static const WCHAR SDDL_GENERIC_READ
[] = {'G','R',0};
302 static const WCHAR SDDL_GENERIC_WRITE
[] = {'G','W',0};
303 static const WCHAR SDDL_GENERIC_EXECUTE
[] = {'G','X',0};
308 static const WCHAR SDDL_PROTECTED
[] = {'P',0};
309 static const WCHAR SDDL_AUTO_INHERIT_REQ
[] = {'A','R',0};
310 static const WCHAR SDDL_AUTO_INHERITED
[] = {'A','I',0};
315 static const WCHAR SDDL_ACCESS_ALLOWED
[] = {'A',0};
316 static const WCHAR SDDL_ACCESS_DENIED
[] = {'D',0};
317 static const WCHAR SDDL_OBJECT_ACCESS_ALLOWED
[] = {'O','A',0};
318 static const WCHAR SDDL_OBJECT_ACCESS_DENIED
[] = {'O','D',0};
319 static const WCHAR SDDL_AUDIT
[] = {'A','U',0};
320 static const WCHAR SDDL_ALARM
[] = {'A','L',0};
321 static const WCHAR SDDL_OBJECT_AUDIT
[] = {'O','U',0};
322 static const WCHAR SDDL_OBJECT_ALARMp
[] = {'O','L',0};
327 static const WCHAR SDDL_CONTAINER_INHERIT
[] = {'C','I',0};
328 static const WCHAR SDDL_OBJECT_INHERIT
[] = {'O','I',0};
329 static const WCHAR SDDL_NO_PROPAGATE
[] = {'N','P',0};
330 static const WCHAR SDDL_INHERIT_ONLY
[] = {'I','O',0};
331 static const WCHAR SDDL_INHERITED
[] = {'I','D',0};
332 static const WCHAR SDDL_AUDIT_SUCCESS
[] = {'S','A',0};
333 static const WCHAR SDDL_AUDIT_FAILURE
[] = {'F','A',0};
335 const char * debugstr_sid(PSID sid
)
338 SID
* psid
= (SID
*)sid
;
343 auth
= psid
->IdentifierAuthority
.Value
[5] +
344 (psid
->IdentifierAuthority
.Value
[4] << 8) +
345 (psid
->IdentifierAuthority
.Value
[3] << 16) +
346 (psid
->IdentifierAuthority
.Value
[2] << 24);
348 switch (psid
->SubAuthorityCount
) {
350 return wine_dbg_sprintf("S-%d-%d", psid
->Revision
, auth
);
352 return wine_dbg_sprintf("S-%d-%d-%u", psid
->Revision
, auth
,
353 psid
->SubAuthority
[0]);
355 return wine_dbg_sprintf("S-%d-%d-%u-%u", psid
->Revision
, auth
,
356 psid
->SubAuthority
[0], psid
->SubAuthority
[1]);
358 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u", psid
->Revision
, auth
,
359 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2]);
361 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u", psid
->Revision
, auth
,
362 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
363 psid
->SubAuthority
[3]);
365 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
366 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
367 psid
->SubAuthority
[3], psid
->SubAuthority
[4]);
369 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
370 psid
->SubAuthority
[3], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
371 psid
->SubAuthority
[0], psid
->SubAuthority
[4], psid
->SubAuthority
[5]);
373 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
374 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
375 psid
->SubAuthority
[3], psid
->SubAuthority
[4], psid
->SubAuthority
[5],
376 psid
->SubAuthority
[6]);
378 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
379 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
380 psid
->SubAuthority
[3], psid
->SubAuthority
[4], psid
->SubAuthority
[5],
381 psid
->SubAuthority
[6], psid
->SubAuthority
[7]);
386 /* set last error code from NT status and get the proper boolean return value */
387 /* used for functions that are a simple wrapper around the corresponding ntdll API */
388 static inline BOOL
set_ntstatus( NTSTATUS status
)
390 if (status
) SetLastError( RtlNtStatusToDosError( status
));
394 #define WINE_SIZE_OF_WORLD_ACCESS_ACL (sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD))
396 static void GetWorldAccessACL(PACL pACL
)
398 PACCESS_ALLOWED_ACE pACE
= (PACCESS_ALLOWED_ACE
) (pACL
+ 1);
400 pACL
->AclRevision
= ACL_REVISION
;
402 pACL
->AclSize
= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
406 pACE
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
407 pACE
->Header
.AceFlags
= CONTAINER_INHERIT_ACE
;
408 pACE
->Header
.AceSize
= sizeof(ACCESS_ALLOWED_ACE
) + sizeof(sidWorld
) - sizeof(DWORD
);
409 pACE
->Mask
= 0xf3ffffff; /* Everything except reserved bits */
410 memcpy(&pACE
->SidStart
, &sidWorld
, sizeof(sidWorld
));
413 /************************************************************
414 * ADVAPI_IsLocalComputer
416 * Checks whether the server name indicates local machine.
418 BOOL
ADVAPI_IsLocalComputer(LPCWSTR ServerName
)
420 DWORD dwSize
= MAX_COMPUTERNAME_LENGTH
+ 1;
424 if (!ServerName
|| !ServerName
[0])
427 buf
= HeapAlloc(GetProcessHeap(), 0, dwSize
* sizeof(WCHAR
));
428 Result
= GetComputerNameW(buf
, &dwSize
);
429 if (Result
&& (ServerName
[0] == '\\') && (ServerName
[1] == '\\'))
431 Result
= Result
&& !lstrcmpW(ServerName
, buf
);
432 HeapFree(GetProcessHeap(), 0, buf
);
437 /************************************************************
438 * ADVAPI_GetComputerSid
440 * Reads the computer SID from the registry.
442 BOOL
ADVAPI_GetComputerSid(PSID sid
)
447 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 };
448 static const WCHAR V
[] = { 'V',0 };
450 if ((ret
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, Account
, 0,
451 KEY_READ
, &key
)) == ERROR_SUCCESS
)
454 ret
= RegQueryValueExW(key
, V
, NULL
, NULL
, NULL
, &size
);
455 if (ret
== ERROR_MORE_DATA
|| ret
== ERROR_SUCCESS
)
457 BYTE
* data
= HeapAlloc(GetProcessHeap(), 0, size
);
460 if ((ret
= RegQueryValueExW(key
, V
, NULL
, NULL
,
461 data
, &size
)) == ERROR_SUCCESS
)
463 /* the SID is in the last 24 bytes of the binary data */
464 CopyMemory(sid
, &data
[size
-24], 24);
467 HeapFree(GetProcessHeap(), 0, data
);
473 if(retval
== TRUE
) return retval
;
475 /* create a new random SID */
476 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Account
,
477 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
) == ERROR_SUCCESS
)
480 SID_IDENTIFIER_AUTHORITY identifierAuthority
= {SECURITY_NT_AUTHORITY
};
483 if (RtlGenRandom(id
, sizeof(id
)))
485 if (AllocateAndInitializeSid(&identifierAuthority
, 4, SECURITY_NT_NON_UNIQUE
, id
[0], id
[1], id
[2], 0, 0, 0, 0, &new_sid
))
487 if (RegSetValueExW(key
, V
, 0, REG_BINARY
, new_sid
, GetLengthSid(new_sid
)) == ERROR_SUCCESS
)
488 retval
= CopySid(GetLengthSid(new_sid
), sid
, new_sid
);
499 /* ##############################
500 ###### TOKEN FUNCTIONS ######
501 ##############################
504 /******************************************************************************
505 * OpenProcessToken [ADVAPI32.@]
506 * Opens the access token associated with a process handle.
509 * ProcessHandle [I] Handle to process
510 * DesiredAccess [I] Desired access to process
511 * TokenHandle [O] Pointer to handle of open access token
514 * Success: TRUE. TokenHandle contains the access token.
518 * See NtOpenProcessToken.
521 OpenProcessToken( HANDLE ProcessHandle
, DWORD DesiredAccess
,
522 HANDLE
*TokenHandle
)
524 return set_ntstatus(NtOpenProcessToken( ProcessHandle
, DesiredAccess
, TokenHandle
));
527 /******************************************************************************
528 * OpenThreadToken [ADVAPI32.@]
530 * Opens the access token associated with a thread handle.
533 * ThreadHandle [I] Handle to process
534 * DesiredAccess [I] Desired access to the thread
536 * TokenHandle [O] Destination for the token handle
539 * Success: TRUE. TokenHandle contains the access token.
543 * See NtOpenThreadToken.
546 OpenThreadToken( HANDLE ThreadHandle
, DWORD DesiredAccess
,
547 BOOL OpenAsSelf
, HANDLE
*TokenHandle
)
549 return set_ntstatus( NtOpenThreadToken(ThreadHandle
, DesiredAccess
, OpenAsSelf
, TokenHandle
));
553 AdjustTokenGroups( HANDLE TokenHandle
, BOOL ResetToDefault
, PTOKEN_GROUPS NewState
,
554 DWORD BufferLength
, PTOKEN_GROUPS PreviousState
, PDWORD ReturnLength
)
556 return set_ntstatus( NtAdjustGroupsToken(TokenHandle
, ResetToDefault
, NewState
, BufferLength
,
557 PreviousState
, ReturnLength
));
560 /******************************************************************************
561 * AdjustTokenPrivileges [ADVAPI32.@]
563 * Adjust the privileges of an open token handle.
566 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
567 * DisableAllPrivileges [I] TRUE=Remove all privileges, FALSE=Use NewState
568 * NewState [I] Desired new privileges of the token
569 * BufferLength [I] Length of NewState
570 * PreviousState [O] Destination for the previous state
571 * ReturnLength [I/O] Size of PreviousState
575 * Success: TRUE. Privileges are set to NewState and PreviousState is updated.
579 * See NtAdjustPrivilegesToken.
582 AdjustTokenPrivileges( HANDLE TokenHandle
, BOOL DisableAllPrivileges
,
583 PTOKEN_PRIVILEGES NewState
, DWORD BufferLength
,
584 PTOKEN_PRIVILEGES PreviousState
, PDWORD ReturnLength
)
590 status
= NtAdjustPrivilegesToken(TokenHandle
, DisableAllPrivileges
,
591 NewState
, BufferLength
, PreviousState
,
593 SetLastError( RtlNtStatusToDosError( status
));
594 if ((status
== STATUS_SUCCESS
) || (status
== STATUS_NOT_ALL_ASSIGNED
))
600 /******************************************************************************
601 * CheckTokenMembership [ADVAPI32.@]
603 * Determine if an access token is a member of a SID.
606 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
607 * SidToCheck [I] SID that possibly contains the token
608 * IsMember [O] Destination for result.
611 * Success: TRUE. IsMember is TRUE if TokenHandle is a member, FALSE otherwise.
615 CheckTokenMembership( HANDLE TokenHandle
, PSID SidToCheck
,
618 FIXME("(%p %p %p) stub!\n", TokenHandle
, SidToCheck
, IsMember
);
624 /******************************************************************************
625 * GetTokenInformation [ADVAPI32.@]
627 * Get a type of information about an access token.
630 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
631 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
632 * tokeninfo [O] Destination for token information
633 * tokeninfolength [I] Length of tokeninfo
634 * retlen [O] Destination for returned token information length
637 * Success: TRUE. tokeninfo contains retlen bytes of token information
641 * See NtQueryInformationToken.
644 GetTokenInformation( HANDLE token
, TOKEN_INFORMATION_CLASS tokeninfoclass
,
645 LPVOID tokeninfo
, DWORD tokeninfolength
, LPDWORD retlen
)
647 TRACE("(%p, %s, %p, %d, %p):\n",
649 (tokeninfoclass
== TokenUser
) ? "TokenUser" :
650 (tokeninfoclass
== TokenGroups
) ? "TokenGroups" :
651 (tokeninfoclass
== TokenPrivileges
) ? "TokenPrivileges" :
652 (tokeninfoclass
== TokenOwner
) ? "TokenOwner" :
653 (tokeninfoclass
== TokenPrimaryGroup
) ? "TokenPrimaryGroup" :
654 (tokeninfoclass
== TokenDefaultDacl
) ? "TokenDefaultDacl" :
655 (tokeninfoclass
== TokenSource
) ? "TokenSource" :
656 (tokeninfoclass
== TokenType
) ? "TokenType" :
657 (tokeninfoclass
== TokenImpersonationLevel
) ? "TokenImpersonationLevel" :
658 (tokeninfoclass
== TokenStatistics
) ? "TokenStatistics" :
659 (tokeninfoclass
== TokenRestrictedSids
) ? "TokenRestrictedSids" :
660 (tokeninfoclass
== TokenSessionId
) ? "TokenSessionId" :
661 (tokeninfoclass
== TokenGroupsAndPrivileges
) ? "TokenGroupsAndPrivileges" :
662 (tokeninfoclass
== TokenSessionReference
) ? "TokenSessionReference" :
663 (tokeninfoclass
== TokenSandBoxInert
) ? "TokenSandBoxInert" :
665 tokeninfo
, tokeninfolength
, retlen
);
666 return set_ntstatus( NtQueryInformationToken( token
, tokeninfoclass
, tokeninfo
,
667 tokeninfolength
, retlen
));
670 /******************************************************************************
671 * SetTokenInformation [ADVAPI32.@]
673 * Set information for an access token.
676 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
677 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
678 * tokeninfo [I] Token information to set
679 * tokeninfolength [I] Length of tokeninfo
682 * Success: TRUE. The information for the token is set to tokeninfo.
686 SetTokenInformation( HANDLE token
, TOKEN_INFORMATION_CLASS tokeninfoclass
,
687 LPVOID tokeninfo
, DWORD tokeninfolength
)
689 TRACE("(%p, %s, %p, %d): stub\n",
691 (tokeninfoclass
== TokenUser
) ? "TokenUser" :
692 (tokeninfoclass
== TokenGroups
) ? "TokenGroups" :
693 (tokeninfoclass
== TokenPrivileges
) ? "TokenPrivileges" :
694 (tokeninfoclass
== TokenOwner
) ? "TokenOwner" :
695 (tokeninfoclass
== TokenPrimaryGroup
) ? "TokenPrimaryGroup" :
696 (tokeninfoclass
== TokenDefaultDacl
) ? "TokenDefaultDacl" :
697 (tokeninfoclass
== TokenSource
) ? "TokenSource" :
698 (tokeninfoclass
== TokenType
) ? "TokenType" :
699 (tokeninfoclass
== TokenImpersonationLevel
) ? "TokenImpersonationLevel" :
700 (tokeninfoclass
== TokenStatistics
) ? "TokenStatistics" :
701 (tokeninfoclass
== TokenRestrictedSids
) ? "TokenRestrictedSids" :
702 (tokeninfoclass
== TokenSessionId
) ? "TokenSessionId" :
703 (tokeninfoclass
== TokenGroupsAndPrivileges
) ? "TokenGroupsAndPrivileges" :
704 (tokeninfoclass
== TokenSessionReference
) ? "TokenSessionReference" :
705 (tokeninfoclass
== TokenSandBoxInert
) ? "TokenSandBoxInert" :
707 tokeninfo
, tokeninfolength
);
709 return set_ntstatus( NtSetInformationToken( token
, tokeninfoclass
, tokeninfo
, tokeninfolength
));
712 /*************************************************************************
713 * SetThreadToken [ADVAPI32.@]
715 * Assigns an 'impersonation token' to a thread so it can assume the
716 * security privileges of another thread or process. Can also remove
717 * a previously assigned token.
720 * thread [O] Handle to thread to set the token for
721 * token [I] Token to set
724 * Success: TRUE. The threads access token is set to token
728 * Only supported on NT or higher. On Win9X this function does nothing.
729 * See SetTokenInformation.
731 BOOL WINAPI
SetThreadToken(PHANDLE thread
, HANDLE token
)
733 return set_ntstatus( NtSetInformationThread( thread
? *thread
: GetCurrentThread(),
734 ThreadImpersonationToken
, &token
, sizeof token
));
737 /*************************************************************************
738 * CreateRestrictedToken [ADVAPI32.@]
740 * Create a new more restricted token from an existing token.
743 * baseToken [I] Token to base the new restricted token on
745 * nDisableSids [I] Length of disableSids array
746 * disableSids [I] Array of SIDs to disable in the new token
747 * nDeletePrivs [I] Length of deletePrivs array
748 * deletePrivs [I] Array of privileges to delete in the new token
749 * nRestrictSids [I] Length of restrictSids array
750 * restrictSids [I] Array of SIDs to restrict in the new token
751 * newToken [O] Address where the new token is stored
757 BOOL WINAPI
CreateRestrictedToken(
761 PSID_AND_ATTRIBUTES disableSids
,
763 PLUID_AND_ATTRIBUTES deletePrivs
,
765 PSID_AND_ATTRIBUTES restrictSids
,
768 FIXME("(%p, 0x%x, %u, %p, %u, %p, %u, %p, %p): stub\n",
769 baseToken
, flags
, nDisableSids
, disableSids
,
770 nDeletePrivs
, deletePrivs
,
771 nRestrictSids
, restrictSids
,
773 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
777 /* ##############################
778 ###### SID FUNCTIONS ######
779 ##############################
782 /******************************************************************************
783 * AllocateAndInitializeSid [ADVAPI32.@]
786 * pIdentifierAuthority []
787 * nSubAuthorityCount []
799 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
800 BYTE nSubAuthorityCount
,
801 DWORD nSubAuthority0
, DWORD nSubAuthority1
,
802 DWORD nSubAuthority2
, DWORD nSubAuthority3
,
803 DWORD nSubAuthority4
, DWORD nSubAuthority5
,
804 DWORD nSubAuthority6
, DWORD nSubAuthority7
,
807 return set_ntstatus( RtlAllocateAndInitializeSid(
808 pIdentifierAuthority
, nSubAuthorityCount
,
809 nSubAuthority0
, nSubAuthority1
, nSubAuthority2
, nSubAuthority3
,
810 nSubAuthority4
, nSubAuthority5
, nSubAuthority6
, nSubAuthority7
,
814 /******************************************************************************
815 * FreeSid [ADVAPI32.@]
824 return NULL
; /* is documented like this */
827 /******************************************************************************
828 * CopySid [ADVAPI32.@]
831 * nDestinationSidLength []
836 CopySid( DWORD nDestinationSidLength
, PSID pDestinationSid
, PSID pSourceSid
)
838 return RtlCopySid(nDestinationSidLength
, pDestinationSid
, pSourceSid
);
841 /******************************************************************************
842 * CreateWellKnownSid [ADVAPI32.@]
845 CreateWellKnownSid( WELL_KNOWN_SID_TYPE WellKnownSidType
,
851 TRACE("(%d, %s, %p, %p)\n", WellKnownSidType
, debugstr_sid(DomainSid
), pSid
, cbSid
);
853 if (cbSid
== NULL
|| pSid
== NULL
|| (DomainSid
&& !IsValidSid(DomainSid
))) {
854 SetLastError(ERROR_INVALID_PARAMETER
);
858 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++) {
859 if (WellKnownSids
[i
].Type
== WellKnownSidType
) {
860 DWORD length
= GetSidLengthRequired(WellKnownSids
[i
].Sid
.SubAuthorityCount
);
862 if (*cbSid
< length
) {
863 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
867 CopyMemory(pSid
, &WellKnownSids
[i
].Sid
.Revision
, length
);
873 if (DomainSid
== NULL
|| *GetSidSubAuthorityCount(DomainSid
) == SID_MAX_SUB_AUTHORITIES
)
875 SetLastError(ERROR_INVALID_PARAMETER
);
879 for (i
= 0; i
< sizeof(WellKnownRids
)/sizeof(WellKnownRids
[0]); i
++)
880 if (WellKnownRids
[i
].Type
== WellKnownSidType
) {
881 UCHAR domain_subauth
= *GetSidSubAuthorityCount(DomainSid
);
882 DWORD domain_sid_length
= GetSidLengthRequired(domain_subauth
);
883 DWORD output_sid_length
= GetSidLengthRequired(domain_subauth
+ 1);
885 if (*cbSid
< output_sid_length
) {
886 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
890 CopyMemory(pSid
, DomainSid
, domain_sid_length
);
891 (*GetSidSubAuthorityCount(pSid
))++;
892 (*GetSidSubAuthority(pSid
, domain_subauth
)) = WellKnownRids
[i
].Rid
;
893 *cbSid
= output_sid_length
;
897 SetLastError(ERROR_INVALID_PARAMETER
);
901 /******************************************************************************
902 * IsWellKnownSid [ADVAPI32.@]
905 IsWellKnownSid( PSID pSid
, WELL_KNOWN_SID_TYPE WellKnownSidType
)
908 TRACE("(%s, %d)\n", debugstr_sid(pSid
), WellKnownSidType
);
910 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
911 if (WellKnownSids
[i
].Type
== WellKnownSidType
)
912 if (EqualSid(pSid
, (PSID
)&(WellKnownSids
[i
].Sid
.Revision
)))
919 IsTokenRestricted( HANDLE TokenHandle
)
921 TOKEN_GROUPS
*groups
;
926 TRACE("(%p)\n", TokenHandle
);
928 status
= NtQueryInformationToken(TokenHandle
, TokenRestrictedSids
, NULL
, 0, &size
);
929 if (status
!= STATUS_BUFFER_TOO_SMALL
)
932 groups
= HeapAlloc(GetProcessHeap(), 0, size
);
935 SetLastError(ERROR_OUTOFMEMORY
);
939 status
= NtQueryInformationToken(TokenHandle
, TokenRestrictedSids
, groups
, size
, &size
);
940 if (status
!= STATUS_SUCCESS
)
942 HeapFree(GetProcessHeap(), 0, groups
);
943 return set_ntstatus(status
);
946 if (groups
->GroupCount
)
951 HeapFree(GetProcessHeap(), 0, groups
);
956 /******************************************************************************
957 * IsValidSid [ADVAPI32.@]
963 IsValidSid( PSID pSid
)
965 return RtlValidSid( pSid
);
968 /******************************************************************************
969 * EqualSid [ADVAPI32.@]
976 EqualSid( PSID pSid1
, PSID pSid2
)
978 return RtlEqualSid( pSid1
, pSid2
);
981 /******************************************************************************
982 * EqualPrefixSid [ADVAPI32.@]
984 BOOL WINAPI
EqualPrefixSid (PSID pSid1
, PSID pSid2
)
986 return RtlEqualPrefixSid(pSid1
, pSid2
);
989 /******************************************************************************
990 * GetSidLengthRequired [ADVAPI32.@]
993 * nSubAuthorityCount []
996 GetSidLengthRequired( BYTE nSubAuthorityCount
)
998 return RtlLengthRequiredSid(nSubAuthorityCount
);
1001 /******************************************************************************
1002 * InitializeSid [ADVAPI32.@]
1005 * pIdentifierAuthority []
1010 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
1011 BYTE nSubAuthorityCount
)
1013 return RtlInitializeSid(pSid
, pIdentifierAuthority
, nSubAuthorityCount
);
1017 GetEffectiveRightsFromAclA( PACL pacl
, PTRUSTEEA pTrustee
, PACCESS_MASK pAccessRights
)
1019 FIXME("%p %p %p - stub\n", pacl
, pTrustee
, pAccessRights
);
1025 GetEffectiveRightsFromAclW( PACL pacl
, PTRUSTEEW pTrustee
, PACCESS_MASK pAccessRights
)
1027 FIXME("%p %p %p - stub\n", pacl
, pTrustee
, pAccessRights
);
1032 /******************************************************************************
1033 * GetSidIdentifierAuthority [ADVAPI32.@]
1038 PSID_IDENTIFIER_AUTHORITY WINAPI
1039 GetSidIdentifierAuthority( PSID pSid
)
1041 return RtlIdentifierAuthoritySid(pSid
);
1044 /******************************************************************************
1045 * GetSidSubAuthority [ADVAPI32.@]
1052 GetSidSubAuthority( PSID pSid
, DWORD nSubAuthority
)
1054 return RtlSubAuthoritySid(pSid
, nSubAuthority
);
1057 /******************************************************************************
1058 * GetSidSubAuthorityCount [ADVAPI32.@]
1064 GetSidSubAuthorityCount (PSID pSid
)
1066 return RtlSubAuthorityCountSid(pSid
);
1069 /******************************************************************************
1070 * GetLengthSid [ADVAPI32.@]
1076 GetLengthSid (PSID pSid
)
1078 return RtlLengthSid(pSid
);
1081 /* ##############################################
1082 ###### SECURITY DESCRIPTOR FUNCTIONS ######
1083 ##############################################
1086 /******************************************************************************
1087 * BuildSecurityDescriptorA [ADVAPI32.@]
1094 * cCountOfAccessEntries [I]
1095 * pListOfAccessEntries [I]
1096 * cCountOfAuditEntries [I]
1097 * pListofAuditEntries [I]
1099 * lpdwBufferLength [I/O]
1103 * Success: ERROR_SUCCESS
1104 * Failure: nonzero error code from Winerror.h
1106 DWORD WINAPI
BuildSecurityDescriptorA(
1107 IN PTRUSTEEA pOwner
,
1108 IN PTRUSTEEA pGroup
,
1109 IN ULONG cCountOfAccessEntries
,
1110 IN PEXPLICIT_ACCESSA pListOfAccessEntries
,
1111 IN ULONG cCountOfAuditEntries
,
1112 IN PEXPLICIT_ACCESSA pListofAuditEntries
,
1113 IN PSECURITY_DESCRIPTOR pOldSD
,
1114 IN OUT PULONG lpdwBufferLength
,
1115 OUT PSECURITY_DESCRIPTOR
* pNewSD
)
1117 FIXME("(%p,%p,%d,%p,%d,%p,%p,%p,%p) stub!\n",pOwner
,pGroup
,
1118 cCountOfAccessEntries
,pListOfAccessEntries
,cCountOfAuditEntries
,
1119 pListofAuditEntries
,pOldSD
,lpdwBufferLength
,pNewSD
);
1121 return ERROR_CALL_NOT_IMPLEMENTED
;
1124 /******************************************************************************
1125 * BuildSecurityDescriptorW [ADVAPI32.@]
1127 * See BuildSecurityDescriptorA.
1129 DWORD WINAPI
BuildSecurityDescriptorW(
1130 IN PTRUSTEEW pOwner
,
1131 IN PTRUSTEEW pGroup
,
1132 IN ULONG cCountOfAccessEntries
,
1133 IN PEXPLICIT_ACCESSW pListOfAccessEntries
,
1134 IN ULONG cCountOfAuditEntries
,
1135 IN PEXPLICIT_ACCESSW pListofAuditEntries
,
1136 IN PSECURITY_DESCRIPTOR pOldSD
,
1137 IN OUT PULONG lpdwBufferLength
,
1138 OUT PSECURITY_DESCRIPTOR
* pNewSD
)
1140 FIXME("(%p,%p,%d,%p,%d,%p,%p,%p,%p) stub!\n",pOwner
,pGroup
,
1141 cCountOfAccessEntries
,pListOfAccessEntries
,cCountOfAuditEntries
,
1142 pListofAuditEntries
,pOldSD
,lpdwBufferLength
,pNewSD
);
1144 return ERROR_CALL_NOT_IMPLEMENTED
;
1147 /******************************************************************************
1148 * InitializeSecurityDescriptor [ADVAPI32.@]
1155 InitializeSecurityDescriptor( PSECURITY_DESCRIPTOR pDescr
, DWORD revision
)
1157 return set_ntstatus( RtlCreateSecurityDescriptor(pDescr
, revision
));
1161 /******************************************************************************
1162 * MakeAbsoluteSD [ADVAPI32.@]
1164 BOOL WINAPI
MakeAbsoluteSD (
1165 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor
,
1166 OUT PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor
,
1167 OUT LPDWORD lpdwAbsoluteSecurityDescriptorSize
,
1169 OUT LPDWORD lpdwDaclSize
,
1171 OUT LPDWORD lpdwSaclSize
,
1173 OUT LPDWORD lpdwOwnerSize
,
1174 OUT PSID pPrimaryGroup
,
1175 OUT LPDWORD lpdwPrimaryGroupSize
)
1177 return set_ntstatus( RtlSelfRelativeToAbsoluteSD(pSelfRelativeSecurityDescriptor
,
1178 pAbsoluteSecurityDescriptor
,
1179 lpdwAbsoluteSecurityDescriptorSize
,
1180 pDacl
, lpdwDaclSize
, pSacl
, lpdwSaclSize
,
1181 pOwner
, lpdwOwnerSize
,
1182 pPrimaryGroup
, lpdwPrimaryGroupSize
));
1185 /******************************************************************************
1186 * GetKernelObjectSecurity [ADVAPI32.@]
1188 BOOL WINAPI
GetKernelObjectSecurity(
1190 SECURITY_INFORMATION RequestedInformation
,
1191 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1193 LPDWORD lpnLengthNeeded
)
1195 TRACE("(%p,0x%08x,%p,0x%08x,%p)\n", Handle
, RequestedInformation
,
1196 pSecurityDescriptor
, nLength
, lpnLengthNeeded
);
1198 return set_ntstatus( NtQuerySecurityObject(Handle
, RequestedInformation
, pSecurityDescriptor
,
1199 nLength
, lpnLengthNeeded
));
1202 /******************************************************************************
1203 * GetPrivateObjectSecurity [ADVAPI32.@]
1205 BOOL WINAPI
GetPrivateObjectSecurity(
1206 PSECURITY_DESCRIPTOR ObjectDescriptor
,
1207 SECURITY_INFORMATION SecurityInformation
,
1208 PSECURITY_DESCRIPTOR ResultantDescriptor
,
1209 DWORD DescriptorLength
,
1210 PDWORD ReturnLength
)
1212 SECURITY_DESCRIPTOR desc
;
1213 BOOL defaulted
, present
;
1217 TRACE("(%p,0x%08x,%p,0x%08x,%p)\n", ObjectDescriptor
, SecurityInformation
,
1218 ResultantDescriptor
, DescriptorLength
, ReturnLength
);
1220 if (!InitializeSecurityDescriptor(&desc
, SECURITY_DESCRIPTOR_REVISION
))
1223 if (SecurityInformation
& OWNER_SECURITY_INFORMATION
)
1225 if (!GetSecurityDescriptorOwner(ObjectDescriptor
, &psid
, &defaulted
))
1227 SetSecurityDescriptorOwner(&desc
, psid
, defaulted
);
1230 if (SecurityInformation
& GROUP_SECURITY_INFORMATION
)
1232 if (!GetSecurityDescriptorGroup(ObjectDescriptor
, &psid
, &defaulted
))
1234 SetSecurityDescriptorGroup(&desc
, psid
, defaulted
);
1237 if (SecurityInformation
& DACL_SECURITY_INFORMATION
)
1239 if (!GetSecurityDescriptorDacl(ObjectDescriptor
, &present
, &pacl
, &defaulted
))
1241 SetSecurityDescriptorDacl(&desc
, present
, pacl
, defaulted
);
1244 if (SecurityInformation
& SACL_SECURITY_INFORMATION
)
1246 if (!GetSecurityDescriptorSacl(ObjectDescriptor
, &present
, &pacl
, &defaulted
))
1248 SetSecurityDescriptorSacl(&desc
, present
, pacl
, defaulted
);
1251 *ReturnLength
= DescriptorLength
;
1252 return MakeSelfRelativeSD(&desc
, ResultantDescriptor
, ReturnLength
);
1255 /******************************************************************************
1256 * GetSecurityDescriptorLength [ADVAPI32.@]
1258 DWORD WINAPI
GetSecurityDescriptorLength( PSECURITY_DESCRIPTOR pDescr
)
1260 return RtlLengthSecurityDescriptor(pDescr
);
1263 /******************************************************************************
1264 * GetSecurityDescriptorOwner [ADVAPI32.@]
1268 * lpbOwnerDefaulted []
1271 GetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pDescr
, PSID
*pOwner
,
1272 LPBOOL lpbOwnerDefaulted
)
1275 BOOL ret
= set_ntstatus( RtlGetOwnerSecurityDescriptor( pDescr
, pOwner
, &defaulted
));
1276 *lpbOwnerDefaulted
= defaulted
;
1280 /******************************************************************************
1281 * SetSecurityDescriptorOwner [ADVAPI32.@]
1285 BOOL WINAPI
SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1286 PSID pOwner
, BOOL bOwnerDefaulted
)
1288 return set_ntstatus( RtlSetOwnerSecurityDescriptor(pSecurityDescriptor
, pOwner
, bOwnerDefaulted
));
1290 /******************************************************************************
1291 * GetSecurityDescriptorGroup [ADVAPI32.@]
1293 BOOL WINAPI
GetSecurityDescriptorGroup(
1294 PSECURITY_DESCRIPTOR SecurityDescriptor
,
1296 LPBOOL GroupDefaulted
)
1299 BOOL ret
= set_ntstatus( RtlGetGroupSecurityDescriptor(SecurityDescriptor
, Group
, &defaulted
));
1300 *GroupDefaulted
= defaulted
;
1303 /******************************************************************************
1304 * SetSecurityDescriptorGroup [ADVAPI32.@]
1306 BOOL WINAPI
SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor
,
1307 PSID Group
, BOOL GroupDefaulted
)
1309 return set_ntstatus( RtlSetGroupSecurityDescriptor( SecurityDescriptor
, Group
, GroupDefaulted
));
1312 /******************************************************************************
1313 * IsValidSecurityDescriptor [ADVAPI32.@]
1319 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor
)
1321 return set_ntstatus( RtlValidSecurityDescriptor(SecurityDescriptor
));
1324 /******************************************************************************
1325 * GetSecurityDescriptorDacl [ADVAPI32.@]
1327 BOOL WINAPI
GetSecurityDescriptorDacl(
1328 IN PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1329 OUT LPBOOL lpbDaclPresent
,
1331 OUT LPBOOL lpbDaclDefaulted
)
1333 BOOLEAN present
, defaulted
;
1334 BOOL ret
= set_ntstatus( RtlGetDaclSecurityDescriptor(pSecurityDescriptor
, &present
, pDacl
, &defaulted
));
1335 *lpbDaclPresent
= present
;
1336 *lpbDaclDefaulted
= defaulted
;
1340 /******************************************************************************
1341 * SetSecurityDescriptorDacl [ADVAPI32.@]
1344 SetSecurityDescriptorDacl (
1345 PSECURITY_DESCRIPTOR lpsd
,
1348 BOOL dacldefaulted
)
1350 return set_ntstatus( RtlSetDaclSecurityDescriptor (lpsd
, daclpresent
, dacl
, dacldefaulted
) );
1352 /******************************************************************************
1353 * GetSecurityDescriptorSacl [ADVAPI32.@]
1355 BOOL WINAPI
GetSecurityDescriptorSacl(
1356 IN PSECURITY_DESCRIPTOR lpsd
,
1357 OUT LPBOOL lpbSaclPresent
,
1359 OUT LPBOOL lpbSaclDefaulted
)
1361 BOOLEAN present
, defaulted
;
1362 BOOL ret
= set_ntstatus( RtlGetSaclSecurityDescriptor(lpsd
, &present
, pSacl
, &defaulted
) );
1363 *lpbSaclPresent
= present
;
1364 *lpbSaclDefaulted
= defaulted
;
1368 /**************************************************************************
1369 * SetSecurityDescriptorSacl [ADVAPI32.@]
1371 BOOL WINAPI
SetSecurityDescriptorSacl (
1372 PSECURITY_DESCRIPTOR lpsd
,
1377 return set_ntstatus (RtlSetSaclSecurityDescriptor(lpsd
, saclpresent
, lpsacl
, sacldefaulted
));
1379 /******************************************************************************
1380 * MakeSelfRelativeSD [ADVAPI32.@]
1389 IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor
,
1390 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor
,
1391 IN OUT LPDWORD lpdwBufferLength
)
1393 return set_ntstatus( RtlMakeSelfRelativeSD( pAbsoluteSecurityDescriptor
,
1394 pSelfRelativeSecurityDescriptor
, lpdwBufferLength
));
1397 /******************************************************************************
1398 * GetSecurityDescriptorControl [ADVAPI32.@]
1401 BOOL WINAPI
GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1402 PSECURITY_DESCRIPTOR_CONTROL pControl
, LPDWORD lpdwRevision
)
1404 return set_ntstatus( RtlGetControlSecurityDescriptor(pSecurityDescriptor
,pControl
,lpdwRevision
));
1407 /******************************************************************************
1408 * SetSecurityDescriptorControl [ADVAPI32.@]
1410 BOOL WINAPI
SetSecurityDescriptorControl( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1411 SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest
,
1412 SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet
)
1414 return set_ntstatus( RtlSetControlSecurityDescriptor(
1415 pSecurityDescriptor
, ControlBitsOfInterest
, ControlBitsToSet
) );
1418 /* ##############################
1419 ###### ACL FUNCTIONS ######
1420 ##############################
1423 /*************************************************************************
1424 * InitializeAcl [ADVAPI32.@]
1426 BOOL WINAPI
InitializeAcl(PACL acl
, DWORD size
, DWORD rev
)
1428 return set_ntstatus( RtlCreateAcl(acl
, size
, rev
));
1431 BOOL WINAPI
ImpersonateNamedPipeClient( HANDLE hNamedPipe
)
1433 IO_STATUS_BLOCK io_block
;
1435 TRACE("(%p)\n", hNamedPipe
);
1437 return set_ntstatus( NtFsControlFile(hNamedPipe
, NULL
, NULL
, NULL
,
1438 &io_block
, FSCTL_PIPE_IMPERSONATE
, NULL
, 0, NULL
, 0) );
1441 /******************************************************************************
1442 * AddAccessAllowedAce [ADVAPI32.@]
1444 BOOL WINAPI
AddAccessAllowedAce(
1446 IN DWORD dwAceRevision
,
1447 IN DWORD AccessMask
,
1450 return set_ntstatus(RtlAddAccessAllowedAce(pAcl
, dwAceRevision
, AccessMask
, pSid
));
1453 /******************************************************************************
1454 * AddAccessAllowedAceEx [ADVAPI32.@]
1456 BOOL WINAPI
AddAccessAllowedAceEx(
1458 IN DWORD dwAceRevision
,
1460 IN DWORD AccessMask
,
1463 return set_ntstatus(RtlAddAccessAllowedAceEx(pAcl
, dwAceRevision
, AceFlags
, AccessMask
, pSid
));
1466 /******************************************************************************
1467 * AddAccessDeniedAce [ADVAPI32.@]
1469 BOOL WINAPI
AddAccessDeniedAce(
1471 IN DWORD dwAceRevision
,
1472 IN DWORD AccessMask
,
1475 return set_ntstatus(RtlAddAccessDeniedAce(pAcl
, dwAceRevision
, AccessMask
, pSid
));
1478 /******************************************************************************
1479 * AddAccessDeniedAceEx [ADVAPI32.@]
1481 BOOL WINAPI
AddAccessDeniedAceEx(
1483 IN DWORD dwAceRevision
,
1485 IN DWORD AccessMask
,
1488 return set_ntstatus(RtlAddAccessDeniedAceEx(pAcl
, dwAceRevision
, AceFlags
, AccessMask
, pSid
));
1491 /******************************************************************************
1492 * AddAce [ADVAPI32.@]
1496 IN DWORD dwAceRevision
,
1497 IN DWORD dwStartingAceIndex
,
1499 DWORD nAceListLength
)
1501 return set_ntstatus(RtlAddAce(pAcl
, dwAceRevision
, dwStartingAceIndex
, pAceList
, nAceListLength
));
1504 /******************************************************************************
1505 * DeleteAce [ADVAPI32.@]
1507 BOOL WINAPI
DeleteAce(PACL pAcl
, DWORD dwAceIndex
)
1509 return set_ntstatus(RtlDeleteAce(pAcl
, dwAceIndex
));
1512 /******************************************************************************
1513 * FindFirstFreeAce [ADVAPI32.@]
1515 BOOL WINAPI
FindFirstFreeAce(IN PACL pAcl
, LPVOID
* pAce
)
1517 return RtlFirstFreeAce(pAcl
, (PACE_HEADER
*)pAce
);
1520 /******************************************************************************
1521 * GetAce [ADVAPI32.@]
1523 BOOL WINAPI
GetAce(PACL pAcl
,DWORD dwAceIndex
,LPVOID
*pAce
)
1525 return set_ntstatus(RtlGetAce(pAcl
, dwAceIndex
, pAce
));
1528 /******************************************************************************
1529 * GetAclInformation [ADVAPI32.@]
1531 BOOL WINAPI
GetAclInformation(
1533 LPVOID pAclInformation
,
1534 DWORD nAclInformationLength
,
1535 ACL_INFORMATION_CLASS dwAclInformationClass
)
1537 return set_ntstatus(RtlQueryInformationAcl(pAcl
, pAclInformation
,
1538 nAclInformationLength
, dwAclInformationClass
));
1541 /******************************************************************************
1542 * IsValidAcl [ADVAPI32.@]
1544 BOOL WINAPI
IsValidAcl(IN PACL pAcl
)
1546 return RtlValidAcl(pAcl
);
1549 /* ##############################
1550 ###### MISC FUNCTIONS ######
1551 ##############################
1554 /******************************************************************************
1555 * AllocateLocallyUniqueId [ADVAPI32.@]
1560 BOOL WINAPI
AllocateLocallyUniqueId( PLUID lpLuid
)
1562 return set_ntstatus(NtAllocateLocallyUniqueId(lpLuid
));
1565 static const WCHAR SE_CREATE_TOKEN_NAME_W
[] =
1566 { 'S','e','C','r','e','a','t','e','T','o','k','e','n','P','r','i','v','i','l','e','g','e',0 };
1567 static const WCHAR SE_ASSIGNPRIMARYTOKEN_NAME_W
[] =
1568 { '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 };
1569 static const WCHAR SE_LOCK_MEMORY_NAME_W
[] =
1570 { 'S','e','L','o','c','k','M','e','m','o','r','y','P','r','i','v','i','l','e','g','e',0 };
1571 static const WCHAR SE_INCREASE_QUOTA_NAME_W
[] =
1572 { '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 };
1573 static const WCHAR SE_MACHINE_ACCOUNT_NAME_W
[] =
1574 { '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 };
1575 static const WCHAR SE_TCB_NAME_W
[] =
1576 { 'S','e','T','c','b','P','r','i','v','i','l','e','g','e',0 };
1577 static const WCHAR SE_SECURITY_NAME_W
[] =
1578 { 'S','e','S','e','c','u','r','i','t','y','P','r','i','v','i','l','e','g','e',0 };
1579 static const WCHAR SE_TAKE_OWNERSHIP_NAME_W
[] =
1580 { '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 };
1581 static const WCHAR SE_LOAD_DRIVER_NAME_W
[] =
1582 { 'S','e','L','o','a','d','D','r','i','v','e','r','P','r','i','v','i','l','e','g','e',0 };
1583 static const WCHAR SE_SYSTEM_PROFILE_NAME_W
[] =
1584 { '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 };
1585 static const WCHAR SE_SYSTEMTIME_NAME_W
[] =
1586 { 'S','e','S','y','s','t','e','m','t','i','m','e','P','r','i','v','i','l','e','g','e',0 };
1587 static const WCHAR SE_PROF_SINGLE_PROCESS_NAME_W
[] =
1588 { '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 };
1589 static const WCHAR SE_INC_BASE_PRIORITY_NAME_W
[] =
1590 { '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 };
1591 static const WCHAR SE_CREATE_PAGEFILE_NAME_W
[] =
1592 { '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 };
1593 static const WCHAR SE_CREATE_PERMANENT_NAME_W
[] =
1594 { '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 };
1595 static const WCHAR SE_BACKUP_NAME_W
[] =
1596 { 'S','e','B','a','c','k','u','p','P','r','i','v','i','l','e','g','e',0 };
1597 static const WCHAR SE_RESTORE_NAME_W
[] =
1598 { 'S','e','R','e','s','t','o','r','e','P','r','i','v','i','l','e','g','e',0 };
1599 static const WCHAR SE_SHUTDOWN_NAME_W
[] =
1600 { 'S','e','S','h','u','t','d','o','w','n','P','r','i','v','i','l','e','g','e',0 };
1601 static const WCHAR SE_DEBUG_NAME_W
[] =
1602 { 'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0 };
1603 static const WCHAR SE_AUDIT_NAME_W
[] =
1604 { 'S','e','A','u','d','i','t','P','r','i','v','i','l','e','g','e',0 };
1605 static const WCHAR SE_SYSTEM_ENVIRONMENT_NAME_W
[] =
1606 { '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 };
1607 static const WCHAR SE_CHANGE_NOTIFY_NAME_W
[] =
1608 { 'S','e','C','h','a','n','g','e','N','o','t','i','f','y','P','r','i','v','i','l','e','g','e',0 };
1609 static const WCHAR SE_REMOTE_SHUTDOWN_NAME_W
[] =
1610 { '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 };
1611 static const WCHAR SE_UNDOCK_NAME_W
[] =
1612 { 'S','e','U','n','d','o','c','k','P','r','i','v','i','l','e','g','e',0 };
1613 static const WCHAR SE_SYNC_AGENT_NAME_W
[] =
1614 { 'S','e','S','y','n','c','A','g','e','n','t','P','r','i','v','i','l','e','g','e',0 };
1615 static const WCHAR SE_ENABLE_DELEGATION_NAME_W
[] =
1616 { '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 };
1617 static const WCHAR SE_MANAGE_VOLUME_NAME_W
[] =
1618 { 'S','e','M','a','n','a','g','e','V','o','l','u','m','e','P','r','i','v','i','l','e','g','e',0 };
1619 static const WCHAR SE_IMPERSONATE_NAME_W
[] =
1620 { 'S','e','I','m','p','e','r','s','o','n','a','t','e','P','r','i','v','i','l','e','g','e',0 };
1621 static const WCHAR SE_CREATE_GLOBAL_NAME_W
[] =
1622 { 'S','e','C','r','e','a','t','e','G','l','o','b','a','l','P','r','i','v','i','l','e','g','e',0 };
1624 static const WCHAR
* const WellKnownPrivNames
[SE_MAX_WELL_KNOWN_PRIVILEGE
+ 1] =
1628 SE_CREATE_TOKEN_NAME_W
,
1629 SE_ASSIGNPRIMARYTOKEN_NAME_W
,
1630 SE_LOCK_MEMORY_NAME_W
,
1631 SE_INCREASE_QUOTA_NAME_W
,
1632 SE_MACHINE_ACCOUNT_NAME_W
,
1635 SE_TAKE_OWNERSHIP_NAME_W
,
1636 SE_LOAD_DRIVER_NAME_W
,
1637 SE_SYSTEM_PROFILE_NAME_W
,
1638 SE_SYSTEMTIME_NAME_W
,
1639 SE_PROF_SINGLE_PROCESS_NAME_W
,
1640 SE_INC_BASE_PRIORITY_NAME_W
,
1641 SE_CREATE_PAGEFILE_NAME_W
,
1642 SE_CREATE_PERMANENT_NAME_W
,
1648 SE_SYSTEM_ENVIRONMENT_NAME_W
,
1649 SE_CHANGE_NOTIFY_NAME_W
,
1650 SE_REMOTE_SHUTDOWN_NAME_W
,
1652 SE_SYNC_AGENT_NAME_W
,
1653 SE_ENABLE_DELEGATION_NAME_W
,
1654 SE_MANAGE_VOLUME_NAME_W
,
1655 SE_IMPERSONATE_NAME_W
,
1656 SE_CREATE_GLOBAL_NAME_W
,
1659 /******************************************************************************
1660 * LookupPrivilegeValueW [ADVAPI32.@]
1662 * See LookupPrivilegeValueA.
1665 LookupPrivilegeValueW( LPCWSTR lpSystemName
, LPCWSTR lpName
, PLUID lpLuid
)
1669 TRACE("%s,%s,%p\n",debugstr_w(lpSystemName
), debugstr_w(lpName
), lpLuid
);
1671 if (!ADVAPI_IsLocalComputer(lpSystemName
))
1673 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
1678 SetLastError(ERROR_NO_SUCH_PRIVILEGE
);
1681 for( i
=SE_MIN_WELL_KNOWN_PRIVILEGE
; i
<SE_MAX_WELL_KNOWN_PRIVILEGE
; i
++ )
1683 if( !WellKnownPrivNames
[i
] )
1685 if( strcmpiW( WellKnownPrivNames
[i
], lpName
) )
1687 lpLuid
->LowPart
= i
;
1688 lpLuid
->HighPart
= 0;
1689 TRACE( "%s -> %08x-%08x\n",debugstr_w( lpSystemName
),
1690 lpLuid
->HighPart
, lpLuid
->LowPart
);
1693 SetLastError(ERROR_NO_SUCH_PRIVILEGE
);
1697 /******************************************************************************
1698 * LookupPrivilegeValueA [ADVAPI32.@]
1700 * Retrieves LUID used on a system to represent the privilege name.
1703 * lpSystemName [I] Name of the system
1704 * lpName [I] Name of the privilege
1705 * lpLuid [O] Destination for the resulting LUID
1708 * Success: TRUE. lpLuid contains the requested LUID.
1712 LookupPrivilegeValueA( LPCSTR lpSystemName
, LPCSTR lpName
, PLUID lpLuid
)
1714 UNICODE_STRING lpSystemNameW
;
1715 UNICODE_STRING lpNameW
;
1718 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW
, lpSystemName
);
1719 RtlCreateUnicodeStringFromAsciiz(&lpNameW
,lpName
);
1720 ret
= LookupPrivilegeValueW(lpSystemNameW
.Buffer
, lpNameW
.Buffer
, lpLuid
);
1721 RtlFreeUnicodeString(&lpNameW
);
1722 RtlFreeUnicodeString(&lpSystemNameW
);
1726 BOOL WINAPI
LookupPrivilegeDisplayNameA( LPCSTR lpSystemName
, LPCSTR lpName
, LPSTR lpDisplayName
,
1727 LPDWORD cchDisplayName
, LPDWORD lpLanguageId
)
1729 FIXME("%s %s %s %p %p - stub\n", debugstr_a(lpSystemName
), debugstr_a(lpName
),
1730 debugstr_a(lpDisplayName
), cchDisplayName
, lpLanguageId
);
1735 BOOL WINAPI
LookupPrivilegeDisplayNameW( LPCWSTR lpSystemName
, LPCWSTR lpName
, LPWSTR lpDisplayName
,
1736 LPDWORD cchDisplayName
, LPDWORD lpLanguageId
)
1738 FIXME("%s %s %s %p %p - stub\n", debugstr_w(lpSystemName
), debugstr_w(lpName
),
1739 debugstr_w(lpDisplayName
), cchDisplayName
, lpLanguageId
);
1744 /******************************************************************************
1745 * LookupPrivilegeNameA [ADVAPI32.@]
1747 * See LookupPrivilegeNameW.
1750 LookupPrivilegeNameA( LPCSTR lpSystemName
, PLUID lpLuid
, LPSTR lpName
,
1753 UNICODE_STRING lpSystemNameW
;
1757 TRACE("%s %p %p %p\n", debugstr_a(lpSystemName
), lpLuid
, lpName
, cchName
);
1759 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW
, lpSystemName
);
1760 ret
= LookupPrivilegeNameW(lpSystemNameW
.Buffer
, lpLuid
, NULL
, &wLen
);
1761 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1763 LPWSTR lpNameW
= HeapAlloc(GetProcessHeap(), 0, wLen
* sizeof(WCHAR
));
1765 ret
= LookupPrivilegeNameW(lpSystemNameW
.Buffer
, lpLuid
, lpNameW
,
1769 /* Windows crashes if cchName is NULL, so will I */
1770 unsigned int len
= WideCharToMultiByte(CP_ACP
, 0, lpNameW
, -1, lpName
,
1771 *cchName
, NULL
, NULL
);
1775 /* WideCharToMultiByte failed */
1778 else if (len
> *cchName
)
1781 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1786 /* WideCharToMultiByte succeeded, output length needs to be
1787 * length not including NULL terminator
1792 HeapFree(GetProcessHeap(), 0, lpNameW
);
1794 RtlFreeUnicodeString(&lpSystemNameW
);
1798 /******************************************************************************
1799 * LookupPrivilegeNameW [ADVAPI32.@]
1801 * Retrieves the privilege name referred to by the LUID lpLuid.
1804 * lpSystemName [I] Name of the system
1805 * lpLuid [I] Privilege value
1806 * lpName [O] Name of the privilege
1807 * cchName [I/O] Number of characters in lpName.
1810 * Success: TRUE. lpName contains the name of the privilege whose value is
1815 * Only well-known privilege names (those defined in winnt.h) can be retrieved
1816 * using this function.
1817 * If the length of lpName is too small, on return *cchName will contain the
1818 * number of WCHARs needed to contain the privilege, including the NULL
1819 * terminator, and GetLastError will return ERROR_INSUFFICIENT_BUFFER.
1820 * On success, *cchName will contain the number of characters stored in
1821 * lpName, NOT including the NULL terminator.
1824 LookupPrivilegeNameW( LPCWSTR lpSystemName
, PLUID lpLuid
, LPWSTR lpName
,
1829 TRACE("%s,%p,%p,%p\n",debugstr_w(lpSystemName
), lpLuid
, lpName
, cchName
);
1831 if (!ADVAPI_IsLocalComputer(lpSystemName
))
1833 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
1836 if (lpLuid
->HighPart
|| (lpLuid
->LowPart
< SE_MIN_WELL_KNOWN_PRIVILEGE
||
1837 lpLuid
->LowPart
> SE_MAX_WELL_KNOWN_PRIVILEGE
))
1839 SetLastError(ERROR_NO_SUCH_PRIVILEGE
);
1842 privNameLen
= strlenW(WellKnownPrivNames
[lpLuid
->LowPart
]);
1843 /* Windows crashes if cchName is NULL, so will I */
1844 if (*cchName
<= privNameLen
)
1846 *cchName
= privNameLen
+ 1;
1847 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1852 strcpyW(lpName
, WellKnownPrivNames
[lpLuid
->LowPart
]);
1853 *cchName
= privNameLen
;
1858 /******************************************************************************
1859 * GetFileSecurityA [ADVAPI32.@]
1861 * Obtains Specified information about the security of a file or directory.
1864 * lpFileName [I] Name of the file to get info for
1865 * RequestedInformation [I] SE_ flags from "winnt.h"
1866 * pSecurityDescriptor [O] Destination for security information
1867 * nLength [I] Length of pSecurityDescriptor
1868 * lpnLengthNeeded [O] Destination for length of returned security information
1871 * Success: TRUE. pSecurityDescriptor contains the requested information.
1872 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
1875 * The information returned is constrained by the callers access rights and
1879 GetFileSecurityA( LPCSTR lpFileName
,
1880 SECURITY_INFORMATION RequestedInformation
,
1881 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1882 DWORD nLength
, LPDWORD lpnLengthNeeded
)
1890 len
= MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, NULL
, 0 );
1891 name
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
1892 MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, name
, len
);
1895 r
= GetFileSecurityW( name
, RequestedInformation
, pSecurityDescriptor
,
1896 nLength
, lpnLengthNeeded
);
1897 HeapFree( GetProcessHeap(), 0, name
);
1902 /******************************************************************************
1903 * GetFileSecurityW [ADVAPI32.@]
1905 * See GetFileSecurityA.
1908 GetFileSecurityW( LPCWSTR lpFileName
,
1909 SECURITY_INFORMATION RequestedInformation
,
1910 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1911 DWORD nLength
, LPDWORD lpnLengthNeeded
)
1917 if (RequestedInformation
& (OWNER_SECURITY_INFORMATION
|GROUP_SECURITY_INFORMATION
|
1918 DACL_SECURITY_INFORMATION
))
1919 access
|= READ_CONTROL
;
1920 if (RequestedInformation
& SACL_SECURITY_INFORMATION
)
1921 access
|= ACCESS_SYSTEM_SECURITY
;
1923 hfile
= CreateFileW( lpFileName
, access
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
1924 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1925 if ( hfile
== INVALID_HANDLE_VALUE
)
1928 status
= NtQuerySecurityObject( hfile
, RequestedInformation
, pSecurityDescriptor
,
1929 nLength
, lpnLengthNeeded
);
1930 CloseHandle( hfile
);
1931 return set_ntstatus( status
);
1935 /******************************************************************************
1936 * LookupAccountSidA [ADVAPI32.@]
1943 IN OUT LPDWORD accountSize
,
1945 IN OUT LPDWORD domainSize
,
1946 OUT PSID_NAME_USE name_use
)
1950 LPWSTR systemW
= NULL
;
1951 LPWSTR accountW
= NULL
;
1952 LPWSTR domainW
= NULL
;
1953 DWORD accountSizeW
= *accountSize
;
1954 DWORD domainSizeW
= *domainSize
;
1956 TRACE("(%s,sid=%s,%p,%p(%u),%p,%p(%u),%p)\n",
1957 debugstr_a(system
),debugstr_sid(sid
),
1958 account
,accountSize
,accountSize
?*accountSize
:0,
1959 domain
,domainSize
,domainSize
?*domainSize
:0,
1963 len
= MultiByteToWideChar( CP_ACP
, 0, system
, -1, NULL
, 0 );
1964 systemW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1965 MultiByteToWideChar( CP_ACP
, 0, system
, -1, systemW
, len
);
1968 accountW
= HeapAlloc( GetProcessHeap(), 0, accountSizeW
* sizeof(WCHAR
) );
1970 domainW
= HeapAlloc( GetProcessHeap(), 0, domainSizeW
* sizeof(WCHAR
) );
1972 r
= LookupAccountSidW( systemW
, sid
, accountW
, &accountSizeW
, domainW
, &domainSizeW
, name_use
);
1975 if (accountW
&& *accountSize
) {
1976 len
= WideCharToMultiByte( CP_ACP
, 0, accountW
, -1, NULL
, 0, NULL
, NULL
);
1977 WideCharToMultiByte( CP_ACP
, 0, accountW
, -1, account
, len
, NULL
, NULL
);
1980 *accountSize
= accountSizeW
+ 1;
1982 if (domainW
&& *domainSize
) {
1983 len
= WideCharToMultiByte( CP_ACP
, 0, domainW
, -1, NULL
, 0, NULL
, NULL
);
1984 WideCharToMultiByte( CP_ACP
, 0, domainW
, -1, domain
, len
, NULL
, NULL
);
1987 *domainSize
= domainSizeW
+ 1;
1990 HeapFree( GetProcessHeap(), 0, systemW
);
1991 HeapFree( GetProcessHeap(), 0, accountW
);
1992 HeapFree( GetProcessHeap(), 0, domainW
);
1997 /******************************************************************************
1998 * LookupAccountSidW [ADVAPI32.@]
2015 IN OUT LPDWORD accountSize
,
2017 IN OUT LPDWORD domainSize
,
2018 OUT PSID_NAME_USE name_use
)
2021 const WCHAR
* ac
= NULL
;
2022 const WCHAR
* dm
= NULL
;
2023 SID_NAME_USE use
= 0;
2024 LPWSTR computer_name
= NULL
;
2026 TRACE("(%s,sid=%s,%p,%p(%u),%p,%p(%u),%p)\n",
2027 debugstr_w(system
),debugstr_sid(sid
),
2028 account
,accountSize
,accountSize
?*accountSize
:0,
2029 domain
,domainSize
,domainSize
?*domainSize
:0,
2032 if (!ADVAPI_IsLocalComputer(system
)) {
2033 FIXME("Only local computer supported!\n");
2034 SetLastError(ERROR_NONE_MAPPED
);
2038 /* check the well known SIDs first */
2039 for (i
= 0; i
<= 60; i
++) {
2040 if (IsWellKnownSid(sid
, i
)) {
2041 for (j
= 0; j
< (sizeof(ACCOUNT_SIDS
) / sizeof(ACCOUNT_SIDS
[0])); j
++) {
2042 if (ACCOUNT_SIDS
[j
].type
== i
) {
2043 ac
= ACCOUNT_SIDS
[j
].account
;
2044 dm
= ACCOUNT_SIDS
[j
].domain
;
2045 use
= ACCOUNT_SIDS
[j
].name_use
;
2055 /* check for the local computer next */
2056 if (ADVAPI_GetComputerSid(&local
)) {
2057 DWORD size
= MAX_COMPUTERNAME_LENGTH
+ 1;
2060 computer_name
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
2061 result
= GetComputerNameW(computer_name
, &size
);
2064 if (EqualSid(sid
, &local
)) {
2069 local
.SubAuthorityCount
++;
2071 if (EqualPrefixSid(sid
, &local
)) {
2074 switch (((MAX_SID
*)sid
)->SubAuthority
[4]) {
2075 case DOMAIN_USER_RID_ADMIN
:
2078 case DOMAIN_USER_RID_GUEST
:
2081 case DOMAIN_GROUP_RID_ADMINS
:
2084 case DOMAIN_GROUP_RID_USERS
:
2087 case DOMAIN_GROUP_RID_GUESTS
:
2090 case DOMAIN_GROUP_RID_COMPUTERS
:
2091 ac
= Domain_Computers
;
2093 case DOMAIN_GROUP_RID_CONTROLLERS
:
2094 ac
= Domain_Controllers
;
2096 case DOMAIN_GROUP_RID_CERT_ADMINS
:
2097 ac
= Cert_Publishers
;
2099 case DOMAIN_GROUP_RID_SCHEMA_ADMINS
:
2102 case DOMAIN_GROUP_RID_ENTERPRISE_ADMINS
:
2103 ac
= Enterprise_Admins
;
2105 case DOMAIN_GROUP_RID_POLICY_ADMINS
:
2106 ac
= Group_Policy_Creator_Owners
;
2108 case DOMAIN_ALIAS_RID_RAS_SERVERS
:
2109 ac
= RAS_and_IAS_Servers
;
2122 DWORD ac_len
= lstrlenW(ac
);
2123 DWORD dm_len
= lstrlenW(dm
);
2126 if (*accountSize
> ac_len
) {
2128 lstrcpyW(account
, ac
);
2130 if (*domainSize
> dm_len
) {
2132 lstrcpyW(domain
, dm
);
2134 if (((*accountSize
!= 0) && (*accountSize
< ac_len
)) ||
2135 ((*domainSize
!= 0) && (*domainSize
< dm_len
))) {
2136 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2140 *domainSize
= dm_len
;
2142 *domainSize
= dm_len
+ 1;
2144 *accountSize
= ac_len
;
2146 *accountSize
= ac_len
+ 1;
2148 HeapFree(GetProcessHeap(), 0, computer_name
);
2152 HeapFree(GetProcessHeap(), 0, computer_name
);
2153 SetLastError(ERROR_NONE_MAPPED
);
2157 /******************************************************************************
2158 * SetFileSecurityA [ADVAPI32.@]
2160 * See SetFileSecurityW.
2162 BOOL WINAPI
SetFileSecurityA( LPCSTR lpFileName
,
2163 SECURITY_INFORMATION RequestedInformation
,
2164 PSECURITY_DESCRIPTOR pSecurityDescriptor
)
2172 len
= MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, NULL
, 0 );
2173 name
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
2174 MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, name
, len
);
2177 r
= SetFileSecurityW( name
, RequestedInformation
, pSecurityDescriptor
);
2178 HeapFree( GetProcessHeap(), 0, name
);
2183 /******************************************************************************
2184 * SetFileSecurityW [ADVAPI32.@]
2186 * Sets the security of a file or directory.
2190 * RequestedInformation []
2191 * pSecurityDescriptor []
2198 SetFileSecurityW( LPCWSTR lpFileName
,
2199 SECURITY_INFORMATION RequestedInformation
,
2200 PSECURITY_DESCRIPTOR pSecurityDescriptor
)
2206 TRACE("(%s, 0x%x, %p)\n", debugstr_w(lpFileName
), RequestedInformation
,
2207 pSecurityDescriptor
);
2209 if (RequestedInformation
& OWNER_SECURITY_INFORMATION
||
2210 RequestedInformation
& GROUP_SECURITY_INFORMATION
)
2211 access
|= WRITE_OWNER
;
2212 if (RequestedInformation
& SACL_SECURITY_INFORMATION
)
2213 access
|= ACCESS_SYSTEM_SECURITY
;
2214 if (RequestedInformation
& DACL_SECURITY_INFORMATION
)
2215 access
|= WRITE_DAC
;
2217 file
= CreateFileW( lpFileName
, access
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
2218 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, NULL
);
2219 if (file
== INVALID_HANDLE_VALUE
)
2222 status
= NtSetSecurityObject( file
, RequestedInformation
, pSecurityDescriptor
);
2223 CloseHandle( file
);
2224 return set_ntstatus( status
);
2227 /******************************************************************************
2228 * QueryWindows31FilesMigration [ADVAPI32.@]
2234 QueryWindows31FilesMigration( DWORD x1
)
2236 FIXME("(%d):stub\n",x1
);
2240 /******************************************************************************
2241 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
2250 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1
, DWORD x2
, DWORD x3
,
2253 FIXME("(0x%08x,0x%08x,0x%08x,0x%08x):stub\n",x1
,x2
,x3
,x4
);
2257 /******************************************************************************
2258 * NotifyBootConfigStatus [ADVAPI32.@]
2264 NotifyBootConfigStatus( BOOL x1
)
2266 FIXME("(0x%08d):stub\n",x1
);
2270 /******************************************************************************
2271 * RevertToSelf [ADVAPI32.@]
2273 * Ends the impersonation of a user.
2283 RevertToSelf( void )
2285 HANDLE Token
= NULL
;
2286 return set_ntstatus( NtSetInformationThread( GetCurrentThread(),
2287 ThreadImpersonationToken
, &Token
, sizeof(Token
) ) );
2290 /******************************************************************************
2291 * ImpersonateSelf [ADVAPI32.@]
2293 * Makes an impersonation token that represents the process user and assigns
2294 * to the current thread.
2297 * ImpersonationLevel [I] Level at which to impersonate.
2304 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
)
2306 return set_ntstatus( RtlImpersonateSelf( ImpersonationLevel
) );
2309 /******************************************************************************
2310 * ImpersonateLoggedOnUser [ADVAPI32.@]
2312 BOOL WINAPI
ImpersonateLoggedOnUser(HANDLE hToken
)
2316 HANDLE ImpersonationToken
;
2318 static BOOL warn
= TRUE
;
2322 FIXME( "(%p)\n", hToken
);
2325 if (!GetTokenInformation( hToken
, TokenType
, &Type
,
2326 sizeof(TOKEN_TYPE
), &size
))
2329 if (Type
== TokenPrimary
)
2331 OBJECT_ATTRIBUTES ObjectAttributes
;
2333 InitializeObjectAttributes( &ObjectAttributes
, NULL
, 0, NULL
, NULL
);
2335 Status
= NtDuplicateToken( hToken
,
2336 TOKEN_IMPERSONATE
| TOKEN_QUERY
,
2338 SecurityImpersonation
,
2340 &ImpersonationToken
);
2341 if (Status
!= STATUS_SUCCESS
)
2343 ERR( "NtDuplicateToken failed with error 0x%08x\n", Status
);
2344 SetLastError( RtlNtStatusToDosError( Status
) );
2349 ImpersonationToken
= hToken
;
2351 Status
= NtSetInformationThread( GetCurrentThread(),
2352 ThreadImpersonationToken
,
2353 &ImpersonationToken
,
2354 sizeof(ImpersonationToken
) );
2356 if (Type
== TokenPrimary
)
2357 NtClose( ImpersonationToken
);
2359 if (Status
!= STATUS_SUCCESS
)
2361 ERR( "NtSetInformationThread failed with error 0x%08x\n", Status
);
2362 SetLastError( RtlNtStatusToDosError( Status
) );
2369 /******************************************************************************
2370 * AccessCheck [ADVAPI32.@]
2374 PSECURITY_DESCRIPTOR SecurityDescriptor
,
2376 DWORD DesiredAccess
,
2377 PGENERIC_MAPPING GenericMapping
,
2378 PPRIVILEGE_SET PrivilegeSet
,
2379 LPDWORD PrivilegeSetLength
,
2380 LPDWORD GrantedAccess
,
2381 LPBOOL AccessStatus
)
2383 NTSTATUS access_status
;
2384 BOOL ret
= set_ntstatus( NtAccessCheck(SecurityDescriptor
, ClientToken
, DesiredAccess
,
2385 GenericMapping
, PrivilegeSet
, PrivilegeSetLength
,
2386 GrantedAccess
, &access_status
) );
2387 if (ret
) *AccessStatus
= set_ntstatus( access_status
);
2392 /******************************************************************************
2393 * AccessCheckByType [ADVAPI32.@]
2395 BOOL WINAPI
AccessCheckByType(
2396 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
2397 PSID PrincipalSelfSid
,
2399 DWORD DesiredAccess
,
2400 POBJECT_TYPE_LIST ObjectTypeList
,
2401 DWORD ObjectTypeListLength
,
2402 PGENERIC_MAPPING GenericMapping
,
2403 PPRIVILEGE_SET PrivilegeSet
,
2404 LPDWORD PrivilegeSetLength
,
2405 LPDWORD GrantedAccess
,
2406 LPBOOL AccessStatus
)
2410 *AccessStatus
= TRUE
;
2412 return !*AccessStatus
;
2415 /******************************************************************************
2416 * MapGenericMask [ADVAPI32.@]
2418 * Maps generic access rights into specific access rights according to the
2422 * AccessMask [I/O] Access rights.
2423 * GenericMapping [I] The mapping between generic and specific rights.
2428 VOID WINAPI
MapGenericMask( PDWORD AccessMask
, PGENERIC_MAPPING GenericMapping
)
2430 RtlMapGenericMask( AccessMask
, GenericMapping
);
2433 /*************************************************************************
2434 * SetKernelObjectSecurity [ADVAPI32.@]
2436 BOOL WINAPI
SetKernelObjectSecurity (
2438 IN SECURITY_INFORMATION SecurityInformation
,
2439 IN PSECURITY_DESCRIPTOR SecurityDescriptor
)
2441 return set_ntstatus (NtSetSecurityObject (Handle
, SecurityInformation
, SecurityDescriptor
));
2445 /******************************************************************************
2446 * AddAuditAccessAce [ADVAPI32.@]
2448 BOOL WINAPI
AddAuditAccessAce(
2450 IN DWORD dwAceRevision
,
2451 IN DWORD dwAccessMask
,
2453 IN BOOL bAuditSuccess
,
2454 IN BOOL bAuditFailure
)
2456 return set_ntstatus( RtlAddAuditAccessAce(pAcl
, dwAceRevision
, dwAccessMask
, pSid
,
2457 bAuditSuccess
, bAuditFailure
) );
2460 /******************************************************************************
2461 * AddAuditAccessAce [ADVAPI32.@]
2463 BOOL WINAPI
AddAuditAccessAceEx(
2465 IN DWORD dwAceRevision
,
2466 IN DWORD dwAceFlags
,
2467 IN DWORD dwAccessMask
,
2469 IN BOOL bAuditSuccess
,
2470 IN BOOL bAuditFailure
)
2472 return set_ntstatus( RtlAddAuditAccessAceEx(pAcl
, dwAceRevision
, dwAceFlags
, dwAccessMask
, pSid
,
2473 bAuditSuccess
, bAuditFailure
) );
2476 /******************************************************************************
2477 * LookupAccountNameA [ADVAPI32.@]
2485 LPSTR ReferencedDomainName
,
2486 IN OUT LPDWORD cbReferencedDomainName
,
2487 OUT PSID_NAME_USE name_use
)
2490 UNICODE_STRING lpSystemW
;
2491 UNICODE_STRING lpAccountW
;
2492 LPWSTR lpReferencedDomainNameW
= NULL
;
2494 RtlCreateUnicodeStringFromAsciiz(&lpSystemW
, system
);
2495 RtlCreateUnicodeStringFromAsciiz(&lpAccountW
, account
);
2497 if (ReferencedDomainName
)
2498 lpReferencedDomainNameW
= HeapAlloc(GetProcessHeap(), 0, *cbReferencedDomainName
* sizeof(WCHAR
));
2500 ret
= LookupAccountNameW(lpSystemW
.Buffer
, lpAccountW
.Buffer
, sid
, cbSid
, lpReferencedDomainNameW
,
2501 cbReferencedDomainName
, name_use
);
2503 if (ret
&& lpReferencedDomainNameW
)
2505 WideCharToMultiByte(CP_ACP
, 0, lpReferencedDomainNameW
, -1,
2506 ReferencedDomainName
, *cbReferencedDomainName
+1, NULL
, NULL
);
2509 RtlFreeUnicodeString(&lpSystemW
);
2510 RtlFreeUnicodeString(&lpAccountW
);
2511 HeapFree(GetProcessHeap(), 0, lpReferencedDomainNameW
);
2516 /******************************************************************************
2517 * LookupAccountNameW [ADVAPI32.@]
2519 BOOL WINAPI
LookupAccountNameW( LPCWSTR lpSystemName
, LPCWSTR lpAccountName
, PSID Sid
,
2520 LPDWORD cbSid
, LPWSTR ReferencedDomainName
,
2521 LPDWORD cchReferencedDomainName
, PSID_NAME_USE peUse
)
2523 /* Default implementation: Always return a default SID */
2524 SID_IDENTIFIER_AUTHORITY identifierAuthority
= {SECURITY_NT_AUTHORITY
};
2527 static const WCHAR dm
[] = {'D','O','M','A','I','N',0};
2532 FIXME("%s %s %p %p %p %p %p - stub\n", debugstr_w(lpSystemName
), debugstr_w(lpAccountName
),
2533 Sid
, cbSid
, ReferencedDomainName
, cchReferencedDomainName
, peUse
);
2535 for (i
= 0; i
< (sizeof(ACCOUNT_SIDS
) / sizeof(ACCOUNT_SIDS
[0])); i
++)
2537 if (!strcmpW(lpAccountName
, ACCOUNT_SIDS
[i
].account
))
2539 ret
= CreateWellKnownSid(ACCOUNT_SIDS
[i
].type
, NULL
, Sid
, cbSid
);
2541 domainName
= ACCOUNT_SIDS
[i
].domain
;
2542 nameLen
= strlenW(domainName
);
2544 if (*cchReferencedDomainName
<= nameLen
|| !ret
)
2546 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2550 else if (ReferencedDomainName
&& domainName
)
2552 strcpyW(ReferencedDomainName
, domainName
);
2555 *cchReferencedDomainName
= nameLen
;
2559 *peUse
= ACCOUNT_SIDS
[i
].name_use
;
2566 ret
= AllocateAndInitializeSid(&identifierAuthority
,
2568 SECURITY_BUILTIN_DOMAIN_RID
,
2569 DOMAIN_ALIAS_RID_ADMINS
,
2576 if (!RtlValidSid(pSid
))
2582 if (Sid
!= NULL
&& (*cbSid
>= GetLengthSid(pSid
)))
2583 CopySid(*cbSid
, Sid
, pSid
);
2584 if (*cbSid
< GetLengthSid(pSid
))
2586 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2589 *cbSid
= GetLengthSid(pSid
);
2592 nameLen
= strlenW(domainName
);
2594 if (*cchReferencedDomainName
<= nameLen
|| !ret
)
2596 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2600 else if (ReferencedDomainName
&& domainName
)
2602 strcpyW(ReferencedDomainName
, domainName
);
2605 *cchReferencedDomainName
= nameLen
;
2609 *peUse
= SidTypeUser
;
2617 /******************************************************************************
2618 * PrivilegeCheck [ADVAPI32.@]
2620 BOOL WINAPI
PrivilegeCheck( HANDLE ClientToken
, PPRIVILEGE_SET RequiredPrivileges
, LPBOOL pfResult
)
2625 TRACE("%p %p %p\n", ClientToken
, RequiredPrivileges
, pfResult
);
2627 ret
= set_ntstatus (NtPrivilegeCheck (ClientToken
, RequiredPrivileges
, &Result
));
2633 /******************************************************************************
2634 * AccessCheckAndAuditAlarmA [ADVAPI32.@]
2636 BOOL WINAPI
AccessCheckAndAuditAlarmA(LPCSTR Subsystem
, LPVOID HandleId
, LPSTR ObjectTypeName
,
2637 LPSTR ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
, DWORD DesiredAccess
,
2638 PGENERIC_MAPPING GenericMapping
, BOOL ObjectCreation
, LPDWORD GrantedAccess
,
2639 LPBOOL AccessStatus
, LPBOOL pfGenerateOnClose
)
2641 FIXME("stub (%s,%p,%s,%s,%p,%08x,%p,%x,%p,%p,%p)\n", debugstr_a(Subsystem
),
2642 HandleId
, debugstr_a(ObjectTypeName
), debugstr_a(ObjectName
),
2643 SecurityDescriptor
, DesiredAccess
, GenericMapping
,
2644 ObjectCreation
, GrantedAccess
, AccessStatus
, pfGenerateOnClose
);
2648 /******************************************************************************
2649 * AccessCheckAndAuditAlarmW [ADVAPI32.@]
2651 BOOL WINAPI
AccessCheckAndAuditAlarmW(LPCWSTR Subsystem
, LPVOID HandleId
, LPWSTR ObjectTypeName
,
2652 LPWSTR ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
, DWORD DesiredAccess
,
2653 PGENERIC_MAPPING GenericMapping
, BOOL ObjectCreation
, LPDWORD GrantedAccess
,
2654 LPBOOL AccessStatus
, LPBOOL pfGenerateOnClose
)
2656 FIXME("stub (%s,%p,%s,%s,%p,%08x,%p,%x,%p,%p,%p)\n", debugstr_w(Subsystem
),
2657 HandleId
, debugstr_w(ObjectTypeName
), debugstr_w(ObjectName
),
2658 SecurityDescriptor
, DesiredAccess
, GenericMapping
,
2659 ObjectCreation
, GrantedAccess
, AccessStatus
, pfGenerateOnClose
);
2663 BOOL WINAPI
ObjectCloseAuditAlarmA(LPCSTR SubsystemName
, LPVOID HandleId
, BOOL GenerateOnClose
)
2665 FIXME("stub (%s,%p,%x)\n", debugstr_a(SubsystemName
), HandleId
, GenerateOnClose
);
2670 BOOL WINAPI
ObjectCloseAuditAlarmW(LPCWSTR SubsystemName
, LPVOID HandleId
, BOOL GenerateOnClose
)
2672 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName
), HandleId
, GenerateOnClose
);
2677 BOOL WINAPI
ObjectDeleteAuditAlarmW(LPCWSTR SubsystemName
, LPVOID HandleId
, BOOL GenerateOnClose
)
2679 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName
), HandleId
, GenerateOnClose
);
2684 BOOL WINAPI
ObjectOpenAuditAlarmA(LPCSTR SubsystemName
, LPVOID HandleId
, LPSTR ObjectTypeName
,
2685 LPSTR ObjectName
, PSECURITY_DESCRIPTOR pSecurityDescriptor
, HANDLE ClientToken
, DWORD DesiredAccess
,
2686 DWORD GrantedAccess
, PPRIVILEGE_SET Privileges
, BOOL ObjectCreation
, BOOL AccessGranted
,
2687 LPBOOL GenerateOnClose
)
2689 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08x,0x%08x,%p,%x,%x,%p)\n", debugstr_a(SubsystemName
),
2690 HandleId
, debugstr_a(ObjectTypeName
), debugstr_a(ObjectName
), pSecurityDescriptor
,
2691 ClientToken
, DesiredAccess
, GrantedAccess
, Privileges
, ObjectCreation
, AccessGranted
,
2697 BOOL WINAPI
ObjectOpenAuditAlarmW(LPCWSTR SubsystemName
, LPVOID HandleId
, LPWSTR ObjectTypeName
,
2698 LPWSTR ObjectName
, PSECURITY_DESCRIPTOR pSecurityDescriptor
, HANDLE ClientToken
, DWORD DesiredAccess
,
2699 DWORD GrantedAccess
, PPRIVILEGE_SET Privileges
, BOOL ObjectCreation
, BOOL AccessGranted
,
2700 LPBOOL GenerateOnClose
)
2702 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08x,0x%08x,%p,%x,%x,%p)\n", debugstr_w(SubsystemName
),
2703 HandleId
, debugstr_w(ObjectTypeName
), debugstr_w(ObjectName
), pSecurityDescriptor
,
2704 ClientToken
, DesiredAccess
, GrantedAccess
, Privileges
, ObjectCreation
, AccessGranted
,
2710 BOOL WINAPI
ObjectPrivilegeAuditAlarmA( LPCSTR SubsystemName
, LPVOID HandleId
, HANDLE ClientToken
,
2711 DWORD DesiredAccess
, PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2713 FIXME("stub (%s,%p,%p,0x%08x,%p,%x)\n", debugstr_a(SubsystemName
), HandleId
, ClientToken
,
2714 DesiredAccess
, Privileges
, AccessGranted
);
2719 BOOL WINAPI
ObjectPrivilegeAuditAlarmW( LPCWSTR SubsystemName
, LPVOID HandleId
, HANDLE ClientToken
,
2720 DWORD DesiredAccess
, PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2722 FIXME("stub (%s,%p,%p,0x%08x,%p,%x)\n", debugstr_w(SubsystemName
), HandleId
, ClientToken
,
2723 DesiredAccess
, Privileges
, AccessGranted
);
2728 BOOL WINAPI
PrivilegedServiceAuditAlarmA( LPCSTR SubsystemName
, LPCSTR ServiceName
, HANDLE ClientToken
,
2729 PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2731 FIXME("stub (%s,%s,%p,%p,%x)\n", debugstr_a(SubsystemName
), debugstr_a(ServiceName
),
2732 ClientToken
, Privileges
, AccessGranted
);
2737 BOOL WINAPI
PrivilegedServiceAuditAlarmW( LPCWSTR SubsystemName
, LPCWSTR ServiceName
, HANDLE ClientToken
,
2738 PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2740 FIXME("stub %s,%s,%p,%p,%x)\n", debugstr_w(SubsystemName
), debugstr_w(ServiceName
),
2741 ClientToken
, Privileges
, AccessGranted
);
2746 /******************************************************************************
2747 * GetSecurityInfo [ADVAPI32.@]
2749 * Retrieves a copy of the security descriptor associated with an object.
2752 * hObject [I] A handle for the object.
2753 * ObjectType [I] The type of object.
2754 * SecurityInfo [I] A bitmask indicating what info to retrieve.
2755 * ppsidOwner [O] If non-null, receives a pointer to the owner SID.
2756 * ppsidGroup [O] If non-null, receives a pointer to the group SID.
2757 * ppDacl [O] If non-null, receives a pointer to the DACL.
2758 * ppSacl [O] If non-null, receives a pointer to the SACL.
2759 * ppSecurityDescriptor [O] Receives a pointer to the security descriptor,
2760 * which must be freed with LocalFree.
2763 * ERROR_SUCCESS if all's well, and a WIN32 error code otherwise.
2765 DWORD WINAPI
GetSecurityInfo(
2766 HANDLE hObject
, SE_OBJECT_TYPE ObjectType
,
2767 SECURITY_INFORMATION SecurityInfo
, PSID
*ppsidOwner
,
2768 PSID
*ppsidGroup
, PACL
*ppDacl
, PACL
*ppSacl
,
2769 PSECURITY_DESCRIPTOR
*ppSecurityDescriptor
2772 PSECURITY_DESCRIPTOR sd
;
2775 BOOL present
, defaulted
;
2777 status
= NtQuerySecurityObject(hObject
, SecurityInfo
, NULL
, 0, &n1
);
2778 if (status
!= STATUS_BUFFER_TOO_SMALL
&& status
!= STATUS_SUCCESS
)
2779 return RtlNtStatusToDosError(status
);
2781 sd
= LocalAlloc(0, n1
);
2783 return ERROR_NOT_ENOUGH_MEMORY
;
2785 status
= NtQuerySecurityObject(hObject
, SecurityInfo
, sd
, n1
, &n2
);
2786 if (status
!= STATUS_SUCCESS
)
2789 return RtlNtStatusToDosError(status
);
2795 GetSecurityDescriptorOwner(sd
, ppsidOwner
, &defaulted
);
2800 GetSecurityDescriptorGroup(sd
, ppsidGroup
, &defaulted
);
2805 GetSecurityDescriptorDacl(sd
, &present
, ppDacl
, &defaulted
);
2810 GetSecurityDescriptorSacl(sd
, &present
, ppSacl
, &defaulted
);
2812 if (ppSecurityDescriptor
)
2813 *ppSecurityDescriptor
= sd
;
2815 return ERROR_SUCCESS
;
2818 /******************************************************************************
2819 * GetSecurityInfoExW [ADVAPI32.@]
2821 DWORD WINAPI
GetSecurityInfoExW(
2822 HANDLE hObject
, SE_OBJECT_TYPE ObjectType
,
2823 SECURITY_INFORMATION SecurityInfo
, LPCWSTR lpProvider
,
2824 LPCWSTR lpProperty
, PACTRL_ACCESSW
*ppAccessList
,
2825 PACTRL_AUDITW
*ppAuditList
, LPWSTR
*lppOwner
, LPWSTR
*lppGroup
2829 return ERROR_BAD_PROVIDER
;
2832 /******************************************************************************
2833 * BuildExplicitAccessWithNameA [ADVAPI32.@]
2835 VOID WINAPI
BuildExplicitAccessWithNameA( PEXPLICIT_ACCESSA pExplicitAccess
,
2836 LPSTR pTrusteeName
, DWORD AccessPermissions
,
2837 ACCESS_MODE AccessMode
, DWORD Inheritance
)
2839 TRACE("%p %s 0x%08x 0x%08x 0x%08x\n", pExplicitAccess
, debugstr_a(pTrusteeName
),
2840 AccessPermissions
, AccessMode
, Inheritance
);
2842 pExplicitAccess
->grfAccessPermissions
= AccessPermissions
;
2843 pExplicitAccess
->grfAccessMode
= AccessMode
;
2844 pExplicitAccess
->grfInheritance
= Inheritance
;
2846 pExplicitAccess
->Trustee
.pMultipleTrustee
= NULL
;
2847 pExplicitAccess
->Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2848 pExplicitAccess
->Trustee
.TrusteeForm
= TRUSTEE_IS_NAME
;
2849 pExplicitAccess
->Trustee
.TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2850 pExplicitAccess
->Trustee
.ptstrName
= pTrusteeName
;
2853 /******************************************************************************
2854 * BuildExplicitAccessWithNameW [ADVAPI32.@]
2856 VOID WINAPI
BuildExplicitAccessWithNameW( PEXPLICIT_ACCESSW pExplicitAccess
,
2857 LPWSTR pTrusteeName
, DWORD AccessPermissions
,
2858 ACCESS_MODE AccessMode
, DWORD Inheritance
)
2860 TRACE("%p %s 0x%08x 0x%08x 0x%08x\n", pExplicitAccess
, debugstr_w(pTrusteeName
),
2861 AccessPermissions
, AccessMode
, Inheritance
);
2863 pExplicitAccess
->grfAccessPermissions
= AccessPermissions
;
2864 pExplicitAccess
->grfAccessMode
= AccessMode
;
2865 pExplicitAccess
->grfInheritance
= Inheritance
;
2867 pExplicitAccess
->Trustee
.pMultipleTrustee
= NULL
;
2868 pExplicitAccess
->Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2869 pExplicitAccess
->Trustee
.TrusteeForm
= TRUSTEE_IS_NAME
;
2870 pExplicitAccess
->Trustee
.TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2871 pExplicitAccess
->Trustee
.ptstrName
= pTrusteeName
;
2874 /******************************************************************************
2875 * BuildTrusteeWithObjectsAndNameA [ADVAPI32.@]
2877 VOID WINAPI
BuildTrusteeWithObjectsAndNameA( PTRUSTEEA pTrustee
, POBJECTS_AND_NAME_A pObjName
,
2878 SE_OBJECT_TYPE ObjectType
, LPSTR ObjectTypeName
,
2879 LPSTR InheritedObjectTypeName
, LPSTR Name
)
2881 DWORD ObjectsPresent
= 0;
2883 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee
, pObjName
,
2884 ObjectType
, ObjectTypeName
, InheritedObjectTypeName
, debugstr_a(Name
));
2886 /* Fill the OBJECTS_AND_NAME structure */
2887 pObjName
->ObjectType
= ObjectType
;
2888 if (ObjectTypeName
!= NULL
)
2890 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2893 pObjName
->InheritedObjectTypeName
= InheritedObjectTypeName
;
2894 if (InheritedObjectTypeName
!= NULL
)
2896 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2899 pObjName
->ObjectsPresent
= ObjectsPresent
;
2900 pObjName
->ptstrName
= Name
;
2902 /* Fill the TRUSTEE structure */
2903 pTrustee
->pMultipleTrustee
= NULL
;
2904 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2905 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_NAME
;
2906 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2907 pTrustee
->ptstrName
= (LPSTR
)pObjName
;
2910 /******************************************************************************
2911 * BuildTrusteeWithObjectsAndNameW [ADVAPI32.@]
2913 VOID WINAPI
BuildTrusteeWithObjectsAndNameW( PTRUSTEEW pTrustee
, POBJECTS_AND_NAME_W pObjName
,
2914 SE_OBJECT_TYPE ObjectType
, LPWSTR ObjectTypeName
,
2915 LPWSTR InheritedObjectTypeName
, LPWSTR Name
)
2917 DWORD ObjectsPresent
= 0;
2919 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee
, pObjName
,
2920 ObjectType
, ObjectTypeName
, InheritedObjectTypeName
, debugstr_w(Name
));
2922 /* Fill the OBJECTS_AND_NAME structure */
2923 pObjName
->ObjectType
= ObjectType
;
2924 if (ObjectTypeName
!= NULL
)
2926 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2929 pObjName
->InheritedObjectTypeName
= InheritedObjectTypeName
;
2930 if (InheritedObjectTypeName
!= NULL
)
2932 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2935 pObjName
->ObjectsPresent
= ObjectsPresent
;
2936 pObjName
->ptstrName
= Name
;
2938 /* Fill the TRUSTEE structure */
2939 pTrustee
->pMultipleTrustee
= NULL
;
2940 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2941 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_NAME
;
2942 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2943 pTrustee
->ptstrName
= (LPWSTR
)pObjName
;
2946 /******************************************************************************
2947 * BuildTrusteeWithObjectsAndSidA [ADVAPI32.@]
2949 VOID WINAPI
BuildTrusteeWithObjectsAndSidA( PTRUSTEEA pTrustee
, POBJECTS_AND_SID pObjSid
,
2950 GUID
* pObjectGuid
, GUID
* pInheritedObjectGuid
, PSID pSid
)
2952 DWORD ObjectsPresent
= 0;
2954 TRACE("%p %p %p %p %p\n", pTrustee
, pObjSid
, pObjectGuid
, pInheritedObjectGuid
, pSid
);
2956 /* Fill the OBJECTS_AND_SID structure */
2957 if (pObjectGuid
!= NULL
)
2959 pObjSid
->ObjectTypeGuid
= *pObjectGuid
;
2960 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2964 ZeroMemory(&pObjSid
->ObjectTypeGuid
,
2968 if (pInheritedObjectGuid
!= NULL
)
2970 pObjSid
->InheritedObjectTypeGuid
= *pInheritedObjectGuid
;
2971 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2975 ZeroMemory(&pObjSid
->InheritedObjectTypeGuid
,
2979 pObjSid
->ObjectsPresent
= ObjectsPresent
;
2980 pObjSid
->pSid
= pSid
;
2982 /* Fill the TRUSTEE structure */
2983 pTrustee
->pMultipleTrustee
= NULL
;
2984 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2985 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_SID
;
2986 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2987 pTrustee
->ptstrName
= (LPSTR
) pObjSid
;
2990 /******************************************************************************
2991 * BuildTrusteeWithObjectsAndSidW [ADVAPI32.@]
2993 VOID WINAPI
BuildTrusteeWithObjectsAndSidW( PTRUSTEEW pTrustee
, POBJECTS_AND_SID pObjSid
,
2994 GUID
* pObjectGuid
, GUID
* pInheritedObjectGuid
, PSID pSid
)
2996 DWORD ObjectsPresent
= 0;
2998 TRACE("%p %p %p %p %p\n", pTrustee
, pObjSid
, pObjectGuid
, pInheritedObjectGuid
, pSid
);
3000 /* Fill the OBJECTS_AND_SID structure */
3001 if (pObjectGuid
!= NULL
)
3003 pObjSid
->ObjectTypeGuid
= *pObjectGuid
;
3004 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
3008 ZeroMemory(&pObjSid
->ObjectTypeGuid
,
3012 if (pInheritedObjectGuid
!= NULL
)
3014 pObjSid
->InheritedObjectTypeGuid
= *pInheritedObjectGuid
;
3015 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
3019 ZeroMemory(&pObjSid
->InheritedObjectTypeGuid
,
3023 pObjSid
->ObjectsPresent
= ObjectsPresent
;
3024 pObjSid
->pSid
= pSid
;
3026 /* Fill the TRUSTEE structure */
3027 pTrustee
->pMultipleTrustee
= NULL
;
3028 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
3029 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_SID
;
3030 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
3031 pTrustee
->ptstrName
= (LPWSTR
) pObjSid
;
3034 /******************************************************************************
3035 * BuildTrusteeWithSidA [ADVAPI32.@]
3037 VOID WINAPI
BuildTrusteeWithSidA(PTRUSTEEA pTrustee
, PSID pSid
)
3039 TRACE("%p %p\n", pTrustee
, pSid
);
3041 pTrustee
->pMultipleTrustee
= NULL
;
3042 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
3043 pTrustee
->TrusteeForm
= TRUSTEE_IS_SID
;
3044 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
3045 pTrustee
->ptstrName
= (LPSTR
) pSid
;
3048 /******************************************************************************
3049 * BuildTrusteeWithSidW [ADVAPI32.@]
3051 VOID WINAPI
BuildTrusteeWithSidW(PTRUSTEEW pTrustee
, PSID pSid
)
3053 TRACE("%p %p\n", pTrustee
, pSid
);
3055 pTrustee
->pMultipleTrustee
= NULL
;
3056 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
3057 pTrustee
->TrusteeForm
= TRUSTEE_IS_SID
;
3058 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
3059 pTrustee
->ptstrName
= (LPWSTR
) pSid
;
3062 /******************************************************************************
3063 * BuildTrusteeWithNameA [ADVAPI32.@]
3065 VOID WINAPI
BuildTrusteeWithNameA(PTRUSTEEA pTrustee
, LPSTR name
)
3067 TRACE("%p %s\n", pTrustee
, debugstr_a(name
) );
3069 pTrustee
->pMultipleTrustee
= NULL
;
3070 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
3071 pTrustee
->TrusteeForm
= TRUSTEE_IS_NAME
;
3072 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
3073 pTrustee
->ptstrName
= name
;
3076 /******************************************************************************
3077 * BuildTrusteeWithNameW [ADVAPI32.@]
3079 VOID WINAPI
BuildTrusteeWithNameW(PTRUSTEEW pTrustee
, LPWSTR name
)
3081 TRACE("%p %s\n", pTrustee
, debugstr_w(name
) );
3083 pTrustee
->pMultipleTrustee
= NULL
;
3084 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
3085 pTrustee
->TrusteeForm
= TRUSTEE_IS_NAME
;
3086 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
3087 pTrustee
->ptstrName
= name
;
3090 /******************************************************************************
3091 * GetTrusteeFormA [ADVAPI32.@]
3093 TRUSTEE_FORM WINAPI
GetTrusteeFormA(PTRUSTEEA pTrustee
)
3095 TRACE("(%p)\n", pTrustee
);
3098 return TRUSTEE_BAD_FORM
;
3100 return pTrustee
->TrusteeForm
;
3103 /******************************************************************************
3104 * GetTrusteeFormW [ADVAPI32.@]
3106 TRUSTEE_FORM WINAPI
GetTrusteeFormW(PTRUSTEEW pTrustee
)
3108 TRACE("(%p)\n", pTrustee
);
3111 return TRUSTEE_BAD_FORM
;
3113 return pTrustee
->TrusteeForm
;
3116 /******************************************************************************
3117 * GetTrusteeNameA [ADVAPI32.@]
3119 LPSTR WINAPI
GetTrusteeNameA(PTRUSTEEA pTrustee
)
3121 TRACE("(%p)\n", pTrustee
);
3126 return pTrustee
->ptstrName
;
3129 /******************************************************************************
3130 * GetTrusteeNameW [ADVAPI32.@]
3132 LPWSTR WINAPI
GetTrusteeNameW(PTRUSTEEW pTrustee
)
3134 TRACE("(%p)\n", pTrustee
);
3139 return pTrustee
->ptstrName
;
3142 /******************************************************************************
3143 * GetTrusteeTypeA [ADVAPI32.@]
3145 TRUSTEE_TYPE WINAPI
GetTrusteeTypeA(PTRUSTEEA pTrustee
)
3147 TRACE("(%p)\n", pTrustee
);
3150 return TRUSTEE_IS_UNKNOWN
;
3152 return pTrustee
->TrusteeType
;
3155 /******************************************************************************
3156 * GetTrusteeTypeW [ADVAPI32.@]
3158 TRUSTEE_TYPE WINAPI
GetTrusteeTypeW(PTRUSTEEW pTrustee
)
3160 TRACE("(%p)\n", pTrustee
);
3163 return TRUSTEE_IS_UNKNOWN
;
3165 return pTrustee
->TrusteeType
;
3168 BOOL WINAPI
SetAclInformation( PACL pAcl
, LPVOID pAclInformation
,
3169 DWORD nAclInformationLength
,
3170 ACL_INFORMATION_CLASS dwAclInformationClass
)
3172 FIXME("%p %p 0x%08x 0x%08x - stub\n", pAcl
, pAclInformation
,
3173 nAclInformationLength
, dwAclInformationClass
);
3178 /******************************************************************************
3179 * SetEntriesInAclA [ADVAPI32.@]
3181 DWORD WINAPI
SetEntriesInAclA( ULONG count
, PEXPLICIT_ACCESSA pEntries
,
3182 PACL OldAcl
, PACL
* NewAcl
)
3184 FIXME("%d %p %p %p\n",count
,pEntries
,OldAcl
,NewAcl
);
3187 return ERROR_SUCCESS
;
3190 /******************************************************************************
3191 * SetEntriesInAclW [ADVAPI32.@]
3193 DWORD WINAPI
SetEntriesInAclW( ULONG count
, PEXPLICIT_ACCESSW pEntries
,
3194 PACL OldAcl
, PACL
* NewAcl
)
3198 DWORD ret
= ERROR_SUCCESS
;
3199 DWORD acl_size
= sizeof(ACL
);
3202 TRACE("%d %p %p %p\n", count
, pEntries
, OldAcl
, NewAcl
);
3206 if (!count
&& !OldAcl
)
3207 return ERROR_SUCCESS
;
3209 /* allocate array of maximum sized sids allowed */
3210 ppsid
= HeapAlloc(GetProcessHeap(), 0, count
* (sizeof(SID
*) + FIELD_OFFSET(SID
, SubAuthority
[SID_MAX_SUB_AUTHORITIES
])));
3212 return ERROR_OUTOFMEMORY
;
3214 for (i
= 0; i
< count
; i
++)
3216 ppsid
[i
] = (char *)&ppsid
[count
] + i
* FIELD_OFFSET(SID
, SubAuthority
[SID_MAX_SUB_AUTHORITIES
]);
3218 TRACE("[%d]:\n\tgrfAccessPermissions = 0x%x\n\tgrfAccessMode = %d\n\tgrfInheritance = 0x%x\n\t"
3219 "Trustee.pMultipleTrustee = %p\n\tMultipleTrusteeOperation = %d\n\tTrusteeForm = %d\n\t"
3220 "Trustee.TrusteeType = %d\n\tptstrName = %p\n", i
,
3221 pEntries
[i
].grfAccessPermissions
, pEntries
[i
].grfAccessMode
, pEntries
[i
].grfInheritance
,
3222 pEntries
[i
].Trustee
.pMultipleTrustee
, pEntries
[i
].Trustee
.MultipleTrusteeOperation
,
3223 pEntries
[i
].Trustee
.TrusteeForm
, pEntries
[i
].Trustee
.TrusteeType
,
3224 pEntries
[i
].Trustee
.ptstrName
);
3226 if (pEntries
[i
].Trustee
.MultipleTrusteeOperation
!= NO_MULTIPLE_TRUSTEE
)
3228 WARN("bad multiple trustee operation %d for trustee %d\n", pEntries
[i
].Trustee
.MultipleTrusteeOperation
, i
);
3229 ret
= ERROR_INVALID_PARAMETER
;
3233 switch (pEntries
[i
].Trustee
.TrusteeForm
)
3235 case TRUSTEE_IS_SID
:
3236 if (!CopySid(FIELD_OFFSET(SID
, SubAuthority
[SID_MAX_SUB_AUTHORITIES
]),
3237 ppsid
[i
], pEntries
[i
].Trustee
.ptstrName
))
3239 WARN("bad sid %p for trustee %d\n", pEntries
[i
].Trustee
.ptstrName
, i
);
3240 ret
= ERROR_INVALID_PARAMETER
;
3244 case TRUSTEE_IS_NAME
:
3246 DWORD sid_size
= FIELD_OFFSET(SID
, SubAuthority
[SID_MAX_SUB_AUTHORITIES
]);
3247 DWORD domain_size
= MAX_COMPUTERNAME_LENGTH
+ 1;
3249 if (!LookupAccountNameW(NULL
, pEntries
[i
].Trustee
.ptstrName
, ppsid
[i
], &sid_size
, NULL
, &domain_size
, &use
))
3251 WARN("bad user name %s for trustee %d\n", debugstr_w(pEntries
[i
].Trustee
.ptstrName
), i
);
3252 ret
= ERROR_INVALID_PARAMETER
;
3257 case TRUSTEE_IS_OBJECTS_AND_SID
:
3258 FIXME("TRUSTEE_IS_OBJECTS_AND_SID unimplemented\n");
3260 case TRUSTEE_IS_OBJECTS_AND_NAME
:
3261 FIXME("TRUSTEE_IS_OBJECTS_AND_NAME unimplemented\n");
3264 WARN("bad trustee form %d for trustee %d\n", pEntries
[i
].Trustee
.TrusteeForm
, i
);
3265 ret
= ERROR_INVALID_PARAMETER
;
3269 /* Note: we overestimate the ACL size here as a tradeoff between
3270 * instructions (simplicity) and memory */
3271 switch (pEntries
[i
].grfAccessMode
)
3275 acl_size
+= FIELD_OFFSET(ACCESS_ALLOWED_ACE
, SidStart
) + GetLengthSid(ppsid
[i
]);
3278 acl_size
+= FIELD_OFFSET(ACCESS_DENIED_ACE
, SidStart
) + GetLengthSid(ppsid
[i
]);
3280 case SET_AUDIT_SUCCESS
:
3281 case SET_AUDIT_FAILURE
:
3282 acl_size
+= FIELD_OFFSET(SYSTEM_AUDIT_ACE
, SidStart
) + GetLengthSid(ppsid
[i
]);
3287 WARN("bad access mode %d for trustee %d\n", pEntries
[i
].grfAccessMode
, i
);
3288 ret
= ERROR_INVALID_PARAMETER
;
3295 ACL_SIZE_INFORMATION size_info
;
3297 status
= RtlQueryInformationAcl(OldAcl
, &size_info
, sizeof(size_info
), AclSizeInformation
);
3298 if (status
!= STATUS_SUCCESS
)
3300 ret
= RtlNtStatusToDosError(status
);
3303 acl_size
+= size_info
.AclBytesInUse
- sizeof(ACL
);
3306 *NewAcl
= LocalAlloc(0, acl_size
);
3309 ret
= ERROR_OUTOFMEMORY
;
3313 status
= RtlCreateAcl( *NewAcl
, acl_size
, ACL_REVISION
);
3314 if (status
!= STATUS_SUCCESS
)
3316 ret
= RtlNtStatusToDosError(status
);
3320 for (i
= 0; i
< count
; i
++)
3322 switch (pEntries
[i
].grfAccessMode
)
3325 status
= RtlAddAccessAllowedAceEx(*NewAcl
, ACL_REVISION
,
3326 pEntries
[i
].grfInheritance
,
3327 pEntries
[i
].grfAccessPermissions
,
3338 const ACE_HEADER
*existing_ace_header
;
3339 status
= RtlGetAce(OldAcl
, j
, (LPVOID
*)&existing_ace_header
);
3340 if (status
!= STATUS_SUCCESS
)
3342 if (pEntries
[i
].grfAccessMode
== SET_ACCESS
&&
3343 existing_ace_header
->AceType
== ACCESS_ALLOWED_ACE_TYPE
&&
3344 EqualSid(ppsid
[i
], &((ACCESS_ALLOWED_ACE
*)existing_ace_header
)->SidStart
))
3352 status
= RtlAddAccessAllowedAceEx(*NewAcl
, ACL_REVISION
,
3353 pEntries
[i
].grfInheritance
,
3354 pEntries
[i
].grfAccessPermissions
,
3359 status
= RtlAddAccessDeniedAceEx(*NewAcl
, ACL_REVISION
,
3360 pEntries
[i
].grfInheritance
,
3361 pEntries
[i
].grfAccessPermissions
,
3364 case SET_AUDIT_SUCCESS
:
3365 status
= RtlAddAuditAccessAceEx(*NewAcl
, ACL_REVISION
,
3366 pEntries
[i
].grfInheritance
,
3367 pEntries
[i
].grfAccessPermissions
,
3368 ppsid
[i
], TRUE
, FALSE
);
3370 case SET_AUDIT_FAILURE
:
3371 status
= RtlAddAuditAccessAceEx(*NewAcl
, ACL_REVISION
,
3372 pEntries
[i
].grfInheritance
,
3373 pEntries
[i
].grfAccessPermissions
,
3374 ppsid
[i
], FALSE
, TRUE
);
3377 FIXME("unhandled access mode %d\n", pEntries
[i
].grfAccessMode
);
3387 const ACE_HEADER
*old_ace_header
;
3388 status
= RtlGetAce(OldAcl
, i
, (LPVOID
*)&old_ace_header
);
3389 if (status
!= STATUS_SUCCESS
) break;
3390 for (j
= 0; j
< count
; j
++)
3392 if (pEntries
[j
].grfAccessMode
== SET_ACCESS
&&
3393 old_ace_header
->AceType
== ACCESS_ALLOWED_ACE_TYPE
&&
3394 EqualSid(ppsid
[j
], &((ACCESS_ALLOWED_ACE
*)old_ace_header
)->SidStart
))
3396 status
= RtlAddAccessAllowedAceEx(*NewAcl
, ACL_REVISION
, pEntries
[j
].grfInheritance
, pEntries
[j
].grfAccessPermissions
, ppsid
[j
]);
3400 else if (pEntries
[j
].grfAccessMode
== REVOKE_ACCESS
)
3402 switch (old_ace_header
->AceType
)
3404 case ACCESS_ALLOWED_ACE_TYPE
:
3405 if (EqualSid(ppsid
[j
], &((ACCESS_ALLOWED_ACE
*)old_ace_header
)->SidStart
))
3408 case ACCESS_DENIED_ACE_TYPE
:
3409 if (EqualSid(ppsid
[j
], &((ACCESS_DENIED_ACE
*)old_ace_header
)->SidStart
))
3412 case SYSTEM_AUDIT_ACE_TYPE
:
3413 if (EqualSid(ppsid
[j
], &((SYSTEM_AUDIT_ACE
*)old_ace_header
)->SidStart
))
3416 case SYSTEM_ALARM_ACE_TYPE
:
3417 if (EqualSid(ppsid
[j
], &((SYSTEM_ALARM_ACE
*)old_ace_header
)->SidStart
))
3421 FIXME("unhandled ace type %d\n", old_ace_header
->AceType
);
3429 status
= RtlAddAce(*NewAcl
, ACL_REVISION
, 1, (PACE_HEADER
)old_ace_header
, old_ace_header
->AceSize
);
3430 if (status
!= STATUS_SUCCESS
)
3432 WARN("RtlAddAce failed with error 0x%08x\n", status
);
3433 ret
= RtlNtStatusToDosError(status
);
3440 HeapFree(GetProcessHeap(), 0, ppsid
);
3444 /******************************************************************************
3445 * SetNamedSecurityInfoA [ADVAPI32.@]
3447 DWORD WINAPI
SetNamedSecurityInfoA(LPSTR pObjectName
,
3448 SE_OBJECT_TYPE ObjectType
, SECURITY_INFORMATION SecurityInfo
,
3449 PSID psidOwner
, PSID psidGroup
, PACL pDacl
, PACL pSacl
)
3455 TRACE("%s %d %d %p %p %p %p\n", debugstr_a(pObjectName
), ObjectType
,
3456 SecurityInfo
, psidOwner
, psidGroup
, pDacl
, pSacl
);
3460 len
= MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, NULL
, 0 );
3461 wstr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
3462 MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, wstr
, len
);
3465 r
= SetNamedSecurityInfoW( wstr
, ObjectType
, SecurityInfo
, psidOwner
,
3466 psidGroup
, pDacl
, pSacl
);
3468 HeapFree( GetProcessHeap(), 0, wstr
);
3473 BOOL WINAPI
SetPrivateObjectSecurity( SECURITY_INFORMATION SecurityInformation
,
3474 PSECURITY_DESCRIPTOR ModificationDescriptor
,
3475 PSECURITY_DESCRIPTOR
* ObjectsSecurityDescriptor
,
3476 PGENERIC_MAPPING GenericMapping
,
3479 FIXME("0x%08x %p %p %p %p - stub\n", SecurityInformation
, ModificationDescriptor
,
3480 ObjectsSecurityDescriptor
, GenericMapping
, Token
);
3485 BOOL WINAPI
AreAllAccessesGranted( DWORD GrantedAccess
, DWORD DesiredAccess
)
3487 return RtlAreAllAccessesGranted( GrantedAccess
, DesiredAccess
);
3490 /******************************************************************************
3491 * AreAnyAccessesGranted [ADVAPI32.@]
3493 * Determines whether or not any of a set of specified access permissions have
3494 * been granted or not.
3497 * GrantedAccess [I] The permissions that have been granted.
3498 * DesiredAccess [I] The permissions that you want to have.
3501 * Nonzero if any of the permissions have been granted, zero if none of the
3502 * permissions have been granted.
3505 BOOL WINAPI
AreAnyAccessesGranted( DWORD GrantedAccess
, DWORD DesiredAccess
)
3507 return RtlAreAnyAccessesGranted( GrantedAccess
, DesiredAccess
);
3510 /******************************************************************************
3511 * SetNamedSecurityInfoW [ADVAPI32.@]
3513 DWORD WINAPI
SetNamedSecurityInfoW(LPWSTR pObjectName
,
3514 SE_OBJECT_TYPE ObjectType
, SECURITY_INFORMATION SecurityInfo
,
3515 PSID psidOwner
, PSID psidGroup
, PACL pDacl
, PACL pSacl
)
3517 FIXME("%s %d %d %p %p %p %p\n", debugstr_w(pObjectName
), ObjectType
,
3518 SecurityInfo
, psidOwner
, psidGroup
, pDacl
, pSacl
);
3519 return ERROR_SUCCESS
;
3522 /******************************************************************************
3523 * GetExplicitEntriesFromAclA [ADVAPI32.@]
3525 DWORD WINAPI
GetExplicitEntriesFromAclA( PACL pacl
, PULONG pcCountOfExplicitEntries
,
3526 PEXPLICIT_ACCESSA
* pListOfExplicitEntries
)
3528 FIXME("%p %p %p\n",pacl
, pcCountOfExplicitEntries
, pListOfExplicitEntries
);
3529 return ERROR_CALL_NOT_IMPLEMENTED
;
3532 /******************************************************************************
3533 * GetExplicitEntriesFromAclW [ADVAPI32.@]
3535 DWORD WINAPI
GetExplicitEntriesFromAclW( PACL pacl
, PULONG pcCountOfExplicitEntries
,
3536 PEXPLICIT_ACCESSW
* pListOfExplicitEntries
)
3538 FIXME("%p %p %p\n",pacl
, pcCountOfExplicitEntries
, pListOfExplicitEntries
);
3539 return ERROR_CALL_NOT_IMPLEMENTED
;
3542 /******************************************************************************
3543 * GetAuditedPermissionsFromAclA [ADVAPI32.@]
3545 DWORD WINAPI
GetAuditedPermissionsFromAclA( PACL pacl
, PTRUSTEEA pTrustee
, PACCESS_MASK pSuccessfulAuditedRights
,
3546 PACCESS_MASK pFailedAuditRights
)
3548 FIXME("%p %p %p %p\n",pacl
, pTrustee
, pSuccessfulAuditedRights
, pFailedAuditRights
);
3549 return ERROR_CALL_NOT_IMPLEMENTED
;
3553 /******************************************************************************
3554 * GetAuditedPermissionsFromAclW [ADVAPI32.@]
3556 DWORD WINAPI
GetAuditedPermissionsFromAclW( PACL pacl
, PTRUSTEEW pTrustee
, PACCESS_MASK pSuccessfulAuditedRights
,
3557 PACCESS_MASK pFailedAuditRights
)
3559 FIXME("%p %p %p %p\n",pacl
, pTrustee
, pSuccessfulAuditedRights
, pFailedAuditRights
);
3560 return ERROR_CALL_NOT_IMPLEMENTED
;
3564 /******************************************************************************
3565 * ParseAclStringFlags
3567 static DWORD
ParseAclStringFlags(LPCWSTR
* StringAcl
)
3570 LPCWSTR szAcl
= *StringAcl
;
3572 while (*szAcl
!= '(')
3576 flags
|= SE_DACL_PROTECTED
;
3578 else if (*szAcl
== 'A')
3582 flags
|= SE_DACL_AUTO_INHERIT_REQ
;
3583 else if (*szAcl
== 'I')
3584 flags
|= SE_DACL_AUTO_INHERITED
;
3593 /******************************************************************************
3594 * ParseAceStringType
3596 static const ACEFLAG AceType
[] =
3598 { SDDL_ALARM
, SYSTEM_ALARM_ACE_TYPE
},
3599 { SDDL_AUDIT
, SYSTEM_AUDIT_ACE_TYPE
},
3600 { SDDL_ACCESS_ALLOWED
, ACCESS_ALLOWED_ACE_TYPE
},
3601 { SDDL_ACCESS_DENIED
, ACCESS_DENIED_ACE_TYPE
},
3603 { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
3604 { SDDL_OBJECT_ACCESS_DENIED, ACCESS_DENIED_OBJECT_ACE_TYPE },
3605 { SDDL_OBJECT_ALARM, SYSTEM_ALARM_OBJECT_ACE_TYPE },
3606 { SDDL_OBJECT_AUDIT, SYSTEM_AUDIT_OBJECT_ACE_TYPE },
3611 static BYTE
ParseAceStringType(LPCWSTR
* StringAcl
)
3614 LPCWSTR szAcl
= *StringAcl
;
3615 const ACEFLAG
*lpaf
= AceType
;
3617 while (lpaf
->wstr
&&
3618 (len
= strlenW(lpaf
->wstr
)) &&
3619 strncmpW(lpaf
->wstr
, szAcl
, len
))
3630 /******************************************************************************
3631 * ParseAceStringFlags
3633 static const ACEFLAG AceFlags
[] =
3635 { SDDL_CONTAINER_INHERIT
, CONTAINER_INHERIT_ACE
},
3636 { SDDL_AUDIT_FAILURE
, FAILED_ACCESS_ACE_FLAG
},
3637 { SDDL_INHERITED
, INHERITED_ACE
},
3638 { SDDL_INHERIT_ONLY
, INHERIT_ONLY_ACE
},
3639 { SDDL_NO_PROPAGATE
, NO_PROPAGATE_INHERIT_ACE
},
3640 { SDDL_OBJECT_INHERIT
, OBJECT_INHERIT_ACE
},
3641 { SDDL_AUDIT_SUCCESS
, SUCCESSFUL_ACCESS_ACE_FLAG
},
3645 static BYTE
ParseAceStringFlags(LPCWSTR
* StringAcl
)
3649 LPCWSTR szAcl
= *StringAcl
;
3651 while (*szAcl
!= ';')
3653 const ACEFLAG
*lpaf
= AceFlags
;
3655 while (lpaf
->wstr
&&
3656 (len
= strlenW(lpaf
->wstr
)) &&
3657 strncmpW(lpaf
->wstr
, szAcl
, len
))
3663 flags
|= lpaf
->value
;
3672 /******************************************************************************
3673 * ParseAceStringRights
3675 static const ACEFLAG AceRights
[] =
3677 { SDDL_GENERIC_ALL
, GENERIC_ALL
},
3678 { SDDL_GENERIC_READ
, GENERIC_READ
},
3679 { SDDL_GENERIC_WRITE
, GENERIC_WRITE
},
3680 { SDDL_GENERIC_EXECUTE
, GENERIC_EXECUTE
},
3682 { SDDL_READ_CONTROL
, READ_CONTROL
},
3683 { SDDL_STANDARD_DELETE
, DELETE
},
3684 { SDDL_WRITE_DAC
, WRITE_DAC
},
3685 { SDDL_WRITE_OWNER
, WRITE_OWNER
},
3687 { SDDL_READ_PROPERTY
, ADS_RIGHT_DS_READ_PROP
},
3688 { SDDL_WRITE_PROPERTY
, ADS_RIGHT_DS_WRITE_PROP
},
3689 { SDDL_CREATE_CHILD
, ADS_RIGHT_DS_CREATE_CHILD
},
3690 { SDDL_DELETE_CHILD
, ADS_RIGHT_DS_DELETE_CHILD
},
3691 { SDDL_LIST_CHILDREN
, ADS_RIGHT_ACTRL_DS_LIST
},
3692 { SDDL_SELF_WRITE
, ADS_RIGHT_DS_SELF
},
3693 { SDDL_LIST_OBJECT
, ADS_RIGHT_DS_LIST_OBJECT
},
3694 { SDDL_DELETE_TREE
, ADS_RIGHT_DS_DELETE_TREE
},
3695 { SDDL_CONTROL_ACCESS
, ADS_RIGHT_DS_CONTROL_ACCESS
},
3697 { SDDL_FILE_ALL
, FILE_ALL_ACCESS
},
3698 { SDDL_FILE_READ
, FILE_GENERIC_READ
},
3699 { SDDL_FILE_WRITE
, FILE_GENERIC_WRITE
},
3700 { SDDL_FILE_EXECUTE
, FILE_GENERIC_EXECUTE
},
3702 { SDDL_KEY_ALL
, KEY_ALL_ACCESS
},
3703 { SDDL_KEY_READ
, KEY_READ
},
3704 { SDDL_KEY_WRITE
, KEY_WRITE
},
3705 { SDDL_KEY_EXECUTE
, KEY_EXECUTE
},
3709 static DWORD
ParseAceStringRights(LPCWSTR
* StringAcl
)
3713 LPCWSTR szAcl
= *StringAcl
;
3715 if ((*szAcl
== '0') && (*(szAcl
+ 1) == 'x'))
3719 while (*p
&& *p
!= ';')
3722 if (p
- szAcl
<= 10 /* 8 hex digits + "0x" */ )
3724 rights
= strtoulW(szAcl
, NULL
, 16);
3728 WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl
, p
- szAcl
));
3732 while (*szAcl
!= ';')
3734 const ACEFLAG
*lpaf
= AceRights
;
3736 while (lpaf
->wstr
&&
3737 (len
= strlenW(lpaf
->wstr
)) &&
3738 strncmpW(lpaf
->wstr
, szAcl
, len
))
3746 rights
|= lpaf
->value
;
3756 /******************************************************************************
3757 * ParseStringAclToAcl
3759 * dacl_flags(string_ace1)(string_ace2)... (string_acen)
3761 static BOOL
ParseStringAclToAcl(LPCWSTR StringAcl
, LPDWORD lpdwFlags
,
3762 PACL pAcl
, LPDWORD cBytes
)
3766 DWORD length
= sizeof(ACL
);
3769 PACCESS_ALLOWED_ACE pAce
= NULL
; /* pointer to current ACE */
3771 TRACE("%s\n", debugstr_w(StringAcl
));
3776 if (pAcl
) /* pAce is only useful if we're setting values */
3777 pAce
= (PACCESS_ALLOWED_ACE
) (pAcl
+ 1);
3779 /* Parse ACL flags */
3780 *lpdwFlags
= ParseAclStringFlags(&StringAcl
);
3783 while (*StringAcl
== '(')
3787 /* Parse ACE type */
3788 val
= ParseAceStringType(&StringAcl
);
3790 pAce
->Header
.AceType
= (BYTE
) val
;
3791 if (*StringAcl
!= ';')
3795 /* Parse ACE flags */
3796 val
= ParseAceStringFlags(&StringAcl
);
3798 pAce
->Header
.AceFlags
= (BYTE
) val
;
3799 if (*StringAcl
!= ';')
3803 /* Parse ACE rights */
3804 val
= ParseAceStringRights(&StringAcl
);
3807 if (*StringAcl
!= ';')
3811 /* Parse ACE object guid */
3812 if (*StringAcl
!= ';')
3814 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3819 /* Parse ACE inherit object guid */
3820 if (*StringAcl
!= ';')
3822 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3827 /* Parse ACE account sid */
3828 if (ParseStringSidToSid(StringAcl
, pAce
? (PSID
)&pAce
->SidStart
: NULL
, &sidlen
))
3830 while (*StringAcl
&& *StringAcl
!= ')')
3834 if (*StringAcl
!= ')')
3838 acesize
= sizeof(ACCESS_ALLOWED_ACE
) - sizeof(DWORD
) + sidlen
;
3842 pAce
->Header
.AceSize
= acesize
;
3843 pAce
= (PACCESS_ALLOWED_ACE
)((LPBYTE
)pAce
+ acesize
);
3850 if (length
> 0xffff)
3852 ERR("ACL too large\n");
3858 pAcl
->AclRevision
= ACL_REVISION
;
3860 pAcl
->AclSize
= length
;
3861 pAcl
->AceCount
= acecount
++;
3867 SetLastError(ERROR_INVALID_ACL
);
3868 WARN("Invalid ACE string format\n");
3873 /******************************************************************************
3874 * ParseStringSecurityDescriptorToSecurityDescriptor
3876 static BOOL
ParseStringSecurityDescriptorToSecurityDescriptor(
3877 LPCWSTR StringSecurityDescriptor
,
3878 SECURITY_DESCRIPTOR
* SecurityDescriptor
,
3883 WCHAR tok
[MAX_PATH
];
3885 LPBYTE lpNext
= NULL
;
3888 *cBytes
= sizeof(SECURITY_DESCRIPTOR
);
3890 if (SecurityDescriptor
)
3891 lpNext
= ((LPBYTE
) SecurityDescriptor
) + sizeof(SECURITY_DESCRIPTOR
);
3893 while (*StringSecurityDescriptor
)
3895 toktype
= *StringSecurityDescriptor
;
3897 /* Expect char identifier followed by ':' */
3898 StringSecurityDescriptor
++;
3899 if (*StringSecurityDescriptor
!= ':')
3901 SetLastError(ERROR_INVALID_PARAMETER
);
3904 StringSecurityDescriptor
++;
3907 lptoken
= StringSecurityDescriptor
;
3908 while (*lptoken
&& *lptoken
!= ':')
3914 len
= lptoken
- StringSecurityDescriptor
;
3915 memcpy( tok
, StringSecurityDescriptor
, len
* sizeof(WCHAR
) );
3924 if (!ParseStringSidToSid(tok
, (PSID
)lpNext
, &bytes
))
3927 if (SecurityDescriptor
)
3929 SecurityDescriptor
->Owner
= (PSID
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3930 lpNext
+= bytes
; /* Advance to next token */
3942 if (!ParseStringSidToSid(tok
, (PSID
)lpNext
, &bytes
))
3945 if (SecurityDescriptor
)
3947 SecurityDescriptor
->Group
= (PSID
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3948 lpNext
+= bytes
; /* Advance to next token */
3961 if (!ParseStringAclToAcl(tok
, &flags
, (PACL
)lpNext
, &bytes
))
3964 if (SecurityDescriptor
)
3966 SecurityDescriptor
->Control
|= SE_DACL_PRESENT
| flags
;
3967 SecurityDescriptor
->Dacl
= (PACL
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3968 lpNext
+= bytes
; /* Advance to next token */
3981 if (!ParseStringAclToAcl(tok
, &flags
, (PACL
)lpNext
, &bytes
))
3984 if (SecurityDescriptor
)
3986 SecurityDescriptor
->Control
|= SE_SACL_PRESENT
| flags
;
3987 SecurityDescriptor
->Sacl
= (PACL
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3988 lpNext
+= bytes
; /* Advance to next token */
3997 FIXME("Unknown token\n");
3998 SetLastError(ERROR_INVALID_PARAMETER
);
4002 StringSecurityDescriptor
= lptoken
;
4011 /******************************************************************************
4012 * ConvertStringSecurityDescriptorToSecurityDescriptorA [ADVAPI32.@]
4014 BOOL WINAPI
ConvertStringSecurityDescriptorToSecurityDescriptorA(
4015 LPCSTR StringSecurityDescriptor
,
4016 DWORD StringSDRevision
,
4017 PSECURITY_DESCRIPTOR
* SecurityDescriptor
,
4018 PULONG SecurityDescriptorSize
)
4022 LPWSTR StringSecurityDescriptorW
;
4024 len
= MultiByteToWideChar(CP_ACP
, 0, StringSecurityDescriptor
, -1, NULL
, 0);
4025 StringSecurityDescriptorW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
4027 if (StringSecurityDescriptorW
)
4029 MultiByteToWideChar(CP_ACP
, 0, StringSecurityDescriptor
, -1, StringSecurityDescriptorW
, len
);
4031 ret
= ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptorW
,
4032 StringSDRevision
, SecurityDescriptor
,
4033 SecurityDescriptorSize
);
4034 HeapFree(GetProcessHeap(), 0, StringSecurityDescriptorW
);
4040 /******************************************************************************
4041 * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
4043 BOOL WINAPI
ConvertStringSecurityDescriptorToSecurityDescriptorW(
4044 LPCWSTR StringSecurityDescriptor
,
4045 DWORD StringSDRevision
,
4046 PSECURITY_DESCRIPTOR
* SecurityDescriptor
,
4047 PULONG SecurityDescriptorSize
)
4050 SECURITY_DESCRIPTOR
* psd
;
4053 TRACE("%s\n", debugstr_w(StringSecurityDescriptor
));
4055 if (GetVersion() & 0x80000000)
4057 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4060 else if (!StringSecurityDescriptor
|| !SecurityDescriptor
)
4062 SetLastError(ERROR_INVALID_PARAMETER
);
4065 else if (StringSDRevision
!= SID_REVISION
)
4067 SetLastError(ERROR_UNKNOWN_REVISION
);
4071 /* Compute security descriptor length */
4072 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor
,
4076 psd
= *SecurityDescriptor
= (SECURITY_DESCRIPTOR
*) LocalAlloc(
4077 GMEM_ZEROINIT
, cBytes
);
4078 if (!psd
) goto lend
;
4080 psd
->Revision
= SID_REVISION
;
4081 psd
->Control
|= SE_SELF_RELATIVE
;
4083 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor
,
4090 if (SecurityDescriptorSize
)
4091 *SecurityDescriptorSize
= cBytes
;
4096 TRACE(" ret=%d\n", bret
);
4100 static void DumpString(LPCWSTR string
, int cch
, WCHAR
**pwptr
, ULONG
*plen
)
4103 cch
= strlenW(string
);
4110 memcpy(*pwptr
, string
, sizeof(WCHAR
)*cch
);
4115 static BOOL
DumpSidNumeric(PSID psid
, WCHAR
**pwptr
, ULONG
*plen
)
4118 WCHAR fmt
[] = { 'S','-','%','u','-','%','d',0 };
4119 WCHAR subauthfmt
[] = { '-','%','u',0 };
4123 if( !IsValidSid( psid
) || pisid
->Revision
!= SDDL_REVISION
)
4125 SetLastError(ERROR_INVALID_SID
);
4129 if (pisid
->IdentifierAuthority
.Value
[0] ||
4130 pisid
->IdentifierAuthority
.Value
[1])
4132 FIXME("not matching MS' bugs\n");
4133 SetLastError(ERROR_INVALID_SID
);
4137 sprintfW( buf
, fmt
, pisid
->Revision
,
4139 MAKEWORD( pisid
->IdentifierAuthority
.Value
[5],
4140 pisid
->IdentifierAuthority
.Value
[4] ),
4141 MAKEWORD( pisid
->IdentifierAuthority
.Value
[3],
4142 pisid
->IdentifierAuthority
.Value
[2] )
4144 DumpString(buf
, -1, pwptr
, plen
);
4146 for( i
=0; i
<pisid
->SubAuthorityCount
; i
++ )
4148 sprintfW( buf
, subauthfmt
, pisid
->SubAuthority
[i
] );
4149 DumpString(buf
, -1, pwptr
, plen
);
4154 static BOOL
DumpSid(PSID psid
, WCHAR
**pwptr
, ULONG
*plen
)
4157 for (i
= 0; i
< sizeof(WellKnownSids
) / sizeof(WellKnownSids
[0]); i
++)
4159 if (WellKnownSids
[i
].wstr
[0] && EqualSid(psid
, (PSID
)&(WellKnownSids
[i
].Sid
.Revision
)))
4161 DumpString(WellKnownSids
[i
].wstr
, 2, pwptr
, plen
);
4166 return DumpSidNumeric(psid
, pwptr
, plen
);
4169 static const LPCWSTR AceRightBitNames
[32] = {
4170 SDDL_CREATE_CHILD
, /* 0 */
4174 SDDL_READ_PROPERTY
, /* 4 */
4175 SDDL_WRITE_PROPERTY
,
4178 SDDL_CONTROL_ACCESS
, /* 8 */
4186 SDDL_STANDARD_DELETE
, /* 16 */
4198 SDDL_GENERIC_ALL
, /* 28 */
4199 SDDL_GENERIC_EXECUTE
,
4204 static void DumpRights(DWORD mask
, WCHAR
**pwptr
, ULONG
*plen
)
4206 static const WCHAR fmtW
[] = {'0','x','%','x',0};
4213 /* first check if the right have name */
4214 for (i
= 0; i
< sizeof(AceRights
)/sizeof(AceRights
[0]); i
++)
4216 if (AceRights
[i
].wstr
== NULL
)
4218 if (mask
== AceRights
[i
].value
)
4220 DumpString(AceRights
[i
].wstr
, -1, pwptr
, plen
);
4225 /* then check if it can be built from bit names */
4226 for (i
= 0; i
< 32; i
++)
4228 if ((mask
& (1 << i
)) && (AceRightBitNames
[i
] == NULL
))
4230 /* can't be built from bit names */
4231 sprintfW(buf
, fmtW
, mask
);
4232 DumpString(buf
, -1, pwptr
, plen
);
4237 /* build from bit names */
4238 for (i
= 0; i
< 32; i
++)
4239 if (mask
& (1 << i
))
4240 DumpString(AceRightBitNames
[i
], -1, pwptr
, plen
);
4243 static BOOL
DumpAce(LPVOID pace
, WCHAR
**pwptr
, ULONG
*plen
)
4245 ACCESS_ALLOWED_ACE
*piace
; /* all the supported ACEs have the same memory layout */
4246 static const WCHAR openbr
= '(';
4247 static const WCHAR closebr
= ')';
4248 static const WCHAR semicolon
= ';';
4250 if (((PACE_HEADER
)pace
)->AceType
> SYSTEM_ALARM_ACE_TYPE
|| ((PACE_HEADER
)pace
)->AceSize
< sizeof(ACCESS_ALLOWED_ACE
))
4252 SetLastError(ERROR_INVALID_ACL
);
4256 piace
= (ACCESS_ALLOWED_ACE
*)pace
;
4257 DumpString(&openbr
, 1, pwptr
, plen
);
4258 switch (piace
->Header
.AceType
)
4260 case ACCESS_ALLOWED_ACE_TYPE
:
4261 DumpString(SDDL_ACCESS_ALLOWED
, -1, pwptr
, plen
);
4263 case ACCESS_DENIED_ACE_TYPE
:
4264 DumpString(SDDL_ACCESS_DENIED
, -1, pwptr
, plen
);
4266 case SYSTEM_AUDIT_ACE_TYPE
:
4267 DumpString(SDDL_AUDIT
, -1, pwptr
, plen
);
4269 case SYSTEM_ALARM_ACE_TYPE
:
4270 DumpString(SDDL_ALARM
, -1, pwptr
, plen
);
4273 DumpString(&semicolon
, 1, pwptr
, plen
);
4275 if (piace
->Header
.AceFlags
& OBJECT_INHERIT_ACE
)
4276 DumpString(SDDL_OBJECT_INHERIT
, -1, pwptr
, plen
);
4277 if (piace
->Header
.AceFlags
& CONTAINER_INHERIT_ACE
)
4278 DumpString(SDDL_CONTAINER_INHERIT
, -1, pwptr
, plen
);
4279 if (piace
->Header
.AceFlags
& NO_PROPAGATE_INHERIT_ACE
)
4280 DumpString(SDDL_NO_PROPAGATE
, -1, pwptr
, plen
);
4281 if (piace
->Header
.AceFlags
& INHERIT_ONLY_ACE
)
4282 DumpString(SDDL_INHERIT_ONLY
, -1, pwptr
, plen
);
4283 if (piace
->Header
.AceFlags
& INHERITED_ACE
)
4284 DumpString(SDDL_INHERITED
, -1, pwptr
, plen
);
4285 if (piace
->Header
.AceFlags
& SUCCESSFUL_ACCESS_ACE_FLAG
)
4286 DumpString(SDDL_AUDIT_SUCCESS
, -1, pwptr
, plen
);
4287 if (piace
->Header
.AceFlags
& FAILED_ACCESS_ACE_FLAG
)
4288 DumpString(SDDL_AUDIT_FAILURE
, -1, pwptr
, plen
);
4289 DumpString(&semicolon
, 1, pwptr
, plen
);
4290 DumpRights(piace
->Mask
, pwptr
, plen
);
4291 DumpString(&semicolon
, 1, pwptr
, plen
);
4292 /* objects not supported */
4293 DumpString(&semicolon
, 1, pwptr
, plen
);
4294 /* objects not supported */
4295 DumpString(&semicolon
, 1, pwptr
, plen
);
4296 if (!DumpSid((PSID
)&piace
->SidStart
, pwptr
, plen
))
4298 DumpString(&closebr
, 1, pwptr
, plen
);
4302 static BOOL
DumpAcl(PACL pacl
, WCHAR
**pwptr
, ULONG
*plen
, BOOL
protected, BOOL autoInheritReq
, BOOL autoInherited
)
4308 DumpString(SDDL_PROTECTED
, -1, pwptr
, plen
);
4310 DumpString(SDDL_AUTO_INHERIT_REQ
, -1, pwptr
, plen
);
4312 DumpString(SDDL_AUTO_INHERITED
, -1, pwptr
, plen
);
4317 if (!IsValidAcl(pacl
))
4320 count
= pacl
->AceCount
;
4321 for (i
= 0; i
< count
; i
++)
4324 if (!GetAce(pacl
, i
, &ace
))
4326 if (!DumpAce(ace
, pwptr
, plen
))
4333 static BOOL
DumpOwner(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
4335 static const WCHAR prefix
[] = {'O',':',0};
4339 if (!GetSecurityDescriptorOwner(SecurityDescriptor
, &psid
, &bDefaulted
))
4345 DumpString(prefix
, -1, pwptr
, plen
);
4346 if (!DumpSid(psid
, pwptr
, plen
))
4351 static BOOL
DumpGroup(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
4353 static const WCHAR prefix
[] = {'G',':',0};
4357 if (!GetSecurityDescriptorGroup(SecurityDescriptor
, &psid
, &bDefaulted
))
4363 DumpString(prefix
, -1, pwptr
, plen
);
4364 if (!DumpSid(psid
, pwptr
, plen
))
4369 static BOOL
DumpDacl(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
4371 static const WCHAR dacl
[] = {'D',':',0};
4372 SECURITY_DESCRIPTOR_CONTROL control
;
4373 BOOL present
, defaulted
;
4377 if (!GetSecurityDescriptorDacl(SecurityDescriptor
, &present
, &pacl
, &defaulted
))
4380 if (!GetSecurityDescriptorControl(SecurityDescriptor
, &control
, &revision
))
4386 DumpString(dacl
, 2, pwptr
, plen
);
4387 if (!DumpAcl(pacl
, pwptr
, plen
, control
& SE_DACL_PROTECTED
, control
& SE_DACL_AUTO_INHERIT_REQ
, control
& SE_DACL_AUTO_INHERITED
))
4392 static BOOL
DumpSacl(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
4394 static const WCHAR sacl
[] = {'S',':',0};
4395 SECURITY_DESCRIPTOR_CONTROL control
;
4396 BOOL present
, defaulted
;
4400 if (!GetSecurityDescriptorSacl(SecurityDescriptor
, &present
, &pacl
, &defaulted
))
4403 if (!GetSecurityDescriptorControl(SecurityDescriptor
, &control
, &revision
))
4409 DumpString(sacl
, 2, pwptr
, plen
);
4410 if (!DumpAcl(pacl
, pwptr
, plen
, control
& SE_SACL_PROTECTED
, control
& SE_SACL_AUTO_INHERIT_REQ
, control
& SE_SACL_AUTO_INHERITED
))
4415 /******************************************************************************
4416 * ConvertSecurityDescriptorToStringSecurityDescriptorA [ADVAPI32.@]
4418 BOOL WINAPI
ConvertSecurityDescriptorToStringSecurityDescriptorW(PSECURITY_DESCRIPTOR SecurityDescriptor
, DWORD SDRevision
, SECURITY_INFORMATION RequestedInformation
, LPWSTR
*OutputString
, PULONG OutputLen
)
4423 if (SDRevision
!= SDDL_REVISION_1
)
4425 ERR("Pogram requested unknown SDDL revision %d\n", SDRevision
);
4426 SetLastError(ERROR_UNKNOWN_REVISION
);
4431 if (RequestedInformation
& OWNER_SECURITY_INFORMATION
)
4432 if (!DumpOwner(SecurityDescriptor
, NULL
, &len
))
4434 if (RequestedInformation
& GROUP_SECURITY_INFORMATION
)
4435 if (!DumpGroup(SecurityDescriptor
, NULL
, &len
))
4437 if (RequestedInformation
& DACL_SECURITY_INFORMATION
)
4438 if (!DumpDacl(SecurityDescriptor
, NULL
, &len
))
4440 if (RequestedInformation
& SACL_SECURITY_INFORMATION
)
4441 if (!DumpSacl(SecurityDescriptor
, NULL
, &len
))
4444 wstr
= wptr
= LocalAlloc(0, (len
+ 1)*sizeof(WCHAR
));
4445 if (RequestedInformation
& OWNER_SECURITY_INFORMATION
)
4446 if (!DumpOwner(SecurityDescriptor
, &wptr
, NULL
))
4448 if (RequestedInformation
& GROUP_SECURITY_INFORMATION
)
4449 if (!DumpGroup(SecurityDescriptor
, &wptr
, NULL
))
4451 if (RequestedInformation
& DACL_SECURITY_INFORMATION
)
4452 if (!DumpDacl(SecurityDescriptor
, &wptr
, NULL
))
4454 if (RequestedInformation
& SACL_SECURITY_INFORMATION
)
4455 if (!DumpSacl(SecurityDescriptor
, &wptr
, NULL
))
4459 TRACE("ret: %s, %d\n", wine_dbgstr_w(wstr
), len
);
4460 *OutputString
= wstr
;
4462 *OutputLen
= strlenW(*OutputString
)+1;
4466 /******************************************************************************
4467 * ConvertSecurityDescriptorToStringSecurityDescriptorA [ADVAPI32.@]
4469 BOOL WINAPI
ConvertSecurityDescriptorToStringSecurityDescriptorA(PSECURITY_DESCRIPTOR SecurityDescriptor
, DWORD SDRevision
, SECURITY_INFORMATION Information
, LPSTR
*OutputString
, PULONG OutputLen
)
4473 if (ConvertSecurityDescriptorToStringSecurityDescriptorW(SecurityDescriptor
, SDRevision
, Information
, &wstr
, &len
))
4477 lenA
= WideCharToMultiByte(CP_ACP
, 0, wstr
, len
, NULL
, 0, NULL
, NULL
);
4478 *OutputString
= HeapAlloc(GetProcessHeap(), 0, lenA
);
4479 WideCharToMultiByte(CP_ACP
, 0, wstr
, len
, *OutputString
, lenA
, NULL
, NULL
);
4482 if (OutputLen
!= NULL
)
4488 *OutputString
= NULL
;
4495 /******************************************************************************
4496 * ConvertStringSidToSidW [ADVAPI32.@]
4498 BOOL WINAPI
ConvertStringSidToSidW(LPCWSTR StringSid
, PSID
* Sid
)
4503 TRACE("%s, %p\n", debugstr_w(StringSid
), Sid
);
4504 if (GetVersion() & 0x80000000)
4505 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4506 else if (!StringSid
|| !Sid
)
4507 SetLastError(ERROR_INVALID_PARAMETER
);
4508 else if (ParseStringSidToSid(StringSid
, NULL
, &cBytes
))
4510 PSID pSid
= *Sid
= LocalAlloc(0, cBytes
);
4512 bret
= ParseStringSidToSid(StringSid
, pSid
, &cBytes
);
4519 /******************************************************************************
4520 * ConvertStringSidToSidA [ADVAPI32.@]
4522 BOOL WINAPI
ConvertStringSidToSidA(LPCSTR StringSid
, PSID
* Sid
)
4526 TRACE("%s, %p\n", debugstr_a(StringSid
), Sid
);
4527 if (GetVersion() & 0x80000000)
4528 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4529 else if (!StringSid
|| !Sid
)
4530 SetLastError(ERROR_INVALID_PARAMETER
);
4533 UINT len
= MultiByteToWideChar(CP_ACP
, 0, StringSid
, -1, NULL
, 0);
4534 LPWSTR wStringSid
= HeapAlloc(GetProcessHeap(), 0,
4535 len
* sizeof(WCHAR
));
4537 MultiByteToWideChar(CP_ACP
, 0, StringSid
, -1, wStringSid
, len
);
4538 bret
= ConvertStringSidToSidW(wStringSid
, Sid
);
4539 HeapFree(GetProcessHeap(), 0, wStringSid
);
4544 /******************************************************************************
4545 * ConvertSidToStringSidW [ADVAPI32.@]
4547 * format of SID string is:
4548 * S-<count>-<auth>-<subauth1>-<subauth2>-<subauth3>...
4550 * <rev> is the revision of the SID encoded as decimal
4551 * <auth> is the identifier authority encoded as hex
4552 * <subauthN> is the subauthority id encoded as decimal
4554 BOOL WINAPI
ConvertSidToStringSidW( PSID pSid
, LPWSTR
*pstr
)
4559 TRACE("%p %p\n", pSid
, pstr
);
4562 if (!DumpSidNumeric(pSid
, NULL
, &len
))
4564 wstr
= wptr
= LocalAlloc(0, (len
+1) * sizeof(WCHAR
));
4565 DumpSidNumeric(pSid
, &wptr
, NULL
);
4572 /******************************************************************************
4573 * ConvertSidToStringSidA [ADVAPI32.@]
4575 BOOL WINAPI
ConvertSidToStringSidA(PSID pSid
, LPSTR
*pstr
)
4581 TRACE("%p %p\n", pSid
, pstr
);
4583 if( !ConvertSidToStringSidW( pSid
, &wstr
) )
4586 len
= WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
4587 str
= LocalAlloc( 0, len
);
4588 WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, str
, len
, NULL
, NULL
);
4596 BOOL WINAPI
ConvertToAutoInheritPrivateObjectSecurity(
4597 PSECURITY_DESCRIPTOR pdesc
,
4598 PSECURITY_DESCRIPTOR cdesc
,
4599 PSECURITY_DESCRIPTOR
* ndesc
,
4602 PGENERIC_MAPPING genmap
)
4604 FIXME("%p %p %p %p %d %p - stub\n", pdesc
, cdesc
, ndesc
, objtype
, isdir
, genmap
);
4609 BOOL WINAPI
CreatePrivateObjectSecurity(
4610 PSECURITY_DESCRIPTOR ParentDescriptor
,
4611 PSECURITY_DESCRIPTOR CreatorDescriptor
,
4612 PSECURITY_DESCRIPTOR
* NewDescriptor
,
4613 BOOL IsDirectoryObject
,
4615 PGENERIC_MAPPING GenericMapping
)
4617 FIXME("%p %p %p %d %p %p - stub\n", ParentDescriptor
, CreatorDescriptor
,
4618 NewDescriptor
, IsDirectoryObject
, Token
, GenericMapping
);
4623 BOOL WINAPI
DestroyPrivateObjectSecurity( PSECURITY_DESCRIPTOR
* ObjectDescriptor
)
4625 FIXME("%p - stub\n", ObjectDescriptor
);
4630 BOOL WINAPI
CreateProcessAsUserA(
4632 LPCSTR lpApplicationName
,
4633 LPSTR lpCommandLine
,
4634 LPSECURITY_ATTRIBUTES lpProcessAttributes
,
4635 LPSECURITY_ATTRIBUTES lpThreadAttributes
,
4636 BOOL bInheritHandles
,
4637 DWORD dwCreationFlags
,
4638 LPVOID lpEnvironment
,
4639 LPCSTR lpCurrentDirectory
,
4640 LPSTARTUPINFOA lpStartupInfo
,
4641 LPPROCESS_INFORMATION lpProcessInformation
)
4643 FIXME("%p %s %s %p %p %d 0x%08x %p %s %p %p - stub\n", hToken
, debugstr_a(lpApplicationName
),
4644 debugstr_a(lpCommandLine
), lpProcessAttributes
, lpThreadAttributes
, bInheritHandles
,
4645 dwCreationFlags
, lpEnvironment
, debugstr_a(lpCurrentDirectory
), lpStartupInfo
, lpProcessInformation
);
4650 BOOL WINAPI
CreateProcessAsUserW(
4652 LPCWSTR lpApplicationName
,
4653 LPWSTR lpCommandLine
,
4654 LPSECURITY_ATTRIBUTES lpProcessAttributes
,
4655 LPSECURITY_ATTRIBUTES lpThreadAttributes
,
4656 BOOL bInheritHandles
,
4657 DWORD dwCreationFlags
,
4658 LPVOID lpEnvironment
,
4659 LPCWSTR lpCurrentDirectory
,
4660 LPSTARTUPINFOW lpStartupInfo
,
4661 LPPROCESS_INFORMATION lpProcessInformation
)
4663 FIXME("%p %s %s %p %p %d 0x%08x %p %s %p %p - semi- stub\n", hToken
,
4664 debugstr_w(lpApplicationName
), debugstr_w(lpCommandLine
), lpProcessAttributes
,
4665 lpThreadAttributes
, bInheritHandles
, dwCreationFlags
, lpEnvironment
,
4666 debugstr_w(lpCurrentDirectory
), lpStartupInfo
, lpProcessInformation
);
4668 /* We should create the process with a suspended main thread */
4669 if (!CreateProcessW (lpApplicationName
,
4671 lpProcessAttributes
,
4674 dwCreationFlags
, /* CREATE_SUSPENDED */
4678 lpProcessInformation
))
4686 /******************************************************************************
4687 * CreateProcessWithLogonW
4689 BOOL WINAPI
CreateProcessWithLogonW( LPCWSTR lpUsername
, LPCWSTR lpDomain
, LPCWSTR lpPassword
, DWORD dwLogonFlags
,
4690 LPCWSTR lpApplicationName
, LPWSTR lpCommandLine
, DWORD dwCreationFlags
, LPVOID lpEnvironment
,
4691 LPCWSTR lpCurrentDirectory
, LPSTARTUPINFOW lpStartupInfo
, LPPROCESS_INFORMATION lpProcessInformation
)
4693 FIXME("%s %s %s 0x%08x %s %s 0x%08x %p %s %p %p stub\n", debugstr_w(lpUsername
), debugstr_w(lpDomain
),
4694 debugstr_w(lpPassword
), dwLogonFlags
, debugstr_w(lpApplicationName
),
4695 debugstr_w(lpCommandLine
), dwCreationFlags
, lpEnvironment
, debugstr_w(lpCurrentDirectory
),
4696 lpStartupInfo
, lpProcessInformation
);
4701 /******************************************************************************
4702 * DuplicateTokenEx [ADVAPI32.@]
4704 BOOL WINAPI
DuplicateTokenEx(
4705 HANDLE ExistingTokenHandle
, DWORD dwDesiredAccess
,
4706 LPSECURITY_ATTRIBUTES lpTokenAttributes
,
4707 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
4708 TOKEN_TYPE TokenType
,
4709 PHANDLE DuplicateTokenHandle
)
4711 OBJECT_ATTRIBUTES ObjectAttributes
;
4713 TRACE("%p 0x%08x 0x%08x 0x%08x %p\n", ExistingTokenHandle
, dwDesiredAccess
,
4714 ImpersonationLevel
, TokenType
, DuplicateTokenHandle
);
4716 InitializeObjectAttributes(
4719 (lpTokenAttributes
&& lpTokenAttributes
->bInheritHandle
) ? OBJ_INHERIT
: 0,
4721 lpTokenAttributes
? lpTokenAttributes
->lpSecurityDescriptor
: NULL
);
4723 return set_ntstatus( NtDuplicateToken( ExistingTokenHandle
,
4728 DuplicateTokenHandle
) );
4731 BOOL WINAPI
DuplicateToken(
4732 HANDLE ExistingTokenHandle
,
4733 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
4734 PHANDLE DuplicateTokenHandle
)
4736 return DuplicateTokenEx( ExistingTokenHandle
, TOKEN_IMPERSONATE
| TOKEN_QUERY
,
4737 NULL
, ImpersonationLevel
, TokenImpersonation
,
4738 DuplicateTokenHandle
);
4741 /******************************************************************************
4742 * ComputeStringSidSize
4744 static DWORD
ComputeStringSidSize(LPCWSTR StringSid
)
4746 if (StringSid
[0] == 'S' && StringSid
[1] == '-') /* S-R-I(-S)+ */
4751 if (*StringSid
== '-')
4757 return GetSidLengthRequired(ctok
- 2);
4759 else /* String constant format - Only available in winxp and above */
4763 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
4764 if (!strncmpW(WellKnownSids
[i
].wstr
, StringSid
, 2))
4765 return GetSidLengthRequired(WellKnownSids
[i
].Sid
.SubAuthorityCount
);
4768 return GetSidLengthRequired(0);
4771 /******************************************************************************
4772 * ParseStringSidToSid
4774 static BOOL
ParseStringSidToSid(LPCWSTR StringSid
, PSID pSid
, LPDWORD cBytes
)
4779 TRACE("%s, %p, %p\n", debugstr_w(StringSid
), pSid
, cBytes
);
4782 SetLastError(ERROR_INVALID_PARAMETER
);
4783 TRACE("StringSid is NULL, returning FALSE\n");
4787 *cBytes
= ComputeStringSidSize(StringSid
);
4788 if (!pisid
) /* Simply compute the size */
4790 TRACE("only size requested, returning TRUE\n");
4794 if (StringSid
[0] == 'S' && StringSid
[1] == '-') /* S-R-I-S-S */
4796 DWORD i
= 0, identAuth
;
4797 DWORD csubauth
= ((*cBytes
- GetSidLengthRequired(0)) / sizeof(DWORD
));
4799 StringSid
+= 2; /* Advance to Revision */
4800 pisid
->Revision
= atoiW(StringSid
);
4802 if (pisid
->Revision
!= SDDL_REVISION
)
4804 TRACE("Revision %d is unknown\n", pisid
->Revision
);
4805 goto lend
; /* ERROR_INVALID_SID */
4809 TRACE("SubAuthorityCount is 0\n");
4810 goto lend
; /* ERROR_INVALID_SID */
4813 pisid
->SubAuthorityCount
= csubauth
;
4815 /* Advance to identifier authority */
4816 while (*StringSid
&& *StringSid
!= '-')
4818 if (*StringSid
== '-')
4821 /* MS' implementation can't handle values greater than 2^32 - 1, so
4822 * we don't either; assume most significant bytes are always 0
4824 pisid
->IdentifierAuthority
.Value
[0] = 0;
4825 pisid
->IdentifierAuthority
.Value
[1] = 0;
4826 identAuth
= atoiW(StringSid
);
4827 pisid
->IdentifierAuthority
.Value
[5] = identAuth
& 0xff;
4828 pisid
->IdentifierAuthority
.Value
[4] = (identAuth
& 0xff00) >> 8;
4829 pisid
->IdentifierAuthority
.Value
[3] = (identAuth
& 0xff0000) >> 16;
4830 pisid
->IdentifierAuthority
.Value
[2] = (identAuth
& 0xff000000) >> 24;
4832 /* Advance to first sub authority */
4833 while (*StringSid
&& *StringSid
!= '-')
4835 if (*StringSid
== '-')
4840 pisid
->SubAuthority
[i
++] = atoiW(StringSid
);
4842 while (*StringSid
&& *StringSid
!= '-')
4844 if (*StringSid
== '-')
4848 if (i
!= pisid
->SubAuthorityCount
)
4849 goto lend
; /* ERROR_INVALID_SID */
4853 else /* String constant format - Only available in winxp and above */
4856 pisid
->Revision
= SDDL_REVISION
;
4858 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
4859 if (!strncmpW(WellKnownSids
[i
].wstr
, StringSid
, 2))
4862 pisid
->SubAuthorityCount
= WellKnownSids
[i
].Sid
.SubAuthorityCount
;
4863 pisid
->IdentifierAuthority
= WellKnownSids
[i
].Sid
.IdentifierAuthority
;
4864 for (j
= 0; j
< WellKnownSids
[i
].Sid
.SubAuthorityCount
; j
++)
4865 pisid
->SubAuthority
[j
] = WellKnownSids
[i
].Sid
.SubAuthority
[j
];
4870 FIXME("String constant not supported: %s\n", debugstr_wn(StringSid
, 2));
4875 SetLastError(ERROR_INVALID_SID
);
4877 TRACE("returning %s\n", bret
? "TRUE" : "FALSE");
4881 /******************************************************************************
4882 * GetNamedSecurityInfoA [ADVAPI32.@]
4884 DWORD WINAPI
GetNamedSecurityInfoA(LPSTR pObjectName
,
4885 SE_OBJECT_TYPE ObjectType
, SECURITY_INFORMATION SecurityInfo
,
4886 PSID
* ppsidOwner
, PSID
* ppsidGroup
, PACL
* ppDacl
, PACL
* ppSacl
,
4887 PSECURITY_DESCRIPTOR
* ppSecurityDescriptor
)
4893 TRACE("%s %d %d %p %p %p %p %p\n", pObjectName
, ObjectType
, SecurityInfo
,
4894 ppsidOwner
, ppsidGroup
, ppDacl
, ppSacl
, ppSecurityDescriptor
);
4898 len
= MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, NULL
, 0 );
4899 wstr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
4900 MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, wstr
, len
);
4903 r
= GetNamedSecurityInfoW( wstr
, ObjectType
, SecurityInfo
, ppsidOwner
,
4904 ppsidGroup
, ppDacl
, ppSacl
, ppSecurityDescriptor
);
4906 HeapFree( GetProcessHeap(), 0, wstr
);
4911 /******************************************************************************
4912 * GetNamedSecurityInfoW [ADVAPI32.@]
4914 DWORD WINAPI
GetNamedSecurityInfoW( LPWSTR name
, SE_OBJECT_TYPE type
,
4915 SECURITY_INFORMATION info
, PSID
* owner
, PSID
* group
, PACL
* dacl
,
4916 PACL
* sacl
, PSECURITY_DESCRIPTOR
* descriptor
)
4918 DWORD needed
, offset
;
4919 SECURITY_DESCRIPTOR_RELATIVE
*relative
;
4922 TRACE( "%s %d %d %p %p %p %p %p\n", debugstr_w(name
), type
, info
, owner
,
4923 group
, dacl
, sacl
, descriptor
);
4925 if (!name
|| !descriptor
) return ERROR_INVALID_PARAMETER
;
4927 needed
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
4928 if (info
& OWNER_SECURITY_INFORMATION
)
4929 needed
+= sizeof(sidWorld
);
4930 if (info
& GROUP_SECURITY_INFORMATION
)
4931 needed
+= sizeof(sidWorld
);
4932 if (info
& DACL_SECURITY_INFORMATION
)
4933 needed
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
4934 if (info
& SACL_SECURITY_INFORMATION
)
4935 needed
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
4937 /* must be freed by caller */
4938 *descriptor
= HeapAlloc( GetProcessHeap(), 0, needed
);
4939 if (!*descriptor
) return ERROR_NOT_ENOUGH_MEMORY
;
4941 if (!InitializeSecurityDescriptor( *descriptor
, SECURITY_DESCRIPTOR_REVISION
))
4943 HeapFree( GetProcessHeap(), 0, *descriptor
);
4944 return ERROR_INVALID_SECURITY_DESCR
;
4947 relative
= (SECURITY_DESCRIPTOR_RELATIVE
*)*descriptor
;
4948 relative
->Control
|= SE_SELF_RELATIVE
;
4949 buffer
= (BYTE
*)relative
;
4950 offset
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
4952 if (info
& OWNER_SECURITY_INFORMATION
)
4954 memcpy( buffer
+ offset
, &sidWorld
, sizeof(sidWorld
) );
4955 relative
->Owner
= offset
;
4957 *owner
= buffer
+ offset
;
4958 offset
+= sizeof(sidWorld
);
4960 if (info
& GROUP_SECURITY_INFORMATION
)
4962 memcpy( buffer
+ offset
, &sidWorld
, sizeof(sidWorld
) );
4963 relative
->Group
= offset
;
4965 *group
= buffer
+ offset
;
4966 offset
+= sizeof(sidWorld
);
4968 if (info
& DACL_SECURITY_INFORMATION
)
4970 relative
->Control
|= SE_DACL_PRESENT
;
4971 GetWorldAccessACL( (PACL
)(buffer
+ offset
) );
4972 relative
->Dacl
= offset
;
4974 *dacl
= (PACL
)(buffer
+ offset
);
4975 offset
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
4977 if (info
& SACL_SECURITY_INFORMATION
)
4979 relative
->Control
|= SE_SACL_PRESENT
;
4980 GetWorldAccessACL( (PACL
)(buffer
+ offset
) );
4981 relative
->Sacl
= offset
;
4983 *sacl
= (PACL
)(buffer
+ offset
);
4985 return ERROR_SUCCESS
;
4988 /******************************************************************************
4989 * DecryptFileW [ADVAPI32.@]
4991 BOOL WINAPI
DecryptFileW(LPCWSTR lpFileName
, DWORD dwReserved
)
4993 FIXME("%s %08x\n", debugstr_w(lpFileName
), dwReserved
);
4997 /******************************************************************************
4998 * DecryptFileA [ADVAPI32.@]
5000 BOOL WINAPI
DecryptFileA(LPCSTR lpFileName
, DWORD dwReserved
)
5002 FIXME("%s %08x\n", debugstr_a(lpFileName
), dwReserved
);
5006 /******************************************************************************
5007 * EncryptFileW [ADVAPI32.@]
5009 BOOL WINAPI
EncryptFileW(LPCWSTR lpFileName
)
5011 FIXME("%s\n", debugstr_w(lpFileName
));
5015 /******************************************************************************
5016 * EncryptFileA [ADVAPI32.@]
5018 BOOL WINAPI
EncryptFileA(LPCSTR lpFileName
)
5020 FIXME("%s\n", debugstr_a(lpFileName
));
5024 /******************************************************************************
5025 * FileEncryptionStatusW [ADVAPI32.@]
5027 BOOL WINAPI
FileEncryptionStatusW(LPCWSTR lpFileName
, LPDWORD lpStatus
)
5029 FIXME("(%s %p): stub\n", debugstr_w(lpFileName
), lpStatus
);
5032 *lpStatus
= FILE_SYSTEM_NOT_SUPPORT
;
5036 /******************************************************************************
5037 * FileEncryptionStatusA [ADVAPI32.@]
5039 BOOL WINAPI
FileEncryptionStatusA(LPCSTR lpFileName
, LPDWORD lpStatus
)
5041 FIXME("(%s %p): stub\n", debugstr_a(lpFileName
), lpStatus
);
5044 *lpStatus
= FILE_SYSTEM_NOT_SUPPORT
;
5048 /******************************************************************************
5049 * SetSecurityInfo [ADVAPI32.@]
5051 DWORD WINAPI
SetSecurityInfo(HANDLE handle
, SE_OBJECT_TYPE ObjectType
,
5052 SECURITY_INFORMATION SecurityInfo
, PSID psidOwner
,
5053 PSID psidGroup
, PACL pDacl
, PACL pSacl
) {
5055 return ERROR_SUCCESS
;