diff --git a/Makefile b/Makefile index 85663b8..a718517 100644 --- a/Makefile +++ b/Makefile @@ -5,10 +5,10 @@ OUTPATH=./build/ SOURCE_MODULES_PATH=./library/ #FOR DEBUG PURPOSE -CFLAGSTEMP=-c -Wall -I. -g -O0 +#CFLAGSTEMP=-c -Wall -I. -g -O0 #FOR RELEASE -#CFLAGSTEMP=-c -Wall -I. +CFLAGSTEMP=-c -Wall -I. OPTIMIZATION=-O3 HEADERS=-I diff --git a/build/modules/auth.o b/build/modules/auth.o index 7682e20..274c747 100644 Binary files a/build/modules/auth.o and b/build/modules/auth.o differ diff --git a/build/modules/configRead.o b/build/modules/configRead.o index a046a7a..5c49d20 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 24072eb..b07252a 100644 Binary files a/build/modules/connection.o and b/build/modules/connection.o differ diff --git a/build/modules/daemon.o b/build/modules/daemon.o index d372df3..1e60449 100644 Binary files a/build/modules/daemon.o and b/build/modules/daemon.o differ diff --git a/build/modules/dynamicMemory.o b/build/modules/dynamicMemory.o index ec502b0..0ea6505 100644 Binary files a/build/modules/dynamicMemory.o and b/build/modules/dynamicMemory.o differ diff --git a/build/modules/dynamicVectors.o b/build/modules/dynamicVectors.o index 89bb83c..5a967df 100644 Binary files a/build/modules/dynamicVectors.o and b/build/modules/dynamicVectors.o differ diff --git a/build/modules/errorHandling.o b/build/modules/errorHandling.o index 4df7f04..46c51ee 100644 Binary files a/build/modules/errorHandling.o and b/build/modules/errorHandling.o differ diff --git a/build/modules/fileManagement.o b/build/modules/fileManagement.o index fe1709c..187f1fc 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 30db405..284b52f 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 3fc6b2d..a7bd9e6 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 1bfa9fd..4024845 100644 Binary files a/build/modules/ftpServer.o and b/build/modules/ftpServer.o differ diff --git a/build/modules/logFunctions.o b/build/modules/logFunctions.o index a8ef6e7..ca9f615 100644 Binary files a/build/modules/logFunctions.o and b/build/modules/logFunctions.o differ diff --git a/build/modules/openSsl.o b/build/modules/openSsl.o index 1cc8bd0..b85496d 100644 Binary files a/build/modules/openSsl.o and b/build/modules/openSsl.o differ diff --git a/build/modules/signals.o b/build/modules/signals.o index 5106668..66a36f9 100644 Binary files a/build/modules/signals.o and b/build/modules/signals.o differ diff --git a/build/uFTP b/build/uFTP index aea9de4..c404c95 100755 Binary files a/build/uFTP and b/build/uFTP differ diff --git a/ftpCommandElaborate.c b/ftpCommandElaborate.c index 5e502e9..1fb964b 100644 --- a/ftpCommandElaborate.c +++ b/ftpCommandElaborate.c @@ -495,19 +495,25 @@ int parseCommandPasv(ftpDataType * data, int socketId) //printf("\n data->clients[%d].workerData.threadHasBeenCreated = %d", socketId, data->clients[socketId].workerData.threadHasBeenCreated); if (data->clients[socketId].workerData.threadIsAlive == 1) { - returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); - //printf("\npasv pthread_cancel = %d", returnCode); - do - { - printf("\nQuit command received the Pasv Thread has been cancelled!!!"); - usleep(10000); - } while (data->clients[socketId].workerData.threadIsAlive == 1); + printf("\nPASV PTHREAD CANCEL"); + int returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); + printf ("\npthread_cancel return code: %d", returnCode); + + returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); + //fflush(0); + data->clients[socketId].workerData.threadHasBeenCreated = 0; + printf("\nparseCommand PASV JOIN RETURN STATUS %d", returnCode); + + printf("\nPASV THREAD CANCELLED!!!"); + + printf("\nftpData->clients[processingSocket].workerData.threadIsAlive = %d", data->clients[socketId].workerData.threadIsAlive); + } if (data->clients[socketId].workerData.threadHasBeenCreated == 1) { returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); - //printf("\nPasv join ok %d", returnCode); + printf("\nPASV JOIN RETURN STATUS %d", returnCode); } data->clients[socketId].workerData.passiveModeOn = 1; @@ -537,16 +543,23 @@ int parseCommandPort(ftpDataType * data, int socketId) void *pReturn; if (data->clients[socketId].workerData.threadIsAlive == 1) { - returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); - do - { - printf("\nQuit command received the Pasv Thread has been cancelled!!!"); - usleep(10000); - } while (data->clients[socketId].workerData.threadIsAlive == 1); + printf("\nPORT PTHREAD CANCEL"); + int returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); + printf ("\npthread_cancel return code: %d", returnCode); + //fflush(0); + + returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); + data->clients[socketId].workerData.threadHasBeenCreated = 0; + printf("\nparseCommand PORT JOIN RETURN STATUS %d", returnCode); + + printf("\nPORT Thread cancelled!!!"); + + printf("\nftpData->clients[processingSocket].workerData.threadIsAlive = %d", data->clients[socketId].workerData.threadIsAlive); } if (data->clients[socketId].workerData.threadHasBeenCreated == 1) { returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); + printf("\nPORT JOIN RETURN STATUS %d", returnCode); } data->clients[socketId].workerData.passiveModeOn = 0; data->clients[socketId].workerData.activeModeOn = 1; @@ -575,12 +588,20 @@ int parseCommandAbor(ftpDataType * data, int socketId) { if (data->clients[socketId].workerData.threadIsAlive == 1) { - pthread_cancel(data->clients[socketId].workerData.workerThread); - do - { - printf("\nQuit command received the Pasv Thread has been cancelled!!!"); - usleep(10000); - } while (data->clients[socketId].workerData.threadIsAlive == 1); + void *pReturn; + + printf("\nABOR PTHREAD CANCEL"); + int returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); + printf ("\npthread_cancel return code: %d", returnCode); + //fflush(0); + + returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); + data->clients[socketId].workerData.threadHasBeenCreated = 0; + printf("\nparseCommand ABOR JOIN RETURN STATUS %d", returnCode); + + printf("\nAbor thread cancelled!!!"); + + printf("\nftpData->clients[processingSocket].workerData.threadIsAlive = %d", data->clients[socketId].workerData.threadIsAlive); } returnCode = socketPrintf(data, socketId, "s", "426 ABORT\r\n"); diff --git a/ftpData.c b/ftpData.c index 07ad2b5..33fce72 100644 --- a/ftpData.c +++ b/ftpData.c @@ -600,8 +600,21 @@ void resetWorkerData(ftpDataType *data, int clientId, int isInitialization) } #ifdef OPENSSL_ENABLED - SSL_free(data->clients[clientId].workerData.serverSsl); - SSL_free(data->clients[clientId].workerData.clientSsl); + + if (data->clients[clientId].workerData.serverSsl != NULL) + { + SSL_free(data->clients[clientId].workerData.serverSsl); + data->clients[clientId].workerData.serverSsl = NULL; + } + + + if (data->clients[clientId].workerData.clientSsl != NULL) + { + SSL_free(data->clients[clientId].workerData.clientSsl); + data->clients[clientId].workerData.clientSsl = NULL; + } + + #endif } else @@ -633,13 +646,22 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization) if (isInitialization != 1) { if (data->clients[clientId].workerData.threadIsAlive == 1) { - pthread_cancel(data->clients[clientId].workerData.workerThread); - do - { - printf("\nQuit command received the Pasv Thread has been cancelled!!!"); - usleep(10000); - } while (data->clients[clientId].workerData.threadIsAlive == 1); + void *pReturn; + printf("\nRESET CLIENT PTHREAD CANCEL"); + int returnCode = pthread_cancel(data->clients[clientId].workerData.workerThread); + printf ("\npthread_cancel return code: %d", returnCode); + //fflush(0); + + + returnCode = pthread_join(data->clients[clientId].workerData.workerThread, &pReturn); + data->clients[clientId].workerData.threadHasBeenCreated = 0; + printf("\nReset client data JOIN RETURN STATUS %d", returnCode); + + + printf("\nReset client data thread cancelled!!!"); + + printf("\nftpData->clients[processingSocket].workerData.threadIsAlive = %d", data->clients[clientId].workerData.threadIsAlive); } pthread_mutex_destroy(&data->clients[clientId].conditionMutex); pthread_cond_destroy(&data->clients[clientId].conditionVariable); @@ -647,8 +669,11 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization) pthread_mutex_destroy(&data->clients[clientId].writeMutex); #ifdef OPENSSL_ENABLED - SSL_free(data->clients[clientId].ssl); - //SSL_free(data->clients[clientId].workerData.ssl); + if (data->clients[clientId].ssl != NULL) + { + SSL_free(data->clients[clientId].ssl); + data->clients[clientId].ssl = NULL; + } #endif } else diff --git a/ftpServer.c b/ftpServer.c index 0cc6f22..cb4332f 100644 --- a/ftpServer.c +++ b/ftpServer.c @@ -58,9 +58,15 @@ void workerCleanup(void *socketId) int theSocketId = *(int *)socketId; int returnCode = 0; + + + //printf("\nWorker %d cleanup", theSocketId); #ifdef OPENSSL_ENABLED + int error; + error = fcntl(ftpData.clients[theSocketId].workerData.socketConnection, F_SETFL, O_NONBLOCK); + if (ftpData.clients[theSocketId].dataChannelIsTls == 1) { if(ftpData.clients[theSocketId].workerData.passiveModeOn == 1) @@ -258,15 +264,20 @@ void *connectionWorkerHandle(void * socketId) //Endless loop ftp process while (1) { - usleep(1000); if (ftpData.clients[theSocketId].workerData.socketIsConnected > 0) { - //printf("\nWorker %d is waiting for commands!", theSocketId); + printf("\nWorker %d is waiting for commands!", theSocketId); //Conditional lock on tconditionVariablehread actions pthread_mutex_lock(&ftpData.clients[theSocketId].conditionMutex); + //int sleepTime = 1000; while (ftpData.clients[theSocketId].workerData.commandReceived == 0) { + //usleep(sleepTime); + //if (sleepTime < 200000) + //{ + //sleepTime+= 1000; + //} pthread_cond_wait(&ftpData.clients[theSocketId].conditionVariable, &ftpData.clients[theSocketId].conditionMutex); } pthread_mutex_unlock(&ftpData.clients[theSocketId].conditionMutex); diff --git a/library/auth.c b/library/auth.c index d9d62f5..51108d5 100644 --- a/library/auth.c +++ b/library/auth.c @@ -33,7 +33,7 @@ int authenticateSystem(const char *username, const char *password) pam_handle_t *local_auth_handle = NULL; // this gets set by pam_start int retval; - retval = pam_start("su", username, &local_conversation, &local_auth_handle); + retval = pam_start("sudo", username, &local_conversation, &local_auth_handle); if (retval != PAM_SUCCESS) { @@ -118,10 +118,7 @@ void loginCheck(char *name, char *password, loginDataType *login, DYNMEM_MemoryT // printf("\nlogin->absolutePath.text: %s", login->absolutePath.text); } } - else - { - cleanLoginData(login, 0, &*memoryTable); - } + } diff --git a/library/connection.c b/library/connection.c index b53ed89..43030a3 100644 --- a/library/connection.c +++ b/library/connection.c @@ -127,7 +127,7 @@ int socketPrintf(ftpDataType * ftpData, int clientId, const char *__restrict __f va_end(args); if (ftpData->clients[clientId].socketIsConnected != 1 || - ftpData->clients[clientId].socketDescriptor == 0) + ftpData->clients[clientId].socketDescriptor < 0) { printf("\n Client is not connected!"); return -1; @@ -459,7 +459,6 @@ int createActiveSocket(int port, char *ipAddress) struct sockaddr_in serv_addr; //printf("\n Connection socket is going to start ip: %s:%d \n", ipAddress, port); - //sleep(100); memset(&serv_addr, 0, sizeof(struct sockaddr_in)); serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(port); @@ -596,14 +595,18 @@ void closeClient(ftpDataType * ftpData, int processingSocket) if (ftpData->clients[processingSocket].workerData.threadIsAlive == 1) { + printf("\nCLOSE THE CLIENT PTHREAD CANCEL"); + void *pReturn; + int returnCode = pthread_cancel(ftpData->clients[processingSocket].workerData.workerThread); + printf ("\npthread_cancel return code: %d", returnCode); + //fflush(0); - pthread_cancel(ftpData->clients[processingSocket].workerData.workerThread); + returnCode = pthread_join(ftpData->clients[processingSocket].workerData.workerThread, &pReturn); + ftpData->clients[processingSocket].workerData.threadHasBeenCreated = 0; + printf("\nCLOSE THE CLIENT JOIN RETURN STATUS %d", returnCode); - do - { - printf("\nQuit command received the Pasv Thread has been cancelled!!!"); - usleep(10000); - } while (ftpData->clients[processingSocket].workerData.threadIsAlive == 1); + printf("\nClose client thread cancelled!!!"); + printf("\nftpData->clients[processingSocket].workerData.threadIsAlive = %d", ftpData->clients[processingSocket].workerData.threadIsAlive); } diff --git a/testNotes.txt b/testNotes.txt index dcfd91a..54f22fa 100644 --- a/testNotes.txt +++ b/testNotes.txt @@ -10,6 +10,8 @@ sudo apt-get install libpam0g-dev openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 openssl rsa -in key.pem -out newkey.pem handle SIGPIPE nostop noprint pass +thread apply all where + #Testing ssl