2 * Implementation of the Local Security Authority API
4 * Copyright 1999 Juergen Schmied
5 * Copyright 2002 Andriy Palamarchuk
6 * Copyright 2004 Mike McCormack
7 * Copyright 2005 Hans Leidekker
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #define WIN32_NO_STATUS
33 #include "advapi32_misc.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
39 #define ADVAPI_ForceLocalComputer(ServerName, FailureCode) \
40 if (!ADVAPI_IsLocalComputer(ServerName)) \
42 FIXME("Action Implemented for local computer only. " \
43 "Requested for server %s\n", debugstr_w(ServerName)); \
47 static void dumpLsaAttributes(const LSA_OBJECT_ATTRIBUTES
*oa
)
51 TRACE("\n\tlength=%u, rootdir=%p, objectname=%s\n\tattr=0x%08x, sid=%s qos=%p\n",
52 oa
->Length
, oa
->RootDirectory
,
53 oa
->ObjectName
?debugstr_w(oa
->ObjectName
->Buffer
):"null",
54 oa
->Attributes
, debugstr_sid(oa
->SecurityDescriptor
),
55 oa
->SecurityQualityOfService
);
59 static void* ADVAPI_GetDomainName(unsigned sz
, unsigned ofs
)
66 static const WCHAR wVNETSUP
[] = {
67 'S','y','s','t','e','m','\\',
68 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
69 'S','e','r','v','i','c','e','s','\\',
70 'V','x','D','\\','V','N','E','T','S','U','P','\0'};
72 ret
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, wVNETSUP
, 0, KEY_READ
, &key
);
73 if (ret
== ERROR_SUCCESS
)
76 static const WCHAR wg
[] = { 'W','o','r','k','g','r','o','u','p',0 };
78 ret
= RegQueryValueExW(key
, wg
, NULL
, NULL
, NULL
, &size
);
79 if (ret
== ERROR_MORE_DATA
|| ret
== ERROR_SUCCESS
)
81 ptr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sz
+ size
);
82 if (!ptr
) return NULL
;
83 ustr
= (UNICODE_STRING
*)(ptr
+ ofs
);
84 ustr
->MaximumLength
= size
;
85 ustr
->Buffer
= (WCHAR
*)(ptr
+ sz
);
86 ret
= RegQueryValueExW(key
, wg
, NULL
, NULL
, (LPBYTE
)ustr
->Buffer
, &size
);
87 if (ret
!= ERROR_SUCCESS
)
89 HeapFree(GetProcessHeap(), 0, ptr
);
92 else ustr
->Length
= size
- sizeof(WCHAR
);
98 static const WCHAR wDomain
[] = {'D','O','M','A','I','N','\0'};
99 ptr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
100 sz
+ sizeof(wDomain
));
101 if (!ptr
) return NULL
;
102 ustr
= (UNICODE_STRING
*)(ptr
+ ofs
);
103 ustr
->MaximumLength
= sizeof(wDomain
);
104 ustr
->Buffer
= (WCHAR
*)(ptr
+ sz
);
105 ustr
->Length
= sizeof(wDomain
) - sizeof(WCHAR
);
106 memcpy(ustr
->Buffer
, wDomain
, sizeof(wDomain
));
111 /******************************************************************************
112 * LsaAddAccountRights [ADVAPI32.@]
115 NTSTATUS WINAPI
LsaAddAccountRights(
118 PLSA_UNICODE_STRING rights
,
121 FIXME("(%p,%p,%p,0x%08x) stub\n", policy
, sid
, rights
, count
);
122 return STATUS_OBJECT_NAME_NOT_FOUND
;
125 /******************************************************************************
126 * LsaClose [ADVAPI32.@]
128 * Closes a handle to a Policy or TrustedDomain.
131 * ObjectHandle [I] Handle to a Policy or TrustedDomain.
134 * Success: STATUS_SUCCESS.
135 * Failure: NTSTATUS code.
137 NTSTATUS WINAPI
LsaClose(IN LSA_HANDLE ObjectHandle
)
139 FIXME("(%p) stub\n", ObjectHandle
);
140 return STATUS_SUCCESS
;
143 /******************************************************************************
144 * LsaCreateTrustedDomainEx [ADVAPI32.@]
147 NTSTATUS WINAPI
LsaCreateTrustedDomainEx(
149 PTRUSTED_DOMAIN_INFORMATION_EX domain_info
,
150 PTRUSTED_DOMAIN_AUTH_INFORMATION auth_info
,
154 FIXME("(%p,%p,%p,0x%08x,%p) stub\n", policy
, domain_info
, auth_info
,
156 return STATUS_SUCCESS
;
159 /******************************************************************************
160 * LsaDeleteTrustedDomain [ADVAPI32.@]
163 NTSTATUS WINAPI
LsaDeleteTrustedDomain(LSA_HANDLE policy
, PSID sid
)
165 FIXME("(%p,%p) stub\n", policy
, sid
);
166 return STATUS_SUCCESS
;
169 /******************************************************************************
170 * LsaEnumerateAccountRights [ADVAPI32.@]
173 NTSTATUS WINAPI
LsaEnumerateAccountRights(
176 PLSA_UNICODE_STRING
*rights
,
179 FIXME("(%p,%p,%p,%p) stub\n", policy
, sid
, rights
, count
);
180 return STATUS_OBJECT_NAME_NOT_FOUND
;
183 /******************************************************************************
184 * LsaEnumerateAccountsWithUserRight [ADVAPI32.@]
187 NTSTATUS WINAPI
LsaEnumerateAccountsWithUserRight(
189 PLSA_UNICODE_STRING rights
,
193 FIXME("(%p,%p,%p,%p) stub\n", policy
, rights
, buffer
, count
);
194 return STATUS_NO_MORE_ENTRIES
;
197 /******************************************************************************
198 * LsaEnumerateTrustedDomains [ADVAPI32.@]
200 * Returns the names and SIDs of trusted domains.
203 * PolicyHandle [I] Handle to a Policy object.
204 * EnumerationContext [I] Pointer to an enumeration handle.
205 * Buffer [O] Contains the names and SIDs of trusted domains.
206 * PreferredMaximumLength[I] Preferred maximum size in bytes of Buffer.
207 * CountReturned [O] Number of elements in Buffer.
210 * Success: STATUS_SUCCESS,
211 * STATUS_MORE_ENTRIES,
212 * STATUS_NO_MORE_ENTRIES
213 * Failure: NTSTATUS code.
216 * LsaEnumerateTrustedDomains can be called multiple times to enumerate
217 * all trusted domains.
219 NTSTATUS WINAPI
LsaEnumerateTrustedDomains(
220 IN LSA_HANDLE PolicyHandle
,
221 IN PLSA_ENUMERATION_HANDLE EnumerationContext
,
223 IN ULONG PreferredMaximumLength
,
224 OUT PULONG CountReturned
)
226 FIXME("(%p,%p,%p,0x%08x,%p) stub\n", PolicyHandle
, EnumerationContext
,
227 Buffer
, PreferredMaximumLength
, CountReturned
);
229 if (CountReturned
) *CountReturned
= 0;
230 return STATUS_SUCCESS
;
233 /******************************************************************************
234 * LsaEnumerateTrustedDomainsEx [ADVAPI32.@]
237 NTSTATUS WINAPI
LsaEnumerateTrustedDomainsEx(
239 PLSA_ENUMERATION_HANDLE context
,
244 FIXME("(%p,%p,%p,0x%08x,%p) stub\n", policy
, context
, buffer
, length
, count
);
246 if (count
) *count
= 0;
247 return STATUS_SUCCESS
;
250 /******************************************************************************
251 * LsaFreeMemory [ADVAPI32.@]
253 * Frees memory allocated by a LSA function.
256 * Buffer [I] Memory buffer to free.
259 * Success: STATUS_SUCCESS.
260 * Failure: NTSTATUS code.
262 NTSTATUS WINAPI
LsaFreeMemory(IN PVOID Buffer
)
264 TRACE("(%p)\n", Buffer
);
265 return HeapFree(GetProcessHeap(), 0, Buffer
);
268 /******************************************************************************
269 * LsaLookupNames [ADVAPI32.@]
271 * Returns the SIDs of an array of user, group, or local group names.
274 * PolicyHandle [I] Handle to a Policy object.
275 * Count [I] Number of names in Names.
276 * Names [I] Array of names to lookup.
277 * ReferencedDomains [O] Array of domains where the names were found.
278 * Sids [O] Array of SIDs corresponding to Names.
281 * Success: STATUS_SUCCESS,
282 * STATUS_SOME_NOT_MAPPED
283 * Failure: STATUS_NONE_MAPPED or NTSTATUS code.
285 NTSTATUS WINAPI
LsaLookupNames(
286 IN LSA_HANDLE PolicyHandle
,
288 IN PLSA_UNICODE_STRING Names
,
289 OUT PLSA_REFERENCED_DOMAIN_LIST
* ReferencedDomains
,
290 OUT PLSA_TRANSLATED_SID
* Sids
)
292 FIXME("(%p,0x%08x,%p,%p,%p) stub\n", PolicyHandle
, Count
, Names
,
293 ReferencedDomains
, Sids
);
295 return STATUS_NONE_MAPPED
;
298 /******************************************************************************
299 * LsaLookupNames2 [ADVAPI32.@]
302 NTSTATUS WINAPI
LsaLookupNames2(
306 PLSA_UNICODE_STRING names
,
307 PLSA_REFERENCED_DOMAIN_LIST
*domains
,
308 PLSA_TRANSLATED_SID2
*sids
)
310 FIXME("(%p,0x%08x,0x%08x,%p,%p,%p) stub\n", policy
, flags
, count
, names
, domains
, sids
);
311 return STATUS_NONE_MAPPED
;
314 /******************************************************************************
315 * LsaLookupSids [ADVAPI32.@]
317 * Looks up the names that correspond to an array of SIDs.
320 * PolicyHandle [I] Handle to a Policy object.
321 * Count [I] Number of SIDs in the Sids array.
322 * Sids [I] Array of SIDs to lookup.
323 * ReferencedDomains [O] Array of domains where the sids were found.
324 * Names [O] Array of names corresponding to Sids.
327 * Success: STATUS_SUCCESS,
328 * STATUS_SOME_NOT_MAPPED
329 * Failure: STATUS_NONE_MAPPED or NTSTATUS code.
331 NTSTATUS WINAPI
LsaLookupSids(
332 IN LSA_HANDLE PolicyHandle
,
335 OUT PLSA_REFERENCED_DOMAIN_LIST
*ReferencedDomains
,
336 OUT PLSA_TRANSLATED_NAME
*Names
)
338 FIXME("(%p,%u,%p,%p,%p) stub\n", PolicyHandle
, Count
, Sids
,
339 ReferencedDomains
, Names
);
341 return STATUS_NONE_MAPPED
;
344 /******************************************************************************
345 * LsaNtStatusToWinError [ADVAPI32.@]
347 * Converts an LSA NTSTATUS code to a Windows error code.
350 * Status [I] NTSTATUS code.
353 * Success: Corresponding Windows error code.
354 * Failure: ERROR_MR_MID_NOT_FOUND.
356 ULONG WINAPI
LsaNtStatusToWinError(NTSTATUS Status
)
358 return RtlNtStatusToDosError(Status
);
361 /******************************************************************************
362 * LsaOpenPolicy [ADVAPI32.@]
364 * Opens a handle to the Policy object on a local or remote system.
367 * SystemName [I] Name of the target system.
368 * ObjectAttributes [I] Connection attributes.
369 * DesiredAccess [I] Requested access rights.
370 * PolicyHandle [I/O] Handle to the Policy object.
373 * Success: STATUS_SUCCESS.
374 * Failure: NTSTATUS code.
377 * Set SystemName to NULL to open the local Policy object.
379 NTSTATUS WINAPI
LsaOpenPolicy(
380 IN PLSA_UNICODE_STRING SystemName
,
381 IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes
,
382 IN ACCESS_MASK DesiredAccess
,
383 IN OUT PLSA_HANDLE PolicyHandle
)
385 FIXME("(%s,%p,0x%08x,%p) stub\n",
386 SystemName
?debugstr_w(SystemName
->Buffer
):"(null)",
387 ObjectAttributes
, DesiredAccess
, PolicyHandle
);
389 ADVAPI_ForceLocalComputer(SystemName
? SystemName
->Buffer
: NULL
,
390 STATUS_ACCESS_VIOLATION
);
391 dumpLsaAttributes(ObjectAttributes
);
393 if(PolicyHandle
) *PolicyHandle
= (LSA_HANDLE
)0xcafe;
394 return STATUS_SUCCESS
;
397 /******************************************************************************
398 * LsaOpenTrustedDomainByName [ADVAPI32.@]
401 NTSTATUS WINAPI
LsaOpenTrustedDomainByName(
403 PLSA_UNICODE_STRING name
,
407 FIXME("(%p,%p,0x%08x,%p) stub\n", policy
, name
, access
, handle
);
408 return STATUS_OBJECT_NAME_NOT_FOUND
;
411 /******************************************************************************
412 * LsaQueryInformationPolicy [ADVAPI32.@]
414 * Returns information about a Policy object.
417 * PolicyHandle [I] Handle to a Policy object.
418 * InformationClass [I] Type of information to retrieve.
419 * Buffer [O] Pointer to the requested information.
422 * Success: STATUS_SUCCESS.
423 * Failure: NTSTATUS code.
425 NTSTATUS WINAPI
LsaQueryInformationPolicy(
426 IN LSA_HANDLE PolicyHandle
,
427 IN POLICY_INFORMATION_CLASS InformationClass
,
430 TRACE("(%p,0x%08x,%p)\n", PolicyHandle
, InformationClass
, Buffer
);
432 if(!Buffer
) return STATUS_INVALID_PARAMETER
;
433 switch (InformationClass
)
435 case PolicyAuditEventsInformation
: /* 2 */
437 PPOLICY_AUDIT_EVENTS_INFO p
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
438 sizeof(POLICY_AUDIT_EVENTS_INFO
));
439 p
->AuditingMode
= FALSE
; /* no auditing */
443 case PolicyPrimaryDomainInformation
: /* 3 */
445 /* Only the domain name is valid for the local computer.
446 * All other fields are zero.
448 PPOLICY_PRIMARY_DOMAIN_INFO pinfo
;
450 pinfo
= ADVAPI_GetDomainName(sizeof(*pinfo
), offsetof(POLICY_PRIMARY_DOMAIN_INFO
, Name
));
452 TRACE("setting domain to %s\n", debugstr_w(pinfo
->Name
.Buffer
));
457 case PolicyAccountDomainInformation
: /* 5 */
461 POLICY_ACCOUNT_DOMAIN_INFO info
;
464 WCHAR domain
[MAX_COMPUTERNAME_LENGTH
+ 1];
467 DWORD dwSize
= MAX_COMPUTERNAME_LENGTH
+ 1;
468 struct di
* xdi
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*xdi
));
470 xdi
->info
.DomainName
.MaximumLength
= dwSize
* sizeof(WCHAR
);
471 xdi
->info
.DomainName
.Buffer
= xdi
->domain
;
472 if (GetComputerNameW(xdi
->info
.DomainName
.Buffer
, &dwSize
))
473 xdi
->info
.DomainName
.Length
= dwSize
* sizeof(WCHAR
);
475 TRACE("setting name to %s\n", debugstr_w(xdi
->info
.DomainName
.Buffer
));
477 xdi
->info
.DomainSid
= &xdi
->sid
;
479 /* read the computer SID from the registry */
480 if (!ADVAPI_GetComputerSid(&xdi
->sid
))
482 HeapFree(GetProcessHeap(), 0, xdi
);
484 WARN("Computer SID not found\n");
486 return STATUS_UNSUCCESSFUL
;
489 TRACE("setting SID to %s\n", debugstr_sid(&xdi
->sid
));
494 case PolicyDnsDomainInformation
: /* 12 (0xc) */
496 /* Only the domain name is valid for the local computer.
497 * All other fields are zero.
499 PPOLICY_DNS_DOMAIN_INFO pinfo
;
501 pinfo
= ADVAPI_GetDomainName(sizeof(*pinfo
), offsetof(POLICY_DNS_DOMAIN_INFO
, Name
));
503 TRACE("setting domain to %s\n", debugstr_w(pinfo
->Name
.Buffer
));
508 case PolicyAuditLogInformation
:
509 case PolicyPdAccountInformation
:
510 case PolicyLsaServerRoleInformation
:
511 case PolicyReplicaSourceInformation
:
512 case PolicyDefaultQuotaInformation
:
513 case PolicyModificationInformation
:
514 case PolicyAuditFullSetInformation
:
515 case PolicyAuditFullQueryInformation
:
517 FIXME("category %d not implemented\n", InformationClass
);
518 return STATUS_UNSUCCESSFUL
;
521 return STATUS_SUCCESS
;
524 /******************************************************************************
525 * LsaQueryTrustedDomainInfo [ADVAPI32.@]
528 NTSTATUS WINAPI
LsaQueryTrustedDomainInfo(
531 TRUSTED_INFORMATION_CLASS
class,
534 FIXME("(%p,%p,%d,%p) stub\n", policy
, sid
, class, buffer
);
535 return STATUS_OBJECT_NAME_NOT_FOUND
;
538 /******************************************************************************
539 * LsaQueryTrustedDomainInfoByName [ADVAPI32.@]
542 NTSTATUS WINAPI
LsaQueryTrustedDomainInfoByName(
544 PLSA_UNICODE_STRING name
,
545 TRUSTED_INFORMATION_CLASS
class,
548 FIXME("(%p,%p,%d,%p) stub\n", policy
, name
, class, buffer
);
549 return STATUS_OBJECT_NAME_NOT_FOUND
;
552 /******************************************************************************
553 * LsaRegisterPolicyChangeNotification [ADVAPI32.@]
556 NTSTATUS WINAPI
LsaRegisterPolicyChangeNotification(
557 POLICY_NOTIFICATION_INFORMATION_CLASS
class,
560 FIXME("(%d,%p) stub\n", class, event
);
561 return STATUS_UNSUCCESSFUL
;
564 /******************************************************************************
565 * LsaRemoveAccountRights [ADVAPI32.@]
568 NTSTATUS WINAPI
LsaRemoveAccountRights(
572 PLSA_UNICODE_STRING rights
,
575 FIXME("(%p,%p,%d,%p,0x%08x) stub\n", policy
, sid
, all
, rights
, count
);
576 return STATUS_SUCCESS
;
579 /******************************************************************************
580 * LsaRetrievePrivateData [ADVAPI32.@]
582 * Retrieves data stored by LsaStorePrivateData.
585 * PolicyHandle [I] Handle to a Policy object.
586 * KeyName [I] Name of the key where the data is stored.
587 * PrivateData [O] Pointer to the private data.
590 * Success: STATUS_SUCCESS.
591 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
593 NTSTATUS WINAPI
LsaRetrievePrivateData(
594 IN LSA_HANDLE PolicyHandle
,
595 IN PLSA_UNICODE_STRING KeyName
,
596 OUT PLSA_UNICODE_STRING
* PrivateData
)
598 FIXME("(%p,%p,%p) stub\n", PolicyHandle
, KeyName
, PrivateData
);
599 return STATUS_OBJECT_NAME_NOT_FOUND
;
602 /******************************************************************************
603 * LsaSetInformationPolicy [ADVAPI32.@]
605 * Modifies information in a Policy object.
608 * PolicyHandle [I] Handle to a Policy object.
609 * InformationClass [I] Type of information to set.
610 * Buffer [I] Pointer to the information to set.
613 * Success: STATUS_SUCCESS.
614 * Failure: NTSTATUS code.
616 NTSTATUS WINAPI
LsaSetInformationPolicy(
617 IN LSA_HANDLE PolicyHandle
,
618 IN POLICY_INFORMATION_CLASS InformationClass
,
621 FIXME("(%p,0x%08x,%p) stub\n", PolicyHandle
, InformationClass
, Buffer
);
623 return STATUS_UNSUCCESSFUL
;
626 /******************************************************************************
627 * LsaSetTrustedDomainInfoByName [ADVAPI32.@]
630 NTSTATUS WINAPI
LsaSetTrustedDomainInfoByName(
632 PLSA_UNICODE_STRING name
,
633 TRUSTED_INFORMATION_CLASS
class,
636 FIXME("(%p,%p,%d,%p) stub\n", policy
, name
, class, buffer
);
637 return STATUS_SUCCESS
;
640 /******************************************************************************
641 * LsaSetTrustedDomainInformation [ADVAPI32.@]
644 NTSTATUS WINAPI
LsaSetTrustedDomainInformation(
647 TRUSTED_INFORMATION_CLASS
class,
650 FIXME("(%p,%p,%d,%p) stub\n", policy
, sid
, class, buffer
);
651 return STATUS_SUCCESS
;
654 /******************************************************************************
655 * LsaStorePrivateData [ADVAPI32.@]
657 * Stores or deletes a Policy object's data under the specified reg key.
660 * PolicyHandle [I] Handle to a Policy object.
661 * KeyName [I] Name of the key where the data will be stored.
662 * PrivateData [O] Pointer to the private data.
665 * Success: STATUS_SUCCESS.
666 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
668 NTSTATUS WINAPI
LsaStorePrivateData(
669 IN LSA_HANDLE PolicyHandle
,
670 IN PLSA_UNICODE_STRING KeyName
,
671 IN PLSA_UNICODE_STRING PrivateData
)
673 FIXME("(%p,%p,%p) stub\n", PolicyHandle
, KeyName
, PrivateData
);
674 return STATUS_OBJECT_NAME_NOT_FOUND
;
677 /******************************************************************************
678 * LsaUnregisterPolicyChangeNotification [ADVAPI32.@]
681 NTSTATUS WINAPI
LsaUnregisterPolicyChangeNotification(
682 POLICY_NOTIFICATION_INFORMATION_CLASS
class,
685 FIXME("(%d,%p) stub\n", class, event
);
686 return STATUS_SUCCESS
;