diff --git a/build/modules/configRead.o b/build/modules/configRead.o index 441ccb4..6ff3bd8 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 9131847..ea5eccf 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 e6d2fb2..0dafa0d 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 e0d3f1b..40142cc 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 673c408..90fe04a 100644 Binary files a/build/modules/ftpServer.o and b/build/modules/ftpServer.o differ diff --git a/build/uFTP b/build/uFTP index a74834a..b35758e 100755 Binary files a/build/uFTP and b/build/uFTP differ diff --git a/ftpCommandElaborate.c b/ftpCommandElaborate.c index 515fed9..dc10a81 100644 --- a/ftpCommandElaborate.c +++ b/ftpCommandElaborate.c @@ -463,12 +463,17 @@ int parseCommandPasv(ftpDataType * data, int socketId) //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); + + if (data->clients[socketId].workerData.threadHasBeenCreated == 1) + 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; @@ -495,11 +500,12 @@ int parseCommandPort(ftpDataType * data, int socketId) returnCode = snprintf(data->clients[socketId].workerData.activeIpAddress, CLIENT_BUFFER_STRING_SIZE, "%d.%d.%d.%d", ipAddressBytes[0],ipAddressBytes[1],ipAddressBytes[2],ipAddressBytes[3]); void *pReturn; - //if (data->clients[socketId].workerData.threadIsAlive == 1) - //{ + if (data->clients[socketId].workerData.threadIsAlive == 1) + { returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); - //} - returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); + } + 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); @@ -526,11 +532,10 @@ int parseCommandAbor(ftpDataType * data, int socketId) if (data->clients[socketId].workerData.threadIsAlive == 1) { void *pReturn; - //if (data->clients[socketId].workerData.threadIsAlive == 1) - //{ + if (data->clients[socketId].workerData.threadIsAlive == 1) + { pthread_cancel(data->clients[socketId].workerData.workerThread); - //} - pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); + } returnCode = socketPrintf(data, socketId, "s", "426 ABORT\r\n"); if (returnCode <= 0) diff --git a/ftpData.c b/ftpData.c index a72402b..09c50c6 100644 --- a/ftpData.c +++ b/ftpData.c @@ -602,7 +602,8 @@ 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.workerThread = 0; + data->clients[clientId].workerData.threadHasBeenCreated = 0; + } if (pthread_mutex_init(&data->clients[clientId].workerData.conditionMutex, NULL) != 0) @@ -639,25 +640,16 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization) if (isInitialization != 1) { - if (data->clients[clientId].workerData.threadIsAlive == 1) - { - void *pReturn; - pthread_cancel(data->clients[clientId].workerData.workerThread); - pthread_join(data->clients[clientId].workerData.workerThread, &pReturn); - } - else - { - void *pReturn = NULL; - pthread_cancel(data->clients[clientId].workerData.workerThread); - pthread_join(data->clients[clientId].workerData.workerThread, &pReturn); - } + void *pReturn; + if (data->clients[clientId].workerData.threadIsAlive == 1) + pthread_cancel(data->clients[clientId].workerData.workerThread); - pthread_mutex_destroy(&data->clients[clientId].writeMutex); + pthread_mutex_destroy(&data->clients[clientId].writeMutex); - #ifdef OPENSSL_ENABLED - SSL_free(data->clients[clientId].ssl); - //SSL_free(data->clients[clientId].workerData.ssl); - #endif + #ifdef OPENSSL_ENABLED + SSL_free(data->clients[clientId].ssl); + //SSL_free(data->clients[clientId].workerData.ssl); + #endif } if (pthread_mutex_init(&data->clients[clientId].writeMutex, NULL) != 0) @@ -665,6 +657,7 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization) printf("\nclientData->writeMutex init failed\n"); exit(0); } + data->clients[clientId].tlsIsNegotiating = 0; data->clients[clientId].tlsIsEnabled = 0; data->clients[clientId].dataChannelIsTls = 0; diff --git a/ftpData.h b/ftpData.h index d637850..035b6fc 100644 --- a/ftpData.h +++ b/ftpData.h @@ -125,6 +125,7 @@ struct workerData #endif int threadIsAlive; + int threadHasBeenCreated; int connectionPort; int passiveModeOn; int activeModeOn; diff --git a/ftpServer.c b/ftpServer.c index 5376d4d..06bead8 100644 --- a/ftpServer.c +++ b/ftpServer.c @@ -570,7 +570,7 @@ void runFtpServer(void) //Debug print errors if (ftpData.clients[processingSock].bufferIndex < 0) { - //ftpData.clients[processingSock].closeTheClient = 1; + ftpData.clients[processingSock].closeTheClient = 1; printf("\n1 Errno = %d", errno); perror("1 Error: "); continue; diff --git a/library/connection.c b/library/connection.c index dbc3984..6275443 100644 --- a/library/connection.c +++ b/library/connection.c @@ -460,13 +460,13 @@ void closeClient(ftpDataType * ftpData, int processingSocket) { printf("\nQUIT FLAG SET!\n"); - // if (ftpData->clients[processingSocket].workerData.threadIsAlive == 1) - // { - void *pReturn; - pthread_cancel(ftpData->clients[processingSocket].workerData.workerThread); - pthread_join(ftpData->clients[processingSocket].workerData.workerThread, &pReturn); - printf("\nQuit command received the Pasv Thread has been cancelled."); - // } + if (ftpData->clients[processingSocket].workerData.threadIsAlive == 1) + { + void *pReturn; + pthread_cancel(ftpData->clients[processingSocket].workerData.workerThread); + //pthread_join(ftpData->clients[processingSocket].workerData.workerThread, &pReturn); + printf("\nQuit command received the Pasv Thread has been cancelled."); + } FD_CLR(ftpData->clients[processingSocket].socketDescriptor, &ftpData->connectionData.rsetAll); FD_CLR(ftpData->clients[processingSocket].socketDescriptor, &ftpData->connectionData.wsetAll); @@ -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 1; + return 0; } } else