policy_module(radicale, 1.0.8)

gen_require(`
    type httpd_t;
    type pop_port_t;
')

########################################
#
# Declarations
#

type radicale_t;
type radicale_exec_t;
init_daemon_domain(radicale_t, radicale_exec_t)

type radicale_log_t;
logging_log_file(radicale_log_t)

type radicale_var_lib_t;
files_type(radicale_var_lib_t)

type radicale_var_run_t;
files_pid_file(radicale_var_run_t)

type radicale_etc_t;
files_config_file(radicale_etc_t);

type radicale_unit_file_t;
systemd_unit_file(radicale_unit_file_t)

type radicale_port_t;
corenet_port(radicale_port_t)

########################################
#
# radicale local policy
#
allow radicale_t self:fifo_file rw_fifo_file_perms;
allow radicale_t self:unix_stream_socket create_stream_socket_perms;
allow radicale_t self:tcp_socket create_stream_socket_perms;
allow radicale_t self:unix_dgram_socket create_stream_socket_perms;

allow radicale_t radicale_port_t:tcp_socket name_bind;
allow radicale_t pop_port_t:tcp_socket name_connect;

manage_dirs_pattern(radicale_t, radicale_log_t, radicale_log_t)
manage_files_pattern(radicale_t, radicale_log_t, radicale_log_t)
manage_lnk_files_pattern(radicale_t, radicale_log_t, radicale_log_t)
logging_log_filetrans(radicale_t, radicale_log_t, { dir file lnk_file })

manage_dirs_pattern(radicale_t, radicale_var_lib_t, radicale_var_lib_t)
manage_files_pattern(radicale_t, radicale_var_lib_t, radicale_var_lib_t)
manage_lnk_files_pattern(radicale_t, radicale_var_lib_t, radicale_var_lib_t)
files_var_lib_filetrans(radicale_t, radicale_var_lib_t, { dir file lnk_file })

manage_files_pattern(radicale_t, radicale_var_run_t, radicale_var_run_t)
files_pid_filetrans(radicale_t, radicale_var_lib_t, file)

domain_use_interactive_fds(radicale_t)

files_read_etc_files(radicale_t)
read_files_pattern(radicale_t, radicale_etc_t, radicale_etc_t)

bool httpd_can_read_write_radicale false;

if (httpd_can_read_write_radicale) {
    manage_dirs_pattern(httpd_t, radicale_log_t, radicale_log_t)
    manage_files_pattern(httpd_t, radicale_log_t, radicale_log_t)
    manage_lnk_files_pattern(httpd_t, radicale_log_t, radicale_log_t)
    #logging_log_filetrans(httpd_t, radicale_log_t, { dir file lnk_file })

    manage_dirs_pattern(httpd_t, radicale_var_lib_t, radicale_var_lib_t)
    manage_files_pattern(httpd_t, radicale_var_lib_t, radicale_var_lib_t)
    manage_lnk_files_pattern(httpd_t, radicale_var_lib_t, radicale_var_lib_t)
    #files_var_lib_filetrans(httpd_t, radicale_var_lib_t, { dir file lnk_file })

    #domain_use_interactive_fds(httpd_t)

    #files_read_etc_files(radicale_t)
    read_files_pattern(httpd_t, radicale_etc_t, radicale_etc_t)
} 

miscfiles_read_localization(radicale_t)
dev_read_urand(radicale_t)
dev_read_rand(radicale_t)
auth_use_nsswitch(radicale_t)
corecmd_exec_shell(radicale_t)
corecmd_exec_bin(radicale_t)
libs_exec_ldconfig(radicale_t)
kernel_read_system_state(radicale_t)
apache_search_config(radicale_t)
