privops.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef VSF_PRIVOPS_H
  2. #define VSF_PRIVOPS_H
  3. struct mystr;
  4. struct vsf_session;
  5. /* vsf_privop_get_ftp_port_sock()
  6. * PURPOSE
  7. * Return a network socket potentially bound to a privileged port (less than
  8. * 1024) and connected to the remote.
  9. * PARAMETERS
  10. * p_sess - the current session object
  11. * remote_port - the remote port to connect to
  12. * use_port_sockaddr - true if we should use the specific sockaddr for connect
  13. * RETURNS
  14. * A file descriptor which is a socket bound to the privileged port, and
  15. * connected to the remote on the specified port.
  16. * Kills the process / session if the bind() fails.
  17. * Returns -1 if the bind() worked but the connect() was not possible.
  18. */
  19. int vsf_privop_get_ftp_port_sock(struct vsf_session* p_sess,
  20. unsigned short remote_port,
  21. int use_port_sockaddr);
  22. /* vsf_privop_pasv_cleanup()
  23. * PURPOSE
  24. * Makes sure any listening passive socket is closed.
  25. * PARAMETERS
  26. * p_sess - the current session object
  27. */
  28. void vsf_privop_pasv_cleanup(struct vsf_session* p_sess);
  29. /* vsf_privop_pasv_listen()
  30. * PURPOSE
  31. * Start listening for an FTP data connection.
  32. * PARAMETERS
  33. * p_sess - the current session object
  34. * RETURNS
  35. * The port we ended up listening on.
  36. */
  37. unsigned short vsf_privop_pasv_listen(struct vsf_session* p_sess);
  38. /* vsf_privop_pasv_active()
  39. * PURPOSE
  40. * Determine whether there is a passive listening socket active.
  41. * PARAMETERS
  42. * p_sess - the current session object
  43. * RETURNS
  44. * 1 if active, 0 if not.
  45. */
  46. int vsf_privop_pasv_active(struct vsf_session* p_sess);
  47. /* vsf_privop_accept_pasv()
  48. * PURPOSE
  49. * Accept a connection on the listening data socket.
  50. * PARAMETERS
  51. * p_sess - the current session object
  52. * RETURNS
  53. * The file descriptor of the accepted incoming connection; or -1 if a
  54. * network error occurred or -2 if the incoming connection was from the
  55. * wrong IP (security issue).
  56. */
  57. int vsf_privop_accept_pasv(struct vsf_session* p_sess);
  58. /* vsf_privop_do_file_chown()
  59. * PURPOSE
  60. * Takes a file owned by the unprivileged FTP user, and change the ownership
  61. * to the value defined in the config file.
  62. * PARAMETERS
  63. * p_sess - the current session object
  64. * fd - the file descriptor of the regular file
  65. */
  66. void vsf_privop_do_file_chown(struct vsf_session* p_sess, int fd);
  67. enum EVSFPrivopLoginResult
  68. {
  69. kVSFLoginNull = 0,
  70. kVSFLoginFail,
  71. kVSFLoginAnon,
  72. kVSFLoginReal
  73. };
  74. /* vsf_privop_do_login()
  75. * PURPOSE
  76. * Check if the supplied username/password combination is valid. This
  77. * interface caters for checking both anonymous and real logins.
  78. * PARAMETERS
  79. * p_sess - the current session object
  80. * p_pass_str - the proposed password
  81. * RETURNS
  82. * kVSFLoginFail - access denied
  83. * kVSFLoginAnon - anonymous login credentials OK
  84. * kVSFLoginReal - real login credentials OK
  85. */
  86. enum EVSFPrivopLoginResult vsf_privop_do_login(
  87. struct vsf_session* p_sess, const struct mystr* p_pass_str);
  88. #endif /* VSF_PRIVOPS_H */