2 * Copyright 1999, 2000 Juergen Schmied <juergen.schmied@debitel.net>
3 * Copyright 2003 CodeWeavers Inc. (Ulrich Czekalla)
4 * Copyright 2006 Robert Reif
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define WIN32_NO_STATUS
40 #include "advapi32_misc.h"
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
47 static BOOL
ParseStringSidToSid(LPCWSTR StringSid
, PSID pSid
, LPDWORD cBytes
);
48 static BOOL
ParseStringAclToAcl(LPCWSTR StringAcl
, LPDWORD lpdwFlags
,
49 PACL pAcl
, LPDWORD cBytes
);
50 static BYTE
ParseAceStringFlags(LPCWSTR
* StringAcl
);
51 static BYTE
ParseAceStringType(LPCWSTR
* StringAcl
);
52 static DWORD
ParseAceStringRights(LPCWSTR
* StringAcl
);
53 static BOOL
ParseStringSecurityDescriptorToSecurityDescriptor(
54 LPCWSTR StringSecurityDescriptor
,
55 SECURITY_DESCRIPTOR
* SecurityDescriptor
,
57 static DWORD
ParseAclStringFlags(LPCWSTR
* StringAcl
);
59 typedef struct _ACEFLAG
63 } ACEFLAG
, *LPACEFLAG
;
65 typedef struct _MAX_SID
67 /* same fields as struct _SID */
69 BYTE SubAuthorityCount
;
70 SID_IDENTIFIER_AUTHORITY IdentifierAuthority
;
71 DWORD SubAuthority
[SID_MAX_SUB_AUTHORITIES
];
74 typedef struct WELLKNOWNSID
77 WELL_KNOWN_SID_TYPE Type
;
81 static const WELLKNOWNSID WellKnownSids
[] =
83 { {0,0}, WinNullSid
, { SID_REVISION
, 1, { SECURITY_NULL_SID_AUTHORITY
}, { SECURITY_NULL_RID
} } },
84 { {'W','D'}, WinWorldSid
, { SID_REVISION
, 1, { SECURITY_WORLD_SID_AUTHORITY
}, { SECURITY_WORLD_RID
} } },
85 { {0,0}, WinLocalSid
, { SID_REVISION
, 1, { SECURITY_LOCAL_SID_AUTHORITY
}, { SECURITY_LOCAL_RID
} } },
86 { {'C','O'}, WinCreatorOwnerSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_OWNER_RID
} } },
87 { {'C','G'}, WinCreatorGroupSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_GROUP_RID
} } },
88 { {0,0}, WinCreatorOwnerServerSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_OWNER_SERVER_RID
} } },
89 { {0,0}, WinCreatorGroupServerSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_GROUP_SERVER_RID
} } },
90 { {0,0}, WinNtAuthoritySid
, { SID_REVISION
, 0, { SECURITY_NT_AUTHORITY
}, { SECURITY_NULL_RID
} } },
91 { {0,0}, WinDialupSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_DIALUP_RID
} } },
92 { {'N','U'}, WinNetworkSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_NETWORK_RID
} } },
93 { {0,0}, WinBatchSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_BATCH_RID
} } },
94 { {'I','U'}, WinInteractiveSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_INTERACTIVE_RID
} } },
95 { {'S','U'}, WinServiceSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_SERVICE_RID
} } },
96 { {'A','N'}, WinAnonymousSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_ANONYMOUS_LOGON_RID
} } },
97 { {0,0}, WinProxySid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_PROXY_RID
} } },
98 { {'E','D'}, WinEnterpriseControllersSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_ENTERPRISE_CONTROLLERS_RID
} } },
99 { {'P','S'}, WinSelfSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_PRINCIPAL_SELF_RID
} } },
100 { {'A','U'}, WinAuthenticatedUserSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_AUTHENTICATED_USER_RID
} } },
101 { {'R','C'}, WinRestrictedCodeSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_RESTRICTED_CODE_RID
} } },
102 { {0,0}, WinTerminalServerSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_TERMINAL_SERVER_RID
} } },
103 { {0,0}, WinRemoteLogonIdSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_REMOTE_LOGON_RID
} } },
104 { {'S','Y'}, WinLocalSystemSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_LOCAL_SYSTEM_RID
} } },
105 { {'L','S'}, WinLocalServiceSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_LOCAL_SERVICE_RID
} } },
106 { {'N','S'}, WinNetworkServiceSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_NETWORK_SERVICE_RID
} } },
107 { {0,0}, WinBuiltinDomainSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
} } },
108 { {'B','A'}, WinBuiltinAdministratorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_ADMINS
} } },
109 { {'B','U'}, WinBuiltinUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_USERS
} } },
110 { {'B','G'}, WinBuiltinGuestsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_GUESTS
} } },
111 { {'P','U'}, WinBuiltinPowerUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_POWER_USERS
} } },
112 { {'A','O'}, WinBuiltinAccountOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_ACCOUNT_OPS
} } },
113 { {'S','O'}, WinBuiltinSystemOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_SYSTEM_OPS
} } },
114 { {'P','O'}, WinBuiltinPrintOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_PRINT_OPS
} } },
115 { {'B','O'}, WinBuiltinBackupOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_BACKUP_OPS
} } },
116 { {'R','E'}, WinBuiltinReplicatorSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_REPLICATOR
} } },
117 { {'R','U'}, WinBuiltinPreWindows2000CompatibleAccessSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_PREW2KCOMPACCESS
} } },
118 { {'R','D'}, WinBuiltinRemoteDesktopUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS
} } },
119 { {'N','O'}, WinBuiltinNetworkConfigurationOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS
} } },
120 { {0,0}, WinNTLMAuthenticationSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_PACKAGE_BASE_RID
, SECURITY_PACKAGE_NTLM_RID
} } },
121 { {0,0}, WinDigestAuthenticationSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_PACKAGE_BASE_RID
, SECURITY_PACKAGE_DIGEST_RID
} } },
122 { {0,0}, WinSChannelAuthenticationSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_PACKAGE_BASE_RID
, SECURITY_PACKAGE_SCHANNEL_RID
} } },
123 { {0,0}, WinThisOrganizationSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_THIS_ORGANIZATION_RID
} } },
124 { {0,0}, WinOtherOrganizationSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_OTHER_ORGANIZATION_RID
} } },
125 { {0,0}, WinBuiltinPerfMonitoringUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_MONITORING_USERS
} } },
126 { {0,0}, WinBuiltinPerfLoggingUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_LOGGING_USERS
} } },
129 static SID
const sidWorld
= { SID_REVISION
, 1, { SECURITY_WORLD_SID_AUTHORITY
} , { SECURITY_WORLD_RID
} };
131 typedef struct _AccountSid
{
132 WELL_KNOWN_SID_TYPE type
;
135 SID_NAME_USE name_use
;
138 static const WCHAR Account_Operators
[] = { 'A','c','c','o','u','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
139 static const WCHAR Administrator
[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0 };
140 static const WCHAR Administrators
[] = { 'A','d','m','i','n','i','s','t','r','a','t','o','r','s',0 };
141 static const WCHAR ANONYMOUS_LOGON
[] = { 'A','N','O','N','Y','M','O','U','S',' ','L','O','G','O','N',0 };
142 static const WCHAR Authenticated_Users
[] = { 'A','u','t','h','e','n','t','i','c','a','t','e','d',' ','U','s','e','r','s',0 };
143 static const WCHAR Backup_Operators
[] = { 'B','a','c','k','u','p',' ','O','p','e','r','a','t','o','r','s',0 };
144 static const WCHAR BATCH
[] = { 'B','A','T','C','H',0 };
145 static const WCHAR Blank
[] = { 0 };
146 static const WCHAR BUILTIN
[] = { 'B','U','I','L','T','I','N',0 };
147 static const WCHAR Cert_Publishers
[] = { 'C','e','r','t',' ','P','u','b','l','i','s','h','e','r','s',0 };
148 static const WCHAR CREATOR_GROUP
[] = { 'C','R','E','A','T','O','R',' ','G','R','O','U','P',0 };
149 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 };
150 static const WCHAR CREATOR_OWNER
[] = { 'C','R','E','A','T','O','R',' ','O','W','N','E','R',0 };
151 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 };
152 static const WCHAR DIALUP
[] = { 'D','I','A','L','U','P',0 };
153 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 };
154 static const WCHAR DOMAIN
[] = {'D','O','M','A','I','N',0};
155 static const WCHAR Domain_Admins
[] = { 'D','o','m','a','i','n',' ','A','d','m','i','n','s',0 };
156 static const WCHAR Domain_Computers
[] = { 'D','o','m','a','i','n',' ','C','o','m','p','u','t','e','r','s',0 };
157 static const WCHAR Domain_Controllers
[] = { 'D','o','m','a','i','n',' ','C','o','n','t','r','o','l','l','e','r','s',0 };
158 static const WCHAR Domain_Guests
[] = { 'D','o','m','a','i','n',' ','G','u','e','s','t','s',0 };
159 static const WCHAR Domain_Users
[] = { 'D','o','m','a','i','n',' ','U','s','e','r','s',0 };
160 static const WCHAR Enterprise_Admins
[] = { 'E','n','t','e','r','p','r','i','s','e',' ','A','d','m','i','n','s',0 };
161 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 };
162 static const WCHAR Everyone
[] = { 'E','v','e','r','y','o','n','e',0 };
163 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 };
164 static const WCHAR Guest
[] = { 'G','u','e','s','t',0 };
165 static const WCHAR Guests
[] = { 'G','u','e','s','t','s',0 };
166 static const WCHAR INTERACTIVE
[] = { 'I','N','T','E','R','A','C','T','I','V','E',0 };
167 static const WCHAR LOCAL
[] = { 'L','O','C','A','L',0 };
168 static const WCHAR LOCAL_SERVICE
[] = { 'L','O','C','A','L',' ','S','E','R','V','I','C','E',0 };
169 static const WCHAR NETWORK
[] = { 'N','E','T','W','O','R','K',0 };
170 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 };
171 static const WCHAR NETWORK_SERVICE
[] = { 'N','E','T','W','O','R','K',' ','S','E','R','V','I','C','E',0 };
172 static const WCHAR NT_AUTHORITY
[] = { 'N','T',' ','A','U','T','H','O','R','I','T','Y',0 };
173 static const WCHAR NT_Pseudo_Domain
[] = { 'N','T',' ','P','s','e','u','d','o',' ','D','o','m','a','i','n',0 };
174 static const WCHAR NTML_Authentication
[] = { 'N','T','M','L',' ','A','u','t','h','e','n','t','i','c','a','t','i','o','n',0 };
175 static const WCHAR NULL_SID
[] = { 'N','U','L','L',' ','S','I','D',0 };
176 static const WCHAR Other_Organization
[] = { 'O','t','h','e','r',' ','O','r','g','a','n','i','z','a','t','i','o','n',0 };
177 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 };
178 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 };
179 static const WCHAR Power_Users
[] = { 'P','o','w','e','r',' ','U','s','e','r','s',0 };
180 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 };
181 static const WCHAR Print_Operators
[] = { 'P','r','i','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
182 static const WCHAR PROXY
[] = { 'P','R','O','X','Y',0 };
183 static const WCHAR RAS_and_IAS_Servers
[] = { 'R','A','S',' ','a','n','d',' ','I','A','S',' ','S','e','r','v','e','r','s',0 };
184 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 };
185 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 };
186 static const WCHAR Replicators
[] = { 'R','e','p','l','i','c','a','t','o','r','s',0 };
187 static const WCHAR RESTRICTED
[] = { 'R','E','S','T','R','I','C','T','E','D',0 };
188 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 };
189 static const WCHAR Schema_Admins
[] = { 'S','c','h','e','m','a',' ','A','d','m','i','n','s',0 };
190 static const WCHAR SELF
[] = { 'S','E','L','F',0 };
191 static const WCHAR Server_Operators
[] = { 'S','e','r','v','e','r',' ','O','p','e','r','a','t','o','r','s',0 };
192 static const WCHAR SERVICE
[] = { 'S','E','R','V','I','C','E',0 };
193 static const WCHAR SYSTEM
[] = { 'S','Y','S','T','E','M',0 };
194 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 };
195 static const WCHAR This_Organization
[] = { 'T','h','i','s',' ','O','r','g','a','n','i','z','a','t','i','o','n',0 };
196 static const WCHAR Users
[] = { 'U','s','e','r','s',0 };
198 static const AccountSid ACCOUNT_SIDS
[] = {
199 { WinNullSid
, NULL_SID
, Blank
, SidTypeWellKnownGroup
},
200 { WinWorldSid
, Everyone
, Blank
, SidTypeWellKnownGroup
},
201 { WinLocalSid
, LOCAL
, Blank
, SidTypeWellKnownGroup
},
202 { WinCreatorOwnerSid
, CREATOR_OWNER
, Blank
, SidTypeWellKnownGroup
},
203 { WinCreatorGroupSid
, CREATOR_GROUP
, Blank
, SidTypeWellKnownGroup
},
204 { WinCreatorOwnerServerSid
, CREATOR_OWNER_SERVER
, Blank
, SidTypeWellKnownGroup
},
205 { WinCreatorGroupServerSid
, CREATOR_GROUP_SERVER
, Blank
, SidTypeWellKnownGroup
},
206 { WinNtAuthoritySid
, NT_Pseudo_Domain
, NT_Pseudo_Domain
, SidTypeDomain
},
207 { WinDialupSid
, DIALUP
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
208 { WinNetworkSid
, NETWORK
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
209 { WinBatchSid
, BATCH
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
210 { WinInteractiveSid
, INTERACTIVE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
211 { WinServiceSid
, SERVICE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
212 { WinAnonymousSid
, ANONYMOUS_LOGON
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
213 { WinProxySid
, PROXY
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
214 { WinEnterpriseControllersSid
, ENTERPRISE_DOMAIN_CONTROLLERS
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
215 { WinSelfSid
, SELF
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
216 { WinAuthenticatedUserSid
, Authenticated_Users
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
217 { WinRestrictedCodeSid
, RESTRICTED
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
218 { WinTerminalServerSid
, TERMINAL_SERVER_USER
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
219 { WinRemoteLogonIdSid
, REMOTE_INTERACTIVE_LOGON
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
220 { WinLocalSystemSid
, SYSTEM
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
221 { WinLocalServiceSid
, LOCAL_SERVICE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
222 { WinNetworkServiceSid
, NETWORK_SERVICE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
223 { WinBuiltinDomainSid
, BUILTIN
, BUILTIN
, SidTypeDomain
},
224 { WinBuiltinAdministratorsSid
, Administrators
, BUILTIN
, SidTypeAlias
},
225 { WinBuiltinUsersSid
, Users
, BUILTIN
, SidTypeAlias
},
226 { WinBuiltinGuestsSid
, Guests
, BUILTIN
, SidTypeAlias
},
227 { WinBuiltinPowerUsersSid
, Power_Users
, BUILTIN
, SidTypeAlias
},
228 { WinBuiltinAccountOperatorsSid
, Account_Operators
, BUILTIN
, SidTypeAlias
},
229 { WinBuiltinSystemOperatorsSid
, Server_Operators
, BUILTIN
, SidTypeAlias
},
230 { WinBuiltinPrintOperatorsSid
, Print_Operators
, BUILTIN
, SidTypeAlias
},
231 { WinBuiltinBackupOperatorsSid
, Backup_Operators
, BUILTIN
, SidTypeAlias
},
232 { WinBuiltinReplicatorSid
, Replicators
, BUILTIN
, SidTypeAlias
},
233 { WinBuiltinPreWindows2000CompatibleAccessSid
, Pre_Windows_2000_Compatible_Access
, BUILTIN
, SidTypeAlias
},
234 { WinBuiltinRemoteDesktopUsersSid
, Remote_Desktop_Users
, BUILTIN
, SidTypeAlias
},
235 { WinBuiltinNetworkConfigurationOperatorsSid
, Network_Configuration_Operators
, BUILTIN
, SidTypeAlias
},
236 { WinNTLMAuthenticationSid
, NTML_Authentication
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
237 { WinDigestAuthenticationSid
, Digest_Authentication
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
238 { WinSChannelAuthenticationSid
, SChannel_Authentication
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
239 { WinThisOrganizationSid
, This_Organization
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
240 { WinOtherOrganizationSid
, Other_Organization
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
241 { WinBuiltinPerfMonitoringUsersSid
, Performance_Monitor_Users
, BUILTIN
, SidTypeAlias
},
242 { WinBuiltinPerfLoggingUsersSid
, Performance_Log_Users
, BUILTIN
, SidTypeAlias
},
247 static const WCHAR SDDL_READ_CONTROL
[] = {'R','C',0};
248 static const WCHAR SDDL_WRITE_DAC
[] = {'W','D',0};
249 static const WCHAR SDDL_WRITE_OWNER
[] = {'W','O',0};
250 static const WCHAR SDDL_STANDARD_DELETE
[] = {'S','D',0};
252 static const WCHAR SDDL_READ_PROPERTY
[] = {'R','P',0};
253 static const WCHAR SDDL_WRITE_PROPERTY
[] = {'W','P',0};
254 static const WCHAR SDDL_CREATE_CHILD
[] = {'C','C',0};
255 static const WCHAR SDDL_DELETE_CHILD
[] = {'D','C',0};
256 static const WCHAR SDDL_LIST_CHILDREN
[] = {'L','C',0};
257 static const WCHAR SDDL_SELF_WRITE
[] = {'S','W',0};
258 static const WCHAR SDDL_LIST_OBJECT
[] = {'L','O',0};
259 static const WCHAR SDDL_DELETE_TREE
[] = {'D','T',0};
260 static const WCHAR SDDL_CONTROL_ACCESS
[] = {'C','R',0};
262 static const WCHAR SDDL_FILE_ALL
[] = {'F','A',0};
263 static const WCHAR SDDL_FILE_READ
[] = {'F','R',0};
264 static const WCHAR SDDL_FILE_WRITE
[] = {'F','W',0};
265 static const WCHAR SDDL_FILE_EXECUTE
[] = {'F','X',0};
267 static const WCHAR SDDL_KEY_ALL
[] = {'K','A',0};
268 static const WCHAR SDDL_KEY_READ
[] = {'K','R',0};
269 static const WCHAR SDDL_KEY_WRITE
[] = {'K','W',0};
270 static const WCHAR SDDL_KEY_EXECUTE
[] = {'K','X',0};
272 static const WCHAR SDDL_GENERIC_ALL
[] = {'G','A',0};
273 static const WCHAR SDDL_GENERIC_READ
[] = {'G','R',0};
274 static const WCHAR SDDL_GENERIC_WRITE
[] = {'G','W',0};
275 static const WCHAR SDDL_GENERIC_EXECUTE
[] = {'G','X',0};
280 static const WCHAR SDDL_ACCESS_ALLOWED
[] = {'A',0};
281 static const WCHAR SDDL_ACCESS_DENIED
[] = {'D',0};
282 static const WCHAR SDDL_OBJECT_ACCESS_ALLOWED
[] = {'O','A',0};
283 static const WCHAR SDDL_OBJECT_ACCESS_DENIED
[] = {'O','D',0};
284 static const WCHAR SDDL_AUDIT
[] = {'A','U',0};
285 static const WCHAR SDDL_ALARM
[] = {'A','L',0};
286 static const WCHAR SDDL_OBJECT_AUDIT
[] = {'O','U',0};
287 static const WCHAR SDDL_OBJECT_ALARMp
[] = {'O','L',0};
292 static const WCHAR SDDL_CONTAINER_INHERIT
[] = {'C','I',0};
293 static const WCHAR SDDL_OBJECT_INHERIT
[] = {'O','I',0};
294 static const WCHAR SDDL_NO_PROPAGATE
[] = {'N','P',0};
295 static const WCHAR SDDL_INHERIT_ONLY
[] = {'I','O',0};
296 static const WCHAR SDDL_INHERITED
[] = {'I','D',0};
297 static const WCHAR SDDL_AUDIT_SUCCESS
[] = {'S','A',0};
298 static const WCHAR SDDL_AUDIT_FAILURE
[] = {'F','A',0};
300 const char * debugstr_sid(PSID sid
)
303 SID
* psid
= (SID
*)sid
;
308 auth
= psid
->IdentifierAuthority
.Value
[5] +
309 (psid
->IdentifierAuthority
.Value
[4] << 8) +
310 (psid
->IdentifierAuthority
.Value
[3] << 16) +
311 (psid
->IdentifierAuthority
.Value
[2] << 24);
313 switch (psid
->SubAuthorityCount
) {
315 return wine_dbg_sprintf("S-%d-%d", psid
->Revision
, auth
);
317 return wine_dbg_sprintf("S-%d-%d-%u", psid
->Revision
, auth
,
318 psid
->SubAuthority
[0]);
320 return wine_dbg_sprintf("S-%d-%d-%u-%u", psid
->Revision
, auth
,
321 psid
->SubAuthority
[0], psid
->SubAuthority
[1]);
323 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u", psid
->Revision
, auth
,
324 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2]);
326 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u", psid
->Revision
, auth
,
327 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
328 psid
->SubAuthority
[3]);
330 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
331 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
332 psid
->SubAuthority
[3], psid
->SubAuthority
[4]);
334 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
335 psid
->SubAuthority
[3], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
336 psid
->SubAuthority
[0], psid
->SubAuthority
[4], psid
->SubAuthority
[5]);
338 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
339 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
340 psid
->SubAuthority
[3], psid
->SubAuthority
[4], psid
->SubAuthority
[5],
341 psid
->SubAuthority
[6]);
343 return wine_dbg_sprintf("S-%d-%d-%u-%u-%u-%u-%u-%u-%u-%u", psid
->Revision
, auth
,
344 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
345 psid
->SubAuthority
[3], psid
->SubAuthority
[4], psid
->SubAuthority
[5],
346 psid
->SubAuthority
[6], psid
->SubAuthority
[7]);
351 /* set last error code from NT status and get the proper boolean return value */
352 /* used for functions that are a simple wrapper around the corresponding ntdll API */
353 static inline BOOL
set_ntstatus( NTSTATUS status
)
355 if (status
) SetLastError( RtlNtStatusToDosError( status
));
359 #define WINE_SIZE_OF_WORLD_ACCESS_ACL (sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD))
361 static void GetWorldAccessACL(PACL pACL
)
363 PACCESS_ALLOWED_ACE pACE
= (PACCESS_ALLOWED_ACE
) (pACL
+ 1);
365 pACL
->AclRevision
= ACL_REVISION
;
367 pACL
->AclSize
= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
371 pACE
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
372 pACE
->Header
.AceFlags
= CONTAINER_INHERIT_ACE
;
373 pACE
->Header
.AceSize
= sizeof(ACCESS_ALLOWED_ACE
) + sizeof(sidWorld
) - sizeof(DWORD
);
374 pACE
->Mask
= 0xf3ffffff; /* Everything except reserved bits */
375 memcpy(&pACE
->SidStart
, &sidWorld
, sizeof(sidWorld
));
378 /************************************************************
379 * ADVAPI_IsLocalComputer
381 * Checks whether the server name indicates local machine.
383 BOOL
ADVAPI_IsLocalComputer(LPCWSTR ServerName
)
385 DWORD dwSize
= MAX_COMPUTERNAME_LENGTH
+ 1;
389 if (!ServerName
|| !ServerName
[0])
392 buf
= HeapAlloc(GetProcessHeap(), 0, dwSize
* sizeof(WCHAR
));
393 Result
= GetComputerNameW(buf
, &dwSize
);
394 if (Result
&& (ServerName
[0] == '\\') && (ServerName
[1] == '\\'))
396 Result
= Result
&& !lstrcmpW(ServerName
, buf
);
397 HeapFree(GetProcessHeap(), 0, buf
);
402 /************************************************************
403 * ADVAPI_GetComputerSid
405 * Reads the computer SID from the registry.
407 BOOL
ADVAPI_GetComputerSid(PSID sid
)
412 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 };
413 static const WCHAR V
[] = { 'V',0 };
415 if ((ret
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, Account
, 0,
416 KEY_READ
, &key
)) == ERROR_SUCCESS
)
419 ret
= RegQueryValueExW(key
, V
, NULL
, NULL
, NULL
, &size
);
420 if (ret
== ERROR_MORE_DATA
|| ret
== ERROR_SUCCESS
)
422 BYTE
* data
= HeapAlloc(GetProcessHeap(), 0, size
);
425 if ((ret
= RegQueryValueExW(key
, V
, NULL
, NULL
,
426 data
, &size
)) == ERROR_SUCCESS
)
428 /* the SID is in the last 24 bytes of the binary data */
429 CopyMemory(sid
, &data
[size
-24], 24);
432 HeapFree(GetProcessHeap(), 0, data
);
438 if(retval
== TRUE
) return retval
;
440 /* create a new random SID */
441 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Account
,
442 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
) == ERROR_SUCCESS
)
445 SID_IDENTIFIER_AUTHORITY identifierAuthority
= {SECURITY_NT_AUTHORITY
};
448 if (RtlGenRandom(&id
, sizeof(id
)))
450 if (AllocateAndInitializeSid(&identifierAuthority
, 4, SECURITY_NT_NON_UNIQUE
, id
[0], id
[1], id
[2], 0, 0, 0, 0, &new_sid
))
452 if (RegSetValueExW(key
, V
, 0, REG_BINARY
, new_sid
, GetLengthSid(new_sid
)) == ERROR_SUCCESS
)
453 retval
= CopySid(GetLengthSid(new_sid
), sid
, new_sid
);
464 /* ##############################
465 ###### TOKEN FUNCTIONS ######
466 ##############################
469 /******************************************************************************
470 * OpenProcessToken [ADVAPI32.@]
471 * Opens the access token associated with a process handle.
474 * ProcessHandle [I] Handle to process
475 * DesiredAccess [I] Desired access to process
476 * TokenHandle [O] Pointer to handle of open access token
479 * Success: TRUE. TokenHandle contains the access token.
483 * See NtOpenProcessToken.
486 OpenProcessToken( HANDLE ProcessHandle
, DWORD DesiredAccess
,
487 HANDLE
*TokenHandle
)
489 return set_ntstatus(NtOpenProcessToken( ProcessHandle
, DesiredAccess
, TokenHandle
));
492 /******************************************************************************
493 * OpenThreadToken [ADVAPI32.@]
495 * Opens the access token associated with a thread handle.
498 * ThreadHandle [I] Handle to process
499 * DesiredAccess [I] Desired access to the thread
501 * TokenHandle [O] Destination for the token handle
504 * Success: TRUE. TokenHandle contains the access token.
508 * See NtOpenThreadToken.
511 OpenThreadToken( HANDLE ThreadHandle
, DWORD DesiredAccess
,
512 BOOL OpenAsSelf
, HANDLE
*TokenHandle
)
514 return set_ntstatus( NtOpenThreadToken(ThreadHandle
, DesiredAccess
, OpenAsSelf
, TokenHandle
));
518 AdjustTokenGroups( HANDLE TokenHandle
, BOOL ResetToDefault
, PTOKEN_GROUPS NewState
,
519 DWORD BufferLength
, PTOKEN_GROUPS PreviousState
, PDWORD ReturnLength
)
521 return set_ntstatus( NtAdjustGroupsToken(TokenHandle
, ResetToDefault
, NewState
, BufferLength
,
522 PreviousState
, ReturnLength
));
525 /******************************************************************************
526 * AdjustTokenPrivileges [ADVAPI32.@]
528 * Adjust the privileges of an open token handle.
531 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
532 * DisableAllPrivileges [I] TRUE=Remove all privileges, FALSE=Use NewState
533 * NewState [I] Desired new privileges of the token
534 * BufferLength [I] Length of NewState
535 * PreviousState [O] Destination for the previous state
536 * ReturnLength [I/O] Size of PreviousState
540 * Success: TRUE. Privileges are set to NewState and PreviousState is updated.
544 * See NtAdjustPrivilegesToken.
547 AdjustTokenPrivileges( HANDLE TokenHandle
, BOOL DisableAllPrivileges
,
548 LPVOID NewState
, DWORD BufferLength
,
549 LPVOID PreviousState
, LPDWORD ReturnLength
)
555 status
= NtAdjustPrivilegesToken(TokenHandle
, DisableAllPrivileges
,
556 NewState
, BufferLength
, PreviousState
,
558 SetLastError( RtlNtStatusToDosError( status
));
559 if ((status
== STATUS_SUCCESS
) || (status
== STATUS_NOT_ALL_ASSIGNED
))
565 /******************************************************************************
566 * CheckTokenMembership [ADVAPI32.@]
568 * Determine if an access token is a member of a SID.
571 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
572 * SidToCheck [I] SID that possibly contains the token
573 * IsMember [O] Destination for result.
576 * Success: TRUE. IsMember is TRUE if TokenHandle is a member, FALSE otherwise.
580 CheckTokenMembership( HANDLE TokenHandle
, PSID SidToCheck
,
583 FIXME("(%p %p %p) stub!\n", TokenHandle
, SidToCheck
, IsMember
);
589 /******************************************************************************
590 * GetTokenInformation [ADVAPI32.@]
592 * Get a type of information about an access token.
595 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
596 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
597 * tokeninfo [O] Destination for token information
598 * tokeninfolength [I] Length of tokeninfo
599 * retlen [O] Destination for returned token information length
602 * Success: TRUE. tokeninfo contains retlen bytes of token information
606 * See NtQueryInformationToken.
609 GetTokenInformation( HANDLE token
, TOKEN_INFORMATION_CLASS tokeninfoclass
,
610 LPVOID tokeninfo
, DWORD tokeninfolength
, LPDWORD retlen
)
612 TRACE("(%p, %s, %p, %d, %p):\n",
614 (tokeninfoclass
== TokenUser
) ? "TokenUser" :
615 (tokeninfoclass
== TokenGroups
) ? "TokenGroups" :
616 (tokeninfoclass
== TokenPrivileges
) ? "TokenPrivileges" :
617 (tokeninfoclass
== TokenOwner
) ? "TokenOwner" :
618 (tokeninfoclass
== TokenPrimaryGroup
) ? "TokenPrimaryGroup" :
619 (tokeninfoclass
== TokenDefaultDacl
) ? "TokenDefaultDacl" :
620 (tokeninfoclass
== TokenSource
) ? "TokenSource" :
621 (tokeninfoclass
== TokenType
) ? "TokenType" :
622 (tokeninfoclass
== TokenImpersonationLevel
) ? "TokenImpersonationLevel" :
623 (tokeninfoclass
== TokenStatistics
) ? "TokenStatistics" :
624 (tokeninfoclass
== TokenRestrictedSids
) ? "TokenRestrictedSids" :
625 (tokeninfoclass
== TokenSessionId
) ? "TokenSessionId" :
626 (tokeninfoclass
== TokenGroupsAndPrivileges
) ? "TokenGroupsAndPrivileges" :
627 (tokeninfoclass
== TokenSessionReference
) ? "TokenSessionReference" :
628 (tokeninfoclass
== TokenSandBoxInert
) ? "TokenSandBoxInert" :
630 tokeninfo
, tokeninfolength
, retlen
);
631 return set_ntstatus( NtQueryInformationToken( token
, tokeninfoclass
, tokeninfo
,
632 tokeninfolength
, retlen
));
635 /******************************************************************************
636 * SetTokenInformation [ADVAPI32.@]
638 * Set information for an access token.
641 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
642 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
643 * tokeninfo [I] Token information to set
644 * tokeninfolength [I] Length of tokeninfo
647 * Success: TRUE. The information for the token is set to tokeninfo.
651 SetTokenInformation( HANDLE token
, TOKEN_INFORMATION_CLASS tokeninfoclass
,
652 LPVOID tokeninfo
, DWORD tokeninfolength
)
654 TRACE("(%p, %s, %p, %d): stub\n",
656 (tokeninfoclass
== TokenUser
) ? "TokenUser" :
657 (tokeninfoclass
== TokenGroups
) ? "TokenGroups" :
658 (tokeninfoclass
== TokenPrivileges
) ? "TokenPrivileges" :
659 (tokeninfoclass
== TokenOwner
) ? "TokenOwner" :
660 (tokeninfoclass
== TokenPrimaryGroup
) ? "TokenPrimaryGroup" :
661 (tokeninfoclass
== TokenDefaultDacl
) ? "TokenDefaultDacl" :
662 (tokeninfoclass
== TokenSource
) ? "TokenSource" :
663 (tokeninfoclass
== TokenType
) ? "TokenType" :
664 (tokeninfoclass
== TokenImpersonationLevel
) ? "TokenImpersonationLevel" :
665 (tokeninfoclass
== TokenStatistics
) ? "TokenStatistics" :
666 (tokeninfoclass
== TokenRestrictedSids
) ? "TokenRestrictedSids" :
667 (tokeninfoclass
== TokenSessionId
) ? "TokenSessionId" :
668 (tokeninfoclass
== TokenGroupsAndPrivileges
) ? "TokenGroupsAndPrivileges" :
669 (tokeninfoclass
== TokenSessionReference
) ? "TokenSessionReference" :
670 (tokeninfoclass
== TokenSandBoxInert
) ? "TokenSandBoxInert" :
672 tokeninfo
, tokeninfolength
);
674 return set_ntstatus( NtSetInformationToken( token
, tokeninfoclass
, tokeninfo
, tokeninfolength
));
677 /*************************************************************************
678 * SetThreadToken [ADVAPI32.@]
680 * Assigns an 'impersonation token' to a thread so it can assume the
681 * security privileges of another thread or process. Can also remove
682 * a previously assigned token.
685 * thread [O] Handle to thread to set the token for
686 * token [I] Token to set
689 * Success: TRUE. The threads access token is set to token
693 * Only supported on NT or higher. On Win9X this function does nothing.
694 * See SetTokenInformation.
696 BOOL WINAPI
SetThreadToken(PHANDLE thread
, HANDLE token
)
698 return set_ntstatus( NtSetInformationThread( thread
? *thread
: GetCurrentThread(),
699 ThreadImpersonationToken
, &token
, sizeof token
));
702 /* ##############################
703 ###### SID FUNCTIONS ######
704 ##############################
707 /******************************************************************************
708 * AllocateAndInitializeSid [ADVAPI32.@]
711 * pIdentifierAuthority []
712 * nSubAuthorityCount []
724 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
725 BYTE nSubAuthorityCount
,
726 DWORD nSubAuthority0
, DWORD nSubAuthority1
,
727 DWORD nSubAuthority2
, DWORD nSubAuthority3
,
728 DWORD nSubAuthority4
, DWORD nSubAuthority5
,
729 DWORD nSubAuthority6
, DWORD nSubAuthority7
,
732 return set_ntstatus( RtlAllocateAndInitializeSid(
733 pIdentifierAuthority
, nSubAuthorityCount
,
734 nSubAuthority0
, nSubAuthority1
, nSubAuthority2
, nSubAuthority3
,
735 nSubAuthority4
, nSubAuthority5
, nSubAuthority6
, nSubAuthority7
,
739 /******************************************************************************
740 * FreeSid [ADVAPI32.@]
749 return NULL
; /* is documented like this */
752 /******************************************************************************
753 * CopySid [ADVAPI32.@]
756 * nDestinationSidLength []
761 CopySid( DWORD nDestinationSidLength
, PSID pDestinationSid
, PSID pSourceSid
)
763 return RtlCopySid(nDestinationSidLength
, pDestinationSid
, pSourceSid
);
766 /******************************************************************************
767 * CreateWellKnownSid [ADVAPI32.@]
770 CreateWellKnownSid( WELL_KNOWN_SID_TYPE WellKnownSidType
,
776 TRACE("(%d, %s, %p, %p)\n", WellKnownSidType
, debugstr_sid(DomainSid
), pSid
, cbSid
);
778 if (DomainSid
!= NULL
) {
779 FIXME("Only local computer supported!\n");
780 SetLastError(ERROR_INVALID_PARAMETER
); /* FIXME */
784 if (cbSid
== NULL
|| pSid
== NULL
) {
785 SetLastError(ERROR_INVALID_PARAMETER
);
789 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++) {
790 if (WellKnownSids
[i
].Type
== WellKnownSidType
) {
791 DWORD length
= GetSidLengthRequired(WellKnownSids
[i
].Sid
.SubAuthorityCount
);
793 if (*cbSid
< length
) {
794 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
798 CopyMemory(pSid
, &WellKnownSids
[i
].Sid
.Revision
, length
);
804 SetLastError(ERROR_INVALID_PARAMETER
);
808 /******************************************************************************
809 * IsWellKnownSid [ADVAPI32.@]
812 IsWellKnownSid( PSID pSid
, WELL_KNOWN_SID_TYPE WellKnownSidType
)
815 TRACE("(%s, %d)\n", debugstr_sid(pSid
), WellKnownSidType
);
817 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
818 if (WellKnownSids
[i
].Type
== WellKnownSidType
)
819 if (EqualSid(pSid
, (PSID
)&(WellKnownSids
[i
].Sid
.Revision
)))
826 IsTokenRestricted( HANDLE TokenHandle
)
828 TOKEN_GROUPS
*groups
;
833 TRACE("(%p)\n", TokenHandle
);
835 status
= NtQueryInformationToken(TokenHandle
, TokenRestrictedSids
, NULL
, 0, &size
);
836 if (status
!= STATUS_BUFFER_TOO_SMALL
)
839 groups
= HeapAlloc(GetProcessHeap(), 0, size
);
842 SetLastError(ERROR_OUTOFMEMORY
);
846 status
= NtQueryInformationToken(TokenHandle
, TokenRestrictedSids
, groups
, size
, &size
);
847 if (status
!= STATUS_SUCCESS
)
849 HeapFree(GetProcessHeap(), 0, groups
);
850 return set_ntstatus(status
);
853 if (groups
->GroupCount
)
858 HeapFree(GetProcessHeap(), 0, groups
);
863 /******************************************************************************
864 * IsValidSid [ADVAPI32.@]
870 IsValidSid( PSID pSid
)
872 return RtlValidSid( pSid
);
875 /******************************************************************************
876 * EqualSid [ADVAPI32.@]
883 EqualSid( PSID pSid1
, PSID pSid2
)
885 return RtlEqualSid( pSid1
, pSid2
);
888 /******************************************************************************
889 * EqualPrefixSid [ADVAPI32.@]
891 BOOL WINAPI
EqualPrefixSid (PSID pSid1
, PSID pSid2
)
893 return RtlEqualPrefixSid(pSid1
, pSid2
);
896 /******************************************************************************
897 * GetSidLengthRequired [ADVAPI32.@]
900 * nSubAuthorityCount []
903 GetSidLengthRequired( BYTE nSubAuthorityCount
)
905 return RtlLengthRequiredSid(nSubAuthorityCount
);
908 /******************************************************************************
909 * InitializeSid [ADVAPI32.@]
912 * pIdentifierAuthority []
917 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
918 BYTE nSubAuthorityCount
)
920 return RtlInitializeSid(pSid
, pIdentifierAuthority
, nSubAuthorityCount
);
924 GetEffectiveRightsFromAclA( PACL pacl
, PTRUSTEEA pTrustee
, PACCESS_MASK pAccessRights
)
926 FIXME("%p %p %p - stub\n", pacl
, pTrustee
, pAccessRights
);
932 GetEffectiveRightsFromAclW( PACL pacl
, PTRUSTEEW pTrustee
, PACCESS_MASK pAccessRights
)
934 FIXME("%p %p %p - stub\n", pacl
, pTrustee
, pAccessRights
);
939 /******************************************************************************
940 * GetSidIdentifierAuthority [ADVAPI32.@]
945 PSID_IDENTIFIER_AUTHORITY WINAPI
946 GetSidIdentifierAuthority( PSID pSid
)
948 return RtlIdentifierAuthoritySid(pSid
);
951 /******************************************************************************
952 * GetSidSubAuthority [ADVAPI32.@]
959 GetSidSubAuthority( PSID pSid
, DWORD nSubAuthority
)
961 return RtlSubAuthoritySid(pSid
, nSubAuthority
);
964 /******************************************************************************
965 * GetSidSubAuthorityCount [ADVAPI32.@]
971 GetSidSubAuthorityCount (PSID pSid
)
973 return RtlSubAuthorityCountSid(pSid
);
976 /******************************************************************************
977 * GetLengthSid [ADVAPI32.@]
983 GetLengthSid (PSID pSid
)
985 return RtlLengthSid(pSid
);
988 /* ##############################################
989 ###### SECURITY DESCRIPTOR FUNCTIONS ######
990 ##############################################
993 /******************************************************************************
994 * BuildSecurityDescriptorA [ADVAPI32.@]
1001 * cCountOfAccessEntries [I]
1002 * pListOfAccessEntries [I]
1003 * cCountOfAuditEntries [I]
1004 * pListofAuditEntries [I]
1006 * lpdwBufferLength [I/O]
1010 * Success: ERROR_SUCCESS
1011 * Failure: nonzero error code from Winerror.h
1013 DWORD WINAPI
BuildSecurityDescriptorA(
1014 IN PTRUSTEEA pOwner
,
1015 IN PTRUSTEEA pGroup
,
1016 IN ULONG cCountOfAccessEntries
,
1017 IN PEXPLICIT_ACCESSA pListOfAccessEntries
,
1018 IN ULONG cCountOfAuditEntries
,
1019 IN PEXPLICIT_ACCESSA pListofAuditEntries
,
1020 IN PSECURITY_DESCRIPTOR pOldSD
,
1021 IN OUT PULONG lpdwBufferLength
,
1022 OUT PSECURITY_DESCRIPTOR
* pNewSD
)
1024 FIXME("(%p,%p,%d,%p,%d,%p,%p,%p,%p) stub!\n",pOwner
,pGroup
,
1025 cCountOfAccessEntries
,pListOfAccessEntries
,cCountOfAuditEntries
,
1026 pListofAuditEntries
,pOldSD
,lpdwBufferLength
,pNewSD
);
1028 return ERROR_CALL_NOT_IMPLEMENTED
;
1031 /******************************************************************************
1032 * BuildSecurityDescriptorW [ADVAPI32.@]
1034 * See BuildSecurityDescriptorA.
1036 DWORD WINAPI
BuildSecurityDescriptorW(
1037 IN PTRUSTEEW pOwner
,
1038 IN PTRUSTEEW pGroup
,
1039 IN ULONG cCountOfAccessEntries
,
1040 IN PEXPLICIT_ACCESSW pListOfAccessEntries
,
1041 IN ULONG cCountOfAuditEntries
,
1042 IN PEXPLICIT_ACCESSW pListofAuditEntries
,
1043 IN PSECURITY_DESCRIPTOR pOldSD
,
1044 IN OUT PULONG lpdwBufferLength
,
1045 OUT PSECURITY_DESCRIPTOR
* pNewSD
)
1047 FIXME("(%p,%p,%d,%p,%d,%p,%p,%p,%p) stub!\n",pOwner
,pGroup
,
1048 cCountOfAccessEntries
,pListOfAccessEntries
,cCountOfAuditEntries
,
1049 pListofAuditEntries
,pOldSD
,lpdwBufferLength
,pNewSD
);
1051 return ERROR_CALL_NOT_IMPLEMENTED
;
1054 /******************************************************************************
1055 * InitializeSecurityDescriptor [ADVAPI32.@]
1062 InitializeSecurityDescriptor( PSECURITY_DESCRIPTOR pDescr
, DWORD revision
)
1064 return set_ntstatus( RtlCreateSecurityDescriptor(pDescr
, revision
));
1068 /******************************************************************************
1069 * MakeAbsoluteSD [ADVAPI32.@]
1071 BOOL WINAPI
MakeAbsoluteSD (
1072 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor
,
1073 OUT PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor
,
1074 OUT LPDWORD lpdwAbsoluteSecurityDescriptorSize
,
1076 OUT LPDWORD lpdwDaclSize
,
1078 OUT LPDWORD lpdwSaclSize
,
1080 OUT LPDWORD lpdwOwnerSize
,
1081 OUT PSID pPrimaryGroup
,
1082 OUT LPDWORD lpdwPrimaryGroupSize
)
1084 return set_ntstatus( RtlSelfRelativeToAbsoluteSD(pSelfRelativeSecurityDescriptor
,
1085 pAbsoluteSecurityDescriptor
,
1086 lpdwAbsoluteSecurityDescriptorSize
,
1087 pDacl
, lpdwDaclSize
, pSacl
, lpdwSaclSize
,
1088 pOwner
, lpdwOwnerSize
,
1089 pPrimaryGroup
, lpdwPrimaryGroupSize
));
1092 /******************************************************************************
1093 * GetKernelObjectSecurity [ADVAPI32.@]
1095 BOOL WINAPI
GetKernelObjectSecurity(
1097 SECURITY_INFORMATION RequestedInformation
,
1098 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1100 LPDWORD lpnLengthNeeded
)
1102 TRACE("(%p,0x%08x,%p,0x%08x,%p)\n", Handle
, RequestedInformation
,
1103 pSecurityDescriptor
, nLength
, lpnLengthNeeded
);
1105 return set_ntstatus( NtQuerySecurityObject(Handle
, RequestedInformation
, pSecurityDescriptor
,
1106 nLength
, lpnLengthNeeded
));
1109 /******************************************************************************
1110 * GetPrivateObjectSecurity [ADVAPI32.@]
1112 BOOL WINAPI
GetPrivateObjectSecurity(
1113 PSECURITY_DESCRIPTOR ObjectDescriptor
,
1114 SECURITY_INFORMATION SecurityInformation
,
1115 PSECURITY_DESCRIPTOR ResultantDescriptor
,
1116 DWORD DescriptorLength
,
1117 PDWORD ReturnLength
)
1119 TRACE("(%p,0x%08x,%p,0x%08x,%p)\n", ObjectDescriptor
, SecurityInformation
,
1120 ResultantDescriptor
, DescriptorLength
, ReturnLength
);
1122 return set_ntstatus( NtQuerySecurityObject(ObjectDescriptor
, SecurityInformation
,
1123 ResultantDescriptor
, DescriptorLength
, ReturnLength
));
1126 /******************************************************************************
1127 * GetSecurityDescriptorLength [ADVAPI32.@]
1129 DWORD WINAPI
GetSecurityDescriptorLength( PSECURITY_DESCRIPTOR pDescr
)
1131 return RtlLengthSecurityDescriptor(pDescr
);
1134 /******************************************************************************
1135 * GetSecurityDescriptorOwner [ADVAPI32.@]
1139 * lpbOwnerDefaulted []
1142 GetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pDescr
, PSID
*pOwner
,
1143 LPBOOL lpbOwnerDefaulted
)
1146 BOOL ret
= set_ntstatus( RtlGetOwnerSecurityDescriptor( pDescr
, pOwner
, &defaulted
));
1147 *lpbOwnerDefaulted
= defaulted
;
1151 /******************************************************************************
1152 * SetSecurityDescriptorOwner [ADVAPI32.@]
1156 BOOL WINAPI
SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1157 PSID pOwner
, BOOL bOwnerDefaulted
)
1159 return set_ntstatus( RtlSetOwnerSecurityDescriptor(pSecurityDescriptor
, pOwner
, bOwnerDefaulted
));
1161 /******************************************************************************
1162 * GetSecurityDescriptorGroup [ADVAPI32.@]
1164 BOOL WINAPI
GetSecurityDescriptorGroup(
1165 PSECURITY_DESCRIPTOR SecurityDescriptor
,
1167 LPBOOL GroupDefaulted
)
1170 BOOL ret
= set_ntstatus( RtlGetGroupSecurityDescriptor(SecurityDescriptor
, Group
, &defaulted
));
1171 *GroupDefaulted
= defaulted
;
1174 /******************************************************************************
1175 * SetSecurityDescriptorGroup [ADVAPI32.@]
1177 BOOL WINAPI
SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor
,
1178 PSID Group
, BOOL GroupDefaulted
)
1180 return set_ntstatus( RtlSetGroupSecurityDescriptor( SecurityDescriptor
, Group
, GroupDefaulted
));
1183 /******************************************************************************
1184 * IsValidSecurityDescriptor [ADVAPI32.@]
1190 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor
)
1192 return set_ntstatus( RtlValidSecurityDescriptor(SecurityDescriptor
));
1195 /******************************************************************************
1196 * GetSecurityDescriptorDacl [ADVAPI32.@]
1198 BOOL WINAPI
GetSecurityDescriptorDacl(
1199 IN PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1200 OUT LPBOOL lpbDaclPresent
,
1202 OUT LPBOOL lpbDaclDefaulted
)
1204 BOOLEAN present
, defaulted
;
1205 BOOL ret
= set_ntstatus( RtlGetDaclSecurityDescriptor(pSecurityDescriptor
, &present
, pDacl
, &defaulted
));
1206 *lpbDaclPresent
= present
;
1207 *lpbDaclDefaulted
= defaulted
;
1211 /******************************************************************************
1212 * SetSecurityDescriptorDacl [ADVAPI32.@]
1215 SetSecurityDescriptorDacl (
1216 PSECURITY_DESCRIPTOR lpsd
,
1219 BOOL dacldefaulted
)
1221 return set_ntstatus( RtlSetDaclSecurityDescriptor (lpsd
, daclpresent
, dacl
, dacldefaulted
) );
1223 /******************************************************************************
1224 * GetSecurityDescriptorSacl [ADVAPI32.@]
1226 BOOL WINAPI
GetSecurityDescriptorSacl(
1227 IN PSECURITY_DESCRIPTOR lpsd
,
1228 OUT LPBOOL lpbSaclPresent
,
1230 OUT LPBOOL lpbSaclDefaulted
)
1232 BOOLEAN present
, defaulted
;
1233 BOOL ret
= set_ntstatus( RtlGetSaclSecurityDescriptor(lpsd
, &present
, pSacl
, &defaulted
) );
1234 *lpbSaclPresent
= present
;
1235 *lpbSaclDefaulted
= defaulted
;
1239 /**************************************************************************
1240 * SetSecurityDescriptorSacl [ADVAPI32.@]
1242 BOOL WINAPI
SetSecurityDescriptorSacl (
1243 PSECURITY_DESCRIPTOR lpsd
,
1248 return set_ntstatus (RtlSetSaclSecurityDescriptor(lpsd
, saclpresent
, lpsacl
, sacldefaulted
));
1250 /******************************************************************************
1251 * MakeSelfRelativeSD [ADVAPI32.@]
1260 IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor
,
1261 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor
,
1262 IN OUT LPDWORD lpdwBufferLength
)
1264 return set_ntstatus( RtlMakeSelfRelativeSD( pAbsoluteSecurityDescriptor
,
1265 pSelfRelativeSecurityDescriptor
, lpdwBufferLength
));
1268 /******************************************************************************
1269 * GetSecurityDescriptorControl [ADVAPI32.@]
1272 BOOL WINAPI
GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1273 PSECURITY_DESCRIPTOR_CONTROL pControl
, LPDWORD lpdwRevision
)
1275 return set_ntstatus( RtlGetControlSecurityDescriptor(pSecurityDescriptor
,pControl
,lpdwRevision
));
1278 /* ##############################
1279 ###### ACL FUNCTIONS ######
1280 ##############################
1283 /*************************************************************************
1284 * InitializeAcl [ADVAPI32.@]
1286 BOOL WINAPI
InitializeAcl(PACL acl
, DWORD size
, DWORD rev
)
1288 return set_ntstatus( RtlCreateAcl(acl
, size
, rev
));
1291 BOOL WINAPI
ImpersonateNamedPipeClient( HANDLE hNamedPipe
)
1293 IO_STATUS_BLOCK io_block
;
1295 TRACE("(%p)\n", hNamedPipe
);
1297 return set_ntstatus( NtFsControlFile(hNamedPipe
, NULL
, NULL
, NULL
,
1298 &io_block
, FSCTL_PIPE_IMPERSONATE
, NULL
, 0, NULL
, 0) );
1301 /******************************************************************************
1302 * AddAccessAllowedAce [ADVAPI32.@]
1304 BOOL WINAPI
AddAccessAllowedAce(
1306 IN DWORD dwAceRevision
,
1307 IN DWORD AccessMask
,
1310 return set_ntstatus(RtlAddAccessAllowedAce(pAcl
, dwAceRevision
, AccessMask
, pSid
));
1313 /******************************************************************************
1314 * AddAccessAllowedAceEx [ADVAPI32.@]
1316 BOOL WINAPI
AddAccessAllowedAceEx(
1318 IN DWORD dwAceRevision
,
1320 IN DWORD AccessMask
,
1323 return set_ntstatus(RtlAddAccessAllowedAceEx(pAcl
, dwAceRevision
, AceFlags
, AccessMask
, pSid
));
1326 /******************************************************************************
1327 * AddAccessDeniedAce [ADVAPI32.@]
1329 BOOL WINAPI
AddAccessDeniedAce(
1331 IN DWORD dwAceRevision
,
1332 IN DWORD AccessMask
,
1335 return set_ntstatus(RtlAddAccessDeniedAce(pAcl
, dwAceRevision
, AccessMask
, pSid
));
1338 /******************************************************************************
1339 * AddAccessDeniedAceEx [ADVAPI32.@]
1341 BOOL WINAPI
AddAccessDeniedAceEx(
1343 IN DWORD dwAceRevision
,
1345 IN DWORD AccessMask
,
1348 return set_ntstatus(RtlAddAccessDeniedAceEx(pAcl
, dwAceRevision
, AceFlags
, AccessMask
, pSid
));
1351 /******************************************************************************
1352 * AddAce [ADVAPI32.@]
1356 IN DWORD dwAceRevision
,
1357 IN DWORD dwStartingAceIndex
,
1359 DWORD nAceListLength
)
1361 return set_ntstatus(RtlAddAce(pAcl
, dwAceRevision
, dwStartingAceIndex
, pAceList
, nAceListLength
));
1364 /******************************************************************************
1365 * DeleteAce [ADVAPI32.@]
1367 BOOL WINAPI
DeleteAce(PACL pAcl
, DWORD dwAceIndex
)
1369 return set_ntstatus(RtlDeleteAce(pAcl
, dwAceIndex
));
1372 /******************************************************************************
1373 * FindFirstFreeAce [ADVAPI32.@]
1375 BOOL WINAPI
FindFirstFreeAce(IN PACL pAcl
, LPVOID
* pAce
)
1377 return RtlFirstFreeAce(pAcl
, (PACE_HEADER
*)pAce
);
1380 /******************************************************************************
1381 * GetAce [ADVAPI32.@]
1383 BOOL WINAPI
GetAce(PACL pAcl
,DWORD dwAceIndex
,LPVOID
*pAce
)
1385 return set_ntstatus(RtlGetAce(pAcl
, dwAceIndex
, pAce
));
1388 /******************************************************************************
1389 * GetAclInformation [ADVAPI32.@]
1391 BOOL WINAPI
GetAclInformation(
1393 LPVOID pAclInformation
,
1394 DWORD nAclInformationLength
,
1395 ACL_INFORMATION_CLASS dwAclInformationClass
)
1397 return set_ntstatus(RtlQueryInformationAcl(pAcl
, pAclInformation
,
1398 nAclInformationLength
, dwAclInformationClass
));
1401 /******************************************************************************
1402 * IsValidAcl [ADVAPI32.@]
1404 BOOL WINAPI
IsValidAcl(IN PACL pAcl
)
1406 return RtlValidAcl(pAcl
);
1409 /* ##############################
1410 ###### MISC FUNCTIONS ######
1411 ##############################
1414 /******************************************************************************
1415 * AllocateLocallyUniqueId [ADVAPI32.@]
1420 BOOL WINAPI
AllocateLocallyUniqueId( PLUID lpLuid
)
1422 return set_ntstatus(NtAllocateLocallyUniqueId(lpLuid
));
1425 static const WCHAR SE_CREATE_TOKEN_NAME_W
[] =
1426 { 'S','e','C','r','e','a','t','e','T','o','k','e','n','P','r','i','v','i','l','e','g','e',0 };
1427 static const WCHAR SE_ASSIGNPRIMARYTOKEN_NAME_W
[] =
1428 { '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 };
1429 static const WCHAR SE_LOCK_MEMORY_NAME_W
[] =
1430 { 'S','e','L','o','c','k','M','e','m','o','r','y','P','r','i','v','i','l','e','g','e',0 };
1431 static const WCHAR SE_INCREASE_QUOTA_NAME_W
[] =
1432 { '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 };
1433 static const WCHAR SE_MACHINE_ACCOUNT_NAME_W
[] =
1434 { '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 };
1435 static const WCHAR SE_TCB_NAME_W
[] =
1436 { 'S','e','T','c','b','P','r','i','v','i','l','e','g','e',0 };
1437 static const WCHAR SE_SECURITY_NAME_W
[] =
1438 { 'S','e','S','e','c','u','r','i','t','y','P','r','i','v','i','l','e','g','e',0 };
1439 static const WCHAR SE_TAKE_OWNERSHIP_NAME_W
[] =
1440 { '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 };
1441 static const WCHAR SE_LOAD_DRIVER_NAME_W
[] =
1442 { 'S','e','L','o','a','d','D','r','i','v','e','r','P','r','i','v','i','l','e','g','e',0 };
1443 static const WCHAR SE_SYSTEM_PROFILE_NAME_W
[] =
1444 { '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 };
1445 static const WCHAR SE_SYSTEMTIME_NAME_W
[] =
1446 { 'S','e','S','y','s','t','e','m','t','i','m','e','P','r','i','v','i','l','e','g','e',0 };
1447 static const WCHAR SE_PROF_SINGLE_PROCESS_NAME_W
[] =
1448 { '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 };
1449 static const WCHAR SE_INC_BASE_PRIORITY_NAME_W
[] =
1450 { '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 };
1451 static const WCHAR SE_CREATE_PAGEFILE_NAME_W
[] =
1452 { '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 };
1453 static const WCHAR SE_CREATE_PERMANENT_NAME_W
[] =
1454 { '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 };
1455 static const WCHAR SE_BACKUP_NAME_W
[] =
1456 { 'S','e','B','a','c','k','u','p','P','r','i','v','i','l','e','g','e',0 };
1457 static const WCHAR SE_RESTORE_NAME_W
[] =
1458 { 'S','e','R','e','s','t','o','r','e','P','r','i','v','i','l','e','g','e',0 };
1459 static const WCHAR SE_SHUTDOWN_NAME_W
[] =
1460 { 'S','e','S','h','u','t','d','o','w','n','P','r','i','v','i','l','e','g','e',0 };
1461 static const WCHAR SE_DEBUG_NAME_W
[] =
1462 { 'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0 };
1463 static const WCHAR SE_AUDIT_NAME_W
[] =
1464 { 'S','e','A','u','d','i','t','P','r','i','v','i','l','e','g','e',0 };
1465 static const WCHAR SE_SYSTEM_ENVIRONMENT_NAME_W
[] =
1466 { '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 };
1467 static const WCHAR SE_CHANGE_NOTIFY_NAME_W
[] =
1468 { 'S','e','C','h','a','n','g','e','N','o','t','i','f','y','P','r','i','v','i','l','e','g','e',0 };
1469 static const WCHAR SE_REMOTE_SHUTDOWN_NAME_W
[] =
1470 { '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 };
1471 static const WCHAR SE_UNDOCK_NAME_W
[] =
1472 { 'S','e','U','n','d','o','c','k','P','r','i','v','i','l','e','g','e',0 };
1473 static const WCHAR SE_SYNC_AGENT_NAME_W
[] =
1474 { 'S','e','S','y','n','c','A','g','e','n','t','P','r','i','v','i','l','e','g','e',0 };
1475 static const WCHAR SE_ENABLE_DELEGATION_NAME_W
[] =
1476 { '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 };
1477 static const WCHAR SE_MANAGE_VOLUME_NAME_W
[] =
1478 { 'S','e','M','a','n','a','g','e','V','o','l','u','m','e','P','r','i','v','i','l','e','g','e',0 };
1479 static const WCHAR SE_IMPERSONATE_NAME_W
[] =
1480 { 'S','e','I','m','p','e','r','s','o','n','a','t','e','P','r','i','v','i','l','e','g','e',0 };
1481 static const WCHAR SE_CREATE_GLOBAL_NAME_W
[] =
1482 { 'S','e','C','r','e','a','t','e','G','l','o','b','a','l','P','r','i','v','i','l','e','g','e',0 };
1484 static const WCHAR
* const WellKnownPrivNames
[SE_MAX_WELL_KNOWN_PRIVILEGE
+ 1] =
1488 SE_CREATE_TOKEN_NAME_W
,
1489 SE_ASSIGNPRIMARYTOKEN_NAME_W
,
1490 SE_LOCK_MEMORY_NAME_W
,
1491 SE_INCREASE_QUOTA_NAME_W
,
1492 SE_MACHINE_ACCOUNT_NAME_W
,
1495 SE_TAKE_OWNERSHIP_NAME_W
,
1496 SE_LOAD_DRIVER_NAME_W
,
1497 SE_SYSTEM_PROFILE_NAME_W
,
1498 SE_SYSTEMTIME_NAME_W
,
1499 SE_PROF_SINGLE_PROCESS_NAME_W
,
1500 SE_INC_BASE_PRIORITY_NAME_W
,
1501 SE_CREATE_PAGEFILE_NAME_W
,
1502 SE_CREATE_PERMANENT_NAME_W
,
1508 SE_SYSTEM_ENVIRONMENT_NAME_W
,
1509 SE_CHANGE_NOTIFY_NAME_W
,
1510 SE_REMOTE_SHUTDOWN_NAME_W
,
1512 SE_SYNC_AGENT_NAME_W
,
1513 SE_ENABLE_DELEGATION_NAME_W
,
1514 SE_MANAGE_VOLUME_NAME_W
,
1515 SE_IMPERSONATE_NAME_W
,
1516 SE_CREATE_GLOBAL_NAME_W
,
1519 /******************************************************************************
1520 * LookupPrivilegeValueW [ADVAPI32.@]
1522 * See LookupPrivilegeValueA.
1525 LookupPrivilegeValueW( LPCWSTR lpSystemName
, LPCWSTR lpName
, PLUID lpLuid
)
1529 TRACE("%s,%s,%p\n",debugstr_w(lpSystemName
), debugstr_w(lpName
), lpLuid
);
1531 if (!ADVAPI_IsLocalComputer(lpSystemName
))
1533 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
1538 SetLastError(ERROR_NO_SUCH_PRIVILEGE
);
1541 for( i
=SE_MIN_WELL_KNOWN_PRIVILEGE
; i
<SE_MAX_WELL_KNOWN_PRIVILEGE
; i
++ )
1543 if( !WellKnownPrivNames
[i
] )
1545 if( strcmpiW( WellKnownPrivNames
[i
], lpName
) )
1547 lpLuid
->LowPart
= i
;
1548 lpLuid
->HighPart
= 0;
1549 TRACE( "%s -> %08x-%08x\n",debugstr_w( lpSystemName
),
1550 lpLuid
->HighPart
, lpLuid
->LowPart
);
1553 SetLastError(ERROR_NO_SUCH_PRIVILEGE
);
1557 /******************************************************************************
1558 * LookupPrivilegeValueA [ADVAPI32.@]
1560 * Retrieves LUID used on a system to represent the privilege name.
1563 * lpSystemName [I] Name of the system
1564 * lpName [I] Name of the privilege
1565 * lpLuid [O] Destination for the resulting LUID
1568 * Success: TRUE. lpLuid contains the requested LUID.
1572 LookupPrivilegeValueA( LPCSTR lpSystemName
, LPCSTR lpName
, PLUID lpLuid
)
1574 UNICODE_STRING lpSystemNameW
;
1575 UNICODE_STRING lpNameW
;
1578 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW
, lpSystemName
);
1579 RtlCreateUnicodeStringFromAsciiz(&lpNameW
,lpName
);
1580 ret
= LookupPrivilegeValueW(lpSystemNameW
.Buffer
, lpNameW
.Buffer
, lpLuid
);
1581 RtlFreeUnicodeString(&lpNameW
);
1582 RtlFreeUnicodeString(&lpSystemNameW
);
1586 BOOL WINAPI
LookupPrivilegeDisplayNameA( LPCSTR lpSystemName
, LPCSTR lpName
, LPSTR lpDisplayName
,
1587 LPDWORD cchDisplayName
, LPDWORD lpLanguageId
)
1589 FIXME("%s %s %s %p %p - stub\n", debugstr_a(lpSystemName
), debugstr_a(lpName
),
1590 debugstr_a(lpDisplayName
), cchDisplayName
, lpLanguageId
);
1595 BOOL WINAPI
LookupPrivilegeDisplayNameW( LPCWSTR lpSystemName
, LPCWSTR lpName
, LPWSTR lpDisplayName
,
1596 LPDWORD cchDisplayName
, LPDWORD lpLanguageId
)
1598 FIXME("%s %s %s %p %p - stub\n", debugstr_w(lpSystemName
), debugstr_w(lpName
),
1599 debugstr_w(lpDisplayName
), cchDisplayName
, lpLanguageId
);
1604 /******************************************************************************
1605 * LookupPrivilegeNameA [ADVAPI32.@]
1607 * See LookupPrivilegeNameW.
1610 LookupPrivilegeNameA( LPCSTR lpSystemName
, PLUID lpLuid
, LPSTR lpName
,
1613 UNICODE_STRING lpSystemNameW
;
1617 TRACE("%s %p %p %p\n", debugstr_a(lpSystemName
), lpLuid
, lpName
, cchName
);
1619 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW
, lpSystemName
);
1620 ret
= LookupPrivilegeNameW(lpSystemNameW
.Buffer
, lpLuid
, NULL
, &wLen
);
1621 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1623 LPWSTR lpNameW
= HeapAlloc(GetProcessHeap(), 0, wLen
* sizeof(WCHAR
));
1625 ret
= LookupPrivilegeNameW(lpSystemNameW
.Buffer
, lpLuid
, lpNameW
,
1629 /* Windows crashes if cchName is NULL, so will I */
1630 int len
= WideCharToMultiByte(CP_ACP
, 0, lpNameW
, -1, lpName
,
1631 *cchName
, NULL
, NULL
);
1635 /* WideCharToMultiByte failed */
1638 else if (len
> *cchName
)
1641 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1646 /* WideCharToMultiByte succeeded, output length needs to be
1647 * length not including NULL terminator
1652 HeapFree(GetProcessHeap(), 0, lpNameW
);
1654 RtlFreeUnicodeString(&lpSystemNameW
);
1658 /******************************************************************************
1659 * LookupPrivilegeNameW [ADVAPI32.@]
1661 * Retrieves the privilege name referred to by the LUID lpLuid.
1664 * lpSystemName [I] Name of the system
1665 * lpLuid [I] Privilege value
1666 * lpName [O] Name of the privilege
1667 * cchName [I/O] Number of characters in lpName.
1670 * Success: TRUE. lpName contains the name of the privilege whose value is
1675 * Only well-known privilege names (those defined in winnt.h) can be retrieved
1676 * using this function.
1677 * If the length of lpName is too small, on return *cchName will contain the
1678 * number of WCHARs needed to contain the privilege, including the NULL
1679 * terminator, and GetLastError will return ERROR_INSUFFICIENT_BUFFER.
1680 * On success, *cchName will contain the number of characters stored in
1681 * lpName, NOT including the NULL terminator.
1684 LookupPrivilegeNameW( LPCWSTR lpSystemName
, PLUID lpLuid
, LPWSTR lpName
,
1689 TRACE("%s,%p,%p,%p\n",debugstr_w(lpSystemName
), lpLuid
, lpName
, cchName
);
1691 if (!ADVAPI_IsLocalComputer(lpSystemName
))
1693 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
1696 if (lpLuid
->HighPart
|| (lpLuid
->LowPart
< SE_MIN_WELL_KNOWN_PRIVILEGE
||
1697 lpLuid
->LowPart
> SE_MAX_WELL_KNOWN_PRIVILEGE
))
1699 SetLastError(ERROR_NO_SUCH_PRIVILEGE
);
1702 privNameLen
= strlenW(WellKnownPrivNames
[lpLuid
->LowPart
]);
1703 /* Windows crashes if cchName is NULL, so will I */
1704 if (*cchName
<= privNameLen
)
1706 *cchName
= privNameLen
+ 1;
1707 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1712 strcpyW(lpName
, WellKnownPrivNames
[lpLuid
->LowPart
]);
1713 *cchName
= privNameLen
;
1718 /******************************************************************************
1719 * GetFileSecurityA [ADVAPI32.@]
1721 * Obtains Specified information about the security of a file or directory.
1724 * lpFileName [I] Name of the file to get info for
1725 * RequestedInformation [I] SE_ flags from "winnt.h"
1726 * pSecurityDescriptor [O] Destination for security information
1727 * nLength [I] Length of pSecurityDescriptor
1728 * lpnLengthNeeded [O] Destination for length of returned security information
1731 * Success: TRUE. pSecurityDescriptor contains the requested information.
1732 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
1735 * The information returned is constrained by the callers access rights and
1739 GetFileSecurityA( LPCSTR lpFileName
,
1740 SECURITY_INFORMATION RequestedInformation
,
1741 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1742 DWORD nLength
, LPDWORD lpnLengthNeeded
)
1750 len
= MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, NULL
, 0 );
1751 name
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
1752 MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, name
, len
);
1755 r
= GetFileSecurityW( name
, RequestedInformation
, pSecurityDescriptor
,
1756 nLength
, lpnLengthNeeded
);
1757 HeapFree( GetProcessHeap(), 0, name
);
1762 /******************************************************************************
1763 * GetFileSecurityW [ADVAPI32.@]
1765 * See GetFileSecurityA.
1768 GetFileSecurityW( LPCWSTR lpFileName
,
1769 SECURITY_INFORMATION RequestedInformation
,
1770 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1771 DWORD nLength
, LPDWORD lpnLengthNeeded
)
1776 hfile
= CreateFileW( lpFileName
, GENERIC_READ
, FILE_SHARE_READ
,
1777 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1778 if ( hfile
== INVALID_HANDLE_VALUE
)
1781 status
= NtQuerySecurityObject( hfile
, RequestedInformation
, pSecurityDescriptor
,
1782 nLength
, lpnLengthNeeded
);
1783 CloseHandle( hfile
);
1784 return set_ntstatus( status
);
1788 /******************************************************************************
1789 * LookupAccountSidA [ADVAPI32.@]
1796 IN OUT LPDWORD accountSize
,
1798 IN OUT LPDWORD domainSize
,
1799 OUT PSID_NAME_USE name_use
)
1803 LPWSTR systemW
= NULL
;
1804 LPWSTR accountW
= NULL
;
1805 LPWSTR domainW
= NULL
;
1806 DWORD accountSizeW
= *accountSize
;
1807 DWORD domainSizeW
= *domainSize
;
1809 TRACE("(%s,sid=%s,%p,%p(%u),%p,%p(%u),%p)\n",
1810 debugstr_a(system
),debugstr_sid(sid
),
1811 account
,accountSize
,accountSize
?*accountSize
:0,
1812 domain
,domainSize
,domainSize
?*domainSize
:0,
1816 len
= MultiByteToWideChar( CP_ACP
, 0, system
, -1, NULL
, 0 );
1817 systemW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1818 MultiByteToWideChar( CP_ACP
, 0, system
, -1, systemW
, len
);
1821 accountW
= HeapAlloc( GetProcessHeap(), 0, accountSizeW
* sizeof(WCHAR
) );
1823 domainW
= HeapAlloc( GetProcessHeap(), 0, domainSizeW
* sizeof(WCHAR
) );
1825 r
= LookupAccountSidW( systemW
, sid
, accountW
, &accountSizeW
, domainW
, &domainSizeW
, name_use
);
1828 if (accountW
&& *accountSize
) {
1829 len
= WideCharToMultiByte( CP_ACP
, 0, accountW
, -1, NULL
, 0, NULL
, NULL
);
1830 WideCharToMultiByte( CP_ACP
, 0, accountW
, -1, account
, len
, NULL
, NULL
);
1833 *accountSize
= accountSizeW
+ 1;
1835 if (domainW
&& *domainSize
) {
1836 len
= WideCharToMultiByte( CP_ACP
, 0, domainW
, -1, NULL
, 0, NULL
, NULL
);
1837 WideCharToMultiByte( CP_ACP
, 0, domainW
, -1, domain
, len
, NULL
, NULL
);
1840 *domainSize
= domainSizeW
+ 1;
1843 HeapFree( GetProcessHeap(), 0, systemW
);
1844 HeapFree( GetProcessHeap(), 0, accountW
);
1845 HeapFree( GetProcessHeap(), 0, domainW
);
1850 /******************************************************************************
1851 * LookupAccountSidW [ADVAPI32.@]
1868 IN OUT LPDWORD accountSize
,
1870 IN OUT LPDWORD domainSize
,
1871 OUT PSID_NAME_USE name_use
)
1874 const WCHAR
* ac
= NULL
;
1875 const WCHAR
* dm
= NULL
;
1876 SID_NAME_USE use
= 0;
1877 LPWSTR computer_name
= NULL
;
1879 TRACE("(%s,sid=%s,%p,%p(%u),%p,%p(%u),%p)\n",
1880 debugstr_w(system
),debugstr_sid(sid
),
1881 account
,accountSize
,accountSize
?*accountSize
:0,
1882 domain
,domainSize
,domainSize
?*domainSize
:0,
1885 if (!ADVAPI_IsLocalComputer(system
)) {
1886 FIXME("Only local computer supported!\n");
1887 SetLastError(ERROR_NONE_MAPPED
);
1891 /* check the well known SIDs first */
1892 for (i
= 0; i
<= 60; i
++) {
1893 if (IsWellKnownSid(sid
, i
)) {
1894 for (j
= 0; j
< (sizeof(ACCOUNT_SIDS
) / sizeof(ACCOUNT_SIDS
[0])); j
++) {
1895 if (ACCOUNT_SIDS
[j
].type
== i
) {
1896 ac
= ACCOUNT_SIDS
[j
].account
;
1897 dm
= ACCOUNT_SIDS
[j
].domain
;
1898 use
= ACCOUNT_SIDS
[j
].name_use
;
1908 /* check for the local computer next */
1909 if (ADVAPI_GetComputerSid(&local
)) {
1910 DWORD size
= MAX_COMPUTERNAME_LENGTH
+ 1;
1913 computer_name
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
1914 result
= GetComputerNameW(computer_name
, &size
);
1917 if (EqualSid(sid
, &local
)) {
1922 local
.SubAuthorityCount
++;
1924 if (EqualPrefixSid(sid
, &local
)) {
1927 switch (((MAX_SID
*)sid
)->SubAuthority
[4]) {
1928 case DOMAIN_USER_RID_ADMIN
:
1931 case DOMAIN_USER_RID_GUEST
:
1934 case DOMAIN_GROUP_RID_ADMINS
:
1937 case DOMAIN_GROUP_RID_USERS
:
1940 case DOMAIN_GROUP_RID_GUESTS
:
1943 case DOMAIN_GROUP_RID_COMPUTERS
:
1944 ac
= Domain_Computers
;
1946 case DOMAIN_GROUP_RID_CONTROLLERS
:
1947 ac
= Domain_Controllers
;
1949 case DOMAIN_GROUP_RID_CERT_ADMINS
:
1950 ac
= Cert_Publishers
;
1952 case DOMAIN_GROUP_RID_SCHEMA_ADMINS
:
1955 case DOMAIN_GROUP_RID_ENTERPRISE_ADMINS
:
1956 ac
= Enterprise_Admins
;
1958 case DOMAIN_GROUP_RID_POLICY_ADMINS
:
1959 ac
= Group_Policy_Creator_Owners
;
1961 case DOMAIN_ALIAS_RID_RAS_SERVERS
:
1962 ac
= RAS_and_IAS_Servers
;
1976 if (*accountSize
> lstrlenW(ac
)) {
1978 lstrcpyW(account
, ac
);
1980 if (*domainSize
> lstrlenW(dm
)) {
1982 lstrcpyW(domain
, dm
);
1984 if (((*accountSize
!= 0) && (*accountSize
< strlenW(ac
))) ||
1985 ((*domainSize
!= 0) && (*domainSize
< strlenW(dm
)))) {
1986 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1990 *domainSize
= strlenW(dm
);
1992 *domainSize
= strlenW(dm
) + 1;
1994 *accountSize
= strlenW(ac
);
1996 *accountSize
= strlenW(ac
) + 1;
1998 HeapFree(GetProcessHeap(), 0, computer_name
);
2002 HeapFree(GetProcessHeap(), 0, computer_name
);
2003 SetLastError(ERROR_NONE_MAPPED
);
2007 /******************************************************************************
2008 * SetFileSecurityA [ADVAPI32.@]
2010 * See SetFileSecurityW.
2012 BOOL WINAPI
SetFileSecurityA( LPCSTR lpFileName
,
2013 SECURITY_INFORMATION RequestedInformation
,
2014 PSECURITY_DESCRIPTOR pSecurityDescriptor
)
2022 len
= MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, NULL
, 0 );
2023 name
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
2024 MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, name
, len
);
2027 r
= SetFileSecurityW( name
, RequestedInformation
, pSecurityDescriptor
);
2028 HeapFree( GetProcessHeap(), 0, name
);
2033 /******************************************************************************
2034 * SetFileSecurityW [ADVAPI32.@]
2036 * Sets the security of a file or directory.
2040 * RequestedInformation []
2041 * pSecurityDescriptor []
2048 SetFileSecurityW( LPCWSTR lpFileName
,
2049 SECURITY_INFORMATION RequestedInformation
,
2050 PSECURITY_DESCRIPTOR pSecurityDescriptor
)
2052 FIXME("(%s) : stub\n", debugstr_w(lpFileName
) );
2056 /******************************************************************************
2057 * QueryWindows31FilesMigration [ADVAPI32.@]
2063 QueryWindows31FilesMigration( DWORD x1
)
2065 FIXME("(%d):stub\n",x1
);
2069 /******************************************************************************
2070 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
2079 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1
, DWORD x2
, DWORD x3
,
2082 FIXME("(0x%08x,0x%08x,0x%08x,0x%08x):stub\n",x1
,x2
,x3
,x4
);
2086 /******************************************************************************
2087 * NotifyBootConfigStatus [ADVAPI32.@]
2093 NotifyBootConfigStatus( BOOL x1
)
2095 FIXME("(0x%08d):stub\n",x1
);
2099 /******************************************************************************
2100 * RevertToSelf [ADVAPI32.@]
2102 * Ends the impersonation of a user.
2112 RevertToSelf( void )
2114 HANDLE Token
= NULL
;
2115 return set_ntstatus( NtSetInformationThread( GetCurrentThread(),
2116 ThreadImpersonationToken
, &Token
, sizeof(Token
) ) );
2119 /******************************************************************************
2120 * ImpersonateSelf [ADVAPI32.@]
2122 * Makes an impersonation token that represents the process user and assigns
2123 * to the current thread.
2126 * ImpersonationLevel [I] Level at which to impersonate.
2133 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
)
2135 return set_ntstatus( RtlImpersonateSelf( ImpersonationLevel
) );
2138 /******************************************************************************
2139 * ImpersonateLoggedOnUser [ADVAPI32.@]
2141 BOOL WINAPI
ImpersonateLoggedOnUser(HANDLE hToken
)
2145 HANDLE ImpersonationToken
;
2148 FIXME( "(%p)\n", hToken
);
2150 if (!GetTokenInformation( hToken
, TokenType
, &Type
,
2151 sizeof(TOKEN_TYPE
), &size
))
2154 if (Type
== TokenPrimary
)
2156 OBJECT_ATTRIBUTES ObjectAttributes
;
2158 InitializeObjectAttributes( &ObjectAttributes
, NULL
, 0, NULL
, NULL
);
2160 Status
= NtDuplicateToken( hToken
,
2161 TOKEN_IMPERSONATE
| TOKEN_QUERY
,
2163 SecurityImpersonation
,
2165 &ImpersonationToken
);
2166 if (Status
!= STATUS_SUCCESS
)
2168 ERR( "NtDuplicateToken failed with error 0x%08x\n", Status
);
2169 SetLastError( RtlNtStatusToDosError( Status
) );
2174 ImpersonationToken
= hToken
;
2176 Status
= NtSetInformationThread( GetCurrentThread(),
2177 ThreadImpersonationToken
,
2178 &ImpersonationToken
,
2179 sizeof(ImpersonationToken
) );
2181 if (Type
== TokenPrimary
)
2182 NtClose( ImpersonationToken
);
2184 if (Status
!= STATUS_SUCCESS
)
2186 ERR( "NtSetInformationThread failed with error 0x%08x\n", Status
);
2187 SetLastError( RtlNtStatusToDosError( Status
) );
2194 /******************************************************************************
2195 * AccessCheck [ADVAPI32.@]
2199 PSECURITY_DESCRIPTOR SecurityDescriptor
,
2201 DWORD DesiredAccess
,
2202 PGENERIC_MAPPING GenericMapping
,
2203 PPRIVILEGE_SET PrivilegeSet
,
2204 LPDWORD PrivilegeSetLength
,
2205 LPDWORD GrantedAccess
,
2206 LPBOOL AccessStatus
)
2208 NTSTATUS access_status
;
2209 BOOL ret
= set_ntstatus( NtAccessCheck(SecurityDescriptor
, ClientToken
, DesiredAccess
,
2210 GenericMapping
, PrivilegeSet
, PrivilegeSetLength
,
2211 GrantedAccess
, &access_status
) );
2212 if (ret
) *AccessStatus
= set_ntstatus( access_status
);
2217 /******************************************************************************
2218 * AccessCheckByType [ADVAPI32.@]
2220 BOOL WINAPI
AccessCheckByType(
2221 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
2222 PSID PrincipalSelfSid
,
2224 DWORD DesiredAccess
,
2225 POBJECT_TYPE_LIST ObjectTypeList
,
2226 DWORD ObjectTypeListLength
,
2227 PGENERIC_MAPPING GenericMapping
,
2228 PPRIVILEGE_SET PrivilegeSet
,
2229 LPDWORD PrivilegeSetLength
,
2230 LPDWORD GrantedAccess
,
2231 LPBOOL AccessStatus
)
2235 *AccessStatus
= TRUE
;
2237 return !*AccessStatus
;
2240 /******************************************************************************
2241 * MapGenericMask [ADVAPI32.@]
2243 * Maps generic access rights into specific access rights according to the
2247 * AccessMask [I/O] Access rights.
2248 * GenericMapping [I] The mapping between generic and specific rights.
2253 VOID WINAPI
MapGenericMask( PDWORD AccessMask
, PGENERIC_MAPPING GenericMapping
)
2255 RtlMapGenericMask( AccessMask
, GenericMapping
);
2258 /*************************************************************************
2259 * SetKernelObjectSecurity [ADVAPI32.@]
2261 BOOL WINAPI
SetKernelObjectSecurity (
2263 IN SECURITY_INFORMATION SecurityInformation
,
2264 IN PSECURITY_DESCRIPTOR SecurityDescriptor
)
2266 return set_ntstatus (NtSetSecurityObject (Handle
, SecurityInformation
, SecurityDescriptor
));
2270 /******************************************************************************
2271 * AddAuditAccessAce [ADVAPI32.@]
2273 BOOL WINAPI
AddAuditAccessAce(
2275 IN DWORD dwAceRevision
,
2276 IN DWORD dwAccessMask
,
2278 IN BOOL bAuditSuccess
,
2279 IN BOOL bAuditFailure
)
2281 return set_ntstatus( RtlAddAuditAccessAce(pAcl
, dwAceRevision
, dwAccessMask
, pSid
,
2282 bAuditSuccess
, bAuditFailure
) );
2285 /******************************************************************************
2286 * AddAuditAccessAce [ADVAPI32.@]
2288 BOOL WINAPI
AddAuditAccessAceEx(
2290 IN DWORD dwAceRevision
,
2291 IN DWORD dwAceFlags
,
2292 IN DWORD dwAccessMask
,
2294 IN BOOL bAuditSuccess
,
2295 IN BOOL bAuditFailure
)
2297 return set_ntstatus( RtlAddAuditAccessAceEx(pAcl
, dwAceRevision
, dwAceFlags
, dwAccessMask
, pSid
,
2298 bAuditSuccess
, bAuditFailure
) );
2301 /******************************************************************************
2302 * LookupAccountNameA [ADVAPI32.@]
2310 LPSTR ReferencedDomainName
,
2311 IN OUT LPDWORD cbReferencedDomainName
,
2312 OUT PSID_NAME_USE name_use
)
2315 UNICODE_STRING lpSystemW
;
2316 UNICODE_STRING lpAccountW
;
2317 LPWSTR lpReferencedDomainNameW
= NULL
;
2319 RtlCreateUnicodeStringFromAsciiz(&lpSystemW
, system
);
2320 RtlCreateUnicodeStringFromAsciiz(&lpAccountW
, account
);
2322 if (ReferencedDomainName
)
2323 lpReferencedDomainNameW
= HeapAlloc(GetProcessHeap(), 0, *cbReferencedDomainName
* sizeof(WCHAR
));
2325 ret
= LookupAccountNameW(lpSystemW
.Buffer
, lpAccountW
.Buffer
, sid
, cbSid
, lpReferencedDomainNameW
,
2326 cbReferencedDomainName
, name_use
);
2328 if (ret
&& lpReferencedDomainNameW
)
2330 WideCharToMultiByte(CP_ACP
, 0, lpReferencedDomainNameW
, *cbReferencedDomainName
,
2331 ReferencedDomainName
, *cbReferencedDomainName
, NULL
, NULL
);
2334 RtlFreeUnicodeString(&lpSystemW
);
2335 RtlFreeUnicodeString(&lpAccountW
);
2336 HeapFree(GetProcessHeap(), 0, lpReferencedDomainNameW
);
2341 /******************************************************************************
2342 * LookupAccountNameW [ADVAPI32.@]
2344 BOOL WINAPI
LookupAccountNameW( LPCWSTR lpSystemName
, LPCWSTR lpAccountName
, PSID Sid
,
2345 LPDWORD cbSid
, LPWSTR ReferencedDomainName
,
2346 LPDWORD cchReferencedDomainName
, PSID_NAME_USE peUse
)
2348 /* Default implementation: Always return a default SID */
2349 SID_IDENTIFIER_AUTHORITY identifierAuthority
= {SECURITY_NT_AUTHORITY
};
2352 static const WCHAR dm
[] = {'D','O','M','A','I','N',0};
2354 FIXME("%s %s %p %p %p %p %p - stub\n", debugstr_w(lpSystemName
), debugstr_w(lpAccountName
),
2355 Sid
, cbSid
, ReferencedDomainName
, cchReferencedDomainName
, peUse
);
2357 ret
= AllocateAndInitializeSid(&identifierAuthority
,
2359 SECURITY_BUILTIN_DOMAIN_RID
,
2360 DOMAIN_ALIAS_RID_ADMINS
,
2367 if (!RtlValidSid(pSid
))
2373 if (Sid
!= NULL
&& (*cbSid
>= GetLengthSid(pSid
)))
2374 CopySid(*cbSid
, Sid
, pSid
);
2375 if (*cbSid
< GetLengthSid(pSid
))
2377 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2380 *cbSid
= GetLengthSid(pSid
);
2382 if (ReferencedDomainName
!= NULL
&& (*cchReferencedDomainName
> strlenW(dm
)))
2383 strcpyW(ReferencedDomainName
, dm
);
2385 if (*cchReferencedDomainName
<= strlenW(dm
))
2387 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2391 *cchReferencedDomainName
= strlenW(dm
)+1;
2398 /******************************************************************************
2399 * PrivilegeCheck [ADVAPI32.@]
2401 BOOL WINAPI
PrivilegeCheck( HANDLE ClientToken
, PPRIVILEGE_SET RequiredPrivileges
, LPBOOL pfResult
)
2406 TRACE("%p %p %p\n", ClientToken
, RequiredPrivileges
, pfResult
);
2408 ret
= set_ntstatus (NtPrivilegeCheck (ClientToken
, RequiredPrivileges
, &Result
));
2414 /******************************************************************************
2415 * AccessCheckAndAuditAlarmA [ADVAPI32.@]
2417 BOOL WINAPI
AccessCheckAndAuditAlarmA(LPCSTR Subsystem
, LPVOID HandleId
, LPSTR ObjectTypeName
,
2418 LPSTR ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
, DWORD DesiredAccess
,
2419 PGENERIC_MAPPING GenericMapping
, BOOL ObjectCreation
, LPDWORD GrantedAccess
,
2420 LPBOOL AccessStatus
, LPBOOL pfGenerateOnClose
)
2422 FIXME("stub (%s,%p,%s,%s,%p,%08x,%p,%x,%p,%p,%p)\n", debugstr_a(Subsystem
),
2423 HandleId
, debugstr_a(ObjectTypeName
), debugstr_a(ObjectName
),
2424 SecurityDescriptor
, DesiredAccess
, GenericMapping
,
2425 ObjectCreation
, GrantedAccess
, AccessStatus
, pfGenerateOnClose
);
2429 /******************************************************************************
2430 * AccessCheckAndAuditAlarmW [ADVAPI32.@]
2432 BOOL WINAPI
AccessCheckAndAuditAlarmW(LPCWSTR Subsystem
, LPVOID HandleId
, LPWSTR ObjectTypeName
,
2433 LPWSTR ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
, DWORD DesiredAccess
,
2434 PGENERIC_MAPPING GenericMapping
, BOOL ObjectCreation
, LPDWORD GrantedAccess
,
2435 LPBOOL AccessStatus
, LPBOOL pfGenerateOnClose
)
2437 FIXME("stub (%s,%p,%s,%s,%p,%08x,%p,%x,%p,%p,%p)\n", debugstr_w(Subsystem
),
2438 HandleId
, debugstr_w(ObjectTypeName
), debugstr_w(ObjectName
),
2439 SecurityDescriptor
, DesiredAccess
, GenericMapping
,
2440 ObjectCreation
, GrantedAccess
, AccessStatus
, pfGenerateOnClose
);
2444 BOOL WINAPI
ObjectCloseAuditAlarmA(LPCSTR SubsystemName
, LPVOID HandleId
, BOOL GenerateOnClose
)
2446 FIXME("stub (%s,%p,%x)\n", debugstr_a(SubsystemName
), HandleId
, GenerateOnClose
);
2451 BOOL WINAPI
ObjectCloseAuditAlarmW(LPCWSTR SubsystemName
, LPVOID HandleId
, BOOL GenerateOnClose
)
2453 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName
), HandleId
, GenerateOnClose
);
2458 BOOL WINAPI
ObjectDeleteAuditAlarmW(LPCWSTR SubsystemName
, LPVOID HandleId
, BOOL GenerateOnClose
)
2460 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName
), HandleId
, GenerateOnClose
);
2465 BOOL WINAPI
ObjectOpenAuditAlarmA(LPCSTR SubsystemName
, LPVOID HandleId
, LPSTR ObjectTypeName
,
2466 LPSTR ObjectName
, PSECURITY_DESCRIPTOR pSecurityDescriptor
, HANDLE ClientToken
, DWORD DesiredAccess
,
2467 DWORD GrantedAccess
, PPRIVILEGE_SET Privileges
, BOOL ObjectCreation
, BOOL AccessGranted
,
2468 LPBOOL GenerateOnClose
)
2470 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08x,0x%08x,%p,%x,%x,%p)\n", debugstr_a(SubsystemName
),
2471 HandleId
, debugstr_a(ObjectTypeName
), debugstr_a(ObjectName
), pSecurityDescriptor
,
2472 ClientToken
, DesiredAccess
, GrantedAccess
, Privileges
, ObjectCreation
, AccessGranted
,
2478 BOOL WINAPI
ObjectOpenAuditAlarmW(LPCWSTR SubsystemName
, LPVOID HandleId
, LPWSTR ObjectTypeName
,
2479 LPWSTR ObjectName
, PSECURITY_DESCRIPTOR pSecurityDescriptor
, HANDLE ClientToken
, DWORD DesiredAccess
,
2480 DWORD GrantedAccess
, PPRIVILEGE_SET Privileges
, BOOL ObjectCreation
, BOOL AccessGranted
,
2481 LPBOOL GenerateOnClose
)
2483 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08x,0x%08x,%p,%x,%x,%p)\n", debugstr_w(SubsystemName
),
2484 HandleId
, debugstr_w(ObjectTypeName
), debugstr_w(ObjectName
), pSecurityDescriptor
,
2485 ClientToken
, DesiredAccess
, GrantedAccess
, Privileges
, ObjectCreation
, AccessGranted
,
2491 BOOL WINAPI
ObjectPrivilegeAuditAlarmA( LPCSTR SubsystemName
, LPVOID HandleId
, HANDLE ClientToken
,
2492 DWORD DesiredAccess
, PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2494 FIXME("stub (%s,%p,%p,0x%08x,%p,%x)\n", debugstr_a(SubsystemName
), HandleId
, ClientToken
,
2495 DesiredAccess
, Privileges
, AccessGranted
);
2500 BOOL WINAPI
ObjectPrivilegeAuditAlarmW( LPCWSTR SubsystemName
, LPVOID HandleId
, HANDLE ClientToken
,
2501 DWORD DesiredAccess
, PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2503 FIXME("stub (%s,%p,%p,0x%08x,%p,%x)\n", debugstr_w(SubsystemName
), HandleId
, ClientToken
,
2504 DesiredAccess
, Privileges
, AccessGranted
);
2509 BOOL WINAPI
PrivilegedServiceAuditAlarmA( LPCSTR SubsystemName
, LPCSTR ServiceName
, HANDLE ClientToken
,
2510 PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2512 FIXME("stub (%s,%s,%p,%p,%x)\n", debugstr_a(SubsystemName
), debugstr_a(ServiceName
),
2513 ClientToken
, Privileges
, AccessGranted
);
2518 BOOL WINAPI
PrivilegedServiceAuditAlarmW( LPCWSTR SubsystemName
, LPCWSTR ServiceName
, HANDLE ClientToken
,
2519 PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2521 FIXME("stub %s,%s,%p,%p,%x)\n", debugstr_w(SubsystemName
), debugstr_w(ServiceName
),
2522 ClientToken
, Privileges
, AccessGranted
);
2527 /******************************************************************************
2528 * GetSecurityInfo [ADVAPI32.@]
2530 DWORD WINAPI
GetSecurityInfo(
2531 HANDLE hObject
, SE_OBJECT_TYPE ObjectType
,
2532 SECURITY_INFORMATION SecurityInfo
, PSID
*ppsidOwner
,
2533 PSID
*ppsidGroup
, PACL
*ppDacl
, PACL
*ppSacl
,
2534 PSECURITY_DESCRIPTOR
*ppSecurityDescriptor
2538 return ERROR_BAD_PROVIDER
;
2541 /******************************************************************************
2542 * GetSecurityInfoExW [ADVAPI32.@]
2544 DWORD WINAPI
GetSecurityInfoExW(
2545 HANDLE hObject
, SE_OBJECT_TYPE ObjectType
,
2546 SECURITY_INFORMATION SecurityInfo
, LPCWSTR lpProvider
,
2547 LPCWSTR lpProperty
, PACTRL_ACCESSW
*ppAccessList
,
2548 PACTRL_AUDITW
*ppAuditList
, LPWSTR
*lppOwner
, LPWSTR
*lppGroup
2552 return ERROR_BAD_PROVIDER
;
2555 /******************************************************************************
2556 * BuildExplicitAccessWithNameA [ADVAPI32.@]
2558 VOID WINAPI
BuildExplicitAccessWithNameA( PEXPLICIT_ACCESSA pExplicitAccess
,
2559 LPSTR pTrusteeName
, DWORD AccessPermissions
,
2560 ACCESS_MODE AccessMode
, DWORD Inheritance
)
2562 TRACE("%p %s 0x%08x 0x%08x 0x%08x\n", pExplicitAccess
, debugstr_a(pTrusteeName
),
2563 AccessPermissions
, AccessMode
, Inheritance
);
2565 pExplicitAccess
->grfAccessPermissions
= AccessPermissions
;
2566 pExplicitAccess
->grfAccessMode
= AccessMode
;
2567 pExplicitAccess
->grfInheritance
= Inheritance
;
2569 pExplicitAccess
->Trustee
.pMultipleTrustee
= NULL
;
2570 pExplicitAccess
->Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2571 pExplicitAccess
->Trustee
.TrusteeForm
= TRUSTEE_IS_NAME
;
2572 pExplicitAccess
->Trustee
.TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2573 pExplicitAccess
->Trustee
.ptstrName
= pTrusteeName
;
2576 /******************************************************************************
2577 * BuildExplicitAccessWithNameW [ADVAPI32.@]
2579 VOID WINAPI
BuildExplicitAccessWithNameW( PEXPLICIT_ACCESSW pExplicitAccess
,
2580 LPWSTR pTrusteeName
, DWORD AccessPermissions
,
2581 ACCESS_MODE AccessMode
, DWORD Inheritance
)
2583 TRACE("%p %s 0x%08x 0x%08x 0x%08x\n", pExplicitAccess
, debugstr_w(pTrusteeName
),
2584 AccessPermissions
, AccessMode
, Inheritance
);
2586 pExplicitAccess
->grfAccessPermissions
= AccessPermissions
;
2587 pExplicitAccess
->grfAccessMode
= AccessMode
;
2588 pExplicitAccess
->grfInheritance
= Inheritance
;
2590 pExplicitAccess
->Trustee
.pMultipleTrustee
= NULL
;
2591 pExplicitAccess
->Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2592 pExplicitAccess
->Trustee
.TrusteeForm
= TRUSTEE_IS_NAME
;
2593 pExplicitAccess
->Trustee
.TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2594 pExplicitAccess
->Trustee
.ptstrName
= pTrusteeName
;
2597 /******************************************************************************
2598 * BuildTrusteeWithObjectsAndNameA [ADVAPI32.@]
2600 VOID WINAPI
BuildTrusteeWithObjectsAndNameA( PTRUSTEEA pTrustee
, POBJECTS_AND_NAME_A pObjName
,
2601 SE_OBJECT_TYPE ObjectType
, LPSTR ObjectTypeName
,
2602 LPSTR InheritedObjectTypeName
, LPSTR Name
)
2604 DWORD ObjectsPresent
= 0;
2606 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee
, pObjName
,
2607 ObjectType
, ObjectTypeName
, InheritedObjectTypeName
, debugstr_a(Name
));
2609 /* Fill the OBJECTS_AND_NAME structure */
2610 pObjName
->ObjectType
= ObjectType
;
2611 if (ObjectTypeName
!= NULL
)
2613 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2616 pObjName
->InheritedObjectTypeName
= InheritedObjectTypeName
;
2617 if (InheritedObjectTypeName
!= NULL
)
2619 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2622 pObjName
->ObjectsPresent
= ObjectsPresent
;
2623 pObjName
->ptstrName
= Name
;
2625 /* Fill the TRUSTEE structure */
2626 pTrustee
->pMultipleTrustee
= NULL
;
2627 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2628 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_NAME
;
2629 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2630 pTrustee
->ptstrName
= (LPSTR
)pObjName
;
2633 /******************************************************************************
2634 * BuildTrusteeWithObjectsAndNameW [ADVAPI32.@]
2636 VOID WINAPI
BuildTrusteeWithObjectsAndNameW( PTRUSTEEW pTrustee
, POBJECTS_AND_NAME_W pObjName
,
2637 SE_OBJECT_TYPE ObjectType
, LPWSTR ObjectTypeName
,
2638 LPWSTR InheritedObjectTypeName
, LPWSTR Name
)
2640 DWORD ObjectsPresent
= 0;
2642 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee
, pObjName
,
2643 ObjectType
, ObjectTypeName
, InheritedObjectTypeName
, debugstr_w(Name
));
2645 /* Fill the OBJECTS_AND_NAME structure */
2646 pObjName
->ObjectType
= ObjectType
;
2647 if (ObjectTypeName
!= NULL
)
2649 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2652 pObjName
->InheritedObjectTypeName
= InheritedObjectTypeName
;
2653 if (InheritedObjectTypeName
!= NULL
)
2655 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2658 pObjName
->ObjectsPresent
= ObjectsPresent
;
2659 pObjName
->ptstrName
= Name
;
2661 /* Fill the TRUSTEE structure */
2662 pTrustee
->pMultipleTrustee
= NULL
;
2663 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2664 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_NAME
;
2665 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2666 pTrustee
->ptstrName
= (LPWSTR
)pObjName
;
2669 /******************************************************************************
2670 * BuildTrusteeWithObjectsAndSidA [ADVAPI32.@]
2672 VOID WINAPI
BuildTrusteeWithObjectsAndSidA( PTRUSTEEA pTrustee
, POBJECTS_AND_SID pObjSid
,
2673 GUID
* pObjectGuid
, GUID
* pInheritedObjectGuid
, PSID pSid
)
2675 DWORD ObjectsPresent
= 0;
2677 TRACE("%p %p %p %p %p\n", pTrustee
, pObjSid
, pObjectGuid
, pInheritedObjectGuid
, pSid
);
2679 /* Fill the OBJECTS_AND_SID structure */
2680 if (pObjectGuid
!= NULL
)
2682 pObjSid
->ObjectTypeGuid
= *pObjectGuid
;
2683 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2687 ZeroMemory(&pObjSid
->ObjectTypeGuid
,
2691 if (pInheritedObjectGuid
!= NULL
)
2693 pObjSid
->InheritedObjectTypeGuid
= *pInheritedObjectGuid
;
2694 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2698 ZeroMemory(&pObjSid
->InheritedObjectTypeGuid
,
2702 pObjSid
->ObjectsPresent
= ObjectsPresent
;
2703 pObjSid
->pSid
= pSid
;
2705 /* Fill the TRUSTEE structure */
2706 pTrustee
->pMultipleTrustee
= NULL
;
2707 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2708 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_SID
;
2709 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2710 pTrustee
->ptstrName
= (LPSTR
) pObjSid
;
2713 /******************************************************************************
2714 * BuildTrusteeWithObjectsAndSidW [ADVAPI32.@]
2716 VOID WINAPI
BuildTrusteeWithObjectsAndSidW( PTRUSTEEW pTrustee
, POBJECTS_AND_SID pObjSid
,
2717 GUID
* pObjectGuid
, GUID
* pInheritedObjectGuid
, PSID pSid
)
2719 DWORD ObjectsPresent
= 0;
2721 TRACE("%p %p %p %p %p\n", pTrustee
, pObjSid
, pObjectGuid
, pInheritedObjectGuid
, pSid
);
2723 /* Fill the OBJECTS_AND_SID structure */
2724 if (pObjectGuid
!= NULL
)
2726 pObjSid
->ObjectTypeGuid
= *pObjectGuid
;
2727 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2731 ZeroMemory(&pObjSid
->ObjectTypeGuid
,
2735 if (pInheritedObjectGuid
!= NULL
)
2737 pObjSid
->InheritedObjectTypeGuid
= *pInheritedObjectGuid
;
2738 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2742 ZeroMemory(&pObjSid
->InheritedObjectTypeGuid
,
2746 pObjSid
->ObjectsPresent
= ObjectsPresent
;
2747 pObjSid
->pSid
= pSid
;
2749 /* Fill the TRUSTEE structure */
2750 pTrustee
->pMultipleTrustee
= NULL
;
2751 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2752 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_SID
;
2753 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2754 pTrustee
->ptstrName
= (LPWSTR
) pObjSid
;
2757 /******************************************************************************
2758 * BuildTrusteeWithSidA [ADVAPI32.@]
2760 VOID WINAPI
BuildTrusteeWithSidA(PTRUSTEEA pTrustee
, PSID pSid
)
2762 TRACE("%p %p\n", pTrustee
, pSid
);
2764 pTrustee
->pMultipleTrustee
= NULL
;
2765 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2766 pTrustee
->TrusteeForm
= TRUSTEE_IS_SID
;
2767 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2768 pTrustee
->ptstrName
= (LPSTR
) pSid
;
2771 /******************************************************************************
2772 * BuildTrusteeWithSidW [ADVAPI32.@]
2774 VOID WINAPI
BuildTrusteeWithSidW(PTRUSTEEW pTrustee
, PSID pSid
)
2776 TRACE("%p %p\n", pTrustee
, pSid
);
2778 pTrustee
->pMultipleTrustee
= NULL
;
2779 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2780 pTrustee
->TrusteeForm
= TRUSTEE_IS_SID
;
2781 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2782 pTrustee
->ptstrName
= (LPWSTR
) pSid
;
2785 /******************************************************************************
2786 * BuildTrusteeWithNameA [ADVAPI32.@]
2788 VOID WINAPI
BuildTrusteeWithNameA(PTRUSTEEA pTrustee
, LPSTR name
)
2790 TRACE("%p %s\n", pTrustee
, debugstr_a(name
) );
2792 pTrustee
->pMultipleTrustee
= NULL
;
2793 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2794 pTrustee
->TrusteeForm
= TRUSTEE_IS_NAME
;
2795 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2796 pTrustee
->ptstrName
= name
;
2799 /******************************************************************************
2800 * BuildTrusteeWithNameW [ADVAPI32.@]
2802 VOID WINAPI
BuildTrusteeWithNameW(PTRUSTEEW pTrustee
, LPWSTR name
)
2804 TRACE("%p %s\n", pTrustee
, debugstr_w(name
) );
2806 pTrustee
->pMultipleTrustee
= NULL
;
2807 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2808 pTrustee
->TrusteeForm
= TRUSTEE_IS_NAME
;
2809 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2810 pTrustee
->ptstrName
= name
;
2813 /******************************************************************************
2814 * GetTrusteeFormA [ADVAPI32.@]
2816 TRUSTEE_FORM WINAPI
GetTrusteeFormA(PTRUSTEEA pTrustee
)
2818 TRACE("(%p)\n", pTrustee
);
2821 return TRUSTEE_BAD_FORM
;
2823 return pTrustee
->TrusteeForm
;
2826 /******************************************************************************
2827 * GetTrusteeFormW [ADVAPI32.@]
2829 TRUSTEE_FORM WINAPI
GetTrusteeFormW(PTRUSTEEW pTrustee
)
2831 TRACE("(%p)\n", pTrustee
);
2834 return TRUSTEE_BAD_FORM
;
2836 return pTrustee
->TrusteeForm
;
2839 /******************************************************************************
2840 * GetTrusteeNameA [ADVAPI32.@]
2842 LPSTR WINAPI
GetTrusteeNameA(PTRUSTEEA pTrustee
)
2844 TRACE("(%p)\n", pTrustee
);
2849 return pTrustee
->ptstrName
;
2852 /******************************************************************************
2853 * GetTrusteeNameW [ADVAPI32.@]
2855 LPWSTR WINAPI
GetTrusteeNameW(PTRUSTEEW pTrustee
)
2857 TRACE("(%p)\n", pTrustee
);
2862 return pTrustee
->ptstrName
;
2865 /******************************************************************************
2866 * GetTrusteeTypeA [ADVAPI32.@]
2868 TRUSTEE_TYPE WINAPI
GetTrusteeTypeA(PTRUSTEEA pTrustee
)
2870 TRACE("(%p)\n", pTrustee
);
2873 return TRUSTEE_IS_UNKNOWN
;
2875 return pTrustee
->TrusteeType
;
2878 /******************************************************************************
2879 * GetTrusteeTypeW [ADVAPI32.@]
2881 TRUSTEE_TYPE WINAPI
GetTrusteeTypeW(PTRUSTEEW pTrustee
)
2883 TRACE("(%p)\n", pTrustee
);
2886 return TRUSTEE_IS_UNKNOWN
;
2888 return pTrustee
->TrusteeType
;
2891 BOOL WINAPI
SetAclInformation( PACL pAcl
, LPVOID pAclInformation
,
2892 DWORD nAclInformationLength
,
2893 ACL_INFORMATION_CLASS dwAclInformationClass
)
2895 FIXME("%p %p 0x%08x 0x%08x - stub\n", pAcl
, pAclInformation
,
2896 nAclInformationLength
, dwAclInformationClass
);
2901 /******************************************************************************
2902 * SetEntriesInAclA [ADVAPI32.@]
2904 DWORD WINAPI
SetEntriesInAclA( ULONG count
, PEXPLICIT_ACCESSA pEntries
,
2905 PACL OldAcl
, PACL
* NewAcl
)
2907 FIXME("%d %p %p %p\n",count
,pEntries
,OldAcl
,NewAcl
);
2909 return ERROR_SUCCESS
;
2912 /******************************************************************************
2913 * SetEntriesInAclW [ADVAPI32.@]
2915 DWORD WINAPI
SetEntriesInAclW( ULONG count
, PEXPLICIT_ACCESSW pEntries
,
2916 PACL OldAcl
, PACL
* NewAcl
)
2918 FIXME("%d %p %p %p\n",count
,pEntries
,OldAcl
,NewAcl
);
2920 return ERROR_SUCCESS
;
2923 /******************************************************************************
2924 * SetNamedSecurityInfoA [ADVAPI32.@]
2926 DWORD WINAPI
SetNamedSecurityInfoA(LPSTR pObjectName
,
2927 SE_OBJECT_TYPE ObjectType
, SECURITY_INFORMATION SecurityInfo
,
2928 PSID psidOwner
, PSID psidGroup
, PACL pDacl
, PACL pSacl
)
2934 TRACE("%s %d %d %p %p %p %p\n", debugstr_a(pObjectName
), ObjectType
,
2935 SecurityInfo
, psidOwner
, psidGroup
, pDacl
, pSacl
);
2939 len
= MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, NULL
, 0 );
2940 wstr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
2941 MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, wstr
, len
);
2944 r
= SetNamedSecurityInfoW( wstr
, ObjectType
, SecurityInfo
, psidOwner
,
2945 psidGroup
, pDacl
, pSacl
);
2947 HeapFree( GetProcessHeap(), 0, wstr
);
2952 BOOL WINAPI
SetPrivateObjectSecurity( SECURITY_INFORMATION SecurityInformation
,
2953 PSECURITY_DESCRIPTOR ModificationDescriptor
,
2954 PSECURITY_DESCRIPTOR
* ObjectsSecurityDescriptor
,
2955 PGENERIC_MAPPING GenericMapping
,
2958 FIXME("0x%08x %p %p %p %p - stub\n", SecurityInformation
, ModificationDescriptor
,
2959 ObjectsSecurityDescriptor
, GenericMapping
, Token
);
2964 BOOL WINAPI
SetSecurityDescriptorControl( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
2965 SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest
,
2966 SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet
)
2968 FIXME("%p 0x%08x 0x%08x - stub\n", pSecurityDescriptor
, ControlBitsOfInterest
,
2974 BOOL WINAPI
AreAllAccessesGranted( DWORD GrantedAccess
, DWORD DesiredAccess
)
2976 return RtlAreAllAccessesGranted( GrantedAccess
, DesiredAccess
);
2979 /******************************************************************************
2980 * AreAnyAccessesGranted [ADVAPI32.@]
2982 * Determines whether or not any of a set of specified access permissions have
2983 * been granted or not.
2986 * GrantedAccess [I] The permissions that have been granted.
2987 * DesiredAccess [I] The permissions that you want to have.
2990 * Nonzero if any of the permissions have been granted, zero if none of the
2991 * permissions have been granted.
2994 BOOL WINAPI
AreAnyAccessesGranted( DWORD GrantedAccess
, DWORD DesiredAccess
)
2996 return RtlAreAnyAccessesGranted( GrantedAccess
, DesiredAccess
);
2999 /******************************************************************************
3000 * SetNamedSecurityInfoW [ADVAPI32.@]
3002 DWORD WINAPI
SetNamedSecurityInfoW(LPWSTR pObjectName
,
3003 SE_OBJECT_TYPE ObjectType
, SECURITY_INFORMATION SecurityInfo
,
3004 PSID psidOwner
, PSID psidGroup
, PACL pDacl
, PACL pSacl
)
3006 FIXME("%s %d %d %p %p %p %p\n", debugstr_w(pObjectName
), ObjectType
,
3007 SecurityInfo
, psidOwner
, psidGroup
, pDacl
, pSacl
);
3008 return ERROR_SUCCESS
;
3011 /******************************************************************************
3012 * GetExplicitEntriesFromAclA [ADVAPI32.@]
3014 DWORD WINAPI
GetExplicitEntriesFromAclA( PACL pacl
, PULONG pcCountOfExplicitEntries
,
3015 PEXPLICIT_ACCESSA
* pListOfExplicitEntries
)
3017 FIXME("%p %p %p\n",pacl
, pcCountOfExplicitEntries
, pListOfExplicitEntries
);
3018 return ERROR_CALL_NOT_IMPLEMENTED
;
3021 /******************************************************************************
3022 * GetExplicitEntriesFromAclW [ADVAPI32.@]
3024 DWORD WINAPI
GetExplicitEntriesFromAclW( PACL pacl
, PULONG pcCountOfExplicitEntries
,
3025 PEXPLICIT_ACCESSW
* pListOfExplicitEntries
)
3027 FIXME("%p %p %p\n",pacl
, pcCountOfExplicitEntries
, pListOfExplicitEntries
);
3028 return ERROR_CALL_NOT_IMPLEMENTED
;
3032 /******************************************************************************
3033 * ParseAclStringFlags
3035 static DWORD
ParseAclStringFlags(LPCWSTR
* StringAcl
)
3038 LPCWSTR szAcl
= *StringAcl
;
3040 while (*szAcl
!= '(')
3044 flags
|= SE_DACL_PROTECTED
;
3046 else if (*szAcl
== 'A')
3050 flags
|= SE_DACL_AUTO_INHERIT_REQ
;
3051 else if (*szAcl
== 'I')
3052 flags
|= SE_DACL_AUTO_INHERITED
;
3061 /******************************************************************************
3062 * ParseAceStringType
3064 static const ACEFLAG AceType
[] =
3066 { SDDL_ACCESS_ALLOWED
, ACCESS_ALLOWED_ACE_TYPE
},
3067 { SDDL_ALARM
, SYSTEM_ALARM_ACE_TYPE
},
3068 { SDDL_AUDIT
, SYSTEM_AUDIT_ACE_TYPE
},
3069 { SDDL_ACCESS_DENIED
, ACCESS_DENIED_ACE_TYPE
},
3071 { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
3072 { SDDL_OBJECT_ACCESS_DENIED, ACCESS_DENIED_OBJECT_ACE_TYPE },
3073 { SDDL_OBJECT_ALARM, SYSTEM_ALARM_OBJECT_ACE_TYPE },
3074 { SDDL_OBJECT_AUDIT, SYSTEM_AUDIT_OBJECT_ACE_TYPE },
3079 static BYTE
ParseAceStringType(LPCWSTR
* StringAcl
)
3082 LPCWSTR szAcl
= *StringAcl
;
3083 const ACEFLAG
*lpaf
= AceType
;
3085 while (lpaf
->wstr
&&
3086 (len
= strlenW(lpaf
->wstr
)) &&
3087 strncmpW(lpaf
->wstr
, szAcl
, len
))
3098 /******************************************************************************
3099 * ParseAceStringFlags
3101 static const ACEFLAG AceFlags
[] =
3103 { SDDL_CONTAINER_INHERIT
, CONTAINER_INHERIT_ACE
},
3104 { SDDL_AUDIT_FAILURE
, FAILED_ACCESS_ACE_FLAG
},
3105 { SDDL_INHERITED
, INHERITED_ACE
},
3106 { SDDL_INHERIT_ONLY
, INHERIT_ONLY_ACE
},
3107 { SDDL_NO_PROPAGATE
, NO_PROPAGATE_INHERIT_ACE
},
3108 { SDDL_OBJECT_INHERIT
, OBJECT_INHERIT_ACE
},
3109 { SDDL_AUDIT_SUCCESS
, SUCCESSFUL_ACCESS_ACE_FLAG
},
3113 static BYTE
ParseAceStringFlags(LPCWSTR
* StringAcl
)
3117 LPCWSTR szAcl
= *StringAcl
;
3119 while (*szAcl
!= ';')
3121 const ACEFLAG
*lpaf
= AceFlags
;
3123 while (lpaf
->wstr
&&
3124 (len
= strlenW(lpaf
->wstr
)) &&
3125 strncmpW(lpaf
->wstr
, szAcl
, len
))
3131 flags
|= lpaf
->value
;
3140 /******************************************************************************
3141 * ParseAceStringRights
3143 static const ACEFLAG AceRights
[] =
3145 { SDDL_GENERIC_ALL
, GENERIC_ALL
},
3146 { SDDL_GENERIC_READ
, GENERIC_READ
},
3147 { SDDL_GENERIC_WRITE
, GENERIC_WRITE
},
3148 { SDDL_GENERIC_EXECUTE
, GENERIC_EXECUTE
},
3150 { SDDL_READ_CONTROL
, READ_CONTROL
},
3151 { SDDL_STANDARD_DELETE
, DELETE
},
3152 { SDDL_WRITE_DAC
, WRITE_DAC
},
3153 { SDDL_WRITE_OWNER
, WRITE_OWNER
},
3155 { SDDL_READ_PROPERTY
, ADS_RIGHT_DS_READ_PROP
},
3156 { SDDL_WRITE_PROPERTY
, ADS_RIGHT_DS_WRITE_PROP
},
3157 { SDDL_CREATE_CHILD
, ADS_RIGHT_DS_CREATE_CHILD
},
3158 { SDDL_DELETE_CHILD
, ADS_RIGHT_DS_DELETE_CHILD
},
3159 { SDDL_LIST_CHILDREN
, ADS_RIGHT_ACTRL_DS_LIST
},
3160 { SDDL_SELF_WRITE
, ADS_RIGHT_DS_SELF
},
3161 { SDDL_LIST_OBJECT
, ADS_RIGHT_DS_LIST_OBJECT
},
3162 { SDDL_DELETE_TREE
, ADS_RIGHT_DS_DELETE_TREE
},
3163 { SDDL_CONTROL_ACCESS
, ADS_RIGHT_DS_CONTROL_ACCESS
},
3165 { SDDL_FILE_ALL
, FILE_ALL_ACCESS
},
3166 { SDDL_FILE_READ
, FILE_GENERIC_READ
},
3167 { SDDL_FILE_WRITE
, FILE_GENERIC_WRITE
},
3168 { SDDL_FILE_EXECUTE
, FILE_GENERIC_EXECUTE
},
3170 { SDDL_KEY_ALL
, KEY_ALL_ACCESS
},
3171 { SDDL_KEY_READ
, KEY_READ
},
3172 { SDDL_KEY_WRITE
, KEY_WRITE
},
3173 { SDDL_KEY_EXECUTE
, KEY_EXECUTE
},
3177 static DWORD
ParseAceStringRights(LPCWSTR
* StringAcl
)
3181 LPCWSTR szAcl
= *StringAcl
;
3183 if ((*szAcl
== '0') && (*(szAcl
+ 1) == 'x'))
3187 while (*p
&& *p
!= ';')
3190 if (p
- szAcl
<= 10 /* 8 hex digits + "0x" */ )
3192 rights
= strtoulW(szAcl
, NULL
, 16);
3196 WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl
, p
- szAcl
));
3200 while (*szAcl
!= ';')
3202 const ACEFLAG
*lpaf
= AceRights
;
3204 while (lpaf
->wstr
&&
3205 (len
= strlenW(lpaf
->wstr
)) &&
3206 strncmpW(lpaf
->wstr
, szAcl
, len
))
3214 rights
|= lpaf
->value
;
3224 /******************************************************************************
3225 * ParseStringAclToAcl
3227 * dacl_flags(string_ace1)(string_ace2)... (string_acen)
3229 static BOOL
ParseStringAclToAcl(LPCWSTR StringAcl
, LPDWORD lpdwFlags
,
3230 PACL pAcl
, LPDWORD cBytes
)
3234 DWORD length
= sizeof(ACL
);
3235 PACCESS_ALLOWED_ACE pAce
= NULL
; /* pointer to current ACE */
3237 TRACE("%s\n", debugstr_w(StringAcl
));
3242 if (pAcl
) /* pAce is only useful if we're setting values */
3243 pAce
= (PACCESS_ALLOWED_ACE
) (pAcl
+ 1);
3245 /* Parse ACL flags */
3246 *lpdwFlags
= ParseAclStringFlags(&StringAcl
);
3249 while (*StringAcl
== '(')
3253 /* Parse ACE type */
3254 val
= ParseAceStringType(&StringAcl
);
3256 pAce
->Header
.AceType
= (BYTE
) val
;
3257 if (*StringAcl
!= ';')
3261 /* Parse ACE flags */
3262 val
= ParseAceStringFlags(&StringAcl
);
3264 pAce
->Header
.AceFlags
= (BYTE
) val
;
3265 if (*StringAcl
!= ';')
3269 /* Parse ACE rights */
3270 val
= ParseAceStringRights(&StringAcl
);
3273 if (*StringAcl
!= ';')
3277 /* Parse ACE object guid */
3278 if (*StringAcl
!= ';')
3280 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3285 /* Parse ACE inherit object guid */
3286 if (*StringAcl
!= ';')
3288 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3293 /* Parse ACE account sid */
3294 if (ParseStringSidToSid(StringAcl
, pAce
? (PSID
)&pAce
->SidStart
: NULL
, &sidlen
))
3296 while (*StringAcl
&& *StringAcl
!= ')')
3300 if (*StringAcl
!= ')')
3304 length
+= sizeof(ACCESS_ALLOWED_ACE
) - sizeof(DWORD
) + sidlen
;
3311 WARN("Invalid ACE string format\n");
3316 /******************************************************************************
3317 * ParseStringSecurityDescriptorToSecurityDescriptor
3319 static BOOL
ParseStringSecurityDescriptorToSecurityDescriptor(
3320 LPCWSTR StringSecurityDescriptor
,
3321 SECURITY_DESCRIPTOR
* SecurityDescriptor
,
3326 WCHAR tok
[MAX_PATH
];
3328 LPBYTE lpNext
= NULL
;
3331 *cBytes
= sizeof(SECURITY_DESCRIPTOR
);
3333 if (SecurityDescriptor
)
3334 lpNext
= ((LPBYTE
) SecurityDescriptor
) + sizeof(SECURITY_DESCRIPTOR
);
3336 while (*StringSecurityDescriptor
)
3338 toktype
= *StringSecurityDescriptor
;
3340 /* Expect char identifier followed by ':' */
3341 StringSecurityDescriptor
++;
3342 if (*StringSecurityDescriptor
!= ':')
3344 SetLastError(ERROR_INVALID_PARAMETER
);
3347 StringSecurityDescriptor
++;
3350 lptoken
= StringSecurityDescriptor
;
3351 while (*lptoken
&& *lptoken
!= ':')
3357 len
= lptoken
- StringSecurityDescriptor
;
3358 memcpy( tok
, StringSecurityDescriptor
, len
* sizeof(WCHAR
) );
3367 if (!ParseStringSidToSid(tok
, (PSID
)lpNext
, &bytes
))
3370 if (SecurityDescriptor
)
3372 SecurityDescriptor
->Owner
= (PSID
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3373 lpNext
+= bytes
; /* Advance to next token */
3385 if (!ParseStringSidToSid(tok
, (PSID
)lpNext
, &bytes
))
3388 if (SecurityDescriptor
)
3390 SecurityDescriptor
->Group
= (PSID
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3391 lpNext
+= bytes
; /* Advance to next token */
3404 if (!ParseStringAclToAcl(tok
, &flags
, (PACL
)lpNext
, &bytes
))
3407 if (SecurityDescriptor
)
3409 SecurityDescriptor
->Control
|= SE_DACL_PRESENT
| flags
;
3410 SecurityDescriptor
->Dacl
= (PACL
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3411 lpNext
+= bytes
; /* Advance to next token */
3424 if (!ParseStringAclToAcl(tok
, &flags
, (PACL
)lpNext
, &bytes
))
3427 if (SecurityDescriptor
)
3429 SecurityDescriptor
->Control
|= SE_SACL_PRESENT
| flags
;
3430 SecurityDescriptor
->Sacl
= (PACL
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3431 lpNext
+= bytes
; /* Advance to next token */
3440 FIXME("Unknown token\n");
3441 SetLastError(ERROR_INVALID_PARAMETER
);
3445 StringSecurityDescriptor
= lptoken
;
3454 /******************************************************************************
3455 * ConvertStringSecurityDescriptorToSecurityDescriptorA [ADVAPI32.@]
3457 BOOL WINAPI
ConvertStringSecurityDescriptorToSecurityDescriptorA(
3458 LPCSTR StringSecurityDescriptor
,
3459 DWORD StringSDRevision
,
3460 PSECURITY_DESCRIPTOR
* SecurityDescriptor
,
3461 PULONG SecurityDescriptorSize
)
3465 LPWSTR StringSecurityDescriptorW
;
3467 len
= MultiByteToWideChar(CP_ACP
, 0, StringSecurityDescriptor
, -1, NULL
, 0);
3468 StringSecurityDescriptorW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3470 if (StringSecurityDescriptorW
)
3472 MultiByteToWideChar(CP_ACP
, 0, StringSecurityDescriptor
, -1, StringSecurityDescriptorW
, len
);
3474 ret
= ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptorW
,
3475 StringSDRevision
, SecurityDescriptor
,
3476 SecurityDescriptorSize
);
3477 HeapFree(GetProcessHeap(), 0, StringSecurityDescriptorW
);
3483 /******************************************************************************
3484 * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
3486 BOOL WINAPI
ConvertStringSecurityDescriptorToSecurityDescriptorW(
3487 LPCWSTR StringSecurityDescriptor
,
3488 DWORD StringSDRevision
,
3489 PSECURITY_DESCRIPTOR
* SecurityDescriptor
,
3490 PULONG SecurityDescriptorSize
)
3493 SECURITY_DESCRIPTOR
* psd
;
3496 TRACE("%s\n", debugstr_w(StringSecurityDescriptor
));
3498 if (GetVersion() & 0x80000000)
3500 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3503 else if (StringSDRevision
!= SID_REVISION
)
3505 SetLastError(ERROR_UNKNOWN_REVISION
);
3509 /* Compute security descriptor length */
3510 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor
,
3514 psd
= *SecurityDescriptor
= (SECURITY_DESCRIPTOR
*) LocalAlloc(
3515 GMEM_ZEROINIT
, cBytes
);
3516 if (!psd
) goto lend
;
3518 psd
->Revision
= SID_REVISION
;
3519 psd
->Control
|= SE_SELF_RELATIVE
;
3521 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor
,
3528 if (SecurityDescriptorSize
)
3529 *SecurityDescriptorSize
= cBytes
;
3534 TRACE(" ret=%d\n", bret
);
3538 /******************************************************************************
3539 * ConvertStringSidToSidW [ADVAPI32.@]
3541 BOOL WINAPI
ConvertStringSidToSidW(LPCWSTR StringSid
, PSID
* Sid
)
3546 TRACE("%s, %p\n", debugstr_w(StringSid
), Sid
);
3547 if (GetVersion() & 0x80000000)
3548 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3549 else if (!StringSid
|| !Sid
)
3550 SetLastError(ERROR_INVALID_PARAMETER
);
3551 else if (ParseStringSidToSid(StringSid
, NULL
, &cBytes
))
3553 PSID pSid
= *Sid
= (PSID
) LocalAlloc(0, cBytes
);
3555 bret
= ParseStringSidToSid(StringSid
, pSid
, &cBytes
);
3559 TRACE("returning %s\n", bret
? "TRUE" : "FALSE");
3563 /******************************************************************************
3564 * ConvertStringSidToSidA [ADVAPI32.@]
3566 BOOL WINAPI
ConvertStringSidToSidA(LPCSTR StringSid
, PSID
* Sid
)
3570 TRACE("%s, %p\n", debugstr_a(StringSid
), Sid
);
3571 if (GetVersion() & 0x80000000)
3572 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3573 else if (!StringSid
|| !Sid
)
3574 SetLastError(ERROR_INVALID_PARAMETER
);
3577 UINT len
= MultiByteToWideChar(CP_ACP
, 0, StringSid
, -1, NULL
, 0);
3578 LPWSTR wStringSid
= HeapAlloc(GetProcessHeap(), 0,
3579 len
* sizeof(WCHAR
));
3581 MultiByteToWideChar(CP_ACP
, 0, StringSid
, -1, wStringSid
, len
);
3582 bret
= ConvertStringSidToSidW(wStringSid
, Sid
);
3583 HeapFree(GetProcessHeap(), 0, wStringSid
);
3585 TRACE("returning %s\n", bret
? "TRUE" : "FALSE");
3589 /******************************************************************************
3590 * ConvertSidToStringSidW [ADVAPI32.@]
3592 * format of SID string is:
3593 * S-<count>-<auth>-<subauth1>-<subauth2>-<subauth3>...
3595 * <rev> is the revision of the SID encoded as decimal
3596 * <auth> is the identifier authority encoded as hex
3597 * <subauthN> is the subauthority id encoded as decimal
3599 BOOL WINAPI
ConvertSidToStringSidW( PSID pSid
, LPWSTR
*pstr
)
3603 WCHAR fmt
[] = { 'S','-','%','u','-','%','d',0 };
3604 WCHAR subauthfmt
[] = { '-','%','u',0 };
3607 TRACE("%p %p\n", pSid
, pstr
);
3609 if( !IsValidSid( pSid
) )
3612 if (pisid
->Revision
!= SDDL_REVISION
)
3614 if (pisid
->IdentifierAuthority
.Value
[0] ||
3615 pisid
->IdentifierAuthority
.Value
[1])
3617 FIXME("not matching MS' bugs\n");
3621 sz
= 14 + pisid
->SubAuthorityCount
* 11;
3622 str
= LocalAlloc( 0, sz
*sizeof(WCHAR
) );
3623 sprintfW( str
, fmt
, pisid
->Revision
, MAKELONG(
3624 MAKEWORD( pisid
->IdentifierAuthority
.Value
[5],
3625 pisid
->IdentifierAuthority
.Value
[4] ),
3626 MAKEWORD( pisid
->IdentifierAuthority
.Value
[3],
3627 pisid
->IdentifierAuthority
.Value
[2] ) ) );
3628 for( i
=0; i
<pisid
->SubAuthorityCount
; i
++ )
3629 sprintfW( str
+ strlenW(str
), subauthfmt
, pisid
->SubAuthority
[i
] );
3635 /******************************************************************************
3636 * ConvertSidToStringSidA [ADVAPI32.@]
3638 BOOL WINAPI
ConvertSidToStringSidA(PSID pSid
, LPSTR
*pstr
)
3644 TRACE("%p %p\n", pSid
, pstr
);
3646 if( !ConvertSidToStringSidW( pSid
, &wstr
) )
3649 len
= WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
3650 str
= LocalAlloc( 0, len
);
3651 WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, str
, len
, NULL
, NULL
);
3659 BOOL WINAPI
CreatePrivateObjectSecurity(
3660 PSECURITY_DESCRIPTOR ParentDescriptor
,
3661 PSECURITY_DESCRIPTOR CreatorDescriptor
,
3662 PSECURITY_DESCRIPTOR
* NewDescriptor
,
3663 BOOL IsDirectoryObject
,
3665 PGENERIC_MAPPING GenericMapping
)
3667 FIXME("%p %p %p %d %p %p - stub\n", ParentDescriptor
, CreatorDescriptor
,
3668 NewDescriptor
, IsDirectoryObject
, Token
, GenericMapping
);
3673 BOOL WINAPI
DestroyPrivateObjectSecurity( PSECURITY_DESCRIPTOR
* ObjectDescriptor
)
3675 FIXME("%p - stub\n", ObjectDescriptor
);
3680 BOOL WINAPI
CreateProcessAsUserA(
3682 LPCSTR lpApplicationName
,
3683 LPSTR lpCommandLine
,
3684 LPSECURITY_ATTRIBUTES lpProcessAttributes
,
3685 LPSECURITY_ATTRIBUTES lpThreadAttributes
,
3686 BOOL bInheritHandles
,
3687 DWORD dwCreationFlags
,
3688 LPVOID lpEnvironment
,
3689 LPCSTR lpCurrentDirectory
,
3690 LPSTARTUPINFOA lpStartupInfo
,
3691 LPPROCESS_INFORMATION lpProcessInformation
)
3693 FIXME("%p %s %s %p %p %d 0x%08x %p %s %p %p - stub\n", hToken
, debugstr_a(lpApplicationName
),
3694 debugstr_a(lpCommandLine
), lpProcessAttributes
, lpThreadAttributes
, bInheritHandles
,
3695 dwCreationFlags
, lpEnvironment
, debugstr_a(lpCurrentDirectory
), lpStartupInfo
, lpProcessInformation
);
3700 BOOL WINAPI
CreateProcessAsUserW(
3702 LPCWSTR lpApplicationName
,
3703 LPWSTR lpCommandLine
,
3704 LPSECURITY_ATTRIBUTES lpProcessAttributes
,
3705 LPSECURITY_ATTRIBUTES lpThreadAttributes
,
3706 BOOL bInheritHandles
,
3707 DWORD dwCreationFlags
,
3708 LPVOID lpEnvironment
,
3709 LPCWSTR lpCurrentDirectory
,
3710 LPSTARTUPINFOW lpStartupInfo
,
3711 LPPROCESS_INFORMATION lpProcessInformation
)
3713 FIXME("%p %s %s %p %p %d 0x%08x %p %s %p %p - semi- stub\n", hToken
,
3714 debugstr_w(lpApplicationName
), debugstr_w(lpCommandLine
), lpProcessAttributes
,
3715 lpThreadAttributes
, bInheritHandles
, dwCreationFlags
, lpEnvironment
,
3716 debugstr_w(lpCurrentDirectory
), lpStartupInfo
, lpProcessInformation
);
3718 /* We should create the process with a suspended main thread */
3719 if (!CreateProcessW (lpApplicationName
,
3721 lpProcessAttributes
,
3724 dwCreationFlags
, /* CREATE_SUSPENDED */
3728 lpProcessInformation
))
3736 /******************************************************************************
3737 * DuplicateTokenEx [ADVAPI32.@]
3739 BOOL WINAPI
DuplicateTokenEx(
3740 HANDLE ExistingTokenHandle
, DWORD dwDesiredAccess
,
3741 LPSECURITY_ATTRIBUTES lpTokenAttributes
,
3742 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
3743 TOKEN_TYPE TokenType
,
3744 PHANDLE DuplicateTokenHandle
)
3746 OBJECT_ATTRIBUTES ObjectAttributes
;
3748 TRACE("%p 0x%08x 0x%08x 0x%08x %p\n", ExistingTokenHandle
, dwDesiredAccess
,
3749 ImpersonationLevel
, TokenType
, DuplicateTokenHandle
);
3751 InitializeObjectAttributes(
3754 (lpTokenAttributes
&& lpTokenAttributes
->bInheritHandle
) ? OBJ_INHERIT
: 0,
3756 lpTokenAttributes
? lpTokenAttributes
->lpSecurityDescriptor
: NULL
);
3758 return set_ntstatus( NtDuplicateToken( ExistingTokenHandle
,
3763 DuplicateTokenHandle
) );
3766 BOOL WINAPI
DuplicateToken(
3767 HANDLE ExistingTokenHandle
,
3768 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
3769 PHANDLE DuplicateTokenHandle
)
3771 return DuplicateTokenEx( ExistingTokenHandle
, TOKEN_IMPERSONATE
| TOKEN_QUERY
,
3772 NULL
, ImpersonationLevel
, TokenImpersonation
,
3773 DuplicateTokenHandle
);
3776 BOOL WINAPI
EnumDependentServicesA(
3778 DWORD dwServiceState
,
3779 LPENUM_SERVICE_STATUSA lpServices
,
3781 LPDWORD pcbBytesNeeded
,
3782 LPDWORD lpServicesReturned
)
3784 FIXME("%p 0x%08x %p 0x%08x %p %p - stub\n", hService
, dwServiceState
,
3785 lpServices
, cbBufSize
, pcbBytesNeeded
, lpServicesReturned
);
3790 BOOL WINAPI
EnumDependentServicesW(
3792 DWORD dwServiceState
,
3793 LPENUM_SERVICE_STATUSW lpServices
,
3795 LPDWORD pcbBytesNeeded
,
3796 LPDWORD lpServicesReturned
)
3798 FIXME("%p 0x%08x %p 0x%08x %p %p - stub\n", hService
, dwServiceState
,
3799 lpServices
, cbBufSize
, pcbBytesNeeded
, lpServicesReturned
);
3804 /******************************************************************************
3805 * ComputeStringSidSize
3807 static DWORD
ComputeStringSidSize(LPCWSTR StringSid
)
3809 if (StringSid
[0] == 'S' && StringSid
[1] == '-') /* S-R-I(-S)+ */
3814 if (*StringSid
== '-')
3820 return GetSidLengthRequired(ctok
- 2);
3822 else /* String constant format - Only available in winxp and above */
3826 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
3827 if (!strncmpW(WellKnownSids
[i
].wstr
, StringSid
, 2))
3828 return GetSidLengthRequired(WellKnownSids
[i
].Sid
.SubAuthorityCount
);
3831 return GetSidLengthRequired(0);
3834 /******************************************************************************
3835 * ParseStringSidToSid
3837 static BOOL
ParseStringSidToSid(LPCWSTR StringSid
, PSID pSid
, LPDWORD cBytes
)
3842 TRACE("%s, %p, %p\n", debugstr_w(StringSid
), pSid
, cBytes
);
3845 SetLastError(ERROR_INVALID_PARAMETER
);
3846 TRACE("StringSid is NULL, returning FALSE\n");
3850 *cBytes
= ComputeStringSidSize(StringSid
);
3851 if (!pisid
) /* Simply compute the size */
3853 TRACE("only size requested, returning TRUE\n");
3857 if (StringSid
[0] == 'S' && StringSid
[1] == '-') /* S-R-I-S-S */
3859 DWORD i
= 0, identAuth
;
3860 DWORD csubauth
= ((*cBytes
- GetSidLengthRequired(0)) / sizeof(DWORD
));
3862 StringSid
+= 2; /* Advance to Revision */
3863 pisid
->Revision
= atoiW(StringSid
);
3865 if (pisid
->Revision
!= SDDL_REVISION
)
3867 TRACE("Revision %d is unknown\n", pisid
->Revision
);
3868 goto lend
; /* ERROR_INVALID_SID */
3872 TRACE("SubAuthorityCount is 0\n");
3873 goto lend
; /* ERROR_INVALID_SID */
3876 pisid
->SubAuthorityCount
= csubauth
;
3878 /* Advance to identifier authority */
3879 while (*StringSid
&& *StringSid
!= '-')
3881 if (*StringSid
== '-')
3884 /* MS' implementation can't handle values greater than 2^32 - 1, so
3885 * we don't either; assume most significant bytes are always 0
3887 pisid
->IdentifierAuthority
.Value
[0] = 0;
3888 pisid
->IdentifierAuthority
.Value
[1] = 0;
3889 identAuth
= atoiW(StringSid
);
3890 pisid
->IdentifierAuthority
.Value
[5] = identAuth
& 0xff;
3891 pisid
->IdentifierAuthority
.Value
[4] = (identAuth
& 0xff00) >> 8;
3892 pisid
->IdentifierAuthority
.Value
[3] = (identAuth
& 0xff0000) >> 16;
3893 pisid
->IdentifierAuthority
.Value
[2] = (identAuth
& 0xff000000) >> 24;
3895 /* Advance to first sub authority */
3896 while (*StringSid
&& *StringSid
!= '-')
3898 if (*StringSid
== '-')
3903 while (*StringSid
&& *StringSid
!= '-')
3905 if (*StringSid
== '-')
3908 pisid
->SubAuthority
[i
++] = atoiW(StringSid
);
3911 if (i
!= pisid
->SubAuthorityCount
)
3912 goto lend
; /* ERROR_INVALID_SID */
3916 else /* String constant format - Only available in winxp and above */
3919 pisid
->Revision
= SDDL_REVISION
;
3921 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
3922 if (!strncmpW(WellKnownSids
[i
].wstr
, StringSid
, 2))
3925 pisid
->SubAuthorityCount
= WellKnownSids
[i
].Sid
.SubAuthorityCount
;
3926 pisid
->IdentifierAuthority
= WellKnownSids
[i
].Sid
.IdentifierAuthority
;
3927 for (j
= 0; j
< WellKnownSids
[i
].Sid
.SubAuthorityCount
; j
++)
3928 pisid
->SubAuthority
[j
] = WellKnownSids
[i
].Sid
.SubAuthority
[j
];
3933 FIXME("String constant not supported: %s\n", debugstr_wn(StringSid
, 2));
3938 SetLastError(ERROR_INVALID_SID
);
3940 TRACE("returning %s\n", bret
? "TRUE" : "FALSE");
3944 /******************************************************************************
3945 * GetNamedSecurityInfoA [ADVAPI32.@]
3947 DWORD WINAPI
GetNamedSecurityInfoA(LPSTR pObjectName
,
3948 SE_OBJECT_TYPE ObjectType
, SECURITY_INFORMATION SecurityInfo
,
3949 PSID
* ppsidOwner
, PSID
* ppsidGroup
, PACL
* ppDacl
, PACL
* ppSacl
,
3950 PSECURITY_DESCRIPTOR
* ppSecurityDescriptor
)
3956 TRACE("%s %d %d %p %p %p %p %p\n", pObjectName
, ObjectType
, SecurityInfo
,
3957 ppsidOwner
, ppsidGroup
, ppDacl
, ppSacl
, ppSecurityDescriptor
);
3961 len
= MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, NULL
, 0 );
3962 wstr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
3963 MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, wstr
, len
);
3966 r
= GetNamedSecurityInfoW( wstr
, ObjectType
, SecurityInfo
, ppsidOwner
,
3967 ppsidGroup
, ppDacl
, ppSacl
, ppSecurityDescriptor
);
3969 HeapFree( GetProcessHeap(), 0, wstr
);
3974 /******************************************************************************
3975 * GetNamedSecurityInfoW [ADVAPI32.@]
3977 DWORD WINAPI
GetNamedSecurityInfoW( LPWSTR name
, SE_OBJECT_TYPE type
,
3978 SECURITY_INFORMATION info
, PSID
* owner
, PSID
* group
, PACL
* dacl
,
3979 PACL
* sacl
, PSECURITY_DESCRIPTOR
* descriptor
)
3981 DWORD needed
, offset
;
3982 SECURITY_DESCRIPTOR_RELATIVE
*relative
;
3985 TRACE( "%s %d %d %p %p %p %p %p\n", debugstr_w(name
), type
, info
, owner
,
3986 group
, dacl
, sacl
, descriptor
);
3988 if (!name
|| !descriptor
) return ERROR_INVALID_PARAMETER
;
3990 needed
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
3991 if (info
& OWNER_SECURITY_INFORMATION
)
3992 needed
+= sizeof(sidWorld
);
3993 if (info
& GROUP_SECURITY_INFORMATION
)
3994 needed
+= sizeof(sidWorld
);
3995 if (info
& DACL_SECURITY_INFORMATION
)
3996 needed
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
3997 if (info
& SACL_SECURITY_INFORMATION
)
3998 needed
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
4000 /* must be freed by caller */
4001 *descriptor
= HeapAlloc( GetProcessHeap(), 0, needed
);
4002 if (!*descriptor
) return ERROR_NOT_ENOUGH_MEMORY
;
4004 if (!InitializeSecurityDescriptor( *descriptor
, SECURITY_DESCRIPTOR_REVISION
))
4006 HeapFree( GetProcessHeap(), 0, *descriptor
);
4007 return ERROR_INVALID_SECURITY_DESCR
;
4010 relative
= (SECURITY_DESCRIPTOR_RELATIVE
*)*descriptor
;
4011 relative
->Control
|= SE_SELF_RELATIVE
;
4012 buffer
= (BYTE
*)relative
;
4013 offset
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
4015 if (info
& OWNER_SECURITY_INFORMATION
)
4017 memcpy( buffer
+ offset
, &sidWorld
, sizeof(sidWorld
) );
4018 relative
->Owner
= offset
;
4020 *owner
= buffer
+ offset
;
4021 offset
+= sizeof(sidWorld
);
4023 if (info
& GROUP_SECURITY_INFORMATION
)
4025 memcpy( buffer
+ offset
, &sidWorld
, sizeof(sidWorld
) );
4026 relative
->Group
= offset
;
4028 *group
= buffer
+ offset
;
4029 offset
+= sizeof(sidWorld
);
4031 if (info
& DACL_SECURITY_INFORMATION
)
4033 relative
->Control
|= SE_DACL_PRESENT
;
4034 GetWorldAccessACL( (PACL
)(buffer
+ offset
) );
4035 relative
->Dacl
= offset
;
4037 *dacl
= (PACL
)(buffer
+ offset
);
4038 offset
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
4040 if (info
& SACL_SECURITY_INFORMATION
)
4042 relative
->Control
|= SE_SACL_PRESENT
;
4043 GetWorldAccessACL( (PACL
)(buffer
+ offset
) );
4044 relative
->Sacl
= offset
;
4046 *sacl
= (PACL
)(buffer
+ offset
);
4048 return ERROR_SUCCESS
;
4051 /******************************************************************************
4052 * DecryptFileW [ADVAPI32.@]
4054 BOOL WINAPI
DecryptFileW(LPCWSTR lpFileName
, DWORD dwReserved
)
4056 FIXME("%s %08x\n", debugstr_w(lpFileName
), dwReserved
);
4060 /******************************************************************************
4061 * DecryptFileA [ADVAPI32.@]
4063 BOOL WINAPI
DecryptFileA(LPCSTR lpFileName
, DWORD dwReserved
)
4065 FIXME("%s %08x\n", debugstr_a(lpFileName
), dwReserved
);
4069 /******************************************************************************
4070 * EncryptFileW [ADVAPI32.@]
4072 BOOL WINAPI
EncryptFileW(LPCWSTR lpFileName
)
4074 FIXME("%s\n", debugstr_w(lpFileName
));
4078 /******************************************************************************
4079 * EncryptFileA [ADVAPI32.@]
4081 BOOL WINAPI
EncryptFileA(LPCSTR lpFileName
)
4083 FIXME("%s\n", debugstr_a(lpFileName
));
4087 /******************************************************************************
4088 * FileEncryptionStatusW [ADVAPI32.@]
4090 BOOL WINAPI
FileEncryptionStatusW(LPCWSTR lpFileName
, LPDWORD lpStatus
)
4092 FIXME("(%s %p): stub\n", debugstr_w(lpFileName
), lpStatus
);
4095 *lpStatus
= FILE_SYSTEM_NOT_SUPPORT
;
4099 /******************************************************************************
4100 * FileEncryptionStatusA [ADVAPI32.@]
4102 BOOL WINAPI
FileEncryptionStatusA(LPCSTR lpFileName
, LPDWORD lpStatus
)
4104 FIXME("(%s %p): stub\n", debugstr_a(lpFileName
), lpStatus
);
4107 *lpStatus
= FILE_SYSTEM_NOT_SUPPORT
;
4111 /******************************************************************************
4112 * SetSecurityInfo [ADVAPI32.@]
4114 DWORD WINAPI
SetSecurityInfo(HANDLE handle
, SE_OBJECT_TYPE ObjectType
,
4115 SECURITY_INFORMATION SecurityInfo
, PSID psidOwner
,
4116 PSID psidGroup
, PACL pDacl
, PACL pSacl
) {
4118 return ERROR_SUCCESS
;