diff options
-rwxr-xr-x | adb/tests/test_adb.py | 24 | ||||
-rwxr-xr-x | init/grab-bootchart.sh | 11 | ||||
-rw-r--r-- | liblog/logd_write.c | 2 | ||||
-rw-r--r-- | liblog/logd_write_kern.c | 2 | ||||
-rw-r--r-- | liblog/logprint.c | 30 | ||||
-rw-r--r-- | libziparchive/Android.mk | 3 | ||||
-rw-r--r-- | libziparchive/zip_archive.cc | 150 | ||||
-rw-r--r-- | logd/Android.mk | 11 | ||||
-rw-r--r-- | toolbox/Android.mk | 1 | ||||
-rw-r--r-- | toolbox/wipe.c | 176 |
10 files changed, 132 insertions, 278 deletions
diff --git a/adb/tests/test_adb.py b/adb/tests/test_adb.py index 49ead73..f111b04 100755 --- a/adb/tests/test_adb.py +++ b/adb/tests/test_adb.py @@ -237,16 +237,36 @@ class AdbBasic(unittest.TestCase): version_num = True self.assertTrue(version_num) - def test_root_unroot(self): - """Make sure that adb root and adb unroot work, using id(1).""" + def _test_root(self): adb = AdbWrapper() adb.root() adb.wait() self.assertEqual("root", adb.shell("id -un").strip()) + + def _test_unroot(self): + adb = AdbWrapper() adb.unroot() adb.wait() self.assertEqual("shell", adb.shell("id -un").strip()) + def test_root_unroot(self): + """Make sure that adb root and adb unroot work, using id(1).""" + adb = AdbWrapper() + original_user = adb.shell("id -un").strip() + try: + if original_user == "root": + self._test_unroot() + self._test_root() + elif original_user == "shell": + self._test_root() + self._test_unroot() + finally: + if original_user == "root": + adb.root() + else: + adb.unroot() + adb.wait() + class AdbFile(unittest.TestCase): SCRATCH_DIR = "/data/local/tmp" diff --git a/init/grab-bootchart.sh b/init/grab-bootchart.sh index 5715862..d6082aa 100755 --- a/init/grab-bootchart.sh +++ b/init/grab-bootchart.sh @@ -1,12 +1,9 @@ #!/bin/sh # -# this script is used to retrieve the bootchart log generated -# by init when compiled with INIT_BOOTCHART=true. -# +# This script is used to retrieve a bootchart log generated by init. # All options are passed to adb, for better or for worse. -# -# for all details, see //device/system/init/README.BOOTCHART -# +# See the readme in this directory for more on bootcharting. + TMPDIR=/tmp/android-bootchart rm -rf $TMPDIR mkdir -p $TMPDIR @@ -22,4 +19,4 @@ done (cd $TMPDIR && tar -czf $TARBALL $FILES) bootchart ${TMPDIR}/${TARBALL} gnome-open ${TARBALL%.tgz}.png -echo "Clean up ${TMPDIR}/ & ./${TARBALL%.tgz}.png when done" +echo "Clean up ${TMPDIR}/ and ./${TARBALL%.tgz}.png when done" diff --git a/liblog/logd_write.c b/liblog/logd_write.c index cd0a216..a865093 100644 --- a/liblog/logd_write.c +++ b/liblog/logd_write.c @@ -491,7 +491,7 @@ void __android_log_assert(const char *cond, const char *tag, } __android_log_write(ANDROID_LOG_FATAL, tag, buf); - __builtin_trap(); /* trap so we have a chance to debug the situation */ + abort(); /* abort so we have a chance to debug the situation */ /* NOTREACHED */ } diff --git a/liblog/logd_write_kern.c b/liblog/logd_write_kern.c index 2ca3c94..ca63067 100644 --- a/liblog/logd_write_kern.c +++ b/liblog/logd_write_kern.c @@ -266,7 +266,7 @@ void __android_log_assert(const char *cond, const char *tag, } __android_log_write(ANDROID_LOG_FATAL, tag, buf); - __builtin_trap(); /* trap so we have a chance to debug the situation */ + abort(); /* abort so we have a chance to debug the situation */ /* NOTREACHED */ } diff --git a/liblog/logprint.c b/liblog/logprint.c index b5145fd..7ba4c8e 100644 --- a/liblog/logprint.c +++ b/liblog/logprint.c @@ -20,7 +20,6 @@ #include <arpa/inet.h> #include <assert.h> #include <ctype.h> -#include <endian.h> #include <errno.h> #include <stdbool.h> #include <stdint.h> @@ -417,6 +416,27 @@ int android_log_processLogBuffer(struct logger_entry *buf, } /* + * Extract a 4-byte value from a byte stream. + */ +static inline uint32_t get4LE(const uint8_t* src) +{ + return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24); +} + +/* + * Extract an 8-byte value from a byte stream. + */ +static inline uint64_t get8LE(const uint8_t* src) +{ + uint32_t low, high; + + low = src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24); + high = src[4] | (src[5] << 8) | (src[6] << 16) | (src[7] << 24); + return ((long long) high << 32) | (long long) low; +} + + +/* * Recursively convert binary log data to printable form. * * This needs to be recursive because you can have lists of lists. @@ -453,7 +473,7 @@ static int android_log_printBinaryEvent(const unsigned char** pEventData, if (eventDataLen < 4) return -1; - ival = le32toh(*((int32_t *)eventData)); + ival = get4LE(eventData); eventData += 4; eventDataLen -= 4; @@ -474,7 +494,7 @@ static int android_log_printBinaryEvent(const unsigned char** pEventData, if (eventDataLen < 8) return -1; - lval = le64toh(*((int64_t *)eventData)); + lval = get8LE(eventData); eventData += 8; eventDataLen -= 8; @@ -495,7 +515,7 @@ static int android_log_printBinaryEvent(const unsigned char** pEventData, if (eventDataLen < 4) return -1; - strLen = le32toh(*((int32_t *)eventData)); + strLen = get4LE(eventData); eventData += 4; eventDataLen -= 4; @@ -610,7 +630,7 @@ int android_log_processBinaryLogBuffer(struct logger_entry *buf, inCount = buf->len; if (inCount < 4) return -1; - tagIndex = le32toh(*((int32_t *)eventData)); + tagIndex = get4LE(eventData); eventData += 4; inCount -= 4; diff --git a/libziparchive/Android.mk b/libziparchive/Android.mk index ba7b74d..3937449 100644 --- a/libziparchive/Android.mk +++ b/libziparchive/Android.mk @@ -24,7 +24,8 @@ LOCAL_SRC_FILES := ${source_files} LOCAL_STATIC_LIBRARIES := libz LOCAL_SHARED_LIBRARIES := libutils LOCAL_MODULE:= libziparchive -LOCAL_CFLAGS := -Werror +LOCAL_CFLAGS := -Werror -Wall +LOCAL_CPPFLAGS := -Wold-style-cast include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc index ebbab9f..59a1734 100644 --- a/libziparchive/zip_archive.cc +++ b/libziparchive/zip_archive.cc @@ -18,6 +18,8 @@ * Read-only access to Zip archives, with minimal heap allocation. */ +#include <memory> + #include <assert.h> #include <errno.h> #include <fcntl.h> @@ -293,7 +295,7 @@ struct ZipArchive { /* mapped central directory area */ off64_t directory_offset; - android::FileMap* directory_map; + android::FileMap directory_map; /* number of entries in the Zip archive */ uint16_t num_entries; @@ -311,7 +313,6 @@ struct ZipArchive { fd(fd), close_file(assume_ownership), directory_offset(0), - directory_map(NULL), num_entries(0), hash_table_size(0), hash_table(NULL) {} @@ -321,25 +322,10 @@ struct ZipArchive { close(fd); } - delete directory_map; free(hash_table); } }; -// Returns 0 on success and negative values on failure. -static android::FileMap* MapFileSegment(const int fd, const off64_t start, - const size_t length, const bool read_only, - const char* debug_file_name) { - android::FileMap* file_map = new android::FileMap; - const bool success = file_map->create(debug_file_name, fd, start, length, read_only); - if (!success) { - delete file_map; - return NULL; - } - - return file_map; -} - static int32_t CopyFileToFile(int fd, uint8_t* begin, const uint32_t length, uint64_t *crc_out) { static const uint32_t kBufSize = 32768; uint8_t buf[kBufSize]; @@ -521,16 +507,12 @@ static int32_t MapCentralDirectory0(int fd, const char* debug_file_name, * It all looks good. Create a mapping for the CD, and set the fields * in archive. */ - android::FileMap* map = MapFileSegment(fd, - static_cast<off64_t>(eocd->cd_start_offset), - static_cast<size_t>(eocd->cd_size), - true /* read only */, debug_file_name); - if (map == NULL) { - archive->directory_map = NULL; + if (!archive->directory_map.create(debug_file_name, fd, + static_cast<off64_t>(eocd->cd_start_offset), + static_cast<size_t>(eocd->cd_size), true /* read only */) ) { return kMmapFailed; } - archive->directory_map = map; archive->num_entries = eocd->num_records; archive->directory_offset = eocd->cd_start_offset; @@ -557,7 +539,7 @@ static int32_t MapCentralDirectory(int fd, const char* debug_file_name, return kInvalidFile; } - if (file_length > (off64_t) 0xffffffff) { + if (file_length > static_cast<off64_t>(0xffffffff)) { ALOGV("Zip: zip file too long %" PRId64, static_cast<int64_t>(file_length)); return kInvalidFile; } @@ -599,9 +581,9 @@ static int32_t MapCentralDirectory(int fd, const char* debug_file_name, * Returns 0 on success. */ static int32_t ParseZipArchive(ZipArchive* archive) { - int32_t result = -1; - const uint8_t* const cd_ptr = (const uint8_t*) archive->directory_map->getDataPtr(); - const size_t cd_length = archive->directory_map->getDataLength(); + const uint8_t* const cd_ptr = + reinterpret_cast<const uint8_t*>(archive->directory_map.getDataPtr()); + const size_t cd_length = archive->directory_map.getDataLength(); const uint16_t num_entries = archive->num_entries; /* @@ -610,8 +592,8 @@ static int32_t ParseZipArchive(ZipArchive* archive) { * least one unused entry to avoid an infinite loop during creation. */ archive->hash_table_size = RoundUpPower2(1 + (num_entries * 4) / 3); - archive->hash_table = (ZipEntryName*) calloc(archive->hash_table_size, - sizeof(ZipEntryName)); + archive->hash_table = reinterpret_cast<ZipEntryName*>(calloc(archive->hash_table_size, + sizeof(ZipEntryName))); /* * Walk through the central directory, adding entries to the hash @@ -624,18 +606,19 @@ static int32_t ParseZipArchive(ZipArchive* archive) { reinterpret_cast<const CentralDirectoryRecord*>(ptr); if (cdr->record_signature != CentralDirectoryRecord::kSignature) { ALOGW("Zip: missed a central dir sig (at %" PRIu16 ")", i); - goto bail; + return -1; } if (ptr + sizeof(CentralDirectoryRecord) > cd_end) { ALOGW("Zip: ran off the end (at %" PRIu16 ")", i); - goto bail; + return -1; } const off64_t local_header_offset = cdr->local_file_header_offset; if (local_header_offset >= archive->directory_offset) { - ALOGW("Zip: bad LFH offset %" PRId64 " at entry %" PRIu16, (int64_t)local_header_offset, i); - goto bail; + ALOGW("Zip: bad LFH offset %" PRId64 " at entry %" PRIu16, + static_cast<int64_t>(local_header_offset), i); + return -1; } const uint16_t file_name_length = cdr->file_name_length; @@ -645,7 +628,7 @@ static int32_t ParseZipArchive(ZipArchive* archive) { /* check that file name is valid UTF-8 and doesn't contain NUL (U+0000) characters */ if (!IsValidEntryName(file_name, file_name_length)) { - goto bail; + return -1; } /* add the CDE filename to the hash table */ @@ -654,25 +637,21 @@ static int32_t ParseZipArchive(ZipArchive* archive) { entry_name.name_length = file_name_length; const int add_result = AddToHash(archive->hash_table, archive->hash_table_size, entry_name); - if (add_result) { + if (add_result != 0) { ALOGW("Zip: Error adding entry to hash table %d", add_result); - result = add_result; - goto bail; + return add_result; } ptr += sizeof(CentralDirectoryRecord) + file_name_length + extra_length + comment_length; if ((ptr - cd_ptr) > static_cast<int64_t>(cd_length)) { ALOGW("Zip: bad CD advance (%tu vs %zu) at entry %" PRIu16, ptr - cd_ptr, cd_length, i); - goto bail; + return -1; } } ALOGV("+++ zip good scan %" PRIu16 " entries", num_entries); - result = 0; - -bail: - return result; + return 0; } static int32_t OpenArchiveInternal(ZipArchive* archive, @@ -713,7 +692,7 @@ int32_t OpenArchive(const char* fileName, ZipArchiveHandle* handle) { * Close a ZipArchive, closing the file and freeing the contents. */ void CloseArchive(ZipArchiveHandle handle) { - ZipArchive* archive = (ZipArchive*) handle; + ZipArchive* archive = reinterpret_cast<ZipArchive*>(handle); ALOGV("Closing archive %p", archive); delete archive; } @@ -774,8 +753,8 @@ static int32_t FindEntry(const ZipArchive* archive, const int ent, // the name that's in the hash table is a pointer to a location within // this mapped region. const uint8_t* base_ptr = reinterpret_cast<const uint8_t*>( - archive->directory_map->getDataPtr()); - if (ptr < base_ptr || ptr > base_ptr + archive->directory_map->getDataLength()) { + archive->directory_map.getDataPtr()); + if (ptr < base_ptr || ptr > base_ptr + archive->directory_map.getDataLength()) { ALOGW("Zip: Invalid entry pointer"); return kInvalidOffset; } @@ -810,7 +789,8 @@ static int32_t FindEntry(const ZipArchive* archive, const int ent, ssize_t actual = ReadAtOffset(archive->fd, lfh_buf, sizeof(lfh_buf), local_header_offset); if (actual != sizeof(lfh_buf)) { - ALOGW("Zip: failed reading lfh name from offset %" PRId64, (int64_t)local_header_offset); + ALOGW("Zip: failed reading lfh name from offset %" PRId64, + static_cast<int64_t>(local_header_offset)); return kIoError; } @@ -848,12 +828,12 @@ static int32_t FindEntry(const ZipArchive* archive, const int ent, return kInvalidOffset; } - uint8_t* name_buf = (uint8_t*) malloc(nameLen); + uint8_t* name_buf = reinterpret_cast<uint8_t*>(malloc(nameLen)); ssize_t actual = ReadAtOffset(archive->fd, name_buf, nameLen, name_offset); if (actual != nameLen) { - ALOGW("Zip: failed reading lfh name from offset %" PRId64, (int64_t)name_offset); + ALOGW("Zip: failed reading lfh name from offset %" PRId64, static_cast<int64_t>(name_offset)); free(name_buf); return kIoError; } @@ -872,20 +852,21 @@ static int32_t FindEntry(const ZipArchive* archive, const int ent, const off64_t data_offset = local_header_offset + sizeof(LocalFileHeader) + lfh->file_name_length + lfh->extra_field_length; if (data_offset > cd_offset) { - ALOGW("Zip: bad data offset %" PRId64 " in zip", (int64_t)data_offset); + ALOGW("Zip: bad data offset %" PRId64 " in zip", static_cast<int64_t>(data_offset)); return kInvalidOffset; } - if ((off64_t)(data_offset + data->compressed_length) > cd_offset) { + if (static_cast<off64_t>(data_offset + data->compressed_length) > cd_offset) { ALOGW("Zip: bad compressed length in zip (%" PRId64 " + %" PRIu32 " > %" PRId64 ")", - (int64_t)data_offset, data->compressed_length, (int64_t)cd_offset); + static_cast<int64_t>(data_offset), data->compressed_length, static_cast<int64_t>(cd_offset)); return kInvalidOffset; } if (data->method == kCompressStored && - (off64_t)(data_offset + data->uncompressed_length) > cd_offset) { + static_cast<off64_t>(data_offset + data->uncompressed_length) > cd_offset) { ALOGW("Zip: bad uncompressed length in zip (%" PRId64 " + %" PRIu32 " > %" PRId64 ")", - (int64_t)data_offset, data->uncompressed_length, (int64_t)cd_offset); + static_cast<int64_t>(data_offset), data->uncompressed_length, + static_cast<int64_t>(cd_offset)); return kInvalidOffset; } @@ -917,7 +898,7 @@ struct IterationHandle { int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr, const ZipEntryName* optional_prefix) { - ZipArchive* archive = (ZipArchive *) handle; + ZipArchive* archive = reinterpret_cast<ZipArchive*>(handle); if (archive == NULL || archive->hash_table == NULL) { ALOGW("Zip: Invalid ZipArchiveHandle"); @@ -939,7 +920,7 @@ void EndIteration(void* cookie) { int32_t FindEntry(const ZipArchiveHandle handle, const ZipEntryName& entryName, ZipEntry* data) { - const ZipArchive* archive = (ZipArchive*) handle; + const ZipArchive* archive = reinterpret_cast<ZipArchive*>(handle); if (entryName.name_length == 0) { ALOGW("Zip: Invalid filename %.*s", entryName.name_length, entryName.name); return kInvalidEntryName; @@ -957,7 +938,7 @@ int32_t FindEntry(const ZipArchiveHandle handle, const ZipEntryName& entryName, } int32_t Next(void* cookie, ZipEntry* data, ZipEntryName* name) { - IterationHandle* handle = (IterationHandle *) cookie; + IterationHandle* handle = reinterpret_cast<IterationHandle*>(cookie); if (handle == NULL) { return kInvalidHandle; } @@ -991,10 +972,17 @@ int32_t Next(void* cookie, ZipEntry* data, ZipEntryName* name) { return kIterationEnd; } +// This method is using libz macros with old-style-casts +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" +static inline int zlib_inflateInit2(z_stream* stream, int window_bits) { + return inflateInit2(stream, window_bits); +} +#pragma GCC diagnostic pop + static int32_t InflateToFile(int fd, const ZipEntry* entry, uint8_t* begin, uint32_t length, uint64_t* crc_out) { - int32_t result = -1; const uint32_t kBufSize = 32768; uint8_t read_buf[kBufSize]; uint8_t write_buf[kBufSize]; @@ -1010,7 +998,7 @@ static int32_t InflateToFile(int fd, const ZipEntry* entry, zstream.opaque = Z_NULL; zstream.next_in = NULL; zstream.avail_in = 0; - zstream.next_out = (Bytef*) write_buf; + zstream.next_out = reinterpret_cast<Bytef*>(write_buf); zstream.avail_out = kBufSize; zstream.data_type = Z_UNKNOWN; @@ -1018,7 +1006,7 @@ static int32_t InflateToFile(int fd, const ZipEntry* entry, * Use the undocumented "negative window bits" feature to tell zlib * that there's no zlib header waiting for it. */ - zerr = inflateInit2(&zstream, -MAX_WBITS); + zerr = zlib_inflateInit2(&zstream, -MAX_WBITS); if (zerr != Z_OK) { if (zerr == Z_VERSION_ERROR) { ALOGE("Installed zlib is not compatible with linked version (%s)", @@ -1030,6 +1018,12 @@ static int32_t InflateToFile(int fd, const ZipEntry* entry, return kZlibError; } + auto zstream_deleter = [](z_stream* stream) { + inflateEnd(stream); /* free up any allocated structures */ + }; + + std::unique_ptr<z_stream, decltype(zstream_deleter)> zstream_guard(&zstream, zstream_deleter); + const uint32_t uncompressed_length = entry->uncompressed_length; uint32_t compressed_length = entry->compressed_length; @@ -1041,8 +1035,7 @@ static int32_t InflateToFile(int fd, const ZipEntry* entry, const ZD_TYPE actual = TEMP_FAILURE_RETRY(read(fd, read_buf, getSize)); if (actual != getSize) { ALOGW("Zip: inflate read failed (" ZD " vs " ZD ")", actual, getSize); - result = kIoError; - goto z_bail; + return kIoError; } compressed_length -= getSize; @@ -1057,8 +1050,7 @@ static int32_t InflateToFile(int fd, const ZipEntry* entry, ALOGW("Zip: inflate zerr=%d (nIn=%p aIn=%u nOut=%p aOut=%u)", zerr, zstream.next_in, zstream.avail_in, zstream.next_out, zstream.avail_out); - result = kZlibError; - goto z_bail; + return kZlibError; } /* write when we're full or when we're done */ @@ -1067,7 +1059,7 @@ static int32_t InflateToFile(int fd, const ZipEntry* entry, const size_t write_size = zstream.next_out - write_buf; // The file might have declared a bogus length. if (write_size + write_count > length) { - goto z_bail; + return -1; } memcpy(begin + write_count, write_buf, write_size); write_count += write_size; @@ -1085,26 +1077,20 @@ static int32_t InflateToFile(int fd, const ZipEntry* entry, if (zstream.total_out != uncompressed_length || compressed_length != 0) { ALOGW("Zip: size mismatch on inflated file (%lu vs %" PRIu32 ")", zstream.total_out, uncompressed_length); - result = kInconsistentInformation; - goto z_bail; + return kInconsistentInformation; } - result = 0; - -z_bail: - inflateEnd(&zstream); /* free up any allocated structures */ - - return result; + return 0; } int32_t ExtractToMemory(ZipArchiveHandle handle, ZipEntry* entry, uint8_t* begin, uint32_t size) { - ZipArchive* archive = (ZipArchive*) handle; + ZipArchive* archive = reinterpret_cast<ZipArchive*>(handle); const uint16_t method = entry->method; off64_t data_offset = entry->offset; if (lseek64(archive->fd, data_offset, SEEK_SET) != data_offset) { - ALOGW("Zip: lseek to data at %" PRId64 " failed", (int64_t)data_offset); + ALOGW("Zip: lseek to data at %" PRId64 " failed", static_cast<int64_t>(data_offset)); return kIoError; } @@ -1148,7 +1134,7 @@ int32_t ExtractEntryToFile(ZipArchiveHandle handle, int result = TEMP_FAILURE_RETRY(ftruncate(fd, declared_length + current_offset)); if (result == -1) { ALOGW("Zip: unable to truncate file to %" PRId64 ": %s", - (int64_t)(declared_length + current_offset), strerror(errno)); + static_cast<int64_t>(declared_length + current_offset), strerror(errno)); return kIoError; } @@ -1159,16 +1145,14 @@ int32_t ExtractEntryToFile(ZipArchiveHandle handle, return 0; } - android::FileMap* map = MapFileSegment(fd, current_offset, declared_length, - false, kTempMappingFileName); - if (map == NULL) { + android::FileMap map; + if (!map.create(kTempMappingFileName, fd, current_offset, declared_length, false)) { return kMmapFailed; } const int32_t error = ExtractToMemory(handle, entry, - reinterpret_cast<uint8_t*>(map->getDataPtr()), - map->getDataLength()); - delete map; + reinterpret_cast<uint8_t*>(map.getDataPtr()), + map.getDataLength()); return error; } @@ -1181,6 +1165,6 @@ const char* ErrorCodeString(int32_t error_code) { } int GetFileDescriptor(const ZipArchiveHandle handle) { - return ((ZipArchive*) handle)->fd; + return reinterpret_cast<ZipArchive*>(handle)->fd; } diff --git a/logd/Android.mk b/logd/Android.mk index 188511f..127a66b 100644 --- a/logd/Android.mk +++ b/logd/Android.mk @@ -26,7 +26,16 @@ LOCAL_SHARED_LIBRARIES := \ libcutils \ libutils -LOCAL_CFLAGS := -Werror $(shell sed -n 's/^\([0-9]*\)[ \t]*auditd[ \t].*/-DAUDITD_LOG_TAG=\1/p' $(LOCAL_PATH)/event.logtags) +# This is what we want to do: +# event_logtags = $(shell \ +# sed -n \ +# "s/^\([0-9]*\)[ \t]*$1[ \t].*/-D`echo $1 | tr a-z A-Z`_LOG_TAG=\1/p" \ +# $(LOCAL_PATH)/$2/event.logtags) +# event_flag := $(call event_logtags,auditd) +# so make sure we do not regret hard-coding it as follows: +event_flag := -DAUDITD_LOG_TAG=1003 + +LOCAL_CFLAGS := -Werror $(event_flag) include $(BUILD_EXECUTABLE) diff --git a/toolbox/Android.mk b/toolbox/Android.mk index 05b83a2..d60dab4 100644 --- a/toolbox/Android.mk +++ b/toolbox/Android.mk @@ -71,7 +71,6 @@ OUR_TOOLS := \ umount \ uptime \ watchprops \ - wipe \ ALL_TOOLS = $(BSD_TOOLS) $(OUR_TOOLS) diff --git a/toolbox/wipe.c b/toolbox/wipe.c deleted file mode 100644 index 650a0d6..0000000 --- a/toolbox/wipe.c +++ /dev/null @@ -1,176 +0,0 @@ -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <dirent.h> -#include <string.h> -#include <errno.h> -#include <sys/types.h> -#include <cutils/android_reboot.h> -#include <sys/stat.h> - -#ifndef PATH_MAX -#define PATH_MAX 4096 -#endif - - -/* Directories created by init defined in system/rootdir/init.rc */ -static char *INIT_DIRS[] = { - "/system/etc/ppp", - "/data/misc", - "/data/local", - "/data/local/tmp", - "/data/data", - "/data/app_private", - "/data/app", - NULL -}; - -static void wipe (const char *path); - -static int usage() -{ - fprintf(stderr, "wipe <system|data|all>\n\n" - "system means '/system'\n" - "data means '/data'\n"); - - return -1; -} - -int wipe_main (int argc, char *argv[]) -{ - char *whatToWipe; - - if (argc != 2) return usage(); - - whatToWipe = argv[1]; - - if (0 == strcmp (whatToWipe, "system")) { - fprintf(stdout, "Wiping /system\n"); - wipe ("/system"); - fprintf(stdout, "Done wiping /android\n"); - } else if (0 == strcmp (whatToWipe, "data")) { - fprintf(stdout, "Wiping /data\n"); - wipe ("/data"); - fprintf(stdout, "Done wiping /data\n"); - } else if (0 == strcmp (whatToWipe, "all")) { - fprintf(stdout, "Wiping /system and /data\n"); - wipe ("/system"); - wipe ("/data"); - fprintf(stdout, "Done wiping /system and /data\n"); - } else if (0 == strcmp(whatToWipe, "nuke")) { - int ret; - fprintf(stdout, "Nuking the device...\n"); - wipe ("/system"); - wipe ("/data"); - fprintf(stdout, "Device nuked! Rebooting...\n"); - ret = android_reboot(ANDROID_RB_RESTART, 0, 0); - if (ret < 0) { - fprintf(stderr, "Reboot failed, %s\n", strerror(errno)); - return 1; - } - } else { - return usage(); - } - - return 0; -} - -static char nameBuffer[PATH_MAX]; -static struct stat statBuffer; - -static void wipe (const char *path) -{ - DIR *dir; - struct dirent *de; - int ret; - - dir = opendir(path); - - if (dir == NULL) { - fprintf (stderr, "Error opendir'ing %s '%s'\n", - path, strerror(errno)); - return; - } - - char *filenameOffset; - - strcpy(nameBuffer, path); - strcat(nameBuffer, "/"); - - filenameOffset = nameBuffer + strlen(nameBuffer); - - for (;;) { - de = readdir(dir); - - if (de == NULL) { - break; - } - - if (0 == strcmp(de->d_name, ".") - || 0 == strcmp(de->d_name, "..") - || 0 == strcmp(de->d_name, "lost+found") - ) { - continue; - } - - strcpy(filenameOffset, de->d_name); - - ret = lstat (nameBuffer, &statBuffer); - - if (ret != 0) { - fprintf(stderr, "stat() error on '%s' '%s'\n", - nameBuffer, strerror(errno)); - } - - if(S_ISDIR(statBuffer.st_mode)) { - int i; - char *newpath; - -#if 0 - closedir(dir); -#endif - - newpath = strdup(nameBuffer); - wipe(newpath); - - /* Leave directories created by init, they have special permissions. */ - for (i = 0; INIT_DIRS[i]; i++) { - if (strcmp(INIT_DIRS[i], newpath) == 0) { - break; - } - } - if (INIT_DIRS[i] == NULL) { - ret = rmdir(newpath); - if (ret != 0) { - fprintf(stderr, "rmdir() error on '%s' '%s'\n", - newpath, strerror(errno)); - } - } - - free(newpath); - -#if 0 - dir = opendir(path); - if (dir == NULL) { - fprintf (stderr, "Error opendir'ing %s '%s'\n", - path, strerror(errno)); - return; - } -#endif - - strcpy(nameBuffer, path); - strcat(nameBuffer, "/"); - - } else { - ret = unlink(nameBuffer); - - if (ret != 0) { - fprintf(stderr, "unlink() error on '%s' '%s'\n", - nameBuffer, strerror(errno)); - } - } - } - - closedir(dir); - -} |