android_filesystem_config.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * Copyright (C) 2007 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* This file is used to define the properties of the filesystem
  17. ** images generated by build tools (mkbootfs and mkyaffs2image) and
  18. ** by the device side of adb.
  19. */
  20. #ifndef _ANDROID_FILESYSTEM_CONFIG_H_
  21. #define _ANDROID_FILESYSTEM_CONFIG_H_
  22. #include <string.h>
  23. #include <sys/stat.h>
  24. #include <sys/types.h>
  25. /* This is the master Users and Groups config for the platform.
  26. ** DO NOT EVER RENUMBER.
  27. */
  28. #define AID_ROOT 0 /* traditional unix root user */
  29. #define AID_SYSTEM 1000 /* system server */
  30. #define AID_RADIO 1001 /* telephony subsystem, RIL */
  31. #define AID_BLUETOOTH 1002 /* bluetooth subsystem */
  32. #define AID_GRAPHICS 1003 /* graphics devices */
  33. #define AID_INPUT 1004 /* input devices */
  34. #define AID_AUDIO 1005 /* audio devices */
  35. #define AID_CAMERA 1006 /* camera devices */
  36. #define AID_LOG 1007 /* log devices */
  37. #define AID_COMPASS 1008 /* compass device */
  38. #define AID_MOUNT 1009 /* mountd socket */
  39. #define AID_WIFI 1010 /* wifi subsystem */
  40. #define AID_ADB 1011 /* android debug bridge (adbd) */
  41. #define AID_INSTALL 1012 /* group for installing packages */
  42. #define AID_MEDIA 1013 /* mediaserver process */
  43. #define AID_DHCP 1014 /* dhcp client */
  44. #define AID_SDCARD_RW 1015 /* external storage write access */
  45. #define AID_VPN 1016 /* vpn system */
  46. #define AID_KEYSTORE 1017 /* keystore subsystem */
  47. #define AID_USB 1018 /* USB devices */
  48. #define AID_DRM 1019 /* DRM server */
  49. #define AID_MDNSR 1020 /* MulticastDNSResponder (service discovery) */
  50. #define AID_GPS 1021 /* GPS daemon */
  51. #define AID_UNUSED1 1022 /* deprecated, DO NOT USE */
  52. #define AID_MEDIA_RW 1023 /* internal media storage write access */
  53. #define AID_MTP 1024 /* MTP USB driver access */
  54. #define AID_UNUSED2 1025 /* deprecated, DO NOT USE */
  55. #define AID_DRMRPC 1026 /* group for drm rpc */
  56. #define AID_NFC 1027 /* nfc subsystem */
  57. #define AID_SDCARD_R 1028 /* external storage read access */
  58. #define AID_SHELL 2000 /* adb and debug shell user */
  59. #define AID_CACHE 2001 /* cache access */
  60. #define AID_DIAG 2002 /* access to diagnostic resources */
  61. /* The 3000 series are intended for use as supplemental group id's only.
  62. * They indicate special Android capabilities that the kernel is aware of. */
  63. #define AID_NET_BT_ADMIN 3001 /* bluetooth: create any socket */
  64. #define AID_NET_BT 3002 /* bluetooth: create sco, rfcomm or l2cap sockets */
  65. #define AID_INET 3003 /* can create AF_INET and AF_INET6 sockets */
  66. #define AID_NET_RAW 3004 /* can create raw INET sockets */
  67. #define AID_NET_ADMIN 3005 /* can configure interfaces and routing tables. */
  68. #define AID_NET_BW_STATS 3006 /* read bandwidth statistics */
  69. #define AID_NET_BW_ACCT 3007 /* change bandwidth statistics accounting */
  70. #define AID_NET_BT_STACK 3008 /* bluetooth: access config files */
  71. #define AID_MISC 9998 /* access to misc storage */
  72. #define AID_NOBODY 9999
  73. #define AID_APP 10000 /* first app user */
  74. #define AID_ISOLATED_START 99000 /* start of uids for fully isolated sandboxed processes */
  75. #define AID_ISOLATED_END 99999 /* end of uids for fully isolated sandboxed processes */
  76. #define AID_USER 100000 /* offset for uid ranges for each user */
  77. #define AID_SHARED_GID_START 50000 /* start of gids for apps in each user to share */
  78. #define AID_SHARED_GID_END 59999 /* start of gids for apps in each user to share */
  79. #if !defined(EXCLUDE_FS_CONFIG_STRUCTURES)
  80. struct android_id_info {
  81. const char *name;
  82. unsigned aid;
  83. };
  84. static const struct android_id_info android_ids[] = {
  85. { "root", AID_ROOT, },
  86. { "system", AID_SYSTEM, },
  87. { "radio", AID_RADIO, },
  88. { "bluetooth", AID_BLUETOOTH, },
  89. { "graphics", AID_GRAPHICS, },
  90. { "input", AID_INPUT, },
  91. { "audio", AID_AUDIO, },
  92. { "camera", AID_CAMERA, },
  93. { "log", AID_LOG, },
  94. { "compass", AID_COMPASS, },
  95. { "mount", AID_MOUNT, },
  96. { "wifi", AID_WIFI, },
  97. { "dhcp", AID_DHCP, },
  98. { "adb", AID_ADB, },
  99. { "install", AID_INSTALL, },
  100. { "media", AID_MEDIA, },
  101. { "drm", AID_DRM, },
  102. { "mdnsr", AID_MDNSR, },
  103. { "nfc", AID_NFC, },
  104. { "drmrpc", AID_DRMRPC, },
  105. { "shell", AID_SHELL, },
  106. { "cache", AID_CACHE, },
  107. { "diag", AID_DIAG, },
  108. { "net_bt_admin", AID_NET_BT_ADMIN, },
  109. { "net_bt", AID_NET_BT, },
  110. { "net_bt_stack", AID_NET_BT_STACK, },
  111. { "sdcard_r", AID_SDCARD_R, },
  112. { "sdcard_rw", AID_SDCARD_RW, },
  113. { "media_rw", AID_MEDIA_RW, },
  114. { "vpn", AID_VPN, },
  115. { "keystore", AID_KEYSTORE, },
  116. { "usb", AID_USB, },
  117. { "mtp", AID_MTP, },
  118. { "gps", AID_GPS, },
  119. { "inet", AID_INET, },
  120. { "net_raw", AID_NET_RAW, },
  121. { "net_admin", AID_NET_ADMIN, },
  122. { "net_bw_stats", AID_NET_BW_STATS, },
  123. { "net_bw_acct", AID_NET_BW_ACCT, },
  124. { "misc", AID_MISC, },
  125. { "nobody", AID_NOBODY, },
  126. };
  127. #define android_id_count \
  128. (sizeof(android_ids) / sizeof(android_ids[0]))
  129. struct fs_path_config {
  130. unsigned mode;
  131. unsigned uid;
  132. unsigned gid;
  133. const char *prefix;
  134. };
  135. /* Rules for directories.
  136. ** These rules are applied based on "first match", so they
  137. ** should start with the most specific path and work their
  138. ** way up to the root.
  139. */
  140. static struct fs_path_config android_dirs[] = {
  141. { 00770, AID_SYSTEM, AID_CACHE, "cache" },
  142. { 00771, AID_SYSTEM, AID_SYSTEM, "data/app" },
  143. { 00771, AID_SYSTEM, AID_SYSTEM, "data/app-private" },
  144. { 00771, AID_SYSTEM, AID_SYSTEM, "data/dalvik-cache" },
  145. { 00771, AID_SYSTEM, AID_SYSTEM, "data/data" },
  146. { 00771, AID_SHELL, AID_SHELL, "data/local/tmp" },
  147. { 00771, AID_SHELL, AID_SHELL, "data/local" },
  148. { 01771, AID_SYSTEM, AID_MISC, "data/misc" },
  149. { 00770, AID_DHCP, AID_DHCP, "data/misc/dhcp" },
  150. { 00775, AID_MEDIA_RW, AID_MEDIA_RW, "data/media" },
  151. { 00775, AID_MEDIA_RW, AID_MEDIA_RW, "data/media/Music" },
  152. { 00771, AID_SYSTEM, AID_SYSTEM, "data" },
  153. { 00750, AID_ROOT, AID_SHELL, "sbin" },
  154. { 00755, AID_ROOT, AID_SHELL, "system/bin" },
  155. { 00755, AID_ROOT, AID_SHELL, "system/vendor" },
  156. { 00755, AID_ROOT, AID_SHELL, "system/xbin" },
  157. { 00755, AID_ROOT, AID_ROOT, "system/etc/ppp" },
  158. { 00777, AID_ROOT, AID_ROOT, "sdcard" },
  159. { 00755, AID_ROOT, AID_ROOT, 0 },
  160. };
  161. /* Rules for files.
  162. ** These rules are applied based on "first match", so they
  163. ** should start with the most specific path and work their
  164. ** way up to the root. Prefixes ending in * denotes wildcard
  165. ** and will allow partial matches.
  166. */
  167. static struct fs_path_config android_files[] = {
  168. { 00440, AID_ROOT, AID_SHELL, "system/etc/init.goldfish.rc" },
  169. { 00550, AID_ROOT, AID_SHELL, "system/etc/init.goldfish.sh" },
  170. { 00440, AID_ROOT, AID_SHELL, "system/etc/init.trout.rc" },
  171. { 00550, AID_ROOT, AID_SHELL, "system/etc/init.ril" },
  172. { 00550, AID_ROOT, AID_SHELL, "system/etc/init.testmenu" },
  173. { 00550, AID_DHCP, AID_SHELL, "system/etc/dhcpcd/dhcpcd-run-hooks" },
  174. { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/dbus.conf" },
  175. { 00444, AID_RADIO, AID_AUDIO, "system/etc/AudioPara4.csv" },
  176. { 00555, AID_ROOT, AID_ROOT, "system/etc/ppp/*" },
  177. { 00555, AID_ROOT, AID_ROOT, "system/etc/rc.*" },
  178. { 00644, AID_SYSTEM, AID_SYSTEM, "data/app/*" },
  179. { 00644, AID_MEDIA_RW, AID_MEDIA_RW, "data/media/*" },
  180. { 00644, AID_SYSTEM, AID_SYSTEM, "data/app-private/*" },
  181. { 00644, AID_APP, AID_APP, "data/data/*" },
  182. /* the following two files are INTENTIONALLY set-gid and not set-uid.
  183. * Do not change. */
  184. { 02755, AID_ROOT, AID_NET_RAW, "system/bin/ping" },
  185. { 02750, AID_ROOT, AID_INET, "system/bin/netcfg" },
  186. /* the following five files are INTENTIONALLY set-uid, but they
  187. * are NOT included on user builds. */
  188. { 06755, AID_ROOT, AID_ROOT, "system/xbin/su" },
  189. { 06755, AID_ROOT, AID_ROOT, "system/xbin/librank" },
  190. { 06755, AID_ROOT, AID_ROOT, "system/xbin/procrank" },
  191. { 06755, AID_ROOT, AID_ROOT, "system/xbin/procmem" },
  192. { 06755, AID_ROOT, AID_ROOT, "system/xbin/tcpdump" },
  193. { 04770, AID_ROOT, AID_RADIO, "system/bin/pppd-ril" },
  194. /* the following file is INTENTIONALLY set-uid, and IS included
  195. * in user builds. */
  196. { 06750, AID_ROOT, AID_SHELL, "system/bin/run-as" },
  197. { 00755, AID_ROOT, AID_SHELL, "system/bin/*" },
  198. { 00755, AID_ROOT, AID_ROOT, "system/lib/valgrind/*" },
  199. { 00755, AID_ROOT, AID_SHELL, "system/xbin/*" },
  200. { 00755, AID_ROOT, AID_SHELL, "system/vendor/bin/*" },
  201. { 00750, AID_ROOT, AID_SHELL, "sbin/*" },
  202. { 00755, AID_ROOT, AID_ROOT, "bin/*" },
  203. { 00750, AID_ROOT, AID_SHELL, "init*" },
  204. { 00750, AID_ROOT, AID_SHELL, "charger*" },
  205. { 00750, AID_ROOT, AID_SHELL, "sbin/fs_mgr" },
  206. { 00640, AID_ROOT, AID_SHELL, "fstab.*" },
  207. { 00644, AID_ROOT, AID_ROOT, 0 },
  208. };
  209. static inline void fs_config(const char *path, int dir,
  210. unsigned *uid, unsigned *gid, unsigned *mode)
  211. {
  212. struct fs_path_config *pc;
  213. int plen;
  214. pc = dir ? android_dirs : android_files;
  215. plen = strlen(path);
  216. for(; pc->prefix; pc++){
  217. int len = strlen(pc->prefix);
  218. if (dir) {
  219. if(plen < len) continue;
  220. if(!strncmp(pc->prefix, path, len)) break;
  221. continue;
  222. }
  223. /* If name ends in * then allow partial matches. */
  224. if (pc->prefix[len -1] == '*') {
  225. if(!strncmp(pc->prefix, path, len - 1)) break;
  226. } else if (plen == len){
  227. if(!strncmp(pc->prefix, path, len)) break;
  228. }
  229. }
  230. *uid = pc->uid;
  231. *gid = pc->gid;
  232. *mode = (*mode & (~07777)) | pc->mode;
  233. #if 0
  234. fprintf(stderr,"< '%s' '%s' %d %d %o >\n",
  235. path, pc->prefix ? pc->prefix : "", *uid, *gid, *mode);
  236. #endif
  237. }
  238. #endif
  239. #endif