]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
sftp: add new quote commands 'atime' and 'mtime'
authorCOFFEETALES <coffeetales.net@gmail.com>
Thu, 13 Aug 2020 23:38:49 +0000 (01:38 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 24 Aug 2020 07:01:56 +0000 (09:01 +0200)
Closes #5810

docs/cmdline-opts/quote.d
docs/libcurl/opts/CURLOPT_QUOTE.3
lib/vssh/libssh.c
lib/vssh/libssh2.c

index 59a98eafbc33503a725ba6577b603f030df0d3ea..3da34f48791cc170e1e9eec846fbeb905bf8fe13 100644 (file)
@@ -26,6 +26,10 @@ itself before sending them to the server.  File names may be quoted
 shell-style to embed spaces or special characters.  Following is the list of
 all supported SFTP quote commands:
 .RS
+.IP "atime date file"
+The atime command sets the last access time of the file named by the file
+operand. The <date expression> can be all sorts of date strings, see the
+\fIcurl_getdate(3)\fP man page for date expression details. (Added in 7.73.0)
 .IP "chgrp group file"
 The chgrp command sets the group ID of the file named by the file operand to
 the group ID specified by the group operand. The group operand is a decimal
@@ -42,6 +46,10 @@ The ln and symlink commands create a symbolic link at the target_file location
 pointing to the source_file location.
 .IP "mkdir directory_name"
 The mkdir command creates the directory named by the directory_name operand.
+.IP "mtime date file"
+The mtime command sets the last modification time of the file named by the
+file operand. The <date expression> can be all sorts of date strings, see the
+\fIcurl_getdate(3)\fP man page for date expression details. (Added in 7.73.0)
 .IP "pwd"
 The pwd command returns the absolute pathname of the current working directory.
 .IP "rename source target"
index 08a342facaabf60bdcf157c91e373e88eec0ce17..408d07d51c63f0c55d424b2fe768e8ac7267bc22 100644 (file)
@@ -43,6 +43,10 @@ mandatory commands).
 
 The valid SFTP commands are:
 .RS
+.IP "atime date file"
+The atime command sets the last access time of the file named by the file
+operand. The <date expression> can be all sorts of date strings, see the
+\fIcurl_getdate(3)\fP man page for date expression details. (Added in 7.73.0)
 .IP "chgrp group file"
 The chgrp command sets the group ID of the file named by the file operand to
 the group ID specified by the group operand. The group operand is a decimal
@@ -59,6 +63,10 @@ The ln and symlink commands create a symbolic link at the target_file location
 pointing to the source_file location.
 .IP "mkdir directory_name"
 The mkdir command creates the directory named by the directory_name operand.
+.IP "mtime date file"
+The mtime command sets the last modification time of the file named by the
+file operand. The <date expression> can be all sorts of date strings, see the
+\fIcurl_getdate(3)\fP man page for date expression details. (Added in 7.73.0)
 .IP "pwd"
 The pwd command returns the absolute pathname of the current working directory.
 .IP "rename source target"
index 8988e2392d589afbc200af8ed28fbf565f7a72d3..8d1cfd0f132e4c19c5affce4b82881eaf26908a2 100644 (file)
@@ -2692,7 +2692,9 @@ static void sftp_quote(struct connectdata *conn)
    */
   if(strncasecompare(cmd, "chgrp ", 6) ||
      strncasecompare(cmd, "chmod ", 6) ||
-     strncasecompare(cmd, "chown ", 6)) {
+     strncasecompare(cmd, "chown ", 6) ||
+     strncasecompare(cmd, "atime ", 6) ||
+     strncasecompare(cmd, "mtime ", 6)) {
     /* attribute change */
 
     /* sshc->quote_path1 contains the mode to set */
@@ -2702,7 +2704,7 @@ static void sftp_quote(struct connectdata *conn)
       if(result == CURLE_OUT_OF_MEMORY)
         failf(data, "Out of memory");
       else
-        failf(data, "Syntax error in chgrp/chmod/chown: "
+        failf(data, "Syntax error in chgrp/chmod/chown/atime/mtime: "
               "Bad second parameter");
       Curl_safefree(sshc->quote_path1);
       state(conn, SSH_SFTP_CLOSE);
@@ -2863,6 +2865,34 @@ static void sftp_quote_stat(struct connectdata *conn)
     }
     sshc->quote_attrs->flags |= SSH_FILEXFER_ATTR_UIDGID;
   }
+  else if(strncasecompare(cmd, "atime", 5)) {
+    time_t date = Curl_getdate_capped(sshc->quote_path1);
+    if(date == -1) {
+      Curl_safefree(sshc->quote_path1);
+      Curl_safefree(sshc->quote_path2);
+      failf(data, "Syntax error: incorrect access date format");
+      state(conn, SSH_SFTP_CLOSE);
+      sshc->nextstate = SSH_NO_STATE;
+      sshc->actualcode = CURLE_QUOTE_ERROR;
+      return;
+    }
+    sshc->quote_attrs->atime = (uint32_t)date;
+    sshc->quote_attrs->flags |= SSH_FILEXFER_ATTR_ACMODTIME;
+  }
+  else if(strncasecompare(cmd, "mtime", 5)) {
+    time_t date = Curl_getdate_capped(sshc->quote_path1);
+    if(date == -1) {
+      Curl_safefree(sshc->quote_path1);
+      Curl_safefree(sshc->quote_path2);
+      failf(data, "Syntax error: incorrect modification date format");
+      state(conn, SSH_SFTP_CLOSE);
+      sshc->nextstate = SSH_NO_STATE;
+      sshc->actualcode = CURLE_QUOTE_ERROR;
+      return;
+    }
+    sshc->quote_attrs->mtime = (uint32_t)date;
+    sshc->quote_attrs->flags |= SSH_FILEXFER_ATTR_ACMODTIME;
+  }
 
   /* Now send the completed structure... */
   state(conn, SSH_SFTP_QUOTE_SETSTAT);
index 4f56bb44ce7fd9a931b37be4f6822b1459377499..dc4db6f2ee3b23337a955efd16bba9bf9ffb8fdd 100644 (file)
@@ -1390,7 +1390,9 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
          */
         if(strncasecompare(cmd, "chgrp ", 6) ||
            strncasecompare(cmd, "chmod ", 6) ||
-           strncasecompare(cmd, "chown ", 6) ) {
+           strncasecompare(cmd, "chown ", 6) ||
+           strncasecompare(cmd, "atime ", 6) ||
+           strncasecompare(cmd, "mtime ", 6)) {
           /* attribute change */
 
           /* sshc->quote_path1 contains the mode to set */
@@ -1587,6 +1589,34 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
           break;
         }
       }
+      else if(strncasecompare(cmd, "atime", 5)) {
+        time_t date = Curl_getdate_capped(sshc->quote_path1);
+        if(date == -1) {
+          Curl_safefree(sshc->quote_path1);
+          Curl_safefree(sshc->quote_path2);
+          failf(data, "Syntax error: incorrect access date format");
+          state(conn, SSH_SFTP_CLOSE);
+          sshc->nextstate = SSH_NO_STATE;
+          sshc->actualcode = CURLE_QUOTE_ERROR;
+          break;
+        }
+        sshc->quote_attrs.atime = (unsigned long)date;
+        sshc->quote_attrs.flags = LIBSSH2_SFTP_ATTR_ACMODTIME;
+      }
+      else if(strncasecompare(cmd, "mtime", 5)) {
+        time_t date = Curl_getdate_capped(sshc->quote_path1);
+        if(date == -1) {
+          Curl_safefree(sshc->quote_path1);
+          Curl_safefree(sshc->quote_path2);
+          failf(data, "Syntax error: incorrect modification date format");
+          state(conn, SSH_SFTP_CLOSE);
+          sshc->nextstate = SSH_NO_STATE;
+          sshc->actualcode = CURLE_QUOTE_ERROR;
+          break;
+        }
+        sshc->quote_attrs.mtime = (unsigned long)date;
+        sshc->quote_attrs.flags = LIBSSH2_SFTP_ATTR_ACMODTIME;
+      }
 
       /* Now send the completed structure... */
       state(conn, SSH_SFTP_QUOTE_SETSTAT);