Added blocklist support

This commit is contained in:
root
2024-04-27 13:29:23 +02:00
parent 2fb8156a24
commit 4defc26372
5 changed files with 53 additions and 5 deletions

View File

@ -3,6 +3,7 @@ CC=gcc
#uncomment next line to compile with musl, suitable for statical compile
#CC=musl-gcc
#CC=/opt/cross/bin/arm-linux-musleabihf-gcc
OUTPATH=./build/
SOURCE_MODULES_PATH=./library/
@ -12,7 +13,7 @@ SOURCE_MODULES_PATH=./library/
ENDFLAG=
#uncomment next line to compile static no libc required,
#ENDFLAG=-static
ENDFLAG=-static
#FOR RELEASE
CFLAGSTEMP=-c -Wall -I.

View File

@ -1,8 +1,8 @@
#ifndef ENABLE_PRINTF_MODULE
// Uncomment next line to enable debug printf
//#define ENABLE_PRINTF
//#define ENABLE_PRINTF_ERROR
// #define ENABLE_PRINTF
// #define ENABLE_PRINTF_ERROR
#ifdef ENABLE_PRINTF
#define my_printf(fmt, args...) fprintf(stderr, " file: %s %d %s()" fmt, __FILE__, __LINE__, __func__, ##args)

View File

@ -63,8 +63,28 @@ int parseCommandUser(ftpDataType * data, int socketId)
{
if (strnlen(theUserName, 1) >= 1)
{
setDynamicStringDataType(&data->clients[socketId].login.name, theUserName, strlen(theUserName), &data->clients[socketId].memoryTable);
returnCode = socketPrintf(data, socketId, "s", "331 User ok, Waiting for the password.\r\n");
int userIsBlocked = 0;
// check if the user is blocked
for(int i = 0; i < data->ftpParameters.blockedUsersVector.Size; i++)
{
if(strncmp(theUserName, data->ftpParameters.blockedUsersVector.Data[i], CLIENT_COMMAND_STRING_SIZE-6) == 0)
{
userIsBlocked = 1;
break;
}
}
if (userIsBlocked == 0)
{
setDynamicStringDataType(&data->clients[socketId].login.name, theUserName, strlen(theUserName), &data->clients[socketId].memoryTable);
returnCode = socketPrintf(data, socketId, "s", "331 User ok, Waiting for the password.\r\n");
}
else
{
returnCode = socketPrintf(data, socketId, "s", "430 User is blocked.\r\n");
}
}
else
{

View File

@ -92,6 +92,7 @@ struct ftpParameters
int daemonModeOn;
int singleInstanceModeOn;
DYNV_VectorGenericDataType usersVector;
DYNV_VectorString_DataType blockedUsersVector;
int maximumIdleInactivity;
int maximumConnectionsPerIp;
int maximumUserAndPassowrdLoginTries;

View File

@ -711,5 +711,31 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
ftpParameters->usersVector.PushBack(&ftpParameters->usersVector, &userData, sizeof(usersParameters_DataType));
}
// parse the blocked user list
userIndex = 0;
memset(userX, 0, PARAMETER_SIZE_LIMIT);
DYNV_VectorString_Init(&ftpParameters->blockedUsersVector);
while(1)
{
int searchUserIndex, returnCode;
returnCode = snprintf(userX, PARAMETER_SIZE_LIMIT, "BLOCK_USER_%d", userIndex);
userIndex++;
searchUserIndex = searchParameter(userX, parametersVector);
if (searchUserIndex == -1)
{
break;
}
my_printf("\nAdd blocked user = %s", ((parameter_DataType *) parametersVector->Data[searchUserIndex])->value);
ftpParameters->blockedUsersVector.PushBack(&ftpParameters->blockedUsersVector, ((parameter_DataType *) parametersVector->Data[searchUserIndex])->value, strnlen(((parameter_DataType *) parametersVector->Data[searchUserIndex])->value, PARAMETER_SIZE_LIMIT));
}
for (int i = 0; i < ftpParameters->blockedUsersVector.Size; i++)
{
my_printf("\n User %s is blocked", ftpParameters->blockedUsersVector.Data[i]);
}
return 1;
}