2 * COPYRIGHT: See COPYING in the top level directory
4 * Copyright 1999, 2000 Juergen Schmied <juergen.schmied@debitel.net>
5 * Copyright 2003 CodeWeavers Inc. (Ulrich Czekalla)
6 * Copyright 2006 Robert Reif
7 * Copyright 2006 Hervé Poussineau
9 * PROJECT: ReactOS system libraries
10 * FILE: dll/win32/advapi32/wine/security.c
17 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
19 static DWORD
ComputeStringSidSize(LPCWSTR StringSid
);
20 static BOOL
ParseStringSidToSid(LPCWSTR StringSid
, PSID pSid
, LPDWORD cBytes
);
22 #define MAX_GUID_STRING_LEN 39
25 AddAuditAccessAceEx(PACL pAcl
,
40 typedef struct _MAX_SID
42 /* same fields as struct _SID */
44 BYTE SubAuthorityCount
;
45 SID_IDENTIFIER_AUTHORITY IdentifierAuthority
;
46 DWORD SubAuthority
[SID_MAX_SUB_AUTHORITIES
];
49 typedef struct WELLKNOWNSID
52 WELL_KNOWN_SID_TYPE Type
;
56 typedef struct _ACEFLAG
60 } ACEFLAG
, *LPACEFLAG
;
62 static const WELLKNOWNSID WellKnownSids
[] =
64 { {0,0}, WinNullSid
, { SID_REVISION
, 1, { SECURITY_NULL_SID_AUTHORITY
}, { SECURITY_NULL_RID
} } },
65 { {'W','D'}, WinWorldSid
, { SID_REVISION
, 1, { SECURITY_WORLD_SID_AUTHORITY
}, { SECURITY_WORLD_RID
} } },
66 { {0,0}, WinLocalSid
, { SID_REVISION
, 1, { SECURITY_LOCAL_SID_AUTHORITY
}, { SECURITY_LOCAL_RID
} } },
67 { {'C','O'}, WinCreatorOwnerSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_OWNER_RID
} } },
68 { {'C','G'}, WinCreatorGroupSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_GROUP_RID
} } },
69 { {0,0}, WinCreatorOwnerServerSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_OWNER_SERVER_RID
} } },
70 { {0,0}, WinCreatorGroupServerSid
, { SID_REVISION
, 1, { SECURITY_CREATOR_SID_AUTHORITY
}, { SECURITY_CREATOR_GROUP_SERVER_RID
} } },
71 { {0,0}, WinNtAuthoritySid
, { SID_REVISION
, 0, { SECURITY_NT_AUTHORITY
}, { SECURITY_NULL_RID
} } },
72 { {0,0}, WinDialupSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_DIALUP_RID
} } },
73 { {'N','U'}, WinNetworkSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_NETWORK_RID
} } },
74 { {0,0}, WinBatchSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_BATCH_RID
} } },
75 { {'I','U'}, WinInteractiveSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_INTERACTIVE_RID
} } },
76 { {'S','U'}, WinServiceSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_SERVICE_RID
} } },
77 { {'A','N'}, WinAnonymousSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_ANONYMOUS_LOGON_RID
} } },
78 { {0,0}, WinProxySid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_PROXY_RID
} } },
79 { {'E','D'}, WinEnterpriseControllersSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_ENTERPRISE_CONTROLLERS_RID
} } },
80 { {'P','S'}, WinSelfSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_PRINCIPAL_SELF_RID
} } },
81 { {'A','U'}, WinAuthenticatedUserSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_AUTHENTICATED_USER_RID
} } },
82 { {'R','C'}, WinRestrictedCodeSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_RESTRICTED_CODE_RID
} } },
83 { {0,0}, WinTerminalServerSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_TERMINAL_SERVER_RID
} } },
84 { {0,0}, WinRemoteLogonIdSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_REMOTE_LOGON_RID
} } },
85 { {'S','Y'}, WinLocalSystemSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_LOCAL_SYSTEM_RID
} } },
86 { {'L','S'}, WinLocalServiceSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_LOCAL_SERVICE_RID
} } },
87 { {'N','S'}, WinNetworkServiceSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_NETWORK_SERVICE_RID
} } },
88 { {0,0}, WinBuiltinDomainSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
} } },
89 { {'B','A'}, WinBuiltinAdministratorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_ADMINS
} } },
90 { {'B','U'}, WinBuiltinUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_USERS
} } },
91 { {'B','G'}, WinBuiltinGuestsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_GUESTS
} } },
92 { {'P','U'}, WinBuiltinPowerUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_POWER_USERS
} } },
93 { {'A','O'}, WinBuiltinAccountOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_ACCOUNT_OPS
} } },
94 { {'S','O'}, WinBuiltinSystemOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_SYSTEM_OPS
} } },
95 { {'P','O'}, WinBuiltinPrintOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_PRINT_OPS
} } },
96 { {'B','O'}, WinBuiltinBackupOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_BACKUP_OPS
} } },
97 { {'R','E'}, WinBuiltinReplicatorSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_REPLICATOR
} } },
98 { {'R','U'}, WinBuiltinPreWindows2000CompatibleAccessSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_PREW2KCOMPACCESS
} } },
99 { {'R','D'}, WinBuiltinRemoteDesktopUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS
} } },
100 { {'N','O'}, WinBuiltinNetworkConfigurationOperatorsSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS
} } },
101 { {0,0}, WinNTLMAuthenticationSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_PACKAGE_BASE_RID
, SECURITY_PACKAGE_NTLM_RID
} } },
102 { {0,0}, WinDigestAuthenticationSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_PACKAGE_BASE_RID
, SECURITY_PACKAGE_DIGEST_RID
} } },
103 { {0,0}, WinSChannelAuthenticationSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_PACKAGE_BASE_RID
, SECURITY_PACKAGE_SCHANNEL_RID
} } },
104 { {0,0}, WinThisOrganizationSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_THIS_ORGANIZATION_RID
} } },
105 { {0,0}, WinOtherOrganizationSid
, { SID_REVISION
, 1, { SECURITY_NT_AUTHORITY
}, { SECURITY_OTHER_ORGANIZATION_RID
} } },
106 { {0,0}, WinBuiltinIncomingForestTrustBuildersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_INCOMING_FOREST_TRUST_BUILDERS
} } },
107 { {0,0}, WinBuiltinPerfMonitoringUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_MONITORING_USERS
} } },
108 { {0,0}, WinBuiltinPerfLoggingUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_LOGGING_USERS
} } },
109 { {0,0}, WinBuiltinAuthorizationAccessSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_AUTHORIZATIONACCESS
} } },
110 { {0,0}, WinBuiltinTerminalServerLicenseServersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_TS_LICENSE_SERVERS
} } },
111 { {0,0}, WinBuiltinDCOMUsersSid
, { SID_REVISION
, 2, { SECURITY_NT_AUTHORITY
}, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_DCOM_USERS
} } },
112 { {'L','W'}, WinLowLabelSid
, { SID_REVISION
, 1, { SECURITY_MANDATORY_LABEL_AUTHORITY
}, { SECURITY_MANDATORY_LOW_RID
} } },
113 { {'M','E'}, WinMediumLabelSid
, { SID_REVISION
, 1, { SECURITY_MANDATORY_LABEL_AUTHORITY
}, { SECURITY_MANDATORY_MEDIUM_RID
} } },
114 { {'H','I'}, WinHighLabelSid
, { SID_REVISION
, 1, { SECURITY_MANDATORY_LABEL_AUTHORITY
}, { SECURITY_MANDATORY_HIGH_RID
} } },
115 { {'S','I'}, WinSystemLabelSid
, { SID_REVISION
, 1, { SECURITY_MANDATORY_LABEL_AUTHORITY
}, { SECURITY_MANDATORY_SYSTEM_RID
} } },
118 typedef struct WELLKNOWNRID
120 WELL_KNOWN_SID_TYPE Type
;
124 static const WELLKNOWNRID WellKnownRids
[] = {
125 { WinAccountAdministratorSid
, DOMAIN_USER_RID_ADMIN
},
126 { WinAccountGuestSid
, DOMAIN_USER_RID_GUEST
},
127 { WinAccountKrbtgtSid
, DOMAIN_USER_RID_KRBTGT
},
128 { WinAccountDomainAdminsSid
, DOMAIN_GROUP_RID_ADMINS
},
129 { WinAccountDomainUsersSid
, DOMAIN_GROUP_RID_USERS
},
130 { WinAccountDomainGuestsSid
, DOMAIN_GROUP_RID_GUESTS
},
131 { WinAccountComputersSid
, DOMAIN_GROUP_RID_COMPUTERS
},
132 { WinAccountControllersSid
, DOMAIN_GROUP_RID_CONTROLLERS
},
133 { WinAccountCertAdminsSid
, DOMAIN_GROUP_RID_CERT_ADMINS
},
134 { WinAccountSchemaAdminsSid
, DOMAIN_GROUP_RID_SCHEMA_ADMINS
},
135 { WinAccountEnterpriseAdminsSid
, DOMAIN_GROUP_RID_ENTERPRISE_ADMINS
},
136 { WinAccountPolicyAdminsSid
, DOMAIN_GROUP_RID_POLICY_ADMINS
},
137 { WinAccountRasAndIasServersSid
, DOMAIN_ALIAS_RID_RAS_SERVERS
},
140 static const SID sidWorld
= { SID_REVISION
, 1, { SECURITY_WORLD_SID_AUTHORITY
} , { SECURITY_WORLD_RID
} };
145 static const WCHAR SDDL_ACCESS_ALLOWED
[] = {'A',0};
146 static const WCHAR SDDL_ACCESS_DENIED
[] = {'D',0};
147 static const WCHAR SDDL_OBJECT_ACCESS_ALLOWED
[] = {'O','A',0};
148 static const WCHAR SDDL_OBJECT_ACCESS_DENIED
[] = {'O','D',0};
149 static const WCHAR SDDL_AUDIT
[] = {'A','U',0};
150 static const WCHAR SDDL_ALARM
[] = {'A','L',0};
151 static const WCHAR SDDL_OBJECT_AUDIT
[] = {'O','U',0};
152 static const WCHAR SDDL_OBJECT_ALARM
[] = {'O','L',0};
157 #define ADS_RIGHT_DS_CREATE_CHILD 0x0001
158 #define ADS_RIGHT_DS_DELETE_CHILD 0x0002
159 #define ADS_RIGHT_ACTRL_DS_LIST 0x0004
160 #define ADS_RIGHT_DS_SELF 0x0008
161 #define ADS_RIGHT_DS_READ_PROP 0x0010
162 #define ADS_RIGHT_DS_WRITE_PROP 0x0020
163 #define ADS_RIGHT_DS_DELETE_TREE 0x0040
164 #define ADS_RIGHT_DS_LIST_OBJECT 0x0080
165 #define ADS_RIGHT_DS_CONTROL_ACCESS 0x0100
170 static const WCHAR SDDL_CONTAINER_INHERIT
[] = {'C','I',0};
171 static const WCHAR SDDL_OBJECT_INHERIT
[] = {'O','I',0};
172 static const WCHAR SDDL_NO_PROPAGATE
[] = {'N','P',0};
173 static const WCHAR SDDL_INHERIT_ONLY
[] = {'I','O',0};
174 static const WCHAR SDDL_INHERITED
[] = {'I','D',0};
175 static const WCHAR SDDL_AUDIT_SUCCESS
[] = {'S','A',0};
176 static const WCHAR SDDL_AUDIT_FAILURE
[] = {'F','A',0};
178 static const char * debugstr_sid(PSID sid
)
181 SID
* psid
= (SID
*)sid
;
186 auth
= psid
->IdentifierAuthority
.Value
[5] +
187 (psid
->IdentifierAuthority
.Value
[4] << 8) +
188 (psid
->IdentifierAuthority
.Value
[3] << 16) +
189 (psid
->IdentifierAuthority
.Value
[2] << 24);
191 switch (psid
->SubAuthorityCount
) {
193 return wine_dbg_sprintf("S-%d-%d", psid
->Revision
, auth
);
195 return wine_dbg_sprintf("S-%d-%d-%lu", psid
->Revision
, auth
,
196 psid
->SubAuthority
[0]);
198 return wine_dbg_sprintf("S-%d-%d-%lu-%lu", psid
->Revision
, auth
,
199 psid
->SubAuthority
[0], psid
->SubAuthority
[1]);
201 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu", psid
->Revision
, auth
,
202 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2]);
204 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu-%lu", psid
->Revision
, auth
,
205 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
206 psid
->SubAuthority
[3]);
208 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu-%lu-%lu", psid
->Revision
, auth
,
209 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
210 psid
->SubAuthority
[3], psid
->SubAuthority
[4]);
212 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu-%lu-%lu-%lu", psid
->Revision
, auth
,
213 psid
->SubAuthority
[3], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
214 psid
->SubAuthority
[0], psid
->SubAuthority
[4], psid
->SubAuthority
[5]);
216 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu-%lu-%lu-%lu-%lu", psid
->Revision
, auth
,
217 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
218 psid
->SubAuthority
[3], psid
->SubAuthority
[4], psid
->SubAuthority
[5],
219 psid
->SubAuthority
[6]);
221 return wine_dbg_sprintf("S-%d-%d-%lu-%lu-%lu-%lu-%lu-%lu-%lu-%lu", psid
->Revision
, auth
,
222 psid
->SubAuthority
[0], psid
->SubAuthority
[1], psid
->SubAuthority
[2],
223 psid
->SubAuthority
[3], psid
->SubAuthority
[4], psid
->SubAuthority
[5],
224 psid
->SubAuthority
[6], psid
->SubAuthority
[7]);
229 static const ACEFLAG AceRights
[] =
231 { SDDL_GENERIC_ALL
, GENERIC_ALL
},
232 { SDDL_GENERIC_READ
, GENERIC_READ
},
233 { SDDL_GENERIC_WRITE
, GENERIC_WRITE
},
234 { SDDL_GENERIC_EXECUTE
, GENERIC_EXECUTE
},
236 { SDDL_READ_CONTROL
, READ_CONTROL
},
237 { SDDL_STANDARD_DELETE
, DELETE
},
238 { SDDL_WRITE_DAC
, WRITE_DAC
},
239 { SDDL_WRITE_OWNER
, WRITE_OWNER
},
241 { SDDL_READ_PROPERTY
, ADS_RIGHT_DS_READ_PROP
},
242 { SDDL_WRITE_PROPERTY
, ADS_RIGHT_DS_WRITE_PROP
},
243 { SDDL_CREATE_CHILD
, ADS_RIGHT_DS_CREATE_CHILD
},
244 { SDDL_DELETE_CHILD
, ADS_RIGHT_DS_DELETE_CHILD
},
245 { SDDL_LIST_CHILDREN
, ADS_RIGHT_ACTRL_DS_LIST
},
246 { SDDL_SELF_WRITE
, ADS_RIGHT_DS_SELF
},
247 { SDDL_LIST_OBJECT
, ADS_RIGHT_DS_LIST_OBJECT
},
248 { SDDL_DELETE_TREE
, ADS_RIGHT_DS_DELETE_TREE
},
249 { SDDL_CONTROL_ACCESS
, ADS_RIGHT_DS_CONTROL_ACCESS
},
251 { SDDL_FILE_ALL
, FILE_ALL_ACCESS
},
252 { SDDL_FILE_READ
, FILE_GENERIC_READ
},
253 { SDDL_FILE_WRITE
, FILE_GENERIC_WRITE
},
254 { SDDL_FILE_EXECUTE
, FILE_GENERIC_EXECUTE
},
256 { SDDL_KEY_ALL
, KEY_ALL_ACCESS
},
257 { SDDL_KEY_READ
, KEY_READ
},
258 { SDDL_KEY_WRITE
, KEY_WRITE
},
259 { SDDL_KEY_EXECUTE
, KEY_EXECUTE
},
263 /* set last error code from NT status and get the proper boolean return value */
264 /* used for functions that are a simple wrapper around the corresponding ntdll API */
265 static __inline BOOL
set_ntstatus( NTSTATUS status
)
267 if (status
) SetLastError( RtlNtStatusToDosError( status
));
271 static const RECORD SidTable
[] =
273 { SDDL_ACCOUNT_OPERATORS
, WinBuiltinAccountOperatorsSid
},
274 { SDDL_ALIAS_PREW2KCOMPACC
, WinBuiltinPreWindows2000CompatibleAccessSid
},
275 { SDDL_ANONYMOUS
, WinAnonymousSid
},
276 { SDDL_AUTHENTICATED_USERS
, WinAuthenticatedUserSid
},
277 { SDDL_BUILTIN_ADMINISTRATORS
, WinBuiltinAdministratorsSid
},
278 { SDDL_BUILTIN_GUESTS
, WinBuiltinGuestsSid
},
279 { SDDL_BACKUP_OPERATORS
, WinBuiltinBackupOperatorsSid
},
280 { SDDL_BUILTIN_USERS
, WinBuiltinUsersSid
},
281 { SDDL_CERT_SERV_ADMINISTRATORS
, WinAccountCertAdminsSid
/* FIXME: DOMAIN_GROUP_RID_CERT_ADMINS */ },
282 { SDDL_CREATOR_GROUP
, WinCreatorGroupSid
},
283 { SDDL_CREATOR_OWNER
, WinCreatorOwnerSid
},
284 { SDDL_DOMAIN_ADMINISTRATORS
, WinAccountDomainAdminsSid
/* FIXME: DOMAIN_GROUP_RID_ADMINS */ },
285 { SDDL_DOMAIN_COMPUTERS
, WinAccountComputersSid
/* FIXME: DOMAIN_GROUP_RID_COMPUTERS */ },
286 { SDDL_DOMAIN_DOMAIN_CONTROLLERS
, WinAccountControllersSid
/* FIXME: DOMAIN_GROUP_RID_CONTROLLERS */ },
287 { SDDL_DOMAIN_GUESTS
, WinAccountDomainGuestsSid
/* FIXME: DOMAIN_GROUP_RID_GUESTS */ },
288 { SDDL_DOMAIN_USERS
, WinAccountDomainUsersSid
/* FIXME: DOMAIN_GROUP_RID_USERS */ },
289 { SDDL_ENTERPRISE_ADMINS
, WinAccountEnterpriseAdminsSid
/* FIXME: DOMAIN_GROUP_RID_ENTERPRISE_ADMINS */ },
290 { SDDL_ENTERPRISE_DOMAIN_CONTROLLERS
, WinEnterpriseControllersSid
},
291 { SDDL_EVERYONE
, WinWorldSid
},
292 { SDDL_GROUP_POLICY_ADMINS
, WinAccountPolicyAdminsSid
/* FIXME: DOMAIN_GROUP_RID_POLICY_ADMINS */ },
293 { SDDL_INTERACTIVE
, WinInteractiveSid
},
294 { SDDL_LOCAL_ADMIN
, WinAccountAdministratorSid
/* FIXME: DOMAIN_USER_RID_ADMIN */ },
295 { SDDL_LOCAL_GUEST
, WinAccountGuestSid
/* FIXME: DOMAIN_USER_RID_GUEST */ },
296 { SDDL_LOCAL_SERVICE
, WinLocalServiceSid
},
297 { SDDL_LOCAL_SYSTEM
, WinLocalSystemSid
},
298 { SDDL_NETWORK
, WinNetworkSid
},
299 { SDDL_NETWORK_CONFIGURATION_OPS
, WinBuiltinNetworkConfigurationOperatorsSid
},
300 { SDDL_NETWORK_SERVICE
, WinNetworkServiceSid
},
301 { SDDL_PRINTER_OPERATORS
, WinBuiltinPrintOperatorsSid
},
302 { SDDL_PERSONAL_SELF
, WinSelfSid
},
303 { SDDL_POWER_USERS
, WinBuiltinPowerUsersSid
},
304 { SDDL_RAS_SERVERS
, WinAccountRasAndIasServersSid
/* FIXME: DOMAIN_ALIAS_RID_RAS_SERVERS */ },
305 { SDDL_REMOTE_DESKTOP
, WinBuiltinRemoteDesktopUsersSid
},
306 { SDDL_REPLICATOR
, WinBuiltinReplicatorSid
},
307 { SDDL_RESTRICTED_CODE
, WinRestrictedCodeSid
},
308 { SDDL_SCHEMA_ADMINISTRATORS
, WinAccountSchemaAdminsSid
/* FIXME: DOMAIN_GROUP_RID_SCHEMA_ADMINS */ },
309 { SDDL_SERVER_OPERATORS
, WinBuiltinSystemOperatorsSid
},
310 { SDDL_SERVICE
, WinServiceSid
},
314 /************************************************************
315 * ADVAPI_IsLocalComputer
317 * Checks whether the server name indicates local machine.
319 BOOL
ADVAPI_IsLocalComputer(LPCWSTR ServerName
)
321 DWORD dwSize
= MAX_COMPUTERNAME_LENGTH
+ 1;
325 if (!ServerName
|| !ServerName
[0])
328 buf
= HeapAlloc(GetProcessHeap(), 0, dwSize
* sizeof(WCHAR
));
329 Result
= GetComputerNameW(buf
, &dwSize
);
330 if (Result
&& (ServerName
[0] == '\\') && (ServerName
[1] == '\\'))
332 Result
= Result
&& !lstrcmpW(ServerName
, buf
);
333 HeapFree(GetProcessHeap(), 0, buf
);
338 /* Exported functions */
344 OpenProcessToken(HANDLE ProcessHandle
,
350 TRACE("%p, %x, %p.\n", ProcessHandle
, DesiredAccess
, TokenHandle
);
352 Status
= NtOpenProcessToken(ProcessHandle
,
355 if (!NT_SUCCESS(Status
))
357 ERR("NtOpenProcessToken failed! Status %08x.\n", Status
);
358 SetLastError(RtlNtStatusToDosError(Status
));
362 TRACE("Returning token %p.\n", *TokenHandle
);
371 OpenThreadToken(HANDLE ThreadHandle
,
378 Status
= NtOpenThreadToken(ThreadHandle
,
382 if (!NT_SUCCESS(Status
))
384 SetLastError(RtlNtStatusToDosError(Status
));
395 AdjustTokenGroups(HANDLE TokenHandle
,
397 PTOKEN_GROUPS NewState
,
399 PTOKEN_GROUPS PreviousState
,
404 Status
= NtAdjustGroupsToken(TokenHandle
,
409 (PULONG
)ReturnLength
);
410 if (!NT_SUCCESS(Status
))
412 SetLastError(RtlNtStatusToDosError(Status
));
423 AdjustTokenPrivileges(HANDLE TokenHandle
,
424 BOOL DisableAllPrivileges
,
425 PTOKEN_PRIVILEGES NewState
,
427 PTOKEN_PRIVILEGES PreviousState
,
432 Status
= NtAdjustPrivilegesToken(TokenHandle
,
433 DisableAllPrivileges
,
437 (PULONG
)ReturnLength
);
438 if (STATUS_NOT_ALL_ASSIGNED
== Status
)
440 SetLastError(ERROR_NOT_ALL_ASSIGNED
);
444 if (!NT_SUCCESS(Status
))
446 SetLastError(RtlNtStatusToDosError(Status
));
450 /* AdjustTokenPrivileges is documented to do this */
451 SetLastError(ERROR_SUCCESS
);
460 GetTokenInformation(HANDLE TokenHandle
,
461 TOKEN_INFORMATION_CLASS TokenInformationClass
,
462 LPVOID TokenInformation
,
463 DWORD TokenInformationLength
,
468 Status
= NtQueryInformationToken(TokenHandle
,
469 TokenInformationClass
,
471 TokenInformationLength
,
472 (PULONG
)ReturnLength
);
473 if (!NT_SUCCESS(Status
))
475 SetLastError(RtlNtStatusToDosError(Status
));
486 SetTokenInformation(HANDLE TokenHandle
,
487 TOKEN_INFORMATION_CLASS TokenInformationClass
,
488 LPVOID TokenInformation
,
489 DWORD TokenInformationLength
)
493 Status
= NtSetInformationToken(TokenHandle
,
494 TokenInformationClass
,
496 TokenInformationLength
);
497 if (!NT_SUCCESS(Status
))
499 SetLastError(RtlNtStatusToDosError(Status
));
510 SetThreadToken(IN PHANDLE ThreadHandle OPTIONAL
,
511 IN HANDLE TokenHandle
)
516 hThread
= (ThreadHandle
!= NULL
) ? *ThreadHandle
: NtCurrentThread();
518 Status
= NtSetInformationThread(hThread
,
519 ThreadImpersonationToken
,
522 if (!NT_SUCCESS(Status
))
524 SetLastError(RtlNtStatusToDosError(Status
));
532 CreateRestrictedToken(HANDLE TokenHandle
,
534 DWORD DisableSidCount
,
535 PSID_AND_ATTRIBUTES pSidAndAttributes
,
536 DWORD DeletePrivilegeCount
,
537 PLUID_AND_ATTRIBUTES pLUIDAndAttributes
,
538 DWORD RestrictedSidCount
,
539 PSID_AND_ATTRIBUTES pSIDAndAttributes
,
540 PHANDLE NewTokenHandle
)
550 AllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
551 BYTE nSubAuthorityCount
,
552 DWORD dwSubAuthority0
,
553 DWORD dwSubAuthority1
,
554 DWORD dwSubAuthority2
,
555 DWORD dwSubAuthority3
,
556 DWORD dwSubAuthority4
,
557 DWORD dwSubAuthority5
,
558 DWORD dwSubAuthority6
,
559 DWORD dwSubAuthority7
,
564 Status
= RtlAllocateAndInitializeSid(pIdentifierAuthority
,
575 if (!NT_SUCCESS(Status
))
577 SetLastError(RtlNtStatusToDosError(Status
));
588 * Docs says this function does NOT return a value
589 * even thou it's defined to return a PVOID...
595 return RtlFreeSid(pSid
);
602 CopySid(DWORD nDestinationSidLength
,
603 PSID pDestinationSid
,
608 Status
= RtlCopySid(nDestinationSidLength
,
611 if (!NT_SUCCESS (Status
))
613 SetLastError(RtlNtStatusToDosError(Status
));
625 CreateWellKnownSid(IN WELL_KNOWN_SID_TYPE WellKnownSidType
,
626 IN PSID DomainSid OPTIONAL
,
631 TRACE("(%d, %s, %p, %p)\n", WellKnownSidType
, debugstr_sid(DomainSid
), pSid
, cbSid
);
633 if (cbSid
== NULL
|| (DomainSid
&& !IsValidSid(DomainSid
)))
635 SetLastError(ERROR_INVALID_PARAMETER
);
639 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++) {
640 if (WellKnownSids
[i
].Type
== WellKnownSidType
) {
641 DWORD length
= GetSidLengthRequired(WellKnownSids
[i
].Sid
.SubAuthorityCount
);
646 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
651 SetLastError(ERROR_INVALID_PARAMETER
);
654 CopyMemory(pSid
, &WellKnownSids
[i
].Sid
.Revision
, length
);
660 if (DomainSid
== NULL
|| *GetSidSubAuthorityCount(DomainSid
) == SID_MAX_SUB_AUTHORITIES
)
662 SetLastError(ERROR_INVALID_PARAMETER
);
666 for (i
= 0; i
< sizeof(WellKnownRids
)/sizeof(WellKnownRids
[0]); i
++)
667 if (WellKnownRids
[i
].Type
== WellKnownSidType
) {
668 UCHAR domain_subauth
= *GetSidSubAuthorityCount(DomainSid
);
669 DWORD domain_sid_length
= GetSidLengthRequired(domain_subauth
);
670 DWORD output_sid_length
= GetSidLengthRequired(domain_subauth
+ 1);
672 if (*cbSid
< output_sid_length
)
674 *cbSid
= output_sid_length
;
675 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
680 SetLastError(ERROR_INVALID_PARAMETER
);
683 CopyMemory(pSid
, DomainSid
, domain_sid_length
);
684 (*GetSidSubAuthorityCount(pSid
))++;
685 (*GetSidSubAuthority(pSid
, domain_subauth
)) = WellKnownRids
[i
].Rid
;
686 *cbSid
= output_sid_length
;
690 SetLastError(ERROR_INVALID_PARAMETER
);
699 IsWellKnownSid(IN PSID pSid
,
700 IN WELL_KNOWN_SID_TYPE WellKnownSidType
)
703 TRACE("(%s, %d)\n", debugstr_sid(pSid
), WellKnownSidType
);
705 for (i
= 0; i
< sizeof(WellKnownSids
) / sizeof(WellKnownSids
[0]); i
++)
707 if (WellKnownSids
[i
].Type
== WellKnownSidType
)
709 if (EqualSid(pSid
, (PSID
)(&WellKnownSids
[i
].Sid
.Revision
)))
722 IsValidSid(PSID pSid
)
724 return (BOOL
)RtlValidSid(pSid
);
735 SetLastError(ERROR_SUCCESS
);
736 return RtlEqualSid (pSid1
, pSid2
);
744 EqualPrefixSid(PSID pSid1
,
747 return RtlEqualPrefixSid (pSid1
, pSid2
);
755 GetSidLengthRequired(UCHAR nSubAuthorityCount
)
757 return (DWORD
)RtlLengthRequiredSid(nSubAuthorityCount
);
765 InitializeSid(PSID Sid
,
766 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
767 BYTE nSubAuthorityCount
)
771 Status
= RtlInitializeSid(Sid
,
772 pIdentifierAuthority
,
774 if (!NT_SUCCESS(Status
))
776 SetLastError(RtlNtStatusToDosError(Status
));
786 PSID_IDENTIFIER_AUTHORITY
788 GetSidIdentifierAuthority(PSID pSid
)
790 return RtlIdentifierAuthoritySid(pSid
);
798 GetSidSubAuthority(PSID pSid
,
801 SetLastError(ERROR_SUCCESS
);
802 return (PDWORD
)RtlSubAuthoritySid(pSid
, nSubAuthority
);
810 GetSidSubAuthorityCount(PSID pSid
)
812 SetLastError(ERROR_SUCCESS
);
813 return RtlSubAuthorityCountSid(pSid
);
821 GetLengthSid(PSID pSid
)
823 return (DWORD
)RtlLengthSid(pSid
);
831 GetKernelObjectSecurity(HANDLE Handle
,
832 SECURITY_INFORMATION RequestedInformation
,
833 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
835 LPDWORD lpnLengthNeeded
)
839 Status
= NtQuerySecurityObject(Handle
,
840 RequestedInformation
,
844 if (!NT_SUCCESS(Status
))
846 SetLastError(RtlNtStatusToDosError(Status
));
858 InitializeAcl(PACL pAcl
,
864 Status
= RtlCreateAcl(pAcl
,
867 if (!NT_SUCCESS(Status
))
869 SetLastError(RtlNtStatusToDosError(Status
));
876 /**********************************************************************
877 * ImpersonateNamedPipeClient EXPORTED
883 ImpersonateNamedPipeClient(HANDLE hNamedPipe
)
885 IO_STATUS_BLOCK StatusBlock
;
888 TRACE("ImpersonateNamedPipeClient() called\n");
890 Status
= NtFsControlFile(hNamedPipe
,
895 FSCTL_PIPE_IMPERSONATE
,
900 if (!NT_SUCCESS(Status
))
902 SetLastError(RtlNtStatusToDosError(Status
));
914 AddAccessAllowedAce(PACL pAcl
,
921 Status
= RtlAddAccessAllowedAce(pAcl
,
925 if (!NT_SUCCESS(Status
))
927 SetLastError(RtlNtStatusToDosError(Status
));
938 AddAccessAllowedAceEx(PACL pAcl
,
946 Status
= RtlAddAccessAllowedAceEx(pAcl
,
951 if (!NT_SUCCESS(Status
))
953 SetLastError(RtlNtStatusToDosError(Status
));
965 AddAccessDeniedAce(PACL pAcl
,
972 Status
= RtlAddAccessDeniedAce(pAcl
,
976 if (!NT_SUCCESS(Status
))
978 SetLastError(RtlNtStatusToDosError(Status
));
989 AddAccessDeniedAceEx(PACL pAcl
,
997 Status
= RtlAddAccessDeniedAceEx(pAcl
,
1002 if (!NT_SUCCESS(Status
))
1004 SetLastError(RtlNtStatusToDosError(Status
));
1017 DWORD dwAceRevision
,
1018 DWORD dwStartingAceIndex
,
1020 DWORD nAceListLength
)
1024 Status
= RtlAddAce(pAcl
,
1029 if (!NT_SUCCESS(Status
))
1031 SetLastError(RtlNtStatusToDosError(Status
));
1043 DeleteAce(PACL pAcl
,
1048 Status
= RtlDeleteAce(pAcl
,
1050 if (!NT_SUCCESS(Status
))
1052 SetLastError(RtlNtStatusToDosError(Status
));
1064 FindFirstFreeAce(PACL pAcl
,
1067 return RtlFirstFreeAce(pAcl
,
1083 Status
= RtlGetAce(pAcl
,
1086 if (!NT_SUCCESS(Status
))
1088 SetLastError(RtlNtStatusToDosError(Status
));
1100 GetAclInformation(PACL pAcl
,
1101 LPVOID pAclInformation
,
1102 DWORD nAclInformationLength
,
1103 ACL_INFORMATION_CLASS dwAclInformationClass
)
1107 Status
= RtlQueryInformationAcl(pAcl
,
1109 nAclInformationLength
,
1110 dwAclInformationClass
);
1111 if (!NT_SUCCESS(Status
))
1113 SetLastError(RtlNtStatusToDosError(Status
));
1125 IsValidAcl(PACL pAcl
)
1127 return RtlValidAcl (pAcl
);
1134 AllocateLocallyUniqueId(PLUID Luid
)
1138 Status
= NtAllocateLocallyUniqueId (Luid
);
1139 if (!NT_SUCCESS (Status
))
1141 SetLastError(RtlNtStatusToDosError(Status
));
1148 /**********************************************************************
1149 * LookupPrivilegeDisplayNameA EXPORTED
1155 LookupPrivilegeDisplayNameA(LPCSTR lpSystemName
,
1157 LPSTR lpDisplayName
,
1158 LPDWORD cbDisplayName
,
1159 LPDWORD lpLanguageId
)
1161 FIXME("%s() not implemented!\n", __FUNCTION__
);
1162 SetLastError (ERROR_CALL_NOT_IMPLEMENTED
);
1167 /**********************************************************************
1168 * LookupPrivilegeDisplayNameW EXPORTED
1174 LookupPrivilegeDisplayNameW(LPCWSTR lpSystemName
,
1176 LPWSTR lpDisplayName
,
1177 LPDWORD cbDisplayName
,
1178 LPDWORD lpLanguageId
)
1180 FIXME("%s() not implemented!\n", __FUNCTION__
);
1181 SetLastError (ERROR_CALL_NOT_IMPLEMENTED
);
1185 /**********************************************************************
1186 * LookupPrivilegeNameA EXPORTED
1192 LookupPrivilegeNameA(LPCSTR lpSystemName
,
1197 UNICODE_STRING lpSystemNameW
;
1201 TRACE("%s %p %p %p\n", debugstr_a(lpSystemName
), lpLuid
, lpName
, cchName
);
1203 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW
, lpSystemName
);
1204 ret
= LookupPrivilegeNameW(lpSystemNameW
.Buffer
, lpLuid
, NULL
, &wLen
);
1205 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1207 LPWSTR lpNameW
= HeapAlloc(GetProcessHeap(), 0, wLen
* sizeof(WCHAR
));
1209 ret
= LookupPrivilegeNameW(lpSystemNameW
.Buffer
, lpLuid
, lpNameW
,
1213 /* Windows crashes if cchName is NULL, so will I */
1214 unsigned int len
= WideCharToMultiByte(CP_ACP
, 0, lpNameW
, -1, lpName
,
1215 *cchName
, NULL
, NULL
);
1219 /* WideCharToMultiByte failed */
1222 else if (len
> *cchName
)
1225 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1230 /* WideCharToMultiByte succeeded, output length needs to be
1231 * length not including NULL terminator
1236 HeapFree(GetProcessHeap(), 0, lpNameW
);
1238 RtlFreeUnicodeString(&lpSystemNameW
);
1242 /******************************************************************************
1243 * GetFileSecurityA [ADVAPI32.@]
1245 * Obtains Specified information about the security of a file or directory.
1248 * lpFileName [I] Name of the file to get info for
1249 * RequestedInformation [I] SE_ flags from "winnt.h"
1250 * pSecurityDescriptor [O] Destination for security information
1251 * nLength [I] Length of pSecurityDescriptor
1252 * lpnLengthNeeded [O] Destination for length of returned security information
1255 * Success: TRUE. pSecurityDescriptor contains the requested information.
1256 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
1259 * The information returned is constrained by the callers access rights and
1266 GetFileSecurityA(LPCSTR lpFileName
,
1267 SECURITY_INFORMATION RequestedInformation
,
1268 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1270 LPDWORD lpnLengthNeeded
)
1272 UNICODE_STRING FileName
;
1275 if (!RtlCreateUnicodeStringFromAsciiz(&FileName
, lpFileName
))
1277 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1281 bResult
= GetFileSecurityW(FileName
.Buffer
,
1282 RequestedInformation
,
1283 pSecurityDescriptor
,
1287 RtlFreeUnicodeString(&FileName
);
1297 GetFileSecurityW(LPCWSTR lpFileName
,
1298 SECURITY_INFORMATION RequestedInformation
,
1299 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1301 LPDWORD lpnLengthNeeded
)
1303 OBJECT_ATTRIBUTES ObjectAttributes
;
1304 IO_STATUS_BLOCK StatusBlock
;
1305 UNICODE_STRING FileName
;
1306 ULONG AccessMask
= 0;
1310 TRACE("GetFileSecurityW() called\n");
1312 QuerySecurityAccessMask(RequestedInformation
, &AccessMask
);
1314 if (!RtlDosPathNameToNtPathName_U(lpFileName
,
1319 ERR("Invalid path\n");
1320 SetLastError(ERROR_INVALID_NAME
);
1324 InitializeObjectAttributes(&ObjectAttributes
,
1326 OBJ_CASE_INSENSITIVE
,
1330 Status
= NtOpenFile(&FileHandle
,
1334 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1337 RtlFreeHeap(RtlGetProcessHeap(),
1341 if (!NT_SUCCESS(Status
))
1343 ERR("NtOpenFile() failed (Status %lx)\n", Status
);
1344 SetLastError(RtlNtStatusToDosError(Status
));
1348 Status
= NtQuerySecurityObject(FileHandle
,
1349 RequestedInformation
,
1350 pSecurityDescriptor
,
1353 NtClose(FileHandle
);
1354 if (!NT_SUCCESS(Status
))
1356 ERR("NtQuerySecurityObject() failed (Status %lx)\n", Status
);
1357 SetLastError(RtlNtStatusToDosError(Status
));
1364 /******************************************************************************
1365 * SetFileSecurityA [ADVAPI32.@]
1366 * Sets the security of a file or directory
1372 SetFileSecurityA(LPCSTR lpFileName
,
1373 SECURITY_INFORMATION SecurityInformation
,
1374 PSECURITY_DESCRIPTOR pSecurityDescriptor
)
1376 UNICODE_STRING FileName
;
1379 if (!RtlCreateUnicodeStringFromAsciiz(&FileName
, lpFileName
))
1381 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1385 bResult
= SetFileSecurityW(FileName
.Buffer
,
1386 SecurityInformation
,
1387 pSecurityDescriptor
);
1389 RtlFreeUnicodeString(&FileName
);
1394 /******************************************************************************
1395 * SetFileSecurityW [ADVAPI32.@]
1396 * Sets the security of a file or directory
1402 SetFileSecurityW(LPCWSTR lpFileName
,
1403 SECURITY_INFORMATION SecurityInformation
,
1404 PSECURITY_DESCRIPTOR pSecurityDescriptor
)
1406 OBJECT_ATTRIBUTES ObjectAttributes
;
1407 IO_STATUS_BLOCK StatusBlock
;
1408 UNICODE_STRING FileName
;
1409 ULONG AccessMask
= 0;
1413 TRACE("SetFileSecurityW() called\n");
1415 SetSecurityAccessMask(SecurityInformation
, &AccessMask
);
1417 if (!RtlDosPathNameToNtPathName_U(lpFileName
,
1422 ERR("Invalid path\n");
1423 SetLastError(ERROR_INVALID_NAME
);
1427 InitializeObjectAttributes(&ObjectAttributes
,
1429 OBJ_CASE_INSENSITIVE
,
1433 Status
= NtOpenFile(&FileHandle
,
1437 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1440 RtlFreeHeap(RtlGetProcessHeap(),
1444 if (!NT_SUCCESS(Status
))
1446 ERR("NtOpenFile() failed (Status %lx)\n", Status
);
1447 SetLastError(RtlNtStatusToDosError(Status
));
1451 Status
= NtSetSecurityObject(FileHandle
,
1452 SecurityInformation
,
1453 pSecurityDescriptor
);
1454 NtClose(FileHandle
);
1456 if (!NT_SUCCESS(Status
))
1458 ERR("NtSetSecurityObject() failed (Status %lx)\n", Status
);
1459 SetLastError(RtlNtStatusToDosError(Status
));
1466 /******************************************************************************
1467 * QueryWindows31FilesMigration [ADVAPI32.@]
1473 QueryWindows31FilesMigration( DWORD x1
)
1475 FIXME("(%d):stub\n",x1
);
1479 /******************************************************************************
1480 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
1489 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1
, DWORD x2
, DWORD x3
,
1492 FIXME("(0x%08x,0x%08x,0x%08x,0x%08x):stub\n",x1
,x2
,x3
,x4
);
1504 HANDLE Token
= NULL
;
1506 Status
= NtSetInformationThread(NtCurrentThread(),
1507 ThreadImpersonationToken
,
1510 if (!NT_SUCCESS(Status
))
1512 SetLastError(RtlNtStatusToDosError(Status
));
1524 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
)
1528 Status
= RtlImpersonateSelf(ImpersonationLevel
);
1529 if (!NT_SUCCESS(Status
))
1531 SetLastError(RtlNtStatusToDosError(Status
));
1543 AccessCheck(IN PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1544 IN HANDLE ClientToken
,
1545 IN DWORD DesiredAccess
,
1546 IN PGENERIC_MAPPING GenericMapping
,
1547 OUT PPRIVILEGE_SET PrivilegeSet OPTIONAL
,
1548 IN OUT LPDWORD PrivilegeSetLength
,
1549 OUT LPDWORD GrantedAccess
,
1550 OUT LPBOOL AccessStatus
)
1553 NTSTATUS NtAccessStatus
;
1555 /* Do the access check */
1556 Status
= NtAccessCheck(pSecurityDescriptor
,
1561 (PULONG
)PrivilegeSetLength
,
1562 (PACCESS_MASK
)GrantedAccess
,
1565 /* See if the access check operation succeeded */
1566 if (!NT_SUCCESS(Status
))
1569 SetLastError(RtlNtStatusToDosError(Status
));
1573 /* Now check the access status */
1574 if (!NT_SUCCESS(NtAccessStatus
))
1577 SetLastError(RtlNtStatusToDosError(NtAccessStatus
));
1578 *AccessStatus
= FALSE
;
1582 /* Access granted */
1583 *AccessStatus
= TRUE
;
1586 /* Check succeeded */
1593 BOOL WINAPI
AccessCheckByType(
1594 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1595 PSID PrincipalSelfSid
,
1597 DWORD DesiredAccess
,
1598 POBJECT_TYPE_LIST ObjectTypeList
,
1599 DWORD ObjectTypeListLength
,
1600 PGENERIC_MAPPING GenericMapping
,
1601 PPRIVILEGE_SET PrivilegeSet
,
1602 LPDWORD PrivilegeSetLength
,
1603 LPDWORD GrantedAccess
,
1604 LPBOOL AccessStatus
)
1608 *AccessStatus
= TRUE
;
1610 return !*AccessStatus
;
1618 SetKernelObjectSecurity(HANDLE Handle
,
1619 SECURITY_INFORMATION SecurityInformation
,
1620 PSECURITY_DESCRIPTOR SecurityDescriptor
)
1624 Status
= NtSetSecurityObject(Handle
,
1625 SecurityInformation
,
1626 SecurityDescriptor
);
1627 if (!NT_SUCCESS(Status
))
1629 SetLastError(RtlNtStatusToDosError(Status
));
1641 AddAuditAccessAce(PACL pAcl
,
1642 DWORD dwAceRevision
,
1650 Status
= RtlAddAuditAccessAce(pAcl
,
1656 if (!NT_SUCCESS(Status
))
1658 SetLastError(RtlNtStatusToDosError(Status
));
1669 AddAuditAccessAceEx(PACL pAcl
,
1670 DWORD dwAceRevision
,
1679 Status
= RtlAddAuditAccessAceEx(pAcl
,
1686 if (!NT_SUCCESS(Status
))
1688 SetLastError(RtlNtStatusToDosError(Status
));
1695 /******************************************************************************
1696 * LookupAccountNameA [ADVAPI32.@]
1702 LookupAccountNameA(LPCSTR SystemName
,
1706 LPSTR ReferencedDomainName
,
1707 LPDWORD hReferencedDomainNameLength
,
1708 PSID_NAME_USE SidNameUse
)
1711 UNICODE_STRING lpSystemW
;
1712 UNICODE_STRING lpAccountW
;
1713 LPWSTR lpReferencedDomainNameW
= NULL
;
1715 RtlCreateUnicodeStringFromAsciiz(&lpSystemW
, SystemName
);
1716 RtlCreateUnicodeStringFromAsciiz(&lpAccountW
, AccountName
);
1718 if (ReferencedDomainName
)
1719 lpReferencedDomainNameW
= HeapAlloc(GetProcessHeap(),
1721 *hReferencedDomainNameLength
* sizeof(WCHAR
));
1723 ret
= LookupAccountNameW(lpSystemW
.Buffer
,
1727 lpReferencedDomainNameW
,
1728 hReferencedDomainNameLength
,
1731 if (ret
&& lpReferencedDomainNameW
)
1733 WideCharToMultiByte(CP_ACP
,
1735 lpReferencedDomainNameW
,
1736 *hReferencedDomainNameLength
+ 1,
1737 ReferencedDomainName
,
1738 *hReferencedDomainNameLength
+ 1,
1743 RtlFreeUnicodeString(&lpSystemW
);
1744 RtlFreeUnicodeString(&lpAccountW
);
1745 HeapFree(GetProcessHeap(), 0, lpReferencedDomainNameW
);
1750 /**********************************************************************
1751 * PrivilegeCheck EXPORTED
1756 PrivilegeCheck(HANDLE ClientToken
,
1757 PPRIVILEGE_SET RequiredPrivileges
,
1763 Status
= NtPrivilegeCheck(ClientToken
,
1766 if (!NT_SUCCESS(Status
))
1768 SetLastError(RtlNtStatusToDosError(Status
));
1772 *pfResult
= (BOOL
)Result
;
1777 /******************************************************************************
1778 * GetSecurityInfoExW EXPORTED
1782 GetSecurityInfoExA(HANDLE hObject
,
1783 SE_OBJECT_TYPE ObjectType
,
1784 SECURITY_INFORMATION SecurityInfo
,
1787 PACTRL_ACCESSA
*ppAccessList
,
1788 PACTRL_AUDITA
*ppAuditList
,
1792 FIXME("%s() not implemented!\n", __FUNCTION__
);
1793 return ERROR_BAD_PROVIDER
;
1797 /******************************************************************************
1798 * GetSecurityInfoExW EXPORTED
1802 GetSecurityInfoExW(HANDLE hObject
,
1803 SE_OBJECT_TYPE ObjectType
,
1804 SECURITY_INFORMATION SecurityInfo
,
1807 PACTRL_ACCESSW
*ppAccessList
,
1808 PACTRL_AUDITW
*ppAuditList
,
1812 FIXME("%s() not implemented!\n", __FUNCTION__
);
1813 return ERROR_BAD_PROVIDER
;
1821 SetAclInformation(PACL pAcl
,
1822 LPVOID pAclInformation
,
1823 DWORD nAclInformationLength
,
1824 ACL_INFORMATION_CLASS dwAclInformationClass
)
1828 Status
= RtlSetInformationAcl(pAcl
,
1830 nAclInformationLength
,
1831 dwAclInformationClass
);
1832 if (!NT_SUCCESS(Status
))
1834 SetLastError(RtlNtStatusToDosError(Status
));
1841 /**********************************************************************
1842 * SetNamedSecurityInfoA EXPORTED
1848 SetNamedSecurityInfoA(LPSTR pObjectName
,
1849 SE_OBJECT_TYPE ObjectType
,
1850 SECURITY_INFORMATION SecurityInfo
,
1856 UNICODE_STRING ObjectName
;
1859 if (!RtlCreateUnicodeStringFromAsciiz(&ObjectName
, pObjectName
))
1861 return ERROR_NOT_ENOUGH_MEMORY
;
1864 Ret
= SetNamedSecurityInfoW(ObjectName
.Buffer
,
1872 RtlFreeUnicodeString(&ObjectName
);
1882 AreAllAccessesGranted(DWORD GrantedAccess
,
1883 DWORD DesiredAccess
)
1885 return (BOOL
)RtlAreAllAccessesGranted(GrantedAccess
,
1894 AreAnyAccessesGranted(DWORD GrantedAccess
,
1895 DWORD DesiredAccess
)
1897 return (BOOL
)RtlAreAnyAccessesGranted(GrantedAccess
,
1901 /******************************************************************************
1902 * ParseAclStringFlags
1904 static DWORD
ParseAclStringFlags(LPCWSTR
* StringAcl
)
1907 LPCWSTR szAcl
= *StringAcl
;
1909 while (*szAcl
!= '(')
1913 flags
|= SE_DACL_PROTECTED
;
1915 else if (*szAcl
== 'A')
1919 flags
|= SE_DACL_AUTO_INHERIT_REQ
;
1920 else if (*szAcl
== 'I')
1921 flags
|= SE_DACL_AUTO_INHERITED
;
1930 /******************************************************************************
1931 * ParseAceStringType
1933 static const ACEFLAG AceType
[] =
1935 { SDDL_ALARM
, SYSTEM_ALARM_ACE_TYPE
},
1936 { SDDL_AUDIT
, SYSTEM_AUDIT_ACE_TYPE
},
1937 { SDDL_ACCESS_ALLOWED
, ACCESS_ALLOWED_ACE_TYPE
},
1938 { SDDL_ACCESS_DENIED
, ACCESS_DENIED_ACE_TYPE
},
1940 { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
1941 { SDDL_OBJECT_ACCESS_DENIED, ACCESS_DENIED_OBJECT_ACE_TYPE },
1942 { SDDL_OBJECT_ALARM, SYSTEM_ALARM_OBJECT_ACE_TYPE },
1943 { SDDL_OBJECT_AUDIT, SYSTEM_AUDIT_OBJECT_ACE_TYPE },
1948 static BYTE
ParseAceStringType(LPCWSTR
* StringAcl
)
1951 LPCWSTR szAcl
= *StringAcl
;
1952 const ACEFLAG
*lpaf
= AceType
;
1954 while (lpaf
->wstr
&&
1955 (len
= strlenW(lpaf
->wstr
)) &&
1956 strncmpW(lpaf
->wstr
, szAcl
, len
))
1967 /******************************************************************************
1968 * ParseAceStringFlags
1970 static const ACEFLAG AceFlags
[] =
1972 { SDDL_CONTAINER_INHERIT
, CONTAINER_INHERIT_ACE
},
1973 { SDDL_AUDIT_FAILURE
, FAILED_ACCESS_ACE_FLAG
},
1974 { SDDL_INHERITED
, INHERITED_ACE
},
1975 { SDDL_INHERIT_ONLY
, INHERIT_ONLY_ACE
},
1976 { SDDL_NO_PROPAGATE
, NO_PROPAGATE_INHERIT_ACE
},
1977 { SDDL_OBJECT_INHERIT
, OBJECT_INHERIT_ACE
},
1978 { SDDL_AUDIT_SUCCESS
, SUCCESSFUL_ACCESS_ACE_FLAG
},
1982 static BYTE
ParseAceStringFlags(LPCWSTR
* StringAcl
)
1986 LPCWSTR szAcl
= *StringAcl
;
1988 while (*szAcl
!= ';')
1990 const ACEFLAG
*lpaf
= AceFlags
;
1992 while (lpaf
->wstr
&&
1993 (len
= strlenW(lpaf
->wstr
)) &&
1994 strncmpW(lpaf
->wstr
, szAcl
, len
))
2000 flags
|= lpaf
->value
;
2009 /******************************************************************************
2010 * ParseAceStringRights
2012 static DWORD
ParseAceStringRights(LPCWSTR
* StringAcl
)
2016 LPCWSTR szAcl
= *StringAcl
;
2018 if ((*szAcl
== '0') && (*(szAcl
+ 1) == 'x'))
2022 while (*p
&& *p
!= ';')
2025 if (p
- szAcl
<= 10 /* 8 hex digits + "0x" */ )
2027 rights
= strtoulW(szAcl
, NULL
, 16);
2031 WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl
, p
- szAcl
));
2035 while (*szAcl
!= ';')
2037 const ACEFLAG
*lpaf
= AceRights
;
2039 while (lpaf
->wstr
&&
2040 (len
= strlenW(lpaf
->wstr
)) &&
2041 strncmpW(lpaf
->wstr
, szAcl
, len
))
2049 rights
|= lpaf
->value
;
2059 /******************************************************************************
2060 * ParseStringAclToAcl
2062 * dacl_flags(string_ace1)(string_ace2)... (string_acen)
2065 ParseStringAclToAcl(LPCWSTR StringAcl
,
2072 DWORD length
= sizeof(ACL
);
2075 PACCESS_ALLOWED_ACE pAce
= NULL
; /* pointer to current ACE */
2077 TRACE("%s\n", debugstr_w(StringAcl
));
2082 if (pAcl
) /* pAce is only useful if we're setting values */
2083 pAce
= (PACCESS_ALLOWED_ACE
) (pAcl
+ 1);
2085 /* Parse ACL flags */
2086 *lpdwFlags
= ParseAclStringFlags(&StringAcl
);
2089 while (*StringAcl
== '(')
2093 /* Parse ACE type */
2094 val
= ParseAceStringType(&StringAcl
);
2096 pAce
->Header
.AceType
= (BYTE
) val
;
2097 if (*StringAcl
!= ';')
2101 /* Parse ACE flags */
2102 val
= ParseAceStringFlags(&StringAcl
);
2104 pAce
->Header
.AceFlags
= (BYTE
) val
;
2105 if (*StringAcl
!= ';')
2109 /* Parse ACE rights */
2110 val
= ParseAceStringRights(&StringAcl
);
2113 if (*StringAcl
!= ';')
2117 /* Parse ACE object guid */
2118 if (*StringAcl
!= ';')
2120 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
2125 /* Parse ACE inherit object guid */
2126 if (*StringAcl
!= ';')
2128 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
2133 /* Parse ACE account sid */
2134 if (ParseStringSidToSid(StringAcl
, pAce
? &pAce
->SidStart
: NULL
, &sidlen
))
2136 while (*StringAcl
&& *StringAcl
!= ')')
2140 if (*StringAcl
!= ')')
2144 acesize
= sizeof(ACCESS_ALLOWED_ACE
) - sizeof(DWORD
) + sidlen
;
2148 pAce
->Header
.AceSize
= acesize
;
2149 pAce
= (PACCESS_ALLOWED_ACE
)((LPBYTE
)pAce
+ acesize
);
2156 if (length
> 0xffff)
2158 ERR("ACL too large\n");
2164 pAcl
->AclRevision
= ACL_REVISION
;
2166 pAcl
->AclSize
= length
;
2167 pAcl
->AceCount
= acecount
++;
2173 SetLastError(ERROR_INVALID_ACL
);
2174 WARN("Invalid ACE string format\n");
2179 /******************************************************************************
2180 * ParseStringSecurityDescriptorToSecurityDescriptor
2183 ParseStringSecurityDescriptorToSecurityDescriptor(LPCWSTR StringSecurityDescriptor
,
2184 SECURITY_DESCRIPTOR_RELATIVE
* SecurityDescriptor
,
2189 WCHAR tok
[MAX_PATH
];
2191 LPBYTE lpNext
= NULL
;
2194 *cBytes
= sizeof(SECURITY_DESCRIPTOR
);
2196 if (SecurityDescriptor
)
2197 lpNext
= (LPBYTE
)(SecurityDescriptor
+ 1);
2199 while (*StringSecurityDescriptor
)
2201 toktype
= *StringSecurityDescriptor
;
2203 /* Expect char identifier followed by ':' */
2204 StringSecurityDescriptor
++;
2205 if (*StringSecurityDescriptor
!= ':')
2207 SetLastError(ERROR_INVALID_PARAMETER
);
2210 StringSecurityDescriptor
++;
2213 lptoken
= StringSecurityDescriptor
;
2214 while (*lptoken
&& *lptoken
!= ':')
2220 len
= lptoken
- StringSecurityDescriptor
;
2221 memcpy( tok
, StringSecurityDescriptor
, len
* sizeof(WCHAR
) );
2230 if (!ParseStringSidToSid(tok
, lpNext
, &bytes
))
2233 if (SecurityDescriptor
)
2235 SecurityDescriptor
->Owner
= lpNext
- (LPBYTE
)SecurityDescriptor
;
2236 lpNext
+= bytes
; /* Advance to next token */
2248 if (!ParseStringSidToSid(tok
, lpNext
, &bytes
))
2251 if (SecurityDescriptor
)
2253 SecurityDescriptor
->Group
= lpNext
- (LPBYTE
)SecurityDescriptor
;
2254 lpNext
+= bytes
; /* Advance to next token */
2267 if (!ParseStringAclToAcl(tok
, &flags
, (PACL
)lpNext
, &bytes
))
2270 if (SecurityDescriptor
)
2272 SecurityDescriptor
->Control
|= SE_DACL_PRESENT
| flags
;
2273 SecurityDescriptor
->Dacl
= lpNext
- (LPBYTE
)SecurityDescriptor
;
2274 lpNext
+= bytes
; /* Advance to next token */
2287 if (!ParseStringAclToAcl(tok
, &flags
, (PACL
)lpNext
, &bytes
))
2290 if (SecurityDescriptor
)
2292 SecurityDescriptor
->Control
|= SE_SACL_PRESENT
| flags
;
2293 SecurityDescriptor
->Sacl
= lpNext
- (LPBYTE
)SecurityDescriptor
;
2294 lpNext
+= bytes
; /* Advance to next token */
2303 FIXME("Unknown token\n");
2304 SetLastError(ERROR_INVALID_PARAMETER
);
2308 StringSecurityDescriptor
= lptoken
;
2317 /* Winehq cvs 20050916 */
2318 /******************************************************************************
2319 * ConvertStringSecurityDescriptorToSecurityDescriptorA [ADVAPI32.@]
2324 ConvertStringSecurityDescriptorToSecurityDescriptorA(LPCSTR StringSecurityDescriptor
,
2325 DWORD StringSDRevision
,
2326 PSECURITY_DESCRIPTOR
* SecurityDescriptor
,
2327 PULONG SecurityDescriptorSize
)
2331 LPWSTR StringSecurityDescriptorW
;
2333 len
= MultiByteToWideChar(CP_ACP
, 0, StringSecurityDescriptor
, -1, NULL
, 0);
2334 StringSecurityDescriptorW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2336 if (StringSecurityDescriptorW
)
2338 MultiByteToWideChar(CP_ACP
, 0, StringSecurityDescriptor
, -1, StringSecurityDescriptorW
, len
);
2340 ret
= ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptorW
,
2341 StringSDRevision
, SecurityDescriptor
,
2342 SecurityDescriptorSize
);
2343 HeapFree(GetProcessHeap(), 0, StringSecurityDescriptorW
);
2349 /******************************************************************************
2350 * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
2354 ConvertStringSecurityDescriptorToSecurityDescriptorW(LPCWSTR StringSecurityDescriptor
,
2355 DWORD StringSDRevision
,
2356 PSECURITY_DESCRIPTOR
* SecurityDescriptor
,
2357 PULONG SecurityDescriptorSize
)
2360 SECURITY_DESCRIPTOR
* psd
;
2363 TRACE("%s\n", debugstr_w(StringSecurityDescriptor
));
2365 if (GetVersion() & 0x80000000)
2367 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2370 else if (!StringSecurityDescriptor
|| !SecurityDescriptor
)
2372 SetLastError(ERROR_INVALID_PARAMETER
);
2375 else if (StringSDRevision
!= SID_REVISION
)
2377 SetLastError(ERROR_UNKNOWN_REVISION
);
2381 /* Compute security descriptor length */
2382 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor
,
2386 psd
= *SecurityDescriptor
= LocalAlloc(GMEM_ZEROINIT
, cBytes
);
2387 if (!psd
) goto lend
;
2389 psd
->Revision
= SID_REVISION
;
2390 psd
->Control
|= SE_SELF_RELATIVE
;
2392 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor
,
2393 (SECURITY_DESCRIPTOR_RELATIVE
*)psd
, &cBytes
))
2399 if (SecurityDescriptorSize
)
2400 *SecurityDescriptorSize
= cBytes
;
2405 TRACE(" ret=%d\n", bret
);
2409 static void DumpString(LPCWSTR string
, int cch
, WCHAR
**pwptr
, ULONG
*plen
)
2412 cch
= strlenW(string
);
2419 memcpy(*pwptr
, string
, sizeof(WCHAR
)*cch
);
2424 static BOOL
DumpSidNumeric(PSID psid
, WCHAR
**pwptr
, ULONG
*plen
)
2427 WCHAR fmt
[] = { 'S','-','%','u','-','%','d',0 };
2428 WCHAR subauthfmt
[] = { '-','%','u',0 };
2432 if( !IsValidSid( psid
) || pisid
->Revision
!= SDDL_REVISION
)
2434 SetLastError(ERROR_INVALID_SID
);
2438 if (pisid
->IdentifierAuthority
.Value
[0] ||
2439 pisid
->IdentifierAuthority
.Value
[1])
2441 FIXME("not matching MS' bugs\n");
2442 SetLastError(ERROR_INVALID_SID
);
2446 sprintfW( buf
, fmt
, pisid
->Revision
,
2448 MAKEWORD( pisid
->IdentifierAuthority
.Value
[5],
2449 pisid
->IdentifierAuthority
.Value
[4] ),
2450 MAKEWORD( pisid
->IdentifierAuthority
.Value
[3],
2451 pisid
->IdentifierAuthority
.Value
[2] )
2453 DumpString(buf
, -1, pwptr
, plen
);
2455 for( i
=0; i
<pisid
->SubAuthorityCount
; i
++ )
2457 sprintfW( buf
, subauthfmt
, pisid
->SubAuthority
[i
] );
2458 DumpString(buf
, -1, pwptr
, plen
);
2463 static BOOL
DumpSid(PSID psid
, WCHAR
**pwptr
, ULONG
*plen
)
2466 for (i
= 0; i
< sizeof(WellKnownSids
) / sizeof(WellKnownSids
[0]); i
++)
2468 if (WellKnownSids
[i
].wstr
[0] && EqualSid(psid
, (PSID
)&(WellKnownSids
[i
].Sid
.Revision
)))
2470 DumpString(WellKnownSids
[i
].wstr
, 2, pwptr
, plen
);
2475 return DumpSidNumeric(psid
, pwptr
, plen
);
2478 static const LPCWSTR AceRightBitNames
[32] = {
2479 SDDL_CREATE_CHILD
, /* 0 */
2483 SDDL_READ_PROPERTY
, /* 4 */
2484 SDDL_WRITE_PROPERTY
,
2487 SDDL_CONTROL_ACCESS
, /* 8 */
2495 SDDL_STANDARD_DELETE
, /* 16 */
2507 SDDL_GENERIC_ALL
, /* 28 */
2508 SDDL_GENERIC_EXECUTE
,
2513 static void DumpRights(DWORD mask
, WCHAR
**pwptr
, ULONG
*plen
)
2515 static const WCHAR fmtW
[] = {'0','x','%','x',0};
2522 /* first check if the right have name */
2523 for (i
= 0; i
< sizeof(AceRights
)/sizeof(AceRights
[0]); i
++)
2525 if (AceRights
[i
].wstr
== NULL
)
2527 if (mask
== AceRights
[i
].value
)
2529 DumpString(AceRights
[i
].wstr
, -1, pwptr
, plen
);
2534 /* then check if it can be built from bit names */
2535 for (i
= 0; i
< 32; i
++)
2537 if ((mask
& (1 << i
)) && (AceRightBitNames
[i
] == NULL
))
2539 /* can't be built from bit names */
2540 sprintfW(buf
, fmtW
, mask
);
2541 DumpString(buf
, -1, pwptr
, plen
);
2546 /* build from bit names */
2547 for (i
= 0; i
< 32; i
++)
2548 if (mask
& (1 << i
))
2549 DumpString(AceRightBitNames
[i
], -1, pwptr
, plen
);
2552 static BOOL
DumpAce(LPVOID pace
, WCHAR
**pwptr
, ULONG
*plen
)
2554 ACCESS_ALLOWED_ACE
*piace
; /* all the supported ACEs have the same memory layout */
2555 static const WCHAR openbr
= '(';
2556 static const WCHAR closebr
= ')';
2557 static const WCHAR semicolon
= ';';
2559 if (((PACE_HEADER
)pace
)->AceType
> SYSTEM_ALARM_ACE_TYPE
|| ((PACE_HEADER
)pace
)->AceSize
< sizeof(ACCESS_ALLOWED_ACE
))
2561 SetLastError(ERROR_INVALID_ACL
);
2566 DumpString(&openbr
, 1, pwptr
, plen
);
2567 switch (piace
->Header
.AceType
)
2569 case ACCESS_ALLOWED_ACE_TYPE
:
2570 DumpString(SDDL_ACCESS_ALLOWED
, -1, pwptr
, plen
);
2572 case ACCESS_DENIED_ACE_TYPE
:
2573 DumpString(SDDL_ACCESS_DENIED
, -1, pwptr
, plen
);
2575 case SYSTEM_AUDIT_ACE_TYPE
:
2576 DumpString(SDDL_AUDIT
, -1, pwptr
, plen
);
2578 case SYSTEM_ALARM_ACE_TYPE
:
2579 DumpString(SDDL_ALARM
, -1, pwptr
, plen
);
2582 DumpString(&semicolon
, 1, pwptr
, plen
);
2584 if (piace
->Header
.AceFlags
& OBJECT_INHERIT_ACE
)
2585 DumpString(SDDL_OBJECT_INHERIT
, -1, pwptr
, plen
);
2586 if (piace
->Header
.AceFlags
& CONTAINER_INHERIT_ACE
)
2587 DumpString(SDDL_CONTAINER_INHERIT
, -1, pwptr
, plen
);
2588 if (piace
->Header
.AceFlags
& NO_PROPAGATE_INHERIT_ACE
)
2589 DumpString(SDDL_NO_PROPAGATE
, -1, pwptr
, plen
);
2590 if (piace
->Header
.AceFlags
& INHERIT_ONLY_ACE
)
2591 DumpString(SDDL_INHERIT_ONLY
, -1, pwptr
, plen
);
2592 if (piace
->Header
.AceFlags
& INHERITED_ACE
)
2593 DumpString(SDDL_INHERITED
, -1, pwptr
, plen
);
2594 if (piace
->Header
.AceFlags
& SUCCESSFUL_ACCESS_ACE_FLAG
)
2595 DumpString(SDDL_AUDIT_SUCCESS
, -1, pwptr
, plen
);
2596 if (piace
->Header
.AceFlags
& FAILED_ACCESS_ACE_FLAG
)
2597 DumpString(SDDL_AUDIT_FAILURE
, -1, pwptr
, plen
);
2598 DumpString(&semicolon
, 1, pwptr
, plen
);
2599 DumpRights(piace
->Mask
, pwptr
, plen
);
2600 DumpString(&semicolon
, 1, pwptr
, plen
);
2601 /* objects not supported */
2602 DumpString(&semicolon
, 1, pwptr
, plen
);
2603 /* objects not supported */
2604 DumpString(&semicolon
, 1, pwptr
, plen
);
2605 if (!DumpSid((PSID
)&piace
->SidStart
, pwptr
, plen
))
2607 DumpString(&closebr
, 1, pwptr
, plen
);
2611 static BOOL
DumpAcl(PACL pacl
, WCHAR
**pwptr
, ULONG
*plen
, BOOL
protected, BOOL autoInheritReq
, BOOL autoInherited
)
2617 DumpString(SDDL_PROTECTED
, -1, pwptr
, plen
);
2619 DumpString(SDDL_AUTO_INHERIT_REQ
, -1, pwptr
, plen
);
2621 DumpString(SDDL_AUTO_INHERITED
, -1, pwptr
, plen
);
2626 if (!IsValidAcl(pacl
))
2629 count
= pacl
->AceCount
;
2630 for (i
= 0; i
< count
; i
++)
2633 if (!GetAce(pacl
, i
, &ace
))
2635 if (!DumpAce(ace
, pwptr
, plen
))
2642 static BOOL
DumpOwner(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
2644 static const WCHAR prefix
[] = {'O',':',0};
2648 if (!GetSecurityDescriptorOwner(SecurityDescriptor
, &psid
, &bDefaulted
))
2654 DumpString(prefix
, -1, pwptr
, plen
);
2655 if (!DumpSid(psid
, pwptr
, plen
))
2660 static BOOL
DumpGroup(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
2662 static const WCHAR prefix
[] = {'G',':',0};
2666 if (!GetSecurityDescriptorGroup(SecurityDescriptor
, &psid
, &bDefaulted
))
2672 DumpString(prefix
, -1, pwptr
, plen
);
2673 if (!DumpSid(psid
, pwptr
, plen
))
2678 static BOOL
DumpDacl(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
2680 static const WCHAR dacl
[] = {'D',':',0};
2681 SECURITY_DESCRIPTOR_CONTROL control
;
2682 BOOL present
, defaulted
;
2686 if (!GetSecurityDescriptorDacl(SecurityDescriptor
, &present
, &pacl
, &defaulted
))
2689 if (!GetSecurityDescriptorControl(SecurityDescriptor
, &control
, &revision
))
2695 DumpString(dacl
, 2, pwptr
, plen
);
2696 if (!DumpAcl(pacl
, pwptr
, plen
, control
& SE_DACL_PROTECTED
, control
& SE_DACL_AUTO_INHERIT_REQ
, control
& SE_DACL_AUTO_INHERITED
))
2701 static BOOL
DumpSacl(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
2703 static const WCHAR sacl
[] = {'S',':',0};
2704 SECURITY_DESCRIPTOR_CONTROL control
;
2705 BOOL present
, defaulted
;
2709 if (!GetSecurityDescriptorSacl(SecurityDescriptor
, &present
, &pacl
, &defaulted
))
2712 if (!GetSecurityDescriptorControl(SecurityDescriptor
, &control
, &revision
))
2718 DumpString(sacl
, 2, pwptr
, plen
);
2719 if (!DumpAcl(pacl
, pwptr
, plen
, control
& SE_SACL_PROTECTED
, control
& SE_SACL_AUTO_INHERIT_REQ
, control
& SE_SACL_AUTO_INHERITED
))
2724 /******************************************************************************
2725 * ConvertSecurityDescriptorToStringSecurityDescriptorW [ADVAPI32.@]
2729 ConvertSecurityDescriptorToStringSecurityDescriptorW(PSECURITY_DESCRIPTOR SecurityDescriptor
,
2731 SECURITY_INFORMATION SecurityInformation
,
2732 LPWSTR
*OutputString
,
2738 if (SDRevision
!= SDDL_REVISION_1
)
2740 ERR("Program requested unknown SDDL revision %d\n", SDRevision
);
2741 SetLastError(ERROR_UNKNOWN_REVISION
);
2746 if (SecurityInformation
& OWNER_SECURITY_INFORMATION
)
2747 if (!DumpOwner(SecurityDescriptor
, NULL
, &len
))
2749 if (SecurityInformation
& GROUP_SECURITY_INFORMATION
)
2750 if (!DumpGroup(SecurityDescriptor
, NULL
, &len
))
2752 if (SecurityInformation
& DACL_SECURITY_INFORMATION
)
2753 if (!DumpDacl(SecurityDescriptor
, NULL
, &len
))
2755 if (SecurityInformation
& SACL_SECURITY_INFORMATION
)
2756 if (!DumpSacl(SecurityDescriptor
, NULL
, &len
))
2759 wstr
= wptr
= LocalAlloc(0, (len
+ 1)*sizeof(WCHAR
));
2763 if (SecurityInformation
& OWNER_SECURITY_INFORMATION
)
2764 if (!DumpOwner(SecurityDescriptor
, &wptr
, NULL
))
2766 if (SecurityInformation
& GROUP_SECURITY_INFORMATION
)
2767 if (!DumpGroup(SecurityDescriptor
, &wptr
, NULL
))
2769 if (SecurityInformation
& DACL_SECURITY_INFORMATION
)
2770 if (!DumpDacl(SecurityDescriptor
, &wptr
, NULL
))
2772 if (SecurityInformation
& SACL_SECURITY_INFORMATION
)
2773 if (!DumpSacl(SecurityDescriptor
, &wptr
, NULL
))
2777 TRACE("ret: %s, %d\n", wine_dbgstr_w(wstr
), len
);
2778 *OutputString
= wstr
;
2780 *OutputLen
= strlenW(*OutputString
)+1;
2784 /******************************************************************************
2785 * ConvertSecurityDescriptorToStringSecurityDescriptorA [ADVAPI32.@]
2789 ConvertSecurityDescriptorToStringSecurityDescriptorA(PSECURITY_DESCRIPTOR SecurityDescriptor
,
2791 SECURITY_INFORMATION Information
,
2792 LPSTR
*OutputString
,
2798 if (ConvertSecurityDescriptorToStringSecurityDescriptorW(SecurityDescriptor
, SDRevision
, Information
, &wstr
, &len
))
2802 lenA
= WideCharToMultiByte(CP_ACP
, 0, wstr
, len
, NULL
, 0, NULL
, NULL
);
2803 *OutputString
= HeapAlloc(GetProcessHeap(), 0, lenA
);
2804 if (*OutputString
== NULL
)
2810 WideCharToMultiByte(CP_ACP
, 0, wstr
, len
, *OutputString
, lenA
, NULL
, NULL
);
2813 if (OutputLen
!= NULL
)
2819 *OutputString
= NULL
;
2831 ConvertStringSidToSidW(IN LPCWSTR StringSid
,
2835 DWORD i
, cBytes
, identAuth
, csubauth
;
2839 TRACE("%s %p\n", debugstr_w(StringSid
), sid
);
2843 SetLastError(ERROR_INVALID_SID
);
2847 for (i
= 0; i
< sizeof(SidTable
) / sizeof(SidTable
[0]) - 1; i
++)
2849 if (wcscmp(StringSid
, SidTable
[i
].key
) == 0)
2851 WELL_KNOWN_SID_TYPE knownSid
= (WELL_KNOWN_SID_TYPE
)SidTable
[i
].value
;
2852 size
= SECURITY_MAX_SID_SIZE
;
2853 *sid
= LocalAlloc(0, size
);
2856 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2859 ret
= CreateWellKnownSid(knownSid
,
2865 SetLastError(ERROR_INVALID_SID
);
2872 /* That's probably a string S-R-I-S-S... */
2873 if (StringSid
[0] != 'S' || StringSid
[1] != '-')
2875 SetLastError(ERROR_INVALID_SID
);
2879 cBytes
= ComputeStringSidSize(StringSid
);
2880 pisid
= (SID
*)LocalAlloc( 0, cBytes
);
2883 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2888 csubauth
= ((cBytes
- GetSidLengthRequired(0)) / sizeof(DWORD
));
2890 StringSid
+= 2; /* Advance to Revision */
2891 pisid
->Revision
= atoiW(StringSid
);
2893 if (pisid
->Revision
!= SDDL_REVISION
)
2895 TRACE("Revision %d is unknown\n", pisid
->Revision
);
2896 goto lend
; /* ERROR_INVALID_SID */
2900 TRACE("SubAuthorityCount is 0\n");
2901 goto lend
; /* ERROR_INVALID_SID */
2904 pisid
->SubAuthorityCount
= csubauth
;
2906 /* Advance to identifier authority */
2907 while (*StringSid
&& *StringSid
!= '-')
2909 if (*StringSid
== '-')
2912 /* MS' implementation can't handle values greater than 2^32 - 1, so
2913 * we don't either; assume most significant bytes are always 0
2915 pisid
->IdentifierAuthority
.Value
[0] = 0;
2916 pisid
->IdentifierAuthority
.Value
[1] = 0;
2917 identAuth
= atoiW(StringSid
);
2918 pisid
->IdentifierAuthority
.Value
[5] = identAuth
& 0xff;
2919 pisid
->IdentifierAuthority
.Value
[4] = (identAuth
& 0xff00) >> 8;
2920 pisid
->IdentifierAuthority
.Value
[3] = (identAuth
& 0xff0000) >> 16;
2921 pisid
->IdentifierAuthority
.Value
[2] = (identAuth
& 0xff000000) >> 24;
2923 /* Advance to first sub authority */
2924 while (*StringSid
&& *StringSid
!= '-')
2926 if (*StringSid
== '-')
2931 pisid
->SubAuthority
[i
++] = atoiW(StringSid
);
2933 while (*StringSid
&& *StringSid
!= '-')
2935 if (*StringSid
== '-')
2939 if (i
!= pisid
->SubAuthorityCount
)
2940 goto lend
; /* ERROR_INVALID_SID */
2949 SetLastError(ERROR_INVALID_SID
);
2952 TRACE("returning %s\n", ret
? "TRUE" : "FALSE");
2961 ConvertStringSidToSidA(IN LPCSTR StringSid
,
2964 BOOL bRetVal
= FALSE
;
2966 TRACE("%s, %p\n", debugstr_a(StringSid
), sid
);
2967 if (GetVersion() & 0x80000000)
2968 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2969 else if (!StringSid
|| !sid
)
2970 SetLastError(ERROR_INVALID_PARAMETER
);
2973 UINT len
= MultiByteToWideChar(CP_ACP
, 0, StringSid
, -1, NULL
, 0);
2974 LPWSTR wStringSid
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2975 if (wStringSid
== NULL
)
2977 MultiByteToWideChar(CP_ACP
, 0, StringSid
, - 1, wStringSid
, len
);
2978 bRetVal
= ConvertStringSidToSidW(wStringSid
, sid
);
2979 HeapFree(GetProcessHeap(), 0, wStringSid
);
2989 ConvertSidToStringSidW(PSID Sid
,
2993 UNICODE_STRING UnicodeString
;
2994 WCHAR FixedBuffer
[64];
2996 if (!RtlValidSid(Sid
))
2998 SetLastError(ERROR_INVALID_SID
);
3002 UnicodeString
.Length
= 0;
3003 UnicodeString
.MaximumLength
= sizeof(FixedBuffer
);
3004 UnicodeString
.Buffer
= FixedBuffer
;
3005 Status
= RtlConvertSidToUnicodeString(&UnicodeString
, Sid
, FALSE
);
3006 if (STATUS_BUFFER_TOO_SMALL
== Status
)
3008 Status
= RtlConvertSidToUnicodeString(&UnicodeString
, Sid
, TRUE
);
3011 if (!NT_SUCCESS(Status
))
3013 SetLastError(RtlNtStatusToDosError(Status
));
3017 *StringSid
= LocalAlloc(LMEM_FIXED
, UnicodeString
.Length
+ sizeof(WCHAR
));
3018 if (NULL
== *StringSid
)
3020 if (UnicodeString
.Buffer
!= FixedBuffer
)
3022 RtlFreeUnicodeString(&UnicodeString
);
3024 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3028 MoveMemory(*StringSid
, UnicodeString
.Buffer
, UnicodeString
.Length
);
3029 ZeroMemory((PCHAR
) *StringSid
+ UnicodeString
.Length
, sizeof(WCHAR
));
3030 if (UnicodeString
.Buffer
!= FixedBuffer
)
3032 RtlFreeUnicodeString(&UnicodeString
);
3043 ConvertSidToStringSidA(PSID Sid
,
3049 if (!ConvertSidToStringSidW(Sid
, &StringSidW
))
3054 Len
= WideCharToMultiByte(CP_ACP
, 0, StringSidW
, -1, NULL
, 0, NULL
, NULL
);
3057 LocalFree(StringSidW
);
3058 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3062 *StringSid
= LocalAlloc(LMEM_FIXED
, Len
);
3063 if (NULL
== *StringSid
)
3065 LocalFree(StringSidW
);
3066 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3070 if (!WideCharToMultiByte(CP_ACP
, 0, StringSidW
, -1, *StringSid
, Len
, NULL
, NULL
))
3072 LocalFree(StringSid
);
3073 LocalFree(StringSidW
);
3077 LocalFree(StringSidW
);
3086 CreateProcessWithLogonW(LPCWSTR lpUsername
,
3090 LPCWSTR lpApplicationName
,
3091 LPWSTR lpCommandLine
,
3092 DWORD dwCreationFlags
,
3093 LPVOID lpEnvironment
,
3094 LPCWSTR lpCurrentDirectory
,
3095 LPSTARTUPINFOW lpStartupInfo
,
3096 LPPROCESS_INFORMATION lpProcessInformation
)
3098 FIXME("%s %s %s 0x%08x %s %s 0x%08x %p %s %p %p stub\n", debugstr_w(lpUsername
), debugstr_w(lpDomain
),
3099 debugstr_w(lpPassword
), dwLogonFlags
, debugstr_w(lpApplicationName
),
3100 debugstr_w(lpCommandLine
), dwCreationFlags
, lpEnvironment
, debugstr_w(lpCurrentDirectory
),
3101 lpStartupInfo
, lpProcessInformation
);
3108 CreateProcessWithTokenW(IN HANDLE hToken
,
3109 IN DWORD dwLogonFlags
,
3110 IN LPCWSTR lpApplicationName OPTIONAL
,
3111 IN OUT LPWSTR lpCommandLine OPTIONAL
,
3112 IN DWORD dwCreationFlags
,
3113 IN LPVOID lpEnvironment OPTIONAL
,
3114 IN LPCWSTR lpCurrentDirectory OPTIONAL
,
3115 IN LPSTARTUPINFOW lpStartupInfo
,
3116 OUT LPPROCESS_INFORMATION lpProcessInfo
)
3126 DuplicateTokenEx(IN HANDLE ExistingTokenHandle
,
3127 IN DWORD dwDesiredAccess
,
3128 IN LPSECURITY_ATTRIBUTES lpTokenAttributes OPTIONAL
,
3129 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
3130 IN TOKEN_TYPE TokenType
,
3131 OUT PHANDLE DuplicateTokenHandle
)
3133 OBJECT_ATTRIBUTES ObjectAttributes
;
3135 SECURITY_QUALITY_OF_SERVICE Sqos
;
3137 TRACE("%p 0x%08x 0x%08x 0x%08x %p\n", ExistingTokenHandle
, dwDesiredAccess
,
3138 ImpersonationLevel
, TokenType
, DuplicateTokenHandle
);
3140 Sqos
.Length
= sizeof(SECURITY_QUALITY_OF_SERVICE
);
3141 Sqos
.ImpersonationLevel
= ImpersonationLevel
;
3142 Sqos
.ContextTrackingMode
= 0;
3143 Sqos
.EffectiveOnly
= FALSE
;
3145 if (lpTokenAttributes
!= NULL
)
3147 InitializeObjectAttributes(&ObjectAttributes
,
3149 lpTokenAttributes
->bInheritHandle
? OBJ_INHERIT
: 0,
3151 lpTokenAttributes
->lpSecurityDescriptor
);
3155 InitializeObjectAttributes(&ObjectAttributes
,
3162 ObjectAttributes
.SecurityQualityOfService
= &Sqos
;
3164 Status
= NtDuplicateToken(ExistingTokenHandle
,
3169 DuplicateTokenHandle
);
3170 if (!NT_SUCCESS(Status
))
3172 ERR("NtDuplicateToken failed: Status %08x\n", Status
);
3173 SetLastError(RtlNtStatusToDosError(Status
));
3177 TRACE("Returning token %p.\n", *DuplicateTokenHandle
);
3186 DuplicateToken(IN HANDLE ExistingTokenHandle
,
3187 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
3188 OUT PHANDLE DuplicateTokenHandle
)
3190 return DuplicateTokenEx(ExistingTokenHandle
,
3191 TOKEN_IMPERSONATE
| TOKEN_QUERY
,
3195 DuplicateTokenHandle
);
3198 /******************************************************************************
3199 * ComputeStringSidSize
3201 static DWORD
ComputeStringSidSize(LPCWSTR StringSid
)
3203 if (StringSid
[0] == 'S' && StringSid
[1] == '-') /* S-R-I(-S)+ */
3208 if (*StringSid
== '-')
3214 return GetSidLengthRequired(ctok
- 2);
3216 else /* String constant format - Only available in winxp and above */
3220 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
3221 if (!strncmpW(WellKnownSids
[i
].wstr
, StringSid
, 2))
3222 return GetSidLengthRequired(WellKnownSids
[i
].Sid
.SubAuthorityCount
);
3225 return GetSidLengthRequired(0);
3228 /******************************************************************************
3229 * ParseStringSidToSid
3231 static BOOL
ParseStringSidToSid(LPCWSTR StringSid
, PSID pSid
, LPDWORD cBytes
)
3236 TRACE("%s, %p, %p\n", debugstr_w(StringSid
), pSid
, cBytes
);
3239 SetLastError(ERROR_INVALID_PARAMETER
);
3240 TRACE("StringSid is NULL, returning FALSE\n");
3244 while (*StringSid
== ' ')
3247 *cBytes
= ComputeStringSidSize(StringSid
);
3248 if (!pisid
) /* Simply compute the size */
3250 TRACE("only size requested, returning TRUE\n");
3254 if (StringSid
[0] == 'S' && StringSid
[1] == '-') /* S-R-I-S-S */
3256 DWORD i
= 0, identAuth
;
3257 DWORD csubauth
= ((*cBytes
- GetSidLengthRequired(0)) / sizeof(DWORD
));
3259 StringSid
+= 2; /* Advance to Revision */
3260 pisid
->Revision
= atoiW(StringSid
);
3262 if (pisid
->Revision
!= SDDL_REVISION
)
3264 TRACE("Revision %d is unknown\n", pisid
->Revision
);
3265 goto lend
; /* ERROR_INVALID_SID */
3269 TRACE("SubAuthorityCount is 0\n");
3270 goto lend
; /* ERROR_INVALID_SID */
3273 pisid
->SubAuthorityCount
= csubauth
;
3275 /* Advance to identifier authority */
3276 while (*StringSid
&& *StringSid
!= '-')
3278 if (*StringSid
== '-')
3281 /* MS' implementation can't handle values greater than 2^32 - 1, so
3282 * we don't either; assume most significant bytes are always 0
3284 pisid
->IdentifierAuthority
.Value
[0] = 0;
3285 pisid
->IdentifierAuthority
.Value
[1] = 0;
3286 identAuth
= atoiW(StringSid
);
3287 pisid
->IdentifierAuthority
.Value
[5] = identAuth
& 0xff;
3288 pisid
->IdentifierAuthority
.Value
[4] = (identAuth
& 0xff00) >> 8;
3289 pisid
->IdentifierAuthority
.Value
[3] = (identAuth
& 0xff0000) >> 16;
3290 pisid
->IdentifierAuthority
.Value
[2] = (identAuth
& 0xff000000) >> 24;
3292 /* Advance to first sub authority */
3293 while (*StringSid
&& *StringSid
!= '-')
3295 if (*StringSid
== '-')
3300 pisid
->SubAuthority
[i
++] = atoiW(StringSid
);
3302 while (*StringSid
&& *StringSid
!= '-')
3304 if (*StringSid
== '-')
3308 if (i
!= pisid
->SubAuthorityCount
)
3309 goto lend
; /* ERROR_INVALID_SID */
3313 else /* String constant format - Only available in winxp and above */
3316 pisid
->Revision
= SDDL_REVISION
;
3318 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
3319 if (!strncmpW(WellKnownSids
[i
].wstr
, StringSid
, 2))
3322 pisid
->SubAuthorityCount
= WellKnownSids
[i
].Sid
.SubAuthorityCount
;
3323 pisid
->IdentifierAuthority
= WellKnownSids
[i
].Sid
.IdentifierAuthority
;
3324 for (j
= 0; j
< WellKnownSids
[i
].Sid
.SubAuthorityCount
; j
++)
3325 pisid
->SubAuthority
[j
] = WellKnownSids
[i
].Sid
.SubAuthority
[j
];
3330 FIXME("String constant not supported: %s\n", debugstr_wn(StringSid
, 2));
3335 SetLastError(ERROR_INVALID_SID
);
3337 TRACE("returning %s\n", bret
? "TRUE" : "FALSE");
3341 /**********************************************************************
3342 * GetNamedSecurityInfoA EXPORTED
3348 GetNamedSecurityInfoA(LPSTR pObjectName
,
3349 SE_OBJECT_TYPE ObjectType
,
3350 SECURITY_INFORMATION SecurityInfo
,
3355 PSECURITY_DESCRIPTOR
*ppSecurityDescriptor
)
3361 TRACE("%s %d %d %p %p %p %p %p\n", pObjectName
, ObjectType
, SecurityInfo
,
3362 ppsidOwner
, ppsidGroup
, ppDacl
, ppSacl
, ppSecurityDescriptor
);
3366 len
= MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, NULL
, 0 );
3367 wstr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
3368 MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, wstr
, len
);
3371 r
= GetNamedSecurityInfoW( wstr
, ObjectType
, SecurityInfo
, ppsidOwner
,
3372 ppsidGroup
, ppDacl
, ppSacl
, ppSecurityDescriptor
);
3374 HeapFree( GetProcessHeap(), 0, wstr
);
3384 GetWindowsAccountDomainSid(IN PSID pSid
,
3385 OUT PSID ppDomainSid
,
3386 IN OUT DWORD
* cbSid
)
3397 EqualDomainSid(IN PSID pSid1
,