mirror of
https://github.com/rapid7/metasploit-framework
synced 2024-11-12 11:52:01 +01:00
The cp command now handles destination directory names and preserves permissions
git-svn-id: file:///home/svn/framework3/trunk@5170 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
parent
3ef7814e8e
commit
adbd594a5b
BIN
data/ipwn/ipwn
BIN
data/ipwn/ipwn
Binary file not shown.
49
external/source/ipwn/cmd_fs.c
vendored
49
external/source/ipwn/cmd_fs.c
vendored
@ -258,17 +258,49 @@ void cmd_cp(int argc, char * argv[])
|
||||
{
|
||||
int src, dst, len;
|
||||
char buff[4096];
|
||||
struct stat s;
|
||||
char *path, *p, *t;
|
||||
|
||||
path = strdup(argv[2]);
|
||||
|
||||
src = open(argv[1], O_RDONLY);
|
||||
if(src == -1)
|
||||
if(src == -1) {
|
||||
free(path);
|
||||
perror("open(src)");
|
||||
|
||||
dst = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, S_IRWXU);
|
||||
if (dst == -1) {
|
||||
close(src);
|
||||
perror("open(dst)");
|
||||
}
|
||||
|
||||
dst = open(path, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU);
|
||||
if (dst == -1) {
|
||||
|
||||
if(errno == EISDIR) {
|
||||
t = strrchr(argv[1], '/');
|
||||
if (t != NULL) {
|
||||
t++;
|
||||
} else {
|
||||
t = argv[1];
|
||||
}
|
||||
|
||||
p = malloc(strlen(path) + strlen(t) + 1);
|
||||
sprintf(p, "%s/%s", path, t);
|
||||
free(path);
|
||||
path = p;
|
||||
|
||||
dst = open(path, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU);
|
||||
if ( dst == -1 ) {
|
||||
close(src);
|
||||
free(path);
|
||||
perror("open(dst)");
|
||||
}
|
||||
|
||||
} else {
|
||||
close(src);
|
||||
free(path);
|
||||
perror("open(dst)");
|
||||
}
|
||||
}
|
||||
|
||||
stat(argv[1], &s);
|
||||
|
||||
while(1)
|
||||
{
|
||||
len = read(src, buff, sizeof(buff));
|
||||
@ -279,5 +311,8 @@ void cmd_cp(int argc, char * argv[])
|
||||
if (len < sizeof(buff)) break;
|
||||
}
|
||||
close(src);
|
||||
close(dst);
|
||||
close(dst);
|
||||
|
||||
chmod(path, s.st_mode);
|
||||
free(path);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user