diff --git a/Makefile b/Makefile index 874bb7a..1756300 100644 --- a/Makefile +++ b/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) diff --git a/build/modules/configRead.o b/build/modules/configRead.o index 12bb1f3..f60e28b 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 2e929eb..a9a96f5 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 0a9acd6..ff40ebc 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 9ad70bb..c330fb8 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 b76e10e..3b56810 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 2305cb7..b85496d 100644 Binary files a/build/modules/openSsl.o and b/build/modules/openSsl.o differ diff --git a/build/uFTP b/build/uFTP index 56af0a5..876323d 100755 Binary files a/build/uFTP and b/build/uFTP differ diff --git a/library/dynamicMemory.c b/library/dynamicMemory.c new file mode 100644 index 0000000..342cca2 --- /dev/null +++ b/library/dynamicMemory.c @@ -0,0 +1,118 @@ +/* + * dynamicMemory.c + * + * Created on: 22 dic 2018 + * Author: ugo + */ + +#include +#include +#include +#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); +} + diff --git a/library/dynamicMemory.h b/library/dynamicMemory.h new file mode 100644 index 0000000..6a7f29b --- /dev/null +++ b/library/dynamicMemory.h @@ -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_ */ diff --git a/library/errorHandling.c b/library/errorHandling.c new file mode 100644 index 0000000..85fbee3 --- /dev/null +++ b/library/errorHandling.c @@ -0,0 +1,33 @@ +/* + * errorHandling.c + * + * Created on: 22 dic 2018 + * Author: ugo + */ + +#include +#include +#include +#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); +} diff --git a/library/errorHandling.h b/library/errorHandling.h new file mode 100644 index 0000000..87359da --- /dev/null +++ b/library/errorHandling.h @@ -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_ */ diff --git a/uftpd.cfg b/uftpd.cfg index 480467e..04c1325 100644 --- a/uftpd.cfg +++ b/uftpd.cfg @@ -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