[SCHEDSVC]
[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 * NetServerDiskEnum (NETAPI32.@)
89 */
90 NET_API_STATUS WINAPI NetServerDiskEnum(
91 LMSTR ServerName,
92 DWORD Level,
93 LPBYTE *Bufptr,
94 DWORD PrefMaxlen,
95 LPDWORD EntriesRead,
96 LPDWORD totalentries,
97 LPDWORD Resume_Handle)
98 {
99 FIXME("Stub (%s %d %p %d %p %p %p)\n", debugstr_w(ServerName),
100 Level, Bufptr, PrefMaxlen, EntriesRead, totalentries, Resume_Handle);
101
102 return ERROR_NO_BROWSER_SERVERS_FOUND;
103 }
104
105 /************************************************************
106 * NetServerGetInfo (NETAPI32.@)
107 */
108 NET_API_STATUS WINAPI NetServerGetInfo(LMSTR servername, DWORD level, LPBYTE* bufptr)
109 {
110 NET_API_STATUS ret;
111
112 TRACE("%s %d %p\n", debugstr_w( servername ), level, bufptr );
113 if (servername)
114 {
115 if (!NETAPI_IsLocalComputer(servername))
116 {
117 FIXME("remote computers not supported\n");
118 return ERROR_INVALID_LEVEL;
119 }
120 }
121 if (!bufptr) return ERROR_INVALID_PARAMETER;
122
123 switch (level)
124 {
125 case 100:
126 case 101:
127 {
128 DWORD computerNameLen, size;
129 WCHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];
130
131 computerNameLen = MAX_COMPUTERNAME_LENGTH + 1;
132 GetComputerNameW(computerName, &computerNameLen);
133 computerNameLen++; /* include NULL terminator */
134
135 size = sizeof(SERVER_INFO_101) + computerNameLen * sizeof(WCHAR);
136 ret = NetApiBufferAllocate(size, (LPVOID *)bufptr);
137 if (ret == NERR_Success)
138 {
139 /* INFO_100 structure is a subset of INFO_101 */
140 PSERVER_INFO_101 info = (PSERVER_INFO_101)*bufptr;
141 OSVERSIONINFOW verInfo;
142
143 info->sv101_platform_id = PLATFORM_ID_NT;
144 info->sv101_name = (LMSTR)(*bufptr + sizeof(SERVER_INFO_101));
145 memcpy(info->sv101_name, computerName,
146 computerNameLen * sizeof(WCHAR));
147 verInfo.dwOSVersionInfoSize = sizeof(verInfo);
148 GetVersionExW(&verInfo);
149 info->sv101_version_major = verInfo.dwMajorVersion;
150 info->sv101_version_minor = verInfo.dwMinorVersion;
151 /* Use generic type as no wine equivalent of DC / Server */
152 info->sv101_type = SV_TYPE_NT;
153 info->sv101_comment = NULL;
154 }
155 break;
156 }
157
158 default:
159 FIXME("level %d unimplemented\n", level);
160 ret = ERROR_INVALID_LEVEL;
161 }
162 return ret;
163 }
164
165
166 /************************************************************
167 * NetStatisticsGet (NETAPI32.@)
168 */
169 NET_API_STATUS WINAPI NetStatisticsGet(LMSTR server, LMSTR service,
170 DWORD level, DWORD options,
171 LPBYTE *bufptr)
172 {
173 TRACE("(%p, %p, %d, %d, %p)\n", server, service, level, options, bufptr);
174 return NERR_InternalError;
175 }
176
177 NET_API_STATUS
178 WINAPI
179 NetpNtStatusToApiStatus(NTSTATUS Status)
180 {
181 NET_API_STATUS ApiStatus;
182
183 switch (Status)
184 {
185 case STATUS_SUCCESS:
186 ApiStatus = NERR_Success;
187 break;
188
189 case STATUS_INVALID_ACCOUNT_NAME:
190 ApiStatus = NERR_BadUsername;
191 break;
192
193 case STATUS_PASSWORD_RESTRICTION:
194 ApiStatus = NERR_PasswordTooShort;
195 break;
196
197 default:
198 ApiStatus = RtlNtStatusToDosError(Status);
199 break;
200 }
201
202 return ApiStatus;
203 }