diff options
Diffstat (limited to 'sftp.c')
-rw-r--r-- | sftp.c | 37 |
1 files changed, 23 insertions, 14 deletions
@@ -24,9 +24,7 @@ | |||
24 | 24 | ||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | 26 | ||
27 | RCSID("$OpenBSD: sftp.c,v 1.34 2003/01/10 08:19:07 fgsch Exp $"); | 27 | RCSID("$OpenBSD: sftp.c,v 1.37 2003/07/10 20:05:55 markus Exp $"); |
28 | |||
29 | /* XXX: short-form remote directory listings (like 'ls -C') */ | ||
30 | 28 | ||
31 | #include "buffer.h" | 29 | #include "buffer.h" |
32 | #include "xmalloc.h" | 30 | #include "xmalloc.h" |
@@ -48,11 +46,21 @@ char *__progname; | |||
48 | FILE* infile; | 46 | FILE* infile; |
49 | size_t copy_buffer_len = 32768; | 47 | size_t copy_buffer_len = 32768; |
50 | size_t num_requests = 16; | 48 | size_t num_requests = 16; |
49 | static pid_t sshpid = -1; | ||
51 | 50 | ||
52 | extern int showprogress; | 51 | extern int showprogress; |
53 | 52 | ||
54 | static void | 53 | static void |
55 | connect_to_server(char *path, char **args, int *in, int *out, pid_t *sshpid) | 54 | killchild(int signo) |
55 | { | ||
56 | if (sshpid > 1) | ||
57 | kill(sshpid, signo); | ||
58 | |||
59 | _exit(1); | ||
60 | } | ||
61 | |||
62 | static void | ||
63 | connect_to_server(char *path, char **args, int *in, int *out) | ||
56 | { | 64 | { |
57 | int c_in, c_out; | 65 | int c_in, c_out; |
58 | 66 | ||
@@ -74,9 +82,9 @@ connect_to_server(char *path, char **args, int *in, int *out, pid_t *sshpid) | |||
74 | c_in = c_out = inout[1]; | 82 | c_in = c_out = inout[1]; |
75 | #endif /* USE_PIPES */ | 83 | #endif /* USE_PIPES */ |
76 | 84 | ||
77 | if ((*sshpid = fork()) == -1) | 85 | if ((sshpid = fork()) == -1) |
78 | fatal("fork: %s", strerror(errno)); | 86 | fatal("fork: %s", strerror(errno)); |
79 | else if (*sshpid == 0) { | 87 | else if (sshpid == 0) { |
80 | if ((dup2(c_in, STDIN_FILENO) == -1) || | 88 | if ((dup2(c_in, STDIN_FILENO) == -1) || |
81 | (dup2(c_out, STDOUT_FILENO) == -1)) { | 89 | (dup2(c_out, STDOUT_FILENO) == -1)) { |
82 | fprintf(stderr, "dup2: %s\n", strerror(errno)); | 90 | fprintf(stderr, "dup2: %s\n", strerror(errno)); |
@@ -91,6 +99,9 @@ connect_to_server(char *path, char **args, int *in, int *out, pid_t *sshpid) | |||
91 | exit(1); | 99 | exit(1); |
92 | } | 100 | } |
93 | 101 | ||
102 | signal(SIGTERM, killchild); | ||
103 | signal(SIGINT, killchild); | ||
104 | signal(SIGHUP, killchild); | ||
94 | close(c_in); | 105 | close(c_in); |
95 | close(c_out); | 106 | close(c_out); |
96 | } | 107 | } |
@@ -101,8 +112,9 @@ usage(void) | |||
101 | extern char *__progname; | 112 | extern char *__progname; |
102 | 113 | ||
103 | fprintf(stderr, | 114 | fprintf(stderr, |
104 | "usage: %s [-vC1] [-b batchfile] [-o option] [-s subsystem|path] [-B buffer_size]\n" | 115 | "usage: %s [-vC1] [-b batchfile] [-o ssh_option] [-s subsystem | sftp_server]\n" |
105 | " [-F config] [-P direct server path] [-S program]\n" | 116 | " [-B buffer_size] [-F ssh_config] [-P sftp_server path]\n" |
117 | " [-R num_requests] [-S program]\n" | ||
106 | " [user@]host[:file [file]]\n", __progname); | 118 | " [user@]host[:file [file]]\n", __progname); |
107 | exit(1); | 119 | exit(1); |
108 | } | 120 | } |
@@ -111,7 +123,6 @@ int | |||
111 | main(int argc, char **argv) | 123 | main(int argc, char **argv) |
112 | { | 124 | { |
113 | int in, out, ch, err; | 125 | int in, out, ch, err; |
114 | pid_t sshpid; | ||
115 | char *host, *userhost, *cp, *file2; | 126 | char *host, *userhost, *cp, *file2; |
116 | int debug_level = 0, sshver = 2; | 127 | int debug_level = 0, sshver = 2; |
117 | char *file1 = NULL, *sftp_server = NULL; | 128 | char *file1 = NULL, *sftp_server = NULL; |
@@ -121,7 +132,7 @@ main(int argc, char **argv) | |||
121 | extern int optind; | 132 | extern int optind; |
122 | extern char *optarg; | 133 | extern char *optarg; |
123 | 134 | ||
124 | __progname = get_progname(argv[0]); | 135 | __progname = ssh_get_progname(argv[0]); |
125 | args.list = NULL; | 136 | args.list = NULL; |
126 | addargs(&args, "ssh"); /* overwritten with ssh_program */ | 137 | addargs(&args, "ssh"); /* overwritten with ssh_program */ |
127 | addargs(&args, "-oForwardX11 no"); | 138 | addargs(&args, "-oForwardX11 no"); |
@@ -229,15 +240,13 @@ main(int argc, char **argv) | |||
229 | args.list[0] = ssh_program; | 240 | args.list[0] = ssh_program; |
230 | 241 | ||
231 | fprintf(stderr, "Connecting to %s...\n", host); | 242 | fprintf(stderr, "Connecting to %s...\n", host); |
232 | connect_to_server(ssh_program, args.list, &in, &out, | 243 | connect_to_server(ssh_program, args.list, &in, &out); |
233 | &sshpid); | ||
234 | } else { | 244 | } else { |
235 | args.list = NULL; | 245 | args.list = NULL; |
236 | addargs(&args, "sftp-server"); | 246 | addargs(&args, "sftp-server"); |
237 | 247 | ||
238 | fprintf(stderr, "Attaching to %s...\n", sftp_direct); | 248 | fprintf(stderr, "Attaching to %s...\n", sftp_direct); |
239 | connect_to_server(sftp_direct, args.list, &in, &out, | 249 | connect_to_server(sftp_direct, args.list, &in, &out); |
240 | &sshpid); | ||
241 | } | 250 | } |
242 | 251 | ||
243 | err = interactive_loop(in, out, file1, file2); | 252 | err = interactive_loop(in, out, file1, file2); |