File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Executing java process as some other user Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Executing java process as some other user" Watch "Executing java process as some other user" New topic
Author

Executing java process as some other user

veerabahu Subramanian
Greenhorn

Joined: Jun 01, 2007
Posts: 17
I need to run a perl code from java code in solaris. I used . I am running the java code as root user. The perl executable has different ownership permission. Moreover the root user doesn't have permission to execute the perl executable. In short its like this
-rwxr-x--- 1 myownuser:myowngroup 10816 Aug 10 05:56 perl
root user is not part of myowngroup. So when i execute the java program i am getting the following exception


  • [list]How can i solve the above issue. One thing i can think of is changing the permission of the executable (even with in java code) before actually running perl script. But i wont be able to do this because of certain constraints.
  • When i run perl test.pl i am able to get the output. Here too i should get some exception rite, because the command is getting executed as a root.
  • Jeanne Boyarsky
    internet detective
    Marshal

    Joined: May 26, 2003
    Posts: 30392
        
    150

    The root user has permission to do anything regardless of the permission bits.

    Does "perl test.pl" work if you run it through the command line rather than through Java?


    [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
    Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
    veerabahu Subramanian
    Greenhorn

    Joined: Jun 01, 2007
    Posts: 17
    Yes, i am able to run through command line. Hmm..if root user has everything to do then whats might be the other reasons for this error.
    veerabahu Subramanian
    Greenhorn

    Joined: Jun 01, 2007
    Posts: 17
    Adding to this when i give execute permission for the other user of perl executable i am able to run everything. I dont get any exceptions. In short

    -rwxr-x--x 1 myownuser myowngroup 10816 Jun 9 20:30 perl

    Works fine.
    Jeanne Boyarsky
    internet detective
    Marshal

    Joined: May 26, 2003
    Posts: 30392
        
    150

    It sounds like Java is running as a user with less permissions than root. Maybe some kind of "run as" is in play?
    veerabahu Subramanian
    Greenhorn

    Joined: Jun 01, 2007
    Posts: 17
    Jeanne, Java is running as a root user, confirmed the same using ps -ef. My question is exactly how to set that "run as" pro grammatically in java.
    Stefan Wagner
    Ranch Hand

    Joined: Jun 02, 2003
    Posts: 1923

    Sounds like a topic we had before:

    http://www.coderanch.com/t/110810/Linux-UNIX/Super-user-unix-not-honoured

    Ernest Friedmann-Hill had a look at the source code, and found out, that Java is checking permissions (user, group, other) without checking whether the user is root, and therefore bypassing the normal permissions.

    Perhaps the suggested bugreport was never made.


    http://home.arcor.de/hirnstrom/bewerbung
    veerabahu Subramanian
    Greenhorn

    Joined: Jun 01, 2007
    Posts: 17
    Thanks Stefan, its exactly the same.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Executing java process as some other user