ReactOS 0.4.16-dev-746-g329a414
wksta.c
Go to the documentation of this file.
1/* Copyright 2002 Andriy Palamarchuk
2 * Copyright (c) 2003 Juan Lang
3 *
4 * netapi32 user functions
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include "netapi32.h"
22
23#include <lmwksta.h>
24#include <lmjoin.h>
25
27
28/************************************************************
29 * NETAPI_IsLocalComputer
30 *
31 * Checks whether the server name indicates local machine.
32 */
34{
36 DWORD size = sizeof(buf) / sizeof(buf[0]);
37 BOOL ret;
38
39 if (!name || !name[0]) return TRUE;
40
42 if (ret && name[0] == '\\' && name[1] == '\\') name += 2;
43 return ret && !strcmpiW( name, buf );
44}
45
46static void wprint_mac(WCHAR* buffer, int len, const MIB_IFROW *ifRow)
47{
48 int i;
49 unsigned char val;
50
51 if (!buffer)
52 return;
53 if (len < 1)
54 return;
55 if (!ifRow)
56 {
57 *buffer = '\0';
58 return;
59 }
60
61 for (i = 0; i < ifRow->dwPhysAddrLen && 2 * i < len; i++)
62 {
63 val = ifRow->bPhysAddr[i];
64 if ((val >>4) >9)
65 buffer[2*i] = (WCHAR)((val >>4) + 'A' - 10);
66 else
67 buffer[2*i] = (WCHAR)((val >>4) + '0');
68 if ((val & 0xf ) >9)
69 buffer[2*i+1] = (WCHAR)((val & 0xf) + 'A' - 10);
70 else
71 buffer[2*i+1] = (WCHAR)((val & 0xf) + '0');
72 }
73 buffer[2*i]=0;
74}
75
76/* Theoretically this could be too short, except that MS defines
77 * MAX_ADAPTER_NAME as 128, and MAX_INTERFACE_NAME_LEN as 256, and both
78 * represent a count of WCHARs, so even with an extraordinarily long header
79 * this will be plenty
80 */
81#define MAX_TRANSPORT_NAME MAX_INTERFACE_NAME_LEN
82#define MAX_TRANSPORT_ADDR 13
83
84#define NBT_TRANSPORT_NAME_HEADER "\\Device\\NetBT_Tcpip_"
85#define UNKNOWN_TRANSPORT_NAME_HEADER "\\Device\\UnknownTransport_"
86
87static void wprint_name(WCHAR *buffer, int len, ULONG transport,
88 PMIB_IFROW ifRow)
89{
90 WCHAR *ptr1, *ptr2;
91 const char *name;
92
93 if (!buffer)
94 return;
95 if (!ifRow)
96 {
97 *buffer = '\0';
98 return;
99 }
100
101 if (!memcmp(&transport, TRANSPORT_NBT, sizeof(ULONG)))
103 else
105
106 for (ptr1 = buffer; *name && ptr1 < buffer + len; ptr1++, name++)
107 *ptr1 = *name;
108 for (ptr2 = ifRow->wszName; *ptr2 && ptr1 < buffer + len; ptr1++, ptr2++)
109 *ptr1 = *ptr2;
110 *ptr1 = '\0';
111}
112
113/***********************************************************************
114 * NetWkstaTransportEnum (NETAPI32.@)
115 */
116
118{
124};
125
126/**********************************************************************/
127
128static BOOL WkstaEnumAdaptersCallback(UCHAR totalLANAs, UCHAR lanaIndex,
129 ULONG transport, const NetBIOSAdapterImpl *data, void *closure)
130{
131 BOOL ret;
132 struct WkstaTransportEnumData *enumData = closure;
133
134 if (enumData && enumData->pbuf)
135 {
136 if (lanaIndex == 0)
137 {
138 DWORD toAllocate;
139
140 enumData->n_adapt = totalLANAs;
141 enumData->n_read = 0;
142
143 toAllocate = totalLANAs * (sizeof(WKSTA_TRANSPORT_INFO_0)
144 + MAX_TRANSPORT_NAME * sizeof(WCHAR) +
145 MAX_TRANSPORT_ADDR * sizeof(WCHAR));
146 if (enumData->prefmaxlen != MAX_PREFERRED_LENGTH)
147 toAllocate = enumData->prefmaxlen;
148 NetApiBufferAllocate(toAllocate, (LPVOID *)enumData->pbuf);
149 }
150 if (*(enumData->pbuf))
151 {
152 UCHAR spaceFor;
153
154 if (enumData->prefmaxlen == MAX_PREFERRED_LENGTH)
155 spaceFor = totalLANAs;
156 else
157 spaceFor = enumData->prefmaxlen /
159 MAX_TRANSPORT_ADDR) * sizeof(WCHAR));
160 if (enumData->n_read < spaceFor)
161 {
163 LMSTR transport_name, transport_addr;
164 MIB_IFROW ifRow;
165
166 ti = (PWKSTA_TRANSPORT_INFO_0)(*(enumData->pbuf) +
167 enumData->n_read * sizeof(WKSTA_TRANSPORT_INFO_0));
168 transport_name = (LMSTR)(*(enumData->pbuf) +
169 totalLANAs * sizeof(WKSTA_TRANSPORT_INFO_0) +
170 enumData->n_read * MAX_TRANSPORT_NAME * sizeof(WCHAR));
171 transport_addr = (LMSTR)(*(enumData->pbuf) +
172 totalLANAs * (sizeof(WKSTA_TRANSPORT_INFO_0) +
173 MAX_TRANSPORT_NAME * sizeof(WCHAR)) +
174 enumData->n_read * MAX_TRANSPORT_ADDR * sizeof(WCHAR));
175
176 ifRow.dwIndex = data->ifIndex;
177 GetIfEntry(&ifRow);
179 ti->wkti0_number_of_vcs = 0;
180 ti->wkti0_transport_name = transport_name;
182 transport, &ifRow);
183 ti->wkti0_transport_address = transport_addr;
185 &ifRow);
186 if (!memcmp(&transport, TRANSPORT_NBT, sizeof(ULONG)))
187 ti->wkti0_wan_ish = TRUE;
188 else
189 ti->wkti0_wan_ish = FALSE;
190 TRACE("%d of %d:ti at %p\n", lanaIndex, totalLANAs, ti);
191 TRACE("transport_name at %p %s\n",
194 TRACE("transport_address at %p %s\n",
197 enumData->n_read++;
198 enumData->ret = NERR_Success;
199 ret = TRUE;
200 }
201 else
202 {
203 enumData->ret = ERROR_MORE_DATA;
204 ret = FALSE;
205 }
206 }
207 else
208 {
209 enumData->ret = ERROR_OUTOFMEMORY;
210 ret = FALSE;
211 }
212 }
213 else
214 ret = FALSE;
215 return ret;
216}
217
218/**********************************************************************/
219
222 DWORD prefmaxlen, LPDWORD read_entries,
223 PDWORD total_entries, PDWORD hresume)
224{
226
227 TRACE(":%s, 0x%08x, %p, 0x%08x, %p, %p, %p\n", debugstr_w(ServerName),
228 level, pbuf, prefmaxlen, read_entries, total_entries,hresume);
229 if (!NETAPI_IsLocalComputer(ServerName))
230 {
231 FIXME(":not implemented for non-local computers\n");
233 }
234 else
235 {
236 if (hresume && *hresume)
237 {
238 FIXME(":resume handle not implemented\n");
239 return ERROR_INVALID_LEVEL;
240 }
241
242 switch (level)
243 {
244 case 0: /* transport info */
245 {
246 ULONG allTransports;
247 struct WkstaTransportEnumData enumData;
248
249 if (NetBIOSNumAdapters() == 0)
251 if (!read_entries)
253 if (!total_entries || !pbuf)
255
256 enumData.prefmaxlen = prefmaxlen;
257 enumData.pbuf = pbuf;
258 memcpy(&allTransports, ALL_TRANSPORTS, sizeof(ULONG));
260 &enumData);
261 *read_entries = enumData.n_read;
262 *total_entries = enumData.n_adapt;
263 if (hresume) *hresume= 0;
264 ret = enumData.ret;
265 break;
266 }
267 default:
268 TRACE("Invalid level %d is specified\n", level);
270 }
271 }
272 return ret;
273}
274
275
276/************************************************************
277 * NetpGetComputerName (NETAPI32.@)
278 */
280{
282
283 TRACE("(%p)\n", Buffer);
286 {
288 *Buffer, (dwSize + 1) * sizeof(WCHAR),
289 (LPVOID *) Buffer);
290 }
291 else
292 {
295 }
296}
297
299 LPVOID p4, LPVOID p5)
300{
301 FIXME("(%p %s %s %p %p): stub\n", p1, debugstr_w(wkgrp), debugstr_w(comp),
302 p4, p5);
304}
305
307 LPVOID p4)
308{
309 FIXME("(%p %s %p %p): stub\n", p1, debugstr_w(wkgrp), p3, p4);
311}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: precomp.h:53
Definition: bufpool.h:45
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define DECLSPEC_HIDDEN
Definition: precomp.h:8
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
NET_API_STATUS WINAPI NetApiBufferAllocate(DWORD ByteCount, LPVOID *Buffer)
Definition: apibuf.c:28
NET_API_STATUS WINAPI NetApiBufferReallocate(LPVOID OldBuffer, DWORD NewByteCount, LPVOID *NewBuffer)
Definition: apibuf.c:53
UCHAR NetBIOSNumAdapters(void)
Definition: netbios.c:284
void NetBIOSEnumAdapters(ULONG transport, NetBIOSEnumAdaptersCallback cb, void *closure)
Definition: netbios.c:296
static void wprint_name(WCHAR *buffer, int len, ULONG transport, PMIB_IFROW ifRow)
Definition: wksta.c:87
NET_API_STATUS WINAPI NetpGetComputerName(LPWSTR *Buffer)
Definition: wksta.c:279
#define MAX_TRANSPORT_ADDR
Definition: wksta.c:82
static void wprint_mac(WCHAR *buffer, int len, const MIB_IFROW *ifRow)
Definition: wksta.c:46
#define UNKNOWN_TRANSPORT_NAME_HEADER
Definition: wksta.c:85
DECLSPEC_HIDDEN BOOL NETAPI_IsLocalComputer(LMCSTR name)
Definition: wksta.c:33
NET_API_STATUS WINAPI I_NetNameCompare(LPVOID p1, LPWSTR wkgrp, LPWSTR comp, LPVOID p4, LPVOID p5)
Definition: wksta.c:298
#define MAX_TRANSPORT_NAME
Definition: wksta.c:81
#define NBT_TRANSPORT_NAME_HEADER
Definition: wksta.c:84
static BOOL WkstaEnumAdaptersCallback(UCHAR totalLANAs, UCHAR lanaIndex, ULONG transport, const NetBIOSAdapterImpl *data, void *closure)
Definition: wksta.c:128
NET_API_STATUS WINAPI NetWkstaTransportEnum(LMSTR ServerName, DWORD level, PBYTE *pbuf, DWORD prefmaxlen, LPDWORD read_entries, PDWORD total_entries, PDWORD hresume)
Definition: wksta.c:221
NET_API_STATUS WINAPI I_NetNameValidate(LPVOID p1, LPWSTR wkgrp, LPVOID p3, LPVOID p4)
Definition: wksta.c:306
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint level
Definition: gl.h:1546
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint GLfloat * val
Definition: glext.h:7180
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
#define debugstr_w
Definition: kernel32.h:32
#define LMSTR
Definition: lmcons.h:68
#define MAX_PREFERRED_LENGTH
Definition: lmcons.h:48
#define NERR_Success
Definition: lmerr.h:5
struct _WKSTA_TRANSPORT_INFO_0 WKSTA_TRANSPORT_INFO_0
struct _WKSTA_TRANSPORT_INFO_0 * PWKSTA_TRANSPORT_INFO_0
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
WCHAR * LMSTR
Definition: ms-dtyp.idl:119
const wchar_t * LMCSTR
Definition: ms-dtyp.idl:118
#define ALL_TRANSPORTS
Definition: nb30.h:23
#define TRANSPORT_NBT
Definition: netbios.h:173
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
BYTE * PBYTE
Definition: pedump.c:66
DWORD * PDWORD
Definition: pedump.c:68
#define strcmpiW(s1, s2)
Definition: unicode.h:45
#define TRACE(s)
Definition: solgame.cpp:4
NET_API_STATUS ret
Definition: wksta.c:123
UCHAR bPhysAddr[MAXLEN_PHYSADDR]
Definition: ifmib.h:43
WCHAR wszName[MAX_INTERFACE_NAME_LEN]
Definition: ifmib.h:37
DWORD dwPhysAddrLen
Definition: ifmib.h:42
DWORD dwIndex
Definition: ifmib.h:38
LPWSTR wkti0_transport_address
Definition: lmwksta.h:214
LPWSTR wkti0_transport_name
Definition: lmwksta.h:213
DWORD wkti0_quality_of_service
Definition: lmwksta.h:211
Definition: name.c:39
Definition: pbuf.h:186
unsigned char * LPBYTE
Definition: typedefs.h:53
uint32_t * LPDWORD
Definition: typedefs.h:59
uint32_t ULONG
Definition: typedefs.h:59
int ret
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:269
#define WINAPI
Definition: msvc.h:6
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
#define ERROR_NETWORK_UNREACHABLE
Definition: winerror.h:734
#define RPC_X_NULL_REF_POINTER
Definition: winerror.h:1087
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184