2 * Copyright 1999, 2000 Juergen Schmied <juergen.schmied@debitel.net>
3 * Copyright 2003 CodeWeavers Inc. (Ulrich Czekalla)
4 * Copyright 2006 Robert Reif
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define WIN32_NO_STATUS
39 #include "advapi32_misc.h"
41 #include "wine/debug.h"
42 #include "wine/unicode.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
46 static BOOL
ParseStringSidToSid(LPCWSTR StringSid
, PSID pSid
, LPDWORD cBytes
);
47 static BOOL
ParseStringAclToAcl(LPCWSTR StringAcl
, LPDWORD lpdwFlags
,
48 PACL pAcl
, LPDWORD cBytes
);
49 static BYTE
ParseAceStringFlags(LPCWSTR
* StringAcl
);
50 static BYTE
ParseAceStringType(LPCWSTR
* StringAcl
);
51 static DWORD
ParseAceStringRights(LPCWSTR
* StringAcl
);
52 static BOOL
ParseStringSecurityDescriptorToSecurityDescriptor(
53 LPCWSTR StringSecurityDescriptor
,
54 SECURITY_DESCRIPTOR
* SecurityDescriptor
,
56 static DWORD
ParseAclStringFlags(LPCWSTR
* StringAcl
);
58 typedef struct _ACEFLAG
62 } ACEFLAG
, *LPACEFLAG
;
64 typedef struct _MAX_SID
66 /* same fields as struct _SID */
68 BYTE SubAuthorityCount
;
69 SID_IDENTIFIER_AUTHORITY IdentifierAuthority
;
70 DWORD SubAuthority
[SID_MAX_SUB_AUTHORITIES
];
73 typedef struct WELLKNOWNSID
76 WELL_KNOWN_SID_TYPE Type
;
80 static const WELLKNOWNSID WellKnownSids
[] =
82 { {0,0}, WinNullSid
, { SID_REVISION
, 1, { SECURITY_NULL_SID_AUTHORITY
}, { SECURITY_NULL_RID
} } },
83 { {'W','D'}, WinWorldSid
, { SID_REVISION
, 1, { SECURITY_WORLD_SID_AUTHORITY
}, { SECURITY_WORLD_RID
} } },
84 { {0,0}, WinLocalSid
, { SID_REVISION
, 1, { SECURITY_LOCAL_SID_AUTHORITY
}, { SECURITY_LOCAL_RID
} } },
85 { {'C','O'}, WinCreatorOwnerSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_OWNER_RID
} } },
86 { {'C','G'}, WinCreatorGroupSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_GROUP_RID
} } },
87 { {0,0}, WinCreatorOwnerServerSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_OWNER_SERVER_RID
} } },
88 { {0,0}, WinCreatorGroupServerSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_GROUP_SERVER_RID
} } },
89 { {0,0}, WinNtAuthoritySid
, { SID_REVISION
, 0, { SECURITY_NT_AUTHORITY
}, { } } },
90 { {0,0}, WinDialupSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_DIALUP_RID
} } },
91 { {'N','U'}, WinNetworkSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_NETWORK_RID
} } },
92 { {0,0}, WinBatchSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_BATCH_RID
} } },
93 { {'I','U'}, WinInteractiveSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_INTERACTIVE_RID
} } },
94 { {'S','U'}, WinServiceSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_SERVICE_RID
} } },
95 { {'A','N'}, WinAnonymousSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_ANONYMOUS_LOGON_RID
} } },
96 { {0,0}, WinProxySid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_PROXY_RID
} } },
97 { {'E','D'}, WinEnterpriseControllersSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_ENTERPRISE_CONTROLLERS_RID
} } },
98 { {'P','S'}, WinSelfSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_PRINCIPAL_SELF_RID
} } },
99 { {'A','U'}, WinAuthenticatedUserSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_AUTHENTICATED_USER_RID
} } },
100 { {'R','C'}, WinRestrictedCodeSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_RESTRICTED_CODE_RID
} } },
101 { {0,0}, WinTerminalServerSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_TERMINAL_SERVER_RID
} } },
102 { {0,0}, WinRemoteLogonIdSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_REMOTE_LOGON_RID
} } },
103 { {'S','Y'}, WinLocalSystemSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_LOCAL_SYSTEM_RID
} } },
104 { {'L','S'}, WinLocalServiceSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_LOCAL_SERVICE_RID
} } },
105 { {'N','S'}, WinNetworkServiceSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_NETWORK_SERVICE_RID
} } },
106 { {0,0}, WinBuiltinDomainSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
} } },
107 { {'B','A'}, WinBuiltinAdministratorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_ADMINS
} } },
108 { {'B','U'}, WinBuiltinUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_USERS
} } },
109 { {'B','G'}, WinBuiltinGuestsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_GUESTS
} } },
110 { {'P','U'}, WinBuiltinPowerUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_POWER_USERS
} } },
111 { {'A','O'}, WinBuiltinAccountOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_ACCOUNT_OPS
} } },
112 { {'S','O'}, WinBuiltinSystemOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_SYSTEM_OPS
} } },
113 { {'P','O'}, WinBuiltinPrintOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_PRINT_OPS
} } },
114 { {'B','O'}, WinBuiltinBackupOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_BACKUP_OPS
} } },
115 { {'R','E'}, WinBuiltinReplicatorSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_REPLICATOR
} } },
116 { {'R','U'}, WinBuiltinPreWindows2000CompatibleAccessSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_PREW2KCOMPACCESS
} } },
117 { {'R','D'}, WinBuiltinRemoteDesktopUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS
} } },
118 { {'N','O'}, WinBuiltinNetworkConfigurationOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS
} } },
119 { {0,0}, WinNTLMAuthenticationSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_PACKAGE_BASE_RID
, SECURITY_PACKAGE_NTLM_RID
} } },
120 { {0,0}, WinDigestAuthenticationSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_PACKAGE_BASE_RID
, SECURITY_PACKAGE_DIGEST_RID
} } },
121 { {0,0}, WinSChannelAuthenticationSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_PACKAGE_BASE_RID
, SECURITY_PACKAGE_SCHANNEL_RID
} } },
122 { {0,0}, WinThisOrganizationSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_THIS_ORGANIZATION_RID
} } },
123 { {0,0}, WinOtherOrganizationSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_OTHER_ORGANIZATION_RID
} } },
124 { {0,0}, WinBuiltinPerfMonitoringUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_MONITORING_USERS
} } },
125 { {0,0}, WinBuiltinPerfLoggingUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_LOGGING_USERS
} } },
128 static SID
const sidWorld
= { SID_REVISION
, 1, { SECURITY_WORLD_SID_AUTHORITY
} , { SECURITY_WORLD_RID
} };
130 typedef struct _AccountSid
{
131 WELL_KNOWN_SID_TYPE type
;
134 SID_NAME_USE name_use
;
137 static const WCHAR Account_Operators
[] = { 'A','c','c','o','u','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
138 static const WCHAR Administrator
[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0 };
139 static const WCHAR Administrators
[] = { 'A','d','m','i','n','i','s','t','r','a','t','o','r','s',0 };
140 static const WCHAR ANONYMOUS_LOGON
[] = { 'A','N','O','N','Y','M','O','U','S',' ','L','O','G','O','N',0 };
141 static const WCHAR Authenticated_Users
[] = { 'A','u','t','h','e','n','t','i','c','a','t','e','d',' ','U','s','e','r','s',0 };
142 static const WCHAR Backup_Operators
[] = { 'B','a','c','k','u','p',' ','O','p','e','r','a','t','o','r','s',0 };
143 static const WCHAR BATCH
[] = { 'B','A','T','C','H',0 };
144 static const WCHAR Blank
[] = { 0 };
145 static const WCHAR BUILTIN
[] = { 'B','U','I','L','T','I','N',0 };
146 static const WCHAR Cert_Publishers
[] = { 'C','e','r','t',' ','P','u','b','l','i','s','h','e','r','s',0 };
147 static const WCHAR CREATOR_GROUP
[] = { 'C','R','E','A','T','O','R',' ','G','R','O','U','P',0 };
148 static const WCHAR CREATOR_GROUP_SERVER
[] = { 'C','R','E','A','T','O','R',' ','G','R','O','U','P',' ','S','E','R','V','E','R',0 };
149 static const WCHAR CREATOR_OWNER
[] = { 'C','R','E','A','T','O','R',' ','O','W','N','E','R',0 };
150 static const WCHAR CREATOR_OWNER_SERVER
[] = { 'C','R','E','A','T','O','R',' ','O','W','N','E','R',' ','S','E','R','V','E','R',0 };
151 static const WCHAR DIALUP
[] = { 'D','I','A','L','U','P',0 };
152 static const WCHAR Digest_Authentication
[] = { 'D','i','g','e','s','t',' ','A','u','t','h','e','n','t','i','c','a','t','i','o','n',0 };
153 static const WCHAR DOMAIN
[] = {'D','O','M','A','I','N',0};
154 static const WCHAR Domain_Admins
[] = { 'D','o','m','a','i','n',' ','A','d','m','i','n','s',0 };
155 static const WCHAR Domain_Computers
[] = { 'D','o','m','a','i','n',' ','C','o','m','p','u','t','e','r','s',0 };
156 static const WCHAR Domain_Controllers
[] = { 'D','o','m','a','i','n',' ','C','o','n','t','r','o','l','l','e','r','s',0 };
157 static const WCHAR Domain_Guests
[] = { 'D','o','m','a','i','n',' ','G','u','e','s','t','s',0 };
158 static const WCHAR Domain_Users
[] = { 'D','o','m','a','i','n',' ','U','s','e','r','s',0 };
159 static const WCHAR Enterprise_Admins
[] = { 'E','n','t','e','r','p','r','i','s','e',' ','A','d','m','i','n','s',0 };
160 static const WCHAR ENTERPRISE_DOMAIN_CONTROLLERS
[] = { 'E','N','T','E','R','P','R','I','S','E',' ','D','O','M','A','I','N',' ','C','O','N','T','R','O','L','L','E','R','S',0 };
161 static const WCHAR Everyone
[] = { 'E','v','e','r','y','o','n','e',0 };
162 static const WCHAR Group_Policy_Creator_Owners
[] = { 'G','r','o','u','p',' ','P','o','l','i','c','y',' ','C','r','e','a','t','o','r',' ','O','w','n','e','r','s',0 };
163 static const WCHAR Guest
[] = { 'G','u','e','s','t',0 };
164 static const WCHAR Guests
[] = { 'G','u','e','s','t','s',0 };
165 static const WCHAR INTERACTIVE
[] = { 'I','N','T','E','R','A','C','T','I','V','E',0 };
166 static const WCHAR LOCAL
[] = { 'L','O','C','A','L',0 };
167 static const WCHAR LOCAL_SERVICE
[] = { 'L','O','C','A','L',' ','S','E','R','V','I','C','E',0 };
168 static const WCHAR NETWORK
[] = { 'N','E','T','W','O','R','K',0 };
169 static const WCHAR Network_Configuration_Operators
[] = { 'N','e','t','w','o','r','k',' ','C','o','n','f','i','g','u','r','a','t','i','o','n',' ','O','p','e','r','a','t','o','r','s',0 };
170 static const WCHAR NETWORK_SERVICE
[] = { 'N','E','T','W','O','R','K',' ','S','E','R','V','I','C','E',0 };
171 static const WCHAR NT_AUTHORITY
[] = { 'N','T',' ','A','U','T','H','O','R','I','T','Y',0 };
172 static const WCHAR NT_Pseudo_Domain
[] = { 'N','T',' ','P','s','e','u','d','o',' ','D','o','m','a','i','n',0 };
173 static const WCHAR NTML_Authentication
[] = { 'N','T','M','L',' ','A','u','t','h','e','n','t','i','c','a','t','i','o','n',0 };
174 static const WCHAR NULL_SID
[] = { 'N','U','L','L',' ','S','I','D',0 };
175 static const WCHAR Other_Organization
[] = { 'O','t','h','e','r',' ','O','r','g','a','n','i','z','a','t','i','o','n',0 };
176 static const WCHAR Performance_Log_Users
[] = { 'P','e','r','f','o','r','m','a','n','c','e',' ','L','o','g',' ','U','s','e','r','s',0 };
177 static const WCHAR Performance_Monitor_Users
[] = { 'P','e','r','f','o','r','m','a','n','c','e',' ','M','o','n','i','t','o','r',' ','U','s','e','r','s',0 };
178 static const WCHAR Power_Users
[] = { 'P','o','w','e','r',' ','U','s','e','r','s',0 };
179 static const WCHAR Pre_Windows_2000_Compatible_Access
[] = { 'P','r','e','-','W','i','n','d','o','w','s',' ','2','0','0','0',' ','C','o','m','p','a','t','i','b','l','e',' ','A','c','c','e','s','s',0 };
180 static const WCHAR Print_Operators
[] = { 'P','r','i','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
181 static const WCHAR PROXY
[] = { 'P','R','O','X','Y',0 };
182 static const WCHAR RAS_and_IAS_Servers
[] = { 'R','A','S',' ','a','n','d',' ','I','A','S',' ','S','e','r','v','e','r','s',0 };
183 static const WCHAR Remote_Desktop_Users
[] = { 'R','e','m','o','t','e',' ','D','e','s','k','t','o','p',' ','U','s','e','r','s',0 };
184 static const WCHAR REMOTE_INTERACTIVE_LOGON
[] = { 'R','E','M','O','T','E',' ','I','N','T','E','R','A','C','T','I','V','E',' ','L','O','G','O','N',0 };
185 static const WCHAR Replicators
[] = { 'R','e','p','l','i','c','a','t','o','r','s',0 };
186 static const WCHAR RESTRICTED
[] = { 'R','E','S','T','R','I','C','T','E','D',0 };
187 static const WCHAR SChannel_Authentication
[] = { 'S','C','h','a','n','n','e','l',' ','A','u','t','h','e','n','t','i','c','a','t','i','o','n',0 };
188 static const WCHAR Schema_Admins
[] = { 'S','c','h','e','m','a',' ','A','d','m','i','n','s',0 };
189 static const WCHAR SELF
[] = { 'S','E','L','F',0 };
190 static const WCHAR Server_Operators
[] = { 'S','e','r','v','e','r',' ','O','p','e','r','a','t','o','r','s',0 };
191 static const WCHAR SERVICE
[] = { 'S','E','R','V','I','C','E',0 };
192 static const WCHAR SYSTEM
[] = { 'S','Y','S','T','E','M',0 };
193 static const WCHAR TERMINAL_SERVER_USER
[] = { 'T','E','R','M','I','N','A','L',' ','S','E','R','V','E','R',' ','U','S','E','R',0 };
194 static const WCHAR This_Organization
[] = { 'T','h','i','s',' ','O','r','g','a','n','i','z','a','t','i','o','n',0 };
195 static const WCHAR Users
[] = { 'U','s','e','r','s',0 };
197 static const AccountSid ACCOUNT_SIDS
[] = {
198 { WinNullSid
, NULL_SID
, Blank
, SidTypeWellKnownGroup
},
199 { WinWorldSid
, Everyone
, Blank
, SidTypeWellKnownGroup
},
200 { WinLocalSid
, LOCAL
, Blank
, SidTypeWellKnownGroup
},
201 { WinCreatorOwnerSid
, CREATOR_OWNER
, Blank
, SidTypeWellKnownGroup
},
202 { WinCreatorGroupSid
, CREATOR_GROUP
, Blank
, SidTypeWellKnownGroup
},
203 { WinCreatorOwnerServerSid
, CREATOR_OWNER_SERVER
, Blank
, SidTypeWellKnownGroup
},
204 { WinCreatorGroupServerSid
, CREATOR_GROUP_SERVER
, Blank
, SidTypeWellKnownGroup
},
205 { WinNtAuthoritySid
, NT_Pseudo_Domain
, NT_Pseudo_Domain
, SidTypeDomain
},
206 { WinDialupSid
, DIALUP
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
207 { WinNetworkSid
, NETWORK
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
208 { WinBatchSid
, BATCH
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
209 { WinInteractiveSid
, INTERACTIVE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
210 { WinServiceSid
, SERVICE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
211 { WinAnonymousSid
, ANONYMOUS_LOGON
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
212 { WinProxySid
, PROXY
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
213 { WinEnterpriseControllersSid
, ENTERPRISE_DOMAIN_CONTROLLERS
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
214 { WinSelfSid
, SELF
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
215 { WinAuthenticatedUserSid
, Authenticated_Users
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
216 { WinRestrictedCodeSid
, RESTRICTED
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
217 { WinTerminalServerSid
, TERMINAL_SERVER_USER
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
218 { WinRemoteLogonIdSid
, REMOTE_INTERACTIVE_LOGON
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
219 { WinLocalSystemSid
, SYSTEM
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
220 { WinLocalServiceSid
, LOCAL_SERVICE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
221 { WinNetworkServiceSid
, NETWORK_SERVICE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
222 { WinBuiltinDomainSid
, BUILTIN
, BUILTIN
, SidTypeDomain
},
223 { WinBuiltinAdministratorsSid
, Administrators
, BUILTIN
, SidTypeAlias
},
224 { WinBuiltinUsersSid
, Users
, BUILTIN
, SidTypeAlias
},
225 { WinBuiltinGuestsSid
, Guests
, BUILTIN
, SidTypeAlias
},
226 { WinBuiltinPowerUsersSid
, Power_Users
, BUILTIN
, SidTypeAlias
},
227 { WinBuiltinAccountOperatorsSid
, Account_Operators
, BUILTIN
, SidTypeAlias
},
228 { WinBuiltinSystemOperatorsSid
, Server_Operators
, BUILTIN
, SidTypeAlias
},
229 { WinBuiltinPrintOperatorsSid
, Print_Operators
, BUILTIN
, SidTypeAlias
},
230 { WinBuiltinBackupOperatorsSid
, Backup_Operators
, BUILTIN
, SidTypeAlias
},
231 { WinBuiltinReplicatorSid
, Replicators
, BUILTIN
, SidTypeAlias
},
232 { WinBuiltinPreWindows2000CompatibleAccessSid
, Pre_Windows_2000_Compatible_Access
, BUILTIN
, SidTypeAlias
},
233 { WinBuiltinRemoteDesktopUsersSid
, Remote_Desktop_Users
, BUILTIN
, SidTypeAlias
},
234 { WinBuiltinNetworkConfigurationOperatorsSid
, Network_Configuration_Operators
, BUILTIN
, SidTypeAlias
},
235 { WinNTLMAuthenticationSid
, NTML_Authentication
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
236 { WinDigestAuthenticationSid
, Digest_Authentication
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
237 { WinSChannelAuthenticationSid
, SChannel_Authentication
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
238 { WinThisOrganizationSid
, This_Organization
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
239 { WinOtherOrganizationSid
, Other_Organization
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
240 { WinBuiltinPerfMonitoringUsersSid
, Performance_Monitor_Users
, BUILTIN
, SidTypeAlias
},
241 { WinBuiltinPerfLoggingUsersSid
, Performance_Log_Users
, BUILTIN
, SidTypeAlias
},
246 static const WCHAR SDDL_READ_CONTROL
[] = {'R','C',0};
247 static const WCHAR SDDL_WRITE_DAC
[] = {'W','D',0};
248 static const WCHAR SDDL_WRITE_OWNER
[] = {'W','O',0};
249 static const WCHAR SDDL_STANDARD_DELETE
[] = {'S','D',0};
250 static const WCHAR SDDL_GENERIC_ALL
[] = {'G','A',0};
251 static const WCHAR SDDL_GENERIC_READ
[] = {'G','R',0};
252 static const WCHAR SDDL_GENERIC_WRITE
[] = {'G','W',0};
253 static const WCHAR SDDL_GENERIC_EXECUTE
[] = {'G','X',0};
258 static const WCHAR SDDL_ACCESS_ALLOWED
[] = {'A',0};
259 static const WCHAR SDDL_ACCESS_DENIED
[] = {'D',0};
260 static const WCHAR SDDL_OBJECT_ACCESS_ALLOWED
[] = {'O','A',0};
261 static const WCHAR SDDL_OBJECT_ACCESS_DENIED
[] = {'O','D',0};
262 static const WCHAR SDDL_AUDIT
[] = {'A','U',0};
263 static const WCHAR SDDL_ALARM
[] = {'A','L',0};
264 static const WCHAR SDDL_OBJECT_AUDIT
[] = {'O','U',0};
265 static const WCHAR SDDL_OBJECT_ALARMp
[] = {'O','L',0};
270 static const WCHAR SDDL_CONTAINER_INHERIT
[] = {'C','I',0};
271 static const WCHAR SDDL_OBJECT_INHERIT
[] = {'O','I',0};
272 static const WCHAR SDDL_NO_PROPAGATE
[] = {'N','P',0};
273 static const WCHAR SDDL_INHERIT_ONLY
[] = {'I','O',0};
274 static const WCHAR SDDL_INHERITED
[] = {'I','D',0};
275 static const WCHAR SDDL_AUDIT_SUCCESS
[] = {'S','A',0};
276 static const WCHAR SDDL_AUDIT_FAILURE
[] = {'F','A',0};
278 const char * debugstr_sid(PSID sid
)
281 SID
* psid
= (SID
*)sid
;
286 auth
= psid
->IdentifierAuthority
.Value
[5] +
287 (psid
->IdentifierAuthority
.Value
[4] << 8) +
288 (psid
->IdentifierAuthority
.Value
[3] << 16) +
289 (psid
->IdentifierAuthority
.Value
[2] << 24);
291 switch (psid
->SubAuthorityCount
) {
293 return wine_dbg_sprintf("S-%d-%d", psid
->Revision
, auth
);
295 return wine_dbg_sprintf("S-%d-%d-%u", psid
->Revision
, auth
,
296 psid
->SubAuthority
[0]);
298 return wine_dbg_sprintf("S-%d-%d-%u-%u", psid
->Revision
, auth
,
299 psid
->SubAuthority
[0], psid
->SubAuthority
[1]);
301 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u", psid
->Revision
, auth
,
302 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2]);
304 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u", psid
->Revision
, auth
,
305 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
306 psid
->SubAuthority
[3]);
308 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
309 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
310 psid
->SubAuthority
[3], psid
->SubAuthority
[4]);
312 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
313 psid
->SubAuthority
[3], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
314 psid
->SubAuthority
[0], psid
->SubAuthority
[4], psid
->SubAuthority
[5]);
316 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
317 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
318 psid
->SubAuthority
[3], psid
->SubAuthority
[4], psid
->SubAuthority
[5],
319 psid
->SubAuthority
[6]);
321 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
322 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
323 psid
->SubAuthority
[3], psid
->SubAuthority
[4], psid
->SubAuthority
[5],
324 psid
->SubAuthority
[6], psid
->SubAuthority
[7]);
329 /* set last error code from NT status and get the proper boolean return value */
330 /* used for functions that are a simple wrapper around the corresponding ntdll API */
331 static inline BOOL
set_ntstatus( NTSTATUS status
)
333 if (status
) SetLastError( RtlNtStatusToDosError( status
));
337 #define WINE_SIZE_OF_WORLD_ACCESS_ACL (sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD))
339 static void GetWorldAccessACL(PACL pACL
)
341 PACCESS_ALLOWED_ACE pACE
= (PACCESS_ALLOWED_ACE
) (pACL
+ 1);
343 pACL
->AclRevision
= ACL_REVISION
;
345 pACL
->AclSize
= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
349 pACE
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
350 pACE
->Header
.AceFlags
= CONTAINER_INHERIT_ACE
;
351 pACE
->Header
.AceSize
= sizeof(ACCESS_ALLOWED_ACE
) + sizeof(sidWorld
) - sizeof(DWORD
);
352 pACE
->Mask
= 0xf3ffffff; /* Everything except reserved bits */
353 memcpy(&pACE
->SidStart
, &sidWorld
, sizeof(sidWorld
));
356 /************************************************************
357 * ADVAPI_IsLocalComputer
359 * Checks whether the server name indicates local machine.
361 BOOL
ADVAPI_IsLocalComputer(LPCWSTR ServerName
)
363 DWORD dwSize
= MAX_COMPUTERNAME_LENGTH
+ 1;
367 if (!ServerName
|| !ServerName
[0])
370 buf
= HeapAlloc(GetProcessHeap(), 0, dwSize
* sizeof(WCHAR
));
371 Result
= GetComputerNameW(buf
, &dwSize
);
372 if (Result
&& (ServerName
[0] == '\\') && (ServerName
[1] == '\\'))
374 Result
= Result
&& !lstrcmpW(ServerName
, buf
);
375 HeapFree(GetProcessHeap(), 0, buf
);
380 /************************************************************
381 * ADVAPI_GetComputerSid
383 * Reads the computer SID from the registry.
385 BOOL
ADVAPI_GetComputerSid(PSID sid
)
390 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 };
391 static const WCHAR V
[] = { 'V',0 };
393 if ((ret
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, Account
, 0,
394 KEY_READ
, &key
)) == ERROR_SUCCESS
)
397 ret
= RegQueryValueExW(key
, V
, NULL
, NULL
, NULL
, &size
);
398 if (ret
== ERROR_MORE_DATA
|| ret
== ERROR_SUCCESS
)
400 BYTE
* data
= HeapAlloc(GetProcessHeap(), 0, size
);
403 if ((ret
= RegQueryValueExW(key
, V
, NULL
, NULL
,
404 data
, &size
)) == ERROR_SUCCESS
)
406 /* the SID is in the last 24 bytes of the binary data */
407 CopyMemory(sid
, &data
[size
-24], 24);
410 HeapFree(GetProcessHeap(), 0, data
);
416 if(retval
== TRUE
) return retval
;
418 /* create a new random SID */
419 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Account
,
420 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
) == ERROR_SUCCESS
)
423 SID_IDENTIFIER_AUTHORITY identifierAuthority
= {SECURITY_NT_AUTHORITY
};
426 if (RtlGenRandom(&id
, sizeof(id
)))
428 if (AllocateAndInitializeSid(&identifierAuthority
, 4, SECURITY_NT_NON_UNIQUE
, id
[0], id
[1], id
[2], 0, 0, 0, 0, &new_sid
))
430 if (RegSetValueExW(key
, V
, 0, REG_BINARY
, new_sid
, GetLengthSid(new_sid
)) == ERROR_SUCCESS
)
431 retval
= CopySid(GetLengthSid(new_sid
), sid
, new_sid
);
442 /* ##############################
443 ###### TOKEN FUNCTIONS ######
444 ##############################
447 /******************************************************************************
448 * OpenProcessToken [ADVAPI32.@]
449 * Opens the access token associated with a process handle.
452 * ProcessHandle [I] Handle to process
453 * DesiredAccess [I] Desired access to process
454 * TokenHandle [O] Pointer to handle of open access token
457 * Success: TRUE. TokenHandle contains the access token.
461 * See NtOpenProcessToken.
464 OpenProcessToken( HANDLE ProcessHandle
, DWORD DesiredAccess
,
465 HANDLE
*TokenHandle
)
467 return set_ntstatus(NtOpenProcessToken( ProcessHandle
, DesiredAccess
, TokenHandle
));
470 /******************************************************************************
471 * OpenThreadToken [ADVAPI32.@]
473 * Opens the access token associated with a thread handle.
476 * ThreadHandle [I] Handle to process
477 * DesiredAccess [I] Desired access to the thread
479 * TokenHandle [O] Destination for the token handle
482 * Success: TRUE. TokenHandle contains the access token.
486 * See NtOpenThreadToken.
489 OpenThreadToken( HANDLE ThreadHandle
, DWORD DesiredAccess
,
490 BOOL OpenAsSelf
, HANDLE
*TokenHandle
)
492 return set_ntstatus( NtOpenThreadToken(ThreadHandle
, DesiredAccess
, OpenAsSelf
, TokenHandle
));
496 AdjustTokenGroups( HANDLE TokenHandle
, BOOL ResetToDefault
, PTOKEN_GROUPS NewState
,
497 DWORD BufferLength
, PTOKEN_GROUPS PreviousState
, PDWORD ReturnLength
)
499 return set_ntstatus( NtAdjustGroupsToken(TokenHandle
, ResetToDefault
, NewState
, BufferLength
,
500 PreviousState
, ReturnLength
));
503 /******************************************************************************
504 * AdjustTokenPrivileges [ADVAPI32.@]
506 * Adjust the privileges of an open token handle.
509 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
510 * DisableAllPrivileges [I] TRUE=Remove all privileges, FALSE=Use NewState
511 * NewState [I] Desired new privileges of the token
512 * BufferLength [I] Length of NewState
513 * PreviousState [O] Destination for the previous state
514 * ReturnLength [I/O] Size of PreviousState
518 * Success: TRUE. Privileges are set to NewState and PreviousState is updated.
522 * See NtAdjustPrivilegesToken.
525 AdjustTokenPrivileges( HANDLE TokenHandle
, BOOL DisableAllPrivileges
,
526 LPVOID NewState
, DWORD BufferLength
,
527 LPVOID PreviousState
, LPDWORD ReturnLength
)
533 status
= NtAdjustPrivilegesToken(TokenHandle
, DisableAllPrivileges
,
534 NewState
, BufferLength
, PreviousState
,
536 SetLastError( RtlNtStatusToDosError( status
));
537 if ((status
== STATUS_SUCCESS
) || (status
== STATUS_NOT_ALL_ASSIGNED
))
543 /******************************************************************************
544 * CheckTokenMembership [ADVAPI32.@]
546 * Determine if an access token is a member of a SID.
549 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
550 * SidToCheck [I] SID that possibly contains the token
551 * IsMember [O] Destination for result.
554 * Success: TRUE. IsMember is TRUE if TokenHandle is a member, FALSE otherwise.
558 CheckTokenMembership( HANDLE TokenHandle
, PSID SidToCheck
,
561 FIXME("(%p %p %p) stub!\n", TokenHandle
, SidToCheck
, IsMember
);
567 /******************************************************************************
568 * GetTokenInformation [ADVAPI32.@]
570 * Get a type of information about an access token.
573 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
574 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
575 * tokeninfo [O] Destination for token information
576 * tokeninfolength [I] Length of tokeninfo
577 * retlen [O] Destination for returned token information length
580 * Success: TRUE. tokeninfo contains retlen bytes of token information
584 * See NtQueryInformationToken.
587 GetTokenInformation( HANDLE token
, TOKEN_INFORMATION_CLASS tokeninfoclass
,
588 LPVOID tokeninfo
, DWORD tokeninfolength
, LPDWORD retlen
)
590 TRACE("(%p, %s, %p, %d, %p):\n",
592 (tokeninfoclass
== TokenUser
) ? "TokenUser" :
593 (tokeninfoclass
== TokenGroups
) ? "TokenGroups" :
594 (tokeninfoclass
== TokenPrivileges
) ? "TokenPrivileges" :
595 (tokeninfoclass
== TokenOwner
) ? "TokenOwner" :
596 (tokeninfoclass
== TokenPrimaryGroup
) ? "TokenPrimaryGroup" :
597 (tokeninfoclass
== TokenDefaultDacl
) ? "TokenDefaultDacl" :
598 (tokeninfoclass
== TokenSource
) ? "TokenSource" :
599 (tokeninfoclass
== TokenType
) ? "TokenType" :
600 (tokeninfoclass
== TokenImpersonationLevel
) ? "TokenImpersonationLevel" :
601 (tokeninfoclass
== TokenStatistics
) ? "TokenStatistics" :
602 (tokeninfoclass
== TokenRestrictedSids
) ? "TokenRestrictedSids" :
603 (tokeninfoclass
== TokenSessionId
) ? "TokenSessionId" :
604 (tokeninfoclass
== TokenGroupsAndPrivileges
) ? "TokenGroupsAndPrivileges" :
605 (tokeninfoclass
== TokenSessionReference
) ? "TokenSessionReference" :
606 (tokeninfoclass
== TokenSandBoxInert
) ? "TokenSandBoxInert" :
608 tokeninfo
, tokeninfolength
, retlen
);
609 return set_ntstatus( NtQueryInformationToken( token
, tokeninfoclass
, tokeninfo
,
610 tokeninfolength
, retlen
));
613 /******************************************************************************
614 * SetTokenInformation [ADVAPI32.@]
616 * Set information for an access token.
619 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
620 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
621 * tokeninfo [I] Token information to set
622 * tokeninfolength [I] Length of tokeninfo
625 * Success: TRUE. The information for the token is set to tokeninfo.
629 SetTokenInformation( HANDLE token
, TOKEN_INFORMATION_CLASS tokeninfoclass
,
630 LPVOID tokeninfo
, DWORD tokeninfolength
)
632 TRACE("(%p, %s, %p, %d): stub\n",
634 (tokeninfoclass
== TokenUser
) ? "TokenUser" :
635 (tokeninfoclass
== TokenGroups
) ? "TokenGroups" :
636 (tokeninfoclass
== TokenPrivileges
) ? "TokenPrivileges" :
637 (tokeninfoclass
== TokenOwner
) ? "TokenOwner" :
638 (tokeninfoclass
== TokenPrimaryGroup
) ? "TokenPrimaryGroup" :
639 (tokeninfoclass
== TokenDefaultDacl
) ? "TokenDefaultDacl" :
640 (tokeninfoclass
== TokenSource
) ? "TokenSource" :
641 (tokeninfoclass
== TokenType
) ? "TokenType" :
642 (tokeninfoclass
== TokenImpersonationLevel
) ? "TokenImpersonationLevel" :
643 (tokeninfoclass
== TokenStatistics
) ? "TokenStatistics" :
644 (tokeninfoclass
== TokenRestrictedSids
) ? "TokenRestrictedSids" :
645 (tokeninfoclass
== TokenSessionId
) ? "TokenSessionId" :
646 (tokeninfoclass
== TokenGroupsAndPrivileges
) ? "TokenGroupsAndPrivileges" :
647 (tokeninfoclass
== TokenSessionReference
) ? "TokenSessionReference" :
648 (tokeninfoclass
== TokenSandBoxInert
) ? "TokenSandBoxInert" :
650 tokeninfo
, tokeninfolength
);
652 return set_ntstatus( NtSetInformationToken( token
, tokeninfoclass
, tokeninfo
, tokeninfolength
));
655 /*************************************************************************
656 * SetThreadToken [ADVAPI32.@]
658 * Assigns an 'impersonation token' to a thread so it can assume the
659 * security privileges of another thread or process. Can also remove
660 * a previously assigned token.
663 * thread [O] Handle to thread to set the token for
664 * token [I] Token to set
667 * Success: TRUE. The threads access token is set to token
671 * Only supported on NT or higher. On Win9X this function does nothing.
672 * See SetTokenInformation.
674 BOOL WINAPI
SetThreadToken(PHANDLE thread
, HANDLE token
)
676 return set_ntstatus( NtSetInformationThread( thread
? *thread
: GetCurrentThread(),
677 ThreadImpersonationToken
, &token
, sizeof token
));
680 /* ##############################
681 ###### SID FUNCTIONS ######
682 ##############################
685 /******************************************************************************
686 * AllocateAndInitializeSid [ADVAPI32.@]
689 * pIdentifierAuthority []
690 * nSubAuthorityCount []
702 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
703 BYTE nSubAuthorityCount
,
704 DWORD nSubAuthority0
, DWORD nSubAuthority1
,
705 DWORD nSubAuthority2
, DWORD nSubAuthority3
,
706 DWORD nSubAuthority4
, DWORD nSubAuthority5
,
707 DWORD nSubAuthority6
, DWORD nSubAuthority7
,
710 return set_ntstatus( RtlAllocateAndInitializeSid(
711 pIdentifierAuthority
, nSubAuthorityCount
,
712 nSubAuthority0
, nSubAuthority1
, nSubAuthority2
, nSubAuthority3
,
713 nSubAuthority4
, nSubAuthority5
, nSubAuthority6
, nSubAuthority7
,
717 /******************************************************************************
718 * FreeSid [ADVAPI32.@]
727 return NULL
; /* is documented like this */
730 /******************************************************************************
731 * CopySid [ADVAPI32.@]
734 * nDestinationSidLength []
739 CopySid( DWORD nDestinationSidLength
, PSID pDestinationSid
, PSID pSourceSid
)
741 return RtlCopySid(nDestinationSidLength
, pDestinationSid
, pSourceSid
);
744 /******************************************************************************
745 * CreateWellKnownSid [ADVAPI32.@]
748 CreateWellKnownSid( WELL_KNOWN_SID_TYPE WellKnownSidType
,
754 TRACE("(%d, %s, %p, %p)\n", WellKnownSidType
, debugstr_sid(DomainSid
), pSid
, cbSid
);
756 if (DomainSid
!= NULL
) {
757 FIXME("Only local computer supported!\n");
758 SetLastError(ERROR_INVALID_PARAMETER
); /* FIXME */
762 if (cbSid
== NULL
|| pSid
== NULL
) {
763 SetLastError(ERROR_INVALID_PARAMETER
);
767 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++) {
768 if (WellKnownSids
[i
].Type
== WellKnownSidType
) {
769 DWORD length
= GetSidLengthRequired(WellKnownSids
[i
].Sid
.SubAuthorityCount
);
771 if (*cbSid
< length
) {
772 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
776 CopyMemory(pSid
, &WellKnownSids
[i
].Sid
.Revision
, length
);
782 SetLastError(ERROR_INVALID_PARAMETER
);
786 /******************************************************************************
787 * IsWellKnownSid [ADVAPI32.@]
790 IsWellKnownSid( PSID pSid
, WELL_KNOWN_SID_TYPE WellKnownSidType
)
793 TRACE("(%s, %d)\n", debugstr_sid(pSid
), WellKnownSidType
);
795 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
796 if (WellKnownSids
[i
].Type
== WellKnownSidType
)
797 if (EqualSid(pSid
, (PSID
)&(WellKnownSids
[i
].Sid
.Revision
)))
804 IsTokenRestricted( HANDLE TokenHandle
)
806 TOKEN_GROUPS
*groups
;
811 TRACE("(%p)\n", TokenHandle
);
813 status
= NtQueryInformationToken(TokenHandle
, TokenRestrictedSids
, NULL
, 0, &size
);
814 if (status
!= STATUS_BUFFER_TOO_SMALL
)
817 groups
= HeapAlloc(GetProcessHeap(), 0, size
);
820 SetLastError(ERROR_OUTOFMEMORY
);
824 status
= NtQueryInformationToken(TokenHandle
, TokenRestrictedSids
, groups
, size
, &size
);
825 if (status
!= STATUS_SUCCESS
)
827 HeapFree(GetProcessHeap(), 0, groups
);
828 return set_ntstatus(status
);
831 if (groups
->GroupCount
)
836 HeapFree(GetProcessHeap(), 0, groups
);
841 /******************************************************************************
842 * IsValidSid [ADVAPI32.@]
848 IsValidSid( PSID pSid
)
850 return RtlValidSid( pSid
);
853 /******************************************************************************
854 * EqualSid [ADVAPI32.@]
861 EqualSid( PSID pSid1
, PSID pSid2
)
863 return RtlEqualSid( pSid1
, pSid2
);
866 /******************************************************************************
867 * EqualPrefixSid [ADVAPI32.@]
869 BOOL WINAPI
EqualPrefixSid (PSID pSid1
, PSID pSid2
)
871 return RtlEqualPrefixSid(pSid1
, pSid2
);
874 /******************************************************************************
875 * GetSidLengthRequired [ADVAPI32.@]
878 * nSubAuthorityCount []
881 GetSidLengthRequired( BYTE nSubAuthorityCount
)
883 return RtlLengthRequiredSid(nSubAuthorityCount
);
886 /******************************************************************************
887 * InitializeSid [ADVAPI32.@]
890 * pIdentifierAuthority []
895 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
896 BYTE nSubAuthorityCount
)
898 return RtlInitializeSid(pSid
, pIdentifierAuthority
, nSubAuthorityCount
);
902 GetEffectiveRightsFromAclA( PACL pacl
, PTRUSTEEA pTrustee
, PACCESS_MASK pAccessRights
)
904 FIXME("%p %p %p - stub\n", pacl
, pTrustee
, pAccessRights
);
910 GetEffectiveRightsFromAclW( PACL pacl
, PTRUSTEEW pTrustee
, PACCESS_MASK pAccessRights
)
912 FIXME("%p %p %p - stub\n", pacl
, pTrustee
, pAccessRights
);
917 /******************************************************************************
918 * GetSidIdentifierAuthority [ADVAPI32.@]
923 PSID_IDENTIFIER_AUTHORITY WINAPI
924 GetSidIdentifierAuthority( PSID pSid
)
926 return RtlIdentifierAuthoritySid(pSid
);
929 /******************************************************************************
930 * GetSidSubAuthority [ADVAPI32.@]
937 GetSidSubAuthority( PSID pSid
, DWORD nSubAuthority
)
939 return RtlSubAuthoritySid(pSid
, nSubAuthority
);
942 /******************************************************************************
943 * GetSidSubAuthorityCount [ADVAPI32.@]
949 GetSidSubAuthorityCount (PSID pSid
)
951 return RtlSubAuthorityCountSid(pSid
);
954 /******************************************************************************
955 * GetLengthSid [ADVAPI32.@]
961 GetLengthSid (PSID pSid
)
963 return RtlLengthSid(pSid
);
966 /* ##############################################
967 ###### SECURITY DESCRIPTOR FUNCTIONS ######
968 ##############################################
971 /******************************************************************************
972 * BuildSecurityDescriptorA [ADVAPI32.@]
979 * cCountOfAccessEntries [I]
980 * pListOfAccessEntries [I]
981 * cCountOfAuditEntries [I]
982 * pListofAuditEntries [I]
984 * lpdwBufferLength [I/O]
988 * Success: ERROR_SUCCESS
989 * Failure: nonzero error code from Winerror.h
991 DWORD WINAPI
BuildSecurityDescriptorA(
994 IN ULONG cCountOfAccessEntries
,
995 IN PEXPLICIT_ACCESSA pListOfAccessEntries
,
996 IN ULONG cCountOfAuditEntries
,
997 IN PEXPLICIT_ACCESSA pListofAuditEntries
,
998 IN PSECURITY_DESCRIPTOR pOldSD
,
999 IN OUT PULONG lpdwBufferLength
,
1000 OUT PSECURITY_DESCRIPTOR
* pNewSD
)
1002 FIXME("(%p,%p,%d,%p,%d,%p,%p,%p,%p) stub!\n",pOwner
,pGroup
,
1003 cCountOfAccessEntries
,pListOfAccessEntries
,cCountOfAuditEntries
,
1004 pListofAuditEntries
,pOldSD
,lpdwBufferLength
,pNewSD
);
1006 return ERROR_CALL_NOT_IMPLEMENTED
;
1009 /******************************************************************************
1010 * BuildSecurityDescriptorW [ADVAPI32.@]
1012 * See BuildSecurityDescriptorA.
1014 DWORD WINAPI
BuildSecurityDescriptorW(
1015 IN PTRUSTEEW pOwner
,
1016 IN PTRUSTEEW pGroup
,
1017 IN ULONG cCountOfAccessEntries
,
1018 IN PEXPLICIT_ACCESSW pListOfAccessEntries
,
1019 IN ULONG cCountOfAuditEntries
,
1020 IN PEXPLICIT_ACCESSW pListofAuditEntries
,
1021 IN PSECURITY_DESCRIPTOR pOldSD
,
1022 IN OUT PULONG lpdwBufferLength
,
1023 OUT PSECURITY_DESCRIPTOR
* pNewSD
)
1025 FIXME("(%p,%p,%d,%p,%d,%p,%p,%p,%p) stub!\n",pOwner
,pGroup
,
1026 cCountOfAccessEntries
,pListOfAccessEntries
,cCountOfAuditEntries
,
1027 pListofAuditEntries
,pOldSD
,lpdwBufferLength
,pNewSD
);
1029 return ERROR_CALL_NOT_IMPLEMENTED
;
1032 /******************************************************************************
1033 * InitializeSecurityDescriptor [ADVAPI32.@]
1040 InitializeSecurityDescriptor( PSECURITY_DESCRIPTOR pDescr
, DWORD revision
)
1042 return set_ntstatus( RtlCreateSecurityDescriptor(pDescr
, revision
));
1046 /******************************************************************************
1047 * MakeAbsoluteSD [ADVAPI32.@]
1049 BOOL WINAPI
MakeAbsoluteSD (
1050 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor
,
1051 OUT PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor
,
1052 OUT LPDWORD lpdwAbsoluteSecurityDescriptorSize
,
1054 OUT LPDWORD lpdwDaclSize
,
1056 OUT LPDWORD lpdwSaclSize
,
1058 OUT LPDWORD lpdwOwnerSize
,
1059 OUT PSID pPrimaryGroup
,
1060 OUT LPDWORD lpdwPrimaryGroupSize
)
1062 return set_ntstatus( RtlSelfRelativeToAbsoluteSD(pSelfRelativeSecurityDescriptor
,
1063 pAbsoluteSecurityDescriptor
,
1064 lpdwAbsoluteSecurityDescriptorSize
,
1065 pDacl
, lpdwDaclSize
, pSacl
, lpdwSaclSize
,
1066 pOwner
, lpdwOwnerSize
,
1067 pPrimaryGroup
, lpdwPrimaryGroupSize
));
1070 /******************************************************************************
1071 * GetKernelObjectSecurity [ADVAPI32.@]
1073 BOOL WINAPI
GetKernelObjectSecurity(
1075 SECURITY_INFORMATION RequestedInformation
,
1076 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1078 LPDWORD lpnLengthNeeded
)
1080 TRACE("(%p,0x%08x,%p,0x%08x,%p)\n", Handle
, RequestedInformation
,
1081 pSecurityDescriptor
, nLength
, lpnLengthNeeded
);
1083 return set_ntstatus( NtQuerySecurityObject(Handle
, RequestedInformation
, pSecurityDescriptor
,
1084 nLength
, lpnLengthNeeded
));
1087 /******************************************************************************
1088 * GetPrivateObjectSecurity [ADVAPI32.@]
1090 BOOL WINAPI
GetPrivateObjectSecurity(
1091 PSECURITY_DESCRIPTOR ObjectDescriptor
,
1092 SECURITY_INFORMATION SecurityInformation
,
1093 PSECURITY_DESCRIPTOR ResultantDescriptor
,
1094 DWORD DescriptorLength
,
1095 PDWORD ReturnLength
)
1097 TRACE("(%p,0x%08x,%p,0x%08x,%p)\n", ObjectDescriptor
, SecurityInformation
,
1098 ResultantDescriptor
, DescriptorLength
, ReturnLength
);
1100 return set_ntstatus( NtQuerySecurityObject(ObjectDescriptor
, SecurityInformation
,
1101 ResultantDescriptor
, DescriptorLength
, ReturnLength
));
1104 /******************************************************************************
1105 * GetSecurityDescriptorLength [ADVAPI32.@]
1107 DWORD WINAPI
GetSecurityDescriptorLength( PSECURITY_DESCRIPTOR pDescr
)
1109 return RtlLengthSecurityDescriptor(pDescr
);
1112 /******************************************************************************
1113 * GetSecurityDescriptorOwner [ADVAPI32.@]
1117 * lpbOwnerDefaulted []
1120 GetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pDescr
, PSID
*pOwner
,
1121 LPBOOL lpbOwnerDefaulted
)
1124 BOOL ret
= set_ntstatus( RtlGetOwnerSecurityDescriptor( pDescr
, pOwner
, &defaulted
));
1125 *lpbOwnerDefaulted
= defaulted
;
1129 /******************************************************************************
1130 * SetSecurityDescriptorOwner [ADVAPI32.@]
1134 BOOL WINAPI
SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1135 PSID pOwner
, BOOL bOwnerDefaulted
)
1137 return set_ntstatus( RtlSetOwnerSecurityDescriptor(pSecurityDescriptor
, pOwner
, bOwnerDefaulted
));
1139 /******************************************************************************
1140 * GetSecurityDescriptorGroup [ADVAPI32.@]
1142 BOOL WINAPI
GetSecurityDescriptorGroup(
1143 PSECURITY_DESCRIPTOR SecurityDescriptor
,
1145 LPBOOL GroupDefaulted
)
1148 BOOL ret
= set_ntstatus( RtlGetGroupSecurityDescriptor(SecurityDescriptor
, Group
, &defaulted
));
1149 *GroupDefaulted
= defaulted
;
1152 /******************************************************************************
1153 * SetSecurityDescriptorGroup [ADVAPI32.@]
1155 BOOL WINAPI
SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor
,
1156 PSID Group
, BOOL GroupDefaulted
)
1158 return set_ntstatus( RtlSetGroupSecurityDescriptor( SecurityDescriptor
, Group
, GroupDefaulted
));
1161 /******************************************************************************
1162 * IsValidSecurityDescriptor [ADVAPI32.@]
1168 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor
)
1170 return set_ntstatus( RtlValidSecurityDescriptor(SecurityDescriptor
));
1173 /******************************************************************************
1174 * GetSecurityDescriptorDacl [ADVAPI32.@]
1176 BOOL WINAPI
GetSecurityDescriptorDacl(
1177 IN PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1178 OUT LPBOOL lpbDaclPresent
,
1180 OUT LPBOOL lpbDaclDefaulted
)
1182 BOOLEAN present
, defaulted
;
1183 BOOL ret
= set_ntstatus( RtlGetDaclSecurityDescriptor(pSecurityDescriptor
, &present
, pDacl
, &defaulted
));
1184 *lpbDaclPresent
= present
;
1185 *lpbDaclDefaulted
= defaulted
;
1189 /******************************************************************************
1190 * SetSecurityDescriptorDacl [ADVAPI32.@]
1193 SetSecurityDescriptorDacl (
1194 PSECURITY_DESCRIPTOR lpsd
,
1197 BOOL dacldefaulted
)
1199 return set_ntstatus( RtlSetDaclSecurityDescriptor (lpsd
, daclpresent
, dacl
, dacldefaulted
) );
1201 /******************************************************************************
1202 * GetSecurityDescriptorSacl [ADVAPI32.@]
1204 BOOL WINAPI
GetSecurityDescriptorSacl(
1205 IN PSECURITY_DESCRIPTOR lpsd
,
1206 OUT LPBOOL lpbSaclPresent
,
1208 OUT LPBOOL lpbSaclDefaulted
)
1210 BOOLEAN present
, defaulted
;
1211 BOOL ret
= set_ntstatus( RtlGetSaclSecurityDescriptor(lpsd
, &present
, pSacl
, &defaulted
) );
1212 *lpbSaclPresent
= present
;
1213 *lpbSaclDefaulted
= defaulted
;
1217 /**************************************************************************
1218 * SetSecurityDescriptorSacl [ADVAPI32.@]
1220 BOOL WINAPI
SetSecurityDescriptorSacl (
1221 PSECURITY_DESCRIPTOR lpsd
,
1226 return set_ntstatus (RtlSetSaclSecurityDescriptor(lpsd
, saclpresent
, lpsacl
, sacldefaulted
));
1228 /******************************************************************************
1229 * MakeSelfRelativeSD [ADVAPI32.@]
1238 IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor
,
1239 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor
,
1240 IN OUT LPDWORD lpdwBufferLength
)
1242 return set_ntstatus( RtlMakeSelfRelativeSD( pAbsoluteSecurityDescriptor
,
1243 pSelfRelativeSecurityDescriptor
, lpdwBufferLength
));
1246 /******************************************************************************
1247 * GetSecurityDescriptorControl [ADVAPI32.@]
1250 BOOL WINAPI
GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1251 PSECURITY_DESCRIPTOR_CONTROL pControl
, LPDWORD lpdwRevision
)
1253 return set_ntstatus( RtlGetControlSecurityDescriptor(pSecurityDescriptor
,pControl
,lpdwRevision
));
1256 /* ##############################
1257 ###### ACL FUNCTIONS ######
1258 ##############################
1261 /*************************************************************************
1262 * InitializeAcl [ADVAPI32.@]
1264 BOOL WINAPI
InitializeAcl(PACL acl
, DWORD size
, DWORD rev
)
1266 return set_ntstatus( RtlCreateAcl(acl
, size
, rev
));
1269 BOOL WINAPI
ImpersonateNamedPipeClient( HANDLE hNamedPipe
)
1271 TRACE("(%p)\n", hNamedPipe
);
1273 return set_ntstatus( NtFsControlFile(hNamedPipe
, NULL
, NULL
, NULL
, NULL
,
1274 FSCTL_PIPE_IMPERSONATE
, NULL
, 0, NULL
, 0) );
1277 /******************************************************************************
1278 * AddAccessAllowedAce [ADVAPI32.@]
1280 BOOL WINAPI
AddAccessAllowedAce(
1282 IN DWORD dwAceRevision
,
1283 IN DWORD AccessMask
,
1286 return set_ntstatus(RtlAddAccessAllowedAce(pAcl
, dwAceRevision
, AccessMask
, pSid
));
1289 /******************************************************************************
1290 * AddAccessAllowedAceEx [ADVAPI32.@]
1292 BOOL WINAPI
AddAccessAllowedAceEx(
1294 IN DWORD dwAceRevision
,
1296 IN DWORD AccessMask
,
1299 return set_ntstatus(RtlAddAccessAllowedAceEx(pAcl
, dwAceRevision
, AceFlags
, AccessMask
, pSid
));
1302 /******************************************************************************
1303 * AddAccessDeniedAce [ADVAPI32.@]
1305 BOOL WINAPI
AddAccessDeniedAce(
1307 IN DWORD dwAceRevision
,
1308 IN DWORD AccessMask
,
1311 return set_ntstatus(RtlAddAccessDeniedAce(pAcl
, dwAceRevision
, AccessMask
, pSid
));
1314 /******************************************************************************
1315 * AddAccessDeniedAceEx [ADVAPI32.@]
1317 BOOL WINAPI
AddAccessDeniedAceEx(
1319 IN DWORD dwAceRevision
,
1321 IN DWORD AccessMask
,
1324 return set_ntstatus(RtlAddAccessDeniedAceEx(pAcl
, dwAceRevision
, AceFlags
, AccessMask
, pSid
));
1327 /******************************************************************************
1328 * AddAce [ADVAPI32.@]
1332 IN DWORD dwAceRevision
,
1333 IN DWORD dwStartingAceIndex
,
1335 DWORD nAceListLength
)
1337 return set_ntstatus(RtlAddAce(pAcl
, dwAceRevision
, dwStartingAceIndex
, pAceList
, nAceListLength
));
1340 /******************************************************************************
1341 * DeleteAce [ADVAPI32.@]
1343 BOOL WINAPI
DeleteAce(PACL pAcl
, DWORD dwAceIndex
)
1345 return set_ntstatus(RtlDeleteAce(pAcl
, dwAceIndex
));
1348 /******************************************************************************
1349 * FindFirstFreeAce [ADVAPI32.@]
1351 BOOL WINAPI
FindFirstFreeAce(IN PACL pAcl
, LPVOID
* pAce
)
1353 return RtlFirstFreeAce(pAcl
, (PACE_HEADER
*)pAce
);
1356 /******************************************************************************
1357 * GetAce [ADVAPI32.@]
1359 BOOL WINAPI
GetAce(PACL pAcl
,DWORD dwAceIndex
,LPVOID
*pAce
)
1361 return set_ntstatus(RtlGetAce(pAcl
, dwAceIndex
, pAce
));
1364 /******************************************************************************
1365 * GetAclInformation [ADVAPI32.@]
1367 BOOL WINAPI
GetAclInformation(
1369 LPVOID pAclInformation
,
1370 DWORD nAclInformationLength
,
1371 ACL_INFORMATION_CLASS dwAclInformationClass
)
1373 return set_ntstatus(RtlQueryInformationAcl(pAcl
, pAclInformation
,
1374 nAclInformationLength
, dwAclInformationClass
));
1377 /******************************************************************************
1378 * IsValidAcl [ADVAPI32.@]
1380 BOOL WINAPI
IsValidAcl(IN PACL pAcl
)
1382 return RtlValidAcl(pAcl
);
1385 /* ##############################
1386 ###### MISC FUNCTIONS ######
1387 ##############################
1390 /******************************************************************************
1391 * AllocateLocallyUniqueId [ADVAPI32.@]
1396 BOOL WINAPI
AllocateLocallyUniqueId( PLUID lpLuid
)
1398 return set_ntstatus(NtAllocateLocallyUniqueId(lpLuid
));
1401 static const WCHAR SE_CREATE_TOKEN_NAME_W
[] =
1402 { 'S','e','C','r','e','a','t','e','T','o','k','e','n','P','r','i','v','i','l','e','g','e',0 };
1403 static const WCHAR SE_ASSIGNPRIMARYTOKEN_NAME_W
[] =
1404 { '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 };
1405 static const WCHAR SE_LOCK_MEMORY_NAME_W
[] =
1406 { 'S','e','L','o','c','k','M','e','m','o','r','y','P','r','i','v','i','l','e','g','e',0 };
1407 static const WCHAR SE_INCREASE_QUOTA_NAME_W
[] =
1408 { '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 };
1409 static const WCHAR SE_MACHINE_ACCOUNT_NAME_W
[] =
1410 { '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 };
1411 static const WCHAR SE_TCB_NAME_W
[] =
1412 { 'S','e','T','c','b','P','r','i','v','i','l','e','g','e',0 };
1413 static const WCHAR SE_SECURITY_NAME_W
[] =
1414 { 'S','e','S','e','c','u','r','i','t','y','P','r','i','v','i','l','e','g','e',0 };
1415 static const WCHAR SE_TAKE_OWNERSHIP_NAME_W
[] =
1416 { '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 };
1417 static const WCHAR SE_LOAD_DRIVER_NAME_W
[] =
1418 { 'S','e','L','o','a','d','D','r','i','v','e','r','P','r','i','v','i','l','e','g','e',0 };
1419 static const WCHAR SE_SYSTEM_PROFILE_NAME_W
[] =
1420 { '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 };
1421 static const WCHAR SE_SYSTEMTIME_NAME_W
[] =
1422 { 'S','e','S','y','s','t','e','m','t','i','m','e','P','r','i','v','i','l','e','g','e',0 };
1423 static const WCHAR SE_PROF_SINGLE_PROCESS_NAME_W
[] =
1424 { '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 };
1425 static const WCHAR SE_INC_BASE_PRIORITY_NAME_W
[] =
1426 { '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 };
1427 static const WCHAR SE_CREATE_PAGEFILE_NAME_W
[] =
1428 { '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 };
1429 static const WCHAR SE_CREATE_PERMANENT_NAME_W
[] =
1430 { '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 };
1431 static const WCHAR SE_BACKUP_NAME_W
[] =
1432 { 'S','e','B','a','c','k','u','p','P','r','i','v','i','l','e','g','e',0 };
1433 static const WCHAR SE_RESTORE_NAME_W
[] =
1434 { 'S','e','R','e','s','t','o','r','e','P','r','i','v','i','l','e','g','e',0 };
1435 static const WCHAR SE_SHUTDOWN_NAME_W
[] =
1436 { 'S','e','S','h','u','t','d','o','w','n','P','r','i','v','i','l','e','g','e',0 };
1437 static const WCHAR SE_DEBUG_NAME_W
[] =
1438 { 'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0 };
1439 static const WCHAR SE_AUDIT_NAME_W
[] =
1440 { 'S','e','A','u','d','i','t','P','r','i','v','i','l','e','g','e',0 };
1441 static const WCHAR SE_SYSTEM_ENVIRONMENT_NAME_W
[] =
1442 { '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 };
1443 static const WCHAR SE_CHANGE_NOTIFY_NAME_W
[] =
1444 { 'S','e','C','h','a','n','g','e','N','o','t','i','f','y','P','r','i','v','i','l','e','g','e',0 };
1445 static const WCHAR SE_REMOTE_SHUTDOWN_NAME_W
[] =
1446 { '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 };
1447 static const WCHAR SE_UNDOCK_NAME_W
[] =
1448 { 'S','e','U','n','d','o','c','k','P','r','i','v','i','l','e','g','e',0 };
1449 static const WCHAR SE_SYNC_AGENT_NAME_W
[] =
1450 { 'S','e','S','y','n','c','A','g','e','n','t','P','r','i','v','i','l','e','g','e',0 };
1451 static const WCHAR SE_ENABLE_DELEGATION_NAME_W
[] =
1452 { '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 };
1453 static const WCHAR SE_MANAGE_VOLUME_NAME_W
[] =
1454 { 'S','e','M','a','n','a','g','e','V','o','l','u','m','e','P','r','i','v','i','l','e','g','e',0 };
1455 static const WCHAR SE_IMPERSONATE_NAME_W
[] =
1456 { 'S','e','I','m','p','e','r','s','o','n','a','t','e','P','r','i','v','i','l','e','g','e',0 };
1457 static const WCHAR SE_CREATE_GLOBAL_NAME_W
[] =
1458 { 'S','e','C','r','e','a','t','e','G','l','o','b','a','l','P','r','i','v','i','l','e','g','e',0 };
1460 static const WCHAR
* const WellKnownPrivNames
[SE_MAX_WELL_KNOWN_PRIVILEGE
+ 1] =
1464 SE_CREATE_TOKEN_NAME_W
,
1465 SE_ASSIGNPRIMARYTOKEN_NAME_W
,
1466 SE_LOCK_MEMORY_NAME_W
,
1467 SE_INCREASE_QUOTA_NAME_W
,
1468 SE_MACHINE_ACCOUNT_NAME_W
,
1471 SE_TAKE_OWNERSHIP_NAME_W
,
1472 SE_LOAD_DRIVER_NAME_W
,
1473 SE_SYSTEM_PROFILE_NAME_W
,
1474 SE_SYSTEMTIME_NAME_W
,
1475 SE_PROF_SINGLE_PROCESS_NAME_W
,
1476 SE_INC_BASE_PRIORITY_NAME_W
,
1477 SE_CREATE_PAGEFILE_NAME_W
,
1478 SE_CREATE_PERMANENT_NAME_W
,
1484 SE_SYSTEM_ENVIRONMENT_NAME_W
,
1485 SE_CHANGE_NOTIFY_NAME_W
,
1486 SE_REMOTE_SHUTDOWN_NAME_W
,
1488 SE_SYNC_AGENT_NAME_W
,
1489 SE_ENABLE_DELEGATION_NAME_W
,
1490 SE_MANAGE_VOLUME_NAME_W
,
1491 SE_IMPERSONATE_NAME_W
,
1492 SE_CREATE_GLOBAL_NAME_W
,
1495 /******************************************************************************
1496 * LookupPrivilegeValueW [ADVAPI32.@]
1498 * See LookupPrivilegeValueA.
1501 LookupPrivilegeValueW( LPCWSTR lpSystemName
, LPCWSTR lpName
, PLUID lpLuid
)
1505 TRACE("%s,%s,%p\n",debugstr_w(lpSystemName
), debugstr_w(lpName
), lpLuid
);
1507 if (!ADVAPI_IsLocalComputer(lpSystemName
))
1509 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
1514 SetLastError(ERROR_NO_SUCH_PRIVILEGE
);
1517 for( i
=SE_MIN_WELL_KNOWN_PRIVILEGE
; i
<SE_MAX_WELL_KNOWN_PRIVILEGE
; i
++ )
1519 if( !WellKnownPrivNames
[i
] )
1521 if( strcmpiW( WellKnownPrivNames
[i
], lpName
) )
1523 lpLuid
->LowPart
= i
;
1524 lpLuid
->HighPart
= 0;
1525 TRACE( "%s -> %08x-%08x\n",debugstr_w( lpSystemName
),
1526 lpLuid
->HighPart
, lpLuid
->LowPart
);
1529 SetLastError(ERROR_NO_SUCH_PRIVILEGE
);
1533 /******************************************************************************
1534 * LookupPrivilegeValueA [ADVAPI32.@]
1536 * Retrieves LUID used on a system to represent the privilege name.
1539 * lpSystemName [I] Name of the system
1540 * lpName [I] Name of the privilege
1541 * lpLuid [O] Destination for the resulting LUID
1544 * Success: TRUE. lpLuid contains the requested LUID.
1548 LookupPrivilegeValueA( LPCSTR lpSystemName
, LPCSTR lpName
, PLUID lpLuid
)
1550 UNICODE_STRING lpSystemNameW
;
1551 UNICODE_STRING lpNameW
;
1554 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW
, lpSystemName
);
1555 RtlCreateUnicodeStringFromAsciiz(&lpNameW
,lpName
);
1556 ret
= LookupPrivilegeValueW(lpSystemNameW
.Buffer
, lpNameW
.Buffer
, lpLuid
);
1557 RtlFreeUnicodeString(&lpNameW
);
1558 RtlFreeUnicodeString(&lpSystemNameW
);
1562 BOOL WINAPI
LookupPrivilegeDisplayNameA( LPCSTR lpSystemName
, LPCSTR lpName
, LPSTR lpDisplayName
,
1563 LPDWORD cchDisplayName
, LPDWORD lpLanguageId
)
1565 FIXME("%s %s %s %p %p - stub\n", debugstr_a(lpSystemName
), debugstr_a(lpName
),
1566 debugstr_a(lpDisplayName
), cchDisplayName
, lpLanguageId
);
1571 BOOL WINAPI
LookupPrivilegeDisplayNameW( LPCWSTR lpSystemName
, LPCWSTR lpName
, LPWSTR lpDisplayName
,
1572 LPDWORD cchDisplayName
, LPDWORD lpLanguageId
)
1574 FIXME("%s %s %s %p %p - stub\n", debugstr_w(lpSystemName
), debugstr_w(lpName
),
1575 debugstr_w(lpDisplayName
), cchDisplayName
, lpLanguageId
);
1580 /******************************************************************************
1581 * LookupPrivilegeNameA [ADVAPI32.@]
1583 * See LookupPrivilegeNameW.
1586 LookupPrivilegeNameA( LPCSTR lpSystemName
, PLUID lpLuid
, LPSTR lpName
,
1589 UNICODE_STRING lpSystemNameW
;
1593 TRACE("%s %p %p %p\n", debugstr_a(lpSystemName
), lpLuid
, lpName
, cchName
);
1595 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW
, lpSystemName
);
1596 ret
= LookupPrivilegeNameW(lpSystemNameW
.Buffer
, lpLuid
, NULL
, &wLen
);
1597 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1599 LPWSTR lpNameW
= HeapAlloc(GetProcessHeap(), 0, wLen
* sizeof(WCHAR
));
1601 ret
= LookupPrivilegeNameW(lpSystemNameW
.Buffer
, lpLuid
, lpNameW
,
1605 /* Windows crashes if cchName is NULL, so will I */
1606 int len
= WideCharToMultiByte(CP_ACP
, 0, lpNameW
, -1, lpName
,
1607 *cchName
, NULL
, NULL
);
1611 /* WideCharToMultiByte failed */
1614 else if (len
> *cchName
)
1617 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1622 /* WideCharToMultiByte succeeded, output length needs to be
1623 * length not including NULL terminator
1628 HeapFree(GetProcessHeap(), 0, lpNameW
);
1630 RtlFreeUnicodeString(&lpSystemNameW
);
1634 /******************************************************************************
1635 * LookupPrivilegeNameW [ADVAPI32.@]
1637 * Retrieves the privilege name referred to by the LUID lpLuid.
1640 * lpSystemName [I] Name of the system
1641 * lpLuid [I] Privilege value
1642 * lpName [O] Name of the privilege
1643 * cchName [I/O] Number of characters in lpName.
1646 * Success: TRUE. lpName contains the name of the privilege whose value is
1651 * Only well-known privilege names (those defined in winnt.h) can be retrieved
1652 * using this function.
1653 * If the length of lpName is too small, on return *cchName will contain the
1654 * number of WCHARs needed to contain the privilege, including the NULL
1655 * terminator, and GetLastError will return ERROR_INSUFFICIENT_BUFFER.
1656 * On success, *cchName will contain the number of characters stored in
1657 * lpName, NOT including the NULL terminator.
1660 LookupPrivilegeNameW( LPCWSTR lpSystemName
, PLUID lpLuid
, LPWSTR lpName
,
1665 TRACE("%s,%p,%p,%p\n",debugstr_w(lpSystemName
), lpLuid
, lpName
, cchName
);
1667 if (!ADVAPI_IsLocalComputer(lpSystemName
))
1669 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
1672 if (lpLuid
->HighPart
|| (lpLuid
->LowPart
< SE_MIN_WELL_KNOWN_PRIVILEGE
||
1673 lpLuid
->LowPart
> SE_MAX_WELL_KNOWN_PRIVILEGE
))
1675 SetLastError(ERROR_NO_SUCH_PRIVILEGE
);
1678 privNameLen
= strlenW(WellKnownPrivNames
[lpLuid
->LowPart
]);
1679 /* Windows crashes if cchName is NULL, so will I */
1680 if (*cchName
<= privNameLen
)
1682 *cchName
= privNameLen
+ 1;
1683 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1688 strcpyW(lpName
, WellKnownPrivNames
[lpLuid
->LowPart
]);
1689 *cchName
= privNameLen
;
1694 /******************************************************************************
1695 * GetFileSecurityA [ADVAPI32.@]
1697 * Obtains Specified information about the security of a file or directory.
1700 * lpFileName [I] Name of the file to get info for
1701 * RequestedInformation [I] SE_ flags from "winnt.h"
1702 * pSecurityDescriptor [O] Destination for security information
1703 * nLength [I] Length of pSecurityDescriptor
1704 * lpnLengthNeeded [O] Destination for length of returned security information
1707 * Success: TRUE. pSecurityDescriptor contains the requested information.
1708 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
1711 * The information returned is constrained by the callers access rights and
1715 GetFileSecurityA( LPCSTR lpFileName
,
1716 SECURITY_INFORMATION RequestedInformation
,
1717 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1718 DWORD nLength
, LPDWORD lpnLengthNeeded
)
1726 len
= MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, NULL
, 0 );
1727 name
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
1728 MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, name
, len
);
1731 r
= GetFileSecurityW( name
, RequestedInformation
, pSecurityDescriptor
,
1732 nLength
, lpnLengthNeeded
);
1733 HeapFree( GetProcessHeap(), 0, name
);
1738 /******************************************************************************
1739 * GetFileSecurityW [ADVAPI32.@]
1741 * See GetFileSecurityA.
1744 GetFileSecurityW( LPCWSTR lpFileName
,
1745 SECURITY_INFORMATION RequestedInformation
,
1746 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1747 DWORD nLength
, LPDWORD lpnLengthNeeded
)
1752 SECURITY_DESCRIPTOR_RELATIVE
*pSDRelative
;
1754 if(INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(lpFileName
))
1757 FIXME("(%s) : returns fake SECURITY_DESCRIPTOR\n", debugstr_w(lpFileName
) );
1759 nNeeded
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
1760 if (RequestedInformation
& OWNER_SECURITY_INFORMATION
)
1761 nNeeded
+= sizeof(sidWorld
);
1762 if (RequestedInformation
& GROUP_SECURITY_INFORMATION
)
1763 nNeeded
+= sizeof(sidWorld
);
1764 if (RequestedInformation
& DACL_SECURITY_INFORMATION
)
1765 nNeeded
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
1766 if (RequestedInformation
& SACL_SECURITY_INFORMATION
)
1767 nNeeded
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
1769 *lpnLengthNeeded
= nNeeded
;
1771 if (nNeeded
> nLength
)
1774 if (!InitializeSecurityDescriptor(pSecurityDescriptor
, SECURITY_DESCRIPTOR_REVISION
))
1777 pSDRelative
= (PISECURITY_DESCRIPTOR_RELATIVE
) pSecurityDescriptor
;
1778 pSDRelative
->Control
|= SE_SELF_RELATIVE
;
1779 pBuffer
= (LPBYTE
) pSDRelative
;
1780 iLocNow
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
1782 if (RequestedInformation
& OWNER_SECURITY_INFORMATION
)
1784 memcpy(pBuffer
+ iLocNow
, &sidWorld
, sizeof(sidWorld
));
1785 pSDRelative
->Owner
= iLocNow
;
1786 iLocNow
+= sizeof(sidWorld
);
1788 if (RequestedInformation
& GROUP_SECURITY_INFORMATION
)
1790 memcpy(pBuffer
+ iLocNow
, &sidWorld
, sizeof(sidWorld
));
1791 pSDRelative
->Group
= iLocNow
;
1792 iLocNow
+= sizeof(sidWorld
);
1794 if (RequestedInformation
& DACL_SECURITY_INFORMATION
)
1796 GetWorldAccessACL((PACL
) (pBuffer
+ iLocNow
));
1797 pSDRelative
->Dacl
= iLocNow
;
1798 iLocNow
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
1800 if (RequestedInformation
& SACL_SECURITY_INFORMATION
)
1802 GetWorldAccessACL((PACL
) (pBuffer
+ iLocNow
));
1803 pSDRelative
->Sacl
= iLocNow
;
1804 /* iLocNow += WINE_SIZE_OF_WORLD_ACCESS_ACL; */
1810 /******************************************************************************
1811 * LookupAccountSidA [ADVAPI32.@]
1818 IN OUT LPDWORD accountSize
,
1820 IN OUT LPDWORD domainSize
,
1821 OUT PSID_NAME_USE name_use
)
1825 LPWSTR systemW
= NULL
;
1826 LPWSTR accountW
= NULL
;
1827 LPWSTR domainW
= NULL
;
1828 DWORD accountSizeW
= *accountSize
;
1829 DWORD domainSizeW
= *domainSize
;
1831 TRACE("(%s,sid=%s,%p,%p(%u),%p,%p(%u),%p)\n",
1832 debugstr_a(system
),debugstr_sid(sid
),
1833 account
,accountSize
,accountSize
?*accountSize
:0,
1834 domain
,domainSize
,domainSize
?*domainSize
:0,
1838 len
= MultiByteToWideChar( CP_ACP
, 0, system
, -1, NULL
, 0 );
1839 systemW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1840 MultiByteToWideChar( CP_ACP
, 0, system
, -1, systemW
, len
);
1843 accountW
= HeapAlloc( GetProcessHeap(), 0, accountSizeW
* sizeof(WCHAR
) );
1845 domainW
= HeapAlloc( GetProcessHeap(), 0, domainSizeW
* sizeof(WCHAR
) );
1847 r
= LookupAccountSidW( systemW
, sid
, accountW
, &accountSizeW
, domainW
, &domainSizeW
, name_use
);
1850 if (accountW
&& *accountSize
) {
1851 len
= WideCharToMultiByte( CP_ACP
, 0, accountW
, -1, NULL
, 0, NULL
, NULL
);
1852 WideCharToMultiByte( CP_ACP
, 0, accountW
, -1, account
, len
, NULL
, NULL
);
1855 *accountSize
= accountSizeW
+ 1;
1857 if (domainW
&& *domainSize
) {
1858 len
= WideCharToMultiByte( CP_ACP
, 0, domainW
, -1, NULL
, 0, NULL
, NULL
);
1859 WideCharToMultiByte( CP_ACP
, 0, domainW
, -1, domain
, len
, NULL
, NULL
);
1862 *domainSize
= domainSizeW
+ 1;
1865 HeapFree( GetProcessHeap(), 0, systemW
);
1866 HeapFree( GetProcessHeap(), 0, accountW
);
1867 HeapFree( GetProcessHeap(), 0, domainW
);
1872 /******************************************************************************
1873 * LookupAccountSidW [ADVAPI32.@]
1890 IN OUT LPDWORD accountSize
,
1892 IN OUT LPDWORD domainSize
,
1893 OUT PSID_NAME_USE name_use
)
1896 const WCHAR
* ac
= NULL
;
1897 const WCHAR
* dm
= NULL
;
1898 SID_NAME_USE use
= 0;
1899 LPWSTR computer_name
= NULL
;
1901 TRACE("(%s,sid=%s,%p,%p(%u),%p,%p(%u),%p)\n",
1902 debugstr_w(system
),debugstr_sid(sid
),
1903 account
,accountSize
,accountSize
?*accountSize
:0,
1904 domain
,domainSize
,domainSize
?*domainSize
:0,
1907 if (!ADVAPI_IsLocalComputer(system
)) {
1908 FIXME("Only local computer supported!\n");
1909 SetLastError(ERROR_NONE_MAPPED
);
1913 /* check the well known SIDs first */
1914 for (i
= 0; i
<= 60; i
++) {
1915 if (IsWellKnownSid(sid
, i
)) {
1916 for (j
= 0; j
< (sizeof(ACCOUNT_SIDS
) / sizeof(ACCOUNT_SIDS
[0])); j
++) {
1917 if (ACCOUNT_SIDS
[j
].type
== i
) {
1918 ac
= ACCOUNT_SIDS
[j
].account
;
1919 dm
= ACCOUNT_SIDS
[j
].domain
;
1920 use
= ACCOUNT_SIDS
[j
].name_use
;
1930 /* check for the local computer next */
1931 if (ADVAPI_GetComputerSid(&local
)) {
1932 DWORD size
= MAX_COMPUTERNAME_LENGTH
+ 1;
1935 computer_name
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
1936 result
= GetComputerNameW(computer_name
, &size
);
1939 if (EqualSid(sid
, &local
)) {
1944 local
.SubAuthorityCount
++;
1946 if (EqualPrefixSid(sid
, &local
)) {
1949 switch (((MAX_SID
*)sid
)->SubAuthority
[4]) {
1950 case DOMAIN_USER_RID_ADMIN
:
1953 case DOMAIN_USER_RID_GUEST
:
1956 case DOMAIN_GROUP_RID_ADMINS
:
1959 case DOMAIN_GROUP_RID_USERS
:
1962 case DOMAIN_GROUP_RID_GUESTS
:
1965 case DOMAIN_GROUP_RID_COMPUTERS
:
1966 ac
= Domain_Computers
;
1968 case DOMAIN_GROUP_RID_CONTROLLERS
:
1969 ac
= Domain_Controllers
;
1971 case DOMAIN_GROUP_RID_CERT_ADMINS
:
1972 ac
= Cert_Publishers
;
1974 case DOMAIN_GROUP_RID_SCHEMA_ADMINS
:
1977 case DOMAIN_GROUP_RID_ENTERPRISE_ADMINS
:
1978 ac
= Enterprise_Admins
;
1980 case DOMAIN_GROUP_RID_POLICY_ADMINS
:
1981 ac
= Group_Policy_Creator_Owners
;
1983 case DOMAIN_ALIAS_RID_RAS_SERVERS
:
1984 ac
= RAS_and_IAS_Servers
;
1998 if (*accountSize
> lstrlenW(ac
)) {
2000 lstrcpyW(account
, ac
);
2002 if (*domainSize
> lstrlenW(dm
)) {
2004 lstrcpyW(domain
, dm
);
2006 if (((*accountSize
!= 0) && (*accountSize
< strlenW(ac
))) ||
2007 ((*domainSize
!= 0) && (*domainSize
< strlenW(dm
)))) {
2008 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2012 *domainSize
= strlenW(dm
);
2014 *domainSize
= strlenW(dm
) + 1;
2016 *accountSize
= strlenW(ac
);
2018 *accountSize
= strlenW(ac
) + 1;
2020 HeapFree(GetProcessHeap(), 0, computer_name
);
2024 HeapFree(GetProcessHeap(), 0, computer_name
);
2025 SetLastError(ERROR_NONE_MAPPED
);
2029 /******************************************************************************
2030 * SetFileSecurityA [ADVAPI32.@]
2032 * See SetFileSecurityW.
2034 BOOL WINAPI
SetFileSecurityA( LPCSTR lpFileName
,
2035 SECURITY_INFORMATION RequestedInformation
,
2036 PSECURITY_DESCRIPTOR pSecurityDescriptor
)
2044 len
= MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, NULL
, 0 );
2045 name
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
2046 MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, name
, len
);
2049 r
= SetFileSecurityW( name
, RequestedInformation
, pSecurityDescriptor
);
2050 HeapFree( GetProcessHeap(), 0, name
);
2055 /******************************************************************************
2056 * SetFileSecurityW [ADVAPI32.@]
2058 * Sets the security of a file or directory.
2062 * RequestedInformation []
2063 * pSecurityDescriptor []
2070 SetFileSecurityW( LPCWSTR lpFileName
,
2071 SECURITY_INFORMATION RequestedInformation
,
2072 PSECURITY_DESCRIPTOR pSecurityDescriptor
)
2074 FIXME("(%s) : stub\n", debugstr_w(lpFileName
) );
2078 /******************************************************************************
2079 * QueryWindows31FilesMigration [ADVAPI32.@]
2085 QueryWindows31FilesMigration( DWORD x1
)
2087 FIXME("(%d):stub\n",x1
);
2091 /******************************************************************************
2092 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
2101 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1
, DWORD x2
, DWORD x3
,
2104 FIXME("(0x%08x,0x%08x,0x%08x,0x%08x):stub\n",x1
,x2
,x3
,x4
);
2108 /******************************************************************************
2109 * NotifyBootConfigStatus [ADVAPI32.@]
2115 NotifyBootConfigStatus( BOOL x1
)
2117 FIXME("(0x%08d):stub\n",x1
);
2121 /******************************************************************************
2122 * RevertToSelf [ADVAPI32.@]
2124 * Ends the impersonation of a user.
2134 RevertToSelf( void )
2136 HANDLE Token
= NULL
;
2137 return set_ntstatus( NtSetInformationThread( GetCurrentThread(),
2138 ThreadImpersonationToken
, &Token
, sizeof(Token
) ) );
2141 /******************************************************************************
2142 * ImpersonateSelf [ADVAPI32.@]
2144 * Makes an impersonation token that represents the process user and assigns
2145 * to the current thread.
2148 * ImpersonationLevel [I] Level at which to impersonate.
2155 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
)
2157 return set_ntstatus( RtlImpersonateSelf( ImpersonationLevel
) );
2160 /******************************************************************************
2161 * ImpersonateLoggedOnUser [ADVAPI32.@]
2163 BOOL WINAPI
ImpersonateLoggedOnUser(HANDLE hToken
)
2167 HANDLE ImpersonationToken
;
2170 FIXME( "(%p)\n", hToken
);
2172 if (!GetTokenInformation( hToken
, TokenType
, &Type
,
2173 sizeof(TOKEN_TYPE
), &size
))
2176 if (Type
== TokenPrimary
)
2178 OBJECT_ATTRIBUTES ObjectAttributes
;
2180 InitializeObjectAttributes( &ObjectAttributes
, NULL
, 0, NULL
, NULL
);
2182 Status
= NtDuplicateToken( hToken
,
2183 TOKEN_IMPERSONATE
| TOKEN_QUERY
,
2185 SecurityImpersonation
,
2187 &ImpersonationToken
);
2188 if (Status
!= STATUS_SUCCESS
)
2190 ERR( "NtDuplicateToken failed with error 0x%08x\n", Status
);
2191 SetLastError( RtlNtStatusToDosError( Status
) );
2196 ImpersonationToken
= hToken
;
2198 Status
= NtSetInformationThread( GetCurrentThread(),
2199 ThreadImpersonationToken
,
2200 &ImpersonationToken
,
2201 sizeof(ImpersonationToken
) );
2203 if (Type
== TokenPrimary
)
2204 NtClose( ImpersonationToken
);
2206 if (Status
!= STATUS_SUCCESS
)
2208 ERR( "NtSetInformationThread failed with error 0x%08x\n", Status
);
2209 SetLastError( RtlNtStatusToDosError( Status
) );
2216 /******************************************************************************
2217 * AccessCheck [ADVAPI32.@]
2221 PSECURITY_DESCRIPTOR SecurityDescriptor
,
2223 DWORD DesiredAccess
,
2224 PGENERIC_MAPPING GenericMapping
,
2225 PPRIVILEGE_SET PrivilegeSet
,
2226 LPDWORD PrivilegeSetLength
,
2227 LPDWORD GrantedAccess
,
2228 LPBOOL AccessStatus
)
2230 NTSTATUS access_status
;
2231 BOOL ret
= set_ntstatus( NtAccessCheck(SecurityDescriptor
, ClientToken
, DesiredAccess
,
2232 GenericMapping
, PrivilegeSet
, PrivilegeSetLength
,
2233 GrantedAccess
, &access_status
) );
2234 if (ret
) *AccessStatus
= set_ntstatus( access_status
);
2239 /******************************************************************************
2240 * AccessCheckByType [ADVAPI32.@]
2242 BOOL WINAPI
AccessCheckByType(
2243 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
2244 PSID PrincipalSelfSid
,
2246 DWORD DesiredAccess
,
2247 POBJECT_TYPE_LIST ObjectTypeList
,
2248 DWORD ObjectTypeListLength
,
2249 PGENERIC_MAPPING GenericMapping
,
2250 PPRIVILEGE_SET PrivilegeSet
,
2251 LPDWORD PrivilegeSetLength
,
2252 LPDWORD GrantedAccess
,
2253 LPBOOL AccessStatus
)
2257 *AccessStatus
= TRUE
;
2259 return !*AccessStatus
;
2262 /******************************************************************************
2263 * MapGenericMask [ADVAPI32.@]
2265 * Maps generic access rights into specific access rights according to the
2269 * AccessMask [I/O] Access rights.
2270 * GenericMapping [I] The mapping between generic and specific rights.
2275 VOID WINAPI
MapGenericMask( PDWORD AccessMask
, PGENERIC_MAPPING GenericMapping
)
2277 RtlMapGenericMask( AccessMask
, GenericMapping
);
2280 /*************************************************************************
2281 * SetKernelObjectSecurity [ADVAPI32.@]
2283 BOOL WINAPI
SetKernelObjectSecurity (
2285 IN SECURITY_INFORMATION SecurityInformation
,
2286 IN PSECURITY_DESCRIPTOR SecurityDescriptor
)
2288 return set_ntstatus (NtSetSecurityObject (Handle
, SecurityInformation
, SecurityDescriptor
));
2292 /******************************************************************************
2293 * AddAuditAccessAce [ADVAPI32.@]
2295 BOOL WINAPI
AddAuditAccessAce(
2297 IN DWORD dwAceRevision
,
2298 IN DWORD dwAccessMask
,
2300 IN BOOL bAuditSuccess
,
2301 IN BOOL bAuditFailure
)
2303 return set_ntstatus( RtlAddAuditAccessAce(pAcl
, dwAceRevision
, dwAccessMask
, pSid
,
2304 bAuditSuccess
, bAuditFailure
) );
2307 /******************************************************************************
2308 * LookupAccountNameA [ADVAPI32.@]
2316 LPSTR ReferencedDomainName
,
2317 IN OUT LPDWORD cbReferencedDomainName
,
2318 OUT PSID_NAME_USE name_use
)
2321 UNICODE_STRING lpSystemW
;
2322 UNICODE_STRING lpAccountW
;
2323 LPWSTR lpReferencedDomainNameW
= NULL
;
2325 RtlCreateUnicodeStringFromAsciiz(&lpSystemW
, system
);
2326 RtlCreateUnicodeStringFromAsciiz(&lpAccountW
, account
);
2328 if (ReferencedDomainName
)
2329 lpReferencedDomainNameW
= HeapAlloc(GetProcessHeap(), 0, *cbReferencedDomainName
* sizeof(WCHAR
));
2331 ret
= LookupAccountNameW(lpSystemW
.Buffer
, lpAccountW
.Buffer
, sid
, cbSid
, lpReferencedDomainNameW
,
2332 cbReferencedDomainName
, name_use
);
2334 if (ret
&& lpReferencedDomainNameW
)
2336 WideCharToMultiByte(CP_ACP
, 0, lpReferencedDomainNameW
, *cbReferencedDomainName
,
2337 ReferencedDomainName
, *cbReferencedDomainName
, NULL
, NULL
);
2340 RtlFreeUnicodeString(&lpSystemW
);
2341 RtlFreeUnicodeString(&lpAccountW
);
2342 HeapFree(GetProcessHeap(), 0, lpReferencedDomainNameW
);
2347 /******************************************************************************
2348 * LookupAccountNameW [ADVAPI32.@]
2350 BOOL WINAPI
LookupAccountNameW( LPCWSTR lpSystemName
, LPCWSTR lpAccountName
, PSID Sid
,
2351 LPDWORD cbSid
, LPWSTR ReferencedDomainName
,
2352 LPDWORD cchReferencedDomainName
, PSID_NAME_USE peUse
)
2354 /* Default implementation: Always return a default SID */
2355 SID_IDENTIFIER_AUTHORITY identifierAuthority
= {SECURITY_NT_AUTHORITY
};
2358 static const WCHAR dm
[] = {'D','O','M','A','I','N',0};
2360 FIXME("%s %s %p %p %p %p %p - stub\n", debugstr_w(lpSystemName
), debugstr_w(lpAccountName
),
2361 Sid
, cbSid
, ReferencedDomainName
, cchReferencedDomainName
, peUse
);
2363 ret
= AllocateAndInitializeSid(&identifierAuthority
,
2365 SECURITY_BUILTIN_DOMAIN_RID
,
2366 DOMAIN_ALIAS_RID_ADMINS
,
2373 if (!RtlValidSid(pSid
))
2379 if (Sid
!= NULL
&& (*cbSid
>= GetLengthSid(pSid
)))
2380 CopySid(*cbSid
, Sid
, pSid
);
2381 if (*cbSid
< GetLengthSid(pSid
))
2383 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2386 *cbSid
= GetLengthSid(pSid
);
2388 if (ReferencedDomainName
!= NULL
&& (*cchReferencedDomainName
> strlenW(dm
)))
2389 strcpyW(ReferencedDomainName
, dm
);
2391 if (*cchReferencedDomainName
<= strlenW(dm
))
2393 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2397 *cchReferencedDomainName
= strlenW(dm
)+1;
2404 /******************************************************************************
2405 * PrivilegeCheck [ADVAPI32.@]
2407 BOOL WINAPI
PrivilegeCheck( HANDLE ClientToken
, PPRIVILEGE_SET RequiredPrivileges
, LPBOOL pfResult
)
2412 TRACE("%p %p %p\n", ClientToken
, RequiredPrivileges
, pfResult
);
2414 ret
= set_ntstatus (NtPrivilegeCheck (ClientToken
, RequiredPrivileges
, &Result
));
2420 /******************************************************************************
2421 * AccessCheckAndAuditAlarmA [ADVAPI32.@]
2423 BOOL WINAPI
AccessCheckAndAuditAlarmA(LPCSTR Subsystem
, LPVOID HandleId
, LPSTR ObjectTypeName
,
2424 LPSTR ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
, DWORD DesiredAccess
,
2425 PGENERIC_MAPPING GenericMapping
, BOOL ObjectCreation
, LPDWORD GrantedAccess
,
2426 LPBOOL AccessStatus
, LPBOOL pfGenerateOnClose
)
2428 FIXME("stub (%s,%p,%s,%s,%p,%08x,%p,%x,%p,%p,%p)\n", debugstr_a(Subsystem
),
2429 HandleId
, debugstr_a(ObjectTypeName
), debugstr_a(ObjectName
),
2430 SecurityDescriptor
, DesiredAccess
, GenericMapping
,
2431 ObjectCreation
, GrantedAccess
, AccessStatus
, pfGenerateOnClose
);
2435 /******************************************************************************
2436 * AccessCheckAndAuditAlarmW [ADVAPI32.@]
2438 BOOL WINAPI
AccessCheckAndAuditAlarmW(LPCWSTR Subsystem
, LPVOID HandleId
, LPWSTR ObjectTypeName
,
2439 LPWSTR ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
, DWORD DesiredAccess
,
2440 PGENERIC_MAPPING GenericMapping
, BOOL ObjectCreation
, LPDWORD GrantedAccess
,
2441 LPBOOL AccessStatus
, LPBOOL pfGenerateOnClose
)
2443 FIXME("stub (%s,%p,%s,%s,%p,%08x,%p,%x,%p,%p,%p)\n", debugstr_w(Subsystem
),
2444 HandleId
, debugstr_w(ObjectTypeName
), debugstr_w(ObjectName
),
2445 SecurityDescriptor
, DesiredAccess
, GenericMapping
,
2446 ObjectCreation
, GrantedAccess
, AccessStatus
, pfGenerateOnClose
);
2450 BOOL WINAPI
ObjectCloseAuditAlarmA(LPCSTR SubsystemName
, LPVOID HandleId
, BOOL GenerateOnClose
)
2452 FIXME("stub (%s,%p,%x)\n", debugstr_a(SubsystemName
), HandleId
, GenerateOnClose
);
2457 BOOL WINAPI
ObjectCloseAuditAlarmW(LPCWSTR SubsystemName
, LPVOID HandleId
, BOOL GenerateOnClose
)
2459 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName
), HandleId
, GenerateOnClose
);
2464 BOOL WINAPI
ObjectDeleteAuditAlarmW(LPCWSTR SubsystemName
, LPVOID HandleId
, BOOL GenerateOnClose
)
2466 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName
), HandleId
, GenerateOnClose
);
2471 BOOL WINAPI
ObjectOpenAuditAlarmA(LPCSTR SubsystemName
, LPVOID HandleId
, LPSTR ObjectTypeName
,
2472 LPSTR ObjectName
, PSECURITY_DESCRIPTOR pSecurityDescriptor
, HANDLE ClientToken
, DWORD DesiredAccess
,
2473 DWORD GrantedAccess
, PPRIVILEGE_SET Privileges
, BOOL ObjectCreation
, BOOL AccessGranted
,
2474 LPBOOL GenerateOnClose
)
2476 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08x,0x%08x,%p,%x,%x,%p)\n", debugstr_a(SubsystemName
),
2477 HandleId
, debugstr_a(ObjectTypeName
), debugstr_a(ObjectName
), pSecurityDescriptor
,
2478 ClientToken
, DesiredAccess
, GrantedAccess
, Privileges
, ObjectCreation
, AccessGranted
,
2484 BOOL WINAPI
ObjectOpenAuditAlarmW(LPCWSTR SubsystemName
, LPVOID HandleId
, LPWSTR ObjectTypeName
,
2485 LPWSTR ObjectName
, PSECURITY_DESCRIPTOR pSecurityDescriptor
, HANDLE ClientToken
, DWORD DesiredAccess
,
2486 DWORD GrantedAccess
, PPRIVILEGE_SET Privileges
, BOOL ObjectCreation
, BOOL AccessGranted
,
2487 LPBOOL GenerateOnClose
)
2489 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08x,0x%08x,%p,%x,%x,%p)\n", debugstr_w(SubsystemName
),
2490 HandleId
, debugstr_w(ObjectTypeName
), debugstr_w(ObjectName
), pSecurityDescriptor
,
2491 ClientToken
, DesiredAccess
, GrantedAccess
, Privileges
, ObjectCreation
, AccessGranted
,
2497 BOOL WINAPI
ObjectPrivilegeAuditAlarmA( LPCSTR SubsystemName
, LPVOID HandleId
, HANDLE ClientToken
,
2498 DWORD DesiredAccess
, PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2500 FIXME("stub (%s,%p,%p,0x%08x,%p,%x)\n", debugstr_a(SubsystemName
), HandleId
, ClientToken
,
2501 DesiredAccess
, Privileges
, AccessGranted
);
2506 BOOL WINAPI
ObjectPrivilegeAuditAlarmW( LPCWSTR SubsystemName
, LPVOID HandleId
, HANDLE ClientToken
,
2507 DWORD DesiredAccess
, PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2509 FIXME("stub (%s,%p,%p,0x%08x,%p,%x)\n", debugstr_w(SubsystemName
), HandleId
, ClientToken
,
2510 DesiredAccess
, Privileges
, AccessGranted
);
2515 BOOL WINAPI
PrivilegedServiceAuditAlarmA( LPCSTR SubsystemName
, LPCSTR ServiceName
, HANDLE ClientToken
,
2516 PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2518 FIXME("stub (%s,%s,%p,%p,%x)\n", debugstr_a(SubsystemName
), debugstr_a(ServiceName
),
2519 ClientToken
, Privileges
, AccessGranted
);
2524 BOOL WINAPI
PrivilegedServiceAuditAlarmW( LPCWSTR SubsystemName
, LPCWSTR ServiceName
, HANDLE ClientToken
,
2525 PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2527 FIXME("stub %s,%s,%p,%p,%x)\n", debugstr_w(SubsystemName
), debugstr_w(ServiceName
),
2528 ClientToken
, Privileges
, AccessGranted
);
2533 /******************************************************************************
2534 * GetSecurityInfo [ADVAPI32.@]
2536 DWORD WINAPI
GetSecurityInfo(
2537 HANDLE hObject
, SE_OBJECT_TYPE ObjectType
,
2538 SECURITY_INFORMATION SecurityInfo
, PSID
*ppsidOwner
,
2539 PSID
*ppsidGroup
, PACL
*ppDacl
, PACL
*ppSacl
,
2540 PSECURITY_DESCRIPTOR
*ppSecurityDescriptor
2544 return ERROR_BAD_PROVIDER
;
2547 /******************************************************************************
2548 * GetSecurityInfoExW [ADVAPI32.@]
2550 DWORD WINAPI
GetSecurityInfoExW(
2551 HANDLE hObject
, SE_OBJECT_TYPE ObjectType
,
2552 SECURITY_INFORMATION SecurityInfo
, LPCWSTR lpProvider
,
2553 LPCWSTR lpProperty
, PACTRL_ACCESSW
*ppAccessList
,
2554 PACTRL_AUDITW
*ppAuditList
, LPWSTR
*lppOwner
, LPWSTR
*lppGroup
2558 return ERROR_BAD_PROVIDER
;
2561 /******************************************************************************
2562 * BuildExplicitAccessWithNameA [ADVAPI32.@]
2564 VOID WINAPI
BuildExplicitAccessWithNameA( PEXPLICIT_ACCESSA pExplicitAccess
,
2565 LPSTR pTrusteeName
, DWORD AccessPermissions
,
2566 ACCESS_MODE AccessMode
, DWORD Inheritance
)
2568 TRACE("%p %s 0x%08x 0x%08x 0x%08x\n", pExplicitAccess
, debugstr_a(pTrusteeName
),
2569 AccessPermissions
, AccessMode
, Inheritance
);
2571 pExplicitAccess
->grfAccessPermissions
= AccessPermissions
;
2572 pExplicitAccess
->grfAccessMode
= AccessMode
;
2573 pExplicitAccess
->grfInheritance
= Inheritance
;
2575 pExplicitAccess
->Trustee
.pMultipleTrustee
= NULL
;
2576 pExplicitAccess
->Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2577 pExplicitAccess
->Trustee
.TrusteeForm
= TRUSTEE_IS_NAME
;
2578 pExplicitAccess
->Trustee
.TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2579 pExplicitAccess
->Trustee
.ptstrName
= pTrusteeName
;
2582 /******************************************************************************
2583 * BuildExplicitAccessWithNameW [ADVAPI32.@]
2585 VOID WINAPI
BuildExplicitAccessWithNameW( PEXPLICIT_ACCESSW pExplicitAccess
,
2586 LPWSTR pTrusteeName
, DWORD AccessPermissions
,
2587 ACCESS_MODE AccessMode
, DWORD Inheritance
)
2589 TRACE("%p %s 0x%08x 0x%08x 0x%08x\n", pExplicitAccess
, debugstr_w(pTrusteeName
),
2590 AccessPermissions
, AccessMode
, Inheritance
);
2592 pExplicitAccess
->grfAccessPermissions
= AccessPermissions
;
2593 pExplicitAccess
->grfAccessMode
= AccessMode
;
2594 pExplicitAccess
->grfInheritance
= Inheritance
;
2596 pExplicitAccess
->Trustee
.pMultipleTrustee
= NULL
;
2597 pExplicitAccess
->Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2598 pExplicitAccess
->Trustee
.TrusteeForm
= TRUSTEE_IS_NAME
;
2599 pExplicitAccess
->Trustee
.TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2600 pExplicitAccess
->Trustee
.ptstrName
= pTrusteeName
;
2603 /******************************************************************************
2604 * BuildTrusteeWithObjectsAndNameA [ADVAPI32.@]
2606 VOID WINAPI
BuildTrusteeWithObjectsAndNameA( PTRUSTEEA pTrustee
, POBJECTS_AND_NAME_A pObjName
,
2607 SE_OBJECT_TYPE ObjectType
, LPSTR ObjectTypeName
,
2608 LPSTR InheritedObjectTypeName
, LPSTR Name
)
2610 DWORD ObjectsPresent
= 0;
2612 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee
, pObjName
,
2613 ObjectType
, ObjectTypeName
, InheritedObjectTypeName
, debugstr_a(Name
));
2615 /* Fill the OBJECTS_AND_NAME structure */
2616 pObjName
->ObjectType
= ObjectType
;
2617 if (ObjectTypeName
!= NULL
)
2619 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2622 pObjName
->InheritedObjectTypeName
= InheritedObjectTypeName
;
2623 if (InheritedObjectTypeName
!= NULL
)
2625 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2628 pObjName
->ObjectsPresent
= ObjectsPresent
;
2629 pObjName
->ptstrName
= Name
;
2631 /* Fill the TRUSTEE structure */
2632 pTrustee
->pMultipleTrustee
= NULL
;
2633 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2634 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_NAME
;
2635 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2636 pTrustee
->ptstrName
= (LPSTR
)pObjName
;
2639 /******************************************************************************
2640 * BuildTrusteeWithObjectsAndNameW [ADVAPI32.@]
2642 VOID WINAPI
BuildTrusteeWithObjectsAndNameW( PTRUSTEEW pTrustee
, POBJECTS_AND_NAME_W pObjName
,
2643 SE_OBJECT_TYPE ObjectType
, LPWSTR ObjectTypeName
,
2644 LPWSTR InheritedObjectTypeName
, LPWSTR Name
)
2646 DWORD ObjectsPresent
= 0;
2648 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee
, pObjName
,
2649 ObjectType
, ObjectTypeName
, InheritedObjectTypeName
, debugstr_w(Name
));
2651 /* Fill the OBJECTS_AND_NAME structure */
2652 pObjName
->ObjectType
= ObjectType
;
2653 if (ObjectTypeName
!= NULL
)
2655 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2658 pObjName
->InheritedObjectTypeName
= InheritedObjectTypeName
;
2659 if (InheritedObjectTypeName
!= NULL
)
2661 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2664 pObjName
->ObjectsPresent
= ObjectsPresent
;
2665 pObjName
->ptstrName
= Name
;
2667 /* Fill the TRUSTEE structure */
2668 pTrustee
->pMultipleTrustee
= NULL
;
2669 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2670 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_NAME
;
2671 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2672 pTrustee
->ptstrName
= (LPWSTR
)pObjName
;
2675 /******************************************************************************
2676 * BuildTrusteeWithObjectsAndSidA [ADVAPI32.@]
2678 VOID WINAPI
BuildTrusteeWithObjectsAndSidA( PTRUSTEEA pTrustee
, POBJECTS_AND_SID pObjSid
,
2679 GUID
* pObjectGuid
, GUID
* pInheritedObjectGuid
, PSID pSid
)
2681 DWORD ObjectsPresent
= 0;
2683 TRACE("%p %p %p %p %p\n", pTrustee
, pObjSid
, pObjectGuid
, pInheritedObjectGuid
, pSid
);
2685 /* Fill the OBJECTS_AND_SID structure */
2686 if (pObjectGuid
!= NULL
)
2688 pObjSid
->ObjectTypeGuid
= *pObjectGuid
;
2689 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2693 ZeroMemory(&pObjSid
->ObjectTypeGuid
,
2697 if (pInheritedObjectGuid
!= NULL
)
2699 pObjSid
->InheritedObjectTypeGuid
= *pInheritedObjectGuid
;
2700 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2704 ZeroMemory(&pObjSid
->InheritedObjectTypeGuid
,
2708 pObjSid
->ObjectsPresent
= ObjectsPresent
;
2709 pObjSid
->pSid
= pSid
;
2711 /* Fill the TRUSTEE structure */
2712 pTrustee
->pMultipleTrustee
= NULL
;
2713 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2714 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_SID
;
2715 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2716 pTrustee
->ptstrName
= (LPSTR
) pObjSid
;
2719 /******************************************************************************
2720 * BuildTrusteeWithObjectsAndSidW [ADVAPI32.@]
2722 VOID WINAPI
BuildTrusteeWithObjectsAndSidW( PTRUSTEEW pTrustee
, POBJECTS_AND_SID pObjSid
,
2723 GUID
* pObjectGuid
, GUID
* pInheritedObjectGuid
, PSID pSid
)
2725 DWORD ObjectsPresent
= 0;
2727 TRACE("%p %p %p %p %p\n", pTrustee
, pObjSid
, pObjectGuid
, pInheritedObjectGuid
, pSid
);
2729 /* Fill the OBJECTS_AND_SID structure */
2730 if (pObjectGuid
!= NULL
)
2732 pObjSid
->ObjectTypeGuid
= *pObjectGuid
;
2733 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2737 ZeroMemory(&pObjSid
->ObjectTypeGuid
,
2741 if (pInheritedObjectGuid
!= NULL
)
2743 pObjSid
->InheritedObjectTypeGuid
= *pInheritedObjectGuid
;
2744 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2748 ZeroMemory(&pObjSid
->InheritedObjectTypeGuid
,
2752 pObjSid
->ObjectsPresent
= ObjectsPresent
;
2753 pObjSid
->pSid
= pSid
;
2755 /* Fill the TRUSTEE structure */
2756 pTrustee
->pMultipleTrustee
= NULL
;
2757 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2758 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_SID
;
2759 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2760 pTrustee
->ptstrName
= (LPWSTR
) pObjSid
;
2763 /******************************************************************************
2764 * BuildTrusteeWithSidA [ADVAPI32.@]
2766 VOID WINAPI
BuildTrusteeWithSidA(PTRUSTEEA pTrustee
, PSID pSid
)
2768 TRACE("%p %p\n", pTrustee
, pSid
);
2770 pTrustee
->pMultipleTrustee
= NULL
;
2771 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2772 pTrustee
->TrusteeForm
= TRUSTEE_IS_SID
;
2773 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2774 pTrustee
->ptstrName
= (LPSTR
) pSid
;
2777 /******************************************************************************
2778 * BuildTrusteeWithSidW [ADVAPI32.@]
2780 VOID WINAPI
BuildTrusteeWithSidW(PTRUSTEEW pTrustee
, PSID pSid
)
2782 TRACE("%p %p\n", pTrustee
, pSid
);
2784 pTrustee
->pMultipleTrustee
= NULL
;
2785 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2786 pTrustee
->TrusteeForm
= TRUSTEE_IS_SID
;
2787 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2788 pTrustee
->ptstrName
= (LPWSTR
) pSid
;
2791 /******************************************************************************
2792 * BuildTrusteeWithNameA [ADVAPI32.@]
2794 VOID WINAPI
BuildTrusteeWithNameA(PTRUSTEEA pTrustee
, LPSTR name
)
2796 TRACE("%p %s\n", pTrustee
, debugstr_a(name
) );
2798 pTrustee
->pMultipleTrustee
= NULL
;
2799 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2800 pTrustee
->TrusteeForm
= TRUSTEE_IS_NAME
;
2801 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2802 pTrustee
->ptstrName
= name
;
2805 /******************************************************************************
2806 * BuildTrusteeWithNameW [ADVAPI32.@]
2808 VOID WINAPI
BuildTrusteeWithNameW(PTRUSTEEW pTrustee
, LPWSTR name
)
2810 TRACE("%p %s\n", pTrustee
, debugstr_w(name
) );
2812 pTrustee
->pMultipleTrustee
= NULL
;
2813 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2814 pTrustee
->TrusteeForm
= TRUSTEE_IS_NAME
;
2815 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2816 pTrustee
->ptstrName
= name
;
2819 /******************************************************************************
2820 * GetTrusteeFormA [ADVAPI32.@]
2822 TRUSTEE_FORM WINAPI
GetTrusteeFormA(PTRUSTEEA pTrustee
)
2824 TRACE("(%p)\n", pTrustee
);
2827 return TRUSTEE_BAD_FORM
;
2829 return pTrustee
->TrusteeForm
;
2832 /******************************************************************************
2833 * GetTrusteeFormW [ADVAPI32.@]
2835 TRUSTEE_FORM WINAPI
GetTrusteeFormW(PTRUSTEEW pTrustee
)
2837 TRACE("(%p)\n", pTrustee
);
2840 return TRUSTEE_BAD_FORM
;
2842 return pTrustee
->TrusteeForm
;
2845 /******************************************************************************
2846 * GetTrusteeNameA [ADVAPI32.@]
2848 LPSTR WINAPI
GetTrusteeNameA(PTRUSTEEA pTrustee
)
2850 TRACE("(%p)\n", pTrustee
);
2855 return pTrustee
->ptstrName
;
2858 /******************************************************************************
2859 * GetTrusteeNameW [ADVAPI32.@]
2861 LPWSTR WINAPI
GetTrusteeNameW(PTRUSTEEW pTrustee
)
2863 TRACE("(%p)\n", pTrustee
);
2868 return pTrustee
->ptstrName
;
2871 /******************************************************************************
2872 * GetTrusteeTypeA [ADVAPI32.@]
2874 TRUSTEE_TYPE WINAPI
GetTrusteeTypeA(PTRUSTEEA pTrustee
)
2876 TRACE("(%p)\n", pTrustee
);
2879 return TRUSTEE_IS_UNKNOWN
;
2881 return pTrustee
->TrusteeType
;
2884 /******************************************************************************
2885 * GetTrusteeTypeW [ADVAPI32.@]
2887 TRUSTEE_TYPE WINAPI
GetTrusteeTypeW(PTRUSTEEW pTrustee
)
2889 TRACE("(%p)\n", pTrustee
);
2892 return TRUSTEE_IS_UNKNOWN
;
2894 return pTrustee
->TrusteeType
;
2897 BOOL WINAPI
SetAclInformation( PACL pAcl
, LPVOID pAclInformation
,
2898 DWORD nAclInformationLength
,
2899 ACL_INFORMATION_CLASS dwAclInformationClass
)
2901 FIXME("%p %p 0x%08x 0x%08x - stub\n", pAcl
, pAclInformation
,
2902 nAclInformationLength
, dwAclInformationClass
);
2907 /******************************************************************************
2908 * SetEntriesInAclA [ADVAPI32.@]
2910 DWORD WINAPI
SetEntriesInAclA( ULONG count
, PEXPLICIT_ACCESSA pEntries
,
2911 PACL OldAcl
, PACL
* NewAcl
)
2913 FIXME("%d %p %p %p\n",count
,pEntries
,OldAcl
,NewAcl
);
2914 return ERROR_CALL_NOT_IMPLEMENTED
;
2917 /******************************************************************************
2918 * SetEntriesInAclW [ADVAPI32.@]
2920 DWORD WINAPI
SetEntriesInAclW( ULONG count
, PEXPLICIT_ACCESSW pEntries
,
2921 PACL OldAcl
, PACL
* NewAcl
)
2923 FIXME("%d %p %p %p\n",count
,pEntries
,OldAcl
,NewAcl
);
2924 return ERROR_CALL_NOT_IMPLEMENTED
;
2927 /******************************************************************************
2928 * SetNamedSecurityInfoA [ADVAPI32.@]
2930 DWORD WINAPI
SetNamedSecurityInfoA(LPSTR pObjectName
,
2931 SE_OBJECT_TYPE ObjectType
, SECURITY_INFORMATION SecurityInfo
,
2932 PSID psidOwner
, PSID psidGroup
, PACL pDacl
, PACL pSacl
)
2938 TRACE("%s %d %d %p %p %p %p\n", debugstr_a(pObjectName
), ObjectType
,
2939 SecurityInfo
, psidOwner
, psidGroup
, pDacl
, pSacl
);
2943 len
= MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, NULL
, 0 );
2944 wstr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
2945 MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, wstr
, len
);
2948 r
= SetNamedSecurityInfoW( wstr
, ObjectType
, SecurityInfo
, psidOwner
,
2949 psidGroup
, pDacl
, pSacl
);
2951 HeapFree( GetProcessHeap(), 0, wstr
);
2956 BOOL WINAPI
SetPrivateObjectSecurity( SECURITY_INFORMATION SecurityInformation
,
2957 PSECURITY_DESCRIPTOR ModificationDescriptor
,
2958 PSECURITY_DESCRIPTOR
* ObjectsSecurityDescriptor
,
2959 PGENERIC_MAPPING GenericMapping
,
2962 FIXME("0x%08x %p %p %p %p - stub\n", SecurityInformation
, ModificationDescriptor
,
2963 ObjectsSecurityDescriptor
, GenericMapping
, Token
);
2968 BOOL WINAPI
SetSecurityDescriptorControl( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
2969 SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest
,
2970 SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet
)
2972 FIXME("%p 0x%08x 0x%08x - stub\n", pSecurityDescriptor
, ControlBitsOfInterest
,
2978 BOOL WINAPI
AreAllAccessesGranted( DWORD GrantedAccess
, DWORD DesiredAccess
)
2980 return RtlAreAllAccessesGranted( GrantedAccess
, DesiredAccess
);
2983 /******************************************************************************
2984 * AreAnyAccessesGranted [ADVAPI32.@]
2986 * Determines whether or not any of a set of specified access permissions have
2987 * been granted or not.
2990 * GrantedAccess [I] The permissions that have been granted.
2991 * DesiredAccess [I] The permissions that you want to have.
2994 * Nonzero if any of the permissions have been granted, zero if none of the
2995 * permissions have been granted.
2998 BOOL WINAPI
AreAnyAccessesGranted( DWORD GrantedAccess
, DWORD DesiredAccess
)
3000 return RtlAreAnyAccessesGranted( GrantedAccess
, DesiredAccess
);
3003 /******************************************************************************
3004 * SetNamedSecurityInfoW [ADVAPI32.@]
3006 DWORD WINAPI
SetNamedSecurityInfoW(LPWSTR pObjectName
,
3007 SE_OBJECT_TYPE ObjectType
, SECURITY_INFORMATION SecurityInfo
,
3008 PSID psidOwner
, PSID psidGroup
, PACL pDacl
, PACL pSacl
)
3010 FIXME("%s %d %d %p %p %p %p\n", debugstr_w(pObjectName
), ObjectType
,
3011 SecurityInfo
, psidOwner
, psidGroup
, pDacl
, pSacl
);
3012 return ERROR_SUCCESS
;
3015 /******************************************************************************
3016 * GetExplicitEntriesFromAclA [ADVAPI32.@]
3018 DWORD WINAPI
GetExplicitEntriesFromAclA( PACL pacl
, PULONG pcCountOfExplicitEntries
,
3019 PEXPLICIT_ACCESSA
* pListOfExplicitEntries
)
3021 FIXME("%p %p %p\n",pacl
, pcCountOfExplicitEntries
, pListOfExplicitEntries
);
3022 return ERROR_CALL_NOT_IMPLEMENTED
;
3025 /******************************************************************************
3026 * GetExplicitEntriesFromAclW [ADVAPI32.@]
3028 DWORD WINAPI
GetExplicitEntriesFromAclW( PACL pacl
, PULONG pcCountOfExplicitEntries
,
3029 PEXPLICIT_ACCESSW
* pListOfExplicitEntries
)
3031 FIXME("%p %p %p\n",pacl
, pcCountOfExplicitEntries
, pListOfExplicitEntries
);
3032 return ERROR_CALL_NOT_IMPLEMENTED
;
3036 /******************************************************************************
3037 * ParseAclStringFlags
3039 static DWORD
ParseAclStringFlags(LPCWSTR
* StringAcl
)
3042 LPCWSTR szAcl
= *StringAcl
;
3044 while (*szAcl
!= '(')
3048 flags
|= SE_DACL_PROTECTED
;
3050 else if (*szAcl
== 'A')
3054 flags
|= SE_DACL_AUTO_INHERIT_REQ
;
3055 else if (*szAcl
== 'I')
3056 flags
|= SE_DACL_AUTO_INHERITED
;
3065 /******************************************************************************
3066 * ParseAceStringType
3068 static const ACEFLAG AceType
[] =
3070 { SDDL_ACCESS_ALLOWED
, ACCESS_ALLOWED_ACE_TYPE
},
3071 { SDDL_ALARM
, SYSTEM_ALARM_ACE_TYPE
},
3072 { SDDL_AUDIT
, SYSTEM_AUDIT_ACE_TYPE
},
3073 { SDDL_ACCESS_DENIED
, ACCESS_DENIED_ACE_TYPE
},
3075 { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
3076 { SDDL_OBJECT_ACCESS_DENIED, ACCESS_DENIED_OBJECT_ACE_TYPE },
3077 { SDDL_OBJECT_ALARM, SYSTEM_ALARM_OBJECT_ACE_TYPE },
3078 { SDDL_OBJECT_AUDIT, SYSTEM_AUDIT_OBJECT_ACE_TYPE },
3083 static BYTE
ParseAceStringType(LPCWSTR
* StringAcl
)
3086 LPCWSTR szAcl
= *StringAcl
;
3087 const ACEFLAG
*lpaf
= AceType
;
3089 while (lpaf
->wstr
&&
3090 (len
= strlenW(lpaf
->wstr
)) &&
3091 strncmpW(lpaf
->wstr
, szAcl
, len
))
3102 /******************************************************************************
3103 * ParseAceStringFlags
3105 static const ACEFLAG AceFlags
[] =
3107 { SDDL_CONTAINER_INHERIT
, CONTAINER_INHERIT_ACE
},
3108 { SDDL_AUDIT_FAILURE
, FAILED_ACCESS_ACE_FLAG
},
3109 { SDDL_INHERITED
, INHERITED_ACE
},
3110 { SDDL_INHERIT_ONLY
, INHERIT_ONLY_ACE
},
3111 { SDDL_NO_PROPAGATE
, NO_PROPAGATE_INHERIT_ACE
},
3112 { SDDL_OBJECT_INHERIT
, OBJECT_INHERIT_ACE
},
3113 { SDDL_AUDIT_SUCCESS
, SUCCESSFUL_ACCESS_ACE_FLAG
},
3117 static BYTE
ParseAceStringFlags(LPCWSTR
* StringAcl
)
3121 LPCWSTR szAcl
= *StringAcl
;
3123 while (*szAcl
!= ';')
3125 const ACEFLAG
*lpaf
= AceFlags
;
3127 while (lpaf
->wstr
&&
3128 (len
= strlenW(lpaf
->wstr
)) &&
3129 strncmpW(lpaf
->wstr
, szAcl
, len
))
3135 flags
|= lpaf
->value
;
3144 /******************************************************************************
3145 * ParseAceStringRights
3147 static const ACEFLAG AceRights
[] =
3149 { SDDL_GENERIC_ALL
, GENERIC_ALL
},
3150 { SDDL_GENERIC_READ
, GENERIC_READ
},
3151 { SDDL_GENERIC_WRITE
, GENERIC_WRITE
},
3152 { SDDL_GENERIC_EXECUTE
, GENERIC_EXECUTE
},
3153 { SDDL_READ_CONTROL
, READ_CONTROL
},
3154 { SDDL_STANDARD_DELETE
, DELETE
},
3155 { SDDL_WRITE_DAC
, WRITE_DAC
},
3156 { SDDL_WRITE_OWNER
, WRITE_OWNER
},
3160 static DWORD
ParseAceStringRights(LPCWSTR
* StringAcl
)
3164 LPCWSTR szAcl
= *StringAcl
;
3166 if ((*szAcl
== '0') && (*(szAcl
+ 1) == 'x'))
3170 while (*p
&& *p
!= ';')
3175 rights
= strtoulW(szAcl
, NULL
, 16);
3179 WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl
, p
- szAcl
));
3183 while (*szAcl
!= ';')
3185 const ACEFLAG
*lpaf
= AceRights
;
3187 while (lpaf
->wstr
&&
3188 (len
= strlenW(lpaf
->wstr
)) &&
3189 strncmpW(lpaf
->wstr
, szAcl
, len
))
3197 rights
|= lpaf
->value
;
3207 /******************************************************************************
3208 * ParseStringAclToAcl
3210 * dacl_flags(string_ace1)(string_ace2)... (string_acen)
3212 static BOOL
ParseStringAclToAcl(LPCWSTR StringAcl
, LPDWORD lpdwFlags
,
3213 PACL pAcl
, LPDWORD cBytes
)
3217 DWORD length
= sizeof(ACL
);
3218 PACCESS_ALLOWED_ACE pAce
= NULL
; /* pointer to current ACE */
3220 TRACE("%s\n", debugstr_w(StringAcl
));
3225 if (pAcl
) /* pAce is only useful if we're setting values */
3226 pAce
= (PACCESS_ALLOWED_ACE
) ((LPBYTE
)pAcl
+ sizeof(PACL
));
3228 /* Parse ACL flags */
3229 *lpdwFlags
= ParseAclStringFlags(&StringAcl
);
3232 while (*StringAcl
== '(')
3236 /* Parse ACE type */
3237 val
= ParseAceStringType(&StringAcl
);
3239 pAce
->Header
.AceType
= (BYTE
) val
;
3240 if (*StringAcl
!= ';')
3244 /* Parse ACE flags */
3245 val
= ParseAceStringFlags(&StringAcl
);
3247 pAce
->Header
.AceFlags
= (BYTE
) val
;
3248 if (*StringAcl
!= ';')
3252 /* Parse ACE rights */
3253 val
= ParseAceStringRights(&StringAcl
);
3256 if (*StringAcl
!= ';')
3260 /* Parse ACE object guid */
3261 if (*StringAcl
!= ';')
3263 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3268 /* Parse ACE inherit object guid */
3269 if (*StringAcl
!= ';')
3271 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3276 /* Parse ACE account sid */
3277 if (ParseStringSidToSid(StringAcl
, pAce
? (PSID
)&pAce
->SidStart
: NULL
, &sidlen
))
3279 while (*StringAcl
&& *StringAcl
!= ')')
3283 if (*StringAcl
!= ')')
3287 length
+= sizeof(ACCESS_ALLOWED_ACE
) - sizeof(DWORD
) + sidlen
;
3294 WARN("Invalid ACE string format\n");
3299 /******************************************************************************
3300 * ParseStringSecurityDescriptorToSecurityDescriptor
3302 static BOOL
ParseStringSecurityDescriptorToSecurityDescriptor(
3303 LPCWSTR StringSecurityDescriptor
,
3304 SECURITY_DESCRIPTOR
* SecurityDescriptor
,
3309 WCHAR tok
[MAX_PATH
];
3311 LPBYTE lpNext
= NULL
;
3316 if (SecurityDescriptor
)
3317 lpNext
= ((LPBYTE
) SecurityDescriptor
) + sizeof(SECURITY_DESCRIPTOR
);
3319 while (*StringSecurityDescriptor
)
3321 toktype
= *StringSecurityDescriptor
;
3323 /* Expect char identifier followed by ':' */
3324 StringSecurityDescriptor
++;
3325 if (*StringSecurityDescriptor
!= ':')
3327 SetLastError(ERROR_INVALID_PARAMETER
);
3330 StringSecurityDescriptor
++;
3333 lptoken
= StringSecurityDescriptor
;
3334 while (*lptoken
&& *lptoken
!= ':')
3340 len
= lptoken
- StringSecurityDescriptor
;
3341 memcpy( tok
, StringSecurityDescriptor
, len
* sizeof(WCHAR
) );
3350 if (!ParseStringSidToSid(tok
, (PSID
)lpNext
, &bytes
))
3353 if (SecurityDescriptor
)
3355 SecurityDescriptor
->Owner
= (PSID
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3356 lpNext
+= bytes
; /* Advance to next token */
3368 if (!ParseStringSidToSid(tok
, (PSID
)lpNext
, &bytes
))
3371 if (SecurityDescriptor
)
3373 SecurityDescriptor
->Group
= (PSID
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3374 lpNext
+= bytes
; /* Advance to next token */
3387 if (!ParseStringAclToAcl(tok
, &flags
, (PACL
)lpNext
, &bytes
))
3390 if (SecurityDescriptor
)
3392 SecurityDescriptor
->Control
|= SE_DACL_PRESENT
| flags
;
3393 SecurityDescriptor
->Dacl
= (PACL
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3394 lpNext
+= bytes
; /* Advance to next token */
3407 if (!ParseStringAclToAcl(tok
, &flags
, (PACL
)lpNext
, &bytes
))
3410 if (SecurityDescriptor
)
3412 SecurityDescriptor
->Control
|= SE_SACL_PRESENT
| flags
;
3413 SecurityDescriptor
->Sacl
= (PACL
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3414 lpNext
+= bytes
; /* Advance to next token */
3423 FIXME("Unknown token\n");
3424 SetLastError(ERROR_INVALID_PARAMETER
);
3428 StringSecurityDescriptor
= lptoken
;
3437 /******************************************************************************
3438 * ConvertStringSecurityDescriptorToSecurityDescriptorA [ADVAPI32.@]
3440 BOOL WINAPI
ConvertStringSecurityDescriptorToSecurityDescriptorA(
3441 LPCSTR StringSecurityDescriptor
,
3442 DWORD StringSDRevision
,
3443 PSECURITY_DESCRIPTOR
* SecurityDescriptor
,
3444 PULONG SecurityDescriptorSize
)
3448 LPWSTR StringSecurityDescriptorW
;
3450 len
= MultiByteToWideChar(CP_ACP
, 0, StringSecurityDescriptor
, -1, NULL
, 0);
3451 StringSecurityDescriptorW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3453 if (StringSecurityDescriptorW
)
3455 MultiByteToWideChar(CP_ACP
, 0, StringSecurityDescriptor
, -1, StringSecurityDescriptorW
, len
);
3457 ret
= ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptorW
,
3458 StringSDRevision
, SecurityDescriptor
,
3459 SecurityDescriptorSize
);
3460 HeapFree(GetProcessHeap(), 0, StringSecurityDescriptorW
);
3466 /******************************************************************************
3467 * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
3469 BOOL WINAPI
ConvertStringSecurityDescriptorToSecurityDescriptorW(
3470 LPCWSTR StringSecurityDescriptor
,
3471 DWORD StringSDRevision
,
3472 PSECURITY_DESCRIPTOR
* SecurityDescriptor
,
3473 PULONG SecurityDescriptorSize
)
3476 SECURITY_DESCRIPTOR
* psd
;
3479 TRACE("%s\n", debugstr_w(StringSecurityDescriptor
));
3481 if (GetVersion() & 0x80000000)
3483 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3486 else if (StringSDRevision
!= SID_REVISION
)
3488 SetLastError(ERROR_UNKNOWN_REVISION
);
3492 /* Compute security descriptor length */
3493 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor
,
3497 psd
= *SecurityDescriptor
= (SECURITY_DESCRIPTOR
*) LocalAlloc(
3498 GMEM_ZEROINIT
, cBytes
);
3500 psd
->Revision
= SID_REVISION
;
3501 psd
->Control
|= SE_SELF_RELATIVE
;
3503 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor
,
3510 if (SecurityDescriptorSize
)
3511 *SecurityDescriptorSize
= cBytes
;
3516 TRACE(" ret=%d\n", bret
);
3520 /******************************************************************************
3521 * ConvertStringSidToSidW [ADVAPI32.@]
3523 BOOL WINAPI
ConvertStringSidToSidW(LPCWSTR StringSid
, PSID
* Sid
)
3528 TRACE("%s, %p\n", debugstr_w(StringSid
), Sid
);
3529 if (GetVersion() & 0x80000000)
3530 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3531 else if (!StringSid
|| !Sid
)
3532 SetLastError(ERROR_INVALID_PARAMETER
);
3533 else if (ParseStringSidToSid(StringSid
, NULL
, &cBytes
))
3535 PSID pSid
= *Sid
= (PSID
) LocalAlloc(0, cBytes
);
3537 bret
= ParseStringSidToSid(StringSid
, pSid
, &cBytes
);
3541 TRACE("returning %s\n", bret
? "TRUE" : "FALSE");
3545 /******************************************************************************
3546 * ConvertStringSidToSidA [ADVAPI32.@]
3548 BOOL WINAPI
ConvertStringSidToSidA(LPCSTR StringSid
, PSID
* Sid
)
3552 TRACE("%s, %p\n", debugstr_a(StringSid
), Sid
);
3553 if (GetVersion() & 0x80000000)
3554 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3555 else if (!StringSid
|| !Sid
)
3556 SetLastError(ERROR_INVALID_PARAMETER
);
3559 UINT len
= MultiByteToWideChar(CP_ACP
, 0, StringSid
, -1, NULL
, 0);
3560 LPWSTR wStringSid
= HeapAlloc(GetProcessHeap(), 0,
3561 len
* sizeof(WCHAR
));
3563 MultiByteToWideChar(CP_ACP
, 0, StringSid
, -1, wStringSid
, len
);
3564 bret
= ConvertStringSidToSidW(wStringSid
, Sid
);
3565 HeapFree(GetProcessHeap(), 0, wStringSid
);
3567 TRACE("returning %s\n", bret
? "TRUE" : "FALSE");
3571 /******************************************************************************
3572 * ConvertSidToStringSidW [ADVAPI32.@]
3574 * format of SID string is:
3575 * S-<count>-<auth>-<subauth1>-<subauth2>-<subauth3>...
3577 * <rev> is the revision of the SID encoded as decimal
3578 * <auth> is the identifier authority encoded as hex
3579 * <subauthN> is the subauthority id encoded as decimal
3581 BOOL WINAPI
ConvertSidToStringSidW( PSID pSid
, LPWSTR
*pstr
)
3585 WCHAR fmt
[] = { 'S','-','%','u','-','%','d',0 };
3586 WCHAR subauthfmt
[] = { '-','%','u',0 };
3589 TRACE("%p %p\n", pSid
, pstr
);
3591 if( !IsValidSid( pSid
) )
3594 if (pisid
->Revision
!= SDDL_REVISION
)
3596 if (pisid
->IdentifierAuthority
.Value
[0] ||
3597 pisid
->IdentifierAuthority
.Value
[1])
3599 FIXME("not matching MS' bugs\n");
3603 sz
= 14 + pisid
->SubAuthorityCount
* 11;
3604 str
= LocalAlloc( 0, sz
*sizeof(WCHAR
) );
3605 sprintfW( str
, fmt
, pisid
->Revision
, MAKELONG(
3606 MAKEWORD( pisid
->IdentifierAuthority
.Value
[5],
3607 pisid
->IdentifierAuthority
.Value
[4] ),
3608 MAKEWORD( pisid
->IdentifierAuthority
.Value
[3],
3609 pisid
->IdentifierAuthority
.Value
[2] ) ) );
3610 for( i
=0; i
<pisid
->SubAuthorityCount
; i
++ )
3611 sprintfW( str
+ strlenW(str
), subauthfmt
, pisid
->SubAuthority
[i
] );
3617 /******************************************************************************
3618 * ConvertSidToStringSidA [ADVAPI32.@]
3620 BOOL WINAPI
ConvertSidToStringSidA(PSID pSid
, LPSTR
*pstr
)
3626 TRACE("%p %p\n", pSid
, pstr
);
3628 if( !ConvertSidToStringSidW( pSid
, &wstr
) )
3631 len
= WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
3632 str
= LocalAlloc( 0, len
);
3633 WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, str
, len
, NULL
, NULL
);
3641 BOOL WINAPI
CreatePrivateObjectSecurity(
3642 PSECURITY_DESCRIPTOR ParentDescriptor
,
3643 PSECURITY_DESCRIPTOR CreatorDescriptor
,
3644 PSECURITY_DESCRIPTOR
* NewDescriptor
,
3645 BOOL IsDirectoryObject
,
3647 PGENERIC_MAPPING GenericMapping
)
3649 FIXME("%p %p %p %d %p %p - stub\n", ParentDescriptor
, CreatorDescriptor
,
3650 NewDescriptor
, IsDirectoryObject
, Token
, GenericMapping
);
3655 BOOL WINAPI
DestroyPrivateObjectSecurity( PSECURITY_DESCRIPTOR
* ObjectDescriptor
)
3657 FIXME("%p - stub\n", ObjectDescriptor
);
3662 BOOL WINAPI
CreateProcessAsUserA(
3664 LPCSTR lpApplicationName
,
3665 LPSTR lpCommandLine
,
3666 LPSECURITY_ATTRIBUTES lpProcessAttributes
,
3667 LPSECURITY_ATTRIBUTES lpThreadAttributes
,
3668 BOOL bInheritHandles
,
3669 DWORD dwCreationFlags
,
3670 LPVOID lpEnvironment
,
3671 LPCSTR lpCurrentDirectory
,
3672 LPSTARTUPINFOA lpStartupInfo
,
3673 LPPROCESS_INFORMATION lpProcessInformation
)
3675 FIXME("%p %s %s %p %p %d 0x%08x %p %s %p %p - stub\n", hToken
, debugstr_a(lpApplicationName
),
3676 debugstr_a(lpCommandLine
), lpProcessAttributes
, lpThreadAttributes
, bInheritHandles
,
3677 dwCreationFlags
, lpEnvironment
, debugstr_a(lpCurrentDirectory
), lpStartupInfo
, lpProcessInformation
);
3682 BOOL WINAPI
CreateProcessAsUserW(
3684 LPCWSTR lpApplicationName
,
3685 LPWSTR lpCommandLine
,
3686 LPSECURITY_ATTRIBUTES lpProcessAttributes
,
3687 LPSECURITY_ATTRIBUTES lpThreadAttributes
,
3688 BOOL bInheritHandles
,
3689 DWORD dwCreationFlags
,
3690 LPVOID lpEnvironment
,
3691 LPCWSTR lpCurrentDirectory
,
3692 LPSTARTUPINFOW lpStartupInfo
,
3693 LPPROCESS_INFORMATION lpProcessInformation
)
3695 FIXME("%p %s %s %p %p %d 0x%08x %p %s %p %p - semi- stub\n", hToken
,
3696 debugstr_w(lpApplicationName
), debugstr_w(lpCommandLine
), lpProcessAttributes
,
3697 lpThreadAttributes
, bInheritHandles
, dwCreationFlags
, lpEnvironment
,
3698 debugstr_w(lpCurrentDirectory
), lpStartupInfo
, lpProcessInformation
);
3700 /* We should create the process with a suspended main thread */
3701 if (!CreateProcessW (lpApplicationName
,
3703 lpProcessAttributes
,
3706 dwCreationFlags
, /* CREATE_SUSPENDED */
3710 lpProcessInformation
))
3718 /******************************************************************************
3719 * DuplicateTokenEx [ADVAPI32.@]
3721 BOOL WINAPI
DuplicateTokenEx(
3722 HANDLE ExistingTokenHandle
, DWORD dwDesiredAccess
,
3723 LPSECURITY_ATTRIBUTES lpTokenAttributes
,
3724 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
3725 TOKEN_TYPE TokenType
,
3726 PHANDLE DuplicateTokenHandle
)
3728 OBJECT_ATTRIBUTES ObjectAttributes
;
3730 TRACE("%p 0x%08x 0x%08x 0x%08x %p\n", ExistingTokenHandle
, dwDesiredAccess
,
3731 ImpersonationLevel
, TokenType
, DuplicateTokenHandle
);
3733 InitializeObjectAttributes(
3736 (lpTokenAttributes
&& lpTokenAttributes
->bInheritHandle
) ? OBJ_INHERIT
: 0,
3738 lpTokenAttributes
? lpTokenAttributes
->lpSecurityDescriptor
: NULL
);
3740 return set_ntstatus( NtDuplicateToken( ExistingTokenHandle
,
3745 DuplicateTokenHandle
) );
3748 BOOL WINAPI
DuplicateToken(
3749 HANDLE ExistingTokenHandle
,
3750 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
3751 PHANDLE DuplicateTokenHandle
)
3753 return DuplicateTokenEx( ExistingTokenHandle
, TOKEN_IMPERSONATE
| TOKEN_QUERY
,
3754 NULL
, ImpersonationLevel
, TokenImpersonation
,
3755 DuplicateTokenHandle
);
3758 BOOL WINAPI
EnumDependentServicesA(
3760 DWORD dwServiceState
,
3761 LPENUM_SERVICE_STATUSA lpServices
,
3763 LPDWORD pcbBytesNeeded
,
3764 LPDWORD lpServicesReturned
)
3766 FIXME("%p 0x%08x %p 0x%08x %p %p - stub\n", hService
, dwServiceState
,
3767 lpServices
, cbBufSize
, pcbBytesNeeded
, lpServicesReturned
);
3772 BOOL WINAPI
EnumDependentServicesW(
3774 DWORD dwServiceState
,
3775 LPENUM_SERVICE_STATUSW lpServices
,
3777 LPDWORD pcbBytesNeeded
,
3778 LPDWORD lpServicesReturned
)
3780 FIXME("%p 0x%08x %p 0x%08x %p %p - stub\n", hService
, dwServiceState
,
3781 lpServices
, cbBufSize
, pcbBytesNeeded
, lpServicesReturned
);
3786 /******************************************************************************
3787 * ComputeStringSidSize
3789 static DWORD
ComputeStringSidSize(LPCWSTR StringSid
)
3791 DWORD size
= sizeof(SID
);
3793 if (StringSid
[0] == 'S' && StringSid
[1] == '-') /* S-R-I-S-S */
3798 if (*StringSid
== '-')
3804 size
+= (ctok
- 3) * sizeof(DWORD
);
3806 else /* String constant format - Only available in winxp and above */
3810 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
3811 if (!strncmpW(WellKnownSids
[i
].wstr
, StringSid
, 2))
3812 size
+= (WellKnownSids
[i
].Sid
.SubAuthorityCount
- 1) * sizeof(DWORD
);
3818 /******************************************************************************
3819 * ParseStringSidToSid
3821 static BOOL
ParseStringSidToSid(LPCWSTR StringSid
, PSID pSid
, LPDWORD cBytes
)
3826 TRACE("%s, %p, %p\n", debugstr_w(StringSid
), pSid
, cBytes
);
3829 SetLastError(ERROR_INVALID_PARAMETER
);
3830 TRACE("StringSid is NULL, returning FALSE\n");
3834 *cBytes
= ComputeStringSidSize(StringSid
);
3835 if (!pisid
) /* Simply compute the size */
3837 TRACE("only size requested, returning TRUE\n");
3841 if (StringSid
[0] == 'S' && StringSid
[1] == '-') /* S-R-I-S-S */
3843 DWORD i
= 0, identAuth
;
3844 DWORD csubauth
= ((*cBytes
- sizeof(SID
)) / sizeof(DWORD
)) + 1;
3846 StringSid
+= 2; /* Advance to Revision */
3847 pisid
->Revision
= atoiW(StringSid
);
3849 if (pisid
->Revision
!= SDDL_REVISION
)
3851 TRACE("Revision %d is unknown\n", pisid
->Revision
);
3852 goto lend
; /* ERROR_INVALID_SID */
3856 TRACE("SubAuthorityCount is 0\n");
3857 goto lend
; /* ERROR_INVALID_SID */
3860 pisid
->SubAuthorityCount
= csubauth
;
3862 /* Advance to identifier authority */
3863 while (*StringSid
&& *StringSid
!= '-')
3865 if (*StringSid
== '-')
3868 /* MS' implementation can't handle values greater than 2^32 - 1, so
3869 * we don't either; assume most significant bytes are always 0
3871 pisid
->IdentifierAuthority
.Value
[0] = 0;
3872 pisid
->IdentifierAuthority
.Value
[1] = 0;
3873 identAuth
= atoiW(StringSid
);
3874 pisid
->IdentifierAuthority
.Value
[5] = identAuth
& 0xff;
3875 pisid
->IdentifierAuthority
.Value
[4] = (identAuth
& 0xff00) >> 8;
3876 pisid
->IdentifierAuthority
.Value
[3] = (identAuth
& 0xff0000) >> 16;
3877 pisid
->IdentifierAuthority
.Value
[2] = (identAuth
& 0xff000000) >> 24;
3879 /* Advance to first sub authority */
3880 while (*StringSid
&& *StringSid
!= '-')
3882 if (*StringSid
== '-')
3887 while (*StringSid
&& *StringSid
!= '-')
3889 if (*StringSid
== '-')
3892 pisid
->SubAuthority
[i
++] = atoiW(StringSid
);
3895 if (i
!= pisid
->SubAuthorityCount
)
3896 goto lend
; /* ERROR_INVALID_SID */
3900 else /* String constant format - Only available in winxp and above */
3903 pisid
->Revision
= SDDL_REVISION
;
3905 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
3906 if (!strncmpW(WellKnownSids
[i
].wstr
, StringSid
, 2))
3909 pisid
->SubAuthorityCount
= WellKnownSids
[i
].Sid
.SubAuthorityCount
;
3910 pisid
->IdentifierAuthority
= WellKnownSids
[i
].Sid
.IdentifierAuthority
;
3911 for (j
= 0; j
< WellKnownSids
[i
].Sid
.SubAuthorityCount
; j
++)
3912 pisid
->SubAuthority
[j
] = WellKnownSids
[i
].Sid
.SubAuthority
[j
];
3917 FIXME("String constant not supported: %s\n", debugstr_wn(StringSid
, 2));
3922 SetLastError(ERROR_INVALID_SID
);
3924 TRACE("returning %s\n", bret
? "TRUE" : "FALSE");
3928 /******************************************************************************
3929 * GetNamedSecurityInfoA [ADVAPI32.@]
3931 DWORD WINAPI
GetNamedSecurityInfoA(LPSTR pObjectName
,
3932 SE_OBJECT_TYPE ObjectType
, SECURITY_INFORMATION SecurityInfo
,
3933 PSID
* ppsidOwner
, PSID
* ppsidGroup
, PACL
* ppDacl
, PACL
* ppSacl
,
3934 PSECURITY_DESCRIPTOR
* ppSecurityDescriptor
)
3940 TRACE("%s %d %d %p %p %p %p %p\n", pObjectName
, ObjectType
, SecurityInfo
,
3941 ppsidOwner
, ppsidGroup
, ppDacl
, ppSacl
, ppSecurityDescriptor
);
3945 len
= MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, NULL
, 0 );
3946 wstr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
3947 MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, wstr
, len
);
3950 r
= GetNamedSecurityInfoW( wstr
, ObjectType
, SecurityInfo
, ppsidOwner
,
3951 ppsidGroup
, ppDacl
, ppSacl
, ppSecurityDescriptor
);
3953 HeapFree( GetProcessHeap(), 0, wstr
);
3958 /******************************************************************************
3959 * GetNamedSecurityInfoW [ADVAPI32.@]
3961 DWORD WINAPI
GetNamedSecurityInfoW( LPWSTR name
, SE_OBJECT_TYPE type
,
3962 SECURITY_INFORMATION info
, PSID
* owner
, PSID
* group
, PACL
* dacl
,
3963 PACL
* sacl
, PSECURITY_DESCRIPTOR
* descriptor
)
3965 DWORD needed
, offset
;
3966 SECURITY_DESCRIPTOR_RELATIVE
*relative
;
3969 TRACE( "%s %d %d %p %p %p %p %p\n", debugstr_w(name
), type
, info
, owner
,
3970 group
, dacl
, sacl
, descriptor
);
3972 if (!name
|| !descriptor
) return ERROR_INVALID_PARAMETER
;
3974 needed
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
3975 if (info
& OWNER_SECURITY_INFORMATION
)
3976 needed
+= sizeof(sidWorld
);
3977 if (info
& GROUP_SECURITY_INFORMATION
)
3978 needed
+= sizeof(sidWorld
);
3979 if (info
& DACL_SECURITY_INFORMATION
)
3980 needed
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
3981 if (info
& SACL_SECURITY_INFORMATION
)
3982 needed
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
3984 /* must be freed by caller */
3985 *descriptor
= HeapAlloc( GetProcessHeap(), 0, needed
);
3986 if (!*descriptor
) return ERROR_NOT_ENOUGH_MEMORY
;
3988 if (!InitializeSecurityDescriptor( *descriptor
, SECURITY_DESCRIPTOR_REVISION
))
3990 HeapFree( GetProcessHeap(), 0, *descriptor
);
3991 return ERROR_INVALID_SECURITY_DESCR
;
3994 relative
= (SECURITY_DESCRIPTOR_RELATIVE
*)*descriptor
;
3995 relative
->Control
|= SE_SELF_RELATIVE
;
3996 buffer
= (BYTE
*)relative
;
3997 offset
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
3999 if (owner
&& (info
& OWNER_SECURITY_INFORMATION
))
4001 memcpy( buffer
+ offset
, &sidWorld
, sizeof(sidWorld
) );
4002 relative
->Owner
= offset
;
4003 *owner
= buffer
+ offset
;
4004 offset
+= sizeof(sidWorld
);
4006 if (group
&& (info
& GROUP_SECURITY_INFORMATION
))
4008 memcpy( buffer
+ offset
, &sidWorld
, sizeof(sidWorld
) );
4009 relative
->Group
= offset
;
4010 *group
= buffer
+ offset
;
4011 offset
+= sizeof(sidWorld
);
4013 if (dacl
&& (info
& DACL_SECURITY_INFORMATION
))
4015 GetWorldAccessACL( (PACL
)(buffer
+ offset
) );
4016 relative
->Dacl
= offset
;
4017 *dacl
= (PACL
)(buffer
+ offset
);
4018 offset
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
4020 if (sacl
&& (info
& SACL_SECURITY_INFORMATION
))
4022 GetWorldAccessACL( (PACL
)(buffer
+ offset
) );
4023 relative
->Sacl
= offset
;
4024 *sacl
= (PACL
)(buffer
+ offset
);
4026 return ERROR_SUCCESS
;
4029 /******************************************************************************
4030 * DecryptFileW [ADVAPI32.@]
4032 BOOL WINAPI
DecryptFileW(LPCWSTR lpFileName
, DWORD dwReserved
)
4034 FIXME("%s %08x\n", debugstr_w(lpFileName
), dwReserved
);
4038 /******************************************************************************
4039 * DecryptFileA [ADVAPI32.@]
4041 BOOL WINAPI
DecryptFileA(LPCSTR lpFileName
, DWORD dwReserved
)
4043 FIXME("%s %08x\n", debugstr_a(lpFileName
), dwReserved
);
4047 /******************************************************************************
4048 * EncryptFileW [ADVAPI32.@]
4050 BOOL WINAPI
EncryptFileW(LPCWSTR lpFileName
)
4052 FIXME("%s\n", debugstr_w(lpFileName
));
4056 /******************************************************************************
4057 * EncryptFileA [ADVAPI32.@]
4059 BOOL WINAPI
EncryptFileA(LPCSTR lpFileName
)
4061 FIXME("%s\n", debugstr_a(lpFileName
));
4065 /******************************************************************************
4066 * FileEncryptionStatusW [ADVAPI32.@]
4068 BOOL WINAPI
FileEncryptionStatusW(LPCWSTR lpFileName
, LPDWORD lpStatus
)
4070 FIXME("(%s %p): stub\n", debugstr_w(lpFileName
), lpStatus
);
4073 *lpStatus
= FILE_SYSTEM_NOT_SUPPORT
;
4077 /******************************************************************************
4078 * FileEncryptionStatusA [ADVAPI32.@]
4080 BOOL WINAPI
FileEncryptionStatusA(LPCSTR lpFileName
, LPDWORD lpStatus
)
4082 FIXME("(%s %p): stub\n", debugstr_a(lpFileName
), lpStatus
);
4085 *lpStatus
= FILE_SYSTEM_NOT_SUPPORT
;
4089 /******************************************************************************
4090 * SetSecurityInfo [ADVAPI32.@]
4092 DWORD WINAPI
SetSecurityInfo(HANDLE handle
, SE_OBJECT_TYPE ObjectType
,
4093 SECURITY_INFORMATION SecurityInfo
, PSID psidOwner
,
4094 PSID psidGroup
, PACL pDacl
, PACL pSacl
) {
4096 return ERROR_SUCCESS
;