mirror of
https://github.com/kingk85/uFTP.git
synced 2025-07-25 13:16:12 +03:00
Removed printf, increased write buffer on write function
This commit is contained in:
4
Makefile
4
Makefile
@ -19,8 +19,8 @@ ENABLE_LARGE_FILE_SUPPORT=-D LARGE_FILE_SUPPORT_ENABLED -D _LARGEFILE64_SOURCE
|
||||
|
||||
ENABLE_OPENSSL_SUPPORT=
|
||||
#TO ENABLE OPENSSL SUPPORT UNCOMMENT NEXT 2 LINES
|
||||
#ENABLE_OPENSSL_SUPPORT=-D OPENSSL_ENABLED
|
||||
#LIBS=-lpthread -lssl -lcrypto
|
||||
ENABLE_OPENSSL_SUPPORT=-D OPENSSL_ENABLED
|
||||
LIBS=-lpthread -lssl -lcrypto
|
||||
|
||||
CFLAGS=$(CFLAGSTEMP) $(ENABLE_LARGE_FILE_SUPPORT) $(ENABLE_OPENSSL_SUPPORT)
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
build/uFTP
BIN
build/uFTP
Binary file not shown.
@ -144,7 +144,7 @@ int parseCommandPass(ftpDataType * data, int socketId)
|
||||
{
|
||||
if (((loginFailsDataType *) data->loginFailsVector.Data[searchPosition])->failureNumbers >= data->ftpParameters.maximumUserAndPassowrdLoginTries)
|
||||
{
|
||||
printf("\n TOO MANY LOGIN FAILS! \n");
|
||||
//printf("\n TOO MANY LOGIN FAILS! \n");
|
||||
data->clients[socketId].closeTheClient = 1;
|
||||
returnCode = socketPrintf(data, socketId, "s", "430 Too many login failure detected, your ip will be blacklisted for 5 minutes\r\n");
|
||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
@ -246,13 +246,13 @@ int parseCommandAuth(ftpDataType * data, int socketId)
|
||||
|
||||
if (returnCodeTls <= 0)
|
||||
{
|
||||
printf("\nSSL NOT YET ACCEPTED: %d", returnCodeTls);
|
||||
//printf("\nSSL NOT YET ACCEPTED: %d", returnCodeTls);
|
||||
data->clients[socketId].tlsIsEnabled = 0;
|
||||
data->clients[socketId].tlsIsNegotiating = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\nSSL ACCEPTED");
|
||||
//printf("\nSSL ACCEPTED");
|
||||
data->clients[socketId].tlsIsEnabled = 1;
|
||||
data->clients[socketId].tlsIsNegotiating = 0;
|
||||
}
|
||||
@ -353,7 +353,7 @@ int parseCommandProt(ftpDataType * data, int socketId)
|
||||
if (theProtArg[0] == 'C' || theProtArg[0] == 'c')
|
||||
{
|
||||
//Clear
|
||||
printf("\nSet data channel to clear");
|
||||
//printf("\nSet data channel to clear");
|
||||
data->clients[socketId].dataChannelIsTls = 0;
|
||||
returnCode = socketPrintf(data, socketId, "scs", "200 PROT set to ", theProtArg[0], "\r\n");
|
||||
|
||||
@ -361,7 +361,7 @@ int parseCommandProt(ftpDataType * data, int socketId)
|
||||
else if (theProtArg[0] == 'P' || theProtArg[0] == 'p')
|
||||
{
|
||||
//Private
|
||||
printf("\nSet data channel to private");
|
||||
//printf("\nSet data channel to private");
|
||||
data->clients[socketId].dataChannelIsTls = 1;
|
||||
returnCode = socketPrintf(data, socketId, "scs", "200 PROT set to ", theProtArg[0], "\r\n");
|
||||
}
|
||||
@ -463,17 +463,17 @@ int parseCommandPasv(ftpDataType * data, int socketId)
|
||||
int returnCode;
|
||||
//printf("\n data->clients[%d].workerData.workerThread = %d",socketId, (int)data->clients[socketId].workerData.workerThread);
|
||||
|
||||
printf("\n data->clients[%d].workerData.threadHasBeenCreated = %d", socketId, data->clients[socketId].workerData.threadHasBeenCreated);
|
||||
//printf("\n data->clients[%d].workerData.threadHasBeenCreated = %d", socketId, data->clients[socketId].workerData.threadHasBeenCreated);
|
||||
if (data->clients[socketId].workerData.threadIsAlive == 1)
|
||||
{
|
||||
returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread);
|
||||
printf("\npasv pthread_cancel = %d", returnCode);
|
||||
//printf("\npasv pthread_cancel = %d", returnCode);
|
||||
}
|
||||
|
||||
if (data->clients[socketId].workerData.threadHasBeenCreated == 1)
|
||||
{
|
||||
returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn);
|
||||
printf("\nPasv join ok %d", returnCode);
|
||||
//printf("\nPasv join ok %d", returnCode);
|
||||
}
|
||||
|
||||
data->clients[socketId].workerData.passiveModeOn = 1;
|
||||
@ -482,7 +482,7 @@ int parseCommandPasv(ftpDataType * data, int socketId)
|
||||
|
||||
if (returnCode != 0)
|
||||
{
|
||||
printf("\nError in pthread_create %d", returnCode);
|
||||
//printf("\nError in pthread_create %d", returnCode);
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
}
|
||||
|
||||
@ -515,7 +515,7 @@ int parseCommandPort(ftpDataType * data, int socketId)
|
||||
|
||||
if (returnCode != 0)
|
||||
{
|
||||
printf("\nError in pthread_create %d", returnCode);
|
||||
//printf("\nError in pthread_create %d", returnCode);
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
}
|
||||
|
||||
@ -582,11 +582,11 @@ int parseCommandList(ftpDataType * data, int socketId)
|
||||
theNameToList = getFtpCommandArg("LIST", data->clients[socketId].theCommandReceived, 1);
|
||||
getFtpCommandArgWithOptions("LIST", data->clients[socketId].theCommandReceived, &data->clients[socketId].workerData.ftpCommand, &data->clients[socketId].workerData.memoryTable);
|
||||
|
||||
if (data->clients[socketId].workerData.ftpCommand.commandArgs.text != NULL)
|
||||
printf("\nLIST COMMAND ARG: %s", data->clients[socketId].workerData.ftpCommand.commandArgs.text);
|
||||
if (data->clients[socketId].workerData.ftpCommand.commandOps.text != NULL)
|
||||
printf("\nLIST COMMAND OPS: %s", data->clients[socketId].workerData.ftpCommand.commandOps.text);
|
||||
printf("\ntheNameToList: %s", theNameToList);
|
||||
// if (data->clients[socketId].workerData.ftpCommand.commandArgs.text != NULL)
|
||||
// printf("\nLIST COMMAND ARG: %s", data->clients[socketId].workerData.ftpCommand.commandArgs.text);
|
||||
//if (data->clients[socketId].workerData.ftpCommand.commandOps.text != NULL)
|
||||
// printf("\nLIST COMMAND OPS: %s", data->clients[socketId].workerData.ftpCommand.commandOps.text);
|
||||
// printf("\ntheNameToList: %s", theNameToList);
|
||||
|
||||
cleanDynamicStringDataType(&data->clients[socketId].workerData.ftpCommand.commandArgs, 0, &data->clients[socketId].workerData.memoryTable);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].workerData.ftpCommand.commandOps, 0, &data->clients[socketId].workerData.memoryTable);
|
||||
@ -619,9 +619,9 @@ int parseCommandNlst(ftpDataType * data, int socketId)
|
||||
theNameToNlist = getFtpCommandArg("NLIST", data->clients[socketId].theCommandReceived, 1);
|
||||
cleanDynamicStringDataType(&data->clients[socketId].nlistPath, 0, &data->clients[socketId].memoryTable);
|
||||
|
||||
printf("\nNLIST COMMAND ARG: %s", data->clients[socketId].workerData.ftpCommand.commandArgs.text);
|
||||
printf("\nNLIST COMMAND OPS: %s", data->clients[socketId].workerData.ftpCommand.commandOps.text);
|
||||
printf("\ntheNameToNlist: %s", theNameToNlist);
|
||||
// printf("\nNLIST COMMAND ARG: %s", data->clients[socketId].workerData.ftpCommand.commandArgs.text);
|
||||
//printf("\nNLIST COMMAND OPS: %s", data->clients[socketId].workerData.ftpCommand.commandOps.text);
|
||||
// printf("\ntheNameToNlist: %s", theNameToNlist);
|
||||
|
||||
if (strlen(theNameToNlist) > 0)
|
||||
{
|
||||
@ -991,7 +991,7 @@ int parseCommandQuit(ftpDataType * data, int socketId)
|
||||
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||
|
||||
data->clients[socketId].closeTheClient = 1;
|
||||
printf("\n Closing the client quit received");
|
||||
//printf("\n Closing the client quit received");
|
||||
return FTP_COMMAND_PROCESSED;
|
||||
}
|
||||
|
||||
@ -1470,7 +1470,7 @@ int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataTyp
|
||||
returnCode = strtol(thePermissionString, 0, 8);
|
||||
if ((returnCodeSetPermissions = chmod (theFinalFilename, returnCode)) < 0)
|
||||
{
|
||||
printf("\n---> ERROR WHILE SETTING FILE PERMISSION");
|
||||
//printf("\n---> ERROR WHILE SETTING FILE PERMISSION");
|
||||
}
|
||||
|
||||
if (returnCodeSetOwnership != 1 || returnCodeSetPermissions == -1)
|
||||
|
11
ftpData.c
11
ftpData.c
@ -471,11 +471,11 @@ void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo,
|
||||
}
|
||||
if (data.isDirectory == 0 && data.isFile == 0)
|
||||
{
|
||||
printf("\nNot a directory, not a file, broken link");
|
||||
//printf("\nNot a directory, not a file, broken link");
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("\nFILE SIZE : %lld", data.fileSize);
|
||||
// printf("\nFILE SIZE : %lld", data.fileSize);
|
||||
|
||||
data.owner = FILE_GetOwner(data.fileList[i], &*memoryTable);
|
||||
data.groupOwner = FILE_GetGroupOwner(data.fileList[i], &*memoryTable);
|
||||
@ -614,14 +614,14 @@ void resetWorkerData(ftpDataType *data, int clientId, int isInitialization)
|
||||
|
||||
if (pthread_mutex_init(&data->clients[clientId].workerData.conditionMutex, NULL) != 0)
|
||||
{
|
||||
printf("\ndata->clients[clientId].workerData.conditionMutex init failed\n");
|
||||
// printf("\ndata->clients[clientId].workerData.conditionMutex init failed\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
if (pthread_cond_init(&data->clients[clientId].workerData.conditionVariable, NULL) != 0)
|
||||
{
|
||||
printf("\ndata->clients[clientId].workerData.conditionVariable init failed\n");
|
||||
// printf("\ndata->clients[clientId].workerData.conditionVariable init failed\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@ -707,8 +707,7 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization)
|
||||
data->clients[clientId].ssl = SSL_new(data->serverCtx);
|
||||
#endif
|
||||
|
||||
|
||||
printf("\nclient memory table :%lld", data->clients[clientId].memoryTable);
|
||||
//printf("\nclient memory table :%lld", data->clients[clientId].memoryTable);
|
||||
}
|
||||
|
||||
int compareStringCaseInsensitive(char * stringIn, char * stringRef, int stringLenght)
|
||||
|
145
ftpServer.c
145
ftpServer.c
@ -58,43 +58,43 @@ void workerCleanup(void *socketId)
|
||||
int theSocketId = *(int *)socketId;
|
||||
int returnCode = 0;
|
||||
|
||||
printf("\nWorker %d cleanup", theSocketId);
|
||||
//printf("\nWorker %d cleanup", theSocketId);
|
||||
|
||||
#ifdef OPENSSL_ENABLED
|
||||
if (ftpData.clients[theSocketId].dataChannelIsTls == 1)
|
||||
{
|
||||
if(ftpData.clients[theSocketId].workerData.passiveModeOn == 1)
|
||||
{
|
||||
printf("\nSSL worker Shutdown 1");
|
||||
//printf("\nSSL worker Shutdown 1");
|
||||
returnCode = SSL_shutdown(ftpData.clients[theSocketId].workerData.serverSsl);
|
||||
printf("\nnSSL worker Shutdown 1 return code : %d", returnCode);
|
||||
//printf("\nnSSL worker Shutdown 1 return code : %d", returnCode);
|
||||
|
||||
if (returnCode < 0)
|
||||
{
|
||||
printf("SSL_shutdown failed return code %d", returnCode);
|
||||
//printf("SSL_shutdown failed return code %d", returnCode);
|
||||
}
|
||||
else if (returnCode == 0)
|
||||
{
|
||||
printf("\nSSL worker Shutdown 2");
|
||||
//printf("\nSSL worker Shutdown 2");
|
||||
returnCode = SSL_shutdown(ftpData.clients[theSocketId].workerData.serverSsl);
|
||||
printf("\nnSSL worker Shutdown 2 return code : %d", returnCode);
|
||||
//printf("\nnSSL worker Shutdown 2 return code : %d", returnCode);
|
||||
|
||||
if (returnCode <= 0)
|
||||
{
|
||||
printf("SSL_shutdown (2nd time) failed");
|
||||
//printf("SSL_shutdown (2nd time) failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ftpData.clients[theSocketId].workerData.activeModeOn == 1)
|
||||
{
|
||||
printf("\nSSL worker Shutdown 1");
|
||||
//printf("\nSSL worker Shutdown 1");
|
||||
returnCode = SSL_shutdown(ftpData.clients[theSocketId].workerData.clientSsl);
|
||||
printf(" return code : %d", returnCode);
|
||||
//printf(" return code : %d", returnCode);
|
||||
|
||||
if (returnCode < 0)
|
||||
{
|
||||
printf("SSL_shutdown failed return code %d", returnCode);
|
||||
//printf("SSL_shutdown failed return code %d", returnCode);
|
||||
}
|
||||
else if (returnCode == 0)
|
||||
{
|
||||
@ -102,7 +102,7 @@ void workerCleanup(void *socketId)
|
||||
|
||||
if (returnCode <= 0)
|
||||
{
|
||||
printf("SSL_shutdown (2nd time) failed");
|
||||
//printf("SSL_shutdown (2nd time) failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -114,12 +114,12 @@ void workerCleanup(void *socketId)
|
||||
returnCode = close(ftpData.clients[theSocketId].workerData.socketConnection);
|
||||
returnCode = close(ftpData.clients[theSocketId].workerData.passiveListeningSocket);
|
||||
resetWorkerData(&ftpData, theSocketId, 0);
|
||||
printf("\nWorker cleaned!");
|
||||
printf("\nWorker memory table :%lld", ftpData.clients[theSocketId].workerData.memoryTable);
|
||||
// printf("\nWorker cleaned!");
|
||||
//printf("\nWorker memory table :%lld", ftpData.clients[theSocketId].workerData.memoryTable);
|
||||
if (ftpData.clients[theSocketId].workerData.memoryTable != NULL)
|
||||
printf("\nMemory table element label: %s", ftpData.clients[theSocketId].workerData.memoryTable->theName);
|
||||
;//printf("\nMemory table element label: %s", ftpData.clients[theSocketId].workerData.memoryTable->theName);
|
||||
else
|
||||
printf("\nNo data to print");
|
||||
;//printf("\nNo data to print");
|
||||
}
|
||||
|
||||
void *connectionWorkerHandle(void * socketId)
|
||||
@ -130,7 +130,7 @@ void *connectionWorkerHandle(void * socketId)
|
||||
ftpData.clients[theSocketId].workerData.threadHasBeenCreated = 1;
|
||||
int returnCode;
|
||||
|
||||
printf("\nWORKER CREATED!");
|
||||
//printf("\nWORKER CREATED!");
|
||||
|
||||
//Passive data connection mode
|
||||
if (ftpData.clients[theSocketId].workerData.passiveModeOn == 1)
|
||||
@ -152,7 +152,7 @@ void *connectionWorkerHandle(void * socketId)
|
||||
if (ftpData.clients[theSocketId].workerData.passiveListeningSocket == -1)
|
||||
{
|
||||
ftpData.clients[theSocketId].closeTheClient = 1;
|
||||
printf("\n Closing the client 1");
|
||||
//printf("\n Closing the client 1");
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ void *connectionWorkerHandle(void * socketId)
|
||||
if (returnCode <= 0)
|
||||
{
|
||||
ftpData.clients[theSocketId].closeTheClient = 1;
|
||||
printf("\n Closing the client 2");
|
||||
//printf("\n Closing the client 2");
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ void *connectionWorkerHandle(void * socketId)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\nSSL ACCEPTED ON WORKER");
|
||||
//printf("\nSSL ACCEPTED ON WORKER");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -228,7 +228,7 @@ void *connectionWorkerHandle(void * socketId)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\nSSL ACCEPTED ON WORKER");
|
||||
//printf("\nSSL ACCEPTED ON WORKER");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -253,7 +253,7 @@ void *connectionWorkerHandle(void * socketId)
|
||||
}
|
||||
|
||||
|
||||
printf("\nftpData.clients[theSocketId].workerData.socketIsConnected = %d", ftpData.clients[theSocketId].workerData.socketIsConnected);
|
||||
//printf("\nftpData.clients[theSocketId].workerData.socketIsConnected = %d", ftpData.clients[theSocketId].workerData.socketIsConnected);
|
||||
|
||||
//Endless loop ftp process
|
||||
while (1)
|
||||
@ -262,7 +262,7 @@ void *connectionWorkerHandle(void * socketId)
|
||||
|
||||
if (ftpData.clients[theSocketId].workerData.socketIsConnected > 0)
|
||||
{
|
||||
printf("\nWorker %d is waiting for commands!", theSocketId);
|
||||
//printf("\nWorker %d is waiting for commands!", theSocketId);
|
||||
//Conditional lock on thread actions
|
||||
pthread_mutex_lock(&ftpData.clients[theSocketId].workerData.conditionMutex);
|
||||
while (ftpData.clients[theSocketId].workerData.commandReceived == 0)
|
||||
@ -271,7 +271,7 @@ void *connectionWorkerHandle(void * socketId)
|
||||
}
|
||||
pthread_mutex_unlock(&ftpData.clients[theSocketId].workerData.conditionMutex);
|
||||
|
||||
printf("\nWorker %d unlocked", theSocketId);
|
||||
//printf("\nWorker %d unlocked", theSocketId);
|
||||
|
||||
if (ftpData.clients[theSocketId].workerData.commandReceived == 1 &&
|
||||
compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "STOR", strlen("STOR")) == 1 &&
|
||||
@ -492,8 +492,12 @@ void runFtpServer(void)
|
||||
//Endless loop ftp process
|
||||
while (1)
|
||||
{
|
||||
/*
|
||||
|
||||
printf("\nUsed memory : %lld", DYNMEM_GetTotalMemory());
|
||||
|
||||
int memCount = 0;
|
||||
|
||||
for (memCount = 0; memCount < ftpData.ftpParameters.maxClients; memCount++)
|
||||
{
|
||||
if (ftpData.clients[memCount].memoryTable != NULL)
|
||||
@ -501,7 +505,6 @@ void runFtpServer(void)
|
||||
printf("\nftpData.clients[%d].memoryTable = %s", memCount, ftpData.clients[memCount].memoryTable->theName);
|
||||
}
|
||||
|
||||
|
||||
if (ftpData.clients[memCount].workerData.memoryTable != NULL)
|
||||
{
|
||||
printf("\nftpData.clients[%d].workerData.memoryTable = %s", memCount, ftpData.clients[memCount].workerData.memoryTable->theName);
|
||||
@ -512,6 +515,8 @@ void runFtpServer(void)
|
||||
printf("\nftpData.clients[%d].workerData.directoryInfo.memoryTable = %s", memCount, ftpData.clients[memCount].workerData.directoryInfo.memoryTable->theName);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/* waits for socket activity, if no activity then checks for client socket timeouts */
|
||||
if (selectWait(&ftpData) == 0)
|
||||
{
|
||||
@ -553,7 +558,7 @@ void runFtpServer(void)
|
||||
|
||||
if (returnCode <= 0)
|
||||
{
|
||||
printf("\nSSL NOT YET ACCEPTED: %d", returnCode);
|
||||
//printf("\nSSL NOT YET ACCEPTED: %d", returnCode);
|
||||
ftpData.clients[processingSock].tlsIsEnabled = 0;
|
||||
ftpData.clients[processingSock].tlsIsNegotiating = 1;
|
||||
|
||||
@ -566,7 +571,7 @@ void runFtpServer(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\nSSL ACCEPTED");
|
||||
//printf("\nSSL ACCEPTED");
|
||||
ftpData.clients[processingSock].tlsIsEnabled = 1;
|
||||
ftpData.clients[processingSock].tlsIsNegotiating = 0;
|
||||
}
|
||||
@ -593,7 +598,7 @@ void runFtpServer(void)
|
||||
fdRemove(&ftpData, processingSock);
|
||||
closeSocket(&ftpData, processingSock);
|
||||
ftpData.connectionData.maxSocketFD = getMaximumSocketFd(ftpData.connectionData.theMainSocket, &ftpData);
|
||||
printf("\nA client has been disconnected!\n");
|
||||
//printf("\nA client has been disconnected!\n");
|
||||
}
|
||||
|
||||
//Debug print errors
|
||||
@ -622,7 +627,7 @@ void runFtpServer(void)
|
||||
if (ftpData.clients[processingSock].buffer[i] == '\n')
|
||||
{
|
||||
ftpData.clients[processingSock].socketCommandReceived = 1;
|
||||
printf("\n Processing the command: %s", ftpData.clients[processingSock].theCommandReceived);
|
||||
//printf("\n Processing the command: %s", ftpData.clients[processingSock].theCommandReceived);
|
||||
commandProcessStatus = processCommand(processingSock);
|
||||
//Echo unrecognized commands
|
||||
if (commandProcessStatus == FTP_COMMAND_NOT_RECONIZED)
|
||||
@ -671,7 +676,6 @@ void runFtpServer(void)
|
||||
//Server Close
|
||||
shutdown(ftpData.connectionData.theMainSocket, SHUT_RDWR);
|
||||
close(ftpData.connectionData.theMainSocket);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -680,7 +684,7 @@ static int processCommand(int processingElement)
|
||||
int toReturn = 0;
|
||||
//printTimeStamp();
|
||||
//printf ("Command received from (%d): %s", processingElement, ftpData.clients[processingElement].theCommandReceived);
|
||||
|
||||
|
||||
cleanDynamicStringDataType(&ftpData.clients[processingElement].ftpCommand.commandArgs, 0, &ftpData.clients[processingElement].memoryTable);
|
||||
cleanDynamicStringDataType(&ftpData.clients[processingElement].ftpCommand.commandOps, 0, &ftpData.clients[processingElement].memoryTable);
|
||||
|
||||
@ -702,183 +706,178 @@ static int processCommand(int processingElement)
|
||||
//Process Command
|
||||
if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "USER", strlen("USER")) == 1)
|
||||
{
|
||||
printf("\nUSER COMMAND RECEIVED");
|
||||
//printf("\nUSER COMMAND RECEIVED");
|
||||
toReturn = parseCommandUser(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PASS", strlen("PASS")) == 1)
|
||||
{
|
||||
printf("\nPASS COMMAND RECEIVED");
|
||||
//printf("\nPASS COMMAND RECEIVED");
|
||||
toReturn = parseCommandPass(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "SITE", strlen("SITE")) == 1)
|
||||
{
|
||||
printf("\nSITE COMMAND RECEIVED");
|
||||
//printf("\nSITE COMMAND RECEIVED");
|
||||
toReturn = parseCommandSite(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "AUTH", strlen("AUTH")) == 1)
|
||||
{
|
||||
printf("\nAUTH COMMAND RECEIVED");
|
||||
//printf("\nAUTH COMMAND RECEIVED");
|
||||
toReturn = parseCommandAuth(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PROT", strlen("PROT")) == 1)
|
||||
{
|
||||
printf("\nPROT COMMAND RECEIVED");
|
||||
//printf("\nPROT COMMAND RECEIVED");
|
||||
toReturn = parseCommandProt(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PBSZ", strlen("PBSZ")) == 1)
|
||||
{
|
||||
printf("\nPBSZ COMMAND RECEIVED");
|
||||
//printf("\nPBSZ COMMAND RECEIVED");
|
||||
toReturn = parseCommandPbsz(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "CCC", strlen("CCC")) == 1)
|
||||
{
|
||||
printf("\nCCC COMMAND RECEIVED");
|
||||
//printf("\nCCC COMMAND RECEIVED");
|
||||
toReturn = parseCommandCcc(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PWD", strlen("PWD")) == 1)
|
||||
{
|
||||
printf("\nPWD COMMAND RECEIVED");
|
||||
//printf("\nPWD COMMAND RECEIVED");
|
||||
toReturn = parseCommandPwd(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "SYST", strlen("SYST")) == 1)
|
||||
{
|
||||
printf("\nSYST COMMAND RECEIVED");
|
||||
//printf("\nSYST COMMAND RECEIVED");
|
||||
toReturn = parseCommandSyst(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "FEAT", strlen("FEAT")) == 1)
|
||||
{
|
||||
printf("\nFEAT COMMAND RECEIVED");
|
||||
//printf("\nFEAT COMMAND RECEIVED");
|
||||
toReturn = parseCommandFeat(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "TYPE I", strlen("TYPE I")) == 1)
|
||||
{
|
||||
printf("\nTYPE I COMMAND RECEIVED");
|
||||
//printf("\nTYPE I COMMAND RECEIVED");
|
||||
toReturn = parseCommandTypeI(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "STRU F", strlen("STRU F")) == 1)
|
||||
{
|
||||
printf("\nTYPE I COMMAND RECEIVED");
|
||||
//printf("\nTYPE I COMMAND RECEIVED");
|
||||
toReturn = parseCommandStruF(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "MODE S", strlen("MODE S")) == 1)
|
||||
{
|
||||
printf("\nMODE S COMMAND RECEIVED");
|
||||
//printf("\nMODE S COMMAND RECEIVED");
|
||||
toReturn = parseCommandModeS(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "TYPE A", strlen("TYPE A")) == 1)
|
||||
{
|
||||
printf("\nTYPE A COMMAND RECEIVED");
|
||||
//printf("\nTYPE A COMMAND RECEIVED");
|
||||
toReturn = parseCommandTypeI(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PASV", strlen("PASV")) == 1)
|
||||
{
|
||||
printf("\nPASV COMMAND RECEIVED");
|
||||
//printf("\nPASV COMMAND RECEIVED");
|
||||
toReturn = parseCommandPasv(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PORT", strlen("PORT")) == 1)
|
||||
{
|
||||
printf("\nPORT COMMAND RECEIVED");
|
||||
//printf("\nPORT COMMAND RECEIVED");
|
||||
toReturn = parseCommandPort(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "LIST", strlen("LIST")) == 1)
|
||||
{
|
||||
printf("\nLIST COMMAND RECEIVED");
|
||||
//printf("\nLIST COMMAND RECEIVED");
|
||||
toReturn = parseCommandList(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "CWD", strlen("CWD")) == 1)
|
||||
{
|
||||
printf("\nCWD COMMAND RECEIVED");
|
||||
//printf("\nCWD COMMAND RECEIVED");
|
||||
toReturn = parseCommandCwd(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "CDUP", strlen("CDUP")) == 1)
|
||||
{
|
||||
printf("\nCDUP COMMAND RECEIVED");
|
||||
//printf("\nCDUP COMMAND RECEIVED");
|
||||
toReturn = parseCommandCdup(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "REST", strlen("REST")) == 1)
|
||||
{
|
||||
printf("\nREST COMMAND RECEIVED");
|
||||
//printf("\nREST COMMAND RECEIVED");
|
||||
toReturn = parseCommandRest(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "RETR", strlen("RETR")) == 1)
|
||||
{
|
||||
printf("\nRETR COMMAND RECEIVED");
|
||||
//printf("\nRETR COMMAND RECEIVED");
|
||||
toReturn = parseCommandRetr(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "STOR", strlen("STOR")) == 1)
|
||||
{
|
||||
printf("\nSTOR COMMAND RECEIVED");
|
||||
//printf("\nSTOR COMMAND RECEIVED");
|
||||
toReturn = parseCommandStor(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "MKD", strlen("MKD")) == 1)
|
||||
{
|
||||
printf("\nMKD command received");
|
||||
//printf("\nMKD command received");
|
||||
toReturn = parseCommandMkd(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "ABOR", strlen("ABOR")) == 1)
|
||||
{
|
||||
printf("\nABOR command received");
|
||||
//printf("\nABOR command received");
|
||||
toReturn = parseCommandAbor(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "DELE", strlen("DELE")) == 1)
|
||||
{
|
||||
printf("\nDELE command received");
|
||||
//printf("\nDELE command received");
|
||||
toReturn = parseCommandDele(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "OPTS", strlen("OPTS")) == 1)
|
||||
{
|
||||
printf("\nOPTS command received");
|
||||
//printf("\nOPTS command received");
|
||||
toReturn = parseCommandOpts(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "MTDM", strlen("MTDM")) == 1)
|
||||
{
|
||||
printf("\nMTDM command received");
|
||||
//printf("\nMTDM command received");
|
||||
//To implement
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "NLST", strlen("NLST")) == 1)
|
||||
{
|
||||
printf("\nNLST command received");
|
||||
// printf("\nNLST command received");
|
||||
toReturn = parseCommandNlst(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PORT", strlen("PORT")) == 1)
|
||||
{
|
||||
printf("\nPORT command received");
|
||||
//To implement
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "QUIT", strlen("QUIT")) == 1)
|
||||
{
|
||||
printf("\nQUIT command received");
|
||||
//printf("\nQUIT command received");
|
||||
toReturn = parseCommandQuit(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "RMD", strlen("RMD")) == 1)
|
||||
{
|
||||
printf("\nRMD command received");
|
||||
// printf("\nRMD command received");
|
||||
toReturn = parseCommandRmd(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "RNFR", strlen("RNFR")) == 1)
|
||||
{
|
||||
printf("\nRNFR command received");
|
||||
// printf("\nRNFR command received");
|
||||
toReturn = parseCommandRnfr(&ftpData, processingElement);
|
||||
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "RNTO", strlen("RNTO")) == 1)
|
||||
{
|
||||
printf("\nRNTO command received");
|
||||
// printf("\nRNTO command received");
|
||||
toReturn = parseCommandRnto(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "SIZE", strlen("SIZE")) == 1)
|
||||
{
|
||||
printf("\nSIZE command received");
|
||||
//printf("\nSIZE command received");
|
||||
toReturn = parseCommandSize(&ftpData, processingElement);
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "APPE", strlen("APPE")) == 1)
|
||||
{
|
||||
printf("\nAPPE command received");
|
||||
// printf("\nAPPE command received");
|
||||
//To implement
|
||||
}
|
||||
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "NOOP", strlen("NOOP")) == 1)
|
||||
{
|
||||
printf("\nNOOP command received");
|
||||
//printf("\nNOOP command received");
|
||||
toReturn = parseCommandNoop(&ftpData, processingElement);
|
||||
}
|
||||
else
|
||||
@ -894,14 +893,13 @@ static int processCommand(int processingElement)
|
||||
void deallocateMemory(void)
|
||||
{
|
||||
int i = 0;
|
||||
// printf("\n Deallocating the memory.. ");
|
||||
// printf("\n Deallocating the memory.. ");
|
||||
// printf("\nDYNMEM_freeAll called");
|
||||
// printf("\nElement size: %ld", ftpData.generalDynamicMemoryTable->size);
|
||||
// printf("\nElement address: %ld", (long int) ftpData.generalDynamicMemoryTable->address);
|
||||
// printf("\nElement nextElement: %ld",(long int) ftpData.generalDynamicMemoryTable->nextElement);
|
||||
// printf("\nElement previousElement: %ld",(long int) ftpData.generalDynamicMemoryTable->previousElement);
|
||||
|
||||
|
||||
for (i = 0; i < ftpData.ftpParameters.maxClients; i++)
|
||||
{
|
||||
DYNMEM_freeAll(&ftpData.clients[i].memoryTable);
|
||||
@ -912,8 +910,7 @@ void deallocateMemory(void)
|
||||
DYNMEM_freeAll(&ftpData.ftpParameters.usersVector.memoryTable);
|
||||
DYNMEM_freeAll(&ftpData.generalDynamicMemoryTable);
|
||||
|
||||
|
||||
printf("\n\nUsed memory at end: %lld", DYNMEM_GetTotalMemory());
|
||||
//printf("\n\nUsed memory at end: %lld", DYNMEM_GetTotalMemory());
|
||||
|
||||
//printf("\n ftpData.generalDynamicMemoryTable = %ld", ftpData.generalDynamicMemoryTable);
|
||||
#ifdef OPENSSL_ENABLED
|
||||
|
@ -27,7 +27,7 @@
|
||||
#define FTPSERVER_H
|
||||
|
||||
#define MAX_FTP_CLIENTS 10
|
||||
#define UFTP_SERVER_VERSION "2.0.0 beta"
|
||||
#define UFTP_SERVER_VERSION "v2.1.0 beta"
|
||||
|
||||
|
||||
void runFtpServer(void);
|
||||
|
@ -336,7 +336,7 @@ static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *paramet
|
||||
nameIndex = 0;
|
||||
valueIndex = 0;
|
||||
state = STATE_START;
|
||||
printf("\nParameter read: %s = %s", parameter.name, parameter.value);
|
||||
//printf("\nParameter read: %s = %s", parameter.name, parameter.value);
|
||||
parametersVector->PushBack(parametersVector, ¶meter, sizeof(parameter_DataType));
|
||||
}
|
||||
break;
|
||||
@ -358,7 +358,7 @@ static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *paramet
|
||||
memset(value, 0, PARAMETER_SIZE_LIMIT);
|
||||
nameIndex = 0;
|
||||
valueIndex = 0;
|
||||
printf("\nParameter read: %s = %s", parameter.name, parameter.value);
|
||||
//printf("\nParameter read: %s = %s", parameter.name, parameter.value);
|
||||
parametersVector->PushBack(parametersVector, ¶meter, sizeof(parameter_DataType));
|
||||
}
|
||||
|
||||
@ -395,42 +395,42 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
||||
userOwnerX[PARAMETER_SIZE_LIMIT],
|
||||
groupOwnerX[PARAMETER_SIZE_LIMIT];
|
||||
|
||||
printf("\nReading configuration settings..");
|
||||
//printf("\nReading configuration settings..");
|
||||
|
||||
searchIndex = searchParameter("MAXIMUM_ALLOWED_FTP_CONNECTION", parametersVector);
|
||||
if (searchIndex != -1)
|
||||
{
|
||||
ftpParameters->maxClients = atoi(((parameter_DataType *) parametersVector->Data[searchIndex])->value);
|
||||
printf("\nMAXIMUM_ALLOWED_FTP_CONNECTION: %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);
|
||||
//printf("\nMAXIMUM_ALLOWED_FTP_CONNECTION parameter not found in the configuration file, using the default value: %d", ftpParameters->maxClients);
|
||||
}
|
||||
|
||||
searchIndex = searchParameter("MAX_CONNECTION_NUMBER_PER_IP", parametersVector);
|
||||
if (searchIndex != -1)
|
||||
{
|
||||
ftpParameters->maximumConnectionsPerIp = atoi(((parameter_DataType *) parametersVector->Data[searchIndex])->value);
|
||||
printf("\nMAX_CONNECTION_NUMBER_PER_IP: %d", ftpParameters->maximumConnectionsPerIp);
|
||||
//printf("\nMAX_CONNECTION_NUMBER_PER_IP: %d", ftpParameters->maximumConnectionsPerIp);
|
||||
}
|
||||
else
|
||||
{
|
||||
ftpParameters->maximumConnectionsPerIp = 4;
|
||||
printf("\nMAX_CONNECTION_NUMBER_PER_IP parameter not found in the configuration file, using the default value: %d", ftpParameters->maximumConnectionsPerIp);
|
||||
//printf("\nMAX_CONNECTION_NUMBER_PER_IP parameter not found in the configuration file, using the default value: %d", ftpParameters->maximumConnectionsPerIp);
|
||||
}
|
||||
|
||||
searchIndex = searchParameter("MAX_CONNECTION_TRY_PER_IP", parametersVector);
|
||||
if (searchIndex != -1)
|
||||
{
|
||||
ftpParameters->maximumUserAndPassowrdLoginTries = atoi(((parameter_DataType *) parametersVector->Data[searchIndex])->value);
|
||||
printf("\nMAX_CONNECTION_TRY_PER_IP: %d", ftpParameters->maximumUserAndPassowrdLoginTries);
|
||||
//printf("\nMAX_CONNECTION_TRY_PER_IP: %d", ftpParameters->maximumUserAndPassowrdLoginTries);
|
||||
}
|
||||
else
|
||||
{
|
||||
ftpParameters->maximumUserAndPassowrdLoginTries = 3;
|
||||
printf("\nMAX_CONNECTION_TRY_PER_IP parameter not found in the configuration file, using the default value: %d", ftpParameters->maximumUserAndPassowrdLoginTries);
|
||||
//printf("\nMAX_CONNECTION_TRY_PER_IP parameter not found in the configuration file, using the default value: %d", ftpParameters->maximumUserAndPassowrdLoginTries);
|
||||
}
|
||||
|
||||
|
||||
@ -439,13 +439,12 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
||||
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);
|
||||
//printf("\nFTP_PORT parameter not found in the configuration file, using the default value: %d", ftpParameters->maxClients);
|
||||
}
|
||||
|
||||
|
||||
@ -456,11 +455,11 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
||||
if(compareStringCaseInsensitive(((parameter_DataType *) parametersVector->Data[searchIndex])->value, "true", strlen("true")) == 1)
|
||||
ftpParameters->daemonModeOn = 1;
|
||||
|
||||
printf("\nDAEMON_MODE value: %d", ftpParameters->daemonModeOn);
|
||||
//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);
|
||||
//printf("\nDAEMON_MODE parameter not found in the configuration file, using the default value: %d", ftpParameters->daemonModeOn);
|
||||
}
|
||||
|
||||
ftpParameters->singleInstanceModeOn = 0;
|
||||
@ -473,7 +472,7 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\nSINGLE_INSTANCE parameter not found in the configuration file, using the default value: %d", ftpParameters->singleInstanceModeOn);
|
||||
// printf("\nSINGLE_INSTANCE parameter not found in the configuration file, using the default value: %d", ftpParameters->singleInstanceModeOn);
|
||||
}
|
||||
|
||||
ftpParameters->maximumIdleInactivity = 3600;
|
||||
@ -481,11 +480,11 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
||||
if (searchIndex != -1)
|
||||
{
|
||||
ftpParameters->maximumIdleInactivity = atoi(((parameter_DataType *) parametersVector->Data[searchIndex])->value);
|
||||
printf("\nIDLE_MAX_TIMEOUT value: %d", ftpParameters->maximumIdleInactivity);
|
||||
//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);
|
||||
//printf("\nIDLE_MAX_TIMEOUT parameter not found in the configuration file, using the default value: %d", ftpParameters->maximumIdleInactivity);
|
||||
}
|
||||
|
||||
searchIndex = searchParameter("FTP_SERVER_IP", parametersVector);
|
||||
@ -495,10 +494,10 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
||||
&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]);
|
||||
//printf("\nFTP_SERVER_IP value: %d.%d.%d.%d", ftpParameters->ftpIpAddress[0],
|
||||
// ftpParameters->ftpIpAddress[1],
|
||||
// ftpParameters->ftpIpAddress[2],
|
||||
// ftpParameters->ftpIpAddress[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -506,7 +505,7 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
||||
ftpParameters->ftpIpAddress[1] = 0;
|
||||
ftpParameters->ftpIpAddress[2] = 0;
|
||||
ftpParameters->ftpIpAddress[3] = 1;
|
||||
printf("\nFTP_SERVER_IP parameter not found in the configuration file, listening on all available networks");
|
||||
//printf("\nFTP_SERVER_IP parameter not found in the configuration file, listening on all available networks");
|
||||
}
|
||||
|
||||
|
||||
@ -514,24 +513,24 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
||||
if (searchIndex != -1)
|
||||
{
|
||||
strcpy(ftpParameters->certificatePath, ((parameter_DataType *) parametersVector->Data[searchIndex])->value);
|
||||
printf("\nCERTIFICATE_PATH: %s", ftpParameters->certificatePath);
|
||||
// printf("\nCERTIFICATE_PATH: %s", ftpParameters->certificatePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(ftpParameters->certificatePath, "cert.pem");
|
||||
printf("\nCERTIFICATE_PATH parameter not found in the configuration file, using the default value: %s", ftpParameters->certificatePath);
|
||||
// printf("\nCERTIFICATE_PATH parameter not found in the configuration file, using the default value: %s", ftpParameters->certificatePath);
|
||||
}
|
||||
|
||||
searchIndex = searchParameter("PRIVATE_CERTIFICATE_PATH", parametersVector);
|
||||
if (searchIndex != -1)
|
||||
{
|
||||
strcpy(ftpParameters->privateCertificatePath, ((parameter_DataType *) parametersVector->Data[searchIndex])->value);
|
||||
printf("\nPRIVATE_CERTIFICATE_PATH: %s", ftpParameters->certificatePath);
|
||||
//printf("\nPRIVATE_CERTIFICATE_PATH: %s", ftpParameters->certificatePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(ftpParameters->privateCertificatePath, "key.pem");
|
||||
printf("\nPRIVATE_CERTIFICATE_PATH parameter not found in the configuration file, using the default value: %s", ftpParameters->privateCertificatePath);
|
||||
//printf("\nPRIVATE_CERTIFICATE_PATH parameter not found in the configuration file, using the default value: %s", ftpParameters->privateCertificatePath);
|
||||
}
|
||||
|
||||
/* USER SETTINGS */
|
||||
@ -571,7 +570,7 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
||||
searchPasswordIndex == -1 ||
|
||||
searchHomeIndex == -1)
|
||||
{
|
||||
printf("\n BREAK ");
|
||||
//printf("\n BREAK ");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -612,16 +611,16 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
||||
userData.ownerShip.groupOwnerString = NULL;
|
||||
userData.ownerShip.userOwnerString = NULL;
|
||||
}
|
||||
|
||||
printf("\n\nUser parameter found");
|
||||
printf("\nName: %s", userData.name);
|
||||
printf("\nPassword: %s", userData.password);
|
||||
printf("\nHomePath: %s", userData.homePath);
|
||||
printf("\ngroupOwnerStr: %s", userData.ownerShip.groupOwnerString);
|
||||
printf("\nuserOwnerStr: %s", userData.ownerShip.userOwnerString);
|
||||
printf("\nuserData.gid = %d", userData.ownerShip.gid);
|
||||
printf("\nuserData.uid = %d", userData.ownerShip.uid);
|
||||
printf("\nuserData.ownerShipSet = %d", userData.ownerShip.ownerShipSet);
|
||||
//
|
||||
// printf("\n\nUser parameter found");
|
||||
// printf("\nName: %s", userData.name);
|
||||
// printf("\nPassword: %s", userData.password);
|
||||
// printf("\nHomePath: %s", userData.homePath);
|
||||
// printf("\ngroupOwnerStr: %s", userData.ownerShip.groupOwnerString);
|
||||
// printf("\nuserOwnerStr: %s", userData.ownerShip.userOwnerString);
|
||||
// printf("\nuserData.gid = %d", userData.ownerShip.gid);
|
||||
// printf("\nuserData.uid = %d", userData.ownerShip.uid);
|
||||
// printf("\nuserData.ownerShipSet = %d", userData.ownerShip.ownerShipSet);
|
||||
ftpParameters->usersVector.PushBack(&ftpParameters->usersVector, &userData, sizeof(usersParameters_DataType));
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ int socketPrintf(ftpDataType * ftpData, int clientId, const char *__restrict __f
|
||||
int theStringSize = 0, theCommandSize = 0;
|
||||
memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER);
|
||||
memset(&commandBuffer, 0, COMMAND_BUFFER);
|
||||
printf("\nWriting to socket id %d, TLS %d: ", clientId, ftpData->clients[clientId].tlsIsEnabled);
|
||||
//printf("\nWriting to socket id %d, TLS %d: ", clientId, ftpData->clients[clientId].tlsIsEnabled);
|
||||
|
||||
pthread_mutex_lock(&ftpData->clients[clientId].writeMutex);
|
||||
|
||||
@ -140,7 +140,7 @@ int socketPrintf(ftpDataType * ftpData, int clientId, const char *__restrict __f
|
||||
#endif
|
||||
}
|
||||
|
||||
printf("\n%s", commandBuffer);
|
||||
//printf("\n%s", commandBuffer);
|
||||
|
||||
pthread_mutex_unlock(&ftpData->clients[clientId].writeMutex);
|
||||
|
||||
@ -149,26 +149,31 @@ int socketPrintf(ftpDataType * ftpData, int clientId, const char *__restrict __f
|
||||
|
||||
int socketWorkerPrintf(ftpDataType * ftpData, int clientId, const char *__restrict __fmt, ...)
|
||||
{
|
||||
#define SOCKET_PRINTF_BUFFER 2048
|
||||
#define COMMAND_BUFFER 9600
|
||||
#define SOCKET_PRINTF_BUFFER2 4096
|
||||
|
||||
int bytesWritten = 0;
|
||||
char theBuffer[SOCKET_PRINTF_BUFFER];
|
||||
int bytesWritten = 0, i = 0, theStringToWriteSize = 0;
|
||||
char theBuffer[SOCKET_PRINTF_BUFFER2];
|
||||
char writeBuffer[COMMAND_BUFFER];
|
||||
int theStringSize = 0;
|
||||
memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER);
|
||||
//printf("\nWriting to worker socket id %dd, TLS %d: ", clientId, ftpData->clients[clientId].dataChannelIsTls);
|
||||
|
||||
memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER2);
|
||||
memset(&writeBuffer, 0, COMMAND_BUFFER);
|
||||
|
||||
va_list args;
|
||||
va_start(args, __fmt);
|
||||
while (*__fmt != '\0')
|
||||
{
|
||||
theStringSize = 0;
|
||||
|
||||
switch(*__fmt)
|
||||
{
|
||||
case 'd':
|
||||
case 'D':
|
||||
{
|
||||
int theInteger = va_arg(args, int);
|
||||
memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER);
|
||||
theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER, "%d", theInteger);
|
||||
memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER2);
|
||||
theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER2, "%d", theInteger);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -176,8 +181,8 @@ int socketWorkerPrintf(ftpDataType * ftpData, int clientId, const char *__restri
|
||||
case 'C':
|
||||
{
|
||||
int theCharInteger = va_arg(args, int);
|
||||
memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER);
|
||||
theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER, "%c", theCharInteger);
|
||||
memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER2);
|
||||
theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER2, "%c", theCharInteger);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -185,8 +190,8 @@ int socketWorkerPrintf(ftpDataType * ftpData, int clientId, const char *__restri
|
||||
case 'F':
|
||||
{
|
||||
float theDouble = va_arg(args, double);
|
||||
memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER);
|
||||
theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER, "%f", theDouble);
|
||||
memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER2);
|
||||
theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER2, "%f", theDouble);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -194,8 +199,8 @@ int socketWorkerPrintf(ftpDataType * ftpData, int clientId, const char *__restri
|
||||
case 'S':
|
||||
{
|
||||
char * theString = va_arg(args, char *);
|
||||
memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER);
|
||||
theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER, "%s", theString);
|
||||
memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER2);
|
||||
theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER2, "%s", theString);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -203,8 +208,8 @@ int socketWorkerPrintf(ftpDataType * ftpData, int clientId, const char *__restri
|
||||
case 'L':
|
||||
{
|
||||
long long int theLongLongInt = va_arg(args, long long int);
|
||||
memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER);
|
||||
theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER, "%lld", theLongLongInt);
|
||||
memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER2);
|
||||
theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER2, "%lld", theLongLongInt);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -214,55 +219,101 @@ int socketWorkerPrintf(ftpDataType * ftpData, int clientId, const char *__restri
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (theStringSize >= SOCKET_PRINTF_BUFFER) {
|
||||
printf("\n String buffer is full!");
|
||||
}
|
||||
else if (theStringSize < SOCKET_PRINTF_BUFFER &&
|
||||
theStringSize > 0)
|
||||
{
|
||||
int theReturnCode = 0;
|
||||
|
||||
if (ftpData->clients[clientId].dataChannelIsTls != 1)
|
||||
{
|
||||
theReturnCode = write(ftpData->clients[clientId].workerData.socketConnection, theBuffer, theStringSize);
|
||||
}
|
||||
else if (ftpData->clients[clientId].dataChannelIsTls == 1)
|
||||
{
|
||||
|
||||
#ifdef OPENSSL_ENABLED
|
||||
if (ftpData->clients[clientId].workerData.passiveModeOn == 1){
|
||||
theReturnCode = SSL_write(ftpData->clients[clientId].workerData.serverSsl, theBuffer, theStringSize);
|
||||
printf("%s", theBuffer);
|
||||
}
|
||||
else if (ftpData->clients[clientId].workerData.activeModeOn == 1){
|
||||
theReturnCode = SSL_write(ftpData->clients[clientId].workerData.clientSsl, theBuffer, theStringSize);
|
||||
printf("%s", theBuffer);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (theReturnCode > 0)
|
||||
{
|
||||
bytesWritten += theReturnCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
bytesWritten = theReturnCode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(theStringSize == 0)
|
||||
{
|
||||
printf("\n Nothing to write.. ");
|
||||
}
|
||||
|
||||
++__fmt;
|
||||
|
||||
//printf("\nThe string: %s", theBuffer);
|
||||
|
||||
for (i = 0; i <theStringSize; i++)
|
||||
{
|
||||
//Write the buffer
|
||||
if (theStringToWriteSize >= COMMAND_BUFFER)
|
||||
{
|
||||
//printf("\nData to write theStringToWriteSize >= COMMAND_BUFFER: %s", writeBuffer);
|
||||
int theReturnCode = 0;
|
||||
if (ftpData->clients[clientId].dataChannelIsTls != 1)
|
||||
{
|
||||
theReturnCode = write(ftpData->clients[clientId].workerData.socketConnection, writeBuffer, theStringToWriteSize);
|
||||
}
|
||||
else if (ftpData->clients[clientId].dataChannelIsTls == 1)
|
||||
{
|
||||
#ifdef OPENSSL_ENABLED
|
||||
if (ftpData->clients[clientId].workerData.passiveModeOn == 1){
|
||||
theReturnCode = SSL_write(ftpData->clients[clientId].workerData.serverSsl, writeBuffer, theStringToWriteSize);
|
||||
//printf("%s", writeBuffer);
|
||||
}
|
||||
else if (ftpData->clients[clientId].workerData.activeModeOn == 1){
|
||||
theReturnCode = SSL_write(ftpData->clients[clientId].workerData.clientSsl, writeBuffer, theStringToWriteSize);
|
||||
//printf("%s", writeBuffer);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (theReturnCode > 0)
|
||||
{
|
||||
bytesWritten += theReturnCode;
|
||||
}
|
||||
|
||||
if (theReturnCode < 0)
|
||||
{
|
||||
printf("\nWrite error");
|
||||
va_end(args);
|
||||
return theReturnCode;
|
||||
}
|
||||
|
||||
memset(&writeBuffer, 0, COMMAND_BUFFER);
|
||||
theStringToWriteSize = 0;
|
||||
}
|
||||
|
||||
if (theStringToWriteSize < COMMAND_BUFFER)
|
||||
{
|
||||
writeBuffer[theStringToWriteSize++] = theBuffer[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
|
||||
//printf("\nData to write: %s (%d bytes)", writeBuffer, theStringToWriteSize);
|
||||
//Write the buffer
|
||||
if (theStringToWriteSize > 0)
|
||||
{
|
||||
//printf("\nwriting data size %d", theStringToWriteSize);
|
||||
int theReturnCode = 0;
|
||||
|
||||
if (ftpData->clients[clientId].dataChannelIsTls != 1)
|
||||
{
|
||||
theReturnCode = write(ftpData->clients[clientId].workerData.socketConnection, writeBuffer, theStringToWriteSize);
|
||||
}
|
||||
else if (ftpData->clients[clientId].dataChannelIsTls == 1)
|
||||
{
|
||||
#ifdef OPENSSL_ENABLED
|
||||
if (ftpData->clients[clientId].workerData.passiveModeOn == 1){
|
||||
theReturnCode = SSL_write(ftpData->clients[clientId].workerData.serverSsl, writeBuffer, theStringToWriteSize);
|
||||
//printf("%s", writeBuffer);
|
||||
}
|
||||
else if (ftpData->clients[clientId].workerData.activeModeOn == 1){
|
||||
theReturnCode = SSL_write(ftpData->clients[clientId].workerData.clientSsl, writeBuffer, theStringToWriteSize);
|
||||
//printf("%s", writeBuffer);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (theReturnCode > 0)
|
||||
{
|
||||
bytesWritten += theReturnCode;
|
||||
}
|
||||
|
||||
if (theReturnCode < 0)
|
||||
{
|
||||
return theReturnCode;
|
||||
}
|
||||
|
||||
memset(&writeBuffer, 0, COMMAND_BUFFER);
|
||||
theStringToWriteSize = 0;
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
//printf("\nbytesWritten = %d", bytesWritten);
|
||||
|
||||
return bytesWritten;
|
||||
}
|
||||
|
||||
@ -285,7 +336,7 @@ int getMaximumSocketFd(int mainSocket, ftpDataType * ftpData)
|
||||
|
||||
int createSocket(ftpDataType * ftpData)
|
||||
{
|
||||
printf("\nCreating main socket on port %d", ftpData->ftpParameters.port);
|
||||
//printf("\nCreating main socket on port %d", ftpData->ftpParameters.port);
|
||||
int sock, errorCode;
|
||||
struct sockaddr_in temp;
|
||||
|
||||
@ -401,7 +452,7 @@ int createActiveSocket(int port, char *ipAddress)
|
||||
int sockfd;
|
||||
struct sockaddr_in serv_addr;
|
||||
|
||||
printf("\n Connection socket is going to start ip: %s:%d \n", ipAddress, port);
|
||||
//printf("\n Connection socket is going to start ip: %s:%d \n", ipAddress, port);
|
||||
//sleep(100);
|
||||
memset(&serv_addr, 0, sizeof(struct sockaddr_in));
|
||||
serv_addr.sin_family = AF_INET;
|
||||
@ -447,7 +498,7 @@ int createActiveSocket(int port, char *ipAddress)
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("\n Connection socket %d is going to start ip: %s:%d \n",sockfd, ipAddress, port);
|
||||
// printf("\n Connection socket %d is going to start ip: %s:%d \n",sockfd, ipAddress, port);
|
||||
|
||||
return sockfd;
|
||||
}
|
||||
@ -486,33 +537,32 @@ void closeSocket(ftpDataType * ftpData, int processingSocket)
|
||||
int theReturnCode = 0;
|
||||
|
||||
#ifdef OPENSSL_ENABLED
|
||||
/*
|
||||
|
||||
if (ftpData->clients[processingSocket].dataChannelIsTls == 1)
|
||||
{
|
||||
if(ftpData->clients[processingSocket].workerData.passiveModeOn == 1)
|
||||
{
|
||||
|
||||
printf("\nSSL worker Shutdown 1");
|
||||
returnCode = SSL_shutdown(ftpData->clients[processingSocket].ssl);
|
||||
printf("\nnSSL worker Shutdown 1 return code : %d", returnCode);
|
||||
theReturnCode = SSL_shutdown(ftpData->clients[processingSocket].ssl);
|
||||
printf("\nnSSL worker Shutdown 1 return code : %d", theReturnCode);
|
||||
|
||||
if (returnCode < 0)
|
||||
if (theReturnCode < 0)
|
||||
{
|
||||
printf("SSL_shutdown failed return code %d", returnCode);
|
||||
printf("SSL_shutdown failed return code %d", theReturnCode);
|
||||
}
|
||||
else if (returnCode == 0)
|
||||
else if (theReturnCode == 0)
|
||||
{
|
||||
printf("\nSSL worker Shutdown 2");
|
||||
returnCode = SSL_shutdown(ftpData->clients[processingSocket].ssl);
|
||||
printf("\nnSSL worker Shutdown 2 return code : %d", returnCode);
|
||||
theReturnCode = SSL_shutdown(ftpData->clients[processingSocket].ssl);
|
||||
printf("\nnSSL worker Shutdown 2 return code : %d", theReturnCode);
|
||||
|
||||
if (returnCode <= 0)
|
||||
if (theReturnCode <= 0)
|
||||
{
|
||||
printf("SSL_shutdown (2nd time) failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
#endif
|
||||
|
||||
//Close the socket
|
||||
@ -529,19 +579,19 @@ void closeSocket(ftpDataType * ftpData, int processingSocket)
|
||||
ftpData->connectedClients = 0;
|
||||
}
|
||||
|
||||
printf("Client id: %d disconnected", processingSocket);
|
||||
printf("\nServer: Clients connected:%d", ftpData->connectedClients);
|
||||
//printf("Client id: %d disconnected", processingSocket);
|
||||
//printf("\nServer: Clients connected:%d", ftpData->connectedClients);
|
||||
return;
|
||||
}
|
||||
|
||||
void closeClient(ftpDataType * ftpData, int processingSocket)
|
||||
{
|
||||
printf("\nQUIT FLAG SET!\n");
|
||||
// printf("\nQUIT FLAG SET!\n");
|
||||
|
||||
if (ftpData->clients[processingSocket].workerData.threadIsAlive == 1)
|
||||
{
|
||||
pthread_cancel(ftpData->clients[processingSocket].workerData.workerThread);
|
||||
printf("\nQuit command received the Pasv Thread has been cancelled.");
|
||||
//printf("\nQuit command received the Pasv Thread has been cancelled.");
|
||||
}
|
||||
|
||||
FD_CLR(ftpData->clients[processingSocket].socketDescriptor, &ftpData->connectionData.rsetAll);
|
||||
@ -653,9 +703,9 @@ int evaluateClientSocketConnection(ftpDataType * ftpData)
|
||||
&(ftpData->clients[availableSocketIndex].server_sockaddr_in.sin_addr),
|
||||
ftpData->clients[availableSocketIndex].serverIpAddress,
|
||||
INET_ADDRSTRLEN);
|
||||
printf("\n Server IP: %s", ftpData->clients[availableSocketIndex].serverIpAddress);
|
||||
printf("Server: New client connected with id: %d", availableSocketIndex);
|
||||
printf("\nServer: Clients connected: %d", ftpData->connectedClients);
|
||||
//printf("\n Server IP: %s", ftpData->clients[availableSocketIndex].serverIpAddress);
|
||||
//printf("Server: New client connected with id: %d", availableSocketIndex);
|
||||
//printf("\nServer: Clients connected: %d", ftpData->connectedClients);
|
||||
sscanf (ftpData->clients[availableSocketIndex].serverIpAddress,"%d.%d.%d.%d", &ftpData->clients[availableSocketIndex].serverIpAddressInteger[0],
|
||||
&ftpData->clients[availableSocketIndex].serverIpAddressInteger[1],
|
||||
&ftpData->clients[availableSocketIndex].serverIpAddressInteger[2],
|
||||
@ -665,9 +715,9 @@ int evaluateClientSocketConnection(ftpDataType * ftpData)
|
||||
&(ftpData->clients[availableSocketIndex].client_sockaddr_in.sin_addr),
|
||||
ftpData->clients[availableSocketIndex].clientIpAddress,
|
||||
INET_ADDRSTRLEN);
|
||||
printf("\n Client IP: %s", ftpData->clients[availableSocketIndex].clientIpAddress);
|
||||
//printf("\n Client IP: %s", ftpData->clients[availableSocketIndex].clientIpAddress);
|
||||
ftpData->clients[availableSocketIndex].clientPort = (int) ntohs(ftpData->clients[availableSocketIndex].client_sockaddr_in.sin_port);
|
||||
printf("\nClient port is: %d\n", ftpData->clients[availableSocketIndex].clientPort);
|
||||
//printf("\nClient port is: %d\n", ftpData->clients[availableSocketIndex].clientPort);
|
||||
|
||||
ftpData->clients[availableSocketIndex].connectionTimeStamp = (int)time(NULL);
|
||||
ftpData->clients[availableSocketIndex].lastActivityTimeStamp = (int)time(NULL);
|
||||
|
@ -185,8 +185,8 @@ void DYNMEM_free(void *f_address, DYNMEM_MemoryTable_DataType ** memoryListHead)
|
||||
//printf("\n\nMemory address : %ld not found\n\n", f_address);
|
||||
//fflush(0);
|
||||
//Debug TRAP
|
||||
char *theData ="c";
|
||||
strcpy(theData, "ciaociaociao");
|
||||
//char *theData ="c";
|
||||
//strcpy(theData, "ciaociaociao");
|
||||
report_error_q("Unable to free memory not previously allocated",__FILE__,__LINE__, 1);
|
||||
// Report this as an error
|
||||
}
|
||||
@ -212,18 +212,18 @@ void DYNMEM_free(void *f_address, DYNMEM_MemoryTable_DataType ** memoryListHead)
|
||||
void DYNMEM_freeAll(DYNMEM_MemoryTable_DataType **memoryListHead)
|
||||
{
|
||||
|
||||
|
||||
DYNMEM_MemoryTable_DataType *temp = NULL;
|
||||
|
||||
while((*memoryListHead) != NULL)
|
||||
{
|
||||
printf("\nDYNMEM_freeAll called");
|
||||
printf("\nElement size: %ld", (*memoryListHead)->size);
|
||||
printf("\nElement address: %ld", (long int) (*memoryListHead)->address);
|
||||
printf("\nElement nextElement: %ld",(long int) (*memoryListHead)->nextElement);
|
||||
printf("\nElement previousElement: %ld",(long int) (*memoryListHead)->previousElement);
|
||||
// printf("\nDYNMEM_freeAll called");
|
||||
// printf("\nElement size: %ld", (*memoryListHead)->size);
|
||||
// printf("\nElement address: %ld", (long int) (*memoryListHead)->address);
|
||||
// printf("\nElement nextElement: %ld",(long int) (*memoryListHead)->nextElement);
|
||||
// printf("\nElement previousElement: %ld",(long int) (*memoryListHead)->previousElement);
|
||||
|
||||
DYNMEM_DecreaseMemoryCounter((*memoryListHead)->size + sizeof(DYNMEM_MemoryTable_DataType));
|
||||
printf("\nFree table element");
|
||||
//printf("\nFree table element");
|
||||
free((*memoryListHead)->address);
|
||||
temp = (*memoryListHead)->nextElement;
|
||||
free((*memoryListHead));
|
||||
|
@ -51,7 +51,7 @@ static int FILE_CompareStringParameter(const void * a, const void * b)
|
||||
{
|
||||
const FILE_StringParameter_DataType * typeA = *(const FILE_StringParameter_DataType **)a;
|
||||
const FILE_StringParameter_DataType * typeB = *(const FILE_StringParameter_DataType **)b;
|
||||
printf("Comparing %s with %s",typeA->Name, typeB->Name);
|
||||
//printf("Comparing %s with %s",typeA->Name, typeB->Name);
|
||||
return strcmp(typeA->Name, typeB->Name);
|
||||
}
|
||||
|
||||
@ -242,7 +242,7 @@ void FILE_GetDirectoryInodeList(char * DirectoryInodeName, char *** InodeList, i
|
||||
}
|
||||
else if (FILE_IsFile(DirectoryInodeName))
|
||||
{
|
||||
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;
|
||||
(*InodeList) = (char ** ) DYNMEM_realloc((*InodeList), ReallocSize, &*memoryTable);
|
||||
int nsize = strlen(DirectoryInodeName) * sizeof(char) + 2;
|
||||
@ -255,7 +255,7 @@ void FILE_GetDirectoryInodeList(char * DirectoryInodeName, char *** InodeList, i
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\n%s is not a file or a directory", DirectoryInodeName);
|
||||
//printf("\n%s is not a file or a directory", DirectoryInodeName);
|
||||
//No valid path specified, returns zero elements
|
||||
(*FilesandFolders) = 0;
|
||||
}
|
||||
@ -359,7 +359,7 @@ void FILE_ReadStringParameters(char * filename, DYNV_VectorGenericDataType *Para
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Parameter initializing from file %s", filename);
|
||||
//printf("Parameter initializing from file %s", filename);
|
||||
|
||||
while(fgets(Line, FILE_MAX_LINE_LENGHT, File) != NULL)
|
||||
{
|
||||
@ -380,7 +380,7 @@ void FILE_ReadStringParameters(char * filename, DYNV_VectorGenericDataType *Para
|
||||
{
|
||||
TheParameter.Name[BufferNameCursor] = '\0';
|
||||
TheParameter.Value[BufferValueCursor] = '\0';
|
||||
printf("Adding name: %s value: %s", TheParameter.Name, TheParameter.Value);
|
||||
//printf("Adding name: %s value: %s", TheParameter.Name, TheParameter.Value);
|
||||
//printf("TheParameter.Name[0] = %d", TheParameter.Name[0]);
|
||||
|
||||
ParametersVector->PushBack(ParametersVector, &TheParameter, sizeof(FILE_StringParameter_DataType));
|
||||
@ -436,19 +436,19 @@ void FILE_ReadStringParameters(char * filename, DYNV_VectorGenericDataType *Para
|
||||
fclose(File);
|
||||
}
|
||||
|
||||
printf("ParametersVector->Size %d", ParametersVector->Size);
|
||||
// printf("ParametersVector->Size %d", ParametersVector->Size);
|
||||
|
||||
for (i = 0; i < ParametersVector->Size; i++)
|
||||
{
|
||||
printf("ParametersVector->Data[%d])->Name = %s",i, ((FILE_StringParameter_DataType *)ParametersVector->Data[i])->Name);
|
||||
//printf("ParametersVector->Data[%d])->Name = %s",i, ((FILE_StringParameter_DataType *)ParametersVector->Data[i])->Name);
|
||||
}
|
||||
|
||||
qsort(ParametersVector->Data, ParametersVector->Size, sizeof(void *), FILE_CompareStringParameter);
|
||||
|
||||
printf("Sorted");
|
||||
//printf("Sorted");
|
||||
for (i = 0; i < ParametersVector->Size; i++)
|
||||
{
|
||||
printf("ParametersVector->Data[%d])->Name = %s",i, ((FILE_StringParameter_DataType *)ParametersVector->Data[i])->Name);
|
||||
//printf("ParametersVector->Data[%d])->Name = %s",i, ((FILE_StringParameter_DataType *)ParametersVector->Data[i])->Name);
|
||||
}
|
||||
|
||||
}
|
||||
@ -742,11 +742,11 @@ void FILE_checkAllOpenedFD(void)
|
||||
fstat(i, &statbuf);
|
||||
if (S_ISSOCK(statbuf.st_mode))
|
||||
{
|
||||
printf("\n fd %d is socket", i);
|
||||
//printf("\n fd %d is socket", i);
|
||||
}
|
||||
else if (S_ISDIR(statbuf.st_mode))
|
||||
{
|
||||
printf("\n fd %d is dir", i);
|
||||
//printf("\n fd %d is dir", i);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -771,5 +771,5 @@ void FILE_checkAllOpenedFD(void)
|
||||
openedFd++;
|
||||
}
|
||||
}
|
||||
printf("\n\nOpened fd : %d", openedFd);
|
||||
//printf("\n\nOpened fd : %d", openedFd);
|
||||
}
|
||||
|
87
pamTest.c
Normal file
87
pamTest.c
Normal file
@ -0,0 +1,87 @@
|
||||
#include <stdio.h>
|
||||
#include <security/pam_appl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//gcc -o pamTest pamTest.c -lpam
|
||||
|
||||
struct pam_response *reply;
|
||||
|
||||
// //function used to get user input
|
||||
int function_conversation(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr)
|
||||
{
|
||||
*resp = reply;
|
||||
return PAM_SUCCESS;
|
||||
}
|
||||
|
||||
int authenticate_system(const char *username, const char *password)
|
||||
{
|
||||
const struct pam_conv local_conversation = { function_conversation, NULL };
|
||||
pam_handle_t *local_auth_handle = NULL; // this gets set by pam_start
|
||||
|
||||
int retval;
|
||||
retval = pam_start("su", username, &local_conversation, &local_auth_handle);
|
||||
|
||||
if (retval != PAM_SUCCESS)
|
||||
{
|
||||
printf("pam_start returned: %d\n ", retval);
|
||||
return 0;
|
||||
}
|
||||
|
||||
reply = (struct pam_response *)malloc(sizeof(struct pam_response));
|
||||
|
||||
reply[0].resp = strdup(password);
|
||||
reply[0].resp_retcode = 0;
|
||||
retval = pam_authenticate(local_auth_handle, 0);
|
||||
|
||||
if (retval != PAM_SUCCESS)
|
||||
{
|
||||
if (retval == PAM_AUTH_ERR)
|
||||
{
|
||||
printf("Authentication failure.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("pam_authenticate returned %d\n", retval);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Authenticated.\n");
|
||||
retval = pam_end(local_auth_handle, retval);
|
||||
|
||||
if (retval != PAM_SUCCESS)
|
||||
{
|
||||
printf("pam_end returned\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
char* login;
|
||||
char* password;
|
||||
|
||||
printf("Authentication module\n");
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
printf("Invalid count of arguments %d.\n", argc);
|
||||
printf("./authModule <username> <password>");
|
||||
return 1;
|
||||
}
|
||||
|
||||
login = argv[1];
|
||||
password = argv[2];
|
||||
|
||||
if (authenticate_system(login, password) == 1)
|
||||
{
|
||||
printf("Authenticate with %s - %s through system\n", login, password);
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Authentication failed!\n");
|
||||
return 1;
|
||||
}
|
61
uFTP.c
61
uFTP.c
@ -22,73 +22,12 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
void myFunction (void * p);
|
||||
void myFunction2 (void * p);
|
||||
void myFunction3 (void * p);
|
||||
void myFunction4 (void **p);
|
||||
|
||||
void myFunction (void * p)
|
||||
{
|
||||
static int i2 = 11;
|
||||
myFunction2(p);
|
||||
p = &i2;
|
||||
printf("\n1 p = %lld address of the pointer is %lld", p, &p);
|
||||
printf(" intval %d", *(int *) p);
|
||||
}
|
||||
|
||||
void myFunction2 (void * p)
|
||||
{
|
||||
myFunction3(p);
|
||||
printf("\n2 p = %lld address of the pointer is %lld", p, &p);
|
||||
printf(" intval %d", *(int *) p);
|
||||
}
|
||||
|
||||
void myFunction3 (void * p)
|
||||
{
|
||||
printf("\n3 p = %lld address of the pointer is %lld", p, &p);
|
||||
printf(" intval %d", *(int *) p);
|
||||
}
|
||||
|
||||
void myFunction4 (void **p)
|
||||
{
|
||||
static int oraSi = 12;
|
||||
printf("\n4 p = %lld address of the pointer is %lld", *p, &*p);
|
||||
printf(" intval %d", *(int *) *p);
|
||||
|
||||
*p = &oraSi;
|
||||
myFunction5(&*p);
|
||||
}
|
||||
|
||||
void myFunction5 (void **p)
|
||||
{
|
||||
static int oraSi = 13;
|
||||
printf("\n5 p = %lld address of the pointer is %lld", *p, &*p);
|
||||
printf(" intval %d", *(int *) *p);
|
||||
|
||||
*p = &oraSi;
|
||||
}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "ftpServer.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
/*
|
||||
void *p;
|
||||
int a = 10;
|
||||
p = (void *)&a;
|
||||
|
||||
printf("\np at init = %lld address of the pointer is %lld", p, &p);
|
||||
//myFunction(p);
|
||||
printf("\np after myFunction = %lld address of the pointer is %lld", p, &p);
|
||||
myFunction4(&p);
|
||||
printf("\np after myFunction4 = %lld address of the pointer is %lld", p, &p);
|
||||
printf(" intval %d", *(int *) p);
|
||||
exit(0);
|
||||
*/
|
||||
runFtpServer();
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
|
Reference in New Issue
Block a user