389
|
1 /*****************************************************************************/
|
|
2 /* ftps.c - General purpose routines for the FTPS protocol */
|
|
3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */
|
|
4 /* */
|
|
5 /* This program is free software; you can redistribute it and/or modify */
|
|
6 /* it under the terms of the GNU General Public License as published by */
|
|
7 /* the Free Software Foundation; either version 2 of the License, or */
|
|
8 /* (at your option) any later version. */
|
|
9 /* */
|
|
10 /* This program is distributed in the hope that it will be useful, */
|
|
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
13 /* GNU General Public License for more details. */
|
|
14 /* */
|
|
15 /* You should have received a copy of the GNU General Public License */
|
|
16 /* along with this program; if not, write to the Free Software */
|
|
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
|
|
18 /*****************************************************************************/
|
|
19
|
|
20 #include "gftp.h"
|
|
21 #include "ftpcommon.h"
|
|
22
|
|
23 static const char cvsid[] = "$Id$";
|
|
24
|
397
|
25 #ifdef USE_SSL
|
|
26 static int
|
|
27 ftps_get_next_file (gftp_request * request, gftp_file * fle, int fd)
|
389
|
28 {
|
397
|
29 rfc959_parms * params;
|
516
|
30 int resetptr;
|
|
31 size_t ret;
|
397
|
32
|
|
33 params = request->protocol_data;
|
|
34 if (request->cached)
|
|
35 {
|
|
36 request->read_function = gftp_fd_read;
|
|
37 request->write_function = gftp_fd_write;
|
|
38 resetptr = 1;
|
|
39 }
|
|
40 else
|
|
41 resetptr = 0;
|
|
42
|
|
43 ret = rfc959_get_next_file (request, fle, fd);
|
|
44
|
|
45 if (resetptr)
|
|
46 {
|
|
47 request->read_function = gftp_ssl_read;
|
|
48 request->write_function = gftp_ssl_write;
|
|
49 }
|
|
50
|
|
51 return (ret);
|
389
|
52 }
|
|
53
|
|
54
|
|
55 static int
|
|
56 ftps_auth_tls_start (gftp_request * request)
|
|
57 {
|
|
58 rfc959_parms * params;
|
|
59 int ret;
|
|
60
|
|
61 params = request->protocol_data;
|
|
62
|
847
|
63 ret = rfc959_send_command (request, "AUTH TLS\r\n", -1, 1, 0);
|
389
|
64 if (ret < 0)
|
|
65 return (ret);
|
|
66 else if (ret != '2')
|
546
|
67 return (GFTP_EFATAL);
|
389
|
68
|
|
69 if ((ret = gftp_ssl_session_setup (request)) < 0)
|
|
70 return (ret);
|
|
71
|
|
72 request->read_function = gftp_ssl_read;
|
|
73 request->write_function = gftp_ssl_write;
|
|
74
|
847
|
75 ret = rfc959_send_command (request, "PBSZ 0\r\n", -1, 1, 0);
|
389
|
76 if (ret < 0)
|
|
77 return (ret);
|
|
78
|
390
|
79 ret = '5'; /* FIXME */
|
847
|
80 /* ret = rfc959_send_command (request, "PROT P\r\n", -1, 1, 0); */
|
389
|
81 if (ret < 0)
|
|
82 return (ret);
|
390
|
83 else if (ret == '2')
|
|
84 {
|
|
85 params->data_conn_read = gftp_ssl_read;
|
|
86 params->data_conn_write = gftp_ssl_write;
|
|
87 }
|
|
88 else
|
|
89 {
|
847
|
90 ret = rfc959_send_command (request, "PROT C\r\n", -1, 1, 0);
|
390
|
91 if (ret < 0)
|
|
92 return (ret);
|
449
|
93 else if (ret != '2')
|
|
94 {
|
|
95 gftp_disconnect (request);
|
|
96 return (GFTP_ERETRYABLE);
|
|
97 }
|
390
|
98
|
|
99 params->data_conn_read = gftp_fd_read;
|
|
100 params->data_conn_write = gftp_fd_write;
|
|
101 }
|
389
|
102
|
|
103 return (0);
|
|
104 }
|
397
|
105 #endif
|
|
106
|
|
107
|
|
108 void
|
|
109 ftps_register_module (void)
|
|
110 {
|
|
111 #ifdef USE_SSL
|
|
112 ssl_register_module ();
|
|
113 #endif
|
|
114 }
|
389
|
115
|
|
116
|
765
|
117 /*@unused@*/ static int
|
451
|
118 ftps_connect (gftp_request * request)
|
|
119 {
|
|
120 if (request->datafd > 0)
|
|
121 return (0);
|
|
122
|
|
123 request->read_function = gftp_fd_read;
|
|
124 request->write_function = gftp_fd_write;
|
|
125
|
|
126 return (rfc959_connect (request));
|
|
127 }
|
|
128
|
|
129
|
389
|
130 int
|
|
131 ftps_init (gftp_request * request)
|
|
132 {
|
|
133 #ifdef USE_SSL
|
|
134 rfc959_parms * params;
|
|
135 int ret;
|
|
136
|
|
137 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
138
|
|
139 if ((ret = gftp_protocols[GFTP_FTP_NUM].init (request)) < 0)
|
|
140 return (ret);
|
|
141
|
|
142 params = request->protocol_data;
|
415
|
143 request->protonum = GFTP_FTPS_NUM;
|
432
|
144 request->init = ftps_init;
|
451
|
145 request->connect = ftps_connect;
|
389
|
146 params->auth_tls_start = ftps_auth_tls_start;
|
397
|
147 request->get_next_file = ftps_get_next_file;
|
389
|
148 request->post_connect = NULL;
|
|
149 request->url_prefix = g_strdup ("ftps");
|
|
150
|
|
151 if ((ret = gftp_ssl_startup (NULL)) < 0)
|
|
152 return (ret);
|
|
153
|
|
154 return (0);
|
|
155 #else
|
|
156 request->logging_function (gftp_logging_error, request,
|
|
157 _("FTPS Support unavailable since SSL support was not compiled in. Aborting connection.\n"));
|
|
158
|
|
159 return (GFTP_EFATAL);
|
|
160 #endif
|
|
161 }
|
|
162
|