2 * Copyright 1999, 2000 Juergen Schmied <juergen.schmied@debitel.net>
3 * Copyright 2003 CodeWeavers Inc. (Ulrich Czekalla)
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define WIN32_NO_STATUS
39 #include "wine/debug.h"
40 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
44 static BOOL
ParseStringSidToSid(LPCWSTR StringSid
, PSID pSid
, LPDWORD cBytes
);
45 static BOOL
ParseStringAclToAcl(LPCWSTR StringAcl
, LPDWORD lpdwFlags
,
46 PACL pAcl
, LPDWORD cBytes
);
47 static BYTE
ParseAceStringFlags(LPCWSTR
* StringAcl
);
48 static BYTE
ParseAceStringType(LPCWSTR
* StringAcl
);
49 static DWORD
ParseAceStringRights(LPCWSTR
* StringAcl
);
50 static BOOL
ParseStringSecurityDescriptorToSecurityDescriptor(
51 LPCWSTR StringSecurityDescriptor
,
52 SECURITY_DESCRIPTOR
* SecurityDescriptor
,
54 static DWORD
ParseAclStringFlags(LPCWSTR
* StringAcl
);
56 typedef struct _ACEFLAG
60 } ACEFLAG
, *LPACEFLAG
;
62 typedef struct _MAX_SID
64 /* same fields as struct _SID */
66 BYTE SubAuthorityCount
;
67 SID_IDENTIFIER_AUTHORITY IdentifierAuthority
;
68 DWORD SubAuthority
[SID_MAX_SUB_AUTHORITIES
];
71 typedef struct WELLKNOWNSID
74 WELL_KNOWN_SID_TYPE Type
;
78 static const WELLKNOWNSID WellKnownSids
[] =
80 { {0,0}, WinNullSid
, { SID_REVISION
, 1, { SECURITY_NULL_SID_AUTHORITY
}, { SECURITY_NULL_RID
} } },
81 { {'W','D'}, WinWorldSid
, { SID_REVISION
, 1, { SECURITY_WORLD_SID_AUTHORITY
}, { SECURITY_WORLD_RID
} } },
82 { {0,0}, WinLocalSid
, { SID_REVISION
, 1, { SECURITY_LOCAL_SID_AUTHORITY
}, { SECURITY_LOCAL_RID
} } },
83 { {'C','O'}, WinCreatorOwnerSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_OWNER_RID
} } },
84 { {'C','G'}, WinCreatorGroupSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_GROUP_RID
} } },
85 { {0,0}, WinCreatorOwnerServerSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_OWNER_SERVER_RID
} } },
86 { {0,0}, WinCreatorGroupServerSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_GROUP_SERVER_RID
} } },
87 { {0,0}, WinNtAuthoritySid
, { SID_REVISION
, 0, { SECURITY_NT_AUTHORITY
}, { } } },
88 { {0,0}, WinDialupSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_DIALUP_RID
} } },
89 { {'N','U'}, WinNetworkSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_NETWORK_RID
} } },
90 { {0,0}, WinBatchSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_BATCH_RID
} } },
91 { {'I','U'}, WinInteractiveSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_INTERACTIVE_RID
} } },
92 { {'S','U'}, WinServiceSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_SERVICE_RID
} } },
93 { {'A','N'}, WinAnonymousSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_ANONYMOUS_LOGON_RID
} } },
94 { {0,0}, WinProxySid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_PROXY_RID
} } },
95 { {'E','D'}, WinEnterpriseControllersSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_ENTERPRISE_CONTROLLERS_RID
} } },
96 { {'P','S'}, WinSelfSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_PRINCIPAL_SELF_RID
} } },
97 { {'A','U'}, WinAuthenticatedUserSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_AUTHENTICATED_USER_RID
} } },
98 { {'R','C'}, WinRestrictedCodeSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_RESTRICTED_CODE_RID
} } },
99 { {0,0}, WinTerminalServerSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_TERMINAL_SERVER_RID
} } },
100 { {0,0}, WinRemoteLogonIdSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_REMOTE_LOGON_RID
} } },
101 { {'S','Y'}, WinLocalSystemSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_LOCAL_SYSTEM_RID
} } },
102 { {'L','S'}, WinLocalServiceSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_LOCAL_SERVICE_RID
} } },
103 { {'N','S'}, WinNetworkServiceSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_NETWORK_SERVICE_RID
} } },
104 { {0,0}, WinBuiltinDomainSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
} } },
105 { {'B','A'}, WinBuiltinAdministratorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_ADMINS
} } },
106 { {'B','U'}, WinBuiltinUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_USERS
} } },
107 { {'B','G'}, WinBuiltinGuestsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_GUESTS
} } },
108 { {'P','U'}, WinBuiltinPowerUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_POWER_USERS
} } },
109 { {'A','O'}, WinBuiltinAccountOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_ACCOUNT_OPS
} } },
110 { {'S','O'}, WinBuiltinSystemOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_SYSTEM_OPS
} } },
111 { {'P','O'}, WinBuiltinPrintOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_PRINT_OPS
} } },
112 { {'B','O'}, WinBuiltinBackupOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_BACKUP_OPS
} } },
113 { {'R','E'}, WinBuiltinReplicatorSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_REPLICATOR
} } },
114 { {'R','U'}, WinBuiltinPreWindows2000CompatibleAccessSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_PREW2KCOMPACCESS
} } },
115 { {'R','D'}, WinBuiltinRemoteDesktopUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS
} } },
116 { {'N','O'}, WinBuiltinNetworkConfigurationOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS
} } },
119 static SID
const sidWorld
= { SID_REVISION
, 1, { SECURITY_WORLD_SID_AUTHORITY
} , { SECURITY_WORLD_RID
} };
121 typedef struct _AccountSid
{
122 WELL_KNOWN_SID_TYPE type
;
125 SID_NAME_USE name_use
;
128 static const WCHAR Account_Operators
[] = { 'A','c','c','o','u','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
129 static const WCHAR Administrator
[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0 };
130 static const WCHAR Administrators
[] = { 'A','d','m','i','n','i','s','t','r','a','t','o','r','s',0 };
131 static const WCHAR ANONYMOUS_LOGON
[] = { 'A','N','O','N','Y','M','O','U','S',' ','L','O','G','O','N',0 };
132 static const WCHAR Authenticated_Users
[] = { 'A','u','t','h','e','n','t','i','c','a','t','e','d',' ','U','s','e','r','s',0 };
133 static const WCHAR Backup_Operators
[] = { 'B','a','c','k','u','p',' ','O','p','e','r','a','t','o','r','s',0 };
134 static const WCHAR BATCH
[] = { 'B','A','T','C','H',0 };
135 static const WCHAR Blank
[] = { 0 };
136 static const WCHAR BUILTIN
[] = { 'B','U','I','L','T','I','N',0 };
137 static const WCHAR CREATOR_GROUP
[] = { 'C','R','E','A','T','O','R',' ','G','R','O','U','P',0 };
138 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 };
139 static const WCHAR CREATOR_OWNER
[] = { 'C','R','E','A','T','O','R',' ','O','W','N','E','R',0 };
140 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 };
141 static const WCHAR DIALUP
[] = { 'D','I','A','L','U','P',0 };
142 static const WCHAR DOMAIN
[] = {'D','O','M','A','I','N',0};
143 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 };
144 static const WCHAR Everyone
[] = { 'E','v','e','r','y','o','n','e',0 };
145 static const WCHAR Guests
[] = { 'G','u','e','s','t','s',0 };
146 static const WCHAR INTERACTIVE
[] = { 'I','N','T','E','R','A','C','T','I','V','E',0 };
147 static const WCHAR LOCAL
[] = { 'L','O','C','A','L',0 };
148 static const WCHAR LOCAL_SERVICE
[] = { 'L','O','C','A','L',' ','S','E','R','V','I','C','E',0 };
149 static const WCHAR NETWORK
[] = { 'N','E','T','W','O','R','K',0 };
150 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 };
151 static const WCHAR NETWORK_SERVICE
[] = { 'N','E','T','W','O','R','K',' ','S','E','R','V','I','C','E',0 };
152 static const WCHAR NT_AUTHORITY
[] = { 'N','T',' ','A','U','T','H','O','R','I','T','Y',0 };
153 static const WCHAR NT_Pseudo_Domain
[] = { 'N','T',' ','P','s','e','u','d','o',' ','D','o','m','a','i','n',0 };
154 static const WCHAR NULL_SID
[] = { 'N','U','L','L',' ','S','I','D',0 };
155 static const WCHAR Power_Users
[] = { 'P','o','w','e','r',' ','U','s','e','r','s',0 };
156 static const WCHAR Print_Operators
[] = { 'P','r','i','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
157 static const WCHAR PROXY
[] = { 'P','R','O','X','Y',0 };
158 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 };
159 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 };
160 static const WCHAR Replicators
[] = { 'R','e','p','l','i','c','a','t','o','r','s',0 };
161 static const WCHAR RESTRICTED
[] = { 'R','E','S','T','R','I','C','T','E','D',0 };
162 static const WCHAR SELF
[] = { 'S','E','L','F',0 };
163 static const WCHAR Server_Operators
[] = { 'S','e','r','v','e','r',' ','O','p','e','r','a','t','o','r','s',0 };
164 static const WCHAR SERVICE
[] = { 'S','E','R','V','I','C','E',0 };
165 static const WCHAR SYSTEM
[] = { 'S','Y','S','T','E','M',0 };
166 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 };
167 static const WCHAR Users
[] = { 'U','s','e','r','s',0 };
169 static const AccountSid ACCOUNT_SIDS
[] = {
170 { WinNullSid
, NULL_SID
, Blank
, SidTypeWellKnownGroup
},
171 { WinWorldSid
, Everyone
, Blank
, SidTypeWellKnownGroup
},
172 { WinLocalSid
, LOCAL
, Blank
, SidTypeWellKnownGroup
},
173 { WinCreatorOwnerSid
, CREATOR_OWNER
, Blank
, SidTypeWellKnownGroup
},
174 { WinCreatorGroupSid
, CREATOR_GROUP
, Blank
, SidTypeWellKnownGroup
},
175 { WinCreatorOwnerServerSid
, CREATOR_OWNER_SERVER
, Blank
, SidTypeWellKnownGroup
},
176 { WinCreatorGroupServerSid
, CREATOR_GROUP_SERVER
, Blank
, SidTypeWellKnownGroup
},
177 { WinNtAuthoritySid
, NT_Pseudo_Domain
, NT_Pseudo_Domain
, SidTypeDomain
},
178 { WinDialupSid
, DIALUP
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
179 { WinNetworkSid
, NETWORK
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
180 { WinBatchSid
, BATCH
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
181 { WinInteractiveSid
, INTERACTIVE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
182 { WinServiceSid
, SERVICE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
183 { WinAnonymousSid
, ANONYMOUS_LOGON
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
184 { WinProxySid
, PROXY
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
185 { WinEnterpriseControllersSid
, ENTERPRISE_DOMAIN_CONTROLLERS
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
186 { WinSelfSid
, SELF
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
187 { WinAuthenticatedUserSid
, Authenticated_Users
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
188 { WinRestrictedCodeSid
, RESTRICTED
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
189 { WinTerminalServerSid
, TERMINAL_SERVER_USER
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
190 { WinRemoteLogonIdSid
, REMOTE_INTERACTIVE_LOGON
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
191 { WinLocalSystemSid
, SYSTEM
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
192 { WinLocalServiceSid
, LOCAL_SERVICE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
193 { WinNetworkServiceSid
, NETWORK_SERVICE
, NT_AUTHORITY
, SidTypeWellKnownGroup
},
194 { WinBuiltinDomainSid
, BUILTIN
, BUILTIN
, SidTypeDomain
},
195 { WinBuiltinAdministratorsSid
, Administrators
, BUILTIN
, SidTypeAlias
},
196 { WinBuiltinUsersSid
, Users
, BUILTIN
, SidTypeAlias
},
197 { WinBuiltinGuestsSid
, Guests
, BUILTIN
, SidTypeAlias
},
198 { WinBuiltinPowerUsersSid
, Power_Users
, BUILTIN
, SidTypeAlias
},
199 { WinBuiltinAccountOperatorsSid
, Account_Operators
, BUILTIN
, SidTypeAlias
},
200 { WinBuiltinSystemOperatorsSid
, Server_Operators
, BUILTIN
, SidTypeAlias
},
201 { WinBuiltinPrintOperatorsSid
, Print_Operators
, BUILTIN
, SidTypeAlias
},
202 { WinBuiltinBackupOperatorsSid
, Backup_Operators
, BUILTIN
, SidTypeAlias
},
203 { WinBuiltinReplicatorSid
, Replicators
, BUILTIN
, SidTypeAlias
},
204 { WinBuiltinRemoteDesktopUsersSid
, Remote_Desktop_Users
, BUILTIN
, SidTypeAlias
},
205 { WinBuiltinNetworkConfigurationOperatorsSid
, Network_Configuration_Operators
, BUILTIN
, SidTypeAlias
},
210 static const WCHAR SDDL_READ_CONTROL
[] = {'R','C',0};
211 static const WCHAR SDDL_WRITE_DAC
[] = {'W','D',0};
212 static const WCHAR SDDL_WRITE_OWNER
[] = {'W','O',0};
213 static const WCHAR SDDL_STANDARD_DELETE
[] = {'S','D',0};
214 static const WCHAR SDDL_GENERIC_ALL
[] = {'G','A',0};
215 static const WCHAR SDDL_GENERIC_READ
[] = {'G','R',0};
216 static const WCHAR SDDL_GENERIC_WRITE
[] = {'G','W',0};
217 static const WCHAR SDDL_GENERIC_EXECUTE
[] = {'G','X',0};
222 static const WCHAR SDDL_ACCESS_ALLOWED
[] = {'A',0};
223 static const WCHAR SDDL_ACCESS_DENIED
[] = {'D',0};
224 static const WCHAR SDDL_OBJECT_ACCESS_ALLOWED
[] = {'O','A',0};
225 static const WCHAR SDDL_OBJECT_ACCESS_DENIED
[] = {'O','D',0};
226 static const WCHAR SDDL_AUDIT
[] = {'A','U',0};
227 static const WCHAR SDDL_ALARM
[] = {'A','L',0};
228 static const WCHAR SDDL_OBJECT_AUDIT
[] = {'O','U',0};
229 static const WCHAR SDDL_OBJECT_ALARMp
[] = {'O','L',0};
234 static const WCHAR SDDL_CONTAINER_INHERIT
[] = {'C','I',0};
235 static const WCHAR SDDL_OBJECT_INHERIT
[] = {'O','I',0};
236 static const WCHAR SDDL_NO_PROPAGATE
[] = {'N','P',0};
237 static const WCHAR SDDL_INHERIT_ONLY
[] = {'I','O',0};
238 static const WCHAR SDDL_INHERITED
[] = {'I','D',0};
239 static const WCHAR SDDL_AUDIT_SUCCESS
[] = {'S','A',0};
240 static const WCHAR SDDL_AUDIT_FAILURE
[] = {'F','A',0};
242 static const char * debugstr_sid(PSID sid
)
245 SID
* psid
= (SID
*)sid
;
250 auth
= psid
->IdentifierAuthority
.Value
[5] +
251 (psid
->IdentifierAuthority
.Value
[4] << 8) +
252 (psid
->IdentifierAuthority
.Value
[3] << 16) +
253 (psid
->IdentifierAuthority
.Value
[2] << 24);
255 switch (psid
->SubAuthorityCount
) {
257 return wine_dbg_sprintf("S-%d-%d", psid
->Revision
, auth
);
259 return wine_dbg_sprintf("S-%d-%d-%lu", psid
->Revision
, auth
,
260 psid
->SubAuthority
[0]);
262 return wine_dbg_sprintf("S-%d-%d-%lu-%lu", psid
->Revision
, auth
,
263 psid
->SubAuthority
[0], psid
->SubAuthority
[1]);
265 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu", psid
->Revision
, auth
,
266 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2]);
268 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu-%lu", psid
->Revision
, auth
,
269 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
270 psid
->SubAuthority
[3]);
272 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu-%lu-%lu", psid
->Revision
, auth
,
273 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
274 psid
->SubAuthority
[3], psid
->SubAuthority
[4]);
276 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu-%lu-%lu-%lu", psid
->Revision
, auth
,
277 psid
->SubAuthority
[3], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
278 psid
->SubAuthority
[0], psid
->SubAuthority
[4], psid
->SubAuthority
[5]);
280 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu-%lu-%lu-%lu-%lu", psid
->Revision
, auth
,
281 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
282 psid
->SubAuthority
[3], psid
->SubAuthority
[4], psid
->SubAuthority
[5],
283 psid
->SubAuthority
[6]);
285 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu-%lu-%lu-%lu-%lu-%lu", psid
->Revision
, auth
,
286 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
287 psid
->SubAuthority
[3], psid
->SubAuthority
[4], psid
->SubAuthority
[5],
288 psid
->SubAuthority
[6], psid
->SubAuthority
[7]);
293 /* set last error code from NT status and get the proper boolean return value */
294 /* used for functions that are a simple wrapper around the corresponding ntdll API */
295 static inline BOOL
set_ntstatus( NTSTATUS status
)
297 if (status
) SetLastError( RtlNtStatusToDosError( status
));
301 #define WINE_SIZE_OF_WORLD_ACCESS_ACL (sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD))
303 static void GetWorldAccessACL(PACL pACL
)
305 PACCESS_ALLOWED_ACE pACE
= (PACCESS_ALLOWED_ACE
) (pACL
+ 1);
307 pACL
->AclRevision
= ACL_REVISION
;
309 pACL
->AclSize
= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
313 pACE
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
314 pACE
->Header
.AceFlags
= CONTAINER_INHERIT_ACE
;
315 pACE
->Header
.AceSize
= sizeof(ACCESS_ALLOWED_ACE
) + sizeof(sidWorld
) - sizeof(DWORD
);
316 pACE
->Mask
= 0xf3ffffff; /* Everything except reserved bits */
317 memcpy(&pACE
->SidStart
, &sidWorld
, sizeof(sidWorld
));
320 /************************************************************
321 * ADVAPI_IsLocalComputer
323 * Checks whether the server name indicates local machine.
325 static BOOL
ADVAPI_IsLocalComputer(LPCWSTR ServerName
)
327 DWORD dwSize
= MAX_COMPUTERNAME_LENGTH
+ 1;
331 if (!ServerName
|| !ServerName
[0])
334 buf
= HeapAlloc(GetProcessHeap(), 0, dwSize
* sizeof(WCHAR
));
335 Result
= GetComputerNameW(buf
, &dwSize
);
336 if (Result
&& (ServerName
[0] == '\\') && (ServerName
[1] == '\\'))
338 Result
= Result
&& !lstrcmpW(ServerName
, buf
);
339 HeapFree(GetProcessHeap(), 0, buf
);
344 /* ##############################
345 ###### TOKEN FUNCTIONS ######
346 ##############################
349 /******************************************************************************
350 * OpenProcessToken [ADVAPI32.@]
351 * Opens the access token associated with a process handle.
354 * ProcessHandle [I] Handle to process
355 * DesiredAccess [I] Desired access to process
356 * TokenHandle [O] Pointer to handle of open access token
359 * Success: TRUE. TokenHandle contains the access token.
363 * See NtOpenProcessToken.
366 OpenProcessToken( HANDLE ProcessHandle
, DWORD DesiredAccess
,
367 HANDLE
*TokenHandle
)
369 return set_ntstatus(NtOpenProcessToken( ProcessHandle
, DesiredAccess
, TokenHandle
));
372 /******************************************************************************
373 * OpenThreadToken [ADVAPI32.@]
375 * Opens the access token associated with a thread handle.
378 * ThreadHandle [I] Handle to process
379 * DesiredAccess [I] Desired access to the thread
381 * TokenHandle [O] Destination for the token handle
384 * Success: TRUE. TokenHandle contains the access token.
388 * See NtOpenThreadToken.
391 OpenThreadToken( HANDLE ThreadHandle
, DWORD DesiredAccess
,
392 BOOL OpenAsSelf
, HANDLE
*TokenHandle
)
394 return set_ntstatus( NtOpenThreadToken(ThreadHandle
, DesiredAccess
, OpenAsSelf
, TokenHandle
));
398 AdjustTokenGroups( HANDLE TokenHandle
, BOOL ResetToDefault
, PTOKEN_GROUPS NewState
,
399 DWORD BufferLength
, PTOKEN_GROUPS PreviousState
, PDWORD ReturnLength
)
401 return set_ntstatus( NtAdjustGroupsToken(TokenHandle
, ResetToDefault
, NewState
, BufferLength
,
402 PreviousState
, ReturnLength
));
405 /******************************************************************************
406 * AdjustTokenPrivileges [ADVAPI32.@]
408 * Adjust the privileges of an open token handle.
411 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
412 * DisableAllPrivileges [I] TRUE=Remove all privileges, FALSE=Use NewState
413 * NewState [I] Desired new privileges of the token
414 * BufferLength [I] Length of NewState
415 * PreviousState [O] Destination for the previous state
416 * ReturnLength [I/O] Size of PreviousState
420 * Success: TRUE. Privileges are set to NewState and PreviousState is updated.
424 * See NtAdjustPrivilegesToken.
427 AdjustTokenPrivileges( HANDLE TokenHandle
, BOOL DisableAllPrivileges
,
428 LPVOID NewState
, DWORD BufferLength
,
429 LPVOID PreviousState
, LPDWORD ReturnLength
)
435 status
= NtAdjustPrivilegesToken(TokenHandle
, DisableAllPrivileges
,
436 NewState
, BufferLength
, PreviousState
,
438 SetLastError( RtlNtStatusToDosError( status
));
439 if ((status
== STATUS_SUCCESS
) || (status
== STATUS_NOT_ALL_ASSIGNED
))
445 /******************************************************************************
446 * CheckTokenMembership [ADVAPI32.@]
448 * Determine if an access token is a member of a SID.
451 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
452 * SidToCheck [I] SID that possibly contains the token
453 * IsMember [O] Destination for result.
456 * Success: TRUE. IsMember is TRUE if TokenHandle is a member, FALSE otherwise.
460 CheckTokenMembership( HANDLE TokenHandle
, PSID SidToCheck
,
463 FIXME("(%p %p %p) stub!\n", TokenHandle
, SidToCheck
, IsMember
);
469 /******************************************************************************
470 * GetTokenInformation [ADVAPI32.@]
472 * Get a type of information about an access token.
475 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
476 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
477 * tokeninfo [O] Destination for token information
478 * tokeninfolength [I] Length of tokeninfo
479 * retlen [O] Destination for returned token information length
482 * Success: TRUE. tokeninfo contains retlen bytes of token information
486 * See NtQueryInformationToken.
489 GetTokenInformation( HANDLE token
, TOKEN_INFORMATION_CLASS tokeninfoclass
,
490 LPVOID tokeninfo
, DWORD tokeninfolength
, LPDWORD retlen
)
492 TRACE("(%p, %s, %p, %ld, %p):\n",
494 (tokeninfoclass
== TokenUser
) ? "TokenUser" :
495 (tokeninfoclass
== TokenGroups
) ? "TokenGroups" :
496 (tokeninfoclass
== TokenPrivileges
) ? "TokenPrivileges" :
497 (tokeninfoclass
== TokenOwner
) ? "TokenOwner" :
498 (tokeninfoclass
== TokenPrimaryGroup
) ? "TokenPrimaryGroup" :
499 (tokeninfoclass
== TokenDefaultDacl
) ? "TokenDefaultDacl" :
500 (tokeninfoclass
== TokenSource
) ? "TokenSource" :
501 (tokeninfoclass
== TokenType
) ? "TokenType" :
502 (tokeninfoclass
== TokenImpersonationLevel
) ? "TokenImpersonationLevel" :
503 (tokeninfoclass
== TokenStatistics
) ? "TokenStatistics" :
504 (tokeninfoclass
== TokenRestrictedSids
) ? "TokenRestrictedSids" :
505 (tokeninfoclass
== TokenSessionId
) ? "TokenSessionId" :
506 (tokeninfoclass
== TokenGroupsAndPrivileges
) ? "TokenGroupsAndPrivileges" :
507 (tokeninfoclass
== TokenSessionReference
) ? "TokenSessionReference" :
508 (tokeninfoclass
== TokenSandBoxInert
) ? "TokenSandBoxInert" :
510 tokeninfo
, tokeninfolength
, retlen
);
511 return set_ntstatus( NtQueryInformationToken( token
, tokeninfoclass
, tokeninfo
,
512 tokeninfolength
, retlen
));
515 /******************************************************************************
516 * SetTokenInformation [ADVAPI32.@]
518 * Set information for an access token.
521 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
522 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
523 * tokeninfo [I] Token information to set
524 * tokeninfolength [I] Length of tokeninfo
527 * Success: TRUE. The information for the token is set to tokeninfo.
531 SetTokenInformation( HANDLE token
, TOKEN_INFORMATION_CLASS tokeninfoclass
,
532 LPVOID tokeninfo
, DWORD tokeninfolength
)
534 TRACE("(%p, %s, %p, %ld): stub\n",
536 (tokeninfoclass
== TokenUser
) ? "TokenUser" :
537 (tokeninfoclass
== TokenGroups
) ? "TokenGroups" :
538 (tokeninfoclass
== TokenPrivileges
) ? "TokenPrivileges" :
539 (tokeninfoclass
== TokenOwner
) ? "TokenOwner" :
540 (tokeninfoclass
== TokenPrimaryGroup
) ? "TokenPrimaryGroup" :
541 (tokeninfoclass
== TokenDefaultDacl
) ? "TokenDefaultDacl" :
542 (tokeninfoclass
== TokenSource
) ? "TokenSource" :
543 (tokeninfoclass
== TokenType
) ? "TokenType" :
544 (tokeninfoclass
== TokenImpersonationLevel
) ? "TokenImpersonationLevel" :
545 (tokeninfoclass
== TokenStatistics
) ? "TokenStatistics" :
546 (tokeninfoclass
== TokenRestrictedSids
) ? "TokenRestrictedSids" :
547 (tokeninfoclass
== TokenSessionId
) ? "TokenSessionId" :
548 (tokeninfoclass
== TokenGroupsAndPrivileges
) ? "TokenGroupsAndPrivileges" :
549 (tokeninfoclass
== TokenSessionReference
) ? "TokenSessionReference" :
550 (tokeninfoclass
== TokenSandBoxInert
) ? "TokenSandBoxInert" :
552 tokeninfo
, tokeninfolength
);
554 return set_ntstatus( NtSetInformationToken( token
, tokeninfoclass
, tokeninfo
, tokeninfolength
));
557 /*************************************************************************
558 * SetThreadToken [ADVAPI32.@]
560 * Assigns an 'impersonation token' to a thread so it can assume the
561 * security privileges of another thread or process. Can also remove
562 * a previously assigned token.
565 * thread [O] Handle to thread to set the token for
566 * token [I] Token to set
569 * Success: TRUE. The threads access token is set to token
573 * Only supported on NT or higher. On Win9X this function does nothing.
574 * See SetTokenInformation.
576 BOOL WINAPI
SetThreadToken(PHANDLE thread
, HANDLE token
)
578 return set_ntstatus( NtSetInformationThread( thread
? *thread
: GetCurrentThread(),
579 ThreadImpersonationToken
, &token
, sizeof token
));
582 /* ##############################
583 ###### SID FUNCTIONS ######
584 ##############################
587 /******************************************************************************
588 * AllocateAndInitializeSid [ADVAPI32.@]
591 * pIdentifierAuthority []
592 * nSubAuthorityCount []
604 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
605 BYTE nSubAuthorityCount
,
606 DWORD nSubAuthority0
, DWORD nSubAuthority1
,
607 DWORD nSubAuthority2
, DWORD nSubAuthority3
,
608 DWORD nSubAuthority4
, DWORD nSubAuthority5
,
609 DWORD nSubAuthority6
, DWORD nSubAuthority7
,
612 return set_ntstatus( RtlAllocateAndInitializeSid(
613 pIdentifierAuthority
, nSubAuthorityCount
,
614 nSubAuthority0
, nSubAuthority1
, nSubAuthority2
, nSubAuthority3
,
615 nSubAuthority4
, nSubAuthority5
, nSubAuthority6
, nSubAuthority7
,
619 /******************************************************************************
620 * FreeSid [ADVAPI32.@]
629 return NULL
; /* is documented like this */
632 /******************************************************************************
633 * CopySid [ADVAPI32.@]
636 * nDestinationSidLength []
641 CopySid( DWORD nDestinationSidLength
, PSID pDestinationSid
, PSID pSourceSid
)
643 return RtlCopySid(nDestinationSidLength
, pDestinationSid
, pSourceSid
);
646 /******************************************************************************
647 * CreateWellKnownSid [ADVAPI32.@]
650 CreateWellKnownSid( WELL_KNOWN_SID_TYPE WellKnownSidType
,
656 TRACE("(%d, %s, %p, %p)\n", WellKnownSidType
, debugstr_sid(DomainSid
), pSid
, cbSid
);
658 if (DomainSid
!= NULL
) {
659 FIXME("Only local computer supported!\n");
660 SetLastError(ERROR_INVALID_PARAMETER
); /* FIXME */
664 if (cbSid
== NULL
|| pSid
== NULL
) {
665 SetLastError(ERROR_INVALID_PARAMETER
);
669 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++) {
670 if (WellKnownSids
[i
].Type
== WellKnownSidType
) {
671 DWORD length
= GetSidLengthRequired(WellKnownSids
[i
].Sid
.SubAuthorityCount
);
673 if (*cbSid
< length
) {
674 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
678 CopyMemory(pSid
, &WellKnownSids
[i
].Sid
.Revision
, length
);
684 SetLastError(ERROR_INVALID_PARAMETER
);
688 /******************************************************************************
689 * IsWellKnownSid [ADVAPI32.@]
692 IsWellKnownSid( PSID pSid
, WELL_KNOWN_SID_TYPE WellKnownSidType
)
695 TRACE("(%s, %d)\n", debugstr_sid(pSid
), WellKnownSidType
);
697 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
698 if (WellKnownSids
[i
].Type
== WellKnownSidType
)
699 if (EqualSid(pSid
, (PSID
)&(WellKnownSids
[i
].Sid
.Revision
)))
706 IsTokenRestricted( HANDLE TokenHandle
)
708 TOKEN_GROUPS
*groups
;
713 TRACE("(%p)\n", TokenHandle
);
715 status
= NtQueryInformationToken(TokenHandle
, TokenRestrictedSids
, NULL
, 0, &size
);
716 if (status
!= STATUS_BUFFER_TOO_SMALL
)
719 groups
= HeapAlloc(GetProcessHeap(), 0, size
);
722 SetLastError(ERROR_OUTOFMEMORY
);
726 status
= NtQueryInformationToken(TokenHandle
, TokenRestrictedSids
, groups
, size
, &size
);
727 if (status
!= STATUS_SUCCESS
)
729 HeapFree(GetProcessHeap(), 0, groups
);
730 return set_ntstatus(status
);
733 if (groups
->GroupCount
)
738 HeapFree(GetProcessHeap(), 0, groups
);
743 /******************************************************************************
744 * IsValidSid [ADVAPI32.@]
750 IsValidSid( PSID pSid
)
752 return RtlValidSid( pSid
);
755 /******************************************************************************
756 * EqualSid [ADVAPI32.@]
763 EqualSid( PSID pSid1
, PSID pSid2
)
765 return RtlEqualSid( pSid1
, pSid2
);
768 /******************************************************************************
769 * EqualPrefixSid [ADVAPI32.@]
771 BOOL WINAPI
EqualPrefixSid (PSID pSid1
, PSID pSid2
)
773 return RtlEqualPrefixSid(pSid1
, pSid2
);
776 /******************************************************************************
777 * GetSidLengthRequired [ADVAPI32.@]
780 * nSubAuthorityCount []
783 GetSidLengthRequired( BYTE nSubAuthorityCount
)
785 return RtlLengthRequiredSid(nSubAuthorityCount
);
788 /******************************************************************************
789 * InitializeSid [ADVAPI32.@]
792 * pIdentifierAuthority []
797 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
798 BYTE nSubAuthorityCount
)
800 return RtlInitializeSid(pSid
, pIdentifierAuthority
, nSubAuthorityCount
);
804 GetEffectiveRightsFromAclA( PACL pacl
, PTRUSTEEA pTrustee
, PACCESS_MASK pAccessRights
)
806 FIXME("%p %p %p - stub\n", pacl
, pTrustee
, pAccessRights
);
812 GetEffectiveRightsFromAclW( PACL pacl
, PTRUSTEEW pTrustee
, PACCESS_MASK pAccessRights
)
814 FIXME("%p %p %p - stub\n", pacl
, pTrustee
, pAccessRights
);
819 /******************************************************************************
820 * GetSidIdentifierAuthority [ADVAPI32.@]
825 PSID_IDENTIFIER_AUTHORITY WINAPI
826 GetSidIdentifierAuthority( PSID pSid
)
828 return RtlIdentifierAuthoritySid(pSid
);
831 /******************************************************************************
832 * GetSidSubAuthority [ADVAPI32.@]
839 GetSidSubAuthority( PSID pSid
, DWORD nSubAuthority
)
841 return RtlSubAuthoritySid(pSid
, nSubAuthority
);
844 /******************************************************************************
845 * GetSidSubAuthorityCount [ADVAPI32.@]
851 GetSidSubAuthorityCount (PSID pSid
)
853 return RtlSubAuthorityCountSid(pSid
);
856 /******************************************************************************
857 * GetLengthSid [ADVAPI32.@]
863 GetLengthSid (PSID pSid
)
865 return RtlLengthSid(pSid
);
868 /* ##############################################
869 ###### SECURITY DESCRIPTOR FUNCTIONS ######
870 ##############################################
873 /******************************************************************************
874 * BuildSecurityDescriptorA [ADVAPI32.@]
881 * cCountOfAccessEntries [I]
882 * pListOfAccessEntries [I]
883 * cCountOfAuditEntries [I]
884 * pListofAuditEntries [I]
886 * lpdwBufferLength [I/O]
890 * Success: ERROR_SUCCESS
891 * Failure: nonzero error code from Winerror.h
893 DWORD WINAPI
BuildSecurityDescriptorA(
896 IN ULONG cCountOfAccessEntries
,
897 IN PEXPLICIT_ACCESSA pListOfAccessEntries
,
898 IN ULONG cCountOfAuditEntries
,
899 IN PEXPLICIT_ACCESSA pListofAuditEntries
,
900 IN PSECURITY_DESCRIPTOR pOldSD
,
901 IN OUT PULONG lpdwBufferLength
,
902 OUT PSECURITY_DESCRIPTOR
* pNewSD
)
904 FIXME("(%p,%p,%ld,%p,%ld,%p,%p,%p,%p) stub!\n",pOwner
,pGroup
,
905 cCountOfAccessEntries
,pListOfAccessEntries
,cCountOfAuditEntries
,
906 pListofAuditEntries
,pOldSD
,lpdwBufferLength
,pNewSD
);
908 return ERROR_CALL_NOT_IMPLEMENTED
;
911 /******************************************************************************
912 * BuildSecurityDescriptorW [ADVAPI32.@]
914 * See BuildSecurityDescriptorA.
916 DWORD WINAPI
BuildSecurityDescriptorW(
919 IN ULONG cCountOfAccessEntries
,
920 IN PEXPLICIT_ACCESSW pListOfAccessEntries
,
921 IN ULONG cCountOfAuditEntries
,
922 IN PEXPLICIT_ACCESSW pListofAuditEntries
,
923 IN PSECURITY_DESCRIPTOR pOldSD
,
924 IN OUT PULONG lpdwBufferLength
,
925 OUT PSECURITY_DESCRIPTOR
* pNewSD
)
927 FIXME("(%p,%p,%ld,%p,%ld,%p,%p,%p,%p) stub!\n",pOwner
,pGroup
,
928 cCountOfAccessEntries
,pListOfAccessEntries
,cCountOfAuditEntries
,
929 pListofAuditEntries
,pOldSD
,lpdwBufferLength
,pNewSD
);
931 return ERROR_CALL_NOT_IMPLEMENTED
;
934 /******************************************************************************
935 * InitializeSecurityDescriptor [ADVAPI32.@]
942 InitializeSecurityDescriptor( PSECURITY_DESCRIPTOR pDescr
, DWORD revision
)
944 return set_ntstatus( RtlCreateSecurityDescriptor(pDescr
, revision
));
948 /******************************************************************************
949 * MakeAbsoluteSD [ADVAPI32.@]
951 BOOL WINAPI
MakeAbsoluteSD (
952 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor
,
953 OUT PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor
,
954 OUT LPDWORD lpdwAbsoluteSecurityDescriptorSize
,
956 OUT LPDWORD lpdwDaclSize
,
958 OUT LPDWORD lpdwSaclSize
,
960 OUT LPDWORD lpdwOwnerSize
,
961 OUT PSID pPrimaryGroup
,
962 OUT LPDWORD lpdwPrimaryGroupSize
)
964 return set_ntstatus( RtlSelfRelativeToAbsoluteSD(pSelfRelativeSecurityDescriptor
,
965 pAbsoluteSecurityDescriptor
,
966 lpdwAbsoluteSecurityDescriptorSize
,
967 pDacl
, lpdwDaclSize
, pSacl
, lpdwSaclSize
,
968 pOwner
, lpdwOwnerSize
,
969 pPrimaryGroup
, lpdwPrimaryGroupSize
));
972 /******************************************************************************
973 * GetKernelObjectSecurity [ADVAPI32.@]
975 BOOL WINAPI
GetKernelObjectSecurity(
977 SECURITY_INFORMATION RequestedInformation
,
978 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
980 LPDWORD lpnLengthNeeded
)
982 TRACE("(%p,0x%08lx,%p,0x%08lx,%p)\n", Handle
, RequestedInformation
,
983 pSecurityDescriptor
, nLength
, lpnLengthNeeded
);
985 return set_ntstatus( NtQuerySecurityObject(Handle
, RequestedInformation
, pSecurityDescriptor
,
986 nLength
, lpnLengthNeeded
));
989 /******************************************************************************
990 * GetPrivateObjectSecurity [ADVAPI32.@]
992 BOOL WINAPI
GetPrivateObjectSecurity(
993 PSECURITY_DESCRIPTOR ObjectDescriptor
,
994 SECURITY_INFORMATION SecurityInformation
,
995 PSECURITY_DESCRIPTOR ResultantDescriptor
,
996 DWORD DescriptorLength
,
997 PDWORD ReturnLength
)
999 TRACE("(%p,0x%08lx,%p,0x%08lx,%p)\n", ObjectDescriptor
, SecurityInformation
,
1000 ResultantDescriptor
, DescriptorLength
, ReturnLength
);
1002 return set_ntstatus( NtQuerySecurityObject(ObjectDescriptor
, SecurityInformation
,
1003 ResultantDescriptor
, DescriptorLength
, ReturnLength
));
1006 /******************************************************************************
1007 * GetSecurityDescriptorLength [ADVAPI32.@]
1009 DWORD WINAPI
GetSecurityDescriptorLength( PSECURITY_DESCRIPTOR pDescr
)
1011 return RtlLengthSecurityDescriptor(pDescr
);
1014 /******************************************************************************
1015 * GetSecurityDescriptorOwner [ADVAPI32.@]
1019 * lpbOwnerDefaulted []
1022 GetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pDescr
, PSID
*pOwner
,
1023 LPBOOL lpbOwnerDefaulted
)
1026 BOOL ret
= set_ntstatus( RtlGetOwnerSecurityDescriptor( pDescr
, pOwner
, &defaulted
));
1027 *lpbOwnerDefaulted
= defaulted
;
1031 /******************************************************************************
1032 * SetSecurityDescriptorOwner [ADVAPI32.@]
1036 BOOL WINAPI
SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1037 PSID pOwner
, BOOL bOwnerDefaulted
)
1039 return set_ntstatus( RtlSetOwnerSecurityDescriptor(pSecurityDescriptor
, pOwner
, bOwnerDefaulted
));
1041 /******************************************************************************
1042 * GetSecurityDescriptorGroup [ADVAPI32.@]
1044 BOOL WINAPI
GetSecurityDescriptorGroup(
1045 PSECURITY_DESCRIPTOR SecurityDescriptor
,
1047 LPBOOL GroupDefaulted
)
1050 BOOL ret
= set_ntstatus( RtlGetGroupSecurityDescriptor(SecurityDescriptor
, Group
, &defaulted
));
1051 *GroupDefaulted
= defaulted
;
1054 /******************************************************************************
1055 * SetSecurityDescriptorGroup [ADVAPI32.@]
1057 BOOL WINAPI
SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor
,
1058 PSID Group
, BOOL GroupDefaulted
)
1060 return set_ntstatus( RtlSetGroupSecurityDescriptor( SecurityDescriptor
, Group
, GroupDefaulted
));
1063 /******************************************************************************
1064 * IsValidSecurityDescriptor [ADVAPI32.@]
1070 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor
)
1072 return set_ntstatus( RtlValidSecurityDescriptor(SecurityDescriptor
));
1075 /******************************************************************************
1076 * GetSecurityDescriptorDacl [ADVAPI32.@]
1078 BOOL WINAPI
GetSecurityDescriptorDacl(
1079 IN PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1080 OUT LPBOOL lpbDaclPresent
,
1082 OUT LPBOOL lpbDaclDefaulted
)
1084 BOOLEAN present
, defaulted
;
1085 BOOL ret
= set_ntstatus( RtlGetDaclSecurityDescriptor(pSecurityDescriptor
, &present
, pDacl
, &defaulted
));
1086 *lpbDaclPresent
= present
;
1087 *lpbDaclDefaulted
= defaulted
;
1091 /******************************************************************************
1092 * SetSecurityDescriptorDacl [ADVAPI32.@]
1095 SetSecurityDescriptorDacl (
1096 PSECURITY_DESCRIPTOR lpsd
,
1099 BOOL dacldefaulted
)
1101 return set_ntstatus( RtlSetDaclSecurityDescriptor (lpsd
, daclpresent
, dacl
, dacldefaulted
) );
1103 /******************************************************************************
1104 * GetSecurityDescriptorSacl [ADVAPI32.@]
1106 BOOL WINAPI
GetSecurityDescriptorSacl(
1107 IN PSECURITY_DESCRIPTOR lpsd
,
1108 OUT LPBOOL lpbSaclPresent
,
1110 OUT LPBOOL lpbSaclDefaulted
)
1112 BOOLEAN present
, defaulted
;
1113 BOOL ret
= set_ntstatus( RtlGetSaclSecurityDescriptor(lpsd
, &present
, pSacl
, &defaulted
) );
1114 *lpbSaclPresent
= present
;
1115 *lpbSaclDefaulted
= defaulted
;
1119 /**************************************************************************
1120 * SetSecurityDescriptorSacl [ADVAPI32.@]
1122 BOOL WINAPI
SetSecurityDescriptorSacl (
1123 PSECURITY_DESCRIPTOR lpsd
,
1128 return set_ntstatus (RtlSetSaclSecurityDescriptor(lpsd
, saclpresent
, lpsacl
, sacldefaulted
));
1130 /******************************************************************************
1131 * MakeSelfRelativeSD [ADVAPI32.@]
1140 IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor
,
1141 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor
,
1142 IN OUT LPDWORD lpdwBufferLength
)
1144 return set_ntstatus( RtlMakeSelfRelativeSD( pAbsoluteSecurityDescriptor
,
1145 pSelfRelativeSecurityDescriptor
, lpdwBufferLength
));
1148 /******************************************************************************
1149 * GetSecurityDescriptorControl [ADVAPI32.@]
1152 BOOL WINAPI
GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1153 PSECURITY_DESCRIPTOR_CONTROL pControl
, LPDWORD lpdwRevision
)
1155 return set_ntstatus( RtlGetControlSecurityDescriptor(pSecurityDescriptor
,pControl
,lpdwRevision
));
1158 /* ##############################
1159 ###### ACL FUNCTIONS ######
1160 ##############################
1163 /*************************************************************************
1164 * InitializeAcl [ADVAPI32.@]
1166 BOOL WINAPI
InitializeAcl(PACL acl
, DWORD size
, DWORD rev
)
1168 return set_ntstatus( RtlCreateAcl(acl
, size
, rev
));
1171 BOOL WINAPI
ImpersonateNamedPipeClient( HANDLE hNamedPipe
)
1173 TRACE("(%p)\n", hNamedPipe
);
1175 return set_ntstatus( NtFsControlFile(hNamedPipe
, NULL
, NULL
, NULL
, NULL
,
1176 FSCTL_PIPE_IMPERSONATE
, NULL
, 0, NULL
, 0) );
1179 /******************************************************************************
1180 * AddAccessAllowedAce [ADVAPI32.@]
1182 BOOL WINAPI
AddAccessAllowedAce(
1184 IN DWORD dwAceRevision
,
1185 IN DWORD AccessMask
,
1188 return set_ntstatus(RtlAddAccessAllowedAce(pAcl
, dwAceRevision
, AccessMask
, pSid
));
1191 /******************************************************************************
1192 * AddAccessAllowedAceEx [ADVAPI32.@]
1194 BOOL WINAPI
AddAccessAllowedAceEx(
1196 IN DWORD dwAceRevision
,
1198 IN DWORD AccessMask
,
1201 return set_ntstatus(RtlAddAccessAllowedAceEx(pAcl
, dwAceRevision
, AceFlags
, AccessMask
, pSid
));
1204 /******************************************************************************
1205 * AddAccessDeniedAce [ADVAPI32.@]
1207 BOOL WINAPI
AddAccessDeniedAce(
1209 IN DWORD dwAceRevision
,
1210 IN DWORD AccessMask
,
1213 return set_ntstatus(RtlAddAccessDeniedAce(pAcl
, dwAceRevision
, AccessMask
, pSid
));
1216 /******************************************************************************
1217 * AddAccessDeniedAceEx [ADVAPI32.@]
1219 BOOL WINAPI
AddAccessDeniedAceEx(
1221 IN DWORD dwAceRevision
,
1223 IN DWORD AccessMask
,
1226 return set_ntstatus(RtlAddAccessDeniedAceEx(pAcl
, dwAceRevision
, AceFlags
, AccessMask
, pSid
));
1229 /******************************************************************************
1230 * AddAce [ADVAPI32.@]
1234 IN DWORD dwAceRevision
,
1235 IN DWORD dwStartingAceIndex
,
1237 DWORD nAceListLength
)
1239 return set_ntstatus(RtlAddAce(pAcl
, dwAceRevision
, dwStartingAceIndex
, pAceList
, nAceListLength
));
1242 /******************************************************************************
1243 * DeleteAce [ADVAPI32.@]
1245 BOOL WINAPI
DeleteAce(PACL pAcl
, DWORD dwAceIndex
)
1247 return set_ntstatus(RtlDeleteAce(pAcl
, dwAceIndex
));
1250 /******************************************************************************
1251 * FindFirstFreeAce [ADVAPI32.@]
1253 BOOL WINAPI
FindFirstFreeAce(IN PACL pAcl
, LPVOID
* pAce
)
1255 return RtlFirstFreeAce(pAcl
, (PACE_HEADER
*)pAce
);
1258 /******************************************************************************
1259 * GetAce [ADVAPI32.@]
1261 BOOL WINAPI
GetAce(PACL pAcl
,DWORD dwAceIndex
,LPVOID
*pAce
)
1263 return set_ntstatus(RtlGetAce(pAcl
, dwAceIndex
, pAce
));
1266 /******************************************************************************
1267 * GetAclInformation [ADVAPI32.@]
1269 BOOL WINAPI
GetAclInformation(
1271 LPVOID pAclInformation
,
1272 DWORD nAclInformationLength
,
1273 ACL_INFORMATION_CLASS dwAclInformationClass
)
1275 return set_ntstatus(RtlQueryInformationAcl(pAcl
, pAclInformation
,
1276 nAclInformationLength
, dwAclInformationClass
));
1279 /******************************************************************************
1280 * IsValidAcl [ADVAPI32.@]
1282 BOOL WINAPI
IsValidAcl(IN PACL pAcl
)
1284 return RtlValidAcl(pAcl
);
1287 /* ##############################
1288 ###### MISC FUNCTIONS ######
1289 ##############################
1292 /******************************************************************************
1293 * AllocateLocallyUniqueId [ADVAPI32.@]
1298 BOOL WINAPI
AllocateLocallyUniqueId( PLUID lpLuid
)
1300 return set_ntstatus(NtAllocateLocallyUniqueId(lpLuid
));
1303 static const WCHAR SE_CREATE_TOKEN_NAME_W
[] =
1304 { 'S','e','C','r','e','a','t','e','T','o','k','e','n','P','r','i','v','i','l','e','g','e',0 };
1305 static const WCHAR SE_ASSIGNPRIMARYTOKEN_NAME_W
[] =
1306 { '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 };
1307 static const WCHAR SE_LOCK_MEMORY_NAME_W
[] =
1308 { 'S','e','L','o','c','k','M','e','m','o','r','y','P','r','i','v','i','l','e','g','e',0 };
1309 static const WCHAR SE_INCREASE_QUOTA_NAME_W
[] =
1310 { '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 };
1311 static const WCHAR SE_MACHINE_ACCOUNT_NAME_W
[] =
1312 { '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 };
1313 static const WCHAR SE_TCB_NAME_W
[] =
1314 { 'S','e','T','c','b','P','r','i','v','i','l','e','g','e',0 };
1315 static const WCHAR SE_SECURITY_NAME_W
[] =
1316 { 'S','e','S','e','c','u','r','i','t','y','P','r','i','v','i','l','e','g','e',0 };
1317 static const WCHAR SE_TAKE_OWNERSHIP_NAME_W
[] =
1318 { '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 };
1319 static const WCHAR SE_LOAD_DRIVER_NAME_W
[] =
1320 { 'S','e','L','o','a','d','D','r','i','v','e','r','P','r','i','v','i','l','e','g','e',0 };
1321 static const WCHAR SE_SYSTEM_PROFILE_NAME_W
[] =
1322 { '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 };
1323 static const WCHAR SE_SYSTEMTIME_NAME_W
[] =
1324 { 'S','e','S','y','s','t','e','m','t','i','m','e','P','r','i','v','i','l','e','g','e',0 };
1325 static const WCHAR SE_PROF_SINGLE_PROCESS_NAME_W
[] =
1326 { '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 };
1327 static const WCHAR SE_INC_BASE_PRIORITY_NAME_W
[] =
1328 { '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 };
1329 static const WCHAR SE_CREATE_PAGEFILE_NAME_W
[] =
1330 { '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 };
1331 static const WCHAR SE_CREATE_PERMANENT_NAME_W
[] =
1332 { '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 };
1333 static const WCHAR SE_BACKUP_NAME_W
[] =
1334 { 'S','e','B','a','c','k','u','p','P','r','i','v','i','l','e','g','e',0 };
1335 static const WCHAR SE_RESTORE_NAME_W
[] =
1336 { 'S','e','R','e','s','t','o','r','e','P','r','i','v','i','l','e','g','e',0 };
1337 static const WCHAR SE_SHUTDOWN_NAME_W
[] =
1338 { 'S','e','S','h','u','t','d','o','w','n','P','r','i','v','i','l','e','g','e',0 };
1339 static const WCHAR SE_DEBUG_NAME_W
[] =
1340 { 'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0 };
1341 static const WCHAR SE_AUDIT_NAME_W
[] =
1342 { 'S','e','A','u','d','i','t','P','r','i','v','i','l','e','g','e',0 };
1343 static const WCHAR SE_SYSTEM_ENVIRONMENT_NAME_W
[] =
1344 { '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 };
1345 static const WCHAR SE_CHANGE_NOTIFY_NAME_W
[] =
1346 { 'S','e','C','h','a','n','g','e','N','o','t','i','f','y','P','r','i','v','i','l','e','g','e',0 };
1347 static const WCHAR SE_REMOTE_SHUTDOWN_NAME_W
[] =
1348 { '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 };
1349 static const WCHAR SE_UNDOCK_NAME_W
[] =
1350 { 'S','e','U','n','d','o','c','k','P','r','i','v','i','l','e','g','e',0 };
1351 static const WCHAR SE_SYNC_AGENT_NAME_W
[] =
1352 { 'S','e','S','y','n','c','A','g','e','n','t','P','r','i','v','i','l','e','g','e',0 };
1353 static const WCHAR SE_ENABLE_DELEGATION_NAME_W
[] =
1354 { '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 };
1355 static const WCHAR SE_MANAGE_VOLUME_NAME_W
[] =
1356 { 'S','e','M','a','n','a','g','e','V','o','l','u','m','e','P','r','i','v','i','l','e','g','e',0 };
1357 static const WCHAR SE_IMPERSONATE_NAME_W
[] =
1358 { 'S','e','I','m','p','e','r','s','o','n','a','t','e','P','r','i','v','i','l','e','g','e',0 };
1359 static const WCHAR SE_CREATE_GLOBAL_NAME_W
[] =
1360 { 'S','e','C','r','e','a','t','e','G','l','o','b','a','l','P','r','i','v','i','l','e','g','e',0 };
1362 static const WCHAR
* const WellKnownPrivNames
[SE_MAX_WELL_KNOWN_PRIVILEGE
+ 1] =
1366 SE_CREATE_TOKEN_NAME_W
,
1367 SE_ASSIGNPRIMARYTOKEN_NAME_W
,
1368 SE_LOCK_MEMORY_NAME_W
,
1369 SE_INCREASE_QUOTA_NAME_W
,
1370 SE_MACHINE_ACCOUNT_NAME_W
,
1373 SE_TAKE_OWNERSHIP_NAME_W
,
1374 SE_LOAD_DRIVER_NAME_W
,
1375 SE_SYSTEM_PROFILE_NAME_W
,
1376 SE_SYSTEMTIME_NAME_W
,
1377 SE_PROF_SINGLE_PROCESS_NAME_W
,
1378 SE_INC_BASE_PRIORITY_NAME_W
,
1379 SE_CREATE_PAGEFILE_NAME_W
,
1380 SE_CREATE_PERMANENT_NAME_W
,
1386 SE_SYSTEM_ENVIRONMENT_NAME_W
,
1387 SE_CHANGE_NOTIFY_NAME_W
,
1388 SE_REMOTE_SHUTDOWN_NAME_W
,
1390 SE_SYNC_AGENT_NAME_W
,
1391 SE_ENABLE_DELEGATION_NAME_W
,
1392 SE_MANAGE_VOLUME_NAME_W
,
1393 SE_IMPERSONATE_NAME_W
,
1394 SE_CREATE_GLOBAL_NAME_W
,
1397 /******************************************************************************
1398 * LookupPrivilegeValueW [ADVAPI32.@]
1400 * See LookupPrivilegeValueA.
1403 LookupPrivilegeValueW( LPCWSTR lpSystemName
, LPCWSTR lpName
, PLUID lpLuid
)
1407 TRACE("%s,%s,%p\n",debugstr_w(lpSystemName
), debugstr_w(lpName
), lpLuid
);
1409 if (!ADVAPI_IsLocalComputer(lpSystemName
))
1411 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
1416 SetLastError(ERROR_NO_SUCH_PRIVILEGE
);
1419 for( i
=SE_MIN_WELL_KNOWN_PRIVILEGE
; i
<SE_MAX_WELL_KNOWN_PRIVILEGE
; i
++ )
1421 if( !WellKnownPrivNames
[i
] )
1423 if( strcmpiW( WellKnownPrivNames
[i
], lpName
) )
1425 lpLuid
->LowPart
= i
;
1426 lpLuid
->HighPart
= 0;
1427 TRACE( "%s -> %08lx-%08lx\n",debugstr_w( lpSystemName
),
1428 lpLuid
->HighPart
, lpLuid
->LowPart
);
1431 SetLastError(ERROR_NO_SUCH_PRIVILEGE
);
1435 /******************************************************************************
1436 * LookupPrivilegeValueA [ADVAPI32.@]
1438 * Retrieves LUID used on a system to represent the privilege name.
1441 * lpSystemName [I] Name of the system
1442 * lpName [I] Name of the privilege
1443 * lpLuid [O] Destination for the resulting LUID
1446 * Success: TRUE. lpLuid contains the requested LUID.
1450 LookupPrivilegeValueA( LPCSTR lpSystemName
, LPCSTR lpName
, PLUID lpLuid
)
1452 UNICODE_STRING lpSystemNameW
;
1453 UNICODE_STRING lpNameW
;
1456 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW
, lpSystemName
);
1457 RtlCreateUnicodeStringFromAsciiz(&lpNameW
,lpName
);
1458 ret
= LookupPrivilegeValueW(lpSystemNameW
.Buffer
, lpNameW
.Buffer
, lpLuid
);
1459 RtlFreeUnicodeString(&lpNameW
);
1460 RtlFreeUnicodeString(&lpSystemNameW
);
1464 BOOL WINAPI
LookupPrivilegeDisplayNameA( LPCSTR lpSystemName
, LPCSTR lpName
, LPSTR lpDisplayName
,
1465 LPDWORD cchDisplayName
, LPDWORD lpLanguageId
)
1467 FIXME("%s %s %s %p %p - stub\n", debugstr_a(lpSystemName
), debugstr_a(lpName
),
1468 debugstr_a(lpDisplayName
), cchDisplayName
, lpLanguageId
);
1473 BOOL WINAPI
LookupPrivilegeDisplayNameW( LPCWSTR lpSystemName
, LPCWSTR lpName
, LPWSTR lpDisplayName
,
1474 LPDWORD cchDisplayName
, LPDWORD lpLanguageId
)
1476 FIXME("%s %s %s %p %p - stub\n", debugstr_w(lpSystemName
), debugstr_w(lpName
),
1477 debugstr_w(lpDisplayName
), cchDisplayName
, lpLanguageId
);
1482 /******************************************************************************
1483 * LookupPrivilegeNameA [ADVAPI32.@]
1485 * See LookupPrivilegeNameW.
1488 LookupPrivilegeNameA( LPCSTR lpSystemName
, PLUID lpLuid
, LPSTR lpName
,
1491 UNICODE_STRING lpSystemNameW
;
1495 TRACE("%s %p %p %p\n", debugstr_a(lpSystemName
), lpLuid
, lpName
, cchName
);
1497 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW
, lpSystemName
);
1498 ret
= LookupPrivilegeNameW(lpSystemNameW
.Buffer
, lpLuid
, NULL
, &wLen
);
1499 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1501 LPWSTR lpNameW
= HeapAlloc(GetProcessHeap(), 0, wLen
* sizeof(WCHAR
));
1503 ret
= LookupPrivilegeNameW(lpSystemNameW
.Buffer
, lpLuid
, lpNameW
,
1507 /* Windows crashes if cchName is NULL, so will I */
1508 int len
= WideCharToMultiByte(CP_ACP
, 0, lpNameW
, -1, lpName
,
1509 *cchName
, NULL
, NULL
);
1513 /* WideCharToMultiByte failed */
1516 else if (len
> *cchName
)
1519 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1524 /* WideCharToMultiByte succeeded, output length needs to be
1525 * length not including NULL terminator
1530 HeapFree(GetProcessHeap(), 0, lpNameW
);
1532 RtlFreeUnicodeString(&lpSystemNameW
);
1536 /******************************************************************************
1537 * LookupPrivilegeNameW [ADVAPI32.@]
1539 * Retrieves the privilege name referred to by the LUID lpLuid.
1542 * lpSystemName [I] Name of the system
1543 * lpLuid [I] Privilege value
1544 * lpName [O] Name of the privilege
1545 * cchName [I/O] Number of characters in lpName.
1548 * Success: TRUE. lpName contains the name of the privilege whose value is
1553 * Only well-known privilege names (those defined in winnt.h) can be retrieved
1554 * using this function.
1555 * If the length of lpName is too small, on return *cchName will contain the
1556 * number of WCHARs needed to contain the privilege, including the NULL
1557 * terminator, and GetLastError will return ERROR_INSUFFICIENT_BUFFER.
1558 * On success, *cchName will contain the number of characters stored in
1559 * lpName, NOT including the NULL terminator.
1562 LookupPrivilegeNameW( LPCWSTR lpSystemName
, PLUID lpLuid
, LPWSTR lpName
,
1567 TRACE("%s,%p,%p,%p\n",debugstr_w(lpSystemName
), lpLuid
, lpName
, cchName
);
1569 if (!ADVAPI_IsLocalComputer(lpSystemName
))
1571 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
1574 if (lpLuid
->HighPart
|| (lpLuid
->LowPart
< SE_MIN_WELL_KNOWN_PRIVILEGE
||
1575 lpLuid
->LowPart
> SE_MAX_WELL_KNOWN_PRIVILEGE
))
1577 SetLastError(ERROR_NO_SUCH_PRIVILEGE
);
1580 privNameLen
= strlenW(WellKnownPrivNames
[lpLuid
->LowPart
]);
1581 /* Windows crashes if cchName is NULL, so will I */
1582 if (*cchName
<= privNameLen
)
1584 *cchName
= privNameLen
+ 1;
1585 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1590 strcpyW(lpName
, WellKnownPrivNames
[lpLuid
->LowPart
]);
1591 *cchName
= privNameLen
;
1596 /******************************************************************************
1597 * GetFileSecurityA [ADVAPI32.@]
1599 * Obtains Specified information about the security of a file or directory.
1602 * lpFileName [I] Name of the file to get info for
1603 * RequestedInformation [I] SE_ flags from "winnt.h"
1604 * pSecurityDescriptor [O] Destination for security information
1605 * nLength [I] Length of pSecurityDescriptor
1606 * lpnLengthNeeded [O] Destination for length of returned security information
1609 * Success: TRUE. pSecurityDescriptor contains the requested information.
1610 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
1613 * The information returned is constrained by the callers access rights and
1617 GetFileSecurityA( LPCSTR lpFileName
,
1618 SECURITY_INFORMATION RequestedInformation
,
1619 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1620 DWORD nLength
, LPDWORD lpnLengthNeeded
)
1628 len
= MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, NULL
, 0 );
1629 name
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
1630 MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, name
, len
);
1633 r
= GetFileSecurityW( name
, RequestedInformation
, pSecurityDescriptor
,
1634 nLength
, lpnLengthNeeded
);
1635 HeapFree( GetProcessHeap(), 0, name
);
1640 /******************************************************************************
1641 * GetFileSecurityW [ADVAPI32.@]
1643 * See GetFileSecurityA.
1646 GetFileSecurityW( LPCWSTR lpFileName
,
1647 SECURITY_INFORMATION RequestedInformation
,
1648 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1649 DWORD nLength
, LPDWORD lpnLengthNeeded
)
1654 SECURITY_DESCRIPTOR_RELATIVE
*pSDRelative
;
1656 if(INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(lpFileName
))
1659 FIXME("(%s) : returns fake SECURITY_DESCRIPTOR\n", debugstr_w(lpFileName
) );
1661 nNeeded
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
1662 if (RequestedInformation
& OWNER_SECURITY_INFORMATION
)
1663 nNeeded
+= sizeof(sidWorld
);
1664 if (RequestedInformation
& GROUP_SECURITY_INFORMATION
)
1665 nNeeded
+= sizeof(sidWorld
);
1666 if (RequestedInformation
& DACL_SECURITY_INFORMATION
)
1667 nNeeded
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
1668 if (RequestedInformation
& SACL_SECURITY_INFORMATION
)
1669 nNeeded
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
1671 *lpnLengthNeeded
= nNeeded
;
1673 if (nNeeded
> nLength
)
1676 if (!InitializeSecurityDescriptor(pSecurityDescriptor
, SECURITY_DESCRIPTOR_REVISION
))
1679 pSDRelative
= (PISECURITY_DESCRIPTOR_RELATIVE
) pSecurityDescriptor
;
1680 pSDRelative
->Control
|= SE_SELF_RELATIVE
;
1681 pBuffer
= (LPBYTE
) pSDRelative
;
1682 iLocNow
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
1684 if (RequestedInformation
& OWNER_SECURITY_INFORMATION
)
1686 memcpy(pBuffer
+ iLocNow
, &sidWorld
, sizeof(sidWorld
));
1687 pSDRelative
->Owner
= iLocNow
;
1688 iLocNow
+= sizeof(sidWorld
);
1690 if (RequestedInformation
& GROUP_SECURITY_INFORMATION
)
1692 memcpy(pBuffer
+ iLocNow
, &sidWorld
, sizeof(sidWorld
));
1693 pSDRelative
->Group
= iLocNow
;
1694 iLocNow
+= sizeof(sidWorld
);
1696 if (RequestedInformation
& DACL_SECURITY_INFORMATION
)
1698 GetWorldAccessACL((PACL
) (pBuffer
+ iLocNow
));
1699 pSDRelative
->Dacl
= iLocNow
;
1700 iLocNow
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
1702 if (RequestedInformation
& SACL_SECURITY_INFORMATION
)
1704 GetWorldAccessACL((PACL
) (pBuffer
+ iLocNow
));
1705 pSDRelative
->Sacl
= iLocNow
;
1706 /* iLocNow += WINE_SIZE_OF_WORLD_ACCESS_ACL; */
1712 /******************************************************************************
1713 * LookupAccountSidA [ADVAPI32.@]
1720 IN OUT LPDWORD accountSize
,
1722 IN OUT LPDWORD domainSize
,
1723 OUT PSID_NAME_USE name_use
)
1727 LPWSTR systemW
= NULL
;
1728 LPWSTR accountW
= NULL
;
1729 LPWSTR domainW
= NULL
;
1730 DWORD accountSizeW
= *accountSize
* sizeof(WCHAR
);
1731 DWORD domainSizeW
= *domainSize
* sizeof(WCHAR
);
1733 TRACE("(%s,sid=%s,%p,%p(%lu),%p,%p(%lu),%p)\n",
1734 debugstr_a(system
),debugstr_sid(sid
),
1735 account
,accountSize
,accountSize
?*accountSize
:0,
1736 domain
,domainSize
,domainSize
?*domainSize
:0,
1740 len
= MultiByteToWideChar( CP_ACP
, 0, system
, -1, NULL
, 0 );
1741 systemW
= HeapAlloc( GetProcessHeap(), 0, (len
+1)*sizeof(WCHAR
) );
1742 MultiByteToWideChar( CP_ACP
, 0, system
, -1, systemW
, len
);
1744 accountW
= HeapAlloc( GetProcessHeap(), 0, accountSizeW
);
1745 domainW
= HeapAlloc( GetProcessHeap(), 0, domainSizeW
);
1747 r
= LookupAccountSidW(systemW
, sid
, accountW
, &accountSizeW
, domainW
, &domainSizeW
, name_use
);
1750 len
= WideCharToMultiByte( CP_ACP
, 0, accountW
, -1, NULL
, 0, NULL
, NULL
);
1751 WideCharToMultiByte( CP_ACP
, 0, accountW
, -1, account
, len
, NULL
, NULL
);
1754 len
= WideCharToMultiByte( CP_ACP
, 0, domainW
, -1, NULL
, 0, NULL
, NULL
);
1755 WideCharToMultiByte( CP_ACP
, 0, domainW
, -1, domain
, len
, NULL
, NULL
);
1759 HeapFree( GetProcessHeap(), 0, systemW
);
1760 HeapFree( GetProcessHeap(), 0, accountW
);
1761 HeapFree( GetProcessHeap(), 0, domainW
);
1766 /******************************************************************************
1767 * LookupAccountSidW [ADVAPI32.@]
1784 IN OUT LPDWORD accountSize
,
1786 IN OUT LPDWORD domainSize
,
1787 OUT PSID_NAME_USE name_use
)
1790 const WCHAR
* ac
= Administrator
; /* FIXME */
1791 const WCHAR
* dm
= DOMAIN
; /* FIXME */
1792 SID_NAME_USE use
= SidTypeUser
; /* FIXME */
1794 TRACE("(%s,sid=%s,%p,%p(%lu),%p,%p(%lu),%p)\n",
1795 debugstr_w(system
),debugstr_sid(sid
),
1796 account
,accountSize
,accountSize
?*accountSize
:0,
1797 domain
,domainSize
,domainSize
?*domainSize
:0,
1800 if (!ADVAPI_IsLocalComputer(system
)) {
1801 FIXME("Only local computer supported!\n");
1802 SetLastError(ERROR_NONE_MAPPED
);
1806 for (i
= 0; i
<= 60; i
++) {
1807 if (IsWellKnownSid(sid
, i
)) {
1808 for (j
= 0; j
< (sizeof(ACCOUNT_SIDS
) / sizeof(ACCOUNT_SIDS
[0])); j
++) {
1809 if (ACCOUNT_SIDS
[j
].type
== i
) {
1810 ac
= ACCOUNT_SIDS
[j
].account
;
1811 dm
= ACCOUNT_SIDS
[j
].domain
;
1812 use
= ACCOUNT_SIDS
[j
].name_use
;
1819 *accountSize
= strlenW(ac
)+1;
1820 if (account
&& (*accountSize
> strlenW(ac
)))
1821 strcpyW(account
, ac
);
1823 *domainSize
= strlenW(dm
)+1;
1824 if (domain
&& (*domainSize
> strlenW(dm
)))
1831 /******************************************************************************
1832 * SetFileSecurityA [ADVAPI32.@]
1834 * See SetFileSecurityW.
1836 BOOL WINAPI
SetFileSecurityA( LPCSTR lpFileName
,
1837 SECURITY_INFORMATION RequestedInformation
,
1838 PSECURITY_DESCRIPTOR pSecurityDescriptor
)
1846 len
= MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, NULL
, 0 );
1847 name
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
1848 MultiByteToWideChar( CP_ACP
, 0, lpFileName
, -1, name
, len
);
1851 r
= SetFileSecurityW( name
, RequestedInformation
, pSecurityDescriptor
);
1852 HeapFree( GetProcessHeap(), 0, name
);
1857 /******************************************************************************
1858 * SetFileSecurityW [ADVAPI32.@]
1860 * Sets the security of a file or directory.
1864 * RequestedInformation []
1865 * pSecurityDescriptor []
1872 SetFileSecurityW( LPCWSTR lpFileName
,
1873 SECURITY_INFORMATION RequestedInformation
,
1874 PSECURITY_DESCRIPTOR pSecurityDescriptor
)
1876 FIXME("(%s) : stub\n", debugstr_w(lpFileName
) );
1880 /******************************************************************************
1881 * QueryWindows31FilesMigration [ADVAPI32.@]
1887 QueryWindows31FilesMigration( DWORD x1
)
1889 FIXME("(%ld):stub\n",x1
);
1893 /******************************************************************************
1894 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
1903 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1
, DWORD x2
, DWORD x3
,
1906 FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1
,x2
,x3
,x4
);
1910 /******************************************************************************
1911 * NotifyBootConfigStatus [ADVAPI32.@]
1917 NotifyBootConfigStatus( BOOL x1
)
1919 FIXME("(0x%08d):stub\n",x1
);
1923 /******************************************************************************
1924 * RevertToSelf [ADVAPI32.@]
1926 * Ends the impersonation of a user.
1936 RevertToSelf( void )
1938 HANDLE Token
= NULL
;
1939 return set_ntstatus( NtSetInformationThread( GetCurrentThread(),
1940 ThreadImpersonationToken
, &Token
, sizeof(Token
) ) );
1943 /******************************************************************************
1944 * ImpersonateSelf [ADVAPI32.@]
1946 * Makes an impersonation token that represents the process user and assigns
1947 * to the current thread.
1950 * ImpersonationLevel [I] Level at which to impersonate.
1957 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
)
1959 return set_ntstatus( RtlImpersonateSelf( ImpersonationLevel
) );
1962 /******************************************************************************
1963 * ImpersonateLoggedOnUser [ADVAPI32.@]
1965 BOOL WINAPI
ImpersonateLoggedOnUser(HANDLE hToken
)
1969 HANDLE ImpersonationToken
;
1972 FIXME( "(%p)\n", hToken
);
1974 if (!GetTokenInformation( hToken
, TokenType
, &Type
,
1975 sizeof(TOKEN_TYPE
), &size
))
1978 if (Type
== TokenPrimary
)
1980 OBJECT_ATTRIBUTES ObjectAttributes
;
1982 InitializeObjectAttributes( &ObjectAttributes
, NULL
, 0, NULL
, NULL
);
1984 Status
= NtDuplicateToken( hToken
,
1985 TOKEN_IMPERSONATE
| TOKEN_QUERY
,
1987 SecurityImpersonation
,
1989 &ImpersonationToken
);
1990 if (Status
!= STATUS_SUCCESS
)
1992 ERR( "NtDuplicateToken failed with error 0x%08lx\n", Status
);
1993 SetLastError( RtlNtStatusToDosError( Status
) );
1998 ImpersonationToken
= hToken
;
2000 Status
= NtSetInformationThread( GetCurrentThread(),
2001 ThreadImpersonationToken
,
2002 &ImpersonationToken
,
2003 sizeof(ImpersonationToken
) );
2005 if (Type
== TokenPrimary
)
2006 NtClose( ImpersonationToken
);
2008 if (Status
!= STATUS_SUCCESS
)
2010 ERR( "NtSetInformationThread failed with error 0x%08lx\n", Status
);
2011 SetLastError( RtlNtStatusToDosError( Status
) );
2018 /******************************************************************************
2019 * AccessCheck [ADVAPI32.@]
2023 PSECURITY_DESCRIPTOR SecurityDescriptor
,
2025 DWORD DesiredAccess
,
2026 PGENERIC_MAPPING GenericMapping
,
2027 PPRIVILEGE_SET PrivilegeSet
,
2028 LPDWORD PrivilegeSetLength
,
2029 LPDWORD GrantedAccess
,
2030 LPBOOL AccessStatus
)
2032 NTSTATUS access_status
;
2033 BOOL ret
= set_ntstatus( NtAccessCheck(SecurityDescriptor
, ClientToken
, DesiredAccess
,
2034 GenericMapping
, PrivilegeSet
, PrivilegeSetLength
,
2035 GrantedAccess
, &access_status
) );
2036 if (ret
) *AccessStatus
= set_ntstatus( access_status
);
2041 /******************************************************************************
2042 * AccessCheckByType [ADVAPI32.@]
2044 BOOL WINAPI
AccessCheckByType(
2045 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
2046 PSID PrincipalSelfSid
,
2048 DWORD DesiredAccess
,
2049 POBJECT_TYPE_LIST ObjectTypeList
,
2050 DWORD ObjectTypeListLength
,
2051 PGENERIC_MAPPING GenericMapping
,
2052 PPRIVILEGE_SET PrivilegeSet
,
2053 LPDWORD PrivilegeSetLength
,
2054 LPDWORD GrantedAccess
,
2055 LPBOOL AccessStatus
)
2059 *AccessStatus
= TRUE
;
2061 return !*AccessStatus
;
2064 /******************************************************************************
2065 * MapGenericMask [ADVAPI32.@]
2067 * Maps generic access rights into specific access rights according to the
2071 * AccessMask [I/O] Access rights.
2072 * GenericMapping [I] The mapping between generic and specific rights.
2077 VOID WINAPI
MapGenericMask( PDWORD AccessMask
, PGENERIC_MAPPING GenericMapping
)
2079 RtlMapGenericMask( AccessMask
, GenericMapping
);
2082 /*************************************************************************
2083 * SetKernelObjectSecurity [ADVAPI32.@]
2085 BOOL WINAPI
SetKernelObjectSecurity (
2087 IN SECURITY_INFORMATION SecurityInformation
,
2088 IN PSECURITY_DESCRIPTOR SecurityDescriptor
)
2090 return set_ntstatus (NtSetSecurityObject (Handle
, SecurityInformation
, SecurityDescriptor
));
2094 /******************************************************************************
2095 * AddAuditAccessAce [ADVAPI32.@]
2097 BOOL WINAPI
AddAuditAccessAce(
2099 IN DWORD dwAceRevision
,
2100 IN DWORD dwAccessMask
,
2102 IN BOOL bAuditSuccess
,
2103 IN BOOL bAuditFailure
)
2105 return set_ntstatus( RtlAddAuditAccessAce(pAcl
, dwAceRevision
, dwAccessMask
, pSid
,
2106 bAuditSuccess
, bAuditFailure
) );
2109 /******************************************************************************
2110 * LookupAccountNameA [ADVAPI32.@]
2118 LPSTR ReferencedDomainName
,
2119 IN OUT LPDWORD cbReferencedDomainName
,
2120 OUT PSID_NAME_USE name_use
)
2123 UNICODE_STRING lpSystemW
;
2124 UNICODE_STRING lpAccountW
;
2125 LPWSTR lpReferencedDomainNameW
= NULL
;
2127 RtlCreateUnicodeStringFromAsciiz(&lpSystemW
, system
);
2128 RtlCreateUnicodeStringFromAsciiz(&lpAccountW
, account
);
2130 if (ReferencedDomainName
)
2131 lpReferencedDomainNameW
= HeapAlloc(GetProcessHeap(), 0, *cbReferencedDomainName
* sizeof(WCHAR
));
2133 ret
= LookupAccountNameW(lpSystemW
.Buffer
, lpAccountW
.Buffer
, sid
, cbSid
, lpReferencedDomainNameW
,
2134 cbReferencedDomainName
, name_use
);
2136 if (ret
&& lpReferencedDomainNameW
)
2138 WideCharToMultiByte(CP_ACP
, 0, lpReferencedDomainNameW
, *cbReferencedDomainName
,
2139 ReferencedDomainName
, *cbReferencedDomainName
, NULL
, NULL
);
2142 RtlFreeUnicodeString(&lpSystemW
);
2143 RtlFreeUnicodeString(&lpAccountW
);
2144 HeapFree(GetProcessHeap(), 0, lpReferencedDomainNameW
);
2149 /******************************************************************************
2150 * LookupAccountNameW [ADVAPI32.@]
2152 BOOL WINAPI
LookupAccountNameW( LPCWSTR lpSystemName
, LPCWSTR lpAccountName
, PSID Sid
,
2153 LPDWORD cbSid
, LPWSTR ReferencedDomainName
,
2154 LPDWORD cchReferencedDomainName
, PSID_NAME_USE peUse
)
2156 /* Default implementation: Always return a default SID */
2157 SID_IDENTIFIER_AUTHORITY identifierAuthority
= {SECURITY_NT_AUTHORITY
};
2160 static const WCHAR dm
[] = {'D','O','M','A','I','N',0};
2162 FIXME("%s %s %p %p %p %p %p - stub\n", debugstr_w(lpSystemName
), debugstr_w(lpAccountName
),
2163 Sid
, cbSid
, ReferencedDomainName
, cchReferencedDomainName
, peUse
);
2165 ret
= AllocateAndInitializeSid(&identifierAuthority
,
2167 SECURITY_BUILTIN_DOMAIN_RID
,
2168 DOMAIN_ALIAS_RID_ADMINS
,
2175 if (!RtlValidSid(pSid
))
2181 if (Sid
!= NULL
&& (*cbSid
>= GetLengthSid(pSid
)))
2182 CopySid(*cbSid
, Sid
, pSid
);
2183 if (*cbSid
< GetLengthSid(pSid
))
2185 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2188 *cbSid
= GetLengthSid(pSid
);
2190 if (ReferencedDomainName
!= NULL
&& (*cchReferencedDomainName
> strlenW(dm
)))
2191 strcpyW(ReferencedDomainName
, dm
);
2193 if (*cchReferencedDomainName
<= strlenW(dm
))
2195 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2199 *cchReferencedDomainName
= strlenW(dm
)+1;
2206 /******************************************************************************
2207 * PrivilegeCheck [ADVAPI32.@]
2209 BOOL WINAPI
PrivilegeCheck( HANDLE ClientToken
, PPRIVILEGE_SET RequiredPrivileges
, LPBOOL pfResult
)
2214 TRACE("%p %p %p\n", ClientToken
, RequiredPrivileges
, pfResult
);
2216 ret
= set_ntstatus (NtPrivilegeCheck (ClientToken
, RequiredPrivileges
, &Result
));
2222 /******************************************************************************
2223 * AccessCheckAndAuditAlarmA [ADVAPI32.@]
2225 BOOL WINAPI
AccessCheckAndAuditAlarmA(LPCSTR Subsystem
, LPVOID HandleId
, LPSTR ObjectTypeName
,
2226 LPSTR ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
, DWORD DesiredAccess
,
2227 PGENERIC_MAPPING GenericMapping
, BOOL ObjectCreation
, LPDWORD GrantedAccess
,
2228 LPBOOL AccessStatus
, LPBOOL pfGenerateOnClose
)
2230 FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_a(Subsystem
),
2231 HandleId
, debugstr_a(ObjectTypeName
), debugstr_a(ObjectName
),
2232 SecurityDescriptor
, DesiredAccess
, GenericMapping
,
2233 ObjectCreation
, GrantedAccess
, AccessStatus
, pfGenerateOnClose
);
2237 /******************************************************************************
2238 * AccessCheckAndAuditAlarmW [ADVAPI32.@]
2240 BOOL WINAPI
AccessCheckAndAuditAlarmW(LPCWSTR Subsystem
, LPVOID HandleId
, LPWSTR ObjectTypeName
,
2241 LPWSTR ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
, DWORD DesiredAccess
,
2242 PGENERIC_MAPPING GenericMapping
, BOOL ObjectCreation
, LPDWORD GrantedAccess
,
2243 LPBOOL AccessStatus
, LPBOOL pfGenerateOnClose
)
2245 FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_w(Subsystem
),
2246 HandleId
, debugstr_w(ObjectTypeName
), debugstr_w(ObjectName
),
2247 SecurityDescriptor
, DesiredAccess
, GenericMapping
,
2248 ObjectCreation
, GrantedAccess
, AccessStatus
, pfGenerateOnClose
);
2252 BOOL WINAPI
ObjectCloseAuditAlarmA(LPCSTR SubsystemName
, LPVOID HandleId
, BOOL GenerateOnClose
)
2254 FIXME("stub (%s,%p,%x)\n", debugstr_a(SubsystemName
), HandleId
, GenerateOnClose
);
2259 BOOL WINAPI
ObjectCloseAuditAlarmW(LPCWSTR SubsystemName
, LPVOID HandleId
, BOOL GenerateOnClose
)
2261 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName
), HandleId
, GenerateOnClose
);
2266 BOOL WINAPI
ObjectDeleteAuditAlarmW(LPCWSTR SubsystemName
, LPVOID HandleId
, BOOL GenerateOnClose
)
2268 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName
), HandleId
, GenerateOnClose
);
2273 BOOL WINAPI
ObjectOpenAuditAlarmA(LPCSTR SubsystemName
, LPVOID HandleId
, LPSTR ObjectTypeName
,
2274 LPSTR ObjectName
, PSECURITY_DESCRIPTOR pSecurityDescriptor
, HANDLE ClientToken
, DWORD DesiredAccess
,
2275 DWORD GrantedAccess
, PPRIVILEGE_SET Privileges
, BOOL ObjectCreation
, BOOL AccessGranted
,
2276 LPBOOL GenerateOnClose
)
2278 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08lx,0x%08lx,%p,%x,%x,%p)\n", debugstr_a(SubsystemName
),
2279 HandleId
, debugstr_a(ObjectTypeName
), debugstr_a(ObjectName
), pSecurityDescriptor
,
2280 ClientToken
, DesiredAccess
, GrantedAccess
, Privileges
, ObjectCreation
, AccessGranted
,
2286 BOOL WINAPI
ObjectOpenAuditAlarmW(LPCWSTR SubsystemName
, LPVOID HandleId
, LPWSTR ObjectTypeName
,
2287 LPWSTR ObjectName
, PSECURITY_DESCRIPTOR pSecurityDescriptor
, HANDLE ClientToken
, DWORD DesiredAccess
,
2288 DWORD GrantedAccess
, PPRIVILEGE_SET Privileges
, BOOL ObjectCreation
, BOOL AccessGranted
,
2289 LPBOOL GenerateOnClose
)
2291 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08lx,0x%08lx,%p,%x,%x,%p)\n", debugstr_w(SubsystemName
),
2292 HandleId
, debugstr_w(ObjectTypeName
), debugstr_w(ObjectName
), pSecurityDescriptor
,
2293 ClientToken
, DesiredAccess
, GrantedAccess
, Privileges
, ObjectCreation
, AccessGranted
,
2299 BOOL WINAPI
ObjectPrivilegeAuditAlarmA( LPCSTR SubsystemName
, LPVOID HandleId
, HANDLE ClientToken
,
2300 DWORD DesiredAccess
, PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2302 FIXME("stub (%s,%p,%p,0x%08lx,%p,%x)\n", debugstr_a(SubsystemName
), HandleId
, ClientToken
,
2303 DesiredAccess
, Privileges
, AccessGranted
);
2308 BOOL WINAPI
ObjectPrivilegeAuditAlarmW( LPCWSTR SubsystemName
, LPVOID HandleId
, HANDLE ClientToken
,
2309 DWORD DesiredAccess
, PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2311 FIXME("stub (%s,%p,%p,0x%08lx,%p,%x)\n", debugstr_w(SubsystemName
), HandleId
, ClientToken
,
2312 DesiredAccess
, Privileges
, AccessGranted
);
2317 BOOL WINAPI
PrivilegedServiceAuditAlarmA( LPCSTR SubsystemName
, LPCSTR ServiceName
, HANDLE ClientToken
,
2318 PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2320 FIXME("stub (%s,%s,%p,%p,%x)\n", debugstr_a(SubsystemName
), debugstr_a(ServiceName
),
2321 ClientToken
, Privileges
, AccessGranted
);
2326 BOOL WINAPI
PrivilegedServiceAuditAlarmW( LPCWSTR SubsystemName
, LPCWSTR ServiceName
, HANDLE ClientToken
,
2327 PPRIVILEGE_SET Privileges
, BOOL AccessGranted
)
2329 FIXME("stub %s,%s,%p,%p,%x)\n", debugstr_w(SubsystemName
), debugstr_w(ServiceName
),
2330 ClientToken
, Privileges
, AccessGranted
);
2335 /******************************************************************************
2336 * GetSecurityInfo [ADVAPI32.@]
2338 DWORD WINAPI
GetSecurityInfo(
2339 HANDLE hObject
, SE_OBJECT_TYPE ObjectType
,
2340 SECURITY_INFORMATION SecurityInfo
, PSID
*ppsidOwner
,
2341 PSID
*ppsidGroup
, PACL
*ppDacl
, PACL
*ppSacl
,
2342 PSECURITY_DESCRIPTOR
*ppSecurityDescriptor
2346 return ERROR_BAD_PROVIDER
;
2349 /******************************************************************************
2350 * GetSecurityInfoExW [ADVAPI32.@]
2352 DWORD WINAPI
GetSecurityInfoExW(
2353 HANDLE hObject
, SE_OBJECT_TYPE ObjectType
,
2354 SECURITY_INFORMATION SecurityInfo
, LPCWSTR lpProvider
,
2355 LPCWSTR lpProperty
, PACTRL_ACCESSW
*ppAccessList
,
2356 PACTRL_AUDITW
*ppAuditList
, LPWSTR
*lppOwner
, LPWSTR
*lppGroup
2360 return ERROR_BAD_PROVIDER
;
2363 /******************************************************************************
2364 * BuildExplicitAccessWithNameA [ADVAPI32.@]
2366 VOID WINAPI
BuildExplicitAccessWithNameA( PEXPLICIT_ACCESSA pExplicitAccess
,
2367 LPSTR pTrusteeName
, DWORD AccessPermissions
,
2368 ACCESS_MODE AccessMode
, DWORD Inheritance
)
2370 TRACE("%p %s 0x%08lx 0x%08x 0x%08lx\n", pExplicitAccess
, debugstr_a(pTrusteeName
),
2371 AccessPermissions
, AccessMode
, Inheritance
);
2373 pExplicitAccess
->grfAccessPermissions
= AccessPermissions
;
2374 pExplicitAccess
->grfAccessMode
= AccessMode
;
2375 pExplicitAccess
->grfInheritance
= Inheritance
;
2377 pExplicitAccess
->Trustee
.pMultipleTrustee
= NULL
;
2378 pExplicitAccess
->Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2379 pExplicitAccess
->Trustee
.TrusteeForm
= TRUSTEE_IS_NAME
;
2380 pExplicitAccess
->Trustee
.TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2381 pExplicitAccess
->Trustee
.ptstrName
= pTrusteeName
;
2384 /******************************************************************************
2385 * BuildExplicitAccessWithNameW [ADVAPI32.@]
2387 VOID WINAPI
BuildExplicitAccessWithNameW( PEXPLICIT_ACCESSW pExplicitAccess
,
2388 LPWSTR pTrusteeName
, DWORD AccessPermissions
,
2389 ACCESS_MODE AccessMode
, DWORD Inheritance
)
2391 TRACE("%p %s 0x%08lx 0x%08x 0x%08lx\n", pExplicitAccess
, debugstr_w(pTrusteeName
),
2392 AccessPermissions
, AccessMode
, Inheritance
);
2394 pExplicitAccess
->grfAccessPermissions
= AccessPermissions
;
2395 pExplicitAccess
->grfAccessMode
= AccessMode
;
2396 pExplicitAccess
->grfInheritance
= Inheritance
;
2398 pExplicitAccess
->Trustee
.pMultipleTrustee
= NULL
;
2399 pExplicitAccess
->Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2400 pExplicitAccess
->Trustee
.TrusteeForm
= TRUSTEE_IS_NAME
;
2401 pExplicitAccess
->Trustee
.TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2402 pExplicitAccess
->Trustee
.ptstrName
= pTrusteeName
;
2405 /******************************************************************************
2406 * BuildTrusteeWithObjectsAndNameA [ADVAPI32.@]
2408 VOID WINAPI
BuildTrusteeWithObjectsAndNameA( PTRUSTEEA pTrustee
, POBJECTS_AND_NAME_A pObjName
,
2409 SE_OBJECT_TYPE ObjectType
, LPSTR ObjectTypeName
,
2410 LPSTR InheritedObjectTypeName
, LPSTR Name
)
2412 DWORD ObjectsPresent
= 0;
2414 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee
, pObjName
,
2415 ObjectType
, ObjectTypeName
, InheritedObjectTypeName
, debugstr_a(Name
));
2417 /* Fill the OBJECTS_AND_NAME structure */
2418 pObjName
->ObjectType
= ObjectType
;
2419 if (ObjectTypeName
!= NULL
)
2421 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2424 pObjName
->InheritedObjectTypeName
= InheritedObjectTypeName
;
2425 if (InheritedObjectTypeName
!= NULL
)
2427 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2430 pObjName
->ObjectsPresent
= ObjectsPresent
;
2431 pObjName
->ptstrName
= Name
;
2433 /* Fill the TRUSTEE structure */
2434 pTrustee
->pMultipleTrustee
= NULL
;
2435 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2436 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_NAME
;
2437 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2438 pTrustee
->ptstrName
= (LPSTR
)pObjName
;
2441 /******************************************************************************
2442 * BuildTrusteeWithObjectsAndNameW [ADVAPI32.@]
2444 VOID WINAPI
BuildTrusteeWithObjectsAndNameW( PTRUSTEEW pTrustee
, POBJECTS_AND_NAME_W pObjName
,
2445 SE_OBJECT_TYPE ObjectType
, LPWSTR ObjectTypeName
,
2446 LPWSTR InheritedObjectTypeName
, LPWSTR Name
)
2448 DWORD ObjectsPresent
= 0;
2450 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee
, pObjName
,
2451 ObjectType
, ObjectTypeName
, InheritedObjectTypeName
, debugstr_w(Name
));
2453 /* Fill the OBJECTS_AND_NAME structure */
2454 pObjName
->ObjectType
= ObjectType
;
2455 if (ObjectTypeName
!= NULL
)
2457 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2460 pObjName
->InheritedObjectTypeName
= InheritedObjectTypeName
;
2461 if (InheritedObjectTypeName
!= NULL
)
2463 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2466 pObjName
->ObjectsPresent
= ObjectsPresent
;
2467 pObjName
->ptstrName
= Name
;
2469 /* Fill the TRUSTEE structure */
2470 pTrustee
->pMultipleTrustee
= NULL
;
2471 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2472 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_NAME
;
2473 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2474 pTrustee
->ptstrName
= (LPWSTR
)pObjName
;
2477 /******************************************************************************
2478 * BuildTrusteeWithObjectsAndSidA [ADVAPI32.@]
2480 VOID WINAPI
BuildTrusteeWithObjectsAndSidA( PTRUSTEEA pTrustee
, POBJECTS_AND_SID pObjSid
,
2481 GUID
* pObjectGuid
, GUID
* pInheritedObjectGuid
, PSID pSid
)
2483 DWORD ObjectsPresent
= 0;
2485 TRACE("%p %p %p %p %p\n", pTrustee
, pObjSid
, pObjectGuid
, pInheritedObjectGuid
, pSid
);
2487 /* Fill the OBJECTS_AND_SID structure */
2488 if (pObjectGuid
!= NULL
)
2490 pObjSid
->ObjectTypeGuid
= *pObjectGuid
;
2491 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2495 ZeroMemory(&pObjSid
->ObjectTypeGuid
,
2499 if (pInheritedObjectGuid
!= NULL
)
2501 pObjSid
->InheritedObjectTypeGuid
= *pInheritedObjectGuid
;
2502 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2506 ZeroMemory(&pObjSid
->InheritedObjectTypeGuid
,
2510 pObjSid
->ObjectsPresent
= ObjectsPresent
;
2511 pObjSid
->pSid
= pSid
;
2513 /* Fill the TRUSTEE structure */
2514 pTrustee
->pMultipleTrustee
= NULL
;
2515 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2516 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_SID
;
2517 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2518 pTrustee
->ptstrName
= (LPSTR
) pObjSid
;
2521 /******************************************************************************
2522 * BuildTrusteeWithObjectsAndSidW [ADVAPI32.@]
2524 VOID WINAPI
BuildTrusteeWithObjectsAndSidW( PTRUSTEEW pTrustee
, POBJECTS_AND_SID pObjSid
,
2525 GUID
* pObjectGuid
, GUID
* pInheritedObjectGuid
, PSID pSid
)
2527 DWORD ObjectsPresent
= 0;
2529 TRACE("%p %p %p %p %p\n", pTrustee
, pObjSid
, pObjectGuid
, pInheritedObjectGuid
, pSid
);
2531 /* Fill the OBJECTS_AND_SID structure */
2532 if (pObjectGuid
!= NULL
)
2534 pObjSid
->ObjectTypeGuid
= *pObjectGuid
;
2535 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2539 ZeroMemory(&pObjSid
->ObjectTypeGuid
,
2543 if (pInheritedObjectGuid
!= NULL
)
2545 pObjSid
->InheritedObjectTypeGuid
= *pInheritedObjectGuid
;
2546 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2550 ZeroMemory(&pObjSid
->InheritedObjectTypeGuid
,
2554 pObjSid
->ObjectsPresent
= ObjectsPresent
;
2555 pObjSid
->pSid
= pSid
;
2557 /* Fill the TRUSTEE structure */
2558 pTrustee
->pMultipleTrustee
= NULL
;
2559 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2560 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_SID
;
2561 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2562 pTrustee
->ptstrName
= (LPWSTR
) pObjSid
;
2565 /******************************************************************************
2566 * BuildTrusteeWithSidA [ADVAPI32.@]
2568 VOID WINAPI
BuildTrusteeWithSidA(PTRUSTEEA pTrustee
, PSID pSid
)
2570 TRACE("%p %p\n", pTrustee
, pSid
);
2572 pTrustee
->pMultipleTrustee
= NULL
;
2573 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2574 pTrustee
->TrusteeForm
= TRUSTEE_IS_SID
;
2575 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2576 pTrustee
->ptstrName
= (LPSTR
) pSid
;
2579 /******************************************************************************
2580 * BuildTrusteeWithSidW [ADVAPI32.@]
2582 VOID WINAPI
BuildTrusteeWithSidW(PTRUSTEEW pTrustee
, PSID pSid
)
2584 TRACE("%p %p\n", pTrustee
, pSid
);
2586 pTrustee
->pMultipleTrustee
= NULL
;
2587 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2588 pTrustee
->TrusteeForm
= TRUSTEE_IS_SID
;
2589 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2590 pTrustee
->ptstrName
= (LPWSTR
) pSid
;
2593 /******************************************************************************
2594 * BuildTrusteeWithNameA [ADVAPI32.@]
2596 VOID WINAPI
BuildTrusteeWithNameA(PTRUSTEEA pTrustee
, LPSTR name
)
2598 TRACE("%p %s\n", pTrustee
, debugstr_a(name
) );
2600 pTrustee
->pMultipleTrustee
= NULL
;
2601 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2602 pTrustee
->TrusteeForm
= TRUSTEE_IS_NAME
;
2603 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2604 pTrustee
->ptstrName
= name
;
2607 /******************************************************************************
2608 * BuildTrusteeWithNameW [ADVAPI32.@]
2610 VOID WINAPI
BuildTrusteeWithNameW(PTRUSTEEW pTrustee
, LPWSTR name
)
2612 TRACE("%p %s\n", pTrustee
, debugstr_w(name
) );
2614 pTrustee
->pMultipleTrustee
= NULL
;
2615 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2616 pTrustee
->TrusteeForm
= TRUSTEE_IS_NAME
;
2617 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2618 pTrustee
->ptstrName
= name
;
2621 /******************************************************************************
2622 * GetTrusteeFormA [ADVAPI32.@]
2624 TRUSTEE_FORM WINAPI
GetTrusteeFormA(PTRUSTEEA pTrustee
)
2626 TRACE("(%p)\n", pTrustee
);
2629 return TRUSTEE_BAD_FORM
;
2631 return pTrustee
->TrusteeForm
;
2634 /******************************************************************************
2635 * GetTrusteeFormW [ADVAPI32.@]
2637 TRUSTEE_FORM WINAPI
GetTrusteeFormW(PTRUSTEEW pTrustee
)
2639 TRACE("(%p)\n", pTrustee
);
2642 return TRUSTEE_BAD_FORM
;
2644 return pTrustee
->TrusteeForm
;
2647 /******************************************************************************
2648 * GetTrusteeNameA [ADVAPI32.@]
2650 LPSTR WINAPI
GetTrusteeNameA(PTRUSTEEA pTrustee
)
2652 TRACE("(%p)\n", pTrustee
);
2657 return pTrustee
->ptstrName
;
2660 /******************************************************************************
2661 * GetTrusteeNameW [ADVAPI32.@]
2663 LPWSTR WINAPI
GetTrusteeNameW(PTRUSTEEW pTrustee
)
2665 TRACE("(%p)\n", pTrustee
);
2670 return pTrustee
->ptstrName
;
2673 /******************************************************************************
2674 * GetTrusteeTypeA [ADVAPI32.@]
2676 TRUSTEE_TYPE WINAPI
GetTrusteeTypeA(PTRUSTEEA pTrustee
)
2678 TRACE("(%p)\n", pTrustee
);
2681 return TRUSTEE_IS_UNKNOWN
;
2683 return pTrustee
->TrusteeType
;
2686 /******************************************************************************
2687 * GetTrusteeTypeW [ADVAPI32.@]
2689 TRUSTEE_TYPE WINAPI
GetTrusteeTypeW(PTRUSTEEW pTrustee
)
2691 TRACE("(%p)\n", pTrustee
);
2694 return TRUSTEE_IS_UNKNOWN
;
2696 return pTrustee
->TrusteeType
;
2699 BOOL WINAPI
SetAclInformation( PACL pAcl
, LPVOID pAclInformation
,
2700 DWORD nAclInformationLength
,
2701 ACL_INFORMATION_CLASS dwAclInformationClass
)
2703 FIXME("%p %p 0x%08lx 0x%08x - stub\n", pAcl
, pAclInformation
,
2704 nAclInformationLength
, dwAclInformationClass
);
2709 /******************************************************************************
2710 * SetEntriesInAclA [ADVAPI32.@]
2712 DWORD WINAPI
SetEntriesInAclA( ULONG count
, PEXPLICIT_ACCESSA pEntries
,
2713 PACL OldAcl
, PACL
* NewAcl
)
2715 FIXME("%ld %p %p %p\n",count
,pEntries
,OldAcl
,NewAcl
);
2716 return ERROR_CALL_NOT_IMPLEMENTED
;
2719 /******************************************************************************
2720 * SetEntriesInAclW [ADVAPI32.@]
2722 DWORD WINAPI
SetEntriesInAclW( ULONG count
, PEXPLICIT_ACCESSW pEntries
,
2723 PACL OldAcl
, PACL
* NewAcl
)
2725 FIXME("%ld %p %p %p\n",count
,pEntries
,OldAcl
,NewAcl
);
2726 return ERROR_CALL_NOT_IMPLEMENTED
;
2729 /******************************************************************************
2730 * SetNamedSecurityInfoA [ADVAPI32.@]
2732 DWORD WINAPI
SetNamedSecurityInfoA(LPSTR pObjectName
,
2733 SE_OBJECT_TYPE ObjectType
, SECURITY_INFORMATION SecurityInfo
,
2734 PSID psidOwner
, PSID psidGroup
, PACL pDacl
, PACL pSacl
)
2740 TRACE("%s %d %ld %p %p %p %p\n", debugstr_a(pObjectName
), ObjectType
,
2741 SecurityInfo
, psidOwner
, psidGroup
, pDacl
, pSacl
);
2745 len
= MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, NULL
, 0 );
2746 wstr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
2747 MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, wstr
, len
);
2750 r
= SetNamedSecurityInfoW( wstr
, ObjectType
, SecurityInfo
, psidOwner
,
2751 psidGroup
, pDacl
, pSacl
);
2753 HeapFree( GetProcessHeap(), 0, wstr
);
2758 BOOL WINAPI
SetPrivateObjectSecurity( SECURITY_INFORMATION SecurityInformation
,
2759 PSECURITY_DESCRIPTOR ModificationDescriptor
,
2760 PSECURITY_DESCRIPTOR
* ObjectsSecurityDescriptor
,
2761 PGENERIC_MAPPING GenericMapping
,
2764 FIXME("0x%08lx %p %p %p %p - stub\n", SecurityInformation
, ModificationDescriptor
,
2765 ObjectsSecurityDescriptor
, GenericMapping
, Token
);
2770 BOOL WINAPI
SetSecurityDescriptorControl( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
2771 SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest
,
2772 SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet
)
2774 FIXME("%p 0x%08x 0x%08x - stub\n", pSecurityDescriptor
, ControlBitsOfInterest
,
2780 BOOL WINAPI
AreAllAccessesGranted( DWORD GrantedAccess
, DWORD DesiredAccess
)
2782 return RtlAreAllAccessesGranted( GrantedAccess
, DesiredAccess
);
2785 /******************************************************************************
2786 * AreAnyAccessesGranted [ADVAPI32.@]
2788 * Determines whether or not any of a set of specified access permissions have
2789 * been granted or not.
2792 * GrantedAccess [I] The permissions that have been granted.
2793 * DesiredAccess [I] The permissions that you want to have.
2796 * Nonzero if any of the permissions have been granted, zero if none of the
2797 * permissions have been granted.
2800 BOOL WINAPI
AreAnyAccessesGranted( DWORD GrantedAccess
, DWORD DesiredAccess
)
2802 return RtlAreAnyAccessesGranted( GrantedAccess
, DesiredAccess
);
2805 /******************************************************************************
2806 * SetNamedSecurityInfoW [ADVAPI32.@]
2808 DWORD WINAPI
SetNamedSecurityInfoW(LPWSTR pObjectName
,
2809 SE_OBJECT_TYPE ObjectType
, SECURITY_INFORMATION SecurityInfo
,
2810 PSID psidOwner
, PSID psidGroup
, PACL pDacl
, PACL pSacl
)
2812 FIXME("%s %d %ld %p %p %p %p\n", debugstr_w(pObjectName
), ObjectType
,
2813 SecurityInfo
, psidOwner
, psidGroup
, pDacl
, pSacl
);
2814 return ERROR_SUCCESS
;
2817 /******************************************************************************
2818 * GetExplicitEntriesFromAclA [ADVAPI32.@]
2820 DWORD WINAPI
GetExplicitEntriesFromAclA( PACL pacl
, PULONG pcCountOfExplicitEntries
,
2821 PEXPLICIT_ACCESSA
* pListOfExplicitEntries
)
2823 FIXME("%p %p %p\n",pacl
, pcCountOfExplicitEntries
, pListOfExplicitEntries
);
2824 return ERROR_CALL_NOT_IMPLEMENTED
;
2827 /******************************************************************************
2828 * GetExplicitEntriesFromAclW [ADVAPI32.@]
2830 DWORD WINAPI
GetExplicitEntriesFromAclW( PACL pacl
, PULONG pcCountOfExplicitEntries
,
2831 PEXPLICIT_ACCESSW
* pListOfExplicitEntries
)
2833 FIXME("%p %p %p\n",pacl
, pcCountOfExplicitEntries
, pListOfExplicitEntries
);
2834 return ERROR_CALL_NOT_IMPLEMENTED
;
2838 /******************************************************************************
2839 * ParseAclStringFlags
2841 static DWORD
ParseAclStringFlags(LPCWSTR
* StringAcl
)
2844 LPCWSTR szAcl
= *StringAcl
;
2846 while (*szAcl
!= '(')
2850 flags
|= SE_DACL_PROTECTED
;
2852 else if (*szAcl
== 'A')
2856 flags
|= SE_DACL_AUTO_INHERIT_REQ
;
2857 else if (*szAcl
== 'I')
2858 flags
|= SE_DACL_AUTO_INHERITED
;
2867 /******************************************************************************
2868 * ParseAceStringType
2870 static const ACEFLAG AceType
[] =
2872 { SDDL_ACCESS_ALLOWED
, ACCESS_ALLOWED_ACE_TYPE
},
2873 { SDDL_ALARM
, SYSTEM_ALARM_ACE_TYPE
},
2874 { SDDL_AUDIT
, SYSTEM_AUDIT_ACE_TYPE
},
2875 { SDDL_ACCESS_DENIED
, ACCESS_DENIED_ACE_TYPE
},
2877 { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
2878 { SDDL_OBJECT_ACCESS_DENIED, ACCESS_DENIED_OBJECT_ACE_TYPE },
2879 { SDDL_OBJECT_ALARM, SYSTEM_ALARM_OBJECT_ACE_TYPE },
2880 { SDDL_OBJECT_AUDIT, SYSTEM_AUDIT_OBJECT_ACE_TYPE },
2885 static BYTE
ParseAceStringType(LPCWSTR
* StringAcl
)
2888 LPCWSTR szAcl
= *StringAcl
;
2889 const ACEFLAG
*lpaf
= AceType
;
2891 while (lpaf
->wstr
&&
2892 (len
= strlenW(lpaf
->wstr
)) &&
2893 strncmpW(lpaf
->wstr
, szAcl
, len
))
2904 /******************************************************************************
2905 * ParseAceStringFlags
2907 static const ACEFLAG AceFlags
[] =
2909 { SDDL_CONTAINER_INHERIT
, CONTAINER_INHERIT_ACE
},
2910 { SDDL_AUDIT_FAILURE
, FAILED_ACCESS_ACE_FLAG
},
2911 { SDDL_INHERITED
, INHERITED_ACE
},
2912 { SDDL_INHERIT_ONLY
, INHERIT_ONLY_ACE
},
2913 { SDDL_NO_PROPAGATE
, NO_PROPAGATE_INHERIT_ACE
},
2914 { SDDL_OBJECT_INHERIT
, OBJECT_INHERIT_ACE
},
2915 { SDDL_AUDIT_SUCCESS
, SUCCESSFUL_ACCESS_ACE_FLAG
},
2919 static BYTE
ParseAceStringFlags(LPCWSTR
* StringAcl
)
2923 LPCWSTR szAcl
= *StringAcl
;
2925 while (*szAcl
!= ';')
2927 const ACEFLAG
*lpaf
= AceFlags
;
2929 while (lpaf
->wstr
&&
2930 (len
= strlenW(lpaf
->wstr
)) &&
2931 strncmpW(lpaf
->wstr
, szAcl
, len
))
2937 flags
|= lpaf
->value
;
2946 /******************************************************************************
2947 * ParseAceStringRights
2949 static const ACEFLAG AceRights
[] =
2951 { SDDL_GENERIC_ALL
, GENERIC_ALL
},
2952 { SDDL_GENERIC_READ
, GENERIC_READ
},
2953 { SDDL_GENERIC_WRITE
, GENERIC_WRITE
},
2954 { SDDL_GENERIC_EXECUTE
, GENERIC_EXECUTE
},
2955 { SDDL_READ_CONTROL
, READ_CONTROL
},
2956 { SDDL_STANDARD_DELETE
, DELETE
},
2957 { SDDL_WRITE_DAC
, WRITE_DAC
},
2958 { SDDL_WRITE_OWNER
, WRITE_OWNER
},
2962 static DWORD
ParseAceStringRights(LPCWSTR
* StringAcl
)
2966 LPCWSTR szAcl
= *StringAcl
;
2968 if ((*szAcl
== '0') && (*(szAcl
+ 1) == 'x'))
2972 while (*p
&& *p
!= ';')
2977 rights
= strtoulW(szAcl
, NULL
, 16);
2981 WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl
, p
- szAcl
));
2985 while (*szAcl
!= ';')
2987 const ACEFLAG
*lpaf
= AceRights
;
2989 while (lpaf
->wstr
&&
2990 (len
= strlenW(lpaf
->wstr
)) &&
2991 strncmpW(lpaf
->wstr
, szAcl
, len
))
2999 rights
|= lpaf
->value
;
3009 /******************************************************************************
3010 * ParseStringAclToAcl
3012 * dacl_flags(string_ace1)(string_ace2)... (string_acen)
3014 static BOOL
ParseStringAclToAcl(LPCWSTR StringAcl
, LPDWORD lpdwFlags
,
3015 PACL pAcl
, LPDWORD cBytes
)
3019 DWORD length
= sizeof(ACL
);
3020 PACCESS_ALLOWED_ACE pAce
= NULL
; /* pointer to current ACE */
3022 TRACE("%s\n", debugstr_w(StringAcl
));
3027 if (pAcl
) /* pAce is only useful if we're setting values */
3028 pAce
= (PACCESS_ALLOWED_ACE
) ((LPBYTE
)pAcl
+ sizeof(PACL
));
3030 /* Parse ACL flags */
3031 *lpdwFlags
= ParseAclStringFlags(&StringAcl
);
3034 while (*StringAcl
== '(')
3038 /* Parse ACE type */
3039 val
= ParseAceStringType(&StringAcl
);
3041 pAce
->Header
.AceType
= (BYTE
) val
;
3042 if (*StringAcl
!= ';')
3046 /* Parse ACE flags */
3047 val
= ParseAceStringFlags(&StringAcl
);
3049 pAce
->Header
.AceFlags
= (BYTE
) val
;
3050 if (*StringAcl
!= ';')
3054 /* Parse ACE rights */
3055 val
= ParseAceStringRights(&StringAcl
);
3058 if (*StringAcl
!= ';')
3062 /* Parse ACE object guid */
3063 if (*StringAcl
!= ';')
3065 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3070 /* Parse ACE inherit object guid */
3071 if (*StringAcl
!= ';')
3073 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
3078 /* Parse ACE account sid */
3079 if (ParseStringSidToSid(StringAcl
, pAce
? (PSID
)&pAce
->SidStart
: NULL
, &sidlen
))
3081 while (*StringAcl
&& *StringAcl
!= ')')
3085 if (*StringAcl
!= ')')
3089 length
+= sizeof(ACCESS_ALLOWED_ACE
) - sizeof(DWORD
) + sidlen
;
3096 WARN("Invalid ACE string format\n");
3101 /******************************************************************************
3102 * ParseStringSecurityDescriptorToSecurityDescriptor
3104 static BOOL
ParseStringSecurityDescriptorToSecurityDescriptor(
3105 LPCWSTR StringSecurityDescriptor
,
3106 SECURITY_DESCRIPTOR
* SecurityDescriptor
,
3111 WCHAR tok
[MAX_PATH
];
3113 LPBYTE lpNext
= NULL
;
3118 if (SecurityDescriptor
)
3119 lpNext
= ((LPBYTE
) SecurityDescriptor
) + sizeof(SECURITY_DESCRIPTOR
);
3121 while (*StringSecurityDescriptor
)
3123 toktype
= *StringSecurityDescriptor
;
3125 /* Expect char identifier followed by ':' */
3126 StringSecurityDescriptor
++;
3127 if (*StringSecurityDescriptor
!= ':')
3129 SetLastError(ERROR_INVALID_PARAMETER
);
3132 StringSecurityDescriptor
++;
3135 lptoken
= StringSecurityDescriptor
;
3136 while (*lptoken
&& *lptoken
!= ':')
3142 len
= lptoken
- StringSecurityDescriptor
;
3143 memcpy( tok
, StringSecurityDescriptor
, len
* sizeof(WCHAR
) );
3152 if (!ParseStringSidToSid(tok
, (PSID
)lpNext
, &bytes
))
3155 if (SecurityDescriptor
)
3157 SecurityDescriptor
->Owner
= (PSID
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3158 lpNext
+= bytes
; /* Advance to next token */
3170 if (!ParseStringSidToSid(tok
, (PSID
)lpNext
, &bytes
))
3173 if (SecurityDescriptor
)
3175 SecurityDescriptor
->Group
= (PSID
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3176 lpNext
+= bytes
; /* Advance to next token */
3189 if (!ParseStringAclToAcl(tok
, &flags
, (PACL
)lpNext
, &bytes
))
3192 if (SecurityDescriptor
)
3194 SecurityDescriptor
->Control
|= SE_DACL_PRESENT
| flags
;
3195 SecurityDescriptor
->Dacl
= (PACL
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3196 lpNext
+= bytes
; /* Advance to next token */
3209 if (!ParseStringAclToAcl(tok
, &flags
, (PACL
)lpNext
, &bytes
))
3212 if (SecurityDescriptor
)
3214 SecurityDescriptor
->Control
|= SE_SACL_PRESENT
| flags
;
3215 SecurityDescriptor
->Sacl
= (PACL
)(lpNext
- (LPBYTE
)SecurityDescriptor
);
3216 lpNext
+= bytes
; /* Advance to next token */
3225 FIXME("Unknown token\n");
3226 SetLastError(ERROR_INVALID_PARAMETER
);
3230 StringSecurityDescriptor
= lptoken
;
3239 /******************************************************************************
3240 * ConvertStringSecurityDescriptorToSecurityDescriptorA [ADVAPI32.@]
3242 BOOL WINAPI
ConvertStringSecurityDescriptorToSecurityDescriptorA(
3243 LPCSTR StringSecurityDescriptor
,
3244 DWORD StringSDRevision
,
3245 PSECURITY_DESCRIPTOR
* SecurityDescriptor
,
3246 PULONG SecurityDescriptorSize
)
3250 LPWSTR StringSecurityDescriptorW
;
3252 len
= MultiByteToWideChar(CP_ACP
, 0, StringSecurityDescriptor
, -1, NULL
, 0);
3253 StringSecurityDescriptorW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3255 if (StringSecurityDescriptorW
)
3257 MultiByteToWideChar(CP_ACP
, 0, StringSecurityDescriptor
, -1, StringSecurityDescriptorW
, len
);
3259 ret
= ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptorW
,
3260 StringSDRevision
, SecurityDescriptor
,
3261 SecurityDescriptorSize
);
3262 HeapFree(GetProcessHeap(), 0, StringSecurityDescriptorW
);
3268 /******************************************************************************
3269 * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
3271 BOOL WINAPI
ConvertStringSecurityDescriptorToSecurityDescriptorW(
3272 LPCWSTR StringSecurityDescriptor
,
3273 DWORD StringSDRevision
,
3274 PSECURITY_DESCRIPTOR
* SecurityDescriptor
,
3275 PULONG SecurityDescriptorSize
)
3278 SECURITY_DESCRIPTOR
* psd
;
3281 TRACE("%s\n", debugstr_w(StringSecurityDescriptor
));
3283 if (GetVersion() & 0x80000000)
3285 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3288 else if (StringSDRevision
!= SID_REVISION
)
3290 SetLastError(ERROR_UNKNOWN_REVISION
);
3294 /* Compute security descriptor length */
3295 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor
,
3299 psd
= *SecurityDescriptor
= (SECURITY_DESCRIPTOR
*) LocalAlloc(
3300 GMEM_ZEROINIT
, cBytes
);
3302 psd
->Revision
= SID_REVISION
;
3303 psd
->Control
|= SE_SELF_RELATIVE
;
3305 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor
,
3312 if (SecurityDescriptorSize
)
3313 *SecurityDescriptorSize
= cBytes
;
3318 TRACE(" ret=%d\n", bret
);
3322 /******************************************************************************
3323 * ConvertStringSidToSidW [ADVAPI32.@]
3325 BOOL WINAPI
ConvertStringSidToSidW(LPCWSTR StringSid
, PSID
* Sid
)
3330 TRACE("%s, %p\n", debugstr_w(StringSid
), Sid
);
3331 if (GetVersion() & 0x80000000)
3332 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3333 else if (!StringSid
|| !Sid
)
3334 SetLastError(ERROR_INVALID_PARAMETER
);
3335 else if (ParseStringSidToSid(StringSid
, NULL
, &cBytes
))
3337 PSID pSid
= *Sid
= (PSID
) LocalAlloc(0, cBytes
);
3339 bret
= ParseStringSidToSid(StringSid
, pSid
, &cBytes
);
3343 TRACE("returning %s\n", bret
? "TRUE" : "FALSE");
3347 /******************************************************************************
3348 * ConvertStringSidToSidA [ADVAPI32.@]
3350 BOOL WINAPI
ConvertStringSidToSidA(LPCSTR StringSid
, PSID
* Sid
)
3354 TRACE("%s, %p\n", debugstr_a(StringSid
), Sid
);
3355 if (GetVersion() & 0x80000000)
3356 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3357 else if (!StringSid
|| !Sid
)
3358 SetLastError(ERROR_INVALID_PARAMETER
);
3361 UINT len
= MultiByteToWideChar(CP_ACP
, 0, StringSid
, -1, NULL
, 0);
3362 LPWSTR wStringSid
= HeapAlloc(GetProcessHeap(), 0,
3363 len
* sizeof(WCHAR
));
3365 MultiByteToWideChar(CP_ACP
, 0, StringSid
, -1, wStringSid
, len
);
3366 bret
= ConvertStringSidToSidW(wStringSid
, Sid
);
3367 HeapFree(GetProcessHeap(), 0, wStringSid
);
3369 TRACE("returning %s\n", bret
? "TRUE" : "FALSE");
3373 /******************************************************************************
3374 * ConvertSidToStringSidW [ADVAPI32.@]
3376 * format of SID string is:
3377 * S-<count>-<auth>-<subauth1>-<subauth2>-<subauth3>...
3379 * <rev> is the revision of the SID encoded as decimal
3380 * <auth> is the identifier authority encoded as hex
3381 * <subauthN> is the subauthority id encoded as decimal
3383 BOOL WINAPI
ConvertSidToStringSidW( PSID pSid
, LPWSTR
*pstr
)
3387 WCHAR fmt
[] = { 'S','-','%','u','-','%','d',0 };
3388 WCHAR subauthfmt
[] = { '-','%','u',0 };
3391 TRACE("%p %p\n", pSid
, pstr
);
3393 if( !IsValidSid( pSid
) )
3396 if (pisid
->Revision
!= SDDL_REVISION
)
3398 if (pisid
->IdentifierAuthority
.Value
[0] ||
3399 pisid
->IdentifierAuthority
.Value
[1])
3401 FIXME("not matching MS' bugs\n");
3405 sz
= 14 + pisid
->SubAuthorityCount
* 11;
3406 str
= LocalAlloc( 0, sz
*sizeof(WCHAR
) );
3407 sprintfW( str
, fmt
, pisid
->Revision
, MAKELONG(
3408 MAKEWORD( pisid
->IdentifierAuthority
.Value
[5],
3409 pisid
->IdentifierAuthority
.Value
[4] ),
3410 MAKEWORD( pisid
->IdentifierAuthority
.Value
[3],
3411 pisid
->IdentifierAuthority
.Value
[2] ) ) );
3412 for( i
=0; i
<pisid
->SubAuthorityCount
; i
++ )
3413 sprintfW( str
+ strlenW(str
), subauthfmt
, pisid
->SubAuthority
[i
] );
3419 /******************************************************************************
3420 * ConvertSidToStringSidA [ADVAPI32.@]
3422 BOOL WINAPI
ConvertSidToStringSidA(PSID pSid
, LPSTR
*pstr
)
3428 TRACE("%p %p\n", pSid
, pstr
);
3430 if( !ConvertSidToStringSidW( pSid
, &wstr
) )
3433 len
= WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
3434 str
= LocalAlloc( 0, len
);
3435 WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, str
, len
, NULL
, NULL
);
3443 BOOL WINAPI
CreatePrivateObjectSecurity(
3444 PSECURITY_DESCRIPTOR ParentDescriptor
,
3445 PSECURITY_DESCRIPTOR CreatorDescriptor
,
3446 PSECURITY_DESCRIPTOR
* NewDescriptor
,
3447 BOOL IsDirectoryObject
,
3449 PGENERIC_MAPPING GenericMapping
)
3451 FIXME("%p %p %p %d %p %p - stub\n", ParentDescriptor
, CreatorDescriptor
,
3452 NewDescriptor
, IsDirectoryObject
, Token
, GenericMapping
);
3457 BOOL WINAPI
DestroyPrivateObjectSecurity( PSECURITY_DESCRIPTOR
* ObjectDescriptor
)
3459 FIXME("%p - stub\n", ObjectDescriptor
);
3464 BOOL WINAPI
CreateProcessAsUserA(
3466 LPCSTR lpApplicationName
,
3467 LPSTR lpCommandLine
,
3468 LPSECURITY_ATTRIBUTES lpProcessAttributes
,
3469 LPSECURITY_ATTRIBUTES lpThreadAttributes
,
3470 BOOL bInheritHandles
,
3471 DWORD dwCreationFlags
,
3472 LPVOID lpEnvironment
,
3473 LPCSTR lpCurrentDirectory
,
3474 LPSTARTUPINFOA lpStartupInfo
,
3475 LPPROCESS_INFORMATION lpProcessInformation
)
3477 FIXME("%p %s %s %p %p %d 0x%08lx %p %s %p %p - stub\n", hToken
, debugstr_a(lpApplicationName
),
3478 debugstr_a(lpCommandLine
), lpProcessAttributes
, lpThreadAttributes
, bInheritHandles
,
3479 dwCreationFlags
, lpEnvironment
, debugstr_a(lpCurrentDirectory
), lpStartupInfo
, lpProcessInformation
);
3484 BOOL WINAPI
CreateProcessAsUserW(
3486 LPCWSTR lpApplicationName
,
3487 LPWSTR lpCommandLine
,
3488 LPSECURITY_ATTRIBUTES lpProcessAttributes
,
3489 LPSECURITY_ATTRIBUTES lpThreadAttributes
,
3490 BOOL bInheritHandles
,
3491 DWORD dwCreationFlags
,
3492 LPVOID lpEnvironment
,
3493 LPCWSTR lpCurrentDirectory
,
3494 LPSTARTUPINFOW lpStartupInfo
,
3495 LPPROCESS_INFORMATION lpProcessInformation
)
3497 FIXME("%p %s %s %p %p %d 0x%08lx %p %s %p %p - semi- stub\n", hToken
,
3498 debugstr_w(lpApplicationName
), debugstr_w(lpCommandLine
), lpProcessAttributes
,
3499 lpThreadAttributes
, bInheritHandles
, dwCreationFlags
, lpEnvironment
,
3500 debugstr_w(lpCurrentDirectory
), lpStartupInfo
, lpProcessInformation
);
3502 /* We should create the process with a suspended main thread */
3503 if (!CreateProcessW (lpApplicationName
,
3505 lpProcessAttributes
,
3508 dwCreationFlags
, /* CREATE_SUSPENDED */
3512 lpProcessInformation
))
3520 BOOL WINAPI
DuplicateTokenEx(
3521 HANDLE ExistingTokenHandle
, DWORD dwDesiredAccess
,
3522 LPSECURITY_ATTRIBUTES lpTokenAttributes
,
3523 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
3524 TOKEN_TYPE TokenType
,
3525 PHANDLE DuplicateTokenHandle
)
3527 OBJECT_ATTRIBUTES ObjectAttributes
;
3529 TRACE("%p 0x%08lx 0x%08x 0x%08x %p\n", ExistingTokenHandle
, dwDesiredAccess
,
3530 ImpersonationLevel
, TokenType
, DuplicateTokenHandle
);
3532 InitializeObjectAttributes(
3535 (lpTokenAttributes
&& lpTokenAttributes
->bInheritHandle
) ? OBJ_INHERIT
: 0,
3537 lpTokenAttributes
? lpTokenAttributes
->lpSecurityDescriptor
: NULL
);
3539 return set_ntstatus( NtDuplicateToken( ExistingTokenHandle
,
3544 DuplicateTokenHandle
) );
3547 BOOL WINAPI
DuplicateToken(
3548 HANDLE ExistingTokenHandle
,
3549 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
3550 PHANDLE DuplicateTokenHandle
)
3552 return DuplicateTokenEx( ExistingTokenHandle
, TOKEN_IMPERSONATE
| TOKEN_QUERY
,
3553 NULL
, ImpersonationLevel
, TokenImpersonation
,
3554 DuplicateTokenHandle
);
3557 BOOL WINAPI
EnumDependentServicesA(
3559 DWORD dwServiceState
,
3560 LPENUM_SERVICE_STATUSA lpServices
,
3562 LPDWORD pcbBytesNeeded
,
3563 LPDWORD lpServicesReturned
)
3565 FIXME("%p 0x%08lx %p 0x%08lx %p %p - stub\n", hService
, dwServiceState
,
3566 lpServices
, cbBufSize
, pcbBytesNeeded
, lpServicesReturned
);
3571 BOOL WINAPI
EnumDependentServicesW(
3573 DWORD dwServiceState
,
3574 LPENUM_SERVICE_STATUSW lpServices
,
3576 LPDWORD pcbBytesNeeded
,
3577 LPDWORD lpServicesReturned
)
3579 FIXME("%p 0x%08lx %p 0x%08lx %p %p - stub\n", hService
, dwServiceState
,
3580 lpServices
, cbBufSize
, pcbBytesNeeded
, lpServicesReturned
);
3585 /******************************************************************************
3586 * ComputeStringSidSize
3588 static DWORD
ComputeStringSidSize(LPCWSTR StringSid
)
3590 DWORD size
= sizeof(SID
);
3592 if (StringSid
[0] == 'S' && StringSid
[1] == '-') /* S-R-I-S-S */
3597 if (*StringSid
== '-')
3603 size
+= (ctok
- 3) * sizeof(DWORD
);
3605 else /* String constant format - Only available in winxp and above */
3609 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
3610 if (!strncmpW(WellKnownSids
[i
].wstr
, StringSid
, 2))
3611 size
+= (WellKnownSids
[i
].Sid
.SubAuthorityCount
- 1) * sizeof(DWORD
);
3617 /******************************************************************************
3618 * ParseStringSidToSid
3620 static BOOL
ParseStringSidToSid(LPCWSTR StringSid
, PSID pSid
, LPDWORD cBytes
)
3625 TRACE("%s, %p, %p\n", debugstr_w(StringSid
), pSid
, cBytes
);
3628 SetLastError(ERROR_INVALID_PARAMETER
);
3629 TRACE("StringSid is NULL, returning FALSE\n");
3633 *cBytes
= ComputeStringSidSize(StringSid
);
3634 if (!pisid
) /* Simply compute the size */
3636 TRACE("only size requested, returning TRUE\n");
3640 if (StringSid
[0] == 'S' && StringSid
[1] == '-') /* S-R-I-S-S */
3642 DWORD i
= 0, identAuth
;
3643 DWORD csubauth
= ((*cBytes
- sizeof(SID
)) / sizeof(DWORD
)) + 1;
3645 StringSid
+= 2; /* Advance to Revision */
3646 pisid
->Revision
= atoiW(StringSid
);
3648 if (pisid
->Revision
!= SDDL_REVISION
)
3650 TRACE("Revision %d is unknown\n", pisid
->Revision
);
3651 goto lend
; /* ERROR_INVALID_SID */
3655 TRACE("SubAuthorityCount is 0\n");
3656 goto lend
; /* ERROR_INVALID_SID */
3659 pisid
->SubAuthorityCount
= csubauth
;
3661 /* Advance to identifier authority */
3662 while (*StringSid
&& *StringSid
!= '-')
3664 if (*StringSid
== '-')
3667 /* MS' implementation can't handle values greater than 2^32 - 1, so
3668 * we don't either; assume most significant bytes are always 0
3670 pisid
->IdentifierAuthority
.Value
[0] = 0;
3671 pisid
->IdentifierAuthority
.Value
[1] = 0;
3672 identAuth
= atoiW(StringSid
);
3673 pisid
->IdentifierAuthority
.Value
[5] = identAuth
& 0xff;
3674 pisid
->IdentifierAuthority
.Value
[4] = (identAuth
& 0xff00) >> 8;
3675 pisid
->IdentifierAuthority
.Value
[3] = (identAuth
& 0xff0000) >> 16;
3676 pisid
->IdentifierAuthority
.Value
[2] = (identAuth
& 0xff000000) >> 24;
3678 /* Advance to first sub authority */
3679 while (*StringSid
&& *StringSid
!= '-')
3681 if (*StringSid
== '-')
3686 while (*StringSid
&& *StringSid
!= '-')
3688 if (*StringSid
== '-')
3691 pisid
->SubAuthority
[i
++] = atoiW(StringSid
);
3694 if (i
!= pisid
->SubAuthorityCount
)
3695 goto lend
; /* ERROR_INVALID_SID */
3699 else /* String constant format - Only available in winxp and above */
3702 pisid
->Revision
= SDDL_REVISION
;
3704 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
3705 if (!strncmpW(WellKnownSids
[i
].wstr
, StringSid
, 2))
3708 pisid
->SubAuthorityCount
= WellKnownSids
[i
].Sid
.SubAuthorityCount
;
3709 pisid
->IdentifierAuthority
= WellKnownSids
[i
].Sid
.IdentifierAuthority
;
3710 for (j
= 0; j
< WellKnownSids
[i
].Sid
.SubAuthorityCount
; j
++)
3711 pisid
->SubAuthority
[j
] = WellKnownSids
[i
].Sid
.SubAuthority
[j
];
3716 FIXME("String constant not supported: %s\n", debugstr_wn(StringSid
, 2));
3721 SetLastError(ERROR_INVALID_SID
);
3723 TRACE("returning %s\n", bret
? "TRUE" : "FALSE");
3727 /******************************************************************************
3728 * GetNamedSecurityInfoA [ADVAPI32.@]
3730 DWORD WINAPI
GetNamedSecurityInfoA(LPSTR pObjectName
,
3731 SE_OBJECT_TYPE ObjectType
, SECURITY_INFORMATION SecurityInfo
,
3732 PSID
* ppsidOwner
, PSID
* ppsidGroup
, PACL
* ppDacl
, PACL
* ppSacl
,
3733 PSECURITY_DESCRIPTOR
* ppSecurityDescriptor
)
3739 TRACE("%s %d %ld %p %p %p %p %p\n", pObjectName
, ObjectType
, SecurityInfo
,
3740 ppsidOwner
, ppsidGroup
, ppDacl
, ppSacl
, ppSecurityDescriptor
);
3744 len
= MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, NULL
, 0 );
3745 wstr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
3746 MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, wstr
, len
);
3749 r
= GetNamedSecurityInfoW( wstr
, ObjectType
, SecurityInfo
, ppsidOwner
,
3750 ppsidGroup
, ppDacl
, ppSacl
, ppSecurityDescriptor
);
3752 HeapFree( GetProcessHeap(), 0, wstr
);
3757 /******************************************************************************
3758 * GetNamedSecurityInfoW [ADVAPI32.@]
3760 DWORD WINAPI
GetNamedSecurityInfoW( LPWSTR name
, SE_OBJECT_TYPE type
,
3761 SECURITY_INFORMATION info
, PSID
* owner
, PSID
* group
, PACL
* dacl
,
3762 PACL
* sacl
, PSECURITY_DESCRIPTOR
* descriptor
)
3764 DWORD needed
, offset
;
3765 SECURITY_DESCRIPTOR_RELATIVE
*relative
;
3768 TRACE( "%s %d %ld %p %p %p %p %p\n", debugstr_w(name
), type
, info
, owner
,
3769 group
, dacl
, sacl
, descriptor
);
3771 if (!name
|| !descriptor
) return ERROR_INVALID_PARAMETER
;
3773 needed
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
3774 if (info
& OWNER_SECURITY_INFORMATION
)
3775 needed
+= sizeof(sidWorld
);
3776 if (info
& GROUP_SECURITY_INFORMATION
)
3777 needed
+= sizeof(sidWorld
);
3778 if (info
& DACL_SECURITY_INFORMATION
)
3779 needed
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
3780 if (info
& SACL_SECURITY_INFORMATION
)
3781 needed
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
3783 /* must be freed by caller */
3784 *descriptor
= HeapAlloc( GetProcessHeap(), 0, needed
);
3785 if (!*descriptor
) return ERROR_NOT_ENOUGH_MEMORY
;
3787 if (!InitializeSecurityDescriptor( *descriptor
, SECURITY_DESCRIPTOR_REVISION
))
3789 HeapFree( GetProcessHeap(), 0, *descriptor
);
3790 return ERROR_INVALID_SECURITY_DESCR
;
3793 relative
= (SECURITY_DESCRIPTOR_RELATIVE
*)*descriptor
;
3794 relative
->Control
|= SE_SELF_RELATIVE
;
3795 buffer
= (BYTE
*)relative
;
3796 offset
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
3798 if (owner
&& (info
& OWNER_SECURITY_INFORMATION
))
3800 memcpy( buffer
+ offset
, &sidWorld
, sizeof(sidWorld
) );
3801 relative
->Owner
= offset
;
3802 *owner
= buffer
+ offset
;
3803 offset
+= sizeof(sidWorld
);
3805 if (group
&& (info
& GROUP_SECURITY_INFORMATION
))
3807 memcpy( buffer
+ offset
, &sidWorld
, sizeof(sidWorld
) );
3808 relative
->Group
= offset
;
3809 *group
= buffer
+ offset
;
3810 offset
+= sizeof(sidWorld
);
3812 if (dacl
&& (info
& DACL_SECURITY_INFORMATION
))
3814 GetWorldAccessACL( (PACL
)(buffer
+ offset
) );
3815 relative
->Dacl
= offset
;
3816 *dacl
= (PACL
)(buffer
+ offset
);
3817 offset
+= WINE_SIZE_OF_WORLD_ACCESS_ACL
;
3819 if (sacl
&& (info
& SACL_SECURITY_INFORMATION
))
3821 GetWorldAccessACL( (PACL
)(buffer
+ offset
) );
3822 relative
->Sacl
= offset
;
3823 *sacl
= (PACL
)(buffer
+ offset
);
3825 return ERROR_SUCCESS
;
3828 /******************************************************************************
3829 * DecryptFileW [ADVAPI32.@]
3831 BOOL WINAPI
DecryptFileW(LPCWSTR lpFileName
, DWORD dwReserved
)
3833 FIXME("%s %08lx\n", debugstr_w(lpFileName
), dwReserved
);
3837 /******************************************************************************
3838 * DecryptFileA [ADVAPI32.@]
3840 BOOL WINAPI
DecryptFileA(LPCSTR lpFileName
, DWORD dwReserved
)
3842 FIXME("%s %08lx\n", debugstr_a(lpFileName
), dwReserved
);
3846 /******************************************************************************
3847 * EncryptFileW [ADVAPI32.@]
3849 BOOL WINAPI
EncryptFileW(LPCWSTR lpFileName
)
3851 FIXME("%s\n", debugstr_w(lpFileName
));
3855 /******************************************************************************
3856 * EncryptFileA [ADVAPI32.@]
3858 BOOL WINAPI
EncryptFileA(LPCSTR lpFileName
)
3860 FIXME("%s\n", debugstr_a(lpFileName
));
3864 /******************************************************************************
3865 * FileEncryptionStatusW [ADVAPI32.@]
3867 BOOL WINAPI
FileEncryptionStatusW(LPCWSTR lpFileName
, LPDWORD lpStatus
)
3869 FIXME("(%s %p): stub\n", debugstr_w(lpFileName
), lpStatus
);
3872 *lpStatus
= FILE_SYSTEM_NOT_SUPPORT
;
3876 /******************************************************************************
3877 * FileEncryptionStatusA [ADVAPI32.@]
3879 BOOL WINAPI
FileEncryptionStatusA(LPCSTR lpFileName
, LPDWORD lpStatus
)
3881 FIXME("(%s %p): stub\n", debugstr_a(lpFileName
), lpStatus
);
3884 *lpStatus
= FILE_SYSTEM_NOT_SUPPORT
;
3888 /******************************************************************************
3889 * SetSecurityInfo [ADVAPI32.@]
3891 DWORD WINAPI
SetSecurityInfo(HANDLE handle
, SE_OBJECT_TYPE ObjectType
,
3892 SECURITY_INFORMATION SecurityInfo
, PSID psidOwner
,
3893 PSID psidGroup
, PACL pDacl
, PACL pSacl
) {
3895 return ERROR_SUCCESS
;