3 * LICENSE: GPL-2.0 (https://spdx.org/licenses/GPL-2.0)
4 * PURPOSE: SAM service interface code
5 * COPYRIGHT: Copyright 2017 Eric Kohl (eric.kohl@reactos.org)
8 /* INCLUDES ******************************************************************/
12 WINE_DEFAULT_DEBUG_CHANNEL(netapi32
);
14 /* FUNCTIONS *****************************************************************/
16 /* PUBLIC FUNCTIONS **********************************************************/
20 NetQueryDisplayInformation(
21 _In_ LPCWSTR ServerName
,
24 _In_ DWORD EntriesRequested
,
25 _In_ DWORD PreferredMaximumLength
,
26 _Out_ LPDWORD ReturnedEntryCount
,
27 _Out_ PVOID
*SortedBuffer
)
29 UNICODE_STRING ServerNameString
;
30 SAM_HANDLE ServerHandle
= NULL
;
31 SAM_HANDLE DomainHandle
= NULL
;
32 DOMAIN_DISPLAY_INFORMATION DisplayInformation
;
33 DWORD LocalTotalBytesAvailable
;
34 DWORD LocalTotalBytesReturned
;
35 DWORD LocalReturnedEntryCount
;
36 PVOID LocalSortedBuffer
;
37 NET_API_STATUS ApiStatus
= NERR_Success
;
40 TRACE("NetQueryDisplayInformation(%s, %ld, %ld, %ld, %ld, %p, %p)\n",
41 debugstr_w(ServerName
), Level
, Index
, EntriesRequested
,
42 PreferredMaximumLength
, ReturnedEntryCount
, SortedBuffer
);
44 *ReturnedEntryCount
= 0;
50 DisplayInformation
= DomainDisplayUser
;
54 DisplayInformation
= DomainDisplayMachine
;
58 DisplayInformation
= DomainDisplayGroup
;
62 return ERROR_INVALID_LEVEL
;
65 if (ServerName
!= NULL
)
66 RtlInitUnicodeString(&ServerNameString
, ServerName
);
68 /* Connect to the SAM Server */
69 Status
= SamConnect((ServerName
!= NULL
) ? &ServerNameString
: NULL
,
71 SAM_SERVER_CONNECT
| SAM_SERVER_LOOKUP_DOMAIN
,
73 if (!NT_SUCCESS(Status
))
75 ERR("SamConnect failed (Status %08lx)\n", Status
);
76 ApiStatus
= NetpNtStatusToApiStatus(Status
);
80 /* Open the Account Domain */
81 Status
= OpenAccountDomain(ServerHandle
,
82 (ServerName
!= NULL
) ? &ServerNameString
: NULL
,
85 if (!NT_SUCCESS(Status
))
87 ERR("OpenAccountDomain failed (Status %08lx)\n", Status
);
88 ApiStatus
= NetpNtStatusToApiStatus(Status
);
92 /* Query the information */
93 Status
= SamQueryDisplayInformation(DomainHandle
,
97 PreferredMaximumLength
,
98 &LocalTotalBytesAvailable
,
99 &LocalTotalBytesReturned
,
100 &LocalReturnedEntryCount
,
102 if (!NT_SUCCESS(Status
))
104 ERR("SamQueryDisplayInformation failed (Status %08lx)\n", Status
);
105 ApiStatus
= NetpNtStatusToApiStatus(Status
);
112 if (DomainHandle
!= NULL
)
113 SamCloseHandle(DomainHandle
);
115 if (ServerHandle
!= NULL
)
116 SamCloseHandle(ServerHandle
);
124 NetGetDisplayInformationIndex(
125 _In_ LPCWSTR ServerName
,
130 UNICODE_STRING ServerNameString
, PrefixString
;
131 SAM_HANDLE ServerHandle
= NULL
;
132 SAM_HANDLE DomainHandle
= NULL
;
133 DOMAIN_DISPLAY_INFORMATION DisplayInformation
;
134 NET_API_STATUS ApiStatus
= NERR_Success
;
137 TRACE("NetGetDisplayInformationIndex(%s %ld %s %p)\n",
138 debugstr_w(ServerName
), Level
, debugstr_w(Prefix
), Index
);
143 DisplayInformation
= DomainDisplayUser
;
147 DisplayInformation
= DomainDisplayMachine
;
151 DisplayInformation
= DomainDisplayGroup
;
155 return ERROR_INVALID_LEVEL
;
158 if (ServerName
!= NULL
)
159 RtlInitUnicodeString(&ServerNameString
, ServerName
);
161 /* Connect to the SAM Server */
162 Status
= SamConnect((ServerName
!= NULL
) ? &ServerNameString
: NULL
,
164 SAM_SERVER_CONNECT
| SAM_SERVER_LOOKUP_DOMAIN
,
166 if (!NT_SUCCESS(Status
))
168 ERR("SamConnect failed (Status %08lx)\n", Status
);
169 ApiStatus
= NetpNtStatusToApiStatus(Status
);
173 /* Open the Account Domain */
174 Status
= OpenAccountDomain(ServerHandle
,
175 (ServerName
!= NULL
) ? &ServerNameString
: NULL
,
176 DOMAIN_LIST_ACCOUNTS
,
178 if (!NT_SUCCESS(Status
))
180 ERR("OpenAccountDomain failed (Status %08lx)\n", Status
);
181 ApiStatus
= NetpNtStatusToApiStatus(Status
);
185 RtlInitUnicodeString(&PrefixString
, Prefix
);
188 Status
= SamGetDisplayEnumerationIndex(DomainHandle
,
192 if (!NT_SUCCESS(Status
))
194 ERR("SamGetDisplayEnumerationIndex failed (Status %08lx)\n", Status
);
195 ApiStatus
= NetpNtStatusToApiStatus(Status
);
199 if (DomainHandle
!= NULL
)
200 SamCloseHandle(DomainHandle
);
202 if (ServerHandle
!= NULL
)
203 SamCloseHandle(ServerHandle
);