mirror of
https://github.com/kingk85/uFTP.git
synced 2025-07-24 20:56:09 +03:00
Fixed security issues, upgrade! Fixed many instability issues on slow connections
This commit is contained in:
4
Makefile
4
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
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
build/uFTP
BIN
build/uFTP
Binary file not shown.
@ -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");
|
||||
|
45
ftpData.c
45
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
|
||||
|
15
ftpServer.c
15
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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user