From 1c935c792d556e3920be9152810434c5431a4c7c Mon Sep 17 00:00:00 2001 From: root Date: Sun, 7 Apr 2024 17:51:30 +0200 Subject: [PATCH] fixed cd .. command on command line clients --- build/compile.sh | 6 ++++++ ftpCommandElaborate.c | 6 +++--- ftpData.c | 4 ++-- ftpServer.c | 13 +++++++------ library/fileManagement.c | 15 +++++++++++---- 5 files changed, 29 insertions(+), 15 deletions(-) create mode 100755 build/compile.sh diff --git a/build/compile.sh b/build/compile.sh new file mode 100755 index 0000000..2af66f9 --- /dev/null +++ b/build/compile.sh @@ -0,0 +1,6 @@ +cd .. +make clean +make +cd build +sudo killall uFTP +./uFTP diff --git a/ftpCommandElaborate.c b/ftpCommandElaborate.c index 3150cd3..542a77d 100755 --- a/ftpCommandElaborate.c +++ b/ftpCommandElaborate.c @@ -773,18 +773,18 @@ int parseCommandCwd(ftpDataType *data, int socketId) thePath = getFtpCommandArg("CWD", data->clients[socketId].theCommandReceived, 0); - // printf("\ncdw requested path: %s", thePath); + //printf("\ncdw requested path: %s", thePath); if (strlen(thePath) > 0) { // printf("Memory data address 1st call : %lld", &data->clients[socketId].memoryTable); isSafePath = getSafePath(&theSafePath, thePath, &data->clients[socketId].login, &data->clients[socketId].memoryTable); - // printf("\ncdw safe path: %s", theSafePath.text); + //printf("\ncdw safe path: %s", theSafePath.text); } if (isSafePath) { - // printf("\n The Path requested for CWD IS:%s", theSafePath.text); + //printf("\n The Path requested for CWD IS:%s", theSafePath.text); setDynamicStringDataType(&absolutePathPrevious, data->clients[socketId].login.absolutePath.text, data->clients[socketId].login.absolutePath.textLen, &data->clients[socketId].memoryTable); setDynamicStringDataType(&ftpPathPrevious, data->clients[socketId].login.ftpPath.text, data->clients[socketId].login.ftpPath.textLen, &data->clients[socketId].memoryTable); diff --git a/ftpData.c b/ftpData.c index e61f643..b876fd1 100755 --- a/ftpData.c +++ b/ftpData.c @@ -737,8 +737,8 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization) int compareStringCaseInsensitive(char * stringIn, char * stringRef, int stringLenght) { int i = 0; - char * alfaLowerCase = "qwertyuiopasdfghjklzxcvbnm "; - char * alfaUpperCase = "QWERTYUIOPASDFGHJKLZXCVBNM "; + char * alfaLowerCase = "qwertyuiopasdfghjklzxcvbnm ."; + char * alfaUpperCase = "QWERTYUIOPASDFGHJKLZXCVBNM ."; int stringInIndex; int stringRefIndex; diff --git a/ftpServer.c b/ftpServer.c index 90913dc..edb4673 100755 --- a/ftpServer.c +++ b/ftpServer.c @@ -753,7 +753,7 @@ static int processCommand(int processingElement) { int toReturn = 0; //printTimeStamp(); - //printf ("\nCommand received from (%d): %s", processingElement, ftpData.clients[processingElement].theCommandReceived); + // printf ("\nCommand received from (%d): %s", processingElement, ftpData.clients[processingElement].theCommandReceived); cleanDynamicStringDataType(&ftpData.clients[processingElement].ftpCommand.commandArgs, 0, &ftpData.clients[processingElement].memoryTable); cleanDynamicStringDataType(&ftpData.clients[processingElement].ftpCommand.commandOps, 0, &ftpData.clients[processingElement].memoryTable); @@ -859,16 +859,17 @@ static int processCommand(int processingElement) //printf("\nLIST COMMAND RECEIVED"); toReturn = parseCommandList(&ftpData, processingElement); } + else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "CDUP", strlen("CDUP")) == 1 || + compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "CWD ..", strlen("CWD ..")) == 1) + { + //printf("\nCDUP COMMAND RECEIVED"); + toReturn = parseCommandCdup(&ftpData, processingElement); + } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "CWD", strlen("CWD")) == 1) { //printf("\nCWD COMMAND RECEIVED"); toReturn = parseCommandCwd(&ftpData, processingElement); } - else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "CDUP", strlen("CDUP")) == 1) - { - //printf("\nCDUP COMMAND RECEIVED"); - toReturn = parseCommandCdup(&ftpData, processingElement); - } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "REST", strlen("REST")) == 1) { //printf("\nREST COMMAND RECEIVED"); diff --git a/library/fileManagement.c b/library/fileManagement.c index da0e98d..cb8bec7 100755 --- a/library/fileManagement.c +++ b/library/fileManagement.c @@ -709,13 +709,14 @@ void FILE_AppendToString(char ** sourceString, char *theString, DYNMEM_MemoryTab void FILE_DirectoryToParent(char ** sourceString, DYNMEM_MemoryTable_DataType ** memoryTable) { - //printf("\n"); + //printf("\n"); - size_t theLastSlash = -1; + int theLastSlash = -1; size_t strLen = 0; strLen = strlen(*sourceString); - //printf("\nstrLen = %d", strLen); + //printf("\nThe directory = %s", (*sourceString)); + //printf("\ndirectory to parent strLen = %d", strLen); for (size_t i = 0; i < strLen; i++) { @@ -723,9 +724,10 @@ void FILE_DirectoryToParent(char ** sourceString, DYNMEM_MemoryTable_DataType ** if ( (*sourceString)[i] == '/') { theLastSlash = i; - //printf("\n theLastSlash = %d", theLastSlash); } } + + //printf("\n theLastSlash = %d", theLastSlash); if (theLastSlash > -1) { @@ -734,8 +736,13 @@ void FILE_DirectoryToParent(char ** sourceString, DYNMEM_MemoryTable_DataType ** { theNewSize = 1; } + + //printf("\n theNewSize = %d", theNewSize); + *sourceString = DYNMEM_realloc(*sourceString, theNewSize+1, &*memoryTable); (*sourceString)[theNewSize] = '\0'; + + //printf("\nThe directory upped is = %s", (*sourceString)); } }