diff --git a/MakeFileGeneric b/MakeFileGeneric index 586392c..4db0455 100644 --- a/MakeFileGeneric +++ b/MakeFileGeneric @@ -36,8 +36,8 @@ start: end: @echo Build process end -uFTP: uFTP.c fileManagement.o configRead.o logFunctions.o ftpCommandElaborate.o ftpData.o ftpServer.o daemon.o - @$(CC) uFTP.c $(LIBPATH)dynamicVectors.o $(LIBPATH)fileManagement.o $(LIBPATH)configRead.o $(LIBPATH)logFunctions.o $(LIBPATH)ftpCommandElaborate.o $(LIBPATH)ftpData.o $(LIBPATH)ftpServer.o $(LIBPATH)daemon.o -o $(OUTPATH)uFTP -lpthread +uFTP: uFTP.c fileManagement.o configRead.o logFunctions.o ftpCommandElaborate.o ftpData.o ftpServer.o daemon.o signals.o + @$(CC) uFTP.c $(LIBPATH)dynamicVectors.o $(LIBPATH)fileManagement.o $(LIBPATH)configRead.o $(LIBPATH)logFunctions.o $(LIBPATH)ftpCommandElaborate.o $(LIBPATH)ftpData.o $(LIBPATH)ftpServer.o $(LIBPATH)daemon.o $(LIBPATH)signals.o -o $(OUTPATH)uFTP -lpthread daemon.o: @$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)daemon.c -o $(LIBPATH)daemon.o @@ -51,6 +51,9 @@ configRead.o: dynamicVectors.o fileManagement.o fileManagement.o: @$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)fileManagement.c -o $(LIBPATH)fileManagement.o +signals.o: + @$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)signals.c -o $(LIBPATH)signals.o + logFunctions.o: @$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)logFunctions.c -o $(LIBPATH)logFunctions.o diff --git a/build/Debug/GNU-Linux/ftpCommandElaborate.o b/build/Debug/GNU-Linux/ftpCommandElaborate.o index a28cfcf..6b0ef63 100644 Binary files a/build/Debug/GNU-Linux/ftpCommandElaborate.o and b/build/Debug/GNU-Linux/ftpCommandElaborate.o differ diff --git a/build/Debug/GNU-Linux/ftpData.o b/build/Debug/GNU-Linux/ftpData.o index 3252171..fc63444 100644 Binary files a/build/Debug/GNU-Linux/ftpData.o and b/build/Debug/GNU-Linux/ftpData.o differ diff --git a/build/Debug/GNU-Linux/ftpServer.o b/build/Debug/GNU-Linux/ftpServer.o index 3a049d8..d82d9c8 100644 Binary files a/build/Debug/GNU-Linux/ftpServer.o and b/build/Debug/GNU-Linux/ftpServer.o differ diff --git a/build/Debug/GNU-Linux/ftpServer.o.d b/build/Debug/GNU-Linux/ftpServer.o.d index 2b7db03..7917d92 100644 --- a/build/Debug/GNU-Linux/ftpServer.o.d +++ b/build/Debug/GNU-Linux/ftpServer.o.d @@ -2,7 +2,7 @@ build/Debug/GNU-Linux/ftpServer.o: ftpServer.c library/dynamicVectors.h \ library/fileManagement.h library/dynamicVectors.h ftpServer.h ftpData.h \ library/dynamicVectors.h library/configRead.h library/dynamicVectors.h \ ftpCommandsElaborate.h library/fileManagement.h library/logFunctions.h \ - library/daemon.h + library/daemon.h library/signals.h library/dynamicVectors.h: @@ -27,3 +27,5 @@ library/fileManagement.h: library/logFunctions.h: library/daemon.h: + +library/signals.h: diff --git a/build/Debug/GNU-Linux/library/configRead.o b/build/Debug/GNU-Linux/library/configRead.o index b5bc422..d2268de 100644 Binary files a/build/Debug/GNU-Linux/library/configRead.o and b/build/Debug/GNU-Linux/library/configRead.o differ diff --git a/build/Debug/GNU-Linux/library/signals.o b/build/Debug/GNU-Linux/library/signals.o new file mode 100644 index 0000000..cf47646 Binary files /dev/null and b/build/Debug/GNU-Linux/library/signals.o differ diff --git a/build/Debug/GNU-Linux/library/signals.o.d b/build/Debug/GNU-Linux/library/signals.o.d new file mode 100644 index 0000000..ff9cc4d --- /dev/null +++ b/build/Debug/GNU-Linux/library/signals.o.d @@ -0,0 +1,11 @@ +build/Debug/GNU-Linux/library/signals.o: library/signals.c \ + library/dynamicVectors.h library/fileManagement.h \ + library/dynamicVectors.h library/../ftpServer.h + +library/dynamicVectors.h: + +library/fileManagement.h: + +library/dynamicVectors.h: + +library/../ftpServer.h: diff --git a/build/Debug/GNU-Linux/uFTP.o b/build/Debug/GNU-Linux/uFTP.o index dd15473..5675003 100644 Binary files a/build/Debug/GNU-Linux/uFTP.o and b/build/Debug/GNU-Linux/uFTP.o differ diff --git a/build/modules/configRead.o b/build/modules/configRead.o index 937108c..18d7799 100644 Binary files a/build/modules/configRead.o and b/build/modules/configRead.o differ diff --git a/build/modules/daemon.o b/build/modules/daemon.o index 023c851..66c893e 100644 Binary files a/build/modules/daemon.o and b/build/modules/daemon.o differ diff --git a/build/modules/dynamicVectors.o b/build/modules/dynamicVectors.o index c91634e..5294836 100644 Binary files a/build/modules/dynamicVectors.o and b/build/modules/dynamicVectors.o differ diff --git a/build/modules/fileManagement.o b/build/modules/fileManagement.o index 0d59177..6cb0e63 100644 Binary files a/build/modules/fileManagement.o and b/build/modules/fileManagement.o differ diff --git a/build/modules/ftpCommandElaborate.o b/build/modules/ftpCommandElaborate.o index 6aeda00..114aa2e 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 ec4b77c..db499c0 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 f51fa1e..381764c 100644 Binary files a/build/modules/ftpServer.o and b/build/modules/ftpServer.o differ diff --git a/build/modules/logFunctions.o b/build/modules/logFunctions.o index cdf163b..3eb2143 100644 Binary files a/build/modules/logFunctions.o and b/build/modules/logFunctions.o differ diff --git a/build/modules/signals.o b/build/modules/signals.o new file mode 100644 index 0000000..d4bb9ca Binary files /dev/null and b/build/modules/signals.o differ diff --git a/build/uFTP b/build/uFTP new file mode 100755 index 0000000..4ad84a9 Binary files /dev/null and b/build/uFTP differ diff --git a/dist/Debug/GNU-Linux/config.cfg b/dist/Debug/GNU-Linux/config.cfg deleted file mode 120000 index 9a53664..0000000 --- a/dist/Debug/GNU-Linux/config.cfg +++ /dev/null @@ -1 +0,0 @@ -../../../config.cfg \ No newline at end of file diff --git a/dist/Debug/GNU-Linux/uftp b/dist/Debug/GNU-Linux/uftp index debe05f..10d8a3d 100755 Binary files a/dist/Debug/GNU-Linux/uftp and b/dist/Debug/GNU-Linux/uftp differ diff --git a/dist/Debug/GNU-Linux/uftpd.cfg b/dist/Debug/GNU-Linux/uftpd.cfg new file mode 120000 index 0000000..630971a --- /dev/null +++ b/dist/Debug/GNU-Linux/uftpd.cfg @@ -0,0 +1 @@ +../../../uftpd.cfg \ No newline at end of file diff --git a/ftpServer.c b/ftpServer.c index 8f8fdc7..952d5ed 100644 --- a/ftpServer.c +++ b/ftpServer.c @@ -29,6 +29,7 @@ #include #include + #include #include #include @@ -47,12 +48,8 @@ #include "library/logFunctions.h" #include "library/configRead.h" #include "library/daemon.h" +#include "library/signals.h" -/* Catch Signal Handler functio */ -void signal_callback_handler(int signum){ - - printf("Caught signal SIGPIPE %d\n",signum); -} static ftpDataType ftpData; @@ -366,15 +363,13 @@ void *connectionWorkerHandle(void * socketId) void runFtpServer(void) { - DYNV_VectorGenericDataType configParameters; fd_set rset, wset, eset, rsetAll, wsetAll, esetAll; static int processingSock = 0; static int maxSocketFD = 0; - DYNV_VectorGeneric_Init(&configParameters); - readConfigurationFile("./config.cfg", &configParameters); - parseConfigurationFile(&ftpData.ftpParameters, &configParameters); - + /*Read the configuration file */ + configurationRead(&ftpData.ftpParameters); + if (ftpData.ftpParameters.singleInstanceModeOn == 1) { int returnCode = isProcessAlreadyRunning(); @@ -385,15 +380,15 @@ void runFtpServer(void) exit(0); } } - /* Fork the process daemon mode */ if (ftpData.ftpParameters.daemonModeOn == 1) { daemonize("uFTP"); } + signalHandlerInstall(); initFtpData(); - + //Socket main creator ftpData.theSocket = createSocket(ftpData.ftpParameters.port); printTimeStamp(); diff --git a/library/configRead.c b/library/configRead.c index a4eb0b2..4b2dc3f 100644 --- a/library/configRead.c +++ b/library/configRead.c @@ -22,8 +22,6 @@ * THE SOFTWARE. */ - - #include #include #include @@ -34,9 +32,58 @@ #define PARAMETER_SIZE_LIMIT 1024 -int readConfigurationFile(char *path, DYNV_VectorGenericDataType *parametersVector) -{ +/* Public Functions */ +int searchUser(char *name, DYNV_VectorGenericDataType *usersVector) +{ + int returnCode = -1; + int i = 0; + + for (i = 0; i Size; i++) + { + if (strcmp(name, ((usersParameters_DataType *) usersVector->Data[i])->name) == 0) + { + return i; + } + } + + return returnCode; +} + +void configurationRead(ftpParameters_DataType *ftpParameters) +{ + int returnCode = 0; + DYNV_VectorGenericDataType configParameters; + DYNV_VectorGeneric_Init(&configParameters); + + if (FILE_IsFile(LOCAL_CONFIGURATION_FILENAME) == 1) + { + printf("\nReading configuration from \n -> %s", LOCAL_CONFIGURATION_FILENAME); + returnCode = readConfigurationFile(LOCAL_CONFIGURATION_FILENAME, &configParameters); + } + else if (FILE_IsFile(DEFAULT_CONFIGURATION_FILENAME) == 1) + { + printf("\nReading configuration from \n -> %s", DEFAULT_CONFIGURATION_FILENAME); + returnCode = readConfigurationFile(DEFAULT_CONFIGURATION_FILENAME, &configParameters); + } + + if (returnCode == 1) + { + parseConfigurationFile(ftpParameters, &configParameters); + } + else + { + printf("\nError: could not read the configuration file located at: \n -> %s or at \n -> %s", DEFAULT_CONFIGURATION_FILENAME, LOCAL_CONFIGURATION_FILENAME); + exit(1); + } + + return; +} + + +/*Private functions*/ +static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *parametersVector) +{ #define STATE_START 0 #define STATE_NAME 1 #define STATE_VALUE 2 @@ -76,17 +123,17 @@ int readConfigurationFile(char *path, DYNV_VectorGenericDataType *parametersVect /* 1st char is a sharp comment case */ else if (theFileContent[i] == '#') { - state = STATE_TO_NEW_LINE; - i++; + state = STATE_TO_NEW_LINE; + i++; } /* Name Start */ else { - state = STATE_NAME; + state = STATE_NAME; } } break; - + case STATE_NAME: { /* Not allowed chars in the name */ @@ -122,7 +169,7 @@ int readConfigurationFile(char *path, DYNV_VectorGenericDataType *parametersVect } } break; - + case STATE_VALUE: { /* Skip not allowed values */ @@ -136,17 +183,19 @@ int readConfigurationFile(char *path, DYNV_VectorGenericDataType *parametersVect else if (theFileContent[i] == '"') { i++; - + if (allowSpacesInValue == 0) allowSpacesInValue = 1; else allowSpacesInValue = 0; - } + } else if (theFileContent[i] == '\n') { /* Value stored proceed to save */ - if (valueIndex > 0) + if (valueIndex > 0) + { state = STATE_STORE; + } else if (valueIndex == 0) /* No void value allowed*/ { memset(name, 0, PARAMETER_SIZE_LIMIT); @@ -171,7 +220,7 @@ int readConfigurationFile(char *path, DYNV_VectorGenericDataType *parametersVect /* Wait until a new line is found */ if (theFileContent[i] == '\n') { - state = STATE_START; + state = STATE_START; } i++; } @@ -179,33 +228,48 @@ int readConfigurationFile(char *path, DYNV_VectorGenericDataType *parametersVect case STATE_STORE: { - parameter_DataType parameter; - parameter.name = malloc(nameIndex+1); - parameter.value = malloc(valueIndex+1); - strcpy(parameter.name, name); - strcpy(parameter.value, value); - parameter.name[nameIndex] = '\0'; - parameter.value[valueIndex] = '\0'; - memset(name, 0, PARAMETER_SIZE_LIMIT); - memset(value, 0, PARAMETER_SIZE_LIMIT); - nameIndex = 0; - valueIndex = 0; - state = STATE_START; - printf("\nParameter read: %s = %s", parameter.name, parameter.value); - parametersVector->PushBack(parametersVector, ¶meter, sizeof(parameter_DataType)); + parameter_DataType parameter; + parameter.name = malloc(nameIndex+1); + parameter.value = malloc(valueIndex+1); + strcpy(parameter.name, name); + strcpy(parameter.value, value); + parameter.name[nameIndex] = '\0'; + parameter.value[valueIndex] = '\0'; + memset(name, 0, PARAMETER_SIZE_LIMIT); + memset(value, 0, PARAMETER_SIZE_LIMIT); + nameIndex = 0; + valueIndex = 0; + state = STATE_START; + //printf("\nParameter read: %s = %s", parameter.name, parameter.value); + parametersVector->PushBack(parametersVector, ¶meter, sizeof(parameter_DataType)); } break; - } - - } - return 1; + /* che if there is a value to store */ + if (state == STATE_VALUE && + valueIndex > 0) + { + parameter_DataType parameter; + parameter.name = malloc(nameIndex+1); + parameter.value = malloc(valueIndex+1); + strcpy(parameter.name, name); + strcpy(parameter.value, value); + parameter.name[nameIndex] = '\0'; + parameter.value[valueIndex] = '\0'; + memset(name, 0, PARAMETER_SIZE_LIMIT); + memset(value, 0, PARAMETER_SIZE_LIMIT); + nameIndex = 0; + valueIndex = 0; + //printf("\nParameter read: %s = %s", parameter.name, parameter.value); + parametersVector->PushBack(parametersVector, ¶meter, sizeof(parameter_DataType)); + } + return 1; } -int searchParameter(char *name, DYNV_VectorGenericDataType *parametersVector) +static int searchParameter(char *name, DYNV_VectorGenericDataType *parametersVector) { int returnCode = -1; int i = 0; @@ -221,48 +285,39 @@ int searchParameter(char *name, DYNV_VectorGenericDataType *parametersVector) return returnCode; } -int searchUser(char *name, DYNV_VectorGenericDataType *usersVector) +static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_VectorGenericDataType *parametersVector) { - int returnCode = -1; - int i = 0; + int searchIndex, userIndex; - for (i = 0; i Size; i++) - { - if (strcmp(name, ((usersParameters_DataType *) usersVector->Data[i])->name) == 0) - { - return i; - } - } - - return returnCode; -} - -int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_VectorGenericDataType *parametersVector) -{ - int searchIndex; - int userIndex; - char userX[PARAMETER_SIZE_LIMIT], passwordX[PARAMETER_SIZE_LIMIT], homeX[PARAMETER_SIZE_LIMIT]; + char userX[PARAMETER_SIZE_LIMIT], + passwordX[PARAMETER_SIZE_LIMIT], + homeX[PARAMETER_SIZE_LIMIT]; + + printf("\nReading configuration settings.."); searchIndex = searchParameter("MAXIMUM_ALLOWED_FTP_CONNECTION", parametersVector); if (searchIndex != -1) { ftpParameters->maxClients = atoi(((parameter_DataType *) parametersVector->Data[searchIndex])->value); - printf("\nFtp maximum allowed clients: %d", ftpParameters->maxClients); + printf("\nMAXIMUM_ALLOWED_FTP_CONNECTION: %d", ftpParameters->maxClients); } else { ftpParameters->maxClients = 10; + printf("\nMAXIMUM_ALLOWED_FTP_CONNECTION parameter not found in the configuration file, using the default value: %d", ftpParameters->maxClients); } searchIndex = searchParameter("FTP_PORT", parametersVector); if (searchIndex != -1) { ftpParameters->port = atoi(((parameter_DataType *) parametersVector->Data[searchIndex])->value); - printf("\nFtp port: %d", ftpParameters->port); + printf("\nFTP_PORT: %d", ftpParameters->port); + } else { ftpParameters->port = 21; + printf("\nFTP_PORT parameter not found in the configuration file, using the default value: %d", ftpParameters->maxClients); } @@ -275,6 +330,12 @@ int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_VectorGen if(strcmp(((parameter_DataType *) parametersVector->Data[searchIndex])->value, "TRUE") == 0) ftpParameters->daemonModeOn = 1; + + printf("\nDAEMON_MODE value: %d", ftpParameters->daemonModeOn); + } + else + { + printf("\nDAEMON_MODE parameter not found in the configuration file, using the default value: %d", ftpParameters->daemonModeOn); } ftpParameters->singleInstanceModeOn = 0; @@ -287,21 +348,22 @@ int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_VectorGen if(strcmp(((parameter_DataType *) parametersVector->Data[searchIndex])->value, "TRUE") == 0) ftpParameters->singleInstanceModeOn = 1; } - - - - ftpParameters->maximumIdleInactivity = 0; + else + { + printf("\nSINGLE_INSTANCE parameter not found in the configuration file, using the default value: %d", ftpParameters->singleInstanceModeOn); + } + + ftpParameters->maximumIdleInactivity = 3600; searchIndex = searchParameter("IDLE_MAX_TIMEOUT", parametersVector); if (searchIndex != -1) { ftpParameters->maximumIdleInactivity = atoi(((parameter_DataType *) parametersVector->Data[searchIndex])->value); - } - printf("\nftpParameters->maximumIdleInactivity: %d", ftpParameters->maximumIdleInactivity); - - - printf("\nFtp singleInstanceModeOn: %d", ftpParameters->singleInstanceModeOn); - printf("\nFtp daemonModeOn: %d", ftpParameters->daemonModeOn); - + printf("\nIDLE_MAX_TIMEOUT value: %d", ftpParameters->maximumIdleInactivity); + } + else + { + printf("\nIDLE_MAX_TIMEOUT parameter not found in the configuration file, using the default value: %d", ftpParameters->maximumIdleInactivity); + } searchIndex = searchParameter("FTP_SERVER_IP", parametersVector); if (searchIndex != -1) @@ -310,32 +372,29 @@ int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_VectorGen &ftpParameters->ftpIpAddress[1], &ftpParameters->ftpIpAddress[2], &ftpParameters->ftpIpAddress[3]); - printf("\nFtp ip address: %d.%d.%d.%d", ftpParameters->ftpIpAddress[0], - ftpParameters->ftpIpAddress[1], - ftpParameters->ftpIpAddress[2], - ftpParameters->ftpIpAddress[3]); + printf("\nFTP_SERVER_IP value: %d.%d.%d.%d", ftpParameters->ftpIpAddress[0], + ftpParameters->ftpIpAddress[1], + ftpParameters->ftpIpAddress[2], + ftpParameters->ftpIpAddress[3]); } else { ftpParameters->ftpIpAddress[0] = 127; ftpParameters->ftpIpAddress[1] = 0; ftpParameters->ftpIpAddress[2] = 0; - ftpParameters->ftpIpAddress[3] = 1; + ftpParameters->ftpIpAddress[3] = 1; + printf("\nFTP_SERVER_IP parameter not found in the configuration file, listening on all available networks"); } - printf("\nFtp port wait start: %d", ftpParameters->port); /* USER SETTINGS */ userIndex = 0; - memset(userX, 0, PARAMETER_SIZE_LIMIT); memset(passwordX, 0, PARAMETER_SIZE_LIMIT); memset(homeX, 0, PARAMETER_SIZE_LIMIT); DYNV_VectorGeneric_Init(&ftpParameters->usersVector); - printf("\nFtp port xxx: %d", ftpParameters->port); while(1) { - printf("\nFtp port start: %d", ftpParameters->port); int searchUserIndex, searchPasswordIndex, searchHomeIndex; usersParameters_DataType userData; @@ -368,17 +427,13 @@ int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_VectorGen userData.password[strlen(((parameter_DataType *) parametersVector->Data[searchPasswordIndex])->value)] = '\0'; userData.homePath[strlen(((parameter_DataType *) parametersVector->Data[searchHomeIndex])->value)] = '\0'; - printf("\n\nAdding user"); + printf("\nUser parameter found"); printf("\nName: %s", userData.name); printf("\nPassword: %s", userData.password); printf("\nHomePath: %s", userData.homePath); - - ftpParameters->usersVector.PushBack(&ftpParameters->usersVector, &userData, sizeof(usersParameters_DataType)); - printf("\nFtp port end: %d", ftpParameters->port); - } - - - + ftpParameters->usersVector.PushBack(&ftpParameters->usersVector, &userData, sizeof(usersParameters_DataType)); + } + return 1; } \ No newline at end of file diff --git a/library/configRead.h b/library/configRead.h index a2eb4bd..b76072d 100644 --- a/library/configRead.h +++ b/library/configRead.h @@ -28,9 +28,14 @@ #ifdef __cplusplus extern "C" { #endif - + #include "dynamicVectors.h" +#define DEFAULT_CONFIGURATION_FILENAME "/etc/uftpd.cfg" +#define LOCAL_CONFIGURATION_FILENAME "./uftpd.cfg" + + +/* Data structures */ struct parameter { char* name; @@ -55,10 +60,15 @@ struct ftpParameters int maximumIdleInactivity; } typedef ftpParameters_DataType; -int readConfigurationFile(char *path, DYNV_VectorGenericDataType *parametersVector); -int searchParameter(char *name, DYNV_VectorGenericDataType *parametersVector); + +/*Public functions */ int searchUser(char *name, DYNV_VectorGenericDataType *usersVector); -int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_VectorGenericDataType *parametersVector); +void configurationRead(ftpParameters_DataType *ftpParameters); + +/* Private Functions */ +static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_VectorGenericDataType *parametersVector); +static int searchParameter(char *name, DYNV_VectorGenericDataType *parametersVector); +static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *parametersVector); #ifdef __cplusplus } diff --git a/library/signals.c b/library/signals.c new file mode 100644 index 0000000..552fb9f --- /dev/null +++ b/library/signals.c @@ -0,0 +1,38 @@ +/* + * The MIT License + * + * Copyright 2018 Ugo Cirmignani + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include "../ftpServer.h" + + +/* Catch Signal Handler functio */ +void signal_callback_handler(int signum){ + + printf("Caught signal SIGPIPE %d\n",signum); +} + +void signalHandlerInstall(void) +{ + signal(SIGPIPE, signal_callback_handler); +} \ No newline at end of file diff --git a/library/signals.h b/library/signals.h new file mode 100644 index 0000000..7b1ebb3 --- /dev/null +++ b/library/signals.h @@ -0,0 +1,47 @@ +/* + * The MIT License + * + * Copyright 2018 Ugo Cirmignani + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/* + * File: signals.h + * Author: ugo + * + * Created on 24 febbraio 2018, 19.15 + */ + +#ifndef SIGNALS_H +#define SIGNALS_H + +#ifdef __cplusplus +extern "C" { +#endif + +void signalHandlerInstall(void); +void signal_callback_handler(int signum); + +#ifdef __cplusplus +} +#endif + +#endif /* SIGNALS_H */ + diff --git a/nbproject/Makefile-Debug.mk b/nbproject/Makefile-Debug.mk index 4325091..900d6f4 100644 --- a/nbproject/Makefile-Debug.mk +++ b/nbproject/Makefile-Debug.mk @@ -43,6 +43,7 @@ OBJECTFILES= \ ${OBJECTDIR}/library/dynamicVectors.o \ ${OBJECTDIR}/library/fileManagement.o \ ${OBJECTDIR}/library/logFunctions.o \ + ${OBJECTDIR}/library/signals.o \ ${OBJECTDIR}/uFTP.o @@ -110,6 +111,11 @@ ${OBJECTDIR}/library/logFunctions.o: library/logFunctions.c ${RM} "$@.d" $(COMPILE.c) -g -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/logFunctions.o library/logFunctions.c +${OBJECTDIR}/library/signals.o: library/signals.c + ${MKDIR} -p ${OBJECTDIR}/library + ${RM} "$@.d" + $(COMPILE.c) -g -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/signals.o library/signals.c + ${OBJECTDIR}/uFTP.o: uFTP.c ${MKDIR} -p ${OBJECTDIR} ${RM} "$@.d" diff --git a/nbproject/Makefile-Release.mk b/nbproject/Makefile-Release.mk index b553a0c..f6f23c7 100644 --- a/nbproject/Makefile-Release.mk +++ b/nbproject/Makefile-Release.mk @@ -43,6 +43,7 @@ OBJECTFILES= \ ${OBJECTDIR}/library/dynamicVectors.o \ ${OBJECTDIR}/library/fileManagement.o \ ${OBJECTDIR}/library/logFunctions.o \ + ${OBJECTDIR}/library/signals.o \ ${OBJECTDIR}/uFTP.o @@ -110,6 +111,11 @@ ${OBJECTDIR}/library/logFunctions.o: library/logFunctions.c ${RM} "$@.d" $(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/logFunctions.o library/logFunctions.c +${OBJECTDIR}/library/signals.o: library/signals.c + ${MKDIR} -p ${OBJECTDIR}/library + ${RM} "$@.d" + $(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/signals.o library/signals.c + ${OBJECTDIR}/uFTP.o: uFTP.c ${MKDIR} -p ${OBJECTDIR} ${RM} "$@.d" diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 55ac939..2c5fccb 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -9,6 +9,7 @@ library/dynamicVectors.h library/fileManagement.h library/logFunctions.h + library/signals.h library/daemon.h ftpCommandsElaborate.h @@ -29,14 +30,15 @@ library/dynamicVectors.c library/fileManagement.c library/logFunctions.c + library/signals.c MakeFileGeneric - config.cfg ftpCommandElaborate.c ftpData.c ftpServer.c todo.txt uFTP.c + uftpd.cfg - - @@ -112,10 +112,16 @@ + + + + + + @@ -139,8 +145,6 @@ - - @@ -175,10 +179,16 @@ + + + + + + diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 3fb12a8..168c334 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -7,7 +7,14 @@ + file:/home/ugo/NetBeansProjects/uFTP/library/configRead.h + file:/home/ugo/NetBeansProjects/uFTP/ftpData.c + file:/home/ugo/NetBeansProjects/uFTP/library/signals.c + file:/home/ugo/NetBeansProjects/uFTP/library/signals.h file:/home/ugo/NetBeansProjects/uFTP/ftpServer.c + file:/home/ugo/NetBeansProjects/uFTP/uFTP.c + file:/home/ugo/NetBeansProjects/uFTP/MakeFileGeneric + file:/home/ugo/NetBeansProjects/uFTP/ftpData.h file:/home/ugo/NetBeansProjects/uFTP/library/configRead.c diff --git a/uFTP.c b/uFTP.c index 457080a..614feca 100644 --- a/uFTP.c +++ b/uFTP.c @@ -26,13 +26,10 @@ #include #include #include "ftpServer.h" -#include int main(int argc, char** argv) { - signal(SIGPIPE, signal_callback_handler); - runFtpServer(); return (EXIT_SUCCESS); } diff --git a/config.cfg b/uftpd.cfg similarity index 100% rename from config.cfg rename to uftpd.cfg