cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: Reflection for Secure IT Server

From: Xu, Qiang (FXSGSC) <Qiang.Xu_at_fujixerox.com>
Date: Tue, 4 May 2010 16:42:40 +0800

> -----Original Message-----
> From: curl-library-bounces_at_cool.haxx.se
> [mailto:curl-library-bounces_at_cool.haxx.se] On Behalf Of
> Daniel Stenberg
> Sent: Monday, May 03, 2010 8:04 PM
> To: libcurl development
> Subject: RE: Reflection for Secure IT Server
>
> I would think you need to instrument how lissh2_sftp_write()
> that libcurl uses acts, and what libcurl then does after the
> working ones etc. Possibly in combination with enabling
> libssh2 debug tracing.

Found that in libssh2-1.2.5/example/sftp_write.c, the flow is very simple, with libssh2_sftp_init(), libssh2_sftp_open followed by libssh2_sftp_write(). While in curl-7.20.1/lib/ssh.c, some socket operations are also involved between libssh2_sftp_open() and libssh2_sftp_write().
=============================================
/* libssh2-1.2.5/example/sftp_write.c */
    sftp_session = libssh2_sftp_init(session);
    ...
    sftp_handle =
        libssh2_sftp_open(sftp_session, sftppath,
                      LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
                      LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
                      LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
    ...
    do {
        nread = fread(mem, 1, sizeof(mem), local);
        if (nread <= 0) {
            /* end of file */
            break;
        }
        ptr = mem;

        do {
            /* write data in a loop until we block */
            rc = libssh2_sftp_write(sftp_handle, ptr, nread);
            ptr += rc;
            nread -= nread;
        } while (rc > 0);
    } while (1);

/* curl-7.20.1/lib/ssh.c */
static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
{
  ...
    case SSH_SFTP_UPLOAD_INIT:
    {
  ...
      sshc->sftp_handle =
        libssh2_sftp_open_ex(sshc->sftp_session, sftp_scp->path,
                             (unsigned int)strlen(sftp_scp->path),
                             flags, data->set.new_file_perms,
                             LIBSSH2_SFTP_OPENFILE);
      /* upload data */
      result = Curl_setup_transfer(conn, -1, -1, FALSE, NULL,
                                   FIRSTSOCKET, NULL);

      /* not set by Curl_setup_transfer to preserve keepon bits */
      conn->sockfd = conn->writesockfd;
  ...
}
=============================================
From Curl_setup_transfer(), the socket stuff comes into play. I am not sure whether this is the cause of libssh2_sftp_write() returning LIBSSH2_ERROR_SOCKET_SEND later. Since socket is not needed in sftp_write.c, why introduce it into libcurl in handling sftp upload?

Confused...
Xu Qiang
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-05-04