From 8e879cf6918efbf40984bbfb6db0deecc26881f5 Mon Sep 17 00:00:00 2001 From: Ben Lindstrom Date: Sat, 9 Nov 2002 15:48:49 +0000 Subject: - markus@cvs.openbsd.org 2002/11/05 20:10:37 [sftp-client.c] typo; GaryF@livevault.com --- sftp-client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sftp-client.c') diff --git a/sftp-client.c b/sftp-client.c index f6a73f379..30bef8936 100644 --- a/sftp-client.c +++ b/sftp-client.c @@ -28,7 +28,7 @@ /* XXX: copy between two remote sites */ #include "includes.h" -RCSID("$OpenBSD: sftp-client.c,v 1.35 2002/09/11 22:41:49 djm Exp $"); +RCSID("$OpenBSD: sftp-client.c,v 1.36 2002/11/05 20:10:37 markus Exp $"); #include "openbsd-compat/sys-queue.h" @@ -660,7 +660,7 @@ do_symlink(struct sftp_conn *conn, char *oldpath, char *newpath) status = get_status(conn->fd_in, id); if (status != SSH2_FX_OK) - error("Couldn't rename file \"%s\" to \"%s\": %s", oldpath, + error("Couldn't symlink file \"%s\" to \"%s\": %s", oldpath, newpath, fx2txt(status)); return(status); -- cgit v1.2.3 From 93576d9538f3b6d373248ffd2ed5ab9852a1555c Mon Sep 17 00:00:00 2001 From: Ben Lindstrom Date: Mon, 23 Dec 2002 02:06:19 +0000 Subject: - deraadt@cvs.openbsd.org 2002/11/21 23:03:51 [auth-krb5.c auth1.c hostfile.h monitor_wrap.c sftp-client.c sftp-int.c ssh-add.c ssh-rsa.c sshconnect.c] KNF --- ChangeLog | 6 +++++- auth-krb5.c | 4 ++-- auth1.c | 4 ++-- hostfile.h | 12 ++++++------ monitor_wrap.c | 4 ++-- sftp-client.c | 14 +++++++------- sftp-int.c | 28 ++++++++++++++-------------- ssh-add.c | 4 ++-- ssh-rsa.c | 4 ++-- sshconnect.c | 10 +++++----- 10 files changed, 47 insertions(+), 43 deletions(-) (limited to 'sftp-client.c') diff --git a/ChangeLog b/ChangeLog index 514d8ab50..e41fef034 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,10 @@ - markus@cvs.openbsd.org 2002/11/21 22:45:31 [cipher.c kex.c packet.c sshconnect.c sshconnect2.c] debug->debug2, unify debug messages + - deraadt@cvs.openbsd.org 2002/11/21 23:03:51 + [auth-krb5.c auth1.c hostfile.h monitor_wrap.c sftp-client.c sftp-int.c ssh-add.c ssh-rsa.c + sshconnect.c] + KNF 20021205 - (djm) PERL-free fixpaths from stuge-openssh-unix-dev@cdy.org @@ -851,4 +855,4 @@ save auth method before monitor_reset_key_state(); bugzilla bug #284; ok provos@ -$Id: ChangeLog,v 1.2519 2002/12/23 02:04:22 mouring Exp $ +$Id: ChangeLog,v 1.2520 2002/12/23 02:06:19 mouring Exp $ diff --git a/auth-krb5.c b/auth-krb5.c index 512f70b78..e3e2d9751 100644 --- a/auth-krb5.c +++ b/auth-krb5.c @@ -28,7 +28,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: auth-krb5.c,v 1.9 2002/09/09 06:48:06 itojun Exp $"); +RCSID("$OpenBSD: auth-krb5.c,v 1.10 2002/11/21 23:03:51 deraadt Exp $"); #include "ssh.h" #include "ssh1.h" @@ -107,7 +107,7 @@ auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client, krb5_data *reply) if (problem) goto err; - problem = krb5_sname_to_principal(authctxt->krb5_ctx, NULL, NULL , + problem = krb5_sname_to_principal(authctxt->krb5_ctx, NULL, NULL, KRB5_NT_SRV_HST, &server); if (problem) goto err; diff --git a/auth1.c b/auth1.c index 9527ba004..1af30e0ec 100644 --- a/auth1.c +++ b/auth1.c @@ -10,7 +10,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: auth1.c,v 1.44 2002/09/26 11:38:43 markus Exp $"); +RCSID("$OpenBSD: auth1.c,v 1.45 2002/11/21 23:03:51 deraadt Exp $"); #include "xmalloc.h" #include "rsa.h" @@ -150,7 +150,7 @@ do_authloop(Authctxt *authctxt) snprintf(info, sizeof(info), " tktuser %.100s", client_user); - + /* Send response to client */ packet_start( SSH_SMSG_AUTH_KERBEROS_RESPONSE); diff --git a/hostfile.h b/hostfile.h index 1df7a22f2..e3d116581 100644 --- a/hostfile.h +++ b/hostfile.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hostfile.h,v 1.12 2002/09/08 20:24:08 markus Exp $ */ +/* $OpenBSD: hostfile.h,v 1.13 2002/11/21 23:03:51 deraadt Exp $ */ /* * Author: Tatu Ylonen @@ -19,10 +19,10 @@ typedef enum { } HostStatus; int hostfile_read_key(char **, u_int *, Key *); -HostStatus -check_host_in_hostfile(const char *, const char *, Key *, Key *, int *); -int add_host_to_hostfile(const char *, const char *, Key *); -int -lookup_key_in_hostfile_by_type(const char *, const char *, int , Key *, int *); +HostStatus check_host_in_hostfile(const char *, const char *, + Key *, Key *, int *); +int add_host_to_hostfile(const char *, const char *, Key *); +int lookup_key_in_hostfile_by_type(const char *, const char *, + int, Key *, int *); #endif diff --git a/monitor_wrap.c b/monitor_wrap.c index 4c53bfd13..b75f9dfc7 100644 --- a/monitor_wrap.c +++ b/monitor_wrap.c @@ -25,7 +25,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: monitor_wrap.c,v 1.19 2002/09/26 11:38:43 markus Exp $"); +RCSID("$OpenBSD: monitor_wrap.c,v 1.20 2002/11/21 23:03:51 deraadt Exp $"); #include #include @@ -969,7 +969,7 @@ mm_auth_krb4(Authctxt *authctxt, void *_auth, char **client, void *_reply) xfree(p); } buffer_free(&m); - return (success); + return (success); } #endif diff --git a/sftp-client.c b/sftp-client.c index 30bef8936..df9838648 100644 --- a/sftp-client.c +++ b/sftp-client.c @@ -28,7 +28,7 @@ /* XXX: copy between two remote sites */ #include "includes.h" -RCSID("$OpenBSD: sftp-client.c,v 1.36 2002/11/05 20:10:37 markus Exp $"); +RCSID("$OpenBSD: sftp-client.c,v 1.37 2002/11/21 23:03:51 deraadt Exp $"); #include "openbsd-compat/sys-queue.h" @@ -857,9 +857,9 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path, (unsigned long long)req->offset + len - 1); if (len > req->len) fatal("Received more data than asked for " - "%u > %u", len, req->len); + "%u > %u", len, req->len); if ((lseek(local_fd, req->offset, SEEK_SET) == -1 || - atomicio(write, local_fd, data, len) != len) && + atomicio(write, local_fd, data, len) != len) && !write_error) { write_errno = errno; write_error = 1; @@ -930,7 +930,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path, if (pflag && chmod(local_path, mode) == -1) #endif /* HAVE_FCHMOD */ error("Couldn't set mode on \"%s\": %s", local_path, - strerror(errno)); + strerror(errno)); if (pflag && (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME)) { struct timeval tv[2]; tv[0].tv_sec = a->atime; @@ -938,7 +938,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path, tv[0].tv_usec = tv[1].tv_usec = 0; if (utimes(local_path, tv) == -1) error("Can't set times on \"%s\": %s", - local_path, strerror(errno)); + local_path, strerror(errno)); } } close(local_fd); @@ -1047,7 +1047,7 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path, buffer_put_string(&msg, data, len); send_msg(conn->fd_out, &msg); debug3("Sent message SSH2_FXP_WRITE I:%u O:%llu S:%u", - id, (unsigned long long)offset, len); + id, (unsigned long long)offset, len); } else if (TAILQ_FIRST(&acks) == NULL) break; @@ -1081,7 +1081,7 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path, if (status != SSH2_FX_OK) { error("Couldn't write to remote file \"%s\": %s", - remote_path, fx2txt(status)); + remote_path, fx2txt(status)); do_close(conn, handle, handle_len); close(local_fd); goto done; diff --git a/sftp-int.c b/sftp-int.c index 6a2012910..04b67c969 100644 --- a/sftp-int.c +++ b/sftp-int.c @@ -25,7 +25,7 @@ /* XXX: recursive operations */ #include "includes.h" -RCSID("$OpenBSD: sftp-int.c,v 1.49 2002/09/12 00:13:06 djm Exp $"); +RCSID("$OpenBSD: sftp-int.c,v 1.50 2002/11/21 23:03:51 deraadt Exp $"); #include "buffer.h" #include "xmalloc.h" @@ -550,7 +550,7 @@ sdirent_comp(const void *aa, const void *bb) SFTP_DIRENT *a = *(SFTP_DIRENT **)aa; SFTP_DIRENT *b = *(SFTP_DIRENT **)bb; - return (strcmp(a->filename, b->filename)); + return (strcmp(a->filename, b->filename)); } /* sftp ls.1 replacement for directories */ @@ -563,7 +563,7 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag) if ((n = do_readdir(conn, path, &d)) != 0) return (n); - /* Count entries for sort */ + /* Count entries for sort */ for (n = 0; d[n] != NULL; n++) ; @@ -571,7 +571,7 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag) for (n = 0; d[n] != NULL; n++) { char *tmp, *fname; - + tmp = path_append(path, d[n]->filename); fname = path_strip(tmp, strip_path); xfree(tmp); @@ -589,7 +589,7 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag) /* XXX - multicolumn display would be nice here */ printf("%s\n", fname); } - + xfree(fname); } @@ -599,7 +599,7 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag) /* sftp ls.1 replacement which handles path globs */ static int -do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, +do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, int lflag) { glob_t g; @@ -609,23 +609,23 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, memset(&g, 0, sizeof(g)); - if (remote_glob(conn, path, GLOB_MARK|GLOB_NOCHECK|GLOB_BRACE, + if (remote_glob(conn, path, GLOB_MARK|GLOB_NOCHECK|GLOB_BRACE, NULL, &g)) { error("Can't ls: \"%s\" not found", path); return (-1); } /* - * If the glob returns a single match, which is the same as the + * If the glob returns a single match, which is the same as the * input glob, and it is a directory, then just list its contents */ - if (g.gl_pathc == 1 && + if (g.gl_pathc == 1 && strncmp(path, g.gl_pathv[0], strlen(g.gl_pathv[0]) - 1) == 0) { if ((a = do_lstat(conn, path, 1)) == NULL) { globfree(&g); return (-1); } - if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) && + if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) && S_ISDIR(a->perm)) { globfree(&g); return (do_ls_dir(conn, path, strip_path, lflag)); @@ -640,8 +640,8 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, if (lflag) { /* * XXX: this is slow - 1 roundtrip per path - * A solution to this is to fork glob() and - * build a sftp specific version which keeps the + * A solution to this is to fork glob() and + * build a sftp specific version which keeps the * attribs (which currently get thrown away) * that the server returns as well as the filenames. */ @@ -666,7 +666,7 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, } static int -parse_args(const char **cpp, int *pflag, int *lflag, +parse_args(const char **cpp, int *pflag, int *lflag, unsigned long *n_arg, char **path1, char **path2) { const char *cmd, *cp = *cpp; @@ -900,7 +900,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd) do_globbed_ls(conn, *pwd, *pwd, lflag); break; } - + /* Strip pwd off beginning of non-absolute paths */ tmp = NULL; if (*path1 != '/') diff --git a/ssh-add.c b/ssh-add.c index 9c729752a..4f4ab3a06 100644 --- a/ssh-add.c +++ b/ssh-add.c @@ -35,7 +35,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: ssh-add.c,v 1.63 2002/09/19 15:51:23 markus Exp $"); +RCSID("$OpenBSD: ssh-add.c,v 1.64 2002/11/21 23:03:51 deraadt Exp $"); #include @@ -169,7 +169,7 @@ add_file(AuthenticationConnection *ac, const char *filename) fprintf(stderr, "Identity added: %s (%s)\n", filename, comment); ret = 0; if (lifetime != 0) - fprintf(stderr, + fprintf(stderr, "Lifetime set to %d seconds\n", lifetime); } else if (ssh_add_identity(ac, private, comment)) { fprintf(stderr, "Identity added: %s (%s)\n", filename, comment); diff --git a/ssh-rsa.c b/ssh-rsa.c index d7b2918f9..c599ce65c 100644 --- a/ssh-rsa.c +++ b/ssh-rsa.c @@ -23,7 +23,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: ssh-rsa.c,v 1.26 2002/08/27 17:13:56 stevesk Exp $"); +RCSID("$OpenBSD: ssh-rsa.c,v 1.27 2002/11/21 23:03:51 deraadt Exp $"); #include #include @@ -37,7 +37,7 @@ RCSID("$OpenBSD: ssh-rsa.c,v 1.26 2002/08/27 17:13:56 stevesk Exp $"); #include "compat.h" #include "ssh.h" -static int openssh_RSA_verify(int, u_char *, u_int, u_char *, u_int , RSA *); +static int openssh_RSA_verify(int, u_char *, u_int, u_char *, u_int, RSA *); /* RSASSA-PKCS1-v1_5 (PKCS #1 v2.0 signature) with SHA1 */ int diff --git a/sshconnect.c b/sshconnect.c index f99fe0257..dae25969a 100644 --- a/sshconnect.c +++ b/sshconnect.c @@ -13,7 +13,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: sshconnect.c,v 1.136 2002/11/21 22:45:31 markus Exp $"); +RCSID("$OpenBSD: sshconnect.c,v 1.137 2002/11/21 23:03:51 deraadt Exp $"); #include @@ -649,10 +649,10 @@ check_host_key(char *host, struct sockaddr *hostaddr, Key *host_key, "%s key fingerprint is %s.\n" "Are you sure you want to continue connecting " "(yes/no)? ", - host, ip, - has_keys ? ",\nbut keys of different type are already " - "known for this host." : ".", - type, fp); + host, ip, + has_keys ? ",\nbut keys of different type are already " + "known for this host." : ".", + type, fp); xfree(fp); if (!confirm(msg)) goto fail; -- cgit v1.2.3 From 770b374a68fdb27de2c6314f154db57067875ff8 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Wed, 8 Jan 2003 14:04:53 +1100 Subject: - djm@cvs.openbsd.org 2003/01/06 23:51:22 [sftp-client.c] Fix "get -p" download to not add user-write perm. mindrot bug #426 reported by gfernandez@livevault.com; ok markus@ --- ChangeLog | 6 +++++- sftp-client.c | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'sftp-client.c') diff --git a/ChangeLog b/ChangeLog index 35b35c1d2..3d489ed24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ - markus@cvs.openbsd.org 2003/01/01 18:08:52 [channels.c] move big output buffer messages to debug2 + - djm@cvs.openbsd.org 2003/01/06 23:51:22 + [sftp-client.c] + Fix "get -p" download to not add user-write perm. mindrot bug #426 + reported by gfernandez@livevault.com; ok markus@ 20030107 - (djm) Bug #401: Work around Linux breakage with IPv6 mapped addresses. @@ -950,4 +954,4 @@ save auth method before monitor_reset_key_state(); bugzilla bug #284; ok provos@ -$Id: ChangeLog,v 1.2551 2003/01/08 03:04:09 djm Exp $ +$Id: ChangeLog,v 1.2552 2003/01/08 03:04:53 djm Exp $ diff --git a/sftp-client.c b/sftp-client.c index df9838648..bff37073c 100644 --- a/sftp-client.c +++ b/sftp-client.c @@ -28,7 +28,7 @@ /* XXX: copy between two remote sites */ #include "includes.h" -RCSID("$OpenBSD: sftp-client.c,v 1.37 2002/11/21 23:03:51 deraadt Exp $"); +RCSID("$OpenBSD: sftp-client.c,v 1.38 2003/01/06 23:51:22 djm Exp $"); #include "openbsd-compat/sys-queue.h" @@ -758,7 +758,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path, /* XXX: should we preserve set[ug]id? */ if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) - mode = S_IWRITE | (a->perm & 0777); + mode = a->perm & 0777; else mode = 0666; @@ -793,7 +793,8 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path, return(-1); } - local_fd = open(local_path, O_WRONLY | O_CREAT | O_TRUNC, mode); + local_fd = open(local_path, O_WRONLY | O_CREAT | O_TRUNC, + mode | S_IWRITE); if (local_fd == -1) { error("Couldn't open local file \"%s\" for writing: %s", local_path, strerror(errno)); -- cgit v1.2.3 From 62d57f605a84b8d80803a36a612a37a5137a9963 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Fri, 10 Jan 2003 21:43:24 +1100 Subject: - fgsch@cvs.openbsd.org 2003/01/10 08:19:07 [scp.c sftp.1 sftp.c sftp-client.c sftp-int.c] sftp progress meter support. original diffs by Nils Nordman via markus@, merged to -current by me, djm@ ok. --- ChangeLog | 7 +- Makefile.in | 10 +-- scp.c | 211 +++------------------------------------------------------- sftp-client.c | 27 +++++++- sftp-int.c | 18 ++++- sftp.1 | 4 +- sftp.c | 5 +- 7 files changed, 69 insertions(+), 213 deletions(-) (limited to 'sftp-client.c') diff --git a/ChangeLog b/ChangeLog index 3c38dbb10..c075cd359 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,11 @@ Allow blank lines and comments in input Ability to suppress abort on error in batchmode ("-put blah") Fixes mindrot bug #452; markus@ ok + - fgsch@cvs.openbsd.org 2003/01/10 08:19:07 + [scp.c sftp.1 sftp.c sftp-client.c sftp-int.c] + sftp progress meter support. + original diffs by Nils Nordman via + markus@, merged to -current by me, djm@ ok. 20030108 - (djm) Sync openbsd-compat/ with OpenBSD -current @@ -976,4 +981,4 @@ save auth method before monitor_reset_key_state(); bugzilla bug #284; ok provos@ -$Id: ChangeLog,v 1.2559 2003/01/10 10:40:00 djm Exp $ +$Id: ChangeLog,v 1.2560 2003/01/10 10:43:24 djm Exp $ diff --git a/Makefile.in b/Makefile.in index 85b108d16..8d5987afd 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,4 +1,4 @@ -# $Id: Makefile.in,v 1.223 2003/01/09 01:22:59 tim Exp $ +# $Id: Makefile.in,v 1.224 2003/01/10 10:43:25 djm Exp $ # uncomment if you run a non bourne compatable shell. Ie. csh #SHELL = @SH@ @@ -117,8 +117,8 @@ ssh$(EXEEXT): $(LIBCOMPAT) libssh.a $(SSHOBJS) sshd$(EXEEXT): libssh.a $(LIBCOMPAT) $(SSHDOBJS) $(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(LIBWRAP) $(LIBPAM) $(LIBS) -scp$(EXEEXT): $(LIBCOMPAT) libssh.a scp.o - $(LD) -o $@ scp.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) +scp$(EXEEXT): $(LIBCOMPAT) libssh.a scp.o progressmeter.o + $(LD) -o $@ scp.o progressmeter.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) ssh-add$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-add.o $(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) @@ -138,8 +138,8 @@ ssh-keyscan$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keyscan.o sftp-server$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-common.o sftp-server.o $(LD) -o $@ sftp-server.o sftp-common.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) -sftp$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-client.o sftp-int.o sftp-common.o sftp-glob.o - $(LD) -o $@ sftp.o sftp-client.o sftp-common.o sftp-int.o sftp-glob.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) +sftp$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-client.o sftp-int.o sftp-common.o sftp-glob.o progressmeter.o + $(LD) -o $@ progressmeter.o sftp.o sftp-client.o sftp-common.o sftp-int.o sftp-glob.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) ssh-rand-helper${EXEEXT}: $(LIBCOMPAT) libssh.a ssh-rand-helper.o $(LD) -o $@ ssh-rand-helper.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) diff --git a/scp.c b/scp.c index 8324549d7..44b5b4582 100644 --- a/scp.c +++ b/scp.c @@ -75,13 +75,14 @@ */ #include "includes.h" -RCSID("$OpenBSD: scp.c,v 1.96 2002/12/13 15:20:52 markus Exp $"); +RCSID("$OpenBSD: scp.c,v 1.97 2003/01/10 08:19:07 fgsch Exp $"); #include "xmalloc.h" #include "atomicio.h" #include "pathnames.h" #include "log.h" #include "misc.h" +#include "progressmeter.h" #ifdef HAVE___PROGNAME extern char *__progname; @@ -89,30 +90,9 @@ extern char *__progname; char *__progname; #endif -/* For progressmeter() -- number of seconds before xfer considered "stalled" */ -#define STALLTIME 5 -/* alarm() interval for updating progress meter */ -#define PROGRESSTIME 1 - -/* Visual statistics about files as they are transferred. */ -void progressmeter(int); - -/* Returns width of the terminal (for progress meter calculations). */ -int getttywidth(void); -int do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc); - /* Struct for addargs */ arglist args; -/* Time a transfer started. */ -static struct timeval start; - -/* Number of bytes of current file transferred so far. */ -volatile off_t statbytes; - -/* Total size of current file. */ -off_t totalbytes = 0; - /* Name of current file being transferred. */ char *curfile; @@ -505,7 +485,7 @@ source(argc, argv) struct stat stb; static BUF buffer; BUF *bp; - off_t i, amt, result; + off_t i, amt, result, statbytes; int fd, haderr, indx; char *last, *name, buf[2048]; int len; @@ -578,10 +558,8 @@ syserr: run_err("%s: %s", name, strerror(errno)); next: (void) close(fd); continue; } - if (showprogress) { - totalbytes = stb.st_size; - progressmeter(-1); - } + if (showprogress) + start_progress_meter(curfile, stb.st_size, &statbytes); /* Keep writing after an error so that we stay sync'd up. */ for (haderr = i = 0; i < stb.st_size; i += bp->cnt) { amt = bp->cnt; @@ -602,7 +580,7 @@ next: (void) close(fd); } } if (showprogress) - progressmeter(1); + stop_progress_meter(); if (close(fd) < 0 && !haderr) haderr = errno; @@ -682,7 +660,7 @@ sink(argc, argv) BUF *bp; off_t i, j; int amt, count, exists, first, mask, mode, ofd, omode; - off_t size; + off_t size, statbytes; int setimes, targisdir, wrerrno = 0; char ch, *cp, *np, *targ, *why, *vect[1], buf[2048]; struct timeval tv[2]; @@ -844,11 +822,9 @@ bad: run_err("%s: %s", np, strerror(errno)); cp = bp->buf; wrerr = NO; - if (showprogress) { - totalbytes = size; - progressmeter(-1); - } statbytes = 0; + if (showprogress) + start_progress_meter(curfile, size, &statbytes); for (count = i = 0; i < size; i += 4096) { amt = 4096; if (i + amt > size) @@ -882,7 +858,7 @@ bad: run_err("%s: %s", np, strerror(errno)); } } if (showprogress) - progressmeter(1); + stop_progress_meter(); if (count != 0 && wrerr == NO && (j = atomicio(write, ofd, bp->buf, count)) != count) { wrerr = YES; @@ -1086,170 +1062,3 @@ lostconn(signo) else exit(1); } - -static void -updateprogressmeter(int ignore) -{ - int save_errno = errno; - - progressmeter(0); - signal(SIGALRM, updateprogressmeter); - alarm(PROGRESSTIME); - errno = save_errno; -} - -static int -foregroundproc(void) -{ - static pid_t pgrp = -1; - int ctty_pgrp; - - if (pgrp == -1) - pgrp = getpgrp(); - -#ifdef HAVE_TCGETPGRP - return ((ctty_pgrp = tcgetpgrp(STDOUT_FILENO)) != -1 && - ctty_pgrp == pgrp); -#else - return ((ioctl(STDOUT_FILENO, TIOCGPGRP, &ctty_pgrp) != -1 && - ctty_pgrp == pgrp)); -#endif -} - -void -progressmeter(int flag) -{ - static const char spaces[] = " " - " " - " " - " " - " " - " "; - static const char prefixes[] = " KMGTP"; - static struct timeval lastupdate; - static off_t lastsize; - struct timeval now, td, wait; - off_t cursize, abbrevsize, bytespersec; - double elapsed; - int ratio, remaining, i, ai, bi, nspaces; - char buf[512]; - - if (flag == -1) { - (void) gettimeofday(&start, (struct timezone *) 0); - lastupdate = start; - lastsize = 0; - } - if (foregroundproc() == 0) - return; - - (void) gettimeofday(&now, (struct timezone *) 0); - cursize = statbytes; - if (totalbytes != 0) { - ratio = 100.0 * cursize / totalbytes; - ratio = MAX(ratio, 0); - ratio = MIN(ratio, 100); - } else - ratio = 100; - - abbrevsize = cursize; - for (ai = 0; abbrevsize >= 10000 && ai < sizeof(prefixes); ai++) - abbrevsize >>= 10; - - timersub(&now, &lastupdate, &wait); - if (cursize > lastsize) { - lastupdate = now; - lastsize = cursize; - wait.tv_sec = 0; - } - timersub(&now, &start, &td); - elapsed = td.tv_sec + (td.tv_usec / 1000000.0); - - bytespersec = 0; - if (statbytes > 0) { - bytespersec = statbytes; - if (elapsed > 0.0) - bytespersec /= elapsed; - } - for (bi = 1; bytespersec >= 1024000 && bi < sizeof(prefixes); bi++) - bytespersec >>= 10; - - nspaces = MIN(getttywidth() - 79, sizeof(spaces) - 1); - -#ifdef HAVE_LONG_LONG_INT - snprintf(buf, sizeof(buf), - "\r%-45.45s%.*s%3d%% %4lld%c%c %3lld.%01d%cB/s", - curfile, - nspaces, - spaces, - ratio, - (long long)abbrevsize, - prefixes[ai], - ai == 0 ? ' ' : 'B', - (long long)(bytespersec / 1024), - (int)((bytespersec % 1024) * 10 / 1024), - prefixes[bi] - ); -#else - snprintf(buf, sizeof(buf), - "\r%-45.45s%.*s%3d%% %4lld%c%c %3lu.%01d%cB/s", - curfile, - nspaces, - spaces, - ratio, - (u_long)abbrevsize, - prefixes[ai], - ai == 0 ? ' ' : 'B', - (u_long)(bytespersec / 1024), - (int)((bytespersec % 1024) * 10 / 1024), - prefixes[bi] - ); -#endif - - if (flag != 1 && - (statbytes <= 0 || elapsed <= 0.0 || cursize > totalbytes)) { - snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), - " --:-- ETA"); - } else if (wait.tv_sec >= STALLTIME) { - snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), - " - stalled -"); - } else { - if (flag != 1) - remaining = (int)(totalbytes / (statbytes / elapsed) - - elapsed); - else - remaining = elapsed; - - i = remaining / 3600; - if (i) - snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), - "%2d:", i); - else - snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), - " "); - i = remaining % 3600; - snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), - "%02d:%02d%s", i / 60, i % 60, - (flag != 1) ? " ETA" : " "); - } - atomicio(write, fileno(stdout), buf, strlen(buf)); - - if (flag == -1) { - mysignal(SIGALRM, updateprogressmeter); - alarm(PROGRESSTIME); - } else if (flag == 1) { - alarm(0); - atomicio(write, fileno(stdout), "\n", 1); - statbytes = 0; - } -} - -int -getttywidth(void) -{ - struct winsize winsize; - - if (ioctl(fileno(stdout), TIOCGWINSZ, &winsize) != -1) - return (winsize.ws_col ? winsize.ws_col : 80); - else - return (80); -} diff --git a/sftp-client.c b/sftp-client.c index bff37073c..e0d3ad568 100644 --- a/sftp-client.c +++ b/sftp-client.c @@ -28,7 +28,7 @@ /* XXX: copy between two remote sites */ #include "includes.h" -RCSID("$OpenBSD: sftp-client.c,v 1.38 2003/01/06 23:51:22 djm Exp $"); +RCSID("$OpenBSD: sftp-client.c,v 1.39 2003/01/10 08:19:07 fgsch Exp $"); #include "openbsd-compat/sys-queue.h" @@ -38,11 +38,14 @@ RCSID("$OpenBSD: sftp-client.c,v 1.38 2003/01/06 23:51:22 djm Exp $"); #include "xmalloc.h" #include "log.h" #include "atomicio.h" +#include "progressmeter.h" #include "sftp.h" #include "sftp-common.h" #include "sftp-client.h" +extern int showprogress; + /* Minimum amount of data to read at at time */ #define MIN_READ_SIZE 512 @@ -741,6 +744,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path, int read_error, write_errno; u_int64_t offset, size; u_int handle_len, mode, type, id, buflen; + off_t progress_counter; struct request { u_int id; u_int len; @@ -806,6 +810,16 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path, /* Read from remote and write to local */ write_error = read_error = write_errno = num_req = offset = 0; max_req = 1; + progress_counter = 0; + + if (showprogress) { + if (size) + start_progress_meter(remote_path, size, + &progress_counter); + else + printf("Fetching %s to %s\n", remote_path, local_path); + } + while (num_req > 0 || max_req > 0) { char *data; u_int len; @@ -866,6 +880,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path, write_error = 1; max_req = 0; } + progress_counter += len; xfree(data); if (len == req->len) { @@ -908,6 +923,9 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path, } } + if (showprogress && size) + stop_progress_meter(); + /* Sanity check */ if (TAILQ_FIRST(&requests) != NULL) fatal("Transfer complete, but requests still in queue"); @@ -1018,6 +1036,11 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path, /* Read from local and write to remote */ offset = 0; + if (showprogress) + start_progress_meter(local_path, sb.st_size, &offset); + else + printf("Uploading %s to %s\n", local_path, remote_path); + for (;;) { int len; @@ -1094,6 +1117,8 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path, } offset += len; } + if (showprogress) + stop_progress_meter(); xfree(data); if (close(local_fd) == -1) { diff --git a/sftp-int.c b/sftp-int.c index f2c8fa6dc..88b0530ab 100644 --- a/sftp-int.c +++ b/sftp-int.c @@ -25,7 +25,7 @@ /* XXX: recursive operations */ #include "includes.h" -RCSID("$OpenBSD: sftp-int.c,v 1.51 2003/01/08 23:53:26 djm Exp $"); +RCSID("$OpenBSD: sftp-int.c,v 1.52 2003/01/10 08:19:07 fgsch Exp $"); #include "buffer.h" #include "xmalloc.h" @@ -47,6 +47,9 @@ extern size_t copy_buffer_len; /* Number of concurrent outstanding requests */ extern int num_requests; +/* This is set to 0 if the progressmeter is not desired. */ +int showprogress = 1; + /* Seperators for interactive commands */ #define WHITESPACE " \t\r\n" @@ -73,6 +76,7 @@ extern int num_requests; #define I_SHELL 20 #define I_SYMLINK 21 #define I_VERSION 22 +#define I_PROGRESS 23 struct CMD { const char *c; @@ -100,6 +104,7 @@ const struct CMD cmds[] = { { "ls", I_LS }, { "lumask", I_LUMASK }, { "mkdir", I_MKDIR }, + { "progress", I_PROGRESS }, { "put", I_PUT }, { "mput", I_PUT }, { "pwd", I_PWD }, @@ -132,6 +137,7 @@ help(void) printf("ls [path] Display remote directory listing\n"); printf("lumask umask Set local umask to 'umask'\n"); printf("mkdir path Create remote directory\n"); + printf("preogress Toggle display of progress meter\n"); printf("put local-path [remote-path] Upload file\n"); printf("pwd Display remote working directory\n"); printf("exit Quit sftp\n"); @@ -425,7 +431,6 @@ process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd, int pflag) err = -1; goto out; } - printf("Fetching %s to %s\n", g.gl_pathv[0], abs_dst); err = do_download(conn, g.gl_pathv[0], abs_dst, pflag); goto out; } @@ -507,7 +512,6 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, int pflag) } abs_dst = make_absolute(abs_dst, pwd); } - printf("Uploading %s to %s\n", g.gl_pathv[0], abs_dst); err = do_upload(conn, g.gl_pathv[0], abs_dst, pflag); goto out; } @@ -810,6 +814,7 @@ parse_args(const char **cpp, int *pflag, int *lflag, int *iflag, case I_LPWD: case I_HELP: case I_VERSION: + case I_PROGRESS: break; default: fatal("Command not implemented"); @@ -1015,6 +1020,13 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, case I_VERSION: printf("SFTP protocol version %u\n", sftp_proto_version(conn)); break; + case I_PROGRESS: + showprogress = !showprogress; + if (showprogress) + printf("Progress meter enabled\n"); + else + printf("Progress meter disabled\n"); + break; default: fatal("%d is not implemented", cmdnum); } diff --git a/sftp.1 b/sftp.1 index 67086bdaa..ecd4d3174 100644 --- a/sftp.1 +++ b/sftp.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sftp.1,v 1.39 2003/01/08 23:53:26 djm Exp $ +.\" $OpenBSD: sftp.1,v 1.40 2003/01/10 08:19:07 fgsch Exp $ .\" .\" Copyright (c) 2001 Damien Miller. All rights reserved. .\" @@ -228,6 +228,8 @@ Set local umask to .It Ic mkdir Ar path Create remote directory specified by .Ar path . +.It Ic progress +Toggle display of progress meter. .It Xo Ic put .Op Ar flags .Ar local-path diff --git a/sftp.c b/sftp.c index d62e9e42c..e8adcba18 100644 --- a/sftp.c +++ b/sftp.c @@ -24,7 +24,7 @@ #include "includes.h" -RCSID("$OpenBSD: sftp.c,v 1.33 2003/01/08 23:53:26 djm Exp $"); +RCSID("$OpenBSD: sftp.c,v 1.34 2003/01/10 08:19:07 fgsch Exp $"); /* XXX: short-form remote directory listings (like 'ls -C') */ @@ -49,6 +49,8 @@ FILE* infile; size_t copy_buffer_len = 32768; size_t num_requests = 16; +extern int showprogress; + static void connect_to_server(char *path, char **args, int *in, int *out, pid_t *sshpid) { @@ -162,6 +164,7 @@ main(int argc, char **argv) fatal("%s (%s).", strerror(errno), optarg); } else fatal("Filename already specified."); + showprogress = 0; break; case 'P': sftp_direct = optarg; -- cgit v1.2.3 From a7f3aaadc30b1533def73449081263a5d42d4aa4 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Fri, 10 Jan 2003 21:43:58 +1100 Subject: - djm@cvs.openbsd.org 2003/01/10 08:48:15 [sftp-client.c] Simplify and avoid redundancy in packet send and receive functions; ok fgs@ --- ChangeLog | 6 +++++- sftp-client.c | 54 +++++++++++++++++++++++++++--------------------------- 2 files changed, 32 insertions(+), 28 deletions(-) (limited to 'sftp-client.c') diff --git a/ChangeLog b/ChangeLog index c075cd359..595f1f6fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,10 @@ sftp progress meter support. original diffs by Nils Nordman via markus@, merged to -current by me, djm@ ok. + - djm@cvs.openbsd.org 2003/01/10 08:48:15 + [sftp-client.c] + Simplify and avoid redundancy in packet send and receive + functions; ok fgs@ 20030108 - (djm) Sync openbsd-compat/ with OpenBSD -current @@ -981,4 +985,4 @@ save auth method before monitor_reset_key_state(); bugzilla bug #284; ok provos@ -$Id: ChangeLog,v 1.2560 2003/01/10 10:43:24 djm Exp $ +$Id: ChangeLog,v 1.2561 2003/01/10 10:43:58 djm Exp $ diff --git a/sftp-client.c b/sftp-client.c index e0d3ad568..3fac22bee 100644 --- a/sftp-client.c +++ b/sftp-client.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001,2002 Damien Miller. All rights reserved. + * Copyright (c) 2001-2003 Damien Miller. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,7 +28,7 @@ /* XXX: copy between two remote sites */ #include "includes.h" -RCSID("$OpenBSD: sftp-client.c,v 1.39 2003/01/10 08:19:07 fgsch Exp $"); +RCSID("$OpenBSD: sftp-client.c,v 1.40 2003/01/10 08:48:15 djm Exp $"); #include "openbsd-compat/sys-queue.h" @@ -49,6 +49,9 @@ extern int showprogress; /* Minimum amount of data to read at at time */ #define MIN_READ_SIZE 512 +/* Maximum packet size */ +#define MAX_MSG_LENGTH (256 * 1024) + struct sftp_conn { int fd_in; int fd_out; @@ -61,48 +64,45 @@ struct sftp_conn { static void send_msg(int fd, Buffer *m) { - int mlen = buffer_len(m); - int len; - Buffer oqueue; + u_char mlen[4]; + + if (buffer_len(m) > MAX_MSG_LENGTH) + fatal("Outbound message too long %u", buffer_len(m)); - buffer_init(&oqueue); - buffer_put_int(&oqueue, mlen); - buffer_append(&oqueue, buffer_ptr(m), mlen); - buffer_consume(m, mlen); + /* Send length first */ + PUT_32BIT(mlen, buffer_len(m)); + if (atomicio(write, fd, mlen, sizeof(mlen)) <= 0) + fatal("Couldn't send packet: %s", strerror(errno)); - len = atomicio(write, fd, buffer_ptr(&oqueue), buffer_len(&oqueue)); - if (len <= 0) + if (atomicio(write, fd, buffer_ptr(m), buffer_len(m)) <= 0) fatal("Couldn't send packet: %s", strerror(errno)); - buffer_free(&oqueue); + buffer_clear(m); } static void get_msg(int fd, Buffer *m) { - u_int len, msg_len; - unsigned char buf[4096]; + ssize_t len; + u_int msg_len; - len = atomicio(read, fd, buf, 4); + buffer_append_space(m, 4); + len = atomicio(read, fd, buffer_ptr(m), 4); if (len == 0) fatal("Connection closed"); else if (len == -1) fatal("Couldn't read packet: %s", strerror(errno)); - msg_len = GET_32BIT(buf); - if (msg_len > 256 * 1024) + msg_len = buffer_get_int(m); + if (msg_len > MAX_MSG_LENGTH) fatal("Received message too long %u", msg_len); - while (msg_len) { - len = atomicio(read, fd, buf, MIN(msg_len, sizeof(buf))); - if (len == 0) - fatal("Connection closed"); - else if (len == -1) - fatal("Couldn't read packet: %s", strerror(errno)); - - msg_len -= len; - buffer_append(m, buf, len); - } + buffer_append_space(m, msg_len); + len = atomicio(read, fd, buffer_ptr(m), msg_len); + if (len == 0) + fatal("Connection closed"); + else if (len == -1) + fatal("Read packet: %s", strerror(errno)); } static void -- cgit v1.2.3 From 5fa01fd7fba87bbd716b4ca32d4d7e2f7180975a Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Tue, 14 Jan 2003 22:24:47 +1100 Subject: - djm@cvs.openbsd.org 2003/01/14 10:58:00 [sftp-client.c sftp-int.c] Don't try to upload or download non-regular files. Report from apoloval@pantuflo.escet.urjc.es; ok markus@ --- ChangeLog | 6 +++++- sftp-client.c | 11 ++++++++--- sftp-int.c | 24 +++++++++++++++++++++++- 3 files changed, 36 insertions(+), 5 deletions(-) (limited to 'sftp-client.c') diff --git a/ChangeLog b/ChangeLog index bbd769ebd..36d5d2ca0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,10 @@ [sftp-int.c] make cmds[] array static to avoid conflict with BSDI libc. mindrot bug #466. Fix from mdev@idg.nl; ok markus@ + - djm@cvs.openbsd.org 2003/01/14 10:58:00 + [sftp-client.c sftp-int.c] + Don't try to upload or download non-regular files. Report from + apoloval@pantuflo.escet.urjc.es; ok markus@ 20030113 - (djm) Rework openbsd-compat/setproctitle.c a bit: move emulation type @@ -1017,4 +1021,4 @@ save auth method before monitor_reset_key_state(); bugzilla bug #284; ok provos@ -$Id: ChangeLog,v 1.2571 2003/01/14 11:24:19 djm Exp $ +$Id: ChangeLog,v 1.2572 2003/01/14 11:24:47 djm Exp $ diff --git a/sftp-client.c b/sftp-client.c index 3fac22bee..8c12dae11 100644 --- a/sftp-client.c +++ b/sftp-client.c @@ -28,7 +28,7 @@ /* XXX: copy between two remote sites */ #include "includes.h" -RCSID("$OpenBSD: sftp-client.c,v 1.40 2003/01/10 08:48:15 djm Exp $"); +RCSID("$OpenBSD: sftp-client.c,v 1.41 2003/01/14 10:58:00 djm Exp $"); #include "openbsd-compat/sys-queue.h" @@ -767,8 +767,8 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path, mode = 0666; if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) && - (a->perm & S_IFDIR)) { - error("Cannot download a directory: %s", remote_path); + (!S_ISREG(a->perm))) { + error("Cannot download non-regular file: %s", remote_path); return(-1); } @@ -1002,6 +1002,11 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path, close(local_fd); return(-1); } + if (!S_ISREG(sb.st_mode)) { + error("%s is not a regular file", local_path); + close(local_fd); + return(-1); + } stat_to_attrib(&sb, &a); a.flags &= ~SSH2_FILEXFER_ATTR_SIZE; diff --git a/sftp-int.c b/sftp-int.c index 3438fdeb0..42040f5bd 100644 --- a/sftp-int.c +++ b/sftp-int.c @@ -25,7 +25,7 @@ /* XXX: recursive operations */ #include "includes.h" -RCSID("$OpenBSD: sftp-int.c,v 1.54 2003/01/13 11:04:04 djm Exp $"); +RCSID("$OpenBSD: sftp-int.c,v 1.55 2003/01/14 10:58:00 djm Exp $"); #include "buffer.h" #include "xmalloc.h" @@ -380,6 +380,17 @@ is_dir(char *path) return(sb.st_mode & S_IFDIR); } +static int +is_reg(char *path) +{ + struct stat sb; + + if (stat(path, &sb) == -1) + fatal("stat %s: %s", path, strerror(errno)); + + return(S_ISREG(sb.st_mode)); +} + static int remote_is_dir(struct sftp_conn *conn, char *path) { @@ -494,6 +505,12 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, int pflag) /* Only one match, dst may be file, directory or unspecified */ if (g.gl_pathv[0] && g.gl_matchc == 1) { + if (!is_reg(g.gl_pathv[i])) { + error("Can't upload %s: not a regular file", + g.gl_pathv[0]); + err = 1; + goto out; + } if (tmp_dst) { /* If directory specified, append filename */ if (remote_is_dir(conn, tmp_dst)) { @@ -525,6 +542,11 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, int pflag) } for (i = 0; g.gl_pathv[i]; i++) { + if (!is_reg(g.gl_pathv[i])) { + error("skipping non-regular file %s", + g.gl_pathv[i]); + continue; + } if (infer_path(g.gl_pathv[i], &tmp)) { err = -1; goto out; -- cgit v1.2.3 From 0011138d47e284273ba77415f7162aaab60d9a44 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Mon, 10 Mar 2003 11:21:17 +1100 Subject: - (djm) OpenBSD CVS Sync - markus@cvs.openbsd.org 2003/03/05 22:33:43 [channels.c monitor.c scp.c session.c sftp-client.c sftp-int.c] [sftp-server.c ssh-add.c sshconnect2.c] fix memory leaks; from dlheine@suif.Stanford.EDU/CLOUSEAU; ok djm@ --- ChangeLog | 9 ++++++++- channels.c | 4 +++- monitor.c | 12 +++++++++--- scp.c | 10 +++++++--- session.c | 9 +++++---- sftp-client.c | 5 ++++- sftp-int.c | 3 ++- sftp-server.c | 10 ++++++---- ssh-add.c | 9 ++++++--- sshconnect2.c | 3 ++- 10 files changed, 52 insertions(+), 22 deletions(-) (limited to 'sftp-client.c') diff --git a/ChangeLog b/ChangeLog index 41c66dbd3..984223fb1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +20030310 +- (djm) OpenBSD CVS Sync + - markus@cvs.openbsd.org 2003/03/05 22:33:43 + [channels.c monitor.c scp.c session.c sftp-client.c sftp-int.c] + [sftp-server.c ssh-add.c sshconnect2.c] + fix memory leaks; from dlheine@suif.Stanford.EDU/CLOUSEAU; ok djm@ + 20030225 - (djm) Fix some compile errors spotted by dtucker and his fabulous tinderbox @@ -1191,4 +1198,4 @@ save auth method before monitor_reset_key_state(); bugzilla bug #284; ok provos@ -$Id: ChangeLog,v 1.2622 2003/02/24 23:22:35 djm Exp $ +$Id: ChangeLog,v 1.2623 2003/03/10 00:21:17 djm Exp $ diff --git a/channels.c b/channels.c index ea1d46c21..1937b0244 100644 --- a/channels.c +++ b/channels.c @@ -39,7 +39,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: channels.c,v 1.186 2003/01/10 10:32:54 djm Exp $"); +RCSID("$OpenBSD: channels.c,v 1.187 2003/03/05 22:33:43 markus Exp $"); #include "ssh.h" #include "ssh1.h" @@ -1997,6 +1997,7 @@ channel_input_port_open(int type, u_int32_t seq, void *ctxt) c->remote_id = remote_id; } if (c == NULL) { + xfree(originator_string); packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE); packet_put_int(remote_id); packet_send(); @@ -2609,6 +2610,7 @@ x11_input_open(int type, u_int32_t seq, void *ctxt) /* Send refusal to the remote host. */ packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE); packet_put_int(remote_id); + xfree(remote_host); } else { /* Send a confirmation to the remote host. */ packet_start(SSH_MSG_CHANNEL_OPEN_CONFIRMATION); diff --git a/monitor.c b/monitor.c index 694cd630a..2b4168831 100644 --- a/monitor.c +++ b/monitor.c @@ -25,7 +25,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: monitor.c,v 1.32 2003/02/16 17:30:33 markus Exp $"); +RCSID("$OpenBSD: monitor.c,v 1.33 2003/03/05 22:33:43 markus Exp $"); #include @@ -806,8 +806,9 @@ mm_answer_keyallowed(int socket, Buffer *m) fatal("%s: unknown key type %d", __func__, type); break; } - key_free(key); } + if (key != NULL) + key_free(key); /* clear temporarily storage (used by verify) */ monitor_reset_key_state(); @@ -1204,8 +1205,9 @@ mm_answer_rsa_keyallowed(int socket, Buffer *m) key_blob = blob; key_bloblen = blen; key_blobtype = MM_RSAUSERKEY; - key_free(key); } + if (key != NULL) + key_free(key); mm_append_debug(m); @@ -1246,6 +1248,9 @@ mm_answer_rsa_challenge(int socket, Buffer *m) mm_request_send(socket, MONITOR_ANS_RSACHALLENGE, m); monitor_permit(mon_dispatch, MONITOR_REQ_RSARESPONSE, 1); + + xfree(blob); + key_free(key); return (0); } @@ -1276,6 +1281,7 @@ mm_answer_rsa_response(int socket, Buffer *m) fatal("%s: received bad response to challenge", __func__); success = auth_rsa_verify_response(key, ssh1_challenge, response); + xfree(blob); key_free(key); xfree(response); diff --git a/scp.c b/scp.c index e44a1cf69..ab67c0bb8 100644 --- a/scp.c +++ b/scp.c @@ -75,7 +75,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: scp.c,v 1.101 2003/02/02 10:51:13 markus Exp $"); +RCSID("$OpenBSD: scp.c,v 1.102 2003/03/05 22:33:43 markus Exp $"); #include "xmalloc.h" #include "atomicio.h" @@ -395,10 +395,14 @@ toremote(targ, argc, argv) suser = argv[i]; if (*suser == '\0') suser = pwd->pw_name; - else if (!okname(suser)) + else if (!okname(suser)) { + xfree(bp); continue; - if (tuser && !okname(tuser)) + } + if (tuser && !okname(tuser)) { + xfree(bp); continue; + } snprintf(bp, len, "%s%s %s -n " "-l %s %s %s %s '%s%s%s:%s'", diff --git a/session.c b/session.c index a1586d3b4..ce9db27ef 100644 --- a/session.c +++ b/session.c @@ -33,7 +33,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: session.c,v 1.153 2003/02/06 09:26:23 markus Exp $"); +RCSID("$OpenBSD: session.c,v 1.154 2003/03/05 22:33:43 markus Exp $"); #include "ssh.h" #include "ssh1.h" @@ -951,7 +951,7 @@ do_setup_env(Session *s, const char *shell) { char buf[256]; u_int i, envsize; - char **env; + char **env, *laddr; struct passwd *pw = s->pw; /* Initialize the environment. */ @@ -1030,9 +1030,10 @@ do_setup_env(Session *s, const char *shell) get_remote_ipaddr(), get_remote_port(), get_local_port()); child_set_env(&env, &envsize, "SSH_CLIENT", buf); + laddr = get_local_ipaddr(packet_get_connection_in()); snprintf(buf, sizeof buf, "%.50s %d %.50s %d", - get_remote_ipaddr(), get_remote_port(), - get_local_ipaddr(packet_get_connection_in()), get_local_port()); + get_remote_ipaddr(), get_remote_port(), laddr, get_local_port()); + xfree(laddr); child_set_env(&env, &envsize, "SSH_CONNECTION", buf); if (s->ttyfd != -1) diff --git a/sftp-client.c b/sftp-client.c index 8c12dae11..3b3279e65 100644 --- a/sftp-client.c +++ b/sftp-client.c @@ -28,7 +28,7 @@ /* XXX: copy between two remote sites */ #include "includes.h" -RCSID("$OpenBSD: sftp-client.c,v 1.41 2003/01/14 10:58:00 djm Exp $"); +RCSID("$OpenBSD: sftp-client.c,v 1.42 2003/03/05 22:33:43 markus Exp $"); #include "openbsd-compat/sys-queue.h" @@ -374,6 +374,7 @@ do_lsreaddir(struct sftp_conn *conn, char *path, int printflag, error("Couldn't read directory: %s", fx2txt(status)); do_close(conn, handle, handle_len); + xfree(handle); return(status); } } else if (type != SSH2_FXP_NAME) @@ -1113,6 +1114,8 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path, remote_path, fx2txt(status)); do_close(conn, handle, handle_len); close(local_fd); + xfree(data); + xfree(ack); goto done; } debug3("In write loop, ack for %u %u bytes at %llu", diff --git a/sftp-int.c b/sftp-int.c index 013ea84e0..6987de9a3 100644 --- a/sftp-int.c +++ b/sftp-int.c @@ -25,7 +25,7 @@ /* XXX: recursive operations */ #include "includes.h" -RCSID("$OpenBSD: sftp-int.c,v 1.56 2003/01/16 03:41:55 djm Exp $"); +RCSID("$OpenBSD: sftp-int.c,v 1.57 2003/03/05 22:33:43 markus Exp $"); #include "buffer.h" #include "xmalloc.h" @@ -1104,6 +1104,7 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2) err = parse_dispatch_command(conn, cmd, &pwd, 1); xfree(dir); + xfree(pwd); return (err); } xfree(dir); diff --git a/sftp-server.c b/sftp-server.c index 4eb31d94e..0c00003f8 100644 --- a/sftp-server.c +++ b/sftp-server.c @@ -22,7 +22,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "includes.h" -RCSID("$OpenBSD: sftp-server.c,v 1.39 2003/02/06 09:29:18 markus Exp $"); +RCSID("$OpenBSD: sftp-server.c,v 1.40 2003/03/05 22:33:43 markus Exp $"); #include "buffer.h" #include "bufaux.h" @@ -158,7 +158,7 @@ handle_new(int use, char *name, int fd, DIR *dirp) handles[i].use = use; handles[i].dirp = dirp; handles[i].fd = fd; - handles[i].name = name; + handles[i].name = xstrdup(name); return i; } } @@ -230,9 +230,11 @@ handle_close(int handle) if (handle_is_ok(handle, HANDLE_FILE)) { ret = close(handles[handle].fd); handles[handle].use = HANDLE_UNUSED; + xfree(handles[handle].name); } else if (handle_is_ok(handle, HANDLE_DIR)) { ret = closedir(handles[handle].dirp); handles[handle].use = HANDLE_UNUSED; + xfree(handles[handle].name); } else { errno = ENOENT; } @@ -396,7 +398,7 @@ process_open(void) if (fd < 0) { status = errno_to_portable(errno); } else { - handle = handle_new(HANDLE_FILE, xstrdup(name), fd, NULL); + handle = handle_new(HANDLE_FILE, name, fd, NULL); if (handle < 0) { close(fd); } else { @@ -681,7 +683,7 @@ process_opendir(void) if (dirp == NULL) { status = errno_to_portable(errno); } else { - handle = handle_new(HANDLE_DIR, xstrdup(path), 0, dirp); + handle = handle_new(HANDLE_DIR, path, 0, dirp); if (handle < 0) { closedir(dirp); } else { diff --git a/ssh-add.c b/ssh-add.c index 0c2ce163c..9adec3094 100644 --- a/ssh-add.c +++ b/ssh-add.c @@ -35,7 +35,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: ssh-add.c,v 1.65 2003/01/23 13:50:27 markus Exp $"); +RCSID("$OpenBSD: ssh-add.c,v 1.66 2003/03/05 22:33:43 markus Exp $"); #include @@ -195,6 +195,7 @@ static int update_card(AuthenticationConnection *ac, int add, const char *id) { char *pin; + int ret = -1; pin = read_passphrase("Enter passphrase for smartcard: ", RP_ALLOW_STDIN); if (pin == NULL) @@ -203,12 +204,14 @@ update_card(AuthenticationConnection *ac, int add, const char *id) if (ssh_update_card(ac, add, id, pin)) { fprintf(stderr, "Card %s: %s\n", add ? "added" : "removed", id); - return 0; + ret = 0; } else { fprintf(stderr, "Could not %s card: %s\n", add ? "add" : "remove", id); - return -1; + ret = -1; } + xfree(pin); + return ret; } static int diff --git a/sshconnect2.c b/sshconnect2.c index 81d1b91c7..1f92f0296 100644 --- a/sshconnect2.c +++ b/sshconnect2.c @@ -23,7 +23,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: sshconnect2.c,v 1.111 2003/02/16 17:09:57 markus Exp $"); +RCSID("$OpenBSD: sshconnect2.c,v 1.112 2003/03/05 22:33:43 markus Exp $"); #include "ssh.h" #include "ssh2.h" @@ -1014,6 +1014,7 @@ userauth_hostbased(Authctxt *authctxt) strlcpy(chost, p, len); strlcat(chost, ".", len); debug2("userauth_hostbased: chost %s", chost); + xfree(p); service = datafellows & SSH_BUG_HBSERVICE ? "ssh-userauth" : authctxt->service; -- cgit v1.2.3