annotate lib/ftps.c @ 389:b39a312323ec

2003-2-3 Brian Masney <masneyb@gftp.org> * lib/Makefile.am lib/gftp.h lib/options.h lib/rfc959.c lib/ftpcommon.h lib/ftps.c - added support for the FTPS protocol. This currently is only for the control connection. (draft-murray-auth-ftp-ssl-09.txt)
author masneyb
date Wed, 04 Feb 2004 01:53:06 +0000
parents
children 0444232dc494
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
389
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
1 /*****************************************************************************/
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
2 /* ftps.c - General purpose routines for the FTPS protocol */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
4 /* */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
5 /* This program is free software; you can redistribute it and/or modify */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
6 /* it under the terms of the GNU General Public License as published by */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
7 /* the Free Software Foundation; either version 2 of the License, or */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
8 /* (at your option) any later version. */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
9 /* */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
10 /* This program is distributed in the hope that it will be useful, */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
13 /* GNU General Public License for more details. */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
14 /* */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
15 /* You should have received a copy of the GNU General Public License */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
16 /* along with this program; if not, write to the Free Software */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
18 /*****************************************************************************/
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
19
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
20 #include "gftp.h"
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
21 #include "ftpcommon.h"
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
22
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
23 static const char cvsid[] = "$Id$";
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
24
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
25 void
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
26 ftps_register_module (void)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
27 {
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
28 #ifdef USE_SSL
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
29 ssl_register_module ();
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
30 #endif
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
31 }
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
32
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
33
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
34 static int
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
35 ftps_auth_tls_start (gftp_request * request)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
36 {
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
37 rfc959_parms * params;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
38 int ret;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
39
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
40 params = request->protocol_data;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
41
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
42 ret = rfc959_send_command (request, "AUTH TLS\r\n", 1);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
43 if (ret < 0)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
44 return (ret);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
45 else if (ret != '2')
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
46 return (0);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
47
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
48 if ((ret = gftp_ssl_session_setup (request)) < 0)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
49 return (ret);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
50
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
51 request->read_function = gftp_ssl_read;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
52 request->write_function = gftp_ssl_write;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
53
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
54 ret = rfc959_send_command (request, "PBSZ 0\r\n", 1);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
55 if (ret < 0)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
56 return (ret);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
57
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
58 ret = rfc959_send_command (request, "PROT C\r\n", 1);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
59 if (ret < 0)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
60 return (ret);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
61
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
62 return (0);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
63 }
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
64
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
65
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
66 int
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
67 ftps_init (gftp_request * request)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
68 {
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
69 #ifdef USE_SSL
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
70 rfc959_parms * params;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
71 int ret;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
72
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
73 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
74
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
75 if ((ret = gftp_protocols[GFTP_FTP_NUM].init (request)) < 0)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
76 return (ret);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
77
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
78 params = request->protocol_data;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
79 params->auth_tls_start = ftps_auth_tls_start;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
80 request->init = ftps_init;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
81 request->post_connect = NULL;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
82 request->url_prefix = g_strdup ("ftps");
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
83
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
84 if ((ret = gftp_ssl_startup (NULL)) < 0)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
85 return (ret);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
86
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
87 return (0);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
88 #else
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
89 request->logging_function (gftp_logging_error, request,
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
90 _("FTPS Support unavailable since SSL support was not compiled in. Aborting connection.\n"));
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
91
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
92 return (GFTP_EFATAL);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
93 #endif
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
94 }
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
95