[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 #include "netapi32.h"
20
21 #include <lmserver.h>
22
23 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
24
25 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
26 {
27 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
28
29 switch (fdwReason) {
30 case DLL_PROCESS_ATTACH:
31 DisableThreadLibraryCalls(hinstDLL);
32 NetBIOSInit();
33 NetBTInit();
34 break;
35 case DLL_PROCESS_DETACH:
36 if (lpvReserved) break;
37 NetBIOSShutdown();
38 break;
39 }
40
41 return TRUE;
42 }
43
44 /************************************************************
45 * NetServerEnum (NETAPI32.@)
46 */
47 NET_API_STATUS WINAPI NetServerEnum(
48 LMCSTR servername,
49 DWORD level,
50 LPBYTE* bufptr,
51 DWORD prefmaxlen,
52 LPDWORD entriesread,
53 LPDWORD totalentries,
54 DWORD servertype,
55 LMCSTR domain,
56 LPDWORD resume_handle
57 )
58 {
59 FIXME("Stub (%s %d %p %d %p %p %d %s %p)\n", debugstr_w(servername),
60 level, bufptr, prefmaxlen, entriesread, totalentries, servertype,
61 debugstr_w(domain), resume_handle);
62
63 return ERROR_NO_BROWSER_SERVERS_FOUND;
64 }
65
66 /************************************************************
67 * NetServerEnumEx (NETAPI32.@)
68 */
69 NET_API_STATUS WINAPI NetServerEnumEx(
70 LMCSTR ServerName,
71 DWORD Level,
72 LPBYTE *Bufptr,
73 DWORD PrefMaxlen,
74 LPDWORD EntriesRead,
75 LPDWORD totalentries,
76 DWORD servertype,
77 LMCSTR domain,
78 LMCSTR FirstNameToReturn)
79 {
80 FIXME("Stub (%s %d %p %d %p %p %d %s %s)\n",
81 debugstr_w(ServerName), Level, Bufptr, PrefMaxlen, EntriesRead, totalentries,
82 servertype, debugstr_w(domain), debugstr_w(FirstNameToReturn));
83
84 return ERROR_NO_BROWSER_SERVERS_FOUND;
85 }
86
87 /************************************************************
88 * NetServerGetInfo (NETAPI32.@)
89 */
90 NET_API_STATUS WINAPI NetServerGetInfo(LMSTR servername, DWORD level, LPBYTE* bufptr)
91 {
92 NET_API_STATUS ret;
93
94 TRACE("%s %d %p\n", debugstr_w( servername ), level, bufptr );
95 if (servername)
96 {
97 if (!NETAPI_IsLocalComputer(servername))
98 {
99 FIXME("remote computers not supported\n");
100 return ERROR_INVALID_LEVEL;
101 }
102 }
103 if (!bufptr) return ERROR_INVALID_PARAMETER;
104
105 switch (level)
106 {
107 case 100:
108 case 101:
109 {
110 DWORD computerNameLen, size;
111 WCHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];
112
113 computerNameLen = MAX_COMPUTERNAME_LENGTH + 1;
114 GetComputerNameW(computerName, &computerNameLen);
115 computerNameLen++; /* include NULL terminator */
116
117 size = sizeof(SERVER_INFO_101) + computerNameLen * sizeof(WCHAR);
118 ret = NetApiBufferAllocate(size, (LPVOID *)bufptr);
119 if (ret == NERR_Success)
120 {
121 /* INFO_100 structure is a subset of INFO_101 */
122 PSERVER_INFO_101 info = (PSERVER_INFO_101)*bufptr;
123 OSVERSIONINFOW verInfo;
124
125 info->sv101_platform_id = PLATFORM_ID_NT;
126 info->sv101_name = (LMSTR)(*bufptr + sizeof(SERVER_INFO_101));
127 memcpy(info->sv101_name, computerName,
128 computerNameLen * sizeof(WCHAR));
129 verInfo.dwOSVersionInfoSize = sizeof(verInfo);
130 GetVersionExW(&verInfo);
131 info->sv101_version_major = verInfo.dwMajorVersion;
132 info->sv101_version_minor = verInfo.dwMinorVersion;
133 /* Use generic type as no wine equivalent of DC / Server */
134 info->sv101_type = SV_TYPE_NT;
135 info->sv101_comment = NULL;
136 }
137 break;
138 }
139
140 default:
141 FIXME("level %d unimplemented\n", level);
142 ret = ERROR_INVALID_LEVEL;
143 }
144 return ret;
145 }
146
147
148 /************************************************************
149 * NetStatisticsGet (NETAPI32.@)
150 */
151 NET_API_STATUS WINAPI NetStatisticsGet(LMSTR server, LMSTR service,
152 DWORD level, DWORD options,
153 LPBYTE *bufptr)
154 {
155 TRACE("(%p, %p, %d, %d, %p)\n", server, service, level, options, bufptr);
156 return NERR_InternalError;
157 }
158
159 NET_API_STATUS
160 WINAPI
161 NetpNtStatusToApiStatus(NTSTATUS Status)
162 {
163 NET_API_STATUS ApiStatus;
164
165 switch (Status)
166 {
167 case STATUS_SUCCESS:
168 ApiStatus = NERR_Success;
169 break;
170
171 case STATUS_INVALID_ACCOUNT_NAME:
172 ApiStatus = NERR_BadUsername;
173 break;
174
175 case STATUS_PASSWORD_RESTRICTION:
176 ApiStatus = NERR_PasswordTooShort;
177 break;
178
179 default:
180 ApiStatus = RtlNtStatusToDosError(Status);
181 break;
182 }
183
184 return ApiStatus;
185 }