0

Linux has the command setcap to change file capabilities. This does not seem to be supported by Android by default. Could anyone confirm this? If so, is there a way to add this command to Android which is a branch of Linux?

As for the reason to run this command, I want to use the answer of of this SO Thread to address the issue of using privileged ports.

Community
  • 1
  • 1
Hong
  • 17,643
  • 21
  • 81
  • 142
  • android uses the linux kernel. but just because it uses the linux kernel doesn't mean all linux commands will be available. kernel != operating system. – Marc B Mar 18 '16 at 16:37
  • @MarcB Thanks for the explanation. Is there a way to add this command? I assume Android supports the capabilities, but just does not support the command to change them. – Hong Mar 18 '16 at 16:46
  • 1
    This awfully much sounds like an XY-Problem. Please explain what you are trying to do first! – Xaver Kapeller Mar 18 '16 at 17:02
  • @XaverKapeller I want to run this command "setcap 'cap_net_bind_service=+ep' /path/to/program". I did not want to distract people by getting into the details of what I wanted to do. In light of your commend, I will add this information to the question. – Hong Mar 18 '16 at 17:07
  • 1
    @Hong Yes, but why are you trying to do that? Are you compiling your own Android distribution? Please explain what you are trying to achieve in the end, don't list the steps that that you think will get you there. – Xaver Kapeller Mar 18 '16 at 17:10
  • You might want to try rooting the device and installing BusyBox then get `setcap` somehow, but I don't think that is in the scope of StackOverflow – OneCricketeer Mar 18 '16 at 17:13
  • @XaverKapeller I edited the question. Please let me know if it is good enough. I did a lot (many hours) research on the issue that I want to address. I did not want to distract people to all the processes. Instead, I want to make the question as specific as possible. – Hong Mar 18 '16 at 18:12
  • @cricket_007 Actually I checked BusyBox before posting the question. I have not tried the app, but the list does not include setcap – Hong Mar 18 '16 at 18:13
  • @XaverKapeller sorry but I forgot to answer your question regarding compiling Android. I have some influence on the specific Android build, but I am trying to find way to work with the existing version. – Hong Mar 18 '16 at 18:16
  • @Hong I understand what you are trying to do with `setcap`, but why? Why do you need to use a privledged port? They are called privledged for a reason. You should **not** use them. So why are trying to do this? I am continuing to ask this because there might be a much simpler and better solution to the problem you are trying to solve with `setcap`. – Xaver Kapeller Mar 18 '16 at 18:16
  • @XaverKapeller Though I do not mind getting all the details, I still want to make it as brief as possible. There are a few reasons. Let me just give one: I want to run my own HTTP service, and I HAVE TO use the default port:80 (Please do not ask why I have to use the default port. This is beyond what I can control). – Hong Mar 18 '16 at 18:34
  • So your question is actually "How do I run a WebServer on an Android device?" – OneCricketeer Mar 18 '16 at 18:40
  • @cricket_007 No. As I said, there are a few reasons. That is one of them. Most importantly, the service has to be done in our code, not using any third party tool. It is only a small part of an app with many other features. – Hong Mar 18 '16 at 18:44
  • @cricket_007 That is exactly the reason that I wanted to avoid getting into the reasons that may distract people, and instead asked a very specific question. – Hong Mar 18 '16 at 18:47
  • Maybe if you briefly provided the **entire** details of what you want to do, we can maybe actually give you an answer instead of guessing what you want. – OneCricketeer Mar 18 '16 at 18:48
  • There is also a thread for [File Capabilities in Android](https://groups.google.com/forum/#!topic/android-kernel/iYakEvY24n4) – OneCricketeer Mar 18 '16 at 18:50
  • @cricket_007 OK. Let's solve the HTTP service that HAS TO use port 80 first. If this problem is solved, others may be solved accordingly. What details would you like to know. My approach is really standard, nothing sepcial - creating a socket listening to port 80. Code new ServerSocket(80) throws "java.net.BindException: bind failed: EACCES (Permission denied)" – Hong Mar 18 '16 at 19:22
  • @cricket_007 I red that thread before posting the question. The Android that I have to use is V4.2. – Hong Mar 18 '16 at 19:24
  • Then you need to root the device and give your app root access. – OneCricketeer Mar 18 '16 at 19:29
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/106757/discussion-between-hong-and-cricket-007). – Hong Mar 18 '16 at 19:31

0 Answers0