ReactOS 0.4.16-dev-297-gc569aee
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 104 of file cmdUse.c.

107{
109
110 if (argc == 2)
111 {
113 if (Status == NO_ERROR)
115 else
117
118 return 0;
119 }
120 else if (argc == 3)
121 {
122 if (!ValidateDeviceName(argv[2]))
123 {
124 PrintMessageStringV(3952, L"DeviceName");
125 return 1;
126 }
127
129 if (Status == NO_ERROR)
131 else
133
134 return 0;
135 }
136
137 Delete = 0;
138 if (_wcsicmp(argv[2], L"/DELETE") == 0)
139 {
140 Delete = 3;
141 }
142 else
143 {
144 if ((argv[2][0] != '*' && argv[2][1] != 0) &&
146 {
147 PrintMessageStringV(3952, L"DeviceName");
148 return 1;
149 }
150 }
151
152 if (_wcsicmp(argv[3], L"/DELETE") == 0)
153 {
154 Delete = 2;
155 }
156
157 if (Delete != 0)
158 {
159 if (!ValidateDeviceName(argv[Delete]) || argv[Delete][0] == L'*')
160 {
161 PrintMessageStringV(3952, L"DeviceName");
162 return 1;
163 }
164
166 if (Status != NO_ERROR)
168
169 return Status;
170 }
171 else
172 {
174 NETRESOURCE lpNet;
175 WCHAR Access[256];
176 DWORD OutFlags = 0, Size = ARRAYSIZE(Access);
177
178 Len = wcslen(argv[3]);
179 if (Len < 4)
180 {
181 PrintMessageStringV(3952, L"Name");
182 return 1;
183 }
184
185 if (argv[3][0] != L'\\' || argv[3][1] != L'\\')
186 {
187 PrintMessageStringV(3952, L"Name");
188 return 1;
189 }
190
191 if (argc > 4)
192 {
193 LPWSTR Cpy;
194 Len = wcslen(argv[4]);
195 if (Len > 12)
196 {
197 Cpy = HeapAlloc(GetProcessHeap(), 0, (Len + 1) * sizeof(WCHAR));
198 if (Cpy)
199 {
200 INT i;
201 for (i = 0; i < Len; ++i)
202 Cpy[i] = towupper(argv[4][i]);
203
204 if (wcsstr(Cpy, L"/PERSISTENT:") == Cpy)
205 {
206 LPWSTR Arg = Cpy + 12;
207 if (Len == 14 && Arg[0] == 'N' && Arg[1] == 'O')
208 {
209 Persist = FALSE;
210 }
211 else if (Len == 15 && Arg[0] == 'Y' && Arg[1] == 'E' && Arg[2] == 'S')
212 {
213 Persist = TRUE;
214 }
215 else
216 {
217 HeapFree(GetProcessHeap(), 0, Cpy);
218 PrintMessageStringV(3952, L"Persistent");
219 return 1;
220 }
221 }
222 HeapFree(GetProcessHeap(), 0, Cpy);
223 }
224 }
225
226 }
227
229 lpNet.lpLocalName = (argv[2][0] != L'*') ? argv[2] : NULL;
230 lpNet.lpRemoteName = argv[3];
231 lpNet.lpProvider = NULL;
232
233 Status = WNetUseConnection(NULL, &lpNet, NULL, NULL, CONNECT_REDIRECT | (Persist ? CONNECT_UPDATE_PROFILE : 0), Access, &Size, &OutFlags);
234 if (argv[2][0] == L'*' && Status == NO_ERROR && OutFlags == CONNECT_LOCALDRIVE)
235 PrintMessageStringV(3919, argv[3], Access);
236 else if (Status != NO_ERROR)
238
239 return Status;
240 }
241}
static int argc
Definition: ServiceArgs.c:12
static VOID PrintErrorMessage(DWORD dwError)
Definition: at.c:308
VOID PrintMessageStringV(DWORD dwMessage,...)
Definition: main.c:93
BOOL Delete(LPCTSTR ServiceName)
Definition: delete.c:12
static DWORD EnumerateConnections(LPCWSTR Local)
Definition: cmdUse.c:14
static VOID PrintError(DWORD Status)
Definition: cmdUse.c:68
static BOOL ValidateDeviceName(PWSTR DevName)
Definition: cmdUse.c:85
#define NO_ERROR
Definition: dderror.h:5
#define Len
Definition: deflate.h:82
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
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
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
static IPersist Persist
Definition: atl.c:503
#define argv
Definition: mplay32.c:18
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
LPSTR lpLocalName
Definition: winnetwk.h:171
LPSTR lpProvider
Definition: winnetwk.h:174
LPSTR lpRemoteName
Definition: winnetwk.h:172
DWORD dwType
Definition: winnetwk.h:168
#define towupper(c)
Definition: wctype.h:99
int32_t INT
Definition: typedefs.h:58
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define CONNECT_REDIRECT
Definition: winnetwk.h:94
#define CONNECT_UPDATE_PROFILE
Definition: winnetwk.h:87
#define RESOURCETYPE_DISK
Definition: winnetwk.h:64
#define CONNECT_LOCALDRIVE
Definition: winnetwk.h:95
#define WNetUseConnection
Definition: winnetwk.h:609
#define WNetCancelConnection2
Definition: winnetwk.h:607
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ 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}
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
#define memset(x, y, z)
Definition: compat.h:39
#define RESOURCE_CONNECTED
Definition: winnetwk.h:58
#define WN_MORE_DATA
Definition: winnetwk.h:117
#define WN_SUCCESS
Definition: winnetwk.h:111
#define WNetEnumResource
Definition: winnetwk.h:599
#define WNetOpenEnum
Definition: winnetwk.h:598
#define WN_NO_MORE_ENTRIES
Definition: winnetwk.h:146
DWORD WINAPI WNetCloseEnum(HANDLE hEnum)
Definition: wnet.c:1762

Referenced by cmdUse().

◆ PrintError()

static VOID PrintError ( DWORD  Status)
static

Definition at line 68 of file cmdUse.c.

69{
70 WCHAR szStatusBuffer[16];
72
73 swprintf(szStatusBuffer, L"%lu", Status);
74 PrintMessageStringV(3502, szStatusBuffer);
75
77 {
78 ConPrintf(StdErr, L"\n%s", Buffer);
80 }
81}
#define StdErr
Definition: fc.c:15
Definition: bufpool.h:45
#define swprintf
Definition: precomp.h:40
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define FormatMessage
Definition: winbase.h:3820
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:446
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:449
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:445

Referenced by cmdUse().

◆ ValidateDeviceName()

static BOOL ValidateDeviceName ( PWSTR  DevName)
static

Definition at line 85 of file cmdUse.c.

86{
87 DWORD Len;
88
89 Len = wcslen(DevName);
90 if (Len != 2)
91 {
92 return FALSE;
93 }
94
95 if (!iswalpha(DevName[0]) || DevName[1] != L':')
96 {
97 return FALSE;
98 }
99
100 return TRUE;
101}
#define iswalpha(_c)
Definition: ctype.h:664

Referenced by cmdUse().