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;
|
|
30 int ret, resetptr;
|
|
31
|
|
32 params = request->protocol_data;
|
|
33 if (request->cached)
|
|
34 {
|
|
35 request->read_function = gftp_fd_read;
|
|
36 request->write_function = gftp_fd_write;
|
|
37 resetptr = 1;
|
|
38 }
|
|
39 else
|
|
40 resetptr = 0;
|
|
41
|
|
42 ret = rfc959_get_next_file (request, fle, fd);
|
|
43
|
|
44 if (resetptr)
|
|
45 {
|
|
46 request->read_function = gftp_ssl_read;
|
|
47 request->write_function = gftp_ssl_write;
|
|
48 }
|
|
49
|
|
50 return (ret);
|
389
|
51 }
|
|
52
|
|
53
|
|
54 static int
|
|
55 ftps_auth_tls_start (gftp_request * request)
|
|
56 {
|
|
57 rfc959_parms * params;
|
|
58 int ret;
|
|
59
|
|
60 params = request->protocol_data;
|
|
61
|
|
62 ret = rfc959_send_command (request, "AUTH TLS\r\n", 1);
|
|
63 if (ret < 0)
|
|
64 return (ret);
|
|
65 else if (ret != '2')
|
|
66 return (0);
|
|
67
|
|
68 if ((ret = gftp_ssl_session_setup (request)) < 0)
|
|
69 return (ret);
|
|
70
|
|
71 request->read_function = gftp_ssl_read;
|
|
72 request->write_function = gftp_ssl_write;
|
|
73
|
|
74 ret = rfc959_send_command (request, "PBSZ 0\r\n", 1);
|
|
75 if (ret < 0)
|
|
76 return (ret);
|
|
77
|
390
|
78 ret = '5'; /* FIXME */
|
|
79 /* ret = rfc959_send_command (request, "PROT P\r\n", 1); */
|
389
|
80 if (ret < 0)
|
|
81 return (ret);
|
390
|
82 else if (ret == '2')
|
|
83 {
|
|
84 params->data_conn_read = gftp_ssl_read;
|
|
85 params->data_conn_write = gftp_ssl_write;
|
|
86 }
|
|
87 else
|
|
88 {
|
|
89 ret = rfc959_send_command (request, "PROT C\r\n", 1);
|
|
90 if (ret < 0)
|
|
91 return (ret);
|
449
|
92 else if (ret != '2')
|
|
93 {
|
|
94 gftp_disconnect (request);
|
|
95 return (GFTP_ERETRYABLE);
|
|
96 }
|
390
|
97
|
|
98 params->data_conn_read = gftp_fd_read;
|
|
99 params->data_conn_write = gftp_fd_write;
|
|
100 }
|
389
|
101
|
|
102 return (0);
|
|
103 }
|
397
|
104 #endif
|
|
105
|
|
106
|
|
107 void
|
|
108 ftps_register_module (void)
|
|
109 {
|
|
110 #ifdef USE_SSL
|
|
111 ssl_register_module ();
|
|
112 #endif
|
|
113 }
|
389
|
114
|
|
115
|
451
|
116 static int
|
|
117 ftps_connect (gftp_request * request)
|
|
118 {
|
|
119 if (request->datafd > 0)
|
|
120 return (0);
|
|
121
|
|
122 request->read_function = gftp_fd_read;
|
|
123 request->write_function = gftp_fd_write;
|
|
124
|
|
125 return (rfc959_connect (request));
|
|
126 }
|
|
127
|
|
128
|
389
|
129 int
|
|
130 ftps_init (gftp_request * request)
|
|
131 {
|
|
132 #ifdef USE_SSL
|
|
133 rfc959_parms * params;
|
|
134 int ret;
|
|
135
|
|
136 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
137
|
|
138 if ((ret = gftp_protocols[GFTP_FTP_NUM].init (request)) < 0)
|
|
139 return (ret);
|
|
140
|
|
141 params = request->protocol_data;
|
415
|
142 request->protonum = GFTP_FTPS_NUM;
|
432
|
143 request->init = ftps_init;
|
451
|
144 request->connect = ftps_connect;
|
389
|
145 params->auth_tls_start = ftps_auth_tls_start;
|
397
|
146 request->get_next_file = ftps_get_next_file;
|
389
|
147 request->post_connect = NULL;
|
|
148 request->url_prefix = g_strdup ("ftps");
|
|
149
|
|
150 if ((ret = gftp_ssl_startup (NULL)) < 0)
|
|
151 return (ret);
|
|
152
|
|
153 return (0);
|
|
154 #else
|
|
155 request->logging_function (gftp_logging_error, request,
|
|
156 _("FTPS Support unavailable since SSL support was not compiled in. Aborting connection.\n"));
|
|
157
|
|
158 return (GFTP_EFATAL);
|
|
159 #endif
|
|
160 }
|
|
161
|