banner.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Part of Very Secure FTPd
  3. * Licence: GPL v2
  4. * Author: Chris Evans
  5. * banner.c
  6. *
  7. * Calls exposed to handle the junk a typical FTP server has to do upon
  8. * entering a new directory (messages, etc), as well as general banner
  9. * writing support.
  10. */
  11. #include "banner.h"
  12. #include "strlist.h"
  13. #include "str.h"
  14. #include "sysstr.h"
  15. #include "tunables.h"
  16. #include "ftpcmdio.h"
  17. #include "filestr.h"
  18. #include "session.h"
  19. #include "sysutil.h"
  20. /* Definitions */
  21. #define VSFTP_MAX_VISIT_REMEMBER 100
  22. #define VSFTP_MAX_MSGFILE_SIZE 4000
  23. void
  24. vsf_banner_dir_changed(struct vsf_session* p_sess, int ftpcode)
  25. {
  26. struct mystr dir_str = INIT_MYSTR;
  27. /* Do nothing if .message support is off */
  28. if (!tunable_dirmessage_enable)
  29. {
  30. return;
  31. }
  32. if (p_sess->p_visited_dir_list == 0)
  33. {
  34. struct mystr_list the_list = INIT_STRLIST;
  35. p_sess->p_visited_dir_list = vsf_sysutil_malloc(sizeof(struct mystr_list));
  36. *p_sess->p_visited_dir_list = the_list;
  37. }
  38. str_getcwd(&dir_str);
  39. /* Do nothing if we already visited this directory */
  40. if (!str_list_contains_str(p_sess->p_visited_dir_list, &dir_str))
  41. {
  42. /* Just in case, cap the max. no of visited directories we'll remember */
  43. if (str_list_get_length(p_sess->p_visited_dir_list) <
  44. VSFTP_MAX_VISIT_REMEMBER)
  45. {
  46. str_list_add(p_sess->p_visited_dir_list, &dir_str, 0);
  47. }
  48. /* If we have a .message file, squirt it out prepended by the ftpcode and
  49. * the continuation mark '-'
  50. */
  51. {
  52. struct mystr msg_file_str = INIT_MYSTR;
  53. if (tunable_message_file)
  54. {
  55. (void) str_fileread(&msg_file_str, tunable_message_file,
  56. VSFTP_MAX_MSGFILE_SIZE);
  57. }
  58. vsf_banner_write(p_sess, &msg_file_str, ftpcode);
  59. str_free(&msg_file_str);
  60. }
  61. }
  62. str_free(&dir_str);
  63. }
  64. void
  65. vsf_banner_write(struct vsf_session* p_sess, struct mystr* p_str, int ftpcode)
  66. {
  67. struct mystr msg_line_str = INIT_MYSTR;
  68. unsigned int str_pos = 0;
  69. while (str_getline(p_str, &msg_line_str, &str_pos))
  70. {
  71. vsf_cmdio_write_str_hyphen(p_sess, ftpcode, &msg_line_str);
  72. }
  73. str_free(&msg_line_str);
  74. }