Merge branch 'stat-struct-fixes'

Conflicts:
	data/meterpreter/ext_server_stdapi.lso
unstable
James Lee 2012-01-27 19:07:27 -07:00
commit e48da7b7db
5 changed files with 62 additions and 5 deletions

View File

@ -21,7 +21,7 @@ DWORD request_fs_ls(Remote *remote, Packet *packet)
LPSTR expanded = NULL, tempFile = NULL;
DWORD tempFileSize = 0;
LPSTR baseDirectory = NULL;
struct stat buf;
struct meterp_stat buf;
directory = packet_get_tlv_value_string(packet, TLV_TYPE_DIRECTORY_PATH);
@ -150,7 +150,7 @@ DWORD request_fs_ls(Remote *remote, Packet *packet)
tempFile);
// Stat the file to get more information about it.
if (stat(tempFile, &buf) >= 0)
if (fs_stat(tempFile, &buf) >= 0)
packet_add_tlv_raw(response, TLV_TYPE_STAT_BUF, &buf,
sizeof(buf));

View File

@ -257,7 +257,7 @@ DWORD request_fs_separator(Remote *remote, Packet *packet)
DWORD request_fs_stat(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
struct stat buf;
struct meterp_stat buf;
LPCSTR filePath;
LPSTR expanded = NULL;
DWORD result = ERROR_SUCCESS;
@ -273,7 +273,7 @@ DWORD request_fs_stat(Remote *remote, Packet *packet)
{
// Stat the file using the Microsoft stat wrapper so that we don't have to
// do translations
if (stat(expanded, &buf) < 0)
if (fs_stat(expanded, &buf) < 0)
result = GetLastError();
else
packet_add_tlv_raw(response, TLV_TYPE_STAT_BUF, &buf,

View File

@ -24,4 +24,33 @@ DWORD request_fs_sha1(Remote *remote, Packet *packet);
*/
DWORD request_fs_file_channel_open(Remote *remote, Packet *packet);
/*
* Stat structures on Windows and various Unixes are all slightly different.
* Use this as a means of standardization so the client has some hope of
* understanding what the stat'd file really is.
*/
struct meterp_stat {
unsigned int st_dev;
unsigned short st_ino;
unsigned short st_mode;
unsigned short st_nlink;
unsigned short st_uid;
unsigned short st_gid;
unsigned short pad;
unsigned int st_rdev;
unsigned int st_size;
/*
* These are always 64-bits on Windows and usually 32-bits on Linux. Force
* them to be the same size everywhere.
*/
unsigned long long st_atime;
unsigned long long st_mtime;
unsigned long long st_ctime;
};
int fs_stat(LPCSTR filename, struct meterp_stat *buf);
#endif

View File

@ -1,4 +1,5 @@
#include "precomp.h"
#include "fs.h"
/*
* Returns an expanded file path that must be freed
@ -37,4 +38,31 @@ LPSTR fs_expand_path(LPCSTR regular)
strcpy(expandedFilePath, regular);
return expandedFilePath;
#endif
}
}
/*
* Fills the platform-independent meterp_stat buf with data from the platform-dependent stat()
*/
int fs_stat(LPCSTR filename, struct meterp_stat *buf) {
struct stat sbuf;
int ret;
ret = stat(filename, &sbuf);
if (ret == 0) {
buf->st_dev = sbuf.st_dev;
buf->st_ino = sbuf.st_ino;
buf->st_mode = sbuf.st_mode;
buf->st_nlink = sbuf.st_nlink;
buf->st_uid = sbuf.st_uid;
buf->st_gid = sbuf.st_gid;
buf->st_rdev = sbuf.st_rdev;
buf->st_size = sbuf.st_size;
buf->st_atime = (unsigned long long)sbuf.st_atime;
buf->st_mtime = (unsigned long long)sbuf.st_mtime;
buf->st_ctime = (unsigned long long)sbuf.st_ctime;
return 0;
} else {
return ret;
}
}