diff --git a/build/modules/connection.o b/build/modules/connection.o index ea5eccf..ccc03c6 100644 Binary files a/build/modules/connection.o and b/build/modules/connection.o differ diff --git a/build/modules/ftpCommandElaborate.o b/build/modules/ftpCommandElaborate.o index 0dafa0d..d0d5c83 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 40142cc..9210736 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 90fe04a..51f0d5d 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 d980f4e..eff822f 100644 Binary files a/build/modules/openSsl.o and b/build/modules/openSsl.o differ diff --git a/build/uFTP b/build/uFTP index b35758e..aab3e1e 100755 Binary files a/build/uFTP and b/build/uFTP differ diff --git a/ftpCommandElaborate.c b/ftpCommandElaborate.c index dc10a81..900fccf 100644 --- a/ftpCommandElaborate.c +++ b/ftpCommandElaborate.c @@ -459,22 +459,21 @@ 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) - // { + 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); } - printf("\npasv pthread_cancel = %d", returnCode); - //} - printf("\npasv join "); 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 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); @@ -505,7 +504,9 @@ int parseCommandPort(ftpDataType * data, int socketId) returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); } if (data->clients[socketId].workerData.threadHasBeenCreated == 1) + { returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); + } data->clients[socketId].workerData.passiveModeOn = 0; data->clients[socketId].workerData.activeModeOn = 1; returnCode = pthread_create(&data->clients[socketId].workerData.workerThread, NULL, connectionWorkerHandle, (void *) &data->clients[socketId].clientProgressiveNumber); diff --git a/ftpData.c b/ftpData.c index 09c50c6..f4df1eb 100644 --- a/ftpData.c +++ b/ftpData.c @@ -603,7 +603,6 @@ void resetWorkerData(ftpDataType *data, int clientId, int isInitialization) DYNV_VectorGeneric_Init(&data->clients[clientId].workerData.directoryInfo); data->clients[clientId].workerData.theStorFile = NULL; data->clients[clientId].workerData.threadHasBeenCreated = 0; - } if (pthread_mutex_init(&data->clients[clientId].workerData.conditionMutex, NULL) != 0) diff --git a/ftpServer.c b/ftpServer.c index 06bead8..b065008 100644 --- a/ftpServer.c +++ b/ftpServer.c @@ -119,6 +119,7 @@ void *connectionWorkerHandle(void * socketId) int theSocketId = *(int *)socketId; pthread_cleanup_push(workerCleanup, (void *) &theSocketId); ftpData.clients[theSocketId].workerData.threadIsAlive = 1; + ftpData.clients[theSocketId].workerData.threadHasBeenCreated = 1; int returnCode; printf("\nWORKER CREATED!"); @@ -505,7 +506,7 @@ void runFtpServer(void) { break; } - + /* no data to check client is not connected, continue to check other clients */ if (isClientConnected(&ftpData, processingSock) == 0) { diff --git a/library/connection.c b/library/connection.c index 6275443..3c4103d 100644 --- a/library/connection.c +++ b/library/connection.c @@ -630,7 +630,7 @@ int evaluateClientSocketConnection(ftpDataType * ftpData) //Errors while accepting, socket will be closed ftpData->clients[availableSocketIndex].closeTheClient = 1; printf("\n2 Errno = %d", errno); - return 0; + return 1; } } else @@ -644,14 +644,9 @@ int evaluateClientSocketConnection(ftpDataType * ftpData) write(socketRefuseFd, messageToWrite, strlen(messageToWrite)); shutdown(socketRefuseFd, SHUT_RDWR); close(socketRefuseFd); - return 0; - } - else - { - ftpData->clients[availableSocketIndex].closeTheClient = 1; - printf("\n3 Errno = %d", errno); - return 1; } + + return 0; } } else diff --git a/library/openSsl.c b/library/openSsl.c index f50e7aa..7cea289 100644 --- a/library/openSsl.c +++ b/library/openSsl.c @@ -33,6 +33,19 @@ #include "openSsl.h" #include "fileManagement.h" + + + +#define MUTEX_TYPE pthread_mutex_t +#define MUTEX_SETUP(x) pthread_mutex_init(&(x), NULL) +#define MUTEX_CLEANUP(x) pthread_mutex_destroy(&(x)) +#define MUTEX_LOCK(x) pthread_mutex_lock(&(x)) +#define MUTEX_UNLOCK(x) pthread_mutex_unlock(&(x)) +#define THREAD_ID pthread_self() + +/* This array will store all of the mutexes available to OpenSSL. */ +static MUTEX_TYPE *mutex_buf = NULL; + void initOpenssl() { OpenSSL_add_all_algorithms(); /* Load cryptos, et.al. */ @@ -40,11 +53,14 @@ void initOpenssl() ERR_load_BIO_strings(); ERR_load_crypto_strings(); SSL_library_init(); + thread_setup(); } void cleanupOpenssl() { + thread_cleanup(); EVP_cleanup(); + } SSL_CTX *createServerContext() @@ -162,4 +178,54 @@ void ShowCerts(SSL* ssl) } + +void handle_error(const char *file, int lineno, const char *msg) +{ + fprintf(stderr, "** %s:%d %s\n", file, lineno, msg); + ERR_print_errors_fp(stderr); + /* exit(-1); */ +} + +static void locking_function(int mode, int n, const char *file, int line) +{ + if(mode & CRYPTO_LOCK) + MUTEX_LOCK(mutex_buf[n]); + else + MUTEX_UNLOCK(mutex_buf[n]); +} + +static unsigned long id_function(void) +{ + return ((unsigned long)THREAD_ID); +} + +int thread_setup(void) +{ + int i; + + mutex_buf = malloc(CRYPTO_num_locks() * sizeof(MUTEX_TYPE)); + if(!mutex_buf) + return 0; + for(i = 0; i < CRYPTO_num_locks(); i++) + MUTEX_SETUP(mutex_buf[i]); + CRYPTO_set_id_callback(id_function); + CRYPTO_set_locking_callback(locking_function); + return 1; +} + +int thread_cleanup(void) +{ + int i; + + if(!mutex_buf) + return 0; + CRYPTO_set_id_callback(NULL); + CRYPTO_set_locking_callback(NULL); + for(i = 0; i < CRYPTO_num_locks(); i++) + MUTEX_CLEANUP(mutex_buf[i]); + free(mutex_buf); + mutex_buf = NULL; + return 1; +} + #endif