diff --git a/Makefile b/Makefile index f8d0a71..e6710f2 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,9 @@ CC=gcc OUTPATH=./build/ SOURCE_MODULES_PATH=./library/ -#FOR DEBUG PURPOSE -#CFLAGSTEMP=-c -Wall -I. -g -O0 -CFLAGSTEMP=-c -Wall -I. +#FOR DEBUG PURPOSE +CFLAGSTEMP=-c -Wall -I. -g -O0 +#CFLAGSTEMP=-c -Wall -I. OPTIMIZATION=-O3 HEADERS=-I LIBPATH=./build/modules/ @@ -38,7 +38,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) $(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) + @$(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 380e94b..441ccb4 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 8c1a304..dcd8352 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..5336d71 100644 Binary files a/build/modules/daemon.o and b/build/modules/daemon.o differ diff --git a/build/modules/dynamicVectors.o b/build/modules/dynamicVectors.o index 8c121dc..e5a967b 100644 Binary files a/build/modules/dynamicVectors.o and b/build/modules/dynamicVectors.o differ diff --git a/build/modules/fileManagement.o b/build/modules/fileManagement.o index 2dde5a0..b36c195 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 dd1b2f6..fe2b698 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 edbf6e8..d351da7 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 9e769a5..ab06ad2 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..28f97b6 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 24380ff..d980f4e 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..a5f5a54 100644 Binary files a/build/modules/signals.o and b/build/modules/signals.o differ diff --git a/build/uFTP b/build/uFTP index ebbb7f9..ff590c4 100755 Binary files a/build/uFTP and b/build/uFTP differ diff --git a/ftpCommandElaborate.c b/ftpCommandElaborate.c index 5ef5e94..bf88b7d 100644 --- a/ftpCommandElaborate.c +++ b/ftpCommandElaborate.c @@ -459,14 +459,17 @@ 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); + printf("\n data->clients[%d].workerData.workerThread = %d",socketId, (int)data->clients[socketId].workerData.workerThread); - if (data->clients[socketId].workerData.threadIsAlive == 1) - { - returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); - } - + //if (data->clients[socketId].workerData.threadIsAlive == 1) + // { + + returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); + printf("\npasv pthread_cancel = %d", returnCode); + //} + printf("\npasv join "); returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); + printf("\npasv join ok"); data->clients[socketId].workerData.passiveModeOn = 1; data->clients[socketId].workerData.activeModeOn = 0; returnCode = pthread_create(&data->clients[socketId].workerData.workerThread, NULL, connectionWorkerHandle, (void *) &data->clients[socketId].clientProgressiveNumber); diff --git a/ftpServer.c b/ftpServer.c index 8c22a79..d40c729 100644 --- a/ftpServer.c +++ b/ftpServer.c @@ -55,6 +55,8 @@ void workerCleanup(void *socketId) int theSocketId = *(int *)socketId; int returnCode = 0; + printf("\nWorker %d cleanup", theSocketId); + #ifdef OPENSSL_ENABLED if (ftpData.clients[theSocketId].dataChannelIsTls == 1) { @@ -62,7 +64,7 @@ void workerCleanup(void *socketId) { printf("\nSSL worker Shutdown 1"); returnCode = SSL_shutdown(ftpData.clients[theSocketId].workerData.serverSsl); - printf(" return code : %d", returnCode); + printf("\nnSSL worker Shutdown 1 return code : %d", returnCode); if (returnCode < 0) { @@ -70,7 +72,9 @@ void workerCleanup(void *socketId) } else if (returnCode == 0) { + printf("\nSSL worker Shutdown 2"); returnCode = SSL_shutdown(ftpData.clients[theSocketId].workerData.serverSsl); + printf("\nnSSL worker Shutdown 2 return code : %d", returnCode); if (returnCode <= 0) { @@ -107,6 +111,7 @@ void workerCleanup(void *socketId) close(ftpData.clients[theSocketId].workerData.socketConnection); close(ftpData.clients[theSocketId].workerData.passiveListeningSocket); resetWorkerData(&ftpData, theSocketId, 0); + printf("\nWorker cleaned!"); } void *connectionWorkerHandle(void * socketId) @@ -248,7 +253,7 @@ void *connectionWorkerHandle(void * socketId) if (ftpData.clients[theSocketId].workerData.socketIsConnected > 0) { - printf("\nWorker is waiting for commands!"); + printf("\nWorker %d is waiting for commands!", theSocketId); //Conditional lock on thread actions pthread_mutex_lock(&ftpData.clients[theSocketId].workerData.conditionMutex); while (ftpData.clients[theSocketId].workerData.commandReceived == 0) @@ -257,6 +262,8 @@ void *connectionWorkerHandle(void * socketId) } pthread_mutex_unlock(&ftpData.clients[theSocketId].workerData.conditionMutex); + printf("\nWorker %d unlocked", theSocketId); + if (ftpData.clients[theSocketId].workerData.commandReceived == 1 && compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "STOR", strlen("STOR")) == 1 && ftpData.clients[theSocketId].fileToStor.textLen > 0) diff --git a/library/connection.c b/library/connection.c index eb31065..165b12d 100644 --- a/library/connection.c +++ b/library/connection.c @@ -233,11 +233,11 @@ int socketWorkerPrintf(ftpDataType * ftpData, int clientId, const char *__restri #ifdef OPENSSL_ENABLED if (ftpData->clients[clientId].workerData.passiveModeOn == 1){ theReturnCode = SSL_write(ftpData->clients[clientId].workerData.serverSsl, theBuffer, theStringSize); - printf("passive: %s", theBuffer); + printf("%s", theBuffer); } else if (ftpData->clients[clientId].workerData.activeModeOn == 1){ theReturnCode = SSL_write(ftpData->clients[clientId].workerData.clientSsl, theBuffer, theStringSize); - printf("Active: %s", theBuffer); + printf("%s", theBuffer); } #endif } diff --git a/testNotes.txt b/testNotes.txt index c1e19a2..95e9809 100644 --- a/testNotes.txt +++ b/testNotes.txt @@ -1,8 +1,19 @@ #NOTES ONLY FOR DEVELOPERS #OPENSSL TEST COMMANDS + +#Required packages to compile +sudo apt-get install libssl-dev + + +#Remove password from a certificate +openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 +openssl rsa -in key.pem -out newkey.pem + + +#Testing ssl openssl s_client -starttls ftp -connect 192.168.1.237:21 sudo openssl s_server -key key.pem -cert cert.pem -accept 123 - +openssl s_client -connect 127.0.0.1:49473 USER username PASS password PROT P diff --git a/uftpd.cfg b/uftpd.cfg index aac0155..88679c1 100644 --- a/uftpd.cfg +++ b/uftpd.cfg @@ -10,7 +10,7 @@ MAXIMUM_ALLOWED_FTP_CONNECTION = 30 FTP_PORT = 21 #TCP/IP PORT SETTINGS (DEFAULT 21) -SINGLE_INSTANCE = true +SINGLE_INSTANCE = false #Allow only one server instance (true or false) DAEMON_MODE = false