diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 diff --git a/MakefileNetBeans b/MakefileNetBeans old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/build/modules/auth.o b/build/modules/auth.o deleted file mode 100644 index 5bcf467..0000000 Binary files a/build/modules/auth.o and /dev/null differ diff --git a/build/modules/configRead.o b/build/modules/configRead.o deleted file mode 100644 index 35c865f..0000000 Binary files a/build/modules/configRead.o and /dev/null differ diff --git a/build/modules/connection.o b/build/modules/connection.o deleted file mode 100644 index b3904dc..0000000 Binary files a/build/modules/connection.o and /dev/null differ diff --git a/build/modules/connection.o.orig b/build/modules/connection.o.orig old mode 100644 new mode 100755 diff --git a/build/modules/daemon.o b/build/modules/daemon.o deleted file mode 100644 index b145dfd..0000000 Binary files a/build/modules/daemon.o and /dev/null differ diff --git a/build/modules/dynamicMemory.o b/build/modules/dynamicMemory.o deleted file mode 100644 index f894014..0000000 Binary files a/build/modules/dynamicMemory.o and /dev/null differ diff --git a/build/modules/dynamicVectors.o b/build/modules/dynamicVectors.o deleted file mode 100644 index 96f8fce..0000000 Binary files a/build/modules/dynamicVectors.o and /dev/null differ diff --git a/build/modules/errorHandling.o b/build/modules/errorHandling.o deleted file mode 100644 index a53a37e..0000000 Binary files a/build/modules/errorHandling.o and /dev/null differ diff --git a/build/modules/fileManagement.o b/build/modules/fileManagement.o deleted file mode 100644 index e2375fb..0000000 Binary files a/build/modules/fileManagement.o and /dev/null differ diff --git a/build/modules/fileManagement.o.orig b/build/modules/fileManagement.o.orig old mode 100644 new mode 100755 diff --git a/build/modules/ftpCommandElaborate.o b/build/modules/ftpCommandElaborate.o deleted file mode 100644 index 4d32a5d..0000000 Binary files a/build/modules/ftpCommandElaborate.o and /dev/null differ diff --git a/build/modules/ftpCommandElaborate.o.orig b/build/modules/ftpCommandElaborate.o.orig old mode 100644 new mode 100755 diff --git a/build/modules/ftpData.o b/build/modules/ftpData.o deleted file mode 100644 index edd6b4d..0000000 Binary files a/build/modules/ftpData.o and /dev/null differ diff --git a/build/modules/ftpData.o.orig b/build/modules/ftpData.o.orig old mode 100644 new mode 100755 diff --git a/build/modules/ftpServer.o b/build/modules/ftpServer.o deleted file mode 100644 index c660dc2..0000000 Binary files a/build/modules/ftpServer.o and /dev/null differ diff --git a/build/modules/ftpServer.o.orig b/build/modules/ftpServer.o.orig old mode 100644 new mode 100755 diff --git a/build/modules/logFunctions.o b/build/modules/logFunctions.o deleted file mode 100644 index e016981..0000000 Binary files a/build/modules/logFunctions.o and /dev/null differ diff --git a/build/modules/openSsl.o b/build/modules/openSsl.o deleted file mode 100644 index cf0ee71..0000000 Binary files a/build/modules/openSsl.o and /dev/null differ diff --git a/build/modules/signals.o b/build/modules/signals.o deleted file mode 100644 index c53769f..0000000 Binary files a/build/modules/signals.o and /dev/null differ diff --git a/build/uFTP b/build/uFTP deleted file mode 100755 index 2a12774..0000000 Binary files a/build/uFTP and /dev/null differ diff --git a/ftpCommandElaborate.c b/ftpCommandElaborate.c old mode 100644 new mode 100755 index 4449809..b2208ac --- a/ftpCommandElaborate.c +++ b/ftpCommandElaborate.c @@ -107,10 +107,8 @@ int parseCommandSite(ftpDataType * data, int socketId) case FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG: default: - { - return FTP_COMMAND_PROCESSED_WRITE_ERROR; - } - break; + return FTP_COMMAND_PROCESSED_WRITE_ERROR; + } } else @@ -773,7 +771,7 @@ int parseCommandAppe(ftpDataType * data, int socketId) int parseCommandCwd(ftpDataType * data, int socketId) { dynamicStringDataType absolutePathPrevious, ftpPathPrevious, theSafePath; - int isSafePath; + int isSafePath = 0; int returnCode; char *thePath; @@ -792,7 +790,7 @@ int parseCommandCwd(ftpDataType * data, int socketId) //printf("\ncdw safe path: %s", theSafePath.text); } - if (isSafePath == 1) + if (isSafePath) { //printf("\n The Path requested for CWD IS:%s", theSafePath.text); setDynamicStringDataType(&absolutePathPrevious, data->clients[socketId].login.absolutePath.text, data->clients[socketId].login.absolutePath.textLen, &data->clients[socketId].memoryTable); @@ -1436,7 +1434,7 @@ long long int writeRetrFile(ftpDataType * data, int theSocketId, long long int s if (writtenSize <= 0) { - printf("\nError %d while writing retr file.", writtenSize); + printf("\nError %lld while writing retr file.", writtenSize); fclose(retrFP); retrFP = NULL; return -1; @@ -1547,14 +1545,17 @@ int getFtpCommandArgWithOptions(char * theCommand, char *theCommandString, ftpCo } } break; + + default: + break; } } if (argMainIndex > 0) - setDynamicStringDataType(&ftpCommand->commandArgs, argMain, argMainIndex, &*memoryTable); + setDynamicStringDataType(&ftpCommand->commandArgs, argMain, argMainIndex, memoryTable); if (argSecondaryIndex > 0) - setDynamicStringDataType(&ftpCommand->commandOps, argSecondary, argSecondaryIndex, &*memoryTable); + setDynamicStringDataType(&ftpCommand->commandOps, argSecondary, argSecondaryIndex, memoryTable); return 1; } @@ -1573,7 +1574,7 @@ int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataTyp char thePermissionString[MAXIMUM_FILENAME_LEN]; char theLocalPath[MAXIMUM_FILENAME_LEN]; char theFinalFilename[MAXIMUM_FILENAME_LEN]; - int returnCodeSetPermissions, returnCodeSetOwnership; + int returnCodeSetPermissions, returnCodeSetOwnership = 0; memset(theLocalPath, 0, MAXIMUM_FILENAME_LEN); memset(thePermissionString, 0, MAXIMUM_FILENAME_LEN); @@ -1611,6 +1612,9 @@ int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataTyp else return FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG; break; + + default: + break; } permissionsCommandCursor++; diff --git a/ftpCommandsElaborate.h b/ftpCommandsElaborate.h old mode 100644 new mode 100755 diff --git a/ftpData.c b/ftpData.c old mode 100644 new mode 100755 index eaa63a0..9306094 --- a/ftpData.c +++ b/ftpData.c @@ -48,11 +48,9 @@ void cleanDynamicStringDataType(dynamicStringDataType *dynamicString, int init, } else { - if (dynamicString->textLen != 0) + if (dynamicString->textLen != 0 && dynamicString->text != 0) { - if (dynamicString->text != 0) { - DYNMEM_free(dynamicString->text, &*memoryTable); - } + DYNMEM_free(dynamicString->text, memoryTable); } dynamicString->textLen = 0; @@ -62,11 +60,11 @@ void cleanDynamicStringDataType(dynamicStringDataType *dynamicString, int init, void cleanLoginData(loginDataType *loginData, int init, DYNMEM_MemoryTable_DataType **memoryTable) { loginData->userLoggedIn = 0; - cleanDynamicStringDataType(&loginData->homePath, init, &*memoryTable); - cleanDynamicStringDataType(&loginData->ftpPath, init, &*memoryTable); - cleanDynamicStringDataType(&loginData->name, init, &*memoryTable); - cleanDynamicStringDataType(&loginData->password, init, &*memoryTable); - cleanDynamicStringDataType(&loginData->absolutePath, init, &*memoryTable); + cleanDynamicStringDataType(&loginData->homePath, init, memoryTable); + cleanDynamicStringDataType(&loginData->ftpPath, init, memoryTable); + cleanDynamicStringDataType(&loginData->name, init, memoryTable); + cleanDynamicStringDataType(&loginData->password, init, memoryTable); + cleanDynamicStringDataType(&loginData->absolutePath, init, memoryTable); } void setDynamicStringDataType(dynamicStringDataType *dynamicString, char *theString, int stringLen, DYNMEM_MemoryTable_DataType **memoryTable) @@ -74,7 +72,7 @@ void setDynamicStringDataType(dynamicStringDataType *dynamicString, char *theStr if (dynamicString->textLen == 0) { //printf("\nMemory data address before memset call : %lld", memoryTable); - dynamicString->text = (char *) DYNMEM_malloc (((sizeof(char) * stringLen) + 1), &*memoryTable, "setDynamicString"); + dynamicString->text = (char *) DYNMEM_malloc (((sizeof(char) * stringLen) + 1), memoryTable, "setDynamicString"); //printf("\nMemory data address after memset call : %lld", memoryTable); memset(dynamicString->text, 0, stringLen + 1); memcpy(dynamicString->text, theString, stringLen); @@ -84,7 +82,7 @@ void setDynamicStringDataType(dynamicStringDataType *dynamicString, char *theStr { if(stringLen != dynamicString->textLen) { - dynamicString->text = (char *) DYNMEM_realloc (dynamicString->text, ((sizeof(char) * stringLen) + 1), &*memoryTable); + dynamicString->text = (char *) DYNMEM_realloc (dynamicString->text, ((sizeof(char) * stringLen) + 1), memoryTable); } memset(dynamicString->text, 0, stringLen + 1); @@ -96,7 +94,7 @@ void setDynamicStringDataType(dynamicStringDataType *dynamicString, char *theStr int getSafePath(dynamicStringDataType *safePath, char *theDirectoryName, loginDataType *loginData, DYNMEM_MemoryTable_DataType **memoryTable) { #define STRING_SIZE 4096 - int theLen, i; + size_t theLen, i; char * theDirectoryNamePointer; theDirectoryNamePointer = theDirectoryName; @@ -163,20 +161,20 @@ int getSafePath(dynamicStringDataType *safePath, char *theDirectoryName, loginDa theDirectoryNamePointer++; //printf("\nMemory data address 2nd call : %lld", memoryTable); - setDynamicStringDataType(safePath, loginData->homePath.text, loginData->homePath.textLen, &*memoryTable); + setDynamicStringDataType(safePath, loginData->homePath.text, loginData->homePath.textLen, memoryTable); //printf("\nMemory data address 3rd call : %lld", memoryTable); - appendToDynamicStringDataType(safePath, theDirectoryNamePointer, strlen(theDirectoryNamePointer), &*memoryTable); + appendToDynamicStringDataType(safePath, theDirectoryNamePointer, strlen(theDirectoryNamePointer), memoryTable); } else { - setDynamicStringDataType(safePath, loginData->absolutePath.text, loginData->absolutePath.textLen, &*memoryTable); + setDynamicStringDataType(safePath, loginData->absolutePath.text, loginData->absolutePath.textLen, memoryTable); if (loginData->absolutePath.text[loginData->absolutePath.textLen-1] != '/') { - appendToDynamicStringDataType(safePath, "/", 1, &*memoryTable); + appendToDynamicStringDataType(safePath, "/", 1, memoryTable); } - appendToDynamicStringDataType(safePath, theDirectoryName, strlen(theDirectoryName), &*memoryTable); + appendToDynamicStringDataType(safePath, theDirectoryName, strlen(theDirectoryName), memoryTable); } return 1; @@ -187,7 +185,7 @@ void appendToDynamicStringDataType(dynamicStringDataType *dynamicString, char *t //printf("\nRealloc dynamicString->text = %lld", dynamicString->text); int theNewSize = dynamicString->textLen + stringLen; - dynamicString->text = DYNMEM_realloc(dynamicString->text, theNewSize + 1, &*memoryTable); + dynamicString->text = DYNMEM_realloc(dynamicString->text, theNewSize + 1, memoryTable); memset(dynamicString->text+dynamicString->textLen, 0, stringLen+1); memcpy(dynamicString->text+dynamicString->textLen, theString, stringLen); @@ -227,7 +225,7 @@ int writeListDataInfoToSocket(ftpDataType *ftpData, int clientId, int *filesNumb int i, x, returnCode; int fileAndFoldersCount = 0; char **fileList = NULL; - FILE_GetDirectoryInodeList(ftpData->clients[clientId].listPath.text, &fileList, &fileAndFoldersCount, 0, &*memoryTable); + FILE_GetDirectoryInodeList(ftpData->clients[clientId].listPath.text, &fileList, &fileAndFoldersCount, 0, memoryTable); *filesNumber = fileAndFoldersCount; returnCode = socketWorkerPrintf(ftpData, clientId, "sds", "total ", fileAndFoldersCount ,"\r\n"); @@ -279,16 +277,16 @@ int writeListDataInfoToSocket(ftpDataType *ftpData, int clientId, int *filesNumb //printf("\nFILE SIZE : %lld", data.fileSize); - data.owner = FILE_GetOwner(fileList[i], &*memoryTable); - data.groupOwner = FILE_GetGroupOwner(fileList[i], &*memoryTable); + data.owner = FILE_GetOwner(fileList[i], memoryTable); + data.groupOwner = FILE_GetGroupOwner(fileList[i], memoryTable); data.fileNameWithPath = fileList[i]; data.fileNameNoPath = FILE_GetFilenameFromPath(fileList[i]); - data.inodePermissionString = FILE_GetListPermissionsString(fileList[i], &*memoryTable); + data.inodePermissionString = FILE_GetListPermissionsString(fileList[i], memoryTable); data.lastModifiedData = FILE_GetLastModifiedData(fileList[i]); if (strlen(data.fileNameNoPath) > 0) { - data.finalStringPath = (char *) DYNMEM_malloc (strlen(data.fileNameNoPath)+1, &*memoryTable, "dataFinalPath"); + data.finalStringPath = (char *) DYNMEM_malloc (strlen(data.fileNameNoPath)+1, memoryTable, "dataFinalPath"); strcpy(data.finalStringPath, data.fileNameNoPath); } @@ -298,12 +296,12 @@ int writeListDataInfoToSocket(ftpDataType *ftpData, int clientId, int *filesNumb { int len = 0; data.isLink = 1; - data.linkPath = (char *) DYNMEM_malloc (CLIENT_COMMAND_STRING_SIZE*sizeof(char), &*memoryTable, "dataLinkPath"); + data.linkPath = (char *) DYNMEM_malloc (CLIENT_COMMAND_STRING_SIZE*sizeof(char), memoryTable, "dataLinkPath"); if ((len = readlink (fileList[i], data.linkPath, CLIENT_COMMAND_STRING_SIZE)) > 0) { data.linkPath[len] = 0; - FILE_AppendToString(&data.finalStringPath, " -> ", &*memoryTable); - FILE_AppendToString(&data.finalStringPath, data.linkPath, &*memoryTable); + FILE_AppendToString(&data.finalStringPath, " -> ", memoryTable); + FILE_AppendToString(&data.finalStringPath, data.linkPath, memoryTable); } } @@ -359,28 +357,28 @@ int writeListDataInfoToSocket(ftpDataType *ftpData, int clientId, int *filesNumb if (data.fileNameWithPath != NULL) - DYNMEM_free(data.fileNameWithPath, &*memoryTable); + DYNMEM_free(data.fileNameWithPath, memoryTable); if (data.linkPath != NULL) - DYNMEM_free(data.linkPath, &*memoryTable); + DYNMEM_free(data.linkPath, memoryTable); if (data.finalStringPath != NULL) - DYNMEM_free(data.finalStringPath, &*memoryTable); + DYNMEM_free(data.finalStringPath, memoryTable); if (data.owner != NULL) - DYNMEM_free(data.owner, &*memoryTable); + DYNMEM_free(data.owner, memoryTable); if (data.groupOwner != NULL) - DYNMEM_free(data.groupOwner, &*memoryTable); + DYNMEM_free(data.groupOwner, memoryTable); if (data.inodePermissionString != NULL) - DYNMEM_free(data.inodePermissionString, &*memoryTable); + DYNMEM_free(data.inodePermissionString, memoryTable); if (returnCode <= 0) { for (x = i+1; x < fileAndFoldersCount; x++) - DYNMEM_free (fileList[x], &*memoryTable); - DYNMEM_free (fileList, &*memoryTable); + DYNMEM_free (fileList[x], memoryTable); + DYNMEM_free (fileList, memoryTable); return -1; } @@ -388,7 +386,7 @@ int writeListDataInfoToSocket(ftpDataType *ftpData, int clientId, int *filesNumb if (fileList != NULL) { - DYNMEM_free (fileList, &*memoryTable); + DYNMEM_free (fileList, memoryTable); } return 1; @@ -421,7 +419,7 @@ void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo, int i; int fileAndFoldersCount = 0; ftpListDataType data; - FILE_GetDirectoryInodeList(thePath, &data.fileList, &fileAndFoldersCount, 0, &*memoryTable); + FILE_GetDirectoryInodeList(thePath, &data.fileList, &fileAndFoldersCount, 0, memoryTable); //printf("\nNUMBER OF FILES: %d", fileAndFoldersCount); //fflush(0); @@ -469,16 +467,16 @@ void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo, // printf("\nFILE SIZE : %lld", data.fileSize); - data.owner = FILE_GetOwner(data.fileList[i], &*memoryTable); - data.groupOwner = FILE_GetGroupOwner(data.fileList[i], &*memoryTable); + data.owner = FILE_GetOwner(data.fileList[i], memoryTable); + data.groupOwner = FILE_GetGroupOwner(data.fileList[i], memoryTable); data.fileNameWithPath = data.fileList[i]; data.fileNameNoPath = FILE_GetFilenameFromPath(data.fileList[i]); - data.inodePermissionString = FILE_GetListPermissionsString(data.fileList[i], &*memoryTable); + data.inodePermissionString = FILE_GetListPermissionsString(data.fileList[i], memoryTable); data.lastModifiedData = FILE_GetLastModifiedData(data.fileList[i]); if (strlen(data.fileNameNoPath) > 0) { - data.finalStringPath = (char *) DYNMEM_malloc (strlen(data.fileNameNoPath)+1, &*memoryTable, "FinalStringPath"); + data.finalStringPath = (char *) DYNMEM_malloc (strlen(data.fileNameNoPath)+1, memoryTable, "FinalStringPath"); strcpy(data.finalStringPath, data.fileNameNoPath); } @@ -488,12 +486,12 @@ void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo, { int len = 0; data.isLink = 1; - data.linkPath = (char *) DYNMEM_malloc (CLIENT_COMMAND_STRING_SIZE*sizeof(char), &*memoryTable, "data.linkPath"); + data.linkPath = (char *) DYNMEM_malloc (CLIENT_COMMAND_STRING_SIZE*sizeof(char), memoryTable, "data.linkPath"); if ((len = readlink (data.fileList[i], data.linkPath, CLIENT_COMMAND_STRING_SIZE)) > 0) { data.linkPath[len] = 0; - FILE_AppendToString(&data.finalStringPath, " -> ", &*memoryTable); - FILE_AppendToString(&data.finalStringPath, data.linkPath, &*memoryTable); + FILE_AppendToString(&data.finalStringPath, " -> ", memoryTable); + FILE_AppendToString(&data.finalStringPath, data.linkPath, memoryTable); } } @@ -663,10 +661,7 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization) } #endif } - else - { - } if (pthread_mutex_init(&data->clients[clientId].writeMutex, NULL) != 0) { diff --git a/ftpData.h b/ftpData.h old mode 100644 new mode 100755 diff --git a/ftpServer.c b/ftpServer.c old mode 100644 new mode 100755 index 418cc80..45409f7 --- a/ftpServer.c +++ b/ftpServer.c @@ -404,7 +404,7 @@ void *connectionWorkerHandle(void * socketId) || (compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "NLST", strlen("NLST")) == 1)) ) { - int theFiles = 0, theCommandType; + int theFiles = 0, theCommandType = 0; if (compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "LIST", strlen("LIST")) == 1) theCommandType = COMMAND_TYPE_LIST; diff --git a/ftpServer.h b/ftpServer.h old mode 100644 new mode 100755 diff --git a/ftpSpecs.h b/ftpSpecs.h old mode 100644 new mode 100755 diff --git a/library/auth.c b/library/auth.c old mode 100644 new mode 100755 diff --git a/library/auth.h b/library/auth.h old mode 100644 new mode 100755 diff --git a/library/configRead.c b/library/configRead.c old mode 100644 new mode 100755 index 851c0c3..62ad370 --- a/library/configRead.c +++ b/library/configRead.c @@ -85,12 +85,12 @@ void configurationRead(ftpParameters_DataType *ftpParameters, DYNMEM_MemoryTable if (FILE_IsFile(LOCAL_CONFIGURATION_FILENAME) == 1) { printf("\nReading configuration from \n -> %s \n", LOCAL_CONFIGURATION_FILENAME); - returnCode = readConfigurationFile(LOCAL_CONFIGURATION_FILENAME, &configParameters, &*memoryTable); + returnCode = readConfigurationFile(LOCAL_CONFIGURATION_FILENAME, &configParameters, memoryTable); } else if (FILE_IsFile(DEFAULT_CONFIGURATION_FILENAME) == 1) { printf("\nReading configuration from \n -> %s\n", DEFAULT_CONFIGURATION_FILENAME); - returnCode = readConfigurationFile(DEFAULT_CONFIGURATION_FILENAME, &configParameters, &*memoryTable); + returnCode = readConfigurationFile(DEFAULT_CONFIGURATION_FILENAME, &configParameters, memoryTable); } if (returnCode == 1) @@ -190,7 +190,7 @@ static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *paramet int i, state, nameIndex, valueIndex, allowSpacesInValue; char * theFileContent; - theFileSize = FILE_GetStringFromFile(path, &theFileContent, &*memoryTable); + theFileSize = FILE_GetStringFromFile(path, &theFileContent, memoryTable); char name[PARAMETER_SIZE_LIMIT]; char value[PARAMETER_SIZE_LIMIT]; @@ -343,6 +343,9 @@ static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *paramet parametersVector->PushBack(parametersVector, ¶meter, sizeof(parameter_DataType)); } break; + + default: + break; } } @@ -367,7 +370,7 @@ static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *paramet if (theFileSize > 0) { - DYNMEM_free(theFileContent, &*memoryTable); + DYNMEM_free(theFileContent, memoryTable); } return 1; diff --git a/library/configRead.h b/library/configRead.h old mode 100644 new mode 100755 diff --git a/library/connection.c b/library/connection.c old mode 100644 new mode 100755 index a299f0e..2aba7f0 --- a/library/connection.c +++ b/library/connection.c @@ -44,7 +44,7 @@ int socketPrintf(ftpDataType * ftpData, int clientId, const char *__restrict __f { #define COMMAND_BUFFER 9600 #define SOCKET_PRINTF_BUFFER 2048 - int bytesWritten = 0; + ssize_t bytesWritten = 0; char theBuffer[SOCKET_PRINTF_BUFFER]; char commandBuffer[COMMAND_BUFFER]; int theStringSize = 0, theCommandSize = 0; @@ -235,7 +235,7 @@ int socketWorkerPrintf(ftpDataType * ftpData, int clientId, const char *__restri if (theStringToWriteSize >= COMMAND_BUFFER) { - int theReturnCode = 0; + ssize_t theReturnCode = 0; if (ftpData->clients[clientId].dataChannelIsTls != 1) { theReturnCode = write(ftpData->clients[clientId].workerData.socketConnection, writeBuffer, theStringToWriteSize); diff --git a/library/connection.h b/library/connection.h old mode 100644 new mode 100755 diff --git a/library/daemon.c b/library/daemon.c old mode 100644 new mode 100755 index 7b65708..cc9c7e1 --- a/library/daemon.c +++ b/library/daemon.c @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include "fileManagement.h" @@ -46,8 +48,8 @@ int isProcessAlreadyRunning(void) { int fd; int returnCode; - char buf[30]; - memset(buf, 0,30); + char buf[101]; + memset(buf, 0,101); fd = open(LOCKFILE, O_RDWR|O_CREAT, LOCKMODE); if (fd < 0) { @@ -71,7 +73,7 @@ int isProcessAlreadyRunning(void) ftruncate(fd, 0); returnCode = snprintf(buf, 100, "%ld", (long)getpid()); returnCode = write(fd, buf, strlen(buf)+1); - return(0); + return 0; } void daemonize(const char *cmd) diff --git a/library/daemon.h b/library/daemon.h old mode 100644 new mode 100755 diff --git a/library/dynamicMemory.c b/library/dynamicMemory.c old mode 100644 new mode 100755 index 806fb74..00c6275 --- a/library/dynamicMemory.c +++ b/library/dynamicMemory.c @@ -67,6 +67,8 @@ void *DYNMEM_malloc(size_t bytes, DYNMEM_MemoryTable_DataType **memoryListHead, if(newItem == NULL) { report_error_q("Memory allocation error, no room for memory list item.",__FILE__,__LINE__, 0); + free(memory); + return NULL; } DYNMEM_IncreaseMemoryCounter(bytes + sizeof(DYNMEM_MemoryTable_DataType)); @@ -99,6 +101,8 @@ void *DYNMEM_malloc(size_t bytes, DYNMEM_MemoryTable_DataType **memoryListHead, } else { + if(newItem) + free(newItem); report_error_q("Memory allocation error, out of memory.", __FILE__,__LINE__,0); return NULL; } @@ -134,7 +138,9 @@ void *DYNMEM_realloc(void *theMemoryAddress, size_t bytes, DYNMEM_MemoryTable_Da //strcpy(theData, "NOOOOOOOOOOOOOOOO"); report_error_q("Unable to reallocate memory not previously allocated",__FILE__,__LINE__, 0); + free(newMemory); // Report this as an error + return NULL; } if (found->size > bytes) @@ -187,6 +193,8 @@ void DYNMEM_free(void *f_address, DYNMEM_MemoryTable_DataType ** memoryListHead) //strcpy(theData, "ciaociaociao"); report_error_q("Unable to free memory not previously allocated",__FILE__,__LINE__, 1); // Report this as an error + + return; } DYNMEM_DecreaseMemoryCounter(found->size + sizeof(DYNMEM_MemoryTable_DataType)); diff --git a/library/dynamicMemory.h b/library/dynamicMemory.h old mode 100644 new mode 100755 diff --git a/library/dynamicVectors.c b/library/dynamicVectors.c old mode 100644 new mode 100755 index d54bfa5..0d6a0bb --- a/library/dynamicVectors.c +++ b/library/dynamicVectors.c @@ -38,12 +38,12 @@ void DYNV_VectorGeneric_Init(DYNV_VectorGenericDataType *TheVectorGeneric) TheVectorGeneric->memoryTable = NULL; //Functions Pointers - TheVectorGeneric->DeleteAt = (void *)DYNV_VectorGeneric_DeleteAt; - TheVectorGeneric->Destroy = (void *)DYNV_VectorGeneric_Destroy; - TheVectorGeneric->PopBack = (void *)DYNV_VectorGeneric_PopBack; - TheVectorGeneric->PushBack = (void *)DYNV_VectorGeneric_PushBack; - TheVectorGeneric->SoftDestroy = (void *)DYNV_VectorGeneric_SoftDestroy; - TheVectorGeneric->SoftPopBack = (void *)DYNV_VectorGeneric_SoftPopBack; + TheVectorGeneric->DeleteAt = &DYNV_VectorGeneric_DeleteAt; + TheVectorGeneric->Destroy = &DYNV_VectorGeneric_Destroy; + TheVectorGeneric->PopBack = &DYNV_VectorGeneric_PopBack; + TheVectorGeneric->PushBack = &DYNV_VectorGeneric_PushBack; + TheVectorGeneric->SoftDestroy = &DYNV_VectorGeneric_SoftDestroy; + TheVectorGeneric->SoftPopBack = &DYNV_VectorGeneric_SoftPopBack; } void DYNV_VectorGeneric_InitWithSearchFunction(DYNV_VectorGenericDataType *TheVectorGeneric, int (*SearchFunction)(void *TheVectorGeneric, void * TheElementData)) @@ -72,7 +72,7 @@ void DYNV_VectorGeneric_PushBack(DYNV_VectorGenericDataType *TheVectorGeneric, v TheVectorGeneric->ElementSize = (int *) DYNMEM_malloc (sizeof(int), &TheVectorGeneric->memoryTable, "PushBack"); } - TheVectorGeneric->Data[TheVectorGeneric->Size] = (void *) DYNMEM_malloc(TheElementSize, &TheVectorGeneric->memoryTable, "pushback"); + TheVectorGeneric->Data[TheVectorGeneric->Size] = DYNMEM_malloc(TheElementSize, &TheVectorGeneric->memoryTable, "pushback"); memcpy(TheVectorGeneric->Data[TheVectorGeneric->Size], TheElementData, TheElementSize); TheVectorGeneric->ElementSize[TheVectorGeneric->Size] = TheElementSize; TheVectorGeneric->Size++; @@ -80,7 +80,7 @@ void DYNV_VectorGeneric_PushBack(DYNV_VectorGenericDataType *TheVectorGeneric, v void DYNV_VectorGeneric_PopBack(DYNV_VectorGenericDataType *TheVector, void (*DeleteElementFunction)(void *TheElementToDelete)) { - DeleteElementFunction((void *) TheVector->Data[TheVector->Size-1]); + DeleteElementFunction( TheVector->Data[TheVector->Size-1]); DYNMEM_free(TheVector->Data[TheVector->Size-1], &TheVector->memoryTable); if (TheVector->Size > 1) { @@ -159,7 +159,7 @@ void DYNV_VectorGeneric_DeleteAt(DYNV_VectorGenericDataType *TheVector, int inde } //Permanent delete of the item At on the Heap - DeleteElementFunction((void *) TheVector->Data[index]); + DeleteElementFunction(TheVector->Data[index]); while (TheVector->Size > index) { @@ -182,10 +182,10 @@ void DYNV_VectorString_Init(DYNV_VectorString_DataType *TheVector) TheVector->memoryTable = NULL; //Functions Pointers - TheVector->DeleteAt = (void *)DYNV_VectorString_DeleteAt; - TheVector->Destroy = (void *)DYNV_VectorString_Destroy; - TheVector->PopBack = (void *)DYNV_VectorString_PopBack; - TheVector->PushBack = (void *)DYNV_VectorString_PushBack; + TheVector->DeleteAt = &DYNV_VectorString_DeleteAt; + TheVector->Destroy = &DYNV_VectorString_Destroy; + TheVector->PopBack = &DYNV_VectorString_PopBack; + TheVector->PushBack = &DYNV_VectorString_PushBack; } void DYNV_VectorString_PushBack(DYNV_VectorString_DataType *TheVector, char * TheString, int StringLenght) @@ -264,11 +264,10 @@ void DYNV_VectorString_Destroy(DYNV_VectorString_DataType *TheVector) void DYNV_VectorString_DeleteAt(DYNV_VectorString_DataType *TheVector, int index) { - int i; DYNV_VectorString_DataType TempVector; DYNV_VectorString_Init(&TempVector); - for (i = index + 1; i < TheVector->Size; i++) + for (int i = index + 1; i < TheVector->Size; i++) { DYNV_VectorString_PushBack(&TempVector, TheVector->Data[i], TheVector->ElementSize[i]); } @@ -278,7 +277,7 @@ void DYNV_VectorString_DeleteAt(DYNV_VectorString_DataType *TheVector, int index DYNV_VectorString_PopBack(TheVector); } - for (i = 0; i < TempVector.Size; i++) + for (int i = 0; i < TempVector.Size; i++) { DYNV_VectorString_PushBack(TheVector, TempVector.Data[i], TempVector.ElementSize[i]); } diff --git a/library/dynamicVectors.h b/library/dynamicVectors.h old mode 100644 new mode 100755 diff --git a/library/errorHandling.c b/library/errorHandling.c old mode 100644 new mode 100755 diff --git a/library/errorHandling.h b/library/errorHandling.h old mode 100644 new mode 100755 diff --git a/library/fileManagement.c b/library/fileManagement.c old mode 100644 new mode 100755 index c557d7e..41cac09 --- a/library/fileManagement.c +++ b/library/fileManagement.c @@ -192,7 +192,7 @@ void FILE_GetDirectoryInodeList(char * DirectoryInodeName, char *** InodeList, i //Allocate the array for the 1st time if (*InodeList == NULL) { - (*InodeList) = (char **) DYNMEM_malloc(sizeof(char *) * (1), &*memoryTable, "InodeList"); + (*InodeList) = (char **) DYNMEM_malloc(sizeof(char *), memoryTable, "InodeList"); } @@ -217,10 +217,10 @@ void FILE_GetDirectoryInodeList(char * DirectoryInodeName, char *** InodeList, i //Set the row to needed size int ReallocSize = sizeof(char *) * (FileAndFolderIndex+1)+1; - (*InodeList) = (char ** ) DYNMEM_realloc((*InodeList), ReallocSize, &*memoryTable); - int nsize = strlen(dir->d_name) * sizeof(char) + strlen(DirectoryInodeName) * sizeof(char) + 2; + (*InodeList) = (char ** ) DYNMEM_realloc((*InodeList), ReallocSize, memoryTable); + size_t nsize = strlen(dir->d_name) * sizeof(char) + strlen(DirectoryInodeName) * sizeof(char) + 2; //Allocate the path string size - (*InodeList)[FileAndFolderIndex] = (char *) DYNMEM_malloc (nsize , &*memoryTable, "InodeList"); + (*InodeList)[FileAndFolderIndex] = (char *) DYNMEM_malloc (nsize , memoryTable, "InodeList"); strcpy((*InodeList)[FileAndFolderIndex], DirectoryInodeName ); strcat((*InodeList)[FileAndFolderIndex], "/" ); strcat((*InodeList)[FileAndFolderIndex], dir->d_name ); @@ -244,10 +244,10 @@ void FILE_GetDirectoryInodeList(char * DirectoryInodeName, char *** InodeList, i { //printf("\nAdding single file to inode list: %s", DirectoryInodeName); int ReallocSize = sizeof(char *) * (FileAndFolderIndex+1)+1; - (*InodeList) = (char ** ) DYNMEM_realloc((*InodeList), ReallocSize, &*memoryTable); + (*InodeList) = (char ** ) DYNMEM_realloc((*InodeList), ReallocSize, memoryTable); int nsize = strlen(DirectoryInodeName) * sizeof(char) + 2; - (*InodeList)[FileAndFolderIndex] = (char *) DYNMEM_malloc (nsize, &*memoryTable, "InodeList"); + (*InodeList)[FileAndFolderIndex] = (char *) DYNMEM_malloc (nsize, memoryTable, "InodeList"); strcpy((*InodeList)[FileAndFolderIndex], DirectoryInodeName ); (*InodeList)[FileAndFolderIndex][strlen(DirectoryInodeName)] = '\0'; (*FilesandFolders)++; @@ -319,7 +319,7 @@ int FILE_GetStringFromFile(char * filename, char **file_content, DYNMEM_MemoryTa file_size = FILE_GetFileSize(file); count = 0; - *file_content = (char *) DYNMEM_malloc((file_size * sizeof(char) + 100), &*memoryTable, "getstringfromfile"); + *file_content = (char *) DYNMEM_malloc((file_size * sizeof(char) + 100), memoryTable, "getstringfromfile"); while ((c = fgetc(file)) != EOF) { @@ -422,12 +422,10 @@ void FILE_ReadStringParameters(char * filename, DYNV_VectorGenericDataType *Para //Get the parameter name if ( FirstChar != '#' && FirstChar != 0 && SeparatorChar == 0 && BufferNameCursor < FILE_MAX_PAR_VAR_SIZE ) - if(BufferNameCursor < FILE_MAX_PAR_VAR_SIZE) TheParameter.Name[BufferNameCursor++] = (char) c; //Get the parameter value if ( FirstChar != '#' && FirstChar != 0 && SeparatorChar != 0 && ParameterChar != 0 && BufferValueCursor < FILE_MAX_PAR_VAR_SIZE ) - if(BufferValueCursor < FILE_MAX_PAR_VAR_SIZE) TheParameter.Value[BufferValueCursor++] = (char) c; } } @@ -455,8 +453,8 @@ void FILE_ReadStringParameters(char * filename, DYNV_VectorGenericDataType *Para int FILE_StringParametersLinearySearch(DYNV_VectorGenericDataType *TheVectorGeneric, void * name) { - int i; - for(i=0; iSize; i++) + + for(int i = 0; i < TheVectorGeneric->Size; i++) { if(strcmp(((FILE_StringParameter_DataType *)TheVectorGeneric->Data[i])->Name, (char *) name) == 0) { @@ -504,21 +502,15 @@ int FILE_StringParametersBinarySearch(DYNV_VectorGenericDataType *TheVectorGener middle = (littler + last)/2; } - if (littler > last) - { - //printf("Not found! %d is not present in the list.\n", Needle); - return -1; - } - return -1; + return -1; } char * FILE_GetFilenameFromPath(char * FileName) { - int i = 0; char * TheStr = FileName; - for (i = 0; i< strlen(FileName); i++) + for (int i = 0; i< strlen(FileName); i++) { if (FileName[i] == '/' || FileName[i] == '\\') { @@ -531,7 +523,7 @@ char * FILE_GetFilenameFromPath(char * FileName) char * FILE_GetListPermissionsString(char *file, DYNMEM_MemoryTable_DataType ** memoryTable) { struct stat st, stl; - char *modeval = DYNMEM_malloc(sizeof(char) * 10 + 1, &*memoryTable, "getperm"); + char *modeval = DYNMEM_malloc(sizeof(char) * 10 + 1, memoryTable, "getperm"); if(stat(file, &st) == 0) { mode_t perm = st.st_mode; @@ -547,9 +539,9 @@ char * FILE_GetListPermissionsString(char *file, DYNMEM_MemoryTable_DataType ** modeval[9] = (perm & S_IXOTH) ? 'x' : '-'; modeval[10] = '\0'; - if(lstat(file, &stl) == 0) + if(lstat(file, &stl) == 0 && + S_ISLNK(stl.st_mode)) { - if (S_ISLNK(stl.st_mode)) modeval[0] = 'l'; // is a link } @@ -566,12 +558,11 @@ int checkParentDirectoryPermissions(char *fileName, int uid, int gid) char theFileName[4096]; memset(theFileName, 0, 4096); - int i; - int theFileNameLen = 0; - int theLen = strlen(fileName); - int theParentLen = 0; + size_t theFileNameLen = 0; + size_t theLen = strlen(fileName); + size_t theParentLen = 0; - for (i = 0; i < theLen; i++) + for (size_t i = 0; i < theLen; i++) { if (fileName[i] == '/') { @@ -579,7 +570,7 @@ int checkParentDirectoryPermissions(char *fileName, int uid, int gid) } } - for (i = 0; i < theParentLen; i++) + for (size_t i = 0; i < theParentLen; i++) { if (i < 4096) theFileName[theFileNameLen++] = fileName[i]; @@ -599,14 +590,6 @@ int checkUserFilePermissions(char *fileName, int uid, int gid) return FILE_PERMISSION_RW; } - static int init = 0; - if (init == 0) - { - - } - - init = 1; - int filePermissions = FILE_PERMISSION_NO_RW; int returnCode = 0; char *toReturn; @@ -626,12 +609,12 @@ int checkUserFilePermissions(char *fileName, int uid, int gid) else { mode_t perm = info.st_mode; - if ((perm & S_IROTH)){ + if (perm & S_IROTH){ //printf("\nfile can be readen"); filePermissions |= FILE_PERMISSION_R; } - if ((perm & S_IWOTH)){ + if (perm & S_IWOTH){ //printf("\nfile can be written"); filePermissions |= FILE_PERMISSION_W; } @@ -653,7 +636,7 @@ char * FILE_GetOwner(char *fileName, DYNMEM_MemoryTable_DataType **memoryTable) if ( (pw = getpwuid(info.st_uid)) == NULL) return NULL; - toReturn = (char *) DYNMEM_malloc (strlen(pw->pw_name) + 1, &*memoryTable, "getowner"); + toReturn = (char *) DYNMEM_malloc (strlen(pw->pw_name) + 1, memoryTable, "getowner"); strcpy(toReturn, pw->pw_name); return toReturn; @@ -670,7 +653,7 @@ char * FILE_GetGroupOwner(char *fileName, DYNMEM_MemoryTable_DataType **memoryTa if ((gr = getgrgid(info.st_gid)) == NULL) return NULL; - toReturn = (char *) DYNMEM_malloc (strlen(gr->gr_name) + 1, &*memoryTable, "getowner"); + toReturn = (char *) DYNMEM_malloc (strlen(gr->gr_name) + 1, memoryTable, "getowner"); strcpy(toReturn, gr->gr_name); return toReturn; @@ -689,8 +672,8 @@ time_t FILE_GetLastModifiedData(char *path) void FILE_AppendToString(char ** sourceString, char *theString, DYNMEM_MemoryTable_DataType ** memoryTable) { - int theNewSize = strlen(*sourceString) + strlen(theString); - *sourceString = DYNMEM_realloc(*sourceString, theNewSize + 10, &*memoryTable); + size_t theNewSize = strlen(*sourceString) + strlen(theString); + *sourceString = DYNMEM_realloc(*sourceString, theNewSize + 10, memoryTable); strcat(*sourceString, theString); (*sourceString)[theNewSize] = '\0'; } @@ -698,12 +681,14 @@ void FILE_AppendToString(char ** sourceString, char *theString, DYNMEM_MemoryTab void FILE_DirectoryToParent(char ** sourceString, DYNMEM_MemoryTable_DataType ** memoryTable) { //printf("\n"); - int i = 0, theLastSlash = -1, strLen = 0; + + size_t theLastSlash = -1; + size_t strLen = 0; strLen = strlen(*sourceString); //printf("\nstrLen = %d", strLen); - for (i = 0; i < strLen; i++) + for (size_t i = 0; i < strLen; i++) { //printf("%c", (*sourceString)[i]); if ( (*sourceString)[i] == '/') @@ -751,8 +736,8 @@ int FILE_doChownFromUidGidString ( const char *file_path, { uid_t uid; gid_t gid; - struct passwd *pwd; - struct group *grp; + const struct passwd *pwd; + const struct group *grp; pwd = getpwnam(user_name); if (pwd == NULL) @@ -772,13 +757,13 @@ int FILE_doChownFromUidGidString ( const char *file_path, { return 0; } - + return 1; } uid_t FILE_getUID(const char *user_name) { - struct passwd *pwd; + const struct passwd *pwd; pwd = getpwnam(user_name); if (pwd == NULL) @@ -804,7 +789,8 @@ gid_t FILE_getGID(const char *group_name) void FILE_checkAllOpenedFD(void) { - int openedFd = 0, i,ret; + int openedFd = 0; + int ret; struct rlimit rl; if (getrlimit(RLIMIT_NOFILE, &rl) < 0) @@ -813,7 +799,7 @@ void FILE_checkAllOpenedFD(void) if (rl.rlim_max == RLIM_INFINITY) rl.rlim_max = 1024; - for (i = 0; i < rl.rlim_max; i++) + for (int i = 0; i < rl.rlim_max; i++) { ret = FILE_fdIsValid(i); //printf("\nret = %d", ret); @@ -830,24 +816,6 @@ void FILE_checkAllOpenedFD(void) //printf("\n fd %d is dir", i); } - /* - else if (S_ISSOCK(statbuf.st_mode)) - { - printf("\n fd %d is socket", fd); - } - else if (S_ISSOCK(statbuf.st_mode)) - { - printf("\n fd %d is socket", fd); - } - else if (S_ISSOCK(statbuf.st_mode)) - { - printf("\n fd %d is socket", fd); - } - else if (S_ISSOCK(statbuf.st_mode)) - { - printf("\n fd %d is socket", fd); - } - */ openedFd++; } diff --git a/library/fileManagement.h b/library/fileManagement.h old mode 100644 new mode 100755 diff --git a/library/logFunctions.c b/library/logFunctions.c old mode 100644 new mode 100755 index db521f0..54e755e --- a/library/logFunctions.c +++ b/library/logFunctions.c @@ -31,8 +31,8 @@ void printTimeStamp(void) { - // time_t ltime; /* calendar time */ - // ltime=time(NULL); /* get current cal time */ + // time_t ltime; calendar time + // ltime=time(NULL); get current cal time // printf("\n\n %s -->",asctime( localtime(<ime) ) ); } diff --git a/library/logFunctions.h b/library/logFunctions.h old mode 100644 new mode 100755 diff --git a/library/openSsl.c b/library/openSsl.c old mode 100644 new mode 100755 diff --git a/library/openSsl.h b/library/openSsl.h old mode 100644 new mode 100755 diff --git a/library/signals.c b/library/signals.c old mode 100644 new mode 100755 index 62b35ca..c37df03 --- a/library/signals.c +++ b/library/signals.c @@ -58,14 +58,13 @@ static void ignore_sigpipe(void) void onUftpClose(int sig) { - printf("\nuFTP exit()\n"); + printf("\nuFTP exit() sig %d\n", sig); deallocateMemory(); exit(0); } void signalHandlerInstall(void) { - //signal(SIGPIPE, signal_callback_handler); signal(SIGINT,onUftpClose); signal(SIGUSR2,SIG_IGN); signal(SIGPIPE,SIG_IGN); diff --git a/library/signals.h b/library/signals.h old mode 100644 new mode 100755 diff --git a/testNotes.txt b/testNotes.txt old mode 100644 new mode 100755 diff --git a/todo.txt b/todo.txt old mode 100644 new mode 100755 diff --git a/uFTP.c b/uFTP.c old mode 100644 new mode 100755 index bcaa03a..2551fe3 --- a/uFTP.c +++ b/uFTP.c @@ -32,5 +32,5 @@ int main(int argc, char** argv) { runFtpServer(); - return (EXIT_SUCCESS); + return EXIT_SUCCESS; } diff --git a/uftpd.cfg b/uftpd.cfg old mode 100644 new mode 100755 index 71881a4..b9c0413 --- a/uftpd.cfg +++ b/uftpd.cfg @@ -13,7 +13,7 @@ FTP_PORT = 21 SINGLE_INSTANCE = true #Allow only one server instance (true or false) -DAEMON_MODE = false +DAEMON_MODE = true #Run in background, daemon mode ok IDLE_MAX_TIMEOUT = 3600