1/*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License as
4 * published by the Free Software Foundation; either version 2 of
5 * the License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
15 * MA 02111-1307 USA
16 */
17/*
18 * Part of Very Secure FTPd
19 * Licence: GPL v2
20 * Author: Chris Evans
21 * access.c
22 *
23 * Routines to do very very simple access control based on filenames.
24 */
25
26#include "access.h"
27#include "ls.h"
28#include "tunables.h"
29#include "str.h"
30#include "sysutil.h"
31
32int
33vsf_access_check_file(const struct mystr* p_filename_str)
34{
35  static struct mystr s_access_str;
36
37  if (!tunable_deny_file)
38  {
39    return 1;
40  }
41  if (str_isempty(&s_access_str))
42  {
43    str_alloc_text(&s_access_str, tunable_deny_file);
44  }
45  if (vsf_filename_passes_filter(p_filename_str, &s_access_str))
46  {
47    return 0;
48  }
49  else
50  {
51    struct str_locate_result loc_res =
52      str_locate_str(p_filename_str, &s_access_str);
53    if (loc_res.found)
54    {
55      return 0;
56    }
57  }
58  return 1;
59}
60
61int
62vsf_access_check_file_visible(const struct mystr* p_filename_str)
63{
64  static struct mystr s_access_str;
65
66  if (!tunable_hide_file)
67  {
68    return 1;
69  }
70  if (str_isempty(&s_access_str))
71  {
72    str_alloc_text(&s_access_str, tunable_hide_file);
73  }
74  if (vsf_filename_passes_filter(p_filename_str, &s_access_str))
75  {
76    return 0;
77  }
78  else
79  {
80    struct str_locate_result loc_res =
81      str_locate_str(p_filename_str, &s_access_str);
82    if (loc_res.found)
83    {
84      return 0;
85    }
86  }
87  return 1;
88}
89