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"
36 #include "wine/unicode.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
40 #define ADVAPI_ForceLocalComputer(ServerName, FailureCode) \
41 if (!ADVAPI_IsLocalComputer(ServerName)) \
43 FIXME("Action Implemented for local computer only. " \
44 "Requested for server %s\n", debugstr_w(ServerName)); \
48 static LPCSTR
debugstr_us( const UNICODE_STRING
*us
)
50 if (!us
) return "(null)";
51 return debugstr_wn(us
->Buffer
, us
->Length
/ sizeof(WCHAR
));
54 static void dumpLsaAttributes(const LSA_OBJECT_ATTRIBUTES
*oa
)
58 TRACE("\n\tlength=%u, rootdir=%p, objectname=%s\n\tattr=0x%08x, sid=%s qos=%p\n",
59 oa
->Length
, oa
->RootDirectory
,
60 oa
->ObjectName
?debugstr_w(oa
->ObjectName
->Buffer
):"null",
61 oa
->Attributes
, debugstr_sid(oa
->SecurityDescriptor
),
62 oa
->SecurityQualityOfService
);
66 static void* ADVAPI_GetDomainName(unsigned sz
, unsigned ofs
)
73 static const WCHAR wVNETSUP
[] = {
74 'S','y','s','t','e','m','\\',
75 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
76 'S','e','r','v','i','c','e','s','\\',
77 'V','x','D','\\','V','N','E','T','S','U','P','\0'};
79 ret
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, wVNETSUP
, 0, KEY_READ
, &key
);
80 if (ret
== ERROR_SUCCESS
)
83 static const WCHAR wg
[] = { 'W','o','r','k','g','r','o','u','p',0 };
85 ret
= RegQueryValueExW(key
, wg
, NULL
, NULL
, NULL
, &size
);
86 if (ret
== ERROR_MORE_DATA
|| ret
== ERROR_SUCCESS
)
88 ptr
= heap_alloc_zero(sz
+ size
);
89 if (!ptr
) return NULL
;
90 ustr
= (UNICODE_STRING
*)(ptr
+ ofs
);
91 ustr
->MaximumLength
= size
;
92 ustr
->Buffer
= (WCHAR
*)(ptr
+ sz
);
93 ret
= RegQueryValueExW(key
, wg
, NULL
, NULL
, (LPBYTE
)ustr
->Buffer
, &size
);
94 if (ret
!= ERROR_SUCCESS
)
99 else ustr
->Length
= size
- sizeof(WCHAR
);
105 static const WCHAR wDomain
[] = {'D','O','M','A','I','N','\0'};
106 ptr
= heap_alloc_zero(sz
+ sizeof(wDomain
));
107 if (!ptr
) return NULL
;
108 ustr
= (UNICODE_STRING
*)(ptr
+ ofs
);
109 ustr
->MaximumLength
= sizeof(wDomain
);
110 ustr
->Buffer
= (WCHAR
*)(ptr
+ sz
);
111 ustr
->Length
= sizeof(wDomain
) - sizeof(WCHAR
);
112 memcpy(ustr
->Buffer
, wDomain
, sizeof(wDomain
));
117 /******************************************************************************
118 * LsaAddAccountRights [ADVAPI32.@]
121 NTSTATUS WINAPI
LsaAddAccountRights(
124 PLSA_UNICODE_STRING rights
,
127 FIXME("(%p,%p,%p,0x%08x) stub\n", policy
, sid
, rights
, count
);
128 return STATUS_SUCCESS
;
131 /******************************************************************************
132 * LsaClose [ADVAPI32.@]
134 * Closes a handle to a Policy or TrustedDomain.
137 * ObjectHandle [I] Handle to a Policy or TrustedDomain.
140 * Success: STATUS_SUCCESS.
141 * Failure: NTSTATUS code.
143 NTSTATUS WINAPI
LsaClose(IN LSA_HANDLE ObjectHandle
)
145 FIXME("(%p) stub\n", ObjectHandle
);
146 return STATUS_SUCCESS
;
149 /******************************************************************************
150 * LsaCreateTrustedDomainEx [ADVAPI32.@]
153 NTSTATUS WINAPI
LsaCreateTrustedDomainEx(
155 PTRUSTED_DOMAIN_INFORMATION_EX domain_info
,
156 PTRUSTED_DOMAIN_AUTH_INFORMATION auth_info
,
160 FIXME("(%p,%p,%p,0x%08x,%p) stub\n", policy
, domain_info
, auth_info
,
162 return STATUS_SUCCESS
;
165 /******************************************************************************
166 * LsaDeleteTrustedDomain [ADVAPI32.@]
169 NTSTATUS WINAPI
LsaDeleteTrustedDomain(LSA_HANDLE policy
, PSID sid
)
171 FIXME("(%p,%p) stub\n", policy
, sid
);
172 return STATUS_SUCCESS
;
175 /******************************************************************************
176 * LsaEnumerateAccountRights [ADVAPI32.@]
179 NTSTATUS WINAPI
LsaEnumerateAccountRights(
182 PLSA_UNICODE_STRING
*rights
,
185 FIXME("(%p,%p,%p,%p) stub\n", policy
, sid
, rights
, count
);
188 return STATUS_OBJECT_NAME_NOT_FOUND
;
191 /******************************************************************************
192 * LsaEnumerateAccountsWithUserRight [ADVAPI32.@]
195 NTSTATUS WINAPI
LsaEnumerateAccountsWithUserRight(
197 PLSA_UNICODE_STRING rights
,
201 FIXME("(%p,%p,%p,%p) stub\n", policy
, rights
, buffer
, count
);
202 return STATUS_NO_MORE_ENTRIES
;
205 /******************************************************************************
206 * LsaEnumerateTrustedDomains [ADVAPI32.@]
208 * Returns the names and SIDs of trusted domains.
211 * PolicyHandle [I] Handle to a Policy object.
212 * EnumerationContext [I] Pointer to an enumeration handle.
213 * Buffer [O] Contains the names and SIDs of trusted domains.
214 * PreferredMaximumLength[I] Preferred maximum size in bytes of Buffer.
215 * CountReturned [O] Number of elements in Buffer.
218 * Success: STATUS_SUCCESS,
219 * STATUS_MORE_ENTRIES,
220 * STATUS_NO_MORE_ENTRIES
221 * Failure: NTSTATUS code.
224 * LsaEnumerateTrustedDomains can be called multiple times to enumerate
225 * all trusted domains.
227 NTSTATUS WINAPI
LsaEnumerateTrustedDomains(
228 IN LSA_HANDLE PolicyHandle
,
229 IN PLSA_ENUMERATION_HANDLE EnumerationContext
,
231 IN ULONG PreferredMaximumLength
,
232 OUT PULONG CountReturned
)
234 FIXME("(%p,%p,%p,0x%08x,%p) stub\n", PolicyHandle
, EnumerationContext
,
235 Buffer
, PreferredMaximumLength
, CountReturned
);
237 if (CountReturned
) *CountReturned
= 0;
238 return STATUS_SUCCESS
;
241 /******************************************************************************
242 * LsaEnumerateTrustedDomainsEx [ADVAPI32.@]
245 NTSTATUS WINAPI
LsaEnumerateTrustedDomainsEx(
247 PLSA_ENUMERATION_HANDLE context
,
252 FIXME("(%p,%p,%p,0x%08x,%p) stub\n", policy
, context
, buffer
, length
, count
);
254 if (count
) *count
= 0;
255 return STATUS_SUCCESS
;
258 /******************************************************************************
259 * LsaFreeMemory [ADVAPI32.@]
261 * Frees memory allocated by a LSA function.
264 * Buffer [I] Memory buffer to free.
267 * Success: STATUS_SUCCESS.
268 * Failure: NTSTATUS code.
270 NTSTATUS WINAPI
LsaFreeMemory(IN PVOID Buffer
)
272 TRACE("(%p)\n", Buffer
);
275 return STATUS_SUCCESS
;
278 /******************************************************************************
279 * LsaLookupNames [ADVAPI32.@]
281 * Returns the SIDs of an array of user, group, or local group names.
284 * PolicyHandle [I] Handle to a Policy object.
285 * Count [I] Number of names in Names.
286 * Names [I] Array of names to lookup.
287 * ReferencedDomains [O] Array of domains where the names were found.
288 * Sids [O] Array of SIDs corresponding to Names.
291 * Success: STATUS_SUCCESS,
292 * STATUS_SOME_NOT_MAPPED
293 * Failure: STATUS_NONE_MAPPED or NTSTATUS code.
295 NTSTATUS WINAPI
LsaLookupNames(
296 IN LSA_HANDLE PolicyHandle
,
298 IN PLSA_UNICODE_STRING Names
,
299 OUT PLSA_REFERENCED_DOMAIN_LIST
* ReferencedDomains
,
300 OUT PLSA_TRANSLATED_SID
* Sids
)
302 FIXME("(%p,0x%08x,%p,%p,%p) stub\n", PolicyHandle
, Count
, Names
,
303 ReferencedDomains
, Sids
);
305 return STATUS_NONE_MAPPED
;
308 static BOOL
lookup_name( LSA_UNICODE_STRING
*name
, SID
*sid
, DWORD
*sid_size
, WCHAR
*domain
,
309 DWORD
*domain_size
, SID_NAME_USE
*use
, BOOL
*handled
)
313 ret
= lookup_local_wellknown_name( name
, sid
, sid_size
, domain
, domain_size
, use
, handled
);
315 ret
= lookup_local_user_name( name
, sid
, sid_size
, domain
, domain_size
, use
, handled
);
320 /* Adds domain info to referenced domain list.
321 Domain list is stored as plain buffer, layout is:
323 LSA_REFERENCED_DOMAIN_LIST,
324 LSA_TRUST_INFORMATION array,
327 domain name data (WCHAR buffer),
332 list [I] referenced list pointer
333 domain [I] domain name string
334 data [IO] pointer to domain data array
336 static LONG
lsa_reflist_add_domain(LSA_REFERENCED_DOMAIN_LIST
*list
, LSA_UNICODE_STRING
*domain
, char **data
)
338 ULONG sid_size
= 0,domain_size
= 0;
339 BOOL handled
= FALSE
;
343 for (i
= 0; i
< list
->Entries
; i
++)
345 /* try to reuse index */
346 if ((list
->Domains
[i
].Name
.Length
== domain
->Length
) &&
347 (!strncmpiW(list
->Domains
[i
].Name
.Buffer
, domain
->Buffer
, (domain
->Length
/ sizeof(WCHAR
)))))
353 /* no matching domain found, store name */
354 list
->Domains
[list
->Entries
].Name
.Length
= domain
->Length
;
355 list
->Domains
[list
->Entries
].Name
.MaximumLength
= domain
->MaximumLength
;
356 list
->Domains
[list
->Entries
].Name
.Buffer
= (WCHAR
*)*data
;
357 memcpy(list
->Domains
[list
->Entries
].Name
.Buffer
, domain
->Buffer
, domain
->MaximumLength
);
358 *data
+= domain
->MaximumLength
;
360 /* get and store SID data */
361 list
->Domains
[list
->Entries
].Sid
= *data
;
362 lookup_name(domain
, NULL
, &sid_size
, NULL
, &domain_size
, &use
, &handled
);
364 lookup_name(domain
, list
->Domains
[list
->Entries
].Sid
, &sid_size
, NULL
, &domain_size
, &use
, &handled
);
367 return list
->Entries
++;
370 /******************************************************************************
371 * LsaLookupNames2 [ADVAPI32.@]
374 NTSTATUS WINAPI
LsaLookupNames2( LSA_HANDLE policy
, ULONG flags
, ULONG count
,
375 PLSA_UNICODE_STRING names
, PLSA_REFERENCED_DOMAIN_LIST
*domains
,
376 PLSA_TRANSLATED_SID2
*sids
)
378 ULONG i
, sid_size_total
= 0, domain_size_max
= 0, size
, domainname_size_total
= 0;
379 ULONG sid_size
, domain_size
, mapped
;
380 LSA_UNICODE_STRING domain
;
381 BOOL handled
= FALSE
;
386 TRACE("(%p,0x%08x,0x%08x,%p,%p,%p)\n", policy
, flags
, count
, names
, domains
, sids
);
389 for (i
= 0; i
< count
; i
++)
392 sid_size
= domain_size
= 0;
393 lookup_name( &names
[i
], NULL
, &sid_size
, NULL
, &domain_size
, &use
, &handled
);
396 sid_size_total
+= sid_size
;
397 domainname_size_total
+= domain_size
;
400 if (domain_size
> domain_size_max
)
401 domain_size_max
= domain_size
;
406 TRACE("mapped %u out of %u\n", mapped
, count
);
408 size
= sizeof(LSA_TRANSLATED_SID2
) * count
+ sid_size_total
;
409 if (!(*sids
= heap_alloc(size
))) return STATUS_NO_MEMORY
;
411 sid
= (SID
*)(*sids
+ count
);
413 /* use maximum domain count */
414 if (!(*domains
= heap_alloc(sizeof(LSA_REFERENCED_DOMAIN_LIST
) + sizeof(LSA_TRUST_INFORMATION
)*count
+
415 sid_size_total
+ domainname_size_total
*sizeof(WCHAR
))))
418 return STATUS_NO_MEMORY
;
420 (*domains
)->Entries
= 0;
421 (*domains
)->Domains
= (LSA_TRUST_INFORMATION
*)((char*)*domains
+ sizeof(LSA_REFERENCED_DOMAIN_LIST
));
422 domain_data
= (char*)(*domains
)->Domains
+ sizeof(LSA_TRUST_INFORMATION
)*count
;
424 domain
.Buffer
= heap_alloc(domain_size_max
*sizeof(WCHAR
));
425 for (i
= 0; i
< count
; i
++)
427 domain
.Length
= domain_size_max
*sizeof(WCHAR
);
428 domain
.MaximumLength
= domain_size_max
*sizeof(WCHAR
);
430 (*sids
)[i
].Use
= SidTypeUnknown
;
431 (*sids
)[i
].DomainIndex
= -1;
432 (*sids
)[i
].Flags
= 0;
435 sid_size
= sid_size_total
;
436 domain_size
= domain_size_max
;
437 lookup_name( &names
[i
], sid
, &sid_size
, domain
.Buffer
, &domain_size
, &use
, &handled
);
440 (*sids
)[i
].Sid
= sid
;
441 (*sids
)[i
].Use
= use
;
443 sid
= (SID
*)((char *)sid
+ sid_size
);
444 sid_size_total
-= sid_size
;
447 domain
.Length
= domain_size
* sizeof(WCHAR
);
448 domain
.MaximumLength
= (domain_size
+ 1) * sizeof(WCHAR
);
449 (*sids
)[i
].DomainIndex
= lsa_reflist_add_domain(*domains
, &domain
, &domain_data
);
453 heap_free(domain
.Buffer
);
455 if (mapped
== count
) return STATUS_SUCCESS
;
456 if (mapped
> 0 && mapped
< count
) return STATUS_SOME_NOT_MAPPED
;
457 return STATUS_NONE_MAPPED
;
460 /******************************************************************************
461 * LsaLookupSids [ADVAPI32.@]
463 * Looks up the names that correspond to an array of SIDs.
466 * PolicyHandle [I] Handle to a Policy object.
467 * Count [I] Number of SIDs in the Sids array.
468 * Sids [I] Array of SIDs to lookup.
469 * ReferencedDomains [O] Array of domains where the sids were found.
470 * Names [O] Array of names corresponding to Sids.
473 * Success: STATUS_SUCCESS,
474 * STATUS_SOME_NOT_MAPPED
475 * Failure: STATUS_NONE_MAPPED or NTSTATUS code.
477 NTSTATUS WINAPI
LsaLookupSids(
478 LSA_HANDLE PolicyHandle
,
481 LSA_REFERENCED_DOMAIN_LIST
**ReferencedDomains
,
482 LSA_TRANSLATED_NAME
**Names
)
484 ULONG i
, mapped
, name_fullsize
, domain_fullsize
;
485 ULONG name_size
, domain_size
;
486 LSA_UNICODE_STRING domain
;
492 TRACE("(%p, %u, %p, %p, %p)\n", PolicyHandle
, Count
, Sids
, ReferencedDomains
, Names
);
494 /* this length does not include actual string length yet */
495 name_fullsize
= sizeof(LSA_TRANSLATED_NAME
) * Count
;
496 if (!(*Names
= heap_alloc(name_fullsize
))) return STATUS_NO_MEMORY
;
497 /* maximum count of stored domain infos is Count, allocate it like that cause really needed
498 count could only be computed after sid data is retrieved */
499 domain_fullsize
= sizeof(LSA_REFERENCED_DOMAIN_LIST
) + sizeof(LSA_TRUST_INFORMATION
)*Count
;
500 if (!(*ReferencedDomains
= heap_alloc(domain_fullsize
)))
503 return STATUS_NO_MEMORY
;
505 (*ReferencedDomains
)->Entries
= 0;
506 (*ReferencedDomains
)->Domains
= (LSA_TRUST_INFORMATION
*)((char*)*ReferencedDomains
+ sizeof(LSA_REFERENCED_DOMAIN_LIST
));
508 /* Get full names data length and full length needed to store domain name and SID */
509 for (i
= 0; i
< Count
; i
++)
511 (*Names
)[i
].Use
= SidTypeUnknown
;
512 (*Names
)[i
].DomainIndex
= -1;
513 RtlInitUnicodeStringEx(&(*Names
)[i
].Name
, NULL
);
515 memset(&(*ReferencedDomains
)->Domains
[i
], 0, sizeof(LSA_TRUST_INFORMATION
));
517 name_size
= domain_size
= 0;
518 if (!LookupAccountSidW(NULL
, Sids
[i
], NULL
, &name_size
, NULL
, &domain_size
, &use
) &&
519 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
523 (*Names
)[i
].Name
.Length
= (name_size
- 1) * sizeof(WCHAR
);
524 (*Names
)[i
].Name
.MaximumLength
= name_size
* sizeof(WCHAR
);
528 (*Names
)[i
].Name
.Length
= 0;
529 (*Names
)[i
].Name
.MaximumLength
= sizeof(WCHAR
);
532 name_fullsize
+= (*Names
)[i
].Name
.MaximumLength
;
534 /* This potentially allocates more than needed, cause different names will reuse same domain index.
535 Also it's not possible to store domain name length right here for the same reason. */
539 BOOL handled
= FALSE
;
542 domain_fullsize
+= domain_size
* sizeof(WCHAR
);
544 /* get domain SID size too */
545 name
= heap_alloc(domain_size
* sizeof(WCHAR
));
547 LookupAccountSidW(NULL
, Sids
[i
], NULL
, &name_size
, name
, &domain_size
, &use
);
549 domain
.Buffer
= name
;
550 domain
.Length
= domain_size
* sizeof(WCHAR
);
551 domain
.MaximumLength
= domain_size
* sizeof(WCHAR
);
553 lookup_name(&domain
, NULL
, &sid_size
, NULL
, &domain_size
, &use
, &handled
);
554 domain_fullsize
+= sid_size
;
560 /* If we don't have a domain name, use a zero-length entry rather than a null value. */
561 domain_fullsize
+= sizeof(WCHAR
);
563 domain
.MaximumLength
= sizeof(WCHAR
);
566 else if (ConvertSidToStringSidW(Sids
[i
], &strsid
))
568 (*Names
)[i
].Name
.Length
= strlenW(strsid
) * sizeof(WCHAR
);
569 (*Names
)[i
].Name
.MaximumLength
= (strlenW(strsid
) + 1) * sizeof(WCHAR
);
570 name_fullsize
+= (strlenW(strsid
) + 1) * sizeof(WCHAR
);
576 /* now we have full length needed for both */
577 *Names
= heap_realloc(*Names
, name_fullsize
);
578 name_buffer
= (WCHAR
*)((char*)*Names
+ sizeof(LSA_TRANSLATED_NAME
)*Count
);
580 *ReferencedDomains
= heap_realloc(*ReferencedDomains
, domain_fullsize
);
581 /* fix pointer after reallocation */
582 (*ReferencedDomains
)->Domains
= (LSA_TRUST_INFORMATION
*)((char*)*ReferencedDomains
+ sizeof(LSA_REFERENCED_DOMAIN_LIST
));
583 domain_data
= (char*)(*ReferencedDomains
)->Domains
+ sizeof(LSA_TRUST_INFORMATION
)*Count
;
586 for (i
= 0; i
< Count
; i
++)
588 name_size
= domain_size
= 0;
590 (*Names
)[i
].Name
.Buffer
= name_buffer
;
592 if (!LookupAccountSidW(NULL
, Sids
[i
], NULL
, &name_size
, NULL
, &domain_size
, &use
) &&
593 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
599 domain
.Length
= (domain_size
- 1) * sizeof(WCHAR
);
600 domain
.MaximumLength
= domain_size
* sizeof(WCHAR
);
604 /* Use a zero-length buffer */
606 domain
.MaximumLength
= sizeof(WCHAR
);
609 domain
.Buffer
= heap_alloc(domain
.MaximumLength
);
611 LookupAccountSidW(NULL
, Sids
[i
], (*Names
)[i
].Name
.Buffer
, &name_size
, domain
.Buffer
, &domain_size
, &use
);
612 (*Names
)[i
].Use
= use
;
614 (*Names
)[i
].DomainIndex
= lsa_reflist_add_domain(*ReferencedDomains
, &domain
, &domain_data
);
615 heap_free(domain
.Buffer
);
617 else if (ConvertSidToStringSidW(Sids
[i
], &strsid
))
619 strcpyW((*Names
)[i
].Name
.Buffer
, strsid
);
623 name_buffer
+= strlenW(name_buffer
) + 1;
625 TRACE("mapped %u out of %u\n", mapped
, Count
);
627 if (mapped
== Count
) return STATUS_SUCCESS
;
628 if (mapped
) return STATUS_SOME_NOT_MAPPED
;
629 return STATUS_NONE_MAPPED
;
632 /******************************************************************************
633 * LsaNtStatusToWinError [ADVAPI32.@]
635 * Converts an LSA NTSTATUS code to a Windows error code.
638 * Status [I] NTSTATUS code.
641 * Success: Corresponding Windows error code.
642 * Failure: ERROR_MR_MID_NOT_FOUND.
644 ULONG WINAPI
LsaNtStatusToWinError(NTSTATUS Status
)
646 return RtlNtStatusToDosError(Status
);
649 /******************************************************************************
650 * LsaOpenPolicy [ADVAPI32.@]
652 * Opens a handle to the Policy object on a local or remote system.
655 * SystemName [I] Name of the target system.
656 * ObjectAttributes [I] Connection attributes.
657 * DesiredAccess [I] Requested access rights.
658 * PolicyHandle [I/O] Handle to the Policy object.
661 * Success: STATUS_SUCCESS.
662 * Failure: NTSTATUS code.
665 * Set SystemName to NULL to open the local Policy object.
667 NTSTATUS WINAPI
LsaOpenPolicy(
668 IN PLSA_UNICODE_STRING SystemName
,
669 IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes
,
670 IN ACCESS_MASK DesiredAccess
,
671 IN OUT PLSA_HANDLE PolicyHandle
)
673 FIXME("(%s,%p,0x%08x,%p) stub\n",
674 SystemName
?debugstr_w(SystemName
->Buffer
):"(null)",
675 ObjectAttributes
, DesiredAccess
, PolicyHandle
);
677 ADVAPI_ForceLocalComputer(SystemName
? SystemName
->Buffer
: NULL
,
678 STATUS_ACCESS_VIOLATION
);
679 dumpLsaAttributes(ObjectAttributes
);
681 if(PolicyHandle
) *PolicyHandle
= (LSA_HANDLE
)0xcafe;
682 return STATUS_SUCCESS
;
685 /******************************************************************************
686 * LsaOpenTrustedDomainByName [ADVAPI32.@]
689 NTSTATUS WINAPI
LsaOpenTrustedDomainByName(
691 PLSA_UNICODE_STRING name
,
695 FIXME("(%p,%p,0x%08x,%p) stub\n", policy
, name
, access
, handle
);
696 return STATUS_OBJECT_NAME_NOT_FOUND
;
699 /******************************************************************************
700 * LsaQueryInformationPolicy [ADVAPI32.@]
702 * Returns information about a Policy object.
705 * PolicyHandle [I] Handle to a Policy object.
706 * InformationClass [I] Type of information to retrieve.
707 * Buffer [O] Pointer to the requested information.
710 * Success: STATUS_SUCCESS.
711 * Failure: NTSTATUS code.
713 NTSTATUS WINAPI
LsaQueryInformationPolicy(
714 IN LSA_HANDLE PolicyHandle
,
715 IN POLICY_INFORMATION_CLASS InformationClass
,
718 TRACE("(%p,0x%08x,%p)\n", PolicyHandle
, InformationClass
, Buffer
);
720 if(!Buffer
) return STATUS_INVALID_PARAMETER
;
721 switch (InformationClass
)
723 case PolicyAuditEventsInformation
: /* 2 */
725 PPOLICY_AUDIT_EVENTS_INFO p
= heap_alloc_zero(sizeof(POLICY_AUDIT_EVENTS_INFO
));
726 p
->AuditingMode
= FALSE
; /* no auditing */
730 case PolicyPrimaryDomainInformation
: /* 3 */
732 /* Only the domain name is valid for the local computer.
733 * All other fields are zero.
735 PPOLICY_PRIMARY_DOMAIN_INFO pinfo
;
737 pinfo
= ADVAPI_GetDomainName(sizeof(*pinfo
), offsetof(POLICY_PRIMARY_DOMAIN_INFO
, Name
));
739 TRACE("setting domain to %s\n", debugstr_w(pinfo
->Name
.Buffer
));
744 case PolicyAccountDomainInformation
: /* 5 */
748 POLICY_ACCOUNT_DOMAIN_INFO info
;
751 WCHAR domain
[MAX_COMPUTERNAME_LENGTH
+ 1];
754 DWORD dwSize
= MAX_COMPUTERNAME_LENGTH
+ 1;
755 struct di
* xdi
= heap_alloc_zero(sizeof(*xdi
));
757 xdi
->info
.DomainName
.MaximumLength
= dwSize
* sizeof(WCHAR
);
758 xdi
->info
.DomainName
.Buffer
= xdi
->domain
;
759 if (GetComputerNameW(xdi
->info
.DomainName
.Buffer
, &dwSize
))
760 xdi
->info
.DomainName
.Length
= dwSize
* sizeof(WCHAR
);
762 TRACE("setting name to %s\n", debugstr_w(xdi
->info
.DomainName
.Buffer
));
764 xdi
->info
.DomainSid
= &xdi
->sid
;
766 if (!ADVAPI_GetComputerSid(&xdi
->sid
))
770 WARN("Computer SID not found\n");
772 return STATUS_UNSUCCESSFUL
;
775 TRACE("setting SID to %s\n", debugstr_sid(&xdi
->sid
));
780 case PolicyDnsDomainInformation
: /* 12 (0xc) */
784 POLICY_DNS_DOMAIN_INFO info
;
788 DWORD sid_subauthority
[3];
790 WCHAR domain_name
[256];
791 WCHAR dns_domain_name
[256];
792 WCHAR dns_forest_name
[256];
797 DWORD sid_subauthority
[3];
801 xdi
= heap_alloc_zero(sizeof(*xdi
));
802 if (!xdi
) return STATUS_NO_MEMORY
;
805 if (GetComputerNameExW(ComputerNamePhysicalDnsDomain
, xdi
->domain_name
, &dwSize
))
809 dot
= strrchrW(xdi
->domain_name
, '.');
811 struprW(xdi
->domain_name
);
812 xdi
->info
.Name
.Buffer
= xdi
->domain_name
;
813 xdi
->info
.Name
.Length
= strlenW(xdi
->domain_name
) * sizeof(WCHAR
);
814 xdi
->info
.Name
.MaximumLength
= xdi
->info
.Name
.Length
+ sizeof(WCHAR
);
815 TRACE("setting Name to %s\n", debugstr_w(xdi
->info
.Name
.Buffer
));
819 if (GetComputerNameExW(ComputerNameDnsDomain
, xdi
->dns_domain_name
, &dwSize
))
821 xdi
->info
.DnsDomainName
.Buffer
= xdi
->dns_domain_name
;
822 xdi
->info
.DnsDomainName
.Length
= dwSize
* sizeof(WCHAR
);
823 xdi
->info
.DnsDomainName
.MaximumLength
= (dwSize
+ 1) * sizeof(WCHAR
);
824 TRACE("setting DnsDomainName to %s\n", debugstr_w(xdi
->info
.DnsDomainName
.Buffer
));
826 xdi
->info
.DnsForestName
.Buffer
= xdi
->dns_domain_name
;
827 xdi
->info
.DnsForestName
.Length
= dwSize
* sizeof(WCHAR
);
828 xdi
->info
.DnsForestName
.MaximumLength
= (dwSize
+ 1) * sizeof(WCHAR
);
829 TRACE("setting DnsForestName to %s\n", debugstr_w(xdi
->info
.DnsForestName
.Buffer
));
832 dwSize
= sizeof(xdi
->domain_sid
);
833 if (ADVAPI_GetComputerSid(&computer_sid
.sid
) && GetWindowsAccountDomainSid(&computer_sid
.sid
, &xdi
->domain_sid
.sid
, &dwSize
))
835 xdi
->info
.Sid
= &xdi
->domain_sid
.sid
;
836 TRACE("setting SID to %s\n", debugstr_sid(&xdi
->domain_sid
.sid
));
842 case PolicyAuditLogInformation
:
843 case PolicyPdAccountInformation
:
844 case PolicyLsaServerRoleInformation
:
845 case PolicyReplicaSourceInformation
:
846 case PolicyDefaultQuotaInformation
:
847 case PolicyModificationInformation
:
848 case PolicyAuditFullSetInformation
:
849 case PolicyAuditFullQueryInformation
:
851 FIXME("category %d not implemented\n", InformationClass
);
852 return STATUS_UNSUCCESSFUL
;
855 return STATUS_SUCCESS
;
858 /******************************************************************************
859 * LsaQueryTrustedDomainInfo [ADVAPI32.@]
862 NTSTATUS WINAPI
LsaQueryTrustedDomainInfo(
865 TRUSTED_INFORMATION_CLASS
class,
868 FIXME("(%p,%p,%d,%p) stub\n", policy
, sid
, class, buffer
);
869 return STATUS_OBJECT_NAME_NOT_FOUND
;
872 /******************************************************************************
873 * LsaQueryTrustedDomainInfoByName [ADVAPI32.@]
876 NTSTATUS WINAPI
LsaQueryTrustedDomainInfoByName(
878 PLSA_UNICODE_STRING name
,
879 TRUSTED_INFORMATION_CLASS
class,
882 FIXME("(%p,%p,%d,%p) stub\n", policy
, name
, class, buffer
);
883 return STATUS_OBJECT_NAME_NOT_FOUND
;
886 /******************************************************************************
887 * LsaRegisterPolicyChangeNotification [ADVAPI32.@]
890 NTSTATUS WINAPI
LsaRegisterPolicyChangeNotification(
891 POLICY_NOTIFICATION_INFORMATION_CLASS
class,
894 FIXME("(%d,%p) stub\n", class, event
);
895 return STATUS_UNSUCCESSFUL
;
898 /******************************************************************************
899 * LsaRemoveAccountRights [ADVAPI32.@]
902 NTSTATUS WINAPI
LsaRemoveAccountRights(
906 PLSA_UNICODE_STRING rights
,
909 FIXME("(%p,%p,%d,%p,0x%08x) stub\n", policy
, sid
, all
, rights
, count
);
910 return STATUS_SUCCESS
;
913 /******************************************************************************
914 * LsaRetrievePrivateData [ADVAPI32.@]
916 * Retrieves data stored by LsaStorePrivateData.
919 * PolicyHandle [I] Handle to a Policy object.
920 * KeyName [I] Name of the key where the data is stored.
921 * PrivateData [O] Pointer to the private data.
924 * Success: STATUS_SUCCESS.
925 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
927 NTSTATUS WINAPI
LsaRetrievePrivateData(
928 IN LSA_HANDLE PolicyHandle
,
929 IN PLSA_UNICODE_STRING KeyName
,
930 OUT PLSA_UNICODE_STRING
* PrivateData
)
932 FIXME("(%p,%p,%p) stub\n", PolicyHandle
, KeyName
, PrivateData
);
933 return STATUS_OBJECT_NAME_NOT_FOUND
;
936 /******************************************************************************
937 * LsaSetInformationPolicy [ADVAPI32.@]
939 * Modifies information in a Policy object.
942 * PolicyHandle [I] Handle to a Policy object.
943 * InformationClass [I] Type of information to set.
944 * Buffer [I] Pointer to the information to set.
947 * Success: STATUS_SUCCESS.
948 * Failure: NTSTATUS code.
950 NTSTATUS WINAPI
LsaSetInformationPolicy(
951 IN LSA_HANDLE PolicyHandle
,
952 IN POLICY_INFORMATION_CLASS InformationClass
,
955 FIXME("(%p,0x%08x,%p) stub\n", PolicyHandle
, InformationClass
, Buffer
);
957 return STATUS_UNSUCCESSFUL
;
960 /******************************************************************************
961 * LsaSetSecret [ADVAPI32.@]
963 * Set old and new values on a secret handle
966 * SecretHandle [I] Handle to a secret object.
967 * EncryptedCurrentValue [I] Pointer to encrypted new value, can be NULL
968 * EncryptedOldValue [I] Pointer to encrypted old value, can be NULL
971 * Success: STATUS_SUCCESS
972 * Failure: NTSTATUS code.
974 NTSTATUS WINAPI
LsaSetSecret(
975 IN LSA_HANDLE SecretHandle
,
976 IN PLSA_UNICODE_STRING EncryptedCurrentValue
,
977 IN PLSA_UNICODE_STRING EncryptedOldValue
)
979 FIXME("(%p,%p,%p) stub\n", SecretHandle
, EncryptedCurrentValue
,
981 return STATUS_SUCCESS
;
984 /******************************************************************************
985 * LsaSetTrustedDomainInfoByName [ADVAPI32.@]
988 NTSTATUS WINAPI
LsaSetTrustedDomainInfoByName(
990 PLSA_UNICODE_STRING name
,
991 TRUSTED_INFORMATION_CLASS
class,
994 FIXME("(%p,%p,%d,%p) stub\n", policy
, name
, class, buffer
);
995 return STATUS_SUCCESS
;
998 /******************************************************************************
999 * LsaSetTrustedDomainInformation [ADVAPI32.@]
1002 NTSTATUS WINAPI
LsaSetTrustedDomainInformation(
1005 TRUSTED_INFORMATION_CLASS
class,
1008 FIXME("(%p,%p,%d,%p) stub\n", policy
, sid
, class, buffer
);
1009 return STATUS_SUCCESS
;
1012 /******************************************************************************
1013 * LsaStorePrivateData [ADVAPI32.@]
1015 * Stores or deletes a Policy object's data under the specified reg key.
1018 * PolicyHandle [I] Handle to a Policy object.
1019 * KeyName [I] Name of the key where the data will be stored.
1020 * PrivateData [O] Pointer to the private data.
1023 * Success: STATUS_SUCCESS.
1024 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
1026 NTSTATUS WINAPI
LsaStorePrivateData(
1027 IN LSA_HANDLE PolicyHandle
,
1028 IN PLSA_UNICODE_STRING KeyName
,
1029 IN PLSA_UNICODE_STRING PrivateData
)
1031 FIXME("(%p,%p,%p) stub\n", PolicyHandle
, KeyName
, PrivateData
);
1032 return STATUS_OBJECT_NAME_NOT_FOUND
;
1035 /******************************************************************************
1036 * LsaUnregisterPolicyChangeNotification [ADVAPI32.@]
1039 NTSTATUS WINAPI
LsaUnregisterPolicyChangeNotification(
1040 POLICY_NOTIFICATION_INFORMATION_CLASS
class,
1043 FIXME("(%d,%p) stub\n", class, event
);
1044 return STATUS_SUCCESS
;
1047 /******************************************************************************
1048 * LsaLookupPrivilegeName [ADVAPI32.@]
1051 NTSTATUS WINAPI
LsaLookupPrivilegeName(LSA_HANDLE handle
, LUID
*luid
, LSA_UNICODE_STRING
**name
)
1053 const WCHAR
*privnameW
;
1057 TRACE("(%p,%p,%p)\n", handle
, luid
, name
);
1059 if (!luid
|| !handle
)
1060 return STATUS_INVALID_PARAMETER
;
1064 if (!(privnameW
= get_wellknown_privilege_name(luid
)))
1065 return STATUS_NO_SUCH_PRIVILEGE
;
1067 length
= strlenW(privnameW
);
1068 *name
= heap_alloc(sizeof(**name
) + (length
+ 1) * sizeof(WCHAR
));
1070 return STATUS_NO_MEMORY
;
1072 strW
= (WCHAR
*)(*name
+ 1);
1073 memcpy(strW
, privnameW
, length
* sizeof(WCHAR
));
1075 RtlInitUnicodeString(*name
, strW
);
1077 return STATUS_SUCCESS
;
1080 /******************************************************************************
1081 * LsaLookupPrivilegeDisplayName [ADVAPI32.@]
1084 NTSTATUS WINAPI
LsaLookupPrivilegeDisplayName(LSA_HANDLE handle
, LSA_UNICODE_STRING
*name
,
1085 LSA_UNICODE_STRING
**display_name
, SHORT
*language
)
1087 FIXME("(%p, %s, %p, %p)\n", handle
, debugstr_us(name
), display_name
, language
);
1089 return STATUS_NO_SUCH_PRIVILEGE
;
1092 /******************************************************************************
1093 * AuditQuerySystemPolicy [ADVAPI32.@]
1096 BOOLEAN WINAPI
AuditQuerySystemPolicy(const GUID
* guids
, ULONG count
, AUDIT_POLICY_INFORMATION
** policy
)
1099 FIXME("(%p, %d, %p)\n", guids
, count
, policy
);
1100 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);