mirror of
https://github.com/kingk85/uFTP.git
synced 2025-07-25 13:16:12 +03:00
Adding new features
This commit is contained in:
4
Makefile
4
Makefile
@ -19,8 +19,8 @@ ENABLE_LARGE_FILE_SUPPORT=-D LARGE_FILE_SUPPORT_ENABLED -D _LARGEFILE64_SOURCE
|
||||
|
||||
ENABLE_OPENSSL_SUPPORT=
|
||||
#TO ENABLE OPENSSL SUPPORT UNCOMMENT NEXT 2 LINES
|
||||
#ENABLE_OPENSSL_SUPPORT=-D OPENSSL_ENABLED
|
||||
#LIBS=-lpthread -lssl -lcrypto
|
||||
ENABLE_OPENSSL_SUPPORT=-D OPENSSL_ENABLED
|
||||
LIBS=-lpthread -lssl -lcrypto
|
||||
|
||||
CFLAGS=$(CFLAGSTEMP) $(ENABLE_LARGE_FILE_SUPPORT) $(ENABLE_OPENSSL_SUPPORT)
|
||||
|
||||
|
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.
118
library/dynamicMemory.c
Normal file
118
library/dynamicMemory.c
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* dynamicMemory.c
|
||||
*
|
||||
* Created on: 22 dic 2018
|
||||
* Author: ugo
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include "dynamicMemory.h"
|
||||
|
||||
//total memory allocated
|
||||
static unsigned long long int theTotalMemory;
|
||||
|
||||
void DYNMEM_Init(void)
|
||||
{
|
||||
theTotalMemory = 0;
|
||||
}
|
||||
|
||||
unsigned long long int DYNMEM_GetTotalMemory(void)
|
||||
{
|
||||
return theTotalMemory;
|
||||
}
|
||||
|
||||
unsigned long long int DYNMEM_IncreaseMemoryCounter(void)
|
||||
{
|
||||
return theTotalMemory;
|
||||
}
|
||||
unsigned long long int DYNMEM_DecreaseMemoryCounter(void)
|
||||
{
|
||||
return theTotalMemory;
|
||||
}
|
||||
|
||||
void * DYNMEM_malloc(size_t bytes)
|
||||
{
|
||||
void *memory = NULL;
|
||||
|
||||
DYNMEM_MemoryTable_DataType *new_item = NULL;
|
||||
|
||||
memory = calloc(bytes,1);
|
||||
new_item = calloc(1,sizeof(struct memory_list));
|
||||
if(memory)
|
||||
{
|
||||
if(new_item == NULL)
|
||||
{
|
||||
report_error_q("Memory allocation error, no room for memory list item.",
|
||||
__FILE__,__LINE__, 0);
|
||||
}
|
||||
|
||||
global_memory_count += bytes + sizeof(struct memory_list);
|
||||
|
||||
new_item->address = memory;
|
||||
new_item->size = bytes;
|
||||
new_item->next = NULL;
|
||||
new_item->prev = NULL;
|
||||
if(memory_list_head) {
|
||||
new_item->next = memory_list_head;
|
||||
memory_list_head->prev = new_item;
|
||||
memory_list_head = new_item;
|
||||
} else {
|
||||
memory_list_head = new_item;
|
||||
}
|
||||
return memory;
|
||||
} else {
|
||||
report_error_q("Memory allocation error, out of memory.",
|
||||
__FILE__,__LINE__,0);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void DYNMEM_free(void *f_address) {
|
||||
memory_list *temp = NULL,*found = NULL;
|
||||
if(f_address == NULL)
|
||||
return;
|
||||
for(temp=memory_list_head;temp!=NULL;temp = temp->next) {
|
||||
if(temp->address == f_address) {
|
||||
found = temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found) {
|
||||
report_error_q("Unable to free memory not previously allocated",
|
||||
__FILE__,__LINE__,0);
|
||||
// Report this as an error
|
||||
}
|
||||
global_memory_count -= found->size + sizeof(struct memory_list);
|
||||
free(f_address);
|
||||
if(found->prev)
|
||||
found->prev->next = found->next;
|
||||
if(found->next)
|
||||
found->next->prev = found->prev;
|
||||
if(found == memory_list_head)
|
||||
memory_list_head = found->next;
|
||||
free(found);
|
||||
}
|
||||
|
||||
|
||||
void DYNMEM_freeAll(void) {
|
||||
memory_list *temp = NULL;
|
||||
while(memory_list_head) {
|
||||
free(memory_list_head->address);
|
||||
309Chapter 13
|
||||
temp = memory_list_head->next;
|
||||
free(memory_list_head);
|
||||
memory_list_head = temp;
|
||||
}
|
||||
}
|
||||
void DYNMEM_memoryInit(void) {
|
||||
static int state = 0;
|
||||
if(state != 0)
|
||||
return;
|
||||
state = 1;
|
||||
memory_list_head = NULL;
|
||||
global_memory_count = 0;
|
||||
atexit(w_free_all);
|
||||
}
|
||||
|
31
library/dynamicMemory.h
Normal file
31
library/dynamicMemory.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* dynamicMemory.h
|
||||
*
|
||||
* Created on: 22 dic 2018
|
||||
* Author: ugo
|
||||
*/
|
||||
|
||||
#ifndef LIBRARY_DYNAMICMEMORY_H_
|
||||
#define LIBRARY_DYNAMICMEMORY_H_
|
||||
|
||||
typedef struct DYNMEM_MemoryTable_DataType
|
||||
{
|
||||
void *address;
|
||||
size_t size;
|
||||
struct DYNMEM_MemoryTable_DataType *nextElement;
|
||||
struct DYNMEM_MemoryTable_DataType *previousElement;
|
||||
};
|
||||
|
||||
void DYNMEM_Init(void);
|
||||
|
||||
unsigned long long int DYNMEM_GetTotalMemory(void);
|
||||
unsigned long long int DYNMEM_IncreaseMemoryCounter(void);
|
||||
unsigned long long int DYNMEM_DecreaseMemoryCounter(void);
|
||||
|
||||
|
||||
void *DYNMEM_malloc(size_t bytes);
|
||||
void DYNMEM_free(void *f_address);
|
||||
void DYNMEM_freeAll(void);
|
||||
void DYNMEM_memoryInit(void);
|
||||
|
||||
#endif /* LIBRARY_DYNAMICMEMORY_H_ */
|
33
library/errorHandling.c
Normal file
33
library/errorHandling.c
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* errorHandling.c
|
||||
*
|
||||
* Created on: 22 dic 2018
|
||||
* Author: ugo
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include "errorHandling.h"
|
||||
|
||||
|
||||
void report_error(const char *msg, const char *file, int line_no, int use_perror)
|
||||
{
|
||||
|
||||
fprintf(stderr,"[%s:%d] ",file,line_no);
|
||||
|
||||
if(use_perror != 0)
|
||||
{
|
||||
perror(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "%s\n",msg);
|
||||
}
|
||||
}
|
||||
|
||||
void report_error_q(const char *msg, const char *file, int line_no, int use_perror)
|
||||
{
|
||||
report_error(msg,file,line_no,use_perror);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
16
library/errorHandling.h
Normal file
16
library/errorHandling.h
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* errorHandling.h
|
||||
*
|
||||
* Created on: 22 dic 2018
|
||||
* Author: ugo
|
||||
*/
|
||||
|
||||
#ifndef LIBRARY_ERRORHANDLING_H_
|
||||
#define LIBRARY_ERRORHANDLING_H_
|
||||
|
||||
void report_error_q(const char *msg, const char *file,int line_no, int use_perror);
|
||||
void report_error(const char *msg, const char *file, int line_no, intuse_perror);
|
||||
|
||||
|
||||
|
||||
#endif /* LIBRARY_ERRORHANDLING_H_ */
|
@ -1,4 +1,4 @@
|
||||
#FTP CONFIGURATION SAMPLE
|
||||
#FTP CONFIGURATION SAMPLE "/etc/uftpd.cfg"
|
||||
|
||||
#######################################################
|
||||
# UFTP SERVER SETTINGS #
|
||||
@ -13,20 +13,18 @@ FTP_PORT = 21
|
||||
SINGLE_INSTANCE = true
|
||||
#Allow only one server instance (true or false)
|
||||
|
||||
DAEMON_MODE = true
|
||||
DAEMON_MODE = false
|
||||
#Run in background, daemon mode ok
|
||||
|
||||
IDLE_MAX_TIMEOUT = 3600
|
||||
# Idle timeout in seconds, client are disconnected for inactivity after the
|
||||
# specified amount of time in seconds, set to 0 to disable
|
||||
|
||||
|
||||
MAX_CONNECTION_NUMBER_PER_IP = 10
|
||||
#MAX CONNECTIONS PER IP
|
||||
#LIMIT THE MAXIMUM NUMBER OF CONNECTION FOR EACH IP ADDRESS
|
||||
# 0 TO DISABLE
|
||||
|
||||
|
||||
MAX_CONNECTION_TRY_PER_IP = 10
|
||||
#MAX LOGIN TRY PER IP
|
||||
#THE IP ADDRESS WILL BE BLOCKED FOR 5 MINUTES AFTER WRONG LOGIN USERNAME AND PASSWORD
|
||||
|
Reference in New Issue
Block a user