summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2009-10-07 08:24:19 +1100
committerDarren Tucker <dtucker@zip.com.au>2009-10-07 08:24:19 +1100
commitc22f090a2f4ac309d1d44a6bbafdefb1e8de532a (patch)
tree283084e47a0260dc2f1a3dcb17ea809d2539aaca
parentc07138e6f6a9173d0315cceb123e3bc4abbd1528 (diff)
- djm@cvs.openbsd.org 2009/08/14 18:17:49
[sftp-client.c] make the "get_handle: ..." error messages vaguely useful by allowing callers to specify their own error message strings.
-rw-r--r--ChangeLog4
-rw-r--r--sftp-client.c39
2 files changed, 31 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 9afa9e820..5b4737632 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -21,6 +21,10 @@
21 - jmc@cvs.openbsd.org 2009/08/13 13:39:54 21 - jmc@cvs.openbsd.org 2009/08/13 13:39:54
22 [sftp.1 sftp.c] 22 [sftp.1 sftp.c]
23 sync synopsis and usage(); 23 sync synopsis and usage();
24 - djm@cvs.openbsd.org 2009/08/14 18:17:49
25 [sftp-client.c]
26 make the "get_handle: ..." error messages vaguely useful by allowing
27 callers to specify their own error message strings.
24 28
2520091002 2920091002
26 - (djm) [Makefile.in] Mention readconf.o in ssh-keysign's make deps. 30 - (djm) [Makefile.in] Mention readconf.o in ssh-keysign's make deps.
diff --git a/sftp-client.c b/sftp-client.c
index 0990b7912..14c172d2f 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-client.c,v 1.87 2009/06/22 05:39:28 dtucker Exp $ */ 1/* $OpenBSD: sftp-client.c,v 1.88 2009/08/14 18:17:49 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -74,6 +74,10 @@ struct sftp_conn {
74 u_int exts; 74 u_int exts;
75}; 75};
76 76
77static char *
78get_handle(int fd, u_int expected_id, u_int *len, const char *errfmt, ...)
79 __attribute__((format(printf, 4, 5)));
80
77static void 81static void
78send_msg(int fd, Buffer *m) 82send_msg(int fd, Buffer *m)
79{ 83{
@@ -179,11 +183,18 @@ get_status(int fd, u_int expected_id)
179} 183}
180 184
181static char * 185static char *
182get_handle(int fd, u_int expected_id, u_int *len) 186get_handle(int fd, u_int expected_id, u_int *len, const char *errfmt, ...)
183{ 187{
184 Buffer msg; 188 Buffer msg;
185 u_int type, id; 189 u_int type, id;
186 char *handle; 190 char *handle, errmsg[256];
191 va_list args;
192 int status;
193
194 va_start(args, errfmt);
195 if (errfmt != NULL)
196 vsnprintf(errmsg, sizeof(errmsg), errfmt, args);
197 va_end(args);
187 198
188 buffer_init(&msg); 199 buffer_init(&msg);
189 get_msg(fd, &msg); 200 get_msg(fd, &msg);
@@ -191,16 +202,17 @@ get_handle(int fd, u_int expected_id, u_int *len)
191 id = buffer_get_int(&msg); 202 id = buffer_get_int(&msg);
192 203
193 if (id != expected_id) 204 if (id != expected_id)
194 fatal("ID mismatch (%u != %u)", id, expected_id); 205 fatal("%s: ID mismatch (%u != %u)",
206 errfmt == NULL ? __func__ : errmsg, id, expected_id);
195 if (type == SSH2_FXP_STATUS) { 207 if (type == SSH2_FXP_STATUS) {
196 int status = buffer_get_int(&msg); 208 status = buffer_get_int(&msg);
197 209 if (errfmt != NULL)
198 error("Couldn't get handle: %s", fx2txt(status)); 210 error("%s: %s", errmsg, fx2txt(status));
199 buffer_free(&msg); 211 buffer_free(&msg);
200 return(NULL); 212 return(NULL);
201 } else if (type != SSH2_FXP_HANDLE) 213 } else if (type != SSH2_FXP_HANDLE)
202 fatal("Expected SSH2_FXP_HANDLE(%u) packet, got %u", 214 fatal("%s: Expected SSH2_FXP_HANDLE(%u) packet, got %u",
203 SSH2_FXP_HANDLE, type); 215 errfmt == NULL ? __func__ : errmsg, SSH2_FXP_HANDLE, type);
204 216
205 handle = buffer_get_string(&msg, len); 217 handle = buffer_get_string(&msg, len);
206 buffer_free(&msg); 218 buffer_free(&msg);
@@ -418,7 +430,8 @@ do_lsreaddir(struct sftp_conn *conn, char *path, int printflag,
418 430
419 buffer_clear(&msg); 431 buffer_clear(&msg);
420 432
421 handle = get_handle(conn->fd_in, id, &handle_len); 433 handle = get_handle(conn->fd_in, id, &handle_len,
434 "remote readdir(\"%s\")", path);
422 if (handle == NULL) 435 if (handle == NULL)
423 return(-1); 436 return(-1);
424 437
@@ -951,7 +964,8 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
951 send_msg(conn->fd_out, &msg); 964 send_msg(conn->fd_out, &msg);
952 debug3("Sent message SSH2_FXP_OPEN I:%u P:%s", id, remote_path); 965 debug3("Sent message SSH2_FXP_OPEN I:%u P:%s", id, remote_path);
953 966
954 handle = get_handle(conn->fd_in, id, &handle_len); 967 handle = get_handle(conn->fd_in, id, &handle_len,
968 "remote open(\"%s\")", remote_path);
955 if (handle == NULL) { 969 if (handle == NULL) {
956 buffer_free(&msg); 970 buffer_free(&msg);
957 return(-1); 971 return(-1);
@@ -1195,7 +1209,8 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
1195 1209
1196 buffer_clear(&msg); 1210 buffer_clear(&msg);
1197 1211
1198 handle = get_handle(conn->fd_in, id, &handle_len); 1212 handle = get_handle(conn->fd_in, id, &handle_len,
1213 "remote open(\"%s\")", remote_path);
1199 if (handle == NULL) { 1214 if (handle == NULL) {
1200 close(local_fd); 1215 close(local_fd);
1201 buffer_free(&msg); 1216 buffer_free(&msg);