[NETAPI32]
[reactos.git] / reactos / dll / win32 / netapi32 / netapi32.c
1 /* Copyright 2001 Mike McCormack
2 * Copyright 2003 Juan Lang
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #define WIN32_NO_STATUS
20 #include <config.h>
21
22 #include <wine/debug.h>
23 //#include "lm.h"
24 #include "netbios.h"
25
26 #define NTOS_MODE_USER
27 #include <ndk/rtlfuncs.h>
28 #include "netapi32.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(netbios);
31
32 static HMODULE NETAPI32_hModule;
33
34 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
35 {
36 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
37
38 switch (fdwReason) {
39 case DLL_PROCESS_ATTACH:
40 {
41 DisableThreadLibraryCalls(hinstDLL);
42 NETAPI32_hModule = hinstDLL;
43 NetBIOSInit();
44 NetBTInit();
45 break;
46 }
47 case DLL_PROCESS_DETACH:
48 {
49 NetBIOSShutdown();
50 break;
51 }
52 }
53
54 return TRUE;
55 }
56
57 /************************************************************
58 * NetServerEnum (NETAPI32.@)
59 */
60 NET_API_STATUS WINAPI NetServerEnum(
61 LMCSTR servername,
62 DWORD level,
63 LPBYTE* bufptr,
64 DWORD prefmaxlen,
65 LPDWORD entriesread,
66 LPDWORD totalentries,
67 DWORD servertype,
68 LMCSTR domain,
69 LPDWORD resume_handle
70 )
71 {
72 FIXME("Stub (%s %d %p %d %p %p %d %s %p)\n", debugstr_w(servername),
73 level, bufptr, prefmaxlen, entriesread, totalentries, servertype,
74 debugstr_w(domain), resume_handle);
75
76 return ERROR_NO_BROWSER_SERVERS_FOUND;
77 }
78
79 /************************************************************
80 * NetServerEnumEx (NETAPI32.@)
81 */
82 NET_API_STATUS WINAPI NetServerEnumEx(
83 LMCSTR ServerName,
84 DWORD Level,
85 LPBYTE *Bufptr,
86 DWORD PrefMaxlen,
87 LPDWORD EntriesRead,
88 LPDWORD totalentries,
89 DWORD servertype,
90 LMCSTR domain,
91 LMCSTR FirstNameToReturn)
92 {
93 FIXME("Stub (%s %d %p %d %p %p %d %s %p)\n", debugstr_w(ServerName),
94 Level, Bufptr, PrefMaxlen, EntriesRead, totalentries, servertype,
95 debugstr_w(domain), debugstr_w(FirstNameToReturn));
96
97 return ERROR_NO_BROWSER_SERVERS_FOUND;
98 }
99
100 /************************************************************
101 * NetServerGetInfo (NETAPI32.@)
102 */
103 NET_API_STATUS WINAPI NetServerGetInfo(LMSTR servername, DWORD level, LPBYTE* bufptr)
104 {
105 NET_API_STATUS ret;
106
107 TRACE("%s %d %p\n", debugstr_w( servername ), level, bufptr );
108 if (servername)
109 {
110 if (!NETAPI_IsLocalComputer(servername))
111 {
112 FIXME("remote computers not supported\n");
113 return ERROR_INVALID_LEVEL;
114 }
115 }
116 if (!bufptr) return ERROR_INVALID_PARAMETER;
117
118 switch (level)
119 {
120 case 100:
121 case 101:
122 {
123 DWORD computerNameLen, size;
124 WCHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];
125
126 computerNameLen = MAX_COMPUTERNAME_LENGTH + 1;
127 GetComputerNameW(computerName, &computerNameLen);
128 computerNameLen++; /* include NULL terminator */
129
130 size = sizeof(SERVER_INFO_101) + computerNameLen * sizeof(WCHAR);
131 ret = NetApiBufferAllocate(size, (LPVOID *)bufptr);
132 if (ret == NERR_Success)
133 {
134 /* INFO_100 structure is a subset of INFO_101 */
135 PSERVER_INFO_101 info = (PSERVER_INFO_101)*bufptr;
136 OSVERSIONINFOW verInfo;
137
138 info->sv101_platform_id = PLATFORM_ID_NT;
139 info->sv101_name = (LMSTR)(*bufptr + sizeof(SERVER_INFO_101));
140 memcpy(info->sv101_name, computerName,
141 computerNameLen * sizeof(WCHAR));
142 verInfo.dwOSVersionInfoSize = sizeof(verInfo);
143 GetVersionExW(&verInfo);
144 info->sv101_version_major = verInfo.dwMajorVersion;
145 info->sv101_version_minor = verInfo.dwMinorVersion;
146 /* Use generic type as no wine equivalent of DC / Server */
147 info->sv101_type = SV_TYPE_NT;
148 info->sv101_comment = NULL;
149 }
150 break;
151 }
152
153 default:
154 FIXME("level %d unimplemented\n", level);
155 ret = ERROR_INVALID_LEVEL;
156 }
157 return ret;
158 }
159
160
161 /************************************************************
162 * NetStatisticsGet (NETAPI32.@)
163 */
164 NET_API_STATUS WINAPI NetStatisticsGet(LMSTR server, LMSTR service,
165 DWORD level, DWORD options,
166 LPBYTE *bufptr)
167 {
168 TRACE("(%p, %p, %d, %d, %p)\n", server, service, level, options, bufptr);
169 return NERR_InternalError;
170 }
171
172 DWORD WINAPI NetpNetBiosStatusToApiStatus(DWORD nrc)
173 {
174 DWORD ret;
175
176 switch (nrc)
177 {
178 case NRC_GOODRET:
179 ret = NO_ERROR;
180 break;
181 case NRC_NORES:
182 ret = NERR_NoNetworkResource;
183 break;
184 case NRC_DUPNAME:
185 ret = NERR_AlreadyExists;
186 break;
187 case NRC_NAMTFUL:
188 ret = NERR_TooManyNames;
189 break;
190 case NRC_ACTSES:
191 ret = NERR_DeleteLater;
192 break;
193 case NRC_REMTFUL:
194 ret = ERROR_REM_NOT_LIST;
195 break;
196 case NRC_NOCALL:
197 ret = NERR_NameNotFound;
198 break;
199 case NRC_NOWILD:
200 ret = ERROR_INVALID_PARAMETER;
201 break;
202 case NRC_INUSE:
203 ret = NERR_DuplicateName;
204 break;
205 case NRC_NAMERR:
206 ret = ERROR_INVALID_PARAMETER;
207 break;
208 case NRC_NAMCONF:
209 ret = NERR_DuplicateName;
210 break;
211 default:
212 ret = NERR_NetworkError;
213 }
214 return ret;
215 }
216
217 NET_API_STATUS
218 WINAPI
219 NetpNtStatusToApiStatus(NTSTATUS Status)
220 {
221 NET_API_STATUS ApiStatus;
222
223 switch (Status)
224 {
225 case STATUS_SUCCESS:
226 ApiStatus = NERR_Success;
227 break;
228
229 case STATUS_INVALID_ACCOUNT_NAME:
230 ApiStatus = NERR_BadUsername;
231 break;
232
233 case STATUS_PASSWORD_RESTRICTION:
234 ApiStatus = NERR_PasswordTooShort;
235 break;
236
237 default:
238 ApiStatus = RtlNtStatusToDosError(Status);
239 break;
240 }
241
242 return ApiStatus;
243 }
244
245 NET_API_STATUS WINAPI NetUseEnum(LMSTR server, DWORD level, LPBYTE* bufptr, DWORD prefmaxsize,
246 LPDWORD entriesread, LPDWORD totalentries, LPDWORD resumehandle)
247 {
248 FIXME("stub (%p, %d, %p, %d, %p, %p, %p)\n", server, level, bufptr, prefmaxsize,
249 entriesread, totalentries, resumehandle);
250 return ERROR_NOT_SUPPORTED;
251 }