1
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:
HD Moore 2007-10-20 20:40:41 +00:00
parent 3ef7814e8e
commit adbd594a5b
2 changed files with 42 additions and 7 deletions

Binary file not shown.

View File

@ -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);
}