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 LPCSTR
debugstr_us( const UNICODE_STRING
*us
)
49 if (!us
) return "(null)";
50 return debugstr_wn(us
->Buffer
, us
->Length
/ sizeof(WCHAR
));
53 static void dumpLsaAttributes(const LSA_OBJECT_ATTRIBUTES
*oa
)
57 TRACE("\n\tlength=%u, rootdir=%p, objectname=%s\n\tattr=0x%08x, sid=%s qos=%p\n",
58 oa
->Length
, oa
->RootDirectory
,
59 oa
->ObjectName
?debugstr_w(oa
->ObjectName
->Buffer
):"null",
60 oa
->Attributes
, debugstr_sid(oa
->SecurityDescriptor
),
61 oa
->SecurityQualityOfService
);
65 static void* ADVAPI_GetDomainName(unsigned sz
, unsigned ofs
)
72 ret
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"System\\CurrentControlSet\\Services\\VxD\\VNETSUP", 0, KEY_READ
, &key
);
73 if (ret
== ERROR_SUCCESS
)
76 ret
= RegQueryValueExW(key
, L
"Workgroup", NULL
, NULL
, NULL
, &size
);
77 if (ret
== ERROR_MORE_DATA
|| ret
== ERROR_SUCCESS
)
79 ptr
= heap_alloc_zero(sz
+ size
);
80 if (!ptr
) return NULL
;
81 ustr
= (UNICODE_STRING
*)(ptr
+ ofs
);
82 ustr
->MaximumLength
= size
;
83 ustr
->Buffer
= (WCHAR
*)(ptr
+ sz
);
84 ret
= RegQueryValueExW(key
, L
"Workgroup", NULL
, NULL
, (LPBYTE
)ustr
->Buffer
, &size
);
85 if (ret
!= ERROR_SUCCESS
)
90 else ustr
->Length
= size
- sizeof(WCHAR
);
96 ptr
= heap_alloc_zero(sz
+ sizeof(L
"DOMAIN"));
97 if (!ptr
) return NULL
;
98 ustr
= (UNICODE_STRING
*)(ptr
+ ofs
);
99 ustr
->MaximumLength
= sizeof(L
"DOMAIN");
100 ustr
->Buffer
= (WCHAR
*)(ptr
+ sz
);
101 ustr
->Length
= sizeof(L
"DOMAIN") - sizeof(WCHAR
);
102 memcpy(ustr
->Buffer
, L
"DOMAIN", sizeof(L
"DOMAIN"));
107 /******************************************************************************
108 * LsaGetUserName [ADVAPI32.@]
111 NTSTATUS WINAPI
LsaGetUserName(PUNICODE_STRING
*user_name
, PUNICODE_STRING
*domain_name
)
113 UNICODE_STRING
*user
;
117 if (GetUserNameW(NULL
, &user_size
) || GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
118 return STATUS_UNSUCCESSFUL
;
120 user
= heap_alloc(sizeof(*user
) + user_size
* sizeof(WCHAR
));
121 if (!user
) return STATUS_NO_MEMORY
;
123 user
->Buffer
= (WCHAR
*)(user
+ 1);
124 user
->MaximumLength
= user_size
* sizeof(WCHAR
);
125 user
->Length
= user
->MaximumLength
- sizeof(WCHAR
);
126 if (!GetUserNameW(user
->Buffer
, &user_size
))
129 return STATUS_UNSUCCESSFUL
;
134 UNICODE_STRING
*domain
;
135 WCHAR computer
[MAX_COMPUTERNAME_LENGTH
+ 1];
138 domain_size
= ARRAY_SIZE(computer
);
139 if (!GetComputerNameW(computer
, &domain_size
))
142 return STATUS_UNSUCCESSFUL
;
145 domain
= heap_alloc(sizeof(*domain
) + (domain_size
+ 1) * sizeof(WCHAR
));
149 return STATUS_NO_MEMORY
;
152 domain
->Buffer
= (WCHAR
*)(domain
+ 1);
153 domain
->Length
= domain_size
* sizeof(WCHAR
);
154 domain
->MaximumLength
= domain
->Length
+ sizeof(WCHAR
);
155 wcscpy(domain
->Buffer
, computer
);
157 *domain_name
= domain
;
162 return STATUS_SUCCESS
;
165 /******************************************************************************
166 * LsaAddAccountRights [ADVAPI32.@]
169 NTSTATUS WINAPI
LsaAddAccountRights(
172 PLSA_UNICODE_STRING rights
,
175 FIXME("(%p,%p,%p,0x%08x) stub\n", policy
, sid
, rights
, count
);
176 return STATUS_SUCCESS
;
179 /******************************************************************************
180 * LsaClose [ADVAPI32.@]
182 * Closes a handle to a Policy or TrustedDomain.
185 * ObjectHandle [I] Handle to a Policy or TrustedDomain.
188 * Success: STATUS_SUCCESS.
189 * Failure: NTSTATUS code.
191 NTSTATUS WINAPI
LsaClose(IN LSA_HANDLE ObjectHandle
)
193 FIXME("(%p) stub\n", ObjectHandle
);
194 return STATUS_SUCCESS
;
197 /******************************************************************************
198 * LsaCreateTrustedDomainEx [ADVAPI32.@]
201 NTSTATUS WINAPI
LsaCreateTrustedDomainEx(
203 PTRUSTED_DOMAIN_INFORMATION_EX domain_info
,
204 PTRUSTED_DOMAIN_AUTH_INFORMATION auth_info
,
208 FIXME("(%p,%p,%p,0x%08x,%p) stub\n", policy
, domain_info
, auth_info
,
210 return STATUS_SUCCESS
;
213 /******************************************************************************
214 * LsaDeleteTrustedDomain [ADVAPI32.@]
217 NTSTATUS WINAPI
LsaDeleteTrustedDomain(LSA_HANDLE policy
, PSID sid
)
219 FIXME("(%p,%p) stub\n", policy
, sid
);
220 return STATUS_SUCCESS
;
223 /******************************************************************************
224 * LsaEnumerateAccountRights [ADVAPI32.@]
227 NTSTATUS WINAPI
LsaEnumerateAccountRights(
230 PLSA_UNICODE_STRING
*rights
,
233 FIXME("(%p,%p,%p,%p) stub\n", policy
, sid
, rights
, count
);
236 return STATUS_OBJECT_NAME_NOT_FOUND
;
239 /******************************************************************************
240 * LsaEnumerateAccountsWithUserRight [ADVAPI32.@]
243 NTSTATUS WINAPI
LsaEnumerateAccountsWithUserRight(
245 PLSA_UNICODE_STRING rights
,
249 FIXME("(%p,%p,%p,%p) stub\n", policy
, rights
, buffer
, count
);
250 return STATUS_NO_MORE_ENTRIES
;
253 /******************************************************************************
254 * LsaEnumerateTrustedDomains [ADVAPI32.@]
256 * Returns the names and SIDs of trusted domains.
259 * PolicyHandle [I] Handle to a Policy object.
260 * EnumerationContext [I] Pointer to an enumeration handle.
261 * Buffer [O] Contains the names and SIDs of trusted domains.
262 * PreferredMaximumLength[I] Preferred maximum size in bytes of Buffer.
263 * CountReturned [O] Number of elements in Buffer.
266 * Success: STATUS_SUCCESS,
267 * STATUS_MORE_ENTRIES,
268 * STATUS_NO_MORE_ENTRIES
269 * Failure: NTSTATUS code.
272 * LsaEnumerateTrustedDomains can be called multiple times to enumerate
273 * all trusted domains.
275 NTSTATUS WINAPI
LsaEnumerateTrustedDomains(
276 IN LSA_HANDLE PolicyHandle
,
277 IN PLSA_ENUMERATION_HANDLE EnumerationContext
,
279 IN ULONG PreferredMaximumLength
,
280 OUT PULONG CountReturned
)
282 FIXME("(%p,%p,%p,0x%08x,%p) stub\n", PolicyHandle
, EnumerationContext
,
283 Buffer
, PreferredMaximumLength
, CountReturned
);
285 if (CountReturned
) *CountReturned
= 0;
286 return STATUS_SUCCESS
;
289 /******************************************************************************
290 * LsaEnumerateTrustedDomainsEx [ADVAPI32.@]
293 NTSTATUS WINAPI
LsaEnumerateTrustedDomainsEx(
295 PLSA_ENUMERATION_HANDLE context
,
300 FIXME("(%p,%p,%p,0x%08x,%p) stub\n", policy
, context
, buffer
, length
, count
);
302 if (count
) *count
= 0;
303 return STATUS_SUCCESS
;
306 /******************************************************************************
307 * LsaFreeMemory [ADVAPI32.@]
309 * Frees memory allocated by a LSA function.
312 * Buffer [I] Memory buffer to free.
315 * Success: STATUS_SUCCESS.
316 * Failure: NTSTATUS code.
318 NTSTATUS WINAPI
LsaFreeMemory(IN PVOID Buffer
)
320 TRACE("(%p)\n", Buffer
);
323 return STATUS_SUCCESS
;
326 /******************************************************************************
327 * LsaLookupNames [ADVAPI32.@]
329 * Returns the SIDs of an array of user, group, or local group names.
332 * PolicyHandle [I] Handle to a Policy object.
333 * Count [I] Number of names in Names.
334 * Names [I] Array of names to lookup.
335 * ReferencedDomains [O] Array of domains where the names were found.
336 * Sids [O] Array of SIDs corresponding to Names.
339 * Success: STATUS_SUCCESS,
340 * STATUS_SOME_NOT_MAPPED
341 * Failure: STATUS_NONE_MAPPED or NTSTATUS code.
343 NTSTATUS WINAPI
LsaLookupNames(
344 IN LSA_HANDLE PolicyHandle
,
346 IN PLSA_UNICODE_STRING Names
,
347 OUT PLSA_REFERENCED_DOMAIN_LIST
* ReferencedDomains
,
348 OUT PLSA_TRANSLATED_SID
* Sids
)
350 FIXME("(%p,0x%08x,%p,%p,%p) stub\n", PolicyHandle
, Count
, Names
,
351 ReferencedDomains
, Sids
);
353 return STATUS_NONE_MAPPED
;
356 static BOOL
lookup_name( LSA_UNICODE_STRING
*name
, SID
*sid
, DWORD
*sid_size
, WCHAR
*domain
,
357 DWORD
*domain_size
, SID_NAME_USE
*use
, BOOL
*handled
)
361 ret
= lookup_local_wellknown_name( name
, sid
, sid_size
, domain
, domain_size
, use
, handled
);
363 ret
= lookup_local_user_name( name
, sid
, sid_size
, domain
, domain_size
, use
, handled
);
368 /* Adds domain info to referenced domain list.
369 Domain list is stored as plain buffer, layout is:
371 LSA_REFERENCED_DOMAIN_LIST,
372 LSA_TRUST_INFORMATION array,
375 domain name data (WCHAR buffer),
380 list [I] referenced list pointer
381 domain [I] domain name string
382 data [IO] pointer to domain data array
384 static LONG
lsa_reflist_add_domain(LSA_REFERENCED_DOMAIN_LIST
*list
, LSA_UNICODE_STRING
*domain
, char **data
)
386 ULONG sid_size
= 0,domain_size
= 0;
387 BOOL handled
= FALSE
;
391 for (i
= 0; i
< list
->Entries
; i
++)
393 /* try to reuse index */
394 if ((list
->Domains
[i
].Name
.Length
== domain
->Length
) &&
395 (!wcsnicmp(list
->Domains
[i
].Name
.Buffer
, domain
->Buffer
, (domain
->Length
/ sizeof(WCHAR
)))))
401 /* no matching domain found, store name */
402 list
->Domains
[list
->Entries
].Name
.Length
= domain
->Length
;
403 list
->Domains
[list
->Entries
].Name
.MaximumLength
= domain
->MaximumLength
;
404 list
->Domains
[list
->Entries
].Name
.Buffer
= (WCHAR
*)*data
;
405 memcpy(list
->Domains
[list
->Entries
].Name
.Buffer
, domain
->Buffer
, domain
->MaximumLength
);
406 *data
+= domain
->MaximumLength
;
408 /* get and store SID data */
409 list
->Domains
[list
->Entries
].Sid
= *data
;
410 lookup_name(domain
, NULL
, &sid_size
, NULL
, &domain_size
, &use
, &handled
);
412 lookup_name(domain
, list
->Domains
[list
->Entries
].Sid
, &sid_size
, NULL
, &domain_size
, &use
, &handled
);
415 return list
->Entries
++;
418 /******************************************************************************
419 * LsaLookupNames2 [ADVAPI32.@]
422 NTSTATUS WINAPI
LsaLookupNames2( LSA_HANDLE policy
, ULONG flags
, ULONG count
,
423 PLSA_UNICODE_STRING names
, PLSA_REFERENCED_DOMAIN_LIST
*domains
,
424 PLSA_TRANSLATED_SID2
*sids
)
426 ULONG i
, sid_size_total
= 0, domain_size_max
= 0, size
, domainname_size_total
= 0;
427 ULONG sid_size
, domain_size
, mapped
;
428 LSA_UNICODE_STRING domain
;
429 BOOL handled
= FALSE
;
434 TRACE("(%p,0x%08x,0x%08x,%p,%p,%p)\n", policy
, flags
, count
, names
, domains
, sids
);
437 for (i
= 0; i
< count
; i
++)
440 sid_size
= domain_size
= 0;
441 lookup_name( &names
[i
], NULL
, &sid_size
, NULL
, &domain_size
, &use
, &handled
);
444 sid_size_total
+= sid_size
;
445 domainname_size_total
+= domain_size
;
448 if (domain_size
> domain_size_max
)
449 domain_size_max
= domain_size
;
454 TRACE("mapped %u out of %u\n", mapped
, count
);
456 size
= sizeof(LSA_TRANSLATED_SID2
) * count
+ sid_size_total
;
457 if (!(*sids
= heap_alloc(size
))) return STATUS_NO_MEMORY
;
459 sid
= (SID
*)(*sids
+ count
);
461 /* use maximum domain count */
462 if (!(*domains
= heap_alloc(sizeof(LSA_REFERENCED_DOMAIN_LIST
) + sizeof(LSA_TRUST_INFORMATION
)*count
+
463 sid_size_total
+ domainname_size_total
*sizeof(WCHAR
))))
466 return STATUS_NO_MEMORY
;
468 (*domains
)->Entries
= 0;
469 (*domains
)->Domains
= (LSA_TRUST_INFORMATION
*)((char*)*domains
+ sizeof(LSA_REFERENCED_DOMAIN_LIST
));
470 domain_data
= (char*)(*domains
)->Domains
+ sizeof(LSA_TRUST_INFORMATION
)*count
;
472 domain
.Buffer
= heap_alloc(domain_size_max
*sizeof(WCHAR
));
473 for (i
= 0; i
< count
; i
++)
475 domain
.Length
= domain_size_max
*sizeof(WCHAR
);
476 domain
.MaximumLength
= domain_size_max
*sizeof(WCHAR
);
478 (*sids
)[i
].Use
= SidTypeUnknown
;
479 (*sids
)[i
].DomainIndex
= -1;
480 (*sids
)[i
].Flags
= 0;
483 sid_size
= sid_size_total
;
484 domain_size
= domain_size_max
;
485 lookup_name( &names
[i
], sid
, &sid_size
, domain
.Buffer
, &domain_size
, &use
, &handled
);
488 (*sids
)[i
].Sid
= sid
;
489 (*sids
)[i
].Use
= use
;
491 sid
= (SID
*)((char *)sid
+ sid_size
);
492 sid_size_total
-= sid_size
;
495 domain
.Length
= domain_size
* sizeof(WCHAR
);
496 domain
.MaximumLength
= (domain_size
+ 1) * sizeof(WCHAR
);
497 (*sids
)[i
].DomainIndex
= lsa_reflist_add_domain(*domains
, &domain
, &domain_data
);
501 heap_free(domain
.Buffer
);
503 if (mapped
== count
) return STATUS_SUCCESS
;
504 if (mapped
> 0 && mapped
< count
) return STATUS_SOME_NOT_MAPPED
;
505 return STATUS_NONE_MAPPED
;
508 /******************************************************************************
509 * LsaLookupSids [ADVAPI32.@]
511 * Looks up the names that correspond to an array of SIDs.
514 * PolicyHandle [I] Handle to a Policy object.
515 * Count [I] Number of SIDs in the Sids array.
516 * Sids [I] Array of SIDs to lookup.
517 * ReferencedDomains [O] Array of domains where the sids were found.
518 * Names [O] Array of names corresponding to Sids.
521 * Success: STATUS_SUCCESS,
522 * STATUS_SOME_NOT_MAPPED
523 * Failure: STATUS_NONE_MAPPED or NTSTATUS code.
525 NTSTATUS WINAPI
LsaLookupSids(
526 LSA_HANDLE PolicyHandle
,
529 LSA_REFERENCED_DOMAIN_LIST
**ReferencedDomains
,
530 LSA_TRANSLATED_NAME
**Names
)
532 ULONG i
, mapped
, name_fullsize
, domain_fullsize
;
533 ULONG name_size
, domain_size
;
534 LSA_UNICODE_STRING domain
;
540 TRACE("(%p, %u, %p, %p, %p)\n", PolicyHandle
, Count
, Sids
, ReferencedDomains
, Names
);
542 /* this length does not include actual string length yet */
543 name_fullsize
= sizeof(LSA_TRANSLATED_NAME
) * Count
;
544 if (!(*Names
= heap_alloc(name_fullsize
))) return STATUS_NO_MEMORY
;
545 /* maximum count of stored domain infos is Count, allocate it like that cause really needed
546 count could only be computed after sid data is retrieved */
547 domain_fullsize
= sizeof(LSA_REFERENCED_DOMAIN_LIST
) + sizeof(LSA_TRUST_INFORMATION
)*Count
;
548 if (!(*ReferencedDomains
= heap_alloc(domain_fullsize
)))
551 return STATUS_NO_MEMORY
;
553 (*ReferencedDomains
)->Entries
= 0;
554 (*ReferencedDomains
)->Domains
= (LSA_TRUST_INFORMATION
*)((char*)*ReferencedDomains
+ sizeof(LSA_REFERENCED_DOMAIN_LIST
));
556 /* Get full names data length and full length needed to store domain name and SID */
557 for (i
= 0; i
< Count
; i
++)
559 (*Names
)[i
].Use
= SidTypeUnknown
;
560 (*Names
)[i
].DomainIndex
= -1;
561 RtlInitUnicodeStringEx(&(*Names
)[i
].Name
, NULL
);
563 memset(&(*ReferencedDomains
)->Domains
[i
], 0, sizeof(LSA_TRUST_INFORMATION
));
565 name_size
= domain_size
= 0;
566 if (!LookupAccountSidW(NULL
, Sids
[i
], NULL
, &name_size
, NULL
, &domain_size
, &use
) &&
567 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
571 (*Names
)[i
].Name
.Length
= (name_size
- 1) * sizeof(WCHAR
);
572 (*Names
)[i
].Name
.MaximumLength
= name_size
* sizeof(WCHAR
);
576 (*Names
)[i
].Name
.Length
= 0;
577 (*Names
)[i
].Name
.MaximumLength
= sizeof(WCHAR
);
580 name_fullsize
+= (*Names
)[i
].Name
.MaximumLength
;
582 /* This potentially allocates more than needed, cause different names will reuse same domain index.
583 Also it's not possible to store domain name length right here for the same reason. */
587 BOOL handled
= FALSE
;
590 domain_fullsize
+= domain_size
* sizeof(WCHAR
);
592 /* get domain SID size too */
593 name
= heap_alloc(domain_size
* sizeof(WCHAR
));
595 LookupAccountSidW(NULL
, Sids
[i
], NULL
, &name_size
, name
, &domain_size
, &use
);
597 domain
.Buffer
= name
;
598 domain
.Length
= domain_size
* sizeof(WCHAR
);
599 domain
.MaximumLength
= domain_size
* sizeof(WCHAR
);
601 lookup_name(&domain
, NULL
, &sid_size
, NULL
, &domain_size
, &use
, &handled
);
602 domain_fullsize
+= sid_size
;
608 /* If we don't have a domain name, use a zero-length entry rather than a null value. */
609 domain_fullsize
+= sizeof(WCHAR
);
611 domain
.MaximumLength
= sizeof(WCHAR
);
614 else if (ConvertSidToStringSidW(Sids
[i
], &strsid
))
616 (*Names
)[i
].Name
.Length
= lstrlenW(strsid
) * sizeof(WCHAR
);
617 (*Names
)[i
].Name
.MaximumLength
= (lstrlenW(strsid
) + 1) * sizeof(WCHAR
);
618 name_fullsize
+= (lstrlenW(strsid
) + 1) * sizeof(WCHAR
);
624 /* now we have full length needed for both */
625 *Names
= heap_realloc(*Names
, name_fullsize
);
626 name_buffer
= (WCHAR
*)((char*)*Names
+ sizeof(LSA_TRANSLATED_NAME
)*Count
);
628 *ReferencedDomains
= heap_realloc(*ReferencedDomains
, domain_fullsize
);
629 /* fix pointer after reallocation */
630 (*ReferencedDomains
)->Domains
= (LSA_TRUST_INFORMATION
*)((char*)*ReferencedDomains
+ sizeof(LSA_REFERENCED_DOMAIN_LIST
));
631 domain_data
= (char*)(*ReferencedDomains
)->Domains
+ sizeof(LSA_TRUST_INFORMATION
)*Count
;
634 for (i
= 0; i
< Count
; i
++)
636 name_size
= domain_size
= 0;
638 (*Names
)[i
].Name
.Buffer
= name_buffer
;
640 if (!LookupAccountSidW(NULL
, Sids
[i
], NULL
, &name_size
, NULL
, &domain_size
, &use
) &&
641 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
647 domain
.Length
= (domain_size
- 1) * sizeof(WCHAR
);
648 domain
.MaximumLength
= domain_size
* sizeof(WCHAR
);
652 /* Use a zero-length buffer */
654 domain
.MaximumLength
= sizeof(WCHAR
);
657 domain
.Buffer
= heap_alloc(domain
.MaximumLength
);
659 LookupAccountSidW(NULL
, Sids
[i
], (*Names
)[i
].Name
.Buffer
, &name_size
, domain
.Buffer
, &domain_size
, &use
);
660 (*Names
)[i
].Use
= use
;
662 (*Names
)[i
].DomainIndex
= lsa_reflist_add_domain(*ReferencedDomains
, &domain
, &domain_data
);
663 heap_free(domain
.Buffer
);
665 else if (ConvertSidToStringSidW(Sids
[i
], &strsid
))
667 lstrcpyW((*Names
)[i
].Name
.Buffer
, strsid
);
671 name_buffer
+= lstrlenW(name_buffer
) + 1;
673 TRACE("mapped %u out of %u\n", mapped
, Count
);
675 if (mapped
== Count
) return STATUS_SUCCESS
;
676 if (mapped
) return STATUS_SOME_NOT_MAPPED
;
677 return STATUS_NONE_MAPPED
;
680 /******************************************************************************
681 * LsaNtStatusToWinError [ADVAPI32.@]
683 * Converts an LSA NTSTATUS code to a Windows error code.
686 * Status [I] NTSTATUS code.
689 * Success: Corresponding Windows error code.
690 * Failure: ERROR_MR_MID_NOT_FOUND.
692 ULONG WINAPI
LsaNtStatusToWinError(NTSTATUS Status
)
694 return RtlNtStatusToDosError(Status
);
697 /******************************************************************************
698 * LsaOpenPolicy [ADVAPI32.@]
700 * Opens a handle to the Policy object on a local or remote system.
703 * SystemName [I] Name of the target system.
704 * ObjectAttributes [I] Connection attributes.
705 * DesiredAccess [I] Requested access rights.
706 * PolicyHandle [I/O] Handle to the Policy object.
709 * Success: STATUS_SUCCESS.
710 * Failure: NTSTATUS code.
713 * Set SystemName to NULL to open the local Policy object.
715 NTSTATUS WINAPI
LsaOpenPolicy(
716 IN PLSA_UNICODE_STRING SystemName
,
717 IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes
,
718 IN ACCESS_MASK DesiredAccess
,
719 IN OUT PLSA_HANDLE PolicyHandle
)
721 FIXME("(%s,%p,0x%08x,%p) stub\n",
722 SystemName
?debugstr_w(SystemName
->Buffer
):"(null)",
723 ObjectAttributes
, DesiredAccess
, PolicyHandle
);
725 ADVAPI_ForceLocalComputer(SystemName
? SystemName
->Buffer
: NULL
,
726 STATUS_ACCESS_VIOLATION
);
727 dumpLsaAttributes(ObjectAttributes
);
729 if(PolicyHandle
) *PolicyHandle
= (LSA_HANDLE
)0xcafe;
730 return STATUS_SUCCESS
;
733 /******************************************************************************
734 * LsaOpenTrustedDomainByName [ADVAPI32.@]
737 NTSTATUS WINAPI
LsaOpenTrustedDomainByName(
739 PLSA_UNICODE_STRING name
,
743 FIXME("(%p,%p,0x%08x,%p) stub\n", policy
, name
, access
, handle
);
744 return STATUS_OBJECT_NAME_NOT_FOUND
;
747 /******************************************************************************
748 * LsaQueryInformationPolicy [ADVAPI32.@]
750 * Returns information about a Policy object.
753 * PolicyHandle [I] Handle to a Policy object.
754 * InformationClass [I] Type of information to retrieve.
755 * Buffer [O] Pointer to the requested information.
758 * Success: STATUS_SUCCESS.
759 * Failure: NTSTATUS code.
761 NTSTATUS WINAPI
LsaQueryInformationPolicy(
762 IN LSA_HANDLE PolicyHandle
,
763 IN POLICY_INFORMATION_CLASS InformationClass
,
766 TRACE("(%p,0x%08x,%p)\n", PolicyHandle
, InformationClass
, Buffer
);
768 if(!Buffer
) return STATUS_INVALID_PARAMETER
;
769 switch (InformationClass
)
771 case PolicyAuditEventsInformation
: /* 2 */
773 PPOLICY_AUDIT_EVENTS_INFO p
= heap_alloc_zero(sizeof(POLICY_AUDIT_EVENTS_INFO
));
774 p
->AuditingMode
= FALSE
; /* no auditing */
778 case PolicyPrimaryDomainInformation
: /* 3 */
780 /* Only the domain name is valid for the local computer.
781 * All other fields are zero.
783 PPOLICY_PRIMARY_DOMAIN_INFO pinfo
;
785 pinfo
= ADVAPI_GetDomainName(sizeof(*pinfo
), offsetof(POLICY_PRIMARY_DOMAIN_INFO
, Name
));
787 TRACE("setting domain to %s\n", debugstr_w(pinfo
->Name
.Buffer
));
792 case PolicyAccountDomainInformation
: /* 5 */
796 POLICY_ACCOUNT_DOMAIN_INFO info
;
799 WCHAR domain
[MAX_COMPUTERNAME_LENGTH
+ 1];
802 DWORD dwSize
= MAX_COMPUTERNAME_LENGTH
+ 1;
803 struct di
* xdi
= heap_alloc_zero(sizeof(*xdi
));
805 xdi
->info
.DomainName
.MaximumLength
= dwSize
* sizeof(WCHAR
);
806 xdi
->info
.DomainName
.Buffer
= xdi
->domain
;
807 if (GetComputerNameW(xdi
->info
.DomainName
.Buffer
, &dwSize
))
808 xdi
->info
.DomainName
.Length
= dwSize
* sizeof(WCHAR
);
810 TRACE("setting name to %s\n", debugstr_w(xdi
->info
.DomainName
.Buffer
));
812 xdi
->info
.DomainSid
= &xdi
->sid
;
814 if (!ADVAPI_GetComputerSid(&xdi
->sid
))
818 WARN("Computer SID not found\n");
820 return STATUS_UNSUCCESSFUL
;
823 TRACE("setting SID to %s\n", debugstr_sid(&xdi
->sid
));
828 case PolicyDnsDomainInformation
: /* 12 (0xc) */
832 POLICY_DNS_DOMAIN_INFO info
;
836 DWORD sid_subauthority
[3];
838 WCHAR domain_name
[256];
839 WCHAR dns_domain_name
[256];
840 WCHAR dns_forest_name
[256];
845 DWORD sid_subauthority
[3];
849 xdi
= heap_alloc_zero(sizeof(*xdi
));
850 if (!xdi
) return STATUS_NO_MEMORY
;
853 if (GetComputerNameExW(ComputerNamePhysicalDnsDomain
, xdi
->domain_name
, &dwSize
))
857 dot
= wcsrchr(xdi
->domain_name
, '.');
859 wcsupr(xdi
->domain_name
);
860 xdi
->info
.Name
.Buffer
= xdi
->domain_name
;
861 xdi
->info
.Name
.Length
= lstrlenW(xdi
->domain_name
) * sizeof(WCHAR
);
862 xdi
->info
.Name
.MaximumLength
= xdi
->info
.Name
.Length
+ sizeof(WCHAR
);
863 TRACE("setting Name to %s\n", debugstr_w(xdi
->info
.Name
.Buffer
));
867 if (GetComputerNameExW(ComputerNameDnsDomain
, xdi
->dns_domain_name
, &dwSize
))
869 xdi
->info
.DnsDomainName
.Buffer
= xdi
->dns_domain_name
;
870 xdi
->info
.DnsDomainName
.Length
= dwSize
* sizeof(WCHAR
);
871 xdi
->info
.DnsDomainName
.MaximumLength
= (dwSize
+ 1) * sizeof(WCHAR
);
872 TRACE("setting DnsDomainName to %s\n", debugstr_w(xdi
->info
.DnsDomainName
.Buffer
));
874 xdi
->info
.DnsForestName
.Buffer
= xdi
->dns_domain_name
;
875 xdi
->info
.DnsForestName
.Length
= dwSize
* sizeof(WCHAR
);
876 xdi
->info
.DnsForestName
.MaximumLength
= (dwSize
+ 1) * sizeof(WCHAR
);
877 TRACE("setting DnsForestName to %s\n", debugstr_w(xdi
->info
.DnsForestName
.Buffer
));
880 dwSize
= sizeof(xdi
->domain_sid
);
881 if (ADVAPI_GetComputerSid(&computer_sid
.sid
) && GetWindowsAccountDomainSid(&computer_sid
.sid
, &xdi
->domain_sid
.sid
, &dwSize
))
883 xdi
->info
.Sid
= &xdi
->domain_sid
.sid
;
884 TRACE("setting SID to %s\n", debugstr_sid(&xdi
->domain_sid
.sid
));
890 case PolicyAuditLogInformation
:
891 case PolicyPdAccountInformation
:
892 case PolicyLsaServerRoleInformation
:
893 case PolicyReplicaSourceInformation
:
894 case PolicyDefaultQuotaInformation
:
895 case PolicyModificationInformation
:
896 case PolicyAuditFullSetInformation
:
897 case PolicyAuditFullQueryInformation
:
899 FIXME("category %d not implemented\n", InformationClass
);
900 return STATUS_UNSUCCESSFUL
;
903 return STATUS_SUCCESS
;
906 /******************************************************************************
907 * LsaQueryTrustedDomainInfo [ADVAPI32.@]
910 NTSTATUS WINAPI
LsaQueryTrustedDomainInfo(
913 TRUSTED_INFORMATION_CLASS
class,
916 FIXME("(%p,%p,%d,%p) stub\n", policy
, sid
, class, buffer
);
917 return STATUS_OBJECT_NAME_NOT_FOUND
;
920 /******************************************************************************
921 * LsaQueryTrustedDomainInfoByName [ADVAPI32.@]
924 NTSTATUS WINAPI
LsaQueryTrustedDomainInfoByName(
926 PLSA_UNICODE_STRING name
,
927 TRUSTED_INFORMATION_CLASS
class,
930 FIXME("(%p,%p,%d,%p) stub\n", policy
, name
, class, buffer
);
931 return STATUS_OBJECT_NAME_NOT_FOUND
;
934 /******************************************************************************
935 * LsaRegisterPolicyChangeNotification [ADVAPI32.@]
938 NTSTATUS WINAPI
LsaRegisterPolicyChangeNotification(
939 POLICY_NOTIFICATION_INFORMATION_CLASS
class,
942 FIXME("(%d,%p) stub\n", class, event
);
943 return STATUS_UNSUCCESSFUL
;
946 /******************************************************************************
947 * LsaRemoveAccountRights [ADVAPI32.@]
950 NTSTATUS WINAPI
LsaRemoveAccountRights(
954 PLSA_UNICODE_STRING rights
,
957 FIXME("(%p,%p,%d,%p,0x%08x) stub\n", policy
, sid
, all
, rights
, count
);
958 return STATUS_SUCCESS
;
961 /******************************************************************************
962 * LsaRetrievePrivateData [ADVAPI32.@]
964 * Retrieves data stored by LsaStorePrivateData.
967 * PolicyHandle [I] Handle to a Policy object.
968 * KeyName [I] Name of the key where the data is stored.
969 * PrivateData [O] Pointer to the private data.
972 * Success: STATUS_SUCCESS.
973 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
975 NTSTATUS WINAPI
LsaRetrievePrivateData(
976 IN LSA_HANDLE PolicyHandle
,
977 IN PLSA_UNICODE_STRING KeyName
,
978 OUT PLSA_UNICODE_STRING
* PrivateData
)
980 FIXME("(%p,%p,%p) stub\n", PolicyHandle
, KeyName
, PrivateData
);
981 return STATUS_OBJECT_NAME_NOT_FOUND
;
984 /******************************************************************************
985 * LsaSetInformationPolicy [ADVAPI32.@]
987 * Modifies information in a Policy object.
990 * PolicyHandle [I] Handle to a Policy object.
991 * InformationClass [I] Type of information to set.
992 * Buffer [I] Pointer to the information to set.
995 * Success: STATUS_SUCCESS.
996 * Failure: NTSTATUS code.
998 NTSTATUS WINAPI
LsaSetInformationPolicy(
999 IN LSA_HANDLE PolicyHandle
,
1000 IN POLICY_INFORMATION_CLASS InformationClass
,
1003 FIXME("(%p,0x%08x,%p) stub\n", PolicyHandle
, InformationClass
, Buffer
);
1005 return STATUS_UNSUCCESSFUL
;
1008 /******************************************************************************
1009 * LsaSetSecret [ADVAPI32.@]
1011 * Set old and new values on a secret handle
1014 * SecretHandle [I] Handle to a secret object.
1015 * EncryptedCurrentValue [I] Pointer to encrypted new value, can be NULL
1016 * EncryptedOldValue [I] Pointer to encrypted old value, can be NULL
1019 * Success: STATUS_SUCCESS
1020 * Failure: NTSTATUS code.
1022 NTSTATUS WINAPI
LsaSetSecret(
1023 IN LSA_HANDLE SecretHandle
,
1024 IN PLSA_UNICODE_STRING EncryptedCurrentValue
,
1025 IN PLSA_UNICODE_STRING EncryptedOldValue
)
1027 FIXME("(%p,%p,%p) stub\n", SecretHandle
, EncryptedCurrentValue
,
1029 return STATUS_SUCCESS
;
1032 /******************************************************************************
1033 * LsaSetTrustedDomainInfoByName [ADVAPI32.@]
1036 NTSTATUS WINAPI
LsaSetTrustedDomainInfoByName(
1038 PLSA_UNICODE_STRING name
,
1039 TRUSTED_INFORMATION_CLASS
class,
1042 FIXME("(%p,%p,%d,%p) stub\n", policy
, name
, class, buffer
);
1043 return STATUS_SUCCESS
;
1046 /******************************************************************************
1047 * LsaSetTrustedDomainInformation [ADVAPI32.@]
1050 NTSTATUS WINAPI
LsaSetTrustedDomainInformation(
1053 TRUSTED_INFORMATION_CLASS
class,
1056 FIXME("(%p,%p,%d,%p) stub\n", policy
, sid
, class, buffer
);
1057 return STATUS_SUCCESS
;
1060 /******************************************************************************
1061 * LsaStorePrivateData [ADVAPI32.@]
1063 * Stores or deletes a Policy object's data under the specified reg key.
1066 * PolicyHandle [I] Handle to a Policy object.
1067 * KeyName [I] Name of the key where the data will be stored.
1068 * PrivateData [O] Pointer to the private data.
1071 * Success: STATUS_SUCCESS.
1072 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
1074 NTSTATUS WINAPI
LsaStorePrivateData(
1075 IN LSA_HANDLE PolicyHandle
,
1076 IN PLSA_UNICODE_STRING KeyName
,
1077 IN PLSA_UNICODE_STRING PrivateData
)
1079 FIXME("(%p,%p,%p) stub\n", PolicyHandle
, KeyName
, PrivateData
);
1080 return STATUS_OBJECT_NAME_NOT_FOUND
;
1083 /******************************************************************************
1084 * LsaUnregisterPolicyChangeNotification [ADVAPI32.@]
1087 NTSTATUS WINAPI
LsaUnregisterPolicyChangeNotification(
1088 POLICY_NOTIFICATION_INFORMATION_CLASS
class,
1091 FIXME("(%d,%p) stub\n", class, event
);
1092 return STATUS_SUCCESS
;
1095 /******************************************************************************
1096 * LsaLookupPrivilegeName [ADVAPI32.@]
1099 NTSTATUS WINAPI
LsaLookupPrivilegeName(LSA_HANDLE handle
, LUID
*luid
, LSA_UNICODE_STRING
**name
)
1101 const WCHAR
*privnameW
;
1105 TRACE("(%p,%p,%p)\n", handle
, luid
, name
);
1107 if (!luid
|| !handle
)
1108 return STATUS_INVALID_PARAMETER
;
1112 if (!(privnameW
= get_wellknown_privilege_name(luid
)))
1113 return STATUS_NO_SUCH_PRIVILEGE
;
1115 length
= lstrlenW(privnameW
);
1116 *name
= heap_alloc(sizeof(**name
) + (length
+ 1) * sizeof(WCHAR
));
1118 return STATUS_NO_MEMORY
;
1120 strW
= (WCHAR
*)(*name
+ 1);
1121 memcpy(strW
, privnameW
, length
* sizeof(WCHAR
));
1123 RtlInitUnicodeString(*name
, strW
);
1125 return STATUS_SUCCESS
;
1128 /******************************************************************************
1129 * LsaLookupPrivilegeDisplayName [ADVAPI32.@]
1132 NTSTATUS WINAPI
LsaLookupPrivilegeDisplayName(LSA_HANDLE handle
, LSA_UNICODE_STRING
*name
,
1133 LSA_UNICODE_STRING
**display_name
, SHORT
*language
)
1135 FIXME("(%p, %s, %p, %p)\n", handle
, debugstr_us(name
), display_name
, language
);
1137 return STATUS_NO_SUCH_PRIVILEGE
;
1140 /******************************************************************************
1141 * AuditQuerySystemPolicy [ADVAPI32.@]
1144 BOOLEAN WINAPI
AuditQuerySystemPolicy(const GUID
* guids
, ULONG count
, AUDIT_POLICY_INFORMATION
** policy
)
1147 FIXME("(%p, %d, %p)\n", guids
, count
, policy
);
1148 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);