Merge "Add support for filesystem capabilities."

This commit is contained in:
Nick Kralevich 2013-02-23 02:03:36 +00:00 committed by Gerrit Code Review
commit e3f247c0e5
2 changed files with 63 additions and 58 deletions

View file

@ -55,6 +55,7 @@ static int total_size = 0;
static void fix_stat(const char *path, struct stat *s) static void fix_stat(const char *path, struct stat *s)
{ {
uint64_t capabilities;
if (canned_config) { if (canned_config) {
// Use the list of file uid/gid/modes loaded from the file // Use the list of file uid/gid/modes loaded from the file
// given with -f. // given with -f.
@ -78,7 +79,7 @@ static void fix_stat(const char *path, struct stat *s)
} else { } else {
// Use the compiled-in fs_config() function. // Use the compiled-in fs_config() function.
fs_config(path, S_ISDIR(s->st_mode), &s->st_uid, &s->st_gid, &s->st_mode); fs_config(path, S_ISDIR(s->st_mode), &s->st_uid, &s->st_gid, &s->st_mode, &capabilities);
} }
} }

View file

@ -25,6 +25,8 @@
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <stdint.h>
#include <linux/capability.h>
/* This is the master Users and Groups config for the platform. /* This is the master Users and Groups config for the platform.
** DO NOT EVER RENUMBER. ** DO NOT EVER RENUMBER.
@ -152,6 +154,7 @@ struct fs_path_config {
unsigned mode; unsigned mode;
unsigned uid; unsigned uid;
unsigned gid; unsigned gid;
uint64_t capabilities;
const char *prefix; const char *prefix;
}; };
@ -161,26 +164,26 @@ struct fs_path_config {
** way up to the root. ** way up to the root.
*/ */
static struct fs_path_config android_dirs[] = { static const struct fs_path_config android_dirs[] = {
{ 00770, AID_SYSTEM, AID_CACHE, "cache" }, { 00770, AID_SYSTEM, AID_CACHE, 0, "cache" },
{ 00771, AID_SYSTEM, AID_SYSTEM, "data/app" }, { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app" },
{ 00771, AID_SYSTEM, AID_SYSTEM, "data/app-private" }, { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private" },
{ 00771, AID_SYSTEM, AID_SYSTEM, "data/dalvik-cache" }, { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/dalvik-cache" },
{ 00771, AID_SYSTEM, AID_SYSTEM, "data/data" }, { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/data" },
{ 00771, AID_SHELL, AID_SHELL, "data/local/tmp" }, { 00771, AID_SHELL, AID_SHELL, 0, "data/local/tmp" },
{ 00771, AID_SHELL, AID_SHELL, "data/local" }, { 00771, AID_SHELL, AID_SHELL, 0, "data/local" },
{ 01771, AID_SYSTEM, AID_MISC, "data/misc" }, { 01771, AID_SYSTEM, AID_MISC, 0, "data/misc" },
{ 00770, AID_DHCP, AID_DHCP, "data/misc/dhcp" }, { 00770, AID_DHCP, AID_DHCP, 0, "data/misc/dhcp" },
{ 00775, AID_MEDIA_RW, AID_MEDIA_RW, "data/media" }, { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media" },
{ 00775, AID_MEDIA_RW, AID_MEDIA_RW, "data/media/Music" }, { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/Music" },
{ 00771, AID_SYSTEM, AID_SYSTEM, "data" }, { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data" },
{ 00750, AID_ROOT, AID_SHELL, "sbin" }, { 00750, AID_ROOT, AID_SHELL, 0, "sbin" },
{ 00755, AID_ROOT, AID_SHELL, "system/bin" }, { 00755, AID_ROOT, AID_SHELL, 0, "system/bin" },
{ 00755, AID_ROOT, AID_SHELL, "system/vendor" }, { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor" },
{ 00755, AID_ROOT, AID_SHELL, "system/xbin" }, { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" },
{ 00755, AID_ROOT, AID_ROOT, "system/etc/ppp" }, { 00755, AID_ROOT, AID_ROOT, 0, "system/etc/ppp" },
{ 00777, AID_ROOT, AID_ROOT, "sdcard" }, { 00777, AID_ROOT, AID_ROOT, 0, "sdcard" },
{ 00755, AID_ROOT, AID_ROOT, 0 }, { 00755, AID_ROOT, AID_ROOT, 0, 0 },
}; };
/* Rules for files. /* Rules for files.
@ -189,53 +192,53 @@ static struct fs_path_config android_dirs[] = {
** way up to the root. Prefixes ending in * denotes wildcard ** way up to the root. Prefixes ending in * denotes wildcard
** and will allow partial matches. ** and will allow partial matches.
*/ */
static struct fs_path_config android_files[] = { static const struct fs_path_config android_files[] = {
{ 00440, AID_ROOT, AID_SHELL, "system/etc/init.goldfish.rc" }, { 00440, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.rc" },
{ 00550, AID_ROOT, AID_SHELL, "system/etc/init.goldfish.sh" }, { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.sh" },
{ 00440, AID_ROOT, AID_SHELL, "system/etc/init.trout.rc" }, { 00440, AID_ROOT, AID_SHELL, 0, "system/etc/init.trout.rc" },
{ 00550, AID_ROOT, AID_SHELL, "system/etc/init.ril" }, { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.ril" },
{ 00550, AID_ROOT, AID_SHELL, "system/etc/init.testmenu" }, { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.testmenu" },
{ 00550, AID_DHCP, AID_SHELL, "system/etc/dhcpcd/dhcpcd-run-hooks" }, { 00550, AID_DHCP, AID_SHELL, 0, "system/etc/dhcpcd/dhcpcd-run-hooks" },
{ 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/dbus.conf" }, { 00440, AID_BLUETOOTH, AID_BLUETOOTH, 0, "system/etc/dbus.conf" },
{ 00444, AID_RADIO, AID_AUDIO, "system/etc/AudioPara4.csv" }, { 00444, AID_RADIO, AID_AUDIO, 0, "system/etc/AudioPara4.csv" },
{ 00555, AID_ROOT, AID_ROOT, "system/etc/ppp/*" }, { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/ppp/*" },
{ 00555, AID_ROOT, AID_ROOT, "system/etc/rc.*" }, { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/rc.*" },
{ 00644, AID_SYSTEM, AID_SYSTEM, "data/app/*" }, { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app/*" },
{ 00644, AID_MEDIA_RW, AID_MEDIA_RW, "data/media/*" }, { 00644, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/*" },
{ 00644, AID_SYSTEM, AID_SYSTEM, "data/app-private/*" }, { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private/*" },
{ 00644, AID_APP, AID_APP, "data/data/*" }, { 00644, AID_APP, AID_APP, 0, "data/data/*" },
/* the following two files are INTENTIONALLY set-gid and not set-uid. /* the following two files are INTENTIONALLY set-gid and not set-uid.
* Do not change. */ * Do not change. */
{ 02755, AID_ROOT, AID_NET_RAW, "system/bin/ping" }, { 02755, AID_ROOT, AID_NET_RAW, 0, "system/bin/ping" },
{ 02750, AID_ROOT, AID_INET, "system/bin/netcfg" }, { 02750, AID_ROOT, AID_INET, 0, "system/bin/netcfg" },
/* the following five files are INTENTIONALLY set-uid, but they /* the following five files are INTENTIONALLY set-uid, but they
* are NOT included on user builds. */ * are NOT included on user builds. */
{ 06755, AID_ROOT, AID_ROOT, "system/xbin/su" }, { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/su" },
{ 06755, AID_ROOT, AID_ROOT, "system/xbin/librank" }, { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/librank" },
{ 06755, AID_ROOT, AID_ROOT, "system/xbin/procrank" }, { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procrank" },
{ 06755, AID_ROOT, AID_ROOT, "system/xbin/procmem" }, { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" },
{ 06755, AID_ROOT, AID_ROOT, "system/xbin/tcpdump" }, { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/tcpdump" },
{ 04770, AID_ROOT, AID_RADIO, "system/bin/pppd-ril" }, { 04770, AID_ROOT, AID_RADIO, 0, "system/bin/pppd-ril" },
/* the following file is INTENTIONALLY set-uid, and IS included /* the following file is INTENTIONALLY set-uid, and IS included
* in user builds. */ * in user builds. */
{ 06750, AID_ROOT, AID_SHELL, "system/bin/run-as" }, { 06750, AID_ROOT, AID_SHELL, 0, "system/bin/run-as" },
{ 00755, AID_ROOT, AID_SHELL, "system/bin/*" }, { 00755, AID_ROOT, AID_SHELL, 0, "system/bin/*" },
{ 00755, AID_ROOT, AID_ROOT, "system/lib/valgrind/*" }, { 00755, AID_ROOT, AID_ROOT, 0, "system/lib/valgrind/*" },
{ 00755, AID_ROOT, AID_SHELL, "system/xbin/*" }, { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin/*" },
{ 00755, AID_ROOT, AID_SHELL, "system/vendor/bin/*" }, { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor/bin/*" },
{ 00750, AID_ROOT, AID_SHELL, "sbin/*" }, { 00750, AID_ROOT, AID_SHELL, 0, "sbin/*" },
{ 00755, AID_ROOT, AID_ROOT, "bin/*" }, { 00755, AID_ROOT, AID_ROOT, 0, "bin/*" },
{ 00750, AID_ROOT, AID_SHELL, "init*" }, { 00750, AID_ROOT, AID_SHELL, 0, "init*" },
{ 00750, AID_ROOT, AID_SHELL, "charger*" }, { 00750, AID_ROOT, AID_SHELL, 0, "charger*" },
{ 00750, AID_ROOT, AID_SHELL, "sbin/fs_mgr" }, { 00750, AID_ROOT, AID_SHELL, 0, "sbin/fs_mgr" },
{ 00640, AID_ROOT, AID_SHELL, "fstab.*" }, { 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" },
{ 00644, AID_ROOT, AID_ROOT, 0 }, { 00644, AID_ROOT, AID_ROOT, 0, 0 },
}; };
static inline void fs_config(const char *path, int dir, static inline void fs_config(const char *path, int dir,
unsigned *uid, unsigned *gid, unsigned *mode) unsigned *uid, unsigned *gid, unsigned *mode, uint64_t *capabilities)
{ {
struct fs_path_config *pc; const struct fs_path_config *pc;
int plen; int plen;
if (path[0] == '/') { if (path[0] == '/') {
@ -261,6 +264,7 @@ static inline void fs_config(const char *path, int dir,
*uid = pc->uid; *uid = pc->uid;
*gid = pc->gid; *gid = pc->gid;
*mode = (*mode & (~07777)) | pc->mode; *mode = (*mode & (~07777)) | pc->mode;
*capabilities = pc->capabilities;
#if 0 #if 0
fprintf(stderr,"< '%s' '%s' %d %d %o >\n", fprintf(stderr,"< '%s' '%s' %d %d %o >\n",