| @ -0,0 +1,67 @@ | |||||
| #! /usr/bin/env bats | |||||
| load '/bats-support/load.bash' | |||||
| load '/bats-assert/load.bash' | |||||
| load '/getssl/test/test_helper.bash' | |||||
| # This is run for every test | |||||
| setup() { | |||||
| export CURL_CA_BUNDLE=/root/pebble-ca-bundle.crt | |||||
| cp $VSFTPD_CONF ${VSFTPD_CONF}.getssl | |||||
| # enable passive and disable active mode | |||||
| # https://www.pixelstech.net/article/1364817664-FTP-active-mode-and-passive-mode | |||||
| cat <<- _FTP >> $VSFTPD_CONF | |||||
| pasv_enable=YES | |||||
| pasv_max_port=10100 | |||||
| pasv_min_port=10090 | |||||
| connect_from_port_20=NO | |||||
| _FTP | |||||
| ${CODE_DIR}/test/restart-ftpd | |||||
| } | |||||
| teardown() { | |||||
| cp ${VSFTPD_CONF}.getssl $VSFTPD_CONF | |||||
| ${CODE_DIR}/test/restart-ftpd | |||||
| } | |||||
| @test "Use Passive FTP to create challenge file" { | |||||
| if [ -n "$STAGING" ]; then | |||||
| skip "Using staging server, skipping internal test" | |||||
| fi | |||||
| if [[ ! -d /var/www/html/.well-known/acme-challenge ]]; then | |||||
| mkdir -p /var/www/html/.well-known/acme-challenge | |||||
| fi | |||||
| # Always change ownership and permissions in case previous tests created the directories as root | |||||
| chgrp -R www-data /var/www/html/.well-known | |||||
| chmod -R g+w /var/www/html/.well-known | |||||
| CONFIG_FILE="getssl-http01.cfg" | |||||
| setup_environment | |||||
| init_getssl | |||||
| cat <<- EOF > ${INSTALL_DIR}/.getssl/${GETSSL_CMD_HOST}/getssl_test_specific.cfg | |||||
| ACL="ftp:ftpuser:ftpuser:${GETSSL_CMD_HOST}:/var/www/html/.well-known/acme-challenge" | |||||
| EOF | |||||
| if [[ "$FTP_PASSIVE_DEFAULT" == "false" ]]; then | |||||
| cat <<- EOF3 >> ${INSTALL_DIR}/.getssl/${GETSSL_CMD_HOST}/getssl_test_specific.cfg | |||||
| FTP_OPTIONS="passive" | |||||
| EOF3 | |||||
| fi | |||||
| create_certificate | |||||
| assert_success | |||||
| assert_line --partial "ftp:ftpuser:ftpuser:" | |||||
| if [[ "$FTP_PASSIVE_DEFAULT" == "false" ]]; then | |||||
| assert_line --partial "Passive mode on" | |||||
| else | |||||
| refute_line --partial "Passive mode off" | |||||
| fi | |||||
| check_output_for_errors | |||||
| } | |||||
| @ -0,0 +1,66 @@ | |||||
| # Example config file /etc/vsftpd.conf (alpine) /etc/vsftpd/vsftpd.conf | |||||
| # | |||||
| # The default compiled in settings are fairly paranoid. This sample file | |||||
| # loosens things up a bit, to make the ftp daemon more usable. | |||||
| # Please see vsftpd.conf.5 for all compiled in defaults. | |||||
| # | |||||
| # Run standalone? vsftpd can run either from an inetd or as a standalone | |||||
| # daemon started from an initscript. | |||||
| listen=YES | |||||
| # | |||||
| # This directive enables listening on IPv6 sockets. By default, listening | |||||
| # on the IPv6 "any" address (::) will accept connections from both IPv6 | |||||
| # and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6 | |||||
| # sockets. If you want that (perhaps because you want to listen on specific | |||||
| # addresses) then you must run two copies of vsftpd with two configuration | |||||
| # files. | |||||
| #listen_ipv6=NO | |||||
| # | |||||
| # Allow anonymous FTP? (Disabled by default). | |||||
| anonymous_enable=NO | |||||
| # | |||||
| # Uncomment this to allow local users to log in. | |||||
| local_enable=YES | |||||
| # | |||||
| # Uncomment this to enable any form of FTP write command. | |||||
| write_enable=YES | |||||
| # | |||||
| # Default umask for local users is 077. You may wish to change this to 022, | |||||
| # if your users expect that (022 is used by most other ftpd's) | |||||
| local_umask=022 | |||||
| # | |||||
| # Activate directory messages - messages given to remote users when they | |||||
| # go into a certain directory. | |||||
| dirmessage_enable=YES | |||||
| # | |||||
| # If enabled, vsftpd will display directory listings with the time | |||||
| # in your local time zone. The default is to display GMT. The | |||||
| # times returned by the MDTM FTP command are also affected by this | |||||
| # option. | |||||
| use_localtime=YES | |||||
| # | |||||
| # Activate logging of uploads/downloads. | |||||
| xferlog_enable=YES | |||||
| # | |||||
| # Make sure PORT transfer connections originate from port 20 (ftp-data). | |||||
| connect_from_port_20=YES | |||||
| # | |||||
| # You may change the default value for timing out an idle session. | |||||
| #idle_session_timeout=600 | |||||
| # | |||||
| # You may change the default value for timing out a data connection. | |||||
| #data_connection_timeout=120 | |||||
| # | |||||
| # You may restrict local users to their home directories. See the FAQ for | |||||
| # the possible risks in this before using chroot_local_user or | |||||
| # chroot_list_enable below. | |||||
| chroot_local_user=NO | |||||
| # | |||||
| # This string is the name of the PAM service vsftpd will use. | |||||
| pam_service_name=vsftpd | |||||
| # | |||||
| # This option specifies the location of the RSA certificate to use for SSL | |||||
| # encrypted connections. | |||||
| rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem | |||||
| rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key | |||||
| ssl_enable=NO | |||||
| @ -0,0 +1,103 @@ | |||||
| #!/bin/sh | |||||
| ### BEGIN INIT INFO | |||||
| # Provides: vsftpd | |||||
| # Required-Start: $network $remote_fs $syslog | |||||
| # Required-Stop: $network $remote_fs $syslog | |||||
| # Default-Start: 2 3 4 5 | |||||
| # Default-Stop: 0 1 6 | |||||
| # Short-Description: Very secure FTP server | |||||
| # Description: Provides a lightweight, efficient FTP server written | |||||
| # for security. | |||||
| ### END INIT INFO | |||||
| set -e | |||||
| DAEMON="/usr/sbin/vsftpd" | |||||
| NAME="vsftpd" | |||||
| PATH="/sbin:/bin:/usr/sbin:/usr/bin" | |||||
| LOGFILE="/var/log/vsftpd.log" | |||||
| CHROOT="/var/run/vsftpd/empty" | |||||
| test -x "${DAEMON}" || exit 0 | |||||
| . /lib/lsb/init-functions | |||||
| if [ ! -e "${LOGFILE}" ] | |||||
| then | |||||
| touch "${LOGFILE}" | |||||
| chmod 640 "${LOGFILE}" | |||||
| chown root:adm "${LOGFILE}" | |||||
| fi | |||||
| if [ ! -d "${CHROOT}" ] | |||||
| then | |||||
| mkdir -p "${CHROOT}" | |||||
| fi | |||||
| case "${1}" in | |||||
| start) | |||||
| log_daemon_msg "Starting FTP server" "${NAME}" | |||||
| if [ -e /etc/vsftpd.conf ] && ! egrep -iq "^ *listen(_ipv6)? *= *yes" /etc/vsftpd.conf | |||||
| then | |||||
| log_warning_msg "vsftpd disabled - listen disabled in config." | |||||
| exit 0 | |||||
| fi | |||||
| start-stop-daemon --start --background -m --oknodo --pidfile /var/run/vsftpd/vsftpd.pid --exec ${DAEMON} | |||||
| n=0 | |||||
| while [ ${n} -le 5 ] | |||||
| do | |||||
| _PID="$(if [ -e /var/run/vsftpd/vsftpd.pid ]; then cat /var/run/vsftpd/vsftpd.pid; fi)" | |||||
| if ! ps -C vsftpd | grep -qs "${_PID}" | |||||
| then | |||||
| break | |||||
| fi | |||||
| sleep 1 | |||||
| n=$(( $n + 1 )) | |||||
| done | |||||
| if ps -C vsftpd | grep -qs "${_PID}" | |||||
| then | |||||
| log_warning_msg "vsftpd failed - probably invalid config." | |||||
| exit 1 | |||||
| fi | |||||
| log_end_msg 0 | |||||
| ;; | |||||
| stop) | |||||
| log_daemon_msg "Stopping FTP server" "${NAME}" | |||||
| start-stop-daemon --stop --pidfile /var/run/vsftpd/vsftpd.pid --oknodo --exec ${DAEMON} | |||||
| rm -f /var/run/vsftpd/vsftpd.pid | |||||
| log_end_msg 0 | |||||
| ;; | |||||
| restart) | |||||
| ${0} stop | |||||
| ${0} start | |||||
| ;; | |||||
| reload|force-reload) | |||||
| log_daemon_msg "Reloading FTP server configuration" | |||||
| start-stop-daemon --stop --pidfile /var/run/vsftpd/vsftpd.pid --signal 1 --exec $DAEMON | |||||
| log_end_msg "${?}" | |||||
| ;; | |||||
| status) | |||||
| status_of_proc "${DAEMON}" "FTP server" | |||||
| ;; | |||||
| *) | |||||
| echo "Usage: ${0} {start|stop|restart|reload|status}" | |||||
| exit 1 | |||||
| ;; | |||||
| esac | |||||
| exit 0 | |||||