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