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