зеркало из https://github.com/Azure/sonic-openssh.git
upstream commit
update sftp client and server to new buffer API. pretty much just mechanical changes; with & ok markus
This commit is contained in:
Родитель
139ca81866
Коммит
7d845f4a0b
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: progressmeter.c,v 1.40 2013/09/19 00:24:52 djm Exp $ */
|
/* $OpenBSD: progressmeter.c,v 1.41 2015/01/14 13:54:13 djm Exp $ */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2003 Nils Nordman. All rights reserved.
|
* Copyright (c) 2003 Nils Nordman. All rights reserved.
|
||||||
*
|
*
|
||||||
|
@ -65,7 +65,7 @@ static void update_progress_meter(int);
|
||||||
|
|
||||||
static time_t start; /* start progress */
|
static time_t start; /* start progress */
|
||||||
static time_t last_update; /* last progress update */
|
static time_t last_update; /* last progress update */
|
||||||
static char *file; /* name of the file being transferred */
|
static const char *file; /* name of the file being transferred */
|
||||||
static off_t start_pos; /* initial position of transfer */
|
static off_t start_pos; /* initial position of transfer */
|
||||||
static off_t end_pos; /* ending position of transfer */
|
static off_t end_pos; /* ending position of transfer */
|
||||||
static off_t cur_pos; /* transfer position as of last refresh */
|
static off_t cur_pos; /* transfer position as of last refresh */
|
||||||
|
@ -248,7 +248,7 @@ update_progress_meter(int ignore)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
start_progress_meter(char *f, off_t filesize, off_t *ctr)
|
start_progress_meter(const char *f, off_t filesize, off_t *ctr)
|
||||||
{
|
{
|
||||||
start = last_update = monotime();
|
start = last_update = monotime();
|
||||||
file = f;
|
file = f;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: progressmeter.h,v 1.2 2006/03/25 22:22:43 djm Exp $ */
|
/* $OpenBSD: progressmeter.h,v 1.3 2015/01/14 13:54:13 djm Exp $ */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2002 Nils Nordman. All rights reserved.
|
* Copyright (c) 2002 Nils Nordman. All rights reserved.
|
||||||
*
|
*
|
||||||
|
@ -23,5 +23,5 @@
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void start_progress_meter(char *, off_t, off_t *);
|
void start_progress_meter(const char *, off_t, off_t *);
|
||||||
void stop_progress_meter(void);
|
void stop_progress_meter(void);
|
||||||
|
|
853
sftp-client.c
853
sftp-client.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: sftp-client.h,v 1.25 2014/04/21 14:36:16 logan Exp $ */
|
/* $OpenBSD: sftp-client.h,v 1.26 2015/01/14 13:54:13 djm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
|
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
|
||||||
|
@ -56,79 +56,81 @@ struct sftp_conn *do_init(int, int, u_int, u_int, u_int64_t);
|
||||||
u_int sftp_proto_version(struct sftp_conn *);
|
u_int sftp_proto_version(struct sftp_conn *);
|
||||||
|
|
||||||
/* Close file referred to by 'handle' */
|
/* Close file referred to by 'handle' */
|
||||||
int do_close(struct sftp_conn *, char *, u_int);
|
int do_close(struct sftp_conn *, const u_char *, u_int);
|
||||||
|
|
||||||
/* Read contents of 'path' to NULL-terminated array 'dir' */
|
/* Read contents of 'path' to NULL-terminated array 'dir' */
|
||||||
int do_readdir(struct sftp_conn *, char *, SFTP_DIRENT ***);
|
int do_readdir(struct sftp_conn *, const char *, SFTP_DIRENT ***);
|
||||||
|
|
||||||
/* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */
|
/* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */
|
||||||
void free_sftp_dirents(SFTP_DIRENT **);
|
void free_sftp_dirents(SFTP_DIRENT **);
|
||||||
|
|
||||||
/* Delete file 'path' */
|
/* Delete file 'path' */
|
||||||
int do_rm(struct sftp_conn *, char *);
|
int do_rm(struct sftp_conn *, const char *);
|
||||||
|
|
||||||
/* Create directory 'path' */
|
/* Create directory 'path' */
|
||||||
int do_mkdir(struct sftp_conn *, char *, Attrib *, int);
|
int do_mkdir(struct sftp_conn *, const char *, Attrib *, int);
|
||||||
|
|
||||||
/* Remove directory 'path' */
|
/* Remove directory 'path' */
|
||||||
int do_rmdir(struct sftp_conn *, char *);
|
int do_rmdir(struct sftp_conn *, const char *);
|
||||||
|
|
||||||
/* Get file attributes of 'path' (follows symlinks) */
|
/* Get file attributes of 'path' (follows symlinks) */
|
||||||
Attrib *do_stat(struct sftp_conn *, char *, int);
|
Attrib *do_stat(struct sftp_conn *, const char *, int);
|
||||||
|
|
||||||
/* Get file attributes of 'path' (does not follow symlinks) */
|
/* Get file attributes of 'path' (does not follow symlinks) */
|
||||||
Attrib *do_lstat(struct sftp_conn *, char *, int);
|
Attrib *do_lstat(struct sftp_conn *, const char *, int);
|
||||||
|
|
||||||
/* Set file attributes of 'path' */
|
/* Set file attributes of 'path' */
|
||||||
int do_setstat(struct sftp_conn *, char *, Attrib *);
|
int do_setstat(struct sftp_conn *, const char *, Attrib *);
|
||||||
|
|
||||||
/* Set file attributes of open file 'handle' */
|
/* Set file attributes of open file 'handle' */
|
||||||
int do_fsetstat(struct sftp_conn *, char *, u_int, Attrib *);
|
int do_fsetstat(struct sftp_conn *, const u_char *, u_int, Attrib *);
|
||||||
|
|
||||||
/* Canonicalise 'path' - caller must free result */
|
/* Canonicalise 'path' - caller must free result */
|
||||||
char *do_realpath(struct sftp_conn *, char *);
|
char *do_realpath(struct sftp_conn *, const char *);
|
||||||
|
|
||||||
/* Get statistics for filesystem hosting file at "path" */
|
/* Get statistics for filesystem hosting file at "path" */
|
||||||
int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int);
|
int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int);
|
||||||
|
|
||||||
/* Rename 'oldpath' to 'newpath' */
|
/* Rename 'oldpath' to 'newpath' */
|
||||||
int do_rename(struct sftp_conn *, char *, char *m, int force_legacy);
|
int do_rename(struct sftp_conn *, const char *, const char *, int force_legacy);
|
||||||
|
|
||||||
/* Link 'oldpath' to 'newpath' */
|
/* Link 'oldpath' to 'newpath' */
|
||||||
int do_hardlink(struct sftp_conn *, char *, char *);
|
int do_hardlink(struct sftp_conn *, const char *, const char *);
|
||||||
|
|
||||||
/* Rename 'oldpath' to 'newpath' */
|
/* Rename 'oldpath' to 'newpath' */
|
||||||
int do_symlink(struct sftp_conn *, char *, char *);
|
int do_symlink(struct sftp_conn *, const char *, const char *);
|
||||||
|
|
||||||
/* Call fsync() on open file 'handle' */
|
/* Call fsync() on open file 'handle' */
|
||||||
int do_fsync(struct sftp_conn *conn, char *, u_int);
|
int do_fsync(struct sftp_conn *conn, u_char *, u_int);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Download 'remote_path' to 'local_path'. Preserve permissions and times
|
* Download 'remote_path' to 'local_path'. Preserve permissions and times
|
||||||
* if 'pflag' is set
|
* if 'pflag' is set
|
||||||
*/
|
*/
|
||||||
int do_download(struct sftp_conn *, char *, char *, Attrib *, int, int, int);
|
int do_download(struct sftp_conn *, const char *, const char *,
|
||||||
|
Attrib *, int, int, int);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Recursively download 'remote_directory' to 'local_directory'. Preserve
|
* Recursively download 'remote_directory' to 'local_directory'. Preserve
|
||||||
* times if 'pflag' is set
|
* times if 'pflag' is set
|
||||||
*/
|
*/
|
||||||
int download_dir(struct sftp_conn *, char *, char *, Attrib *, int,
|
int download_dir(struct sftp_conn *, const char *, const char *,
|
||||||
int, int, int);
|
Attrib *, int, int, int, int);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Upload 'local_path' to 'remote_path'. Preserve permissions and times
|
* Upload 'local_path' to 'remote_path'. Preserve permissions and times
|
||||||
* if 'pflag' is set
|
* if 'pflag' is set
|
||||||
*/
|
*/
|
||||||
int do_upload(struct sftp_conn *, char *, char *, int, int, int);
|
int do_upload(struct sftp_conn *, const char *, const char *, int, int, int);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Recursively upload 'local_directory' to 'remote_directory'. Preserve
|
* Recursively upload 'local_directory' to 'remote_directory'. Preserve
|
||||||
* times if 'pflag' is set
|
* times if 'pflag' is set
|
||||||
*/
|
*/
|
||||||
int upload_dir(struct sftp_conn *, char *, char *, int, int, int, int);
|
int upload_dir(struct sftp_conn *, const char *, const char *, int, int, int,
|
||||||
|
int);
|
||||||
|
|
||||||
/* Concatenate paths, taking care of slashes. Caller must free result. */
|
/* Concatenate paths, taking care of slashes. Caller must free result. */
|
||||||
char *path_append(char *, char *);
|
char *path_append(const char *, const char *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: sftp-common.c,v 1.26 2014/01/09 03:26:00 guenther Exp $ */
|
/* $OpenBSD: sftp-common.c,v 1.27 2015/01/14 13:54:13 djm Exp $ */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001 Markus Friedl. All rights reserved.
|
* Copyright (c) 2001 Markus Friedl. All rights reserved.
|
||||||
* Copyright (c) 2001 Damien Miller. All rights reserved.
|
* Copyright (c) 2001 Damien Miller. All rights reserved.
|
||||||
|
@ -42,7 +42,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
#include "buffer.h"
|
#include "ssherr.h"
|
||||||
|
#include "sshbuf.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#include "sftp.h"
|
#include "sftp.h"
|
||||||
|
@ -100,59 +101,81 @@ attrib_to_stat(const Attrib *a, struct stat *st)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Decode attributes in buffer */
|
/* Decode attributes in buffer */
|
||||||
Attrib *
|
int
|
||||||
decode_attrib(Buffer *b)
|
decode_attrib(struct sshbuf *b, Attrib *a)
|
||||||
{
|
{
|
||||||
static Attrib a;
|
int r;
|
||||||
|
|
||||||
attrib_clear(&a);
|
attrib_clear(a);
|
||||||
a.flags = buffer_get_int(b);
|
if ((r = sshbuf_get_u32(b, &a->flags)) != 0)
|
||||||
if (a.flags & SSH2_FILEXFER_ATTR_SIZE)
|
return r;
|
||||||
a.size = buffer_get_int64(b);
|
if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {
|
||||||
if (a.flags & SSH2_FILEXFER_ATTR_UIDGID) {
|
if ((r = sshbuf_get_u64(b, &a->size)) != 0)
|
||||||
a.uid = buffer_get_int(b);
|
return r;
|
||||||
a.gid = buffer_get_int(b);
|
|
||||||
}
|
}
|
||||||
if (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS)
|
if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) {
|
||||||
a.perm = buffer_get_int(b);
|
if ((r = sshbuf_get_u32(b, &a->uid)) != 0 ||
|
||||||
if (a.flags & SSH2_FILEXFER_ATTR_ACMODTIME) {
|
(r = sshbuf_get_u32(b, &a->gid)) != 0)
|
||||||
a.atime = buffer_get_int(b);
|
return r;
|
||||||
a.mtime = buffer_get_int(b);
|
}
|
||||||
|
if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) {
|
||||||
|
if ((r = sshbuf_get_u32(b, &a->perm)) != 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) {
|
||||||
|
if ((r = sshbuf_get_u32(b, &a->atime)) != 0 ||
|
||||||
|
(r = sshbuf_get_u32(b, &a->mtime)) != 0)
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
/* vendor-specific extensions */
|
/* vendor-specific extensions */
|
||||||
if (a.flags & SSH2_FILEXFER_ATTR_EXTENDED) {
|
if (a->flags & SSH2_FILEXFER_ATTR_EXTENDED) {
|
||||||
char *type, *data;
|
char *type;
|
||||||
int i, count;
|
u_char *data;
|
||||||
|
size_t dlen;
|
||||||
|
u_int i, count;
|
||||||
|
|
||||||
count = buffer_get_int(b);
|
if ((r = sshbuf_get_u32(b, &count)) != 0)
|
||||||
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
type = buffer_get_string(b, NULL);
|
if ((r = sshbuf_get_cstring(b, &type, NULL)) != 0 ||
|
||||||
data = buffer_get_string(b, NULL);
|
(r = sshbuf_get_string(b, &data, &dlen)) != 0)
|
||||||
debug3("Got file attribute \"%s\"", type);
|
return r;
|
||||||
|
debug3("Got file attribute \"%.100s\" len %zu",
|
||||||
|
type, dlen);
|
||||||
free(type);
|
free(type);
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &a;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Encode attributes to buffer */
|
/* Encode attributes to buffer */
|
||||||
void
|
int
|
||||||
encode_attrib(Buffer *b, const Attrib *a)
|
encode_attrib(struct sshbuf *b, const Attrib *a)
|
||||||
{
|
{
|
||||||
buffer_put_int(b, a->flags);
|
int r;
|
||||||
if (a->flags & SSH2_FILEXFER_ATTR_SIZE)
|
|
||||||
buffer_put_int64(b, a->size);
|
if ((r = sshbuf_put_u32(b, a->flags)) != 0)
|
||||||
|
return r;
|
||||||
|
if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {
|
||||||
|
if ((r = sshbuf_put_u64(b, a->size)) != 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) {
|
if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) {
|
||||||
buffer_put_int(b, a->uid);
|
if ((r = sshbuf_put_u32(b, a->uid)) != 0 ||
|
||||||
buffer_put_int(b, a->gid);
|
(r = sshbuf_put_u32(b, a->gid)) != 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) {
|
||||||
|
if ((r = sshbuf_put_u32(b, a->perm)) != 0)
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)
|
|
||||||
buffer_put_int(b, a->perm);
|
|
||||||
if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) {
|
if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) {
|
||||||
buffer_put_int(b, a->atime);
|
if ((r = sshbuf_put_u32(b, a->atime)) != 0 ||
|
||||||
buffer_put_int(b, a->mtime);
|
(r = sshbuf_put_u32(b, a->mtime)) != 0)
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert from SSH2_FX_ status to text error message */
|
/* Convert from SSH2_FX_ status to text error message */
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: sftp-common.h,v 1.11 2010/01/13 01:40:16 djm Exp $ */
|
/* $OpenBSD: sftp-common.h,v 1.12 2015/01/14 13:54:13 djm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001 Markus Friedl. All rights reserved.
|
* Copyright (c) 2001 Markus Friedl. All rights reserved.
|
||||||
|
@ -28,6 +28,7 @@
|
||||||
/* Maximum packet that we are willing to send/accept */
|
/* Maximum packet that we are willing to send/accept */
|
||||||
#define SFTP_MAX_MSG_LENGTH (256 * 1024)
|
#define SFTP_MAX_MSG_LENGTH (256 * 1024)
|
||||||
|
|
||||||
|
struct sshbuf;
|
||||||
typedef struct Attrib Attrib;
|
typedef struct Attrib Attrib;
|
||||||
|
|
||||||
/* File attributes */
|
/* File attributes */
|
||||||
|
@ -44,8 +45,8 @@ struct Attrib {
|
||||||
void attrib_clear(Attrib *);
|
void attrib_clear(Attrib *);
|
||||||
void stat_to_attrib(const struct stat *, Attrib *);
|
void stat_to_attrib(const struct stat *, Attrib *);
|
||||||
void attrib_to_stat(const Attrib *, struct stat *);
|
void attrib_to_stat(const Attrib *, struct stat *);
|
||||||
Attrib *decode_attrib(Buffer *);
|
int decode_attrib(struct sshbuf *, Attrib *);
|
||||||
void encode_attrib(Buffer *, const Attrib *);
|
int encode_attrib(struct sshbuf *, const Attrib *);
|
||||||
char *ls_file(const char *, const struct stat *, int, int);
|
char *ls_file(const char *, const struct stat *, int, int);
|
||||||
|
|
||||||
const char *fx2txt(int);
|
const char *fx2txt(int);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: sftp-glob.c,v 1.26 2013/11/08 11:15:19 dtucker Exp $ */
|
/* $OpenBSD: sftp-glob.c,v 1.27 2015/01/14 13:54:13 djm Exp $ */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
|
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
|
||||||
*
|
*
|
||||||
|
@ -25,10 +25,10 @@
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
#include "sftp.h"
|
#include "sftp.h"
|
||||||
#include "buffer.h"
|
|
||||||
#include "sftp-common.h"
|
#include "sftp-common.h"
|
||||||
#include "sftp-client.h"
|
#include "sftp-client.h"
|
||||||
|
|
||||||
|
|
606
sftp-server.c
606
sftp-server.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
5
sftp.c
5
sftp.c
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: sftp.c,v 1.168 2014/11/26 18:34:51 millert Exp $ */
|
/* $OpenBSD: sftp.c,v 1.169 2015/01/14 13:54:13 djm Exp $ */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
|
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
|
||||||
*
|
*
|
||||||
|
@ -63,7 +63,8 @@ typedef void EditLine;
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
#include "sftp.h"
|
#include "sftp.h"
|
||||||
#include "buffer.h"
|
#include "ssherr.h"
|
||||||
|
#include "sshbuf.h"
|
||||||
#include "sftp-common.h"
|
#include "sftp-common.h"
|
||||||
#include "sftp-client.h"
|
#include "sftp-client.h"
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче