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 PWSTR 139 WINAPI 140 NetpAllocWStrFromAnsiStr( 141 _In_ PSTR InString) 142 { 143 ANSI_STRING AnsiString; 144 UNICODE_STRING UnicodeString; 145 ULONG Size; 146 NET_API_STATUS NetStatus; 147 NTSTATUS Status; 148 149 RtlInitAnsiString(&AnsiString, InString); 150 151 Size = RtlAnsiStringToUnicodeSize(&AnsiString); 152 NetStatus = NetApiBufferAllocate(Size, 153 (PVOID*)&UnicodeString.Buffer); 154 if (NetStatus != NERR_Success) 155 return NULL; 156 157 Status = RtlAnsiStringToUnicodeString(&UnicodeString, 158 &AnsiString, 159 FALSE); 160 if (!NT_SUCCESS(Status)) 161 { 162 NetApiBufferFree(UnicodeString.Buffer); 163 return NULL; 164 } 165 166 return UnicodeString.Buffer; 167 } 168 169 170 PWSTR 171 WINAPI 172 NetpAllocWStrFromStr( 173 _In_ PSTR InString) 174 { 175 OEM_STRING OemString; 176 UNICODE_STRING UnicodeString; 177 ULONG Size; 178 NET_API_STATUS NetStatus; 179 NTSTATUS Status; 180 181 RtlInitAnsiString((PANSI_STRING)&OemString, InString); 182 183 Size = RtlOemStringToUnicodeSize(&OemString); 184 NetStatus = NetApiBufferAllocate(Size, 185 (PVOID*)&UnicodeString.Buffer); 186 if (NetStatus != NERR_Success) 187 return NULL; 188 189 Status = RtlOemStringToUnicodeString(&UnicodeString, 190 &OemString, 191 FALSE); 192 if (!NT_SUCCESS(Status)) 193 { 194 NetApiBufferFree(UnicodeString.Buffer); 195 return NULL; 196 } 197 198 return UnicodeString.Buffer; 199 } 200 201 202 PWSTR 203 WINAPI 204 NetpAllocWStrFromWStr( 205 _In_ PWSTR InString) 206 { 207 PWSTR OutString; 208 ULONG Size; 209 NET_API_STATUS Status; 210 211 Size = (wcslen(InString) + 1) * sizeof(WCHAR); 212 Status = NetApiBufferAllocate(Size, 213 (PVOID*)&OutString); 214 if (Status != NERR_Success) 215 return NULL; 216 217 wcscpy(OutString, InString); 218 219 return OutString; 220 } 221 222 223 NET_API_STATUS 224 WINAPI 225 NetpNtStatusToApiStatus( 226 _In_ NTSTATUS Status) 227 { 228 NET_API_STATUS ApiStatus; 229 230 switch (Status) 231 { 232 case STATUS_SUCCESS: 233 ApiStatus = NERR_Success; 234 break; 235 236 case STATUS_INVALID_ACCOUNT_NAME: 237 ApiStatus = NERR_BadUsername; 238 break; 239 240 case STATUS_PASSWORD_RESTRICTION: 241 ApiStatus = NERR_PasswordTooShort; 242 break; 243 244 default: 245 ApiStatus = RtlNtStatusToDosError(Status); 246 break; 247 } 248 249 return ApiStatus; 250 } 251 252 /* EOF */ 253