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