aspose file tools*
The moose likes Java in General and the fly likes obtain root privileges Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "obtain root privileges" Watch "obtain root privileges" New topic
Author

obtain root privileges

Marc Verschueren
Greenhorn

Joined: Jul 24, 2005
Posts: 4
Hi,

I'm new to programming JAVA 5 on MAC OS X 10.4 and now i would like to make a class where a process is started that needs to have root priviledges. I've searched for several hours and can't find a clue on how to do this.

Can anyone help me with this one or direct me to information regarding this?

Thx!!

Marc.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8964
    
    9

sudo


[How To Ask Questions On JavaRanch]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
What does it need root priveleges for? One posibility is to write your program assuming that it will be run with root priveleges. Then you can run it as root or using sudo. There might be other sophisticated ways to do this as well using third-party security APIs. I'm not familiar with any of these APIs, so I don't have any suggestions there. I still think it will help to answer the first question since it may determine what APIs you should use.

HTH

Layne


Java API Documentation
The Java Tutorial
Jeffrey Spaulding
Ranch Hand

Joined: Jan 15, 2004
Posts: 149
If you run the application from the shell, the permissions are determined by the user that is logged in.

So, if you want to tun something with root privileges, you need to be logged in as root or as someone with rights equal to root.
Marc Verschueren
Greenhorn

Joined: Jul 24, 2005
Posts: 4
Thx all very much for replying!

Pointing me to sudo plus other information elsewhere solved my problem.

I needed to be root in the program to be able to start and stop a postgresql server, while logged in as another user, f.i. "marc". To do this one must be logged in as the "postgres" user, so, finally, in my java program i did:

Process proc = new ProcessBuilder("sudo", "su", "postgres", "start").start();

Where "start" is the cmd file which starts the progresql server, and it works just fine (asks the root's password first).

Thx to you all!

Marc.
[ August 03, 2005: Message edited by: Marc Verschueren ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: obtain root privileges