mirror of
https://github.com/reactos/reactos.git
synced 2025-01-04 21:38:43 +00:00
[SUBST]
- Headers reordering. - Use ARRAYSIZE. - Give the internal helper function IsSubstedDrive just the single letter of the drive to check for. - AddSubst and DeleteSubst: both take a drive string of *exactly* two characters: the drive letter and the ':' (and of course there's the NULL terminator): fix the parameter check in this regard. - AddSubst: It is possible on Windows to use the DefineDosDevice API to map a drive letter to a *file* (yes yes!!) (but the mapping made is unusable). Forbids this case in SUBST since it is not made for that. CORE-10681 svn path=/trunk/; revision=71693
This commit is contained in:
parent
6d8d3402b3
commit
38416a7c00
16 changed files with 68 additions and 44 deletions
|
@ -5,6 +5,7 @@ BEGIN
|
|||
IDS_INCORRECT_PARAMETER_COUNT "Неправилен брой ключове - %s\n"
|
||||
IDS_INVALID_PARAMETER "Неправилен брой ключове - %s\n"
|
||||
IDS_INVALID_PARAMETER2 "Недопустим ключ - %s\n"
|
||||
IDS_PATH_NOT_FOUND "Path not found - %s\n"
|
||||
IDS_DRIVE_ALREADY_SUBSTED "Устройството вече е подложено на SUBST\n"
|
||||
IDS_FAILED_WITH_ERRORCODE "Грешка номер: 0x%x: %s\n"
|
||||
IDS_USAGE "Обвързва път с име на устройство (дял).\n\n\
|
||||
|
|
|
@ -5,6 +5,7 @@ BEGIN
|
|||
IDS_INCORRECT_PARAMETER_COUNT "Falsche Anzahl an Parametern - %s\n"
|
||||
IDS_INVALID_PARAMETER "Falsche Anzahl an Parametern - %s\n"
|
||||
IDS_INVALID_PARAMETER2 "Falscher Parameter - %s\n"
|
||||
IDS_PATH_NOT_FOUND "Path not found - %s\n"
|
||||
IDS_DRIVE_ALREADY_SUBSTED "SUBST wurde hier schon ausgeführt.\n"
|
||||
IDS_FAILED_WITH_ERRORCODE "Fehlgeschlagen - Code 0x%x: %s\n"
|
||||
IDS_USAGE "Weist einem Pfad einen Laufwerksbuchstaben zu.n\n\
|
||||
|
|
|
@ -5,6 +5,7 @@ BEGIN
|
|||
IDS_INCORRECT_PARAMETER_COUNT "Incorrect number of parameters - %s\n"
|
||||
IDS_INVALID_PARAMETER "Incorrect number of parameters - %s\n"
|
||||
IDS_INVALID_PARAMETER2 "Invalid parameter - %s\n"
|
||||
IDS_PATH_NOT_FOUND "Path not found - %s\n"
|
||||
IDS_DRIVE_ALREADY_SUBSTED "Drive already SUBSTed\n"
|
||||
IDS_FAILED_WITH_ERRORCODE "Failed with error code 0x%x: %s\n"
|
||||
IDS_USAGE "Associates a path with a drive letter.\n\n\
|
||||
|
|
|
@ -5,6 +5,7 @@ BEGIN
|
|||
IDS_INCORRECT_PARAMETER_COUNT "Cantidad de parámetros incorrecta - %s\n"
|
||||
IDS_INVALID_PARAMETER "Cantidad de parámetros incorrecta - %s\n"
|
||||
IDS_INVALID_PARAMETER2 "Parámetro incorrecto - %s\n"
|
||||
IDS_PATH_NOT_FOUND "Path not found - %s\n"
|
||||
IDS_DRIVE_ALREADY_SUBSTED "Unidad ya sustituida\n"
|
||||
IDS_FAILED_WITH_ERRORCODE "Falla con código de error 0x%x: %s\n"
|
||||
IDS_USAGE "Asocia una ruta con una letra de unidad.\n\n\
|
||||
|
|
|
@ -5,8 +5,9 @@ BEGIN
|
|||
IDS_INCORRECT_PARAMETER_COUNT "Nombre incorrect de paramètres - %s\n"
|
||||
IDS_INVALID_PARAMETER "Nombre incorrect de paramètres - %s\n"
|
||||
IDS_INVALID_PARAMETER2 "Paramètre incorrect - %s\n"
|
||||
IDS_PATH_NOT_FOUND "Chemin d'accès introuvable - %s\n"
|
||||
IDS_DRIVE_ALREADY_SUBSTED "Disque déjà substitué\n"
|
||||
IDS_FAILED_WITH_ERRORCODE "Échoue avec le code d'erreur 0x%x: %s\n"
|
||||
IDS_FAILED_WITH_ERRORCODE "Échoue avec le code d'erreur 0x%x : %s\n"
|
||||
IDS_USAGE "Associe un chemin avec une lettre de lecteur.\n\n\
|
||||
SUBST [disque1: [disque2:]chemin]\n\
|
||||
SUBST disque1: /D\n\n\
|
||||
|
|
|
@ -5,6 +5,7 @@ BEGIN
|
|||
IDS_INCORRECT_PARAMETER_COUNT "Numero di parametri errato - %s\n"
|
||||
IDS_INVALID_PARAMETER "Numero di parametri errato - %s\n"
|
||||
IDS_INVALID_PARAMETER2 "Parametro errato - %s\n"
|
||||
IDS_PATH_NOT_FOUND "Path not found - %s\n"
|
||||
IDS_DRIVE_ALREADY_SUBSTED "Unità già sostituita\n"
|
||||
IDS_FAILED_WITH_ERRORCODE "Interruzione con codice di errore 0x%x: %s\n"
|
||||
IDS_USAGE "Associa un percorso ad una lettera di unità.\n\n\
|
||||
|
|
|
@ -13,6 +13,7 @@ BEGIN
|
|||
IDS_INCORRECT_PARAMETER_COUNT "Nieprawidłowa liczba parametrów - %s\n"
|
||||
IDS_INVALID_PARAMETER "Nieprawidłowy parametr - %s\n"
|
||||
IDS_INVALID_PARAMETER2 "Nieprawidłowe parametry - %s\n"
|
||||
IDS_PATH_NOT_FOUND "Path not found - %s\n"
|
||||
IDS_DRIVE_ALREADY_SUBSTED "Na tym dysku już użyto komendy SUBST\n"
|
||||
IDS_FAILED_WITH_ERRORCODE "Błąd 0x%x: %s\n"
|
||||
IDS_USAGE "Powiązuje ścieżkę z literą napędu.\n\n\
|
||||
|
|
|
@ -7,6 +7,7 @@ BEGIN
|
|||
IDS_INCORRECT_PARAMETER_COUNT "Număr eronat de parametri - %s\n"
|
||||
IDS_INVALID_PARAMETER "Număr eronat de parametri - %s\n"
|
||||
IDS_INVALID_PARAMETER2 "Parametru eronat - %s\n"
|
||||
IDS_PATH_NOT_FOUND "Path not found - %s\n"
|
||||
IDS_DRIVE_ALREADY_SUBSTED "Unitatea este deja SUBSTituită\n"
|
||||
IDS_FAILED_WITH_ERRORCODE "Operația a eșuat. Codul de eroare 0x%x: %s\n"
|
||||
IDS_USAGE "Substituie un director cu o unitate de stocare.\n\n\
|
||||
|
|
|
@ -7,6 +7,7 @@ BEGIN
|
|||
IDS_INCORRECT_PARAMETER_COUNT "Неверное число параметров - %s\n"
|
||||
IDS_INVALID_PARAMETER "Неверное число параметров - %s\n"
|
||||
IDS_INVALID_PARAMETER2 "Неверный параметр - %s\n"
|
||||
IDS_PATH_NOT_FOUND "Path not found - %s\n"
|
||||
IDS_DRIVE_ALREADY_SUBSTED "Диск уже сопоставлен\n"
|
||||
IDS_FAILED_WITH_ERRORCODE "Сбой с кодом ошибки 0x%x: %s\n"
|
||||
IDS_USAGE "Сопоставление имени диска указанному пути.\n\n\
|
||||
|
|
|
@ -9,6 +9,7 @@ BEGIN
|
|||
IDS_INCORRECT_PARAMETER_COUNT "Numri i parametrave jo i sakte - %s\n"
|
||||
IDS_INVALID_PARAMETER "Numri i parametrave jo i sakte - %s\n"
|
||||
IDS_INVALID_PARAMETER2 "Parameter i gabuar - %s\n"
|
||||
IDS_PATH_NOT_FOUND "Path not found - %s\n"
|
||||
IDS_DRIVE_ALREADY_SUBSTED "Drive tashme i SUBSTed\n"
|
||||
IDS_FAILED_WITH_ERRORCODE "Deshtoj me error kode 0x%x: %s\n"
|
||||
IDS_USAGE "Perputh rrugen e driverit me germën.\n\n\
|
||||
|
|
|
@ -7,6 +7,7 @@ BEGIN
|
|||
IDS_INCORRECT_PARAMETER_COUNT "Değişken sayısı yanlış - %s\n"
|
||||
IDS_INVALID_PARAMETER "Değişken sayısı yanlış - %s\n"
|
||||
IDS_INVALID_PARAMETER2 "Geçersiz değişken - %s\n"
|
||||
IDS_PATH_NOT_FOUND "Path not found - %s\n"
|
||||
IDS_DRIVE_ALREADY_SUBSTED "Sürücü önceden SUBST edilmiş.\n"
|
||||
IDS_FAILED_WITH_ERRORCODE "Yanlışlık kodu ile başarısız oldu 0x%x: %s\n"
|
||||
IDS_USAGE "Bir sürücü harfiyle bir yolu ilişkilendirir.\n\n\
|
||||
|
|
|
@ -7,6 +7,7 @@ BEGIN
|
|||
IDS_INCORRECT_PARAMETER_COUNT "Невірна кількість параметрів - %s\n"
|
||||
IDS_INVALID_PARAMETER "Невірна кількість параметрів - %s\n"
|
||||
IDS_INVALID_PARAMETER2 "Невірний параметр - %s\n"
|
||||
IDS_PATH_NOT_FOUND "Path not found - %s\n"
|
||||
IDS_DRIVE_ALREADY_SUBSTED "До диску вже застосовано SUBST\n"
|
||||
IDS_FAILED_WITH_ERRORCODE "Невдача з кодом помилки 0x%x: %s\n"
|
||||
IDS_USAGE "Асоціює шлях з буквою диску.\n\n\
|
||||
|
|
|
@ -7,6 +7,7 @@ BEGIN
|
|||
IDS_INCORRECT_PARAMETER_COUNT "参数个数不正确 - %s\n"
|
||||
IDS_INVALID_PARAMETER "参数个数不正确 - %s\n"
|
||||
IDS_INVALID_PARAMETER2 "无效参数 - %s\n"
|
||||
IDS_PATH_NOT_FOUND "Path not found - %s\n"
|
||||
IDS_DRIVE_ALREADY_SUBSTED "驱动器已经运行过 SUBST\n"
|
||||
IDS_FAILED_WITH_ERRORCODE "操作失败!错误码 0x%x:%s\n"
|
||||
IDS_USAGE "将一个路径用驱动器号关联。\n\n\
|
||||
|
|
|
@ -7,6 +7,7 @@ BEGIN
|
|||
IDS_INCORRECT_PARAMETER_COUNT "參數個數不正確 - %s\n"
|
||||
IDS_INVALID_PARAMETER "參數個數不正確 - %s\n"
|
||||
IDS_INVALID_PARAMETER2 "無效參數 - %s\n"
|
||||
IDS_PATH_NOT_FOUND "Path not found - %s\n"
|
||||
IDS_DRIVE_ALREADY_SUBSTED "驅動器已經運行過 SUBST\n"
|
||||
IDS_FAILED_WITH_ERRORCODE "操作失敗!錯誤碼 0x%x:%s\n"
|
||||
IDS_USAGE "將一個路徑用驅動器號關聯。\n\n\
|
||||
|
|
|
@ -8,4 +8,5 @@
|
|||
#define IDS_INCORRECT_PARAMETER_COUNT 1003
|
||||
#define IDS_INVALID_PARAMETER 1004
|
||||
#define IDS_INVALID_PARAMETER2 1005
|
||||
#define IDS_DRIVE_ALREADY_SUBSTED 1006
|
||||
#define IDS_PATH_NOT_FOUND 1006
|
||||
#define IDS_DRIVE_ALREADY_SUBSTED 1007
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
|
||||
/* INCLUDES *****************************************************************/
|
||||
|
||||
#define WIN32_NO_STATUS
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#define WIN32_NO_STATUS
|
||||
#include <windef.h>
|
||||
#include <winbase.h>
|
||||
#include <winuser.h>
|
||||
#include <stdlib.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
@ -22,7 +23,7 @@
|
|||
|
||||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
void PrintError(DWORD ErrCode)
|
||||
VOID PrintError(DWORD ErrCode)
|
||||
{
|
||||
TCHAR szFmtString[RC_STRING_MAX_SIZE] = {0};
|
||||
TCHAR *buffer = (TCHAR*) calloc(2048,
|
||||
|
@ -41,7 +42,7 @@ void PrintError(DWORD ErrCode)
|
|||
LoadString(GetModuleHandle(NULL),
|
||||
IDS_FAILED_WITH_ERRORCODE,
|
||||
szFmtString,
|
||||
sizeof(szFmtString) / sizeof(szFmtString[0]));
|
||||
ARRAYSIZE(szFmtString));
|
||||
_sntprintf(buffer,
|
||||
2048,
|
||||
szFmtString,
|
||||
|
@ -55,25 +56,25 @@ void PrintError(DWORD ErrCode)
|
|||
}
|
||||
}
|
||||
|
||||
void DisplaySubstUsage(void)
|
||||
VOID DisplaySubstUsage(VOID)
|
||||
{
|
||||
TCHAR szHelp[RC_STRING_MAX_SIZE] = {0};
|
||||
|
||||
LoadString(GetModuleHandle(NULL),
|
||||
IDS_USAGE,
|
||||
szHelp,
|
||||
sizeof(szHelp) / sizeof(szHelp[0]));
|
||||
ARRAYSIZE(szHelp));
|
||||
_tprintf(_T("%s"), szHelp);
|
||||
}
|
||||
|
||||
BOOLEAN IsSubstedDrive(TCHAR *Drive)
|
||||
BOOLEAN IsSubstedDrive(TCHAR DriveLetter)
|
||||
{
|
||||
BOOLEAN Result = FALSE;
|
||||
TCHAR Drive[3] = _T("A:");
|
||||
LPTSTR lpTargetPath = NULL;
|
||||
DWORD CharCount, dwSize;
|
||||
|
||||
if (_tcslen(Drive) > 2)
|
||||
return FALSE;
|
||||
Drive[0] = DriveLetter;
|
||||
|
||||
dwSize = MAX_PATH;
|
||||
lpTargetPath = (LPTSTR)malloc(sizeof(TCHAR) * dwSize);
|
||||
|
@ -109,7 +110,7 @@ BOOLEAN IsSubstedDrive(TCHAR *Drive)
|
|||
return Result;
|
||||
}
|
||||
|
||||
void DumpSubstedDrives(void)
|
||||
VOID DumpSubstedDrives(VOID)
|
||||
{
|
||||
TCHAR Drive[3] = _T("A:");
|
||||
LPTSTR lpTargetPath = NULL;
|
||||
|
@ -159,7 +160,7 @@ void DumpSubstedDrives(void)
|
|||
free(lpTargetPath);
|
||||
}
|
||||
|
||||
int DeleteSubst(TCHAR* Drive)
|
||||
INT DeleteSubst(TCHAR* Drive)
|
||||
{
|
||||
BOOL Result;
|
||||
TCHAR szFmtString[RC_STRING_MAX_SIZE] = {0};
|
||||
|
@ -167,26 +168,24 @@ int DeleteSubst(TCHAR* Drive)
|
|||
LoadString(GetModuleHandle(NULL),
|
||||
IDS_INVALID_PARAMETER2,
|
||||
szFmtString,
|
||||
sizeof(szFmtString) / sizeof(szFmtString[0]));
|
||||
ARRAYSIZE(szFmtString));
|
||||
|
||||
if (_tcslen(Drive) > 2)
|
||||
if ((_tcslen(Drive) != 2) || (Drive[1] != _T(':')))
|
||||
{
|
||||
_tprintf(szFmtString,
|
||||
Drive);
|
||||
_tprintf(szFmtString, Drive);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (! IsSubstedDrive(Drive))
|
||||
if (!IsSubstedDrive(Drive[0]))
|
||||
{
|
||||
_tprintf(szFmtString,
|
||||
Drive);
|
||||
_tprintf(szFmtString, Drive);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Result = DefineDosDevice(DDD_REMOVE_DEFINITION,
|
||||
Drive,
|
||||
NULL);
|
||||
if (! Result)
|
||||
if (!Result)
|
||||
{
|
||||
PrintError(GetLastError());
|
||||
return 1;
|
||||
|
@ -194,35 +193,47 @@ int DeleteSubst(TCHAR* Drive)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int AddSubst(TCHAR* Drive, TCHAR *Path)
|
||||
INT AddSubst(TCHAR* Drive, TCHAR *Path)
|
||||
{
|
||||
BOOL Result;
|
||||
DWORD dwPathAttr;
|
||||
TCHAR szFmtString[RC_STRING_MAX_SIZE] = {0};
|
||||
|
||||
LoadString(GetModuleHandle(NULL),
|
||||
IDS_INVALID_PARAMETER2,
|
||||
szFmtString,
|
||||
sizeof(szFmtString) / sizeof(szFmtString[0]));
|
||||
if (_tcslen(Drive) != 2)
|
||||
if ((_tcslen(Drive) != 2) || (Drive[1] != _T(':')))
|
||||
{
|
||||
_tprintf(szFmtString,
|
||||
Drive);
|
||||
LoadString(GetModuleHandle(NULL),
|
||||
IDS_INVALID_PARAMETER2,
|
||||
szFmtString,
|
||||
ARRAYSIZE(szFmtString));
|
||||
_tprintf(szFmtString, Drive);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (Drive[1] != _T(':'))
|
||||
/*
|
||||
* Even if DefineDosDevice allows to map files to drive letters (yes yes!!)
|
||||
* it is not the purpose of SUBST to allow that. Therefore check whether
|
||||
* the given path exists and really is a path to a directory, and if not,
|
||||
* just fail with an error.
|
||||
*/
|
||||
dwPathAttr = GetFileAttributes(Path);
|
||||
if ( (dwPathAttr == INVALID_FILE_ATTRIBUTES) ||
|
||||
!(dwPathAttr & FILE_ATTRIBUTE_DIRECTORY) )
|
||||
{
|
||||
_tprintf(szFmtString,
|
||||
Drive);
|
||||
LoadString(GetModuleHandle(NULL),
|
||||
IDS_PATH_NOT_FOUND,
|
||||
szFmtString,
|
||||
ARRAYSIZE(szFmtString));
|
||||
_tprintf(szFmtString, Path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (IsSubstedDrive(Drive))
|
||||
if (IsSubstedDrive(Drive[0]))
|
||||
{
|
||||
// ERROR_IS_SUBSTED
|
||||
LoadString(GetModuleHandle(NULL),
|
||||
IDS_DRIVE_ALREADY_SUBSTED,
|
||||
szFmtString,
|
||||
sizeof(szFmtString) / sizeof(szFmtString[0]));
|
||||
ARRAYSIZE(szFmtString));
|
||||
_tprintf(szFmtString);
|
||||
return 1;
|
||||
}
|
||||
|
@ -230,7 +241,7 @@ int AddSubst(TCHAR* Drive, TCHAR *Path)
|
|||
Result = DefineDosDevice(0,
|
||||
Drive,
|
||||
Path);
|
||||
if (! Result)
|
||||
if (!Result)
|
||||
{
|
||||
PrintError(GetLastError());
|
||||
return 1;
|
||||
|
@ -259,9 +270,8 @@ int _tmain(int argc, TCHAR* argv[])
|
|||
LoadString(GetModuleHandle(NULL),
|
||||
IDS_INVALID_PARAMETER,
|
||||
szFmtString,
|
||||
sizeof(szFmtString) / sizeof(szFmtString[0]));
|
||||
_tprintf(szFmtString,
|
||||
argv[1]);
|
||||
ARRAYSIZE(szFmtString));
|
||||
_tprintf(szFmtString, argv[1]);
|
||||
return 1;
|
||||
}
|
||||
DumpSubstedDrives();
|
||||
|
@ -273,15 +283,14 @@ int _tmain(int argc, TCHAR* argv[])
|
|||
LoadString(GetModuleHandle(NULL),
|
||||
IDS_INCORRECT_PARAMETER_COUNT,
|
||||
szFmtString,
|
||||
sizeof(szFmtString) / sizeof(szFmtString[0]));
|
||||
_tprintf(szFmtString,
|
||||
argv[3]);
|
||||
ARRAYSIZE(szFmtString));
|
||||
_tprintf(szFmtString, argv[3]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (! _tcsicmp(argv[1], _T("/D")))
|
||||
if (!_tcsicmp(argv[1], _T("/D")))
|
||||
return DeleteSubst(argv[2]);
|
||||
if (! _tcsicmp(argv[2], _T("/D")))
|
||||
if (!_tcsicmp(argv[2], _T("/D")))
|
||||
return DeleteSubst(argv[1]);
|
||||
return AddSubst(argv[1], argv[2]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue