diff --git a/Makefile b/Makefile index 37c2260..82c5dbd 100644 --- a/Makefile +++ b/Makefile @@ -5,18 +5,24 @@ OUTPATH=./build/ SOURCE_MODULES_PATH=./library/ #FOR DEBUG PURPOSE -CFLAGS=-c -Wall -I. -g -O0 -#CFLAGS=-c -Wall -I. +CFLAGSTEMP=-c -Wall -I. -g -O0 +#CFLAGSTEMP=-c -Wall -I. OPTIMIZATION=-O3 HEADERS=-I LIBPATH=./build/modules/ BUILDFILES=start uFTP end LIBS=-lpthread -lssl -lcrypto -#DEFINITIONS= +#ENABLE_LARGE_FILE_SUPPORT= #TO ENABLE THE LARGE FILE SUPPORT UNCOMMENT THE NEXT LINE -DEFINITIONS=-D_LARGEFILE64_SOURCE +ENABLE_LARGE_FILE_SUPPORT=-D LARGE_FILE_SUPPORT_ENABLED -D _LARGEFILE64_SOURCE + +#ENABLE_OPENSSL_SUPPORT= +#TO ENABLE OPENSSL SUPPORT UNCOMMENT THE NEXT LINE +ENABLE_OPENSSL_SUPPORT=-D OPENSSL_ENABLED + +CFLAGS=$(CFLAGSTEMP) $(ENABLE_LARGE_FILE_SUPPORT) $(ENABLE_OPENSSL_SUPPORT) all: $(BUILDFILES) @@ -31,7 +37,7 @@ end: @echo Build process end uFTP: uFTP.c fileManagement.o configRead.o logFunctions.o ftpCommandElaborate.o ftpData.o ftpServer.o daemon.o signals.o connection.o openSsl.o - @$(CC) $(DEFINITIONS) uFTP.c $(LIBPATH)dynamicVectors.o $(LIBPATH)fileManagement.o $(LIBPATH)configRead.o $(LIBPATH)logFunctions.o $(LIBPATH)ftpCommandElaborate.o $(LIBPATH)ftpData.o $(LIBPATH)ftpServer.o $(LIBPATH)daemon.o $(LIBPATH)signals.o $(LIBPATH)connection.o $(LIBPATH)openSsl.o -o $(OUTPATH)uFTP $(LIBS) + @$(CC) $(ENABLE_LARGE_FILE_SUPPORT) $(ENABLE_OPENSSL_SUPPORT) uFTP.c $(LIBPATH)dynamicVectors.o $(LIBPATH)fileManagement.o $(LIBPATH)configRead.o $(LIBPATH)logFunctions.o $(LIBPATH)ftpCommandElaborate.o $(LIBPATH)ftpData.o $(LIBPATH)ftpServer.o $(LIBPATH)daemon.o $(LIBPATH)signals.o $(LIBPATH)connection.o $(LIBPATH)openSsl.o -o $(OUTPATH)uFTP $(LIBS) daemon.o: @$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)daemon.c -o $(LIBPATH)daemon.o diff --git a/build/modules/configRead.o b/build/modules/configRead.o index ee50065..bc8ab43 100644 Binary files a/build/modules/configRead.o and b/build/modules/configRead.o differ diff --git a/build/modules/connection.o b/build/modules/connection.o index aa58a57..aa33402 100644 Binary files a/build/modules/connection.o and b/build/modules/connection.o differ diff --git a/build/modules/fileManagement.o b/build/modules/fileManagement.o index c3c96e2..472014a 100644 Binary files a/build/modules/fileManagement.o and b/build/modules/fileManagement.o differ diff --git a/build/modules/ftpCommandElaborate.o b/build/modules/ftpCommandElaborate.o index ec3621f..62707aa 100644 Binary files a/build/modules/ftpCommandElaborate.o and b/build/modules/ftpCommandElaborate.o differ diff --git a/build/modules/ftpData.o b/build/modules/ftpData.o index 418802a..19f51eb 100644 Binary files a/build/modules/ftpData.o and b/build/modules/ftpData.o differ diff --git a/build/modules/ftpServer.o b/build/modules/ftpServer.o index e5b3025..4fdc416 100644 Binary files a/build/modules/ftpServer.o and b/build/modules/ftpServer.o differ diff --git a/build/modules/openSsl.o b/build/modules/openSsl.o index 8881265..b09b4bb 100644 Binary files a/build/modules/openSsl.o and b/build/modules/openSsl.o differ diff --git a/build/uFTP b/build/uFTP index 624c885..ebcf86c 100755 Binary files a/build/uFTP and b/build/uFTP differ diff --git a/ftpCommandElaborate.c b/ftpCommandElaborate.c index b5e20db..b8dd392 100644 --- a/ftpCommandElaborate.c +++ b/ftpCommandElaborate.c @@ -218,30 +218,61 @@ int parseCommandPass(ftpDataType * data, int socketId) } } -int parseCommandAuth(clientDataType *theClientData, SSL_CTX *ctx) +int parseCommandAuth(ftpDataType * data, int socketId) { int returnCode; - //returnCode = socketPrintf(data, socketId, "s", "234 AUTH TLS OK..\r\n"); - if (returnCode <= 0) - return FTP_COMMAND_PROCESSED_WRITE_ERROR; - - theClientData->tlsIsEnabled = 1; - SSL *ssl; - ssl = SSL_new(ctx); - SSL_set_fd(ssl, theClientData->socketDescriptor); + #ifndef OPENSSL_ENABLED + returnCode = socketPrintf(data, socketId, "s", "502 Security extensions not implemented.\r\n"); + if (returnCode <= 0) + return FTP_COMMAND_PROCESSED_WRITE_ERROR; - if (SSL_accept(ssl) <= 0) { - printf("\nSSL ERRORS"); - ERR_print_errors_fp(stderr); + return FTP_COMMAND_PROCESSED; + #endif + + #ifdef OPENSSL_ENABLED + returnCode = socketPrintf(data, socketId, "s", "234 AUTH TLS OK..\r\n"); + if (returnCode <= 0) + return FTP_COMMAND_PROCESSED_WRITE_ERROR; + + data->clients[socketId].tlsIsEnabled = 1; + + printf("\n SSL_set_fd"); + fflush(0); + + SSL_set_fd(data->clients[socketId].ssl, data->clients[socketId].socketDescriptor); + + printf("\n SSL_set_fd OK"); + fflush(0); + + int sslAcceptTimeout = 0; + do { + returnCode = SSL_accept(data->clients[socketId].ssl); + + printf("\n SSL_accept"); + fflush(0); + + printf("\nSSL waiting handshake %d.. return code = %d", sslAcceptTimeout, returnCode); + fflush(0); + if (returnCode <= 0) { + printf("\nSSL ERRORS"); + fflush(0); + ERR_print_errors_fp(stderr); + } + else { + printf("\nSSL ACCEPTED"); + fflush(0); + } + sslAcceptTimeout++; + sleep(1); } - else { - printf("\nSSL ACCEPTED"); - SSL_write(ssl, "ciao prova\r\n", strlen("ciao prova\r\n")); - } - - //client -> AUTH TLS - //server -> 234 AUTH TLS OK. + while(returnCode <=0 && + sslAcceptTimeout < 3); + + return FTP_COMMAND_PROCESSED; + #endif + + return FTP_COMMAND_PROCESSED; } @@ -346,22 +377,31 @@ int parseCommandPasv(ftpDataType * data, int socketId) { /* Create worker thread */ void *pReturn; + int returnCode; printf("\n data->clients[%d].workerData.workerThread = %d",socketId, (int)data->clients[socketId].workerData.workerThread); if (data->clients[socketId].workerData.threadIsAlive == 1) { - pthread_cancel(data->clients[socketId].workerData.workerThread); + returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); } - pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); + returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); 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); + returnCode = pthread_create(&data->clients[socketId].workerData.workerThread, NULL, connectionWorkerHandle, (void *) &data->clients[socketId].clientProgressiveNumber); + + if (returnCode != 0) + { + printf("\nError in pthread_create %d", returnCode); + return FTP_COMMAND_PROCESSED_WRITE_ERROR; + } + return FTP_COMMAND_PROCESSED; } int parseCommandPort(ftpDataType * data, int socketId) { + int returnCode; char *theIpAndPort; int ipAddressBytes[4]; int portBytes[2]; @@ -373,12 +413,20 @@ int parseCommandPort(ftpDataType * data, int socketId) void *pReturn; if (data->clients[socketId].workerData.threadIsAlive == 1) { - pthread_cancel(data->clients[socketId].workerData.workerThread); + returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); } - pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); + returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); 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); + returnCode = pthread_create(&data->clients[socketId].workerData.workerThread, NULL, connectionWorkerHandle, (void *) &data->clients[socketId].clientProgressiveNumber); + + if (returnCode != 0) + { + printf("\nError in pthread_create %d", returnCode); + return FTP_COMMAND_PROCESSED_WRITE_ERROR; + } + + return FTP_COMMAND_PROCESSED; } @@ -1058,11 +1106,13 @@ long long int writeRetrFile(char * theFilename, int thePasvSocketConnection, lon long long int theFileSize; char buffer[FTP_COMMAND_ELABORATE_CHAR_BUFFER]; - #ifdef _LARGEFILE64_SOURCE + #ifdef LARGE_FILE_SUPPORT_ENABLED + //#warning LARGE FILE SUPPORT IS ENABLED! retrFP = fopen64(theFilename, "rb"); #endif - #ifndef _LARGEFILE64_SOURCE + #ifndef LARGE_FILE_SUPPORT_ENABLED + #warning LARGE FILE SUPPORT IS NOT ENABLED! retrFP = fopen(theFilename, "rb"); #endif @@ -1076,11 +1126,13 @@ long long int writeRetrFile(char * theFilename, int thePasvSocketConnection, lon if (startFrom > 0) { - #ifdef _LARGEFILE64_SOURCE + #ifdef LARGE_FILE_SUPPORT_ENABLED + //#warning LARGE FILE SUPPORT IS ENABLED! currentPosition = (long long int) lseek64(fileno(retrFP), startFrom, SEEK_SET); #endif - #ifndef _LARGEFILE64_SOURCE + #ifndef LARGE_FILE_SUPPORT_ENABLED + #warning LARGE FILE SUPPORT IS NOT ENABLED! currentPosition = (long long int) lseek(fileno(retrFP), startFrom, SEEK_SET); #endif diff --git a/ftpCommandsElaborate.h b/ftpCommandsElaborate.h index d3be4d1..4c21cc0 100644 --- a/ftpCommandsElaborate.h +++ b/ftpCommandsElaborate.h @@ -50,9 +50,7 @@ extern "C" { int parseCommandUser(ftpDataType * data, int socketId); int parseCommandSite(ftpDataType * data, int socketId); int parseCommandPass(ftpDataType * data, int socketId); - -int parseCommandAuth(clientDataType *theClientData, SSL_CTX *); - +int parseCommandAuth(ftpDataType * data, int socketId); int parseCommandPwd(ftpDataType * data, int socketId); int parseCommandSyst(ftpDataType * data, int socketId); int parseCommandFeat(ftpDataType * data, int socketId); diff --git a/ftpData.c b/ftpData.c index 5e04644..8b8cd52 100644 --- a/ftpData.c +++ b/ftpData.c @@ -603,66 +603,76 @@ void resetWorkerData(workerDataType *workerData, int isInitialization) } } -void resetClientData(clientDataType *clientData, int isInitialization) +void resetClientData(ftpDataType *data, int clientId, int isInitialization) { + if (isInitialization != 1) { - if (clientData->workerData.threadIsAlive == 1) + if (data->clients[clientId].workerData.threadIsAlive == 1) { void *pReturn; - pthread_cancel(clientData->workerData.workerThread); - pthread_join(clientData->workerData.workerThread, &pReturn); + pthread_cancel(data->clients[clientId].workerData.workerThread); + pthread_join(data->clients[clientId].workerData.workerThread, &pReturn); } else { void *pReturn = NULL; - pthread_join(clientData->workerData.workerThread, &pReturn); + pthread_join(data->clients[clientId].workerData.workerThread, &pReturn); } - pthread_mutex_destroy(&clientData->writeMutex); + pthread_mutex_destroy(&data->clients[clientId].writeMutex); + + #ifdef OPENSSL_ENABLED + SSL_free(data->clients[clientId].ssl); + #endif } - if (pthread_mutex_init(&clientData->writeMutex, NULL) != 0) + if (pthread_mutex_init(&data->clients[clientId].writeMutex, NULL) != 0) { printf("\nclientData->writeMutex init failed\n"); exit(0); } - clientData->socketDescriptor = -1; - clientData->socketCommandReceived = 0; - clientData->socketIsConnected = 0; - clientData->bufferIndex = 0; - clientData->commandIndex = 0; - clientData->closeTheClient = 0; - clientData->sockaddr_in_size = sizeof(struct sockaddr_in); - clientData->sockaddr_in_server_size = sizeof(struct sockaddr_in); + data->clients[clientId].tlsIsEnabled = 0; + data->clients[clientId].socketDescriptor = -1; + data->clients[clientId].socketCommandReceived = 0; + data->clients[clientId].socketIsConnected = 0; + data->clients[clientId].bufferIndex = 0; + data->clients[clientId].commandIndex = 0; + data->clients[clientId].closeTheClient = 0; + data->clients[clientId].sockaddr_in_size = sizeof(struct sockaddr_in); + data->clients[clientId].sockaddr_in_server_size = sizeof(struct sockaddr_in); - clientData->serverIpAddressInteger[0] = 0; - clientData->serverIpAddressInteger[1] = 0; - clientData->serverIpAddressInteger[2] = 0; - clientData->serverIpAddressInteger[3] = 0; + data->clients[clientId].serverIpAddressInteger[0] = 0; + data->clients[clientId].serverIpAddressInteger[1] = 0; + data->clients[clientId].serverIpAddressInteger[2] = 0; + data->clients[clientId].serverIpAddressInteger[3] = 0; - memset(&clientData->client_sockaddr_in, 0, clientData->sockaddr_in_size); - memset(&clientData->server_sockaddr_in, 0, clientData->sockaddr_in_server_size); - memset(clientData->clientIpAddress, 0, INET_ADDRSTRLEN); - memset(clientData->buffer, 0, CLIENT_BUFFER_STRING_SIZE); - memset(clientData->theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE); - cleanLoginData(&clientData->login, isInitialization); + memset(&data->clients[clientId].client_sockaddr_in, 0, data->clients[clientId].sockaddr_in_size); + memset(&data->clients[clientId].server_sockaddr_in, 0, data->clients[clientId].sockaddr_in_server_size); + 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); //Rename from and to data init - cleanDynamicStringDataType(&clientData->renameFromFile, isInitialization); - cleanDynamicStringDataType(&clientData->renameToFile, isInitialization); - cleanDynamicStringDataType(&clientData->fileToStor, isInitialization); - cleanDynamicStringDataType(&clientData->fileToRetr, isInitialization); - cleanDynamicStringDataType(&clientData->listPath, isInitialization); - cleanDynamicStringDataType(&clientData->nlistPath, isInitialization); + 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(&clientData->ftpCommand.commandArgs, isInitialization); - cleanDynamicStringDataType(&clientData->ftpCommand.commandOps, isInitialization); + cleanDynamicStringDataType(&data->clients[clientId].ftpCommand.commandArgs, isInitialization); + cleanDynamicStringDataType(&data->clients[clientId].ftpCommand.commandOps, isInitialization); - clientData->connectionTimeStamp = 0; - clientData->lastActivityTimeStamp = 0; + data->clients[clientId].connectionTimeStamp = 0; + data->clients[clientId].lastActivityTimeStamp = 0; + + #ifdef OPENSSL_ENABLED + data->clients[clientId].ssl = SSL_new(data->ctx); + #endif } int compareStringCaseInsensitive(char * stringIn, char * stringRef, int stringLenght) diff --git a/ftpData.h b/ftpData.h index 7905ad8..6f5f049 100644 --- a/ftpData.h +++ b/ftpData.h @@ -148,7 +148,10 @@ struct workerData struct clientData { + #ifdef OPENSSL_ENABLED SSL *ssl; + #endif + int tlsIsEnabled; pthread_mutex_t writeMutex; @@ -207,7 +210,10 @@ struct ConnectionParameters struct ftpData { - + #ifdef OPENSSL_ENABLED + SSL_CTX *ctx; + #endif + int connectedClients; char welcomeMessage[1024]; ConnectionData_DataType connectionData; @@ -247,8 +253,10 @@ int writeListDataInfoToSocket(char * thePath, int theSocket, int *filesNumber, i int searchInLoginFailsVector(void *loginFailsVector, void *element); void deleteLoginFailsData(void *element); void deleteListDataInfoVector(void *TheElementToDelete); + void resetWorkerData(workerDataType *pasvData, int isInitialization); -void resetClientData(clientDataType *clientData, int isInitialization); +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(void * data); diff --git a/ftpServer.c b/ftpServer.c index 8126b10..fbf6fde 100644 --- a/ftpServer.c +++ b/ftpServer.c @@ -48,7 +48,6 @@ #include "ftpCommandsElaborate.h" ftpDataType ftpData; -SSL_CTX *ctx; static int processCommand(int processingElement); @@ -160,11 +159,13 @@ void *connectionWorkerHandle(void * socketId) ftpData.clients[theSocketId].fileToStor.textLen > 0) { - #ifdef _LARGEFILE64_SOURCE + #ifdef LARGE_FILE_SUPPORT_ENABLED + //#warning LARGE FILE SUPPORT IS ENABLED! ftpData.clients[theSocketId].workerData.theStorFile = fopen64(ftpData.clients[theSocketId].fileToStor.text, "wb"); #endif - #ifndef _LARGEFILE64_SOURCE + #ifndef LARGE_FILE_SUPPORT_ENABLED + #warning LARGE FILE SUPPORT IS NOT ENABLED! ftpData.clients[theSocketId].workerData.theStorFile = fopen(ftpData.clients[theSocketId].fileToStor.text, "wb"); #endif @@ -325,9 +326,9 @@ void runFtpServer(void) { printf("\nHello uFTP server v%s starting..\n", UFTP_SERVER_VERSION); - /* Needed for Select*/ - static int processingSock = 0, returnCode = 0; + static int processingSock = 0, + returnCode = 0; /* Handle signals */ signalHandlerInstall(); @@ -351,9 +352,6 @@ void runFtpServer(void) /* the maximum socket fd is now the main socket descriptor */ ftpData.connectionData.maxSocketFD = ftpData.connectionData.theMainSocket+1; - initOpenssl(); - ctx = createContext(); - configureContext(ctx); //Endless loop ftp process while (1) @@ -391,8 +389,20 @@ void runFtpServer(void) if (FD_ISSET(ftpData.clients[processingSock].socketDescriptor, &ftpData.connectionData.rset) || FD_ISSET(ftpData.clients[processingSock].socketDescriptor, &ftpData.connectionData.eset)) { + + if (ftpData.clients[processingSock].tlsIsEnabled == 1) + { + #ifdef OPENSSL_ENABLED + ftpData.clients[processingSock].bufferIndex = SSL_read(ftpData.clients[processingSock].ssl, ftpData.clients[processingSock].buffer, CLIENT_BUFFER_STRING_SIZE); + #endif + } + else + { + ftpData.clients[processingSock].bufferIndex = read(ftpData.clients[processingSock].socketDescriptor, ftpData.clients[processingSock].buffer, CLIENT_BUFFER_STRING_SIZE); + } + //The client is not connected anymore - if ((ftpData.clients[processingSock].bufferIndex = read(ftpData.clients[processingSock].socketDescriptor, ftpData.clients[processingSock].buffer, CLIENT_BUFFER_STRING_SIZE)) == 0) + if ((ftpData.clients[processingSock].bufferIndex) == 0) { fdRemove(&ftpData, processingSock); closeSocket(&ftpData, processingSock); @@ -519,12 +529,12 @@ static int processCommand(int processingElement) else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "AUTH", strlen("AUTH")) == 1) { printf("\nAUTH COMMAND RECEIVED"); + toReturn = parseCommandAuth(&ftpData, processingElement); - int returnCode; - //returnCode = dprintf(theClientData->socketDescriptor, "502 Security extensions not implemented.\r\n"); - returnCode = dprintf(ftpData.clients[processingElement].socketDescriptor, "234 AUTH TLS OK..\r\n"); - + //returnCode = dprintf(theClientData->socketDescriptor, "502 Security extensions not implemented.\r\n"); + //returnCode = dprintf(ftpData.clients[processingElement].socketDescriptor, "234 AUTH TLS OK..\r\n"); +/* ftpData.clients[processingElement].tlsIsEnabled = 1; SSL *ssl; ssl = SSL_new(ctx); @@ -559,8 +569,8 @@ static int processCommand(int processingElement) sleep(1); } +*/ - // toReturn = parseCommandAuth(&ftpData.clients[processingElement], ctx); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PWD", strlen("PWD")) == 1) { @@ -721,4 +731,8 @@ static int processCommand(int processingElement) void deallocateMemory(void) { printf("\n Deallocating the memory.. "); + #ifndef OPENSSL_ENABLED + SSL_CTX_free(ftpData.ctx); + cleanup_openssl(); + #endif } diff --git a/ftpServer.h b/ftpServer.h index d67da6c..583f20d 100644 --- a/ftpServer.h +++ b/ftpServer.h @@ -27,7 +27,9 @@ #define FTPSERVER_H #define MAX_FTP_CLIENTS 10 -#define UFTP_SERVER_VERSION "1.0.1 beta" +#define UFTP_SERVER_VERSION "2.0.0 beta" +#warning remove in final release, must be specified by makefile +#define OPENSSL_ENABLED void runFtpServer(void); void *connectionWorkerHandle(void * socketId); diff --git a/library/configRead.c b/library/configRead.c index f693182..339b873 100644 --- a/library/configRead.c +++ b/library/configRead.c @@ -30,6 +30,7 @@ #include "configRead.h" #include "../ftpData.h" #include "dynamicVectors.h" +#include "openSsl.h" #include "fileManagement.h" #include "daemon.h" @@ -122,10 +123,17 @@ void applyConfiguration(ftpParameters_DataType *ftpParameters) void initFtpData(ftpDataType *ftpData) { - int i; + int i; /* Intializes random number generator */ srand(time(NULL)); + #ifdef OPENSSL_ENABLED + #warning OPENSSL ENABLED! + initOpenssl(); + ftpData->ctx = createContext(); + configureContext(ftpData->ctx); + #endif + ftpData->connectedClients = 0; ftpData->clients = (clientDataType *) malloc( sizeof(clientDataType) * ftpData->ftpParameters.maxClients); @@ -143,7 +151,7 @@ void initFtpData(ftpDataType *ftpData) for (i = 0; i < ftpData->ftpParameters.maxClients; i++) { resetWorkerData(&ftpData->clients[i].workerData, 1); - resetClientData(&ftpData->clients[i], 1); + resetClientData(ftpData, i, 1); ftpData->clients[i].clientProgressiveNumber = i; } @@ -573,8 +581,7 @@ 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)); } diff --git a/library/connection.c b/library/connection.c index 4ae2964..4f82510 100644 --- a/library/connection.c +++ b/library/connection.c @@ -120,7 +120,18 @@ int socketPrintf(ftpDataType * ftpData, int clientId, const char *__restrict __f theStringSize > 0) { int theReturnCode = 0; - theReturnCode = write(ftpData->clients[clientId].socketDescriptor, theBuffer, theStringSize); + + if (ftpData->clients[clientId].tlsIsEnabled != 1) + { + theReturnCode = write(ftpData->clients[clientId].socketDescriptor, theBuffer, theStringSize); + } + else if (ftpData->clients[clientId].tlsIsEnabled == 1) + { + #ifdef OPENSSL_ENABLED + theReturnCode = SSL_write(ftpData->clients[clientId].ssl, theBuffer, theStringSize); + #endif + } + printf("%s", theBuffer); if (theReturnCode > 0) @@ -320,7 +331,7 @@ void closeSocket(ftpDataType * ftpData, int processingSocket) shutdown(ftpData->clients[processingSocket].socketDescriptor, SHUT_RDWR); close(ftpData->clients[processingSocket].socketDescriptor); - resetClientData(&ftpData->clients[processingSocket], 0); + resetClientData(ftpData, processingSocket, 0); resetWorkerData(&ftpData->clients[processingSocket].workerData, 0); //Update client connecteds @@ -495,7 +506,7 @@ int evaluateClientSocketConnection(ftpDataType * ftpData) } else { - int returnCode = socketPrintf(&ftpData, availableSocketIndex, "s", ftpData->welcomeMessage); + int returnCode = socketPrintf(ftpData, availableSocketIndex, "s", ftpData->welcomeMessage); if (returnCode <= 0) { ftpData->clients[availableSocketIndex].closeTheClient = 1; diff --git a/library/fileManagement.c b/library/fileManagement.c index 1096750..a0a9398 100644 --- a/library/fileManagement.c +++ b/library/fileManagement.c @@ -91,7 +91,8 @@ long int FILE_GetAvailableSpace(const char* path) /* Get the file size */ long long int FILE_GetFileSize(FILE *TheFilePointer) { -#ifdef _LARGEFILE64_SOURCE +#ifdef LARGE_FILE_SUPPORT_ENABLED + //#warning LARGE FILE SUPPORT IS ENABLED! long long int Prev = 0, TheFileSize = 0; Prev = ftello64(TheFilePointer); fseeko64(TheFilePointer, 0, SEEK_END); @@ -100,7 +101,8 @@ long long int FILE_GetFileSize(FILE *TheFilePointer) return TheFileSize; #endif -#ifndef _LARGEFILE64_SOURCE +#ifndef LARGE_FILE_SUPPORT_ENABLED + #warning LARGE FILE SUPPORT IS NOT ENABLED! long long int Prev = 0, TheFileSize = 0; Prev = ftell(TheFilePointer); fseek(TheFilePointer, 0, SEEK_END); @@ -114,7 +116,8 @@ long long int FILE_GetFileSizeFromPath(char *TheFileName) { -#ifdef _LARGEFILE64_SOURCE +#ifdef LARGE_FILE_SUPPORT_ENABLED + //#warning LARGE FILE SUPPORT IS ENABLED! if (FILE_IsFile(TheFileName) == 1) { FILE *TheFilePointer; @@ -133,7 +136,8 @@ long long int FILE_GetFileSizeFromPath(char *TheFileName) } #endif -#ifndef _LARGEFILE64_SOURCE +#ifndef LARGE_FILE_SUPPORT_ENABLED +#warning LARGE FILE SUPPORT IS NOT ENABLED! if (FILE_IsFile(TheFileName) == 1) { FILE *TheFilePointer; @@ -160,11 +164,13 @@ int FILE_IsFile(const char *TheFileName) { FILE *TheFile; - #ifdef _LARGEFILE64_SOURCE + #ifdef LARGE_FILE_SUPPORT_ENABLED + //#warning LARGE FILE SUPPORT IS ENABLED! TheFile = fopen64(TheFileName, "rb"); #endif - #ifndef _LARGEFILE64_SOURCE + #ifndef LARGE_FILE_SUPPORT_ENABLED +#warning LARGE FILE SUPPORT IS NOT ENABLED! TheFile = fopen(TheFileName, "rb"); #endif @@ -293,11 +299,13 @@ int FILE_GetStringFromFile(char * filename, char **file_content) } - #ifdef _LARGEFILE64_SOURCE + #ifdef LARGE_FILE_SUPPORT_ENABLED + //#warning LARGE FILE SUPPORT IS ENABLED! FILE *file = fopen64(filename, "rb"); #endif - #ifndef _LARGEFILE64_SOURCE + #ifndef LARGE_FILE_SUPPORT_ENABLED +#warning LARGE FILE SUPPORT IS NOT ENABLED! FILE *file = fopen(filename, "rb"); #endif diff --git a/library/openSsl.c b/library/openSsl.c index 28a8597..dc0641a 100644 --- a/library/openSsl.c +++ b/library/openSsl.c @@ -21,7 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - +#ifdef OPENSSL_ENABLED +#warning SSL ENABLED #include #include #include @@ -74,4 +75,5 @@ void configureContext(SSL_CTX *ctx) ERR_print_errors_fp(stderr); exit(EXIT_FAILURE); } -} \ No newline at end of file +} +#endif diff --git a/library/openSsl.h b/library/openSsl.h index a27958b..6503616 100644 --- a/library/openSsl.h +++ b/library/openSsl.h @@ -21,7 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - +#ifdef OPENSSL_ENABLED +#warning SSL ENABLED #ifndef OPENSSL_H #define OPENSSL_H @@ -43,4 +44,4 @@ void configureContext(SSL_CTX *ctx); #endif #endif /* OPENSSL_H */ - +#endif diff --git a/nbproject/Makefile-Debug.mk b/nbproject/Makefile-Debug.mk index 6b82ede..1fc9129 100644 --- a/nbproject/Makefile-Debug.mk +++ b/nbproject/Makefile-Debug.mk @@ -76,62 +76,62 @@ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/uftp: ${OBJECTFILES} ${OBJECTDIR}/ftpCommandElaborate.o: ftpCommandElaborate.c ${MKDIR} -p ${OBJECTDIR} ${RM} "$@.d" - $(COMPILE.c) -g -Wall -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/ftpCommandElaborate.o ftpCommandElaborate.c + $(COMPILE.c) -g -Wall -D_LARGE_FILE_SUPPORT_ENABLED -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/ftpCommandElaborate.o ftpCommandElaborate.c ${OBJECTDIR}/ftpData.o: ftpData.c ${MKDIR} -p ${OBJECTDIR} ${RM} "$@.d" - $(COMPILE.c) -g -Wall -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/ftpData.o ftpData.c + $(COMPILE.c) -g -Wall -D_LARGE_FILE_SUPPORT_ENABLED -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/ftpData.o ftpData.c ${OBJECTDIR}/ftpServer.o: ftpServer.c ${MKDIR} -p ${OBJECTDIR} ${RM} "$@.d" - $(COMPILE.c) -g -Wall -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/ftpServer.o ftpServer.c + $(COMPILE.c) -g -Wall -D_LARGE_FILE_SUPPORT_ENABLED -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/ftpServer.o ftpServer.c ${OBJECTDIR}/library/configRead.o: library/configRead.c ${MKDIR} -p ${OBJECTDIR}/library ${RM} "$@.d" - $(COMPILE.c) -g -Wall -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/configRead.o library/configRead.c + $(COMPILE.c) -g -Wall -D_LARGE_FILE_SUPPORT_ENABLED -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/configRead.o library/configRead.c ${OBJECTDIR}/library/connection.o: library/connection.c ${MKDIR} -p ${OBJECTDIR}/library ${RM} "$@.d" - $(COMPILE.c) -g -Wall -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/connection.o library/connection.c + $(COMPILE.c) -g -Wall -D_LARGE_FILE_SUPPORT_ENABLED -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/connection.o library/connection.c ${OBJECTDIR}/library/daemon.o: library/daemon.c ${MKDIR} -p ${OBJECTDIR}/library ${RM} "$@.d" - $(COMPILE.c) -g -Wall -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/daemon.o library/daemon.c + $(COMPILE.c) -g -Wall -D_LARGE_FILE_SUPPORT_ENABLED -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/daemon.o library/daemon.c ${OBJECTDIR}/library/dynamicVectors.o: library/dynamicVectors.c ${MKDIR} -p ${OBJECTDIR}/library ${RM} "$@.d" - $(COMPILE.c) -g -Wall -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/dynamicVectors.o library/dynamicVectors.c + $(COMPILE.c) -g -Wall -D_LARGE_FILE_SUPPORT_ENABLED -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/dynamicVectors.o library/dynamicVectors.c ${OBJECTDIR}/library/fileManagement.o: library/fileManagement.c ${MKDIR} -p ${OBJECTDIR}/library ${RM} "$@.d" - $(COMPILE.c) -g -Wall -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/fileManagement.o library/fileManagement.c + $(COMPILE.c) -g -Wall -D_LARGE_FILE_SUPPORT_ENABLED -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/fileManagement.o library/fileManagement.c ${OBJECTDIR}/library/logFunctions.o: library/logFunctions.c ${MKDIR} -p ${OBJECTDIR}/library ${RM} "$@.d" - $(COMPILE.c) -g -Wall -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/logFunctions.o library/logFunctions.c + $(COMPILE.c) -g -Wall -D_LARGE_FILE_SUPPORT_ENABLED -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/logFunctions.o library/logFunctions.c ${OBJECTDIR}/library/openSsl.o: library/openSsl.c ${MKDIR} -p ${OBJECTDIR}/library ${RM} "$@.d" - $(COMPILE.c) -g -Wall -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/openSsl.o library/openSsl.c + $(COMPILE.c) -g -Wall -D_LARGE_FILE_SUPPORT_ENABLED -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/openSsl.o library/openSsl.c ${OBJECTDIR}/library/signals.o: library/signals.c ${MKDIR} -p ${OBJECTDIR}/library ${RM} "$@.d" - $(COMPILE.c) -g -Wall -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/signals.o library/signals.c + $(COMPILE.c) -g -Wall -D_LARGE_FILE_SUPPORT_ENABLED -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/signals.o library/signals.c ${OBJECTDIR}/uFTP.o: uFTP.c ${MKDIR} -p ${OBJECTDIR} ${RM} "$@.d" - $(COMPILE.c) -g -Wall -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/uFTP.o uFTP.c + $(COMPILE.c) -g -Wall -D_LARGE_FILE_SUPPORT_ENABLED -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h `pkg-config --cflags libcrypto` `pkg-config --cflags libssl` `pkg-config --cflags openssl` -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/uFTP.o uFTP.c # Subprojects .build-subprojects: diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 9c09f8c..948d338 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -80,7 +80,7 @@ library/fileManagement.h - _LARGEFILE64_SOURCE + _LARGE_FILE_SUPPORT_ENABLED 2