Some refactoring

This commit is contained in:
kingk85
2023-06-20 13:06:57 -07:00
parent 06c0293e4f
commit c1e646df43
56 changed files with 134 additions and 156 deletions

0
Makefile Normal file → Executable file
View File

0
MakefileNetBeans Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

0
build/modules/connection.o.orig Normal file → Executable file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

0
build/modules/fileManagement.o.orig Normal file → Executable file
View File

Binary file not shown.

0
build/modules/ftpCommandElaborate.o.orig Normal file → Executable file
View File

Binary file not shown.

0
build/modules/ftpData.o.orig Normal file → Executable file
View File

Binary file not shown.

0
build/modules/ftpServer.o.orig Normal file → Executable file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

22
ftpCommandElaborate.c Normal file → Executable file
View File

@ -107,10 +107,8 @@ int parseCommandSite(ftpDataType * data, int socketId)
case FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG: case FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG:
default: default:
{
return FTP_COMMAND_PROCESSED_WRITE_ERROR; return FTP_COMMAND_PROCESSED_WRITE_ERROR;
}
break;
} }
} }
else else
@ -773,7 +771,7 @@ int parseCommandAppe(ftpDataType * data, int socketId)
int parseCommandCwd(ftpDataType * data, int socketId) int parseCommandCwd(ftpDataType * data, int socketId)
{ {
dynamicStringDataType absolutePathPrevious, ftpPathPrevious, theSafePath; dynamicStringDataType absolutePathPrevious, ftpPathPrevious, theSafePath;
int isSafePath; int isSafePath = 0;
int returnCode; int returnCode;
char *thePath; char *thePath;
@ -792,7 +790,7 @@ int parseCommandCwd(ftpDataType * data, int socketId)
//printf("\ncdw safe path: %s", theSafePath.text); //printf("\ncdw safe path: %s", theSafePath.text);
} }
if (isSafePath == 1) if (isSafePath)
{ {
//printf("\n The Path requested for CWD IS:%s", theSafePath.text); //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); 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) if (writtenSize <= 0)
{ {
printf("\nError %d while writing retr file.", writtenSize); printf("\nError %lld while writing retr file.", writtenSize);
fclose(retrFP); fclose(retrFP);
retrFP = NULL; retrFP = NULL;
return -1; return -1;
@ -1547,14 +1545,17 @@ int getFtpCommandArgWithOptions(char * theCommand, char *theCommandString, ftpCo
} }
} }
break; break;
default:
break;
} }
} }
if (argMainIndex > 0) if (argMainIndex > 0)
setDynamicStringDataType(&ftpCommand->commandArgs, argMain, argMainIndex, &*memoryTable); setDynamicStringDataType(&ftpCommand->commandArgs, argMain, argMainIndex, memoryTable);
if (argSecondaryIndex > 0) if (argSecondaryIndex > 0)
setDynamicStringDataType(&ftpCommand->commandOps, argSecondary, argSecondaryIndex, &*memoryTable); setDynamicStringDataType(&ftpCommand->commandOps, argSecondary, argSecondaryIndex, memoryTable);
return 1; return 1;
} }
@ -1573,7 +1574,7 @@ int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataTyp
char thePermissionString[MAXIMUM_FILENAME_LEN]; char thePermissionString[MAXIMUM_FILENAME_LEN];
char theLocalPath[MAXIMUM_FILENAME_LEN]; char theLocalPath[MAXIMUM_FILENAME_LEN];
char theFinalFilename[MAXIMUM_FILENAME_LEN]; char theFinalFilename[MAXIMUM_FILENAME_LEN];
int returnCodeSetPermissions, returnCodeSetOwnership; int returnCodeSetPermissions, returnCodeSetOwnership = 0;
memset(theLocalPath, 0, MAXIMUM_FILENAME_LEN); memset(theLocalPath, 0, MAXIMUM_FILENAME_LEN);
memset(thePermissionString, 0, MAXIMUM_FILENAME_LEN); memset(thePermissionString, 0, MAXIMUM_FILENAME_LEN);
@ -1611,6 +1612,9 @@ int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataTyp
else else
return FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG; return FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG;
break; break;
default:
break;
} }
permissionsCommandCursor++; permissionsCommandCursor++;

0
ftpCommandsElaborate.h Normal file → Executable file
View File

87
ftpData.c Normal file → Executable file
View File

@ -48,11 +48,9 @@ void cleanDynamicStringDataType(dynamicStringDataType *dynamicString, int init,
} }
else 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; dynamicString->textLen = 0;
@ -62,11 +60,11 @@ void cleanDynamicStringDataType(dynamicStringDataType *dynamicString, int init,
void cleanLoginData(loginDataType *loginData, int init, DYNMEM_MemoryTable_DataType **memoryTable) void cleanLoginData(loginDataType *loginData, int init, DYNMEM_MemoryTable_DataType **memoryTable)
{ {
loginData->userLoggedIn = 0; loginData->userLoggedIn = 0;
cleanDynamicStringDataType(&loginData->homePath, init, &*memoryTable); cleanDynamicStringDataType(&loginData->homePath, init, memoryTable);
cleanDynamicStringDataType(&loginData->ftpPath, init, &*memoryTable); cleanDynamicStringDataType(&loginData->ftpPath, init, memoryTable);
cleanDynamicStringDataType(&loginData->name, init, &*memoryTable); cleanDynamicStringDataType(&loginData->name, init, memoryTable);
cleanDynamicStringDataType(&loginData->password, init, &*memoryTable); cleanDynamicStringDataType(&loginData->password, init, memoryTable);
cleanDynamicStringDataType(&loginData->absolutePath, init, &*memoryTable); cleanDynamicStringDataType(&loginData->absolutePath, init, memoryTable);
} }
void setDynamicStringDataType(dynamicStringDataType *dynamicString, char *theString, int stringLen, DYNMEM_MemoryTable_DataType **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) if (dynamicString->textLen == 0)
{ {
//printf("\nMemory data address before memset call : %lld", memoryTable); //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); //printf("\nMemory data address after memset call : %lld", memoryTable);
memset(dynamicString->text, 0, stringLen + 1); memset(dynamicString->text, 0, stringLen + 1);
memcpy(dynamicString->text, theString, stringLen); memcpy(dynamicString->text, theString, stringLen);
@ -84,7 +82,7 @@ void setDynamicStringDataType(dynamicStringDataType *dynamicString, char *theStr
{ {
if(stringLen != dynamicString->textLen) 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); 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) int getSafePath(dynamicStringDataType *safePath, char *theDirectoryName, loginDataType *loginData, DYNMEM_MemoryTable_DataType **memoryTable)
{ {
#define STRING_SIZE 4096 #define STRING_SIZE 4096
int theLen, i; size_t theLen, i;
char * theDirectoryNamePointer; char * theDirectoryNamePointer;
theDirectoryNamePointer = theDirectoryName; theDirectoryNamePointer = theDirectoryName;
@ -163,20 +161,20 @@ int getSafePath(dynamicStringDataType *safePath, char *theDirectoryName, loginDa
theDirectoryNamePointer++; theDirectoryNamePointer++;
//printf("\nMemory data address 2nd call : %lld", memoryTable); //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); //printf("\nMemory data address 3rd call : %lld", memoryTable);
appendToDynamicStringDataType(safePath, theDirectoryNamePointer, strlen(theDirectoryNamePointer), &*memoryTable); appendToDynamicStringDataType(safePath, theDirectoryNamePointer, strlen(theDirectoryNamePointer), memoryTable);
} }
else 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] != '/') 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; return 1;
@ -187,7 +185,7 @@ void appendToDynamicStringDataType(dynamicStringDataType *dynamicString, char *t
//printf("\nRealloc dynamicString->text = %lld", dynamicString->text); //printf("\nRealloc dynamicString->text = %lld", dynamicString->text);
int theNewSize = dynamicString->textLen + stringLen; 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); memset(dynamicString->text+dynamicString->textLen, 0, stringLen+1);
memcpy(dynamicString->text+dynamicString->textLen, theString, stringLen); memcpy(dynamicString->text+dynamicString->textLen, theString, stringLen);
@ -227,7 +225,7 @@ int writeListDataInfoToSocket(ftpDataType *ftpData, int clientId, int *filesNumb
int i, x, returnCode; int i, x, returnCode;
int fileAndFoldersCount = 0; int fileAndFoldersCount = 0;
char **fileList = NULL; 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; *filesNumber = fileAndFoldersCount;
returnCode = socketWorkerPrintf(ftpData, clientId, "sds", "total ", fileAndFoldersCount ,"\r\n"); 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); //printf("\nFILE SIZE : %lld", data.fileSize);
data.owner = FILE_GetOwner(fileList[i], &*memoryTable); data.owner = FILE_GetOwner(fileList[i], memoryTable);
data.groupOwner = FILE_GetGroupOwner(fileList[i], &*memoryTable); data.groupOwner = FILE_GetGroupOwner(fileList[i], memoryTable);
data.fileNameWithPath = fileList[i]; data.fileNameWithPath = fileList[i];
data.fileNameNoPath = FILE_GetFilenameFromPath(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]); data.lastModifiedData = FILE_GetLastModifiedData(fileList[i]);
if (strlen(data.fileNameNoPath) > 0) 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); strcpy(data.finalStringPath, data.fileNameNoPath);
} }
@ -298,12 +296,12 @@ int writeListDataInfoToSocket(ftpDataType *ftpData, int clientId, int *filesNumb
{ {
int len = 0; int len = 0;
data.isLink = 1; 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) if ((len = readlink (fileList[i], data.linkPath, CLIENT_COMMAND_STRING_SIZE)) > 0)
{ {
data.linkPath[len] = 0; data.linkPath[len] = 0;
FILE_AppendToString(&data.finalStringPath, " -> ", &*memoryTable); FILE_AppendToString(&data.finalStringPath, " -> ", memoryTable);
FILE_AppendToString(&data.finalStringPath, data.linkPath, &*memoryTable); FILE_AppendToString(&data.finalStringPath, data.linkPath, memoryTable);
} }
} }
@ -359,28 +357,28 @@ int writeListDataInfoToSocket(ftpDataType *ftpData, int clientId, int *filesNumb
if (data.fileNameWithPath != NULL) if (data.fileNameWithPath != NULL)
DYNMEM_free(data.fileNameWithPath, &*memoryTable); DYNMEM_free(data.fileNameWithPath, memoryTable);
if (data.linkPath != NULL) if (data.linkPath != NULL)
DYNMEM_free(data.linkPath, &*memoryTable); DYNMEM_free(data.linkPath, memoryTable);
if (data.finalStringPath != NULL) if (data.finalStringPath != NULL)
DYNMEM_free(data.finalStringPath, &*memoryTable); DYNMEM_free(data.finalStringPath, memoryTable);
if (data.owner != NULL) if (data.owner != NULL)
DYNMEM_free(data.owner, &*memoryTable); DYNMEM_free(data.owner, memoryTable);
if (data.groupOwner != NULL) if (data.groupOwner != NULL)
DYNMEM_free(data.groupOwner, &*memoryTable); DYNMEM_free(data.groupOwner, memoryTable);
if (data.inodePermissionString != NULL) if (data.inodePermissionString != NULL)
DYNMEM_free(data.inodePermissionString, &*memoryTable); DYNMEM_free(data.inodePermissionString, memoryTable);
if (returnCode <= 0) if (returnCode <= 0)
{ {
for (x = i+1; x < fileAndFoldersCount; x++) for (x = i+1; x < fileAndFoldersCount; x++)
DYNMEM_free (fileList[x], &*memoryTable); DYNMEM_free (fileList[x], memoryTable);
DYNMEM_free (fileList, &*memoryTable); DYNMEM_free (fileList, memoryTable);
return -1; return -1;
} }
@ -388,7 +386,7 @@ int writeListDataInfoToSocket(ftpDataType *ftpData, int clientId, int *filesNumb
if (fileList != NULL) if (fileList != NULL)
{ {
DYNMEM_free (fileList, &*memoryTable); DYNMEM_free (fileList, memoryTable);
} }
return 1; return 1;
@ -421,7 +419,7 @@ void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo,
int i; int i;
int fileAndFoldersCount = 0; int fileAndFoldersCount = 0;
ftpListDataType data; ftpListDataType data;
FILE_GetDirectoryInodeList(thePath, &data.fileList, &fileAndFoldersCount, 0, &*memoryTable); FILE_GetDirectoryInodeList(thePath, &data.fileList, &fileAndFoldersCount, 0, memoryTable);
//printf("\nNUMBER OF FILES: %d", fileAndFoldersCount); //printf("\nNUMBER OF FILES: %d", fileAndFoldersCount);
//fflush(0); //fflush(0);
@ -469,16 +467,16 @@ void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo,
// printf("\nFILE SIZE : %lld", data.fileSize); // printf("\nFILE SIZE : %lld", data.fileSize);
data.owner = FILE_GetOwner(data.fileList[i], &*memoryTable); data.owner = FILE_GetOwner(data.fileList[i], memoryTable);
data.groupOwner = FILE_GetGroupOwner(data.fileList[i], &*memoryTable); data.groupOwner = FILE_GetGroupOwner(data.fileList[i], memoryTable);
data.fileNameWithPath = data.fileList[i]; data.fileNameWithPath = data.fileList[i];
data.fileNameNoPath = FILE_GetFilenameFromPath(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]); data.lastModifiedData = FILE_GetLastModifiedData(data.fileList[i]);
if (strlen(data.fileNameNoPath) > 0) 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); strcpy(data.finalStringPath, data.fileNameNoPath);
} }
@ -488,12 +486,12 @@ void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo,
{ {
int len = 0; int len = 0;
data.isLink = 1; 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) if ((len = readlink (data.fileList[i], data.linkPath, CLIENT_COMMAND_STRING_SIZE)) > 0)
{ {
data.linkPath[len] = 0; data.linkPath[len] = 0;
FILE_AppendToString(&data.finalStringPath, " -> ", &*memoryTable); FILE_AppendToString(&data.finalStringPath, " -> ", memoryTable);
FILE_AppendToString(&data.finalStringPath, data.linkPath, &*memoryTable); FILE_AppendToString(&data.finalStringPath, data.linkPath, memoryTable);
} }
} }
@ -663,10 +661,7 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization)
} }
#endif #endif
} }
else
{
}
if (pthread_mutex_init(&data->clients[clientId].writeMutex, NULL) != 0) if (pthread_mutex_init(&data->clients[clientId].writeMutex, NULL) != 0)
{ {

0
ftpData.h Normal file → Executable file
View File

2
ftpServer.c Normal file → Executable file
View File

@ -404,7 +404,7 @@ void *connectionWorkerHandle(void * socketId)
|| (compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "NLST", strlen("NLST")) == 1)) || (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) if (compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "LIST", strlen("LIST")) == 1)
theCommandType = COMMAND_TYPE_LIST; theCommandType = COMMAND_TYPE_LIST;

0
ftpServer.h Normal file → Executable file
View File

0
ftpSpecs.h Normal file → Executable file
View File

0
library/auth.c Normal file → Executable file
View File

0
library/auth.h Normal file → Executable file
View File

11
library/configRead.c Normal file → Executable file
View File

@ -85,12 +85,12 @@ void configurationRead(ftpParameters_DataType *ftpParameters, DYNMEM_MemoryTable
if (FILE_IsFile(LOCAL_CONFIGURATION_FILENAME) == 1) if (FILE_IsFile(LOCAL_CONFIGURATION_FILENAME) == 1)
{ {
printf("\nReading configuration from \n -> %s \n", LOCAL_CONFIGURATION_FILENAME); 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) else if (FILE_IsFile(DEFAULT_CONFIGURATION_FILENAME) == 1)
{ {
printf("\nReading configuration from \n -> %s\n", DEFAULT_CONFIGURATION_FILENAME); 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) if (returnCode == 1)
@ -190,7 +190,7 @@ static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *paramet
int i, state, nameIndex, valueIndex, allowSpacesInValue; int i, state, nameIndex, valueIndex, allowSpacesInValue;
char * theFileContent; char * theFileContent;
theFileSize = FILE_GetStringFromFile(path, &theFileContent, &*memoryTable); theFileSize = FILE_GetStringFromFile(path, &theFileContent, memoryTable);
char name[PARAMETER_SIZE_LIMIT]; char name[PARAMETER_SIZE_LIMIT];
char value[PARAMETER_SIZE_LIMIT]; char value[PARAMETER_SIZE_LIMIT];
@ -343,6 +343,9 @@ static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *paramet
parametersVector->PushBack(parametersVector, &parameter, sizeof(parameter_DataType)); parametersVector->PushBack(parametersVector, &parameter, sizeof(parameter_DataType));
} }
break; break;
default:
break;
} }
} }
@ -367,7 +370,7 @@ static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *paramet
if (theFileSize > 0) if (theFileSize > 0)
{ {
DYNMEM_free(theFileContent, &*memoryTable); DYNMEM_free(theFileContent, memoryTable);
} }
return 1; return 1;

0
library/configRead.h Normal file → Executable file
View File

4
library/connection.c Normal file → Executable file
View File

@ -44,7 +44,7 @@ int socketPrintf(ftpDataType * ftpData, int clientId, const char *__restrict __f
{ {
#define COMMAND_BUFFER 9600 #define COMMAND_BUFFER 9600
#define SOCKET_PRINTF_BUFFER 2048 #define SOCKET_PRINTF_BUFFER 2048
int bytesWritten = 0; ssize_t bytesWritten = 0;
char theBuffer[SOCKET_PRINTF_BUFFER]; char theBuffer[SOCKET_PRINTF_BUFFER];
char commandBuffer[COMMAND_BUFFER]; char commandBuffer[COMMAND_BUFFER];
int theStringSize = 0, theCommandSize = 0; int theStringSize = 0, theCommandSize = 0;
@ -235,7 +235,7 @@ int socketWorkerPrintf(ftpDataType * ftpData, int clientId, const char *__restri
if (theStringToWriteSize >= COMMAND_BUFFER) if (theStringToWriteSize >= COMMAND_BUFFER)
{ {
int theReturnCode = 0; ssize_t theReturnCode = 0;
if (ftpData->clients[clientId].dataChannelIsTls != 1) if (ftpData->clients[clientId].dataChannelIsTls != 1)
{ {
theReturnCode = write(ftpData->clients[clientId].workerData.socketConnection, writeBuffer, theStringToWriteSize); theReturnCode = write(ftpData->clients[clientId].workerData.socketConnection, writeBuffer, theStringToWriteSize);

0
library/connection.h Normal file → Executable file
View File

8
library/daemon.c Normal file → Executable file
View File

@ -33,6 +33,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <signal.h> #include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "fileManagement.h" #include "fileManagement.h"
@ -46,8 +48,8 @@ int isProcessAlreadyRunning(void)
{ {
int fd; int fd;
int returnCode; int returnCode;
char buf[30]; char buf[101];
memset(buf, 0,30); memset(buf, 0,101);
fd = open(LOCKFILE, O_RDWR|O_CREAT, LOCKMODE); fd = open(LOCKFILE, O_RDWR|O_CREAT, LOCKMODE);
if (fd < 0) if (fd < 0)
{ {
@ -71,7 +73,7 @@ int isProcessAlreadyRunning(void)
ftruncate(fd, 0); ftruncate(fd, 0);
returnCode = snprintf(buf, 100, "%ld", (long)getpid()); returnCode = snprintf(buf, 100, "%ld", (long)getpid());
returnCode = write(fd, buf, strlen(buf)+1); returnCode = write(fd, buf, strlen(buf)+1);
return(0); return 0;
} }
void daemonize(const char *cmd) void daemonize(const char *cmd)

0
library/daemon.h Normal file → Executable file
View File

8
library/dynamicMemory.c Normal file → Executable file
View File

@ -67,6 +67,8 @@ void *DYNMEM_malloc(size_t bytes, DYNMEM_MemoryTable_DataType **memoryListHead,
if(newItem == NULL) if(newItem == NULL)
{ {
report_error_q("Memory allocation error, no room for memory list item.",__FILE__,__LINE__, 0); 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)); DYNMEM_IncreaseMemoryCounter(bytes + sizeof(DYNMEM_MemoryTable_DataType));
@ -99,6 +101,8 @@ void *DYNMEM_malloc(size_t bytes, DYNMEM_MemoryTable_DataType **memoryListHead,
} }
else else
{ {
if(newItem)
free(newItem);
report_error_q("Memory allocation error, out of memory.", __FILE__,__LINE__,0); report_error_q("Memory allocation error, out of memory.", __FILE__,__LINE__,0);
return NULL; return NULL;
} }
@ -134,7 +138,9 @@ void *DYNMEM_realloc(void *theMemoryAddress, size_t bytes, DYNMEM_MemoryTable_Da
//strcpy(theData, "NOOOOOOOOOOOOOOOO"); //strcpy(theData, "NOOOOOOOOOOOOOOOO");
report_error_q("Unable to reallocate memory not previously allocated",__FILE__,__LINE__, 0); report_error_q("Unable to reallocate memory not previously allocated",__FILE__,__LINE__, 0);
free(newMemory);
// Report this as an error // Report this as an error
return NULL;
} }
if (found->size > bytes) if (found->size > bytes)
@ -187,6 +193,8 @@ void DYNMEM_free(void *f_address, DYNMEM_MemoryTable_DataType ** memoryListHead)
//strcpy(theData, "ciaociaociao"); //strcpy(theData, "ciaociaociao");
report_error_q("Unable to free memory not previously allocated",__FILE__,__LINE__, 1); report_error_q("Unable to free memory not previously allocated",__FILE__,__LINE__, 1);
// Report this as an error // Report this as an error
return;
} }
DYNMEM_DecreaseMemoryCounter(found->size + sizeof(DYNMEM_MemoryTable_DataType)); DYNMEM_DecreaseMemoryCounter(found->size + sizeof(DYNMEM_MemoryTable_DataType));

0
library/dynamicMemory.h Normal file → Executable file
View File

31
library/dynamicVectors.c Normal file → Executable file
View File

@ -38,12 +38,12 @@ void DYNV_VectorGeneric_Init(DYNV_VectorGenericDataType *TheVectorGeneric)
TheVectorGeneric->memoryTable = NULL; TheVectorGeneric->memoryTable = NULL;
//Functions Pointers //Functions Pointers
TheVectorGeneric->DeleteAt = (void *)DYNV_VectorGeneric_DeleteAt; TheVectorGeneric->DeleteAt = &DYNV_VectorGeneric_DeleteAt;
TheVectorGeneric->Destroy = (void *)DYNV_VectorGeneric_Destroy; TheVectorGeneric->Destroy = &DYNV_VectorGeneric_Destroy;
TheVectorGeneric->PopBack = (void *)DYNV_VectorGeneric_PopBack; TheVectorGeneric->PopBack = &DYNV_VectorGeneric_PopBack;
TheVectorGeneric->PushBack = (void *)DYNV_VectorGeneric_PushBack; TheVectorGeneric->PushBack = &DYNV_VectorGeneric_PushBack;
TheVectorGeneric->SoftDestroy = (void *)DYNV_VectorGeneric_SoftDestroy; TheVectorGeneric->SoftDestroy = &DYNV_VectorGeneric_SoftDestroy;
TheVectorGeneric->SoftPopBack = (void *)DYNV_VectorGeneric_SoftPopBack; TheVectorGeneric->SoftPopBack = &DYNV_VectorGeneric_SoftPopBack;
} }
void DYNV_VectorGeneric_InitWithSearchFunction(DYNV_VectorGenericDataType *TheVectorGeneric, int (*SearchFunction)(void *TheVectorGeneric, void * TheElementData)) 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->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); memcpy(TheVectorGeneric->Data[TheVectorGeneric->Size], TheElementData, TheElementSize);
TheVectorGeneric->ElementSize[TheVectorGeneric->Size] = TheElementSize; TheVectorGeneric->ElementSize[TheVectorGeneric->Size] = TheElementSize;
TheVectorGeneric->Size++; 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)) 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); DYNMEM_free(TheVector->Data[TheVector->Size-1], &TheVector->memoryTable);
if (TheVector->Size > 1) 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 //Permanent delete of the item At on the Heap
DeleteElementFunction((void *) TheVector->Data[index]); DeleteElementFunction(TheVector->Data[index]);
while (TheVector->Size > index) while (TheVector->Size > index)
{ {
@ -182,10 +182,10 @@ void DYNV_VectorString_Init(DYNV_VectorString_DataType *TheVector)
TheVector->memoryTable = NULL; TheVector->memoryTable = NULL;
//Functions Pointers //Functions Pointers
TheVector->DeleteAt = (void *)DYNV_VectorString_DeleteAt; TheVector->DeleteAt = &DYNV_VectorString_DeleteAt;
TheVector->Destroy = (void *)DYNV_VectorString_Destroy; TheVector->Destroy = &DYNV_VectorString_Destroy;
TheVector->PopBack = (void *)DYNV_VectorString_PopBack; TheVector->PopBack = &DYNV_VectorString_PopBack;
TheVector->PushBack = (void *)DYNV_VectorString_PushBack; TheVector->PushBack = &DYNV_VectorString_PushBack;
} }
void DYNV_VectorString_PushBack(DYNV_VectorString_DataType *TheVector, char * TheString, int StringLenght) 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) void DYNV_VectorString_DeleteAt(DYNV_VectorString_DataType *TheVector, int index)
{ {
int i;
DYNV_VectorString_DataType TempVector; DYNV_VectorString_DataType TempVector;
DYNV_VectorString_Init(&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]); 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); 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]); DYNV_VectorString_PushBack(TheVector, TempVector.Data[i], TempVector.ElementSize[i]);
} }

0
library/dynamicVectors.h Normal file → Executable file
View File

0
library/errorHandling.c Normal file → Executable file
View File

0
library/errorHandling.h Normal file → Executable file
View File

100
library/fileManagement.c Normal file → Executable file
View File

@ -192,7 +192,7 @@ void FILE_GetDirectoryInodeList(char * DirectoryInodeName, char *** InodeList, i
//Allocate the array for the 1st time //Allocate the array for the 1st time
if (*InodeList == NULL) 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 //Set the row to needed size
int ReallocSize = sizeof(char *) * (FileAndFolderIndex+1)+1; int ReallocSize = sizeof(char *) * (FileAndFolderIndex+1)+1;
(*InodeList) = (char ** ) DYNMEM_realloc((*InodeList), ReallocSize, &*memoryTable); (*InodeList) = (char ** ) DYNMEM_realloc((*InodeList), ReallocSize, memoryTable);
int nsize = strlen(dir->d_name) * sizeof(char) + strlen(DirectoryInodeName) * sizeof(char) + 2; size_t nsize = strlen(dir->d_name) * sizeof(char) + strlen(DirectoryInodeName) * sizeof(char) + 2;
//Allocate the path string size //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 ); strcpy((*InodeList)[FileAndFolderIndex], DirectoryInodeName );
strcat((*InodeList)[FileAndFolderIndex], "/" ); strcat((*InodeList)[FileAndFolderIndex], "/" );
strcat((*InodeList)[FileAndFolderIndex], dir->d_name ); 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); //printf("\nAdding single file to inode list: %s", DirectoryInodeName);
int ReallocSize = sizeof(char *) * (FileAndFolderIndex+1)+1; 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; 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 ); strcpy((*InodeList)[FileAndFolderIndex], DirectoryInodeName );
(*InodeList)[FileAndFolderIndex][strlen(DirectoryInodeName)] = '\0'; (*InodeList)[FileAndFolderIndex][strlen(DirectoryInodeName)] = '\0';
(*FilesandFolders)++; (*FilesandFolders)++;
@ -319,7 +319,7 @@ int FILE_GetStringFromFile(char * filename, char **file_content, DYNMEM_MemoryTa
file_size = FILE_GetFileSize(file); file_size = FILE_GetFileSize(file);
count = 0; 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) while ((c = fgetc(file)) != EOF)
{ {
@ -422,12 +422,10 @@ void FILE_ReadStringParameters(char * filename, DYNV_VectorGenericDataType *Para
//Get the parameter name //Get the parameter name
if ( FirstChar != '#' && FirstChar != 0 && SeparatorChar == 0 && BufferNameCursor < FILE_MAX_PAR_VAR_SIZE ) if ( FirstChar != '#' && FirstChar != 0 && SeparatorChar == 0 && BufferNameCursor < FILE_MAX_PAR_VAR_SIZE )
if(BufferNameCursor < FILE_MAX_PAR_VAR_SIZE)
TheParameter.Name[BufferNameCursor++] = (char) c; TheParameter.Name[BufferNameCursor++] = (char) c;
//Get the parameter value //Get the parameter value
if ( FirstChar != '#' && FirstChar != 0 && SeparatorChar != 0 && ParameterChar != 0 && BufferValueCursor < FILE_MAX_PAR_VAR_SIZE ) 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; 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 FILE_StringParametersLinearySearch(DYNV_VectorGenericDataType *TheVectorGeneric, void * name)
{ {
int i;
for(i=0; i<TheVectorGeneric->Size; i++) for(int i = 0; i < TheVectorGeneric->Size; i++)
{ {
if(strcmp(((FILE_StringParameter_DataType *)TheVectorGeneric->Data[i])->Name, (char *) name) == 0) if(strcmp(((FILE_StringParameter_DataType *)TheVectorGeneric->Data[i])->Name, (char *) name) == 0)
{ {
@ -504,11 +502,6 @@ int FILE_StringParametersBinarySearch(DYNV_VectorGenericDataType *TheVectorGener
middle = (littler + last)/2; 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;
@ -516,9 +509,8 @@ int FILE_StringParametersBinarySearch(DYNV_VectorGenericDataType *TheVectorGener
char * FILE_GetFilenameFromPath(char * FileName) char * FILE_GetFilenameFromPath(char * FileName)
{ {
int i = 0;
char * TheStr = FileName; char * TheStr = FileName;
for (i = 0; i< strlen(FileName); i++) for (int i = 0; i< strlen(FileName); i++)
{ {
if (FileName[i] == '/' || 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) { char * FILE_GetListPermissionsString(char *file, DYNMEM_MemoryTable_DataType ** memoryTable) {
struct stat st, stl; 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) if(stat(file, &st) == 0)
{ {
mode_t perm = st.st_mode; 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[9] = (perm & S_IXOTH) ? 'x' : '-';
modeval[10] = '\0'; 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 modeval[0] = 'l'; // is a link
} }
@ -566,12 +558,11 @@ int checkParentDirectoryPermissions(char *fileName, int uid, int gid)
char theFileName[4096]; char theFileName[4096];
memset(theFileName, 0, 4096); memset(theFileName, 0, 4096);
int i; size_t theFileNameLen = 0;
int theFileNameLen = 0; size_t theLen = strlen(fileName);
int theLen = strlen(fileName); size_t theParentLen = 0;
int theParentLen = 0;
for (i = 0; i < theLen; i++) for (size_t i = 0; i < theLen; i++)
{ {
if (fileName[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) if (i < 4096)
theFileName[theFileNameLen++] = fileName[i]; theFileName[theFileNameLen++] = fileName[i];
@ -599,14 +590,6 @@ int checkUserFilePermissions(char *fileName, int uid, int gid)
return FILE_PERMISSION_RW; return FILE_PERMISSION_RW;
} }
static int init = 0;
if (init == 0)
{
}
init = 1;
int filePermissions = FILE_PERMISSION_NO_RW; int filePermissions = FILE_PERMISSION_NO_RW;
int returnCode = 0; int returnCode = 0;
char *toReturn; char *toReturn;
@ -626,12 +609,12 @@ int checkUserFilePermissions(char *fileName, int uid, int gid)
else else
{ {
mode_t perm = info.st_mode; mode_t perm = info.st_mode;
if ((perm & S_IROTH)){ if (perm & S_IROTH){
//printf("\nfile can be readen"); //printf("\nfile can be readen");
filePermissions |= FILE_PERMISSION_R; filePermissions |= FILE_PERMISSION_R;
} }
if ((perm & S_IWOTH)){ if (perm & S_IWOTH){
//printf("\nfile can be written"); //printf("\nfile can be written");
filePermissions |= FILE_PERMISSION_W; filePermissions |= FILE_PERMISSION_W;
} }
@ -653,7 +636,7 @@ char * FILE_GetOwner(char *fileName, DYNMEM_MemoryTable_DataType **memoryTable)
if ( (pw = getpwuid(info.st_uid)) == NULL) if ( (pw = getpwuid(info.st_uid)) == NULL)
return 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); strcpy(toReturn, pw->pw_name);
return toReturn; return toReturn;
@ -670,7 +653,7 @@ char * FILE_GetGroupOwner(char *fileName, DYNMEM_MemoryTable_DataType **memoryTa
if ((gr = getgrgid(info.st_gid)) == NULL) if ((gr = getgrgid(info.st_gid)) == NULL)
return 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); strcpy(toReturn, gr->gr_name);
return toReturn; return toReturn;
@ -689,8 +672,8 @@ time_t FILE_GetLastModifiedData(char *path)
void FILE_AppendToString(char ** sourceString, char *theString, DYNMEM_MemoryTable_DataType ** memoryTable) void FILE_AppendToString(char ** sourceString, char *theString, DYNMEM_MemoryTable_DataType ** memoryTable)
{ {
int theNewSize = strlen(*sourceString) + strlen(theString); size_t theNewSize = strlen(*sourceString) + strlen(theString);
*sourceString = DYNMEM_realloc(*sourceString, theNewSize + 10, &*memoryTable); *sourceString = DYNMEM_realloc(*sourceString, theNewSize + 10, memoryTable);
strcat(*sourceString, theString); strcat(*sourceString, theString);
(*sourceString)[theNewSize] = '\0'; (*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) void FILE_DirectoryToParent(char ** sourceString, DYNMEM_MemoryTable_DataType ** memoryTable)
{ {
//printf("\n"); //printf("\n");
int i = 0, theLastSlash = -1, strLen = 0;
size_t theLastSlash = -1;
size_t strLen = 0;
strLen = strlen(*sourceString); strLen = strlen(*sourceString);
//printf("\nstrLen = %d", strLen); //printf("\nstrLen = %d", strLen);
for (i = 0; i < strLen; i++) for (size_t i = 0; i < strLen; i++)
{ {
//printf("%c", (*sourceString)[i]); //printf("%c", (*sourceString)[i]);
if ( (*sourceString)[i] == '/') if ( (*sourceString)[i] == '/')
@ -751,8 +736,8 @@ int FILE_doChownFromUidGidString ( const char *file_path,
{ {
uid_t uid; uid_t uid;
gid_t gid; gid_t gid;
struct passwd *pwd; const struct passwd *pwd;
struct group *grp; const struct group *grp;
pwd = getpwnam(user_name); pwd = getpwnam(user_name);
if (pwd == NULL) if (pwd == NULL)
@ -778,7 +763,7 @@ int FILE_doChownFromUidGidString ( const char *file_path,
uid_t FILE_getUID(const char *user_name) uid_t FILE_getUID(const char *user_name)
{ {
struct passwd *pwd; const struct passwd *pwd;
pwd = getpwnam(user_name); pwd = getpwnam(user_name);
if (pwd == NULL) if (pwd == NULL)
@ -804,7 +789,8 @@ gid_t FILE_getGID(const char *group_name)
void FILE_checkAllOpenedFD(void) void FILE_checkAllOpenedFD(void)
{ {
int openedFd = 0, i,ret; int openedFd = 0;
int ret;
struct rlimit rl; struct rlimit rl;
if (getrlimit(RLIMIT_NOFILE, &rl) < 0) if (getrlimit(RLIMIT_NOFILE, &rl) < 0)
@ -813,7 +799,7 @@ void FILE_checkAllOpenedFD(void)
if (rl.rlim_max == RLIM_INFINITY) if (rl.rlim_max == RLIM_INFINITY)
rl.rlim_max = 1024; 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); ret = FILE_fdIsValid(i);
//printf("\nret = %d", ret); //printf("\nret = %d", ret);
@ -830,24 +816,6 @@ void FILE_checkAllOpenedFD(void)
//printf("\n fd %d is dir", i); //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++; openedFd++;
} }

0
library/fileManagement.h Normal file → Executable file
View File

4
library/logFunctions.c Normal file → Executable file
View File

@ -31,8 +31,8 @@
void printTimeStamp(void) void printTimeStamp(void)
{ {
// time_t ltime; /* calendar time */ // time_t ltime; calendar time
// ltime=time(NULL); /* get current cal time */ // ltime=time(NULL); get current cal time
// printf("\n\n %s -->",asctime( localtime(&ltime) ) ); // printf("\n\n %s -->",asctime( localtime(&ltime) ) );
} }

0
library/logFunctions.h Normal file → Executable file
View File

0
library/openSsl.c Normal file → Executable file
View File

0
library/openSsl.h Normal file → Executable file
View File

3
library/signals.c Normal file → Executable file
View File

@ -58,14 +58,13 @@ static void ignore_sigpipe(void)
void onUftpClose(int sig) void onUftpClose(int sig)
{ {
printf("\nuFTP exit()\n"); printf("\nuFTP exit() sig %d\n", sig);
deallocateMemory(); deallocateMemory();
exit(0); exit(0);
} }
void signalHandlerInstall(void) void signalHandlerInstall(void)
{ {
//signal(SIGPIPE, signal_callback_handler);
signal(SIGINT,onUftpClose); signal(SIGINT,onUftpClose);
signal(SIGUSR2,SIG_IGN); signal(SIGUSR2,SIG_IGN);
signal(SIGPIPE,SIG_IGN); signal(SIGPIPE,SIG_IGN);

0
library/signals.h Normal file → Executable file
View File

0
testNotes.txt Normal file → Executable file
View File

0
todo.txt Normal file → Executable file
View File

2
uFTP.c Normal file → Executable file
View File

@ -32,5 +32,5 @@ int main(int argc, char** argv)
{ {
runFtpServer(); runFtpServer();
return (EXIT_SUCCESS); return EXIT_SUCCESS;
} }

2
uftpd.cfg Normal file → Executable file
View File

@ -13,7 +13,7 @@ FTP_PORT = 21
SINGLE_INSTANCE = true SINGLE_INSTANCE = true
#Allow only one server instance (true or false) #Allow only one server instance (true or false)
DAEMON_MODE = false DAEMON_MODE = true
#Run in background, daemon mode ok #Run in background, daemon mode ok
IDLE_MAX_TIMEOUT = 3600 IDLE_MAX_TIMEOUT = 3600