view lib/ftps.c @ 397:14ef37b62c20

2004-2-8 Brian Masney <masneyb@gftp.org> * src/gtk/gftp-gtk.h src/gtk/gtkui.c - added gftpui_gtk_get_utf8_file_pos() that will return the file in UTF8 format if it is available * src/gtk/gtkui_transfer.c src/gtk/transfer.c - call gftpui_gtk_get_utf8_file_pos() to display the file in the file transfer status. This fixes a bug where non-UTF8 files were being chopped off * src/text/textui.c src/uicommon/gftpui.c src/uicommon/gftpui.h src/text/gtkui_transfer.c - updated declaration of gftpui_add_file_to_transfer() * lib/protocols.c (gftp_swap_socks) - swap the SSL sockets between the two request structures * lib/ftps.c - added ftps_get_next_file() that will pull items from the cache properly * lib/Makefile.am - updated LOCALE_DIR declaration (from Sung-Hyun Nam <namsh@kldp.org>) * ChangeLog-old - updated summary of changes since 2.0.16 * TODO - removed several items that were completed
author masneyb
date Sun, 08 Feb 2004 16:19:26 +0000
parents 0444232dc494
children 1ffdbc487a70
line wrap: on
line source

/*****************************************************************************/
/*  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$";

#ifdef USE_SSL
static int
ftps_get_next_file (gftp_request * request, gftp_file * fle, int fd)
{
  rfc959_parms * params;
  int ret, resetptr;

  params = request->protocol_data;
  if (request->cached)
    {
      request->read_function = gftp_fd_read;
      request->write_function = gftp_fd_write;
      resetptr = 1;
    }
  else
    resetptr = 0;

  ret = rfc959_get_next_file (request, fle, fd);

  if (resetptr)
    {
      request->read_function = gftp_ssl_read;
      request->write_function = gftp_ssl_write;
    }

  return (ret);
}


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 = '5'; /* FIXME */
  /* ret = rfc959_send_command (request, "PROT P\r\n", 1); */
  if (ret < 0)
    return (ret);
  else if (ret == '2')
    {
      params->data_conn_read = gftp_ssl_read;
      params->data_conn_write = gftp_ssl_write;
      params->encrypted_connection = 1;
    }
  else
    {
      ret = rfc959_send_command (request, "PROT C\r\n", 1);
      if (ret < 0)
        return (ret);

      params->data_conn_read = gftp_fd_read;
      params->data_conn_write = gftp_fd_write;
      params->encrypted_connection = 0;
    }

  return (0);
}
#endif


void
ftps_register_module (void)
{
#ifdef USE_SSL
  ssl_register_module ();
#endif
}


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->get_next_file = ftps_get_next_file;
  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
}