diff --git a/build/Debug/GNU-Linux/ftpCommandElaborate.o b/build/Debug/GNU-Linux/ftpCommandElaborate.o index 6bb7a17..557a7d9 100644 Binary files a/build/Debug/GNU-Linux/ftpCommandElaborate.o and b/build/Debug/GNU-Linux/ftpCommandElaborate.o differ diff --git a/build/Debug/GNU-Linux/ftpData.o b/build/Debug/GNU-Linux/ftpData.o index 886821b..7699e0f 100644 Binary files a/build/Debug/GNU-Linux/ftpData.o and b/build/Debug/GNU-Linux/ftpData.o differ diff --git a/build/Debug/GNU-Linux/ftpServer.o b/build/Debug/GNU-Linux/ftpServer.o index 0328589..7fee24b 100644 Binary files a/build/Debug/GNU-Linux/ftpServer.o and b/build/Debug/GNU-Linux/ftpServer.o differ diff --git a/build/Debug/GNU-Linux/library/configRead.o b/build/Debug/GNU-Linux/library/configRead.o index e2258e3..ba5323c 100644 Binary files a/build/Debug/GNU-Linux/library/configRead.o and b/build/Debug/GNU-Linux/library/configRead.o differ diff --git a/build/Debug/GNU-Linux/library/connection.o b/build/Debug/GNU-Linux/library/connection.o index a26ec1f..7afd810 100644 Binary files a/build/Debug/GNU-Linux/library/connection.o and b/build/Debug/GNU-Linux/library/connection.o differ diff --git a/build/Debug/GNU-Linux/library/daemon.o b/build/Debug/GNU-Linux/library/daemon.o index b1e3b9e..8f85ed5 100644 Binary files a/build/Debug/GNU-Linux/library/daemon.o and b/build/Debug/GNU-Linux/library/daemon.o differ diff --git a/build/Debug/GNU-Linux/library/dynamicVectors.o b/build/Debug/GNU-Linux/library/dynamicVectors.o index f4d601c..2f77978 100644 Binary files a/build/Debug/GNU-Linux/library/dynamicVectors.o and b/build/Debug/GNU-Linux/library/dynamicVectors.o differ diff --git a/build/Debug/GNU-Linux/library/fileManagement.o b/build/Debug/GNU-Linux/library/fileManagement.o index 8a51513..d776919 100644 Binary files a/build/Debug/GNU-Linux/library/fileManagement.o and b/build/Debug/GNU-Linux/library/fileManagement.o differ diff --git a/build/Debug/GNU-Linux/library/logFunctions.o b/build/Debug/GNU-Linux/library/logFunctions.o index 41b67dd..cfcc46c 100644 Binary files a/build/Debug/GNU-Linux/library/logFunctions.o and b/build/Debug/GNU-Linux/library/logFunctions.o differ diff --git a/build/Debug/GNU-Linux/library/signals.o b/build/Debug/GNU-Linux/library/signals.o index 3f931cc..f93f401 100644 Binary files a/build/Debug/GNU-Linux/library/signals.o and b/build/Debug/GNU-Linux/library/signals.o differ diff --git a/build/Debug/GNU-Linux/uFTP.o b/build/Debug/GNU-Linux/uFTP.o index 4fe0bf1..a0074ac 100644 Binary files a/build/Debug/GNU-Linux/uFTP.o and b/build/Debug/GNU-Linux/uFTP.o differ diff --git a/dist/Debug/GNU-Linux/uftp b/dist/Debug/GNU-Linux/uftp index 8c2b9ed..7b889ff 100755 Binary files a/dist/Debug/GNU-Linux/uftp and b/dist/Debug/GNU-Linux/uftp differ diff --git a/dist/Debug/GNU-Linux/uftpReleased b/dist/Debug/GNU-Linux/uftpReleased deleted file mode 100755 index 4cf6276..0000000 Binary files a/dist/Debug/GNU-Linux/uftpReleased and /dev/null differ diff --git a/ftpCommandElaborate.c b/ftpCommandElaborate.c index 4436137..48cd941 100644 --- a/ftpCommandElaborate.c +++ b/ftpCommandElaborate.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#define _LARGEFILE64_SOURCE #include #include @@ -798,7 +799,7 @@ int parseCommandSize(clientDataType *theClientData) { int returnCode; int isSafePath; - unsigned long long int theSize; + long long int theSize; char *theFileName; dynamicStringDataType theResponse; dynamicStringDataType getSizeFromFileName; @@ -963,16 +964,15 @@ int parseCommandCdup(clientDataType *theClientData) return 1; } -int writeRetrFile(char * theFilename, int thePasvSocketConnection, int startFrom, FILE *retrFP) +long long int writeRetrFile(char * theFilename, int thePasvSocketConnection, long long int startFrom, FILE *retrFP) { - long int readen = 0; - long int toReturn = 0, writtenSize = 0; - long int currentPosition = 0; + long long int readen = 0; + long long int toReturn = 0, writtenSize = 0; + long long int currentPosition = 0; long long int theFileSize; char buffer[FTP_COMMAND_ELABORATE_CHAR_BUFFER]; - - retrFP = fopen(theFilename, "rb"); + retrFP = fopen64(theFilename, "rb"); if (retrFP == NULL) { return -1; @@ -983,7 +983,7 @@ int writeRetrFile(char * theFilename, int thePasvSocketConnection, int startFrom if (startFrom > 0) { //printf("\nSeek startFrom: %d", startFrom); - currentPosition = (long int) lseek(fileno(retrFP), startFrom, SEEK_SET); + currentPosition = (long long int) lseek64(fileno(retrFP), startFrom, SEEK_SET); // printf("\nSeek result: %ld", currentPosition); if (currentPosition == -1) { @@ -993,7 +993,7 @@ int writeRetrFile(char * theFilename, int thePasvSocketConnection, int startFrom } } - while ((readen = (long int) fread(buffer, sizeof(char), FTP_COMMAND_ELABORATE_CHAR_BUFFER, retrFP)) > 0) + while ((readen = (long long int) fread(buffer, sizeof(char), FTP_COMMAND_ELABORATE_CHAR_BUFFER, retrFP)) > 0) { writtenSize = write(thePasvSocketConnection, buffer, readen); diff --git a/ftpCommandsElaborate.h b/ftpCommandsElaborate.h index cd97ca2..2fcee3b 100644 --- a/ftpCommandsElaborate.h +++ b/ftpCommandsElaborate.h @@ -72,7 +72,7 @@ int parseCommandOpts(clientDataType *theClientData); int parseCommandRnfr(clientDataType *theClientData); int parseCommandRnto(clientDataType *theClientData); -int writeRetrFile(char * theFilename, int thePasvSocketConnection, int startFrom, FILE *retrFP); +long long int writeRetrFile(char * theFilename, int thePasvSocketConnection, long long int startFrom, FILE *retrFP); char *getFtpCommandArg(char * theCommand, char *theCommandString, int skipArgs); int getFtpCommandArgWithOptions(char * theCommand, char *theCommandString, ftpCommandDataType *ftpCommand); int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataType ownerShip); diff --git a/ftpData.c b/ftpData.c index 34c6401..b95b70f 100644 --- a/ftpData.c +++ b/ftpData.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#define _LARGEFILE64_SOURCE #include #include @@ -217,13 +218,172 @@ void setRandomicPort(ftpDataType *data, int socketPosition) printf("data->clients[%d].workerData.connectionPort = %d", socketPosition, data->clients[socketPosition].workerData.connectionPort); } + + +int writeListDataInfoToSocket(char * thePath, int theSocket, int *filesNumber, int commandType) +{ + int i, x, returnCode; + int fileAndFoldersCount = 0; + char **fileList = NULL; + FILE_GetDirectoryInodeList(thePath, &fileList, &fileAndFoldersCount, 0); + *filesNumber = fileAndFoldersCount; + + returnCode = dprintf(theSocket, "total %d\r\n", fileAndFoldersCount); + if (returnCode <= 0) + { + return -1; + } + + for (i = 0; i < fileAndFoldersCount; i++) + { + ftpListDataType data; + data.owner = NULL; + data.groupOwner = NULL; + data.inodePermissionString = NULL; + data.fileNameWithPath = NULL; + data.finalStringPath = NULL; + data.linkPath = NULL; + + data.numberOfSubDirectories = 1; /* to Do*/ + data.isFile = 0; + data.isDirectory = 0; + + + printf("\nPROCESSING: %s", fileList[i]); + fflush(0); + + if (FILE_IsDirectory(fileList[i]) == 1) + { + printf("\nis directory"); + fflush(0); + data.isDirectory = 1; + data.isFile = 0; + data.isLink = 0; + data.fileSize = 4096; + } + else if (FILE_IsFile(fileList[i]) == 1) + { + printf("\nis file"); + fflush(0); + data.isDirectory = 0; + data.isFile = 1; + data.isLink = 0; + data.fileSize = FILE_GetFileSizeFromPath(fileList[i]); + } + if (data.isDirectory == 0 && data.isFile == 0) + { + printf("\nNot a directory, not a file, broken link"); + continue; + } + + printf("\nFILE SIZE : %lld", data.fileSize); + + data.owner = FILE_GetOwner(fileList[i]); + data.groupOwner = FILE_GetGroupOwner(fileList[i]); + data.fileNameWithPath = fileList[i]; + data.fileNameNoPath = FILE_GetFilenameFromPath(fileList[i]); + data.inodePermissionString = FILE_GetListPermissionsString(fileList[i]); + data.lastModifiedData = FILE_GetLastModifiedData(fileList[i]); + + if (strlen(data.fileNameNoPath) > 0) + { + data.finalStringPath = (char *) malloc (strlen(data.fileNameNoPath)+1); + strcpy(data.finalStringPath, data.fileNameNoPath); + } + + if (data.inodePermissionString != NULL && + strlen(data.inodePermissionString) > 0 && + data.inodePermissionString[0] == 'l') + { + int len = 0; + data.isLink = 1; + data.linkPath = (char *) malloc (CLIENT_COMMAND_STRING_SIZE*sizeof(char)); + if ((len = readlink (fileList[i], data.linkPath, CLIENT_COMMAND_STRING_SIZE)) > 0) + { + data.linkPath[len] = 0; + FILE_AppendToString(&data.finalStringPath, " -> "); + FILE_AppendToString(&data.finalStringPath, data.linkPath); + } + } + + memset(data.lastModifiedDataString, 0, LIST_DATA_TYPE_MODIFIED_DATA_STR_SIZE); + strftime(data.lastModifiedDataString, LIST_DATA_TYPE_MODIFIED_DATA_STR_SIZE, "%b %d %Y", localtime(&data.lastModifiedData)); + + + switch (commandType) + { + case COMMAND_TYPE_LIST: + { + returnCode = dprintf(theSocket, "%s %d %s %s %lld %s %s\r\n", + data.inodePermissionString == NULL? "Uknown" : data.inodePermissionString + ,data.numberOfSubDirectories + ,data.owner == NULL? "Uknown" : data.owner + ,data.groupOwner == NULL? "Uknown" : data.groupOwner + ,data.fileSize + ,data.lastModifiedDataString == NULL? "Uknown" : data.lastModifiedDataString + ,data.finalStringPath == NULL? "Uknown" : data.finalStringPath); + } + break; + + case COMMAND_TYPE_NLIST: + { + returnCode = dprintf(theSocket, "%s\r\n",data.fileNameNoPath); + } + break; + + + default: + { + printf("\nWarning switch default in function writeListDataInfoToSocket (%d)", commandType); + } + break; + + } + + + if (data.fileNameWithPath != NULL) + free(data.fileNameWithPath); + + if (data.linkPath != NULL) + free(data.linkPath); + + if (data.finalStringPath != NULL) + free(data.finalStringPath); + + if (data.owner != NULL) + free(data.owner); + + if (data.groupOwner != NULL) + free(data.groupOwner); + + if (data.inodePermissionString != NULL) + free(data.inodePermissionString); + + if (returnCode <= 0) + { + for (x = i+1; x < fileAndFoldersCount; x++) + free (fileList[x]); + free (fileList); + return -1; + } + + } + free (fileList); + + return 1; + } + + void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo) { int i; int fileAndFoldersCount = 0; ftpListDataType data; FILE_GetDirectoryInodeList(thePath, &data.fileList, &fileAndFoldersCount, 0); - + + printf("\nNUMBER OF FILES: %d", fileAndFoldersCount); + fflush(0); + for (i = 0; i < fileAndFoldersCount; i++) { data.owner = NULL; @@ -237,8 +397,14 @@ void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo) data.isFile = 0; data.isDirectory = 0; + + printf("\nPROCESSING: %s", data.fileList[i]); + fflush(0); + if (FILE_IsDirectory(data.fileList[i]) == 1) { + printf("\nis file"); + fflush(0); data.isDirectory = 1; data.isFile = 0; data.isLink = 0; @@ -246,6 +412,8 @@ void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo) } else if (FILE_IsFile(data.fileList[i]) == 1) { + printf("\nis file"); + fflush(0); data.isDirectory = 0; data.isFile = 1; data.isLink = 0; @@ -253,9 +421,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); data.owner = FILE_GetOwner(data.fileList[i]); data.groupOwner = FILE_GetGroupOwner(data.fileList[i]); diff --git a/ftpData.h b/ftpData.h index 1fc4fd3..266ee10 100644 --- a/ftpData.h +++ b/ftpData.h @@ -25,7 +25,7 @@ #ifndef FTPDATA_H #define FTPDATA_H - +#define _LARGEFILE64_SOURCE #include #include "library/dynamicVectors.h" @@ -33,7 +33,10 @@ #define CLIENT_COMMAND_STRING_SIZE 2048 #define CLIENT_BUFFER_STRING_SIZE 2048 -#define LIST_DATA_TYPE_MODIFIED_DATA_STR_SIZE 80 +#define LIST_DATA_TYPE_MODIFIED_DATA_STR_SIZE 1024 + +#define COMMAND_TYPE_LIST 0 +#define COMMAND_TYPE_NLIST 1 #ifdef __cplusplus @@ -128,7 +131,7 @@ struct workerData char theCommandReceived[CLIENT_COMMAND_STRING_SIZE]; int commandReceived; - unsigned long int retrRestartAtByte; + long long int retrRestartAtByte; /* The PASV thread will wait the signal before start */ pthread_mutex_t conditionMutex; @@ -208,7 +211,7 @@ struct ftpListData int isLink; char *owner; char *groupOwner; - int fileSize; + long long int fileSize; char *inodePermissionString; char **fileList; time_t lastModifiedData; @@ -222,6 +225,7 @@ int getSafePath(dynamicStringDataType *safePath, char *theDirectoryName, loginDa void appendToDynamicStringDataType(dynamicStringDataType *dynamicString, char *theString, int stringLen); void setRandomicPort(ftpDataType *data, int socketPosition); void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo); +int writeListDataInfoToSocket(char * thePath, int theSocket, int *filesNumber, int commandType); void deleteListDataInfoVector(void *TheElementToDelete); void resetWorkerData(workerDataType *pasvData, int isInitialization); void resetClientData(clientDataType *clientData, int isInitialization); diff --git a/ftpServer.c b/ftpServer.c index ee4ae22..db03ca2 100644 --- a/ftpServer.c +++ b/ftpServer.c @@ -22,6 +22,8 @@ * THE SOFTWARE. */ +#define _LARGEFILE64_SOURCE + #include #include #include @@ -171,7 +173,7 @@ void *connectionWorkerHandle(void * socketId) { char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER]; memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER); - ftpData.clients[theSocketId].workerData.theStorFile = fopen(ftpData.clients[theSocketId].fileToStor.text, "wb"); + ftpData.clients[theSocketId].workerData.theStorFile = fopen64(ftpData.clients[theSocketId].fileToStor.text, "wb"); if (ftpData.clients[theSocketId].workerData.theStorFile == NULL) { @@ -238,122 +240,45 @@ void *connectionWorkerHandle(void * socketId) break; } else if (ftpData.clients[theSocketId].workerData.commandReceived == 1 && - (compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "LIST", strlen("LIST")) == 1)) + ( (compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "LIST", strlen("LIST")) == 1) + || (compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "NLST", strlen("NLST")) == 1)) + ) { - int i; - char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER]; - char theBufferWrite[FTP_COMMAND_ELABORATE_CHAR_BUFFER_BIG]; - memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER); - getListDataInfo(ftpData.clients[theSocketId].listPath.text, &ftpData.clients[theSocketId].workerData.directoryInfo); - - printf("\nPasv (%d) ftpData.clients[theSocketId].listPath.text = %s", theSocketId, ftpData.clients[theSocketId].listPath.text); - strcpy(theResponse, "150 Accepted data connection\r\n"); - returnCode = write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse)); + int theFiles = 0, theCommandType; + + + if (compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "LIST", strlen("LIST")) == 1) + theCommandType = COMMAND_TYPE_LIST; + else if (compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "NLST", strlen("NLST")) == 1) + theCommandType = COMMAND_TYPE_NLIST; + + returnCode = dprintf(ftpData.clients[theSocketId].socketDescriptor, "150 Accepted data connection\r\n"); + if (returnCode <= 0) + { + ftpData.clients[theSocketId].closeTheClient = 1; + pthread_exit(NULL); + } + + returnCode = writeListDataInfoToSocket(ftpData.clients[theSocketId].listPath.text, ftpData.clients[theSocketId].workerData.socketConnection, &theFiles, theCommandType); if (returnCode <= 0) { ftpData.clients[theSocketId].closeTheClient = 1; pthread_exit(NULL); } - memset(theBufferWrite, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER_BIG); - sprintf(theBufferWrite, "total %d\r\n", ftpData.clients[theSocketId].workerData.directoryInfo.Size); - returnCode = write(ftpData.clients[theSocketId].workerData.socketConnection, theBufferWrite, strlen(theBufferWrite)); - if (returnCode <= 0) - { - pthread_exit(NULL); - } - - //printf("%s", theBufferWrite); - for (i = 0; i < ftpData.clients[theSocketId].workerData.directoryInfo.Size; i++) - { - memset(theBufferWrite, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER_BIG); - sprintf(theBufferWrite, "%s %d %s %s %d %s %s\r\n", - ((((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->inodePermissionString) == NULL? "Uknown" : (((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->inodePermissionString)) - ,((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->numberOfSubDirectories - ,((((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->owner) == NULL? "Uknown" : (((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->owner)) - ,((((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->groupOwner) == NULL? "Uknown" : (((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->groupOwner)) - ,((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->fileSize - ,((((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->lastModifiedDataString) == NULL? "Uknown" : (((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->lastModifiedDataString)) - ,((((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->finalStringPath) == NULL? "Uknown" : (((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->finalStringPath))); - printf("\n%s", theBufferWrite); - returnCode = write(ftpData.clients[theSocketId].workerData.socketConnection, theBufferWrite, strlen(theBufferWrite)); - - if (returnCode <= 0) - { - pthread_exit(NULL); - } - } - - memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER); - sprintf(theResponse, "226 %d matches total\r\n", ftpData.clients[theSocketId].workerData.directoryInfo.Size); - returnCode = write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse)); + returnCode = dprintf(ftpData.clients[theSocketId].socketDescriptor, "226 %d matches total\r\n", theFiles); if (returnCode <= 0) { ftpData.clients[theSocketId].closeTheClient = 1; pthread_exit(NULL); } - printf("\nPasv (%d) List end", theSocketId); break; } - else if (ftpData.clients[theSocketId].workerData.commandReceived == 1 && - compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "NLST", strlen("NLST")) == 1) - { - int i; - char theBufferWrite[FTP_COMMAND_ELABORATE_CHAR_BUFFER_BIG]; - char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER]; - - getListDataInfo(ftpData.clients[theSocketId].nlistPath.text, &ftpData.clients[theSocketId].workerData.directoryInfo); - printf("\nPasv (%d) ftpData.clients[theSocketId].login.absolutePath.text = %s",theSocketId, ftpData.clients[theSocketId].login.absolutePath.text); - - memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER); - strcpy(theResponse, "150 Accepted data connection\r\n"); - returnCode = write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse)); - if (returnCode <= 0) - { - ftpData.clients[theSocketId].closeTheClient = 1; - pthread_exit(NULL); - } - - memset(theBufferWrite, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER_BIG); - sprintf(theBufferWrite, "total %d\r\n", ftpData.clients[theSocketId].workerData.directoryInfo.Size); - returnCode = write(ftpData.clients[theSocketId].workerData.socketConnection, theBufferWrite, strlen(theBufferWrite)); - - if (returnCode <= 0) - { - pthread_exit(NULL); - } - //printf("%s", theBufferWrite); - for (i = 0; i < ftpData.clients[theSocketId].workerData.directoryInfo.Size; i++) - { - memset(theBufferWrite, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER_BIG); - sprintf(theBufferWrite, "%s\r\n" - ,((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->fileNameNoPath); - //printf("%s", theBufferWrite); - returnCode = write(ftpData.clients[theSocketId].workerData.socketConnection, theBufferWrite, strlen(theBufferWrite)); - if (returnCode <= 0) - { - pthread_exit(NULL); - } - } - - memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER); - - sprintf(theResponse, "226 %d matches total\r\n", ftpData.clients[theSocketId].workerData.directoryInfo.Size); - returnCode = write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse)); - if (returnCode <= 0) - { - ftpData.clients[theSocketId].closeTheClient = 1; - pthread_exit(NULL); - } - - printf("\nPasv (%d) List end", theSocketId); - break; - } else if (ftpData.clients[theSocketId].workerData.commandReceived == 1 && compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "RETR", strlen("RETR")) == 1) { - int writenSize = 0, writeReturn = 0; + long long int writenSize = 0, writeReturn = 0; char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER]; memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER); strcpy(theResponse, "150 Accepted data connection\r\n"); diff --git a/library/configRead.c b/library/configRead.c index ec2b431..bf2461e 100644 --- a/library/configRead.c +++ b/library/configRead.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#define _LARGEFILE64_SOURCE #include #include diff --git a/library/connection.c b/library/connection.c index 42a5986..8640f19 100644 --- a/library/connection.c +++ b/library/connection.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#define _LARGEFILE64_SOURCE #include #include diff --git a/library/daemon.c b/library/daemon.c index b9267d5..d35d1d4 100644 --- a/library/daemon.c +++ b/library/daemon.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#define _LARGEFILE64_SOURCE #include #include diff --git a/library/dynamicVectors.c b/library/dynamicVectors.c index c2ae937..ad06000 100644 --- a/library/dynamicVectors.c +++ b/library/dynamicVectors.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#define _LARGEFILE64_SOURCE #include #include diff --git a/library/fileManagement.c b/library/fileManagement.c index 49ebf38..1e62a7e 100644 --- a/library/fileManagement.c +++ b/library/fileManagement.c @@ -23,6 +23,8 @@ */ +#define _LARGEFILE64_SOURCE + #include #include @@ -65,13 +67,13 @@ int FILE_IsDirectory(char *DirectoryPath) { struct stat sb; if (stat(DirectoryPath, &sb) == 0 && S_ISDIR(sb.st_mode)) - { + { return 1; - } + } else - { + { return 0; - } + } return 0; } @@ -91,27 +93,29 @@ long int FILE_GetAvailableSpace(const char* path) } /* Get the file size */ -int FILE_GetFileSize(FILE *TheFilePointer) +long long int FILE_GetFileSize(FILE *TheFilePointer) { - int Prev = 0, TheFileSize = 0; - Prev = ftell(TheFilePointer); - fseek(TheFilePointer, 0L, SEEK_END); - TheFileSize = ftell(TheFilePointer); - fseek(TheFilePointer, Prev, SEEK_SET); + long long int Prev = 0, TheFileSize = 0; + Prev = ftello64(TheFilePointer); + fseeko64(TheFilePointer, 0, SEEK_END); + TheFileSize = ftello64(TheFilePointer); + fseeko64(TheFilePointer, Prev, SEEK_SET); return TheFileSize; } -int FILE_GetFileSizeFromPath(char *TheFileName) +long long int FILE_GetFileSizeFromPath(char *TheFileName) { if (FILE_IsFile(TheFileName) == 1) { FILE *TheFilePointer; - TheFilePointer = fopen(TheFileName, "rb"); - int Prev = 0, TheFileSize = 0; - Prev = ftell(TheFilePointer); - fseek(TheFilePointer, 0L, SEEK_END); - TheFileSize = ftell(TheFilePointer); - fseek(TheFilePointer, Prev, SEEK_SET); + TheFilePointer = fopen64(TheFileName, "rb"); + long long int Prev = 0, TheFileSize = 0; + Prev = ftello64(TheFilePointer); + fseeko64(TheFilePointer, 0L, SEEK_END); + TheFileSize = ftello64(TheFilePointer); + printf("ftello64(TheFilePointer) == %lli", ftello64(TheFilePointer)); + fseeko64(TheFilePointer, Prev, SEEK_SET); + fclose(TheFilePointer); return TheFileSize; } @@ -125,9 +129,9 @@ int FILE_GetFileSizeFromPath(char *TheFileName) int FILE_IsFile(const char *TheFileName) { FILE *TheFile; - TheFile = fopen(TheFileName, "rb"); + TheFile = fopen64(TheFileName, "rb"); - if (TheFile) + if (TheFile != NULL) { fclose(TheFile); return 1; @@ -188,7 +192,7 @@ void FILE_GetDirectoryInodeList(char * DirectoryInodeName, char *** InodeList, i int FILE_GetStringFromFile(char * filename, char **file_content) { - int file_size = 0; + long long int file_size = 0; int c, count; if (FILE_IsFile(filename) == 0) @@ -219,134 +223,134 @@ int FILE_GetStringFromFile(char * filename, char **file_content) } void FILE_ReadStringParameters(char * filename, DYNV_VectorGenericDataType *ParametersVector) - { - FILE *File; - char Line[FILE_MAX_LINE_LENGHT]; - int i; - int c; - char FirstChar = 0; - char SeparatorChar = 0; - char ParameterChar = 0; - int BufferNameCursor = 0; - int BufferValueCursor = 0; - FILE_StringParameter_DataType TheParameter; +{ + FILE *File; + char Line[FILE_MAX_LINE_LENGHT]; + int i; + int c; + char FirstChar = 0; + char SeparatorChar = 0; + char ParameterChar = 0; + int BufferNameCursor = 0; + int BufferValueCursor = 0; + FILE_StringParameter_DataType TheParameter; - memset (TheParameter.Name, 0, FILE_MAX_PAR_VAR_SIZE); - memset (TheParameter.Value, 0, FILE_MAX_PAR_VAR_SIZE); + memset (TheParameter.Name, 0, FILE_MAX_PAR_VAR_SIZE); + memset (TheParameter.Value, 0, FILE_MAX_PAR_VAR_SIZE); - File = fopen(filename, "r"); - if(File == NULL) - { - printf("error while opening file %s", filename); - } - else - { - printf("Parameter initializing from file %s", filename); + File = fopen(filename, "r"); + if(File == NULL) + { + printf("error while opening file %s", filename); + } + else + { + printf("Parameter initializing from file %s", filename); - while(fgets(Line, FILE_MAX_LINE_LENGHT, File) != NULL) - { - //printf("LINE: %s", Line); - i = 0; + while(fgets(Line, FILE_MAX_LINE_LENGHT, File) != NULL) + { + //printf("LINE: %s", Line); + i = 0; - while (iPushBack(ParametersVector, &TheParameter, sizeof(FILE_StringParameter_DataType)); - BufferNameCursor = 0; - BufferValueCursor = 0; - memset (TheParameter.Name, 0, FILE_MAX_PAR_VAR_SIZE); - memset (TheParameter.Value, 0, FILE_MAX_PAR_VAR_SIZE); - } + ParametersVector->PushBack(ParametersVector, &TheParameter, sizeof(FILE_StringParameter_DataType)); + BufferNameCursor = 0; + BufferValueCursor = 0; + memset (TheParameter.Name, 0, FILE_MAX_PAR_VAR_SIZE); + memset (TheParameter.Value, 0, FILE_MAX_PAR_VAR_SIZE); + } - FirstChar = 0; - SeparatorChar = 0; - ParameterChar = 0; + FirstChar = 0; + SeparatorChar = 0; + ParameterChar = 0; - if ((char) c == '\0') - { - break; - } - } - else - { - //printf("Checking chars"); + if ((char) c == '\0') + { + break; + } + } + else + { + //printf("Checking chars"); - //first char, parameter name - if (FirstChar == 0) - { - FirstChar = (char) c; - //printf("FirstChar = %c", FirstChar); - } - else if (FirstChar != 0 && SeparatorChar == 0 && (char) c == '=') - { - SeparatorChar = (char) c; - //printf("SeparatorChar = %c", SeparatorChar); - } - else if (FirstChar != 0 && SeparatorChar != 0 && ParameterChar == 0) - { - ParameterChar = (char) c; - //printf("ParameterChar = %c", ParameterChar); - } + //first char, parameter name + if (FirstChar == 0) + { + FirstChar = (char) c; + //printf("FirstChar = %c", FirstChar); + } + else if (FirstChar != 0 && SeparatorChar == 0 && (char) c == '=') + { + SeparatorChar = (char) c; + //printf("SeparatorChar = %c", SeparatorChar); + } + else if (FirstChar != 0 && SeparatorChar != 0 && ParameterChar == 0) + { + ParameterChar = (char) c; + //printf("ParameterChar = %c", ParameterChar); + } - //Get the parameter name - if ( FirstChar != '#' && FirstChar != 0 && SeparatorChar == 0 && BufferNameCursor < FILE_MAX_PAR_VAR_SIZE ) - if(BufferNameCursor < FILE_MAX_PAR_VAR_SIZE) - TheParameter.Name[BufferNameCursor++] = (char) c; + //Get the parameter name + if ( FirstChar != '#' && FirstChar != 0 && SeparatorChar == 0 && BufferNameCursor < FILE_MAX_PAR_VAR_SIZE ) + if(BufferNameCursor < FILE_MAX_PAR_VAR_SIZE) + TheParameter.Name[BufferNameCursor++] = (char) c; - //Get the parameter value - if ( FirstChar != '#' && FirstChar != 0 && SeparatorChar != 0 && ParameterChar != 0 && BufferValueCursor < FILE_MAX_PAR_VAR_SIZE ) - if(BufferValueCursor < FILE_MAX_PAR_VAR_SIZE) - TheParameter.Value[BufferValueCursor++] = (char) c; - } - } - } + //Get the parameter value + if ( FirstChar != '#' && FirstChar != 0 && SeparatorChar != 0 && ParameterChar != 0 && BufferValueCursor < FILE_MAX_PAR_VAR_SIZE ) + if(BufferValueCursor < FILE_MAX_PAR_VAR_SIZE) + TheParameter.Value[BufferValueCursor++] = (char) c; + } + } + } - fclose(File); - } + 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); - } + for (i = 0; i < ParametersVector->Size; i++) + { + printf("ParametersVector->Data[%d])->Name = %s",i, ((FILE_StringParameter_DataType *)ParametersVector->Data[i])->Name); + } - qsort(ParametersVector->Data, ParametersVector->Size, sizeof(void *), FILE_CompareStringParameter); + qsort(ParametersVector->Data, ParametersVector->Size, sizeof(void *), FILE_CompareStringParameter); - printf("Sorted"); - for (i = 0; i < ParametersVector->Size; i++) - { - printf("ParametersVector->Data[%d])->Name = %s",i, ((FILE_StringParameter_DataType *)ParametersVector->Data[i])->Name); - } + printf("Sorted"); + for (i = 0; i < ParametersVector->Size; i++) + { + printf("ParametersVector->Data[%d])->Name = %s",i, ((FILE_StringParameter_DataType *)ParametersVector->Data[i])->Name); + } - } +} int FILE_StringParametersLinearySearch(DYNV_VectorGenericDataType *TheVectorGeneric, void * name) - { - int i; - for(i=0; iSize; i++) - { - if(strcmp(((FILE_StringParameter_DataType *)TheVectorGeneric->Data[i])->Name, (char *) name) == 0) - { - return i; - } - } - return -1; - } +{ + int i; + for(i=0; iSize; i++) + { + if(strcmp(((FILE_StringParameter_DataType *)TheVectorGeneric->Data[i])->Name, (char *) name) == 0) + { + return i; + } + } + return -1; +} int FILE_StringParametersBinarySearch(DYNV_VectorGenericDataType *TheVectorGeneric, void * Needle) { @@ -490,47 +494,40 @@ time_t FILE_GetLastModifiedData(char *path) void FILE_AppendToString(char ** sourceString, char *theString) { - //printf("\n sourcestring = %s", *sourceString); - //printf("\n theString = %s", theString); - - int theNewSize = strlen(*sourceString) + strlen(theString); - *sourceString = realloc(*sourceString, theNewSize + 10); - strcat(*sourceString, theString); - (*sourceString)[theNewSize] = '\0'; - - // printf("\n sourcestring = %s", *sourceString); - // printf("\n theString = %s", theString); - // printf("\n theNewSize = %d", theNewSize); + int theNewSize = strlen(*sourceString) + strlen(theString); + *sourceString = realloc(*sourceString, theNewSize + 10); + strcat(*sourceString, theString); + (*sourceString)[theNewSize] = '\0'; } void FILE_DirectoryToParent(char ** sourceString) { - //printf("\n"); - int i = 0, theLastSlash = -1, strLen = 0; - - strLen = strlen(*sourceString); - //printf("\nstrLen = %d", strLen); - - for (i = 0; i < strLen; i++) - { - //printf("%c", (*sourceString)[i]); - if ( (*sourceString)[i] == '/') - { - theLastSlash = i; - //printf("\n theLastSlash = %d", theLastSlash); - } - } + //printf("\n"); + int i = 0, theLastSlash = -1, strLen = 0; - if (theLastSlash > -1) - { - int theNewSize = theLastSlash; - if (theLastSlash == 0) - { - theNewSize = 1; - } - *sourceString = realloc(*sourceString, theNewSize+1); - (*sourceString)[theNewSize] = '\0'; - } + strLen = strlen(*sourceString); + //printf("\nstrLen = %d", strLen); + + for (i = 0; i < strLen; i++) + { + //printf("%c", (*sourceString)[i]); + if ( (*sourceString)[i] == '/') + { + theLastSlash = i; + //printf("\n theLastSlash = %d", theLastSlash); + } + } + + if (theLastSlash > -1) + { + int theNewSize = theLastSlash; + if (theLastSlash == 0) + { + theNewSize = 1; + } + *sourceString = realloc(*sourceString, theNewSize+1); + (*sourceString)[theNewSize] = '\0'; + } } diff --git a/library/fileManagement.h b/library/fileManagement.h index 0277ae6..a1c4915 100644 --- a/library/fileManagement.h +++ b/library/fileManagement.h @@ -23,7 +23,7 @@ */ #ifndef GEN_FILE_MANAGEMENT_TYPES - + #define _LARGEFILE64_SOURCE #include #include #include @@ -48,9 +48,9 @@ } FILE_fileInfo_DataType; - int FILE_GetFileSize(FILE *theFilePointer); + long long int FILE_GetFileSize(FILE *theFilePointer); long int FILE_GetAvailableSpace(const char* ThePath); - int FILE_GetFileSizeFromPath(char *TheFileName); + long long int FILE_GetFileSizeFromPath(char *TheFileName); int FILE_IsFile(const char *theFileName); int FILE_IsDirectory (char *directory_path); void FILE_GetDirectoryInodeList(char * DirectoryInodeName, char *** InodeList, int * filesandfolders, int recursive); diff --git a/library/logFunctions.c b/library/logFunctions.c index dd19bf6..0a7ffdd 100644 --- a/library/logFunctions.c +++ b/library/logFunctions.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#define _LARGEFILE64_SOURCE #include #include "logFunctions.h" diff --git a/library/signals.c b/library/signals.c index 65a4c47..0dc7efe 100644 --- a/library/signals.c +++ b/library/signals.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#define _LARGEFILE64_SOURCE #include #include diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 752dd27..3fb12a8 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -7,10 +7,7 @@ - file:/home/ugo/NetBeansProjects/uFTP/ftpData.c - file:/home/ugo/NetBeansProjects/uFTP/ftpCommandElaborate.c file:/home/ugo/NetBeansProjects/uFTP/ftpServer.c - file:/home/ugo/NetBeansProjects/uFTP/uFTP.c file:/home/ugo/NetBeansProjects/uFTP/library/configRead.c diff --git a/uFTP.c b/uFTP.c index 8895c92..b7d62d3 100644 --- a/uFTP.c +++ b/uFTP.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#define _LARGEFILE64_SOURCE #include #include @@ -30,5 +31,4 @@ int main(int argc, char** argv) { runFtpServer(); return (EXIT_SUCCESS); -} - +} \ No newline at end of file