Chris PeBenito ab58ad
#DESC Ftpd - Ftp daemon
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
# Authors:  Stephen Smalley <sds@epoch.ncsc.mil> and Timothy Fraser  
Chris PeBenito ab58ad
#           Russell Coker <russell@coker.com.au>
Chris PeBenito ab58ad
# X-Debian-Packages: proftpd-common bsd-ftpd ftpd vsftpd
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
Chris PeBenito ab58ad
#################################
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
# Rules for the ftpd_t domain 
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
daemon_domain(ftpd, `, auth_chkpwd, nscd_client_domain')
Chris PeBenito ab58ad
etc_domain(ftpd)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
can_network(ftpd_t)
Chris PeBenito ab58ad
allow ftpd_t port_type:tcp_socket name_connect;
Chris PeBenito ab58ad
allow ftpd_t self:unix_dgram_socket { sendto create_socket_perms };
Chris PeBenito ab58ad
allow ftpd_t self:unix_stream_socket create_socket_perms;
Chris PeBenito ab58ad
allow ftpd_t self:process { getcap setcap setsched setrlimit };
Chris PeBenito ab58ad
allow ftpd_t self:fifo_file rw_file_perms;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow ftpd_t bin_t:dir search;
Chris PeBenito ab58ad
can_exec(ftpd_t, bin_t)
Chris PeBenito ab58ad
allow ftpd_t bin_t:lnk_file read;
Chris PeBenito ab58ad
read_sysctl(ftpd_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow ftpd_t urandom_device_t:chr_file { getattr read };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
ifdef(`crond.te', `
Chris PeBenito ab58ad
system_crond_entry(ftpd_exec_t, ftpd_t)
Chris PeBenito ab58ad
allow system_crond_t xferlog_t:file r_file_perms;
Chris PeBenito ab58ad
can_exec(ftpd_t, { sbin_t shell_exec_t })
Chris PeBenito ab58ad
allow ftpd_t usr_t:file { getattr read };
Chris PeBenito ab58ad
ifdef(`logrotate.te', `
Chris PeBenito ab58ad
can_exec(ftpd_t, logrotate_exec_t)
Chris PeBenito ab58ad
')dnl end if logrotate.te
Chris PeBenito ab58ad
')dnl end if crond.te
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow ftpd_t ftp_data_port_t:tcp_socket name_bind;
Chris PeBenito ab58ad
allow ftpd_t port_t:tcp_socket name_bind;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# ftpd_lock_t is only needed when ftpd_is_daemon is true, but we cannot define types conditionally
Chris PeBenito ab58ad
type ftpd_lock_t, file_type, sysadmfile, lockfile;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Allow ftpd to run directly without inetd.
Chris PeBenito ab58ad
bool ftpd_is_daemon false;
Chris PeBenito ab58ad
if (ftpd_is_daemon) {
Chris PeBenito ab58ad
file_type_auto_trans(ftpd_t, var_lock_t, ftpd_lock_t, file)
Chris PeBenito ab58ad
allow ftpd_t ftp_port_t:tcp_socket name_bind;
Chris PeBenito ab58ad
can_tcp_connect(userdomain, ftpd_t)
Chris PeBenito ab58ad
# Allows it to check exec privs on daemon
Chris PeBenito ab58ad
allow inetd_t ftpd_exec_t:file x_file_perms;
Chris PeBenito ab58ad
}
Chris PeBenito ab58ad
ifdef(`inetd.te', `
Chris PeBenito ab58ad
if (!ftpd_is_daemon) {
Chris PeBenito ab58ad
ifdef(`tcpd.te', `domain_auto_trans(tcpd_t, ftpd_exec_t, ftpd_t)')
Chris PeBenito ab58ad
domain_auto_trans(inetd_t, ftpd_exec_t, ftpd_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Use sockets inherited from inetd.
Chris PeBenito ab58ad
allow ftpd_t inetd_t:fd use;
Chris PeBenito ab58ad
allow ftpd_t inetd_t:tcp_socket rw_stream_socket_perms;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Send SIGCHLD to inetd on death.
Chris PeBenito ab58ad
allow ftpd_t inetd_t:process sigchld;
Chris PeBenito ab58ad
}
Chris PeBenito ab58ad
') dnl end inetd.te
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Access shared memory tmpfs instance.
Chris PeBenito ab58ad
tmpfs_domain(ftpd)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Use capabilities.
Chris PeBenito ab58ad
allow ftpd_t self:capability { chown fowner fsetid setgid setuid net_bind_service sys_chroot sys_nice sys_resource };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Append to /var/log/wtmp.
Chris PeBenito ab58ad
allow ftpd_t wtmp_t:file { getattr append };
Chris PeBenito ab58ad
#kerberized ftp requires the following
Chris PeBenito ab58ad
allow ftpd_t wtmp_t:file { write lock };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Create and modify /var/log/xferlog.
Chris PeBenito ab58ad
type xferlog_t, file_type, sysadmfile, logfile;
Chris PeBenito ab58ad
file_type_auto_trans(ftpd_t, var_log_t, xferlog_t, file)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Execute /bin/ls (can comment this out for proftpd)
Chris PeBenito ab58ad
# also may need rules to allow tar etc...
Chris PeBenito ab58ad
can_exec(ftpd_t, ls_exec_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow initrc_t ftpd_etc_t:file { getattr read };
Chris PeBenito ab58ad
allow ftpd_t { etc_t etc_runtime_t }:file { getattr read };
Chris PeBenito ab58ad
allow ftpd_t proc_t:file { getattr read };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
dontaudit ftpd_t sysadm_home_dir_t:dir getattr;
Chris PeBenito ab58ad
dontaudit ftpd_t selinux_config_t:dir search;
Chris PeBenito ab58ad
allow ftpd_t autofs_t:dir search;
Chris PeBenito ab58ad
allow ftpd_t self:file { getattr read };
Chris PeBenito ab58ad
tmp_domain(ftpd)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Allow ftp to read/write files in the user home directories.
Chris PeBenito ab58ad
bool ftp_home_dir false;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
if (ftp_home_dir) {
Chris PeBenito ab58ad
# allow access to /home
Chris PeBenito ab58ad
allow ftpd_t home_root_t:dir r_dir_perms;
Chris PeBenito ab58ad
create_dir_file(ftpd_t, home_type)
Chris PeBenito ab58ad
ifdef(`targeted_policy', `
Chris PeBenito ab58ad
file_type_auto_trans(ftpd_t, user_home_dir_t, user_home_t)
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
}
Chris PeBenito ab58ad
if (use_nfs_home_dirs && ftp_home_dir) {
Chris PeBenito ab58ad
	r_dir_file(ftpd_t, nfs_t)
Chris PeBenito ab58ad
}
Chris PeBenito ab58ad
if (use_samba_home_dirs && ftp_home_dir) {
Chris PeBenito ab58ad
	r_dir_file(ftpd_t, cifs_t)
Chris PeBenito ab58ad
}
Chris PeBenito ab58ad
dontaudit ftpd_t selinux_config_t:dir search;
Chris PeBenito ab58ad
anonymous_domain(ftpd)
Chris PeBenito ab58ad