-4

i am trying to switch unix super user through java code. but getting authentication failure error, please help to switch user using java.

3
  • Please be more specific and give more details. Commented Aug 17, 2016 at 9:13
  • @phk, i think the thing is clear. run some code as user A, then make some kind of call, and begin being user B. As the question says, "switch Unix super user" it is clear that before the call, the java code must run as a normal user, and after the call, the same java code will run as super user. As I tell in my answer, this is not possible, as the setuid(2) system call is reserved for the root account. Commented Aug 17, 2016 at 9:17
  • 2
    Programming questions are off-topic here. Furthermore this question is not answerable at all. When you ask why your code doesn't work, you need to show your code! Commented Aug 17, 2016 at 22:02

1 Answer 1

2

You simply cannot. The only way to switch users in a process in unix is through the setuid(2) system call, that for an unprivileged user account is only valid to switch user ids between the real and saved user ids (this happens only in case of a suid executable) Java Threads run as process threads in architectures that allow that, but not as different processes, so all the JVM runs normally as a single process.

All these concepts are foreign to Java, as the JVM runs on behalf of the user who started the application (you can make java setuid root, but this is a highly dangerous security risk, as the JVM has no means to check for the validity of the uid change and in such situation all users capable of executing java code should be able to switch to whatever user they want) So this being said, no possibility of changing users for a java process is allowed in a un*x system.

I don't know if there exists a Runtime.setuid() call, but as the only utility is for JVMs started by root, who is the only user that can switch users without validating them, I think there's no implementation and you'll have to deal with some JNI programming to implement such a thing.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.