diff options
Diffstat (limited to 'sftp-int.c')
-rw-r--r-- | sftp-int.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/sftp-int.c b/sftp-int.c index 7aa7abdb9..6f5b3677a 100644 --- a/sftp-int.c +++ b/sftp-int.c | |||
@@ -28,7 +28,7 @@ | |||
28 | /* XXX: recursive operations */ | 28 | /* XXX: recursive operations */ |
29 | 29 | ||
30 | #include "includes.h" | 30 | #include "includes.h" |
31 | RCSID("$OpenBSD: sftp-int.c,v 1.25 2001/03/06 06:11:44 deraadt Exp $"); | 31 | RCSID("$OpenBSD: sftp-int.c,v 1.26 2001/03/07 10:11:23 djm Exp $"); |
32 | 32 | ||
33 | #include "buffer.h" | 33 | #include "buffer.h" |
34 | #include "xmalloc.h" | 34 | #include "xmalloc.h" |
@@ -40,7 +40,11 @@ RCSID("$OpenBSD: sftp-int.c,v 1.25 2001/03/06 06:11:44 deraadt Exp $"); | |||
40 | #include "sftp-client.h" | 40 | #include "sftp-client.h" |
41 | #include "sftp-int.h" | 41 | #include "sftp-int.h" |
42 | 42 | ||
43 | extern FILE* infile; | 43 | /* File to read commands from */ |
44 | extern FILE *infile; | ||
45 | |||
46 | /* Version of server we are speaking to */ | ||
47 | int version; | ||
44 | 48 | ||
45 | /* Seperators for interactive commands */ | 49 | /* Seperators for interactive commands */ |
46 | #define WHITESPACE " \t\r\n" | 50 | #define WHITESPACE " \t\r\n" |
@@ -66,6 +70,7 @@ extern FILE* infile; | |||
66 | #define I_RM 18 | 70 | #define I_RM 18 |
67 | #define I_RMDIR 19 | 71 | #define I_RMDIR 19 |
68 | #define I_SHELL 20 | 72 | #define I_SHELL 20 |
73 | #define I_SYMLINK 21 | ||
69 | 74 | ||
70 | struct CMD { | 75 | struct CMD { |
71 | const char *c; | 76 | const char *c; |
@@ -86,6 +91,7 @@ const struct CMD cmds[] = { | |||
86 | { "lchdir", I_LCHDIR }, | 91 | { "lchdir", I_LCHDIR }, |
87 | { "lls", I_LLS }, | 92 | { "lls", I_LLS }, |
88 | { "lmkdir", I_LMKDIR }, | 93 | { "lmkdir", I_LMKDIR }, |
94 | { "ln", I_SYMLINK }, | ||
89 | { "lpwd", I_LPWD }, | 95 | { "lpwd", I_LPWD }, |
90 | { "ls", I_LS }, | 96 | { "ls", I_LS }, |
91 | { "lumask", I_LUMASK }, | 97 | { "lumask", I_LUMASK }, |
@@ -96,6 +102,7 @@ const struct CMD cmds[] = { | |||
96 | { "rename", I_RENAME }, | 102 | { "rename", I_RENAME }, |
97 | { "rm", I_RM }, | 103 | { "rm", I_RM }, |
98 | { "rmdir", I_RMDIR }, | 104 | { "rmdir", I_RMDIR }, |
105 | { "symlink", I_SYMLINK }, | ||
99 | { "!", I_SHELL }, | 106 | { "!", I_SHELL }, |
100 | { "?", I_HELP }, | 107 | { "?", I_HELP }, |
101 | { NULL, -1} | 108 | { NULL, -1} |
@@ -113,6 +120,7 @@ help(void) | |||
113 | printf("help Display this help text\n"); | 120 | printf("help Display this help text\n"); |
114 | printf("get remote-path [local-path] Download file\n"); | 121 | printf("get remote-path [local-path] Download file\n"); |
115 | printf("lls [ls-options [path]] Display local directory listing\n"); | 122 | printf("lls [ls-options [path]] Display local directory listing\n"); |
123 | printf("ln oldpath newpath Symlink remote file\n"); | ||
116 | printf("lmkdir path Create local directory\n"); | 124 | printf("lmkdir path Create local directory\n"); |
117 | printf("lpwd Print local working directory\n"); | 125 | printf("lpwd Print local working directory\n"); |
118 | printf("ls [path] Display remote directory listing\n"); | 126 | printf("ls [path] Display remote directory listing\n"); |
@@ -125,6 +133,7 @@ help(void) | |||
125 | printf("rename oldpath newpath Rename remote file\n"); | 133 | printf("rename oldpath newpath Rename remote file\n"); |
126 | printf("rmdir path Remove remote directory\n"); | 134 | printf("rmdir path Remove remote directory\n"); |
127 | printf("rm path Delete remote file\n"); | 135 | printf("rm path Delete remote file\n"); |
136 | printf("symlink oldpath newpath Symlink remote file\n"); | ||
128 | printf("!command Execute 'command' in local shell\n"); | 137 | printf("!command Execute 'command' in local shell\n"); |
129 | printf("! Escape to local shell\n"); | 138 | printf("! Escape to local shell\n"); |
130 | printf("? Synonym for help\n"); | 139 | printf("? Synonym for help\n"); |
@@ -356,7 +365,7 @@ parse_args(const char **cpp, int *pflag, unsigned long *n_arg, | |||
356 | return(-1); | 365 | return(-1); |
357 | break; | 366 | break; |
358 | case I_RENAME: | 367 | case I_RENAME: |
359 | /* Get first pathname (mandatory) */ | 368 | case I_SYMLINK: |
360 | if (get_pathname(&cp, path1)) | 369 | if (get_pathname(&cp, path1)) |
361 | return(-1); | 370 | return(-1); |
362 | if (get_pathname(&cp, path2)) | 371 | if (get_pathname(&cp, path2)) |
@@ -468,6 +477,16 @@ parse_dispatch_command(int in, int out, const char *cmd, char **pwd) | |||
468 | path2 = make_absolute(path2, *pwd); | 477 | path2 = make_absolute(path2, *pwd); |
469 | err = do_rename(in, out, path1, path2); | 478 | err = do_rename(in, out, path1, path2); |
470 | break; | 479 | break; |
480 | case I_SYMLINK: | ||
481 | if (version < 3) { | ||
482 | error("The server (version %d) does not support " | ||
483 | "this operation", version); | ||
484 | err = -1; | ||
485 | } else { | ||
486 | path2 = make_absolute(path2, *pwd); | ||
487 | err = do_symlink(in, out, path1, path2); | ||
488 | } | ||
489 | break; | ||
471 | case I_RM: | 490 | case I_RM: |
472 | path1 = make_absolute(path1, *pwd); | 491 | path1 = make_absolute(path1, *pwd); |
473 | err = do_rm(in, out, path1); | 492 | err = do_rm(in, out, path1); |
@@ -624,6 +643,10 @@ interactive_loop(int fd_in, int fd_out) | |||
624 | char *pwd; | 643 | char *pwd; |
625 | char cmd[2048]; | 644 | char cmd[2048]; |
626 | 645 | ||
646 | version = do_init(fd_in, fd_out); | ||
647 | if (version == -1) | ||
648 | fatal("Couldn't initialise connection to server"); | ||
649 | |||
627 | pwd = do_realpath(fd_in, fd_out, "."); | 650 | pwd = do_realpath(fd_in, fd_out, "."); |
628 | if (pwd == NULL) | 651 | if (pwd == NULL) |
629 | fatal("Need cwd"); | 652 | fatal("Need cwd"); |