diff options
author | Jean-Baptiste Queru <jbq@google.com> | 2009-07-29 14:57:08 -0700 |
---|---|---|
committer | Jean-Baptiste Queru <jbq@google.com> | 2009-07-29 14:57:08 -0700 |
commit | 913f841638abc4799accd050537748a1825275d0 (patch) | |
tree | 9c2819d3b290e142a5d1e451001a922a3a06410e | |
parent | e92807b964bef9b003f39ae1c3be6bf379f148dd (diff) | |
parent | 7082788e24208a19007f237ae4c4622a8bd6bc6e (diff) | |
download | extras-913f841638abc4799accd050537748a1825275d0.tar.gz |
merge from donut
-rw-r--r-- | tests/bionic/libstdc++/Android.mk | 14 | ||||
-rw-r--r-- | tests/bionic/libstdc++/test_cassert.cpp | 2 | ||||
-rw-r--r-- | tests/bionic/libstdc++/test_cctype.cpp | 2 | ||||
-rw-r--r-- | tests/bionic/libstdc++/test_climits.cpp | 2 | ||||
-rw-r--r-- | tests/bionic/libstdc++/test_cmath.cpp | 2 | ||||
-rw-r--r-- | tests/bionic/libstdc++/test_csetjmp.cpp | 2 | ||||
-rw-r--r-- | tests/bionic/libstdc++/test_csignal.cpp | 2 | ||||
-rw-r--r-- | tests/bionic/libstdc++/test_cstddef.cpp | 2 | ||||
-rw-r--r-- | tests/bionic/libstdc++/test_cstdint.cpp | 2 | ||||
-rw-r--r-- | tests/bionic/libstdc++/test_cstdio.cpp | 2 | ||||
-rw-r--r-- | tests/bionic/libstdc++/test_cstdlib.cpp | 73 | ||||
-rw-r--r-- | tests/bionic/libstdc++/test_cstring.cpp | 2 | ||||
-rw-r--r-- | tests/bionic/libstdc++/test_ctime.cpp | 2 | ||||
-rw-r--r-- | tests/fstest/Android.mk | 6 | ||||
-rw-r--r-- | tests/fstest/README | 2 | ||||
-rwxr-xr-x | tests/fstest/mounts-test.sh | 23 | ||||
-rw-r--r-- | tests/fstest/perm_checker.c | 143 | ||||
-rw-r--r-- | tests/fstest/perm_checker.conf | 1 |
18 files changed, 209 insertions, 75 deletions
diff --git a/tests/bionic/libstdc++/Android.mk b/tests/bionic/libstdc++/Android.mk index 103b3274..12286622 100644 --- a/tests/bionic/libstdc++/Android.mk +++ b/tests/bionic/libstdc++/Android.mk @@ -31,7 +31,6 @@ define device-test $(eval include $(CLEAR_VARS)) \ $(eval LOCAL_SRC_FILES := $(file)) \ $(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \ - $(eval $(info LOCAL_MODULE=$(LOCAL_MODULE))) \ $(eval LOCAL_CFLAGS += $(EXTRA_CFLAGS)) \ $(eval LOCAL_MODULE_TAGS := tests) \ $(eval include $(BUILD_EXECUTABLE)) \ @@ -47,7 +46,6 @@ define host-test $(eval include $(CLEAR_VARS)) \ $(eval LOCAL_SRC_FILES := $(file)) \ $(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \ - $(eval $(info LOCAL_MODULE=$(LOCAL_MODULE) file=$(file))) \ $(eval LOCAL_CFLAGS += $(EXTRA_CFLAGS)) \ $(eval LOCAL_LDLIBS += $(EXTRA_LDLIBS)) \ $(eval LOCAL_MODULE_TAGS := tests) \ @@ -65,16 +63,22 @@ sources := \ test_csetjmp.cpp \ test_csignal.cpp \ test_cstddef.cpp \ - test_cstdint.cpp \ test_cstdio.cpp \ test_cstdlib.cpp \ test_cstring.cpp \ test_ctime.cpp -EXTRA_CFLAGS := -I bionic/libstdc++/include $(call host-test, $(sources)) -EXTRA_CFLAGS := -I bionic/libstdc++/include +EXTRA_CFLAGS := -DBIONIC=1 -I bionic/libstdc++/include + +# <cstdint> is not part of the C++ standard yet, and some +# host environments don't provide it unless you use specific +# compiler flags, so only build this test for device/Bionic +# builds at the moment. +# +sources += test_cstdint.cpp + $(call device-test, $(sources)) endif # BIONIC_TESTS diff --git a/tests/bionic/libstdc++/test_cassert.cpp b/tests/bionic/libstdc++/test_cassert.cpp index 67c96deb..fc669a92 100644 --- a/tests/bionic/libstdc++/test_cassert.cpp +++ b/tests/bionic/libstdc++/test_cassert.cpp @@ -28,7 +28,7 @@ #include <cassert> -#ifndef BIONIC_LIBSTDCPP_INCLUDE_CASSERT__ +#if defined BIONIC && !defined BIONIC_LIBSTDCPP_INCLUDE_CASSERT__ #error "Wrong header file included!!" #endif diff --git a/tests/bionic/libstdc++/test_cctype.cpp b/tests/bionic/libstdc++/test_cctype.cpp index bedb77fb..cc641712 100644 --- a/tests/bionic/libstdc++/test_cctype.cpp +++ b/tests/bionic/libstdc++/test_cctype.cpp @@ -27,7 +27,7 @@ */ #include <cctype> -#ifndef BIONIC_LIBSTDCPP_INCLUDE_CCTYPE__ +#if defined BIONIC && !defined BIONIC_LIBSTDCPP_INCLUDE_CCTYPE__ #error "Wrong header file included!!" #endif diff --git a/tests/bionic/libstdc++/test_climits.cpp b/tests/bionic/libstdc++/test_climits.cpp index f3ce0232..9fdba56c 100644 --- a/tests/bionic/libstdc++/test_climits.cpp +++ b/tests/bionic/libstdc++/test_climits.cpp @@ -28,7 +28,7 @@ #include <climits> -#ifndef BIONIC_LIBSTDCPP_INCLUDE_CLIMITS__ +#if defined BIONIC && !defined BIONIC_LIBSTDCPP_INCLUDE_CLIMITS__ #error "Wrong header file included!!" #endif diff --git a/tests/bionic/libstdc++/test_cmath.cpp b/tests/bionic/libstdc++/test_cmath.cpp index 438fb649..847c9340 100644 --- a/tests/bionic/libstdc++/test_cmath.cpp +++ b/tests/bionic/libstdc++/test_cmath.cpp @@ -27,7 +27,7 @@ */ #include <cmath> -#ifndef BIONIC_LIBSTDCPP_INCLUDE_CMATH__ +#if defined BIONIC && !defined BIONIC_LIBSTDCPP_INCLUDE_CMATH__ #error "Wrong header file included!!" #endif diff --git a/tests/bionic/libstdc++/test_csetjmp.cpp b/tests/bionic/libstdc++/test_csetjmp.cpp index 9b314909..79b23d88 100644 --- a/tests/bionic/libstdc++/test_csetjmp.cpp +++ b/tests/bionic/libstdc++/test_csetjmp.cpp @@ -27,7 +27,7 @@ */ #include <csetjmp> -#ifndef BIONIC_LIBSTDCPP_INCLUDE_CSETJMP__ +#if defined BIONIC && !defined BIONIC_LIBSTDCPP_INCLUDE_CSETJMP__ #error "Wrong header file included!!" #endif diff --git a/tests/bionic/libstdc++/test_csignal.cpp b/tests/bionic/libstdc++/test_csignal.cpp index 22fa946f..a460e649 100644 --- a/tests/bionic/libstdc++/test_csignal.cpp +++ b/tests/bionic/libstdc++/test_csignal.cpp @@ -27,7 +27,7 @@ */ #include <csignal> -#ifndef BIONIC_LIBSTDCPP_INCLUDE_CSIGNAL__ +#if defined BIONIC && !defined BIONIC_LIBSTDCPP_INCLUDE_CSIGNAL__ #error "Wrong header file included!!" #endif diff --git a/tests/bionic/libstdc++/test_cstddef.cpp b/tests/bionic/libstdc++/test_cstddef.cpp index 19f9d422..b1e280ff 100644 --- a/tests/bionic/libstdc++/test_cstddef.cpp +++ b/tests/bionic/libstdc++/test_cstddef.cpp @@ -27,7 +27,7 @@ */ #include <cstddef> -#ifndef BIONIC_LIBSTDCPP_INCLUDE_CSTDDEF__ +#if defined BIONIC && !defined BIONIC_LIBSTDCPP_INCLUDE_CSTDDEF__ #error "Wrong header file included!!" #endif diff --git a/tests/bionic/libstdc++/test_cstdint.cpp b/tests/bionic/libstdc++/test_cstdint.cpp index 8753cf7d..a01164f9 100644 --- a/tests/bionic/libstdc++/test_cstdint.cpp +++ b/tests/bionic/libstdc++/test_cstdint.cpp @@ -27,7 +27,7 @@ */ #include <cstdint> -#ifndef BIONIC_LIBSTDCPP_INCLUDE_CSTDINT__ +#if defined BIONIC && !defined BIONIC_LIBSTDCPP_INCLUDE_CSTDINT__ #error "Wrong header file included!!" #endif diff --git a/tests/bionic/libstdc++/test_cstdio.cpp b/tests/bionic/libstdc++/test_cstdio.cpp index 573746dc..f22250a4 100644 --- a/tests/bionic/libstdc++/test_cstdio.cpp +++ b/tests/bionic/libstdc++/test_cstdio.cpp @@ -27,7 +27,7 @@ */ #include <cstdio> -#ifndef BIONIC_LIBSTDCPP_INCLUDE_CSTDIO__ +#if defined BIONIC && !defined BIONIC_LIBSTDCPP_INCLUDE_CSTDIO__ #error "Wrong header file included!!" #endif diff --git a/tests/bionic/libstdc++/test_cstdlib.cpp b/tests/bionic/libstdc++/test_cstdlib.cpp index c5c914c4..0450d066 100644 --- a/tests/bionic/libstdc++/test_cstdlib.cpp +++ b/tests/bionic/libstdc++/test_cstdlib.cpp @@ -27,7 +27,7 @@ */ #include <cstdlib> -#ifndef BIONIC_LIBSTDCPP_INCLUDE_CSTDLIB__ +#if defined BIONIC && !defined BIONIC_LIBSTDCPP_INCLUDE_CSTDLIB__ #error "Wrong header file included!!" #endif @@ -40,6 +40,77 @@ const int kFailed = 1; namespace android { +using ::exit; +using ::abort; +using ::atexit; +using ::on_exit; + +using ::getenv; +using ::putenv; +using ::setenv; +using ::unsetenv; +using ::clearenv; + +using ::mktemp; +using ::mkstemp; + +using ::strtol; +using ::strtoll; +using ::strtoul; +using ::strtoull; +using ::strtod; +using ::strtof; + +using ::atoi; +using ::atol; +using ::atoll; +using ::atof; + +using ::abs; +using ::labs; +using ::llabs; + +using ::realpath; +using ::system; + +using ::bsearch; +using ::qsort; + +using ::jrand48; +using ::mrand48; +using ::nrand48; +using ::lrand48; +using ::seed48; +using ::srand48; + +using ::rand; +using ::srand; +using ::random; +using ::srandom; + +using ::malloc; +using ::free; +using ::calloc; +using ::realloc; + +using ::unlockpt; +using ::ptsname; +using ::ptsname_r; +using ::getpt; +using ::grantpt; + +using ::div_t; +using ::div; +using ::ldiv_t; +using ::ldiv; +using ::lldiv_t; +using ::lldiv; + +using ::mblen; +using ::mbstowcs; +using ::mbtowc; +using ::wctomb; +using ::wcstombs; } // namespace android int main(int argc, char **argv) diff --git a/tests/bionic/libstdc++/test_cstring.cpp b/tests/bionic/libstdc++/test_cstring.cpp index eab64a1e..f01b8a84 100644 --- a/tests/bionic/libstdc++/test_cstring.cpp +++ b/tests/bionic/libstdc++/test_cstring.cpp @@ -27,7 +27,7 @@ */ #include <cstring> -#ifndef BIONIC_LIBSTDCPP_INCLUDE_CSTRING__ +#if defined BIONIC && !defined BIONIC_LIBSTDCPP_INCLUDE_CSTRING__ #error "Wrong header file included!!" #endif diff --git a/tests/bionic/libstdc++/test_ctime.cpp b/tests/bionic/libstdc++/test_ctime.cpp index 72a13cb9..9fae6837 100644 --- a/tests/bionic/libstdc++/test_ctime.cpp +++ b/tests/bionic/libstdc++/test_ctime.cpp @@ -27,7 +27,7 @@ */ #include <ctime> -#ifndef BIONIC_LIBSTDCPP_INCLUDE_CTIME__ +#if defined BIONIC && !defined BIONIC_LIBSTDCPP_INCLUDE_CTIME__ #error "Wrong header file included!!" #endif diff --git a/tests/fstest/Android.mk b/tests/fstest/Android.mk index 14c32aa0..7ab89e12 100644 --- a/tests/fstest/Android.mk +++ b/tests/fstest/Android.mk @@ -24,6 +24,8 @@ LOCAL_MODULE := perm_checker LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/local + include $(BUILD_EXECUTABLE) #### @@ -34,9 +36,9 @@ LOCAL_MODULE := perm_checker.conf LOCAL_MODULE_TAGS := optional -LOCAL_MODULE_CLASS := ETC +LOCAL_MODULE_CLASS := DATA -LOCAL_MODULE_PATH := $(TARGET_OUT)/etc/ +LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/local LOCAL_SRC_FILES := $(LOCAL_MODULE) diff --git a/tests/fstest/README b/tests/fstest/README index e4f8194c..b3281006 100644 --- a/tests/fstest/README +++ b/tests/fstest/README @@ -1,5 +1,5 @@ All files and directories will be matched against entries taken from -/etc/perm_checker.conf, and any file/directory which fails the ruleset +/data/local/perm_checker.conf, and any file/directory which fails the ruleset will cause an error message along with a corresponding explicit (fully specified and minimal) rule for that file/directory to be printed on stdout. If only the message "Passed." is printed on stdout, all files are diff --git a/tests/fstest/mounts-test.sh b/tests/fstest/mounts-test.sh new file mode 100755 index 00000000..80a2416a --- /dev/null +++ b/tests/fstest/mounts-test.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +rtrn=0 + +adb shell mount | grep -q /sdcard +if [ 0 -ne $? ] +then + echo FAILURE: /sdcard is not mounted + exit 1 +fi + +for i in nosuid noexec +do + adb shell mount | grep /sdcard | grep -q $i + if [ 0 -ne $? ] + then + echo FAILURE: /sdcard is not mounted $i + rtrn=$(expr $rtrn + 1) + fi +done + +exit $rtrn + diff --git a/tests/fstest/perm_checker.c b/tests/fstest/perm_checker.c index 86d2cdce..e6b2105b 100644 --- a/tests/fstest/perm_checker.c +++ b/tests/fstest/perm_checker.c @@ -36,11 +36,16 @@ #include <linux/kdev_t.h> +#define DEFAULT_CONFIG_FILE "/data/local/perm_checker.conf" + #define PERMS(M) (M & ~S_IFMT) #define MAX_NAME_LEN 4096 #define MAX_UID_LEN 256 #define MAX_GID_LEN MAX_UID_LEN +static char *config_file; +static char *executable_file; + enum perm_rule_type {EXACT_FILE = 0, EXACT_DIR, WILDCARD, RECURSIVE, NUM_PR_TYPES}; @@ -90,14 +95,69 @@ static gid_t str2gid(char *str, int line_num) return gr->gr_gid; } +static void add_rule(int line_num, char *spec, + unsigned long min_mode, unsigned long max_mode, + char *min_uid_buf, char *max_uid_buf, + char *min_gid_buf, char *max_gid_buf) { + + char rule_text_buf[MAX_NAME_LEN + 2*MAX_UID_LEN + 2*MAX_GID_LEN + 9]; + perm_rule_t *pr = malloc(sizeof(perm_rule_t)); + if (!pr) { + printf("Out of memory.\n"); + exit(255); + } + if (snprintf(rule_text_buf, sizeof(rule_text_buf), + "%s %lo %lo %s %s %s %s", spec, min_mode, max_mode, + min_uid_buf, max_uid_buf, min_gid_buf, max_gid_buf) + >= (long int) sizeof(rule_text_buf)) { + // This should never happen, but just in case... + printf("# ERROR # Maximum length limits exceeded on line %d\n", + line_num); + exit(255); + } + pr->rule_text = strndup(rule_text_buf, sizeof(rule_text_buf)); + pr->rule_line = line_num; + if (strstr(spec, "/...")) { + pr->spec = strndup(spec, strlen(spec) - 3); + pr->type = RECURSIVE; + } else if (spec[strlen(spec) - 1] == '*') { + pr->spec = strndup(spec, strlen(spec) - 1); + pr->type = WILDCARD; + } else if (spec[strlen(spec) - 1] == '/') { + pr->spec = strdup(spec); + pr->type = EXACT_DIR; + } else { + pr->spec = strdup(spec); + pr->type = EXACT_FILE; + } + if ((pr->spec == NULL) || (pr->rule_text == NULL)) { + printf("Out of memory.\n"); + exit(255); + } + pr->min_mode = min_mode; + pr->max_mode = max_mode; + pr->min_uid = str2uid(min_uid_buf, line_num); + pr->max_uid = str2uid(max_uid_buf, line_num); + pr->min_gid = str2gid(min_gid_buf, line_num); + pr->max_gid = str2gid(max_gid_buf, line_num); + + // Add the rule to the appropriate set + pr->next = rules[pr->type]; + rules[pr->type] = pr; +#if 0 // Useful for debugging + printf("rule #%d: type = %d spec = %s min_mode = %o max_mode = %o " + "min_uid = %d max_uid = %d min_gid = %d max_gid = %d\n", + num_rules, pr->type, pr->spec, pr->min_mode, pr->max_mode, + pr->min_uid, pr->max_uid, pr->min_gid, pr->max_gid); +#endif +} + static int read_rules(FILE *fp) { char spec[MAX_NAME_LEN + 5]; // Allows for "/..." suffix + terminator char min_uid_buf[MAX_UID_LEN + 1], max_uid_buf[MAX_UID_LEN + 1]; char min_gid_buf[MAX_GID_LEN + 1], max_gid_buf[MAX_GID_LEN + 1]; - char rule_text_buf[MAX_NAME_LEN + 2*MAX_UID_LEN + 2*MAX_GID_LEN + 9]; unsigned long min_mode, max_mode; - perm_rule_t *pr; int res; int num_rules = 0, num_lines = 0; @@ -110,56 +170,25 @@ static int read_rules(FILE *fp) printf("# WARNING # Invalid rule on line number %d\n", num_lines); continue; } - if (!(pr = malloc(sizeof(perm_rule_t)))) { - printf("Out of memory.\n"); - exit(255); - } - if (snprintf(rule_text_buf, sizeof(rule_text_buf), - "%s %lo %lo %s %s %s %s", spec, min_mode, max_mode, - min_uid_buf, max_uid_buf, min_gid_buf, max_gid_buf) - >= (long int) sizeof(rule_text_buf)) { - // This should never happen, but just in case... - printf("# ERROR # Maximum length limits exceeded on line %d\n", - num_lines); - exit(255); - } - pr->rule_text = strndup(rule_text_buf, sizeof(rule_text_buf)); - pr->rule_line = num_lines; - if (strstr(spec, "/...")) { - pr->spec = strndup(spec, strlen(spec) - 3); - pr->type = RECURSIVE; - } else if (spec[strlen(spec) - 1] == '*') { - pr->spec = strndup(spec, strlen(spec) - 1); - pr->type = WILDCARD; - } else if (spec[strlen(spec) - 1] == '/') { - pr->spec = strdup(spec); - pr->type = EXACT_DIR; - } else { - pr->spec = strdup(spec); - pr->type = EXACT_FILE; - } - if ((pr->spec == NULL) || (pr->rule_text == NULL)) { - printf("Out of memory.\n"); - exit(255); - } - pr->min_mode = min_mode; - pr->max_mode = max_mode; - pr->min_uid = str2uid(min_uid_buf, num_lines); - pr->max_uid = str2uid(max_uid_buf, num_lines); - pr->min_gid = str2gid(min_gid_buf, num_lines); - pr->max_gid = str2gid(max_gid_buf, num_lines); - - // Add the rule to the appropriate set - pr->next = rules[pr->type]; - rules[pr->type] = pr; + add_rule(num_lines, spec, + min_mode, max_mode, + min_uid_buf, max_uid_buf, + min_gid_buf, max_gid_buf); num_rules++; -#if 0 // Useful for debugging - printf("rule #%d: type = %d spec = %s min_mode = %o max_mode = %o " - "min_uid = %d max_uid = %d min_gid = %d max_gid = %d\n", - num_rules, pr->type, pr->spec, pr->min_mode, pr->max_mode, - pr->min_uid, pr->max_uid, pr->min_gid, pr->max_gid); -#endif } + + // Automatically add a rule to match this executable itself + add_rule(-1, executable_file, + 000, 0777, + "root", "shell", + "root", "shell"); + + // Automatically add a rule to match the configuration file + add_rule(-1, config_file, + 000, 0777, + "root", "shell", + "root", "shell"); + return num_lines - num_rules; } @@ -274,7 +303,7 @@ static int validate_link(const char *name, mode_t mode, uid_t uid, gid_t gid) printf("# WARNING # Multiple exact rules for link: %s\n", name); if (retval) print_new_rule(name, mode, uid, gid); - + // Note: Unlike files, if no rules matches for links, retval = 0 (success). return retval; } @@ -380,12 +409,18 @@ int main(int argc, char **argv) FILE *fp; int i; + if (argc > 2) { + printf("\nSyntax: %s [configfilename]\n", argv[0]); + } + config_file = (argc == 2) ? argv[1] : DEFAULT_CONFIG_FILE; + executable_file = argv[0]; + // Initialize ruleset pointers for (i = 0; i < NUM_PR_TYPES; i++) rules[i] = NULL; - if (!(fp = fopen("/etc/perm_checker.conf", "r"))) { - printf("Error opening /etc/perm_checker.conf\n"); + if (!(fp = fopen(config_file, "r"))) { + printf("Error opening %s\n", config_file); exit(255); } read_rules(fp); @@ -393,7 +428,7 @@ int main(int argc, char **argv) if (check_path("/")) return 255; - + printf("Passed.\n"); return 0; } diff --git a/tests/fstest/perm_checker.conf b/tests/fstest/perm_checker.conf index 15485b84..467c713a 100644 --- a/tests/fstest/perm_checker.conf +++ b/tests/fstest/perm_checker.conf @@ -139,7 +139,6 @@ /system/etc/init.goldfish.sh 500 550 root root root shell /system/etc/init.gprs-pppd 500 550 root root root shell /system/etc/init.testmenu 500 550 root root root root -/system/etc/perm_checker.conf 000 777 root shell root shell /system/etc/ppp/ 755 755 root root root root /system/etc/ppp/* 555 555 root root root root /system/etc/security/ 755 755 root root root root |