Skip to content

Commit

Permalink
Allow hidg0/hidg1 to be used by shell in enforcing selinux
Browse files Browse the repository at this point in the history
This will probably not work on Nougat due to binary contexts :(

Signed-off-by: James Christopher Adduono <[email protected]>
  • Loading branch information
jcadduono committed Dec 11, 2016
1 parent 05ecaee commit 2518451
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions nethunter-installer/boot-patcher/patch.d-env
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ cd "$tmp"
default_prop=$ramdisk/default.prop
build_prop=/system/build.prop
ueventd=$ramdisk/ueventd.rc
file_contexts=$ramdisk/file_contexts

found_prop=false
found_build_prop=false
found_ueventd=false
found_file_contexts=false
[ -f "$default_prop" ] && found_prop=true
[ -f "$build_prop" ] && found_build_prop=true
[ -f "$ueventd" ] && found_ueventd=true
[ -f "$file_contexts" ] && found_file_contexts=true

print() {
if [ "$1" ]; then
Expand Down Expand Up @@ -146,6 +149,23 @@ ueventd_set() {
replace_file "$ueventd" "$ueventd-"
}

# context_set <file path regex> <context>
# use this to set selinux contexts of file paths
context_set() {
$found_file_contexts || return
awk -vfile="$1" -vcontext="$2" '
function pfcon() {
printf "%-48s %s\n", file, context
set = 1
}
$1 == file && !set { pfcon() }
$1 == file { next }
{ print }
END { if (!set) pfcon() }
' "$file_contexts" > "$file_contexts-"
replace_file "$file_contexts" "$file_contexts-"
}

# import_rc <rc file>
# adds an init rc file as an import to init.rc, it will be imported last
import_rc() {
Expand Down
3 changes: 2 additions & 1 deletion nethunter-installer/boot-patcher/patch.d/01-ramdisk-patch
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ setprop ro.secure 0
import_rc init.nethunter.rc

# ensure /dev/hidg0 and /dev/hidg1 have the correct access rights
ueventd_set "/dev/hidg*" 0666 root system
ueventd_set "/dev/hidg*" 0666 root root
context_set "/dev/hidg[0-9]*" "u:object_r:input_device:s0"

0 comments on commit 2518451

Please sign in to comment.