forked from checkedc/checkedc-vsftpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccess.c
113 lines (97 loc) · 2.11 KB
/
access.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Part of Very Secure FTPd
* Licence: GPL v2
* Author: Chris Evans
* access.c
*
* Routines to do very very simple access control based on filenames.
*/
#include "access.h"
#include "ls.h"
#include "tunables.h"
#include "str.h"
#pragma CHECKED_SCOPE on
static int
vsf_match_filter(const _Ptr<const struct mystr> p_filename_str, const _Ptr<const struct mystr> p_access_str) {
unsigned iters = 0;
if (vsf_filename_passes_filter(p_filename_str, p_access_str, &iters))
{
return 1;
}
else
{
struct str_locate_result const loc_res =
str_locate_str(p_filename_str, p_access_str);
return loc_res.found;
}
}
int
vsf_access_check_file(const struct mystr *p_filename_str : itype(_Ptr<const struct mystr>))
{
static struct mystr s_access_str = {};
if (!tunable_deny_file)
{
return 1;
}
if (str_isempty(&s_access_str))
{
str_alloc_text(&s_access_str, tunable_deny_file);
}
if (vsf_match_filter(p_filename_str, &s_access_str))
{
return 0;
}
else
{
return 1;
}
}
int
vsf_access_check_file_visible(const struct mystr *p_filename_str : itype(_Ptr<const struct mystr>))
{
static struct mystr s_access_str = {};
if (!tunable_hide_file)
{
return 1;
}
if (str_isempty(&s_access_str))
{
str_alloc_text(&s_access_str, tunable_hide_file);
}
if (vsf_match_filter(p_filename_str, &s_access_str))
{
return 0;
}
else
{
return 1;
}
}
int
vsf_access_check_file_upload(const struct mystr *p_filename_str : itype(_Ptr<const struct mystr>))
{
static struct mystr s_access_str = {};
if (!tunable_upload_file)
{
return 1;
}
if (str_isempty(&s_access_str))
{
str_alloc_text(&s_access_str, tunable_upload_file);
}
return vsf_match_filter(p_filename_str, &s_access_str);
}
int
vsf_access_check_file_download(const struct mystr *p_filename_str : itype(_Ptr<const struct mystr>))
{
static struct mystr s_access_str = {};
if (!tunable_download_file)
{
return 1;
}
if (str_isempty(&s_access_str))
{
str_alloc_text(&s_access_str, tunable_download_file);
}
return vsf_match_filter(p_filename_str, &s_access_str);
}