diff --git a/MakeFileGeneric b/MakeFileGeneric deleted file mode 100644 index 19044e1..0000000 --- a/MakeFileGeneric +++ /dev/null @@ -1,67 +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 - -#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 - @$(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 -o $(OUTPATH)uFTP -lpthread - -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 - -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: - @$(CC) $(CFLAGS) ftpServer.c -o $(LIBPATH)ftpServer.o - -clean: - @rm -rf $(LIBPATH)*.o $(OUTPATH)uFTP - @echo "Clean ok" diff --git a/Makefile b/Makefile index 05de621..e6710f2 100644 --- a/Makefile +++ b/Makefile @@ -1,128 +1,78 @@ -# -# 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/ + +#FOR DEBUG PURPOSE +CFLAGSTEMP=-c -Wall -I. -g -O0 +#CFLAGSTEMP=-c -Wall -I. +OPTIMIZATION=-O3 +HEADERS=-I +LIBPATH=./build/modules/ +BUILDFILES=start uFTP end +LIBS=-lpthread -# Environment -MKDIR=mkdir -CP=cp -CCADMIN=CCadmin +#ENABLE_LARGE_FILE_SUPPORT= +#TO ENABLE THE LARGE FILE SUPPORT UNCOMMENT THE NEXT LINE +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 -# build -build: .build-post +CFLAGS=$(CFLAGSTEMP) $(ENABLE_LARGE_FILE_SUPPORT) $(ENABLE_OPENSSL_SUPPORT) -.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) $(ENABLE_LARGE_FILE_SUPPORT) $(ENABLE_OPENSSL_SUPPORT) 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 +configRead.o: dynamicVectors.o fileManagement.o + @$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)configRead.c -o $(LIBPATH)configRead.o -# clobber -clobber: .clobber-post +fileManagement.o: + @$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)fileManagement.c -o $(LIBPATH)fileManagement.o -.clobber-pre: -# Add your pre '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 -.clobber-post: .clobber-impl -# Add your post 'clobber' code here... +logFunctions.o: + @$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)logFunctions.c -o $(LIBPATH)logFunctions.o +ftpCommandElaborate.o: + @$(CC) $(CFLAGS) ftpCommandElaborate.c -o $(LIBPATH)ftpCommandElaborate.o -# all -all: .all-post +ftpData.o: + @$(CC) $(CFLAGS) ftpData.c -o $(LIBPATH)ftpData.o -.all-pre: -# Add your pre 'all' code here... +ftpServer.o: openSsl.o + @$(CC) $(CFLAGS) ftpServer.c -o $(LIBPATH)ftpServer.o -.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 +clean: + @rm -rf $(LIBPATH)*.o $(OUTPATH)uFTP + @echo "Clean ok" diff --git a/MakefileNetBeans b/MakefileNetBeans new file mode 100644 index 0000000..05de621 --- /dev/null +++ b/MakefileNetBeans @@ -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 diff --git a/README.md b/README.md index 5a57fd6..0b4bfb8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,132 @@ -# uFTP -This project is a very easy to configure and light FTP server designed for servers, embedded arm devices and every other common usage. +About uFTP + +uFTP is a light FTP server designed for servers and embedded arm devices, is provided under MIT license terms. Visit the official project website to obtain more information: http://www.uftpserver.com/ + +This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (http://www.openssl.org) + +The MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + + OpenSSL License + --------------- + +/* ==================================================================== + * Copyright (c) 1998-2018 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + + Original SSLeay License + ----------------------- + +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + \ No newline at end of file diff --git a/build/Debug/GNU-Linux/ftpCommandElaborate.o b/build/Debug/GNU-Linux/ftpCommandElaborate.o deleted file mode 100644 index bd9195e..0000000 Binary files a/build/Debug/GNU-Linux/ftpCommandElaborate.o and /dev/null differ diff --git a/build/Debug/GNU-Linux/ftpCommandElaborate.o.d b/build/Debug/GNU-Linux/ftpCommandElaborate.o.d deleted file mode 100644 index 3f031c8..0000000 --- a/build/Debug/GNU-Linux/ftpCommandElaborate.o.d +++ /dev/null @@ -1,29 +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 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: - -ftpCommandsElaborate.h: diff --git a/build/Debug/GNU-Linux/ftpData.o b/build/Debug/GNU-Linux/ftpData.o deleted file mode 100644 index 373b8d9..0000000 Binary files a/build/Debug/GNU-Linux/ftpData.o and /dev/null differ diff --git a/build/Debug/GNU-Linux/ftpData.o.d b/build/Debug/GNU-Linux/ftpData.o.d deleted file mode 100644 index 32965f1..0000000 --- a/build/Debug/GNU-Linux/ftpData.o.d +++ /dev/null @@ -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: diff --git a/build/Debug/GNU-Linux/ftpServer.o b/build/Debug/GNU-Linux/ftpServer.o deleted file mode 100644 index ec6abe0..0000000 Binary files a/build/Debug/GNU-Linux/ftpServer.o and /dev/null differ diff --git a/build/Debug/GNU-Linux/ftpServer.o.d b/build/Debug/GNU-Linux/ftpServer.o.d deleted file mode 100644 index 0b9ef77..0000000 --- a/build/Debug/GNU-Linux/ftpServer.o.d +++ /dev/null @@ -1,33 +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/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/connection.h: diff --git a/build/Debug/GNU-Linux/library/configRead.o b/build/Debug/GNU-Linux/library/configRead.o deleted file mode 100644 index 2c3a8fe..0000000 Binary files a/build/Debug/GNU-Linux/library/configRead.o and /dev/null differ diff --git a/build/Debug/GNU-Linux/library/configRead.o.d b/build/Debug/GNU-Linux/library/configRead.o.d deleted file mode 100644 index 18058fc..0000000 --- a/build/Debug/GNU-Linux/library/configRead.o.d +++ /dev/null @@ -1,23 +0,0 @@ -build/Debug/GNU-Linux/library/configRead.o: library/configRead.c \ - library/dynamicVectors.h library/fileManagement.h \ - library/dynamicVectors.h library/configRead.h library/dynamicVectors.h \ - library/../ftpData.h library/../library/dynamicVectors.h \ - library/fileManagement.h library/daemon.h - -library/dynamicVectors.h: - -library/fileManagement.h: - -library/dynamicVectors.h: - -library/configRead.h: - -library/dynamicVectors.h: - -library/../ftpData.h: - -library/../library/dynamicVectors.h: - -library/fileManagement.h: - -library/daemon.h: diff --git a/build/Debug/GNU-Linux/library/connection.o b/build/Debug/GNU-Linux/library/connection.o deleted file mode 100644 index 7d8dc8c..0000000 Binary files a/build/Debug/GNU-Linux/library/connection.o and /dev/null differ diff --git a/build/Debug/GNU-Linux/library/connection.o.d b/build/Debug/GNU-Linux/library/connection.o.d deleted file mode 100644 index 9cfe267..0000000 --- a/build/Debug/GNU-Linux/library/connection.o.d +++ /dev/null @@ -1,16 +0,0 @@ -build/Debug/GNU-Linux/library/connection.o: library/connection.c \ - library/dynamicVectors.h library/fileManagement.h \ - library/dynamicVectors.h library/../ftpData.h \ - library/../library/dynamicVectors.h library/connection.h - -library/dynamicVectors.h: - -library/fileManagement.h: - -library/dynamicVectors.h: - -library/../ftpData.h: - -library/../library/dynamicVectors.h: - -library/connection.h: diff --git a/build/Debug/GNU-Linux/library/daemon.o b/build/Debug/GNU-Linux/library/daemon.o deleted file mode 100644 index c233c0f..0000000 Binary files a/build/Debug/GNU-Linux/library/daemon.o and /dev/null differ diff --git a/build/Debug/GNU-Linux/library/daemon.o.d b/build/Debug/GNU-Linux/library/daemon.o.d deleted file mode 100644 index 87c2092..0000000 --- a/build/Debug/GNU-Linux/library/daemon.o.d +++ /dev/null @@ -1,11 +0,0 @@ -build/Debug/GNU-Linux/library/daemon.o: library/daemon.c \ - library/dynamicVectors.h library/fileManagement.h \ - library/dynamicVectors.h library/fileManagement.h - -library/dynamicVectors.h: - -library/fileManagement.h: - -library/dynamicVectors.h: - -library/fileManagement.h: diff --git a/build/Debug/GNU-Linux/library/dynamicVectors.o b/build/Debug/GNU-Linux/library/dynamicVectors.o deleted file mode 100644 index b1fe279..0000000 Binary files a/build/Debug/GNU-Linux/library/dynamicVectors.o and /dev/null differ diff --git a/build/Debug/GNU-Linux/library/dynamicVectors.o.d b/build/Debug/GNU-Linux/library/dynamicVectors.o.d deleted file mode 100644 index a02322d..0000000 --- a/build/Debug/GNU-Linux/library/dynamicVectors.o.d +++ /dev/null @@ -1,11 +0,0 @@ -build/Debug/GNU-Linux/library/dynamicVectors.o: library/dynamicVectors.c \ - library/dynamicVectors.h library/fileManagement.h \ - library/dynamicVectors.h library/dynamicVectors.h - -library/dynamicVectors.h: - -library/fileManagement.h: - -library/dynamicVectors.h: - -library/dynamicVectors.h: diff --git a/build/Debug/GNU-Linux/library/fileManagement.o b/build/Debug/GNU-Linux/library/fileManagement.o deleted file mode 100644 index 5ecefd3..0000000 Binary files a/build/Debug/GNU-Linux/library/fileManagement.o and /dev/null differ diff --git a/build/Debug/GNU-Linux/library/fileManagement.o.d b/build/Debug/GNU-Linux/library/fileManagement.o.d deleted file mode 100644 index 78e7134..0000000 --- a/build/Debug/GNU-Linux/library/fileManagement.o.d +++ /dev/null @@ -1,14 +0,0 @@ -build/Debug/GNU-Linux/library/fileManagement.o: library/fileManagement.c \ - library/dynamicVectors.h library/fileManagement.h \ - library/dynamicVectors.h library/fileManagement.h \ - library/dynamicVectors.h - -library/dynamicVectors.h: - -library/fileManagement.h: - -library/dynamicVectors.h: - -library/fileManagement.h: - -library/dynamicVectors.h: diff --git a/build/Debug/GNU-Linux/library/logFunctions.o b/build/Debug/GNU-Linux/library/logFunctions.o deleted file mode 100644 index 6b5f61c..0000000 Binary files a/build/Debug/GNU-Linux/library/logFunctions.o and /dev/null differ diff --git a/build/Debug/GNU-Linux/library/logFunctions.o.d b/build/Debug/GNU-Linux/library/logFunctions.o.d deleted file mode 100644 index e52d825..0000000 --- a/build/Debug/GNU-Linux/library/logFunctions.o.d +++ /dev/null @@ -1,11 +0,0 @@ -build/Debug/GNU-Linux/library/logFunctions.o: library/logFunctions.c \ - library/dynamicVectors.h library/fileManagement.h \ - library/dynamicVectors.h library/logFunctions.h - -library/dynamicVectors.h: - -library/fileManagement.h: - -library/dynamicVectors.h: - -library/logFunctions.h: diff --git a/build/Debug/GNU-Linux/library/signals.o b/build/Debug/GNU-Linux/library/signals.o deleted file mode 100644 index 78c4af6..0000000 Binary files a/build/Debug/GNU-Linux/library/signals.o and /dev/null differ diff --git a/build/Debug/GNU-Linux/library/signals.o.d b/build/Debug/GNU-Linux/library/signals.o.d deleted file mode 100644 index ff9cc4d..0000000 --- a/build/Debug/GNU-Linux/library/signals.o.d +++ /dev/null @@ -1,11 +0,0 @@ -build/Debug/GNU-Linux/library/signals.o: library/signals.c \ - library/dynamicVectors.h library/fileManagement.h \ - library/dynamicVectors.h library/../ftpServer.h - -library/dynamicVectors.h: - -library/fileManagement.h: - -library/dynamicVectors.h: - -library/../ftpServer.h: diff --git a/build/Debug/GNU-Linux/uFTP.o b/build/Debug/GNU-Linux/uFTP.o deleted file mode 100644 index 63c9847..0000000 Binary files a/build/Debug/GNU-Linux/uFTP.o and /dev/null differ diff --git a/build/Debug/GNU-Linux/uFTP.o.d b/build/Debug/GNU-Linux/uFTP.o.d deleted file mode 100644 index 2e331b6..0000000 --- a/build/Debug/GNU-Linux/uFTP.o.d +++ /dev/null @@ -1,10 +0,0 @@ -build/Debug/GNU-Linux/uFTP.o: uFTP.c library/dynamicVectors.h \ - library/fileManagement.h library/dynamicVectors.h ftpServer.h - -library/dynamicVectors.h: - -library/fileManagement.h: - -library/dynamicVectors.h: - -ftpServer.h: diff --git a/build/Release/GNU-Linux/ftpCommandElaborate.o b/build/Release/GNU-Linux/ftpCommandElaborate.o deleted file mode 100644 index 4f26c9a..0000000 Binary files a/build/Release/GNU-Linux/ftpCommandElaborate.o and /dev/null differ diff --git a/build/Release/GNU-Linux/ftpCommandElaborate.o.d b/build/Release/GNU-Linux/ftpCommandElaborate.o.d deleted file mode 100644 index 89264c2..0000000 --- a/build/Release/GNU-Linux/ftpCommandElaborate.o.d +++ /dev/null @@ -1,22 +0,0 @@ -build/Release/GNU-Linux/ftpCommandElaborate.o: ftpCommandElaborate.c \ - ftpData.h library/dynamicVectors.h ftpServer.h library/logFunctions.h \ - library/fileManagement.h library/dynamicVectors.h library/configRead.h \ - library/../ftpData.h ftpCommandsElaborate.h - -ftpData.h: - -library/dynamicVectors.h: - -ftpServer.h: - -library/logFunctions.h: - -library/fileManagement.h: - -library/dynamicVectors.h: - -library/configRead.h: - -library/../ftpData.h: - -ftpCommandsElaborate.h: diff --git a/build/Release/GNU-Linux/ftpData.o b/build/Release/GNU-Linux/ftpData.o deleted file mode 100644 index 7490fa0..0000000 Binary files a/build/Release/GNU-Linux/ftpData.o and /dev/null differ diff --git a/build/Release/GNU-Linux/ftpData.o.d b/build/Release/GNU-Linux/ftpData.o.d deleted file mode 100644 index 5bd6d3f..0000000 --- a/build/Release/GNU-Linux/ftpData.o.d +++ /dev/null @@ -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: diff --git a/build/Release/GNU-Linux/ftpServer.o b/build/Release/GNU-Linux/ftpServer.o deleted file mode 100644 index 3c85790..0000000 Binary files a/build/Release/GNU-Linux/ftpServer.o and /dev/null differ diff --git a/build/Release/GNU-Linux/ftpServer.o.d b/build/Release/GNU-Linux/ftpServer.o.d deleted file mode 100644 index 024a6fa..0000000 --- a/build/Release/GNU-Linux/ftpServer.o.d +++ /dev/null @@ -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: diff --git a/build/Release/GNU-Linux/library/configRead.o b/build/Release/GNU-Linux/library/configRead.o deleted file mode 100644 index 2d2c42e..0000000 Binary files a/build/Release/GNU-Linux/library/configRead.o and /dev/null differ diff --git a/build/Release/GNU-Linux/library/configRead.o.d b/build/Release/GNU-Linux/library/configRead.o.d deleted file mode 100644 index 256b794..0000000 --- a/build/Release/GNU-Linux/library/configRead.o.d +++ /dev/null @@ -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: diff --git a/build/Release/GNU-Linux/library/connection.o b/build/Release/GNU-Linux/library/connection.o deleted file mode 100644 index 5d47fb7..0000000 Binary files a/build/Release/GNU-Linux/library/connection.o and /dev/null differ diff --git a/build/Release/GNU-Linux/library/connection.o.d b/build/Release/GNU-Linux/library/connection.o.d deleted file mode 100644 index bf0bff0..0000000 --- a/build/Release/GNU-Linux/library/connection.o.d +++ /dev/null @@ -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: diff --git a/build/Release/GNU-Linux/library/daemon.o b/build/Release/GNU-Linux/library/daemon.o deleted file mode 100644 index 0312512..0000000 Binary files a/build/Release/GNU-Linux/library/daemon.o and /dev/null differ diff --git a/build/Release/GNU-Linux/library/daemon.o.d b/build/Release/GNU-Linux/library/daemon.o.d deleted file mode 100644 index 3b7f89b..0000000 --- a/build/Release/GNU-Linux/library/daemon.o.d +++ /dev/null @@ -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: diff --git a/build/Release/GNU-Linux/library/dynamicVectors.o b/build/Release/GNU-Linux/library/dynamicVectors.o deleted file mode 100644 index 147b9cb..0000000 Binary files a/build/Release/GNU-Linux/library/dynamicVectors.o and /dev/null differ diff --git a/build/Release/GNU-Linux/library/dynamicVectors.o.d b/build/Release/GNU-Linux/library/dynamicVectors.o.d deleted file mode 100644 index aad49ae..0000000 --- a/build/Release/GNU-Linux/library/dynamicVectors.o.d +++ /dev/null @@ -1,4 +0,0 @@ -build/Release/GNU-Linux/library/dynamicVectors.o: \ - library/dynamicVectors.c library/dynamicVectors.h - -library/dynamicVectors.h: diff --git a/build/Release/GNU-Linux/library/fileManagement.o b/build/Release/GNU-Linux/library/fileManagement.o deleted file mode 100644 index 2ef7796..0000000 Binary files a/build/Release/GNU-Linux/library/fileManagement.o and /dev/null differ diff --git a/build/Release/GNU-Linux/library/fileManagement.o.d b/build/Release/GNU-Linux/library/fileManagement.o.d deleted file mode 100644 index e65ea70..0000000 --- a/build/Release/GNU-Linux/library/fileManagement.o.d +++ /dev/null @@ -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: diff --git a/build/Release/GNU-Linux/library/logFunctions.o b/build/Release/GNU-Linux/library/logFunctions.o deleted file mode 100644 index 0ea1537..0000000 Binary files a/build/Release/GNU-Linux/library/logFunctions.o and /dev/null differ diff --git a/build/Release/GNU-Linux/library/logFunctions.o.d b/build/Release/GNU-Linux/library/logFunctions.o.d deleted file mode 100644 index c78775e..0000000 --- a/build/Release/GNU-Linux/library/logFunctions.o.d +++ /dev/null @@ -1,4 +0,0 @@ -build/Release/GNU-Linux/library/logFunctions.o: library/logFunctions.c \ - library/logFunctions.h - -library/logFunctions.h: diff --git a/build/Release/GNU-Linux/library/signals.o b/build/Release/GNU-Linux/library/signals.o deleted file mode 100644 index 0c967e0..0000000 Binary files a/build/Release/GNU-Linux/library/signals.o and /dev/null differ diff --git a/build/Release/GNU-Linux/library/signals.o.d b/build/Release/GNU-Linux/library/signals.o.d deleted file mode 100644 index 3ad557a..0000000 --- a/build/Release/GNU-Linux/library/signals.o.d +++ /dev/null @@ -1,4 +0,0 @@ -build/Release/GNU-Linux/library/signals.o: library/signals.c \ - library/../ftpServer.h - -library/../ftpServer.h: diff --git a/build/Release/GNU-Linux/uFTP.o b/build/Release/GNU-Linux/uFTP.o deleted file mode 100644 index 2b23bbc..0000000 Binary files a/build/Release/GNU-Linux/uFTP.o and /dev/null differ diff --git a/build/Release/GNU-Linux/uFTP.o.d b/build/Release/GNU-Linux/uFTP.o.d deleted file mode 100644 index 6eef1ae..0000000 --- a/build/Release/GNU-Linux/uFTP.o.d +++ /dev/null @@ -1,3 +0,0 @@ -build/Release/GNU-Linux/uFTP.o: uFTP.c ftpServer.h - -ftpServer.h: diff --git a/build/modules/connection.o b/build/modules/connection.o index 0ecef0a..b905654 100644 Binary files a/build/modules/connection.o and b/build/modules/connection.o differ diff --git a/build/modules/daemon.o b/build/modules/daemon.o index caf4c95..d372df3 100644 Binary files a/build/modules/daemon.o and b/build/modules/daemon.o differ diff --git a/build/modules/dynamicVectors.o b/build/modules/dynamicVectors.o index 485add8..8c121dc 100644 Binary files a/build/modules/dynamicVectors.o and b/build/modules/dynamicVectors.o differ diff --git a/build/modules/fileManagement.o b/build/modules/fileManagement.o index 889c7ef..2dde5a0 100644 Binary files a/build/modules/fileManagement.o and b/build/modules/fileManagement.o differ diff --git a/build/modules/ftpData.o b/build/modules/ftpData.o index 7191afa..896207f 100644 Binary files a/build/modules/ftpData.o and b/build/modules/ftpData.o differ diff --git a/build/modules/ftpServer.o b/build/modules/ftpServer.o index fd05f0f..8fe56ed 100644 Binary files a/build/modules/ftpServer.o and b/build/modules/ftpServer.o differ diff --git a/build/modules/logFunctions.o b/build/modules/logFunctions.o index ca9f615..a8ef6e7 100644 Binary files a/build/modules/logFunctions.o and b/build/modules/logFunctions.o differ diff --git a/build/modules/openSsl.o b/build/modules/openSsl.o new file mode 100644 index 0000000..faab2f4 Binary files /dev/null and b/build/modules/openSsl.o differ diff --git a/build/modules/signals.o b/build/modules/signals.o index f0007f5..5106668 100644 Binary files a/build/modules/signals.o and b/build/modules/signals.o differ diff --git a/cert.pem b/cert.pem new file mode 100644 index 0000000..fbdb3b8 --- /dev/null +++ b/cert.pem @@ -0,0 +1,31 @@ +-----BEGIN CERTIFICATE----- +MIIFYDCCA0igAwIBAgIJAKwUkwIPWR4KMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV +BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX +aWRnaXRzIFB0eSBMdGQwHhcNMTgxMTI0MTE0NjQyWhcNMTkxMTI0MTE0NjQyWjBF +MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50 +ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC +CgKCAgEAxtffV5tVrEF9pXAVaDmA2ObGchVThV+8P78W0bJFOBNqDlIrmDtSgNdA +/MUOndLGgit2VeQo35w5YCxHpX8aR/hm3LNwK7MOy8Vq0xtafasSzdZAuv1Qfq8Q +yVNOc4lZXOHURAmULooj4tM5a0jbQjGhB85FWyhlZDMLM+d4/1C17C6HOS9jpFgy +oCPADsUmqHDJ4gKn6ly8lW5ulDtDwjIXFJSFq+NqQ7DnZburpxVxbJzy2vdySatx +EbfVoQNUyInJWQ5sxlIk4uFmfeixmponX+IWfv6bQ2x4oH93o0av1wb4/bJj8C92 +wmxO2a6sH8gQjOR7jDoXBuRAu8ghPzEXRDMfmWUcdHIQDymgWOb63JPF+9MLZK/Q +8WB1xGYdZ98qvvVmOmTqTeuAzGhQDMfxA4OSeLmdD//aI/6ciGqxUrGNJVf6jyNt +u72bCd/R553/STp+X9CIGRlBKlHL523YBkVEo6UFGtCqfMIQOtIS/frgfq48UpYI +CyVBkPv6bvHkJjGJYswLs//saEnfv4bunMAgzkn/GXVMxMMnEQXwHNtTqinLkFlt +sEc8kr9KHUx/T+QIZrqzDJmS7HLWuneMyBstSvY4XP83TjiuzVm5R7UtqmEOwx5k +dVFH7/2x03Hm+GsC59xPDnb77l2h64FaLnizvgn01JMSE7+jHeMCAwEAAaNTMFEw +HQYDVR0OBBYEFL06WcF7b8AhRJPEr8XimqQwzs12MB8GA1UdIwQYMBaAFL06WcF7 +b8AhRJPEr8XimqQwzs12MA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQAD +ggIBAC7r1tZTPiQSB0i7pJfoRlYM+CTUymUZnBZi2MSE89+VTvuXIS7aDD7l78qa +SjBU3KwNuRYhcmHUUOf/kh3cXQFKwpr6gAz3gzKIOOqcnt0KYRGgcrEHTnw4ONy4 +YxC/rqmi9qk7MF4ahX8S1rusHrf2XonUJlsRoKqWzIz6+VlDuQOlLbgkKOr041YI +OflCbZTgds0w+lAV5pQ5T8DzldIRRdj50Us2t8It8F25yG4chTebtlSX6bHO79f6 +xYeUCmciZaRTJAX/FAxeSlWmL0ygBOQs0c6u7gV+QHgmmxKhHcQSWVDnBBcpa1fK +yZG6fH7va0IFlyeCPmqYFxziGwUJjkjGdBj3ub/tasaiTYzvd58mG58a+FCzeQLZ +ijbA3a7FBgPQxyF2Ijn5UNEAmeZRDzqRVH9D/vbZHKSyMuUK8NR/BbxOEIprn4sY +SrS97WxlT/wjStG/wnc+GgDui7mJ1yikzxp4UcEsXp6fLMhqBfi6jNFOiD0UwLGN +fbmdM71sSwZqviXxLi3/+2nNTT29XkYOhtCcMSOMFa39g5KNlSs0vcRqQsdYtXlu +FnvV/27fjJazvpHzC7f6HL4VSOsOC55qsbgLP1OGXgpgJVJnOlfHl4gadsI9wU1w +jBoIHCZr/BJVC9GdZkzs3T05TNRjiX1OCE73b5VaUaWqcIKg +-----END CERTIFICATE----- diff --git a/dist/Debug/GNU-Linux/uftp b/dist/Debug/GNU-Linux/uftp deleted file mode 100755 index c62b2b6..0000000 Binary files a/dist/Debug/GNU-Linux/uftp and /dev/null differ diff --git a/ftpCommandElaborate.c b/ftpCommandElaborate.c index f80bc6d..72b2b6d 100644 --- a/ftpCommandElaborate.c +++ b/ftpCommandElaborate.c @@ -40,20 +40,22 @@ #include "library/logFunctions.h" #include "library/fileManagement.h" #include "library/configRead.h" +#include "library/openSsl.h" +#include "library/connection.h" #include "ftpCommandsElaborate.h" /* Elaborate the User login command */ -int parseCommandUser(clientDataType *theClientData) +int parseCommandUser(ftpDataType * data, int socketId) { int returnCode; char *theUserName; - theUserName = getFtpCommandArg("USER", theClientData->theCommandReceived, 0); + theUserName = getFtpCommandArg("USER", data->clients[socketId].theCommandReceived, 0); if (strlen(theUserName) >= 1) { - setDynamicStringDataType(&theClientData->login.name, theUserName, strlen(theUserName)); - returnCode = dprintf(theClientData->socketDescriptor, "331 User ok, Waiting for the password.\r\n"); + setDynamicStringDataType(&data->clients[socketId].login.name, theUserName, strlen(theUserName)); + returnCode = socketPrintf(data, socketId, "s", "331 User ok, Waiting for the password.\r\n"); if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; @@ -62,9 +64,9 @@ int parseCommandUser(clientDataType *theClientData) } else { - returnCode = dprintf(theClientData->socketDescriptor, "430 Invalid username.\r\n"); - - if (returnCode <= 0) + returnCode = socketPrintf(data, socketId, "s", "430 Invalid username.\r\n"); + + if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; return FTP_COMMAND_PROCESSED; @@ -72,33 +74,33 @@ int parseCommandUser(clientDataType *theClientData) } /* Elaborate the User login command */ -int parseCommandSite(clientDataType *theClientData) +int parseCommandSite(ftpDataType * data, int socketId) { int returnCode, setPermissionsReturnCode; char *theCommand; - theCommand = getFtpCommandArg("SITE", theClientData->theCommandReceived, 0); + theCommand = getFtpCommandArg("SITE", data->clients[socketId].theCommandReceived, 0); if(compareStringCaseInsensitive(theCommand, "CHMOD", strlen("CHMOD")) == 1) { - setPermissionsReturnCode = setPermissions(theCommand, theClientData->login.absolutePath.text, theClientData->login.ownerShip); + setPermissionsReturnCode = setPermissions(theCommand, data->clients[socketId].login.absolutePath.text, data->clients[socketId].login.ownerShip); switch (setPermissionsReturnCode) { case FTP_CHMODE_COMMAND_RETURN_CODE_OK: { - returnCode = dprintf(theClientData->socketDescriptor, "200 Permissions changed\r\n"); + returnCode = socketPrintf(data, socketId, "s", "200 Permissions changed\r\n"); } break; case FTP_CHMODE_COMMAND_RETURN_CODE_NO_FILE: { - returnCode = dprintf(theClientData->socketDescriptor, "550 chmod no such file\r\n"); + returnCode = socketPrintf(data, socketId, "s", "550 chmod no such file\r\n"); } break; case FTP_CHMODE_COMMAND_RETURN_CODE_NO_PERMISSIONS: { - returnCode = dprintf(theClientData->socketDescriptor, "550 Some errors occoured while changing file permissions.\r\n"); + returnCode = socketPrintf(data, socketId, "s", "550 Some errors occurred while changing file permissions.\r\n"); } break; @@ -112,7 +114,7 @@ int parseCommandSite(clientDataType *theClientData) } else { - returnCode = dprintf(theClientData->socketDescriptor, "500 unknown extension\r\n"); + returnCode = socketPrintf(data, socketId, "s", "500 unknown extension\r\n"); if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; @@ -144,7 +146,7 @@ int parseCommandPass(ftpDataType * data, int socketId) { printf("\n TOO MANY LOGIN FAILS! \n"); data->clients[socketId].closeTheClient = 1; - returnCode = dprintf(data->clients[socketId].socketDescriptor, "430 Too many login failure detected, your ip will be blacklisted for 5 minutes\r\n"); + 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; return FTP_COMMAND_PROCESSED; } @@ -171,9 +173,9 @@ int parseCommandPass(ftpDataType * data, int socketId) ((loginFailsDataType *) data->loginFailsVector.Data[searchPosition])->failureNumbers++; ((loginFailsDataType *) data->loginFailsVector.Data[searchPosition])->failTimeStamp = time(NULL); } - - returnCode = dprintf(data->clients[socketId].socketDescriptor, "430 Invalid username or password\r\n"); - if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; + returnCode = socketPrintf(data, socketId, "s", "430 Invalid username or password\r\n"); + if (returnCode <= 0) + return FTP_COMMAND_PROCESSED_WRITE_ERROR; } else { @@ -187,8 +189,9 @@ int parseCommandPass(ftpDataType * data, int socketId) data->clients[socketId].login.ownerShip.uid = ((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->ownerShip.uid; data->clients[socketId].login.userLoggedIn = 1; - returnCode = dprintf(data->clients[socketId].socketDescriptor, "230 Login Ok.\r\n"); - if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; + returnCode = socketPrintf(data, socketId, "s", "230 Login Ok.\r\n"); + if (returnCode <= 0) + return FTP_COMMAND_PROCESSED_WRITE_ERROR; } return FTP_COMMAND_PROCESSED; @@ -208,46 +211,80 @@ int parseCommandPass(ftpDataType * data, int socketId) ((loginFailsDataType *) data->loginFailsVector.Data[searchPosition])->failTimeStamp = time(NULL); } - returnCode = dprintf(data->clients[socketId].socketDescriptor, "430 Invalid username or password\r\n"); - if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; + returnCode = socketPrintf(data, socketId, "s", "430 Invalid username or password\r\n"); + if (returnCode <= 0) + return FTP_COMMAND_PROCESSED_WRITE_ERROR; return 1; } } -int parseCommandAuth(clientDataType *theClientData) +int parseCommandAuth(ftpDataType * data, int socketId) { - int returnCode; - returnCode = dprintf(theClientData->socketDescriptor, "502 Security extensions not implemented.\r\n"); - if (returnCode <= 0) - return FTP_COMMAND_PROCESSED_WRITE_ERROR; - - //client -> AUTH TLS - //server -> 234 AUTH TLS OK. + int returnCode, returnCodeTls; + + #ifndef OPENSSL_ENABLED + returnCode = socketPrintf(data, socketId, "s", "502 Security extensions not implemented.\r\n"); + if (returnCode <= 0) + return FTP_COMMAND_PROCESSED_WRITE_ERROR; + #endif + + #ifdef OPENSSL_ENABLED + + returnCode = socketPrintf(data, socketId, "s", "234 AUTH TLS OK..\r\n"); + if (returnCode <= 0) + return FTP_COMMAND_PROCESSED_WRITE_ERROR; + + returnCode = SSL_set_fd(data->clients[socketId].ssl, data->clients[socketId].socketDescriptor); + + if (returnCode == 0) + { + return FTP_COMMAND_PROCESSED_WRITE_ERROR; + } + + returnCodeTls = SSL_accept(data->clients[socketId].ssl); + data->clients[socketId].tlsNegotiatingTimeStart = (int)time(NULL); + + if (returnCodeTls <= 0) + { + printf("\nSSL NOT YET ACCEPTED: %d", returnCodeTls); + data->clients[socketId].tlsIsEnabled = 0; + data->clients[socketId].tlsIsNegotiating = 1; + } + else + { + printf("\nSSL ACCEPTED"); + data->clients[socketId].tlsIsEnabled = 1; + data->clients[socketId].tlsIsNegotiating = 0; + } + #endif + + return FTP_COMMAND_PROCESSED; } -int parseCommandPwd(clientDataType *theClientData) +int parseCommandPwd(ftpDataType * data, int socketId) { int returnCode; - returnCode = dprintf(theClientData->socketDescriptor, "257 \"%s\" is your current location\r\n", theClientData->login.ftpPath.text); + returnCode = socketPrintf(data, socketId, "sss", "257 \"", data->clients[socketId].login.ftpPath.text ,"\" is your current location\r\n"); + if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; return FTP_COMMAND_PROCESSED; } -int parseCommandSyst(clientDataType *theClientData) +int parseCommandSyst(ftpDataType * data, int socketId) { int returnCode; - returnCode = dprintf(theClientData->socketDescriptor, "215 UNIX Type: L8\r\n"); + returnCode = socketPrintf(data, socketId, "s", "215 UNIX Type: L8\r\n"); if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; return FTP_COMMAND_PROCESSED; } -int parseCommandFeat(clientDataType *theClientData) +int parseCommandFeat(ftpDataType * data, int socketId) { /* 211-Extensions supported: @@ -270,29 +307,125 @@ int parseCommandFeat(clientDataType *theClientData) SPSV ESTP 211 End. + + +211-Extensions supported: + EPRT + IDLE + MDTM + SIZE + MFMT + REST STREAM + MLST type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*; + MLSD + AUTH TLS + PBSZ + PROT + UTF8 + TVFS + ESTA + PASV + EPSV + SPSV + ESTP +211 End. */ + int returnCode; - returnCode = dprintf(theClientData->socketDescriptor, "211-Extensions supported:\r\n PASV\r\nUTF8\r\n211 End.\r\n"); + #ifdef OPENSSL_ENABLED + returnCode = socketPrintf(data, socketId, "s", "211-Extensions supported:\r\nPASV\r\nUTF8\r\nAUTH TLS\r\nPBSZ\r\nPROT\r\n211 End.\r\n"); + #endif + #ifndef OPENSSL_ENABLED + returnCode = socketPrintf(data, socketId, "s", "211-Extensions supported:\r\nPASV\r\nUTF8\r\n211 End.\r\n"); + #endif + if (returnCode <= 0) + return FTP_COMMAND_PROCESSED_WRITE_ERROR; + + return FTP_COMMAND_PROCESSED; +} + +int parseCommandProt(ftpDataType * data, int socketId) +{ + int returnCode; + char *theProtArg; + theProtArg = getFtpCommandArg("PROT", data->clients[socketId].theCommandReceived, 0); + + if (theProtArg[0] == 'C' || theProtArg[0] == 'c') + { + //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"); + + } + else if (theProtArg[0] == 'P' || theProtArg[0] == 'p') + { + //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"); + } + else + { + returnCode = socketPrintf(data, socketId, "scs", "502 Mode ", theProtArg[0]," is not implemented\r\n"); + } + + if (returnCode <= 0) + return FTP_COMMAND_PROCESSED_WRITE_ERROR; + + return FTP_COMMAND_PROCESSED; +} + +int parseCommandCcc(ftpDataType * data, int socketId) +{ + #ifdef OPENSSL_ENABLED + int returnCode; + returnCode = socketPrintf(data, socketId, "s", "200 TLS connection aborted\r\n"); + SSL_set_shutdown(data->clients[socketId].ssl, SSL_SENT_SHUTDOWN); + data->clients[socketId].tlsIsEnabled = 0; + + if (returnCode <= 0) + return FTP_COMMAND_PROCESSED_WRITE_ERROR; + #endif + + #ifdef OPENSSL_ENABLED + returnCode = socketPrintf(data, socketId, "s", "500 command not supported\r\n"); + + if (returnCode <= 0) + return FTP_COMMAND_PROCESSED_WRITE_ERROR; + #endif + + return FTP_COMMAND_PROCESSED; +} + +int parseCommandPbsz(ftpDataType * data, int socketId) +{ + int returnCode; + char *thePbszSize; + thePbszSize = getFtpCommandArg("PBSZ", data->clients[socketId].theCommandReceived, 0); + + returnCode = socketPrintf(data, socketId, "sss", "200 PBSZ set to ", thePbszSize, "\r\n"); if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; return FTP_COMMAND_PROCESSED; } -int parseCommandTypeA(clientDataType *theClientData) +int parseCommandTypeA(ftpDataType * data, int socketId) { int returnCode; - returnCode = dprintf(theClientData->socketDescriptor, "200 TYPE is now 8-bit binary\r\n"); + returnCode = socketPrintf(data, socketId, "s", "200 TYPE is now 8-bit binary\r\n"); + if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; return FTP_COMMAND_PROCESSED; } -int parseCommandTypeI(clientDataType *theClientData) +int parseCommandTypeI(ftpDataType * data, int socketId) { int returnCode; - returnCode = dprintf(theClientData->socketDescriptor, "200 TYPE is now 8-bit binary\r\n"); + returnCode = socketPrintf(data, socketId, "s", "200 TYPE is now 8-bit binary\r\n"); if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; @@ -300,21 +433,21 @@ int parseCommandTypeI(clientDataType *theClientData) return FTP_COMMAND_PROCESSED; } -int parseCommandStruF(clientDataType *theClientData) +int parseCommandStruF(ftpDataType * data, int socketId) { int returnCode; - returnCode = dprintf(theClientData->socketDescriptor, "200 TYPE is now 8-bit binary\r\n"); + returnCode = socketPrintf(data, socketId, "s", "200 TYPE is now 8-bit binary\r\n"); if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; return FTP_COMMAND_PROCESSED; } -int parseCommandModeS(clientDataType *theClientData) +int parseCommandModeS(ftpDataType * data, int socketId) { int returnCode; - returnCode = dprintf(theClientData->socketDescriptor, "200 TYPE is now 8-bit binary\r\n"); - + returnCode = socketPrintf(data, socketId, "s", "200 TYPE is now 8-bit binary\r\n"); + if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; @@ -325,38 +458,66 @@ int parseCommandPasv(ftpDataType * data, int socketId) { /* Create worker thread */ void *pReturn; + int returnCode; + //printf("\n data->clients[%d].workerData.workerThread = %d",socketId, (int)data->clients[socketId].workerData.workerThread); - if (data->clients[socketId].workerData.threadIsAlive == 1) + printf("\n data->clients[%d].workerData.threadHasBeenCreated = %d", socketId, data->clients[socketId].workerData.threadHasBeenCreated); + if (data->clients[socketId].workerData.threadIsAlive == 1) { - pthread_cancel(data->clients[socketId].workerData.workerThread); + returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); + printf("\npasv pthread_cancel = %d", returnCode); } - - pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); + + if (data->clients[socketId].workerData.threadHasBeenCreated == 1) + { + returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); + printf("\nPasv join ok %d", returnCode); + } + data->clients[socketId].workerData.passiveModeOn = 1; data->clients[socketId].workerData.activeModeOn = 0; - pthread_create(&data->clients[socketId].workerData.workerThread, NULL, connectionWorkerHandle, (void *) &data->clients[socketId].clientProgressiveNumber); + returnCode = pthread_create(&data->clients[socketId].workerData.workerThread, NULL, connectionWorkerHandle, (void *) &data->clients[socketId].clientProgressiveNumber); + + if (returnCode != 0) + { + printf("\nError in pthread_create %d", returnCode); + return FTP_COMMAND_PROCESSED_WRITE_ERROR; + } + return FTP_COMMAND_PROCESSED; } int parseCommandPort(ftpDataType * data, int socketId) { + int returnCode; char *theIpAndPort; int ipAddressBytes[4]; int portBytes[2]; theIpAndPort = getFtpCommandArg("PORT", data->clients[socketId].theCommandReceived, 0); sscanf(theIpAndPort, "%d,%d,%d,%d,%d,%d", &ipAddressBytes[0], &ipAddressBytes[1], &ipAddressBytes[2], &ipAddressBytes[3], &portBytes[0], &portBytes[1]); data->clients[socketId].workerData.connectionPort = (portBytes[0]*256)+portBytes[1]; - sprintf(data->clients[socketId].workerData.activeIpAddress, "%d.%d.%d.%d", ipAddressBytes[0],ipAddressBytes[1],ipAddressBytes[2],ipAddressBytes[3]); + returnCode = snprintf(data->clients[socketId].workerData.activeIpAddress, CLIENT_BUFFER_STRING_SIZE, "%d.%d.%d.%d", ipAddressBytes[0],ipAddressBytes[1],ipAddressBytes[2],ipAddressBytes[3]); void *pReturn; if (data->clients[socketId].workerData.threadIsAlive == 1) { - pthread_cancel(data->clients[socketId].workerData.workerThread); + returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); + } + if (data->clients[socketId].workerData.threadHasBeenCreated == 1) + { + returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); } - pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); data->clients[socketId].workerData.passiveModeOn = 0; data->clients[socketId].workerData.activeModeOn = 1; - pthread_create(&data->clients[socketId].workerData.workerThread, NULL, connectionWorkerHandle, (void *) &data->clients[socketId].clientProgressiveNumber); + returnCode = pthread_create(&data->clients[socketId].workerData.workerThread, NULL, connectionWorkerHandle, (void *) &data->clients[socketId].clientProgressiveNumber); + + if (returnCode != 0) + { + printf("\nError in pthread_create %d", returnCode); + return FTP_COMMAND_PROCESSED_WRITE_ERROR; + } + + return FTP_COMMAND_PROCESSED; } @@ -376,19 +537,18 @@ int parseCommandAbor(ftpDataType * data, int socketId) { pthread_cancel(data->clients[socketId].workerData.workerThread); } - pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); - returnCode = dprintf(data->clients[socketId].socketDescriptor, "426 ABORT\r\n"); + returnCode = socketPrintf(data, socketId, "s", "426 ABORT\r\n"); if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; - - returnCode = dprintf(data->clients[socketId].socketDescriptor, "226 Transfer aborted\r\n"); + + returnCode = socketPrintf(data, socketId, "s", "226 Transfer aborted\r\n"); if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; } else { - returnCode = dprintf(data->clients[socketId].socketDescriptor, "226 Since you see this ABOR must've succeeded\r\n"); + returnCode = socketPrintf(data, socketId, "s", "226 Since you see this ABOR must've succeeded\r\n"); if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; } @@ -421,8 +581,10 @@ 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); - printf("\nLIST COMMAND ARG: %s", data->clients[socketId].workerData.ftpCommand.commandArgs.text); - printf("\nLIST COMMAND OPS: %s", data->clients[socketId].workerData.ftpCommand.commandOps.text); + 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); @@ -440,7 +602,7 @@ int parseCommandList(ftpDataType * data, int socketId) setDynamicStringDataType(&data->clients[socketId].listPath, data->clients[socketId].login.absolutePath.text, data->clients[socketId].login.absolutePath.textLen); } - pthread_mutex_lock(&data->clients[socketId].workerData.conditionMutex); + pthread_mutex_trylock(&data->clients[socketId].workerData.conditionMutex); memset(data->clients[socketId].workerData.theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE); strcpy(data->clients[socketId].workerData.theCommandReceived, data->clients[socketId].theCommandReceived); data->clients[socketId].workerData.commandReceived = 1; @@ -471,7 +633,7 @@ int parseCommandNlst(ftpDataType * data, int socketId) setDynamicStringDataType(&data->clients[socketId].nlistPath, data->clients[socketId].login.absolutePath.text, data->clients[socketId].login.absolutePath.textLen); } - pthread_mutex_lock(&data->clients[socketId].workerData.conditionMutex); + pthread_mutex_trylock(&data->clients[socketId].workerData.conditionMutex); memset(data->clients[socketId].workerData.theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE); strcpy(data->clients[socketId].workerData.theCommandReceived, data->clients[socketId].theCommandReceived); data->clients[socketId].workerData.commandReceived = 1; @@ -496,7 +658,7 @@ int parseCommandRetr(ftpDataType * data, int socketId) if (isSafePath == 1 && FILE_IsFile(data->clients[socketId].fileToRetr.text) == 1) { - pthread_mutex_lock(&data->clients[socketId].workerData.conditionMutex); + pthread_mutex_trylock(&data->clients[socketId].workerData.conditionMutex); memset(data->clients[socketId].workerData.theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE); strcpy(data->clients[socketId].workerData.theCommandReceived, data->clients[socketId].theCommandReceived); data->clients[socketId].workerData.commandReceived = 1; @@ -526,7 +688,7 @@ int parseCommandStor(ftpDataType * data, int socketId) if (isSafePath == 1) { - pthread_mutex_lock(&data->clients[socketId].workerData.conditionMutex); + pthread_mutex_trylock(&data->clients[socketId].workerData.conditionMutex); memset(data->clients[socketId].workerData.theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE); strcpy(data->clients[socketId].workerData.theCommandReceived, data->clients[socketId].theCommandReceived); data->clients[socketId].workerData.commandReceived = 1; @@ -541,7 +703,7 @@ int parseCommandStor(ftpDataType * data, int socketId) return FTP_COMMAND_PROCESSED; } -int parseCommandCwd(clientDataType *theClientData) +int parseCommandCwd(ftpDataType * data, int socketId) { dynamicStringDataType absolutePathPrevious, ftpPathPrevious, theSafePath; int isSafePath; @@ -552,62 +714,62 @@ int parseCommandCwd(clientDataType *theClientData) cleanDynamicStringDataType(&ftpPathPrevious, 1); cleanDynamicStringDataType(&theSafePath, 1); - thePath = getFtpCommandArg("CWD", theClientData->theCommandReceived, 0); + thePath = getFtpCommandArg("CWD", data->clients[socketId].theCommandReceived, 0); if (strlen(thePath) > 0) { - isSafePath = getSafePath(&theSafePath, thePath, &theClientData->login); + isSafePath = getSafePath(&theSafePath, thePath, &data->clients[socketId].login); } if (isSafePath == 1) { - printf("\n The Path requested for CWD IS:%s", theSafePath.text); - setDynamicStringDataType(&absolutePathPrevious, theClientData->login.absolutePath.text, theClientData->login.absolutePath.textLen); - setDynamicStringDataType(&ftpPathPrevious, theClientData->login.ftpPath.text, theClientData->login.ftpPath.textLen); + //printf("\n The Path requested for CWD IS:%s", theSafePath.text); + setDynamicStringDataType(&absolutePathPrevious, data->clients[socketId].login.absolutePath.text, data->clients[socketId].login.absolutePath.textLen); + setDynamicStringDataType(&ftpPathPrevious, data->clients[socketId].login.ftpPath.text, data->clients[socketId].login.ftpPath.textLen); if (theSafePath.text[0] != '/') { - if (theClientData->login.absolutePath.text[theClientData->login.absolutePath.textLen-1] != '/') - appendToDynamicStringDataType(&theClientData->login.absolutePath, "/", 1); + if (data->clients[socketId].login.absolutePath.text[data->clients[socketId].login.absolutePath.textLen-1] != '/') + appendToDynamicStringDataType(&data->clients[socketId].login.absolutePath, "/", 1); - if (theClientData->login.ftpPath.text[theClientData->login.ftpPath.textLen-1] != '/') - appendToDynamicStringDataType(&theClientData->login.ftpPath, "/", 1); + if (data->clients[socketId].login.ftpPath.text[data->clients[socketId].login.ftpPath.textLen-1] != '/') + appendToDynamicStringDataType(&data->clients[socketId].login.ftpPath, "/", 1); - appendToDynamicStringDataType(&theClientData->login.absolutePath, theSafePath.text, theSafePath.textLen); - appendToDynamicStringDataType(&theClientData->login.ftpPath, theSafePath.text, theSafePath.textLen); + appendToDynamicStringDataType(&data->clients[socketId].login.absolutePath, theSafePath.text, theSafePath.textLen); + appendToDynamicStringDataType(&data->clients[socketId].login.ftpPath, theSafePath.text, theSafePath.textLen); } else if (theSafePath.text[0] == '/') { - cleanDynamicStringDataType(&theClientData->login.ftpPath, 0); - cleanDynamicStringDataType(&theClientData->login.absolutePath, 0); + cleanDynamicStringDataType(&data->clients[socketId].login.ftpPath, 0); + cleanDynamicStringDataType(&data->clients[socketId].login.absolutePath, 0); - setDynamicStringDataType(&theClientData->login.ftpPath, theSafePath.text, theSafePath.textLen); - setDynamicStringDataType(&theClientData->login.absolutePath, theClientData->login.homePath.text, theClientData->login.homePath.textLen); + setDynamicStringDataType(&data->clients[socketId].login.ftpPath, theSafePath.text, theSafePath.textLen); + setDynamicStringDataType(&data->clients[socketId].login.absolutePath, data->clients[socketId].login.homePath.text, data->clients[socketId].login.homePath.textLen); if (strlen(theSafePath.text)> 0) { char *theDirPointer = theSafePath.text; - if (theClientData->login.absolutePath.text[theClientData->login.absolutePath.textLen-1] == '/') + if (data->clients[socketId].login.absolutePath.text[data->clients[socketId].login.absolutePath.textLen-1] == '/') { while(theDirPointer[0] == '/') theDirPointer++; } if (strlen(theDirPointer) > 0) - appendToDynamicStringDataType(&theClientData->login.absolutePath, theDirPointer, strlen(theDirPointer)); + appendToDynamicStringDataType(&data->clients[socketId].login.absolutePath, theDirPointer, strlen(theDirPointer)); } } - if (FILE_IsDirectory(theClientData->login.absolutePath.text) == 1) + if (FILE_IsDirectory(data->clients[socketId].login.absolutePath.text) == 1) { - returnCode = dprintf(theClientData->socketDescriptor, "250 OK. Current directory is %s\r\n", theClientData->login.ftpPath.text); + returnCode = socketPrintf(data, socketId, "sss", "250 OK. Current directory is ", data->clients[socketId].login.ftpPath.text, "\r\n"); } else { - setDynamicStringDataType(&theClientData->login.absolutePath, absolutePathPrevious.text, absolutePathPrevious.textLen); - setDynamicStringDataType(&theClientData->login.ftpPath, ftpPathPrevious.text, ftpPathPrevious.textLen); - returnCode = dprintf(theClientData->socketDescriptor, "530 Can't change directory to %s: No such file or directory\r\n", theClientData->login.absolutePath.text); + setDynamicStringDataType(&data->clients[socketId].login.absolutePath, absolutePathPrevious.text, absolutePathPrevious.textLen); + setDynamicStringDataType(&data->clients[socketId].login.ftpPath, ftpPathPrevious.text, ftpPathPrevious.textLen); + returnCode = socketPrintf(data, socketId, "sss", "530 Can't change directory to ", data->clients[socketId].login.absolutePath.text, ": No such file or directory\r\n"); } cleanDynamicStringDataType(&absolutePathPrevious, 0); @@ -629,7 +791,7 @@ int parseCommandCwd(clientDataType *theClientData) } } -int parseCommandRest(clientDataType *theClientData) +int parseCommandRest(ftpDataType * data, int socketId) { int returnCode; int i, theSizeIndex; @@ -637,33 +799,33 @@ int parseCommandRest(clientDataType *theClientData) memset(theSize, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER); theSizeIndex = 0; - for (i = strlen("REST")+1; i < theClientData->commandIndex; i++) + for (i = strlen("REST")+1; i < data->clients[socketId].commandIndex; i++) { - if (theClientData->theCommandReceived[i] == '\r' || - theClientData->theCommandReceived[i] == '\0' || - theClientData->theCommandReceived[i] == '\n') + if (data->clients[socketId].theCommandReceived[i] == '\r' || + data->clients[socketId].theCommandReceived[i] == '\0' || + data->clients[socketId].theCommandReceived[i] == '\n') { break; } if (theSizeIndex < FTP_COMMAND_ELABORATE_CHAR_BUFFER && - (theClientData->theCommandReceived[i] == '0' || - theClientData->theCommandReceived[i] == '1' || - theClientData->theCommandReceived[i] == '2' || - theClientData->theCommandReceived[i] == '3' || - theClientData->theCommandReceived[i] == '4' || - theClientData->theCommandReceived[i] == '5' || - theClientData->theCommandReceived[i] == '6' || - theClientData->theCommandReceived[i] == '7' || - theClientData->theCommandReceived[i] == '8' || - theClientData->theCommandReceived[i] == '9' )) + (data->clients[socketId].theCommandReceived[i] == '0' || + data->clients[socketId].theCommandReceived[i] == '1' || + data->clients[socketId].theCommandReceived[i] == '2' || + data->clients[socketId].theCommandReceived[i] == '3' || + data->clients[socketId].theCommandReceived[i] == '4' || + data->clients[socketId].theCommandReceived[i] == '5' || + data->clients[socketId].theCommandReceived[i] == '6' || + data->clients[socketId].theCommandReceived[i] == '7' || + data->clients[socketId].theCommandReceived[i] == '8' || + data->clients[socketId].theCommandReceived[i] == '9' )) { - theSize[theSizeIndex++] = theClientData->theCommandReceived[i]; + theSize[theSizeIndex++] = data->clients[socketId].theCommandReceived[i]; } } - theClientData->workerData.retrRestartAtByte = atoll(theSize); - returnCode = dprintf(theClientData->socketDescriptor, "350 Restarting at %s\r\n", theSize); + data->clients[socketId].workerData.retrRestartAtByte = atoll(theSize); + returnCode = socketPrintf(data, socketId, "sss", "350 Restarting at ", theSize, "\r\n"); if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; @@ -671,7 +833,7 @@ int parseCommandRest(clientDataType *theClientData) return FTP_COMMAND_PROCESSED; } -int parseCommandMkd(clientDataType *theClientData) +int parseCommandMkd(ftpDataType * data, int socketId) { int returnCode; int functionReturnCode = FTP_COMMAND_NOT_RECONIZED; @@ -679,11 +841,11 @@ int parseCommandMkd(clientDataType *theClientData) char *theDirectoryFilename; dynamicStringDataType mkdFileName; - theDirectoryFilename = getFtpCommandArg("MKD", theClientData->theCommandReceived, 0); + theDirectoryFilename = getFtpCommandArg("MKD", data->clients[socketId].theCommandReceived, 0); cleanDynamicStringDataType(&mkdFileName, 1); - isSafePath = getSafePath(&mkdFileName, theDirectoryFilename, &theClientData->login); + isSafePath = getSafePath(&mkdFileName, theDirectoryFilename, &data->clients[socketId].login); if (isSafePath == 1) { @@ -692,8 +854,7 @@ int parseCommandMkd(clientDataType *theClientData) if (returnStatus == -1) { - returnCode = dprintf(theClientData->socketDescriptor, "550 error while creating directory %s\r\n", theDirectoryFilename); - + returnCode = socketPrintf(data, socketId, "sss", "550 error while creating directory ", theDirectoryFilename, "\r\n"); if (returnCode <= 0) { functionReturnCode = FTP_COMMAND_PROCESSED_WRITE_ERROR; @@ -705,12 +866,12 @@ int parseCommandMkd(clientDataType *theClientData) } else { - if (theClientData->login.ownerShip.ownerShipSet == 1) + if (data->clients[socketId].login.ownerShip.ownerShipSet == 1) { - returnStatus = FILE_doChownFromUidGid(mkdFileName.text, theClientData->login.ownerShip.uid, theClientData->login.ownerShip.gid); + returnStatus = FILE_doChownFromUidGid(mkdFileName.text, data->clients[socketId].login.ownerShip.uid, data->clients[socketId].login.ownerShip.gid); } - returnCode = dprintf(theClientData->socketDescriptor, "257 \"%s\" : The directory was successfully created\r\n", theDirectoryFilename); + returnCode = socketPrintf(data, socketId, "sss", "257 \"", theDirectoryFilename, "\" : The directory was successfully created\r\n"); if (returnCode <= 0) { @@ -732,10 +893,10 @@ int parseCommandMkd(clientDataType *theClientData) return functionReturnCode; } -int parseCommandOpts(clientDataType *theClientData) +int parseCommandOpts(ftpDataType * data, int socketId) { int returnCode; - returnCode = dprintf(theClientData->socketDescriptor, "200 OK\r\n"); + returnCode = socketPrintf(data, socketId, "s", "200 OK\r\n"); if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; @@ -743,7 +904,7 @@ int parseCommandOpts(clientDataType *theClientData) return FTP_COMMAND_PROCESSED; } -int parseCommandDele(clientDataType *theClientData) +int parseCommandDele(ftpDataType * data, int socketId) { int functionReturnCode = 0; int returnCode; @@ -752,10 +913,10 @@ int parseCommandDele(clientDataType *theClientData) char *theFileToDelete; dynamicStringDataType deleFileName; - theFileToDelete = getFtpCommandArg("DELE", theClientData->theCommandReceived, 0); + theFileToDelete = getFtpCommandArg("DELE", data->clients[socketId].theCommandReceived, 0); cleanDynamicStringDataType(&deleFileName, 1); - isSafePath = getSafePath(&deleFileName, theFileToDelete, &theClientData->login); + isSafePath = getSafePath(&deleFileName, theFileToDelete, &data->clients[socketId].login); if (isSafePath == 1) { @@ -766,11 +927,11 @@ int parseCommandDele(clientDataType *theClientData) if (returnStatus == -1) { - returnCode = dprintf(theClientData->socketDescriptor, "550 Could not delete the file: %s some errors occoured\r\n", theFileToDelete); + returnCode = socketPrintf(data, socketId, "sss", "550 Could not delete the file: ", theFileToDelete, " some errors occurred\r\n"); } else { - returnCode = dprintf(theClientData->socketDescriptor, "250 Deleted %s\r\n", theFileToDelete); + returnCode = socketPrintf(data, socketId, "sss", "250 Deleted ", theFileToDelete, "\r\n"); } functionReturnCode = FTP_COMMAND_PROCESSED; @@ -780,7 +941,7 @@ int parseCommandDele(clientDataType *theClientData) } else { - returnCode = dprintf(theClientData->socketDescriptor, "550 Could not delete the file: No such file or file is a directory\r\n"); + returnCode = socketPrintf(data, socketId, "s", "550 Could not delete the file: No such file or file is a directory\r\n"); functionReturnCode = FTP_COMMAND_PROCESSED; if (returnCode <= 0) @@ -796,11 +957,11 @@ int parseCommandDele(clientDataType *theClientData) return functionReturnCode; } -int parseCommandNoop(clientDataType *theClientData) +int parseCommandNoop(ftpDataType * data, int socketId) { int returnCode; - returnCode = dprintf(theClientData->socketDescriptor, "200 Zzz...\r\n"); - + + returnCode = socketPrintf(data, socketId, "s", "200 Zzz...\r\n"); if (returnCode <= 0) { return FTP_COMMAND_PROCESSED_WRITE_ERROR; } @@ -808,10 +969,11 @@ int parseCommandNoop(clientDataType *theClientData) return FTP_COMMAND_PROCESSED; } -int notLoggedInMessage(clientDataType *theClientData) +int notLoggedInMessage(ftpDataType * data, int socketId) { int returnCode; - returnCode = dprintf(theClientData->socketDescriptor, "530 You aren't logged in\r\n"); + returnCode = socketPrintf(data, socketId, "s", "530 You aren't logged in\r\n"); + if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; @@ -821,7 +983,8 @@ int notLoggedInMessage(clientDataType *theClientData) int parseCommandQuit(ftpDataType * data, int socketId) { int returnCode; - returnCode = dprintf(data->clients[socketId].socketDescriptor, "221 Logout.\r\n"); + returnCode = socketPrintf(data, socketId, "s", "221 Logout.\r\n"); + if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; @@ -830,7 +993,7 @@ int parseCommandQuit(ftpDataType * data, int socketId) return FTP_COMMAND_PROCESSED; } -int parseCommandRmd(clientDataType *theClientData) +int parseCommandRmd(ftpDataType * data, int socketId) { int functionReturnCode = 0; int returnCode; @@ -839,11 +1002,9 @@ int parseCommandRmd(clientDataType *theClientData) char *theDirectoryFilename; dynamicStringDataType rmdFileName; - theDirectoryFilename = getFtpCommandArg("RMD", theClientData->theCommandReceived, 0); - + theDirectoryFilename = getFtpCommandArg("RMD", data->clients[socketId].theCommandReceived, 0); cleanDynamicStringDataType(&rmdFileName, 1); - - isSafePath = getSafePath(&rmdFileName, theDirectoryFilename, &theClientData->login); + isSafePath = getSafePath(&rmdFileName, theDirectoryFilename, &data->clients[socketId].login); if (isSafePath == 1) { @@ -853,11 +1014,11 @@ int parseCommandRmd(clientDataType *theClientData) if (returnStatus == -1) { - returnCode = dprintf(theClientData->socketDescriptor, "550 Could not remove the directory, some errors occoured.\r\n"); + returnCode = socketPrintf(data, socketId, "s", "550 Could not remove the directory, some errors occurred.\r\n"); } else { - returnCode = dprintf(theClientData->socketDescriptor, "250 The directory was successfully removed\r\n"); + returnCode = socketPrintf(data, socketId, "s", "250 The directory was successfully removed\r\n"); } functionReturnCode = FTP_COMMAND_PROCESSED; @@ -867,7 +1028,7 @@ int parseCommandRmd(clientDataType *theClientData) } else { - returnCode = dprintf(theClientData->socketDescriptor, "550 Could not delete the directory:No such directory\r\n"); + returnCode = socketPrintf(data, socketId, "s", "550 Could not delete the directory:No such directory\r\n"); functionReturnCode = FTP_COMMAND_PROCESSED; if (returnCode <= 0) @@ -884,7 +1045,7 @@ int parseCommandRmd(clientDataType *theClientData) return functionReturnCode; } -int parseCommandSize(clientDataType *theClientData) +int parseCommandSize(ftpDataType * data, int socketId) { int returnCode; int isSafePath; @@ -892,11 +1053,11 @@ int parseCommandSize(clientDataType *theClientData) char *theFileName; dynamicStringDataType getSizeFromFileName; - theFileName = getFtpCommandArg("SIZE", theClientData->theCommandReceived, 0); + theFileName = getFtpCommandArg("SIZE", data->clients[socketId].theCommandReceived, 0); cleanDynamicStringDataType(&getSizeFromFileName, 1); - isSafePath = getSafePath(&getSizeFromFileName, theFileName, &theClientData->login); + isSafePath = getSafePath(&getSizeFromFileName, theFileName, &data->clients[socketId].login); if (isSafePath == 1) { @@ -904,16 +1065,16 @@ int parseCommandSize(clientDataType *theClientData) if (FILE_IsFile(getSizeFromFileName.text)== 1) { theSize = FILE_GetFileSizeFromPath(getSizeFromFileName.text); - returnCode = dprintf(theClientData->socketDescriptor, "213 %lld\r\n", theSize); + returnCode = socketPrintf(data, socketId, "sls", "213 ", theSize, "\r\n"); } else { - returnCode = dprintf(theClientData->socketDescriptor, "550 Can't check for file existence\r\n"); + returnCode = socketPrintf(data, socketId, "s", "550 Can't check for file existence\r\n"); } } else { - returnCode = dprintf(theClientData->socketDescriptor, "550 Can't check for file existence\r\n"); + returnCode = socketPrintf(data, socketId, "s", "550 Can't check for file existence\r\n"); } cleanDynamicStringDataType(&getSizeFromFileName, 0); @@ -923,34 +1084,34 @@ int parseCommandSize(clientDataType *theClientData) return FTP_COMMAND_PROCESSED; } -int parseCommandRnfr(clientDataType *theClientData) +int parseCommandRnfr(ftpDataType * data, int socketId) { int returnCode; int isSafePath; char *theRnfrFileName; - theRnfrFileName = getFtpCommandArg("RNFR", theClientData->theCommandReceived, 0); - cleanDynamicStringDataType(&theClientData->renameFromFile, 0); + theRnfrFileName = getFtpCommandArg("RNFR", data->clients[socketId].theCommandReceived, 0); + cleanDynamicStringDataType(&data->clients[socketId].renameFromFile, 0); - isSafePath = getSafePath(&theClientData->renameFromFile, theRnfrFileName, &theClientData->login); + isSafePath = getSafePath(&data->clients[socketId].renameFromFile, theRnfrFileName, &data->clients[socketId].login); if (isSafePath == 1&& - (FILE_IsFile(theClientData->renameFromFile.text) == 1 || - FILE_IsDirectory(theClientData->renameFromFile.text) == 1)) + (FILE_IsFile(data->clients[socketId].renameFromFile.text) == 1 || + FILE_IsDirectory(data->clients[socketId].renameFromFile.text) == 1)) { - if (FILE_IsFile(theClientData->renameFromFile.text) == 1 || - FILE_IsDirectory(theClientData->renameFromFile.text) == 1) + if (FILE_IsFile(data->clients[socketId].renameFromFile.text) == 1 || + FILE_IsDirectory(data->clients[socketId].renameFromFile.text) == 1) { - returnCode = dprintf(theClientData->socketDescriptor, "350 RNFR accepted - file exists, ready for destination\r\n"); + returnCode = socketPrintf(data, socketId, "s", "350 RNFR accepted - file exists, ready for destination\r\n"); } else { - returnCode = dprintf(theClientData->socketDescriptor, "550 Sorry, but that file doesn't exist\r\n"); + returnCode = socketPrintf(data, socketId, "s", "550 Sorry, but that file doesn't exist\r\n"); } } else { - returnCode = dprintf(theClientData->socketDescriptor, "550 Sorry, but that file doesn't exist\r\n"); + returnCode = socketPrintf(data, socketId, "s", "550 Sorry, but that file doesn't exist\r\n"); } @@ -958,63 +1119,74 @@ int parseCommandRnfr(clientDataType *theClientData) return FTP_COMMAND_PROCESSED; } -int parseCommandRnto(clientDataType *theClientData) +int parseCommandRnto(ftpDataType * data, int socketId) { - int returnCode; + int returnCode = 0; int isSafePath; char *theRntoFileName; - theRntoFileName = getFtpCommandArg("RNTO", theClientData->theCommandReceived, 0); - cleanDynamicStringDataType(&theClientData->renameToFile, 0); + theRntoFileName = getFtpCommandArg("RNTO", data->clients[socketId].theCommandReceived, 0); + cleanDynamicStringDataType(&data->clients[socketId].renameToFile, 0); - isSafePath = getSafePath(&theClientData->renameToFile, theRntoFileName, &theClientData->login); + isSafePath = getSafePath(&data->clients[socketId].renameToFile, theRntoFileName, &data->clients[socketId].login); if (isSafePath == 1 && - theClientData->renameFromFile.textLen > 0) + data->clients[socketId].renameFromFile.textLen > 0) { - if (FILE_IsFile(theClientData->renameFromFile.text) == 1 || - FILE_IsDirectory(theClientData->renameFromFile.text) == 1) + if (FILE_IsFile(data->clients[socketId].renameFromFile.text) == 1 || + FILE_IsDirectory(data->clients[socketId].renameFromFile.text) == 1) { +<<<<<<< HEAD returnCode = rename (theClientData->renameFromFile.text, theClientData->renameToFile.text); +======= + returnCode = rename (data->clients[socketId].renameFromFile.text, data->clients[socketId].renameToFile.text); +>>>>>>> TLS if (returnCode == 0) { - returnCode = dprintf(theClientData->socketDescriptor, "250 File successfully renamed or moved\r\n"); + returnCode = socketPrintf(data, socketId, "s", "250 File successfully renamed or moved\r\n"); } else { - returnCode = dprintf(theClientData->socketDescriptor, "503 Error Renaming the file\r\n"); + returnCode = socketPrintf(data, socketId, "s", "503 Error Renaming the file\r\n"); } } else { - returnCode = dprintf(theClientData->socketDescriptor, "503 Need RNFR before RNTO\r\n"); + returnCode = socketPrintf(data, socketId, "s", "503 Need RNFR before RNTO\r\n"); } } else { - returnCode = dprintf(theClientData->socketDescriptor, "503 Error Renaming the file\r\n"); + returnCode = socketPrintf(data, socketId, "s", "503 Error Renaming the file\r\n"); + } + + if (returnCode <= 0) + { + return FTP_COMMAND_PROCESSED_WRITE_ERROR; + } + else + { + return FTP_COMMAND_PROCESSED; } - if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; - return FTP_COMMAND_PROCESSED; } -int parseCommandCdup(clientDataType *theClientData) +int parseCommandCdup(ftpDataType * data, int socketId) { int returnCode; - FILE_DirectoryToParent(&theClientData->login.absolutePath.text); - FILE_DirectoryToParent(&theClientData->login.ftpPath.text); - theClientData->login.absolutePath.textLen = strlen(theClientData->login.absolutePath.text); - theClientData->login.ftpPath.textLen = strlen(theClientData->login.ftpPath.text); + FILE_DirectoryToParent(&data->clients[socketId].login.absolutePath.text); + FILE_DirectoryToParent(&data->clients[socketId].login.ftpPath.text); + data->clients[socketId].login.absolutePath.textLen = strlen(data->clients[socketId].login.absolutePath.text); + data->clients[socketId].login.ftpPath.textLen = strlen(data->clients[socketId].login.ftpPath.text); - if(strncmp(theClientData->login.absolutePath.text, theClientData->login.homePath.text, theClientData->login.homePath.textLen) != 0) + if(strncmp(data->clients[socketId].login.absolutePath.text, data->clients[socketId].login.homePath.text, data->clients[socketId].login.homePath.textLen) != 0) { - setDynamicStringDataType(&theClientData->login.absolutePath, theClientData->login.homePath.text, theClientData->login.homePath.textLen); + setDynamicStringDataType(&data->clients[socketId].login.absolutePath, data->clients[socketId].login.homePath.text, data->clients[socketId].login.homePath.textLen); } - returnCode = dprintf(theClientData->socketDescriptor, "250 OK. Current directory is %s\r\n", theClientData->login.ftpPath.text); + returnCode = socketPrintf(data, socketId, "sss", "250 OK. Current directory is ", data->clients[socketId].login.ftpPath.text, "\r\n"); if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR; @@ -1022,7 +1194,7 @@ int parseCommandCdup(clientDataType *theClientData) return FTP_COMMAND_PROCESSED; } -long long int writeRetrFile(char * theFilename, int thePasvSocketConnection, long long int startFrom, FILE *retrFP) +long long int writeRetrFile(ftpDataType * data, int theSocketId, long long int startFrom, FILE *retrFP) { long long int readen = 0; long long int toReturn = 0, writtenSize = 0; @@ -1030,12 +1202,14 @@ long long int writeRetrFile(char * theFilename, int thePasvSocketConnection, lon long long int theFileSize; char buffer[FTP_COMMAND_ELABORATE_CHAR_BUFFER]; - #ifdef _LARGEFILE64_SOURCE - retrFP = fopen64(theFilename, "rb"); + #ifdef LARGE_FILE_SUPPORT_ENABLED + //#warning LARGE FILE SUPPORT IS ENABLED! + retrFP = fopen64(data->clients[theSocketId].fileToRetr.text, "rb"); #endif - #ifndef _LARGEFILE64_SOURCE - retrFP = fopen(theFilename, "rb"); + #ifndef LARGE_FILE_SUPPORT_ENABLED + #warning LARGE FILE SUPPORT IS NOT ENABLED! + retrFP = fopen(data->clients[theSocketId].fileToRetr.text, "rb"); #endif if (retrFP == NULL) @@ -1047,12 +1221,13 @@ long long int writeRetrFile(char * theFilename, int thePasvSocketConnection, lon if (startFrom > 0) { - - #ifdef _LARGEFILE64_SOURCE + #ifdef LARGE_FILE_SUPPORT_ENABLED + //#warning LARGE FILE SUPPORT IS ENABLED! currentPosition = (long long int) lseek64(fileno(retrFP), startFrom, SEEK_SET); #endif - #ifndef _LARGEFILE64_SOURCE + #ifndef LARGE_FILE_SUPPORT_ENABLED + #warning LARGE FILE SUPPORT IS NOT ENABLED! currentPosition = (long long int) lseek(fileno(retrFP), startFrom, SEEK_SET); #endif @@ -1066,8 +1241,22 @@ long long int writeRetrFile(char * theFilename, int thePasvSocketConnection, lon while ((readen = (long long int) fread(buffer, sizeof(char), FTP_COMMAND_ELABORATE_CHAR_BUFFER, retrFP)) > 0) { - writtenSize = write(thePasvSocketConnection, buffer, readen); - + + if (data->clients[theSocketId].dataChannelIsTls != 1) + { + writtenSize = write(data->clients[theSocketId].workerData.socketConnection, buffer, readen); + } + else + { + + #ifdef OPENSSL_ENABLED + if (data->clients[theSocketId].workerData.passiveModeOn == 1) + writtenSize = SSL_write(data->clients[theSocketId].workerData.serverSsl, buffer, readen); + else if (data->clients[theSocketId].workerData.activeModeOn == 1) + writtenSize = SSL_write(data->clients[theSocketId].workerData.clientSsl, buffer, readen); + #endif + } + if (writtenSize <= 0) { fclose(retrFP); @@ -1194,6 +1383,7 @@ int getFtpCommandArgWithOptions(char * theCommand, char *theCommandString, ftpCo int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataType ownerShip) { + #define MAXIMUM_FILENAME_LEN 4096 #define STATUS_INCREASE 0 #define STATUS_PERMISSIONS 1 #define STATUS_LOCAL_PATH 2 @@ -1202,14 +1392,14 @@ int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataTyp int returnCode = 0; int status = STATUS_INCREASE; - char thePermissionString[1024]; - char theLocalPath[1024]; - char theFinalFilename[2048]; + char thePermissionString[MAXIMUM_FILENAME_LEN]; + char theLocalPath[MAXIMUM_FILENAME_LEN]; + char theFinalFilename[MAXIMUM_FILENAME_LEN]; int returnCodeSetPermissions, returnCodeSetOwnership; - memset(theLocalPath, 0, 1024); - memset(thePermissionString, 0, 1024); - memset(theFinalFilename, 0, 2048); + memset(theLocalPath, 0, MAXIMUM_FILENAME_LEN); + memset(thePermissionString, 0, MAXIMUM_FILENAME_LEN); + memset(theFinalFilename, 0, MAXIMUM_FILENAME_LEN); int thePermissionStringCursor = 0, theLocalPathCursor = 0; while (permissionsCommand[permissionsCommandCursor] != '\r' && @@ -1231,14 +1421,14 @@ int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataTyp status = STATUS_LOCAL_PATH; break; } - if (thePermissionStringCursor < 1024 ) + if (thePermissionStringCursor < MAXIMUM_FILENAME_LEN ) thePermissionString[thePermissionStringCursor++] = permissionsCommand[permissionsCommandCursor]; else return FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG; break; case STATUS_LOCAL_PATH: - if (theLocalPathCursor < 1024) + if (theLocalPathCursor < MAXIMUM_FILENAME_LEN) theLocalPath[theLocalPathCursor++] = permissionsCommand[permissionsCommandCursor]; else return FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG; @@ -1248,20 +1438,24 @@ int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataTyp permissionsCommandCursor++; } - memset(theFinalFilename, 0, 2048); - - if ((strlen(basePath) + strlen(theLocalPath) + 2) >= 2048) + if ((strlen(basePath) + strlen(theLocalPath) + 2) >= MAXIMUM_FILENAME_LEN) { return FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG; } if (basePath[strlen(basePath)-1] != '/') { - sprintf(theFinalFilename, "%s/%s", basePath, theLocalPath); + returnCode = snprintf(theFinalFilename, MAXIMUM_FILENAME_LEN, "%s/%s", basePath, theLocalPath); + + if (returnCode >= MAXIMUM_FILENAME_LEN) + return FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG; } else { - sprintf(theFinalFilename, "%s%s", basePath, theLocalPath); + returnCode = snprintf(theFinalFilename, MAXIMUM_FILENAME_LEN, "%s%s", basePath, theLocalPath); + + if (returnCode >= MAXIMUM_FILENAME_LEN) + return FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG; } if (FILE_IsFile(theFinalFilename) != 1 && @@ -1276,7 +1470,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"); } diff --git a/ftpCommandsElaborate.h b/ftpCommandsElaborate.h index 9a82fe5..a4a31cc 100644 --- a/ftpCommandsElaborate.h +++ b/ftpCommandsElaborate.h @@ -37,7 +37,8 @@ #define FTP_CHMODE_COMMAND_RETURN_CODE_NO_FILE 2 #define FTP_CHMODE_COMMAND_RETURN_CODE_NO_PERMISSIONS 3 #define FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG 4 - +#include +#include #include "ftpData.h" #ifdef __cplusplus @@ -46,39 +47,42 @@ extern "C" { /* Elaborate the User login command */ -int parseCommandUser(clientDataType *theClientData); -int parseCommandSite(clientDataType *theClientData); +int parseCommandUser(ftpDataType * data, int socketId); +int parseCommandSite(ftpDataType * data, int socketId); int parseCommandPass(ftpDataType * data, int socketId); -int parseCommandAuth(clientDataType *theClientData); -int parseCommandPwd(clientDataType *theClientData); -int parseCommandSyst(clientDataType *theClientData); -int parseCommandFeat(clientDataType *theClientData); -int parseCommandStruF(clientDataType *theClientData); -int parseCommandTypeI(clientDataType *theClientData); -int parseCommandModeS(clientDataType *theClientData); -int parseCommandTypeA(clientDataType *theClientData); +int parseCommandAuth(ftpDataType * data, int socketId); +int parseCommandPwd(ftpDataType * data, int socketId); +int parseCommandSyst(ftpDataType * data, int socketId); +int parseCommandFeat(ftpDataType * data, int socketId); +int parseCommandProt(ftpDataType * data, int socketId); +int parseCommandCcc(ftpDataType * data, int socketId); +int parseCommandPbsz(ftpDataType * data, int socketId); +int parseCommandStruF(ftpDataType * data, int socketId); +int parseCommandTypeI(ftpDataType * data, int socketId); +int parseCommandModeS(ftpDataType * data, int socketId); +int parseCommandTypeA(ftpDataType * data, int socketId); int parseCommandAbor(ftpDataType * data, int socketId); int parseCommandPasv(ftpDataType * data, int socketId); int parseCommandPort(ftpDataType * data, int socketId); int parseCommandList(ftpDataType * data, int socketId); int parseCommandNlst(ftpDataType * data, int socketId); int parseCommandRetr(ftpDataType * data, int socketId); -int parseCommandMkd(clientDataType *theClientData); -int parseCommandNoop(clientDataType *theClientData); -int notLoggedInMessage(clientDataType *theClientData); -int parseCommandRmd(clientDataType *theClientData); +int parseCommandMkd(ftpDataType * data, int socketId); +int parseCommandNoop(ftpDataType * data, int socketId); +int notLoggedInMessage(ftpDataType * data, int socketId); +int parseCommandRmd(ftpDataType * data, int socketId); int parseCommandQuit(ftpDataType * data, int socketId); -int parseCommandSize(clientDataType *theClientData); +int parseCommandSize(ftpDataType * data, int socketId); int parseCommandStor(ftpDataType * data, int socketId); -int parseCommandCwd(clientDataType *theClientData); -int parseCommandRest(clientDataType *theClientData); -int parseCommandCdup(clientDataType *theClientData); -int parseCommandDele(clientDataType *theClientData); -int parseCommandOpts(clientDataType *theClientData); -int parseCommandRnfr(clientDataType *theClientData); -int parseCommandRnto(clientDataType *theClientData); +int parseCommandCwd(ftpDataType * data, int socketId); +int parseCommandRest(ftpDataType * data, int socketId); +int parseCommandCdup(ftpDataType * data, int socketId); +int parseCommandDele(ftpDataType * data, int socketId); +int parseCommandOpts(ftpDataType * data, int socketId); +int parseCommandRnfr(ftpDataType * data, int socketId); +int parseCommandRnto(ftpDataType * data, int socketId); -long long int writeRetrFile(char * theFilename, int thePasvSocketConnection, long long int startFrom, FILE *retrFP); +long long int writeRetrFile(ftpDataType * data, int theSocketId, 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 b4aa33b..f4df1eb 100644 --- a/ftpData.c +++ b/ftpData.c @@ -36,6 +36,7 @@ #include "ftpData.h" #include "library/configRead.h" #include "library/fileManagement.h" +#include "library/connection.h" void cleanDynamicStringDataType(dynamicStringDataType *dynamicString, int init) { @@ -90,6 +91,7 @@ void setDynamicStringDataType(dynamicStringDataType *dynamicString, char *theStr int getSafePath(dynamicStringDataType *safePath, char *theDirectoryName, loginDataType *loginData) { + #define STRING_SIZE 4096 int theLen, i; char * theDirectoryNamePointer; theDirectoryNamePointer = theDirectoryName; @@ -123,9 +125,9 @@ int getSafePath(dynamicStringDataType *safePath, char *theDirectoryName, loginDa } //Check for /../ - char theDirectoryToCheck[2048]; + char theDirectoryToCheck[STRING_SIZE]; int theDirectoryToCheckIndex = 0; - memset(theDirectoryToCheck, 0, 2048); + memset(theDirectoryToCheck, 0, STRING_SIZE); for (i = 0; i< theLen; i++) { @@ -139,11 +141,11 @@ int getSafePath(dynamicStringDataType *safePath, char *theDirectoryName, loginDa } theDirectoryToCheckIndex = 0; - memset(theDirectoryToCheck, 0, 2048); + memset(theDirectoryToCheck, 0, STRING_SIZE); continue; } - if (theDirectoryToCheckIndex<2048) + if (theDirectoryToCheckIndexclients[socketPosition].workerData.connectionPort = randomicPort; - printf("data->clients[%d].workerData.connectionPort = %d", socketPosition, data->clients[socketPosition].workerData.connectionPort); + //printf("data->clients[%d].workerData.connectionPort = %d", socketPosition, data->clients[socketPosition].workerData.connectionPort); } -int writeListDataInfoToSocket(char * thePath, int theSocket, int *filesNumber, int commandType) +int writeListDataInfoToSocket(ftpDataType *ftpData, int clientId, int *filesNumber, int commandType) { int i, x, returnCode; int fileAndFoldersCount = 0; char **fileList = NULL; - FILE_GetDirectoryInodeList(thePath, &fileList, &fileAndFoldersCount, 0); + FILE_GetDirectoryInodeList(ftpData->clients[clientId].listPath.text, &fileList, &fileAndFoldersCount, 0); *filesNumber = fileAndFoldersCount; - returnCode = dprintf(theSocket, "total %d\r\n", fileAndFoldersCount); + returnCode = socketWorkerPrintf(ftpData, clientId, "sds", "total ", fileAndFoldersCount ,"\r\n"); if (returnCode <= 0) { return -1; @@ -241,14 +243,10 @@ int writeListDataInfoToSocket(char * thePath, int theSocket, int *filesNumber, i data.fileNameWithPath = NULL; data.finalStringPath = NULL; data.linkPath = NULL; - - data.isFile = 0; data.isDirectory = 0; - - + //printf("\nPROCESSING: %s", fileList[i]); - //fflush(0); if (FILE_IsDirectory(fileList[i]) == 1) { @@ -315,21 +313,37 @@ int writeListDataInfoToSocket(char * thePath, int theSocket, int *filesNumber, i { case COMMAND_TYPE_LIST: { + returnCode = socketWorkerPrintf(ftpData, clientId, "ssdssssslsssss", + data.inodePermissionString == NULL? "Unknown" : data.inodePermissionString + ," " + ,data.numberOfSubDirectories + ," " + ,data.owner == NULL? "Unknown" : data.owner + ," " + ,data.groupOwner == NULL? "Unknown" : data.groupOwner + ," " + ,data.fileSize + ," " + ,data.lastModifiedDataString == NULL? "Unknown" : data.lastModifiedDataString + ," " + ,data.finalStringPath == NULL? "Unknown" : data.finalStringPath + ,"\r\n"); + /* returnCode = dprintf(theSocket, "%s %d %s %s %lld %s %s\r\n", - data.inodePermissionString == NULL? "Uknown" : data.inodePermissionString + data.inodePermissionString == NULL? "Unknown" : data.inodePermissionString ,data.numberOfSubDirectories - ,data.owner == NULL? "Uknown" : data.owner - ,data.groupOwner == NULL? "Uknown" : data.groupOwner + ,data.owner == NULL? "Unknown" : data.owner + ,data.groupOwner == NULL? "Unknown" : data.groupOwner ,data.fileSize - ,data.lastModifiedDataString == NULL? "Uknown" : data.lastModifiedDataString - ,data.finalStringPath == NULL? "Uknown" : data.finalStringPath); - + ,data.lastModifiedDataString == NULL? "Unknown" : data.lastModifiedDataString + ,data.finalStringPath == NULL? "Unknown" : data.finalStringPath); + */ } break; case COMMAND_TYPE_NLST: { - returnCode = dprintf(theSocket, "%s\r\n",data.fileNameNoPath); + returnCode = socketWorkerPrintf(ftpData, clientId, "ss", data.fileNameNoPath, "\r\n"); } break; @@ -339,7 +353,6 @@ int writeListDataInfoToSocket(char * thePath, int theSocket, int *filesNumber, i printf("\nWarning switch default in function writeListDataInfoToSocket (%d)", commandType); } break; - } @@ -370,10 +383,12 @@ int writeListDataInfoToSocket(char * thePath, int theSocket, int *filesNumber, i } } - - if (fileList != NULL) - free (fileList); - + + if (fileList != NULL) + { + free (fileList); + } + return 1; } @@ -390,7 +405,10 @@ int searchInLoginFailsVector(void * loginFailsVector, void *element) return i; } } - + void cleanup_openssl() + { + EVP_cleanup(); + } return -1; } @@ -539,114 +557,150 @@ void deleteListDataInfoVector(void *TheElementToDelete) } } -void resetWorkerData(workerDataType *workerData, int isInitialization) +void resetWorkerData(ftpDataType *data, int clientId, int isInitialization) { - workerData->connectionPort = 0; - workerData->passiveModeOn = 0; - workerData->socketIsConnected = 0; - workerData->commandIndex = 0; - workerData->passiveListeningSocket = 0; - workerData->socketConnection = 0; - workerData->bufferIndex = 0; - workerData->commandReceived = 0; - workerData->retrRestartAtByte = 0; - workerData->threadIsAlive = 0; - workerData->activeModeOn = 0; - workerData->passiveModeOn = 0; - workerData->activeIpAddressIndex = 0; - memset(workerData->buffer, 0, CLIENT_BUFFER_STRING_SIZE); - memset(workerData->activeIpAddress, 0, CLIENT_BUFFER_STRING_SIZE); - memset(workerData->theCommandReceived, 0, CLIENT_BUFFER_STRING_SIZE); + data->clients[clientId].workerData.connectionPort = 0; + data->clients[clientId].workerData.passiveModeOn = 0; + data->clients[clientId].workerData.socketIsConnected = 0; + data->clients[clientId].workerData.commandIndex = 0; + data->clients[clientId].workerData.passiveListeningSocket = 0; + data->clients[clientId].workerData.socketConnection = 0; + data->clients[clientId].workerData.bufferIndex = 0; + data->clients[clientId].workerData.commandReceived = 0; + data->clients[clientId].workerData.retrRestartAtByte = 0; + data->clients[clientId].workerData.threadIsAlive = 0; + data->clients[clientId].workerData.activeModeOn = 0; + data->clients[clientId].workerData.passiveModeOn = 0; + data->clients[clientId].workerData.activeIpAddressIndex = 0; - cleanDynamicStringDataType(&workerData->ftpCommand.commandArgs, isInitialization); - cleanDynamicStringDataType(&workerData->ftpCommand.commandOps, isInitialization); + memset(data->clients[clientId].workerData.buffer, 0, CLIENT_BUFFER_STRING_SIZE); + memset(data->clients[clientId].workerData.activeIpAddress, 0, CLIENT_BUFFER_STRING_SIZE); + memset(data->clients[clientId].workerData.theCommandReceived, 0, CLIENT_BUFFER_STRING_SIZE); + + cleanDynamicStringDataType(&data->clients[clientId].workerData.ftpCommand.commandArgs, isInitialization); + cleanDynamicStringDataType(&data->clients[clientId].workerData.ftpCommand.commandOps, isInitialization); /* wait main for action */ if (isInitialization != 1) { - pthread_mutex_destroy(&workerData->conditionMutex); - pthread_cond_destroy(&workerData->conditionVariable); + pthread_mutex_destroy(&data->clients[clientId].workerData.conditionMutex); + pthread_cond_destroy(&data->clients[clientId].workerData.conditionVariable); - if (workerData->theStorFile != NULL) + if (data->clients[clientId].workerData.theStorFile != NULL) { - fclose(workerData->theStorFile); - workerData->theStorFile = NULL; + fclose(data->clients[clientId].workerData.theStorFile); + data->clients[clientId].workerData.theStorFile = NULL; } - + + #ifdef OPENSSL_ENABLED + SSL_free(data->clients[clientId].workerData.serverSsl); + SSL_free(data->clients[clientId].workerData.clientSsl); + #endif } else { - DYNV_VectorGeneric_Init(&workerData->directoryInfo); - workerData->theStorFile = NULL; + DYNV_VectorGeneric_Init(&data->clients[clientId].workerData.directoryInfo); + data->clients[clientId].workerData.theStorFile = NULL; + data->clients[clientId].workerData.threadHasBeenCreated = 0; + } + + if (pthread_mutex_init(&data->clients[clientId].workerData.conditionMutex, NULL) != 0) + { + 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"); + exit(0); } - pthread_mutex_init(&workerData->conditionMutex, NULL); - pthread_cond_init(&workerData->conditionVariable, NULL); - //Clear the dynamic vector structure - int theSize = workerData->directoryInfo.Size; + int theSize = data->clients[clientId].workerData.directoryInfo.Size; char ** lastToDestroy = NULL; if (theSize > 0) { - lastToDestroy = ((ftpListDataType *)workerData->directoryInfo.Data[0])->fileList; - workerData->directoryInfo.Destroy(&workerData->directoryInfo, deleteListDataInfoVector); + lastToDestroy = ((ftpListDataType *)data->clients[clientId].workerData.directoryInfo.Data[0])->fileList; + data->clients[clientId].workerData.directoryInfo.Destroy(&data->clients[clientId].workerData.directoryInfo, deleteListDataInfoVector); free(lastToDestroy); } + + #ifdef OPENSSL_ENABLED + data->clients[clientId].workerData.serverSsl = SSL_new(data->serverCtx); + data->clients[clientId].workerData.clientSsl = SSL_new(data->clientCtx); + #endif } -void resetClientData(clientDataType *clientData, int isInitialization) +void resetClientData(ftpDataType *data, int clientId, int isInitialization) { - if (isInitialization != 0) + + if (isInitialization != 1) { - if (clientData->workerData.threadIsAlive == 1) - { - void *pReturn; - pthread_cancel(clientData->workerData.workerThread); - pthread_join(clientData->workerData.workerThread, &pReturn); - } - else - { - void *pReturn; - pthread_join(clientData->workerData.workerThread, &pReturn); - } + void *pReturn; + if (data->clients[clientId].workerData.threadIsAlive == 1) + pthread_cancel(data->clients[clientId].workerData.workerThread); + + pthread_mutex_destroy(&data->clients[clientId].writeMutex); + + #ifdef OPENSSL_ENABLED + SSL_free(data->clients[clientId].ssl); + //SSL_free(data->clients[clientId].workerData.ssl); + #endif } - clientData->socketDescriptor = -1; - clientData->socketCommandReceived = 0; - clientData->socketIsConnected = 0; - clientData->bufferIndex = 0; - clientData->commandIndex = 0; - clientData->closeTheClient = 0; - clientData->sockaddr_in_size = sizeof(struct sockaddr_in); - clientData->sockaddr_in_server_size = sizeof(struct sockaddr_in); + if (pthread_mutex_init(&data->clients[clientId].writeMutex, NULL) != 0) + { + printf("\nclientData->writeMutex init failed\n"); + exit(0); + } + + data->clients[clientId].tlsIsNegotiating = 0; + data->clients[clientId].tlsIsEnabled = 0; + data->clients[clientId].dataChannelIsTls = 0; + data->clients[clientId].socketDescriptor = -1; + data->clients[clientId].socketCommandReceived = 0; + data->clients[clientId].socketIsConnected = 0; + data->clients[clientId].bufferIndex = 0; + data->clients[clientId].commandIndex = 0; + data->clients[clientId].closeTheClient = 0; + data->clients[clientId].sockaddr_in_size = sizeof(struct sockaddr_in); + data->clients[clientId].sockaddr_in_server_size = sizeof(struct sockaddr_in); - clientData->serverIpAddressInteger[0] = 0; - clientData->serverIpAddressInteger[1] = 0; - clientData->serverIpAddressInteger[2] = 0; - clientData->serverIpAddressInteger[3] = 0; + data->clients[clientId].serverIpAddressInteger[0] = 0; + data->clients[clientId].serverIpAddressInteger[1] = 0; + data->clients[clientId].serverIpAddressInteger[2] = 0; + data->clients[clientId].serverIpAddressInteger[3] = 0; - memset(&clientData->client_sockaddr_in, 0, clientData->sockaddr_in_size); - memset(&clientData->server_sockaddr_in, 0, clientData->sockaddr_in_server_size); - memset(clientData->clientIpAddress, 0, INET_ADDRSTRLEN); - memset(clientData->buffer, 0, CLIENT_BUFFER_STRING_SIZE); - memset(clientData->theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE); - cleanLoginData(&clientData->login, isInitialization); + memset(&data->clients[clientId].client_sockaddr_in, 0, data->clients[clientId].sockaddr_in_size); + memset(&data->clients[clientId].server_sockaddr_in, 0, data->clients[clientId].sockaddr_in_server_size); + memset(data->clients[clientId].clientIpAddress, 0, INET_ADDRSTRLEN); + memset(data->clients[clientId].buffer, 0, CLIENT_BUFFER_STRING_SIZE); + memset(data->clients[clientId].theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE); + cleanLoginData(&data->clients[clientId].login, isInitialization); //Rename from and to data init - cleanDynamicStringDataType(&clientData->renameFromFile, isInitialization); - cleanDynamicStringDataType(&clientData->renameToFile, isInitialization); - cleanDynamicStringDataType(&clientData->fileToStor, isInitialization); - cleanDynamicStringDataType(&clientData->fileToRetr, isInitialization); - cleanDynamicStringDataType(&clientData->listPath, isInitialization); - cleanDynamicStringDataType(&clientData->nlistPath, isInitialization); + cleanDynamicStringDataType(&data->clients[clientId].renameFromFile, isInitialization); + cleanDynamicStringDataType(&data->clients[clientId].renameToFile, isInitialization); + cleanDynamicStringDataType(&data->clients[clientId].fileToStor, isInitialization); + cleanDynamicStringDataType(&data->clients[clientId].fileToRetr, isInitialization); + cleanDynamicStringDataType(&data->clients[clientId].listPath, isInitialization); + cleanDynamicStringDataType(&data->clients[clientId].nlistPath, isInitialization); - cleanDynamicStringDataType(&clientData->ftpCommand.commandArgs, isInitialization); - cleanDynamicStringDataType(&clientData->ftpCommand.commandOps, isInitialization); + cleanDynamicStringDataType(&data->clients[clientId].ftpCommand.commandArgs, isInitialization); + cleanDynamicStringDataType(&data->clients[clientId].ftpCommand.commandOps, isInitialization); - clientData->connectionTimeStamp = 0; - clientData->lastActivityTimeStamp = 0; + data->clients[clientId].connectionTimeStamp = 0; + data->clients[clientId].tlsNegotiatingTimeStart = 0; + data->clients[clientId].lastActivityTimeStamp = 0; + + #ifdef OPENSSL_ENABLED + //data->clients[clientId].workerData.ssl = SSL_new(data->ctx); + data->clients[clientId].ssl = SSL_new(data->serverCtx); + #endif } int compareStringCaseInsensitive(char * stringIn, char * stringRef, int stringLenght) diff --git a/ftpData.h b/ftpData.h index 88f0a45..035b6fc 100644 --- a/ftpData.h +++ b/ftpData.h @@ -27,11 +27,14 @@ #define FTPDATA_H #include +#include +#include #include "library/dynamicVectors.h" -#define CLIENT_COMMAND_STRING_SIZE 2048 -#define CLIENT_BUFFER_STRING_SIZE 2048 +#define CLIENT_COMMAND_STRING_SIZE 4096 +#define CLIENT_BUFFER_STRING_SIZE 4096 +#define MAXIMUM_INODE_NAME 4096 #define LIST_DATA_TYPE_MODIFIED_DATA_STR_SIZE 1024 @@ -50,7 +53,6 @@ struct parameter char* value; } typedef parameter_DataType; - struct ownerShip { int ownerShipSet; @@ -80,10 +82,11 @@ struct ftpParameters int singleInstanceModeOn; DYNV_VectorGenericDataType usersVector; int maximumIdleInactivity; - int maximumConnectionsPerIp; int maximumUserAndPassowrdLoginTries; - + + char certificatePath[MAXIMUM_INODE_NAME]; + char privateCertificatePath[MAXIMUM_INODE_NAME]; } typedef ftpParameters_DataType; struct dynamicStringData @@ -116,7 +119,13 @@ struct ipData struct workerData { + #ifdef OPENSSL_ENABLED + SSL *serverSsl; + SSL *clientSsl; + #endif + int threadIsAlive; + int threadHasBeenCreated; int connectionPort; int passiveModeOn; int activeModeOn; @@ -147,6 +156,16 @@ struct workerData struct clientData { + #ifdef OPENSSL_ENABLED + SSL *ssl; + #endif + + int tlsIsEnabled; + int tlsIsNegotiating; + unsigned long long int tlsNegotiatingTimeStart; + int dataChannelIsTls; + pthread_mutex_t writeMutex; + int clientProgressiveNumber; int socketDescriptor; int socketIsConnected; @@ -202,6 +221,11 @@ struct ConnectionParameters struct ftpData { + #ifdef OPENSSL_ENABLED + SSL_CTX *serverCtx; + SSL_CTX *clientCtx; + #endif + int connectedClients; char welcomeMessage[1024]; ConnectionData_DataType connectionData; @@ -237,14 +261,15 @@ 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); +int writeListDataInfoToSocket(ftpDataType *data, int clientId, int *filesNumber, int commandType); int searchInLoginFailsVector(void *loginFailsVector, void *element); void deleteLoginFailsData(void *element); void deleteListDataInfoVector(void *TheElementToDelete); -void resetWorkerData(workerDataType *pasvData, int isInitialization); -void resetClientData(clientDataType *clientData, int isInitialization); +void resetWorkerData(ftpDataType *data, int clientId, int isInitialization); +void resetClientData(ftpDataType *data, int clientId, int isInitialization); int compareStringCaseInsensitive(char *stringIn, char* stringRef, int stringLenght); int isCharInString(char *theString, int stringLen, char theChar); +void destroyConfigurationVectorElement(void * data); #ifdef __cplusplus } #endif diff --git a/ftpServer.c b/ftpServer.c index 1c45ba0..d6ec03b 100644 --- a/ftpServer.c +++ b/ftpServer.c @@ -22,13 +22,10 @@ * THE SOFTWARE. */ - - #include #include #include #include - #include #include #include @@ -39,15 +36,15 @@ #include /* FTP LIBS */ -#include "ftpServer.h" -#include "ftpData.h" -#include "ftpCommandsElaborate.h" - #include "library/fileManagement.h" #include "library/logFunctions.h" #include "library/configRead.h" #include "library/signals.h" +#include "library/openSsl.h" #include "library/connection.h" +#include "ftpServer.h" +#include "ftpData.h" +#include "ftpCommandsElaborate.h" ftpDataType ftpData; @@ -55,13 +52,66 @@ static int processCommand(int processingElement); void workerCleanup(void *socketId) { - int theSocketId = *(int *)socketId; - //printf("\nClosing pasv socket (%d) ok!", theSocketId); + int theSocketId = *(int *)socketId; + int returnCode = 0; + + 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"); + returnCode = SSL_shutdown(ftpData.clients[theSocketId].workerData.serverSsl); + printf("\nnSSL worker Shutdown 1 return code : %d", returnCode); + + if (returnCode < 0) + { + printf("SSL_shutdown failed return code %d", returnCode); + } + else if (returnCode == 0) + { + printf("\nSSL worker Shutdown 2"); + returnCode = SSL_shutdown(ftpData.clients[theSocketId].workerData.serverSsl); + printf("\nnSSL worker Shutdown 2 return code : %d", returnCode); + + if (returnCode <= 0) + { + printf("SSL_shutdown (2nd time) failed"); + } + } + } + + if(ftpData.clients[theSocketId].workerData.activeModeOn == 1) + { + printf("\nSSL worker Shutdown 1"); + returnCode = SSL_shutdown(ftpData.clients[theSocketId].workerData.clientSsl); + printf(" return code : %d", returnCode); + + if (returnCode < 0) + { + printf("SSL_shutdown failed return code %d", returnCode); + } + else if (returnCode == 0) + { + returnCode = SSL_shutdown(ftpData.clients[theSocketId].workerData.clientSsl); + + if (returnCode <= 0) + { + printf("SSL_shutdown (2nd time) failed"); + } + } + } + } + #endif + shutdown(ftpData.clients[theSocketId].workerData.socketConnection, SHUT_RDWR); shutdown(ftpData.clients[theSocketId].workerData.passiveListeningSocket, SHUT_RDWR); close(ftpData.clients[theSocketId].workerData.socketConnection); close(ftpData.clients[theSocketId].workerData.passiveListeningSocket); - resetWorkerData(&ftpData.clients[theSocketId].workerData, 0); + resetWorkerData(&ftpData, theSocketId, 0); + printf("\nWorker cleaned!"); } void *connectionWorkerHandle(void * socketId) @@ -69,8 +119,11 @@ void *connectionWorkerHandle(void * socketId) int theSocketId = *(int *)socketId; pthread_cleanup_push(workerCleanup, (void *) &theSocketId); ftpData.clients[theSocketId].workerData.threadIsAlive = 1; + ftpData.clients[theSocketId].workerData.threadHasBeenCreated = 1; int returnCode; + printf("\nWORKER CREATED!"); + //Passive data connection mode if (ftpData.clients[theSocketId].workerData.passiveModeOn == 1) { @@ -84,9 +137,10 @@ void *connectionWorkerHandle(void * socketId) { break; } - + tries--; } + if (ftpData.clients[theSocketId].workerData.passiveListeningSocket == -1) { ftpData.clients[theSocketId].closeTheClient = 1; @@ -96,8 +150,7 @@ void *connectionWorkerHandle(void * socketId) if (ftpData.clients[theSocketId].workerData.socketIsConnected == 0) { - - returnCode = dprintf(ftpData.clients[theSocketId].socketDescriptor, "227 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n", ftpData.clients[theSocketId].serverIpAddressInteger[0], ftpData.clients[theSocketId].serverIpAddressInteger[1], ftpData.clients[theSocketId].serverIpAddressInteger[2], ftpData.clients[theSocketId].serverIpAddressInteger[3], (ftpData.clients[theSocketId].workerData.connectionPort / 256), (ftpData.clients[theSocketId].workerData.connectionPort % 256)); + returnCode = socketPrintf(&ftpData, theSocketId, "sdsdsdsdsdsds", "227 Entering Passive Mode (", ftpData.clients[theSocketId].serverIpAddressInteger[0], ",", ftpData.clients[theSocketId].serverIpAddressInteger[1], ",", ftpData.clients[theSocketId].serverIpAddressInteger[2], ",", ftpData.clients[theSocketId].serverIpAddressInteger[3], ",", (ftpData.clients[theSocketId].workerData.connectionPort / 256), ",", (ftpData.clients[theSocketId].workerData.connectionPort % 256), ")\r\n"); if (returnCode <= 0) { ftpData.clients[theSocketId].closeTheClient = 1; @@ -109,6 +162,32 @@ void *connectionWorkerHandle(void * socketId) if ((ftpData.clients[theSocketId].workerData.socketConnection = accept(ftpData.clients[theSocketId].workerData.passiveListeningSocket, 0, 0))!=-1) { ftpData.clients[theSocketId].workerData.socketIsConnected = 1; + #ifdef OPENSSL_ENABLED + if (ftpData.clients[theSocketId].dataChannelIsTls == 1) + { + + returnCode = SSL_set_fd(ftpData.clients[theSocketId].workerData.serverSsl, ftpData.clients[theSocketId].workerData.socketConnection); + + if (returnCode == 0) + { + printf("\nSSL ERRORS ON WORKER SSL_set_fd"); + ftpData.clients[theSocketId].closeTheClient = 1; + } + + returnCode = SSL_accept(ftpData.clients[theSocketId].workerData.serverSsl); + + if (returnCode <= 0) + { + printf("\nSSL ERRORS ON WORKER"); + ERR_print_errors_fp(stderr); + ftpData.clients[theSocketId].closeTheClient = 1; + } + else + { + printf("\nSSL ACCEPTED ON WORKER"); + } + } + #endif } else { @@ -122,6 +201,30 @@ void *connectionWorkerHandle(void * socketId) { ftpData.clients[theSocketId].workerData.socketConnection = createActiveSocket(ftpData.clients[theSocketId].workerData.connectionPort, ftpData.clients[theSocketId].workerData.activeIpAddress); + #ifdef OPENSSL_ENABLED + if (ftpData.clients[theSocketId].dataChannelIsTls == 1) + { + returnCode = SSL_set_fd(ftpData.clients[theSocketId].workerData.clientSsl, ftpData.clients[theSocketId].workerData.socketConnection); + + if (returnCode == 0) + { + printf("\nSSL ERRORS ON WORKER SSL_set_fd"); + ftpData.clients[theSocketId].closeTheClient = 1; + } + //SSL_set_connect_state(ftpData.clients[theSocketId].workerData.clientSsl); + returnCode = SSL_connect(ftpData.clients[theSocketId].workerData.clientSsl); + if (returnCode <= 0) + { + printf("\nSSL ERRORS ON WORKER %d error code: %d", returnCode, SSL_get_error(ftpData.clients[theSocketId].workerData.clientSsl, returnCode)); + ERR_print_errors_fp(stderr); + } + else + { + printf("\nSSL ACCEPTED ON WORKER"); + } + } + #endif + if (ftpData.clients[theSocketId].workerData.socketConnection < 0) { ftpData.clients[theSocketId].closeTheClient = 1; @@ -129,7 +232,7 @@ void *connectionWorkerHandle(void * socketId) pthread_exit(NULL); } - returnCode = dprintf(ftpData.clients[theSocketId].socketDescriptor, "200 connection accepted\r\n"); + returnCode = socketPrintf(&ftpData, theSocketId, "s", "200 connection accepted\r\n"); if (returnCode <= 0) { @@ -141,6 +244,9 @@ void *connectionWorkerHandle(void * socketId) ftpData.clients[theSocketId].workerData.socketIsConnected = 1; } + + printf("\nftpData.clients[theSocketId].workerData.socketIsConnected = %d", ftpData.clients[theSocketId].workerData.socketIsConnected); + //Endless loop ftp process while (1) { @@ -148,6 +254,7 @@ void *connectionWorkerHandle(void * socketId) if (ftpData.clients[theSocketId].workerData.socketIsConnected > 0) { + 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) @@ -156,23 +263,26 @@ void *connectionWorkerHandle(void * socketId) } pthread_mutex_unlock(&ftpData.clients[theSocketId].workerData.conditionMutex); + printf("\nWorker %d unlocked", theSocketId); + if (ftpData.clients[theSocketId].workerData.commandReceived == 1 && compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "STOR", strlen("STOR")) == 1 && ftpData.clients[theSocketId].fileToStor.textLen > 0) { - #ifdef _LARGEFILE64_SOURCE + #ifdef LARGE_FILE_SUPPORT_ENABLED + //#warning LARGE FILE SUPPORT IS ENABLED! ftpData.clients[theSocketId].workerData.theStorFile = fopen64(ftpData.clients[theSocketId].fileToStor.text, "wb"); #endif - #ifndef _LARGEFILE64_SOURCE + #ifndef LARGE_FILE_SUPPORT_ENABLED + #warning LARGE FILE SUPPORT IS NOT ENABLED! ftpData.clients[theSocketId].workerData.theStorFile = fopen(ftpData.clients[theSocketId].fileToStor.text, "wb"); #endif - if (ftpData.clients[theSocketId].workerData.theStorFile == NULL) - { - returnCode = dprintf(ftpData.clients[theSocketId].socketDescriptor, "553 Unable to write the file\r\n"); + { + returnCode = socketPrintf(&ftpData, theSocketId, "s", "553 Unable to write the file\r\n"); if (returnCode <= 0) { @@ -184,7 +294,7 @@ void *connectionWorkerHandle(void * socketId) break; } - returnCode = dprintf(ftpData.clients[theSocketId].socketDescriptor, "150 Accepted data connection\r\n"); + returnCode = socketPrintf(&ftpData, theSocketId, "s", "150 Accepted data connection\r\n"); if (returnCode <= 0) { @@ -195,8 +305,26 @@ void *connectionWorkerHandle(void * socketId) while(1) { - ftpData.clients[theSocketId].workerData.bufferIndex = read(ftpData.clients[theSocketId].workerData.socketConnection, ftpData.clients[theSocketId].workerData.buffer, CLIENT_BUFFER_STRING_SIZE); - + + if (ftpData.clients[theSocketId].dataChannelIsTls != 1) + { + ftpData.clients[theSocketId].workerData.bufferIndex = read(ftpData.clients[theSocketId].workerData.socketConnection, ftpData.clients[theSocketId].workerData.buffer, CLIENT_BUFFER_STRING_SIZE); + } + else if (ftpData.clients[theSocketId].dataChannelIsTls == 1) + { + + #ifdef OPENSSL_ENABLED + if (ftpData.clients[theSocketId].workerData.passiveModeOn == 1) + ftpData.clients[theSocketId].workerData.bufferIndex = SSL_read(ftpData.clients[theSocketId].workerData.serverSsl, ftpData.clients[theSocketId].workerData.buffer, CLIENT_BUFFER_STRING_SIZE); + else if(ftpData.clients[theSocketId].workerData.activeModeOn == 1) + ftpData.clients[theSocketId].workerData.bufferIndex = SSL_read(ftpData.clients[theSocketId].workerData.clientSsl, ftpData.clients[theSocketId].workerData.buffer, CLIENT_BUFFER_STRING_SIZE); + #endif + } + else + { + printf("\nError state"); + } + if (ftpData.clients[theSocketId].workerData.bufferIndex == 0) { break; @@ -213,14 +341,13 @@ void *connectionWorkerHandle(void * socketId) } fclose(ftpData.clients[theSocketId].workerData.theStorFile); ftpData.clients[theSocketId].workerData.theStorFile = NULL; - - + if (ftpData.clients[theSocketId].login.ownerShip.ownerShipSet == 1) { FILE_doChownFromUidGid(ftpData.clients[theSocketId].fileToStor.text, ftpData.clients[theSocketId].login.ownerShip.uid, ftpData.clients[theSocketId].login.ownerShip.gid); } - returnCode = dprintf(ftpData.clients[theSocketId].socketDescriptor, "226 file stor ok\r\n"); + returnCode = socketPrintf(&ftpData, theSocketId, "s", "226 file stor ok\r\n"); if (returnCode <= 0) { ftpData.clients[theSocketId].closeTheClient = 1; @@ -242,7 +369,7 @@ void *connectionWorkerHandle(void * socketId) else if (compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "NLST", strlen("NLST")) == 1) theCommandType = COMMAND_TYPE_NLST; - returnCode = dprintf(ftpData.clients[theSocketId].socketDescriptor, "150 Accepted data connection\r\n"); + returnCode = socketPrintf(&ftpData, theSocketId, "s", "150 Accepted data connection\r\n"); if (returnCode <= 0) { ftpData.clients[theSocketId].closeTheClient = 1; @@ -250,7 +377,8 @@ void *connectionWorkerHandle(void * socketId) pthread_exit(NULL); } - returnCode = writeListDataInfoToSocket(ftpData.clients[theSocketId].listPath.text, ftpData.clients[theSocketId].workerData.socketConnection, &theFiles, theCommandType); + //returnCode = writeListDataInfoToSocket(ftpData.clients[theSocketId].listPath.text, ftpData.clients[theSocketId].workerData.socketConnection, &theFiles, theCommandType); + returnCode = writeListDataInfoToSocket(&ftpData, theSocketId, &theFiles, theCommandType); if (returnCode <= 0) { ftpData.clients[theSocketId].closeTheClient = 1; @@ -258,7 +386,7 @@ void *connectionWorkerHandle(void * socketId) pthread_exit(NULL); } - returnCode = dprintf(ftpData.clients[theSocketId].socketDescriptor, "226 %d matches total\r\n", theFiles); + returnCode = socketPrintf(&ftpData, theSocketId, "sds", "226 ", theFiles, " matches total\r\n"); if (returnCode <= 0) { ftpData.clients[theSocketId].closeTheClient = 1; @@ -272,8 +400,7 @@ void *connectionWorkerHandle(void * socketId) compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "RETR", strlen("RETR")) == 1) { long long int writenSize = 0, writeReturn = 0; - - writeReturn = dprintf(ftpData.clients[theSocketId].socketDescriptor, "150 Accepted data connection\r\n"); + writeReturn = socketPrintf(&ftpData, theSocketId, "s", "150 Accepted data connection\r\n"); if (writeReturn <= 0) { ftpData.clients[theSocketId].closeTheClient = 1; @@ -282,12 +409,12 @@ void *connectionWorkerHandle(void * socketId) } - writenSize = writeRetrFile(ftpData.clients[theSocketId].fileToRetr.text, ftpData.clients[theSocketId].workerData.socketConnection, ftpData.clients[theSocketId].workerData.retrRestartAtByte, ftpData.clients[theSocketId].workerData.theStorFile); + writenSize = writeRetrFile(&ftpData, theSocketId, ftpData.clients[theSocketId].workerData.retrRestartAtByte, ftpData.clients[theSocketId].workerData.theStorFile); ftpData.clients[theSocketId].workerData.retrRestartAtByte = 0; if (writenSize == -1) { - writeReturn = dprintf(ftpData.clients[theSocketId].socketDescriptor, "550 unable to open the file for reading\r\n"); + writeReturn = socketPrintf(&ftpData, theSocketId, "s", "550 unable to open the file for reading\r\n"); if (writeReturn <= 0) { @@ -298,7 +425,7 @@ void *connectionWorkerHandle(void * socketId) break; } - writeReturn = dprintf(ftpData.clients[theSocketId].socketDescriptor, "226-File successfully transferred\r\n226 done\r\n"); + writeReturn = socketPrintf(&ftpData, theSocketId, "s", "226-File successfully transferred\r\n226 done\r\n"); if (writeReturn <= 0) { @@ -325,11 +452,11 @@ void *connectionWorkerHandle(void * socketId) void runFtpServer(void) { - printf("\nHello uFTP server v%s starting..\n", UFTP_SERVER_VERSION); - + /* Needed for Select*/ - static int processingSock = 0, returnCode = 0; + static int processingSock = 0, + returnCode = 0; /* Handle signals */ signalHandlerInstall(); @@ -352,6 +479,7 @@ void runFtpServer(void) /* the maximum socket fd is now the main socket descriptor */ ftpData.connectionData.maxSocketFD = ftpData.connectionData.theMainSocket+1; + //Endless loop ftp process while (1) @@ -359,9 +487,7 @@ void runFtpServer(void) /* waits for socket activity, if no activity then checks for client socket timeouts */ if (selectWait(&ftpData) == 0) { - checkClientConnectionTimeout(&ftpData); - flushLoginWrongTriesData(&ftpData); } @@ -380,7 +506,7 @@ void runFtpServer(void) { break; } - + /* no data to check client is not connected, continue to check other clients */ if (isClientConnected(&ftpData, processingSock) == 0) { @@ -391,8 +517,50 @@ void runFtpServer(void) if (FD_ISSET(ftpData.clients[processingSock].socketDescriptor, &ftpData.connectionData.rset) || FD_ISSET(ftpData.clients[processingSock].socketDescriptor, &ftpData.connectionData.eset)) { + + #ifdef OPENSSL_ENABLED + if (ftpData.clients[processingSock].tlsIsNegotiating == 1) + { + returnCode = SSL_accept(ftpData.clients[processingSock].ssl); + + if (returnCode <= 0) + { + printf("\nSSL NOT YET ACCEPTED: %d", returnCode); + ftpData.clients[processingSock].tlsIsEnabled = 0; + ftpData.clients[processingSock].tlsIsNegotiating = 1; + + if ( ((int)time(NULL) - ftpData.clients[processingSock].tlsNegotiatingTimeStart) > TLS_NEGOTIATING_TIMEOUT ) + { + ftpData.clients[processingSock].closeTheClient = 1; + printf("\nTLS timeout closing the client time:%lld, start time: %lld..", (int)time(NULL), ftpData.clients[processingSock].tlsNegotiatingTimeStart); + } + + } + else + { + printf("\nSSL ACCEPTED"); + ftpData.clients[processingSock].tlsIsEnabled = 1; + ftpData.clients[processingSock].tlsIsNegotiating = 0; + } + + + continue; + } + #endif + + if (ftpData.clients[processingSock].tlsIsEnabled == 1) + { + #ifdef OPENSSL_ENABLED + ftpData.clients[processingSock].bufferIndex = SSL_read(ftpData.clients[processingSock].ssl, ftpData.clients[processingSock].buffer, CLIENT_BUFFER_STRING_SIZE); + #endif + } + else + { + ftpData.clients[processingSock].bufferIndex = read(ftpData.clients[processingSock].socketDescriptor, ftpData.clients[processingSock].buffer, CLIENT_BUFFER_STRING_SIZE); + } + //The client is not connected anymore - if ((ftpData.clients[processingSock].bufferIndex = read(ftpData.clients[processingSock].socketDescriptor, ftpData.clients[processingSock].buffer, CLIENT_BUFFER_STRING_SIZE)) == 0) + if ((ftpData.clients[processingSock].bufferIndex) == 0) { fdRemove(&ftpData, processingSock); closeSocket(&ftpData, processingSock); @@ -403,7 +571,7 @@ void runFtpServer(void) //Debug print errors if (ftpData.clients[processingSock].bufferIndex < 0) { - ftpData.clients[processingSock].closeTheClient = 1; + //ftpData.clients[processingSock].closeTheClient = 1; printf("\n1 Errno = %d", errno); perror("1 Error: "); continue; @@ -426,15 +594,16 @@ 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) { int returnCode = 0; - returnCode = dprintf(ftpData.clients[processingSock].socketDescriptor, "500 Unknown command\r\n"); + returnCode = socketPrintf(&ftpData, processingSock, "s", "500 Unknown command\r\n"); if (returnCode < 0) { - ftpData.clients[processingSock].closeTheClient = 1; + ftpData.clients[processingSock].closeTheClient = 1; } printf("\n COMMAND NOT SUPPORTED ********* %s", ftpData.clients[processingSock].buffer); } @@ -446,7 +615,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!"); } } } @@ -456,7 +625,7 @@ void runFtpServer(void) int returnCode; ftpData.clients[processingSock].commandIndex = 0; memset(ftpData.clients[processingSock].theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE); - returnCode = dprintf(ftpData.clients[processingSock].socketDescriptor, "500 Unknown command\r\n"); + returnCode = socketPrintf(&ftpData, processingSock, "s", "500 Unknown command\r\n"); if (returnCode <= 0) ftpData.clients[processingSock].closeTheClient = 1; @@ -481,8 +650,8 @@ void runFtpServer(void) static int processCommand(int processingElement) { int toReturn = 0; - printTimeStamp(); - printf ("Command received from (%d): %s", processingElement, ftpData.clients[processingElement].theCommandReceived); + //printTimeStamp(); + //printf ("Command received from (%d): %s", processingElement, ftpData.clients[processingElement].theCommandReceived); cleanDynamicStringDataType(&ftpData.clients[processingElement].ftpCommand.commandArgs, 0); cleanDynamicStringDataType(&ftpData.clients[processingElement].ftpCommand.commandOps, 0); @@ -491,9 +660,12 @@ static int processCommand(int processingElement) (compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "USER", strlen("USER")) != 1 && compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PASS", strlen("PASS")) != 1 && compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "QUIT", strlen("QUIT")) != 1 && + compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PBSZ", strlen("PBSZ")) != 1 && + compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PROT", strlen("PROT")) != 1 && + compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "CCC", strlen("CCC")) != 1 && compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "AUTH", strlen("AUTH")) != 1)) { - toReturn = notLoggedInMessage(&ftpData.clients[processingElement]); + toReturn = notLoggedInMessage(&ftpData, processingElement); ftpData.clients[processingElement].commandIndex = 0; memset(ftpData.clients[processingElement].theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE); return 1; @@ -503,7 +675,7 @@ static int processCommand(int processingElement) if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "USER", strlen("USER")) == 1) { printf("\nUSER COMMAND RECEIVED"); - toReturn = parseCommandUser(&ftpData.clients[processingElement]); + toReturn = parseCommandUser(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PASS", strlen("PASS")) == 1) { @@ -513,47 +685,62 @@ static int processCommand(int processingElement) else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "SITE", strlen("SITE")) == 1) { printf("\nSITE COMMAND RECEIVED"); - toReturn = parseCommandSite(&ftpData.clients[processingElement]); + toReturn = parseCommandSite(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "AUTH", strlen("AUTH")) == 1) { printf("\nAUTH COMMAND RECEIVED"); - toReturn = parseCommandAuth(&ftpData.clients[processingElement]); + toReturn = parseCommandAuth(&ftpData, processingElement); + } + else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PROT", strlen("PROT")) == 1) + { + printf("\nPROT COMMAND RECEIVED"); + toReturn = parseCommandProt(&ftpData, processingElement); + } + else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PBSZ", strlen("PBSZ")) == 1) + { + printf("\nPBSZ COMMAND RECEIVED"); + toReturn = parseCommandPbsz(&ftpData, processingElement); + } + else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "CCC", strlen("CCC")) == 1) + { + printf("\nCCC COMMAND RECEIVED"); + toReturn = parseCommandCcc(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PWD", strlen("PWD")) == 1) { printf("\nPWD COMMAND RECEIVED"); - toReturn = parseCommandPwd(&ftpData.clients[processingElement]); + toReturn = parseCommandPwd(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "SYST", strlen("SYST")) == 1) { printf("\nSYST COMMAND RECEIVED"); - toReturn = parseCommandSyst(&ftpData.clients[processingElement]); + toReturn = parseCommandSyst(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "FEAT", strlen("FEAT")) == 1) { printf("\nFEAT COMMAND RECEIVED"); - toReturn = parseCommandFeat(&ftpData.clients[processingElement]); + toReturn = parseCommandFeat(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "TYPE I", strlen("TYPE I")) == 1) { printf("\nTYPE I COMMAND RECEIVED"); - toReturn = parseCommandTypeI(&ftpData.clients[processingElement]); + toReturn = parseCommandTypeI(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "STRU F", strlen("STRU F")) == 1) { printf("\nTYPE I COMMAND RECEIVED"); - toReturn = parseCommandStruF(&ftpData.clients[processingElement]); + toReturn = parseCommandStruF(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "MODE S", strlen("MODE S")) == 1) { printf("\nMODE S COMMAND RECEIVED"); - toReturn = parseCommandModeS(&ftpData.clients[processingElement]); + toReturn = parseCommandModeS(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "TYPE A", strlen("TYPE A")) == 1) { printf("\nTYPE A COMMAND RECEIVED"); - toReturn = parseCommandTypeI(&ftpData.clients[processingElement]); + toReturn = parseCommandTypeI(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PASV", strlen("PASV")) == 1) { @@ -573,17 +760,17 @@ static int processCommand(int processingElement) else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "CWD", strlen("CWD")) == 1) { printf("\nCWD COMMAND RECEIVED"); - toReturn = parseCommandCwd(&ftpData.clients[processingElement]); + toReturn = parseCommandCwd(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "CDUP", strlen("CDUP")) == 1) { printf("\nCDUP COMMAND RECEIVED"); - toReturn = parseCommandCdup(&ftpData.clients[processingElement]); + toReturn = parseCommandCdup(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "REST", strlen("REST")) == 1) { printf("\nREST COMMAND RECEIVED"); - toReturn = parseCommandRest(&ftpData.clients[processingElement]); + toReturn = parseCommandRest(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "RETR", strlen("RETR")) == 1) { @@ -598,7 +785,7 @@ static int processCommand(int processingElement) else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "MKD", strlen("MKD")) == 1) { printf("\nMKD command received"); - toReturn = parseCommandMkd(&ftpData.clients[processingElement]); + toReturn = parseCommandMkd(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "ABOR", strlen("ABOR")) == 1) { @@ -608,12 +795,12 @@ static int processCommand(int processingElement) else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "DELE", strlen("DELE")) == 1) { printf("\nDELE command received"); - toReturn = parseCommandDele(&ftpData.clients[processingElement]); + toReturn = parseCommandDele(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "OPTS", strlen("OPTS")) == 1) { printf("\nOPTS command received"); - toReturn = parseCommandOpts(&ftpData.clients[processingElement]); + toReturn = parseCommandOpts(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "MTDM", strlen("MTDM")) == 1) { @@ -638,23 +825,23 @@ static int processCommand(int processingElement) else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "RMD", strlen("RMD")) == 1) { printf("\nRMD command received"); - toReturn = parseCommandRmd(&ftpData.clients[processingElement]); + toReturn = parseCommandRmd(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "RNFR", strlen("RNFR")) == 1) { printf("\nRNFR command received"); - toReturn = parseCommandRnfr(&ftpData.clients[processingElement]); + toReturn = parseCommandRnfr(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "RNTO", strlen("RNTO")) == 1) { printf("\nRNTO command received"); - toReturn = parseCommandRnto(&ftpData.clients[processingElement]); + toReturn = parseCommandRnto(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "SIZE", strlen("SIZE")) == 1) { printf("\nSIZE command received"); - toReturn = parseCommandSize(&ftpData.clients[processingElement]); + toReturn = parseCommandSize(&ftpData, processingElement); } else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "APPE", strlen("APPE")) == 1) { @@ -664,7 +851,7 @@ static int processCommand(int processingElement) else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "NOOP", strlen("NOOP")) == 1) { printf("\nNOOP command received"); - toReturn = parseCommandNoop(&ftpData.clients[processingElement]); + toReturn = parseCommandNoop(&ftpData, processingElement); } else { @@ -675,3 +862,13 @@ static int processCommand(int processingElement) memset(ftpData.clients[processingElement].theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE); return toReturn; } + +void deallocateMemory(void) +{ + printf("\n Deallocating the memory.. "); + + #ifdef OPENSSL_ENABLED + SSL_CTX_free(ftpData.serverCtx); + cleanupOpenssl(); + #endif +} diff --git a/ftpServer.h b/ftpServer.h index ea57c39..6b7b673 100644 --- a/ftpServer.h +++ b/ftpServer.h @@ -27,12 +27,14 @@ #define FTPSERVER_H #define MAX_FTP_CLIENTS 10 -#define UFTP_SERVER_VERSION "1.0.1 beta" +#define UFTP_SERVER_VERSION "2.0.0 beta" + void runFtpServer(void); void *connectionWorkerHandle(void * socketId); void workerCleanup(void *socketId); void signal_callback_handler(int signum); +void deallocateMemory(void); #endif /* FTPSERVER_H */ diff --git a/key.pem b/key.pem new file mode 100644 index 0000000..e4666a6 --- /dev/null +++ b/key.pem @@ -0,0 +1,51 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIJKQIBAAKCAgEAxtffV5tVrEF9pXAVaDmA2ObGchVThV+8P78W0bJFOBNqDlIr +mDtSgNdA/MUOndLGgit2VeQo35w5YCxHpX8aR/hm3LNwK7MOy8Vq0xtafasSzdZA +uv1Qfq8QyVNOc4lZXOHURAmULooj4tM5a0jbQjGhB85FWyhlZDMLM+d4/1C17C6H +OS9jpFgyoCPADsUmqHDJ4gKn6ly8lW5ulDtDwjIXFJSFq+NqQ7DnZburpxVxbJzy +2vdySatxEbfVoQNUyInJWQ5sxlIk4uFmfeixmponX+IWfv6bQ2x4oH93o0av1wb4 +/bJj8C92wmxO2a6sH8gQjOR7jDoXBuRAu8ghPzEXRDMfmWUcdHIQDymgWOb63JPF ++9MLZK/Q8WB1xGYdZ98qvvVmOmTqTeuAzGhQDMfxA4OSeLmdD//aI/6ciGqxUrGN +JVf6jyNtu72bCd/R553/STp+X9CIGRlBKlHL523YBkVEo6UFGtCqfMIQOtIS/frg +fq48UpYICyVBkPv6bvHkJjGJYswLs//saEnfv4bunMAgzkn/GXVMxMMnEQXwHNtT +qinLkFltsEc8kr9KHUx/T+QIZrqzDJmS7HLWuneMyBstSvY4XP83TjiuzVm5R7Ut +qmEOwx5kdVFH7/2x03Hm+GsC59xPDnb77l2h64FaLnizvgn01JMSE7+jHeMCAwEA +AQKCAgBGXzwB602kywDGviY1XrSFDxeIZJfMihc7kEtpJ2hr8iMEsnwPQl9ujb/I +NY14uZHbm7ojp733dXiw2rr4jUUl13m//hlivdosr8+gqvuZoiPjiUIba29Dhn2w +YrVPGnrv7lSLR8CTv/v3WL3nhD9k69+Lvaq6Gk/X6GC8m90srsnTrpvY1zaygSxZ +lI1yLMADuPcZ78qxnOR5Fj44Y8kVP1j/xZiRPsjq7/7U+FhFp8ceo2UnrY9bFzvL +A36tn1owJuOFix9gCM5ZJWB6ixHgH1J0ErXXeBBHCmqekr4qoOe2eBdC4hGQfZvQ +LziwvarZDJse4fX/qMdhfwKR8sAg1svVREB9/EfnKKGuKvhCxb0hbBfA/ctMAQOG +kZeupEOaEsaA5f3cNVU9GOedy2zYxAtXc2oJRQA02H7Ta4WSglq4qhj5VWu+jm7O +M7QGH8iQ6Ldo9UpHKwVSP+GmdDef55EmWwNxmnz2vpllpw+RzFRTkSmSQoG7HTcS +5NlCwm6VaA9gflKwHukNe1Zt5QYsx+eyatJc5X38nNCOrg369QBFuDMOtgwQQ8Z5 +0KqiunCP1KZg/0NHjPNBvUEruYc8KIa1j8S4koqPmc9OXT7/NXSkDAbVH8qRigad +GLBXyX8ePPLp2D9Q6ad4QRMKhcdpY49dl0dXFHvCk6ySPZ7cIQKCAQEA9uZ+meYq +p7TW24Zw3Uu8y2kSm/gXFCBefYrWR2W1X0OiiEEbOz2DEDlBcrsJof1dj/9QAHDW +T5VMQBbFBRFhMdkIFacqd3C3D3ZtDzXMcv2VtbuouYrScRe2+Z6wbNQkC1ICYa6h +PExkgCgZJlPjNjNfF0uo+QUjfEtTk9AdoV+BHJYzX/wT3i3+dnlPUQr5NpBajz51 +IZJaMpkK5sr4ae39NZxaq1mzOEpdXqiD1ooggSloL6CLtgf1aIn77oRKyiSyIKjY +obyu1AfdZixSosyoTZGEqTBDhlk4jKb6Thohj+yTV/9td0vF+m/zmxNR31vGKHrH +/MFhzffe/naOiwKCAQEAziv1ekGY+3U4QmbXh9bPH00aEEAB9J9gY9vXzUy3ojtL +BQJd5kcnp9peJX+7dNxAcB99Ws5+YHpP08Q19Mlb+ziMQAFnK80bGEFtVlvyyvK7 +MHeHMssbO377ksyilFmpvjXGTIJVhV5CNN7KeKVDw84jf0iYYjFcRuZe6scVJIHl +7GLNj1CewXBYzAF3MVdv0xErlKzXpbukDkMEr+qIaCQtSMXp9daQpHlgHl6OT/T2 +tdrGxfO2MfTmk9TEKUDeRi0DV6AO6fAwXGyE+GtAdFlHmzufyMgfQOQybDnSUvUN +NHVdM++qEK7v1B/zVXb3o1qlE+0hc8t3A7cuFf6xCQKCAQEAkZPifffamrvkG9gv +YCwyC3XOxSwI35MeY8OjCMINqTgF83UAC3P/fWdlEbL6wQrVSfxuPXRKyO3s4bUL +Qiu3NV8Uhz/jqD1LktBvCZLdE8g1p8wYdh5GauxitNg+ikyjXBFk2hfPdfBNKct6 +2MCJrgGoReIUpY/EFpuLkhIaBnZ7eFGPxT6qsExKR6zLeauQuf1viBp5kevrRv46 +EU8IHd13eU7Rn0rqg3xFhXSzF6Kl+8JgbgSpnBEhQBxr8X0LZBky9lLYOLU6GEby +4jWsG9W0PthYcjHE/shIsZYa7EY4F9aUIkS3VKnW+A1eg8dmdN51/pQ2qu+TLZDD +aSKadQKCAQEApy2yEf6bJFv60K0/2+Btdz44AjFE5K1PpemgZdLtnNljjZ5LsezE +1TEW4mVfBfWLMt/17+o9Q9IqZNdXwTR+J4nFACmjFTtt2w9Cr6JDkBmffD+QG7ni +TS48pN7WfmDuaVSFhYix/EFggiqeF5I7Ds1ar12YYxcPclZfZRUlqcLDRBkiAjIn +aUfGWTZfBl2WSZpEsnwtKTCsaPwjEtqk3X1oUvhZLIVeKGBbdoTJ9T/3xaKvR9jF +RmEFj54ZqjH1iwX5Dda2ATBIpslAUYf2beHvVIrWmCLeZOolkOiaCba3jHAWsYSH +bJvN0T5PPGAJkiZwcWX5mEHGMfcZobAysQKCAQBYlQZR5ziU1igh7+OMqxKzLNKr +TNc8uuDDSIeVRgxpBq+Ub1U1Ct7UxbfI2JGWKJ1Q7gwm5M/asYX9nFm8aRbcAL7e +AcP9gXCFUq6bndk0XF7LfhvmavLOBlAbOiBozQsUKG0eLH24zBkkIShRGxtLyA8+ +r98RRylaPsDPfegLBb45QW1DzeC6ZEoJ1plTWJonh65+l6ADtA9iF5ZxixXV6LUD +ID4+KlRnj7ycAo++329VdvtCbRrozrrV0SNWzOlin4mUq6UKcugGvwgV8rZSIADP +sh1d6YA3nFICcNgY8qhSTv8iN6QYBpQRoVonCbIksfgd3vR5hT6d75Ivq1iq +-----END RSA PRIVATE KEY----- diff --git a/key.pem.cfr b/key.pem.cfr new file mode 100644 index 0000000..4192fd0 --- /dev/null +++ b/key.pem.cfr @@ -0,0 +1,54 @@ +-----BEGIN ENCRYPTED PRIVATE KEY----- +MIIJnDBOBgkqhkiG9w0BBQ0wQTApBgkqhkiG9w0BBQwwHAQIk9UFKRwEjw8CAggA +MAwGCCqGSIb3DQIJBQAwFAYIKoZIhvcNAwcECGutkv5IqpwYBIIJSOqHgV8C9ZRY +okfTbCG9TxaCwX8Lxy0+7/FK2hpRDv3WwdNN5YYyr7iTUl5EiL2MsBpWshtIpT0H +P4ODORNWA1ZbQAYdPvdwsyo+Q1+A9j9Cl02Us9t8D2OSHWjxKzaJJrWgROtHicYP +t1V3tgLpQikG8idL9/eIy4os/i3HMZPTRrzs7XfsH5YWQKEcHS0hjJkeZy5uVAKz +J2UEiQJBS/DP+bvS0dTyU8JwbXpVjSXFHNWy0a5AhdddXL5etWWaZn+VJaWjvYI6 +IkOP6bk0V9YcbvLm5rmXoWkQ3ZufFP+T/HU1bFFEpy1H1aV9aE91UBXxQm9ShOIU +0f9itc19JUg1P7Z1IK7J3f332Wy2/tjVX/XQ5rQqMrC/qsH9llfBeZshb+2SmNzC +vs88hSH4KZ2dAehyUazW4z6RGzH26V+CK2MXc1UV3ocTRvhiMux2XFlni1yyd0hy +2uSFT6a2rRPMoVzW0mLzu4qTgFf0vDaihGrJGFZH/WBcSiSvKzSDg86LfO5ZVAWQ +JHAdP4il9IraMQo9ugAK/EmkDDGN+d0VnLAmtuwkxAI/QhUGYkGfGIn8FEx8xLpL +lGcQqwJQBmd3FL6oOpISvaba+ZeawK7QtUjGiWj7IjahJLdmrnI5W8dLf7l+rQRY +VYfv4qvoB5oZLrS7/DGBQs/zNv9uY6pKv4dwoilGkv+hTbAtfMp/VlqhM49mSgdA +nNXnRGy0dfG3R8nymcaCXz5gU3VLB7J8Gcmo93L9XKz9LCUjourmCW2u9hDMXBXh +La/6F88wOiwhi1ZfLQjMr+eaM0QjVWhrt9GnRl9Qp6qGmiAErnWUeMl2iYnEx0kq +PvfmdlMiZpnw4JcErblFR4XWyGwfH9EBpU7t9CLTkqqgW+vJdYBIXisy9AWwJOrB +746BiceBwW2HpaEcskeh3DRtLp6FJM7pCUfyfNLzII28/p1z+ZmY8RAro+Nhiv2j +SOz4ZvwKTt7CKYmZj6IQw4+fxzysHAV4wYSAGYcztOHnK7PVwqb+kvfmCTfvnnUX +BPOULPex7dtzQWuGFGWL0+rpygzvnzD/TWj1DyWCpxCpcPfRGwBU9mWgfMibOJ2Y +f52TIlf2EWgHOBJJFlT2WVu2lPTV7V1twtssvDrhvpzP6D3Di3VRnF3aEGkMPW6J +Y6iJpMpc3SxcgP2V+0Sgqghw2VsU3BALGVtY7VcSpQXP0FwhuRlYSwz1HuKsnYbs +OnGnKTtWBTUYPtW+kPsyQ3CRIPicJrzV3uAEo9SGZvcxSIi06FI7VBjpLeqYv4tU +or7PILQrETIgPWr2HRXn/I6Gj9T0I0FwhJFPEVvIAmDRnZs0/j5/QJBLj3CI0jCN +nAg6rsjicBKw564+8xPtkWM8/RgSF/t4Wg6Bp6iA2EiPxfCW4BCBqYyMlMTFKy3h +RRdXqPCE8j1JFdTlQFw6fjEAq780Uoc6kLi5bDs/mWWaKYII/1Kn7+KT91XDz4Bv +pZBTxgIGgkbNGB/drF+I4jRgn8+sPRXBoIItKpQBPxjKnISJ3HUG703XQPxfJo+p +nw5/lRw4DafBOY4AIL4dG0aiRT7G6hyrf1jTQgme4k/vRy+WIcxIiSo4lIYA4zqb +6E2T55S2fCLmRsZus4f2s7xHf677rCEon2Z44zDhVlmr1C8HXbaitvEWsflSAQ8+ +kgD2PgqmT/D/GXCikbwyHt1aRJh0ze1rPqnR35gR3giSe+7LXB2KMCq4qVfTbM9s +QCLBPc+Xkg7V8B/xGKPvQscsP5ZojVIlQDW03fT9EN8kFFgPuzYMamP48AKly4HT +6ADWaVM1u6OpwSK5dxdBUXiNmqCkCEGX8UUXiWSbmsxNjmSUM8DCikCCUf//ZGC1 +ZuDA6WowQh5l9dPKhAINDof+cjmrojX2YQbXo9QTkTVopEPxeued9abrS+r7w3k7 +ltwZOb31Ifzx0kx1uFlEKPMX6vL2atFhPPZY4Yg1d97oBVwIlxnUERr4pE/+Bz6y +fbDAeyXI9GUWbPLM/tMx3TuCRc1daMQml/8wCj1S5bnWNB7MQiadce9eHc8UZXRv +a1NWeJxRElS+TY89ou81CUgwISdu6QUMZwIXITYPFBnMnlh+l1R4JUxB5+PhwZmJ +SQUunfXnLhRzCj2ch9dt9bgOVdKm/KuSz0CSwdEtopLyDXZSyvinx/G1jqSUWhlB +y6DFwERdLGQcO3srrTpF2B+8IIljdozk+F2tCjCb8Aal01iJ/0Km3MC4czK2wkiV +5U0ahcwEgA5lH/5TSUubLlxvSsOTqXGfuyOtk2WLHwDdBCBJcw5y9YrJvJeIFNb0 +z/5b1p6b2R4vHjt4cQYYvQJ5YiK/yFbEcqNVmC7yiTb4jZifwpfaTVygmU2Yz9wl +rArPAERSiCTsce/5DGsW9tqeeHvKSt7wMJeEiuKWvegp8yvOqy57u3nsZv++bx1a +N1Y0bqxbc6iW/eUJ7M7ekTJIvM5rAp2aShPlg+fHJnUHddl7RnSo+QyKwTYYeRDw +fluSfoMB+F7j42auh7GnOV4Mdpw4CyXW4SbFrsrJiPQx3JXqLCMw9sgw0k/33IVc +Zx6Lca9KjUwtgsK0oTUMvvN8M/tL1z17Lf/KKQ7JMw4ANtnQSRARkElLJ7IAhM6K +5bHbPaNGr3Uj/r2wrrvAdjbe2uIyAmW8kP65l5Aw1cHh3GNbc23oSfE7yVBeoEHo +QVc4GX5waiqtgfjhbb8u+KD+26y3W6wq0clTseTq1tw0qWU3uCJbG/4//nbtf6/e +hoR7gux+YRliEqAkVhIQFMtMQNSViAx5liPIwklZ68qKmHQ779C1OUqBwoYSHRUg +JzWCLmcAjd1v16na+CRjpyPi7zdEeC2JJq7Aq6Kd6z8mxbHAwd03ZkFaf8NRukh6 +B1b4G2AwQVFMBKCHV/bourQgmc9HbxquT7BOMQrMtXcCJZ3d8S/xaMqUdgtJcJvY +HLJ2pchHH/14crDeE2eUobRt50LEC8aoqn+LeCtJtM8AW1qnPoVUR8ng/jL5ABqw ++bEdTualgsLaBay+4VwoaypxAFh1WZKew+2mkoANLFtWWfOB/HazNh442iOsv5g2 +ptRDth1SZsFhKa0ovi88avQji3zBQWoz7lp9L4W7VR2Y8bR33KHG2T9sTdv/+rxG +K2EdyPkehQ1J4kxpT5WkMQ== +-----END ENCRYPTED PRIVATE KEY----- diff --git a/library/configRead.c b/library/configRead.c index c75139b..47cc5d3 100644 --- a/library/configRead.c +++ b/library/configRead.c @@ -30,6 +30,7 @@ #include "configRead.h" #include "../ftpData.h" #include "dynamicVectors.h" +#include "openSsl.h" #include "fileManagement.h" #include "daemon.h" @@ -40,6 +41,12 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve static int searchParameter(char *name, DYNV_VectorGenericDataType *parametersVector); static int readConfigurationFile(char *path, DYNV_VectorGenericDataType *parametersVector); +void destroyConfigurationVectorElement(void * data) +{ + free( ((parameter_DataType *) data)->value); + free( ((parameter_DataType *) data)->name); +} + /* Public Functions */ int searchUser(char *name, DYNV_VectorGenericDataType *usersVector) { @@ -66,20 +73,12 @@ void configurationRead(ftpParameters_DataType *ftpParameters) if (FILE_IsFile(LOCAL_CONFIGURATION_FILENAME) == 1) { printf("\nReading configuration from \n -> %s \n", LOCAL_CONFIGURATION_FILENAME); - returnCode = readConfigurationFile(LOCAL_CONFIGURATION_FILENAME, &configParameters); - - printf("\nDONE\n"); - } else if (FILE_IsFile(DEFAULT_CONFIGURATION_FILENAME) == 1) { printf("\nReading configuration from \n -> %s\n", DEFAULT_CONFIGURATION_FILENAME); - returnCode = readConfigurationFile(DEFAULT_CONFIGURATION_FILENAME, &configParameters); - - printf("\nDONE\n"); - } if (returnCode == 1) @@ -92,6 +91,9 @@ void configurationRead(ftpParameters_DataType *ftpParameters) exit(1); } + + DYNV_VectorGeneric_Destroy(&configParameters, destroyConfigurationVectorElement); + return; } @@ -117,10 +119,18 @@ void applyConfiguration(ftpParameters_DataType *ftpParameters) void initFtpData(ftpDataType *ftpData) { - int i; + int i; /* Intializes random number generator */ srand(time(NULL)); + #ifdef OPENSSL_ENABLED + initOpenssl(); + ftpData->serverCtx = createServerContext(); + ftpData->clientCtx = createClientContext(); + configureContext(ftpData->serverCtx, ftpData->ftpParameters.certificatePath, ftpData->ftpParameters.privateCertificatePath); + configureClientContext(ftpData->clientCtx, ftpData->ftpParameters.certificatePath, ftpData->ftpParameters.privateCertificatePath); + #endif + ftpData->connectedClients = 0; ftpData->clients = (clientDataType *) calloc( sizeof(clientDataType), ftpData->ftpParameters.maxClients); @@ -137,8 +147,8 @@ void initFtpData(ftpDataType *ftpData) //Client data reset to zero for (i = 0; i < ftpData->ftpParameters.maxClients; i++) { - resetWorkerData(&ftpData->clients[i].workerData, 1); - resetClientData(&ftpData->clients[i], 1); + resetWorkerData(ftpData, i, 1); + resetClientData(ftpData, i, 1); ftpData->clients[i].clientProgressiveNumber = i; } @@ -481,6 +491,31 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve printf("\nFTP_SERVER_IP parameter not found in the configuration file, listening on all available networks"); } + + searchIndex = searchParameter("CERTIFICATE_PATH", parametersVector); + if (searchIndex != -1) + { + strcpy(ftpParameters->certificatePath, ((parameter_DataType *) parametersVector->Data[searchIndex])->value); + 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); + } + + 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); + } + else + { + strcpy(ftpParameters->privateCertificatePath, "key.pem"); + printf("\nPRIVATE_CERTIFICATE_PATH parameter not found in the configuration file, using the default value: %s", ftpParameters->privateCertificatePath); + } + /* USER SETTINGS */ userIndex = 0; memset(userX, 0, PARAMETER_SIZE_LIMIT); @@ -492,14 +527,14 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve DYNV_VectorGeneric_Init(&ftpParameters->usersVector); while(1) { - int searchUserIndex, searchPasswordIndex, searchHomeIndex, searchUserOwnerIndex, searchGroupOwnerIndex; + int searchUserIndex, searchPasswordIndex, searchHomeIndex, searchUserOwnerIndex, searchGroupOwnerIndex, returnCode; usersParameters_DataType userData; - sprintf(userX, "USER_%d", userIndex); - sprintf(passwordX, "PASSWORD_%d", userIndex); - sprintf(homeX, "HOME_%d", userIndex); - sprintf(groupOwnerX, "GROUP_NAME_OWNER_%d", userIndex); - sprintf(userOwnerX, "USER_NAME_OWNER_%d", userIndex); + returnCode = snprintf(userX, PARAMETER_SIZE_LIMIT, "USER_%d", userIndex); + returnCode = snprintf(passwordX, PARAMETER_SIZE_LIMIT, "PASSWORD_%d", userIndex); + returnCode = snprintf(homeX, PARAMETER_SIZE_LIMIT, "HOME_%d", userIndex); + returnCode = snprintf(groupOwnerX, PARAMETER_SIZE_LIMIT, "GROUP_NAME_OWNER_%d", userIndex); + returnCode = snprintf(userOwnerX, PARAMETER_SIZE_LIMIT, "USER_NAME_OWNER_%d", userIndex); userIndex++; searchUserIndex = searchParameter(userX, parametersVector); @@ -568,8 +603,7 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve 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)); } diff --git a/library/connection.c b/library/connection.c index 2219009..3c4103d 100644 --- a/library/connection.c +++ b/library/connection.c @@ -34,10 +34,238 @@ #include #include #include +#include + #include "../ftpData.h" #include "connection.h" + + +int socketPrintf(ftpDataType * ftpData, int clientId, const char *__restrict __fmt, ...) +{ + #define COMMAND_BUFFER 9600 + #define SOCKET_PRINTF_BUFFER 2048 + int bytesWritten = 0; + char theBuffer[SOCKET_PRINTF_BUFFER]; + char commandBuffer[COMMAND_BUFFER]; + 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); + + pthread_mutex_lock(&ftpData->clients[clientId].writeMutex); + + va_list args; + va_start(args, __fmt); + while (*__fmt != '\0') + { + int i = 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); + } + break; + + case 'c': + case 'C': + { + int theCharInteger = va_arg(args, int); + memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER); + theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER, "%c", theCharInteger); + } + break; + + case 'f': + case 'F': + { + float theDouble = va_arg(args, double); + memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER); + theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER, "%f", theDouble); + } + break; + + case 's': + case 'S': + { + char * theString = va_arg(args, char *); + memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER); + theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER, "%s", theString); + } + break; + + case 'l': + 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); + } + break; + + default: + { + printf("\n Switch is default (%c)", *__fmt); + } + break; + } + + for (i = 0; i clients[clientId].tlsIsEnabled != 1) + { + bytesWritten = write(ftpData->clients[clientId].socketDescriptor, commandBuffer, theCommandSize); + } + else if (ftpData->clients[clientId].tlsIsEnabled == 1) + { + #ifdef OPENSSL_ENABLED + bytesWritten = SSL_write(ftpData->clients[clientId].ssl, commandBuffer, theCommandSize); + #endif + } + + printf("\n%s", commandBuffer); + + pthread_mutex_unlock(&ftpData->clients[clientId].writeMutex); + + return bytesWritten; +} + +int socketWorkerPrintf(ftpDataType * ftpData, int clientId, const char *__restrict __fmt, ...) +{ + #define SOCKET_PRINTF_BUFFER 2048 + + int bytesWritten = 0; + char theBuffer[SOCKET_PRINTF_BUFFER]; + int theStringSize = 0; + memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER); + printf("\nWriting to worker socket id %dd, TLS %d: ", clientId, ftpData->clients[clientId].dataChannelIsTls); + 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); + } + break; + + case 'c': + case 'C': + { + int theCharInteger = va_arg(args, int); + memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER); + theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER, "%c", theCharInteger); + } + break; + + case 'f': + case 'F': + { + float theDouble = va_arg(args, double); + memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER); + theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER, "%f", theDouble); + } + break; + + case 's': + case 'S': + { + char * theString = va_arg(args, char *); + memset(&theBuffer, 0, SOCKET_PRINTF_BUFFER); + theStringSize = snprintf(theBuffer, SOCKET_PRINTF_BUFFER, "%s", theString); + } + break; + + case 'l': + 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); + } + break; + + default: + { + printf("\n Switch is default (%c)", *__fmt); + } + 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; + } + + va_end(args); + return bytesWritten; +} + /* Return the higher socket available*/ int getMaximumSocketFd(int mainSocket, ftpDataType * ftpData) { @@ -132,7 +360,9 @@ 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); + //sleep(100); memset(&serv_addr, 0, sizeof(struct sockaddr_in)); serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(port); @@ -211,8 +441,8 @@ void closeSocket(ftpDataType * ftpData, int processingSocket) shutdown(ftpData->clients[processingSocket].socketDescriptor, SHUT_RDWR); close(ftpData->clients[processingSocket].socketDescriptor); - resetClientData(&ftpData->clients[processingSocket], 0); - resetWorkerData(&ftpData->clients[processingSocket].workerData, 0); + resetClientData(ftpData, processingSocket, 0); + resetWorkerData(ftpData, processingSocket, 0); //Update client connecteds ftpData->connectedClients--; @@ -232,10 +462,10 @@ void closeClient(ftpDataType * ftpData, int processingSocket) if (ftpData->clients[processingSocket].workerData.threadIsAlive == 1) { - void *pReturn; - pthread_cancel(ftpData->clients[processingSocket].workerData.workerThread); - pthread_join(ftpData->clients[processingSocket].workerData.workerThread, &pReturn); - printf("\nQuit command received the Pasv Thread has been cancelled."); + void *pReturn; + pthread_cancel(ftpData->clients[processingSocket].workerData.workerThread); + //pthread_join(ftpData->clients[processingSocket].workerData.workerThread, &pReturn); + printf("\nQuit command received the Pasv Thread has been cancelled."); } FD_CLR(ftpData->clients[processingSocket].socketDescriptor, &ftpData->connectionData.rsetAll); @@ -381,12 +611,16 @@ int evaluateClientSocketConnection(ftpDataType * ftpData) if (ftpData->ftpParameters.maximumConnectionsPerIp > 0 && numberOfConnectionFromSameIp >= ftpData->ftpParameters.maximumConnectionsPerIp) { - dprintf(ftpData->clients[availableSocketIndex].socketDescriptor, "530 too many connection from your ip address %s \r\n", ftpData->clients[availableSocketIndex].clientIpAddress); + int theReturnCode = socketPrintf(ftpData, availableSocketIndex, "sss", "530 too many connection from your ip address ", ftpData->clients[availableSocketIndex].clientIpAddress, " \r\n"); ftpData->clients[availableSocketIndex].closeTheClient = 1; } else { - write(ftpData->clients[availableSocketIndex].socketDescriptor, ftpData->welcomeMessage, strlen(ftpData->welcomeMessage)); + int returnCode = socketPrintf(ftpData, availableSocketIndex, "s", ftpData->welcomeMessage); + if (returnCode <= 0) + { + ftpData->clients[availableSocketIndex].closeTheClient = 1; + } } return 1; @@ -410,14 +644,9 @@ int evaluateClientSocketConnection(ftpDataType * ftpData) write(socketRefuseFd, messageToWrite, strlen(messageToWrite)); shutdown(socketRefuseFd, SHUT_RDWR); close(socketRefuseFd); - return 0; - } - else - { - ftpData->clients[availableSocketIndex].closeTheClient = 1; - printf("\n3 Errno = %d", errno); - return 1; } + + return 0; } } else diff --git a/library/connection.h b/library/connection.h index 2382ce7..7f95c7d 100644 --- a/library/connection.h +++ b/library/connection.h @@ -48,7 +48,8 @@ int selectWait(ftpDataType * ftpData); int isClientConnected(ftpDataType * ftpData, int cliendId); int getAvailableClientSocketIndex(ftpDataType * ftpData); int evaluateClientSocketConnection(ftpDataType * ftpData); - +int socketPrintf(ftpDataType * ftpData, int clientId, const char *__restrict __fmt, ...); +int socketWorkerPrintf(ftpDataType * ftpData, int clientId, const char *__restrict __fmt, ...); #ifdef __cplusplus diff --git a/library/daemon.c b/library/daemon.c index 28854f0..17b83af 100644 --- a/library/daemon.c +++ b/library/daemon.c @@ -44,7 +44,8 @@ int isProcessAlreadyRunning(void) { int fd; int returnCode; - char buf[16]; + char buf[30]; + memset(buf, 0,30); fd = open(LOCKFILE, O_RDWR|O_CREAT, LOCKMODE); if (fd < 0) { @@ -66,8 +67,8 @@ int isProcessAlreadyRunning(void) //printf("\nFILE_LockFile returnCode = %d", returnCode); ftruncate(fd, 0); - sprintf(buf, "%ld", (long)getpid()); - write(fd, buf, strlen(buf)+1); + returnCode = snprintf(buf, 100, "%ld", (long)getpid()); + returnCode = write(fd, buf, strlen(buf)+1); return(0); } @@ -133,4 +134,4 @@ void daemonize(const char *cmd) fd0 = open("/dev/null", O_RDWR); fd1 = dup(0); fd2 = dup(0); - } \ No newline at end of file + } diff --git a/library/fileManagement.c b/library/fileManagement.c index 1096750..c9fb21a 100644 --- a/library/fileManagement.c +++ b/library/fileManagement.c @@ -91,7 +91,8 @@ long int FILE_GetAvailableSpace(const char* path) /* Get the file size */ long long int FILE_GetFileSize(FILE *TheFilePointer) { -#ifdef _LARGEFILE64_SOURCE +#ifdef LARGE_FILE_SUPPORT_ENABLED + //#warning LARGE FILE SUPPORT IS ENABLED! long long int Prev = 0, TheFileSize = 0; Prev = ftello64(TheFilePointer); fseeko64(TheFilePointer, 0, SEEK_END); @@ -100,7 +101,8 @@ long long int FILE_GetFileSize(FILE *TheFilePointer) return TheFileSize; #endif -#ifndef _LARGEFILE64_SOURCE +#ifndef LARGE_FILE_SUPPORT_ENABLED + #warning LARGE FILE SUPPORT IS NOT ENABLED! long long int Prev = 0, TheFileSize = 0; Prev = ftell(TheFilePointer); fseek(TheFilePointer, 0, SEEK_END); @@ -114,7 +116,8 @@ long long int FILE_GetFileSizeFromPath(char *TheFileName) { -#ifdef _LARGEFILE64_SOURCE +#ifdef LARGE_FILE_SUPPORT_ENABLED + //#warning LARGE FILE SUPPORT IS ENABLED! if (FILE_IsFile(TheFileName) == 1) { FILE *TheFilePointer; @@ -133,7 +136,8 @@ long long int FILE_GetFileSizeFromPath(char *TheFileName) } #endif -#ifndef _LARGEFILE64_SOURCE +#ifndef LARGE_FILE_SUPPORT_ENABLED +#warning LARGE FILE SUPPORT IS NOT ENABLED! if (FILE_IsFile(TheFileName) == 1) { FILE *TheFilePointer; @@ -160,11 +164,13 @@ int FILE_IsFile(const char *TheFileName) { FILE *TheFile; - #ifdef _LARGEFILE64_SOURCE + #ifdef LARGE_FILE_SUPPORT_ENABLED + //#warning LARGE FILE SUPPORT IS ENABLED! TheFile = fopen64(TheFileName, "rb"); #endif - #ifndef _LARGEFILE64_SOURCE + #ifndef LARGE_FILE_SUPPORT_ENABLED +#warning LARGE FILE SUPPORT IS NOT ENABLED! TheFile = fopen(TheFileName, "rb"); #endif @@ -190,7 +196,7 @@ void FILE_GetDirectoryInodeList(char * DirectoryInodeName, char *** InodeList, i if (FILE_IsDirectory(DirectoryInodeName)) { - printf("\nReading directory: %s", DirectoryInodeName); + //printf("\nReading directory: %s", DirectoryInodeName); DIR *TheDirectory; struct dirent *dir; @@ -293,11 +299,13 @@ int FILE_GetStringFromFile(char * filename, char **file_content) } - #ifdef _LARGEFILE64_SOURCE + #ifdef LARGE_FILE_SUPPORT_ENABLED + //#warning LARGE FILE SUPPORT IS ENABLED! FILE *file = fopen64(filename, "rb"); #endif - #ifndef _LARGEFILE64_SOURCE + #ifndef LARGE_FILE_SUPPORT_ENABLED +#warning LARGE FILE SUPPORT IS NOT ENABLED! FILE *file = fopen(filename, "rb"); #endif diff --git a/library/openSsl.c b/library/openSsl.c new file mode 100644 index 0000000..0a92bfa --- /dev/null +++ b/library/openSsl.c @@ -0,0 +1,229 @@ +/* + * The MIT License + * + * Copyright 2018 Ugo Cirmignani. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifdef OPENSSL_ENABLED +#include +#include +#include +#include +#include +#include +#include + +#include "openSsl.h" +#include "fileManagement.h" + + + + +#define MUTEX_TYPE pthread_mutex_t +#define MUTEX_SETUP(x) pthread_mutex_init(&(x), NULL) +#define MUTEX_CLEANUP(x) pthread_mutex_destroy(&(x)) +#define MUTEX_LOCK(x) pthread_mutex_lock(&(x)) +#define MUTEX_UNLOCK(x) pthread_mutex_unlock(&(x)) +#define THREAD_ID pthread_self() + +/* This array will store all of the mutexes available to OpenSSL. */ +static MUTEX_TYPE *mutex_buf = NULL; + +void initOpenssl() +{ + OpenSSL_add_all_algorithms(); /* Load cryptos, et.al. */ + SSL_load_error_strings(); /* Bring in and register error messages */ + ERR_load_BIO_strings(); + ERR_load_crypto_strings(); + SSL_library_init(); + thread_setup(); +} + +void cleanupOpenssl() +{ + thread_cleanup(); + EVP_cleanup(); +} + +SSL_CTX *createServerContext() +{ + const SSL_METHOD *method; + SSL_CTX *ctx; + + method = TLS_server_method(); + + ctx = SSL_CTX_new(method); + if (!ctx) + { + perror("Unable to create server SSL context"); + ERR_print_errors_fp(stderr); + exit(0); + } + + return ctx; +} + +SSL_CTX *createClientContext(void) +{ + const SSL_METHOD *method; + SSL_CTX *ctx; + method = TLS_client_method(); /* Create new client-method instance */ + ctx = SSL_CTX_new(method); /* Create new context */ + //SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1); + //SSL_CTX_set_options(ctx, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION | SSL_OP_CIPHER_SERVER_PREFERENCE| SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1); + //SSL_CTX_set_ecdh_auto(ctx, 1); + + if (ctx == NULL) + { + perror("Unable to create server SSL context"); + ERR_print_errors_fp(stderr); + abort(); + exit(0); + } + return ctx; +} + + +void configureClientContext(SSL_CTX *ctx, char *certificatePath, char* privateCertificatePath) +{/* + if (FILE_IsFile(certificatePath) != 1) + { + printf("\ncertificate file: %s not found!", certificatePath); + exit(0); + } + + if (FILE_IsFile(privateCertificatePath) != 1) + { + printf("\ncertificate file: %s not found!", privateCertificatePath); + exit(0); + } + + Set the key and cert + if (SSL_CTX_use_certificate_file(ctx, certificatePath, SSL_FILETYPE_PEM) <= 0) { + ERR_print_errors_fp(stderr); + exit(EXIT_FAILURE); + } + + if (SSL_CTX_use_PrivateKey_file(ctx, privateCertificatePath, SSL_FILETYPE_PEM) <= 0 ) { + ERR_print_errors_fp(stderr); + exit(EXIT_FAILURE); + } */ +} + +void configureContext(SSL_CTX *ctx, char *certificatePath, char* privateCertificatePath) +{ + if (FILE_IsFile(certificatePath) != 1) + { + printf("\ncertificate file: %s not found!", certificatePath); + exit(0); + } + + if (FILE_IsFile(privateCertificatePath) != 1) + { + printf("\ncertificate file: %s not found!", privateCertificatePath); + exit(0); + } + + SSL_CTX_set_ecdh_auto(ctx, 1); + + /* Set the key and cert */ + if (SSL_CTX_use_certificate_file(ctx, certificatePath, SSL_FILETYPE_PEM) <= 0) { + ERR_print_errors_fp(stderr); + exit(EXIT_FAILURE); + } + + if (SSL_CTX_use_PrivateKey_file(ctx, privateCertificatePath, SSL_FILETYPE_PEM) <= 0 ) { + ERR_print_errors_fp(stderr); + exit(EXIT_FAILURE); + } +} + + +void ShowCerts(SSL* ssl) +{ X509 *cert; + char *line; + + cert = SSL_get_peer_certificate(ssl); /* get the server's certificate */ + if ( cert != NULL ) + { + printf("Server certificates:\n"); + line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0); + printf("Subject: %s\n", line); + free(line); /* free the malloc'ed string */ + line = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0); + printf("Issuer: %s\n", line); + free(line); /* free the malloc'ed string */ + X509_free(cert); /* free the malloc'ed certificate copy */ + } + else + printf("No certificates.\n"); +} + + +void handle_error(const char *file, int lineno, const char *msg) +{ + fprintf(stderr, "** %s:%d %s\n", file, lineno, msg); + ERR_print_errors_fp(stderr); + /* exit(-1); */ +} + +static void locking_function(int mode, int n, const char *file, int line) +{ + if(mode & CRYPTO_LOCK) + MUTEX_LOCK(mutex_buf[n]); + else + MUTEX_UNLOCK(mutex_buf[n]); +} + +static unsigned long id_function(void) +{ + return ((unsigned long)THREAD_ID); +} + +int thread_setup(void) +{ + int i; + + mutex_buf = malloc(CRYPTO_num_locks() * sizeof(MUTEX_TYPE)); + if(!mutex_buf) + return 0; + for(i = 0; i < CRYPTO_num_locks(); i++) + MUTEX_SETUP(mutex_buf[i]); + CRYPTO_set_id_callback(id_function); + CRYPTO_set_locking_callback(locking_function); + return 1; +} + +int thread_cleanup(void) +{ + int i; + + if(!mutex_buf) + return 0; + CRYPTO_set_id_callback(NULL); + CRYPTO_set_locking_callback(NULL); + for(i = 0; i < CRYPTO_num_locks(); i++) + MUTEX_CLEANUP(mutex_buf[i]); + free(mutex_buf); + mutex_buf = NULL; + return 1; +} + +#endif diff --git a/library/openSsl.h b/library/openSsl.h new file mode 100644 index 0000000..8c13924 --- /dev/null +++ b/library/openSsl.h @@ -0,0 +1,52 @@ +/* + * The MIT License + * + * Copyright 2018 Ugo Cirmignani. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifdef OPENSSL_ENABLED +#ifndef OPENSSL_H +#define OPENSSL_H + +#include +#include + +#define TLS_NEGOTIATING_TIMEOUT 30 + +#ifdef __cplusplus +extern "C" { +#endif + +void initOpenssl(); +void cleanupOpenssl(); +int thread_cleanup(void); +int thread_setup(void); +void handle_error(const char *file, int lineno, const char *msg); +SSL_CTX *createServerContext(); +SSL_CTX *createClientContext(); +void configureContext(SSL_CTX *ctx, char *certificatePath, char* privateCertificatePath); +void configureClientContext(SSL_CTX *ctx, char *certificatePath, char* privateCertificatePath); +void ShowCerts(SSL* ssl); +#ifdef __cplusplus +} +#endif + +#endif /* OPENSSL_H */ +#endif diff --git a/library/signals.c b/library/signals.c index 9b080fa..62b35ca 100644 --- a/library/signals.c +++ b/library/signals.c @@ -56,9 +56,17 @@ static void ignore_sigpipe(void) } } +void onUftpClose(int sig) +{ + printf("\nuFTP exit()\n"); + deallocateMemory(); + exit(0); +} + void signalHandlerInstall(void) { //signal(SIGPIPE, signal_callback_handler); + signal(SIGINT,onUftpClose); signal(SIGUSR2,SIG_IGN); signal(SIGPIPE,SIG_IGN); signal(SIGALRM,SIG_IGN); diff --git a/library/signals.h b/library/signals.h index d6570f1..792e6da 100644 --- a/library/signals.h +++ b/library/signals.h @@ -31,6 +31,7 @@ extern "C" { void signalHandlerInstall(void); void signal_callback_handler(int signum); +void onUftpClose(int sig); #ifdef __cplusplus } diff --git a/nbproject/Makefile-Debug.mk b/nbproject/Makefile-Debug.mk deleted file mode 100644 index e44ad8f..0000000 --- a/nbproject/Makefile-Debug.mk +++ /dev/null @@ -1,143 +0,0 @@ -# -# Generated Makefile - do not edit! -# -# Edit the Makefile in the project folder instead (../Makefile). Each target -# has a -pre and a -post target defined where you can add customized code. -# -# This makefile implements configuration specific macros and targets. - - -# Environment -MKDIR=mkdir -CP=cp -GREP=grep -NM=nm -CCADMIN=CCadmin -RANLIB=ranlib -CC=gcc -CCC=g++ -CXX=g++ -FC=gfortran -AS=as - -# Macros -CND_PLATFORM=GNU-Linux -CND_DLIB_EXT=so -CND_CONF=Debug -CND_DISTDIR=dist -CND_BUILDDIR=build - -# Include project Makefile -include Makefile - -# Object Directory -OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM} - -# Object Files -OBJECTFILES= \ - ${OBJECTDIR}/ftpCommandElaborate.o \ - ${OBJECTDIR}/ftpData.o \ - ${OBJECTDIR}/ftpServer.o \ - ${OBJECTDIR}/library/configRead.o \ - ${OBJECTDIR}/library/connection.o \ - ${OBJECTDIR}/library/daemon.o \ - ${OBJECTDIR}/library/dynamicVectors.o \ - ${OBJECTDIR}/library/fileManagement.o \ - ${OBJECTDIR}/library/logFunctions.o \ - ${OBJECTDIR}/library/signals.o \ - ${OBJECTDIR}/uFTP.o - - -# C Compiler Flags -CFLAGS=-pthread - -# CC Compiler Flags -CCFLAGS= -CXXFLAGS= - -# Fortran Compiler Flags -FFLAGS= - -# Assembler Flags -ASFLAGS= - -# Link Libraries and Options -LDLIBSOPTIONS= - -# Build Targets -.build-conf: ${BUILD_SUBPROJECTS} - "${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/uftp - -${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/uftp: ${OBJECTFILES} - ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} - ${LINK.c} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/uftp ${OBJECTFILES} ${LDLIBSOPTIONS} - -${OBJECTDIR}/ftpCommandElaborate.o: ftpCommandElaborate.c - ${MKDIR} -p ${OBJECTDIR} - ${RM} "$@.d" - $(COMPILE.c) -g -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/ftpCommandElaborate.o ftpCommandElaborate.c - -${OBJECTDIR}/ftpData.o: ftpData.c - ${MKDIR} -p ${OBJECTDIR} - ${RM} "$@.d" - $(COMPILE.c) -g -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/ftpData.o ftpData.c - -${OBJECTDIR}/ftpServer.o: ftpServer.c - ${MKDIR} -p ${OBJECTDIR} - ${RM} "$@.d" - $(COMPILE.c) -g -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/ftpServer.o ftpServer.c - -${OBJECTDIR}/library/configRead.o: library/configRead.c - ${MKDIR} -p ${OBJECTDIR}/library - ${RM} "$@.d" - $(COMPILE.c) -g -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/configRead.o library/configRead.c - -${OBJECTDIR}/library/connection.o: library/connection.c - ${MKDIR} -p ${OBJECTDIR}/library - ${RM} "$@.d" - $(COMPILE.c) -g -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/connection.o library/connection.c - -${OBJECTDIR}/library/daemon.o: library/daemon.c - ${MKDIR} -p ${OBJECTDIR}/library - ${RM} "$@.d" - $(COMPILE.c) -g -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/daemon.o library/daemon.c - -${OBJECTDIR}/library/dynamicVectors.o: library/dynamicVectors.c - ${MKDIR} -p ${OBJECTDIR}/library - ${RM} "$@.d" - $(COMPILE.c) -g -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/dynamicVectors.o library/dynamicVectors.c - -${OBJECTDIR}/library/fileManagement.o: library/fileManagement.c - ${MKDIR} -p ${OBJECTDIR}/library - ${RM} "$@.d" - $(COMPILE.c) -g -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/fileManagement.o library/fileManagement.c - -${OBJECTDIR}/library/logFunctions.o: library/logFunctions.c - ${MKDIR} -p ${OBJECTDIR}/library - ${RM} "$@.d" - $(COMPILE.c) -g -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/logFunctions.o library/logFunctions.c - -${OBJECTDIR}/library/signals.o: library/signals.c - ${MKDIR} -p ${OBJECTDIR}/library - ${RM} "$@.d" - $(COMPILE.c) -g -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/signals.o library/signals.c - -${OBJECTDIR}/uFTP.o: uFTP.c - ${MKDIR} -p ${OBJECTDIR} - ${RM} "$@.d" - $(COMPILE.c) -g -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/uFTP.o uFTP.c - -# Subprojects -.build-subprojects: - -# Clean Targets -.clean-conf: ${CLEAN_SUBPROJECTS} - ${RM} -r ${CND_BUILDDIR}/${CND_CONF} - -# Subprojects -.clean-subprojects: - -# Enable dependency checking -.dep.inc: .depcheck-impl - -include .dep.inc diff --git a/nbproject/Makefile-Release.mk b/nbproject/Makefile-Release.mk deleted file mode 100644 index db54051..0000000 --- a/nbproject/Makefile-Release.mk +++ /dev/null @@ -1,143 +0,0 @@ -# -# Generated Makefile - do not edit! -# -# Edit the Makefile in the project folder instead (../Makefile). Each target -# has a -pre and a -post target defined where you can add customized code. -# -# This makefile implements configuration specific macros and targets. - - -# Environment -MKDIR=mkdir -CP=cp -GREP=grep -NM=nm -CCADMIN=CCadmin -RANLIB=ranlib -CC=gcc -CCC=g++ -CXX=g++ -FC=gfortran -AS=as - -# Macros -CND_PLATFORM=GNU-Linux -CND_DLIB_EXT=so -CND_CONF=Release -CND_DISTDIR=dist -CND_BUILDDIR=build - -# Include project Makefile -include Makefile - -# Object Directory -OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM} - -# Object Files -OBJECTFILES= \ - ${OBJECTDIR}/ftpCommandElaborate.o \ - ${OBJECTDIR}/ftpData.o \ - ${OBJECTDIR}/ftpServer.o \ - ${OBJECTDIR}/library/configRead.o \ - ${OBJECTDIR}/library/connection.o \ - ${OBJECTDIR}/library/daemon.o \ - ${OBJECTDIR}/library/dynamicVectors.o \ - ${OBJECTDIR}/library/fileManagement.o \ - ${OBJECTDIR}/library/logFunctions.o \ - ${OBJECTDIR}/library/signals.o \ - ${OBJECTDIR}/uFTP.o - - -# C Compiler Flags -CFLAGS= - -# CC Compiler Flags -CCFLAGS= -CXXFLAGS= - -# Fortran Compiler Flags -FFLAGS= - -# Assembler Flags -ASFLAGS= - -# Link Libraries and Options -LDLIBSOPTIONS= - -# Build Targets -.build-conf: ${BUILD_SUBPROJECTS} - "${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/uftp - -${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/uftp: ${OBJECTFILES} - ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} - ${LINK.c} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/uftp ${OBJECTFILES} ${LDLIBSOPTIONS} - -${OBJECTDIR}/ftpCommandElaborate.o: ftpCommandElaborate.c - ${MKDIR} -p ${OBJECTDIR} - ${RM} "$@.d" - $(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/ftpCommandElaborate.o ftpCommandElaborate.c - -${OBJECTDIR}/ftpData.o: ftpData.c - ${MKDIR} -p ${OBJECTDIR} - ${RM} "$@.d" - $(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/ftpData.o ftpData.c - -${OBJECTDIR}/ftpServer.o: ftpServer.c - ${MKDIR} -p ${OBJECTDIR} - ${RM} "$@.d" - $(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/ftpServer.o ftpServer.c - -${OBJECTDIR}/library/configRead.o: library/configRead.c - ${MKDIR} -p ${OBJECTDIR}/library - ${RM} "$@.d" - $(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/configRead.o library/configRead.c - -${OBJECTDIR}/library/connection.o: library/connection.c - ${MKDIR} -p ${OBJECTDIR}/library - ${RM} "$@.d" - $(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/connection.o library/connection.c - -${OBJECTDIR}/library/daemon.o: library/daemon.c - ${MKDIR} -p ${OBJECTDIR}/library - ${RM} "$@.d" - $(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/daemon.o library/daemon.c - -${OBJECTDIR}/library/dynamicVectors.o: library/dynamicVectors.c - ${MKDIR} -p ${OBJECTDIR}/library - ${RM} "$@.d" - $(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/dynamicVectors.o library/dynamicVectors.c - -${OBJECTDIR}/library/fileManagement.o: library/fileManagement.c - ${MKDIR} -p ${OBJECTDIR}/library - ${RM} "$@.d" - $(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/fileManagement.o library/fileManagement.c - -${OBJECTDIR}/library/logFunctions.o: library/logFunctions.c - ${MKDIR} -p ${OBJECTDIR}/library - ${RM} "$@.d" - $(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/logFunctions.o library/logFunctions.c - -${OBJECTDIR}/library/signals.o: library/signals.c - ${MKDIR} -p ${OBJECTDIR}/library - ${RM} "$@.d" - $(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/signals.o library/signals.c - -${OBJECTDIR}/uFTP.o: uFTP.c - ${MKDIR} -p ${OBJECTDIR} - ${RM} "$@.d" - $(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/uFTP.o uFTP.c - -# Subprojects -.build-subprojects: - -# Clean Targets -.clean-conf: ${CLEAN_SUBPROJECTS} - ${RM} -r ${CND_BUILDDIR}/${CND_CONF} - -# Subprojects -.clean-subprojects: - -# Enable dependency checking -.dep.inc: .depcheck-impl - -include .dep.inc diff --git a/nbproject/Makefile-impl.mk b/nbproject/Makefile-impl.mk deleted file mode 100644 index a655098..0000000 --- a/nbproject/Makefile-impl.mk +++ /dev/null @@ -1,133 +0,0 @@ -# -# Generated Makefile - do not edit! -# -# Edit the Makefile in the project folder instead (../Makefile). Each target -# has a pre- and a post- target defined where you can add customization code. -# -# This makefile implements macros and targets common to all configurations. -# -# NOCDDL - - -# Building and Cleaning subprojects are done by default, but can be controlled with the SUB -# macro. If SUB=no, subprojects will not be built or cleaned. The following macro -# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf -# and .clean-reqprojects-conf unless SUB has the value 'no' -SUB_no=NO -SUBPROJECTS=${SUB_${SUB}} -BUILD_SUBPROJECTS_=.build-subprojects -BUILD_SUBPROJECTS_NO= -BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}} -CLEAN_SUBPROJECTS_=.clean-subprojects -CLEAN_SUBPROJECTS_NO= -CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}} - - -# Project Name -PROJECTNAME=uFTP - -# Active Configuration -DEFAULTCONF=Debug -CONF=${DEFAULTCONF} - -# All Configurations -ALLCONFS=Debug Release - - -# build -.build-impl: .build-pre .validate-impl .depcheck-impl - @#echo "=> Running $@... Configuration=$(CONF)" - "${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf - - -# clean -.clean-impl: .clean-pre .validate-impl .depcheck-impl - @#echo "=> Running $@... Configuration=$(CONF)" - "${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf - - -# clobber -.clobber-impl: .clobber-pre .depcheck-impl - @#echo "=> Running $@..." - for CONF in ${ALLCONFS}; \ - do \ - "${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf; \ - done - -# all -.all-impl: .all-pre .depcheck-impl - @#echo "=> Running $@..." - for CONF in ${ALLCONFS}; \ - do \ - "${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf; \ - done - -# build tests -.build-tests-impl: .build-impl .build-tests-pre - @#echo "=> Running $@... Configuration=$(CONF)" - "${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-tests-conf - -# run tests -.test-impl: .build-tests-impl .test-pre - @#echo "=> Running $@... Configuration=$(CONF)" - "${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .test-conf - -# dependency checking support -.depcheck-impl: - @echo "# This code depends on make tool being used" >.dep.inc - @if [ -n "${MAKE_VERSION}" ]; then \ - echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES} \$${TESTOBJECTFILES}))" >>.dep.inc; \ - echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \ - echo "include \$${DEPFILES}" >>.dep.inc; \ - echo "endif" >>.dep.inc; \ - else \ - echo ".KEEP_STATE:" >>.dep.inc; \ - echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \ - fi - -# configuration validation -.validate-impl: - @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ - then \ - echo ""; \ - echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \ - echo "See 'make help' for details."; \ - echo "Current directory: " `pwd`; \ - echo ""; \ - fi - @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ - then \ - exit 1; \ - fi - - -# help -.help-impl: .help-pre - @echo "This makefile supports the following configurations:" - @echo " ${ALLCONFS}" - @echo "" - @echo "and the following targets:" - @echo " build (default target)" - @echo " clean" - @echo " clobber" - @echo " all" - @echo " help" - @echo "" - @echo "Makefile Usage:" - @echo " make [CONF=] [SUB=no] build" - @echo " make [CONF=] [SUB=no] clean" - @echo " make [SUB=no] clobber" - @echo " make [SUB=no] all" - @echo " make help" - @echo "" - @echo "Target 'build' will build a specific configuration and, unless 'SUB=no'," - @echo " also build subprojects." - @echo "Target 'clean' will clean a specific configuration and, unless 'SUB=no'," - @echo " also clean subprojects." - @echo "Target 'clobber' will remove all built files from all configurations and," - @echo " unless 'SUB=no', also from subprojects." - @echo "Target 'all' will will build all configurations and, unless 'SUB=no'," - @echo " also build subprojects." - @echo "Target 'help' prints this message." - @echo "" - diff --git a/nbproject/Makefile-variables.mk b/nbproject/Makefile-variables.mk deleted file mode 100644 index 558a2b7..0000000 --- a/nbproject/Makefile-variables.mk +++ /dev/null @@ -1,35 +0,0 @@ -# -# Generated - do not edit! -# -# NOCDDL -# -CND_BASEDIR=`pwd` -CND_BUILDDIR=build -CND_DISTDIR=dist -# Debug configuration -CND_PLATFORM_Debug=GNU-Linux -CND_ARTIFACT_DIR_Debug=dist/Debug/GNU-Linux -CND_ARTIFACT_NAME_Debug=uftp -CND_ARTIFACT_PATH_Debug=dist/Debug/GNU-Linux/uftp -CND_PACKAGE_DIR_Debug=dist/Debug/GNU-Linux/package -CND_PACKAGE_NAME_Debug=uftp.tar -CND_PACKAGE_PATH_Debug=dist/Debug/GNU-Linux/package/uftp.tar -# Release configuration -CND_PLATFORM_Release=GNU-Linux -CND_ARTIFACT_DIR_Release=dist/Release/GNU-Linux -CND_ARTIFACT_NAME_Release=uftp -CND_ARTIFACT_PATH_Release=dist/Release/GNU-Linux/uftp -CND_PACKAGE_DIR_Release=dist/Release/GNU-Linux/package -CND_PACKAGE_NAME_Release=uftp.tar -CND_PACKAGE_PATH_Release=dist/Release/GNU-Linux/package/uftp.tar -# -# include compiler specific variables -# -# dmake command -ROOT:sh = test -f nbproject/private/Makefile-variables.mk || \ - (mkdir -p nbproject/private && touch nbproject/private/Makefile-variables.mk) -# -# gmake command -.PHONY: $(shell test -f nbproject/private/Makefile-variables.mk || (mkdir -p nbproject/private && touch nbproject/private/Makefile-variables.mk)) -# -include nbproject/private/Makefile-variables.mk diff --git a/nbproject/Package-Debug.bash b/nbproject/Package-Debug.bash deleted file mode 100644 index cf4c7d2..0000000 --- a/nbproject/Package-Debug.bash +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash -x - -# -# Generated - do not edit! -# - -# Macros -TOP=`pwd` -CND_PLATFORM=GNU-Linux -CND_CONF=Debug -CND_DISTDIR=dist -CND_BUILDDIR=build -CND_DLIB_EXT=so -NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging -TMPDIRNAME=tmp-packaging -OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/uftp -OUTPUT_BASENAME=uftp -PACKAGE_TOP_DIR=uftp/ - -# Functions -function checkReturnCode -{ - rc=$? - if [ $rc != 0 ] - then - exit $rc - fi -} -function makeDirectory -# $1 directory path -# $2 permission (optional) -{ - mkdir -p "$1" - checkReturnCode - if [ "$2" != "" ] - then - chmod $2 "$1" - checkReturnCode - fi -} -function copyFileToTmpDir -# $1 from-file path -# $2 to-file path -# $3 permission -{ - cp "$1" "$2" - checkReturnCode - if [ "$3" != "" ] - then - chmod $3 "$2" - checkReturnCode - fi -} - -# Setup -cd "${TOP}" -mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package -rm -rf ${NBTMPDIR} -mkdir -p ${NBTMPDIR} - -# Copy files and create directories and links -cd "${TOP}" -makeDirectory "${NBTMPDIR}/uftp/bin" -copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 - - -# Generate tar file -cd "${TOP}" -rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/uftp.tar -cd ${NBTMPDIR} -tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/uftp.tar * -checkReturnCode - -# Cleanup -cd "${TOP}" -rm -rf ${NBTMPDIR} diff --git a/nbproject/Package-Release.bash b/nbproject/Package-Release.bash deleted file mode 100644 index 8642e54..0000000 --- a/nbproject/Package-Release.bash +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash -x - -# -# Generated - do not edit! -# - -# Macros -TOP=`pwd` -CND_PLATFORM=GNU-Linux -CND_CONF=Release -CND_DISTDIR=dist -CND_BUILDDIR=build -CND_DLIB_EXT=so -NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging -TMPDIRNAME=tmp-packaging -OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/uftp -OUTPUT_BASENAME=uftp -PACKAGE_TOP_DIR=uftp/ - -# Functions -function checkReturnCode -{ - rc=$? - if [ $rc != 0 ] - then - exit $rc - fi -} -function makeDirectory -# $1 directory path -# $2 permission (optional) -{ - mkdir -p "$1" - checkReturnCode - if [ "$2" != "" ] - then - chmod $2 "$1" - checkReturnCode - fi -} -function copyFileToTmpDir -# $1 from-file path -# $2 to-file path -# $3 permission -{ - cp "$1" "$2" - checkReturnCode - if [ "$3" != "" ] - then - chmod $3 "$2" - checkReturnCode - fi -} - -# Setup -cd "${TOP}" -mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package -rm -rf ${NBTMPDIR} -mkdir -p ${NBTMPDIR} - -# Copy files and create directories and links -cd "${TOP}" -makeDirectory "${NBTMPDIR}/uftp/bin" -copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 - - -# Generate tar file -cd "${TOP}" -rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/uftp.tar -cd ${NBTMPDIR} -tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/uftp.tar * -checkReturnCode - -# Cleanup -cd "${TOP}" -rm -rf ${NBTMPDIR} diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml deleted file mode 100644 index 3ad328a..0000000 --- a/nbproject/configurations.xml +++ /dev/null @@ -1,212 +0,0 @@ - - - - - - library/configRead.h - library/connection.h - library/dynamicVectors.h - library/fileManagement.h - library/logFunctions.h - library/signals.h - - library/daemon.h - ftpCommandsElaborate.h - ftpData.h - ftpServer.h - ftpSpecs.h - - - README.md - - - - library/configRead.c - library/connection.c - library/daemon.c - library/dynamicVectors.c - library/fileManagement.c - library/logFunctions.c - library/signals.c - - MakeFileGeneric - ftpCommandElaborate.c - ftpData.c - ftpServer.c - todo.txt - uFTP.c - uftpd.cfg - - - - - Makefile - - - - library - - Makefile - - - - default - true - false - - - - gcc - - library - - - library/dynamicVectors.h - library/fileManagement.h - - -pthread - - _LARGEFILE64_SOURCE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - default - true - false - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/nbproject/private/Makefile-variables.mk b/nbproject/private/Makefile-variables.mk deleted file mode 100644 index a64183e..0000000 --- a/nbproject/private/Makefile-variables.mk +++ /dev/null @@ -1,7 +0,0 @@ -# -# Generated - do not edit! -# -# NOCDDL -# -# Debug configuration -# Release configuration diff --git a/nbproject/private/c_standard_headers_indexer.c b/nbproject/private/c_standard_headers_indexer.c deleted file mode 100644 index c2548d2..0000000 --- a/nbproject/private/c_standard_headers_indexer.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - * - * Contributor(s): - */ - -// List of standard headers was taken in http://en.cppreference.com/w/c/header - -#include // Conditionally compiled macro that compares its argument to zero -#include // Functions to determine the type contained in character data -#include // Macros reporting error conditions -#include // Limits of float types -#include // Sizes of basic types -#include // Localization utilities -#include // Common mathematics functions -#include // Nonlocal jumps -#include // Signal handling -#include // Variable arguments -#include // Common macro definitions -#include // Input/output -#include // String handling -#include // General utilities: memory management, program utilities, string conversions, random numbers -#include // Time/date utilities -#include // (since C95) Alternative operator spellings -#include // (since C95) Extended multibyte and wide character utilities -#include // (since C95) Wide character classification and mapping utilities -#ifdef _STDC_C99 -#include // (since C99) Complex number arithmetic -#include // (since C99) Floating-point environment -#include // (since C99) Format conversion of integer types -#include // (since C99) Boolean type -#include // (since C99) Fixed-width integer types -#include // (since C99) Type-generic math (macros wrapping math.h and complex.h) -#endif -#ifdef _STDC_C11 -#include // (since C11) alignas and alignof convenience macros -#include // (since C11) Atomic types -#include // (since C11) noreturn convenience macros -#include // (since C11) Thread library -#include // (since C11) UTF-16 and UTF-32 character utilities -#endif diff --git a/nbproject/private/configurations.xml b/nbproject/private/configurations.xml deleted file mode 100644 index 7954229..0000000 --- a/nbproject/private/configurations.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - Makefile - - - - localhost - 2 - - - - - - - - - - - - - - - - - gdb - - - - sudo "${OUTPUT_PATH}" - "${OUTPUT_PATH}" - sudo "${OUTPUT_PATH}" - - sudo "${OUTPUT_PATH}" - - true - 1 - 0 - 0 - - - - - - - localhost - 2 - - - - - - - - - - - - - - - gdb - - - - "${OUTPUT_PATH}" - - "${OUTPUT_PATH}" - - true - 0 - 0 - - - - - - diff --git a/nbproject/private/cpp_standard_headers_indexer.cpp b/nbproject/private/cpp_standard_headers_indexer.cpp deleted file mode 100644 index 04f6fa6..0000000 --- a/nbproject/private/cpp_standard_headers_indexer.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - * - * Contributor(s): - */ - -// List of standard headers was taken in http://en.cppreference.com/w/cpp/header - -#include // General purpose utilities: program control, dynamic memory allocation, random numbers, sort and search -#include // Functions and macro constants for signal management -#include // Macro (and function) that saves (and jumps) to an execution context -#include // Handling of variable length argument lists -#include // Runtime type information utilities -#include // std::bitset class template -#include // Function objects, designed for use with the standard algorithms -#include // Various utility components -#include // C-style time/date utilites -#include // typedefs for types such as size_t, NULL and others -#include // Low-level memory management utilities -#include // Higher level memory management utilities -#include // limits of integral types -#include // limits of float types -#include // standardized way to query properties of arithmetic types -#include // Exception handling utilities -#include // Standard exception objects -#include // Conditionally compiled macro that compares its argument to zero -#include // Macro containing the last error number -#include // functions to determine the type contained in character data -#include // functions for determining the type of wide character data -#include // various narrow character string handling functions -#include // various wide and multibyte string handling functions -#include // std::basic_string class template -#include // std::vector container -#include // std::deque container -#include // std::list container -#include // std::set and std::multiset associative containers -#include // std::map and std::multimap associative containers -#include // std::stack container adaptor -#include // std::queue and std::priority_queue container adaptors -#include // Algorithms that operate on containers -#include // Container iterators -#include // Common mathematics functions -#include // Complex number type -#include // Class for representing and manipulating arrays of values -#include // Numeric operations on values in containers -#include // forward declarations of all classes in the input/output library -#include // std::ios_base class, std::basic_ios class template and several typedefs -#include // std::basic_istream class template and several typedefs -#include // std::basic_ostream, std::basic_iostream class templates and several typedefs -#include // several standard stream objects -#include // std::basic_fstream, std::basic_ifstream, std::basic_ofstream class templates and several typedefs -#include // std::basic_stringstream, std::basic_istringstream, std::basic_ostringstream class templates and several typedefs -#include // std::strstream, std::istrstream, std::ostrstream(deprecated) -#include // Helper functions to control the format or input and output -#include // std::basic_streambuf class template -#include // C-style input-output functions -#include // Localization utilities -#include // C localization utilities -#include // empty header. The macros that appear in iso646.h in C are keywords in C++ -#if __cplusplus >= 201103L -#include // (since C++11) std::type_index -#include // (since C++11) Compile-time type information -#include // (since C++11) C++ time utilites -#include // (since C++11) std::initializer_list class template -#include // (since C++11) std::tuple class template -#include // (since C++11) Nested allocator class -#include // (since C++11) fixed-size types and limits of other types -#include // (since C++11) formatting macros , intmax_t and uintmax_t math and conversions -#include // (since C++11) defines std::error_code, a platform-dependent error code -#include // (since C++11) C-style Unicode character conversion functions -#include // (since C++11) std::array container -#include // (since C++11) std::forward_list container -#include // (since C++11) std::unordered_set and std::unordered_multiset unordered associative containers -#include // (since C++11) std::unordered_map and std::unordered_multimap unordered associative containers -#include // (since C++11) Random number generators and distributions -#include // (since C++11) Compile-time rational arithmetic -#include // (since C++11) Floating-point environment access functions -#include // (since C++11) Unicode conversion facilities -#include // (since C++11) Classes, algorithms and iterators to support regular expression processing -#include // (since C++11) Atomic operations library -#include // (since C++11)(deprecated in C++17) simply includes the header -#include // (since C++11)(deprecated in C++17) simply includes the headers (until C++17) (since C++17) and : the overloads equivalent to the contents of the C header tgmath.h are already provided by those headers -#include // (since C++11)(deprecated in C++17) defines one compatibility macro constant -#include // (since C++11)(deprecated in C++17) defines one compatibility macro constant -#include // (since C++11) std::thread class and supporting functions -#include // (since C++11) mutual exclusion primitives -#include // (since C++11) primitives for asynchronous computations -#include // (since C++11) thread waiting conditions -#endif -#if __cplusplus >= 201300L -#include // (since C++14) shared mutual exclusion primitives -#endif -#if __cplusplus >= 201500L -#include // (since C++17) std::any class template -#include // (since C++17) std::optional class template -#include // (since C++17) std::variant class template -#include // (since C++17) Polymorphic allocators and memory resources -#include // (since C++17) std::basic_string_view class template -#include // (since C++17) Predefined execution policies for parallel versions of the algorithms -#include // (since C++17) std::path class and supporting functions -#endif diff --git a/nbproject/private/launcher.properties b/nbproject/private/launcher.properties deleted file mode 100644 index 3edc2d8..0000000 --- a/nbproject/private/launcher.properties +++ /dev/null @@ -1,42 +0,0 @@ -# Launchers File syntax: -# -# [Must-have property line] -# launcher1.runCommand= -# [Optional extra properties] -# launcher1.displayName= -# launcher1.hide= -# launcher1.buildCommand= -# launcher1.runDir= -# launcher1.runInOwnTab= -# launcher1.symbolFiles= -# launcher1.env.= -# (If this value is quoted with ` it is handled as a native command which execution result will become the value) -# [Common launcher properties] -# common.runDir= -# (This value is overwritten by a launcher specific runDir value if the latter exists) -# common.env.= -# (Environment variables from common launcher are merged with launcher specific variables) -# common.symbolFiles= -# (This value is overwritten by a launcher specific symbolFiles value if the latter exists) -# -# In runDir, symbolFiles and env fields you can use these macroses: -# ${PROJECT_DIR} - project directory absolute path -# ${OUTPUT_PATH} - linker output path (relative to project directory path) -# ${OUTPUT_BASENAME}- linker output filename -# ${TESTDIR} - test files directory (relative to project directory path) -# ${OBJECTDIR} - object files directory (relative to project directory path) -# ${CND_DISTDIR} - distribution directory (relative to project directory path) -# ${CND_BUILDDIR} - build directory (relative to project directory path) -# ${CND_PLATFORM} - platform name -# ${CND_CONF} - configuration name -# ${CND_DLIB_EXT} - dynamic library extension -# -# All the project launchers must be listed in the file! -# -# launcher1.runCommand=... -# launcher2.runCommand=... -# ... -# common.runDir=... -# common.env.KEY=VALUE - -# launcher1.runCommand= \ No newline at end of file diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml deleted file mode 100644 index aef7ea3..0000000 --- a/nbproject/private/private.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - 1 - 0 - - - - - - diff --git a/nbproject/project.properties b/nbproject/project.properties deleted file mode 100644 index de9ff56..0000000 --- a/nbproject/project.properties +++ /dev/null @@ -1,2 +0,0 @@ -#Sat Oct 21 15:56:01 CEST 2017 -project.license=mit diff --git a/nbproject/project.xml b/nbproject/project.xml deleted file mode 100644 index b9773ad..0000000 --- a/nbproject/project.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - org.netbeans.modules.cnd.makeproject - - - uFTP - c - - h - UTF-8 - - - library - - - - Debug - 1 - - - Release - 1 - - - - false - - - - diff --git a/testNotes.txt b/testNotes.txt new file mode 100644 index 0000000..26c89c6 --- /dev/null +++ b/testNotes.txt @@ -0,0 +1,22 @@ +#NOTES ONLY FOR DEVELOPERS +#OPENSSL TEST COMMANDS + +#Required packages to compile +sudo apt-get install libssl-dev + + +#Remove password from a certificate +openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 +openssl rsa -in key.pem -out newkey.pem +handle SIGPIPE nostop noprint pass + + +#Testing ssl +openssl s_client -starttls ftp -connect 192.168.1.237:21 +sudo openssl s_server -key key.pem -cert cert.pem -accept 123 +openssl s_client -connect 127.0.0.1:49473 +USER username +PASS password +PROT P +PORT 192,168,1,237,0,123 +LIST diff --git a/todo.txt b/todo.txt index e69de29..0a37e9c 100644 --- a/todo.txt +++ b/todo.txt @@ -0,0 +1,3 @@ +To remove key files: +openssl rsa -in key.pem -out newkey.pem + diff --git a/uftpd.cfg b/uftpd.cfg index 6d78ad9..88679c1 100644 --- a/uftpd.cfg +++ b/uftpd.cfg @@ -10,10 +10,10 @@ MAXIMUM_ALLOWED_FTP_CONNECTION = 30 FTP_PORT = 21 #TCP/IP PORT SETTINGS (DEFAULT 21) -SINGLE_INSTANCE = true +SINGLE_INSTANCE = false #Allow only one server instance (true or false) -DAEMON_MODE = true +DAEMON_MODE = false #Run in background, daemon mode ok IDLE_MAX_TIMEOUT = 3600 @@ -32,6 +32,10 @@ MAX_CONNECTION_TRY_PER_IP = 10 #THE IP ADDRESS WILL BE BLOCKED FOR 5 MINUTES AFTER WRONG LOGIN USERNAME AND PASSWORD #0 TO DISABLE +#TLS CERTIFICATE FILE PATH +CERTIFICATE_PATH=/home/ugo/NetBeansProjects/uFTP/cert.pem +PRIVATE_CERTIFICATE_PATH=/home/ugo/NetBeansProjects/uFTP/key.pem + #USERS #START FROM USER 0 TO XXX USER_0 = username