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