mirror of
https://github.com/kingk85/uFTP.git
synced 2025-07-23 20:26:11 +03:00
Working on memory tables
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
build/uFTP
BIN
build/uFTP
Binary file not shown.
@ -42,6 +42,7 @@
|
||||
#include "library/configRead.h"
|
||||
#include "library/openSsl.h"
|
||||
#include "library/connection.h"
|
||||
#include "library/dynamicMemory.h"
|
||||
#include "ftpCommandsElaborate.h"
|
||||
|
||||
|
||||
@ -54,7 +55,7 @@ int parseCommandUser(ftpDataType * data, int socketId)
|
||||
|
||||
if (strlen(theUserName) >= 1)
|
||||
{
|
||||
setDynamicStringDataType(&data->clients[socketId].login.name, theUserName, strlen(theUserName));
|
||||
setDynamicStringDataType(&data->clients[socketId].login.name, theUserName, strlen(theUserName), &data->clients[socketId].memoryTable);
|
||||
returnCode = socketPrintf(data, socketId, "s", "331 User ok, Waiting for the password.\r\n");
|
||||
|
||||
if (returnCode <= 0)
|
||||
@ -179,10 +180,10 @@ int parseCommandPass(ftpDataType * data, int socketId)
|
||||
}
|
||||
else
|
||||
{
|
||||
setDynamicStringDataType(&data->clients[socketId].login.password, thePass, strlen(thePass));
|
||||
setDynamicStringDataType(&data->clients[socketId].login.absolutePath, ((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath, strlen(((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath));
|
||||
setDynamicStringDataType(&data->clients[socketId].login.homePath, ((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath, strlen(((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath));
|
||||
setDynamicStringDataType(&data->clients[socketId].login.ftpPath, "/", strlen("/"));
|
||||
setDynamicStringDataType(&data->clients[socketId].login.password, thePass, strlen(thePass), &data->clients[socketId].memoryTable);
|
||||
setDynamicStringDataType(&data->clients[socketId].login.absolutePath, ((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath, strlen(((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath), &data->clients[socketId].memoryTable);
|
||||
setDynamicStringDataType(&data->clients[socketId].login.homePath, ((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath, strlen(((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath), &data->clients[socketId].memoryTable);
|
||||
setDynamicStringDataType(&data->clients[socketId].login.ftpPath, "/", strlen("/"), &data->clients[socketId].memoryTable);
|
||||
|
||||
data->clients[socketId].login.ownerShip.ownerShipSet = ((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->ownerShip.ownerShipSet;
|
||||
data->clients[socketId].login.ownerShip.gid = ((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->ownerShip.gid;
|
||||
@ -532,7 +533,6 @@ int parseCommandAbor(ftpDataType * data, int socketId)
|
||||
int returnCode;
|
||||
if (data->clients[socketId].workerData.threadIsAlive == 1)
|
||||
{
|
||||
void *pReturn;
|
||||
if (data->clients[socketId].workerData.threadIsAlive == 1)
|
||||
{
|
||||
pthread_cancel(data->clients[socketId].workerData.workerThread);
|
||||
@ -579,7 +579,7 @@ int parseCommandList(ftpDataType * data, int socketId)
|
||||
char *theNameToList;
|
||||
|
||||
theNameToList = getFtpCommandArg("LIST", data->clients[socketId].theCommandReceived, 1);
|
||||
getFtpCommandArgWithOptions("LIST", data->clients[socketId].theCommandReceived, &data->clients[socketId].workerData.ftpCommand);
|
||||
getFtpCommandArgWithOptions("LIST", data->clients[socketId].theCommandReceived, &data->clients[socketId].workerData.ftpCommand, &data->clients[socketId].workerData.memoryTable);
|
||||
|
||||
if (data->clients[socketId].workerData.ftpCommand.commandArgs.text != NULL)
|
||||
printf("\nLIST COMMAND ARG: %s", data->clients[socketId].workerData.ftpCommand.commandArgs.text);
|
||||
@ -587,19 +587,19 @@ int parseCommandList(ftpDataType * data, int socketId)
|
||||
printf("\nLIST COMMAND OPS: %s", data->clients[socketId].workerData.ftpCommand.commandOps.text);
|
||||
printf("\ntheNameToList: %s", theNameToList);
|
||||
|
||||
cleanDynamicStringDataType(&data->clients[socketId].workerData.ftpCommand.commandArgs, 0);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].workerData.ftpCommand.commandOps, 0);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].listPath, 0);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].workerData.ftpCommand.commandArgs, 0, &data->clients[socketId].workerData.memoryTable);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].workerData.ftpCommand.commandOps, 0, &data->clients[socketId].workerData.memoryTable);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].listPath, 0, &data->clients[socketId].memoryTable);
|
||||
|
||||
if (strlen(theNameToList) > 0)
|
||||
{
|
||||
isSafePath = getSafePath(&data->clients[socketId].listPath, theNameToList, &data->clients[socketId].login);
|
||||
isSafePath = getSafePath(&data->clients[socketId].listPath, theNameToList, &data->clients[socketId].login, &data->clients[socketId].memoryTable);
|
||||
}
|
||||
|
||||
if (isSafePath == 0)
|
||||
{
|
||||
cleanDynamicStringDataType(&data->clients[socketId].listPath, 0);
|
||||
setDynamicStringDataType(&data->clients[socketId].listPath, data->clients[socketId].login.absolutePath.text, data->clients[socketId].login.absolutePath.textLen);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].listPath, 0, &data->clients[socketId].memoryTable);
|
||||
setDynamicStringDataType(&data->clients[socketId].listPath, data->clients[socketId].login.absolutePath.text, data->clients[socketId].login.absolutePath.textLen, &data->clients[socketId].memoryTable);
|
||||
}
|
||||
|
||||
pthread_mutex_trylock(&data->clients[socketId].workerData.conditionMutex);
|
||||
@ -616,7 +616,7 @@ int parseCommandNlst(ftpDataType * data, int socketId)
|
||||
int isSafePath = 0;
|
||||
char *theNameToNlist;
|
||||
theNameToNlist = getFtpCommandArg("NLIST", data->clients[socketId].theCommandReceived, 1);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].nlistPath, 0);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].nlistPath, 0, &data->clients[socketId].memoryTable);
|
||||
|
||||
printf("\nNLIST COMMAND ARG: %s", data->clients[socketId].workerData.ftpCommand.commandArgs.text);
|
||||
printf("\nNLIST COMMAND OPS: %s", data->clients[socketId].workerData.ftpCommand.commandOps.text);
|
||||
@ -624,13 +624,13 @@ int parseCommandNlst(ftpDataType * data, int socketId)
|
||||
|
||||
if (strlen(theNameToNlist) > 0)
|
||||
{
|
||||
isSafePath = getSafePath(&data->clients[socketId].nlistPath, theNameToNlist, &data->clients[socketId].login);
|
||||
isSafePath = getSafePath(&data->clients[socketId].nlistPath, theNameToNlist, &data->clients[socketId].login, &data->clients[socketId].memoryTable);
|
||||
}
|
||||
|
||||
if (isSafePath == 0)
|
||||
{
|
||||
cleanDynamicStringDataType(&data->clients[socketId].nlistPath, 0);
|
||||
setDynamicStringDataType(&data->clients[socketId].nlistPath, data->clients[socketId].login.absolutePath.text, data->clients[socketId].login.absolutePath.textLen);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].nlistPath, 0, &data->clients[socketId].memoryTable);
|
||||
setDynamicStringDataType(&data->clients[socketId].nlistPath, data->clients[socketId].login.absolutePath.text, data->clients[socketId].login.absolutePath.textLen, &data->clients[socketId].memoryTable);
|
||||
}
|
||||
|
||||
pthread_mutex_trylock(&data->clients[socketId].workerData.conditionMutex);
|
||||
@ -648,11 +648,11 @@ int parseCommandRetr(ftpDataType * data, int socketId)
|
||||
char *theNameToRetr;
|
||||
|
||||
theNameToRetr = getFtpCommandArg("RETR", data->clients[socketId].theCommandReceived, 0);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].fileToRetr, 0);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].fileToRetr, 0, &data->clients[socketId].memoryTable);
|
||||
|
||||
if (strlen(theNameToRetr) > 0)
|
||||
{
|
||||
isSafePath = getSafePath(&data->clients[socketId].fileToRetr, theNameToRetr, &data->clients[socketId].login);
|
||||
isSafePath = getSafePath(&data->clients[socketId].fileToRetr, theNameToRetr, &data->clients[socketId].login, &data->clients[socketId].memoryTable);
|
||||
}
|
||||
|
||||
if (isSafePath == 1 &&
|
||||
@ -679,11 +679,11 @@ int parseCommandStor(ftpDataType * data, int socketId)
|
||||
int isSafePath = 0;
|
||||
char *theNameToStor;
|
||||
theNameToStor = getFtpCommandArg("STOR", data->clients[socketId].theCommandReceived, 0);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].fileToStor, 0);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].fileToStor, 0, &data->clients[socketId].memoryTable);
|
||||
|
||||
if (strlen(theNameToStor) > 0)
|
||||
{
|
||||
isSafePath = getSafePath(&data->clients[socketId].fileToStor, theNameToStor, &data->clients[socketId].login);
|
||||
isSafePath = getSafePath(&data->clients[socketId].fileToStor, theNameToStor, &data->clients[socketId].login, &data->clients[socketId].memoryTable);
|
||||
}
|
||||
|
||||
if (isSafePath == 1)
|
||||
@ -710,41 +710,42 @@ int parseCommandCwd(ftpDataType * data, int socketId)
|
||||
int returnCode;
|
||||
char *thePath;
|
||||
|
||||
cleanDynamicStringDataType(&absolutePathPrevious, 1);
|
||||
cleanDynamicStringDataType(&ftpPathPrevious, 1);
|
||||
cleanDynamicStringDataType(&theSafePath, 1);
|
||||
cleanDynamicStringDataType(&absolutePathPrevious, 1, &data->clients[socketId].memoryTable);
|
||||
cleanDynamicStringDataType(&ftpPathPrevious, 1, &data->clients[socketId].memoryTable);
|
||||
cleanDynamicStringDataType(&theSafePath, 1, &data->clients[socketId].memoryTable);
|
||||
|
||||
thePath = getFtpCommandArg("CWD", data->clients[socketId].theCommandReceived, 0);
|
||||
|
||||
if (strlen(thePath) > 0)
|
||||
{
|
||||
isSafePath = getSafePath(&theSafePath, thePath, &data->clients[socketId].login);
|
||||
//printf("Memory data address 1st call : %lld", &data->clients[socketId].memoryTable);
|
||||
isSafePath = getSafePath(&theSafePath, thePath, &data->clients[socketId].login, &data->clients[socketId].memoryTable);
|
||||
}
|
||||
|
||||
if (isSafePath == 1)
|
||||
{
|
||||
//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);
|
||||
setDynamicStringDataType(&ftpPathPrevious, data->clients[socketId].login.ftpPath.text, data->clients[socketId].login.ftpPath.textLen);
|
||||
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);
|
||||
|
||||
if (theSafePath.text[0] != '/')
|
||||
{
|
||||
if (data->clients[socketId].login.absolutePath.text[data->clients[socketId].login.absolutePath.textLen-1] != '/')
|
||||
appendToDynamicStringDataType(&data->clients[socketId].login.absolutePath, "/", 1);
|
||||
appendToDynamicStringDataType(&data->clients[socketId].login.absolutePath, "/", 1, &data->clients[socketId].memoryTable);
|
||||
|
||||
if (data->clients[socketId].login.ftpPath.text[data->clients[socketId].login.ftpPath.textLen-1] != '/')
|
||||
appendToDynamicStringDataType(&data->clients[socketId].login.ftpPath, "/", 1);
|
||||
appendToDynamicStringDataType(&data->clients[socketId].login.ftpPath, "/", 1, &data->clients[socketId].memoryTable);
|
||||
|
||||
appendToDynamicStringDataType(&data->clients[socketId].login.absolutePath, theSafePath.text, theSafePath.textLen);
|
||||
appendToDynamicStringDataType(&data->clients[socketId].login.ftpPath, theSafePath.text, theSafePath.textLen);
|
||||
appendToDynamicStringDataType(&data->clients[socketId].login.absolutePath, theSafePath.text, theSafePath.textLen, &data->clients[socketId].memoryTable);
|
||||
appendToDynamicStringDataType(&data->clients[socketId].login.ftpPath, theSafePath.text, theSafePath.textLen, &data->clients[socketId].memoryTable);
|
||||
}
|
||||
else if (theSafePath.text[0] == '/')
|
||||
{
|
||||
cleanDynamicStringDataType(&data->clients[socketId].login.ftpPath, 0);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].login.absolutePath, 0);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].login.ftpPath, 0, &data->clients[socketId].memoryTable);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].login.absolutePath, 0, &data->clients[socketId].memoryTable);
|
||||
|
||||
setDynamicStringDataType(&data->clients[socketId].login.ftpPath, theSafePath.text, theSafePath.textLen);
|
||||
setDynamicStringDataType(&data->clients[socketId].login.absolutePath, data->clients[socketId].login.homePath.text, data->clients[socketId].login.homePath.textLen);
|
||||
setDynamicStringDataType(&data->clients[socketId].login.ftpPath, theSafePath.text, theSafePath.textLen, &data->clients[socketId].memoryTable);
|
||||
setDynamicStringDataType(&data->clients[socketId].login.absolutePath, data->clients[socketId].login.homePath.text, data->clients[socketId].login.homePath.textLen, &data->clients[socketId].memoryTable);
|
||||
|
||||
if (strlen(theSafePath.text)> 0)
|
||||
{
|
||||
@ -757,7 +758,7 @@ int parseCommandCwd(ftpDataType * data, int socketId)
|
||||
}
|
||||
|
||||
if (strlen(theDirPointer) > 0)
|
||||
appendToDynamicStringDataType(&data->clients[socketId].login.absolutePath, theDirPointer, strlen(theDirPointer));
|
||||
appendToDynamicStringDataType(&data->clients[socketId].login.absolutePath, theDirPointer, strlen(theDirPointer), &data->clients[socketId].memoryTable);
|
||||
}
|
||||
}
|
||||
|
||||
@ -767,14 +768,14 @@ int parseCommandCwd(ftpDataType * data, int socketId)
|
||||
}
|
||||
else
|
||||
{
|
||||
setDynamicStringDataType(&data->clients[socketId].login.absolutePath, absolutePathPrevious.text, absolutePathPrevious.textLen);
|
||||
setDynamicStringDataType(&data->clients[socketId].login.ftpPath, ftpPathPrevious.text, ftpPathPrevious.textLen);
|
||||
setDynamicStringDataType(&data->clients[socketId].login.absolutePath, absolutePathPrevious.text, absolutePathPrevious.textLen, &data->clients[socketId].memoryTable);
|
||||
setDynamicStringDataType(&data->clients[socketId].login.ftpPath, ftpPathPrevious.text, ftpPathPrevious.textLen, &data->clients[socketId].memoryTable);
|
||||
returnCode = socketPrintf(data, socketId, "sss", "530 Can't change directory to ", data->clients[socketId].login.absolutePath.text, ": No such file or directory\r\n");
|
||||
}
|
||||
|
||||
cleanDynamicStringDataType(&absolutePathPrevious, 0);
|
||||
cleanDynamicStringDataType(&ftpPathPrevious, 0);
|
||||
cleanDynamicStringDataType(&theSafePath, 0);
|
||||
cleanDynamicStringDataType(&absolutePathPrevious, 0, &data->clients[socketId].memoryTable);
|
||||
cleanDynamicStringDataType(&ftpPathPrevious, 0, &data->clients[socketId].memoryTable);
|
||||
cleanDynamicStringDataType(&theSafePath, 0, &data->clients[socketId].memoryTable);
|
||||
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
@ -784,9 +785,9 @@ int parseCommandCwd(ftpDataType * data, int socketId)
|
||||
}
|
||||
else
|
||||
{
|
||||
cleanDynamicStringDataType(&absolutePathPrevious, 0);
|
||||
cleanDynamicStringDataType(&ftpPathPrevious, 0);
|
||||
cleanDynamicStringDataType(&theSafePath, 0);
|
||||
cleanDynamicStringDataType(&absolutePathPrevious, 0, &data->clients[socketId].memoryTable);
|
||||
cleanDynamicStringDataType(&ftpPathPrevious, 0, &data->clients[socketId].memoryTable);
|
||||
cleanDynamicStringDataType(&theSafePath, 0, &data->clients[socketId].memoryTable);
|
||||
return FTP_COMMAND_NOT_RECONIZED;
|
||||
}
|
||||
}
|
||||
@ -843,9 +844,9 @@ int parseCommandMkd(ftpDataType * data, int socketId)
|
||||
|
||||
theDirectoryFilename = getFtpCommandArg("MKD", data->clients[socketId].theCommandReceived, 0);
|
||||
|
||||
cleanDynamicStringDataType(&mkdFileName, 1);
|
||||
cleanDynamicStringDataType(&mkdFileName, 1, &data->clients[socketId].memoryTable);
|
||||
|
||||
isSafePath = getSafePath(&mkdFileName, theDirectoryFilename, &data->clients[socketId].login);
|
||||
isSafePath = getSafePath(&mkdFileName, theDirectoryFilename, &data->clients[socketId].login, &data->clients[socketId].memoryTable);
|
||||
|
||||
if (isSafePath == 1)
|
||||
{
|
||||
@ -885,11 +886,11 @@ int parseCommandMkd(ftpDataType * data, int socketId)
|
||||
}
|
||||
else
|
||||
{
|
||||
cleanDynamicStringDataType(&mkdFileName, 0);
|
||||
cleanDynamicStringDataType(&mkdFileName, 0, &data->clients[socketId].memoryTable);
|
||||
functionReturnCode = FTP_COMMAND_NOT_RECONIZED;
|
||||
}
|
||||
|
||||
cleanDynamicStringDataType(&mkdFileName, 0);
|
||||
cleanDynamicStringDataType(&mkdFileName, 0, &data->clients[socketId].memoryTable);
|
||||
return functionReturnCode;
|
||||
}
|
||||
|
||||
@ -915,8 +916,8 @@ int parseCommandDele(ftpDataType * data, int socketId)
|
||||
|
||||
theFileToDelete = getFtpCommandArg("DELE", data->clients[socketId].theCommandReceived, 0);
|
||||
|
||||
cleanDynamicStringDataType(&deleFileName, 1);
|
||||
isSafePath = getSafePath(&deleFileName, theFileToDelete, &data->clients[socketId].login);
|
||||
cleanDynamicStringDataType(&deleFileName, 1, &data->clients[socketId].memoryTable);
|
||||
isSafePath = getSafePath(&deleFileName, theFileToDelete, &data->clients[socketId].login, &data->clients[socketId].memoryTable);
|
||||
|
||||
if (isSafePath == 1)
|
||||
{
|
||||
@ -953,7 +954,7 @@ int parseCommandDele(ftpDataType * data, int socketId)
|
||||
functionReturnCode = FTP_COMMAND_NOT_RECONIZED;
|
||||
}
|
||||
|
||||
cleanDynamicStringDataType(&deleFileName, 0);
|
||||
cleanDynamicStringDataType(&deleFileName, 0, &data->clients[socketId].memoryTable);
|
||||
return functionReturnCode;
|
||||
}
|
||||
|
||||
@ -1003,8 +1004,8 @@ int parseCommandRmd(ftpDataType * data, int socketId)
|
||||
dynamicStringDataType rmdFileName;
|
||||
|
||||
theDirectoryFilename = getFtpCommandArg("RMD", data->clients[socketId].theCommandReceived, 0);
|
||||
cleanDynamicStringDataType(&rmdFileName, 1);
|
||||
isSafePath = getSafePath(&rmdFileName, theDirectoryFilename, &data->clients[socketId].login);
|
||||
cleanDynamicStringDataType(&rmdFileName, 1, &data->clients[socketId].memoryTable);
|
||||
isSafePath = getSafePath(&rmdFileName, theDirectoryFilename, &data->clients[socketId].login, &data->clients[socketId].memoryTable);
|
||||
|
||||
if (isSafePath == 1)
|
||||
{
|
||||
@ -1040,7 +1041,7 @@ int parseCommandRmd(ftpDataType * data, int socketId)
|
||||
functionReturnCode = FTP_COMMAND_NOT_RECONIZED;
|
||||
}
|
||||
|
||||
cleanDynamicStringDataType(&rmdFileName, 0);
|
||||
cleanDynamicStringDataType(&rmdFileName, 0, &data->clients[socketId].memoryTable);
|
||||
|
||||
return functionReturnCode;
|
||||
}
|
||||
@ -1055,9 +1056,9 @@ int parseCommandSize(ftpDataType * data, int socketId)
|
||||
|
||||
theFileName = getFtpCommandArg("SIZE", data->clients[socketId].theCommandReceived, 0);
|
||||
|
||||
cleanDynamicStringDataType(&getSizeFromFileName, 1);
|
||||
cleanDynamicStringDataType(&getSizeFromFileName, 1, &data->clients[socketId].memoryTable);
|
||||
|
||||
isSafePath = getSafePath(&getSizeFromFileName, theFileName, &data->clients[socketId].login);
|
||||
isSafePath = getSafePath(&getSizeFromFileName, theFileName, &data->clients[socketId].login, &data->clients[socketId].memoryTable);
|
||||
|
||||
if (isSafePath == 1)
|
||||
{
|
||||
@ -1076,7 +1077,7 @@ int parseCommandSize(ftpDataType * data, int socketId)
|
||||
{
|
||||
returnCode = socketPrintf(data, socketId, "s", "550 Can't check for file existence\r\n");
|
||||
}
|
||||
cleanDynamicStringDataType(&getSizeFromFileName, 0);
|
||||
cleanDynamicStringDataType(&getSizeFromFileName, 0, &data->clients[socketId].memoryTable);
|
||||
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
@ -1091,9 +1092,9 @@ int parseCommandRnfr(ftpDataType * data, int socketId)
|
||||
char *theRnfrFileName;
|
||||
|
||||
theRnfrFileName = getFtpCommandArg("RNFR", data->clients[socketId].theCommandReceived, 0);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].renameFromFile, 0);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].renameFromFile, 0, &data->clients[socketId].memoryTable);
|
||||
|
||||
isSafePath = getSafePath(&data->clients[socketId].renameFromFile, theRnfrFileName, &data->clients[socketId].login);
|
||||
isSafePath = getSafePath(&data->clients[socketId].renameFromFile, theRnfrFileName, &data->clients[socketId].login, &data->clients[socketId].memoryTable);
|
||||
|
||||
if (isSafePath == 1&&
|
||||
(FILE_IsFile(data->clients[socketId].renameFromFile.text) == 1 ||
|
||||
@ -1126,9 +1127,9 @@ int parseCommandRnto(ftpDataType * data, int socketId)
|
||||
char *theRntoFileName;
|
||||
|
||||
theRntoFileName = getFtpCommandArg("RNTO", data->clients[socketId].theCommandReceived, 0);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].renameToFile, 0);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].renameToFile, 0, &data->clients[socketId].memoryTable);
|
||||
|
||||
isSafePath = getSafePath(&data->clients[socketId].renameToFile, theRntoFileName, &data->clients[socketId].login);
|
||||
isSafePath = getSafePath(&data->clients[socketId].renameToFile, theRntoFileName, &data->clients[socketId].login, &data->clients[socketId].memoryTable);
|
||||
|
||||
if (isSafePath == 1 &&
|
||||
data->clients[socketId].renameFromFile.textLen > 0)
|
||||
@ -1179,7 +1180,7 @@ int parseCommandCdup(ftpDataType * data, int socketId)
|
||||
|
||||
if(strncmp(data->clients[socketId].login.absolutePath.text, data->clients[socketId].login.homePath.text, data->clients[socketId].login.homePath.textLen) != 0)
|
||||
{
|
||||
setDynamicStringDataType(&data->clients[socketId].login.absolutePath, data->clients[socketId].login.homePath.text, data->clients[socketId].login.homePath.textLen);
|
||||
setDynamicStringDataType(&data->clients[socketId].login.absolutePath, data->clients[socketId].login.homePath.text, data->clients[socketId].login.homePath.textLen, &data->clients[socketId].memoryTable);
|
||||
}
|
||||
|
||||
returnCode = socketPrintf(data, socketId, "sss", "250 OK. Current directory is ", data->clients[socketId].login.ftpPath.text, "\r\n");
|
||||
@ -1303,7 +1304,7 @@ char *getFtpCommandArg(char * theCommand, char *theCommandString, int skipArgs)
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
int getFtpCommandArgWithOptions(char * theCommand, char *theCommandString, ftpCommandDataType *ftpCommand)
|
||||
int getFtpCommandArgWithOptions(char * theCommand, char *theCommandString, ftpCommandDataType *ftpCommand, DYNMEM_MemoryTable_DataType **memoryTable)
|
||||
{
|
||||
#define CASE_ARG_MAIN 0
|
||||
#define CASE_ARG_SECONDARY 1
|
||||
@ -1369,10 +1370,10 @@ int getFtpCommandArgWithOptions(char * theCommand, char *theCommandString, ftpCo
|
||||
}
|
||||
|
||||
if (argMainIndex > 0)
|
||||
setDynamicStringDataType(&ftpCommand->commandArgs, argMain, argMainIndex);
|
||||
setDynamicStringDataType(&ftpCommand->commandArgs, argMain, argMainIndex, &*memoryTable);
|
||||
|
||||
if (argSecondaryIndex > 0)
|
||||
setDynamicStringDataType(&ftpCommand->commandOps, argSecondary, argSecondaryIndex);
|
||||
setDynamicStringDataType(&ftpCommand->commandOps, argSecondary, argSecondaryIndex, &*memoryTable);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ int parseCommandRnto(ftpDataType * data, int socketId);
|
||||
|
||||
long long int writeRetrFile(ftpDataType * data, int theSocketId, long long int startFrom, FILE *retrFP);
|
||||
char *getFtpCommandArg(char * theCommand, char *theCommandString, int skipArgs);
|
||||
int getFtpCommandArgWithOptions(char * theCommand, char *theCommandString, ftpCommandDataType *ftpCommand);
|
||||
int getFtpCommandArgWithOptions(char * theCommand, char *theCommandString, ftpCommandDataType *ftpCommand, DYNMEM_MemoryTable_DataType **memoryTable);
|
||||
int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataType ownerShip);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
102
ftpData.c
102
ftpData.c
@ -37,8 +37,9 @@
|
||||
#include "library/configRead.h"
|
||||
#include "library/fileManagement.h"
|
||||
#include "library/connection.h"
|
||||
#include "library/dynamicMemory.h"
|
||||
|
||||
void cleanDynamicStringDataType(dynamicStringDataType *dynamicString, int init)
|
||||
void cleanDynamicStringDataType(dynamicStringDataType *dynamicString, int init, DYNMEM_MemoryTable_DataType **memoryTable)
|
||||
{
|
||||
if (init == 1)
|
||||
{
|
||||
@ -50,7 +51,7 @@ void cleanDynamicStringDataType(dynamicStringDataType *dynamicString, int init)
|
||||
if (dynamicString->textLen != 0)
|
||||
{
|
||||
if (dynamicString->text != 0) {
|
||||
free(dynamicString->text);
|
||||
DYNMEM_free(dynamicString->text, &*memoryTable);
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,38 +59,43 @@ void cleanDynamicStringDataType(dynamicStringDataType *dynamicString, int init)
|
||||
}
|
||||
}
|
||||
|
||||
void cleanLoginData(loginDataType *loginData, int init)
|
||||
void cleanLoginData(loginDataType *loginData, int init, DYNMEM_MemoryTable_DataType **memoryTable)
|
||||
{
|
||||
loginData->userLoggedIn = 0;
|
||||
cleanDynamicStringDataType(&loginData->homePath, init);
|
||||
cleanDynamicStringDataType(&loginData->ftpPath, init);
|
||||
cleanDynamicStringDataType(&loginData->name, init);
|
||||
cleanDynamicStringDataType(&loginData->password, init);
|
||||
cleanDynamicStringDataType(&loginData->absolutePath, init);
|
||||
cleanDynamicStringDataType(&loginData->homePath, init, &*memoryTable);
|
||||
cleanDynamicStringDataType(&loginData->ftpPath, init, &*memoryTable);
|
||||
cleanDynamicStringDataType(&loginData->name, init, &*memoryTable);
|
||||
cleanDynamicStringDataType(&loginData->password, init, &*memoryTable);
|
||||
cleanDynamicStringDataType(&loginData->absolutePath, init, &*memoryTable);
|
||||
}
|
||||
|
||||
void setDynamicStringDataType(dynamicStringDataType *dynamicString, char *theString, int stringLen)
|
||||
void setDynamicStringDataType(dynamicStringDataType *dynamicString, char *theString, int stringLen, DYNMEM_MemoryTable_DataType **memoryTable)
|
||||
{
|
||||
if (dynamicString->textLen == 0)
|
||||
{
|
||||
dynamicString->text = (char *) malloc ((sizeof(char) * stringLen) + 1);
|
||||
//printf("\nMemory data address before memset call : %lld", memoryTable);
|
||||
dynamicString->text = (char *) DYNMEM_malloc (((sizeof(char) * stringLen) + 1), &*memoryTable);
|
||||
//printf("\nMemory data address after memset call : %lld", memoryTable);
|
||||
memset(dynamicString->text, 0, stringLen + 1);
|
||||
memcpy(dynamicString->text, theString, stringLen);
|
||||
dynamicString->textLen = stringLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(stringLen != dynamicString->textLen) {
|
||||
dynamicString->text = (char *) realloc (dynamicString->text, (sizeof(char) * stringLen) + 1);
|
||||
if(stringLen != dynamicString->textLen)
|
||||
{
|
||||
dynamicString->text = (char *) DYNMEM_realloc (dynamicString->text, ((sizeof(char) * stringLen) + 1), &*memoryTable);
|
||||
}
|
||||
|
||||
memset(dynamicString->text, 0, stringLen + 1);
|
||||
memcpy(dynamicString->text, theString, stringLen);
|
||||
dynamicString->textLen = stringLen;
|
||||
}
|
||||
|
||||
//printf("\ndynamicString->text = %lld", dynamicString->text);
|
||||
}
|
||||
|
||||
int getSafePath(dynamicStringDataType *safePath, char *theDirectoryName, loginDataType *loginData)
|
||||
int getSafePath(dynamicStringDataType *safePath, char *theDirectoryName, loginDataType *loginData, DYNMEM_MemoryTable_DataType **memoryTable)
|
||||
{
|
||||
#define STRING_SIZE 4096
|
||||
int theLen, i;
|
||||
@ -158,30 +164,36 @@ int getSafePath(dynamicStringDataType *safePath, char *theDirectoryName, loginDa
|
||||
while (theDirectoryNamePointer[0] == '/')
|
||||
theDirectoryNamePointer++;
|
||||
|
||||
setDynamicStringDataType(safePath, loginData->homePath.text, loginData->homePath.textLen);
|
||||
appendToDynamicStringDataType(safePath, theDirectoryNamePointer, strlen(theDirectoryNamePointer));
|
||||
//printf("\nMemory data address 2nd call : %lld", memoryTable);
|
||||
setDynamicStringDataType(safePath, loginData->homePath.text, loginData->homePath.textLen, &*memoryTable);
|
||||
//printf("\nMemory data address 3rd call : %lld", memoryTable);
|
||||
appendToDynamicStringDataType(safePath, theDirectoryNamePointer, strlen(theDirectoryNamePointer), &*memoryTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
setDynamicStringDataType(safePath, loginData->absolutePath.text, loginData->absolutePath.textLen);
|
||||
setDynamicStringDataType(safePath, loginData->absolutePath.text, loginData->absolutePath.textLen, &*memoryTable);
|
||||
|
||||
if (loginData->absolutePath.text[loginData->absolutePath.textLen-1] != '/')
|
||||
{
|
||||
appendToDynamicStringDataType(safePath, "/", 1);
|
||||
appendToDynamicStringDataType(safePath, "/", 1, &*memoryTable);
|
||||
}
|
||||
|
||||
appendToDynamicStringDataType(safePath, theDirectoryName, strlen(theDirectoryName));
|
||||
appendToDynamicStringDataType(safePath, theDirectoryName, strlen(theDirectoryName), &*memoryTable);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void appendToDynamicStringDataType(dynamicStringDataType *dynamicString, char *theString, int stringLen)
|
||||
void appendToDynamicStringDataType(dynamicStringDataType *dynamicString, char *theString, int stringLen, DYNMEM_MemoryTable_DataType **memoryTable)
|
||||
{
|
||||
//printf("\nRealloc dynamicString->text = %lld", dynamicString->text);
|
||||
int theNewSize = dynamicString->textLen + stringLen;
|
||||
dynamicString->text = realloc(dynamicString->text, theNewSize + 1);
|
||||
|
||||
dynamicString->text = DYNMEM_realloc(dynamicString->text, theNewSize + 1, &*memoryTable);
|
||||
|
||||
memset(dynamicString->text+dynamicString->textLen, 0, stringLen+1);
|
||||
memcpy(dynamicString->text+dynamicString->textLen, theString, stringLen);
|
||||
|
||||
dynamicString->text[theNewSize] = '\0';
|
||||
dynamicString->textLen = theNewSize;
|
||||
}
|
||||
@ -220,7 +232,7 @@ void setRandomicPort(ftpDataType *data, int socketPosition)
|
||||
//printf("data->clients[%d].workerData.connectionPort = %d", socketPosition, data->clients[socketPosition].workerData.connectionPort);
|
||||
}
|
||||
|
||||
int writeListDataInfoToSocket(ftpDataType *ftpData, int clientId, int *filesNumber, int commandType)
|
||||
int writeListDataInfoToSocket(ftpDataType *ftpData, int clientId, int *filesNumber, int commandType, DYNMEM_MemoryTable_DataType **memoryTable)
|
||||
{
|
||||
int i, x, returnCode;
|
||||
int fileAndFoldersCount = 0;
|
||||
@ -286,7 +298,7 @@ int writeListDataInfoToSocket(ftpDataType *ftpData, int clientId, int *filesNumb
|
||||
|
||||
if (strlen(data.fileNameNoPath) > 0)
|
||||
{
|
||||
data.finalStringPath = (char *) malloc (strlen(data.fileNameNoPath)+1);
|
||||
data.finalStringPath = (char *) DYNMEM_malloc (strlen(data.fileNameNoPath)+1, &*memoryTable);
|
||||
strcpy(data.finalStringPath, data.fileNameNoPath);
|
||||
}
|
||||
|
||||
@ -296,12 +308,12 @@ int writeListDataInfoToSocket(ftpDataType *ftpData, int clientId, int *filesNumb
|
||||
{
|
||||
int len = 0;
|
||||
data.isLink = 1;
|
||||
data.linkPath = (char *) malloc (CLIENT_COMMAND_STRING_SIZE*sizeof(char));
|
||||
data.linkPath = (char *) DYNMEM_malloc (CLIENT_COMMAND_STRING_SIZE*sizeof(char), &*memoryTable);
|
||||
if ((len = readlink (fileList[i], data.linkPath, CLIENT_COMMAND_STRING_SIZE)) > 0)
|
||||
{
|
||||
data.linkPath[len] = 0;
|
||||
FILE_AppendToString(&data.finalStringPath, " -> ");
|
||||
FILE_AppendToString(&data.finalStringPath, data.linkPath);
|
||||
FILE_AppendToString(&data.finalStringPath, " -> ", &*memoryTable);
|
||||
FILE_AppendToString(&data.finalStringPath, data.linkPath, &*memoryTable);
|
||||
}
|
||||
}
|
||||
|
||||
@ -405,10 +417,7 @@ int searchInLoginFailsVector(void * loginFailsVector, void *element)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
void cleanup_openssl()
|
||||
{
|
||||
EVP_cleanup();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -417,7 +426,7 @@ void deleteLoginFailsData(void *element)
|
||||
; //NOP
|
||||
}
|
||||
|
||||
void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo)
|
||||
void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo, DYNMEM_MemoryTable_DataType **memoryTable)
|
||||
{
|
||||
int i;
|
||||
int fileAndFoldersCount = 0;
|
||||
@ -479,7 +488,7 @@ void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo)
|
||||
|
||||
if (strlen(data.fileNameNoPath) > 0)
|
||||
{
|
||||
data.finalStringPath = (char *) malloc (strlen(data.fileNameNoPath)+1);
|
||||
data.finalStringPath = (char *) DYNMEM_malloc (strlen(data.fileNameNoPath)+1, &*memoryTable);
|
||||
strcpy(data.finalStringPath, data.fileNameNoPath);
|
||||
}
|
||||
|
||||
@ -489,12 +498,12 @@ void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo)
|
||||
{
|
||||
int len = 0;
|
||||
data.isLink = 1;
|
||||
data.linkPath = (char *) malloc (CLIENT_COMMAND_STRING_SIZE*sizeof(char));
|
||||
data.linkPath = (char *) DYNMEM_malloc (CLIENT_COMMAND_STRING_SIZE*sizeof(char), &*memoryTable);
|
||||
if ((len = readlink (data.fileList[i], data.linkPath, CLIENT_COMMAND_STRING_SIZE)) > 0)
|
||||
{
|
||||
data.linkPath[len] = 0;
|
||||
FILE_AppendToString(&data.finalStringPath, " -> ");
|
||||
FILE_AppendToString(&data.finalStringPath, data.linkPath);
|
||||
FILE_AppendToString(&data.finalStringPath, " -> ", &*memoryTable);
|
||||
FILE_AppendToString(&data.finalStringPath, data.linkPath, &*memoryTable);
|
||||
}
|
||||
}
|
||||
|
||||
@ -578,8 +587,8 @@ void resetWorkerData(ftpDataType *data, int clientId, int isInitialization)
|
||||
memset(data->clients[clientId].workerData.activeIpAddress, 0, CLIENT_BUFFER_STRING_SIZE);
|
||||
memset(data->clients[clientId].workerData.theCommandReceived, 0, CLIENT_BUFFER_STRING_SIZE);
|
||||
|
||||
cleanDynamicStringDataType(&data->clients[clientId].workerData.ftpCommand.commandArgs, isInitialization);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].workerData.ftpCommand.commandOps, isInitialization);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].workerData.ftpCommand.commandArgs, isInitialization, &data->clients[clientId].workerData.memoryTable);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].workerData.ftpCommand.commandOps, isInitialization, &data->clients[clientId].workerData.memoryTable);
|
||||
|
||||
/* wait main for action */
|
||||
if (isInitialization != 1)
|
||||
@ -638,7 +647,7 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization)
|
||||
{
|
||||
if (isInitialization != 1)
|
||||
{
|
||||
void *pReturn;
|
||||
|
||||
if (data->clients[clientId].workerData.threadIsAlive == 1)
|
||||
pthread_cancel(data->clients[clientId].workerData.workerThread);
|
||||
|
||||
@ -679,18 +688,17 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization)
|
||||
memset(data->clients[clientId].clientIpAddress, 0, INET_ADDRSTRLEN);
|
||||
memset(data->clients[clientId].buffer, 0, CLIENT_BUFFER_STRING_SIZE);
|
||||
memset(data->clients[clientId].theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE);
|
||||
cleanLoginData(&data->clients[clientId].login, isInitialization);
|
||||
cleanLoginData(&data->clients[clientId].login, isInitialization, &data->clients[clientId].memoryTable);
|
||||
|
||||
//Rename from and to data init
|
||||
cleanDynamicStringDataType(&data->clients[clientId].renameFromFile, isInitialization);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].renameToFile, isInitialization);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].fileToStor, isInitialization);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].fileToRetr, isInitialization);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].listPath, isInitialization);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].nlistPath, isInitialization);
|
||||
|
||||
cleanDynamicStringDataType(&data->clients[clientId].ftpCommand.commandArgs, isInitialization);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].ftpCommand.commandOps, isInitialization);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].renameFromFile, isInitialization, &data->clients[clientId].memoryTable);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].renameToFile, isInitialization, &data->clients[clientId].memoryTable);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].fileToStor, isInitialization, &data->clients[clientId].memoryTable);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].fileToRetr, isInitialization, &data->clients[clientId].memoryTable);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].listPath, isInitialization, &data->clients[clientId].memoryTable);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].nlistPath, isInitialization, &data->clients[clientId].memoryTable);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].ftpCommand.commandArgs, isInitialization, &data->clients[clientId].memoryTable);
|
||||
cleanDynamicStringDataType(&data->clients[clientId].ftpCommand.commandOps, isInitialization, &data->clients[clientId].memoryTable);
|
||||
|
||||
data->clients[clientId].connectionTimeStamp = 0;
|
||||
data->clients[clientId].tlsNegotiatingTimeStart = 0;
|
||||
|
19
ftpData.h
19
ftpData.h
@ -259,14 +259,18 @@ struct ftpListData
|
||||
char lastModifiedDataString[LIST_DATA_TYPE_MODIFIED_DATA_STR_SIZE];
|
||||
} typedef ftpListDataType;
|
||||
|
||||
void cleanLoginData(loginDataType *loginData, int init);
|
||||
void cleanDynamicStringDataType(dynamicStringDataType *dynamicString, int init);
|
||||
void setDynamicStringDataType(dynamicStringDataType *dynamicString, char *theString, int stringLen);
|
||||
int getSafePath(dynamicStringDataType *safePath, char *theDirectoryName, loginDataType *theHomePath);
|
||||
void appendToDynamicStringDataType(dynamicStringDataType *dynamicString, char *theString, int stringLen);
|
||||
void cleanLoginData(loginDataType *loginData, int init, DYNMEM_MemoryTable_DataType **memoryTable);
|
||||
void cleanDynamicStringDataType(dynamicStringDataType *dynamicString, int init, DYNMEM_MemoryTable_DataType **memoryTable);
|
||||
|
||||
void setDynamicStringDataType(dynamicStringDataType *dynamicString, char *theString, int stringLen, DYNMEM_MemoryTable_DataType **memoryTable);
|
||||
int getSafePath(dynamicStringDataType *safePath, char *theDirectoryName, loginDataType *theHomePath, DYNMEM_MemoryTable_DataType **memoryTable);
|
||||
void appendToDynamicStringDataType(dynamicStringDataType *dynamicString, char *theString, int stringLen, DYNMEM_MemoryTable_DataType **memoryTable);
|
||||
|
||||
|
||||
void setRandomicPort(ftpDataType *data, int socketPosition);
|
||||
void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo);
|
||||
int writeListDataInfoToSocket(ftpDataType *data, int clientId, int *filesNumber, int commandType);
|
||||
void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo, DYNMEM_MemoryTable_DataType **memoryTable);
|
||||
int writeListDataInfoToSocket(ftpDataType *data, int clientId, int *filesNumber, int commandType, DYNMEM_MemoryTable_DataType **memoryTable);
|
||||
|
||||
int searchInLoginFailsVector(void *loginFailsVector, void *element);
|
||||
void deleteLoginFailsData(void *element);
|
||||
void deleteListDataInfoVector(void *TheElementToDelete);
|
||||
@ -275,6 +279,7 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization);
|
||||
int compareStringCaseInsensitive(char *stringIn, char* stringRef, int stringLenght);
|
||||
int isCharInString(char *theString, int stringLen, char theChar);
|
||||
void destroyConfigurationVectorElement(DYNV_VectorGenericDataType *theVector);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
30
ftpServer.c
30
ftpServer.c
@ -381,7 +381,7 @@ void *connectionWorkerHandle(void * socketId)
|
||||
}
|
||||
|
||||
//returnCode = writeListDataInfoToSocket(ftpData.clients[theSocketId].listPath.text, ftpData.clients[theSocketId].workerData.socketConnection, &theFiles, theCommandType);
|
||||
returnCode = writeListDataInfoToSocket(&ftpData, theSocketId, &theFiles, theCommandType);
|
||||
returnCode = writeListDataInfoToSocket(&ftpData, theSocketId, &theFiles, theCommandType, &ftpData.clients[theSocketId].workerData.memoryTable);
|
||||
if (returnCode <= 0)
|
||||
{
|
||||
ftpData.clients[theSocketId].closeTheClient = 1;
|
||||
@ -485,6 +485,9 @@ void runFtpServer(void)
|
||||
//Endless loop ftp process
|
||||
while (1)
|
||||
{
|
||||
|
||||
printf("\nUsed memory : %lld", DYNMEM_GetTotalMemory());
|
||||
|
||||
/* waits for socket activity, if no activity then checks for client socket timeouts */
|
||||
if (selectWait(&ftpData) == 0)
|
||||
{
|
||||
@ -654,8 +657,8 @@ static int processCommand(int processingElement)
|
||||
//printTimeStamp();
|
||||
//printf ("Command received from (%d): %s", processingElement, ftpData.clients[processingElement].theCommandReceived);
|
||||
|
||||
cleanDynamicStringDataType(&ftpData.clients[processingElement].ftpCommand.commandArgs, 0);
|
||||
cleanDynamicStringDataType(&ftpData.clients[processingElement].ftpCommand.commandOps, 0);
|
||||
cleanDynamicStringDataType(&ftpData.clients[processingElement].ftpCommand.commandArgs, 0, &ftpData.clients[processingElement].memoryTable);
|
||||
cleanDynamicStringDataType(&ftpData.clients[processingElement].ftpCommand.commandOps, 0, &ftpData.clients[processingElement].memoryTable);
|
||||
|
||||
if (ftpData.clients[processingElement].login.userLoggedIn == 0 &&
|
||||
(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "USER", strlen("USER")) != 1 &&
|
||||
@ -866,17 +869,24 @@ static int processCommand(int processingElement)
|
||||
|
||||
void deallocateMemory(void)
|
||||
{
|
||||
printf("\n Deallocating the memory.. ");
|
||||
int i = 0;
|
||||
// printf("\n Deallocating the memory.. ");
|
||||
// printf("\nDYNMEM_freeAll called");
|
||||
// printf("\nElement size: %ld", ftpData.generalDynamicMemoryTable->size);
|
||||
// printf("\nElement address: %ld", (long int) ftpData.generalDynamicMemoryTable->address);
|
||||
// printf("\nElement nextElement: %ld",(long int) ftpData.generalDynamicMemoryTable->nextElement);
|
||||
// printf("\nElement previousElement: %ld",(long int) ftpData.generalDynamicMemoryTable->previousElement);
|
||||
|
||||
printf("\nDYNMEM_freeAll called");
|
||||
printf("\nElement size: %ld", ftpData.generalDynamicMemoryTable->size);
|
||||
printf("\nElement address: %ld", (long int) ftpData.generalDynamicMemoryTable->address);
|
||||
printf("\nElement nextElement: %ld",(long int) ftpData.generalDynamicMemoryTable->nextElement);
|
||||
printf("\nElement previousElement: %ld",(long int) ftpData.generalDynamicMemoryTable->previousElement);
|
||||
|
||||
for (i = 0; i < ftpData.ftpParameters.maxClients; i++)
|
||||
{
|
||||
DYNMEM_freeAll(&ftpData.clients[i].memoryTable);
|
||||
DYNMEM_freeAll(&ftpData.clients[i].workerData.memoryTable);
|
||||
}
|
||||
|
||||
DYNMEM_freeAll(&ftpData.ftpParameters.usersVector.memoryTable);
|
||||
DYNMEM_freeAll(&ftpData.generalDynamicMemoryTable);
|
||||
//printf("\n ftpData.generalDynamicMemoryTable = %ld", ftpData.generalDynamicMemoryTable);
|
||||
|
||||
#ifdef OPENSSL_ENABLED
|
||||
SSL_CTX_free(ftpData.serverCtx);
|
||||
cleanupOpenssl();
|
||||
|
@ -47,9 +47,9 @@ void destroyConfigurationVectorElement(DYNV_VectorGenericDataType *theVector)
|
||||
int i;
|
||||
for (i = 0; i < theVector->Size; i++)
|
||||
{
|
||||
printf("\n(parameter_DataType *)theVector->Data[%d])->value = %ld", i, ((parameter_DataType *)theVector->Data)->value);
|
||||
//printf("\n(parameter_DataType *)theVector->Data[%d])->value = %ld", i, ((parameter_DataType *)theVector->Data)->value);
|
||||
DYNMEM_free(((parameter_DataType *)theVector->Data[i])->value, &theVector->memoryTable);
|
||||
printf("\n(parameter_DataType *)theVector->Data[%d])->name = %ld", i, ((parameter_DataType *)theVector->Data)->name);
|
||||
//printf("\n(parameter_DataType *)theVector->Data[%d])->name = %ld", i, ((parameter_DataType *)theVector->Data)->name);
|
||||
DYNMEM_free(((parameter_DataType *)theVector->Data[i])->name, &theVector->memoryTable);
|
||||
DYNMEM_free(theVector->Data[i], &theVector->memoryTable);
|
||||
}
|
||||
@ -100,7 +100,7 @@ void configurationRead(ftpParameters_DataType *ftpParameters)
|
||||
}
|
||||
|
||||
DYNV_VectorGeneric_Destroy(&configParameters, destroyConfigurationVectorElement);
|
||||
printf("\n\nconfigParameters.memoryTable = %d ***", configParameters.memoryTable);
|
||||
//printf("\n\nconfigParameters.memoryTable = %d ***", configParameters.memoryTable);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -144,13 +144,13 @@ void initFtpData(ftpDataType *ftpData)
|
||||
ftpData->connectedClients = 0;
|
||||
ftpData->clients = (clientDataType *) DYNMEM_malloc((sizeof(clientDataType) * ftpData->ftpParameters.maxClients), &ftpData->generalDynamicMemoryTable);
|
||||
|
||||
printf("\nDYNMEM_malloc called");
|
||||
printf("\nElement location: %ld", (long int) ftpData->generalDynamicMemoryTable);
|
||||
fflush(0);
|
||||
printf("\nElement size: %ld", ftpData->generalDynamicMemoryTable->size);
|
||||
printf("\nElement address: %ld", (long int) ftpData->generalDynamicMemoryTable->address);
|
||||
printf("\nElement nextElement: %ld",(long int) ftpData->generalDynamicMemoryTable->nextElement);
|
||||
printf("\nElement previousElement: %ld",(long int) ftpData->generalDynamicMemoryTable->previousElement);
|
||||
//printf("\nDYNMEM_malloc called");
|
||||
//printf("\nElement location: %ld", (long int) ftpData->generalDynamicMemoryTable);
|
||||
//fflush(0);
|
||||
//printf("\nElement size: %ld", ftpData->generalDynamicMemoryTable->size);
|
||||
//printf("\nElement address: %ld", (long int) ftpData->generalDynamicMemoryTable->address);
|
||||
//printf("\nElement nextElement: %ld",(long int) ftpData->generalDynamicMemoryTable->nextElement);
|
||||
//printf("\nElement previousElement: %ld",(long int) ftpData->generalDynamicMemoryTable->previousElement);
|
||||
|
||||
|
||||
ftpData->serverIp.ip[0] = 127;
|
||||
@ -578,9 +578,6 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
||||
userData.ownerShip.groupOwnerString = NULL;
|
||||
userData.ownerShip.userOwnerString = NULL;
|
||||
|
||||
|
||||
|
||||
|
||||
userData.name = DYNMEM_malloc((strlen(((parameter_DataType *) parametersVector->Data[searchUserIndex])->value) + 1), &ftpParameters->usersVector.memoryTable);
|
||||
userData.password = DYNMEM_malloc((strlen(((parameter_DataType *) parametersVector->Data[searchPasswordIndex])->value) + 1), &ftpParameters->usersVector.memoryTable);
|
||||
userData.homePath = DYNMEM_malloc((strlen(((parameter_DataType *) parametersVector->Data[searchHomeIndex])->value) + 1), &ftpParameters->usersVector.memoryTable);
|
||||
@ -625,7 +622,6 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
||||
printf("\nuserData.gid = %d", userData.ownerShip.gid);
|
||||
printf("\nuserData.uid = %d", userData.ownerShip.uid);
|
||||
printf("\nuserData.ownerShipSet = %d", userData.ownerShip.ownerShipSet);
|
||||
|
||||
ftpParameters->usersVector.PushBack(&ftpParameters->usersVector, &userData, sizeof(usersParameters_DataType));
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ int socketWorkerPrintf(ftpDataType * ftpData, int clientId, const char *__restri
|
||||
char theBuffer[SOCKET_PRINTF_BUFFER];
|
||||
int theStringSize = 0;
|
||||
memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER);
|
||||
printf("\nWriting to worker socket id %dd, TLS %d: ", clientId, ftpData->clients[clientId].dataChannelIsTls);
|
||||
//printf("\nWriting to worker socket id %dd, TLS %d: ", clientId, ftpData->clients[clientId].dataChannelIsTls);
|
||||
va_list args;
|
||||
va_start(args, __fmt);
|
||||
while (*__fmt != '\0')
|
||||
@ -462,7 +462,7 @@ void closeClient(ftpDataType * ftpData, int processingSocket)
|
||||
|
||||
if (ftpData->clients[processingSocket].workerData.threadIsAlive == 1)
|
||||
{
|
||||
void *pReturn;
|
||||
|
||||
pthread_cancel(ftpData->clients[processingSocket].workerData.workerThread);
|
||||
//pthread_join(ftpData->clients[processingSocket].workerData.workerThread, &pReturn);
|
||||
printf("\nQuit command received the Pasv Thread has been cancelled.");
|
||||
|
@ -59,8 +59,7 @@ void *DYNMEM_malloc(size_t bytes, DYNMEM_MemoryTable_DataType **memoryListHead)
|
||||
DYNMEM_MemoryTable_DataType *newItem = NULL;
|
||||
memory = calloc(bytes,1);
|
||||
newItem = calloc(1, sizeof(DYNMEM_MemoryTable_DataType));
|
||||
|
||||
printf("Allocating new item in memory, size of %d", bytes);
|
||||
//printf("Allocating new item in memory, size of %d", bytes);
|
||||
|
||||
if(memory)
|
||||
{
|
||||
@ -89,10 +88,10 @@ void *DYNMEM_malloc(size_t bytes, DYNMEM_MemoryTable_DataType **memoryListHead)
|
||||
//printf("\nmemoryListHead = newItem %ld", (int) *memoryListHead);
|
||||
}
|
||||
|
||||
//printf("\nElement size: %ld", (*memoryListHead)->size);
|
||||
printf("\nElement address: %ld", (long int) (*memoryListHead)->address);
|
||||
//printf("\nElement nextElement: %ld",(long int) (*memoryListHead)->nextElement);
|
||||
//printf("\nElement previousElement: %ld",(long int) (*memoryListHead)->previousElement);
|
||||
// printf("\nElement size: %ld", (*memoryListHead)->size);
|
||||
// printf("\nElement address: %ld", (long int) (*memoryListHead)->address);
|
||||
// printf("\nElement nextElement: %ld",(long int) (*memoryListHead)->nextElement);
|
||||
// printf("\nElement previousElement: %ld",(long int) (*memoryListHead)->previousElement);
|
||||
|
||||
return memory;
|
||||
}
|
||||
@ -106,15 +105,19 @@ void *DYNMEM_malloc(size_t bytes, DYNMEM_MemoryTable_DataType **memoryListHead)
|
||||
void *DYNMEM_realloc(void *theMemoryAddress, size_t bytes, DYNMEM_MemoryTable_DataType **memoryListHead)
|
||||
{
|
||||
void *newMemory = NULL;
|
||||
//printf("\nSearching address %lld", theMemoryAddress);
|
||||
newMemory = realloc(theMemoryAddress, bytes);
|
||||
|
||||
//printf("Reallocating item in memory, size of %d", bytes);
|
||||
//printf("\nReallocating item in memory, size of %d", bytes);
|
||||
//printf("\nSearching address %lld", theMemoryAddress);
|
||||
//printf("(*memoryListHead) = %lld", (*memoryListHead));
|
||||
|
||||
if(newMemory)
|
||||
{
|
||||
DYNMEM_MemoryTable_DataType *temp = NULL,*found = NULL;
|
||||
for( temp = (*memoryListHead); temp!=NULL; temp = temp->nextElement)
|
||||
{
|
||||
//printf("\n %lld == %lld", temp->address, theMemoryAddress);
|
||||
if(temp->address == theMemoryAddress)
|
||||
{
|
||||
found = temp;
|
||||
@ -124,7 +127,12 @@ void *DYNMEM_realloc(void *theMemoryAddress, size_t bytes, DYNMEM_MemoryTable_Da
|
||||
|
||||
if(!found)
|
||||
{
|
||||
report_error_q("Unable to free memory not previously allocated",__FILE__,__LINE__, 0);
|
||||
fflush(0);
|
||||
//Debug TRAP
|
||||
char *theData ="c";
|
||||
strcpy(theData, "NOOOOOOOOOOOOOOOO");
|
||||
|
||||
report_error_q("Unable to reallocate memory not previously allocated",__FILE__,__LINE__, 0);
|
||||
// Report this as an error
|
||||
}
|
||||
|
||||
@ -184,7 +192,7 @@ void DYNMEM_free(void *f_address, DYNMEM_MemoryTable_DataType ** memoryListHead)
|
||||
DYNMEM_DecreaseMemoryCounter(found->size + sizeof(DYNMEM_MemoryTable_DataType));
|
||||
|
||||
|
||||
printf("\nFree of %ld", f_address);
|
||||
//printf("\nFree of %ld", f_address);
|
||||
|
||||
free(f_address);
|
||||
if(found->previousElement)
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
#include "fileManagement.h"
|
||||
#include "dynamicVectors.h"
|
||||
#include "dynamicMemory.h"
|
||||
|
||||
static int FILE_CompareString(const void * a, const void * b);
|
||||
|
||||
@ -605,10 +606,10 @@ time_t FILE_GetLastModifiedData(char *path)
|
||||
return statbuf.st_mtime;
|
||||
}
|
||||
|
||||
void FILE_AppendToString(char ** sourceString, char *theString)
|
||||
void FILE_AppendToString(char ** sourceString, char *theString, DYNMEM_MemoryTable_DataType ** memoryTable)
|
||||
{
|
||||
int theNewSize = strlen(*sourceString) + strlen(theString);
|
||||
*sourceString = realloc(*sourceString, theNewSize + 10);
|
||||
*sourceString = DYNMEM_realloc(*sourceString, theNewSize + 10, &*memoryTable);
|
||||
strcat(*sourceString, theString);
|
||||
(*sourceString)[theNewSize] = '\0';
|
||||
}
|
||||
|
@ -64,7 +64,7 @@
|
||||
char * FILE_GetOwner(char *fileName);
|
||||
char * FILE_GetGroupOwner(char *fileName);
|
||||
time_t FILE_GetLastModifiedData(char *path);
|
||||
void FILE_AppendToString(char ** sourceString, char *theString);
|
||||
void FILE_AppendToString(char ** sourceString, char *theString, DYNMEM_MemoryTable_DataType ** memoryTable);
|
||||
void FILE_DirectoryToParent(char ** sourceString);
|
||||
int FILE_LockFile(int fd);
|
||||
int FILE_doChownFromUidGidString(const char *file_path, const char *user_name, const char *group_name);
|
||||
|
62
uFTP.c
62
uFTP.c
@ -22,6 +22,53 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
void myFunction (void * p);
|
||||
void myFunction2 (void * p);
|
||||
void myFunction3 (void * p);
|
||||
void myFunction4 (void **p);
|
||||
|
||||
void myFunction (void * p)
|
||||
{
|
||||
static int i2 = 11;
|
||||
myFunction2(p);
|
||||
p = &i2;
|
||||
printf("\n1 p = %lld address of the pointer is %lld", p, &p);
|
||||
printf(" intval %d", *(int *) p);
|
||||
}
|
||||
|
||||
void myFunction2 (void * p)
|
||||
{
|
||||
myFunction3(p);
|
||||
printf("\n2 p = %lld address of the pointer is %lld", p, &p);
|
||||
printf(" intval %d", *(int *) p);
|
||||
}
|
||||
|
||||
void myFunction3 (void * p)
|
||||
{
|
||||
printf("\n3 p = %lld address of the pointer is %lld", p, &p);
|
||||
printf(" intval %d", *(int *) p);
|
||||
}
|
||||
|
||||
void myFunction4 (void **p)
|
||||
{
|
||||
static int oraSi = 12;
|
||||
printf("\n4 p = %lld address of the pointer is %lld", *p, &*p);
|
||||
printf(" intval %d", *(int *) *p);
|
||||
|
||||
*p = &oraSi;
|
||||
myFunction5(&*p);
|
||||
}
|
||||
|
||||
void myFunction5 (void **p)
|
||||
{
|
||||
static int oraSi = 13;
|
||||
printf("\n5 p = %lld address of the pointer is %lld", *p, &*p);
|
||||
printf(" intval %d", *(int *) *p);
|
||||
|
||||
*p = &oraSi;
|
||||
}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -29,6 +76,19 @@
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
/*
|
||||
void *p;
|
||||
int a = 10;
|
||||
p = (void *)&a;
|
||||
|
||||
printf("\np at init = %lld address of the pointer is %lld", p, &p);
|
||||
//myFunction(p);
|
||||
printf("\np after myFunction = %lld address of the pointer is %lld", p, &p);
|
||||
myFunction4(&p);
|
||||
printf("\np after myFunction4 = %lld address of the pointer is %lld", p, &p);
|
||||
printf(" intval %d", *(int *) p);
|
||||
exit(0);
|
||||
*/
|
||||
runFtpServer();
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user