xref: /aosp_15_r20/external/sandboxed-api/oss-internship-2020/libarchive/README.md (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1*ec63e07aSXin Li# libarchive Sandboxed API
2*ec63e07aSXin Li
3*ec63e07aSXin LiSandboxed version of the [libarchive](https://www.libarchive.org/) minitar [example](https://github.com/libarchive/libarchive/blob/master/examples/minitar/minitar.c) using [Sandboxed API](https://github.com/google/sandboxed-api).
4*ec63e07aSXin Li
5*ec63e07aSXin Li## Build
6*ec63e07aSXin Li
7*ec63e07aSXin Li```
8*ec63e07aSXin Limkdir -p build && cd build
9*ec63e07aSXin Licmake .. -G Ninja
10*ec63e07aSXin Licmake --build .
11*ec63e07aSXin Li```
12*ec63e07aSXin Li
13*ec63e07aSXin LiThe example binary file can be found at **build/examples/sapi_minitar** and the unit tests at **build/test/sapi_minitar_test**.
14*ec63e07aSXin Li
15*ec63e07aSXin Li## Patches
16*ec63e07aSXin Li
17*ec63e07aSXin LiThe original libarchive code required patching since one of the custom types produced errors with libclang Python byndings. The patches are applied automatically during the build step and they do not modify the functionality of the library. The repository is also fetched automatically.
18*ec63e07aSXin Li
19*ec63e07aSXin Li## Examples
20*ec63e07aSXin Li
21*ec63e07aSXin LiIn this project, the minitar example is sandboxed.
22*ec63e07aSXin LiThe code is found in the **examples** directory and is structured as follows:
23*ec63e07aSXin Li- **sapi_minitar_main.cc** - ***main*** function of the minitar tool. This is mostly similar to the original example.
24*ec63e07aSXin Li- **sapi_minitar.h** and **sapi_minitar.cc** - The two main functions (***CreateArchive*** and ***ExtractArchive***) and other helper functions.
25*ec63e07aSXin Li- **sandbox.h** - Custom security policies, depending on the whether the user creates or extracts an archive.
26*ec63e07aSXin Li
27*ec63e07aSXin LiOn top of that, unit tests can be found in the **test/minitar_test.cc** file.
28*ec63e07aSXin Li
29*ec63e07aSXin Li## Usage
30*ec63e07aSXin Li
31*ec63e07aSXin LiThe unit tests can be executed with `./build/test/sapi_minitar_test`.
32*ec63e07aSXin Li
33*ec63e07aSXin LiThe **sapi_minitar** command line tool can be used in the same way as the original example. It is also similar to the [tar](https://man7.org/linux/man-pages/man1/tar.1.html) command, only with fewer options:
34*ec63e07aSXin Li
35*ec63e07aSXin Li`./build/examples/sapi_minitar -[options] [-f file] [files]`
36*ec63e07aSXin Li
37*ec63e07aSXin LiThe available options are:
38*ec63e07aSXin Li- *c* - Create archive.
39*ec63e07aSXin Li- *x* - Extract archive.
40*ec63e07aSXin Li- *t* - Extract archive but only print entries.
41*ec63e07aSXin Li- *p* - Preserve.
42*ec63e07aSXin Li- *v* - Verbose.
43*ec63e07aSXin Li- *j* or *y* - Compress with BZIP2.
44*ec63e07aSXin Li- *Z* - Default compression.
45*ec63e07aSXin Li- *z* - Compress with GZIP.
46*ec63e07aSXin Li
47*ec63e07aSXin LiIf no compression method is chosen (in the case of archive creation) the files will only be stored.
48*ec63e07aSXin Li
49