1 /* 2 * $Id: ftp_session.h,v 1.13 2001/05/10 23:28:57 shane Exp $ 3 * 4 * Restrictions: 5 * - Only stream MODE is supported. 6 * - Only "ftp" or "anonymous" accepted as a user. 7 */ 8 9 #ifndef FTP_SESSION_H 10 #define FTP_SESSION_H 11 12 #include <netinet/in.h> 13 #include <sys/types.h> 14 #include <limits.h> 15 #include "af_portability.h" 16 #include "watchdog.h" 17 #include "error.h" 18 19 /* data representation types supported */ 20 #define TYPE_ASCII 0 21 #define TYPE_IMAGE 1 22 23 /* file structure types supported */ 24 #define STRU_FILE 0 25 #define STRU_RECORD 1 26 27 /* data path chosen */ 28 #define DATA_PORT 0 29 #define DATA_PASSIVE 1 30 31 /* space required for text representation of address and port, 32 e.g. "192.168.0.1 port 1024" or 33 "2001:3333:DEAD:BEEF:0666:0013:0069:0042 port 65535" */ 34 #define ADDRPORT_STRLEN 58 35 36 /* structure encapsulating an FTP session's information */ 37 typedef struct { 38 /* flag whether session is active */ 39 int session_active; 40 41 /* incremented for each command */ 42 unsigned long command_number; 43 44 /* options about transfer set by user */ 45 int data_type; 46 int file_structure; 47 48 /* offset to begin sending file from */ 49 off_t file_offset; 50 unsigned long file_offset_command_number; 51 52 /* flag set if client requests ESPV ALL - this prevents subsequent 53 use of PORT, PASV, LPRT, LPSV, or EPRT */ 54 int epsv_all_set; 55 56 /* address of client */ 57 sockaddr_storage_t client_addr; 58 char client_addr_str[ADDRPORT_STRLEN]; 59 60 /* address of server (including IPv4 version) */ 61 sockaddr_storage_t server_addr; 62 struct sockaddr_in server_ipv4_addr; 63 64 /* telnet session to encapsulate control channel logic */ 65 telnet_session_t *telnet_session; 66 67 /* current working directory of this connection */ 68 char dir[PATH_MAX+1]; 69 70 /* data channel information, including type, 71 and client address or server port depending on type */ 72 int data_channel; 73 sockaddr_storage_t data_port; 74 int server_fd; 75 76 /* watchdog to handle timeout */ 77 watched_t *watched; 78 } ftp_session_t; 79 80 int ftp_session_init(ftp_session_t *f, 81 const sockaddr_storage_t *client_addr, 82 const sockaddr_storage_t *server_addr, 83 telnet_session_t *t, 84 const char *dir, 85 error_t *err); 86 void ftp_session_drop(ftp_session_t *f, const char *reason); 87 void ftp_session_run(ftp_session_t *f, watched_t *watched); 88 void ftp_session_destroy(ftp_session_t *f); 89 90 #endif /* FTP_SESSION_H */ 91 92