Merge my current work done on the kd++ branch:
[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 NETAPI_IsLocalComputer(LMCSTR ServerName);
35
36 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
37 {
38 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
39
40 switch (fdwReason) {
41 case DLL_PROCESS_ATTACH:
42 {
43 DisableThreadLibraryCalls(hinstDLL);
44 NETAPI32_hModule = hinstDLL;
45 NetBIOSInit();
46 NetBTInit();
47 break;
48 }
49 case DLL_PROCESS_DETACH:
50 {
51 NetBIOSShutdown();
52 break;
53 }
54 }
55
56 return TRUE;
57 }
58
59 /************************************************************
60 * NetServerEnum (NETAPI32.@)
61 */
62 NET_API_STATUS WINAPI NetServerEnum(
63 LMCSTR servername,
64 DWORD level,
65 LPBYTE* bufptr,
66 DWORD prefmaxlen,
67 LPDWORD entriesread,
68 LPDWORD totalentries,
69 DWORD servertype,
70 LMCSTR domain,
71 LPDWORD resume_handle
72 )
73 {
74 FIXME("Stub (%s %d %p %d %p %p %d %s %p)\n", debugstr_w(servername),
75 level, bufptr, prefmaxlen, entriesread, totalentries, servertype,
76 debugstr_w(domain), resume_handle);
77
78 return ERROR_NO_BROWSER_SERVERS_FOUND;
79 }
80
81 /************************************************************
82 * NetServerEnumEx (NETAPI32.@)
83 */
84 NET_API_STATUS WINAPI NetServerEnumEx(
85 LMCSTR ServerName,
86 DWORD Level,
87 LPBYTE *Bufptr,
88 DWORD PrefMaxlen,
89 LPDWORD EntriesRead,
90 LPDWORD totalentries,
91 DWORD servertype,
92 LMCSTR domain,
93 LMCSTR FirstNameToReturn)
94 {
95 FIXME("Stub (%s %d %p %d %p %p %d %s %p)\n", debugstr_w(ServerName),
96 Level, Bufptr, PrefMaxlen, EntriesRead, totalentries, servertype,
97 debugstr_w(domain), debugstr_w(FirstNameToReturn));
98
99 return ERROR_NO_BROWSER_SERVERS_FOUND;
100 }
101
102 /************************************************************
103 * NetServerGetInfo (NETAPI32.@)
104 */
105 NET_API_STATUS WINAPI NetServerGetInfo(LMSTR servername, DWORD level, LPBYTE* bufptr)
106 {
107 NET_API_STATUS ret;
108
109 TRACE("%s %d %p\n", debugstr_w( servername ), level, bufptr );
110 if (servername)
111 {
112 if (!NETAPI_IsLocalComputer(servername))
113 {
114 FIXME("remote computers not supported\n");
115 return ERROR_INVALID_LEVEL;
116 }
117 }
118 if (!bufptr) return ERROR_INVALID_PARAMETER;
119
120 switch (level)
121 {
122 case 100:
123 case 101:
124 {
125 DWORD computerNameLen, size;
126 WCHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];
127
128 computerNameLen = MAX_COMPUTERNAME_LENGTH + 1;
129 GetComputerNameW(computerName, &computerNameLen);
130 computerNameLen++; /* include NULL terminator */
131
132 size = sizeof(SERVER_INFO_101) + computerNameLen * sizeof(WCHAR);
133 ret = NetApiBufferAllocate(size, (LPVOID *)bufptr);
134 if (ret == NERR_Success)
135 {
136 /* INFO_100 structure is a subset of INFO_101 */
137 PSERVER_INFO_101 info = (PSERVER_INFO_101)*bufptr;
138 OSVERSIONINFOW verInfo;
139
140 info->sv101_platform_id = PLATFORM_ID_NT;
141 info->sv101_name = (LMSTR)(*bufptr + sizeof(SERVER_INFO_101));
142 memcpy(info->sv101_name, computerName,
143 computerNameLen * sizeof(WCHAR));
144 verInfo.dwOSVersionInfoSize = sizeof(verInfo);
145 GetVersionExW(&verInfo);
146 info->sv101_version_major = verInfo.dwMajorVersion;
147 info->sv101_version_minor = verInfo.dwMinorVersion;
148 /* Use generic type as no wine equivalent of DC / Server */
149 info->sv101_type = SV_TYPE_NT;
150 info->sv101_comment = NULL;
151 }
152 break;
153 }
154
155 default:
156 FIXME("level %d unimplemented\n", level);
157 ret = ERROR_INVALID_LEVEL;
158 }
159 return ret;
160 }
161
162
163 /************************************************************
164 * NetStatisticsGet (NETAPI32.@)
165 */
166 NET_API_STATUS WINAPI NetStatisticsGet(LMSTR server, LMSTR service,
167 DWORD level, DWORD options,
168 LPBYTE *bufptr)
169 {
170 TRACE("(%p, %p, %d, %d, %p)\n", server, service, level, options, bufptr);
171 return NERR_InternalError;
172 }
173
174 DWORD WINAPI NetpNetBiosStatusToApiStatus(DWORD nrc)
175 {
176 DWORD ret;
177
178 switch (nrc)
179 {
180 case NRC_GOODRET:
181 ret = NO_ERROR;
182 break;
183 case NRC_NORES:
184 ret = NERR_NoNetworkResource;
185 break;
186 case NRC_DUPNAME:
187 ret = NERR_AlreadyExists;
188 break;
189 case NRC_NAMTFUL:
190 ret = NERR_TooManyNames;
191 break;
192 case NRC_ACTSES:
193 ret = NERR_DeleteLater;
194 break;
195 case NRC_REMTFUL:
196 ret = ERROR_REM_NOT_LIST;
197 break;
198 case NRC_NOCALL:
199 ret = NERR_NameNotFound;
200 break;
201 case NRC_NOWILD:
202 ret = ERROR_INVALID_PARAMETER;
203 break;
204 case NRC_INUSE:
205 ret = NERR_DuplicateName;
206 break;
207 case NRC_NAMERR:
208 ret = ERROR_INVALID_PARAMETER;
209 break;
210 case NRC_NAMCONF:
211 ret = NERR_DuplicateName;
212 break;
213 default:
214 ret = NERR_NetworkError;
215 }
216 return ret;
217 }
218
219 NET_API_STATUS
220 WINAPI
221 NetpNtStatusToApiStatus(NTSTATUS Status)
222 {
223 return RtlNtStatusToDosError(Status);
224 }
225
226 NET_API_STATUS WINAPI NetUseEnum(LMSTR server, DWORD level, LPBYTE* bufptr, DWORD prefmaxsize,
227 LPDWORD entriesread, LPDWORD totalentries, LPDWORD resumehandle)
228 {
229 FIXME("stub (%p, %d, %p, %d, %p, %p, %p)\n", server, level, bufptr, prefmaxsize,
230 entriesread, totalentries, resumehandle);
231 return ERROR_NOT_SUPPORTED;
232 }