Problems with here docs/strings in Android implementations of bash/mksh -


i've encountered several issues process substitution , here docs/strings in bash , mksh shells on android.

process substitution in bash fails both privileged , unprivileged users.

$ cat < <(ls) bash: /dev/fd/62: no such file or directory 

bash's man page states:

process substitution supported on systems support named pipes (fifos) or /dev/fd method of naming open files.

android lacks /dev/fd can resolve issue running following command su (or placing in userinit.d run upon boot):

ln -s /proc/self/fd /dev/fd 

this sort of process substitution not supported in mksh, can around using named pipes, file descriptors, , here docs/strings. here docs/strings function in both bash , mksh while run root/su.

herein lies problem: here docs/strings fail unprivileged users in both bash , mksh

$ cat <<< "string" bash: cannot create temp file here-document: permission denied  $ cat <<< "string" /system/bin/sh: can't create temporary file /data/local/sh5debnv.tmp: permission denied 

it clear shells lacks access suitable /tmp folder. shell variable tmpdir appears involved.

i've temporarily modified bashrc/mkshrc files set tmpdir world-writable directory in /data [ $user != root ]. functions when running scripts adb/terminal seems sloppy , potentially dangerous idea. setting tmpdir /sdcard instance works fine when calling scripts 'terminal emulator android' fails elsewhere.

i'd scripts function reliably when called unprivileged non-interactive shells (i.e. tasker or other apps). have suggestions set tmpdir to, set (i.e. mkshrc/bashrc, userinit.d, or repack init.rc), or entirely new solution?

you've pretty answered question here. these questions though. mirabilos, creator , maintainer of mksh(official shell android), said while ago reason tmpdir isn't there security reasons, it's google , him trying sort out.

as make temporary directory, make in /sdcard since accessible non-root processes. function use in /system/etc/mkshrc , /system/etc/bash/bashrc, locations mkshrc , bashrc in android:

mktmp3(){   [[ -e $tmpdir ]] && [[ -w $tmpdir ]] && return 0 || :    [[ -e /sdcard ]] || {     [[ -e /storage/emulated/0 ]] && ln -sf /storage/emulated/0 /sdcard     }    (( $user_id )) && {     export tmpdir=/sdcard/.tmp/$random     mkdir -p $tmpdir 2>/dev/null   } || :    (( $user_id )) || {     busybox mount -o rw,remount /     mkdir -p /tmp 2>/dev/null     busybox mount -o ro,remount /     busybox mount -t tmpfs -o rw /tmp /tmp     export tmpdir=/tmp/$random     mkdir -p $tmpdir 2>/dev/null   } }  mktmp3 

that make secure temporary directory root , non-root randomly generated.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -