Virtual User With Proftpd And MySQL on CentOS

Xây dựng FTP server với proftpd sử dụng MySQL

Phiên bản sử dụng hiện tại là 1.3.2 stable, download tại http://proftpd.org/
Giải nén

tar xjf proftpd-1.3.2.tar.bz2
cd proftpd-1.3.2/

Ta sẽ sử dụng mySql để lưu thông tin người dùng. Do đó bạn cần đảm bảo máy bạn đã có mysql

mysql_config --help
Options:
--cflags [-I/usr/include/mysql -g -pipe -DUNIV_LINUX]
--include [-I/usr/include/mysql]
--libs [-rdynamic -L/usr/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -lmygcc]
--libs_r [-rdynamic -L/usr/lib/mysql -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lmygcc]
--plugindir [/usr/lib/mysql/plugin]
--socket [/var/lib/mysql/mysql.sock]
--port [0]
--version [5.1.41]
--libmysqld-libs [-rdynamic -L/usr/lib/mysql -lmysqld -ldl -lz -lpthread -lcrypt -lnsl -lm -lpthread -lrt -lmygcc]

để ý tham số include và lib
Configure cho proftpd integate mysql:

./configure --with-modules=mod_sql:mod_sql_mysql \
--with-includes=/usr/include/mysql \
--with-libraries=/usr/lib/mysql \
--sysconfdir=/etc
make
make install

H ta sẽ tạo cơ sở dữ liệu để lưu thông tin người dùng:
Tạo database proftpd, trong đó tạo 2 bảng:

CREATE TABLE users (
userid VARCHAR(30) NOT NULL UNIQUE,
passwd VARCHAR(80) NOT NULL,
uid INTEGER UNIQUE,
gid INTEGER,
homedir VARCHAR(255),
shell VARCHAR(255)
);
CREATE TABLE groups (
groupname VARCHAR(30) NOT NULL,
gid INTEGER NOT NULL,
members VARCHAR(255)
);

Sửa file cấu hình: /etc/proftpd.conf
Tại dòng có nội dung: Group nogroup ta đổi thành Group nobody
Thêm dòng:

[...]
DefaultRoot ~
IdentLookups off
ServerIdent on “FTP Server ready.”
[...]

Tìm và uncommnet lại:

[...]
# Bar use of SITE CHMOD by default

DenyAll

[...]

Thêm vào cuối:

#------------------------mysql Modul: 4.x

# Hikaru

SQLAuthTypes Plaintext
SQLAuthenticate users*
# tham số là database proftpd tại localhost, user root pass là 123456
SQLConnectInfo proftpd@localhost root 123456
SQLDefaultGID 65534
SQLDefaultUID 65534
SQLMinUserGID 100
SQLMinUserUID 500
SQLUserInfo users userid passwd uid gid homedir shell

# aktive SQL Kommandos, ab hier passiert etwas :-)

SQLLog PASS counter
SQLNamedQuery counter UPDATE "letzter_zugriff=now(), count=count+1 WHERE username='%u'" ftp

# xfer Log in mysql
SQLLog RETR,STOR transfer1
SQLNamedQuery transfer1 INSERT "'%u', '%f', '%b', '%h', '%a', '%m', '%T', now(), 'c', NULL" xfer_stat

SQLLOG ERR_RETR,ERR_STOR transfer2
SQLNamedQuery transfer2 INSERT "'%u', '%f', '%b', '%h', '%a', '%m', '%T', now(), 'i', NULL" xfer_stat

#------------------------mysql

Tiếp theo, tiến hành tạo file script khởi độg:
which proftpd
nhớ cái này:

#!/bin/sh
# $Id: proftpd.init,v 1.1 2004/02/26 17:54:30 thias Exp $

# proftpd This shell script takes care of starting and stopping

proftpd.

# chkconfig: - 80 30
# description: ProFTPD is an enhanced FTP server with a focus towards \

simplicity, security, and ease of configuration. \

It features a very Apache-like configuration syntax, \

and a highly customizable server infrastructure, \

including support for multiple 'virtual' FTP servers, \

anonymous FTP, and permission-based directory visibility.

# processname: proftpd
# config: /etc/proftp.conf
# pidfile: /usr/local/var/proftpd.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -x /usr/local/sbin/proftpd ] || exit 0

RETVAL=0

prog="proftpd"

start() {
echo -n $"Starting $prog: "
daemon /usr/local/sbin/proftpd
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/proftpd
}

stop() {
echo -n $"Shutting down $prog: "
killproc proftpd
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/proftpd
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status proftpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/proftpd ]; then
stop
start
fi
;;
reload)
echo -n $"Re-reading $prog configuration: "
killproc proftpd -HUP
RETVAL=$?
echo
;;
*)
echo "Usage: $prog {start|stop|restart|reload|condrestart|status}"
exit 1
esac

exit $RETVAL

Nếu ko chạy, chay thế [ -x /usr/local/sbin/proftpd ] || exit 0 bằng path đến proftpd ( dùng which)
Cái này còn tùy, nếu mà ko run đc cứ: proftpd là tự chạy
kiểm tra:

lsof -i :21
lsof -i :20

Nếu có lắng nghe, ta thử ftp vào:
Dùng cmd của windown hoặc các soft FTP Client như cuteftp, flaxXP..........
Thanks for reading
---------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------
All my Lab:
Linux Lab -- window and Cisco Lab
to be continued - I will update more.

Nam Habach