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
|
|
25 void
|
|
26 ftps_register_module (void)
|
|
27 {
|
|
28 #ifdef USE_SSL
|
|
29 ssl_register_module ();
|
|
30 #endif
|
|
31 }
|
|
32
|
|
33
|
|
34 static int
|
|
35 ftps_auth_tls_start (gftp_request * request)
|
|
36 {
|
|
37 rfc959_parms * params;
|
|
38 int ret;
|
|
39
|
|
40 params = request->protocol_data;
|
|
41
|
|
42 ret = rfc959_send_command (request, "AUTH TLS\r\n", 1);
|
|
43 if (ret < 0)
|
|
44 return (ret);
|
|
45 else if (ret != '2')
|
|
46 return (0);
|
|
47
|
|
48 if ((ret = gftp_ssl_session_setup (request)) < 0)
|
|
49 return (ret);
|
|
50
|
|
51 request->read_function = gftp_ssl_read;
|
|
52 request->write_function = gftp_ssl_write;
|
|
53
|
|
54 ret = rfc959_send_command (request, "PBSZ 0\r\n", 1);
|
|
55 if (ret < 0)
|
|
56 return (ret);
|
|
57
|
390
|
58 ret = '5'; /* FIXME */
|
|
59 /* ret = rfc959_send_command (request, "PROT P\r\n", 1); */
|
389
|
60 if (ret < 0)
|
|
61 return (ret);
|
390
|
62 else if (ret == '2')
|
|
63 {
|
|
64 params->data_conn_read = gftp_ssl_read;
|
|
65 params->data_conn_write = gftp_ssl_write;
|
|
66 params->encrypted_connection = 1;
|
|
67 }
|
|
68 else
|
|
69 {
|
|
70 ret = rfc959_send_command (request, "PROT C\r\n", 1);
|
|
71 if (ret < 0)
|
|
72 return (ret);
|
|
73
|
|
74 params->data_conn_read = gftp_fd_read;
|
|
75 params->data_conn_write = gftp_fd_write;
|
|
76 params->encrypted_connection = 0;
|
|
77 }
|
389
|
78
|
|
79 return (0);
|
|
80 }
|
|
81
|
|
82
|
|
83 int
|
|
84 ftps_init (gftp_request * request)
|
|
85 {
|
|
86 #ifdef USE_SSL
|
|
87 rfc959_parms * params;
|
|
88 int ret;
|
|
89
|
|
90 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
91
|
|
92 if ((ret = gftp_protocols[GFTP_FTP_NUM].init (request)) < 0)
|
|
93 return (ret);
|
|
94
|
|
95 params = request->protocol_data;
|
|
96 params->auth_tls_start = ftps_auth_tls_start;
|
|
97 request->init = ftps_init;
|
|
98 request->post_connect = NULL;
|
|
99 request->url_prefix = g_strdup ("ftps");
|
|
100
|
|
101 if ((ret = gftp_ssl_startup (NULL)) < 0)
|
|
102 return (ret);
|
|
103
|
|
104 return (0);
|
|
105 #else
|
|
106 request->logging_function (gftp_logging_error, request,
|
|
107 _("FTPS Support unavailable since SSL support was not compiled in. Aborting connection.\n"));
|
|
108
|
|
109 return (GFTP_EFATAL);
|
|
110 #endif
|
|
111 }
|
|
112
|