1

I have an issue with file permission in Termux.

For instance, I installed c4droid and copied the Termux /include and /lib folders content in the /c4droid folder where the headers are being looked for at compilation. I changed the owner and group to the correct name and mode to 777, but at compilation, it says "cannot open ****.h permission denied".

Same thing with a worldlist that comes from the SD card that I put on a folder meant to be used with hydra, not only have I have to use root access to unzip the file and move it around, but hydra itself can't open it.

What is this so important thing that I am missing about Termux and filed ownership and permissions?

7
  • I installed c4droid and copied the termux include and lib folders content in the c4droid folder. And what's the exact location of c4droid folder? Commented Jul 2, 2019 at 7:53
  • /data/data/com.n0n3m4.droidc/files/gcc/'somethinglikeaarcharm'/
    – Yvain
    Commented Jul 2, 2019 at 8:51
  • So you are trying to access /data/data/com.n0n3m4.droidc/ from Termux, right? That won't work. Termux can't read/write data outside its own private directory /data/data/com.termux/. That's the app sandboxing mechanism of Android - for security and privacy. Other possible location which Termux can access is /sdcard/Android/data/com.termux. Also whole /sdcard if you grant Termux Storage permission. Commented Jul 2, 2019 at 8:54
  • No, i su in termux to put the files in c4droid folder. After that I change the permissions and ownership to the user / group of c4droid and try to compile with this app, not termux
    – Yvain
    Commented Jul 2, 2019 at 8:56
  • Ok. Did you fix SELinux context of files along with ownership and permission mode? Also there could possibly be hard-code PATHs in haders / libs. Termux packages have source code modified. Commented Jul 2, 2019 at 8:57

2 Answers 2

0

The above comments hint toward SELinux blocking access to the files that are being copied around to the /data/data/ directory of apps. Yes, it is SELinux blocking the access, you just need to set it to permissive mode with SELinux_switch, and don't forget to set the user and group to the app's one.

So, copying the files from Termux with the option -pZL keeps everything in place, and once you set the correct owner and group, it will work. I have not tried having a symlink from the droidc's /includes and /libs folder to Termux's ones. If you missed fixing permission while copying files, you can use /system/bin/restorecon -R (recurse) one both /include and /lib folders.

1
  • 2
    Don't set SELinux permissive with SELinux Switcher, it's like turning your back to a security feature in which professionals have spent years to implement. Instead set proper context on your files/directories. If you answer my question in chat, I can try to help you how to do that. If that doesn't work, you can swith SELinux permissive temporarily, not permanently. PS: you don't need an app to do that, just echo 0 >/sys/fs/selinux/enforce Commented Jul 2, 2019 at 9:58
0

TL;DR:

$su
#chown u0_a???:u0_a??? <files>
#restorecon -v <files>
#exit

or

$su
#chown -R u-a???:u0_a??? <directories>
#restorecon -vR <directories>
#exit

IMPORTANT: Commands run via sudo work differently from commands run from a root prompt via su. sudo ls -lZsu ls -lZ (which is unexpected and violates so many assumptions, but I assure you that it is nevertheless so. I assume there are a couple of other non-obvious ways these commands could fail, so I'd advise trying a couple of different ways to be root if this fails)

Make sure to get the correct username and group for your termux user via "ls -l" or similar, and use that username and group in the commands above.

I found this solution to fixing SElinux file permissions after copying from the SDcard back into my Termux home directory on a GitHub issue And it took me so much time and effort to dig up that I figured I repost it a couple of times to make it easier next time this "Why, no! you're not allowed to restore your backups!" bites my ass.

You can test to see if this is your problem before implementing this via ls -lZ. Compare to a file you can access to compare the SELinux security context of the two files and verify that they differ.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .