ReactOS  0.4.14-dev-614-gbfd8a84
misc.c
Go to the documentation of this file.
1 /*
2  * PROJECT: NetAPI DLL
3  * LICENSE: GPL-2.0 (https://spdx.org/licenses/GPL-2.0)
4  * PURPOSE: Miscellaneous functions
5  * COPYRIGHT: Copyright 2017 Eric Kohl (eric.kohl@reactos.org)
6  */
7 
8 /* INCLUDES ******************************************************************/
9 
10 #include "netapi32.h"
11 
12 #include <rpc.h>
13 #include "srvsvc_c.h"
14 #include "wkssvc_c.h"
15 
16 
18 
19 /* FUNCTIONS *****************************************************************/
20 
22 WINAPI
24  _Out_ PHANDLE NotificationEventHandle)
25 {
28 
29  TRACE("NetRegisterDomainNameChangeNotification(%p)\n",
30  NotificationEventHandle);
31 
32  if (NotificationEventHandle == NULL)
34 
36  if (EventHandle == NULL)
37  return GetLastError();
38 
40  NotificationEventHandle);
41  if (!NT_SUCCESS(Status))
42  {
45  }
46 
47  *NotificationEventHandle = EventHandle;
48 
49  return NERR_Success;
50 }
51 
52 
54 WINAPI
57  _In_ LPWSTR service,
61 {
63 
64  TRACE("NetStatisticsGet(%s %s %lu %lu %p)\n",
66 
67  *bufptr = NULL;
68 
69  if (_wcsicmp(service, L"LanmanWorkstation") == 0)
70  {
71  if (level != 0)
72  return ERROR_INVALID_LEVEL;
73 
74  if (options != 0)
76 
78  {
80  L"LanmanWorkstation",
81  level,
82  options,
84  }
86  {
88  }
90  }
91  else if (_wcsicmp(service, L"LanmanServer") == 0)
92  {
93  if (level != 0)
94  return ERROR_INVALID_LEVEL;
95 
96  if (options != 0)
98 
100  {
102  L"LanmanServer",
103  level,
104  options,
106  }
108  {
110  }
111  RpcEndExcept;
112  }
113 
114  return status;
115 }
116 
117 
119 WINAPI
121  _In_ HANDLE NotificationEventHandle)
122 {
124 
125  TRACE("NetUnregisterDomainNameChangeNotification(%p)\n",
126  NotificationEventHandle);
127 
128  if (NotificationEventHandle == NULL)
130 
132  NotificationEventHandle);
133 
135 }
136 
137 
138 PSTR
139 WINAPI
141  _In_ PWSTR InString)
142 {
145  ULONG Size;
146  NET_API_STATUS NetStatus;
148 
150 
152  NetStatus = NetApiBufferAllocate(Size,
153  (PVOID*)&AnsiString.Buffer);
154  if (NetStatus != NERR_Success)
155  return NULL;
156 
158  &UnicodeString,
159  FALSE);
160  if (!NT_SUCCESS(Status))
161  {
163  return NULL;
164  }
165 
166  return AnsiString.Buffer;
167 }
168 
169 
170 PSTR
171 WINAPI
173  _In_ PWSTR InString)
174 {
177  ULONG Size;
178  NET_API_STATUS NetStatus;
180 
182 
184  NetStatus = NetApiBufferAllocate(Size,
185  (PVOID*)&OemString.Buffer);
186  if (NetStatus != NERR_Success)
187  return NULL;
188 
190  &UnicodeString,
191  FALSE);
192  if (!NT_SUCCESS(Status))
193  {
194  NetApiBufferFree(OemString.Buffer);
195  return NULL;
196  }
197 
198  return OemString.Buffer;
199 }
200 
201 
202 PWSTR
203 WINAPI
205  _In_ PSTR InString)
206 {
209  ULONG Size;
210  NET_API_STATUS NetStatus;
212 
213  RtlInitAnsiString(&AnsiString, InString);
214 
216  NetStatus = NetApiBufferAllocate(Size,
217  (PVOID*)&UnicodeString.Buffer);
218  if (NetStatus != NERR_Success)
219  return NULL;
220 
222  &AnsiString,
223  FALSE);
224  if (!NT_SUCCESS(Status))
225  {
227  return NULL;
228  }
229 
230  return UnicodeString.Buffer;
231 }
232 
233 
234 PWSTR
235 WINAPI
237  _In_ PSTR InString)
238 {
241  ULONG Size;
242  NET_API_STATUS NetStatus;
244 
246 
248  NetStatus = NetApiBufferAllocate(Size,
249  (PVOID*)&UnicodeString.Buffer);
250  if (NetStatus != NERR_Success)
251  return NULL;
252 
254  &OemString,
255  FALSE);
256  if (!NT_SUCCESS(Status))
257  {
259  return NULL;
260  }
261 
262  return UnicodeString.Buffer;
263 }
264 
265 
266 PWSTR
267 WINAPI
269  _In_ PWSTR InString)
270 {
271  PWSTR OutString;
272  ULONG Size;
274 
275  Size = (wcslen(InString) + 1) * sizeof(WCHAR);
277  (PVOID*)&OutString);
278  if (Status != NERR_Success)
279  return NULL;
280 
281  wcscpy(OutString, InString);
282 
283  return OutString;
284 }
285 
286 
288 WINAPI
291 {
292  NET_API_STATUS ApiStatus;
293 
294  switch (Status)
295  {
296  case STATUS_SUCCESS:
297  ApiStatus = NERR_Success;
298  break;
299 
301  ApiStatus = NERR_BadUsername;
302  break;
303 
305  ApiStatus = NERR_PasswordTooShort;
306  break;
307 
308  default:
309  ApiStatus = RtlNtStatusToDosError(Status);
310  break;
311  }
312 
313  return ApiStatus;
314 }
315 
316 /* EOF */
NET_API_STATUS WINAPI NetApiBufferAllocate(DWORD ByteCount, LPVOID *Buffer)
Definition: apibuf.c:28
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
*BytesInOemString PCHAR OemString
Definition: rtlfuncs.h:1561
GLint level
Definition: gl.h:1546
#define RpcEndExcept
Definition: rpc.h:128
PSTR WINAPI NetpAllocAnsiStrFromWStr(_In_ PWSTR InString)
Definition: misc.c:140
NTSYSAPI DWORD WINAPI RtlUnicodeStringToAnsiSize(const UNICODE_STRING *)
#define CloseHandle
Definition: compat.h:406
*BytesInUnicodeString PWCH UnicodeString
Definition: rtlfuncs.h:1980
static rfbScreenInfoPtr server
Definition: vnc.c:74
unsigned long __stdcall NetrWorkstationStatisticsGet(WKSSVC_IDENTIFY_HANDLE ServerName, wchar_t *ServiceName, unsigned long Level, unsigned long Options, LPSTAT_WORKSTATION_0 *Buffer)
Definition: rpcserver.c:263
static unsigned int bufptr
Definition: tncon.cpp:77
uint16_t * PWSTR
Definition: typedefs.h:54
NET_API_STATUS WINAPI NetStatisticsGet(_In_ LPWSTR server, _In_ LPWSTR service, _In_ DWORD level, _In_ DWORD options, _Out_ LPBYTE *bufptr)
Definition: misc.c:55
LONG NTSTATUS
Definition: precomp.h:26
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
STRING OEM_STRING
Definition: umtypes.h:203
NTSYSAPI DWORD WINAPI RtlUnicodeStringToOemSize(const UNICODE_STRING *)
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
#define NERR_Success
Definition: lmerr.h:5
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define STATUS_PASSWORD_RESTRICTION
Definition: ntstatus.h:330
PWSTR WINAPI NetpAllocWStrFromAnsiStr(_In_ PSTR InString)
Definition: misc.c:204
unsigned char * LPBYTE
Definition: typedefs.h:52
#define debugstr_w
Definition: kernel32.h:32
#define RpcTryExcept
Definition: rpc.h:126
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define NERR_PasswordTooShort
Definition: lmerr.h:112
smooth NULL
Definition: ftsmooth.c:416
#define _Out_
Definition: no_sal2.h:323
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define STATUS_INVALID_ACCOUNT_NAME
Definition: ntstatus.h:320
#define RpcExceptionCode()
Definition: rpc.h:132
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NET_API_STATUS __stdcall NetrServerStatisticsGet(SRVSVC_HANDLE ServerName, WCHAR *Service, DWORD Level, DWORD Options, LPSTAT_SERVER_0 *InfoStruct)
Definition: rpcserver.c:472
#define WINAPI
Definition: msvc.h:6
WINE_DEFAULT_DEBUG_CHANNEL(advapi)
unsigned long DWORD
Definition: ntddk_ex.h:95
PWSTR WINAPI NetpAllocWStrFromStr(_In_ PSTR InString)
Definition: misc.c:236
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
NET_API_STATUS WINAPI NetpNtStatusToApiStatus(_In_ NTSTATUS Status)
Definition: misc.c:289
PSTR WINAPI NetpAllocStrFromWStr(_In_ PWSTR InString)
Definition: misc.c:172
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToOemString(POEM_STRING DestinationString, PCUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
NTSYSAPI NTSTATUS NTAPI RtlOemStringToUnicodeString(PUNICODE_STRING DestinationString, PCOEM_STRING SourceString, BOOLEAN AllocateDestinationString)
Status
Definition: gdiplustypes.h:24
NET_API_STATUS WINAPI NetRegisterDomainNameChangeNotification(_Out_ PHANDLE NotificationEventHandle)
Definition: misc.c:23
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define _In_
Definition: no_sal2.h:204
NET_API_STATUS WINAPI NetUnregisterDomainNameChangeNotification(_In_ HANDLE NotificationEventHandle)
Definition: misc.c:120
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
NTSYSAPI DWORD WINAPI RtlAnsiStringToUnicodeSize(const STRING *)
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
signed char * PSTR
Definition: retypes.h:7
PWSTR WINAPI NetpAllocWStrFromWStr(_In_ PWSTR InString)
Definition: misc.c:268
#define ERROR_NOT_SUPPORTED
Definition: compat.h:90
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
WCHAR * LPWSTR
Definition: xmlstorage.h:184
NTSTATUS NTAPI LsaRegisterPolicyChangeNotification(POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass, HANDLE NotificationEventHandle)
Definition: lsalpc.c:330
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
NTSTATUS NTAPI LsaUnregisterPolicyChangeNotification(POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass, HANDLE NotificationEventHandle)
Definition: lsalpc.c:377
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define NERR_BadUsername
Definition: lmerr.h:72
#define RpcExcept(expr)
Definition: rpc.h:127
NTSYSAPI UINT WINAPI RtlOemStringToUnicodeSize(const STRING *)
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:855
LONG WINAPI I_RpcMapWin32Status(RPC_STATUS status)
Definition: rpcrt4_main.c:738
Definition: ps.c:97