From: Pierre Schweitzer Date: Sun, 2 Jul 2017 20:39:48 +0000 (+0000) Subject: [NET] X-Git-Tag: ReactOS-0.4.6~126 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=3ff085924b815a8e3e94e8d219fb0a2d249cb8c4;ds=inline [NET] On dismount, you can either use: net use /delete : or net use : /delete CORE-13517 svn path=/trunk/; revision=75271 --- diff --git a/reactos/base/applications/network/net/cmdUse.c b/reactos/base/applications/network/net/cmdUse.c index f0f405d3c3c..59bc580a4d0 100644 --- a/reactos/base/applications/network/net/cmdUse.c +++ b/reactos/base/applications/network/net/cmdUse.c @@ -78,12 +78,32 @@ PrintError(DWORD Status) } } +static +BOOL +ValidateDeviceName(PWSTR DevName) +{ + DWORD Len; + + Len = wcslen(DevName); + if (Len != 2) + { + return FALSE; + } + + if (!iswalpha(DevName[0]) || DevName[1] != L':') + { + return FALSE; + } + + return TRUE; +} + INT cmdUse( INT argc, WCHAR **argv) { - DWORD Status, Len; + DWORD Status, Len, Delete; if (argc == 2) { @@ -97,14 +117,7 @@ cmdUse( } else if (argc == 3) { - Len = wcslen(argv[2]); - if (Len != 2) - { - ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"DeviceName"); - return 1; - } - - if (!iswalpha(argv[2][0]) || argv[2][1] != L':') + if (!ValidateDeviceName(argv[2])) { ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"DeviceName"); return 1; @@ -119,34 +132,39 @@ cmdUse( return 0; } - Len = wcslen(argv[2]); - if (Len != 1 && Len != 2) + Delete = 0; + if (wcsicmp(argv[2], L"/DELETE") == 0) { - ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"DeviceName"); - return 1; + Delete = 3; } - - if (Len == 2 && argv[2][1] != L':') + else { - ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"DeviceName"); - return 1; + if ((argv[2][0] != '*' && argv[2][1] != 0) && + !ValidateDeviceName(argv[2])) + { + ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"DeviceName"); + return 1; + } } - if (argv[2][0] != L'*' && !iswalpha(argv[2][0])) + if (wcsicmp(argv[3], L"/DELETE") == 0) { - ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"DeviceName"); - return 1; + Delete = 2; } - if (wcsicmp(argv[3], L"/DELETE") == 0) + if (Delete != 0) { - if (argv[2][0] == L'*') + if (!ValidateDeviceName(argv[Delete]) || argv[Delete][0] == L'*') { ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"DeviceName"); return 1; } - return WNetCancelConnection2(argv[2], CONNECT_UPDATE_PROFILE, FALSE); + Status = WNetCancelConnection2(argv[Delete], CONNECT_UPDATE_PROFILE, FALSE); + if (Status != NO_ERROR) + PrintError(Status); + + return Status; } else {