Bugzilla – Attachment 2212 Details for
Bug 2067
lsetstat extension to sftp-server
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for sftp-server to add lsetstat extension
lsetstat.patch (text/plain), 5.00 KB, created by
Bert Haverkamp
on 2013-02-02 00:16:28 AEDT
(
hide
)
Description:
Patch for sftp-server to add lsetstat extension
Filename:
MIME Type:
Creator:
Bert Haverkamp
Created:
2013-02-02 00:16:28 AEDT
Size:
5.00 KB
patch
obsolete
>diff -rupN openssh-5.8p1-orig/sftp-client.c openssh-5.8p1/sftp-client.c >--- openssh-5.8p1-orig/sftp-client.c 2012-04-23 19:49:21.000000000 +0200 >+++ openssh-5.8p1/sftp-client.c 2013-01-21 21:27:10.000000000 +0100 >@@ -76,6 +76,7 @@ struct sftp_conn { > #define SFTP_EXT_STATVFS 0x00000002 > #define SFTP_EXT_FSTATVFS 0x00000004 > #define SFTP_EXT_HARDLINK 0x00000008 >+#define SFTP_EXT_LSETSTAT 0x00000016 > u_int exts; > u_int64_t limit_kbps; > struct bwlimit bwlimit_in, bwlimit_out; >@@ -387,6 +387,10 @@ do_init(int fd_in, int fd_out, u_int tra > strcmp(value, "1") == 0) { > ret->exts |= SFTP_EXT_HARDLINK; > known = 1; >+ } else if (strcmp(name, "lsetstat@openssh.com") == 0 && >+ strcmp(value, "1") == 0) { >+ ret->exts |= SFTP_EXT_LSETSTAT; >+ known = 1; > } > if (known) { > debug2("Server supports extension \"%s\" revision %s", >@@ -833,6 +834,75 @@ do_hardlink(struct sftp_conn *conn, char > } > > int >+do_lsetstat(struct sftp_conn *conn, char *path, Attrib *a) >+{ >+ Buffer msg; >+ u_int status, id; >+ >+ buffer_init(&msg); >+ /* Send link request */ >+ id = conn->msg_id++; >+ if ((conn->exts & SFTP_EXT_HARDLINK) == 0) { >+ error("Server does not support hardlink@openssh.com extension"); >+ return -1; >+ } >+ >+ buffer_put_char(&msg, SSH2_FXP_EXTENDED); >+ buffer_put_int(&msg, id); >+ buffer_put_cstring(&msg, "lsetstat@openssh.com"); >+ buffer_put_cstring(&msg, path); >+ encode_attrib(&msg, a); >+ send_msg(conn, &msg); >+ debug3("Sent message lsetstat@openssh.com \"%s\"", >+ path); >+ buffer_free(&msg); >+ >+ status = get_status(conn, id); >+ if (status != SSH2_FX_OK) >+ error("Couldn't lsetstat file \"%s\": %s", >+ path, fx2txt(status)); >+ >+ return(status); >+} >+ >+int do_create(struct sftp_conn *conn, char *path, Attrib *a) >+{ >+ Buffer msg; >+ u_int status, id, handle_len; >+ char *handle; >+ >+ buffer_init(&msg); >+ >+ /* Send open request */ >+ id = conn->msg_id++; >+ buffer_put_char(&msg, SSH2_FXP_OPEN); >+ buffer_put_int(&msg, id); >+ buffer_put_cstring(&msg, path); >+ buffer_put_int(&msg, SSH2_FXF_CREAT); >+ encode_attrib(&msg, a); >+ send_msg(conn, &msg); >+ debug3("Sent message SSH2_FXP_OPEN I:%u P:%s", id, path); >+ >+ /* Get Handle */ >+ handle = get_handle(conn, id, &handle_len, >+ "remote open(\"%s\")", path); >+ if (handle == NULL) { >+ buffer_free(&msg); >+ return(-1); >+ } >+ >+ /* Send close request */ >+ status=do_close(conn, handle, handle_len); >+ buffer_free(&msg); >+ xfree(handle); >+ if (status != SSH2_FX_OK) >+ error("Couldn't create file \"%s\": %s", >+ path, fx2txt(status)); >+ >+ return status; >+} >+ >+int > do_symlink(struct sftp_conn *conn, char *oldpath, char *newpath) > { > Buffer msg; >diff -rupN openssh-5.8p1-orig/sftp-client.h openssh-5.8p1/sftp-client.h >--- openssh-5.8p1-orig/sftp-client.h 2012-04-23 19:49:21.000000000 +0200 >+++ openssh-5.8p1/sftp-client.h 2012-09-24 20:47:20.000000000 +0200 >@@ -85,6 +85,12 @@ int do_setstat(struct sftp_conn *, char > /* Set file attributes of open file 'handle' */ > int do_fsetstat(struct sftp_conn *, char *, u_int, Attrib *); > >+/* Set file attributes of 'path' to softlink */ >+int do_lsetstat(struct sftp_conn *, char *, Attrib *); >+ >+/* Open a file or create it */ >+int do_create(struct sftp_conn *conn, char *path, Attrib *a); >+ > /* Canonicalise 'path' - caller must free result */ > char *do_realpath(struct sftp_conn *, char *); > >diff -rupN openssh-5.8p1-orig/sftp-common.c openssh-5.8p1/sftp-common.c >diff -rupN openssh-5.8p1-orig/sftp-server.c openssh-5.8p1/sftp-server.c >--- openssh-5.8p1-orig/sftp-server.c 2012-04-23 19:49:21.000000000 +0200 >+++ openssh-5.8p1/sftp-server.c 2013-01-21 21:28:08.000000000 +0100 >@@ -538,6 +538,9 @@ process_init(void) > /* hardlink extension */ > buffer_put_cstring(&msg, "hardlink@openssh.com"); > buffer_put_cstring(&msg, "1"); /* version */ >+ /* lsetstat extension */ >+ buffer_put_cstring(&msg, "lsetstat@openssh.com"); >+ buffer_put_cstring(&msg, "1"); /* version */ > send_msg(&msg); > buffer_free(&msg); > } >@@ -1247,6 +1249,35 @@ process_extended_hardlink(u_int32_t id) > } > > static void >+process_extended_lsetstat(u_int32_t id) >+{ >+ Attrib *a; >+ char *name; >+ int status = SSH2_FX_OK, ret; >+ >+ name = get_string(NULL); >+ a = get_attrib(); >+ debug3("request %u: lsetstat name \"%s\"", id, name); >+ if (readonly) { >+ status = SSH2_FX_PERMISSION_DENIED; >+ a->flags = 0; >+ } >+ if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) { >+ char buf[64]; >+ time_t t = a->mtime; >+ >+ strftime(buf, sizeof(buf), "%Y%m%d-%H:%M:%S", >+ localtime(&t)); >+ logit("lset \"%s\" modtime %s", name, buf); >+ ret = lutimes(name, attrib_to_tv(a)); >+ if (ret == -1) >+ status = errno_to_portable(errno); >+ } >+ send_status(id, status); >+ xfree(name); >+} >+ >+static void > process_extended(void) > { > u_int32_t id; >@@ -1262,6 +1293,8 @@ process_extended(void) > process_extended_fstatvfs(id); > else if (strcmp(request, "hardlink@openssh.com") == 0) > process_extended_hardlink(id); >+ else if (strcmp(request, "lsetstat@openssh.com") == 0) >+ process_extended_lsetstat(id); > else > send_status(id, SSH2_FX_OP_UNSUPPORTED); /* MUST */ > xfree(request);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 2067
:
2212
|
2213
|
3219