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
;
1816 /******************************************************************************
1817 * BuildExplicitAccessWithNameA [ADVAPI32.@]
1820 BuildExplicitAccessWithNameA(PEXPLICIT_ACCESSA pExplicitAccess
,
1822 DWORD AccessPermissions
,
1823 ACCESS_MODE AccessMode
,
1826 pExplicitAccess
->grfAccessPermissions
= AccessPermissions
;
1827 pExplicitAccess
->grfAccessMode
= AccessMode
;
1828 pExplicitAccess
->grfInheritance
= Inheritance
;
1830 pExplicitAccess
->Trustee
.pMultipleTrustee
= NULL
;
1831 pExplicitAccess
->Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1832 pExplicitAccess
->Trustee
.TrusteeForm
= TRUSTEE_IS_NAME
;
1833 pExplicitAccess
->Trustee
.TrusteeType
= TRUSTEE_IS_UNKNOWN
;
1834 pExplicitAccess
->Trustee
.ptstrName
= pTrusteeName
;
1838 /******************************************************************************
1839 * BuildExplicitAccessWithNameW [ADVAPI32.@]
1842 BuildExplicitAccessWithNameW(PEXPLICIT_ACCESSW pExplicitAccess
,
1843 LPWSTR pTrusteeName
,
1844 DWORD AccessPermissions
,
1845 ACCESS_MODE AccessMode
,
1848 pExplicitAccess
->grfAccessPermissions
= AccessPermissions
;
1849 pExplicitAccess
->grfAccessMode
= AccessMode
;
1850 pExplicitAccess
->grfInheritance
= Inheritance
;
1852 pExplicitAccess
->Trustee
.pMultipleTrustee
= NULL
;
1853 pExplicitAccess
->Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1854 pExplicitAccess
->Trustee
.TrusteeForm
= TRUSTEE_IS_NAME
;
1855 pExplicitAccess
->Trustee
.TrusteeType
= TRUSTEE_IS_UNKNOWN
;
1856 pExplicitAccess
->Trustee
.ptstrName
= pTrusteeName
;
1859 /******************************************************************************
1860 * BuildTrusteeWithObjectsAndNameA [ADVAPI32.@]
1862 VOID WINAPI
BuildTrusteeWithObjectsAndNameA( PTRUSTEEA pTrustee
, POBJECTS_AND_NAME_A pObjName
,
1863 SE_OBJECT_TYPE ObjectType
, LPSTR ObjectTypeName
,
1864 LPSTR InheritedObjectTypeName
, LPSTR Name
)
1866 DWORD ObjectsPresent
= 0;
1868 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee
, pObjName
,
1869 ObjectType
, ObjectTypeName
, InheritedObjectTypeName
, debugstr_a(Name
));
1871 /* Fill the OBJECTS_AND_NAME structure */
1872 pObjName
->ObjectType
= ObjectType
;
1873 if (ObjectTypeName
!= NULL
)
1875 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
1878 pObjName
->InheritedObjectTypeName
= InheritedObjectTypeName
;
1879 if (InheritedObjectTypeName
!= NULL
)
1881 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
1884 pObjName
->ObjectsPresent
= ObjectsPresent
;
1885 pObjName
->ptstrName
= Name
;
1887 /* Fill the TRUSTEE structure */
1888 pTrustee
->pMultipleTrustee
= NULL
;
1889 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1890 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_NAME
;
1891 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
1892 pTrustee
->ptstrName
= (LPSTR
)pObjName
;
1895 /******************************************************************************
1896 * BuildTrusteeWithObjectsAndNameW [ADVAPI32.@]
1898 VOID WINAPI
BuildTrusteeWithObjectsAndNameW( PTRUSTEEW pTrustee
, POBJECTS_AND_NAME_W pObjName
,
1899 SE_OBJECT_TYPE ObjectType
, LPWSTR ObjectTypeName
,
1900 LPWSTR InheritedObjectTypeName
, LPWSTR Name
)
1902 DWORD ObjectsPresent
= 0;
1904 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee
, pObjName
,
1905 ObjectType
, ObjectTypeName
, InheritedObjectTypeName
, debugstr_w(Name
));
1907 /* Fill the OBJECTS_AND_NAME structure */
1908 pObjName
->ObjectType
= ObjectType
;
1909 if (ObjectTypeName
!= NULL
)
1911 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
1914 pObjName
->InheritedObjectTypeName
= InheritedObjectTypeName
;
1915 if (InheritedObjectTypeName
!= NULL
)
1917 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
1920 pObjName
->ObjectsPresent
= ObjectsPresent
;
1921 pObjName
->ptstrName
= Name
;
1923 /* Fill the TRUSTEE structure */
1924 pTrustee
->pMultipleTrustee
= NULL
;
1925 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1926 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_NAME
;
1927 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
1928 pTrustee
->ptstrName
= (LPWSTR
)pObjName
;
1931 /******************************************************************************
1932 * BuildTrusteeWithObjectsAndSidA [ADVAPI32.@]
1935 BuildTrusteeWithObjectsAndSidA(PTRUSTEEA pTrustee
,
1936 POBJECTS_AND_SID pObjSid
,
1938 GUID
*pInheritedObjectGuid
,
1941 DWORD ObjectsPresent
= 0;
1943 TRACE("%p %p %p %p %p\n", pTrustee
, pObjSid
, pObjectGuid
, pInheritedObjectGuid
, pSid
);
1945 /* Fill the OBJECTS_AND_SID structure */
1946 if (pObjectGuid
!= NULL
)
1948 pObjSid
->ObjectTypeGuid
= *pObjectGuid
;
1949 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
1953 ZeroMemory(&pObjSid
->ObjectTypeGuid
,
1957 if (pInheritedObjectGuid
!= NULL
)
1959 pObjSid
->InheritedObjectTypeGuid
= *pInheritedObjectGuid
;
1960 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
1964 ZeroMemory(&pObjSid
->InheritedObjectTypeGuid
,
1968 pObjSid
->ObjectsPresent
= ObjectsPresent
;
1969 pObjSid
->pSid
= pSid
;
1971 /* Fill the TRUSTEE structure */
1972 pTrustee
->pMultipleTrustee
= NULL
;
1973 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1974 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_SID
;
1975 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
1976 pTrustee
->ptstrName
= (LPSTR
) pObjSid
;
1980 /******************************************************************************
1981 * BuildTrusteeWithObjectsAndSidW [ADVAPI32.@]
1984 BuildTrusteeWithObjectsAndSidW(PTRUSTEEW pTrustee
,
1985 POBJECTS_AND_SID pObjSid
,
1987 GUID
*pInheritedObjectGuid
,
1990 DWORD ObjectsPresent
= 0;
1992 TRACE("%p %p %p %p %p\n", pTrustee
, pObjSid
, pObjectGuid
, pInheritedObjectGuid
, pSid
);
1994 /* Fill the OBJECTS_AND_SID structure */
1995 if (pObjectGuid
!= NULL
)
1997 pObjSid
->ObjectTypeGuid
= *pObjectGuid
;
1998 ObjectsPresent
|= ACE_OBJECT_TYPE_PRESENT
;
2002 ZeroMemory(&pObjSid
->ObjectTypeGuid
,
2006 if (pInheritedObjectGuid
!= NULL
)
2008 pObjSid
->InheritedObjectTypeGuid
= *pInheritedObjectGuid
;
2009 ObjectsPresent
|= ACE_INHERITED_OBJECT_TYPE_PRESENT
;
2013 ZeroMemory(&pObjSid
->InheritedObjectTypeGuid
,
2017 pObjSid
->ObjectsPresent
= ObjectsPresent
;
2018 pObjSid
->pSid
= pSid
;
2020 /* Fill the TRUSTEE structure */
2021 pTrustee
->pMultipleTrustee
= NULL
;
2022 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2023 pTrustee
->TrusteeForm
= TRUSTEE_IS_OBJECTS_AND_SID
;
2024 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2025 pTrustee
->ptstrName
= (LPWSTR
) pObjSid
;
2028 /******************************************************************************
2029 * BuildTrusteeWithSidA [ADVAPI32.@]
2032 BuildTrusteeWithSidA(PTRUSTEE_A pTrustee
,
2035 TRACE("%p %p\n", pTrustee
, pSid
);
2037 pTrustee
->pMultipleTrustee
= NULL
;
2038 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2039 pTrustee
->TrusteeForm
= TRUSTEE_IS_SID
;
2040 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2041 pTrustee
->ptstrName
= (LPSTR
) pSid
;
2045 /******************************************************************************
2046 * BuildTrusteeWithSidW [ADVAPI32.@]
2049 BuildTrusteeWithSidW(PTRUSTEE_W pTrustee
,
2052 TRACE("%p %p\n", pTrustee
, pSid
);
2054 pTrustee
->pMultipleTrustee
= NULL
;
2055 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2056 pTrustee
->TrusteeForm
= TRUSTEE_IS_SID
;
2057 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2058 pTrustee
->ptstrName
= (LPWSTR
) pSid
;
2061 /******************************************************************************
2062 * BuildTrusteeWithNameA [ADVAPI32.@]
2065 BuildTrusteeWithNameA(PTRUSTEE_A pTrustee
,
2068 TRACE("%p %s\n", pTrustee
, name
);
2070 pTrustee
->pMultipleTrustee
= NULL
;
2071 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2072 pTrustee
->TrusteeForm
= TRUSTEE_IS_NAME
;
2073 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2074 pTrustee
->ptstrName
= name
;
2077 /******************************************************************************
2078 * BuildTrusteeWithNameW [ADVAPI32.@]
2081 BuildTrusteeWithNameW(PTRUSTEE_W pTrustee
,
2084 TRACE("%p %s\n", pTrustee
, name
);
2086 pTrustee
->pMultipleTrustee
= NULL
;
2087 pTrustee
->MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
2088 pTrustee
->TrusteeForm
= TRUSTEE_IS_NAME
;
2089 pTrustee
->TrusteeType
= TRUSTEE_IS_UNKNOWN
;
2090 pTrustee
->ptstrName
= name
;
2093 /******************************************************************************
2094 * GetTrusteeFormW [ADVAPI32.@]
2097 GetTrusteeFormA(PTRUSTEE_A pTrustee
)
2099 return pTrustee
->TrusteeForm
;
2103 /******************************************************************************
2104 * GetTrusteeFormW [ADVAPI32.@]
2107 GetTrusteeFormW(PTRUSTEE_W pTrustee
)
2109 return pTrustee
->TrusteeForm
;
2112 /******************************************************************************
2113 * GetTrusteeNameA [ADVAPI32.@]
2116 GetTrusteeNameA(PTRUSTEE_A pTrustee
)
2118 return pTrustee
->ptstrName
;
2122 /******************************************************************************
2123 * GetTrusteeNameW [ADVAPI32.@]
2126 GetTrusteeNameW(PTRUSTEE_W pTrustee
)
2128 return pTrustee
->ptstrName
;
2131 /******************************************************************************
2132 * GetTrusteeTypeA [ADVAPI32.@]
2135 GetTrusteeTypeA(PTRUSTEE_A pTrustee
)
2137 return pTrustee
->TrusteeType
;
2140 /******************************************************************************
2141 * GetTrusteeTypeW [ADVAPI32.@]
2144 GetTrusteeTypeW(PTRUSTEE_W pTrustee
)
2146 return pTrustee
->TrusteeType
;
2154 SetAclInformation(PACL pAcl
,
2155 LPVOID pAclInformation
,
2156 DWORD nAclInformationLength
,
2157 ACL_INFORMATION_CLASS dwAclInformationClass
)
2161 Status
= RtlSetInformationAcl(pAcl
,
2163 nAclInformationLength
,
2164 dwAclInformationClass
);
2165 if (!NT_SUCCESS(Status
))
2167 SetLastError(RtlNtStatusToDosError(Status
));
2174 /**********************************************************************
2175 * SetNamedSecurityInfoA EXPORTED
2181 SetNamedSecurityInfoA(LPSTR pObjectName
,
2182 SE_OBJECT_TYPE ObjectType
,
2183 SECURITY_INFORMATION SecurityInfo
,
2189 UNICODE_STRING ObjectName
;
2192 if (!RtlCreateUnicodeStringFromAsciiz(&ObjectName
, pObjectName
))
2194 return ERROR_NOT_ENOUGH_MEMORY
;
2197 Ret
= SetNamedSecurityInfoW(ObjectName
.Buffer
,
2205 RtlFreeUnicodeString(&ObjectName
);
2215 AreAllAccessesGranted(DWORD GrantedAccess
,
2216 DWORD DesiredAccess
)
2218 return (BOOL
)RtlAreAllAccessesGranted(GrantedAccess
,
2227 AreAnyAccessesGranted(DWORD GrantedAccess
,
2228 DWORD DesiredAccess
)
2230 return (BOOL
)RtlAreAnyAccessesGranted(GrantedAccess
,
2234 /******************************************************************************
2235 * ParseAclStringFlags
2237 static DWORD
ParseAclStringFlags(LPCWSTR
* StringAcl
)
2240 LPCWSTR szAcl
= *StringAcl
;
2242 while (*szAcl
!= '(')
2246 flags
|= SE_DACL_PROTECTED
;
2248 else if (*szAcl
== 'A')
2252 flags
|= SE_DACL_AUTO_INHERIT_REQ
;
2253 else if (*szAcl
== 'I')
2254 flags
|= SE_DACL_AUTO_INHERITED
;
2263 /******************************************************************************
2264 * ParseAceStringType
2266 static const ACEFLAG AceType
[] =
2268 { SDDL_ALARM
, SYSTEM_ALARM_ACE_TYPE
},
2269 { SDDL_AUDIT
, SYSTEM_AUDIT_ACE_TYPE
},
2270 { SDDL_ACCESS_ALLOWED
, ACCESS_ALLOWED_ACE_TYPE
},
2271 { SDDL_ACCESS_DENIED
, ACCESS_DENIED_ACE_TYPE
},
2273 { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
2274 { SDDL_OBJECT_ACCESS_DENIED, ACCESS_DENIED_OBJECT_ACE_TYPE },
2275 { SDDL_OBJECT_ALARM, SYSTEM_ALARM_OBJECT_ACE_TYPE },
2276 { SDDL_OBJECT_AUDIT, SYSTEM_AUDIT_OBJECT_ACE_TYPE },
2281 static BYTE
ParseAceStringType(LPCWSTR
* StringAcl
)
2284 LPCWSTR szAcl
= *StringAcl
;
2285 const ACEFLAG
*lpaf
= AceType
;
2287 while (lpaf
->wstr
&&
2288 (len
= strlenW(lpaf
->wstr
)) &&
2289 strncmpW(lpaf
->wstr
, szAcl
, len
))
2300 /******************************************************************************
2301 * ParseAceStringFlags
2303 static const ACEFLAG AceFlags
[] =
2305 { SDDL_CONTAINER_INHERIT
, CONTAINER_INHERIT_ACE
},
2306 { SDDL_AUDIT_FAILURE
, FAILED_ACCESS_ACE_FLAG
},
2307 { SDDL_INHERITED
, INHERITED_ACE
},
2308 { SDDL_INHERIT_ONLY
, INHERIT_ONLY_ACE
},
2309 { SDDL_NO_PROPAGATE
, NO_PROPAGATE_INHERIT_ACE
},
2310 { SDDL_OBJECT_INHERIT
, OBJECT_INHERIT_ACE
},
2311 { SDDL_AUDIT_SUCCESS
, SUCCESSFUL_ACCESS_ACE_FLAG
},
2315 static BYTE
ParseAceStringFlags(LPCWSTR
* StringAcl
)
2319 LPCWSTR szAcl
= *StringAcl
;
2321 while (*szAcl
!= ';')
2323 const ACEFLAG
*lpaf
= AceFlags
;
2325 while (lpaf
->wstr
&&
2326 (len
= strlenW(lpaf
->wstr
)) &&
2327 strncmpW(lpaf
->wstr
, szAcl
, len
))
2333 flags
|= lpaf
->value
;
2342 /******************************************************************************
2343 * ParseAceStringRights
2345 static DWORD
ParseAceStringRights(LPCWSTR
* StringAcl
)
2349 LPCWSTR szAcl
= *StringAcl
;
2351 if ((*szAcl
== '0') && (*(szAcl
+ 1) == 'x'))
2355 while (*p
&& *p
!= ';')
2358 if (p
- szAcl
<= 10 /* 8 hex digits + "0x" */ )
2360 rights
= strtoulW(szAcl
, NULL
, 16);
2364 WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl
, p
- szAcl
));
2368 while (*szAcl
!= ';')
2370 const ACEFLAG
*lpaf
= AceRights
;
2372 while (lpaf
->wstr
&&
2373 (len
= strlenW(lpaf
->wstr
)) &&
2374 strncmpW(lpaf
->wstr
, szAcl
, len
))
2382 rights
|= lpaf
->value
;
2392 /******************************************************************************
2393 * ParseStringAclToAcl
2395 * dacl_flags(string_ace1)(string_ace2)... (string_acen)
2398 ParseStringAclToAcl(LPCWSTR StringAcl
,
2405 DWORD length
= sizeof(ACL
);
2408 PACCESS_ALLOWED_ACE pAce
= NULL
; /* pointer to current ACE */
2410 TRACE("%s\n", debugstr_w(StringAcl
));
2415 if (pAcl
) /* pAce is only useful if we're setting values */
2416 pAce
= (PACCESS_ALLOWED_ACE
) (pAcl
+ 1);
2418 /* Parse ACL flags */
2419 *lpdwFlags
= ParseAclStringFlags(&StringAcl
);
2422 while (*StringAcl
== '(')
2426 /* Parse ACE type */
2427 val
= ParseAceStringType(&StringAcl
);
2429 pAce
->Header
.AceType
= (BYTE
) val
;
2430 if (*StringAcl
!= ';')
2434 /* Parse ACE flags */
2435 val
= ParseAceStringFlags(&StringAcl
);
2437 pAce
->Header
.AceFlags
= (BYTE
) val
;
2438 if (*StringAcl
!= ';')
2442 /* Parse ACE rights */
2443 val
= ParseAceStringRights(&StringAcl
);
2446 if (*StringAcl
!= ';')
2450 /* Parse ACE object guid */
2451 if (*StringAcl
!= ';')
2453 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
2458 /* Parse ACE inherit object guid */
2459 if (*StringAcl
!= ';')
2461 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
2466 /* Parse ACE account sid */
2467 if (ParseStringSidToSid(StringAcl
, pAce
? &pAce
->SidStart
: NULL
, &sidlen
))
2469 while (*StringAcl
&& *StringAcl
!= ')')
2473 if (*StringAcl
!= ')')
2477 acesize
= sizeof(ACCESS_ALLOWED_ACE
) - sizeof(DWORD
) + sidlen
;
2481 pAce
->Header
.AceSize
= acesize
;
2482 pAce
= (PACCESS_ALLOWED_ACE
)((LPBYTE
)pAce
+ acesize
);
2489 if (length
> 0xffff)
2491 ERR("ACL too large\n");
2497 pAcl
->AclRevision
= ACL_REVISION
;
2499 pAcl
->AclSize
= length
;
2500 pAcl
->AceCount
= acecount
++;
2506 SetLastError(ERROR_INVALID_ACL
);
2507 WARN("Invalid ACE string format\n");
2512 /******************************************************************************
2513 * ParseStringSecurityDescriptorToSecurityDescriptor
2516 ParseStringSecurityDescriptorToSecurityDescriptor(LPCWSTR StringSecurityDescriptor
,
2517 SECURITY_DESCRIPTOR_RELATIVE
* SecurityDescriptor
,
2522 WCHAR tok
[MAX_PATH
];
2524 LPBYTE lpNext
= NULL
;
2527 *cBytes
= sizeof(SECURITY_DESCRIPTOR
);
2529 if (SecurityDescriptor
)
2530 lpNext
= (LPBYTE
)(SecurityDescriptor
+ 1);
2532 while (*StringSecurityDescriptor
)
2534 toktype
= *StringSecurityDescriptor
;
2536 /* Expect char identifier followed by ':' */
2537 StringSecurityDescriptor
++;
2538 if (*StringSecurityDescriptor
!= ':')
2540 SetLastError(ERROR_INVALID_PARAMETER
);
2543 StringSecurityDescriptor
++;
2546 lptoken
= StringSecurityDescriptor
;
2547 while (*lptoken
&& *lptoken
!= ':')
2553 len
= lptoken
- StringSecurityDescriptor
;
2554 memcpy( tok
, StringSecurityDescriptor
, len
* sizeof(WCHAR
) );
2563 if (!ParseStringSidToSid(tok
, lpNext
, &bytes
))
2566 if (SecurityDescriptor
)
2568 SecurityDescriptor
->Owner
= lpNext
- (LPBYTE
)SecurityDescriptor
;
2569 lpNext
+= bytes
; /* Advance to next token */
2581 if (!ParseStringSidToSid(tok
, lpNext
, &bytes
))
2584 if (SecurityDescriptor
)
2586 SecurityDescriptor
->Group
= lpNext
- (LPBYTE
)SecurityDescriptor
;
2587 lpNext
+= bytes
; /* Advance to next token */
2600 if (!ParseStringAclToAcl(tok
, &flags
, (PACL
)lpNext
, &bytes
))
2603 if (SecurityDescriptor
)
2605 SecurityDescriptor
->Control
|= SE_DACL_PRESENT
| flags
;
2606 SecurityDescriptor
->Dacl
= lpNext
- (LPBYTE
)SecurityDescriptor
;
2607 lpNext
+= bytes
; /* Advance to next token */
2620 if (!ParseStringAclToAcl(tok
, &flags
, (PACL
)lpNext
, &bytes
))
2623 if (SecurityDescriptor
)
2625 SecurityDescriptor
->Control
|= SE_SACL_PRESENT
| flags
;
2626 SecurityDescriptor
->Sacl
= lpNext
- (LPBYTE
)SecurityDescriptor
;
2627 lpNext
+= bytes
; /* Advance to next token */
2636 FIXME("Unknown token\n");
2637 SetLastError(ERROR_INVALID_PARAMETER
);
2641 StringSecurityDescriptor
= lptoken
;
2650 /* Winehq cvs 20050916 */
2651 /******************************************************************************
2652 * ConvertStringSecurityDescriptorToSecurityDescriptorA [ADVAPI32.@]
2657 ConvertStringSecurityDescriptorToSecurityDescriptorA(LPCSTR StringSecurityDescriptor
,
2658 DWORD StringSDRevision
,
2659 PSECURITY_DESCRIPTOR
* SecurityDescriptor
,
2660 PULONG SecurityDescriptorSize
)
2664 LPWSTR StringSecurityDescriptorW
;
2666 len
= MultiByteToWideChar(CP_ACP
, 0, StringSecurityDescriptor
, -1, NULL
, 0);
2667 StringSecurityDescriptorW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2669 if (StringSecurityDescriptorW
)
2671 MultiByteToWideChar(CP_ACP
, 0, StringSecurityDescriptor
, -1, StringSecurityDescriptorW
, len
);
2673 ret
= ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptorW
,
2674 StringSDRevision
, SecurityDescriptor
,
2675 SecurityDescriptorSize
);
2676 HeapFree(GetProcessHeap(), 0, StringSecurityDescriptorW
);
2682 /******************************************************************************
2683 * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
2687 ConvertStringSecurityDescriptorToSecurityDescriptorW(LPCWSTR StringSecurityDescriptor
,
2688 DWORD StringSDRevision
,
2689 PSECURITY_DESCRIPTOR
* SecurityDescriptor
,
2690 PULONG SecurityDescriptorSize
)
2693 SECURITY_DESCRIPTOR
* psd
;
2696 TRACE("%s\n", debugstr_w(StringSecurityDescriptor
));
2698 if (GetVersion() & 0x80000000)
2700 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2703 else if (!StringSecurityDescriptor
|| !SecurityDescriptor
)
2705 SetLastError(ERROR_INVALID_PARAMETER
);
2708 else if (StringSDRevision
!= SID_REVISION
)
2710 SetLastError(ERROR_UNKNOWN_REVISION
);
2714 /* Compute security descriptor length */
2715 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor
,
2719 psd
= *SecurityDescriptor
= LocalAlloc(GMEM_ZEROINIT
, cBytes
);
2720 if (!psd
) goto lend
;
2722 psd
->Revision
= SID_REVISION
;
2723 psd
->Control
|= SE_SELF_RELATIVE
;
2725 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor
,
2726 (SECURITY_DESCRIPTOR_RELATIVE
*)psd
, &cBytes
))
2732 if (SecurityDescriptorSize
)
2733 *SecurityDescriptorSize
= cBytes
;
2738 TRACE(" ret=%d\n", bret
);
2742 static void DumpString(LPCWSTR string
, int cch
, WCHAR
**pwptr
, ULONG
*plen
)
2745 cch
= strlenW(string
);
2752 memcpy(*pwptr
, string
, sizeof(WCHAR
)*cch
);
2757 static BOOL
DumpSidNumeric(PSID psid
, WCHAR
**pwptr
, ULONG
*plen
)
2760 WCHAR fmt
[] = { 'S','-','%','u','-','%','d',0 };
2761 WCHAR subauthfmt
[] = { '-','%','u',0 };
2765 if( !IsValidSid( psid
) || pisid
->Revision
!= SDDL_REVISION
)
2767 SetLastError(ERROR_INVALID_SID
);
2771 if (pisid
->IdentifierAuthority
.Value
[0] ||
2772 pisid
->IdentifierAuthority
.Value
[1])
2774 FIXME("not matching MS' bugs\n");
2775 SetLastError(ERROR_INVALID_SID
);
2779 sprintfW( buf
, fmt
, pisid
->Revision
,
2781 MAKEWORD( pisid
->IdentifierAuthority
.Value
[5],
2782 pisid
->IdentifierAuthority
.Value
[4] ),
2783 MAKEWORD( pisid
->IdentifierAuthority
.Value
[3],
2784 pisid
->IdentifierAuthority
.Value
[2] )
2786 DumpString(buf
, -1, pwptr
, plen
);
2788 for( i
=0; i
<pisid
->SubAuthorityCount
; i
++ )
2790 sprintfW( buf
, subauthfmt
, pisid
->SubAuthority
[i
] );
2791 DumpString(buf
, -1, pwptr
, plen
);
2796 static BOOL
DumpSid(PSID psid
, WCHAR
**pwptr
, ULONG
*plen
)
2799 for (i
= 0; i
< sizeof(WellKnownSids
) / sizeof(WellKnownSids
[0]); i
++)
2801 if (WellKnownSids
[i
].wstr
[0] && EqualSid(psid
, (PSID
)&(WellKnownSids
[i
].Sid
.Revision
)))
2803 DumpString(WellKnownSids
[i
].wstr
, 2, pwptr
, plen
);
2808 return DumpSidNumeric(psid
, pwptr
, plen
);
2811 static const LPCWSTR AceRightBitNames
[32] = {
2812 SDDL_CREATE_CHILD
, /* 0 */
2816 SDDL_READ_PROPERTY
, /* 4 */
2817 SDDL_WRITE_PROPERTY
,
2820 SDDL_CONTROL_ACCESS
, /* 8 */
2828 SDDL_STANDARD_DELETE
, /* 16 */
2840 SDDL_GENERIC_ALL
, /* 28 */
2841 SDDL_GENERIC_EXECUTE
,
2846 static void DumpRights(DWORD mask
, WCHAR
**pwptr
, ULONG
*plen
)
2848 static const WCHAR fmtW
[] = {'0','x','%','x',0};
2855 /* first check if the right have name */
2856 for (i
= 0; i
< sizeof(AceRights
)/sizeof(AceRights
[0]); i
++)
2858 if (AceRights
[i
].wstr
== NULL
)
2860 if (mask
== AceRights
[i
].value
)
2862 DumpString(AceRights
[i
].wstr
, -1, pwptr
, plen
);
2867 /* then check if it can be built from bit names */
2868 for (i
= 0; i
< 32; i
++)
2870 if ((mask
& (1 << i
)) && (AceRightBitNames
[i
] == NULL
))
2872 /* can't be built from bit names */
2873 sprintfW(buf
, fmtW
, mask
);
2874 DumpString(buf
, -1, pwptr
, plen
);
2879 /* build from bit names */
2880 for (i
= 0; i
< 32; i
++)
2881 if (mask
& (1 << i
))
2882 DumpString(AceRightBitNames
[i
], -1, pwptr
, plen
);
2885 static BOOL
DumpAce(LPVOID pace
, WCHAR
**pwptr
, ULONG
*plen
)
2887 ACCESS_ALLOWED_ACE
*piace
; /* all the supported ACEs have the same memory layout */
2888 static const WCHAR openbr
= '(';
2889 static const WCHAR closebr
= ')';
2890 static const WCHAR semicolon
= ';';
2892 if (((PACE_HEADER
)pace
)->AceType
> SYSTEM_ALARM_ACE_TYPE
|| ((PACE_HEADER
)pace
)->AceSize
< sizeof(ACCESS_ALLOWED_ACE
))
2894 SetLastError(ERROR_INVALID_ACL
);
2899 DumpString(&openbr
, 1, pwptr
, plen
);
2900 switch (piace
->Header
.AceType
)
2902 case ACCESS_ALLOWED_ACE_TYPE
:
2903 DumpString(SDDL_ACCESS_ALLOWED
, -1, pwptr
, plen
);
2905 case ACCESS_DENIED_ACE_TYPE
:
2906 DumpString(SDDL_ACCESS_DENIED
, -1, pwptr
, plen
);
2908 case SYSTEM_AUDIT_ACE_TYPE
:
2909 DumpString(SDDL_AUDIT
, -1, pwptr
, plen
);
2911 case SYSTEM_ALARM_ACE_TYPE
:
2912 DumpString(SDDL_ALARM
, -1, pwptr
, plen
);
2915 DumpString(&semicolon
, 1, pwptr
, plen
);
2917 if (piace
->Header
.AceFlags
& OBJECT_INHERIT_ACE
)
2918 DumpString(SDDL_OBJECT_INHERIT
, -1, pwptr
, plen
);
2919 if (piace
->Header
.AceFlags
& CONTAINER_INHERIT_ACE
)
2920 DumpString(SDDL_CONTAINER_INHERIT
, -1, pwptr
, plen
);
2921 if (piace
->Header
.AceFlags
& NO_PROPAGATE_INHERIT_ACE
)
2922 DumpString(SDDL_NO_PROPAGATE
, -1, pwptr
, plen
);
2923 if (piace
->Header
.AceFlags
& INHERIT_ONLY_ACE
)
2924 DumpString(SDDL_INHERIT_ONLY
, -1, pwptr
, plen
);
2925 if (piace
->Header
.AceFlags
& INHERITED_ACE
)
2926 DumpString(SDDL_INHERITED
, -1, pwptr
, plen
);
2927 if (piace
->Header
.AceFlags
& SUCCESSFUL_ACCESS_ACE_FLAG
)
2928 DumpString(SDDL_AUDIT_SUCCESS
, -1, pwptr
, plen
);
2929 if (piace
->Header
.AceFlags
& FAILED_ACCESS_ACE_FLAG
)
2930 DumpString(SDDL_AUDIT_FAILURE
, -1, pwptr
, plen
);
2931 DumpString(&semicolon
, 1, pwptr
, plen
);
2932 DumpRights(piace
->Mask
, pwptr
, plen
);
2933 DumpString(&semicolon
, 1, pwptr
, plen
);
2934 /* objects not supported */
2935 DumpString(&semicolon
, 1, pwptr
, plen
);
2936 /* objects not supported */
2937 DumpString(&semicolon
, 1, pwptr
, plen
);
2938 if (!DumpSid((PSID
)&piace
->SidStart
, pwptr
, plen
))
2940 DumpString(&closebr
, 1, pwptr
, plen
);
2944 static BOOL
DumpAcl(PACL pacl
, WCHAR
**pwptr
, ULONG
*plen
, BOOL
protected, BOOL autoInheritReq
, BOOL autoInherited
)
2950 DumpString(SDDL_PROTECTED
, -1, pwptr
, plen
);
2952 DumpString(SDDL_AUTO_INHERIT_REQ
, -1, pwptr
, plen
);
2954 DumpString(SDDL_AUTO_INHERITED
, -1, pwptr
, plen
);
2959 if (!IsValidAcl(pacl
))
2962 count
= pacl
->AceCount
;
2963 for (i
= 0; i
< count
; i
++)
2966 if (!GetAce(pacl
, i
, &ace
))
2968 if (!DumpAce(ace
, pwptr
, plen
))
2975 static BOOL
DumpOwner(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
2977 static const WCHAR prefix
[] = {'O',':',0};
2981 if (!GetSecurityDescriptorOwner(SecurityDescriptor
, &psid
, &bDefaulted
))
2987 DumpString(prefix
, -1, pwptr
, plen
);
2988 if (!DumpSid(psid
, pwptr
, plen
))
2993 static BOOL
DumpGroup(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
2995 static const WCHAR prefix
[] = {'G',':',0};
2999 if (!GetSecurityDescriptorGroup(SecurityDescriptor
, &psid
, &bDefaulted
))
3005 DumpString(prefix
, -1, pwptr
, plen
);
3006 if (!DumpSid(psid
, pwptr
, plen
))
3011 static BOOL
DumpDacl(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
3013 static const WCHAR dacl
[] = {'D',':',0};
3014 SECURITY_DESCRIPTOR_CONTROL control
;
3015 BOOL present
, defaulted
;
3019 if (!GetSecurityDescriptorDacl(SecurityDescriptor
, &present
, &pacl
, &defaulted
))
3022 if (!GetSecurityDescriptorControl(SecurityDescriptor
, &control
, &revision
))
3028 DumpString(dacl
, 2, pwptr
, plen
);
3029 if (!DumpAcl(pacl
, pwptr
, plen
, control
& SE_DACL_PROTECTED
, control
& SE_DACL_AUTO_INHERIT_REQ
, control
& SE_DACL_AUTO_INHERITED
))
3034 static BOOL
DumpSacl(PSECURITY_DESCRIPTOR SecurityDescriptor
, WCHAR
**pwptr
, ULONG
*plen
)
3036 static const WCHAR sacl
[] = {'S',':',0};
3037 SECURITY_DESCRIPTOR_CONTROL control
;
3038 BOOL present
, defaulted
;
3042 if (!GetSecurityDescriptorSacl(SecurityDescriptor
, &present
, &pacl
, &defaulted
))
3045 if (!GetSecurityDescriptorControl(SecurityDescriptor
, &control
, &revision
))
3051 DumpString(sacl
, 2, pwptr
, plen
);
3052 if (!DumpAcl(pacl
, pwptr
, plen
, control
& SE_SACL_PROTECTED
, control
& SE_SACL_AUTO_INHERIT_REQ
, control
& SE_SACL_AUTO_INHERITED
))
3057 /******************************************************************************
3058 * ConvertSecurityDescriptorToStringSecurityDescriptorW [ADVAPI32.@]
3062 ConvertSecurityDescriptorToStringSecurityDescriptorW(PSECURITY_DESCRIPTOR SecurityDescriptor
,
3064 SECURITY_INFORMATION SecurityInformation
,
3065 LPWSTR
*OutputString
,
3071 if (SDRevision
!= SDDL_REVISION_1
)
3073 ERR("Program requested unknown SDDL revision %d\n", SDRevision
);
3074 SetLastError(ERROR_UNKNOWN_REVISION
);
3079 if (SecurityInformation
& OWNER_SECURITY_INFORMATION
)
3080 if (!DumpOwner(SecurityDescriptor
, NULL
, &len
))
3082 if (SecurityInformation
& GROUP_SECURITY_INFORMATION
)
3083 if (!DumpGroup(SecurityDescriptor
, NULL
, &len
))
3085 if (SecurityInformation
& DACL_SECURITY_INFORMATION
)
3086 if (!DumpDacl(SecurityDescriptor
, NULL
, &len
))
3088 if (SecurityInformation
& SACL_SECURITY_INFORMATION
)
3089 if (!DumpSacl(SecurityDescriptor
, NULL
, &len
))
3092 wstr
= wptr
= LocalAlloc(0, (len
+ 1)*sizeof(WCHAR
));
3096 if (SecurityInformation
& OWNER_SECURITY_INFORMATION
)
3097 if (!DumpOwner(SecurityDescriptor
, &wptr
, NULL
))
3099 if (SecurityInformation
& GROUP_SECURITY_INFORMATION
)
3100 if (!DumpGroup(SecurityDescriptor
, &wptr
, NULL
))
3102 if (SecurityInformation
& DACL_SECURITY_INFORMATION
)
3103 if (!DumpDacl(SecurityDescriptor
, &wptr
, NULL
))
3105 if (SecurityInformation
& SACL_SECURITY_INFORMATION
)
3106 if (!DumpSacl(SecurityDescriptor
, &wptr
, NULL
))
3110 TRACE("ret: %s, %d\n", wine_dbgstr_w(wstr
), len
);
3111 *OutputString
= wstr
;
3113 *OutputLen
= strlenW(*OutputString
)+1;
3117 /******************************************************************************
3118 * ConvertSecurityDescriptorToStringSecurityDescriptorA [ADVAPI32.@]
3122 ConvertSecurityDescriptorToStringSecurityDescriptorA(PSECURITY_DESCRIPTOR SecurityDescriptor
,
3124 SECURITY_INFORMATION Information
,
3125 LPSTR
*OutputString
,
3131 if (ConvertSecurityDescriptorToStringSecurityDescriptorW(SecurityDescriptor
, SDRevision
, Information
, &wstr
, &len
))
3135 lenA
= WideCharToMultiByte(CP_ACP
, 0, wstr
, len
, NULL
, 0, NULL
, NULL
);
3136 *OutputString
= HeapAlloc(GetProcessHeap(), 0, lenA
);
3137 if (*OutputString
== NULL
)
3143 WideCharToMultiByte(CP_ACP
, 0, wstr
, len
, *OutputString
, lenA
, NULL
, NULL
);
3146 if (OutputLen
!= NULL
)
3152 *OutputString
= NULL
;
3164 ConvertStringSidToSidW(IN LPCWSTR StringSid
,
3168 DWORD i
, cBytes
, identAuth
, csubauth
;
3172 TRACE("%s %p\n", debugstr_w(StringSid
), sid
);
3176 SetLastError(ERROR_INVALID_SID
);
3180 for (i
= 0; i
< sizeof(SidTable
) / sizeof(SidTable
[0]) - 1; i
++)
3182 if (wcscmp(StringSid
, SidTable
[i
].key
) == 0)
3184 WELL_KNOWN_SID_TYPE knownSid
= (WELL_KNOWN_SID_TYPE
)SidTable
[i
].value
;
3185 size
= SECURITY_MAX_SID_SIZE
;
3186 *sid
= LocalAlloc(0, size
);
3189 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3192 ret
= CreateWellKnownSid(knownSid
,
3198 SetLastError(ERROR_INVALID_SID
);
3205 /* That's probably a string S-R-I-S-S... */
3206 if (StringSid
[0] != 'S' || StringSid
[1] != '-')
3208 SetLastError(ERROR_INVALID_SID
);
3212 cBytes
= ComputeStringSidSize(StringSid
);
3213 pisid
= (SID
*)LocalAlloc( 0, cBytes
);
3216 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3221 csubauth
= ((cBytes
- GetSidLengthRequired(0)) / sizeof(DWORD
));
3223 StringSid
+= 2; /* Advance to Revision */
3224 pisid
->Revision
= atoiW(StringSid
);
3226 if (pisid
->Revision
!= SDDL_REVISION
)
3228 TRACE("Revision %d is unknown\n", pisid
->Revision
);
3229 goto lend
; /* ERROR_INVALID_SID */
3233 TRACE("SubAuthorityCount is 0\n");
3234 goto lend
; /* ERROR_INVALID_SID */
3237 pisid
->SubAuthorityCount
= csubauth
;
3239 /* Advance to identifier authority */
3240 while (*StringSid
&& *StringSid
!= '-')
3242 if (*StringSid
== '-')
3245 /* MS' implementation can't handle values greater than 2^32 - 1, so
3246 * we don't either; assume most significant bytes are always 0
3248 pisid
->IdentifierAuthority
.Value
[0] = 0;
3249 pisid
->IdentifierAuthority
.Value
[1] = 0;
3250 identAuth
= atoiW(StringSid
);
3251 pisid
->IdentifierAuthority
.Value
[5] = identAuth
& 0xff;
3252 pisid
->IdentifierAuthority
.Value
[4] = (identAuth
& 0xff00) >> 8;
3253 pisid
->IdentifierAuthority
.Value
[3] = (identAuth
& 0xff0000) >> 16;
3254 pisid
->IdentifierAuthority
.Value
[2] = (identAuth
& 0xff000000) >> 24;
3256 /* Advance to first sub authority */
3257 while (*StringSid
&& *StringSid
!= '-')
3259 if (*StringSid
== '-')
3264 pisid
->SubAuthority
[i
++] = atoiW(StringSid
);
3266 while (*StringSid
&& *StringSid
!= '-')
3268 if (*StringSid
== '-')
3272 if (i
!= pisid
->SubAuthorityCount
)
3273 goto lend
; /* ERROR_INVALID_SID */
3282 SetLastError(ERROR_INVALID_SID
);
3285 TRACE("returning %s\n", ret
? "TRUE" : "FALSE");
3294 ConvertStringSidToSidA(IN LPCSTR StringSid
,
3297 BOOL bRetVal
= FALSE
;
3299 TRACE("%s, %p\n", debugstr_a(StringSid
), sid
);
3300 if (GetVersion() & 0x80000000)
3301 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3302 else if (!StringSid
|| !sid
)
3303 SetLastError(ERROR_INVALID_PARAMETER
);
3306 UINT len
= MultiByteToWideChar(CP_ACP
, 0, StringSid
, -1, NULL
, 0);
3307 LPWSTR wStringSid
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3308 if (wStringSid
== NULL
)
3310 MultiByteToWideChar(CP_ACP
, 0, StringSid
, - 1, wStringSid
, len
);
3311 bRetVal
= ConvertStringSidToSidW(wStringSid
, sid
);
3312 HeapFree(GetProcessHeap(), 0, wStringSid
);
3322 ConvertSidToStringSidW(PSID Sid
,
3326 UNICODE_STRING UnicodeString
;
3327 WCHAR FixedBuffer
[64];
3329 if (!RtlValidSid(Sid
))
3331 SetLastError(ERROR_INVALID_SID
);
3335 UnicodeString
.Length
= 0;
3336 UnicodeString
.MaximumLength
= sizeof(FixedBuffer
);
3337 UnicodeString
.Buffer
= FixedBuffer
;
3338 Status
= RtlConvertSidToUnicodeString(&UnicodeString
, Sid
, FALSE
);
3339 if (STATUS_BUFFER_TOO_SMALL
== Status
)
3341 Status
= RtlConvertSidToUnicodeString(&UnicodeString
, Sid
, TRUE
);
3344 if (!NT_SUCCESS(Status
))
3346 SetLastError(RtlNtStatusToDosError(Status
));
3350 *StringSid
= LocalAlloc(LMEM_FIXED
, UnicodeString
.Length
+ sizeof(WCHAR
));
3351 if (NULL
== *StringSid
)
3353 if (UnicodeString
.Buffer
!= FixedBuffer
)
3355 RtlFreeUnicodeString(&UnicodeString
);
3357 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3361 MoveMemory(*StringSid
, UnicodeString
.Buffer
, UnicodeString
.Length
);
3362 ZeroMemory((PCHAR
) *StringSid
+ UnicodeString
.Length
, sizeof(WCHAR
));
3363 if (UnicodeString
.Buffer
!= FixedBuffer
)
3365 RtlFreeUnicodeString(&UnicodeString
);
3376 ConvertSidToStringSidA(PSID Sid
,
3382 if (!ConvertSidToStringSidW(Sid
, &StringSidW
))
3387 Len
= WideCharToMultiByte(CP_ACP
, 0, StringSidW
, -1, NULL
, 0, NULL
, NULL
);
3390 LocalFree(StringSidW
);
3391 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3395 *StringSid
= LocalAlloc(LMEM_FIXED
, Len
);
3396 if (NULL
== *StringSid
)
3398 LocalFree(StringSidW
);
3399 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3403 if (!WideCharToMultiByte(CP_ACP
, 0, StringSidW
, -1, *StringSid
, Len
, NULL
, NULL
))
3405 LocalFree(StringSid
);
3406 LocalFree(StringSidW
);
3410 LocalFree(StringSidW
);
3419 CreateProcessWithLogonW(LPCWSTR lpUsername
,
3423 LPCWSTR lpApplicationName
,
3424 LPWSTR lpCommandLine
,
3425 DWORD dwCreationFlags
,
3426 LPVOID lpEnvironment
,
3427 LPCWSTR lpCurrentDirectory
,
3428 LPSTARTUPINFOW lpStartupInfo
,
3429 LPPROCESS_INFORMATION lpProcessInformation
)
3431 FIXME("%s %s %s 0x%08x %s %s 0x%08x %p %s %p %p stub\n", debugstr_w(lpUsername
), debugstr_w(lpDomain
),
3432 debugstr_w(lpPassword
), dwLogonFlags
, debugstr_w(lpApplicationName
),
3433 debugstr_w(lpCommandLine
), dwCreationFlags
, lpEnvironment
, debugstr_w(lpCurrentDirectory
),
3434 lpStartupInfo
, lpProcessInformation
);
3441 CreateProcessWithTokenW(IN HANDLE hToken
,
3442 IN DWORD dwLogonFlags
,
3443 IN LPCWSTR lpApplicationName OPTIONAL
,
3444 IN OUT LPWSTR lpCommandLine OPTIONAL
,
3445 IN DWORD dwCreationFlags
,
3446 IN LPVOID lpEnvironment OPTIONAL
,
3447 IN LPCWSTR lpCurrentDirectory OPTIONAL
,
3448 IN LPSTARTUPINFOW lpStartupInfo
,
3449 OUT LPPROCESS_INFORMATION lpProcessInfo
)
3459 DuplicateTokenEx(IN HANDLE ExistingTokenHandle
,
3460 IN DWORD dwDesiredAccess
,
3461 IN LPSECURITY_ATTRIBUTES lpTokenAttributes OPTIONAL
,
3462 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
3463 IN TOKEN_TYPE TokenType
,
3464 OUT PHANDLE DuplicateTokenHandle
)
3466 OBJECT_ATTRIBUTES ObjectAttributes
;
3468 SECURITY_QUALITY_OF_SERVICE Sqos
;
3470 TRACE("%p 0x%08x 0x%08x 0x%08x %p\n", ExistingTokenHandle
, dwDesiredAccess
,
3471 ImpersonationLevel
, TokenType
, DuplicateTokenHandle
);
3473 Sqos
.Length
= sizeof(SECURITY_QUALITY_OF_SERVICE
);
3474 Sqos
.ImpersonationLevel
= ImpersonationLevel
;
3475 Sqos
.ContextTrackingMode
= 0;
3476 Sqos
.EffectiveOnly
= FALSE
;
3478 if (lpTokenAttributes
!= NULL
)
3480 InitializeObjectAttributes(&ObjectAttributes
,
3482 lpTokenAttributes
->bInheritHandle
? OBJ_INHERIT
: 0,
3484 lpTokenAttributes
->lpSecurityDescriptor
);
3488 InitializeObjectAttributes(&ObjectAttributes
,
3495 ObjectAttributes
.SecurityQualityOfService
= &Sqos
;
3497 Status
= NtDuplicateToken(ExistingTokenHandle
,
3502 DuplicateTokenHandle
);
3503 if (!NT_SUCCESS(Status
))
3505 ERR("NtDuplicateToken failed: Status %08x\n", Status
);
3506 SetLastError(RtlNtStatusToDosError(Status
));
3510 TRACE("Returning token %p.\n", *DuplicateTokenHandle
);
3519 DuplicateToken(IN HANDLE ExistingTokenHandle
,
3520 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
3521 OUT PHANDLE DuplicateTokenHandle
)
3523 return DuplicateTokenEx(ExistingTokenHandle
,
3524 TOKEN_IMPERSONATE
| TOKEN_QUERY
,
3528 DuplicateTokenHandle
);
3531 /******************************************************************************
3532 * ComputeStringSidSize
3534 static DWORD
ComputeStringSidSize(LPCWSTR StringSid
)
3536 if (StringSid
[0] == 'S' && StringSid
[1] == '-') /* S-R-I(-S)+ */
3541 if (*StringSid
== '-')
3547 return GetSidLengthRequired(ctok
- 2);
3549 else /* String constant format - Only available in winxp and above */
3553 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
3554 if (!strncmpW(WellKnownSids
[i
].wstr
, StringSid
, 2))
3555 return GetSidLengthRequired(WellKnownSids
[i
].Sid
.SubAuthorityCount
);
3558 return GetSidLengthRequired(0);
3561 /******************************************************************************
3562 * ParseStringSidToSid
3564 static BOOL
ParseStringSidToSid(LPCWSTR StringSid
, PSID pSid
, LPDWORD cBytes
)
3569 TRACE("%s, %p, %p\n", debugstr_w(StringSid
), pSid
, cBytes
);
3572 SetLastError(ERROR_INVALID_PARAMETER
);
3573 TRACE("StringSid is NULL, returning FALSE\n");
3577 while (*StringSid
== ' ')
3580 *cBytes
= ComputeStringSidSize(StringSid
);
3581 if (!pisid
) /* Simply compute the size */
3583 TRACE("only size requested, returning TRUE\n");
3587 if (StringSid
[0] == 'S' && StringSid
[1] == '-') /* S-R-I-S-S */
3589 DWORD i
= 0, identAuth
;
3590 DWORD csubauth
= ((*cBytes
- GetSidLengthRequired(0)) / sizeof(DWORD
));
3592 StringSid
+= 2; /* Advance to Revision */
3593 pisid
->Revision
= atoiW(StringSid
);
3595 if (pisid
->Revision
!= SDDL_REVISION
)
3597 TRACE("Revision %d is unknown\n", pisid
->Revision
);
3598 goto lend
; /* ERROR_INVALID_SID */
3602 TRACE("SubAuthorityCount is 0\n");
3603 goto lend
; /* ERROR_INVALID_SID */
3606 pisid
->SubAuthorityCount
= csubauth
;
3608 /* Advance to identifier authority */
3609 while (*StringSid
&& *StringSid
!= '-')
3611 if (*StringSid
== '-')
3614 /* MS' implementation can't handle values greater than 2^32 - 1, so
3615 * we don't either; assume most significant bytes are always 0
3617 pisid
->IdentifierAuthority
.Value
[0] = 0;
3618 pisid
->IdentifierAuthority
.Value
[1] = 0;
3619 identAuth
= atoiW(StringSid
);
3620 pisid
->IdentifierAuthority
.Value
[5] = identAuth
& 0xff;
3621 pisid
->IdentifierAuthority
.Value
[4] = (identAuth
& 0xff00) >> 8;
3622 pisid
->IdentifierAuthority
.Value
[3] = (identAuth
& 0xff0000) >> 16;
3623 pisid
->IdentifierAuthority
.Value
[2] = (identAuth
& 0xff000000) >> 24;
3625 /* Advance to first sub authority */
3626 while (*StringSid
&& *StringSid
!= '-')
3628 if (*StringSid
== '-')
3633 pisid
->SubAuthority
[i
++] = atoiW(StringSid
);
3635 while (*StringSid
&& *StringSid
!= '-')
3637 if (*StringSid
== '-')
3641 if (i
!= pisid
->SubAuthorityCount
)
3642 goto lend
; /* ERROR_INVALID_SID */
3646 else /* String constant format - Only available in winxp and above */
3649 pisid
->Revision
= SDDL_REVISION
;
3651 for (i
= 0; i
< sizeof(WellKnownSids
)/sizeof(WellKnownSids
[0]); i
++)
3652 if (!strncmpW(WellKnownSids
[i
].wstr
, StringSid
, 2))
3655 pisid
->SubAuthorityCount
= WellKnownSids
[i
].Sid
.SubAuthorityCount
;
3656 pisid
->IdentifierAuthority
= WellKnownSids
[i
].Sid
.IdentifierAuthority
;
3657 for (j
= 0; j
< WellKnownSids
[i
].Sid
.SubAuthorityCount
; j
++)
3658 pisid
->SubAuthority
[j
] = WellKnownSids
[i
].Sid
.SubAuthority
[j
];
3663 FIXME("String constant not supported: %s\n", debugstr_wn(StringSid
, 2));
3668 SetLastError(ERROR_INVALID_SID
);
3670 TRACE("returning %s\n", bret
? "TRUE" : "FALSE");
3674 /**********************************************************************
3675 * GetNamedSecurityInfoA EXPORTED
3681 GetNamedSecurityInfoA(LPSTR pObjectName
,
3682 SE_OBJECT_TYPE ObjectType
,
3683 SECURITY_INFORMATION SecurityInfo
,
3688 PSECURITY_DESCRIPTOR
*ppSecurityDescriptor
)
3694 TRACE("%s %d %d %p %p %p %p %p\n", pObjectName
, ObjectType
, SecurityInfo
,
3695 ppsidOwner
, ppsidGroup
, ppDacl
, ppSacl
, ppSecurityDescriptor
);
3699 len
= MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, NULL
, 0 );
3700 wstr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
));
3701 MultiByteToWideChar( CP_ACP
, 0, pObjectName
, -1, wstr
, len
);
3704 r
= GetNamedSecurityInfoW( wstr
, ObjectType
, SecurityInfo
, ppsidOwner
,
3705 ppsidGroup
, ppDacl
, ppSacl
, ppSecurityDescriptor
);
3707 HeapFree( GetProcessHeap(), 0, wstr
);
3717 GetWindowsAccountDomainSid(IN PSID pSid
,
3718 OUT PSID ppDomainSid
,
3719 IN OUT DWORD
* cbSid
)
3730 EqualDomainSid(IN PSID pSid1
,