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(PLSA_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
;
449 pinfo
= ADVAPI_GetDomainName(sizeof(*pinfo
), (char*)&pinfo
->Name
- (char*)pinfo
);
451 TRACE("setting domain to %s\n", debugstr_w(pinfo
->Name
.Buffer
));
456 case PolicyAccountDomainInformation
: /* 5 */
460 POLICY_ACCOUNT_DOMAIN_INFO info
;
463 WCHAR domain
[MAX_COMPUTERNAME_LENGTH
+ 1];
466 DWORD dwSize
= MAX_COMPUTERNAME_LENGTH
+ 1;
467 struct di
* xdi
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*xdi
));
469 xdi
->info
.DomainName
.MaximumLength
= dwSize
* sizeof(WCHAR
);
470 xdi
->info
.DomainName
.Buffer
= xdi
->domain
;
471 if (GetComputerNameW(xdi
->info
.DomainName
.Buffer
, &dwSize
))
472 xdi
->info
.DomainName
.Length
= dwSize
* sizeof(WCHAR
);
474 TRACE("setting name to %s\n", debugstr_w(xdi
->info
.DomainName
.Buffer
));
476 xdi
->info
.DomainSid
= &xdi
->sid
;
478 /* read the computer SID from the registry */
479 if (!ADVAPI_GetComputerSid(&xdi
->sid
))
481 HeapFree(GetProcessHeap(), 0, xdi
);
483 WARN("Computer SID not found\n");
485 return STATUS_UNSUCCESSFUL
;
488 TRACE("setting SID to %s\n", debugstr_sid(&xdi
->sid
));
493 case PolicyDnsDomainInformation
: /* 12 (0xc) */
495 /* Only the domain name is valid for the local computer.
496 * All other fields are zero.
498 PPOLICY_DNS_DOMAIN_INFO pinfo
;
500 pinfo
= ADVAPI_GetDomainName(sizeof(*pinfo
), (char*)&pinfo
->Name
- (char*)pinfo
);
502 TRACE("setting domain to %s\n", debugstr_w(pinfo
->Name
.Buffer
));
507 case PolicyAuditLogInformation
:
508 case PolicyPdAccountInformation
:
509 case PolicyLsaServerRoleInformation
:
510 case PolicyReplicaSourceInformation
:
511 case PolicyDefaultQuotaInformation
:
512 case PolicyModificationInformation
:
513 case PolicyAuditFullSetInformation
:
514 case PolicyAuditFullQueryInformation
:
516 FIXME("category %d not implemented\n", InformationClass
);
517 return STATUS_UNSUCCESSFUL
;
520 return STATUS_SUCCESS
;
523 /******************************************************************************
524 * LsaQueryTrustedDomainInfo [ADVAPI32.@]
527 NTSTATUS WINAPI
LsaQueryTrustedDomainInfo(
530 TRUSTED_INFORMATION_CLASS
class,
533 FIXME("(%p,%p,%d,%p) stub\n", policy
, sid
, class, buffer
);
534 return STATUS_OBJECT_NAME_NOT_FOUND
;
537 /******************************************************************************
538 * LsaQueryTrustedDomainInfoByName [ADVAPI32.@]
541 NTSTATUS WINAPI
LsaQueryTrustedDomainInfoByName(
543 PLSA_UNICODE_STRING name
,
544 TRUSTED_INFORMATION_CLASS
class,
547 FIXME("(%p,%p,%d,%p) stub\n", policy
, name
, class, buffer
);
548 return STATUS_OBJECT_NAME_NOT_FOUND
;
551 /******************************************************************************
552 * LsaRegisterPolicyChangeNotification [ADVAPI32.@]
555 NTSTATUS WINAPI
LsaRegisterPolicyChangeNotification(
556 POLICY_NOTIFICATION_INFORMATION_CLASS
class,
559 FIXME("(%d,%p) stub\n", class, event
);
560 return STATUS_UNSUCCESSFUL
;
563 /******************************************************************************
564 * LsaRemoveAccountRights [ADVAPI32.@]
567 NTSTATUS WINAPI
LsaRemoveAccountRights(
571 PLSA_UNICODE_STRING rights
,
574 FIXME("(%p,%p,%d,%p,0x%08x) stub\n", policy
, sid
, all
, rights
, count
);
575 return STATUS_SUCCESS
;
578 /******************************************************************************
579 * LsaRetrievePrivateData [ADVAPI32.@]
581 * Retrieves data stored by LsaStorePrivateData.
584 * PolicyHandle [I] Handle to a Policy object.
585 * KeyName [I] Name of the key where the data is stored.
586 * PrivateData [O] Pointer to the private data.
589 * Success: STATUS_SUCCESS.
590 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
592 NTSTATUS WINAPI
LsaRetrievePrivateData(
593 IN LSA_HANDLE PolicyHandle
,
594 IN PLSA_UNICODE_STRING KeyName
,
595 OUT PLSA_UNICODE_STRING
* PrivateData
)
597 FIXME("(%p,%p,%p) stub\n", PolicyHandle
, KeyName
, PrivateData
);
598 return STATUS_OBJECT_NAME_NOT_FOUND
;
601 /******************************************************************************
602 * LsaSetInformationPolicy [ADVAPI32.@]
604 * Modifies information in a Policy object.
607 * PolicyHandle [I] Handle to a Policy object.
608 * InformationClass [I] Type of information to set.
609 * Buffer [I] Pointer to the information to set.
612 * Success: STATUS_SUCCESS.
613 * Failure: NTSTATUS code.
615 NTSTATUS WINAPI
LsaSetInformationPolicy(
616 IN LSA_HANDLE PolicyHandle
,
617 IN POLICY_INFORMATION_CLASS InformationClass
,
620 FIXME("(%p,0x%08x,%p) stub\n", PolicyHandle
, InformationClass
, Buffer
);
622 return STATUS_UNSUCCESSFUL
;
625 /******************************************************************************
626 * LsaSetTrustedDomainInfoByName [ADVAPI32.@]
629 NTSTATUS WINAPI
LsaSetTrustedDomainInfoByName(
631 PLSA_UNICODE_STRING name
,
632 TRUSTED_INFORMATION_CLASS
class,
635 FIXME("(%p,%p,%d,%p) stub\n", policy
, name
, class, buffer
);
636 return STATUS_SUCCESS
;
639 /******************************************************************************
640 * LsaSetTrustedDomainInformation [ADVAPI32.@]
643 NTSTATUS WINAPI
LsaSetTrustedDomainInformation(
646 TRUSTED_INFORMATION_CLASS
class,
649 FIXME("(%p,%p,%d,%p) stub\n", policy
, sid
, class, buffer
);
650 return STATUS_SUCCESS
;
653 /******************************************************************************
654 * LsaStorePrivateData [ADVAPI32.@]
656 * Stores or deletes a Policy object's data under the specified reg key.
659 * PolicyHandle [I] Handle to a Policy object.
660 * KeyName [I] Name of the key where the data will be stored.
661 * PrivateData [O] Pointer to the private data.
664 * Success: STATUS_SUCCESS.
665 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
667 NTSTATUS WINAPI
LsaStorePrivateData(
668 IN LSA_HANDLE PolicyHandle
,
669 IN PLSA_UNICODE_STRING KeyName
,
670 IN PLSA_UNICODE_STRING PrivateData
)
672 FIXME("(%p,%p,%p) stub\n", PolicyHandle
, KeyName
, PrivateData
);
673 return STATUS_OBJECT_NAME_NOT_FOUND
;
676 /******************************************************************************
677 * LsaUnregisterPolicyChangeNotification [ADVAPI32.@]
680 NTSTATUS WINAPI
LsaUnregisterPolicyChangeNotification(
681 POLICY_NOTIFICATION_INFORMATION_CLASS
class,
684 FIXME("(%d,%p) stub\n", class, event
);
685 return STATUS_SUCCESS
;