[NETAPI32] Implement NetRegisterDomainNameChangeNotification() and NetUnregisterDomai...
[reactos.git] / dll / win32 / netapi32 / misc.c
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
17 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
18
19 /* FUNCTIONS *****************************************************************/
20
21 NET_API_STATUS
22 WINAPI
23 NetRegisterDomainNameChangeNotification(
24 _Out_ PHANDLE NotificationEventHandle)
25 {
26 HANDLE EventHandle;
27 NTSTATUS Status;
28
29 TRACE("NetRegisterDomainNameChangeNotification(%p)\n",
30 NotificationEventHandle);
31
32 if (NotificationEventHandle == NULL)
33 return ERROR_INVALID_PARAMETER;
34
35 EventHandle = CreateEventW(NULL, FALSE, FALSE, NULL);
36 if (EventHandle == NULL)
37 return GetLastError();
38
39 Status = LsaRegisterPolicyChangeNotification(PolicyNotifyDnsDomainInformation,
40 NotificationEventHandle);
41 if (!NT_SUCCESS(Status))
42 {
43 CloseHandle(EventHandle);
44 return NetpNtStatusToApiStatus(Status);
45 }
46
47 *NotificationEventHandle = EventHandle;
48
49 return NERR_Success;
50 }
51
52
53 NET_API_STATUS
54 WINAPI
55 NetStatisticsGet(
56 _In_ LPWSTR server,
57 _In_ LPWSTR service,
58 _In_ DWORD level,
59 _In_ DWORD options,
60 _Out_ LPBYTE *bufptr)
61 {
62 NET_API_STATUS status = ERROR_NOT_SUPPORTED;
63
64 TRACE("NetStatisticsGet(%s %s %lu %lu %p)\n",
65 debugstr_w(server), debugstr_w(service), level, options, bufptr);
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)
75 return ERROR_INVALID_PARAMETER;
76
77 RpcTryExcept
78 {
79 status = NetrWorkstationStatisticsGet(server,
80 L"LanmanWorkstation",
81 level,
82 options,
83 (LPSTAT_WORKSTATION_0*)bufptr);
84 }
85 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
86 {
87 status = I_RpcMapWin32Status(RpcExceptionCode());
88 }
89 RpcEndExcept;
90 }
91 else if (_wcsicmp(service, L"LanmanServer") == 0)
92 {
93 if (level != 0)
94 return ERROR_INVALID_LEVEL;
95
96 if (options != 0)
97 return ERROR_INVALID_PARAMETER;
98
99 RpcTryExcept
100 {
101 status = NetrServerStatisticsGet(server,
102 L"LanmanServer",
103 level,
104 options,
105 (LPSTAT_SERVER_0 *)bufptr);
106 }
107 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
108 {
109 status = I_RpcMapWin32Status(RpcExceptionCode());
110 }
111 RpcEndExcept;
112 }
113
114 return status;
115 }
116
117
118 NET_API_STATUS
119 WINAPI
120 NetUnregisterDomainNameChangeNotification(
121 _In_ HANDLE NotificationEventHandle)
122 {
123 NTSTATUS Status;
124
125 TRACE("NetUnregisterDomainNameChangeNotification(%p)\n",
126 NotificationEventHandle);
127
128 if (NotificationEventHandle == NULL)
129 return ERROR_INVALID_PARAMETER;
130
131 Status = LsaUnregisterPolicyChangeNotification(PolicyNotifyDnsDomainInformation,
132 NotificationEventHandle);
133
134 return NetpNtStatusToApiStatus(Status);
135 }
136
137
138 NET_API_STATUS
139 WINAPI
140 NetpNtStatusToApiStatus(
141 _In_ NTSTATUS Status)
142 {
143 NET_API_STATUS ApiStatus;
144
145 switch (Status)
146 {
147 case STATUS_SUCCESS:
148 ApiStatus = NERR_Success;
149 break;
150
151 case STATUS_INVALID_ACCOUNT_NAME:
152 ApiStatus = NERR_BadUsername;
153 break;
154
155 case STATUS_PASSWORD_RESTRICTION:
156 ApiStatus = NERR_PasswordTooShort;
157 break;
158
159 default:
160 ApiStatus = RtlNtStatusToDosError(Status);
161 break;
162 }
163
164 return ApiStatus;
165 }
166
167 /* EOF */