Release 20050930.
[wine/gsoc-2012-control.git] / dlls / advapi32 / lsa.c
blobf072b4fbe92eeba27cbabda39c2430fefd9c1704
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winternl.h"
30 #include "ntstatus.h"
31 #include "ntsecapi.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
37 #define ADVAPI_ForceLocalComputer(ServerName, FailureCode) \
38 if (!ADVAPI_IsLocalComputer(ServerName)) \
39 { \
40 FIXME("Action Implemented for local computer only. " \
41 "Requested for server %s\n", debugstr_w(ServerName)); \
42 return FailureCode; \
45 static void dumpLsaAttributes(PLSA_OBJECT_ATTRIBUTES oa)
47 if (oa)
49 TRACE("\n\tlength=%lu, rootdir=%p, objectname=%s\n\tattr=0x%08lx, sid=%p qos=%p\n",
50 oa->Length, oa->RootDirectory,
51 oa->ObjectName?debugstr_w(oa->ObjectName->Buffer):"null",
52 oa->Attributes, oa->SecurityDescriptor, oa->SecurityQualityOfService);
56 /************************************************************
57 * ADVAPI_IsLocalComputer
59 * Checks whether the server name indicates local machine.
61 static BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName)
63 DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
64 BOOL Result;
65 LPWSTR buf;
67 if (!ServerName || !ServerName[0])
68 return TRUE;
70 buf = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
71 Result = GetComputerNameW(buf, &dwSize);
72 if (Result && (ServerName[0] == '\\') && (ServerName[1] == '\\'))
73 ServerName += 2;
74 Result = Result && !lstrcmpW(ServerName, buf);
75 HeapFree(GetProcessHeap(), 0, buf);
77 return Result;
80 /******************************************************************************
81 * LsaClose [ADVAPI32.@]
83 * Closes a handle to a Policy or TrustedDomain.
85 * PARAMS
86 * ObjectHandle [I] Handle to a Policy or TrustedDomain.
88 * RETURNS
89 * Success: STATUS_SUCCESS.
90 * Failure: NTSTATUS code.
92 NTSTATUS WINAPI LsaClose(IN LSA_HANDLE ObjectHandle)
94 FIXME("(%p) stub\n", ObjectHandle);
95 return 0xc0000000;
98 /******************************************************************************
99 * LsaEnumerateTrustedDomains [ADVAPI32.@]
101 * Returns the names and SIDs of trusted domains.
103 * PARAMS
104 * PolicyHandle [I] Handle to a Policy object.
105 * EnumerationContext [I] Pointer to an enumeration handle.
106 * Buffer [O] Contains the names and SIDs of trusted domains.
107 * PreferredMaximumLength[I] Preferred maximum size in bytes of Buffer.
108 * CountReturned [O] Number of elements in Buffer.
110 * RETURNS
111 * Success: STATUS_SUCCESS,
112 * STATUS_MORE_ENTRIES,
113 * STATUS_NO_MORE_ENTRIES
114 * Failure: NTSTATUS code.
116 * NOTES
117 * LsaEnumerateTrustedDomains can be called multiple times to enumerate
118 * all trusted domains.
120 NTSTATUS WINAPI LsaEnumerateTrustedDomains(
121 IN LSA_HANDLE PolicyHandle,
122 IN PLSA_ENUMERATION_HANDLE EnumerationContext,
123 OUT PVOID* Buffer,
124 IN ULONG PreferredMaximumLength,
125 OUT PULONG CountReturned)
127 FIXME("(%p,%p,%p,0x%08lx,%p) stub\n", PolicyHandle, EnumerationContext,
128 Buffer, PreferredMaximumLength, CountReturned);
130 if (CountReturned) *CountReturned = 0;
131 return STATUS_SUCCESS;
134 /******************************************************************************
135 * LsaFreeMemory [ADVAPI32.@]
137 * Frees memory allocated by a LSA function.
139 * PARAMS
140 * Buffer [I] Memory buffer to free.
142 * RETURNS
143 * Success: STATUS_SUCCESS.
144 * Failure: NTSTATUS code.
146 NTSTATUS WINAPI LsaFreeMemory(IN PVOID Buffer)
148 TRACE("(%p)\n", Buffer);
149 return HeapFree(GetProcessHeap(), 0, Buffer);
152 /******************************************************************************
153 * LsaLookupNames [ADVAPI32.@]
155 * Returns the SIDs of an array of user, group, or local group names.
157 * PARAMS
158 * PolicyHandle [I] Handle to a Policy object.
159 * Count [I] Number of names in Names.
160 * Names [I] Array of names to lookup.
161 * ReferencedDomains [O] Array of domains where the names were found.
162 * Sids [O] Array of SIDs corresponding to Names.
164 * RETURNS
165 * Success: STATUS_SUCCESS,
166 * STATUS_SOME_NOT_MAPPED
167 * Failure: STATUS_NONE_MAPPED or NTSTATUS code.
169 NTSTATUS WINAPI LsaLookupNames(
170 IN LSA_HANDLE PolicyHandle,
171 IN ULONG Count,
172 IN PLSA_UNICODE_STRING Names,
173 OUT PLSA_REFERENCED_DOMAIN_LIST* ReferencedDomains,
174 OUT PLSA_TRANSLATED_SID* Sids)
176 FIXME("(%p,0x%08lx,%p,%p,%p) stub\n", PolicyHandle, Count, Names,
177 ReferencedDomains, Sids);
179 return STATUS_NONE_MAPPED;
182 /******************************************************************************
183 * LsaLookupSids [ADVAPI32.@]
185 * Looks up the names that correspond to an array of SIDs.
187 * PARAMS
188 * PolicyHandle [I] Handle to a Policy object.
189 * Count [I] Number of SIDs in the Sids array.
190 * Sids [I] Array of SIDs to lookup.
191 * ReferencedDomains [O] Array of domains where the sids were found.
192 * Names [O] Array of names corresponding to Sids.
194 * RETURNS
195 * Success: STATUS_SUCCESS,
196 * STATUS_SOME_NOT_MAPPED
197 * Failure: STATUS_NONE_MAPPED or NTSTATUS code.
199 NTSTATUS WINAPI LsaLookupSids(
200 IN LSA_HANDLE PolicyHandle,
201 IN ULONG Count,
202 IN PSID *Sids,
203 OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains,
204 OUT PLSA_TRANSLATED_NAME *Names )
206 FIXME("(%p,%lu,%p,%p,%p) stub\n", PolicyHandle, Count, Sids,
207 ReferencedDomains, Names);
209 return FALSE;
212 /******************************************************************************
213 * LsaNtStatusToWinError [ADVAPI32.@]
215 * Converts an LSA NTSTATUS code to a Windows error code.
217 * PARAMS
218 * Status [I] NTSTATUS code.
220 * RETURNS
221 * Success: Corresponding Windows error code.
222 * Failure: ERROR_MR_MID_NOT_FOUND.
224 ULONG WINAPI LsaNtStatusToWinError(NTSTATUS Status)
226 return RtlNtStatusToDosError(Status);
229 /******************************************************************************
230 * LsaOpenPolicy [ADVAPI32.@]
232 * Opens a handle to the Policy object on a local or remote system.
234 * PARAMS
235 * SystemName [I] Name of the target system.
236 * ObjectAttributes [I] Connection attributes.
237 * DesiredAccess [I] Requested access rights.
238 * PolicyHandle [I/O] Handle to the Policy object.
240 * RETURNS
241 * Success: STATUS_SUCCESS.
242 * Failure: NTSTATUS code.
244 * NOTES
245 * Set SystemName to NULL to open the local Policy object.
247 NTSTATUS WINAPI LsaOpenPolicy(
248 IN PLSA_UNICODE_STRING SystemName,
249 IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes,
250 IN ACCESS_MASK DesiredAccess,
251 IN OUT PLSA_HANDLE PolicyHandle)
253 FIXME("(%s,%p,0x%08lx,%p) stub\n",
254 SystemName?debugstr_w(SystemName->Buffer):"(null)",
255 ObjectAttributes, DesiredAccess, PolicyHandle);
257 ADVAPI_ForceLocalComputer(SystemName ? SystemName->Buffer : NULL,
258 STATUS_ACCESS_VIOLATION);
259 dumpLsaAttributes(ObjectAttributes);
261 if(PolicyHandle) *PolicyHandle = (LSA_HANDLE)0xcafe;
262 return STATUS_SUCCESS;
265 /******************************************************************************
266 * LsaQueryInformationPolicy [ADVAPI32.@]
268 * Returns information about a Policy object.
270 * PARAMS
271 * PolicyHandle [I] Handle to a Policy object.
272 * InformationClass [I] Type of information to retrieve.
273 * Buffer [O] Pointer to the requested information.
275 * RETURNS
276 * Success: STATUS_SUCCESS.
277 * Failure: NTSTATUS code.
279 NTSTATUS WINAPI LsaQueryInformationPolicy(
280 IN LSA_HANDLE PolicyHandle,
281 IN POLICY_INFORMATION_CLASS InformationClass,
282 OUT PVOID *Buffer)
284 FIXME("(%p,0x%08x,%p) stub\n", PolicyHandle, InformationClass, Buffer);
286 if(!Buffer) return FALSE;
287 switch (InformationClass)
289 case PolicyAuditEventsInformation: /* 2 */
291 PPOLICY_AUDIT_EVENTS_INFO p = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
292 sizeof(POLICY_AUDIT_EVENTS_INFO));
293 p->AuditingMode = FALSE; /* no auditing */
294 *Buffer = p;
296 break;
297 case PolicyPrimaryDomainInformation: /* 3 */
298 case PolicyAccountDomainInformation: /* 5 */
300 struct di
302 POLICY_PRIMARY_DOMAIN_INFO ppdi;
303 SID sid;
306 SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
308 struct di * xdi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(xdi));
309 HKEY key;
310 BOOL useDefault = TRUE;
311 LONG ret;
313 if ((ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
314 "System\\CurrentControlSet\\Services\\VxD\\VNETSUP", 0,
315 KEY_READ, &key)) == ERROR_SUCCESS)
317 DWORD size = 0;
318 static const WCHAR wg[] = { 'W','o','r','k','g','r','o','u','p',0 };
320 ret = RegQueryValueExW(key, wg, NULL, NULL, NULL, &size);
321 if (ret == ERROR_MORE_DATA || ret == ERROR_SUCCESS)
323 xdi->ppdi.Name.Buffer = HeapAlloc(GetProcessHeap(),
324 HEAP_ZERO_MEMORY, size);
326 if ((ret = RegQueryValueExW(key, wg, NULL, NULL,
327 (LPBYTE)xdi->ppdi.Name.Buffer, &size)) == ERROR_SUCCESS)
329 xdi->ppdi.Name.Length = (USHORT)size;
330 useDefault = FALSE;
332 else
334 HeapFree(GetProcessHeap(), 0, xdi->ppdi.Name.Buffer);
335 xdi->ppdi.Name.Buffer = NULL;
338 RegCloseKey(key);
340 if (useDefault)
341 RtlCreateUnicodeStringFromAsciiz(&(xdi->ppdi.Name), "DOMAIN");
343 TRACE("setting domain to %s\n", debugstr_w(xdi->ppdi.Name.Buffer));
345 xdi->ppdi.Sid = &(xdi->sid);
346 xdi->sid.Revision = SID_REVISION;
347 xdi->sid.SubAuthorityCount = 1;
348 xdi->sid.IdentifierAuthority = localSidAuthority;
349 xdi->sid.SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
350 *Buffer = xdi;
352 break;
353 case PolicyAuditLogInformation:
354 case PolicyPdAccountInformation:
355 case PolicyLsaServerRoleInformation:
356 case PolicyReplicaSourceInformation:
357 case PolicyDefaultQuotaInformation:
358 case PolicyModificationInformation:
359 case PolicyAuditFullSetInformation:
360 case PolicyAuditFullQueryInformation:
361 case PolicyDnsDomainInformation:
363 FIXME("category not implemented\n");
364 return FALSE;
367 return TRUE;
370 /******************************************************************************
371 * LsaRetrievePrivateData [ADVAPI32.@]
373 * Retrieves data stored by LsaStorePrivateData.
375 * PARAMS
376 * PolicyHandle [I] Handle to a Policy object.
377 * KeyName [I] Name of the key where the data is stored.
378 * PrivateData [O] Pointer to the private data.
380 * RETURNS
381 * Success: STATUS_SUCCESS.
382 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
384 NTSTATUS WINAPI LsaRetrievePrivateData(
385 IN LSA_HANDLE PolicyHandle,
386 IN PLSA_UNICODE_STRING KeyName,
387 OUT PLSA_UNICODE_STRING* PrivateData)
389 FIXME("(%p,%p,%p) stub\n", PolicyHandle, KeyName, PrivateData);
390 return STATUS_OBJECT_NAME_NOT_FOUND;
393 /******************************************************************************
394 * LsaSetInformationPolicy [ADVAPI32.@]
396 * Modifies information in a Policy object.
398 * PARAMS
399 * PolicyHandle [I] Handle to a Policy object.
400 * InformationClass [I] Type of information to set.
401 * Buffer [I] Pointer to the information to set.
403 * RETURNS
404 * Success: STATUS_SUCCESS.
405 * Failure: NTSTATUS code.
407 NTSTATUS WINAPI LsaSetInformationPolicy(
408 IN LSA_HANDLE PolicyHandle,
409 IN POLICY_INFORMATION_CLASS InformationClass,
410 IN PVOID Buffer)
412 FIXME("(%p,0x%08x,%p) stub\n", PolicyHandle, InformationClass, Buffer);
414 return STATUS_UNSUCCESSFUL;
417 /******************************************************************************
418 * LsaStorePrivateData [ADVAPI32.@]
420 * Stores or deletes a Policy object's data under the specified reg key.
422 * PARAMS
423 * PolicyHandle [I] Handle to a Policy object.
424 * KeyName [I] Name of the key where the data will be stored.
425 * PrivateData [O] Pointer to the private data.
427 * RETURNS
428 * Success: STATUS_SUCCESS.
429 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
431 NTSTATUS WINAPI LsaStorePrivateData(
432 IN LSA_HANDLE PolicyHandle,
433 IN PLSA_UNICODE_STRING KeyName,
434 IN PLSA_UNICODE_STRING PrivateData)
436 FIXME("(%p,%p,%p) stub\n", PolicyHandle, KeyName, PrivateData);
437 return STATUS_OBJECT_NAME_NOT_FOUND;