summaryrefslogtreecommitdiffstats
path: root/fuse_sideload.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fuse_sideload.cpp')
-rw-r--r--fuse_sideload.cpp34
1 files changed, 26 insertions, 8 deletions
diff --git a/fuse_sideload.cpp b/fuse_sideload.cpp
index 219374fdb..f667cd4a1 100644
--- a/fuse_sideload.cpp
+++ b/fuse_sideload.cpp
@@ -46,7 +46,7 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
-#include <linux/fuse.h>
+#include "fuse.h"
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
@@ -61,10 +61,12 @@
#include <sys/uio.h>
#include <unistd.h>
-#include <string>
-
-#include <android-base/stringprintf.h>
+#ifdef USE_MINCRYPT
+#include "mincrypt/sha256.h"
+#define SHA256_DIGEST_LENGTH SHA256_DIGEST_SIZE
+#else
#include <openssl/sha.h>
+#endif
#include "fuse_sideload.h"
@@ -74,6 +76,10 @@
#define NO_STATUS 1
#define NO_STATUS_EXIT 2
+#ifndef MIN
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
struct fuse_data {
int ffd; // file descriptor for the fuse socket
@@ -276,7 +282,11 @@ static int fetch_block(struct fuse_data* fd, uint32_t block) {
// - Otherwise, return -EINVAL for the read.
uint8_t hash[SHA256_DIGEST_LENGTH];
+#ifdef USE_MINCRYPT
+ SHA256_hash(fd->block_data, fd->block_size, hash);
+#else
SHA256(fd->block_data, fd->block_size, hash);
+#endif
uint8_t* blockhash = fd->hashes + block * SHA256_DIGEST_LENGTH;
if (memcmp(hash, blockhash, SHA256_DIGEST_LENGTH) == 0) {
return 0;
@@ -430,12 +440,14 @@ int run_fuse_sideload(struct provider_vtab* vtab, void* cookie, uint64_t file_si
}
{
- std::string opts = android::base::StringPrintf(
- "fd=%d,user_id=%d,group_id=%d,max_read=%u,allow_other,rootmode=040000", fd.ffd, fd.uid,
- fd.gid, block_size);
+ char opts[256];
+ snprintf(opts, sizeof(opts),
+ ("fd=%d,user_id=%d,group_id=%d,max_read=%u,"
+ "allow_other,rootmode=040000"),
+ fd.ffd, fd.uid, fd.gid, block_size);
result = mount("/dev/fuse", FUSE_SIDELOAD_HOST_MOUNTPOINT, "fuse",
- MS_NOSUID | MS_NODEV | MS_RDONLY | MS_NOEXEC, opts.c_str());
+ MS_NOSUID | MS_NODEV | MS_RDONLY | MS_NOEXEC, opts);
if (result < 0) {
perror("mount");
goto done;
@@ -527,3 +539,9 @@ done:
return result;
}
+
+extern "C" int run_old_fuse_sideload(struct provider_vtab* vtab, void* cookie,
+ uint64_t file_size, uint32_t block_size)
+{
+ return run_fuse_sideload(vtab, cookie, file_size, block_size);
+}