Commit 4cd7f854 authored by James Housley's avatar James Housley
Browse files

Add two new options for the SFTP/SCP/FILE protocols: CURLOPT_NEW_FILE_PERMS

and CURLOPT_NEW_DIRECTORY_PERMS.  These control the premissions for files
and directories created on the remote server.  CURLOPT_NEW_FILE_PERMS
defaults to 0644 and CURLOPT_NEW_DIRECTORY_PERMS defaults to 0755
parent edd35cab
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -1401,6 +1401,17 @@ this curl handle use the data from the shared handle instead of keeping the
data to itself. This enables several curl handles to share data. If the curl
handles are used simultaneously, you \fBMUST\fP use the locking methods in the
share handle. See \fIcurl_share_setopt(3)\fP for details.
.IP CURLOPT_NEW_FILE_PERMS
Pass a long as a parameter, containing the value of the permissions that will
be assigned to newly created files on the remote server.  The default value is
\fI0644\fP, but any valid value can be used.  The only protocols that can use
this are \fIsftp://\fP, \fIscp://\fP and \fIfile://\fP. (Added in 7.16.4)
.IP CURLOPT_NEW_DIRECTORY_PERMS
Pass a long as a parameter, containing the value of the permissions that will
be assigned to newly created directories on the remote server.  The default
value is \fI0755\fP, but any valid value can be used.  The only protocols that
can use this are \fIsftp://\fP, \fIscp://\fP and \fIfile://\fP.
(Added in 7.16.4)
.SH TELNET OPTIONS
.IP CURLOPT_TELNETOPTIONS
Provide a pointer to a curl_slist with variables to pass to the telnet
+5 −0
Original line number Diff line number Diff line
@@ -1076,6 +1076,11 @@ typedef enum {
  CINIT(HTTP_TRANSFER_DECODING, LONG, 157),
  CINIT(HTTP_CONTENT_DECODING, LONG, 158),

  /* Permission used when creating new files and directories on the remote
     server for protocols that support it, SFTP/SCP/FILE */
  CINIT(NEW_FILE_PERMS, LONG, 159),
  CINIT(NEW_DIRECTORY_PERMS, LONG, 160),

  CURLOPT_LASTENTRY /* the last unused */
} CURLoption;

+2 −0
Original line number Diff line number Diff line
@@ -731,6 +731,8 @@ void curl_easy_reset(CURL *curl)

  data->set.ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth
                                                      type */
  data->set.new_file_perms = 0644;    /* Default permissions */
  data->set.new_directory_perms = 0755; /* Default permissions */
}

#ifdef CURL_DOES_CONVERSIONS
+16 −1
Original line number Diff line number Diff line
@@ -217,8 +217,23 @@ static CURLcode file_upload(struct connectdata *conn)

  if(data->reqdata.resume_from)
    fp = fopen( file->path, "ab" );
  else
  else {
    int fd;

#if defined(WIN32) || defined(MSDOS) || defined(__EMX__)
    fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,
              conn->data->set.new_file_perms);
#else /* !(WIN32 || MSDOS || __EMX__) */
    fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC,
              conn->data->set.new_file_perms);
#endif /* !(WIN32 || MSDOS || __EMX__) */
    if (fd < 0) {
      failf(data, "Can't open %s for writing", file->path);
      return CURLE_WRITE_ERROR;
    }
    close(fd);
    fp = fopen(file->path, "wb");
  }

  if(!fp) {
    failf(data, "Can't open %s for writing", file->path);
+10 −26
Original line number Diff line number Diff line
@@ -1137,10 +1137,7 @@ CURLcode Curl_scp_do(struct connectdata *conn, bool *done)
#if (LIBSSH2_APINO >= 200706012030)
    do {
      scp->ssh_channel = libssh2_scp_send_ex(scp->ssh_session, scp->path,
                                             LIBSSH2_SFTP_S_IRUSR|
                                             LIBSSH2_SFTP_S_IWUSR|
                                             LIBSSH2_SFTP_S_IRGRP|
                                             LIBSSH2_SFTP_S_IROTH,
                                             conn->data->set.new_file_perms,
                                             conn->data->set.infilesize, 0, 0);
      if (!scp->ssh_channel &&
          (libssh2_session_last_errno(scp->ssh_session) !=
@@ -1150,10 +1147,7 @@ CURLcode Curl_scp_do(struct connectdata *conn, bool *done)
    } while (!scp->ssh_channel);
#else /* !(LIBSSH2_APINO >= 200706012030) */
    scp->ssh_channel = libssh2_scp_send_ex(scp->ssh_session, scp->path,
                                           LIBSSH2_SFTP_S_IRUSR|
                                           LIBSSH2_SFTP_S_IWUSR|
                                           LIBSSH2_SFTP_S_IRGRP|
                                           LIBSSH2_SFTP_S_IROTH,
                                           conn->data->set.new_file_perms,
                                           conn->data->set.infilesize, 0, 0);
    if (!scp->ssh_channel)
      return CURLE_FAILED_INIT;
@@ -1363,8 +1357,7 @@ CURLcode Curl_sftp_do(struct connectdata *conn, bool *done)
      sftp->sftp_handle =
        libssh2_sftp_open(sftp->sftp_session, sftp->path,
                        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);
                        data->set.new_file_perms);
      if (!sftp->sftp_handle &&
          (libssh2_session_last_errno(sftp->ssh_session) !=
           LIBSSH2_ERROR_EAGAIN)) {
@@ -1381,8 +1374,7 @@ CURLcode Curl_sftp_do(struct connectdata *conn, bool *done)
              sftp->sftp_handle = libssh2_sftp_open(sftp->sftp_session,
                          sftp->path,
                          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);
                          data->set.new_file_perms);
              if (!sftp->sftp_handle &&
                  (libssh2_session_last_errno(sftp->ssh_session) !=
                   LIBSSH2_ERROR_EAGAIN)) {
@@ -1406,8 +1398,7 @@ CURLcode Curl_sftp_do(struct connectdata *conn, bool *done)
    sftp->sftp_handle =
      libssh2_sftp_open(sftp->sftp_session, sftp->path,
                        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);
                        data->set.new_file_perms);
    if (!sftp->sftp_handle) {
      err = libssh2_sftp_last_error(sftp->sftp_session);
      if (((err == LIBSSH2_FX_NO_SUCH_FILE) ||
@@ -1420,8 +1411,7 @@ CURLcode Curl_sftp_do(struct connectdata *conn, bool *done)
        if (res == 0) {
          sftp->sftp_handle = libssh2_sftp_open(sftp->sftp_session, sftp->path,
                    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);
                    data->set.new_file_perms);
        }
      }
      if (!sftp->sftp_handle) {
@@ -1636,8 +1626,7 @@ CURLcode Curl_sftp_do(struct connectdata *conn, bool *done)
      do {
        sftp->sftp_handle =
          libssh2_sftp_open(sftp->sftp_session, sftp->path, LIBSSH2_FXF_READ,
                          LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
                          LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
                          data->set.new_file_perms);
        if (!sftp->sftp_handle &&
            (libssh2_session_last_errno(sftp->ssh_session) !=
                                   LIBSSH2_ERROR_EAGAIN)) {
@@ -1650,8 +1639,7 @@ CURLcode Curl_sftp_do(struct connectdata *conn, bool *done)
#else /* !(LIBSSH2_APINO >= 200706012030) */
      sftp->sftp_handle =
        libssh2_sftp_open(sftp->sftp_session, sftp->path, LIBSSH2_FXF_READ,
                          LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
                          LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
                          data->set.new_file_perms);
      if (!sftp->sftp_handle) {
        err = libssh2_sftp_last_error(sftp->sftp_session);
        failf(conn->data, "Could not open remote file for reading: %s",
@@ -2304,15 +2292,11 @@ static CURLcode sftp_create_dirs(struct connectdata *conn) {
      /* 'mode' - parameter is preliminary - default to 0644 */
#if (LIBSSH2_APINO >= 200706012030)
      while ((rc = libssh2_sftp_mkdir(sftp->sftp_session, sftp->path,
                               LIBSSH2_SFTP_S_IRWXU |
                               LIBSSH2_SFTP_S_IRGRP | LIBSSH2_SFTP_S_IXGRP |
                               LIBSSH2_SFTP_S_IROTH | LIBSSH2_SFTP_S_IXOTH)) ==
                                      conn->data->set.new_directory_perms)) ==
             LIBSSH2_ERROR_EAGAIN);
#else /* !(LIBSSH2_APINO >= 200706012030) */
      rc = libssh2_sftp_mkdir(sftp->sftp_session, sftp->path,
                               LIBSSH2_SFTP_S_IRWXU |
                               LIBSSH2_SFTP_S_IRGRP | LIBSSH2_SFTP_S_IXGRP |
                               LIBSSH2_SFTP_S_IROTH | LIBSSH2_SFTP_S_IXOTH);
                               conn->data->set.new_directory_perms);
#endif /* !(LIBSSH2_APINO >= 200706012030) */
      *slash_pos = '/';
      ++slash_pos;
Loading