Skip to content

Commit

Permalink
fix derp
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Pohlad-Thomas committed Aug 14, 2013
1 parent 3c42387 commit 71173bf
Showing 1 changed file with 93 additions and 74 deletions.
167 changes: 93 additions & 74 deletions include/private/android_filesystem_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdint.h>

#ifdef HAVE_ANDROID_OS
#include <linux/capability.h>
#else
#include "android_filesystem_capability.h"
#endif

/* This is the master Users and Groups config for the platform.
** DO NOT EVER RENUMBER.
Expand Down Expand Up @@ -62,9 +69,12 @@
#define AID_DRMRPC 1026 /* group for drm rpc */
#define AID_NFC 1027 /* nfc subsystem */
#define AID_SDCARD_R 1028 /* external storage read access */
#define AID_FM_RADIO 1029 /* FM radio */
#define AID_SMARTCARD 1130 /* smart card subsystem */
#define AID_AUDIT 1031 /* audit daemon */
#define AID_CLAT 1029 /* clat part of nat464 */
#define AID_LOOP_RADIO 1030 /* loop radio devices */
#define AID_MEDIA_DRM 1031 /* MediaDrm plugins */
#define AID_AUDIT 1032 /* audit daemon */
#define AID_FM_RADIO 1033 /* FM radio */
#define AID_SMARTCARD 1134 /* smart card subsystem */

#define AID_THEMEMAN 1300 /* theme manager */

Expand Down Expand Up @@ -159,6 +169,7 @@ static const struct android_id_info android_ids[] = {
{ "net_admin", AID_NET_ADMIN, },
{ "net_bw_stats", AID_NET_BW_STATS, },
{ "net_bw_acct", AID_NET_BW_ACCT, },
{ "loop_radio", AID_LOOP_RADIO, },
{ "qcom_oncrpc", AID_QCOM_ONCRPC, },
{ "qcom_diag", AID_QCOM_DIAG, },
{ "fm_radio", AID_FM_RADIO, },
Expand All @@ -177,6 +188,8 @@ static const struct android_id_info android_ids[] = {
{ "mot_atvc", AID_MOT_ATVC, },
{ "misc", AID_MISC, },
{ "nobody", AID_NOBODY, },
{ "clat", AID_CLAT, },
{ "mediadrm", AID_MEDIA_DRM, },
{ "theme_man", AID_THEMEMAN },
{ "audit", AID_AUDIT, },
};
Expand All @@ -188,6 +201,7 @@ struct fs_path_config {
unsigned mode;
unsigned uid;
unsigned gid;
uint64_t capabilities;
const char *prefix;
};

Expand All @@ -197,27 +211,28 @@ struct fs_path_config {
** way up to the root.
*/

static struct fs_path_config android_dirs[] = {
{ 00770, AID_SYSTEM, AID_CACHE, "cache" },
{ 00771, AID_SYSTEM, AID_SYSTEM, "data/app" },
{ 00771, AID_SYSTEM, AID_SYSTEM, "data/app-private" },
{ 00771, AID_SYSTEM, AID_SYSTEM, "data/dalvik-cache" },
{ 00771, AID_SYSTEM, AID_SYSTEM, "data/data" },
{ 00771, AID_SHELL, AID_SHELL, "data/local/tmp" },
{ 00771, AID_SHELL, AID_SHELL, "data/local" },
{ 01771, AID_SYSTEM, AID_MISC, "data/misc" },
{ 00770, AID_DHCP, AID_DHCP, "data/misc/dhcp" },
{ 00775, AID_MEDIA_RW, AID_MEDIA_RW, "data/media" },
{ 00775, AID_MEDIA_RW, AID_MEDIA_RW, "data/media/Music" },
{ 00771, AID_SYSTEM, AID_SYSTEM, "data" },
{ 00750, AID_ROOT, AID_SHELL, "sbin" },
{ 00755, AID_ROOT, AID_ROOT, "system/addon.d" },
{ 00755, AID_ROOT, AID_SHELL, "system/bin" },
{ 00755, AID_ROOT, AID_SHELL, "system/vendor" },
{ 00755, AID_ROOT, AID_SHELL, "system/xbin" },
{ 00755, AID_ROOT, AID_ROOT, "system/etc/ppp" },
{ 00777, AID_ROOT, AID_ROOT, "sdcard" },
{ 00755, AID_ROOT, AID_ROOT, 0 },
static const struct fs_path_config android_dirs[] = {
{ 00770, AID_SYSTEM, AID_CACHE, 0, "cache" },
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app" },
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private" },
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/dalvik-cache" },
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/data" },
{ 00771, AID_SHELL, AID_SHELL, 0, "data/local/tmp" },
{ 00771, AID_SHELL, AID_SHELL, 0, "data/local" },
{ 01771, AID_SYSTEM, AID_MISC, 0, "data/misc" },
{ 00770, AID_DHCP, AID_DHCP, 0, "data/misc/dhcp" },
{ 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media" },
{ 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/Music" },
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data" },
{ 00750, AID_ROOT, AID_SHELL, 0, "sbin" },
{ 00755, AID_ROOT, AID_ROOT, 0, "system/addon.d" },
{ 00755, AID_ROOT, AID_SHELL, 0, "system/bin" },
{ 00755, AID_ROOT, AID_SHELL, 0, "system/vendor" },
{ 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" },
{ 00755, AID_ROOT, AID_ROOT, 0, "system/etc/ppp" },
{ 00755, AID_ROOT, AID_SHELL, 0, "vendor" },
{ 00777, AID_ROOT, AID_ROOT, 0, "sdcard" },
{ 00755, AID_ROOT, AID_ROOT, 0, 0 },
};

/* Rules for files.
Expand All @@ -226,62 +241,65 @@ static struct fs_path_config android_dirs[] = {
** way up to the root. Prefixes ending in * denotes wildcard
** and will allow partial matches.
*/
static struct fs_path_config android_files[] = {
{ 00440, AID_ROOT, AID_SHELL, "system/etc/init.goldfish.rc" },
{ 00550, AID_ROOT, AID_SHELL, "system/etc/init.goldfish.sh" },
{ 00550, AID_SYSTEM, AID_SYSTEM, "system/etc/init.qcom.sdio.sh" },
{ 00440, AID_ROOT, AID_SHELL, "system/etc/init.trout.rc" },
{ 00550, AID_ROOT, AID_SHELL, "system/etc/init.ril" },
{ 00550, AID_ROOT, AID_SHELL, "system/etc/init.testmenu" },
{ 00550, AID_DHCP, AID_SHELL, "system/etc/dhcpcd/dhcpcd-run-hooks" },
{ 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/dbus.conf" },
{ 00644, AID_SYSTEM, AID_SYSTEM, "system/etc/paranoid/properties.conf" },
{ 00444, AID_RADIO, AID_AUDIO, "system/etc/AudioPara4.csv" },
{ 00555, AID_ROOT, AID_ROOT, "system/etc/ppp/*" },
{ 00555, AID_ROOT, AID_ROOT, "system/etc/rc.*" },
{ 00755, AID_ROOT, AID_ROOT, "system/addon.d/*" },
{ 00644, AID_SYSTEM, AID_SYSTEM, "data/app/*" },
{ 00644, AID_MEDIA_RW, AID_MEDIA_RW, "data/media/*" },
{ 00644, AID_SYSTEM, AID_SYSTEM, "data/app-private/*" },
{ 00644, AID_APP, AID_APP, "data/data/*" },
/* the following two files are INTENTIONALLY set-gid and not set-uid.
* Do not change. */
{ 02755, AID_ROOT, AID_NET_RAW, "system/bin/ping" },
{ 02750, AID_ROOT, AID_INET, "system/bin/netcfg" },
/* the following five files are INTENTIONALLY set-uid, but they
* are NOT included on user builds. */
{ 06755, AID_ROOT, AID_ROOT, "system/xbin/su" },
{ 06755, AID_ROOT, AID_ROOT, "system/xbin/librank" },
{ 06755, AID_ROOT, AID_ROOT, "system/xbin/procrank" },
{ 06755, AID_ROOT, AID_ROOT, "system/xbin/procmem" },
{ 06755, AID_ROOT, AID_ROOT, "system/xbin/tcpdump" },
{ 04770, AID_ROOT, AID_RADIO, "system/bin/pppd-ril" },
/* the following file is INTENTIONALLY set-uid, and IS included
* in user builds. */
{ 06750, AID_ROOT, AID_SHELL, "system/bin/run-as" },
{ 06750, AID_ROOT, AID_SYSTEM, "system/bin/rebootcmd" },
{ 00750, AID_ROOT, AID_SYSTEM, "system/bin/tc" },
{ 00750, AID_ROOT, AID_SYSTEM, "system/bin/iptables" },
{ 00755, AID_ROOT, AID_SHELL, "system/bin/*" },
{ 00755, AID_ROOT, AID_ROOT, "system/lib/valgrind/*" },
{ 00755, AID_ROOT, AID_SHELL, "system/xbin/*" },
{ 00755, AID_ROOT, AID_SHELL, "system/vendor/bin/*" },
{ 00750, AID_ROOT, AID_SHELL, "sbin/*" },
{ 00755, AID_ROOT, AID_ROOT, "bin/*" },
{ 00750, AID_ROOT, AID_SHELL, "init*" },
{ 00750, AID_ROOT, AID_SHELL, "charger*" },
{ 00750, AID_ROOT, AID_SHELL, "sbin/fs_mgr" },
{ 00640, AID_ROOT, AID_SHELL, "fstab.*" },
{ 00755, AID_ROOT, AID_SHELL, "system/etc/init.d/*" },
{ 00644, AID_ROOT, AID_ROOT, 0 },
static const struct fs_path_config android_files[] = {
{ 00440, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.rc" },
{ 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.sh" },
{ 00550, AID_SYSTEM, AID_SYSTEM, 0, "system/etc/init.qcom.sdio.sh" },
{ 00440, AID_ROOT, AID_SHELL, 0, "system/etc/init.trout.rc" },
{ 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.ril" },
{ 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.testmenu" },
{ 00550, AID_DHCP, AID_SHELL, 0, "system/etc/dhcpcd/dhcpcd-run-hooks" },
{ 00444, AID_RADIO, AID_AUDIO, 0, "system/etc/AudioPara4.csv" },
{ 00555, AID_ROOT, AID_ROOT, 0, "system/etc/ppp/*" },
{ 00555, AID_ROOT, AID_ROOT, 0, "system/etc/rc.*" },
{ 00755, AID_ROOT, AID_ROOT, 0, "system/addon.d/*" },
{ 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app/*" },
{ 00644, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/*" },
{ 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private/*" },
{ 00644, AID_APP, AID_APP, 0, "data/data/*" },
{ 00755, AID_ROOT, AID_ROOT, 0, "system/bin/ping" },

/* the following file is INTENTIONALLY set-gid and not set-uid.
* Do not change. */
{ 02750, AID_ROOT, AID_INET, 0, "system/bin/netcfg" },

/* the following five files are INTENTIONALLY set-uid, but they
* are NOT included on user builds. */
{ 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/su" },
{ 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/librank" },
{ 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procrank" },
{ 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" },
{ 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/tcpdump" },
{ 04770, AID_ROOT, AID_RADIO, 0, "system/bin/pppd-ril" },

/* the following file has enhanced capabilities and IS included in user builds. */
{ 00750, AID_ROOT, AID_SHELL, (1 << CAP_SETUID) | (1 << CAP_SETGID), "system/bin/run-as" },

{ 00755, AID_ROOT, AID_SHELL, 0, "system/bin/*" },
{ 00755, AID_ROOT, AID_ROOT, 0, "system/lib/valgrind/*" },
{ 00755, AID_ROOT, AID_SHELL, 0, "system/xbin/*" },
{ 00755, AID_ROOT, AID_SHELL, 0, "system/vendor/bin/*" },
{ 00755, AID_ROOT, AID_SHELL, 0, "vendor/bin/*" },
{ 00750, AID_ROOT, AID_SHELL, 0, "sbin/*" },
{ 00755, AID_ROOT, AID_ROOT, 0, "bin/*" },
{ 00750, AID_ROOT, AID_SHELL, 0, "init*" },
{ 00750, AID_ROOT, AID_SHELL, 0, "charger*" },
{ 00750, AID_ROOT, AID_SHELL, 0, "sbin/fs_mgr" },
{ 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" },
{ 00755, AID_ROOT, AID_SHELL, 0, "system/etc/init.d/*" },
{ 00644, AID_ROOT, AID_ROOT, 0, 0 },
};

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;

if (path[0] == '/') {
path++;
}

pc = dir ? android_dirs : android_files;
plen = strlen(path);
for(; pc->prefix; pc++){
Expand All @@ -301,6 +319,7 @@ static inline void fs_config(const char *path, int dir,
*uid = pc->uid;
*gid = pc->gid;
*mode = (*mode & (~07777)) | pc->mode;
*capabilities = pc->capabilities;

#if 0
fprintf(stderr,"< '%s' '%s' %d %d %o >\n",
Expand Down

0 comments on commit 71173bf

Please sign in to comment.