version 1.26, 2001/03/07 10:11:23 |
version 1.27, 2001/03/13 22:42:54 |
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
*/ |
|
|
/* XXX: finish implementation of all commands */ |
|
/* XXX: do fnmatch() instead of using raw pathname */ |
|
/* XXX: globbed ls */ |
/* XXX: globbed ls */ |
/* XXX: recursive operations */ |
/* XXX: recursive operations */ |
|
|
#include "includes.h" |
#include "includes.h" |
RCSID("$OpenBSD$"); |
RCSID("$OpenBSD$"); |
|
|
|
#include <glob.h> |
|
|
#include "buffer.h" |
#include "buffer.h" |
#include "xmalloc.h" |
#include "xmalloc.h" |
#include "log.h" |
#include "log.h" |
|
|
|
|
#include "sftp.h" |
#include "sftp.h" |
#include "sftp-common.h" |
#include "sftp-common.h" |
|
#include "sftp-glob.h" |
#include "sftp-client.h" |
#include "sftp-client.h" |
#include "sftp-int.h" |
#include "sftp-int.h" |
|
|
|
|
{ |
{ |
char *cp; |
char *cp; |
|
|
debug("XXX: P = \"%s\"", p); |
|
|
|
cp = strrchr(p, '/'); |
cp = strrchr(p, '/'); |
if (cp == NULL) { |
if (cp == NULL) { |
*ifp = xstrdup(p); |
*ifp = xstrdup(p); |
|
|
/* Try to get second pathname (optional) */ |
/* Try to get second pathname (optional) */ |
if (get_pathname(&cp, path2)) |
if (get_pathname(&cp, path2)) |
return(-1); |
return(-1); |
/* Otherwise try to guess it from first path */ |
|
if (*path2 == NULL && infer_path(*path1, path2)) |
|
return(-1); |
|
break; |
break; |
case I_RENAME: |
case I_RENAME: |
case I_SYMLINK: |
case I_SYMLINK: |
|
|
parse_dispatch_command(int in, int out, const char *cmd, char **pwd) |
parse_dispatch_command(int in, int out, const char *cmd, char **pwd) |
{ |
{ |
char *path1, *path2, *tmp; |
char *path1, *path2, *tmp; |
int pflag, cmdnum; |
int pflag, cmdnum, i; |
unsigned long n_arg; |
unsigned long n_arg; |
Attrib a, *aa; |
Attrib a, *aa; |
char path_buf[MAXPATHLEN]; |
char path_buf[MAXPATHLEN]; |
int err = 0; |
int err = 0; |
|
glob_t g; |
|
|
path1 = path2 = NULL; |
path1 = path2 = NULL; |
cmdnum = parse_args(&cmd, &pflag, &n_arg, &path1, &path2); |
cmdnum = parse_args(&cmd, &pflag, &n_arg, &path1, &path2); |
|
|
case -1: |
case -1: |
break; |
break; |
case I_GET: |
case I_GET: |
path1 = make_absolute(path1, *pwd); |
memset(&g, 0, sizeof(g)); |
err = do_download(in, out, path1, path2, pflag); |
if (!remote_glob(in, out, path1, 0, NULL, &g)) { |
|
if (path2) { |
|
/* XXX: target should be directory */ |
|
error("You cannot specify a target when " |
|
"downloading multiple files"); |
|
err = -1; |
|
break; |
|
} |
|
for(i = 0; g.gl_pathv[i]; i++) { |
|
if (!infer_path(g.gl_pathv[i], &path2)) { |
|
printf("Fetching %s\n", g.gl_pathv[i]); |
|
if (do_download(in, out, g.gl_pathv[i], |
|
path2, pflag) == -1) |
|
err = -1; |
|
free(path2); |
|
path2 = NULL; |
|
} else |
|
err = -1; |
|
} |
|
} else { |
|
if (!path2 && infer_path(path1, &path2)) { |
|
err = -1; |
|
break; |
|
} |
|
err = do_download(in, out, path1, path2, pflag); |
|
} |
break; |
break; |
case I_PUT: |
case I_PUT: |
path2 = make_absolute(path2, *pwd); |
if (!glob(path1, 0, NULL, &g)) { |
err = do_upload(in, out, path1, path2, pflag); |
if (path2) { |
break; |
error("You cannot specify a target when " |
case I_RENAME: |
"uploading multiple files"); |
|
err = -1; |
|
break; |
|
} |
|
for(i = 0; g.gl_pathv[i]; i++) { |
|
if (!infer_path(g.gl_pathv[i], &path2)) { |
|
path2 = make_absolute(path2, *pwd); |
|
printf("Uploading %s\n", g.gl_pathv[i]); |
|
if (do_upload(in, out, g.gl_pathv[i], |
|
path2, pflag) == -1) |
|
err = -1; |
|
free(path2); |
|
path2 = NULL; |
|
} else |
|
err = -1; |
|
} |
|
} else { |
|
if (!path2 && infer_path(path1, &path2)) { |
|
err = -1; |
|
break; |
|
} |
|
err = do_upload(in, out, path1, path2, pflag); |
|
} |
|
break; |
|
case I_RENAME: |
path1 = make_absolute(path1, *pwd); |
path1 = make_absolute(path1, *pwd); |
path2 = make_absolute(path2, *pwd); |
path2 = make_absolute(path2, *pwd); |
err = do_rename(in, out, path1, path2); |
err = do_rename(in, out, path1, path2); |
|
|
break; |
break; |
case I_RM: |
case I_RM: |
path1 = make_absolute(path1, *pwd); |
path1 = make_absolute(path1, *pwd); |
err = do_rm(in, out, path1); |
remote_glob(in, out, path1, GLOB_NOCHECK, NULL, &g); |
|
for(i = 0; g.gl_pathv[i]; i++) { |
|
printf("Removing %s\n", g.gl_pathv[i]); |
|
if (do_rm(in, out, g.gl_pathv[i]) == -1) |
|
err = -1; |
|
} |
break; |
break; |
case I_MKDIR: |
case I_MKDIR: |
path1 = make_absolute(path1, *pwd); |
path1 = make_absolute(path1, *pwd); |
|
|
attrib_clear(&a); |
attrib_clear(&a); |
a.flags |= SSH2_FILEXFER_ATTR_PERMISSIONS; |
a.flags |= SSH2_FILEXFER_ATTR_PERMISSIONS; |
a.perm = n_arg; |
a.perm = n_arg; |
do_setstat(in, out, path1, &a); |
remote_glob(in, out, path1, GLOB_NOCHECK, NULL, &g); |
|
for(i = 0; g.gl_pathv[i]; i++) { |
|
printf("Changing mode on %s\n", g.gl_pathv[i]); |
|
do_setstat(in, out, g.gl_pathv[i], &a); |
|
} |
break; |
break; |
case I_CHOWN: |
case I_CHOWN: |
path1 = make_absolute(path1, *pwd); |
path1 = make_absolute(path1, *pwd); |
if (!(aa = do_stat(in, out, path1))) |
remote_glob(in, out, path1, GLOB_NOCHECK, NULL, &g); |
break; |
for(i = 0; g.gl_pathv[i]; i++) { |
if (!(aa->flags & SSH2_FILEXFER_ATTR_UIDGID)) { |
if (!(aa = do_stat(in, out, g.gl_pathv[i]))) |
error("Can't get current ownership of " |
continue; |
"remote file \"%s\"", path1); |
if (!(aa->flags & SSH2_FILEXFER_ATTR_UIDGID)) { |
break; |
error("Can't get current ownership of " |
|
"remote file \"%s\"", g.gl_pathv[i]); |
|
continue; |
|
} |
|
printf("Changing owner on %s\n", g.gl_pathv[i]); |
|
aa->flags &= SSH2_FILEXFER_ATTR_UIDGID; |
|
aa->uid = n_arg; |
|
do_setstat(in, out, g.gl_pathv[i], aa); |
} |
} |
aa->flags &= SSH2_FILEXFER_ATTR_UIDGID; |
|
aa->uid = n_arg; |
|
do_setstat(in, out, path1, aa); |
|
break; |
break; |
case I_CHGRP: |
case I_CHGRP: |
path1 = make_absolute(path1, *pwd); |
path1 = make_absolute(path1, *pwd); |
if (!(aa = do_stat(in, out, path1))) |
remote_glob(in, out, path1, GLOB_NOCHECK, NULL, &g); |
break; |
for(i = 0; g.gl_pathv[i]; i++) { |
if (!(aa->flags & SSH2_FILEXFER_ATTR_UIDGID)) { |
if (!(aa = do_stat(in, out, g.gl_pathv[i]))) |
error("Can't get current ownership of " |
continue; |
"remote file \"%s\"", path1); |
if (!(aa->flags & SSH2_FILEXFER_ATTR_UIDGID)) { |
break; |
error("Can't get current ownership of " |
|
"remote file \"%s\"", g.gl_pathv[i]); |
|
continue; |
|
} |
|
printf("Changing group on %s\n", g.gl_pathv[i]); |
|
aa->flags &= SSH2_FILEXFER_ATTR_UIDGID; |
|
aa->gid = n_arg; |
|
do_setstat(in, out, g.gl_pathv[i], aa); |
} |
} |
aa->flags &= SSH2_FILEXFER_ATTR_UIDGID; |
|
aa->gid = n_arg; |
|
do_setstat(in, out, path1, aa); |
|
break; |
break; |
case I_PWD: |
case I_PWD: |
printf("Remote working directory: %s\n", *pwd); |
printf("Remote working directory: %s\n", *pwd); |