mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 13:26:17 +00:00
[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 svn path=/trunk/; revision=72088
This commit is contained in:
parent
0549e22a98
commit
e3e7dd3331
4 changed files with 196 additions and 2 deletions
|
@ -10,12 +10,13 @@ list(APPEND SOURCE
|
||||||
cmdPause.c
|
cmdPause.c
|
||||||
cmdStart.c
|
cmdStart.c
|
||||||
cmdStop.c
|
cmdStop.c
|
||||||
|
cmdUse.c
|
||||||
cmdUser.c
|
cmdUser.c
|
||||||
help.c
|
help.c
|
||||||
net.h)
|
net.h)
|
||||||
|
|
||||||
add_executable(net ${SOURCE} net.rc)
|
add_executable(net ${SOURCE} net.rc)
|
||||||
set_module_type(net win32cui UNICODE)
|
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_pch(net net.h SOURCE)
|
||||||
add_cd_file(TARGET net DESTINATION reactos/system32 FOR all)
|
add_cd_file(TARGET net DESTINATION reactos/system32 FOR all)
|
||||||
|
|
191
reactos/base/applications/network/net/cmdUse.c
Normal file
191
reactos/base/applications/network/net/cmdUse.c
Normal file
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,7 +39,7 @@ COMMAND cmds[] =
|
||||||
{L"statistics", unimplemented},
|
{L"statistics", unimplemented},
|
||||||
{L"stop", cmdStop},
|
{L"stop", cmdStop},
|
||||||
{L"time", unimplemented},
|
{L"time", unimplemented},
|
||||||
{L"use", unimplemented},
|
{L"use", cmdUse},
|
||||||
{L"user", cmdUser},
|
{L"user", cmdUser},
|
||||||
{L"view", unimplemented},
|
{L"view", unimplemented},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <wincon.h>
|
#include <wincon.h>
|
||||||
#include <winuser.h>
|
#include <winuser.h>
|
||||||
#include <winsvc.h>
|
#include <winsvc.h>
|
||||||
|
#include <winnetwk.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
@ -66,6 +67,7 @@ INT cmdLocalGroup(INT argc, WCHAR **argv);
|
||||||
INT cmdPause(INT argc, WCHAR **argv);
|
INT cmdPause(INT argc, WCHAR **argv);
|
||||||
INT cmdStart(INT argc, WCHAR **argv);
|
INT cmdStart(INT argc, WCHAR **argv);
|
||||||
INT cmdStop(INT argc, WCHAR **argv);
|
INT cmdStop(INT argc, WCHAR **argv);
|
||||||
|
INT cmdUse(INT argc, WCHAR **argv);
|
||||||
INT cmdUser(INT argc, WCHAR **argv);
|
INT cmdUser(INT argc, WCHAR **argv);
|
||||||
|
|
||||||
#endif /* _NET_PCH_ */
|
#endif /* _NET_PCH_ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue