xref: /reactos/dll/win32/netapi32/display.c (revision c2c66aff)
1 /*
2  * PROJECT:     NetAPI DLL
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)
6  */
7 
8 /* INCLUDES ******************************************************************/
9 
10 #include "netapi32.h"
11 
12 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
13 
14 /* FUNCTIONS *****************************************************************/
15 
16 /* PUBLIC FUNCTIONS **********************************************************/
17 
18 NET_API_STATUS
19 WINAPI
NetQueryDisplayInformation(_In_ LPCWSTR ServerName,_In_ DWORD Level,_In_ DWORD Index,_In_ DWORD EntriesRequested,_In_ DWORD PreferredMaximumLength,_Out_ LPDWORD ReturnedEntryCount,_Out_ PVOID * SortedBuffer)20 NetQueryDisplayInformation(
21     _In_ LPCWSTR ServerName,
22     _In_ DWORD Level,
23     _In_ DWORD Index,
24     _In_ DWORD EntriesRequested,
25     _In_ DWORD PreferredMaximumLength,
26     _Out_ LPDWORD ReturnedEntryCount,
27     _Out_ PVOID *SortedBuffer)
28 {
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;
38     NTSTATUS Status;
39 
40     TRACE("NetQueryDisplayInformation(%s, %ld, %ld, %ld, %ld, %p, %p)\n",
41           debugstr_w(ServerName), Level, Index, EntriesRequested,
42           PreferredMaximumLength, ReturnedEntryCount, SortedBuffer);
43 
44     *ReturnedEntryCount = 0;
45     *SortedBuffer = NULL;
46 
47     switch (Level)
48     {
49         case 1:
50             DisplayInformation = DomainDisplayUser;
51             break;
52 
53         case 2:
54             DisplayInformation = DomainDisplayMachine;
55             break;
56 
57         case 3:
58             DisplayInformation = DomainDisplayGroup;
59             break;
60 
61         default:
62             return ERROR_INVALID_LEVEL;
63     }
64 
65     if (ServerName != NULL)
66         RtlInitUnicodeString(&ServerNameString, ServerName);
67 
68     /* Connect to the SAM Server */
69     Status = SamConnect((ServerName != NULL) ? &ServerNameString : NULL,
70                         &ServerHandle,
71                         SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
72                         NULL);
73     if (!NT_SUCCESS(Status))
74     {
75         ERR("SamConnect failed (Status %08lx)\n", Status);
76         ApiStatus = NetpNtStatusToApiStatus(Status);
77         goto done;
78     }
79 
80     /* Open the Account Domain */
81     Status = OpenAccountDomain(ServerHandle,
82                                (ServerName != NULL) ? &ServerNameString : NULL,
83                                DOMAIN_LIST_ACCOUNTS,
84                                &DomainHandle);
85     if (!NT_SUCCESS(Status))
86     {
87         ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
88         ApiStatus = NetpNtStatusToApiStatus(Status);
89         goto done;
90     }
91 
92     /* Query the information */
93     Status = SamQueryDisplayInformation(DomainHandle,
94                                         DisplayInformation,
95                                         Index,
96                                         EntriesRequested,
97                                         PreferredMaximumLength,
98                                         &LocalTotalBytesAvailable,
99                                         &LocalTotalBytesReturned,
100                                         &LocalReturnedEntryCount,
101                                         &LocalSortedBuffer);
102     if (!NT_SUCCESS(Status))
103     {
104         ERR("SamQueryDisplayInformation failed (Status %08lx)\n", Status);
105         ApiStatus = NetpNtStatusToApiStatus(Status);
106         goto done;
107     }
108 
109     /* FIXME */
110 
111 done:
112     if (DomainHandle != NULL)
113         SamCloseHandle(DomainHandle);
114 
115     if (ServerHandle != NULL)
116         SamCloseHandle(ServerHandle);
117 
118     return ApiStatus;
119 }
120 
121 
122 NET_API_STATUS
123 WINAPI
NetGetDisplayInformationIndex(_In_ LPCWSTR ServerName,_In_ DWORD Level,_In_ LPCWSTR Prefix,_Out_ LPDWORD Index)124 NetGetDisplayInformationIndex(
125     _In_ LPCWSTR ServerName,
126     _In_ DWORD Level,
127     _In_ LPCWSTR Prefix,
128     _Out_ LPDWORD Index)
129 {
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;
135     NTSTATUS Status;
136 
137     TRACE("NetGetDisplayInformationIndex(%s %ld %s %p)\n",
138           debugstr_w(ServerName), Level, debugstr_w(Prefix), Index);
139 
140     switch (Level)
141     {
142         case 1:
143             DisplayInformation = DomainDisplayUser;
144             break;
145 
146         case 2:
147             DisplayInformation = DomainDisplayMachine;
148             break;
149 
150         case 3:
151             DisplayInformation = DomainDisplayGroup;
152             break;
153 
154         default:
155             return ERROR_INVALID_LEVEL;
156     }
157 
158     if (ServerName != NULL)
159         RtlInitUnicodeString(&ServerNameString, ServerName);
160 
161     /* Connect to the SAM Server */
162     Status = SamConnect((ServerName != NULL) ? &ServerNameString : NULL,
163                         &ServerHandle,
164                         SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
165                         NULL);
166     if (!NT_SUCCESS(Status))
167     {
168         ERR("SamConnect failed (Status %08lx)\n", Status);
169         ApiStatus = NetpNtStatusToApiStatus(Status);
170         goto done;
171     }
172 
173     /* Open the Account Domain */
174     Status = OpenAccountDomain(ServerHandle,
175                                (ServerName != NULL) ? &ServerNameString : NULL,
176                                DOMAIN_LIST_ACCOUNTS,
177                                &DomainHandle);
178     if (!NT_SUCCESS(Status))
179     {
180         ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
181         ApiStatus = NetpNtStatusToApiStatus(Status);
182         goto done;
183     }
184 
185     RtlInitUnicodeString(&PrefixString, Prefix);
186 
187     /* Get the index */
188     Status = SamGetDisplayEnumerationIndex(DomainHandle,
189                                            DisplayInformation,
190                                            &PrefixString,
191                                            Index);
192     if (!NT_SUCCESS(Status))
193     {
194         ERR("SamGetDisplayEnumerationIndex failed (Status %08lx)\n", Status);
195         ApiStatus = NetpNtStatusToApiStatus(Status);
196     }
197 
198 done:
199     if (DomainHandle != NULL)
200         SamCloseHandle(DomainHandle);
201 
202     if (ServerHandle != NULL)
203         SamCloseHandle(ServerHandle);
204 
205     return ApiStatus;
206 }
207 
208 /* EOF */
209