access.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Part of Very Secure FTPd
  3. * Licence: GPL v2
  4. * Author: Chris Evans
  5. * access.c
  6. *
  7. * Routines to do very very simple access control based on filenames.
  8. */
  9. #include "access.h"
  10. #include "ls.h"
  11. #include "tunables.h"
  12. #include "str.h"
  13. int
  14. vsf_access_check_file(const struct mystr* p_filename_str)
  15. {
  16. static struct mystr s_access_str;
  17. unsigned int iters = 0;
  18. if (!tunable_deny_file)
  19. {
  20. return 1;
  21. }
  22. if (str_isempty(&s_access_str))
  23. {
  24. str_alloc_text(&s_access_str, tunable_deny_file);
  25. }
  26. if (vsf_filename_passes_filter(p_filename_str, &s_access_str, &iters))
  27. {
  28. return 0;
  29. }
  30. else
  31. {
  32. struct str_locate_result loc_res =
  33. str_locate_str(p_filename_str, &s_access_str);
  34. if (loc_res.found)
  35. {
  36. return 0;
  37. }
  38. }
  39. return 1;
  40. }
  41. int
  42. vsf_access_check_file_visible(const struct mystr* p_filename_str)
  43. {
  44. static struct mystr s_access_str;
  45. unsigned int iters = 0;
  46. if (!tunable_hide_file)
  47. {
  48. return 1;
  49. }
  50. if (str_isempty(&s_access_str))
  51. {
  52. str_alloc_text(&s_access_str, tunable_hide_file);
  53. }
  54. if (vsf_filename_passes_filter(p_filename_str, &s_access_str, &iters))
  55. {
  56. return 0;
  57. }
  58. else
  59. {
  60. struct str_locate_result loc_res =
  61. str_locate_str(p_filename_str, &s_access_str);
  62. if (loc_res.found)
  63. {
  64. return 0;
  65. }
  66. }
  67. return 1;
  68. }