Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 1 | /* Copyright 2008 The Android Open Source Project |
| 2 | */ |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <errno.h> |
| 7 | #include <fcntl.h> |
| 8 | |
| 9 | #include <private/android_filesystem_config.h> |
| 10 | |
Riley Spahn | 69154df | 2014-06-05 11:07:18 -0700 | [diff] [blame^] | 11 | #include <selinux/android.h> |
| 12 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 13 | #include "binder.h" |
| 14 | |
| 15 | #if 0 |
| 16 | #define ALOGI(x...) fprintf(stderr, "svcmgr: " x) |
| 17 | #define ALOGE(x...) fprintf(stderr, "svcmgr: " x) |
| 18 | #else |
| 19 | #define LOG_TAG "ServiceManager" |
| 20 | #include <cutils/log.h> |
| 21 | #endif |
| 22 | |
| 23 | /* TODO: |
| 24 | * These should come from a config file or perhaps be |
| 25 | * based on some namespace rules of some sort (media |
| 26 | * uid can register media.*, etc) |
| 27 | */ |
| 28 | static struct { |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 29 | uid_t uid; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 30 | const char *name; |
| 31 | } allowed[] = { |
| 32 | { AID_MEDIA, "media.audio_flinger" }, |
Glenn Kasten | 64c8be0 | 2013-01-16 12:06:39 -0800 | [diff] [blame] | 33 | { AID_MEDIA, "media.log" }, |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 34 | { AID_MEDIA, "media.player" }, |
| 35 | { AID_MEDIA, "media.camera" }, |
| 36 | { AID_MEDIA, "media.audio_policy" }, |
| 37 | { AID_DRM, "drm.drmManager" }, |
| 38 | { AID_NFC, "nfc" }, |
| 39 | { AID_BLUETOOTH, "bluetooth" }, |
| 40 | { AID_RADIO, "radio.phone" }, |
| 41 | { AID_RADIO, "radio.sms" }, |
| 42 | { AID_RADIO, "radio.phonesubinfo" }, |
| 43 | { AID_RADIO, "radio.simphonebook" }, |
| 44 | /* TODO: remove after phone services are updated: */ |
| 45 | { AID_RADIO, "phone" }, |
| 46 | { AID_RADIO, "sip" }, |
| 47 | { AID_RADIO, "isms" }, |
| 48 | { AID_RADIO, "iphonesubinfo" }, |
| 49 | { AID_RADIO, "simphonebook" }, |
| 50 | { AID_MEDIA, "common_time.clock" }, |
| 51 | { AID_MEDIA, "common_time.config" }, |
Kenny Root | 2444087 | 2012-11-14 15:42:38 -0800 | [diff] [blame] | 52 | { AID_KEYSTORE, "android.security.keystore" }, |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 55 | uint32_t svcmgr_handle; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 56 | |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 57 | const char *str8(const uint16_t *x) |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 58 | { |
| 59 | static char buf[128]; |
| 60 | unsigned max = 127; |
| 61 | char *p = buf; |
| 62 | |
| 63 | if (x) { |
| 64 | while (*x && max--) { |
| 65 | *p++ = *x++; |
| 66 | } |
| 67 | } |
| 68 | *p++ = 0; |
| 69 | return buf; |
| 70 | } |
| 71 | |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 72 | int str16eq(const uint16_t *a, const char *b) |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 73 | { |
| 74 | while (*a && *b) |
| 75 | if (*a++ != *b++) return 0; |
| 76 | if (*a || *b) |
| 77 | return 0; |
| 78 | return 1; |
| 79 | } |
| 80 | |
Riley Spahn | 69154df | 2014-06-05 11:07:18 -0700 | [diff] [blame^] | 81 | static struct selabel_handle* sehandle; |
| 82 | |
| 83 | static bool check_mac_perms(const char *name, pid_t spid) |
| 84 | { |
| 85 | if (is_selinux_enabled() <= 0) { |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | bool allowed = false; |
| 90 | |
| 91 | const char *class = "service_manager"; |
| 92 | const char *perm = "add"; |
| 93 | |
| 94 | char *tctx = NULL; |
| 95 | char *sctx = NULL; |
| 96 | |
| 97 | if (!sehandle) { |
| 98 | ALOGE("SELinux: Failed to find sehandle %s.\n", name); |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | if (getpidcon(spid, &sctx) < 0) { |
| 103 | ALOGE("SELinux: getpidcon failed to retrieve pid context.\n"); |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | if (!sctx) { |
| 108 | ALOGE("SELinux: Failed to find sctx for %s.\n", name); |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | if (selabel_lookup(sehandle, &tctx, name, 1) != 0) { |
| 113 | ALOGE("SELinux: selabel_lookup failed to set tctx for %s.\n", name); |
| 114 | freecon(sctx); |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | if (!tctx) { |
| 119 | ALOGE("SELinux: Failed to find tctx for %s.\n", name); |
| 120 | freecon(sctx); |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | int result = selinux_check_access(sctx, tctx, class, perm, (void *) name); |
| 125 | allowed = (result == 0); |
| 126 | |
| 127 | freecon(sctx); |
| 128 | freecon(tctx); |
| 129 | return allowed; |
| 130 | } |
| 131 | |
| 132 | static int svc_can_register(uid_t uid, const uint16_t *name, pid_t spid) |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 133 | { |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 134 | size_t n; |
| 135 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 136 | if ((uid == 0) || (uid == AID_SYSTEM)) |
Riley Spahn | 69154df | 2014-06-05 11:07:18 -0700 | [diff] [blame^] | 137 | return check_mac_perms(str8(name), spid) ? 1 : 0; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 138 | |
| 139 | for (n = 0; n < sizeof(allowed) / sizeof(allowed[0]); n++) |
| 140 | if ((uid == allowed[n].uid) && str16eq(name, allowed[n].name)) |
Riley Spahn | 69154df | 2014-06-05 11:07:18 -0700 | [diff] [blame^] | 141 | return check_mac_perms(str8(name), spid) ? 1 : 0; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 146 | struct svcinfo |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 147 | { |
| 148 | struct svcinfo *next; |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 149 | uint32_t handle; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 150 | struct binder_death death; |
| 151 | int allow_isolated; |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 152 | size_t len; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 153 | uint16_t name[0]; |
| 154 | }; |
| 155 | |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 156 | struct svcinfo *svclist = NULL; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 157 | |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 158 | struct svcinfo *find_svc(const uint16_t *s16, size_t len) |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 159 | { |
| 160 | struct svcinfo *si; |
| 161 | |
| 162 | for (si = svclist; si; si = si->next) { |
| 163 | if ((len == si->len) && |
| 164 | !memcmp(s16, si->name, len * sizeof(uint16_t))) { |
| 165 | return si; |
| 166 | } |
| 167 | } |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 168 | return NULL; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void svcinfo_death(struct binder_state *bs, void *ptr) |
| 172 | { |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 173 | struct svcinfo *si = (struct svcinfo* ) ptr; |
| 174 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 175 | ALOGI("service '%s' died\n", str8(si->name)); |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 176 | if (si->handle) { |
| 177 | binder_release(bs, si->handle); |
| 178 | si->handle = 0; |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 179 | } |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 182 | uint16_t svcmgr_id[] = { |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 183 | 'a','n','d','r','o','i','d','.','o','s','.', |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 184 | 'I','S','e','r','v','i','c','e','M','a','n','a','g','e','r' |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 185 | }; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 186 | |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 187 | |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 188 | uint32_t do_find_service(struct binder_state *bs, const uint16_t *s, size_t len, uid_t uid) |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 189 | { |
| 190 | struct svcinfo *si; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 191 | |
Serban Constantinescu | 3a345f0 | 2013-12-19 09:11:41 +0000 | [diff] [blame] | 192 | si = find_svc(s, len); |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 193 | //ALOGI("check_service('%s') handle = %x\n", str8(s), si ? si->handle : 0); |
| 194 | if (si && si->handle) { |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 195 | if (!si->allow_isolated) { |
| 196 | // If this service doesn't allow access from isolated processes, |
| 197 | // then check the uid to see if it is isolated. |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 198 | uid_t appid = uid % AID_USER; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 199 | if (appid >= AID_ISOLATED_START && appid <= AID_ISOLATED_END) { |
| 200 | return 0; |
| 201 | } |
| 202 | } |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 203 | return si->handle; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 204 | } else { |
| 205 | return 0; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | int do_add_service(struct binder_state *bs, |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 210 | const uint16_t *s, size_t len, |
Riley Spahn | 69154df | 2014-06-05 11:07:18 -0700 | [diff] [blame^] | 211 | uint32_t handle, uid_t uid, int allow_isolated, |
| 212 | pid_t spid) |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 213 | { |
| 214 | struct svcinfo *si; |
Serban Constantinescu | 3a345f0 | 2013-12-19 09:11:41 +0000 | [diff] [blame] | 215 | |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 216 | //ALOGI("add_service('%s',%x,%s) uid=%d\n", str8(s), handle, |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 217 | // allow_isolated ? "allow_isolated" : "!allow_isolated", uid); |
| 218 | |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 219 | if (!handle || (len == 0) || (len > 127)) |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 220 | return -1; |
| 221 | |
Riley Spahn | 69154df | 2014-06-05 11:07:18 -0700 | [diff] [blame^] | 222 | if (!svc_can_register(uid, s, spid)) { |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 223 | ALOGE("add_service('%s',%x) uid=%d - PERMISSION DENIED\n", |
| 224 | str8(s), handle, uid); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 225 | return -1; |
| 226 | } |
| 227 | |
| 228 | si = find_svc(s, len); |
| 229 | if (si) { |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 230 | if (si->handle) { |
| 231 | ALOGE("add_service('%s',%x) uid=%d - ALREADY REGISTERED, OVERRIDE\n", |
| 232 | str8(s), handle, uid); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 233 | svcinfo_death(bs, si); |
| 234 | } |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 235 | si->handle = handle; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 236 | } else { |
| 237 | si = malloc(sizeof(*si) + (len + 1) * sizeof(uint16_t)); |
| 238 | if (!si) { |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 239 | ALOGE("add_service('%s',%x) uid=%d - OUT OF MEMORY\n", |
| 240 | str8(s), handle, uid); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 241 | return -1; |
| 242 | } |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 243 | si->handle = handle; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 244 | si->len = len; |
| 245 | memcpy(si->name, s, (len + 1) * sizeof(uint16_t)); |
| 246 | si->name[len] = '\0'; |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 247 | si->death.func = (void*) svcinfo_death; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 248 | si->death.ptr = si; |
| 249 | si->allow_isolated = allow_isolated; |
| 250 | si->next = svclist; |
| 251 | svclist = si; |
| 252 | } |
| 253 | |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 254 | binder_acquire(bs, handle); |
| 255 | binder_link_to_death(bs, handle, &si->death); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | int svcmgr_handler(struct binder_state *bs, |
Serban Constantinescu | bcf3888 | 2014-01-10 13:56:27 +0000 | [diff] [blame] | 260 | struct binder_transaction_data *txn, |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 261 | struct binder_io *msg, |
| 262 | struct binder_io *reply) |
| 263 | { |
| 264 | struct svcinfo *si; |
| 265 | uint16_t *s; |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 266 | size_t len; |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 267 | uint32_t handle; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 268 | uint32_t strict_policy; |
| 269 | int allow_isolated; |
| 270 | |
Serban Constantinescu | 3a345f0 | 2013-12-19 09:11:41 +0000 | [diff] [blame] | 271 | //ALOGI("target=%x code=%d pid=%d uid=%d\n", |
| 272 | // txn->target.handle, txn->code, txn->sender_pid, txn->sender_euid); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 273 | |
Serban Constantinescu | bcf3888 | 2014-01-10 13:56:27 +0000 | [diff] [blame] | 274 | if (txn->target.handle != svcmgr_handle) |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 275 | return -1; |
| 276 | |
Arve Hjønnevåg | e5245cb | 2014-01-28 21:35:03 -0800 | [diff] [blame] | 277 | if (txn->code == PING_TRANSACTION) |
| 278 | return 0; |
| 279 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 280 | // Equivalent to Parcel::enforceInterface(), reading the RPC |
| 281 | // header with the strict mode policy mask and the interface name. |
| 282 | // Note that we ignore the strict_policy and don't propagate it |
| 283 | // further (since we do no outbound RPCs anyway). |
| 284 | strict_policy = bio_get_uint32(msg); |
| 285 | s = bio_get_string16(msg, &len); |
| 286 | if ((len != (sizeof(svcmgr_id) / 2)) || |
| 287 | memcmp(svcmgr_id, s, sizeof(svcmgr_id))) { |
| 288 | fprintf(stderr,"invalid id %s\n", str8(s)); |
| 289 | return -1; |
| 290 | } |
| 291 | |
Riley Spahn | 69154df | 2014-06-05 11:07:18 -0700 | [diff] [blame^] | 292 | if (sehandle && selinux_status_updated() > 0) { |
| 293 | struct selabel_handle *tmp_sehandle = selinux_android_service_context_handle(); |
| 294 | if (tmp_sehandle) { |
| 295 | selabel_close(sehandle); |
| 296 | sehandle = tmp_sehandle; |
| 297 | } |
| 298 | } |
| 299 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 300 | switch(txn->code) { |
| 301 | case SVC_MGR_GET_SERVICE: |
| 302 | case SVC_MGR_CHECK_SERVICE: |
| 303 | s = bio_get_string16(msg, &len); |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 304 | handle = do_find_service(bs, s, len, txn->sender_euid); |
| 305 | if (!handle) |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 306 | break; |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 307 | bio_put_ref(reply, handle); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 308 | return 0; |
| 309 | |
| 310 | case SVC_MGR_ADD_SERVICE: |
| 311 | s = bio_get_string16(msg, &len); |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 312 | handle = bio_get_ref(msg); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 313 | allow_isolated = bio_get_uint32(msg) ? 1 : 0; |
Riley Spahn | 69154df | 2014-06-05 11:07:18 -0700 | [diff] [blame^] | 314 | if (do_add_service(bs, s, len, handle, txn->sender_euid, |
| 315 | allow_isolated, txn->sender_pid)) |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 316 | return -1; |
| 317 | break; |
| 318 | |
| 319 | case SVC_MGR_LIST_SERVICES: { |
Serban Constantinescu | 3a345f0 | 2013-12-19 09:11:41 +0000 | [diff] [blame] | 320 | uint32_t n = bio_get_uint32(msg); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 321 | |
| 322 | si = svclist; |
| 323 | while ((n-- > 0) && si) |
| 324 | si = si->next; |
| 325 | if (si) { |
| 326 | bio_put_string16(reply, si->name); |
| 327 | return 0; |
| 328 | } |
| 329 | return -1; |
| 330 | } |
| 331 | default: |
| 332 | ALOGE("unknown code %d\n", txn->code); |
| 333 | return -1; |
| 334 | } |
| 335 | |
| 336 | bio_put_uint32(reply, 0); |
| 337 | return 0; |
| 338 | } |
| 339 | |
Riley Spahn | 69154df | 2014-06-05 11:07:18 -0700 | [diff] [blame^] | 340 | |
| 341 | static int audit_callback(void *data, security_class_t cls, char *buf, size_t len) |
| 342 | { |
| 343 | snprintf(buf, len, "service=%s", !data ? "NULL" : (char *)data); |
| 344 | return 0; |
| 345 | } |
| 346 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 347 | int main(int argc, char **argv) |
| 348 | { |
| 349 | struct binder_state *bs; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 350 | |
| 351 | bs = binder_open(128*1024); |
Serban Constantinescu | a44542c | 2014-01-30 15:16:45 +0000 | [diff] [blame] | 352 | if (!bs) { |
| 353 | ALOGE("failed to open binder driver\n"); |
| 354 | return -1; |
| 355 | } |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 356 | |
| 357 | if (binder_become_context_manager(bs)) { |
| 358 | ALOGE("cannot become context manager (%s)\n", strerror(errno)); |
| 359 | return -1; |
| 360 | } |
| 361 | |
Riley Spahn | 69154df | 2014-06-05 11:07:18 -0700 | [diff] [blame^] | 362 | sehandle = selinux_android_service_context_handle(); |
| 363 | |
| 364 | union selinux_callback cb; |
| 365 | cb.func_audit = audit_callback; |
| 366 | selinux_set_callback(SELINUX_CB_AUDIT, cb); |
| 367 | cb.func_log = selinux_log_callback; |
| 368 | selinux_set_callback(SELINUX_CB_LOG, cb); |
| 369 | |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 370 | svcmgr_handle = BINDER_SERVICE_MANAGER; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 371 | binder_loop(bs, svcmgr_handler); |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 372 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 373 | return 0; |
| 374 | } |