version 1.75, 2006/02/20 17:19:54 |
version 1.75.2.2, 2006/11/08 00:17:14 |
|
|
|
/* $OpenBSD$ */ |
/* |
/* |
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> |
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> |
* |
* |
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
*/ |
*/ |
|
|
#include "includes.h" |
|
RCSID("$OpenBSD$"); |
|
|
|
#include <sys/ioctl.h> |
|
#include <sys/types.h> |
#include <sys/types.h> |
|
#include <sys/ioctl.h> |
#include <sys/wait.h> |
#include <sys/wait.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
|
#include <sys/socket.h> |
|
#include <sys/param.h> |
|
|
|
#include <errno.h> |
#include <glob.h> |
#include <glob.h> |
#include <histedit.h> |
#include <histedit.h> |
#include <paths.h> |
#include <paths.h> |
#include <signal.h> |
#include <signal.h> |
|
#include <stdlib.h> |
|
#include <stdio.h> |
|
#include <string.h> |
|
#include <unistd.h> |
|
#include <stdarg.h> |
|
|
#include "buffer.h" |
|
#include "xmalloc.h" |
#include "xmalloc.h" |
#include "log.h" |
#include "log.h" |
#include "pathnames.h" |
#include "pathnames.h" |
#include "misc.h" |
#include "misc.h" |
|
|
#include "sftp.h" |
#include "sftp.h" |
|
#include "buffer.h" |
#include "sftp-common.h" |
#include "sftp-common.h" |
#include "sftp-client.h" |
#include "sftp-client.h" |
|
|
|
|
if (errno != EINTR) |
if (errno != EINTR) |
fatal("Couldn't wait for child: %s", strerror(errno)); |
fatal("Couldn't wait for child: %s", strerror(errno)); |
if (!WIFEXITED(status)) |
if (!WIFEXITED(status)) |
error("Shell exited abormally"); |
error("Shell exited abnormally"); |
else if (WEXITSTATUS(status)) |
else if (WEXITSTATUS(status)) |
error("Shell exited with status %d", WEXITSTATUS(status)); |
error("Shell exited with status %d", WEXITSTATUS(status)); |
} |
} |
|
|
if (stat(path, &sb) == -1) |
if (stat(path, &sb) == -1) |
return(0); |
return(0); |
|
|
return(sb.st_mode & S_IFDIR); |
return(S_ISDIR(sb.st_mode)); |
} |
} |
|
|
static int |
static int |
|
|
return(0); |
return(0); |
if (!(a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)) |
if (!(a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)) |
return(0); |
return(0); |
return(a->perm & S_IFDIR); |
return(S_ISDIR(a->perm)); |
} |
} |
|
|
static int |
static int |
|
|
|
|
if (g.gl_matchc == 1 && dst) { |
if (g.gl_matchc == 1 && dst) { |
/* If directory specified, append filename */ |
/* If directory specified, append filename */ |
|
xfree(tmp); |
if (is_dir(dst)) { |
if (is_dir(dst)) { |
if (infer_path(g.gl_pathv[0], &tmp)) { |
if (infer_path(g.gl_pathv[0], &tmp)) { |
err = 1; |
err = 1; |
|
|
|
|
out: |
out: |
xfree(abs_src); |
xfree(abs_src); |
if (abs_dst) |
|
xfree(abs_dst); |
|
globfree(&g); |
globfree(&g); |
return(err); |
return(err); |
} |
} |
|
|
case I_CHOWN: |
case I_CHOWN: |
case I_CHGRP: |
case I_CHGRP: |
/* Get numeric arg (mandatory) */ |
/* Get numeric arg (mandatory) */ |
|
errno = 0; |
l = strtol(cp, &cp2, base); |
l = strtol(cp, &cp2, base); |
if (cp2 == cp || ((l == LONG_MIN || l == LONG_MAX) && |
if (cp2 == cp || ((l == LONG_MIN || l == LONG_MAX) && |
errno == ERANGE) || l < 0) { |
errno == ERANGE) || l < 0) { |
|
|
if (parse_dispatch_command(conn, cmd, &pwd, 1) != 0) { |
if (parse_dispatch_command(conn, cmd, &pwd, 1) != 0) { |
xfree(dir); |
xfree(dir); |
xfree(pwd); |
xfree(pwd); |
|
xfree(conn); |
return (-1); |
return (-1); |
} |
} |
} else { |
} else { |
|
|
err = parse_dispatch_command(conn, cmd, &pwd, 1); |
err = parse_dispatch_command(conn, cmd, &pwd, 1); |
xfree(dir); |
xfree(dir); |
xfree(pwd); |
xfree(pwd); |
|
xfree(conn); |
return (err); |
return (err); |
} |
} |
xfree(dir); |
xfree(dir); |
|
|
break; |
break; |
} |
} |
xfree(pwd); |
xfree(pwd); |
|
xfree(conn); |
|
|
if (el != NULL) |
if (el != NULL) |
el_end(el); |
el_end(el); |
|
|
{ |
{ |
int c_in, c_out; |
int c_in, c_out; |
|
|
#ifdef USE_PIPES |
|
int pin[2], pout[2]; |
|
|
|
if ((pipe(pin) == -1) || (pipe(pout) == -1)) |
|
fatal("pipe: %s", strerror(errno)); |
|
*in = pin[0]; |
|
*out = pout[1]; |
|
c_in = pout[0]; |
|
c_out = pin[1]; |
|
#else /* USE_PIPES */ |
|
int inout[2]; |
int inout[2]; |
|
|
if (socketpair(AF_UNIX, SOCK_STREAM, 0, inout) == -1) |
if (socketpair(AF_UNIX, SOCK_STREAM, 0, inout) == -1) |
fatal("socketpair: %s", strerror(errno)); |
fatal("socketpair: %s", strerror(errno)); |
*in = *out = inout[0]; |
*in = *out = inout[0]; |
c_in = c_out = inout[1]; |
c_in = c_out = inout[1]; |
#endif /* USE_PIPES */ |
|
|
|
if ((sshpid = fork()) == -1) |
if ((sshpid = fork()) == -1) |
fatal("fork: %s", strerror(errno)); |
fatal("fork: %s", strerror(errno)); |
|
|
|
|
memset(&args, '\0', sizeof(args)); |
memset(&args, '\0', sizeof(args)); |
args.list = NULL; |
args.list = NULL; |
addargs(&args, ssh_program); |
addargs(&args, "%s", ssh_program); |
addargs(&args, "-oForwardX11 no"); |
addargs(&args, "-oForwardX11 no"); |
addargs(&args, "-oForwardAgent no"); |
addargs(&args, "-oForwardAgent no"); |
addargs(&args, "-oPermitLocalCommand no"); |
addargs(&args, "-oPermitLocalCommand no"); |