Some debug with valgrind, fixed rnto returncode variable scope issue

This commit is contained in:
Ugo Cirmignani
2018-12-01 16:21:33 +01:00
parent 228eb8d222
commit a497187993
40 changed files with 206 additions and 387 deletions

View File

@ -1,71 +0,0 @@
#Linux Generic
CC=gcc
OUTPATH=./build/
SOURCE_MODULES_PATH=./library/
#FOR DEBUG PURPOSE
CFLAGS=-c -Wall -I. -g -O0
#CFLAGS=-c -Wall -I.
OPTIMIZATION=-O3
HEADERS=-I
LIBPATH=./build/modules/
BUILDFILES=start uFTP end
LIBS=-lpthread -lssl -lcrypto
#DEFINITIONS=
#TO ENABLE THE LARGE FILE SUPPORT UNCOMMENT THE NEXT LINE
DEFINITIONS=-D_LARGEFILE64_SOURCE
all: $(BUILDFILES)
start:
@echo Compiler: $(CC)
@echo Output Directory: $(OUTPATH)
@echo CGI FILES: $(BUILDFILES)
@rm -rf $(LIBPATH)*.o $(OUTPATH)uFTP
@echo "Clean ok"
end:
@echo Build process end
uFTP: uFTP.c fileManagement.o configRead.o logFunctions.o ftpCommandElaborate.o ftpData.o ftpServer.o daemon.o signals.o connection.o openSsl.o
@$(CC) $(DEFINITIONS) uFTP.c $(LIBPATH)dynamicVectors.o $(LIBPATH)fileManagement.o $(LIBPATH)configRead.o $(LIBPATH)logFunctions.o $(LIBPATH)ftpCommandElaborate.o $(LIBPATH)ftpData.o $(LIBPATH)ftpServer.o $(LIBPATH)daemon.o $(LIBPATH)signals.o $(LIBPATH)connection.o $(LIBPATH)openSsl.o -o $(OUTPATH)uFTP $(LIBS)
daemon.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)daemon.c -o $(LIBPATH)daemon.o
dynamicVectors.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)dynamicVectors.c -o $(LIBPATH)dynamicVectors.o
openSsl.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)openSsl.c -o $(LIBPATH)openSsl.o
configRead.o: dynamicVectors.o fileManagement.o
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)configRead.c -o $(LIBPATH)configRead.o
fileManagement.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)fileManagement.c -o $(LIBPATH)fileManagement.o
signals.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)signals.c -o $(LIBPATH)signals.o
connection.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)connection.c -o $(LIBPATH)connection.o
logFunctions.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)logFunctions.c -o $(LIBPATH)logFunctions.o
ftpCommandElaborate.o:
@$(CC) $(CFLAGS) ftpCommandElaborate.c -o $(LIBPATH)ftpCommandElaborate.o
ftpData.o:
@$(CC) $(CFLAGS) ftpData.c -o $(LIBPATH)ftpData.o
ftpServer.o: openSsl.o
@$(CC) $(CFLAGS) ftpServer.c -o $(LIBPATH)ftpServer.o
clean:
@rm -rf $(LIBPATH)*.o $(OUTPATH)uFTP
@echo "Clean ok"

159
Makefile
View File

@ -1,128 +1,71 @@
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_PLATFORM_${CONF} platform name (current configuration)
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
#Linux Generic
CC=gcc
OUTPATH=./build/
SOURCE_MODULES_PATH=./library/
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
#FOR DEBUG PURPOSE
CFLAGS=-c -Wall -I. -g -O0
#CFLAGS=-c -Wall -I.
OPTIMIZATION=-O3
HEADERS=-I
LIBPATH=./build/modules/
BUILDFILES=start uFTP end
LIBS=-lpthread -lssl -lcrypto
#DEFINITIONS=
# build
build: .build-post
#TO ENABLE THE LARGE FILE SUPPORT UNCOMMENT THE NEXT LINE
DEFINITIONS=-D_LARGEFILE64_SOURCE
.build-pre:
# Add your pre 'build' code here...
all: $(BUILDFILES)
.build-post: .build-impl
# Add your post 'build' code here...
start:
@echo Compiler: $(CC)
@echo Output Directory: $(OUTPATH)
@echo CGI FILES: $(BUILDFILES)
@rm -rf $(LIBPATH)*.o $(OUTPATH)uFTP
@echo "Clean ok"
end:
@echo Build process end
# clean
clean: .clean-post
uFTP: uFTP.c fileManagement.o configRead.o logFunctions.o ftpCommandElaborate.o ftpData.o ftpServer.o daemon.o signals.o connection.o openSsl.o
@$(CC) $(DEFINITIONS) uFTP.c $(LIBPATH)dynamicVectors.o $(LIBPATH)fileManagement.o $(LIBPATH)configRead.o $(LIBPATH)logFunctions.o $(LIBPATH)ftpCommandElaborate.o $(LIBPATH)ftpData.o $(LIBPATH)ftpServer.o $(LIBPATH)daemon.o $(LIBPATH)signals.o $(LIBPATH)connection.o $(LIBPATH)openSsl.o -o $(OUTPATH)uFTP $(LIBS)
.clean-pre:
# Add your pre 'clean' code here...
daemon.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)daemon.c -o $(LIBPATH)daemon.o
.clean-post: .clean-impl
# Add your post 'clean' code here...
dynamicVectors.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)dynamicVectors.c -o $(LIBPATH)dynamicVectors.o
openSsl.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)openSsl.c -o $(LIBPATH)openSsl.o
# clobber
clobber: .clobber-post
configRead.o: dynamicVectors.o fileManagement.o
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)configRead.c -o $(LIBPATH)configRead.o
.clobber-pre:
# Add your pre 'clobber' code here...
fileManagement.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)fileManagement.c -o $(LIBPATH)fileManagement.o
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
signals.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)signals.c -o $(LIBPATH)signals.o
connection.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)connection.c -o $(LIBPATH)connection.o
# all
all: .all-post
logFunctions.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)logFunctions.c -o $(LIBPATH)logFunctions.o
.all-pre:
# Add your pre 'all' code here...
ftpCommandElaborate.o:
@$(CC) $(CFLAGS) ftpCommandElaborate.c -o $(LIBPATH)ftpCommandElaborate.o
.all-post: .all-impl
# Add your post 'all' code here...
ftpData.o:
@$(CC) $(CFLAGS) ftpData.c -o $(LIBPATH)ftpData.o
ftpServer.o: openSsl.o
@$(CC) $(CFLAGS) ftpServer.c -o $(LIBPATH)ftpServer.o
# build tests
build-tests: .build-tests-post
.build-tests-pre:
# Add your pre 'build-tests' code here...
.build-tests-post: .build-tests-impl
# Add your post 'build-tests' code here...
# run tests
test: .test-post
.test-pre: build-tests
# Add your pre 'test' code here...
.test-post: .test-impl
# Add your post 'test' code here...
# help
help: .help-post
.help-pre:
# Add your pre 'help' code here...
.help-post: .help-impl
# Add your post 'help' code here...
# include project implementation makefile
include nbproject/Makefile-impl.mk
# include project make variables
include nbproject/Makefile-variables.mk
clean:
@rm -rf $(LIBPATH)*.o $(OUTPATH)uFTP
@echo "Clean ok"

128
MakefileNetBeans Normal file
View File

@ -0,0 +1,128 @@
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_PLATFORM_${CONF} platform name (current configuration)
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
# build
build: .build-post
.build-pre:
# Add your pre 'build' code here...
.build-post: .build-impl
# Add your post 'build' code here...
# clean
clean: .clean-post
.clean-pre:
# Add your pre 'clean' code here...
.clean-post: .clean-impl
# Add your post 'clean' code here...
# clobber
clobber: .clobber-post
.clobber-pre:
# Add your pre 'clobber' code here...
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
# all
all: .all-post
.all-pre:
# Add your pre 'all' code here...
.all-post: .all-impl
# Add your post 'all' code here...
# build tests
build-tests: .build-tests-post
.build-tests-pre:
# Add your pre 'build-tests' code here...
.build-tests-post: .build-tests-impl
# Add your post 'build-tests' code here...
# run tests
test: .test-post
.test-pre: build-tests
# Add your pre 'test' code here...
.test-post: .test-impl
# Add your post 'test' code here...
# help
help: .help-post
.help-pre:
# Add your pre 'help' code here...
.help-post: .help-impl
# Add your post 'help' code here...
# include project implementation makefile
include nbproject/Makefile-impl.mk
# include project make variables
include nbproject/Makefile-variables.mk

View File

@ -1,32 +0,0 @@
build/Debug/GNU-Linux/ftpCommandElaborate.o: ftpCommandElaborate.c \
library/dynamicVectors.h library/fileManagement.h \
library/dynamicVectors.h ftpData.h library/dynamicVectors.h ftpServer.h \
library/logFunctions.h library/fileManagement.h library/configRead.h \
library/dynamicVectors.h library/../ftpData.h library/openSsl.h \
ftpCommandsElaborate.h
library/dynamicVectors.h:
library/fileManagement.h:
library/dynamicVectors.h:
ftpData.h:
library/dynamicVectors.h:
ftpServer.h:
library/logFunctions.h:
library/fileManagement.h:
library/configRead.h:
library/dynamicVectors.h:
library/../ftpData.h:
library/openSsl.h:
ftpCommandsElaborate.h:

Binary file not shown.

View File

@ -1,27 +0,0 @@
build/Debug/GNU-Linux/ftpData.o: ftpData.c library/dynamicVectors.h \
library/fileManagement.h library/dynamicVectors.h ftpServer.h \
ftpCommandsElaborate.h ftpData.h library/dynamicVectors.h \
library/configRead.h library/dynamicVectors.h library/../ftpData.h \
library/fileManagement.h
library/dynamicVectors.h:
library/fileManagement.h:
library/dynamicVectors.h:
ftpServer.h:
ftpCommandsElaborate.h:
ftpData.h:
library/dynamicVectors.h:
library/configRead.h:
library/dynamicVectors.h:
library/../ftpData.h:
library/fileManagement.h:

Binary file not shown.

View File

@ -1,36 +0,0 @@
build/Debug/GNU-Linux/ftpServer.o: ftpServer.c library/dynamicVectors.h \
library/fileManagement.h library/dynamicVectors.h ftpServer.h ftpData.h \
library/dynamicVectors.h ftpCommandsElaborate.h library/fileManagement.h \
library/logFunctions.h library/configRead.h library/dynamicVectors.h \
library/../ftpData.h library/signals.h library/openSsl.h \
library/connection.h
library/dynamicVectors.h:
library/fileManagement.h:
library/dynamicVectors.h:
ftpServer.h:
ftpData.h:
library/dynamicVectors.h:
ftpCommandsElaborate.h:
library/fileManagement.h:
library/logFunctions.h:
library/configRead.h:
library/dynamicVectors.h:
library/../ftpData.h:
library/signals.h:
library/openSsl.h:
library/connection.h:

Binary file not shown.

View File

@ -1,20 +0,0 @@
build/Release/GNU-Linux/ftpData.o: ftpData.c ftpServer.h \
ftpCommandsElaborate.h ftpData.h library/dynamicVectors.h \
library/configRead.h library/dynamicVectors.h library/../ftpData.h \
library/fileManagement.h
ftpServer.h:
ftpCommandsElaborate.h:
ftpData.h:
library/dynamicVectors.h:
library/configRead.h:
library/dynamicVectors.h:
library/../ftpData.h:
library/fileManagement.h:

Binary file not shown.

View File

@ -1,26 +0,0 @@
build/Release/GNU-Linux/ftpServer.o: ftpServer.c ftpServer.h ftpData.h \
library/dynamicVectors.h ftpCommandsElaborate.h library/fileManagement.h \
library/dynamicVectors.h library/logFunctions.h library/configRead.h \
library/../ftpData.h library/signals.h library/connection.h
ftpServer.h:
ftpData.h:
library/dynamicVectors.h:
ftpCommandsElaborate.h:
library/fileManagement.h:
library/dynamicVectors.h:
library/logFunctions.h:
library/configRead.h:
library/../ftpData.h:
library/signals.h:
library/connection.h:

View File

@ -1,16 +0,0 @@
build/Release/GNU-Linux/library/configRead.o: library/configRead.c \
library/configRead.h library/dynamicVectors.h library/../ftpData.h \
library/../library/dynamicVectors.h library/fileManagement.h \
library/daemon.h
library/configRead.h:
library/dynamicVectors.h:
library/../ftpData.h:
library/../library/dynamicVectors.h:
library/fileManagement.h:
library/daemon.h:

View File

@ -1,9 +0,0 @@
build/Release/GNU-Linux/library/connection.o: library/connection.c \
library/../ftpData.h library/../library/dynamicVectors.h \
library/connection.h
library/../ftpData.h:
library/../library/dynamicVectors.h:
library/connection.h:

View File

@ -1,6 +0,0 @@
build/Release/GNU-Linux/library/daemon.o: library/daemon.c \
library/fileManagement.h library/dynamicVectors.h
library/fileManagement.h:
library/dynamicVectors.h:

View File

@ -1,4 +0,0 @@
build/Release/GNU-Linux/library/dynamicVectors.o: \
library/dynamicVectors.c library/dynamicVectors.h
library/dynamicVectors.h:

View File

@ -1,7 +0,0 @@
build/Release/GNU-Linux/library/fileManagement.o: \
library/fileManagement.c library/fileManagement.h \
library/dynamicVectors.h
library/fileManagement.h:
library/dynamicVectors.h:

View File

@ -1,4 +0,0 @@
build/Release/GNU-Linux/library/logFunctions.o: library/logFunctions.c \
library/logFunctions.h
library/logFunctions.h:

View File

@ -1,4 +0,0 @@
build/Release/GNU-Linux/library/signals.o: library/signals.c \
library/../ftpServer.h
library/../ftpServer.h:

Binary file not shown.

View File

@ -1,3 +0,0 @@
build/Release/GNU-Linux/uFTP.o: uFTP.c ftpServer.h
ftpServer.h:

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -342,6 +342,7 @@ int parseCommandPasv(ftpDataType * data, int socketId)
{
/* Create worker thread */
void *pReturn;
printf("\n data->clients[%d].workerData.workerThread = %d",socketId, (int)data->clients[socketId].workerData.workerThread);
if (data->clients[socketId].workerData.threadIsAlive == 1)
{
@ -977,7 +978,7 @@ int parseCommandRnfr(clientDataType *theClientData)
int parseCommandRnto(clientDataType *theClientData)
{
int returnCode;
int returnCode = 0;
int isSafePath;
char *theRntoFileName;
@ -993,29 +994,39 @@ int parseCommandRnto(clientDataType *theClientData)
if (FILE_IsFile(theClientData->renameFromFile.text) == 1 ||
FILE_IsDirectory(theClientData->renameFromFile.text) == 1)
{
int returnCode = 0;
returnCode = rename (theClientData->renameFromFile.text, theClientData->renameToFile.text);
if (returnCode == 0)
{
printf("\n250 File successfully renamed or moved");
returnCode = dprintf(theClientData->socketDescriptor, "250 File successfully renamed or moved\r\n");
}
else
{
printf("\n503 Error Renaming the file");
returnCode = dprintf(theClientData->socketDescriptor, "503 Error Renaming the file\r\n");
}
}
else
{
printf("\n503 Need RNFR before RNTO");
returnCode = dprintf(theClientData->socketDescriptor, "503 Need RNFR before RNTO\r\n");
}
}
else
{
printf("\n503 Error Renaming the file");
returnCode = dprintf(theClientData->socketDescriptor, "503 Error Renaming the file\r\n");
}
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
if (returnCode <= 0)
{
printf("\, parseCommandRnto return code: %d", returnCode);
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
}
else {
return FTP_COMMAND_PROCESSED;
}
}
int parseCommandCdup(clientDataType *theClientData)
@ -1294,7 +1305,7 @@ int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataTyp
}
returnCode = strtol(thePermissionString, 0, 8);
if (returnCodeSetPermissions = chmod (theFinalFilename, returnCode) < 0)
if ((returnCodeSetPermissions = chmod (theFinalFilename, returnCode)) < 0)
{
printf("\n---> ERROR WHILE SETTING FILE PERMISSION");
}

View File

@ -372,7 +372,9 @@ int writeListDataInfoToSocket(char * thePath, int theSocket, int *filesNumber, i
}
if (fileList != NULL)
{
free (fileList);
}
return 1;
}
@ -579,6 +581,7 @@ void resetWorkerData(workerDataType *workerData, int isInitialization)
{
DYNV_VectorGeneric_Init(&workerData->directoryInfo);
workerData->theStorFile = NULL;
workerData->workerThread = 0;
}
pthread_mutex_init(&workerData->conditionMutex, NULL);

View File

@ -428,6 +428,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);
commandProcessStatus = processCommand(processingSock);
//Echo unrecognized commands
if (commandProcessStatus == FTP_COMMAND_NOT_RECONIZED)
@ -448,7 +449,7 @@ void runFtpServer(void)
else if (commandProcessStatus == FTP_COMMAND_PROCESSED_WRITE_ERROR)
{
ftpData.clients[processingSock].closeTheClient = 1;
printf("\n Write error, closing the client!");
printf("\n Write error WARNING!");
}
}
}

View File

@ -6,8 +6,6 @@
</data>
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/ugo/NetBeansProjects/uFTP/MakeFileGeneric</file>
</group>
<group/>
</open-files>
</project-private>