advapi32: Return correct short domain name.
[wine.git] / dlls / advapi32 / lsa.c
blobca357688fc24956bf40a7ec1287c9f7e90ed01ac
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 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)
55 if (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)
67 HKEY key;
68 LONG ret;
69 BYTE* ptr = NULL;
70 UNICODE_STRING* ustr;
72 static const WCHAR wVNETSUP[] = {
73 'S','y','s','t','e','m','\\',
74 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
75 'S','e','r','v','i','c','e','s','\\',
76 'V','x','D','\\','V','N','E','T','S','U','P','\0'};
78 ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wVNETSUP, 0, KEY_READ, &key);
79 if (ret == ERROR_SUCCESS)
81 DWORD size = 0;
82 static const WCHAR wg[] = { 'W','o','r','k','g','r','o','u','p',0 };
84 ret = RegQueryValueExW(key, wg, NULL, NULL, NULL, &size);
85 if (ret == ERROR_MORE_DATA || ret == ERROR_SUCCESS)
87 ptr = heap_alloc_zero(sz + size);
88 if (!ptr) return NULL;
89 ustr = (UNICODE_STRING*)(ptr + ofs);
90 ustr->MaximumLength = size;
91 ustr->Buffer = (WCHAR*)(ptr + sz);
92 ret = RegQueryValueExW(key, wg, NULL, NULL, (LPBYTE)ustr->Buffer, &size);
93 if (ret != ERROR_SUCCESS)
95 heap_free(ptr);
96 ptr = NULL;
98 else ustr->Length = size - sizeof(WCHAR);
100 RegCloseKey(key);
102 if (!ptr)
104 static const WCHAR wDomain[] = {'D','O','M','A','I','N','\0'};
105 ptr = heap_alloc_zero(sz + sizeof(wDomain));
106 if (!ptr) return NULL;
107 ustr = (UNICODE_STRING*)(ptr + ofs);
108 ustr->MaximumLength = sizeof(wDomain);
109 ustr->Buffer = (WCHAR*)(ptr + sz);
110 ustr->Length = sizeof(wDomain) - sizeof(WCHAR);
111 memcpy(ustr->Buffer, wDomain, sizeof(wDomain));
113 return ptr;
116 /******************************************************************************
117 * LsaAddAccountRights [ADVAPI32.@]
120 NTSTATUS WINAPI LsaAddAccountRights(
121 LSA_HANDLE policy,
122 PSID sid,
123 PLSA_UNICODE_STRING rights,
124 ULONG count)
126 FIXME("(%p,%p,%p,0x%08x) stub\n", policy, sid, rights, count);
127 return STATUS_SUCCESS;
130 /******************************************************************************
131 * LsaClose [ADVAPI32.@]
133 * Closes a handle to a Policy or TrustedDomain.
135 * PARAMS
136 * ObjectHandle [I] Handle to a Policy or TrustedDomain.
138 * RETURNS
139 * Success: STATUS_SUCCESS.
140 * Failure: NTSTATUS code.
142 NTSTATUS WINAPI LsaClose(IN LSA_HANDLE ObjectHandle)
144 FIXME("(%p) stub\n", ObjectHandle);
145 return STATUS_SUCCESS;
148 /******************************************************************************
149 * LsaCreateTrustedDomainEx [ADVAPI32.@]
152 NTSTATUS WINAPI LsaCreateTrustedDomainEx(
153 LSA_HANDLE policy,
154 PTRUSTED_DOMAIN_INFORMATION_EX domain_info,
155 PTRUSTED_DOMAIN_AUTH_INFORMATION auth_info,
156 ACCESS_MASK access,
157 PLSA_HANDLE domain)
159 FIXME("(%p,%p,%p,0x%08x,%p) stub\n", policy, domain_info, auth_info,
160 access, domain);
161 return STATUS_SUCCESS;
164 /******************************************************************************
165 * LsaDeleteTrustedDomain [ADVAPI32.@]
168 NTSTATUS WINAPI LsaDeleteTrustedDomain(LSA_HANDLE policy, PSID sid)
170 FIXME("(%p,%p) stub\n", policy, sid);
171 return STATUS_SUCCESS;
174 /******************************************************************************
175 * LsaEnumerateAccountRights [ADVAPI32.@]
178 NTSTATUS WINAPI LsaEnumerateAccountRights(
179 LSA_HANDLE policy,
180 PSID sid,
181 PLSA_UNICODE_STRING *rights,
182 PULONG count)
184 FIXME("(%p,%p,%p,%p) stub\n", policy, sid, rights, count);
185 *rights = 0;
186 *count = 0;
187 return STATUS_OBJECT_NAME_NOT_FOUND;
190 /******************************************************************************
191 * LsaEnumerateAccountsWithUserRight [ADVAPI32.@]
194 NTSTATUS WINAPI LsaEnumerateAccountsWithUserRight(
195 LSA_HANDLE policy,
196 PLSA_UNICODE_STRING rights,
197 PVOID *buffer,
198 PULONG count)
200 FIXME("(%p,%p,%p,%p) stub\n", policy, rights, buffer, count);
201 return STATUS_NO_MORE_ENTRIES;
204 /******************************************************************************
205 * LsaEnumerateTrustedDomains [ADVAPI32.@]
207 * Returns the names and SIDs of trusted domains.
209 * PARAMS
210 * PolicyHandle [I] Handle to a Policy object.
211 * EnumerationContext [I] Pointer to an enumeration handle.
212 * Buffer [O] Contains the names and SIDs of trusted domains.
213 * PreferredMaximumLength[I] Preferred maximum size in bytes of Buffer.
214 * CountReturned [O] Number of elements in Buffer.
216 * RETURNS
217 * Success: STATUS_SUCCESS,
218 * STATUS_MORE_ENTRIES,
219 * STATUS_NO_MORE_ENTRIES
220 * Failure: NTSTATUS code.
222 * NOTES
223 * LsaEnumerateTrustedDomains can be called multiple times to enumerate
224 * all trusted domains.
226 NTSTATUS WINAPI LsaEnumerateTrustedDomains(
227 IN LSA_HANDLE PolicyHandle,
228 IN PLSA_ENUMERATION_HANDLE EnumerationContext,
229 OUT PVOID* Buffer,
230 IN ULONG PreferredMaximumLength,
231 OUT PULONG CountReturned)
233 FIXME("(%p,%p,%p,0x%08x,%p) stub\n", PolicyHandle, EnumerationContext,
234 Buffer, PreferredMaximumLength, CountReturned);
236 if (CountReturned) *CountReturned = 0;
237 return STATUS_SUCCESS;
240 /******************************************************************************
241 * LsaEnumerateTrustedDomainsEx [ADVAPI32.@]
244 NTSTATUS WINAPI LsaEnumerateTrustedDomainsEx(
245 LSA_HANDLE policy,
246 PLSA_ENUMERATION_HANDLE context,
247 PVOID *buffer,
248 ULONG length,
249 PULONG count)
251 FIXME("(%p,%p,%p,0x%08x,%p) stub\n", policy, context, buffer, length, count);
253 if (count) *count = 0;
254 return STATUS_SUCCESS;
257 /******************************************************************************
258 * LsaFreeMemory [ADVAPI32.@]
260 * Frees memory allocated by a LSA function.
262 * PARAMS
263 * Buffer [I] Memory buffer to free.
265 * RETURNS
266 * Success: STATUS_SUCCESS.
267 * Failure: NTSTATUS code.
269 NTSTATUS WINAPI LsaFreeMemory(IN PVOID Buffer)
271 TRACE("(%p)\n", Buffer);
273 heap_free(Buffer);
274 return STATUS_SUCCESS;
277 /******************************************************************************
278 * LsaLookupNames [ADVAPI32.@]
280 * Returns the SIDs of an array of user, group, or local group names.
282 * PARAMS
283 * PolicyHandle [I] Handle to a Policy object.
284 * Count [I] Number of names in Names.
285 * Names [I] Array of names to lookup.
286 * ReferencedDomains [O] Array of domains where the names were found.
287 * Sids [O] Array of SIDs corresponding to Names.
289 * RETURNS
290 * Success: STATUS_SUCCESS,
291 * STATUS_SOME_NOT_MAPPED
292 * Failure: STATUS_NONE_MAPPED or NTSTATUS code.
294 NTSTATUS WINAPI LsaLookupNames(
295 IN LSA_HANDLE PolicyHandle,
296 IN ULONG Count,
297 IN PLSA_UNICODE_STRING Names,
298 OUT PLSA_REFERENCED_DOMAIN_LIST* ReferencedDomains,
299 OUT PLSA_TRANSLATED_SID* Sids)
301 FIXME("(%p,0x%08x,%p,%p,%p) stub\n", PolicyHandle, Count, Names,
302 ReferencedDomains, Sids);
304 return STATUS_NONE_MAPPED;
307 static BOOL lookup_name( LSA_UNICODE_STRING *name, SID *sid, DWORD *sid_size, WCHAR *domain,
308 DWORD *domain_size, SID_NAME_USE *use, BOOL *handled )
310 BOOL ret;
312 ret = lookup_local_wellknown_name( name, sid, sid_size, domain, domain_size, use, handled );
313 if (!*handled)
314 ret = lookup_local_user_name( name, sid, sid_size, domain, domain_size, use, handled );
316 return ret;
319 /* Adds domain info to referenced domain list.
320 Domain list is stored as plain buffer, layout is:
322 LSA_REFERENCED_DOMAIN_LIST,
323 LSA_TRUST_INFORMATION array,
324 domain data array of
326 domain name data (WCHAR buffer),
327 SID data
330 Parameters:
331 list [I] referenced list pointer
332 domain [I] domain name string
333 data [IO] pointer to domain data array
335 static LONG lsa_reflist_add_domain(LSA_REFERENCED_DOMAIN_LIST *list, LSA_UNICODE_STRING *domain, char **data)
337 ULONG sid_size = 0,domain_size = 0;
338 BOOL handled = FALSE;
339 SID_NAME_USE use;
340 LONG i;
342 for (i = 0; i < list->Entries; i++)
344 /* try to reuse index */
345 if ((list->Domains[i].Name.Length == domain->Length) &&
346 (!strncmpiW(list->Domains[i].Name.Buffer, domain->Buffer, (domain->Length / sizeof(WCHAR)))))
348 return i;
352 /* no matching domain found, store name */
353 list->Domains[list->Entries].Name.Length = domain->Length;
354 list->Domains[list->Entries].Name.MaximumLength = domain->MaximumLength;
355 list->Domains[list->Entries].Name.Buffer = (WCHAR*)*data;
356 memcpy(list->Domains[list->Entries].Name.Buffer, domain->Buffer, domain->MaximumLength);
357 *data += domain->MaximumLength;
359 /* get and store SID data */
360 list->Domains[list->Entries].Sid = *data;
361 lookup_name(domain, NULL, &sid_size, NULL, &domain_size, &use, &handled);
362 domain_size = 0;
363 lookup_name(domain, list->Domains[list->Entries].Sid, &sid_size, NULL, &domain_size, &use, &handled);
364 *data += sid_size;
366 return list->Entries++;
369 /******************************************************************************
370 * LsaLookupNames2 [ADVAPI32.@]
373 NTSTATUS WINAPI LsaLookupNames2( LSA_HANDLE policy, ULONG flags, ULONG count,
374 PLSA_UNICODE_STRING names, PLSA_REFERENCED_DOMAIN_LIST *domains,
375 PLSA_TRANSLATED_SID2 *sids )
377 ULONG i, sid_size_total = 0, domain_size_max = 0, size, domainname_size_total = 0;
378 ULONG sid_size, domain_size, mapped;
379 LSA_UNICODE_STRING domain;
380 BOOL handled = FALSE;
381 char *domain_data;
382 SID_NAME_USE use;
383 SID *sid;
385 TRACE("(%p,0x%08x,0x%08x,%p,%p,%p)\n", policy, flags, count, names, domains, sids);
387 mapped = 0;
388 for (i = 0; i < count; i++)
390 handled = FALSE;
391 sid_size = domain_size = 0;
392 lookup_name( &names[i], NULL, &sid_size, NULL, &domain_size, &use, &handled );
393 if (handled)
395 sid_size_total += sid_size;
396 domainname_size_total += domain_size;
397 if (domain_size)
399 if (domain_size > domain_size_max)
400 domain_size_max = domain_size;
402 mapped++;
405 TRACE("mapped %u out of %u\n", mapped, count);
407 size = sizeof(LSA_TRANSLATED_SID2) * count + sid_size_total;
408 if (!(*sids = heap_alloc(size))) return STATUS_NO_MEMORY;
410 sid = (SID *)(*sids + count);
412 /* use maximum domain count */
413 if (!(*domains = heap_alloc(sizeof(LSA_REFERENCED_DOMAIN_LIST) + sizeof(LSA_TRUST_INFORMATION)*count +
414 sid_size_total + domainname_size_total*sizeof(WCHAR))))
416 heap_free(*sids);
417 return STATUS_NO_MEMORY;
419 (*domains)->Entries = 0;
420 (*domains)->Domains = (LSA_TRUST_INFORMATION*)((char*)*domains + sizeof(LSA_REFERENCED_DOMAIN_LIST));
421 domain_data = (char*)(*domains)->Domains + sizeof(LSA_TRUST_INFORMATION)*count;
423 domain.Buffer = heap_alloc(domain_size_max*sizeof(WCHAR));
424 for (i = 0; i < count; i++)
426 domain.Length = domain_size_max*sizeof(WCHAR);
427 domain.MaximumLength = domain_size_max*sizeof(WCHAR);
429 (*sids)[i].Use = SidTypeUnknown;
430 (*sids)[i].DomainIndex = -1;
431 (*sids)[i].Flags = 0;
433 handled = FALSE;
434 sid_size = sid_size_total;
435 domain_size = domain_size_max;
436 lookup_name( &names[i], sid, &sid_size, domain.Buffer, &domain_size, &use, &handled );
437 if (handled)
439 (*sids)[i].Sid = sid;
440 (*sids)[i].Use = use;
442 sid = (SID *)((char *)sid + sid_size);
443 sid_size_total -= sid_size;
444 if (domain_size)
446 domain.Length = domain_size * sizeof(WCHAR);
447 domain.MaximumLength = (domain_size + 1) * sizeof(WCHAR);
448 (*sids)[i].DomainIndex = lsa_reflist_add_domain(*domains, &domain, &domain_data);
452 heap_free(domain.Buffer);
454 if (mapped == count) return STATUS_SUCCESS;
455 if (mapped > 0 && mapped < count) return STATUS_SOME_NOT_MAPPED;
456 return STATUS_NONE_MAPPED;
459 /******************************************************************************
460 * LsaLookupSids [ADVAPI32.@]
462 * Looks up the names that correspond to an array of SIDs.
464 * PARAMS
465 * PolicyHandle [I] Handle to a Policy object.
466 * Count [I] Number of SIDs in the Sids array.
467 * Sids [I] Array of SIDs to lookup.
468 * ReferencedDomains [O] Array of domains where the sids were found.
469 * Names [O] Array of names corresponding to Sids.
471 * RETURNS
472 * Success: STATUS_SUCCESS,
473 * STATUS_SOME_NOT_MAPPED
474 * Failure: STATUS_NONE_MAPPED or NTSTATUS code.
476 NTSTATUS WINAPI LsaLookupSids(
477 LSA_HANDLE PolicyHandle,
478 ULONG Count,
479 PSID *Sids,
480 LSA_REFERENCED_DOMAIN_LIST **ReferencedDomains,
481 LSA_TRANSLATED_NAME **Names)
483 ULONG i, mapped, name_fullsize, domain_fullsize;
484 ULONG name_size, domain_size;
485 LSA_UNICODE_STRING domain;
486 WCHAR *name_buffer;
487 char *domain_data;
488 SID_NAME_USE use;
490 TRACE("(%p, %u, %p, %p, %p)\n", PolicyHandle, Count, Sids, ReferencedDomains, Names);
492 /* this length does not include actual string length yet */
493 name_fullsize = sizeof(LSA_TRANSLATED_NAME) * Count;
494 if (!(*Names = heap_alloc(name_fullsize))) return STATUS_NO_MEMORY;
495 /* maximum count of stored domain infos is Count, allocate it like that cause really needed
496 count could only be computed after sid data is retrieved */
497 domain_fullsize = sizeof(LSA_REFERENCED_DOMAIN_LIST) + sizeof(LSA_TRUST_INFORMATION)*Count;
498 if (!(*ReferencedDomains = heap_alloc(domain_fullsize)))
500 heap_free(*Names);
501 return STATUS_NO_MEMORY;
503 (*ReferencedDomains)->Entries = 0;
504 (*ReferencedDomains)->Domains = (LSA_TRUST_INFORMATION*)((char*)*ReferencedDomains + sizeof(LSA_REFERENCED_DOMAIN_LIST));
506 /* Get full names data length and full length needed to store domain name and SID */
507 for (i = 0; i < Count; i++)
509 (*Names)[i].Use = SidTypeUnknown;
510 (*Names)[i].DomainIndex = -1;
511 (*Names)[i].Name.Buffer = NULL;
513 memset(&(*ReferencedDomains)->Domains[i], 0, sizeof(LSA_TRUST_INFORMATION));
515 name_size = domain_size = 0;
516 if (!LookupAccountSidW(NULL, Sids[i], NULL, &name_size, NULL, &domain_size, &use) &&
517 GetLastError() == ERROR_INSUFFICIENT_BUFFER)
519 if (name_size)
521 (*Names)[i].Name.Length = (name_size - 1) * sizeof(WCHAR);
522 (*Names)[i].Name.MaximumLength = name_size * sizeof(WCHAR);
524 else
526 (*Names)[i].Name.Length = 0;
527 (*Names)[i].Name.MaximumLength = sizeof(WCHAR);
530 name_fullsize += (*Names)[i].Name.MaximumLength;
532 /* This potentially allocates more than needed, cause different names will reuse same domain index.
533 Also it's not possible to store domain name length right here for the same reason. */
534 if (domain_size)
536 ULONG sid_size = 0;
537 BOOL handled = FALSE;
538 WCHAR *name;
540 domain_fullsize += domain_size * sizeof(WCHAR);
542 /* get domain SID size too */
543 name = heap_alloc(domain_size * sizeof(WCHAR));
544 *name = 0;
545 LookupAccountSidW(NULL, Sids[i], NULL, &name_size, name, &domain_size, &use);
547 domain.Buffer = name;
548 domain.Length = domain_size * sizeof(WCHAR);
549 domain.MaximumLength = domain_size * sizeof(WCHAR);
551 lookup_name(&domain, NULL, &sid_size, NULL, &domain_size, &use, &handled);
552 domain_fullsize += sid_size;
554 heap_free(name);
556 else
558 /* If we don't have a domain name, use a zero-length entry rather than a null value. */
559 domain_fullsize += sizeof(WCHAR);
560 domain.Length = 0;
561 domain.MaximumLength = sizeof(WCHAR);
566 /* now we have full length needed for both */
567 *Names = heap_realloc(*Names, name_fullsize);
568 name_buffer = (WCHAR*)((char*)*Names + sizeof(LSA_TRANSLATED_NAME)*Count);
570 *ReferencedDomains = heap_realloc(*ReferencedDomains, domain_fullsize);
571 /* fix pointer after reallocation */
572 (*ReferencedDomains)->Domains = (LSA_TRUST_INFORMATION*)((char*)*ReferencedDomains + sizeof(LSA_REFERENCED_DOMAIN_LIST));
573 domain_data = (char*)(*ReferencedDomains)->Domains + sizeof(LSA_TRUST_INFORMATION)*Count;
575 mapped = 0;
576 for (i = 0; i < Count; i++)
578 name_size = domain_size = 0;
580 if (!LookupAccountSidW(NULL, Sids[i], NULL, &name_size, NULL, &domain_size, &use) &&
581 GetLastError() == ERROR_INSUFFICIENT_BUFFER)
583 mapped++;
585 if (domain_size)
587 domain.Length = (domain_size - 1) * sizeof(WCHAR);
588 domain.MaximumLength = domain_size * sizeof(WCHAR);
590 else
592 /* Use a zero-length buffer */
593 domain.Length = 0;
594 domain.MaximumLength = sizeof(WCHAR);
597 domain.Buffer = heap_alloc(domain.MaximumLength);
599 (*Names)[i].Name.Buffer = name_buffer;
600 LookupAccountSidW(NULL, Sids[i], (*Names)[i].Name.Buffer, &name_size, domain.Buffer, &domain_size, &use);
601 (*Names)[i].Use = use;
603 (*Names)[i].DomainIndex = lsa_reflist_add_domain(*ReferencedDomains, &domain, &domain_data);
604 heap_free(domain.Buffer);
607 name_buffer += name_size;
609 TRACE("mapped %u out of %u\n", mapped, Count);
611 if (mapped == Count) return STATUS_SUCCESS;
612 if (mapped) return STATUS_SOME_NOT_MAPPED;
613 return STATUS_NONE_MAPPED;
616 /******************************************************************************
617 * LsaNtStatusToWinError [ADVAPI32.@]
619 * Converts an LSA NTSTATUS code to a Windows error code.
621 * PARAMS
622 * Status [I] NTSTATUS code.
624 * RETURNS
625 * Success: Corresponding Windows error code.
626 * Failure: ERROR_MR_MID_NOT_FOUND.
628 ULONG WINAPI LsaNtStatusToWinError(NTSTATUS Status)
630 return RtlNtStatusToDosError(Status);
633 /******************************************************************************
634 * LsaOpenPolicy [ADVAPI32.@]
636 * Opens a handle to the Policy object on a local or remote system.
638 * PARAMS
639 * SystemName [I] Name of the target system.
640 * ObjectAttributes [I] Connection attributes.
641 * DesiredAccess [I] Requested access rights.
642 * PolicyHandle [I/O] Handle to the Policy object.
644 * RETURNS
645 * Success: STATUS_SUCCESS.
646 * Failure: NTSTATUS code.
648 * NOTES
649 * Set SystemName to NULL to open the local Policy object.
651 NTSTATUS WINAPI LsaOpenPolicy(
652 IN PLSA_UNICODE_STRING SystemName,
653 IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes,
654 IN ACCESS_MASK DesiredAccess,
655 IN OUT PLSA_HANDLE PolicyHandle)
657 FIXME("(%s,%p,0x%08x,%p) stub\n",
658 SystemName?debugstr_w(SystemName->Buffer):"(null)",
659 ObjectAttributes, DesiredAccess, PolicyHandle);
661 ADVAPI_ForceLocalComputer(SystemName ? SystemName->Buffer : NULL,
662 STATUS_ACCESS_VIOLATION);
663 dumpLsaAttributes(ObjectAttributes);
665 if(PolicyHandle) *PolicyHandle = (LSA_HANDLE)0xcafe;
666 return STATUS_SUCCESS;
669 /******************************************************************************
670 * LsaOpenTrustedDomainByName [ADVAPI32.@]
673 NTSTATUS WINAPI LsaOpenTrustedDomainByName(
674 LSA_HANDLE policy,
675 PLSA_UNICODE_STRING name,
676 ACCESS_MASK access,
677 PLSA_HANDLE handle)
679 FIXME("(%p,%p,0x%08x,%p) stub\n", policy, name, access, handle);
680 return STATUS_OBJECT_NAME_NOT_FOUND;
683 /******************************************************************************
684 * LsaQueryInformationPolicy [ADVAPI32.@]
686 * Returns information about a Policy object.
688 * PARAMS
689 * PolicyHandle [I] Handle to a Policy object.
690 * InformationClass [I] Type of information to retrieve.
691 * Buffer [O] Pointer to the requested information.
693 * RETURNS
694 * Success: STATUS_SUCCESS.
695 * Failure: NTSTATUS code.
697 NTSTATUS WINAPI LsaQueryInformationPolicy(
698 IN LSA_HANDLE PolicyHandle,
699 IN POLICY_INFORMATION_CLASS InformationClass,
700 OUT PVOID *Buffer)
702 TRACE("(%p,0x%08x,%p)\n", PolicyHandle, InformationClass, Buffer);
704 if(!Buffer) return STATUS_INVALID_PARAMETER;
705 switch (InformationClass)
707 case PolicyAuditEventsInformation: /* 2 */
709 PPOLICY_AUDIT_EVENTS_INFO p = heap_alloc_zero(sizeof(POLICY_AUDIT_EVENTS_INFO));
710 p->AuditingMode = FALSE; /* no auditing */
711 *Buffer = p;
713 break;
714 case PolicyPrimaryDomainInformation: /* 3 */
716 /* Only the domain name is valid for the local computer.
717 * All other fields are zero.
719 PPOLICY_PRIMARY_DOMAIN_INFO pinfo;
721 pinfo = ADVAPI_GetDomainName(sizeof(*pinfo), offsetof(POLICY_PRIMARY_DOMAIN_INFO, Name));
723 TRACE("setting domain to %s\n", debugstr_w(pinfo->Name.Buffer));
725 *Buffer = pinfo;
727 break;
728 case PolicyAccountDomainInformation: /* 5 */
730 struct di
732 POLICY_ACCOUNT_DOMAIN_INFO info;
733 SID sid;
734 DWORD padding[3];
735 WCHAR domain[MAX_COMPUTERNAME_LENGTH + 1];
738 DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
739 struct di * xdi = heap_alloc_zero(sizeof(*xdi));
741 xdi->info.DomainName.MaximumLength = dwSize * sizeof(WCHAR);
742 xdi->info.DomainName.Buffer = xdi->domain;
743 if (GetComputerNameW(xdi->info.DomainName.Buffer, &dwSize))
744 xdi->info.DomainName.Length = dwSize * sizeof(WCHAR);
746 TRACE("setting name to %s\n", debugstr_w(xdi->info.DomainName.Buffer));
748 xdi->info.DomainSid = &xdi->sid;
750 if (!ADVAPI_GetComputerSid(&xdi->sid))
752 heap_free(xdi);
754 WARN("Computer SID not found\n");
756 return STATUS_UNSUCCESSFUL;
759 TRACE("setting SID to %s\n", debugstr_sid(&xdi->sid));
761 *Buffer = xdi;
763 break;
764 case PolicyDnsDomainInformation: /* 12 (0xc) */
766 struct
768 POLICY_DNS_DOMAIN_INFO info;
769 struct
771 SID sid;
772 DWORD sid_subauthority[3];
773 } domain_sid;
774 WCHAR domain_name[MAX_COMPUTERNAME_LENGTH + 1];
775 WCHAR dns_domain_name[MAX_COMPUTERNAME_LENGTH + 1];
776 WCHAR dns_forest_name[MAX_COMPUTERNAME_LENGTH + 1];
777 } *xdi;
778 struct
780 SID sid;
781 DWORD sid_subauthority[3];
782 } computer_sid;
783 DWORD dwSize;
785 xdi = heap_alloc_zero(sizeof(*xdi));
786 if (!xdi) return STATUS_NO_MEMORY;
788 dwSize = MAX_COMPUTERNAME_LENGTH + 1;
789 if (GetComputerNameExW(ComputerNamePhysicalDnsDomain, xdi->domain_name, &dwSize))
791 WCHAR *dot;
793 dot = strrchrW(xdi->domain_name, '.');
794 if (dot) *dot = 0;
795 struprW(xdi->domain_name);
796 xdi->info.Name.Buffer = xdi->domain_name;
797 xdi->info.Name.Length = strlenW(xdi->domain_name) * sizeof(WCHAR);
798 xdi->info.Name.MaximumLength = xdi->info.Name.Length + sizeof(WCHAR);
799 TRACE("setting Name to %s\n", debugstr_w(xdi->info.Name.Buffer));
802 /* FIXME: also set DnsDomainName and DnsForestName */
804 dwSize = sizeof(xdi->domain_sid);
805 if (ADVAPI_GetComputerSid(&computer_sid.sid) && GetWindowsAccountDomainSid(&computer_sid.sid, &xdi->domain_sid.sid, &dwSize))
807 xdi->info.Sid = &xdi->domain_sid.sid;
808 TRACE("setting SID to %s\n", debugstr_sid(&xdi->domain_sid.sid));
811 *Buffer = xdi;
813 break;
814 case PolicyAuditLogInformation:
815 case PolicyPdAccountInformation:
816 case PolicyLsaServerRoleInformation:
817 case PolicyReplicaSourceInformation:
818 case PolicyDefaultQuotaInformation:
819 case PolicyModificationInformation:
820 case PolicyAuditFullSetInformation:
821 case PolicyAuditFullQueryInformation:
823 FIXME("category %d not implemented\n", InformationClass);
824 return STATUS_UNSUCCESSFUL;
827 return STATUS_SUCCESS;
830 /******************************************************************************
831 * LsaQueryTrustedDomainInfo [ADVAPI32.@]
834 NTSTATUS WINAPI LsaQueryTrustedDomainInfo(
835 LSA_HANDLE policy,
836 PSID sid,
837 TRUSTED_INFORMATION_CLASS class,
838 PVOID *buffer)
840 FIXME("(%p,%p,%d,%p) stub\n", policy, sid, class, buffer);
841 return STATUS_OBJECT_NAME_NOT_FOUND;
844 /******************************************************************************
845 * LsaQueryTrustedDomainInfoByName [ADVAPI32.@]
848 NTSTATUS WINAPI LsaQueryTrustedDomainInfoByName(
849 LSA_HANDLE policy,
850 PLSA_UNICODE_STRING name,
851 TRUSTED_INFORMATION_CLASS class,
852 PVOID *buffer)
854 FIXME("(%p,%p,%d,%p) stub\n", policy, name, class, buffer);
855 return STATUS_OBJECT_NAME_NOT_FOUND;
858 /******************************************************************************
859 * LsaRegisterPolicyChangeNotification [ADVAPI32.@]
862 NTSTATUS WINAPI LsaRegisterPolicyChangeNotification(
863 POLICY_NOTIFICATION_INFORMATION_CLASS class,
864 HANDLE event)
866 FIXME("(%d,%p) stub\n", class, event);
867 return STATUS_UNSUCCESSFUL;
870 /******************************************************************************
871 * LsaRemoveAccountRights [ADVAPI32.@]
874 NTSTATUS WINAPI LsaRemoveAccountRights(
875 LSA_HANDLE policy,
876 PSID sid,
877 BOOLEAN all,
878 PLSA_UNICODE_STRING rights,
879 ULONG count)
881 FIXME("(%p,%p,%d,%p,0x%08x) stub\n", policy, sid, all, rights, count);
882 return STATUS_SUCCESS;
885 /******************************************************************************
886 * LsaRetrievePrivateData [ADVAPI32.@]
888 * Retrieves data stored by LsaStorePrivateData.
890 * PARAMS
891 * PolicyHandle [I] Handle to a Policy object.
892 * KeyName [I] Name of the key where the data is stored.
893 * PrivateData [O] Pointer to the private data.
895 * RETURNS
896 * Success: STATUS_SUCCESS.
897 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
899 NTSTATUS WINAPI LsaRetrievePrivateData(
900 IN LSA_HANDLE PolicyHandle,
901 IN PLSA_UNICODE_STRING KeyName,
902 OUT PLSA_UNICODE_STRING* PrivateData)
904 FIXME("(%p,%p,%p) stub\n", PolicyHandle, KeyName, PrivateData);
905 return STATUS_OBJECT_NAME_NOT_FOUND;
908 /******************************************************************************
909 * LsaSetInformationPolicy [ADVAPI32.@]
911 * Modifies information in a Policy object.
913 * PARAMS
914 * PolicyHandle [I] Handle to a Policy object.
915 * InformationClass [I] Type of information to set.
916 * Buffer [I] Pointer to the information to set.
918 * RETURNS
919 * Success: STATUS_SUCCESS.
920 * Failure: NTSTATUS code.
922 NTSTATUS WINAPI LsaSetInformationPolicy(
923 IN LSA_HANDLE PolicyHandle,
924 IN POLICY_INFORMATION_CLASS InformationClass,
925 IN PVOID Buffer)
927 FIXME("(%p,0x%08x,%p) stub\n", PolicyHandle, InformationClass, Buffer);
929 return STATUS_UNSUCCESSFUL;
932 /******************************************************************************
933 * LsaSetSecret [ADVAPI32.@]
935 * Set old and new values on a secret handle
937 * PARAMS
938 * SecretHandle [I] Handle to a secret object.
939 * EncryptedCurrentValue [I] Pointer to encrypted new value, can be NULL
940 * EncryptedOldValue [I] Pointer to encrypted old value, can be NULL
942 * RETURNS
943 * Success: STATUS_SUCCESS
944 * Failure: NTSTATUS code.
946 NTSTATUS WINAPI LsaSetSecret(
947 IN LSA_HANDLE SecretHandle,
948 IN PLSA_UNICODE_STRING EncryptedCurrentValue,
949 IN PLSA_UNICODE_STRING EncryptedOldValue)
951 FIXME("(%p,%p,%p) stub\n", SecretHandle, EncryptedCurrentValue,
952 EncryptedOldValue);
953 return STATUS_SUCCESS;
956 /******************************************************************************
957 * LsaSetTrustedDomainInfoByName [ADVAPI32.@]
960 NTSTATUS WINAPI LsaSetTrustedDomainInfoByName(
961 LSA_HANDLE policy,
962 PLSA_UNICODE_STRING name,
963 TRUSTED_INFORMATION_CLASS class,
964 PVOID buffer)
966 FIXME("(%p,%p,%d,%p) stub\n", policy, name, class, buffer);
967 return STATUS_SUCCESS;
970 /******************************************************************************
971 * LsaSetTrustedDomainInformation [ADVAPI32.@]
974 NTSTATUS WINAPI LsaSetTrustedDomainInformation(
975 LSA_HANDLE policy,
976 PSID sid,
977 TRUSTED_INFORMATION_CLASS class,
978 PVOID buffer)
980 FIXME("(%p,%p,%d,%p) stub\n", policy, sid, class, buffer);
981 return STATUS_SUCCESS;
984 /******************************************************************************
985 * LsaStorePrivateData [ADVAPI32.@]
987 * Stores or deletes a Policy object's data under the specified reg key.
989 * PARAMS
990 * PolicyHandle [I] Handle to a Policy object.
991 * KeyName [I] Name of the key where the data will be stored.
992 * PrivateData [O] Pointer to the private data.
994 * RETURNS
995 * Success: STATUS_SUCCESS.
996 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
998 NTSTATUS WINAPI LsaStorePrivateData(
999 IN LSA_HANDLE PolicyHandle,
1000 IN PLSA_UNICODE_STRING KeyName,
1001 IN PLSA_UNICODE_STRING PrivateData)
1003 FIXME("(%p,%p,%p) stub\n", PolicyHandle, KeyName, PrivateData);
1004 return STATUS_OBJECT_NAME_NOT_FOUND;
1007 /******************************************************************************
1008 * LsaUnregisterPolicyChangeNotification [ADVAPI32.@]
1011 NTSTATUS WINAPI LsaUnregisterPolicyChangeNotification(
1012 POLICY_NOTIFICATION_INFORMATION_CLASS class,
1013 HANDLE event)
1015 FIXME("(%d,%p) stub\n", class, event);
1016 return STATUS_SUCCESS;
1019 /******************************************************************************
1020 * LsaLookupPrivilegeName [ADVAPI32.@]
1023 NTSTATUS WINAPI LsaLookupPrivilegeName(LSA_HANDLE handle, LUID *luid, LSA_UNICODE_STRING **name)
1025 const WCHAR *privnameW;
1026 DWORD length;
1027 WCHAR *strW;
1029 TRACE("(%p,%p,%p)\n", handle, luid, name);
1031 if (!luid || !handle)
1032 return STATUS_INVALID_PARAMETER;
1034 *name = NULL;
1036 if (!(privnameW = get_wellknown_privilege_name(luid)))
1037 return STATUS_NO_SUCH_PRIVILEGE;
1039 length = strlenW(privnameW);
1040 *name = heap_alloc(sizeof(**name) + (length + 1) * sizeof(WCHAR));
1041 if (!*name)
1042 return STATUS_NO_MEMORY;
1044 strW = (WCHAR *)(*name + 1);
1045 memcpy(strW, privnameW, length * sizeof(WCHAR));
1046 strW[length] = 0;
1047 RtlInitUnicodeString(*name, strW);
1049 return STATUS_SUCCESS;
1052 /******************************************************************************
1053 * LsaLookupPrivilegeDisplayName [ADVAPI32.@]
1056 NTSTATUS WINAPI LsaLookupPrivilegeDisplayName(LSA_HANDLE handle, LSA_UNICODE_STRING *name,
1057 LSA_UNICODE_STRING **display_name, SHORT *language)
1059 FIXME("(%p, %s, %p, %p)\n", handle, debugstr_us(name), display_name, language);
1061 return STATUS_NO_SUCH_PRIVILEGE;