Rework category mapping and perform some code cleanup.

Map the app IDs to a category pair rather than a single category.
With this scheme,  we can represent up to 2^16 app IDs, which exceeds
the maximum of 10000 imposed by Android.  This also only uses category
bits 0-511, so 512-1023 remain free for use for other purposes (or we
could shrink the number of categories defined in the policy).

Also perform other minor code cleanups previously suggested, e.g.
fix const declaration, use an enum rather than #define, correct %lu
to %u for format string, etc.

Change-Id: I5bb727bfb4297e3e13ba1ef078e41db3ea7d1b8f
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Switch app_* and isolated to _app and _isolated in seapp_contexts.

The app_* syntax was a legacy of the original approach of looking up
the username returned by getpwuid() and the original username encoding
scheme by bionic.  With the recent changes to move away from this approach,
there is no reason to retain that syntax.  Instead, just use _app to match
app UIDs and _isolated to match isolated service UIDs.  The underscore
prefix is to signify that these are not real usernames and to avoid
conflicts with any system usernames.

Requires a corresponding change to sepolicy.

Change-Id: I21f9f88415b653c1bf6332fc100d91d969c9da64
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Apply context validation when loading file_contexts.

Change-Id: I7c0bdca5c9a1ffe428200a830c1b706fc8ed9675
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Do not try to restorecon if selinux is disabled

debuggerd tries to restorecon on the tombstones directory which fails
when SELinux is not enabled in the kernel. That would return an error
condition to debuggerd which would then abort its attempt to dump the
stacks of the failing program.

Fix it here in case there are other places that might call this in the
future. Currently the only other caller is android_os_SELinux.cpp JNI
code.

Change-Id: Id73796a70174333b61fd04ee6b1d99fccbea8116
Mount selinuxfs on /sys/fs/selinux when possible.

Linux 3.0 introduced /sys/fs/selinux as the preferred mount point
directory for selinuxfs.  Upstream libselinux tries to mount selinuxfs
on /sys/fs/selinux first and falls back to /selinux if it doesn't exist.
Do likewise in Android.

Change-Id: Iec738ff7e2f13f809a271eb03f08ef6cd2582bd4
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Generalize levelFromUid support.

Generalize levelFromUid support to support per-app, per-user,
or per-combination level assignment.  Adds a new levelFrom=none|app|user|all
syntax for specifying the desired behavior in seapp_contexts.
levelFromUid=true|false is still supported but translated to
levelFrom=app|none.

No change in existing behavior for existing seapp_contexts configurations.

Change-Id: I0e9c18ecf3113fa7079d2101899c92a241ef80a0
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Return an error if no path is supplied to the label backends.

Change-Id: I5af4591d733429b3348bbe87d6711200645af27b
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Check mkdir return value before calling mount.

Change-Id: If058da4431215fa4b6f895563ba13620b7d9a81a
Adjustments to android property backend.

Allow the android property backend parser to accept the
SELABEL_OPT_VALIDATE option and to perform a validate
callback.

Change-Id: Ifd4b9839df6ff67b868b5cf6448920e8b3aa2a7a
Signed-off-by: Robert Craig <rpcraig@tycho.ncsc.mil>
Adjustments to android property backend.

Allow the android property backend parser to accept the
SELABEL_OPT_VALIDATE option and to perform a validate
callback.

Change-Id: If061502c5e2489a1155798fac1d8357dbb8d13ba
Signed-off-by: Robert Craig <rpcraig@tycho.ncsc.mil>
Move location of policy files

Move location of policy files from /data/system to
/data/security

Change-Id: If75da3889c75ca83eb7dbd6e5540657a4cf65831
Merged in billcroberts/external-libselinux/seandroid-policy-move (pull request #1)

Move location of policy files
Merge "Adjustments to android property backend."
Generalize levelFromUid support.

Generalize levelFromUid support to support per-app, per-user,
or per-combination level assignment.  Adds a new levelFrom=none|app|user|all
syntax for specifying the desired behavior in seapp_contexts.
levelFromUid=true|false is still supported but translated to
levelFrom=app|none.

No change in existing behavior for existing seapp_contexts configurations.

Change-Id: I0e9c18ecf3113fa7079d2101899c92a241ef80a0
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Add new location for policy files

Add new location for policy, /data/security, which has
precedence over /data/system

Change-Id: If75da3889c75ca83eb7dbd6e5540657a4cf65831
Drop /data/system as a location for policy files

/data/system is no longer supported as a possible
location for policy files, use /data/security instead.

Change-Id: I83e5014a9e2f64bd95c0f1be6cd463fd71a7025b
Merge branch 'master' into seandroid

Conflicts:
	src/android.c
Merge branch 'master' into seandroid
Sync with master.
Add selinux status functions from upstream libselinux.

These functions allow programs to check whether there has
been a change to the SELinux status without needing to poll a netlink socket.

Change-Id: Ic7f310d69a7c420e48fbc974000cf4a5b9ab4a3b
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>