diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/ftps.c	Wed Feb 04 01:53:06 2004 +0000
@@ -0,0 +1,95 @@
+/*****************************************************************************/
+/*  ftps.c - General purpose routines for the FTPS protocol                  */
+/*  Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org>                  */
+/*                                                                           */
+/*  This program is free software; you can redistribute it and/or modify     */
+/*  it under the terms of the GNU General Public License as published by     */
+/*  the Free Software Foundation; either version 2 of the License, or        */
+/*  (at your option) any later version.                                      */
+/*                                                                           */
+/*  This program is distributed in the hope that it will be useful,          */
+/*  but WITHOUT ANY WARRANTY; without even the implied warranty of           */
+/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            */
+/*  GNU General Public License for more details.                             */
+/*                                                                           */
+/*  You should have received a copy of the GNU General Public License        */
+/*  along with this program; if not, write to the Free Software              */
+/*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA      */
+/*****************************************************************************/
+
+#include "gftp.h"
+#include "ftpcommon.h"
+
+static const char cvsid[] = "$Id$";
+
+void
+ftps_register_module (void)
+{
+#ifdef USE_SSL
+  ssl_register_module ();
+#endif
+}
+
+
+static int 
+ftps_auth_tls_start (gftp_request * request)
+{
+  rfc959_parms * params;
+  int ret;
+
+  params = request->protocol_data;
+
+  ret = rfc959_send_command (request, "AUTH TLS\r\n", 1);
+  if (ret < 0)
+    return (ret);
+  else if (ret != '2')
+    return (0);
+
+  if ((ret = gftp_ssl_session_setup (request)) < 0)
+    return (ret);
+
+  request->read_function = gftp_ssl_read;
+  request->write_function = gftp_ssl_write;
+
+  ret = rfc959_send_command (request, "PBSZ 0\r\n", 1);
+  if (ret < 0)
+    return (ret);
+
+  ret = rfc959_send_command (request, "PROT C\r\n", 1);
+  if (ret < 0)
+    return (ret);
+
+  return (0);
+}
+
+
+int
+ftps_init (gftp_request * request)
+{
+#ifdef USE_SSL
+  rfc959_parms * params;
+  int ret;
+
+  g_return_val_if_fail (request != NULL, GFTP_EFATAL);
+
+  if ((ret = gftp_protocols[GFTP_FTP_NUM].init (request)) < 0)
+    return (ret);
+
+  params = request->protocol_data;
+  params->auth_tls_start = ftps_auth_tls_start;
+  request->init = ftps_init;
+  request->post_connect = NULL;
+  request->url_prefix = g_strdup ("ftps");
+
+  if ((ret = gftp_ssl_startup (NULL)) < 0)
+    return (ret);
+
+  return (0);
+#else
+  request->logging_function (gftp_logging_error, request,
+                             _("FTPS Support unavailable since SSL support was not compiled in. Aborting connection.\n"));
+
+  return (GFTP_EFATAL);
+#endif
+}
+