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
|
|
58 ret = rfc959_send_command (request, "PROT C\r\n", 1);
|
|
59 if (ret < 0)
|
|
60 return (ret);
|
|
61
|
|
62 return (0);
|
|
63 }
|
|
64
|
|
65
|
|
66 int
|
|
67 ftps_init (gftp_request * request)
|
|
68 {
|
|
69 #ifdef USE_SSL
|
|
70 rfc959_parms * params;
|
|
71 int ret;
|
|
72
|
|
73 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
74
|
|
75 if ((ret = gftp_protocols[GFTP_FTP_NUM].init (request)) < 0)
|
|
76 return (ret);
|
|
77
|
|
78 params = request->protocol_data;
|
|
79 params->auth_tls_start = ftps_auth_tls_start;
|
|
80 request->init = ftps_init;
|
|
81 request->post_connect = NULL;
|
|
82 request->url_prefix = g_strdup ("ftps");
|
|
83
|
|
84 if ((ret = gftp_ssl_startup (NULL)) < 0)
|
|
85 return (ret);
|
|
86
|
|
87 return (0);
|
|
88 #else
|
|
89 request->logging_function (gftp_logging_error, request,
|
|
90 _("FTPS Support unavailable since SSL support was not compiled in. Aborting connection.\n"));
|
|
91
|
|
92 return (GFTP_EFATAL);
|
|
93 #endif
|
|
94 }
|
|
95
|