mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
added extraction example to minitar
This commit is contained in:
parent
9789eb6768
commit
9ec90b741c
|
@ -65,7 +65,7 @@ add_sapi_library(
|
||||||
libarchive/libarchive/archive.h
|
libarchive/libarchive/archive.h
|
||||||
libarchive/libarchive/archive_entry.h
|
libarchive/libarchive/archive_entry.h
|
||||||
|
|
||||||
LIBRARY archive
|
LIBRARY archive_static
|
||||||
LIBRARY_NAME Libarchive
|
LIBRARY_NAME Libarchive
|
||||||
NAMESPACE ""
|
NAMESPACE ""
|
||||||
)
|
)
|
||||||
|
|
|
@ -25,7 +25,7 @@ std::vector<std::string> MakeAbsolutePathsVec(char *argv[]) {
|
||||||
|
|
||||||
|
|
||||||
std::string CheckStatusAndGetString(const sapi::StatusOr<char *> &status, LibarchiveSandbox &sandbox) {
|
std::string CheckStatusAndGetString(const sapi::StatusOr<char *> &status, LibarchiveSandbox &sandbox) {
|
||||||
CHECK(status.ok() && status.value()) << "Could not get error message";
|
CHECK(status.ok() && status.value() != NULL) << "Could not get error message";
|
||||||
|
|
||||||
sapi::StatusOr<std::string> ret = sandbox.GetCString(sapi::v::RemotePtr(status.value()));
|
sapi::StatusOr<std::string> ret = sandbox.GetCString(sapi::v::RemotePtr(status.value()));
|
||||||
CHECK(ret.ok()) << "Could not transfer error message";
|
CHECK(ret.ok()) << "Could not transfer error message";
|
||||||
|
|
|
@ -41,11 +41,16 @@ class SapiLibarchiveSandboxExtract : public LibarchiveSandbox {
|
||||||
.AllowWrite()
|
.AllowWrite()
|
||||||
.AllowOpen()
|
.AllowOpen()
|
||||||
.AllowSystemMalloc()
|
.AllowSystemMalloc()
|
||||||
|
.AllowGetIDs()
|
||||||
|
.AllowSafeFcntl()
|
||||||
|
.AllowStat()
|
||||||
|
.AllowExit()
|
||||||
.AllowSyscalls({
|
.AllowSyscalls({
|
||||||
__NR_futex,
|
__NR_futex,
|
||||||
__NR_lseek,
|
__NR_lseek,
|
||||||
__NR_close,
|
__NR_close,
|
||||||
__NR_gettid,
|
__NR_gettid,
|
||||||
|
__NR_umask,
|
||||||
})
|
})
|
||||||
.AddFile(archive_path_);
|
.AddFile(archive_path_);
|
||||||
|
|
||||||
|
|
|
@ -244,12 +244,13 @@ static void extract(const char *filename, int do_extract, int flags) {
|
||||||
api.archive_read_new().IgnoreError();
|
api.archive_read_new().IgnoreError();
|
||||||
sapi::StatusOr<archive *> ret = api.archive_read_new();
|
sapi::StatusOr<archive *> ret = api.archive_read_new();
|
||||||
CHECK(ret.ok()) << "archive_read_new call failed";
|
CHECK(ret.ok()) << "archive_read_new call failed";
|
||||||
CHECK(!ret.value()) << "Failed to create read archive";
|
// std::cout << "RET VALUE = " << ret.value() << std::endl;
|
||||||
|
CHECK(ret.value() != NULL) << "Failed to create read archive";
|
||||||
a = ret.value();
|
a = ret.value();
|
||||||
|
|
||||||
ret = api.archive_write_disk_new();
|
ret = api.archive_write_disk_new();
|
||||||
CHECK(ret.ok()) << "write_disk_new call failed";
|
CHECK(ret.ok()) << "write_disk_new call failed";
|
||||||
CHECK(!ret.value()) << "Failed to create write disk archive";
|
CHECK(ret.value() != NULL) << "Failed to create write disk archive";
|
||||||
ext = ret.value();
|
ext = ret.value();
|
||||||
|
|
||||||
sapi::v::RemotePtr a_ptr(a);
|
sapi::v::RemotePtr a_ptr(a);
|
||||||
|
@ -296,30 +297,40 @@ static void extract(const char *filename, int do_extract, int flags) {
|
||||||
filename = NULL;
|
filename = NULL;
|
||||||
|
|
||||||
sapi::v::ConstCStr sapi_filename(filename_absolute.c_str());
|
sapi::v::ConstCStr sapi_filename(filename_absolute.c_str());
|
||||||
|
|
||||||
|
std::cout << "opening filename" << std::endl;
|
||||||
|
|
||||||
ret2 = api.archive_read_open_filename(&a_ptr, sapi_filename.PtrBefore(), 10240);
|
ret2 = api.archive_read_open_filename(&a_ptr, sapi_filename.PtrBefore(), 10240);
|
||||||
CHECK(ret2.ok()) << "read_open_filename call failed";
|
CHECK(ret2.ok()) << "read_open_filename call failed";
|
||||||
// CHECK(!ret2.value()) << GetErrorString(&a_ptr, sandbox, api);
|
// CHECK(!ret2.value()) << GetErrorString(&a_ptr, sandbox, api);
|
||||||
CHECK(!ret2.value()) << CheckStatusAndGetString(api.archive_error_string(&a_ptr), sandbox);
|
CHECK(!ret2.value()) << CheckStatusAndGetString(api.archive_error_string(&a_ptr), sandbox);
|
||||||
// CHECK(!ret2.value()) << CallFunctionAndGetString(&a_ptr, sandbox, &api, &api.archive_error_string);
|
// CHECK(!ret2.value()) << CallFunctionAndGetString(&a_ptr, sandbox, &api, &api.archive_error_string);
|
||||||
|
|
||||||
|
sapi::v::IntBase<struct archive_entry *> entry_ptr_tmp(0);
|
||||||
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
sapi::v::IntBase<struct archive_entry *> entry_ptr_tmp(0);
|
|
||||||
|
|
||||||
|
std::cout << "================reading headers==============" << std::endl;
|
||||||
|
|
||||||
ret2 = api.archive_read_next_header(&a_ptr, entry_ptr_tmp.PtrBoth());
|
ret2 = api.archive_read_next_header(&a_ptr, entry_ptr_tmp.PtrBoth());
|
||||||
|
//std::cout << "val = " << ret2.value() << std::endl;
|
||||||
CHECK(ret2.ok()) << "read_next_header call failed";
|
CHECK(ret2.ok()) << "read_next_header call failed";
|
||||||
// CHECK(ret2.value() != ARCHIVE_OK) << GetErrorString(&a_ptr, sandbox, api);
|
// CHECK(ret2.value() != ARCHIVE_OK) << GetErrorString(&a_ptr, sandbox, api);
|
||||||
CHECK(ret2.value() != ARCHIVE_OK) << CheckStatusAndGetString(api.archive_error_string(&a_ptr), sandbox);
|
|
||||||
|
|
||||||
if(ret2.value() == ARCHIVE_EOF) {
|
if(ret2.value() == ARCHIVE_EOF) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHECK(ret2.value() == ARCHIVE_OK) << CheckStatusAndGetString(api.archive_error_string(&a_ptr), sandbox);
|
||||||
|
|
||||||
|
|
||||||
sapi::v::RemotePtr entry_ptr(entry_ptr_tmp.GetValue());
|
sapi::v::RemotePtr entry_ptr(entry_ptr_tmp.GetValue());
|
||||||
|
|
||||||
if(verbose && do_extract) {
|
if(verbose && do_extract) {
|
||||||
std::cout << "x " ;
|
std::cout << "x " ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (verbose || !do_extract) {
|
if (verbose || !do_extract) {
|
||||||
std::cout << CheckStatusAndGetString(api.archive_entry_pathname(&entry_ptr), sandbox) << " ";
|
std::cout << CheckStatusAndGetString(api.archive_entry_pathname(&entry_ptr), sandbox) << " ";
|
||||||
|
@ -331,7 +342,11 @@ static void extract(const char *filename, int do_extract, int flags) {
|
||||||
// use the needcr stuff here TODO
|
// use the needcr stuff here TODO
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
ret2 = api.archive_read_close(&a_ptr);
|
}
|
||||||
|
|
||||||
|
std::cout << "out of loop" << std::endl;
|
||||||
|
|
||||||
|
ret2 = api.archive_read_close(&a_ptr);
|
||||||
CHECK(ret2.ok()) << "read_close call failed";
|
CHECK(ret2.ok()) << "read_close call failed";
|
||||||
CHECK(!ret2.value()) << "Unexpected value from read_close call";
|
CHECK(!ret2.value()) << "Unexpected value from read_close call";
|
||||||
|
|
||||||
|
@ -349,8 +364,6 @@ static void extract(const char *filename, int do_extract, int flags) {
|
||||||
CHECK(ret2.ok()) << "write_free call failed";
|
CHECK(ret2.ok()) << "write_free call failed";
|
||||||
CHECK(!ret2.value()) << "Unexpected result from write_free call";
|
CHECK(!ret2.value()) << "Unexpected result from write_free call";
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int copy_data(struct archive *ar, struct archive *aw) {
|
static int copy_data(struct archive *ar, struct archive *aw) {
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user