mirror of
https://github.com/kingk85/uFTP.git
synced 2025-04-12 10:48:40 +03:00
Many error handling bug fix and some minor fix
This commit is contained in:
@ -1,20 +1,6 @@
|
||||
#LINARO
|
||||
#CC=arm-linux-gnueabihf-gcc
|
||||
|
||||
#Other arm
|
||||
#CC=arm-unknown-linux-gnu-gcc
|
||||
|
||||
#Linux Generic
|
||||
CC=gcc
|
||||
|
||||
#Windows
|
||||
#CC=i686-w64-mingw32-gcc
|
||||
|
||||
#Windows
|
||||
#CCWIN=i686-w64-mingw32-gcc
|
||||
#CCLINUX=gcc
|
||||
#CCARM=/opt/crosstool/gcc-4.0.1-glibc-2.3.5/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-gcc
|
||||
|
||||
OUTPATH=./build/
|
||||
SOURCE_MODULES_PATH=./library/
|
||||
CFLAGS=-c -Wall -I.
|
||||
@ -23,10 +9,10 @@ HEADERS=-I
|
||||
LIBPATH=./build/modules/
|
||||
BUILDFILES=start uFTP end
|
||||
|
||||
DEFINITIONS=
|
||||
#DEFINITIONS=
|
||||
|
||||
#TO ENABLE THE LARGE FILE SUPPORT UNCOMMENT THE NEXT LINE
|
||||
#DEFINITIONS=-D_LARGEFILE64_SOURCE
|
||||
DEFINITIONS=-D_LARGEFILE64_SOURCE
|
||||
|
||||
all: $(BUILDFILES)
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
dist/Debug/GNU-Linux/uftp
vendored
BIN
dist/Debug/GNU-Linux/uftp
vendored
Binary file not shown.
1
dist/Debug/GNU-Linux/uftpd.cfg
vendored
1
dist/Debug/GNU-Linux/uftpd.cfg
vendored
@ -1 +0,0 @@
|
||||
../../../uftpd.cfg
|
@ -47,22 +47,26 @@
|
||||
int parseCommandUser(clientDataType *theClientData)
|
||||
{
|
||||
int returnCode;
|
||||
char *theName;
|
||||
theName = getFtpCommandArg("USER", theClientData->theCommandReceived, 0);
|
||||
char *theUserName;
|
||||
theUserName = getFtpCommandArg("USER", theClientData->theCommandReceived, 0);
|
||||
|
||||
if (strlen(theName) >= 1)
|
||||
if (strlen(theUserName) >= 1)
|
||||
{
|
||||
setDynamicStringDataType(&theClientData->login.name, theName, strlen(theName));
|
||||
setDynamicStringDataType(&theClientData->login.name, theUserName, strlen(theUserName));
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "331 User ok, Waiting for the password.\r\n");
|
||||
//printf("\nUSER COMMAND OK, USERNAME IS: %s", theClientData->login.name.text);
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "430 Invalid username.\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
}
|
||||
@ -70,20 +74,48 @@ int parseCommandUser(clientDataType *theClientData)
|
||||
/* Elaborate the User login command */
|
||||
int parseCommandSite(clientDataType *theClientData)
|
||||
{
|
||||
int returnCode;
|
||||
int returnCode, setPermissionsReturnCode;
|
||||
char *theCommand;
|
||||
theCommand = getFtpCommandArg("SITE", theClientData->theCommandReceived, 0);
|
||||
|
||||
|
||||
if(compareStringCaseInsensitive(theCommand, "CHMOD", strlen("CHMOD")) == 1)
|
||||
{
|
||||
setPermissions(theCommand, theClientData->login.absolutePath.text, theClientData->login.ownerShip);
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "200 Permissions changed\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
setPermissionsReturnCode = setPermissions(theCommand, theClientData->login.absolutePath.text, theClientData->login.ownerShip);
|
||||
|
||||
switch (setPermissionsReturnCode)
|
||||
{
|
||||
case FTP_CHMODE_COMMAND_RETURN_CODE_OK:
|
||||
{
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "200 Permissions changed\r\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case FTP_CHMODE_COMMAND_RETURN_CODE_NO_FILE:
|
||||
{
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "550 chmod no such file\r\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case FTP_CHMODE_COMMAND_RETURN_CODE_NO_PERMISSIONS:
|
||||
{
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "550 Some errors occoured while changing file permissions.\r\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG:
|
||||
default:
|
||||
{
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "500 unknown extension\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
}
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
@ -103,7 +135,6 @@ int parseCommandPass(ftpDataType * data, int socketId)
|
||||
element.failureNumbers = 1;
|
||||
|
||||
searchPosition = data->loginFailsVector.SearchElement(&data->loginFailsVector, &element);
|
||||
//printf("\nsearchPosition = %d", searchPosition);
|
||||
|
||||
if (searchPosition != -1)
|
||||
{
|
||||
@ -187,7 +218,9 @@ int parseCommandAuth(clientDataType *theClientData)
|
||||
{
|
||||
int returnCode;
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "502 Security extensions not implemented.\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
|
||||
@ -195,7 +228,9 @@ int parseCommandPwd(clientDataType *theClientData)
|
||||
{
|
||||
int returnCode;
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "257 \"%s\" is your current location\r\n", theClientData->login.ftpPath.text);
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
|
||||
@ -203,13 +238,14 @@ int parseCommandSyst(clientDataType *theClientData)
|
||||
{
|
||||
int returnCode;
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "215 UNIX Type: L8\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
|
||||
int parseCommandFeat(clientDataType *theClientData)
|
||||
{
|
||||
|
||||
/*
|
||||
211-Extensions supported:
|
||||
EPRT
|
||||
@ -234,7 +270,9 @@ int parseCommandFeat(clientDataType *theClientData)
|
||||
*/
|
||||
int returnCode;
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "211-Extensions supported:\r\n PASV\r\nUTF8\r\n211 End.\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
|
||||
@ -242,7 +280,9 @@ int parseCommandTypeA(clientDataType *theClientData)
|
||||
{
|
||||
int returnCode;
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "200 TYPE is now 8-bit binary\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
|
||||
@ -250,7 +290,10 @@ int parseCommandTypeI(clientDataType *theClientData)
|
||||
{
|
||||
int returnCode;
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "200 TYPE is now 8-bit binary\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
|
||||
@ -258,7 +301,9 @@ int parseCommandStruF(clientDataType *theClientData)
|
||||
{
|
||||
int returnCode;
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "200 TYPE is now 8-bit binary\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
|
||||
@ -266,7 +311,10 @@ int parseCommandModeS(clientDataType *theClientData)
|
||||
{
|
||||
int returnCode;
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "200 TYPE is now 8-bit binary\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
|
||||
@ -279,8 +327,8 @@ int parseCommandPasv(ftpDataType * data, int socketId)
|
||||
{
|
||||
pthread_cancel(data->clients[socketId].workerData.workerThread);
|
||||
}
|
||||
|
||||
pthread_join(data->clients[socketId].workerData.workerThread, &pReturn);
|
||||
//printf("\nThread has been cancelled.");
|
||||
data->clients[socketId].workerData.passiveModeOn = 1;
|
||||
data->clients[socketId].workerData.activeModeOn = 0;
|
||||
pthread_create(&data->clients[socketId].workerData.workerThread, NULL, connectionWorkerHandle, (void *) &data->clients[socketId].clientProgressiveNumber);
|
||||
@ -294,11 +342,8 @@ int parseCommandPort(ftpDataType * data, int socketId)
|
||||
int portBytes[2];
|
||||
theIpAndPort = getFtpCommandArg("PORT", data->clients[socketId].theCommandReceived, 0);
|
||||
sscanf(theIpAndPort, "%d,%d,%d,%d,%d,%d", &ipAddressBytes[0], &ipAddressBytes[1], &ipAddressBytes[2], &ipAddressBytes[3], &portBytes[0], &portBytes[1]);
|
||||
//printf("\ntheIpAndPort: %s", theIpAndPort);
|
||||
data->clients[socketId].workerData.connectionPort = (portBytes[0]*256)+portBytes[1];
|
||||
sprintf(data->clients[socketId].workerData.activeIpAddress, "%d.%d.%d.%d", ipAddressBytes[0],ipAddressBytes[1],ipAddressBytes[2],ipAddressBytes[3]);
|
||||
//printf("\ndata->clients[socketId].workerData.connectionPort: %d", data->clients[socketId].workerData.connectionPort);
|
||||
//printf("\ndata->clients[socketId].workerData.activeIpAddress: %s", data->clients[socketId].workerData.activeIpAddress);
|
||||
|
||||
void *pReturn;
|
||||
if (data->clients[socketId].workerData.threadIsAlive == 1)
|
||||
@ -306,7 +351,6 @@ int parseCommandPort(ftpDataType * data, int socketId)
|
||||
pthread_cancel(data->clients[socketId].workerData.workerThread);
|
||||
}
|
||||
pthread_join(data->clients[socketId].workerData.workerThread, &pReturn);
|
||||
//printf("\nThread has been cancelled.");
|
||||
data->clients[socketId].workerData.passiveModeOn = 0;
|
||||
data->clients[socketId].workerData.activeModeOn = 1;
|
||||
pthread_create(&data->clients[socketId].workerData.workerThread, NULL, connectionWorkerHandle, (void *) &data->clients[socketId].clientProgressiveNumber);
|
||||
@ -332,15 +376,18 @@ int parseCommandAbor(ftpDataType * data, int socketId)
|
||||
pthread_join(data->clients[socketId].workerData.workerThread, &pReturn);
|
||||
|
||||
returnCode = dprintf(data->clients[socketId].socketDescriptor, "426 ABORT\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
returnCode = dprintf(data->clients[socketId].socketDescriptor, "226 Transfer aborted\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnCode = dprintf(data->clients[socketId].socketDescriptor, "226 Since you see this ABOR must've succeeded\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
}
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
@ -396,7 +443,7 @@ int parseCommandList(ftpDataType * data, int socketId)
|
||||
data->clients[socketId].workerData.commandReceived = 1;
|
||||
pthread_mutex_unlock(&data->clients[socketId].workerData.conditionMutex);
|
||||
pthread_cond_signal(&data->clients[socketId].workerData.conditionVariable);
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
|
||||
int parseCommandNlst(ftpDataType * data, int socketId)
|
||||
@ -434,17 +481,13 @@ int parseCommandRetr(ftpDataType * data, int socketId)
|
||||
{
|
||||
int isSafePath = 0;
|
||||
char *theNameToRetr;
|
||||
|
||||
|
||||
//printf("\n\ndata->clients[socketId].theCommandReceived = %s", data->clients[socketId].theCommandReceived);
|
||||
|
||||
theNameToRetr = getFtpCommandArg("RETR", data->clients[socketId].theCommandReceived, 0);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].fileToRetr, 0);
|
||||
//printf("\n\ntheNameToRetr = %s", theNameToRetr);
|
||||
|
||||
|
||||
if (strlen(theNameToRetr) > 0)
|
||||
{
|
||||
isSafePath = getSafePath(&data->clients[socketId].fileToRetr, theNameToRetr, &data->clients[socketId].login);
|
||||
//printf("\n\ndata->clients[socketId].fileToRetr = %s", data->clients[socketId].fileToRetr);
|
||||
}
|
||||
|
||||
if (isSafePath == 1 &&
|
||||
@ -481,7 +524,6 @@ int parseCommandStor(ftpDataType * data, int socketId)
|
||||
if (isSafePath == 1)
|
||||
{
|
||||
pthread_mutex_lock(&data->clients[socketId].workerData.conditionMutex);
|
||||
//printf("data->clients[%d].fileToStor = %s", socketId, data->clients[socketId].fileToStor.text);
|
||||
memset(data->clients[socketId].workerData.theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE);
|
||||
strcpy(data->clients[socketId].workerData.theCommandReceived, data->clients[socketId].theCommandReceived);
|
||||
data->clients[socketId].workerData.commandReceived = 1;
|
||||
@ -622,12 +664,14 @@ int parseCommandRest(clientDataType *theClientData)
|
||||
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
|
||||
int parseCommandMkd(clientDataType *theClientData)
|
||||
{
|
||||
int returnCode;
|
||||
int functionReturnCode = FTP_COMMAND_NOT_RECONIZED;
|
||||
int isSafePath;
|
||||
char *theDirectoryFilename;
|
||||
dynamicStringDataType mkdFileName;
|
||||
@ -641,31 +685,58 @@ int parseCommandMkd(clientDataType *theClientData)
|
||||
if (isSafePath == 1)
|
||||
{
|
||||
int returnStatus;
|
||||
//printf("\nThe directory to make is: %s", mkdFileName.text);
|
||||
returnStatus = mkdir(mkdFileName.text, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
if (theClientData->login.ownerShip.ownerShipSet == 1)
|
||||
{
|
||||
FILE_doChownFromUidGid(mkdFileName.text, theClientData->login.ownerShip.uid, theClientData->login.ownerShip.gid);
|
||||
}
|
||||
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "257 \"%s\" : The directory was successfully created\r\n", theDirectoryFilename);
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
if (returnStatus == -1)
|
||||
{
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "550 error while creating directory %s\r\n", theDirectoryFilename);
|
||||
|
||||
if (returnCode <= 0)
|
||||
{
|
||||
functionReturnCode = FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
functionReturnCode = FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (theClientData->login.ownerShip.ownerShipSet == 1)
|
||||
{
|
||||
returnStatus = FILE_doChownFromUidGid(mkdFileName.text, theClientData->login.ownerShip.uid, theClientData->login.ownerShip.gid);
|
||||
}
|
||||
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "257 \"%s\" : The directory was successfully created\r\n", theDirectoryFilename);
|
||||
|
||||
if (returnCode <= 0)
|
||||
{
|
||||
functionReturnCode = FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
functionReturnCode = FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cleanDynamicStringDataType(&mkdFileName, 0);
|
||||
return FTP_COMMAND_NOT_RECONIZED;
|
||||
functionReturnCode = FTP_COMMAND_NOT_RECONIZED;
|
||||
}
|
||||
|
||||
cleanDynamicStringDataType(&mkdFileName, 0);
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
return functionReturnCode;
|
||||
}
|
||||
|
||||
int parseCommandOpts(clientDataType *theClientData)
|
||||
{
|
||||
int returnCode;
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "200 OK\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
|
||||
@ -681,7 +752,6 @@ int parseCommandDele(clientDataType *theClientData)
|
||||
theFileToDelete = getFtpCommandArg("DELE", theClientData->theCommandReceived, 0);
|
||||
|
||||
cleanDynamicStringDataType(&deleFileName, 1);
|
||||
|
||||
isSafePath = getSafePath(&deleFileName, theFileToDelete, &theClientData->login);
|
||||
|
||||
if (isSafePath == 1)
|
||||
@ -690,15 +760,28 @@ int parseCommandDele(clientDataType *theClientData)
|
||||
if (FILE_IsFile(deleFileName.text) == 1)
|
||||
{
|
||||
returnStatus = remove(deleFileName.text);
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "250 Deleted %s\r\n", theFileToDelete);
|
||||
|
||||
if (returnStatus == -1)
|
||||
{
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "550 Could not delete the file: %s some errors occoured\r\n", theFileToDelete);
|
||||
}
|
||||
else
|
||||
{
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "250 Deleted %s\r\n", theFileToDelete);
|
||||
}
|
||||
|
||||
functionReturnCode = FTP_COMMAND_PROCESSED;
|
||||
if (returnCode <= 0) functionReturnCode = FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
if (returnCode <= 0)
|
||||
functionReturnCode = FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "550 Could not delete the file: No such file\r\n");
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "550 Could not delete the file: No such file or file is a directory\r\n");
|
||||
functionReturnCode = FTP_COMMAND_PROCESSED;
|
||||
if (returnCode <= 0) functionReturnCode = FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
if (returnCode <= 0)
|
||||
functionReturnCode = FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -714,7 +797,11 @@ int parseCommandNoop(clientDataType *theClientData)
|
||||
{
|
||||
int returnCode;
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "200 Zzz...\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
if (returnCode <= 0) {
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
}
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
|
||||
@ -722,7 +809,9 @@ int notLoggedInMessage(clientDataType *theClientData)
|
||||
{
|
||||
int returnCode;
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "530 You aren't logged in\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
|
||||
@ -730,7 +819,9 @@ int parseCommandQuit(ftpDataType * data, int socketId)
|
||||
{
|
||||
int returnCode;
|
||||
returnCode = dprintf(data->clients[socketId].socketDescriptor, "221 Logout.\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
data->clients[socketId].closeTheClient = 1;
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
@ -752,19 +843,31 @@ int parseCommandRmd(clientDataType *theClientData)
|
||||
|
||||
if (isSafePath == 1)
|
||||
{
|
||||
//printf("\nThe directory to delete is: %s", rmdFileName.text);
|
||||
if (FILE_IsDirectory(rmdFileName.text) == 1)
|
||||
{
|
||||
returnStatus = rmdir(rmdFileName.text);
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "250 The directory was successfully removed\r\n");
|
||||
|
||||
if (returnStatus == -1)
|
||||
{
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "550 Could not remove the directory, some errors occoured.\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "250 The directory was successfully removed\r\n");
|
||||
}
|
||||
|
||||
functionReturnCode = FTP_COMMAND_PROCESSED;
|
||||
if (returnCode <= 0) functionReturnCode = FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
if (returnCode <= 0)
|
||||
functionReturnCode = FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "550 Could not delete the directory:No such directory\r\n");
|
||||
functionReturnCode = FTP_COMMAND_PROCESSED;
|
||||
if (returnCode <= 0) functionReturnCode = FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
if (returnCode <= 0)
|
||||
functionReturnCode = FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -896,22 +999,24 @@ int parseCommandRnto(clientDataType *theClientData)
|
||||
|
||||
int parseCommandCdup(clientDataType *theClientData)
|
||||
{
|
||||
int returnCode;
|
||||
|
||||
FILE_DirectoryToParent(&theClientData->login.absolutePath.text);
|
||||
FILE_DirectoryToParent(&theClientData->login.ftpPath.text);
|
||||
theClientData->login.absolutePath.textLen = strlen(theClientData->login.absolutePath.text);
|
||||
theClientData->login.ftpPath.textLen = strlen(theClientData->login.ftpPath.text);
|
||||
int returnCode;
|
||||
|
||||
if(strncmp(theClientData->login.absolutePath.text, theClientData->login.homePath.text, theClientData->login.homePath.textLen) != 0)
|
||||
{
|
||||
setDynamicStringDataType(&theClientData->login.absolutePath, theClientData->login.homePath.text, theClientData->login.homePath.textLen);
|
||||
}
|
||||
FILE_DirectoryToParent(&theClientData->login.absolutePath.text);
|
||||
FILE_DirectoryToParent(&theClientData->login.ftpPath.text);
|
||||
theClientData->login.absolutePath.textLen = strlen(theClientData->login.absolutePath.text);
|
||||
theClientData->login.ftpPath.textLen = strlen(theClientData->login.ftpPath.text);
|
||||
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "250 OK. Current directory is %s\r\n", theClientData->login.ftpPath.text);
|
||||
if(strncmp(theClientData->login.absolutePath.text, theClientData->login.homePath.text, theClientData->login.homePath.textLen) != 0)
|
||||
{
|
||||
setDynamicStringDataType(&theClientData->login.absolutePath, theClientData->login.homePath.text, theClientData->login.homePath.textLen);
|
||||
}
|
||||
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
returnCode = dprintf(theClientData->socketDescriptor, "250 OK. Current directory is %s\r\n", theClientData->login.ftpPath.text);
|
||||
|
||||
if (returnCode <= 0)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
|
||||
long long int writeRetrFile(char * theFilename, int thePasvSocketConnection, long long int startFrom, FILE *retrFP)
|
||||
@ -922,15 +1027,13 @@ long long int writeRetrFile(char * theFilename, int thePasvSocketConnection, lon
|
||||
long long int theFileSize;
|
||||
char buffer[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
|
||||
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
retrFP = fopen64(theFilename, "rb");
|
||||
#endif
|
||||
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
retrFP = fopen64(theFilename, "rb");
|
||||
#endif
|
||||
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
retrFP = fopen(theFilename, "rb");
|
||||
#endif
|
||||
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
retrFP = fopen(theFilename, "rb");
|
||||
#endif
|
||||
|
||||
if (retrFP == NULL)
|
||||
{
|
||||
@ -941,17 +1044,15 @@ long long int writeRetrFile(char * theFilename, int thePasvSocketConnection, lon
|
||||
|
||||
if (startFrom > 0)
|
||||
{
|
||||
//printf("\nSeek startFrom: %d", startFrom);
|
||||
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
currentPosition = (long long int) lseek64(fileno(retrFP), startFrom, SEEK_SET);
|
||||
#endif
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
currentPosition = (long long int) lseek64(fileno(retrFP), startFrom, SEEK_SET);
|
||||
#endif
|
||||
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
currentPosition = (long long int) lseek(fileno(retrFP), startFrom, SEEK_SET);
|
||||
#endif
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
currentPosition = (long long int) lseek(fileno(retrFP), startFrom, SEEK_SET);
|
||||
#endif
|
||||
|
||||
// printf("\nSeek result: %ld", currentPosition);
|
||||
if (currentPosition == -1)
|
||||
{
|
||||
fclose(retrFP);
|
||||
@ -1093,19 +1194,21 @@ int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataTyp
|
||||
#define STATUS_INCREASE 0
|
||||
#define STATUS_PERMISSIONS 1
|
||||
#define STATUS_LOCAL_PATH 2
|
||||
|
||||
|
||||
int permissionsCommandCursor = 0;
|
||||
int returnCode = 0;
|
||||
|
||||
int status = STATUS_INCREASE;
|
||||
char thePermissionString[1024];
|
||||
char theLocalPath[1024];
|
||||
char theFinalCommand[2048];
|
||||
char theFinalFilename[2048];
|
||||
int returnCodeSetPermissions, returnCodeSetOwnership;
|
||||
|
||||
memset(theLocalPath, 0, 1024);
|
||||
memset(thePermissionString, 0, 1024);
|
||||
memset(theFinalCommand, 0, 2048);
|
||||
memset(theFinalFilename, 0, 2048);
|
||||
int thePermissionStringCursor = 0, theLocalPathCursor = 0;
|
||||
|
||||
|
||||
while (permissionsCommand[permissionsCommandCursor] != '\r' &&
|
||||
permissionsCommand[permissionsCommandCursor] != '\n' &&
|
||||
permissionsCommand[permissionsCommandCursor] != '\0')
|
||||
@ -1127,51 +1230,58 @@ int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataTyp
|
||||
}
|
||||
if (thePermissionStringCursor < 1024 )
|
||||
thePermissionString[thePermissionStringCursor++] = permissionsCommand[permissionsCommandCursor];
|
||||
else
|
||||
return FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG;
|
||||
break;
|
||||
|
||||
case STATUS_LOCAL_PATH:
|
||||
if (theLocalPathCursor < 1024)
|
||||
theLocalPath[theLocalPathCursor++] = permissionsCommand[permissionsCommandCursor];
|
||||
else
|
||||
return FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG;
|
||||
break;
|
||||
}
|
||||
|
||||
permissionsCommandCursor++;
|
||||
}
|
||||
|
||||
//printf("\n thePermissionString = %s ", thePermissionString);
|
||||
//printf("\n theLocalPathCursor = %s ", theLocalPath);
|
||||
|
||||
//if (basePath[strlen(basePath)-1] != '/')
|
||||
//sprintf(theFinalCommand, "chmod %s %s/%s", thePermissionString, basePath, theLocalPath);
|
||||
//else
|
||||
//sprintf(theFinalCommand, "chmod %s %s%s", thePermissionString, basePath, theLocalPath);
|
||||
memset(theFinalFilename, 0, 2048);
|
||||
|
||||
//printf("\ntheFinalCommand = %s ", theFinalCommand);
|
||||
|
||||
//system(theFinalCommand);
|
||||
if (ownerShip.ownerShipSet == 1)
|
||||
if ((strlen(basePath) + strlen(theLocalPath) + 2) >= 2048)
|
||||
{
|
||||
memset(theFinalCommand, 0, 2048);
|
||||
if (basePath[strlen(basePath)-1] != '/')
|
||||
sprintf(theFinalCommand, "%s/%s", basePath, theLocalPath);
|
||||
else
|
||||
sprintf(theFinalCommand, "%s%s", basePath, theLocalPath);
|
||||
|
||||
FILE_doChownFromUidGid(theFinalCommand, ownerShip.uid, ownerShip.gid);
|
||||
return FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG;
|
||||
}
|
||||
|
||||
memset(theFinalCommand, 0, 2048);
|
||||
if (basePath[strlen(basePath)-1] != '/')
|
||||
{
|
||||
sprintf(theFinalFilename, "%s/%s", basePath, theLocalPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(theFinalFilename, "%s%s", basePath, theLocalPath);
|
||||
}
|
||||
|
||||
if (FILE_IsFile(theFinalFilename) != 1 &&
|
||||
FILE_IsDirectory(theFinalFilename) != 1)
|
||||
{
|
||||
return FTP_CHMODE_COMMAND_RETURN_CODE_NO_FILE;
|
||||
}
|
||||
|
||||
if (basePath[strlen(basePath)-1] != '/')
|
||||
sprintf(theFinalCommand, "%s/%s", basePath, theLocalPath);
|
||||
else
|
||||
sprintf(theFinalCommand, "%s%s", basePath, theLocalPath);
|
||||
if (ownerShip.ownerShipSet == 1)
|
||||
{
|
||||
returnCodeSetOwnership = FILE_doChownFromUidGid(theFinalFilename, ownerShip.uid, ownerShip.gid);
|
||||
}
|
||||
|
||||
returnCode = strtol(thePermissionString, 0, 8);
|
||||
if (chmod (theFinalCommand, returnCode) < 0)
|
||||
if (returnCodeSetPermissions = chmod (theFinalFilename, returnCode) < 0)
|
||||
{
|
||||
printf("\n---> ERROR WHILE SETTING FILE PERMISSION");
|
||||
}
|
||||
|
||||
return 1;
|
||||
if (returnCodeSetOwnership != 1 || returnCodeSetPermissions == -1)
|
||||
{
|
||||
return FTP_CHMODE_COMMAND_RETURN_CODE_NO_PERMISSIONS;
|
||||
}
|
||||
|
||||
return FTP_CHMODE_COMMAND_RETURN_CODE_OK;
|
||||
}
|
||||
|
@ -32,6 +32,12 @@
|
||||
#define FTP_COMMAND_PROCESSED 1
|
||||
#define FTP_COMMAND_PROCESSED_WRITE_ERROR 2
|
||||
|
||||
|
||||
#define FTP_CHMODE_COMMAND_RETURN_CODE_OK 1
|
||||
#define FTP_CHMODE_COMMAND_RETURN_CODE_NO_FILE 2
|
||||
#define FTP_CHMODE_COMMAND_RETURN_CODE_NO_PERMISSIONS 3
|
||||
#define FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG 4
|
||||
|
||||
#include "ftpData.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
40
ftpServer.c
40
ftpServer.c
@ -56,7 +56,7 @@ static int processCommand(int processingElement);
|
||||
void workerCleanup(void *socketId)
|
||||
{
|
||||
int theSocketId = *(int *)socketId;
|
||||
printf("\nClosing pasv socket (%d) ok!", theSocketId);
|
||||
//printf("\nClosing pasv socket (%d) ok!", theSocketId);
|
||||
shutdown(ftpData.clients[theSocketId].workerData.socketConnection, SHUT_RDWR);
|
||||
shutdown(ftpData.clients[theSocketId].workerData.passiveListeningSocket, SHUT_RDWR);
|
||||
close(ftpData.clients[theSocketId].workerData.socketConnection);
|
||||
@ -75,9 +75,6 @@ void *connectionWorkerHandle(void * socketId)
|
||||
if (ftpData.clients[theSocketId].workerData.passiveModeOn == 1)
|
||||
{
|
||||
int tries = 30;
|
||||
printf("\nPasv (%d) thread init opening port: %d", theSocketId, ftpData.clients[theSocketId].workerData.connectionPort);
|
||||
printf("\nPasv (%d) open ok: %d", theSocketId, ftpData.clients[theSocketId].workerData.connectionPort);
|
||||
|
||||
while (tries > 0)
|
||||
{
|
||||
setRandomicPort(&ftpData, theSocketId);
|
||||
@ -92,15 +89,13 @@ void *connectionWorkerHandle(void * socketId)
|
||||
}
|
||||
if (ftpData.clients[theSocketId].workerData.passiveListeningSocket == -1)
|
||||
{
|
||||
printf("\n ftpData.clients[theSocketId].workerData.passiveListeningSocket == -1");
|
||||
ftpData.clients[theSocketId].closeTheClient = 1;
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
if (ftpData.clients[theSocketId].workerData.socketIsConnected == 0)
|
||||
{
|
||||
printf("Waiting for pasv client connection on port: %d", ftpData.clients[theSocketId].workerData.connectionPort);
|
||||
|
||||
|
||||
returnCode = dprintf(ftpData.clients[theSocketId].socketDescriptor, "227 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n", ftpData.clients[theSocketId].serverIpAddressInteger[0], ftpData.clients[theSocketId].serverIpAddressInteger[1], ftpData.clients[theSocketId].serverIpAddressInteger[2], ftpData.clients[theSocketId].serverIpAddressInteger[3], (ftpData.clients[theSocketId].workerData.connectionPort / 256), (ftpData.clients[theSocketId].workerData.connectionPort % 256));
|
||||
if (returnCode <= 0)
|
||||
{
|
||||
@ -111,13 +106,10 @@ void *connectionWorkerHandle(void * socketId)
|
||||
//Wait for sockets
|
||||
if ((ftpData.clients[theSocketId].workerData.socketConnection = accept(ftpData.clients[theSocketId].workerData.passiveListeningSocket, 0, 0))!=-1)
|
||||
{
|
||||
printf("\nPasv (%d) connection initialized", theSocketId);
|
||||
ftpData.clients[theSocketId].workerData.socketIsConnected = 1;
|
||||
printf("\nPasv (%d) connection ok", theSocketId);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\n ftpData.clients[theSocketId].workerData.socketConnection == -1");
|
||||
ftpData.clients[theSocketId].closeTheClient = 1;
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
@ -125,7 +117,6 @@ void *connectionWorkerHandle(void * socketId)
|
||||
}
|
||||
else if (ftpData.clients[theSocketId].workerData.activeModeOn == 1)
|
||||
{
|
||||
printf("\nConnecting on the active client %s:%d", ftpData.clients[theSocketId].workerData.activeIpAddress, ftpData.clients[theSocketId].workerData.connectionPort);
|
||||
ftpData.clients[theSocketId].workerData.socketConnection = createActiveSocket(ftpData.clients[theSocketId].workerData.connectionPort, ftpData.clients[theSocketId].workerData.activeIpAddress);
|
||||
|
||||
if (ftpData.clients[theSocketId].workerData.socketConnection < 0)
|
||||
@ -165,19 +156,17 @@ void *connectionWorkerHandle(void * socketId)
|
||||
ftpData.clients[theSocketId].fileToStor.textLen > 0)
|
||||
{
|
||||
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
ftpData.clients[theSocketId].workerData.theStorFile = fopen64(ftpData.clients[theSocketId].fileToStor.text, "wb");
|
||||
#endif
|
||||
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
ftpData.clients[theSocketId].workerData.theStorFile = fopen(ftpData.clients[theSocketId].fileToStor.text, "wb");
|
||||
#endif
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
ftpData.clients[theSocketId].workerData.theStorFile = fopen64(ftpData.clients[theSocketId].fileToStor.text, "wb");
|
||||
#endif
|
||||
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
ftpData.clients[theSocketId].workerData.theStorFile = fopen(ftpData.clients[theSocketId].fileToStor.text, "wb");
|
||||
#endif
|
||||
|
||||
|
||||
if (ftpData.clients[theSocketId].workerData.theStorFile == NULL)
|
||||
{
|
||||
perror("Can't open the file");
|
||||
{
|
||||
returnCode = dprintf(ftpData.clients[theSocketId].socketDescriptor, "553 Unable to write the file\r\n");
|
||||
|
||||
if (returnCode <= 0)
|
||||
@ -189,9 +178,6 @@ void *connectionWorkerHandle(void * socketId)
|
||||
break;
|
||||
}
|
||||
|
||||
printf("\nftpData.clients[theSocketId].theFileNameToStor: %s", ftpData.clients[theSocketId].fileToStor.text);
|
||||
printf("\nftpData.clients[theSocketId].login.absolutePath.text: %s", ftpData.clients[theSocketId].login.absolutePath.text);
|
||||
|
||||
returnCode = dprintf(ftpData.clients[theSocketId].socketDescriptor, "150 Accepted data connection\r\n");
|
||||
|
||||
if (returnCode <= 0)
|
||||
@ -283,13 +269,10 @@ void *connectionWorkerHandle(void * socketId)
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
printf("\nPasv (%d) writeReturn: %lld", theSocketId, writeReturn);
|
||||
|
||||
writenSize = writeRetrFile(ftpData.clients[theSocketId].fileToRetr.text, ftpData.clients[theSocketId].workerData.socketConnection, ftpData.clients[theSocketId].workerData.retrRestartAtByte, ftpData.clients[theSocketId].workerData.theStorFile);
|
||||
ftpData.clients[theSocketId].workerData.retrRestartAtByte = 0;
|
||||
|
||||
printf("\nPasv (%d) writeReturn data: %lld",theSocketId, writeReturn);
|
||||
|
||||
if (writenSize == -1)
|
||||
{
|
||||
writeReturn = dprintf(ftpData.clients[theSocketId].socketDescriptor, "550 unable to open the file for reading\r\n");
|
||||
@ -309,7 +292,6 @@ void *connectionWorkerHandle(void * socketId)
|
||||
ftpData.clients[theSocketId].closeTheClient = 1;
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
printf("\nPasv (%d) writeReturn response to 21: %lld",theSocketId, writeReturn);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -329,6 +311,9 @@ void *connectionWorkerHandle(void * socketId)
|
||||
|
||||
void runFtpServer(void)
|
||||
{
|
||||
|
||||
printf("\nHello uFTP server v%s starting..\n", UFTP_SERVER_VERSION);
|
||||
|
||||
/* Needed for Select*/
|
||||
static int processingSock = 0, returnCode = 0;
|
||||
|
||||
@ -372,7 +357,6 @@ void runFtpServer(void)
|
||||
/* close the connection if quit flag has been set */
|
||||
if (ftpData.clients[processingSock].closeTheClient == 1)
|
||||
{
|
||||
printf("\nClosing client connection %d", ftpData.clients[processingSock].closeTheClient);
|
||||
closeClient(&ftpData, processingSock);
|
||||
continue;
|
||||
}
|
||||
|
@ -27,14 +27,11 @@
|
||||
#define FTPSERVER_H
|
||||
|
||||
#define MAX_FTP_CLIENTS 10
|
||||
|
||||
#define UFTP_SERVER_VERSION "1.0.1 beta"
|
||||
|
||||
void runFtpServer(void);
|
||||
|
||||
|
||||
void *connectionWorkerHandle(void * socketId);
|
||||
void workerCleanup(void *socketId);
|
||||
|
||||
void signal_callback_handler(int signum);
|
||||
|
||||
#endif /* FTPSERVER_H */
|
||||
|
@ -158,12 +158,7 @@ static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *paramet
|
||||
int i, state, nameIndex, valueIndex, allowSpacesInValue;
|
||||
char * theFileContent;
|
||||
|
||||
|
||||
printf("\n FILE_GetStringFromFile");
|
||||
|
||||
theFileSize = FILE_GetStringFromFile(path, &theFileContent);
|
||||
printf("\n FILE_GetStringFromFile Done");
|
||||
|
||||
|
||||
char name[PARAMETER_SIZE_LIMIT];
|
||||
char value[PARAMETER_SIZE_LIMIT];
|
||||
@ -178,6 +173,7 @@ static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *paramet
|
||||
|
||||
while (i < theFileSize)
|
||||
{
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case STATE_START:
|
||||
@ -259,7 +255,8 @@ static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *paramet
|
||||
else
|
||||
allowSpacesInValue = 0;
|
||||
}
|
||||
else if (theFileContent[i] == '\n')
|
||||
else if (theFileContent[i] == '\n' ||
|
||||
i == (theFileSize-1))
|
||||
{
|
||||
/* Value stored proceed to save */
|
||||
if (valueIndex > 0)
|
||||
@ -319,7 +316,7 @@ static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *paramet
|
||||
}
|
||||
|
||||
/* che if there is a value to store */
|
||||
if (state == STATE_VALUE &&
|
||||
if (state == STATE_STORE &&
|
||||
valueIndex > 0)
|
||||
{
|
||||
parameter_DataType parameter;
|
||||
@ -334,7 +331,6 @@ static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *paramet
|
||||
nameIndex = 0;
|
||||
valueIndex = 0;
|
||||
printf("\nParameter read: %s = %s", parameter.name, parameter.value);
|
||||
|
||||
parametersVector->PushBack(parametersVector, ¶meter, sizeof(parameter_DataType));
|
||||
}
|
||||
|
||||
|
@ -406,7 +406,7 @@ int evaluateClientSocketConnection(ftpDataType * ftpData)
|
||||
struct sockaddr_in socketRefuse_sockaddr_in;
|
||||
if ((socketRefuseFd = accept(ftpData->connectionData.theMainSocket, (struct sockaddr *)&socketRefuse_sockaddr_in, (socklen_t*)&socketRefuse_in_size))!=-1)
|
||||
{
|
||||
char *messageToWrite = "530 Server reached the maximum number of connection, please try later.\r\n";
|
||||
char *messageToWrite = "10068 Server reached the maximum number of connection, please try later.\r\n";
|
||||
write(socketRefuseFd, messageToWrite, strlen(messageToWrite));
|
||||
shutdown(socketRefuseFd, SHUT_RDWR);
|
||||
close(socketRefuseFd);
|
||||
|
@ -158,26 +158,23 @@ long long int FILE_GetFileSizeFromPath(char *TheFileName)
|
||||
/* Check if a file is valid */
|
||||
int FILE_IsFile(const char *TheFileName)
|
||||
{
|
||||
FILE *TheFile;
|
||||
FILE *TheFile;
|
||||
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
TheFile = fopen64(TheFileName, "rb");
|
||||
#endif
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
TheFile = fopen64(TheFileName, "rb");
|
||||
#endif
|
||||
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
TheFile = fopen(TheFileName, "rb");
|
||||
#endif
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
TheFile = fopen(TheFileName, "rb");
|
||||
#endif
|
||||
|
||||
if (TheFile != NULL)
|
||||
{
|
||||
fclose(TheFile);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (TheFile != NULL)
|
||||
{
|
||||
fclose(TheFile);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FILE_GetDirectoryInodeList(char * DirectoryInodeName, char *** InodeList, int * FilesandFolders, int Recursive)
|
||||
@ -296,13 +293,13 @@ int FILE_GetStringFromFile(char * filename, char **file_content)
|
||||
}
|
||||
|
||||
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
FILE *file = fopen64(filename, "rb");
|
||||
#endif
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
FILE *file = fopen64(filename, "rb");
|
||||
#endif
|
||||
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
FILE *file = fopen(filename, "rb");
|
||||
#endif
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
FILE *file = fopen(filename, "rb");
|
||||
#endif
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
@ -312,8 +309,6 @@ int FILE_GetStringFromFile(char * filename, char **file_content)
|
||||
|
||||
file_size = FILE_GetFileSize(file);
|
||||
|
||||
|
||||
|
||||
count = 0;
|
||||
*file_content = (char *) malloc(file_size * sizeof(char) + 100);
|
||||
|
||||
|
@ -6,6 +6,11 @@
|
||||
</data>
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||
<group/>
|
||||
<group>
|
||||
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpData.c</file>
|
||||
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpCommandElaborate.c</file>
|
||||
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpServer.c</file>
|
||||
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpCommandsElaborate.h</file>
|
||||
</group>
|
||||
</open-files>
|
||||
</project-private>
|
||||
|
@ -13,7 +13,7 @@ FTP_PORT = 21
|
||||
SINGLE_INSTANCE = true
|
||||
#Allow only one server instance (true or false)
|
||||
|
||||
DAEMON_MODE = false
|
||||
DAEMON_MODE = true
|
||||
#Run in background, daemon mode ok
|
||||
|
||||
IDLE_MAX_TIMEOUT = 3600
|
||||
@ -21,13 +21,13 @@ IDLE_MAX_TIMEOUT = 3600
|
||||
# specified amount of time in seconds, set to 0 to disable
|
||||
|
||||
|
||||
MAX_CONNECTION_NUMBER_PER_IP = 2
|
||||
MAX_CONNECTION_NUMBER_PER_IP = 10
|
||||
#MAX CONNECTIONS PER IP
|
||||
#LIMIT THE MAXIMUM NUMBER OF CONNECTION FOR EACH IP ADDRESS
|
||||
# 0 TO DISABLE
|
||||
|
||||
|
||||
MAX_CONNECTION_TRY_PER_IP = 3
|
||||
MAX_CONNECTION_TRY_PER_IP = 10
|
||||
#MAX LOGIN TRY PER IP
|
||||
#THE IP ADDRESS WILL BE BLOCKED FOR 5 MINUTES AFTER WRONG LOGIN USERNAME AND PASSWORD
|
||||
#0 TO DISABLE
|
||||
|
Reference in New Issue
Block a user