移植vsftpd到arm linux

vsftpdvery secure FTP daemon(很是安全的FTP進程),是一個基於GPL發佈的類UNIX類操做系統上運行的服務器的名字(是一種守護進程),能夠運行在諸如Linux、BSD、Solaris、HP-UX以及Irix等系統上面。vsftpd支持不少其餘傳統的FTP服務器不支持的良好特性。使用 vsftpd 能夠在 Linux/Unix 系統上搭建一個安全、高性能、穩定性好的輕量級FTP服務器。html

如今基於quectel的EC20CEFAG模塊,來移植vsftpd服務。linux

1 下載

下載最新版本源碼包,下載地址:https://security.appspot.com/vsftpd.html#download。本文以 vsftpd-3.0.2.tar.gz 版本爲例。安全

若是以上下載地址沒法訪問,也能夠本地下載 vsftpd-3.0.2.tar.gz服務器

2 解壓

$ mkdir ~/vsftpd
$ cp vsftpd-3.0.2.tar.gz ~/vsftpd
$ cd ~/vsftpd
$ tar xzf vsftpd-3.0.2.tar.gz
$ cd vsftpd-3.0.2/

3 配置

修改Makefile文件:session

CC = arm-oe-linux-gnueabi-gcc

4 設置交叉編譯環境&編譯

$ source ../../ql-ol-crosstool/ql-ol-crosstool-env-initapp

$ make                  socket

sysdeputil.o:sysdeputil.c:function vsf_sysdep_has_capabilities: error: undefined reference to 'cap_get_proc'
sysdeputil.o:sysdeputil.c:function vsf_sysdep_has_capabilities: error: undefined reference to 'cap_free'
sysdeputil.o:sysdeputil.c:function vsf_sysdep_adopt_capabilities: error: undefined reference to 'cap_init'
sysdeputil.o:sysdeputil.c:function vsf_sysdep_adopt_capabilities: error: undefined reference to 'cap_set_proc'
sysdeputil.o:sysdeputil.c:function vsf_sysdep_adopt_capabilities: error: undefined reference to 'cap_free'
sysdeputil.o:sysdeputil.c:function vsf_sysdep_adopt_capabilities: error: undefined reference to 'cap_set_flag'
sysdeputil.o:sysdeputil.c:function vsf_sysdep_adopt_capabilities: error: undefined reference to 'cap_set_flag'
sysdeputil.o:sysdeputil.c:function vsf_sysdep_adopt_capabilities: error: undefined reference to 'cap_set_flag'
sysdeputil.o:sysdeputil.c:function vsf_sysdep_adopt_capabilities: error: undefined reference to 'cap_set_flag'
collect2: error: ld returned 1 exit status
Makefile:32: recipe for target 'vsftpd' failed
make: *** [vsftpd] Error 1

編譯報錯,修改Makefile文件,在CC 後面添加「 -lcap 」async

 27 .c.o:
 28         $(CC) -c $*.c $(CFLAGS) $(IFLAGS) -lcap
 29         #$(CC) -c $*.c $(CFLAGS) $(IFLAGS)
 30
 31 vsftpd: $(OBJS)
 32         $(CC) -o vsftpd $(OBJS) $(LINK) $(LDFLAGS) $(LIBS) -lcap
 33         #$(CC) -o vsftpd $(OBJS) $(LINK) $(LDFLAGS) $(LIBS)

 

make 後,當前目錄下會生成兩個文件:vsftpdvsftpd.conf,這兩個文件是咱們要用的。ide

 5 複製文件

將生成的 vsftpd 複製到目標板 /usr/sbin 目錄,vsftpd.conf 複製到目標板 /etc 目錄,並添加 vsftpd 爲可執行:性能

$ cp vsftpd ql-ol-sdk/ql-ol-rootfs/usr/sbin                       # 複製執行文件到目標板
$ cp vsftpd.conf ql-ol-sdk/ql-ol-rootfs/etc/                      # 複製配置文件到目標板
$ chmod +x ql-ol-sdk/ql-ol-rootfs/usr/sbin/vsftpd                 # 添加可執行權限

6 配置

使用 vi 打開 vsftpd.conf 文件,並進行配置,以下配置可實現正常上傳下載功能:(這段能夠隨便改)

 

# Example config file /etc/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.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
# 容許登陸的FTP用戶寫權限,還要視目錄的權限而定
write_enable=YES

pam_service_name=vsftpd
#
# 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
anon_umask=0000
file_open_mode=0777
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
# 容許匿名用戶上傳文件
anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
# 容許匿名用戶建立目錄
anon_mkdir_write_enable=YES
# 容許匿名用戶進行刪除或者更名等操做
anon_other_write_enable=YES
# 指定匿名用戶登陸後的主目錄爲/data/software目錄
#anon_root=/data/software
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=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
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
#xferlog_std_format=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
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
ftpd_banner=Welcome to LSDDM-AMR1808-B4 FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd with two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES
# 指定匿名用戶,默認爲ftp
ftp_username=ftp

$ adduser nobody                    # vsftpd默認配置須要
$ mkdir  ql-ol-sdk/ql-ol-rootfs/usr/share/empty            # vsftpd默認配置須要

再在目標版上使用命令配置:

建立一個本地用戶,並設置密碼:

$ adduser root
Changing password for root
New password:
Retype password:
Password for ftpadmin changed by root

7 打開vsftp

配置完以後,在目標板上打開vsftp,命令:

# /usr/sbin/vsftpd &

注意,後面還有一個 &。若是要讓 vsftpd 開機啓動,能夠將該命令添加到 /etc/profile 或者 rc.local 文件最後。

8 客戶端測試

C:\Users\ricks>ftp
ftp> open 192.168.31.45
鏈接到 192.168.31.45220 Welcome to EC20 FTP service.
200 Always in UTF8 mode.
用戶(192.168.31.45:(none)): root
331 Please specify the password.
密碼:
230 Login successful.

待續。。。

相關文章
相關標籤/搜索