︙ | | | ︙ | |
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
|
pthread_create(&thread_id, NULL, filed_logging_thread, args);
filed_log_msg("START");
return(0);
}
#endif
#ifdef FILED_DONT_TIMEOUT
#define filed_sockettimeout_thread_init() 0
#define filed_sockettimeout_init() 0
#define filed_sockettimeout_accept(x) /**/
#define filed_sockettimeout_processing_start(x) /**/
#define filed_sockettimeout_processing_end(x) /**/
|
|
|
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
|
pthread_create(&thread_id, NULL, filed_logging_thread, args);
filed_log_msg("START");
return(0);
}
#endif /* FILED_DONT_LOG */
#ifdef FILED_DONT_TIMEOUT
#define filed_sockettimeout_thread_init() 0
#define filed_sockettimeout_init() 0
#define filed_sockettimeout_accept(x) /**/
#define filed_sockettimeout_processing_start(x) /**/
#define filed_sockettimeout_processing_end(x) /**/
|
︙ | | | ︙ | |
723
724
725
726
727
728
729
730
731
732
733
734
735
736
|
pthread_t thread_id;
long idx;
int count;
int valid;
int time_interval = 30;
int check_period = 90;
while (1) {
for (count = 0; count < (check_period / time_interval); count++) {
sleep_time.tv_sec = time_interval;
sleep_time.tv_nsec = 0;
nanosleep(&sleep_time, NULL);
pthread_mutex_lock(&filed_sockettimeout_mutex);
|
>
>
|
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
|
pthread_t thread_id;
long idx;
int count;
int valid;
int time_interval = 30;
int check_period = 90;
filed_sockettimeout_time = time(NULL);
while (1) {
for (count = 0; count < (check_period / time_interval); count++) {
sleep_time.tv_sec = time_interval;
sleep_time.tv_nsec = 0;
nanosleep(&sleep_time, NULL);
pthread_mutex_lock(&filed_sockettimeout_mutex);
|
︙ | | | ︙ | |
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
|
continue;
}
expiration_time = filed_sockettimeout_sockstatus[idx].expiration_time;
thread_id = filed_sockettimeout_sockstatus[idx].thread_id;
if (expiration_time > now) {
continue;
}
filed_sockettimeout_close(idx, 1);
dup2(filed_sockettimeout_devnull_fd, idx);
|
|
|
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
|
continue;
}
expiration_time = filed_sockettimeout_sockstatus[idx].expiration_time;
thread_id = filed_sockettimeout_sockstatus[idx].thread_id;
if (expiration_time > filed_sockettimeout_time) {
continue;
}
filed_sockettimeout_close(idx, 1);
dup2(filed_sockettimeout_devnull_fd, idx);
|
︙ | | | ︙ | |
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
|
filed_sockettimeout_devnull_fd = open("/dev/null", O_RDWR);
if (filed_sockettimeout_devnull_fd < 0) {
return(-1);
}
return(0);
}
#endif
/* Format time per RFC2616 */
static char *filed_format_time(char *buffer, size_t buffer_len, const time_t timeinfo) {
struct tm timeinfo_tm, *timeinfo_tm_p;
timeinfo_tm_p = gmtime_r(&timeinfo, &timeinfo_tm);
if (timeinfo_tm_p == NULL) {
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
|
filed_sockettimeout_devnull_fd = open("/dev/null", O_RDWR);
if (filed_sockettimeout_devnull_fd < 0) {
return(-1);
}
return(0);
}
#endif /* FILED_DONT_TIMEOUT */
#ifndef FILED_DO_SECCOMP
#define filed_init_seccomp() 0
#else
#include <linux/seccomp.h>
#include <linux/filter.h>
#include <linux/audit.h>
#include <sys/ptrace.h>
#include <sys/prctl.h>
#include <stddef.h>
static int filed_init_seccomp(void) {
struct sock_fprog filter;
struct sock_filter rules[] = {
#include "filed.seccomp.h"
};
int prctl_ret;
/* Do not allow any privilege changes beyond this point */
prctl_ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
if (prctl_ret != 0) {
return(-1);
}
filter.len = sizeof(rules) / sizeof(*rules);
filter.filter = rules;
prctl_ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &filter);
if (prctl_ret != 0) {
return(-1);
}
return(0);
}
#endif /* FILED_DO_SECCOMP */
/* Format time per RFC2616 */
static char *filed_format_time(char *buffer, size_t buffer_len, const time_t timeinfo) {
struct tm timeinfo_tm, *timeinfo_tm_p;
timeinfo_tm_p = gmtime_r(&timeinfo, &timeinfo_tm);
if (timeinfo_tm_p == NULL) {
|
︙ | | | ︙ | |
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
|
}
return;
}
/* Add a getopt option */
static void filed_getopt_long_setopt(struct option *opt, const char *name, int has_arg, int val) {
opt->name = name;
opt->has_arg = has_arg;
opt->flag = NULL;
opt->val = val;
return;
}
|
|
|
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
|
}
return;
}
/* Add a getopt option */
static void filed_getopt_long_setopt(struct option *opt, const char *name, int has_arg, int val) {
opt->name = (const char *) name;
opt->has_arg = has_arg;
opt->flag = NULL;
opt->val = val;
return;
}
|
︙ | | | ︙ | |
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
|
int port = PORT, thread_count = THREAD_COUNT;
int cache_size = CACHE_SIZE;
int init_ret, chroot_ret, setuid_ret, lookup_ret, chdir_ret;
int setuid_enabled = 0, daemon_enabled = 0;
int ch;
int fd;
/* Process arguments */
filed_getopt_long_setopt(&options[0], "port", required_argument, 'p');
filed_getopt_long_setopt(&options[1], "threads", required_argument, 't');
filed_getopt_long_setopt(&options[2], "cache", required_argument, 'c');
filed_getopt_long_setopt(&options[3], "bind", required_argument, 'b');
filed_getopt_long_setopt(&options[4], "user", required_argument, 'u');
filed_getopt_long_setopt(&options[5], "root", required_argument, 'r');
|
>
>
>
|
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
|
int port = PORT, thread_count = THREAD_COUNT;
int cache_size = CACHE_SIZE;
int init_ret, chroot_ret, setuid_ret, lookup_ret, chdir_ret;
int setuid_enabled = 0, daemon_enabled = 0;
int ch;
int fd;
/* Set default value */
thread_options.fake_newroot = NULL;
/* Process arguments */
filed_getopt_long_setopt(&options[0], "port", required_argument, 'p');
filed_getopt_long_setopt(&options[1], "threads", required_argument, 't');
filed_getopt_long_setopt(&options[2], "cache", required_argument, 'c');
filed_getopt_long_setopt(&options[3], "bind", required_argument, 'b');
filed_getopt_long_setopt(&options[4], "user", required_argument, 'u');
filed_getopt_long_setopt(&options[5], "root", required_argument, 'r');
|
︙ | | | ︙ | |
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
|
/* Create socket termination thread */
init_ret = filed_sockettimeout_thread_init();
if (init_ret != 0) {
perror("filed_sockettimeout_thread_init");
return(7);
}
/* Create worker threads */
init_ret = filed_worker_threads_init(fd, thread_count, &thread_options);
if (init_ret != 0) {
perror("filed_worker_threads_init");
return(5);
|
>
>
>
>
>
>
>
>
|
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
|
/* Create socket termination thread */
init_ret = filed_sockettimeout_thread_init();
if (init_ret != 0) {
perror("filed_sockettimeout_thread_init");
return(7);
}
/* Initialize seccomp */
init_ret = filed_init_seccomp();
if (init_ret != 0) {
perror("filed_init_seccomp");
return(9);
}
/* Create worker threads */
init_ret = filed_worker_threads_init(fd, thread_count, &thread_options);
if (init_ret != 0) {
perror("filed_worker_threads_init");
return(5);
|
︙ | | | ︙ | |