Author: pschweitzer
Date: Tue Aug 2 10:10:25 2016
New Revision: 72088
URL:
http://svn.reactos.org/svn/reactos?rev=72088&view=rev
Log:
[NET]
Implement the "net use" usage of the net command.
This allows connecting remote resources to local system with assigning them a local name,
to enumerate such connected resources and to delete them.
This obsoletes the hackssign application.
The implementation is a bit... raw. It is mainly here to demonstrate what's doable in
ReactOS now. And to help using features we were lacking up to now.
For instance, you can make use of 'net use * \\vmware-host\Shared
Folders\{YOURSHARE}' to assign a local letter to your VMware shared folders.
ROSAPPS-303
Added:
trunk/reactos/base/applications/network/net/cmdUse.c (with props)
Modified:
trunk/reactos/base/applications/network/net/CMakeLists.txt
trunk/reactos/base/applications/network/net/main.c
trunk/reactos/base/applications/network/net/net.h
Modified: trunk/reactos/base/applications/network/net/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/…
==============================================================================
--- trunk/reactos/base/applications/network/net/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/net/CMakeLists.txt [iso-8859-1] Tue Aug 2
10:10:25 2016
@@ -10,12 +10,13 @@
cmdPause.c
cmdStart.c
cmdStop.c
+ cmdUse.c
cmdUser.c
help.c
net.h)
add_executable(net ${SOURCE} net.rc)
set_module_type(net win32cui UNICODE)
-add_importlibs(net advapi32 netapi32 msvcrt kernel32 user32 ntdll)
+add_importlibs(net advapi32 netapi32 msvcrt kernel32 user32 ntdll mpr)
add_pch(net net.h SOURCE)
add_cd_file(TARGET net DESTINATION reactos/system32 FOR all)
Added: trunk/reactos/base/applications/network/net/cmdUse.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/…
==============================================================================
--- trunk/reactos/base/applications/network/net/cmdUse.c (added)
+++ trunk/reactos/base/applications/network/net/cmdUse.c [iso-8859-1] Tue Aug 2 10:10:25
2016
@@ -0,0 +1,191 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS net command
+ * FILE: base/applications/network/net/cmdUse.c
+ * PURPOSE:
+ *
+ * PROGRAMMERS: Pierre Schweitzer
+ */
+
+#include "net.h"
+
+static
+DWORD
+EnumerateConnections(LPCWSTR Local)
+{
+ DWORD dRet;
+ HANDLE hEnum;
+ LPNETRESOURCE lpRes;
+ DWORD dSize = 0x1000;
+ DWORD dCount = -1;
+ LPNETRESOURCE lpCur;
+
+ printf("%S\t\t\t%S\t\t\t\t%S\n", L"Local", L"Remote",
L"Provider");
+
+ dRet = WNetOpenEnum(RESOURCE_CONNECTED, RESOURCETYPE_DISK, 0, NULL, &hEnum);
+ if (dRet != WN_SUCCESS)
+ {
+ return 1;
+ }
+
+ lpRes = HeapAlloc(GetProcessHeap(), 0, dSize);
+ if (!lpRes)
+ {
+ WNetCloseEnum(hEnum);
+ return 1;
+ }
+
+ do
+ {
+ dSize = 0x1000;
+ dCount = -1;
+
+ memset(lpRes, 0, dSize);
+ dRet = WNetEnumResource(hEnum, &dCount, lpRes, &dSize);
+ if (dRet == WN_SUCCESS || dRet == WN_MORE_DATA)
+ {
+ lpCur = lpRes;
+ for (; dCount; dCount--)
+ {
+ if (!Local || wcsicmp(lpCur->lpLocalName, Local) == 0)
+ {
+ printf("%S\t\t\t%S\t\t%S\n", lpCur->lpLocalName,
lpCur->lpRemoteName, lpCur->lpProvider);
+ }
+
+ lpCur++;
+ }
+ }
+ } while (dRet != WN_NO_MORE_ENTRIES);
+
+ HeapFree(GetProcessHeap(), 0, lpRes);
+ WNetCloseEnum(hEnum);
+
+ return 0;
+}
+
+INT
+cmdUse(
+ INT argc,
+ WCHAR **argv)
+{
+ DWORD Status, Len;
+
+ if (argc == 2)
+ {
+ Status = EnumerateConnections(NULL);
+ printf("Status: %lu\n", Status);
+ return 0;
+ }
+ else if (argc == 3)
+ {
+ Len = wcslen(argv[2]);
+ if (Len != 2)
+ {
+ PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE,
L"DeviceName");
+ return 1;
+ }
+
+ if (!iswalpha(argv[2][0]) || argv[2][1] != L':')
+ {
+ PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE,
L"DeviceName");
+ return 1;
+ }
+
+ Status = EnumerateConnections(argv[2]);
+ printf("Status: %lu\n", Status);
+ return 0;
+ }
+
+ Len = wcslen(argv[2]);
+ if (Len != 1 && Len != 2)
+ {
+ PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"DeviceName");
+ printf("Len: %lu\n", Len);
+ return 1;
+ }
+
+ if (Len == 2 && argv[2][1] != L':')
+ {
+ PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"DeviceName");
+ return 1;
+ }
+
+ if (argv[2][0] != L'*' && !iswalpha(argv[2][0]))
+ {
+ PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"DeviceName");
+ return 1;
+ }
+
+ if (wcsicmp(argv[3], L"/DELETE") == 0)
+ {
+ if (argv[2][0] == L'*')
+ {
+ PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE,
L"DeviceName");
+ return 1;
+ }
+
+ return WNetCancelConnection(argv[2], FALSE);
+ }
+ else
+ {
+ BOOL Persist = FALSE;
+ NETRESOURCE lpNet;
+
+ Len = wcslen(argv[3]);
+ if (Len < 4)
+ {
+ PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"Name");
+ return 1;
+ }
+
+ if (argv[3][0] != L'\\' || argv[3][1] != L'\\')
+ {
+ PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"Name");
+ return 1;
+ }
+
+ if (argc > 4)
+ {
+ LPWSTR Cpy;
+ Len = wcslen(argv[4]);
+ if (Len > 12)
+ {
+ Cpy = HeapAlloc(GetProcessHeap(), 0, (Len + 1) * sizeof(WCHAR));
+ if (Cpy)
+ {
+ INT i;
+ for (i = 0; i < Len; ++i)
+ Cpy[i] = towupper(argv[4][i]);
+
+ if (wcsstr(Cpy, L"/PERSISTENT:") == Cpy)
+ {
+ LPWSTR Arg = Cpy + 12;
+ if (Len == 14 && Arg[0] == 'N' && Arg[1]
== 'O')
+ {
+ Persist = FALSE;
+ }
+ else if (Len == 15 && Arg[0] == 'Y' &&
Arg[1] == 'E' && Arg[2] == 'S')
+ {
+ Persist = TRUE;
+ }
+ else
+ {
+ HeapFree(GetProcessHeap(), 0, Cpy);
+ PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE,
L"Persistent");
+ return 1;
+ }
+ }
+ HeapFree(GetProcessHeap(), 0, Cpy);
+ }
+ }
+
+ }
+
+ lpNet.dwType = RESOURCETYPE_DISK;
+ lpNet.lpLocalName = (argv[2][0] != L'*') ? argv[2] : NULL;
+ lpNet.lpRemoteName = argv[3];
+ lpNet.lpProvider = NULL;
+
+ return WNetAddConnection2(&lpNet, NULL, NULL, CONNECT_REDIRECT | (Persist ?
CONNECT_UPDATE_PROFILE : 0));
+ }
+}
Propchange: trunk/reactos/base/applications/network/net/cmdUse.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/base/applications/network/net/main.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/…
==============================================================================
--- trunk/reactos/base/applications/network/net/main.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/net/main.c [iso-8859-1] Tue Aug 2 10:10:25
2016
@@ -39,7 +39,7 @@
{L"statistics", unimplemented},
{L"stop", cmdStop},
{L"time", unimplemented},
- {L"use", unimplemented},
+ {L"use", cmdUse},
{L"user", cmdUser},
{L"view", unimplemented},
{NULL, NULL}
Modified: trunk/reactos/base/applications/network/net/net.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/…
==============================================================================
--- trunk/reactos/base/applications/network/net/net.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/net/net.h [iso-8859-1] Tue Aug 2 10:10:25
2016
@@ -17,6 +17,7 @@
#include <wincon.h>
#include <winuser.h>
#include <winsvc.h>
+#include <winnetwk.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
@@ -66,6 +67,7 @@
INT cmdPause(INT argc, WCHAR **argv);
INT cmdStart(INT argc, WCHAR **argv);
INT cmdStop(INT argc, WCHAR **argv);
+INT cmdUse(INT argc, WCHAR **argv);
INT cmdUser(INT argc, WCHAR **argv);
#endif /* _NET_PCH_ */