ReactOS  0.4.12-dev-721-g03c3dd5
cmdUse.c File Reference
#include "net.h"
Include dependency graph for cmdUse.c:

Go to the source code of this file.

Functions

static DWORD EnumerateConnections (LPCWSTR Local)
 
static VOID PrintError (DWORD Status)
 
static BOOL ValidateDeviceName (PWSTR DevName)
 
INT cmdUse (INT argc, WCHAR **argv)
 

Function Documentation

◆ cmdUse()

INT cmdUse ( INT  argc,
WCHAR **  argv 
)

Definition at line 102 of file cmdUse.c.

105 {
107 
108  if (argc == 2)
109  {
111  if (Status == NO_ERROR)
113  else
115 
116  return 0;
117  }
118  else if (argc == 3)
119  {
120  if (!ValidateDeviceName(argv[2]))
121  {
123  return 1;
124  }
125 
127  if (Status == NO_ERROR)
129  else
131 
132  return 0;
133  }
134 
135  Delete = 0;
136  if (wcsicmp(argv[2], L"/DELETE") == 0)
137  {
138  Delete = 3;
139  }
140  else
141  {
142  if ((argv[2][0] != '*' && argv[2][1] != 0) &&
144  {
146  return 1;
147  }
148  }
149 
150  if (wcsicmp(argv[3], L"/DELETE") == 0)
151  {
152  Delete = 2;
153  }
154 
155  if (Delete != 0)
156  {
157  if (!ValidateDeviceName(argv[Delete]) || argv[Delete][0] == L'*')
158  {
160  return 1;
161  }
162 
164  if (Status != NO_ERROR)
166 
167  return Status;
168  }
169  else
170  {
171  BOOL Persist = FALSE;
172  NETRESOURCE lpNet;
173  WCHAR Access[256];
174  DWORD OutFlags = 0, Size = ARRAYSIZE(Access);
175 
176  Len = wcslen(argv[3]);
177  if (Len < 4)
178  {
180  return 1;
181  }
182 
183  if (argv[3][0] != L'\\' || argv[3][1] != L'\\')
184  {
186  return 1;
187  }
188 
189  if (argc > 4)
190  {
191  LPWSTR Cpy;
192  Len = wcslen(argv[4]);
193  if (Len > 12)
194  {
195  Cpy = HeapAlloc(GetProcessHeap(), 0, (Len + 1) * sizeof(WCHAR));
196  if (Cpy)
197  {
198  INT i;
199  for (i = 0; i < Len; ++i)
200  Cpy[i] = towupper(argv[4][i]);
201 
202  if (wcsstr(Cpy, L"/PERSISTENT:") == Cpy)
203  {
204  LPWSTR Arg = Cpy + 12;
205  if (Len == 14 && Arg[0] == 'N' && Arg[1] == 'O')
206  {
207  Persist = FALSE;
208  }
209  else if (Len == 15 && Arg[0] == 'Y' && Arg[1] == 'E' && Arg[2] == 'S')
210  {
211  Persist = TRUE;
212  }
213  else
214  {
215  HeapFree(GetProcessHeap(), 0, Cpy);
217  return 1;
218  }
219  }
220  HeapFree(GetProcessHeap(), 0, Cpy);
221  }
222  }
223 
224  }
225 
226  lpNet.dwType = RESOURCETYPE_DISK;
227  lpNet.lpLocalName = (argv[2][0] != L'*') ? argv[2] : NULL;
228  lpNet.lpRemoteName = argv[3];
229  lpNet.lpProvider = NULL;
230 
231  Status = WNetUseConnection(NULL, &lpNet, NULL, NULL, CONNECT_REDIRECT | (Persist ? CONNECT_UPDATE_PROFILE : 0), Access, &Size, &OutFlags);
232  if (argv[2][0] == L'*' && Status == NO_ERROR && OutFlags == CONNECT_LOCALDRIVE)
234  else if (Status != NO_ERROR)
236 
237  return Status;
238  }
239 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
DWORD dwType
Definition: winnetwk.h:168
#define CONNECT_UPDATE_PROFILE
Definition: winnetwk.h:87
#define ERROR_SUCCESS
Definition: deptool.c:10
__wchar_t WCHAR
Definition: xmlstorage.h:180
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
#define WNetCancelConnection2
Definition: winnetwk.h:607
#define IDS_ERROR_INVALID_OPTION_VALUE
Definition: resource.h:122
LPSTR lpLocalName
Definition: winnetwk.h:171
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define WNetUseConnection
Definition: winnetwk.h:609
#define argv
Definition: mplay32.c:18
#define NO_ERROR
Definition: dderror.h:5
int32_t INT
Definition: typedefs.h:56
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
static IPersist Persist
Definition: atl.c:503
smooth NULL
Definition: ftsmooth.c:416
LPSTR lpProvider
Definition: winnetwk.h:174
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
static DWORD EnumerateConnections(LPCWSTR Local)
Definition: cmdUse.c:14
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define CONNECT_REDIRECT
Definition: winnetwk.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
static VOID PrintError(DWORD Status)
Definition: cmdUse.c:68
#define Len
Definition: deflate.h:82
#define StdErr
Definition: stream.h:77
static const WCHAR L[]
Definition: oid.c:1250
#define IDS_USE_NOW_CONNECTED
Definition: resource.h:109
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define wcsicmp
Definition: string.h:1152
#define RESOURCETYPE_DISK
Definition: winnetwk.h:64
Status
Definition: gdiplustypes.h:24
static BOOL ValidateDeviceName(PWSTR DevName)
Definition: cmdUse.c:83
static VOID PrintErrorMessage(DWORD dwError)
Definition: at.c:308
LPSTR lpRemoteName
Definition: winnetwk.h:172
#define CONNECT_LOCALDRIVE
Definition: winnetwk.h:95
#define StdOut
Definition: stream.h:76
#define towupper(c)
Definition: wctype.h:99
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BOOL Delete(LPCTSTR ServiceName)
Definition: delete.c:12
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394

◆ EnumerateConnections()

static DWORD EnumerateConnections ( LPCWSTR  Local)
static

Definition at line 14 of file cmdUse.c.

15 {
16  DWORD dRet;
17  HANDLE hEnum;
18  LPNETRESOURCE lpRes;
19  DWORD dSize = 0x1000;
20  DWORD dCount = -1;
21  LPNETRESOURCE lpCur;
22 
23  ConPrintf(StdOut, L"%s\t\t\t%s\t\t\t\t%s\n", L"Local", L"Remote", L"Provider");
24 
26  if (dRet != WN_SUCCESS)
27  {
28  return 1;
29  }
30 
31  lpRes = HeapAlloc(GetProcessHeap(), 0, dSize);
32  if (!lpRes)
33  {
34  WNetCloseEnum(hEnum);
35  return 1;
36  }
37 
38  do
39  {
40  dSize = 0x1000;
41  dCount = -1;
42 
43  memset(lpRes, 0, dSize);
44  dRet = WNetEnumResource(hEnum, &dCount, lpRes, &dSize);
45  if (dRet == WN_SUCCESS || dRet == WN_MORE_DATA)
46  {
47  lpCur = lpRes;
48  for (; dCount; dCount--)
49  {
50  if (!Local || wcsicmp(lpCur->lpLocalName, Local) == 0)
51  {
52  ConPrintf(StdOut, L"%s\t\t\t%s\t\t%s\n", lpCur->lpLocalName, lpCur->lpRemoteName, lpCur->lpProvider);
53  }
54 
55  lpCur++;
56  }
57  }
58  } while (dRet != WN_NO_MORE_ENTRIES);
59 
60  HeapFree(GetProcessHeap(), 0, lpRes);
61  WNetCloseEnum(hEnum);
62 
63  return 0;
64 }
#define WN_SUCCESS
Definition: winnetwk.h:111
LPSTR lpLocalName
Definition: winnetwk.h:171
#define RESOURCE_CONNECTED
Definition: winnetwk.h:58
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
smooth NULL
Definition: ftsmooth.c:416
LPSTR lpProvider
Definition: winnetwk.h:174
#define WNetOpenEnum
Definition: winnetwk.h:598
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
DWORD WINAPI WNetCloseEnum(HANDLE hEnum)
Definition: wnet.c:1621
#define wcsicmp
Definition: string.h:1152
#define WNetEnumResource
Definition: winnetwk.h:599
#define RESOURCETYPE_DISK
Definition: winnetwk.h:64
#define WN_NO_MORE_ENTRIES
Definition: winnetwk.h:146
LPSTR lpRemoteName
Definition: winnetwk.h:172
#define StdOut
Definition: stream.h:76
#define WN_MORE_DATA
Definition: winnetwk.h:117
#define memset(x, y, z)
Definition: compat.h:39
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by cmdUse().

◆ PrintError()

static VOID PrintError ( DWORD  Status)
static

Definition at line 68 of file cmdUse.c.

69 {
70  LPWSTR Buffer;
71 
73 
75  {
76  ConPrintf(StdErr, L"\n%s", Buffer);
78  }
79 }
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
#define StdErr
Definition: stream.h:77
#define FormatMessage
Definition: winbase.h:3609
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
#define IDS_ERROR_SYSTEM_ERROR
Definition: resource.h:123
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:401
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
WCHAR * LPWSTR
Definition: xmlstorage.h:184
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by cmdUse().

◆ ValidateDeviceName()

static BOOL ValidateDeviceName ( PWSTR  DevName)
static

Definition at line 83 of file cmdUse.c.

84 {
85  DWORD Len;
86 
87  Len = wcslen(DevName);
88  if (Len != 2)
89  {
90  return FALSE;
91  }
92 
93  if (!iswalpha(DevName[0]) || DevName[1] != L':')
94  {
95  return FALSE;
96  }
97 
98  return TRUE;
99 }
#define TRUE
Definition: types.h:120
#define iswalpha(_c)
Definition: ctype.h:664
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
static const WCHAR L[]
Definition: oid.c:1250
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by cmdUse().