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
27 #define WIN32_NO_STATUS
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
38 #define ADVAPI_ForceLocalComputer(ServerName, FailureCode) \
39 if (!ADVAPI_IsLocalComputer(ServerName)) \
41 FIXME("Action Implemented for local computer only. " \
42 "Requested for server %s\n", debugstr_w(ServerName)); \
46 static void dumpLsaAttributes(PLSA_OBJECT_ATTRIBUTES oa
)
50 TRACE("\n\tlength=%lu, rootdir=%p, objectname=%s\n\tattr=0x%08lx, sid=%p qos=%p\n",
51 oa
->Length
, oa
->RootDirectory
,
52 oa
->ObjectName
?debugstr_w(oa
->ObjectName
->Buffer
):"null",
53 oa
->Attributes
, oa
->SecurityDescriptor
, oa
->SecurityQualityOfService
);
57 /************************************************************
58 * ADVAPI_IsLocalComputer
60 * Checks whether the server name indicates local machine.
62 static BOOL
ADVAPI_IsLocalComputer(LPCWSTR ServerName
)
64 DWORD dwSize
= MAX_COMPUTERNAME_LENGTH
+ 1;
68 if (!ServerName
|| !ServerName
[0])
71 buf
= HeapAlloc(GetProcessHeap(), 0, dwSize
* sizeof(WCHAR
));
72 Result
= GetComputerNameW(buf
, &dwSize
);
73 if (Result
&& (ServerName
[0] == '\\') && (ServerName
[1] == '\\'))
75 Result
= Result
&& !lstrcmpW(ServerName
, buf
);
76 HeapFree(GetProcessHeap(), 0, buf
);
81 /******************************************************************************
82 * LsaClose [ADVAPI32.@]
84 * Closes a handle to a Policy or TrustedDomain.
87 * ObjectHandle [I] Handle to a Policy or TrustedDomain.
90 * Success: STATUS_SUCCESS.
91 * Failure: NTSTATUS code.
93 NTSTATUS WINAPI
LsaClose(IN LSA_HANDLE ObjectHandle
)
95 FIXME("(%p) stub\n", ObjectHandle
);
99 /******************************************************************************
100 * LsaEnumerateTrustedDomains [ADVAPI32.@]
102 * Returns the names and SIDs of trusted domains.
105 * PolicyHandle [I] Handle to a Policy object.
106 * EnumerationContext [I] Pointer to an enumeration handle.
107 * Buffer [O] Contains the names and SIDs of trusted domains.
108 * PreferredMaximumLength[I] Preferred maximum size in bytes of Buffer.
109 * CountReturned [O] Number of elements in Buffer.
112 * Success: STATUS_SUCCESS,
113 * STATUS_MORE_ENTRIES,
114 * STATUS_NO_MORE_ENTRIES
115 * Failure: NTSTATUS code.
118 * LsaEnumerateTrustedDomains can be called multiple times to enumerate
119 * all trusted domains.
121 NTSTATUS WINAPI
LsaEnumerateTrustedDomains(
122 IN LSA_HANDLE PolicyHandle
,
123 IN PLSA_ENUMERATION_HANDLE EnumerationContext
,
125 IN ULONG PreferredMaximumLength
,
126 OUT PULONG CountReturned
)
128 FIXME("(%p,%p,%p,0x%08lx,%p) stub\n", PolicyHandle
, EnumerationContext
,
129 Buffer
, PreferredMaximumLength
, CountReturned
);
131 if (CountReturned
) *CountReturned
= 0;
132 return STATUS_SUCCESS
;
135 /******************************************************************************
136 * LsaFreeMemory [ADVAPI32.@]
138 * Frees memory allocated by a LSA function.
141 * Buffer [I] Memory buffer to free.
144 * Success: STATUS_SUCCESS.
145 * Failure: NTSTATUS code.
147 NTSTATUS WINAPI
LsaFreeMemory(IN PVOID Buffer
)
149 TRACE("(%p)\n", Buffer
);
150 return HeapFree(GetProcessHeap(), 0, Buffer
);
153 /******************************************************************************
154 * LsaLookupNames [ADVAPI32.@]
156 * Returns the SIDs of an array of user, group, or local group names.
159 * PolicyHandle [I] Handle to a Policy object.
160 * Count [I] Number of names in Names.
161 * Names [I] Array of names to lookup.
162 * ReferencedDomains [O] Array of domains where the names were found.
163 * Sids [O] Array of SIDs corresponding to Names.
166 * Success: STATUS_SUCCESS,
167 * STATUS_SOME_NOT_MAPPED
168 * Failure: STATUS_NONE_MAPPED or NTSTATUS code.
170 NTSTATUS WINAPI
LsaLookupNames(
171 IN LSA_HANDLE PolicyHandle
,
173 IN PLSA_UNICODE_STRING Names
,
174 OUT PLSA_REFERENCED_DOMAIN_LIST
* ReferencedDomains
,
175 OUT PLSA_TRANSLATED_SID
* Sids
)
177 FIXME("(%p,0x%08lx,%p,%p,%p) stub\n", PolicyHandle
, Count
, Names
,
178 ReferencedDomains
, Sids
);
180 return STATUS_NONE_MAPPED
;
183 /******************************************************************************
184 * LsaLookupSids [ADVAPI32.@]
186 * Looks up the names that correspond to an array of SIDs.
189 * PolicyHandle [I] Handle to a Policy object.
190 * Count [I] Number of SIDs in the Sids array.
191 * Sids [I] Array of SIDs to lookup.
192 * ReferencedDomains [O] Array of domains where the sids were found.
193 * Names [O] Array of names corresponding to Sids.
196 * Success: STATUS_SUCCESS,
197 * STATUS_SOME_NOT_MAPPED
198 * Failure: STATUS_NONE_MAPPED or NTSTATUS code.
200 NTSTATUS WINAPI
LsaLookupSids(
201 IN LSA_HANDLE PolicyHandle
,
204 OUT PLSA_REFERENCED_DOMAIN_LIST
*ReferencedDomains
,
205 OUT PLSA_TRANSLATED_NAME
*Names
)
207 FIXME("(%p,%lu,%p,%p,%p) stub\n", PolicyHandle
, Count
, Sids
,
208 ReferencedDomains
, Names
);
210 return STATUS_NONE_MAPPED
;
213 /******************************************************************************
214 * LsaNtStatusToWinError [ADVAPI32.@]
216 * Converts an LSA NTSTATUS code to a Windows error code.
219 * Status [I] NTSTATUS code.
222 * Success: Corresponding Windows error code.
223 * Failure: ERROR_MR_MID_NOT_FOUND.
225 ULONG WINAPI
LsaNtStatusToWinError(NTSTATUS Status
)
227 return RtlNtStatusToDosError(Status
);
230 /******************************************************************************
231 * LsaOpenPolicy [ADVAPI32.@]
233 * Opens a handle to the Policy object on a local or remote system.
236 * SystemName [I] Name of the target system.
237 * ObjectAttributes [I] Connection attributes.
238 * DesiredAccess [I] Requested access rights.
239 * PolicyHandle [I/O] Handle to the Policy object.
242 * Success: STATUS_SUCCESS.
243 * Failure: NTSTATUS code.
246 * Set SystemName to NULL to open the local Policy object.
248 NTSTATUS WINAPI
LsaOpenPolicy(
249 IN PLSA_UNICODE_STRING SystemName
,
250 IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes
,
251 IN ACCESS_MASK DesiredAccess
,
252 IN OUT PLSA_HANDLE PolicyHandle
)
254 FIXME("(%s,%p,0x%08lx,%p) stub\n",
255 SystemName
?debugstr_w(SystemName
->Buffer
):"(null)",
256 ObjectAttributes
, DesiredAccess
, PolicyHandle
);
258 ADVAPI_ForceLocalComputer(SystemName
? SystemName
->Buffer
: NULL
,
259 STATUS_ACCESS_VIOLATION
);
260 dumpLsaAttributes(ObjectAttributes
);
262 if(PolicyHandle
) *PolicyHandle
= (LSA_HANDLE
)0xcafe;
263 return STATUS_SUCCESS
;
266 /******************************************************************************
267 * LsaQueryInformationPolicy [ADVAPI32.@]
269 * Returns information about a Policy object.
272 * PolicyHandle [I] Handle to a Policy object.
273 * InformationClass [I] Type of information to retrieve.
274 * Buffer [O] Pointer to the requested information.
277 * Success: STATUS_SUCCESS.
278 * Failure: NTSTATUS code.
280 NTSTATUS WINAPI
LsaQueryInformationPolicy(
281 IN LSA_HANDLE PolicyHandle
,
282 IN POLICY_INFORMATION_CLASS InformationClass
,
285 FIXME("(%p,0x%08x,%p) stub\n", PolicyHandle
, InformationClass
, Buffer
);
287 if(!Buffer
) return FALSE
;
288 switch (InformationClass
)
290 case PolicyAuditEventsInformation
: /* 2 */
292 PPOLICY_AUDIT_EVENTS_INFO p
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
293 sizeof(POLICY_AUDIT_EVENTS_INFO
));
294 p
->AuditingMode
= FALSE
; /* no auditing */
298 case PolicyPrimaryDomainInformation
: /* 3 */
299 case PolicyAccountDomainInformation
: /* 5 */
303 POLICY_PRIMARY_DOMAIN_INFO ppdi
;
307 SID_IDENTIFIER_AUTHORITY localSidAuthority
= {SECURITY_NT_AUTHORITY
};
309 struct di
* xdi
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(xdi
));
311 BOOL useDefault
= TRUE
;
314 if ((ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
315 "System\\CurrentControlSet\\Services\\VxD\\VNETSUP", 0,
316 KEY_READ
, &key
)) == ERROR_SUCCESS
)
319 static const WCHAR wg
[] = { 'W','o','r','k','g','r','o','u','p',0 };
321 ret
= RegQueryValueExW(key
, wg
, NULL
, NULL
, NULL
, &size
);
322 if (ret
== ERROR_MORE_DATA
|| ret
== ERROR_SUCCESS
)
324 xdi
->ppdi
.Name
.Buffer
= HeapAlloc(GetProcessHeap(),
325 HEAP_ZERO_MEMORY
, size
);
327 if ((ret
= RegQueryValueExW(key
, wg
, NULL
, NULL
,
328 (LPBYTE
)xdi
->ppdi
.Name
.Buffer
, &size
)) == ERROR_SUCCESS
)
330 xdi
->ppdi
.Name
.Length
= (USHORT
)size
;
335 HeapFree(GetProcessHeap(), 0, xdi
->ppdi
.Name
.Buffer
);
336 xdi
->ppdi
.Name
.Buffer
= NULL
;
342 RtlCreateUnicodeStringFromAsciiz(&(xdi
->ppdi
.Name
), "DOMAIN");
344 TRACE("setting domain to %s\n", debugstr_w(xdi
->ppdi
.Name
.Buffer
));
346 xdi
->ppdi
.Sid
= &(xdi
->sid
);
347 xdi
->sid
.Revision
= SID_REVISION
;
348 xdi
->sid
.SubAuthorityCount
= 1;
349 xdi
->sid
.IdentifierAuthority
= localSidAuthority
;
350 xdi
->sid
.SubAuthority
[0] = SECURITY_LOCAL_SYSTEM_RID
;
354 case PolicyAuditLogInformation
:
355 case PolicyPdAccountInformation
:
356 case PolicyLsaServerRoleInformation
:
357 case PolicyReplicaSourceInformation
:
358 case PolicyDefaultQuotaInformation
:
359 case PolicyModificationInformation
:
360 case PolicyAuditFullSetInformation
:
361 case PolicyAuditFullQueryInformation
:
362 case PolicyDnsDomainInformation
:
364 FIXME("category not implemented\n");
371 /******************************************************************************
372 * LsaRetrievePrivateData [ADVAPI32.@]
374 * Retrieves data stored by LsaStorePrivateData.
377 * PolicyHandle [I] Handle to a Policy object.
378 * KeyName [I] Name of the key where the data is stored.
379 * PrivateData [O] Pointer to the private data.
382 * Success: STATUS_SUCCESS.
383 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
385 NTSTATUS WINAPI
LsaRetrievePrivateData(
386 IN LSA_HANDLE PolicyHandle
,
387 IN PLSA_UNICODE_STRING KeyName
,
388 OUT PLSA_UNICODE_STRING
* PrivateData
)
390 FIXME("(%p,%p,%p) stub\n", PolicyHandle
, KeyName
, PrivateData
);
391 return STATUS_OBJECT_NAME_NOT_FOUND
;
394 /******************************************************************************
395 * LsaSetInformationPolicy [ADVAPI32.@]
397 * Modifies information in a Policy object.
400 * PolicyHandle [I] Handle to a Policy object.
401 * InformationClass [I] Type of information to set.
402 * Buffer [I] Pointer to the information to set.
405 * Success: STATUS_SUCCESS.
406 * Failure: NTSTATUS code.
408 NTSTATUS WINAPI
LsaSetInformationPolicy(
409 IN LSA_HANDLE PolicyHandle
,
410 IN POLICY_INFORMATION_CLASS InformationClass
,
413 FIXME("(%p,0x%08x,%p) stub\n", PolicyHandle
, InformationClass
, Buffer
);
415 return STATUS_UNSUCCESSFUL
;
418 /******************************************************************************
419 * LsaStorePrivateData [ADVAPI32.@]
421 * Stores or deletes a Policy object's data under the specified reg key.
424 * PolicyHandle [I] Handle to a Policy object.
425 * KeyName [I] Name of the key where the data will be stored.
426 * PrivateData [O] Pointer to the private data.
429 * Success: STATUS_SUCCESS.
430 * Failure: STATUS_OBJECT_NAME_NOT_FOUND or NTSTATUS code.
432 NTSTATUS WINAPI
LsaStorePrivateData(
433 IN LSA_HANDLE PolicyHandle
,
434 IN PLSA_UNICODE_STRING KeyName
,
435 IN PLSA_UNICODE_STRING PrivateData
)
437 FIXME("(%p,%p,%p) stub\n", PolicyHandle
, KeyName
, PrivateData
);
438 return STATUS_OBJECT_NAME_NOT_FOUND
;