1 /*
2  * $Id: ftp-client.h,v 1.6.2.1 2003/05/07 11:12:03 mt Exp $
3  *
4  * Header for the FTP Proxy client handling
5  *
6  * Author(s): Jens-Gero Boehm <jens-gero.boehm@suse.de>
7  *            Pieter Hollants <pieter.hollants@suse.de>
8  *            Marius Tomaschewski <mt@suse.de>
9  *            Volker Wiegand <volker.wiegand@suse.de>
10  *
11  * This file is part of the SuSE Proxy Suite
12  *            See also  http://proxy-suite.suse.de/
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version
17  * 2 of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the
26  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27  * Boston, MA 02111-1307, USA.
28  *
29  * A history log can be found at the end of this file.
30  */
31 
32 #if !defined(_FTP_CLIENT_H_)
33 #define _FTP_CLIENT_H_
34 
35 #include "com-socket.h"		/* Make sure we know PEER_LEN	*/
36 
37 
38 /* ------------------------------------------------------------ */
39 
40 /*
41 ** Define the necessary Telnet support
42 */
43 
44 #if !defined(DM)
45 #  define DM		242	/* Data Mark			*/
46 #endif
47 #if !defined(IP)
48 #  define IP		244	/* Interrupt Process		*/
49 #endif
50 #if !defined(WILL)
51 #  define WILL		251	/* I will perform option	*/
52 #endif
53 #if !defined(WONT)
54 #  define WONT		252	/* I won't perform option	*/
55 #endif
56 #if !defined(DO)
57 #  define DO		253	/* Please do perform option	*/
58 #endif
59 #if !defined(DONT)
60 #  define DONT		254	/* Please don't perform option	*/
61 #endif
62 #if !defined(IAC)
63 #  define IAC		255	/* Interpret as Command		*/
64 #endif
65 
66 
67 /* ------------------------------------------------------------ */
68 
69 #if !defined(IPPORT_FTP)
70 #  define IPPORT_FTP	21	/* Usually "well known"		*/
71 #endif
72 
73 #define MOD_RESET	0	/* Reset mode to Active FTP	*/
74 #define MOD_ACT_FTP	1	/* Active FTP mode		*/
75 #define MOD_PAS_FTP	2	/* Passive FTP mode		*/
76 #define MOD_CLI_FTP	3	/* Same FTP mode as client	*/
77 
78 #define EXP_IDLE	0	/* Idle: expect nothing		*/
79 #define EXP_CONN	1	/* Connect: expect 220 or 421	*/
80 #define EXP_USER	2	/* USER: expect 230, 331 or 5xx	*/
81 #define EXP_ABOR	3	/* ABOR: expect 226 *and* 230	*/
82 #define EXP_PASV	4	/* PASV: expect 227		*/
83 #define EXP_PORT	5	/* PORT: expect 200		*/
84 #define EXP_XFER	6	/* Transfer: expect 226		*/
85 #define EXP_PTHR	7	/* Pass-Through: just relay	*/
86 
87 #define UAUTH_NONE	0	/* No user auth used		*/
88 #define UAUTH_FTP	1	/* Auth with ftp user + pass	*/
89 #define UAUTH_MAU	2	/* Magic auth mode auth%user	*/
90 #define UAUTH_MUA	3	/* Magic auth mode user%auth	*/
91 
92 typedef struct {
93 	HLS *cli_ctrl;		/* Control path to the client	*/
94 	HLS *cli_data;		/* Data path to the client	*/
95 	HLS *srv_ctrl;		/* Control path to the server	*/
96 	HLS *srv_data;		/* Data path to the server	*/
97 
98 	char *username;		/* Client's ftp-username	*/
99 	char *userpass;		/* Client's ftp-password	*/
100 	char *userauth;		/* Client's user auth name	*/
101 
102 	int   auth_mode;	/* Client auth mode flag	*/
103 	char *magic_auth;	/* Magic-Auth mode string	*/
104 
105 	u_int32_t magic_addr;	/* The "real" destination ...	*/
106 	u_int16_t magic_port;	/* ... and corresponding port	*/
107 
108 	int cli_mode;		/* Transfer mode to client	*/
109 	u_int32_t cli_addr;	/* Address from client PORT	*/
110 	u_int16_t cli_port;	/* TCP port from client PORT	*/
111 
112 	u_int16_t act_lrng;	/* Lower port range (active)	*/
113 	u_int16_t act_urng;	/* Upper port range (active)	*/
114 	u_int16_t pas_lrng;	/* Lower port range (passive)	*/
115 	u_int16_t pas_urng;	/* Upper port range (passive)	*/
116 
117 	int same_adr;		/* 1=PORT to same address only	*/
118 
119 	int srv_mode;		/* Transfer mode to server	*/
120 	u_int32_t srv_addr;	/* Destination server IP addr	*/
121 	u_int16_t srv_port;	/* Destination server port	*/
122 	u_int16_t srv_lrng;	/* Lower port range to server	*/
123 	u_int16_t srv_urng;	/* Upper port range to server	*/
124 
125 	char *curr_cmd;		/* Current outstanding command	*/
126 	int expect;		/* Expected answer from server	*/
127 
128 	int timeout;		/* Inactivity timeout in secs	*/
129 
130 	time_t sess_beg;	/* Start time of session	*/
131 
132 	char   xfer_cmd[16];	/* Outstanding transfer cmd	*/
133 	char   xfer_arg[1024];	/* Argument for xfer_cmd	*/
134 	char   xfer_rep[1024];	/* Outstanding server reply	*/
135 	time_t xfer_beg;	/* Start time of data transfer	*/
136 	size_t xfer_rcnt;	/* bytes, read transfers	*/
137 	size_t xfer_rsec;	/* secs, read transfers		*/
138 	size_t xfer_wcnt;	/* bytes, write transfers	*/
139 	size_t xfer_wsec;	/* secs, write transfers	*/
140 } CONTEXT;
141 
142 
143 /* ------------------------------------------------------------ */
144 
145 void client_run    (void);
146 void client_reinit (void);
147 void client_respond(int code, char *file, char *fmt, ...);
148 void client_data_reset(int mode);
149 
150 int  client_setup(char *pwd);
151 void client_srv_open(void);
152 
153 /* ------------------------------------------------------------ */
154 
155 #endif /* defined(_FTP_CLIENT_H_) */
156 
157 /* ------------------------------------------------------------
158  * $Log: ftp-client.h,v $
159  * Revision 1.6.2.1  2003/05/07 11:12:03  mt
160  * added ctx->auth_mode variale and UAUTH_ flags to remember auth mode
161  *
162  * Revision 1.6  2002/05/02 13:15:36  mt
163  * implemented simple (ldap based) user auth
164  *
165  * Revision 1.5  2002/01/14 19:35:44  mt
166  * implemented workarround for Netscape (4.x) directory symlink handling
167  * implemented a MaxRecvBufSize option limiting max recv buffer size
168  * extended log messages to provide basic transfer statistics data
169  * added snprintf usage if supported, replaced strncpy with misc_strncpy
170  *
171  * Revision 1.4  1999/09/24 06:38:52  wiegand
172  * added regular expressions for all commands
173  * removed character map and length of paths
174  * added flag to reset PASV on every PORT
175  * added "magic" user with built-in destination
176  * added some argument pointer fortification
177  *
178  * Revision 1.3  1999/09/17 16:32:29  wiegand
179  * changes from source code review
180  * added POSIX regular expressions
181  *
182  * Revision 1.2  1999/09/16 16:29:57  wiegand
183  * minor updates improving code quality
184  *
185  * Revision 1.1  1999/09/15 14:06:22  wiegand
186  * initial checkin
187  *
188  * ------------------------------------------------------------ */
189 
190