472,984 Members | 2,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,984 software developers and data experts.

Permission problems when trying to execute simple system command

Hi, I am quite new to JSP so please forgive me if I ask really simple things... I am trying to run system commands on the server and display the output on a webpage. This is what I've got:


Expand|Select|Wrap|Line Numbers
  1. <%@ page import="java.io.*" %>
  2. <HTML>
  3. <BODY>
  4. <%
  5.     Runtime rt = Runtime.getRuntime();
  6.  
  7. Process p = rt.exec("/bin/ls");
  8.  
  9. // for reading the output of the program
  10. // (out of the program is in for us)
  11. BufferedReader sOut = new BufferedReader(new
  12.         InputStreamReader(p.getInputStream()));
  13.  
  14. // read the output
  15. String line;
  16. while ((line = sOut.readLine()) != null)
  17. {
  18.         out.println("line<BR/>");
  19. }
  20.  
  21. %>
  22. </BODY>
  23. </HTML>

However, when I run this, I get the following:



description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Exception in JSP: /research/test.jsp:7

4: <%
5: Runtime rt = Runtime.getRuntime();
6:
7: Process p = rt.exec("/bin/ls");
8:
9: // for reading the output of the program
10: // (out of the program is in for us)


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
sun.reflect.GeneratedMethodAccessor63.invoke(Unkno wn Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.catalina.security.SecurityUtil$1.run(Se curityUtil.java:244)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject .java:517)
org.apache.catalina.security.SecurityUtil.execute( SecurityUtil.java:276)
org.apache.catalina.security.SecurityUtil.doAsPriv ilege(SecurityUtil.java:162)

root cause

java.security.AccessControlException: access denied (java.io.FilePermission /bin/ls execute)
java.security.AccessControlContext.checkPermission (AccessControlContext.java:323)
java.security.AccessController.checkPermission(Acc essController.java:546)
java.lang.SecurityManager.checkPermission(Security Manager.java:532)
java.lang.SecurityManager.checkExec(SecurityManage r.java:779)
java.lang.ProcessBuilder.start(ProcessBuilder.java :447)
java.lang.Runtime.exec(Runtime.java:593)
java.lang.Runtime.exec(Runtime.java:431)
java.lang.Runtime.exec(Runtime.java:328)
org.apache.jsp.research.test_jsp._jspService(test_ jsp.java:49)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
sun.reflect.GeneratedMethodAccessor63.invoke(Unkno wn Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.catalina.security.SecurityUtil$1.run(Se curityUtil.java:244)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject .java:517)
org.apache.catalina.security.SecurityUtil.execute( SecurityUtil.java:276)
org.apache.catalina.security.SecurityUtil.doAsPriv ilege(SecurityUtil.java:162)





Seems like it has something to do with the permissions granted to the JVM? I have googled high and low and still haven't found a way to solve it. I've also tried adding
Expand|Select|Wrap|Line Numbers
  1. grant { permission java.io.FilePermission "file:/bin/ls", "execute"; }
to my java.policy file but to no avail. Could somebody point out how to solve this? Thanks!
Jan 13 '09 #1
5 6993
JosAH
11,448 Expert 8TB
If you were allowed to do what you want to do you can, say, execute the command "rm -rf /". You don't want to be able to do that and that's why the installed SecurityManager forbids you to do that. Be grateful.

kind regards,

Jos
Jan 13 '09 #2
Thanks for your reply. That sounds very logical but I'm sure its still something that many people wish there was a way to do. OK, eventually my goal is to be able to execute a Perl script and grab its output. Is there any way I can make the security manager grant access to a particular script etc?
Jan 13 '09 #3
JosAH
11,448 Expert 8TB
@sayeo87
You have to (re)configure your (web)server and make it install another SecurityManager (or no manager at all) if possible. The manager itself is a breeze:

Expand|Select|Wrap|Line Numbers
  1. import java.security.Permission;
  2.  
  3. public class MySecurityManager extends SecurityManager {
  4.  
  5.     public MySecurityManager() { }
  6.  
  7.     /* allow everything: */
  8.     public void checkPermission(Permission perm) { }
  9.     public void checkPermission(Permission perm, Object context) { }
  10. }
  11.  
kind regards,

Jos
Jan 13 '09 #4
OK, I'm using a Tomcat webserver and the security manager was not turned on. What else could be blocking access then?
Jan 14 '09 #5
JosAH
11,448 Expert 8TB
Well, something forbid you to do your ugly deed (check if there's a SecurityManager installed; I bet there is). What does your catalina.policy file say?

kind regards,

Jos
Jan 14 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: bird | last post by:
What can cause the PHP code fopen("filename","a") to fail with permission denied message as below? ------------------ Warning: fopen(filename): failed to open stream: Permission denied in...
2
by: Joey Mack | last post by:
Greetings. I am trying to use the System.Diagnostics.Process class to perform some actions through the Windows command line. The applicable code appears below. The code builds the follow command...
2
by: Taishi | last post by:
New user of SQL Everything is on the same machine My error is close to the bottom After reading it today, I can see there is a problem with 2 dbases 'PUBS' and 'Master' There are also some...
0
by: David Berman | last post by:
Hello, I'm receiving an error reading the machine.config file when I try to access my web application. This error came out of nowhere. After searching many sites, googelizing and searching here,...
0
by: ElGordo | last post by:
I have a routine which opens a command shell and runs an executable. This all worked fine until recently, and I noticed that each time the statement is run, an event is logged in the event viewer...
0
by: ElGordo | last post by:
I have a .Net application which includes a function to open a command shell and run an executable (for a file extraction program, 7zip). I can run the same exact command line manually with no...
0
by: Sergistm | last post by:
Hello World, :D I have a problem that it is making me crazy, I hope you can help me. I'm trying to execute a .exe file with the Procces.Start, and there is no problem when the file is on my...
0
by: =?Utf-8?B?bWVzdGVyYWs=?= | last post by:
I have attempted to use some simple code to wrap execution of the pathman.exe utility released with the Windows Resource Toolkit 2k3. The goal is to update the PATH variable as needed. I have...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.