a2ffcefd524eea7ea402edf0c072e84abdb71ce2
[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(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 * NetServerGetInfo (NETAPI32.@)
46 */
47 NET_API_STATUS WINAPI NetServerGetInfo(LMSTR servername, DWORD level, LPBYTE* bufptr)
48 {
49 NET_API_STATUS ret;
50
51 TRACE("%s %d %p\n", debugstr_w( servername ), level, bufptr );
52 if (servername)
53 {
54 if (!NETAPI_IsLocalComputer(servername))
55 {
56 FIXME("remote computers not supported\n");
57 return ERROR_INVALID_LEVEL;
58 }
59 }
60 if (!bufptr) return ERROR_INVALID_PARAMETER;
61
62 switch (level)
63 {
64 case 100:
65 case 101:
66 {
67 DWORD computerNameLen, size;
68 WCHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];
69
70 computerNameLen = MAX_COMPUTERNAME_LENGTH + 1;
71 GetComputerNameW(computerName, &computerNameLen);
72 computerNameLen++; /* include NULL terminator */
73
74 size = sizeof(SERVER_INFO_101) + computerNameLen * sizeof(WCHAR);
75 ret = NetApiBufferAllocate(size, (LPVOID *)bufptr);
76 if (ret == NERR_Success)
77 {
78 /* INFO_100 structure is a subset of INFO_101 */
79 PSERVER_INFO_101 info = (PSERVER_INFO_101)*bufptr;
80 OSVERSIONINFOW verInfo;
81
82 info->sv101_platform_id = PLATFORM_ID_NT;
83 info->sv101_name = (LMSTR)(*bufptr + sizeof(SERVER_INFO_101));
84 memcpy(info->sv101_name, computerName,
85 computerNameLen * sizeof(WCHAR));
86 verInfo.dwOSVersionInfoSize = sizeof(verInfo);
87 GetVersionExW(&verInfo);
88 info->sv101_version_major = verInfo.dwMajorVersion;
89 info->sv101_version_minor = verInfo.dwMinorVersion;
90 /* Use generic type as no wine equivalent of DC / Server */
91 info->sv101_type = SV_TYPE_NT;
92 info->sv101_comment = NULL;
93 }
94 break;
95 }
96
97 default:
98 FIXME("level %d unimplemented\n", level);
99 ret = ERROR_INVALID_LEVEL;
100 }
101 return ret;
102 }
103