FreeNAS Code
This project has moved to github - see https://github.com/freenas
Brought to you by:
cochard,
mattolander
#!/bin/sh # Copyright (c) 2007-2008 Volker Theile (votdev@gmx.de) # All rights reserved. # PROVIDE: pureftpd # REQUIRE: NETWORKING SERVERS # BEFORE: DAEMON # KEYWORD: shutdown # XQUERY: -i "count(//ftpd/enable) > 0" -o "0" -b # RCVAR: pureftpd . /etc/rc.subr . /etc/configxml.subr name="pureftpd" rcvar=`set_rcvar` load_rc_config "$name" # Custom commands start_precmd="start_precmd" # Defaults pureftpd_enable=${pureftpd_enable:-"NO"} pureftpd_certfile=${pureftpd_certfile:-"/var/etc/ssl/private/pure-ftpd.pem"} command="/usr/local/sbin/pure-ftpd" pidfile="/var/run/pure-ftpd.pid" start_precmd() { local _banner _productname _tls _certificate _privatekey # Create /mnt/.banner file _banner=`configxml_get "//ftpd/banner"` if [ -z "${_banner}" ]; then _productname=`cat /etc/prd.name` echo "Welcome to ${_productname} FTP service" > /mnt/.banner else echo ${_banner} > /mnt/.banner fi # Create SSL/TLS certificate _tls=`configxml_get "//ftpd/tls"` if [ "0" != "${_tls}" ]; then _certificate=`configxml_get "//ftpd/certificate"` _privatekey=`configxml_get "//ftpd/privatekey"` # Create /var/etc/ssl/private/pure-ftpd.pem file if [ -n "${_certificate}" -a -n "${_privatekey}" ]; then _tmpfile=/tmp/pure-ftpd$$.tmp echo "${_certificate}" > ${_tmpfile} /usr/bin/uudecode -m -p -r ${_tmpfile} > ${pureftpd_certfile} echo "" >> ${pureftpd_certfile} echo "${_privatekey}" > ${_tmpfile} /usr/bin/uudecode -m -p -r ${_tmpfile} >> ${pureftpd_certfile} echo "" >> ${pureftpd_certfile} /bin/chmod 0600 ${pureftpd_certfile} /bin/rm -f ${_tmpfile} fi fi # Set command args command_args=`/usr/local/bin/xml sel -t -m "//ftpd" \ -v "concat('-S ',port)" \ -v "concat(' -c ',numberclients)" \ -v "concat(' -I ',timeout)" \ -v "concat(' -Y ',tls)" \ -o " -M -B -b" \ -i "maxconperip[. > 0]" -v "concat(' -C ',maxconperip)" -b \ -i "count(anonymousonly) > 0" -o " -e" -b \ -i "count(localusersonly) > 0" -o " -E" -b \ -i "pasv_min_port[. != '0']" -i "pasv_max_port[. != '0']" -v "concat(' -p ',pasv_min_port,':',pasv_max_port)" -b -b \ -i "string-length(filemask) > 0" -i "string-length(directorymask) > 0" -v "concat(' -U ',filemask,':',directorymask)" -b -b \ -i "string-length(filemask) = 0" -i "string-length(directorymask) = 0" -o " -U 077:022" -b -b \ -i "string-length(pasv_address) > 0" -v "concat(' -P ',pasv_address)" -b \ -i "count(natmode) > 0" -o " -N" -b \ -i "count(fxp) > 0" -o " -W" -b \ -i "count(keepallfiles) > 0" -o " -K" -b \ -i "count(permitrootlogin) = 0" -o " -u 1" -b \ -i "count(chrooteveryone) > 0" -o " -A" -b \ ${configxml_file} | /usr/local/bin/xml unesc` } run_rc_command "$1"