rpcrt4: Store all active connections in RpcServerProtseq.
[wine.git] / dlls / advapi32 / lsa.c
blob3da6d19b82988e329042d8b1b977133d2114241f
1 /*
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
24 #include <stdarg.h>
26 #include "ntstatus.h"
27 #define WIN32_NO_STATUS
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "winternl.h"
32 #include "advapi32_misc.h"
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
39 #define ADVAPI_ForceLocalComputer(ServerName, FailureCode) \
40 if (!ADVAPI_IsLocalComputer(ServerName)) \
41 { \
42 FIXME("Action Implemented for local computer only. " \
43 "Requested for server %s\n", debugstr_w(ServerName)); \
44 return FailureCode; \
47 static void dumpLsaAttributes(const LSA_OBJECT_ATTRIBUTES *oa)
49 if (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)
61 HKEY key;
62 LONG ret;
63 BYTE* ptr = NULL;
64 UNICODE_STRING* ustr;
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)
75 DWORD size = 0;
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 = heap_alloc_zero(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 heap_free(ptr);
90 ptr = NULL;
92 else ustr->Length = size - sizeof(WCHAR);
94 RegCloseKey(key);
96 if (!ptr)
98 static const WCHAR wDomain[] = {'D','O','M','A','I','N','\0'};
99 ptr = heap_alloc_zero(sz + sizeof(wDomain));
100 if (!ptr) return NULL;
101 ustr = (UNICODE_STRING*)(ptr + ofs);
102 ustr->MaximumLength = sizeof(wDomain);
103 ustr->Buffer = (WCHAR*)(ptr + sz);
104 ustr->Length = sizeof(wDomain) - sizeof(WCHAR);
105 memcpy(ustr->Buffer, wDomain, sizeof(wDomain));
107 return ptr;
110 /******************************************************************************
111 * LsaAddAccountRights [ADVAPI32.@]
114 NTSTATUS WINAPI LsaAddAccountRights(
115 LSA_HANDLE policy,
116 PSID sid,
117 PLSA_UNICODE_STRING rights,
118 ULONG count)
120 FIXME("(%p,%p,%p,0x%08x) stub\n", policy, sid, rights, count);
121 return STATUS_SUCCESS;
124 /******************************************************************************
125 * LsaClose [ADVAPI32.@]
127 * Closes a handle to a Policy or TrustedDomain.
129 * PARAMS
130 * ObjectHandle [I] Handle to a Policy or TrustedDomain.
132 * RETURNS
133 * Success: STATUS_SUCCESS.
134 * Failure: NTSTATUS code.
136 NTSTATUS WINAPI LsaClose(IN LSA_HANDLE ObjectHandle)
138 FIXME("(%p) stub\n", ObjectHandle);
139 return STATUS_SUCCESS;
142 /******************************************************************************
143 * LsaCreateTrustedDomainEx [ADVAPI32.@]
146 NTSTATUS WINAPI LsaCreateTrustedDomainEx(
147 LSA_HANDLE policy,
148 PTRUSTED_DOMAIN_INFORMATION_EX domain_info,
149 PTRUSTED_DOMAIN_AUTH_INFORMATION auth_info,
150 ACCESS_MASK access,
151 PLSA_HANDLE domain)
153 FIXME("(%p,%p,%p,0x%08x,%p) stub\n", policy, domain_info, auth_info,
154 access, domain);
155 return STATUS_SUCCESS;
158 /******************************************************************************
159 * LsaDeleteTrustedDomain [ADVAPI32.@]
162 NTSTATUS WINAPI LsaDeleteTrustedDomain(LSA_HANDLE policy, PSID sid)
164 FIXME("(%p,%p) stub\n", policy, sid);
165 return STATUS_SUCCESS;
168 /******************************************************************************
169 * LsaEnumerateAccountRights [ADVAPI32.@]
172 NTSTATUS WINAPI LsaEnumerateAccountRights(
173 LSA_HANDLE policy,
174 PSID sid,
175 PLSA_UNICODE_STRING *rights,
176 PULONG count)
178 FIXME("(%p,%p,%p,%p) stub\n", policy, sid, rights, count);
179 *rights = 0;
180 *count = 0;
181 return STATUS_OBJECT_NAME_NOT_FOUND;
184 /******************************************************************************
185 * LsaEnumerateAccountsWithUserRight [ADVAPI32.@]
188 NTSTATUS WINAPI LsaEnumerateAccountsWithUserRight(
189 LSA_HANDLE policy,
190 PLSA_UNICODE_STRING rights,
191 PVOID *buffer,
192 PULONG count)
194 FIXME("(%p,%p,%p,%p) stub\n", policy, rights, buffer, count);
195 return STATUS_NO_MORE_ENTRIES;
198 /******************************************************************************
199 * LsaEnumerateTrustedDomains [ADVAPI32.@]
201 * Returns the names and SIDs of trusted domains.
203 * PARAMS
204 * PolicyHandle [I] Handle to a Policy object.
205 * EnumerationContext [I] Pointer to an enumeration handle.
206 * Buffer [O] Contains the names and SIDs of trusted domains.
207 * PreferredMaximumLength[I] Preferred maximum size in bytes of Buffer.
208 * CountReturned [O] Number of elements in Buffer.
210 * RETURNS
211 * Success: STATUS_SUCCESS,
212 * STATUS_MORE_ENTRIES,
213 * STATUS_NO_MORE_ENTRIES
214 * Failure: NTSTATUS code.
216 * NOTES
217 * LsaEnumerateTrustedDomains can be called multiple times to enumerate
218 * all trusted domains.
220 NTSTATUS WINAPI LsaEnumerateTrustedDomains(
221 IN LSA_HANDLE PolicyHandle,
222 IN PLSA_ENUMERATION_HANDLE EnumerationContext,
223 OUT PVOID* Buffer,
224 IN ULONG PreferredMaximumLength,
225 OUT PULONG CountReturned)
227 FIXME("(%p,%p,%p,0x%08x,%p) stub\n", PolicyHandle, EnumerationContext,
228 Buffer, PreferredMaximumLength, CountReturned);
230 if (CountReturned) *CountReturned = 0;
231 return STATUS_SUCCESS;
234 /******************************************************************************
235 * LsaEnumerateTrustedDomainsEx [ADVAPI32.@]
238 NTSTATUS WINAPI LsaEnumerateTrustedDomainsEx(
239 LSA_HANDLE policy,
240 PLSA_ENUMERATION_HANDLE context,
241 PVOID *buffer,
242 ULONG length,
243 PULONG count)
245 FIXME("(%p,%p,%p,0x%08x,%p) stub\n", policy, context, buffer, length, count);
247 if (count) *count = 0;
248 return STATUS_SUCCESS;
251 /******************************************************************************
252 * LsaFreeMemory [ADVAPI32.@]
254 * Frees memory allocated by a LSA function.
256 * PARAMS
257 * Buffer [I] Memory buffer to free.
259 * RETURNS
260 * Success: STATUS_SUCCESS.
261 * Failure: NTSTATUS code.
263 NTSTATUS WINAPI LsaFreeMemory(IN PVOID Buffer)
265 TRACE("(%p)\n", Buffer);
267 heap_free(Buffer);
268 return STATUS_SUCCESS;
271 /******************************************************************************
272 * LsaLookupNames [ADVAPI32.@]
274 * Returns the SIDs of an array of user, group, or local group names.
276 * PARAMS
277 * PolicyHandle [I] Handle to a Policy object.
278 * Count [I] Number of names in Names.
279 * Names [I] Array of names to lookup.
280 * ReferencedDomains [O] Array of domains where the names were found.
281 * Sids [O] Array of SIDs corresponding to Names.
283 * RETURNS
284 * Success: STATUS_SUCCESS,
285 * STATUS_SOME_NOT_MAPPED
286 * Failure: STATUS_NONE_MAPPED or NTSTATUS code.
288 NTSTATUS WINAPI LsaLookupNames(
289 IN LSA_HANDLE PolicyHandle,
290 IN ULONG Count,
291 IN PLSA_UNICODE_STRING Names,
292 OUT PLSA_REFERENCED_DOMAIN_LIST* ReferencedDomains,
293 OUT PLSA_TRANSLATED_SID* Sids)
295 FIXME("(%p,0x%08x,%p,%p,%p) stub\n", PolicyHandle, Count, Names,
296 ReferencedDomains, Sids);
298 return STATUS_NONE_MAPPED;
301 static BOOL lookup_name( LSA_UNICODE_STRING *name, SID *sid, DWORD *sid_size, WCHAR *domain,
302 DWORD *domain_size, SID_NAME_USE *use, BOOL *handled )
304 BOOL ret;
306 ret = lookup_local_wellknown_name( name, sid, sid_size, domain, domain_size, use, handled );
307 if (!*handled)
308 ret = lookup_local_user_name( name, sid, sid_size, domain, domain_size, use, handled );
310 return ret;
313 /* Adds domain info to referenced domain list.
314 Domain list is stored as plain buffer, layout is:
316 LSA_REFERENCED_DOMAIN_LIST,
317 LSA_TRUST_INFORMATION array,
318 domain data array of
320 domain name data (WCHAR buffer),
321 SID data
324 Parameters:
325 list [I] referenced list pointer
326 domain [I] domain name string
327 data [IO] pointer to domain data array
329 static LONG lsa_reflist_add_domain(LSA_REFERENCED_DOMAIN_LIST *list, LSA_UNICODE_STRING *domain, char **data)
331 ULONG sid_size = 0,domain_size = 0;
332 BOOL handled = FALSE;
333 SID_NAME_USE use;
334 LONG i;
336 for (i = 0; i < list->Entries; i++)
338 /* try to reuse index */
339 if ((list->Domains[i].Name.Length == domain->Length) &&
340 (!strncmpiW(list->Domains[i].Name.Buffer, domain->Buffer, (domain->Length / sizeof(WCHAR)))))
342 return i;
346 /* no matching domain found, store name */
347 list->Domains[list->Entries].Name.Length = domain->Length;
348 list->Domains[list->Entries].Name.MaximumLength = domain->MaximumLength;
349 list->Domains[list->Entries].Name.Buffer = (WCHAR*)*data;
350 memcpy(list->Domains[list->Entries].Name.Buffer, domain->Buffer, domain->MaximumLength);
351 *data += domain->MaximumLength;
353 /* get and store SID data */
354 list->Domains[list->Entries].Sid = *data;
355 lookup_name(domain, NULL, &sid_size, NULL, &domain_size, &use, &handled);
356 domain_size = 0;
357 lookup_name(domain, list->Domains[list->Entries].Sid, &sid_size, NULL, &domain_size, &use, &handled);
358 *data += sid_size;
360 return list->Entries++;
363 /******************************************************************************
364 * LsaLookupNames2 [ADVAPI32.@]
367 NTSTATUS WINAPI LsaLookupNames2( LSA_HANDLE policy, ULONG flags, ULONG count,
368 PLSA_UNICODE_STRING names, PLSA_REFERENCED_DOMAIN_LIST *domains,
369 PLSA_TRANSLATED_SID2 *sids )
371 ULONG i, sid_size_total = 0, domain_size_max = 0, size, domainname_size_total = 0;
372 ULONG sid_size, domain_size, mapped;
373 LSA_UNICODE_STRING domain;
374 BOOL handled = FALSE;
375 char *domain_data;
376 SID_NAME_USE use;
377 SID *sid;
379 TRACE("(%p,0x%08x,0x%08x,%p,%p,%p)\n", policy, flags, count, names, domains, sids);
381 mapped = 0;
382 for (i = 0; i < count; i++)
384 handled = FALSE;
385 sid_size = domain_size = 0;
386 lookup_name( &names[i], NULL, &sid_size, NULL, &domain_size, &use, &handled );
387 if (handled)
389 sid_size_total += sid_size;
390 domainname_size_total += domain_size;
391 if (domain_size)
393 if (domain_size > domain_size_max)
394 domain_size_max = domain_size;
396 mapped++;
399 TRACE("mapped %u out of %u\n", mapped, count);
401 size = sizeof(LSA_TRANSLATED_SID2) * count + sid_size_total;
402 if (!(*sids = heap_alloc(size))) return STATUS_NO_MEMORY;
404 sid = (SID *)(*sids + count);
406 /* use maximum domain count */
407 if (!(*domains = heap_alloc(sizeof(LSA_REFERENCED_DOMAIN_LIST) + sizeof(LSA_TRUST_INFORMATION)*count +
408 sid_size_total + domainname_size_total*sizeof(WCHAR))))
410 heap_free(*sids);
411 return STATUS_NO_MEMORY;
413 (*domains)->Entries = 0;
414 (*domains)->Domains = (LSA_TRUST_INFORMATION*)((char*)*domains + sizeof(LSA_REFERENCED_DOMAIN_LIST));
415 domain_data = (char*)(*domains)->Domains + sizeof(LSA_TRUST_INFORMATION)*count;
417 domain.Buffer = heap_alloc(domain_size_max*sizeof(WCHAR));
418 for (i = 0; i < count; i++)
420 domain.Length = domain_size_max*sizeof(WCHAR);
421 domain.MaximumLength = domain_size_max*sizeof(WCHAR);
423 (*sids)[i].Use = SidTypeUnknown;
424 (*sids)[i].DomainIndex = -1;
425 (*sids)[i].Flags = 0;
427 handled = FALSE;
428 sid_size = sid_size_total;
429 domain_size = domain_size_max;
430 lookup_name( &names[i], sid, &sid_size, domain.Buffer, &domain_size, &use, &handled );
431 if (handled)
433 (*sids)[i].Sid = sid;
434 (*sids)[i].Use = use;
436 sid = (SID *)((char *)sid + sid_size);
437 sid_size_total -= sid_size;
438 if (domain_size)
440 domain.Length = domain_size * sizeof(WCHAR);
441 domain.MaximumLength = (domain_size + 1) * sizeof(WCHAR);
442 (*sids)[i].DomainIndex = lsa_reflist_add_domain(*domains, &domain, &domain_data);
446 heap_free(domain.Buffer);
448 if (mapped == count) return STATUS_SUCCESS;
449 if (mapped > 0 && mapped < count) return STATUS_SOME_NOT_MAPPED;
450 return STATUS_NONE_MAPPED;
453 /******************************************************************************
454 * LsaLookupSids [ADVAPI32.@]
456 * Looks up the names that correspond to an array of SIDs.
458 * PARAMS
459 * PolicyHandle [I] Handle to a Policy object.
460 * Count [I] Number of SIDs in the Sids array.
461 * Sids [I] Array of SIDs to lookup.
462 * ReferencedDomains [O] Array of domains where the sids were found.
463 * Names [O] Array of names corresponding to Sids.
465 * RETURNS
466 * Success: STATUS_SUCCESS,
467 * STATUS_SOME_NOT_MAPPED
468 * Failure: STATUS_NONE_MAPPED or NTSTATUS code.
470 NTSTATUS WINAPI LsaLookupSids(
471 LSA_HANDLE PolicyHandle,
472 ULONG Count,
473 PSID *Sids,
474 LSA_REFERENCED_DOMAIN_LIST **ReferencedDomains,
475 LSA_TRANSLATED_NAME **Names)
477 ULONG i, mapped, name_fullsize, domain_fullsize;
478 ULONG name_size, domain_size;
479 LSA_UNICODE_STRING domain;
480 WCHAR *name_buffer;
481 char *domain_data;
482 SID_NAME_USE use;
484 TRACE("(%p, %u, %p, %p, %p)\n", PolicyHandle, Count, Sids, ReferencedDomains, Names);
486 /* this length does not include actual string length yet */
487 name_fullsize = sizeof(LSA_TRANSLATED_NAME) * Count;
488 if (!(*Names = heap_alloc(name_fullsize))) return STATUS_NO_MEMORY;
489 /* maximum count of stored domain infos is Count, allocate it like that cause really needed
490 count could only be computed after sid data is retrieved */
491 domain_fullsize = sizeof(LSA_REFERENCED_DOMAIN_LIST) + sizeof(LSA_TRUST_INFORMATION)*Count;
492 if (!(*ReferencedDomains = heap_alloc(domain_fullsize)))
494 heap_free(*Names);
495 return STATUS_NO_MEMORY;
497 (*ReferencedDomains)->Entries = 0;
498 (*ReferencedDomains)->Domains = (LSA_TRUST_INFORMATION*)((char*)*ReferencedDomains + sizeof(LSA_REFERENCED_DOMAIN_LIST));
500 /* Get full names data length and full length needed to store domain name and SID */
501 for (i = 0; i < Count; i++)
503 (*Names)[i].Use = SidTypeUnknown;
504 (*Names)[i].DomainIndex = -1;
505 (*Names)[i].Name.Buffer = NULL;
507 memset(&(*ReferencedDomains)->Domains[i], 0, sizeof(LSA_TRUST_INFORMATION));
509 name_size = domain_size = 0;
510 if (!LookupAccountSidW(NULL, Sids[i], NULL, &name_size, NULL, &domain_size, &use) &&
511 GetLastError() == ERROR_INSUFFICIENT_BUFFER)
513 if (name_size)
515 (*Names)[i].Name.Length = (name_size - 1) * sizeof(WCHAR);
516 (*Names)[i].Name.MaximumLength = name_size * sizeof(WCHAR);
518 else
520 (*Names)[i].Name.Length = 0;
521 (*Names)[i].Name.MaximumLength = sizeof(WCHAR);
524 name_fullsize += (*Names)[i].Name.MaximumLength;
526 /* This potentially allocates more than needed, cause different names will reuse same domain index.
527 Also it's not possible to store domain name length right here for the same reason. */
528 if (domain_size)
530 ULONG sid_size = 0;
531 BOOL handled = FALSE;
532 WCHAR *name;
534 domain_fullsize += domain_size * sizeof(WCHAR);
536 /* get domain SID size too */
537 name = heap_alloc(domain_size * sizeof(WCHAR));
538 *name = 0;
539 LookupAccountSidW(NULL, Sids[i], NULL, &name_size, name, &domain_size, &use);
541 domain.Buffer = name;
542 domain.Length = domain_size * sizeof(WCHAR);
543 domain.MaximumLength = domain_size * sizeof(WCHAR);
545 lookup_name(&domain, NULL, &sid_size, NULL, &domain_size, &use, &handled);
546 domain_fullsize += sid_size;
548 heap_free(name);
550 else
552 /* If we don't have a domain name, use a zero-length entry rather than a null value. */
553 domain_fullsize += sizeof(WCHAR);
554 domain.Length = 0;
555 domain.MaximumLength = sizeof(WCHAR);
560 /* now we have full length needed for both */
561 *Names = heap_realloc(*Names, name_fullsize);
562 name_buffer = (WCHAR*)((char*)*Names + sizeof(LSA_TRANSLATED_NAME)*Count);
564 *ReferencedDomains = heap_realloc(*ReferencedDomains, domain_fullsize);
565 /* fix pointer after reallocation */
566 (*ReferencedDomains)->Domains = (LSA_TRUST_INFORMATION*)((char*)*ReferencedDomains + sizeof(LSA_REFERENCED_DOMAIN_LIST));
567 domain_data = (char*)(*ReferencedDomains)->Domains + sizeof(LSA_TRUST_INFORMATION)*Count;
569 mapped = 0;
570 for (i = 0; i < Count; i++)
572 name_size = domain_size = 0;
574 if (!LookupAccountSidW(NULL, Sids[i], NULL, &name_size, NULL, &domain_size, &use) &&
575 GetLastError() == ERROR_INSUFFICIENT_BUFFER)
577 mapped++;
579 if (domain_size)
581 domain.Length = (domain_size - 1) * sizeof(WCHAR);
582 domain.MaximumLength = domain_size * sizeof(WCHAR);
584 else
586 /* Use a zero-length buffer */
587 domain.Length = 0;
588 domain.MaximumLength = sizeof(WCHAR);
591 domain.Buffer = heap_alloc(domain.MaximumLength);
593 (*Names)[i].Name.Buffer = name_buffer;
594 LookupAccountSidW(NULL, Sids[i], (*Names)[i].Name.Buffer, &name_size, domain.Buffer, &domain_size, &use);
595 (*Names)[i].Use = use;
597 (*Names)[i].DomainIndex = lsa_reflist_add_domain(*ReferencedDomains, &domain, &domain_data);
598 heap_free(domain.Buffer);
601 name_buffer += name_size;
603 TRACE("mapped %u out of %u\n", mapped, Count);
605 if (mapped == Count) return STATUS_SUCCESS;
606 if (mapped) return STATUS_SOME_NOT_MAPPED;
607 return STATUS_NONE_MAPPED;
610 /******************************************************************************
611 * LsaNtStatusToWinError [ADVAPI32.@]
613 * Converts an LSA NTSTATUS code to a Windows error code.
615 * PARAMS
616 * Status [I] NTSTATUS code.
618 * RETURNS
619 * Success: Corresponding Windows error code.
620 * Failure: ERROR_MR_MID_NOT_FOUND.
622 ULONG WINAPI LsaNtStatusToWinError(NTSTATUS Status)
624 return RtlNtStatusToDosError(Status);
627 /******************************************************************************
628 * LsaOpenPolicy [ADVAPI32.@]
630 * Opens a handle to the Policy object on a local or remote system.
632 * PARAMS
633 * SystemName [I] Name of the target system.
634 * ObjectAttributes [I] Connection attributes.
635 * DesiredAccess [I] Requested access rights.
636 * PolicyHandle [I/O] Handle to the Policy object.
638 * RETURNS
639 * Success: STATUS_SUCCESS.
640 * Failure: NTSTATUS code.
642 * NOTES
643 * Set SystemName to NULL to open the local Policy object.
645 NTSTATUS WINAPI LsaOpenPolicy(
646 IN PLSA_UNICODE_STRING SystemName,
647 IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes,
648 IN ACCESS_MASK DesiredAccess,
649 IN OUT PLSA_HANDLE PolicyHandle)
651 FIXME("(%s,%p,0x%08x,%p) stub\n",
652 SystemName?debugstr_w(SystemName->Buffer):"(null)",
653 ObjectAttributes, DesiredAccess, PolicyHandle);
655 ADVAPI_ForceLocalComputer(SystemName ? SystemName->Buffer : NULL,
656 STATUS_ACCESS_VIOLATION);
657 dumpLsaAttributes(ObjectAttributes);
659 if(PolicyHandle) *PolicyHandle = (LSA_HANDLE)0xcafe;
660 return STATUS_SUCCESS;
663 /******************************************************************************
664 * LsaOpenTrustedDomainByName [ADVAPI32.@]
667 NTSTATUS WINAPI LsaOpenTrustedDomainByName(
668 LSA_HANDLE policy,
669 PLSA_UNICODE_STRING name,
670 ACCESS_MASK access,
671 PLSA_HANDLE handle)
673 FIXME("(%p,%p,0x%08x,%p) stub\n", policy, name, access, handle);
674 return STATUS_OBJECT_NAME_NOT_FOUND;
677 /******************************************************************************
678 * LsaQueryInformationPolicy [ADVAPI32.@]
680 * Returns information about a Policy object.
682 * PARAMS
683 * PolicyHandle [I] Handle to a Policy object.
684 * InformationClass [I] Type of information to retrieve.
685 * Buffer [O] Pointer to the requested information.
687 * RETURNS
688 * Success: STATUS_SUCCESS.
689 * Failure: NTSTATUS code.
691 NTSTATUS WINAPI LsaQueryInformationPolicy(
692 IN LSA_HANDLE PolicyHandle,
693 IN POLICY_INFORMATION_CLASS InformationClass,
694 OUT PVOID *Buffer)
696 TRACE("(%p,0x%08x,%p)\n", PolicyHandle, InformationClass, Buffer);
698 if(!Buffer) return STATUS_INVALID_PARAMETER;
699 switch (InformationClass)
701 case PolicyAuditEventsInformation: /* 2 */
703 PPOLICY_AUDIT_EVENTS_INFO p = heap_alloc_zero(sizeof(POLICY_AUDIT_EVENTS_INFO));
704 p->AuditingMode = FALSE; /* no auditing */
705 *Buffer = p;
707 break;
708 case PolicyPrimaryDomainInformation: /* 3 */
710 /* Only the domain name is valid for the local computer.
711 * All other fields are zero.
713 PPOLICY_PRIMARY_DOMAIN_INFO pinfo;
715 pinfo = ADVAPI_GetDomainName(sizeof(*pinfo), offsetof(POLICY_PRIMARY_DOMAIN_INFO, Name));
717 TRACE("setting domain to %s\n", debugstr_w(pinfo->Name.Buffer));
719 *Buffer = pinfo;
721 break;
722 case PolicyAccountDomainInformation: /* 5 */
724 struct di
726 POLICY_ACCOUNT_DOMAIN_INFO info;
727 SID sid;
728 DWORD padding[3];
729 WCHAR domain[MAX_COMPUTERNAME_LENGTH + 1];
732 DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
733 struct di * xdi = heap_alloc_zero(sizeof(*xdi));
735 xdi->info.DomainName.MaximumLength = dwSize * sizeof(WCHAR);
736 xdi->info.DomainName.Buffer = xdi->domain;
737 if (GetComputerNameW(xdi->info.DomainName.Buffer, &dwSize))
738 xdi->info.DomainName.Length = dwSize * sizeof(WCHAR);
740 TRACE("setting name to %s\n", debugstr_w(xdi->info.DomainName.Buffer));
742 xdi->info.DomainSid = &xdi->sid;
744 if (!ADVAPI_GetComputerSid(&xdi->sid))
746 heap_free(xdi);
748 WARN("Computer SID not found\n");
750 return STATUS_UNSUCCESSFUL;
753 TRACE("setting SID to %s\n", debugstr_sid(&xdi->sid));
755 *Buffer = xdi;
757 break;
758 case PolicyDnsDomainInformation: /* 12 (0xc) */
760 /* Only the domain name is valid for the local computer.
761 * All other fields are zero.
763 PPOLICY_DNS_DOMAIN_INFO pinfo;
765 pinfo = ADVAPI_GetDomainName(sizeof(*pinfo), offsetof(POLICY_DNS_DOMAIN_INFO, Name));
767 TRACE("setting domain to %s\n", debugstr_w(pinfo->Name.Buffer));
769 *Buffer = pinfo;
771 break;
772 case PolicyAuditLogInformation:
773 case PolicyPdAccountInformation:
774 case PolicyLsaServerRoleInformation:
775 case PolicyReplicaSourceInformation:
776 case PolicyDefaultQuotaInformation:
777 case PolicyModificationInformation:
778 case PolicyAuditFullSetInformation:
779 case PolicyAuditFullQueryInformation:
781 FIXME("category %d not implemented\n", InformationClass);
782 return STATUS_UNSUCCESSFUL;
785 return STATUS_SUCCESS;
788 /******************************************************************************
789 * LsaQueryTrustedDomainInfo [ADVAPI32.@]
792 NTSTATUS WINAPI LsaQueryTrustedDomainInfo(
793 LSA_HANDLE policy,
794 PSID sid,
795 TRUSTED_INFORMATION_CLASS class,
796 PVOID *buffer)
798 FIXME("(%p,%p,%d,%p) stub\n", policy, sid, class, buffer);
799 return STATUS_OBJECT_NAME_NOT_FOUND;
802 /******************************************************************************
803 * LsaQueryTrustedDomainInfoByName [ADVAPI32.@]
806 NTSTATUS WINAPI LsaQueryTrustedDomainInfoByName(
807 LSA_HANDLE policy,
808 PLSA_UNICODE_STRING name,
809 TRUSTED_INFORMATION_CLASS class,
810 PVOID *buffer)
812 FIXME("(%p,%p,%d,%p) stub\n", policy, name, class, buffer);
813 return STATUS_OBJECT_NAME_NOT_FOUND;
816 /******************************************************************************
817 * LsaRegisterPolicyChangeNotification [ADVAPI32.@]
820 NTSTATUS WINAPI LsaRegisterPolicyChangeNotification(
821 POLICY_NOTIFICATION_INFORMATION_CLASS class,
822 HANDLE event)
824 FIXME("(%d,%p) stub\n", class, event);
825 return STATUS_UNSUCCESSFUL;
828 /******************************************************************************
829 * LsaRemoveAccountRights [ADVAPI32.@]
832 NTSTATUS WINAPI LsaRemoveAccountRights(
833 LSA_HANDLE policy,
834 PSID sid,
835 BOOLEAN all,
836 PLSA_UNICODE_STRING rights,
837 ULONG count)
839 FIXME("(%p,%p,%d,%p,0x%08x) stub\n", policy, sid, all, rights, count);
840 return STATUS_SUCCESS;
843 /******************************************************************************
844 * LsaRetrievePrivateData [ADVAPI32.@]
846 * Retrieves data stored by LsaStorePrivateData.
848 * PARAMS
849 * PolicyHandle [I] Handle to a Policy object.
850 * KeyName [I] Name of the key where the data is stored.
851 * PrivateData [O] Pointer to the private data.
853 * RETURNS
854 * Success: STATUS_SUCCESS.
855 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
857 NTSTATUS WINAPI LsaRetrievePrivateData(
858 IN LSA_HANDLE PolicyHandle,
859 IN PLSA_UNICODE_STRING KeyName,
860 OUT PLSA_UNICODE_STRING* PrivateData)
862 FIXME("(%p,%p,%p) stub\n", PolicyHandle, KeyName, PrivateData);
863 return STATUS_OBJECT_NAME_NOT_FOUND;
866 /******************************************************************************
867 * LsaSetInformationPolicy [ADVAPI32.@]
869 * Modifies information in a Policy object.
871 * PARAMS
872 * PolicyHandle [I] Handle to a Policy object.
873 * InformationClass [I] Type of information to set.
874 * Buffer [I] Pointer to the information to set.
876 * RETURNS
877 * Success: STATUS_SUCCESS.
878 * Failure: NTSTATUS code.
880 NTSTATUS WINAPI LsaSetInformationPolicy(
881 IN LSA_HANDLE PolicyHandle,
882 IN POLICY_INFORMATION_CLASS InformationClass,
883 IN PVOID Buffer)
885 FIXME("(%p,0x%08x,%p) stub\n", PolicyHandle, InformationClass, Buffer);
887 return STATUS_UNSUCCESSFUL;
890 /******************************************************************************
891 * LsaSetSecret [ADVAPI32.@]
893 * Set old and new values on a secret handle
895 * PARAMS
896 * SecretHandle [I] Handle to a secret object.
897 * EncryptedCurrentValue [I] Pointer to encrypted new value, can be NULL
898 * EncryptedOldValue [I] Pointer to encrypted old value, can be NULL
900 * RETURNS
901 * Success: STATUS_SUCCESS
902 * Failure: NTSTATUS code.
904 NTSTATUS WINAPI LsaSetSecret(
905 IN LSA_HANDLE SecretHandle,
906 IN PLSA_UNICODE_STRING EncryptedCurrentValue,
907 IN PLSA_UNICODE_STRING EncryptedOldValue)
909 FIXME("(%p,%p,%p) stub\n", SecretHandle, EncryptedCurrentValue,
910 EncryptedOldValue);
911 return STATUS_SUCCESS;
914 /******************************************************************************
915 * LsaSetTrustedDomainInfoByName [ADVAPI32.@]
918 NTSTATUS WINAPI LsaSetTrustedDomainInfoByName(
919 LSA_HANDLE policy,
920 PLSA_UNICODE_STRING name,
921 TRUSTED_INFORMATION_CLASS class,
922 PVOID buffer)
924 FIXME("(%p,%p,%d,%p) stub\n", policy, name, class, buffer);
925 return STATUS_SUCCESS;
928 /******************************************************************************
929 * LsaSetTrustedDomainInformation [ADVAPI32.@]
932 NTSTATUS WINAPI LsaSetTrustedDomainInformation(
933 LSA_HANDLE policy,
934 PSID sid,
935 TRUSTED_INFORMATION_CLASS class,
936 PVOID buffer)
938 FIXME("(%p,%p,%d,%p) stub\n", policy, sid, class, buffer);
939 return STATUS_SUCCESS;
942 /******************************************************************************
943 * LsaStorePrivateData [ADVAPI32.@]
945 * Stores or deletes a Policy object's data under the specified reg key.
947 * PARAMS
948 * PolicyHandle [I] Handle to a Policy object.
949 * KeyName [I] Name of the key where the data will be stored.
950 * PrivateData [O] Pointer to the private data.
952 * RETURNS
953 * Success: STATUS_SUCCESS.
954 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
956 NTSTATUS WINAPI LsaStorePrivateData(
957 IN LSA_HANDLE PolicyHandle,
958 IN PLSA_UNICODE_STRING KeyName,
959 IN PLSA_UNICODE_STRING PrivateData)
961 FIXME("(%p,%p,%p) stub\n", PolicyHandle, KeyName, PrivateData);
962 return STATUS_OBJECT_NAME_NOT_FOUND;
965 /******************************************************************************
966 * LsaUnregisterPolicyChangeNotification [ADVAPI32.@]
969 NTSTATUS WINAPI LsaUnregisterPolicyChangeNotification(
970 POLICY_NOTIFICATION_INFORMATION_CLASS class,
971 HANDLE event)
973 FIXME("(%d,%p) stub\n", class, event);
974 return STATUS_SUCCESS;