You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Michel Jubault <mi...@free.fr> on 2003/06/24 09:51:37 UTC

How use an external C program in a Servlet

Hi there !!

I've  a little C program. This computes some variables and return a kind of
statistic result. I need it in a servlet. But I don't know how to call it.
I'm using Tomcat 4.1.24.
Where this program must be to be launched ?
How can I pass arguments to C program and use in servlet the return value ?

Thanks in advance !

Michel


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: How use an external C program in a Servlet

Posted by Michel Jubault <mi...@free.fr>.
Thanks for this advice !

Michel

----- Original Message -----
From: Holger Klawitter <li...@klawitter.de>
To: Tomcat Users List <to...@jakarta.apache.org>
Sent: Tuesday, June 24, 2003 11:46 AM
Subject: Re: How use an external C program in a Servlet


Am Dienstag, 24. Juni 2003 11:13 schrieb Michel Jubault:
> Thanks, I try it straight away !
> What kind of problem could occur with security ?

It depends on your situation. If any user may upload servlets, these
servlets
may execute every program on that machine - with the rights of the tomcat
account, which might be root! Same problem if the arguments to the C program
are not sufficiently checked.

Mit freundlichem Gruß / With kind regards
Holger Klawitter
--
lists@klawitter.de


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: How use an external C program in a Servlet

Posted by Atreya Basu <at...@greenfieldresearch.ca>.
Hi Holger,

There are two things that you can do.  If your programme is a Library
then you can use JNI to create native wrappers then just call them from
the servlet.  This is pretty straightforward and I use them.

The other is to use: Runtime.getRuntime().exec(<exec_name_and_params>);
That will just execute a programme, you can get the Process object and
get it's InputStream and OutputStream.

Good Luck,

_____________________________________
Atreya Basu
Developer,
Greenfield Research Inc.
e-mail: atreya (at) greenfieldresearch (dot) ca

-----Original Message-----
From: Holger Klawitter [mailto:lists@klawitter.de] 
Sent: June 24, 2003 6:46 AM
To: Tomcat Users List
Subject: Re: How use an external C program in a Servlet

Am Dienstag, 24. Juni 2003 11:13 schrieb Michel Jubault:
> Thanks, I try it straight away !
> What kind of problem could occur with security ?

It depends on your situation. If any user may upload servlets, these
servlets 
may execute every program on that machine - with the rights of the
tomcat 
account, which might be root! Same problem if the arguments to the C
program 
are not sufficiently checked.

Mit freundlichem Gruß / With kind regards
	Holger Klawitter
--
lists@klawitter.de


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: How use an external C program in a Servlet

Posted by Holger Klawitter <li...@klawitter.de>.
Am Dienstag, 24. Juni 2003 11:13 schrieb Michel Jubault:
> Thanks, I try it straight away !
> What kind of problem could occur with security ?

It depends on your situation. If any user may upload servlets, these servlets 
may execute every program on that machine - with the rights of the tomcat 
account, which might be root! Same problem if the arguments to the C program 
are not sufficiently checked.

Mit freundlichem Gruß / With kind regards
	Holger Klawitter
--
lists@klawitter.de


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: How use an external C program in a Servlet

Posted by Michel Jubault <mi...@free.fr>.
Thanks, I try it straight away !
What kind of problem could occur with security ?

Regards

Michel

----- Original Message -----
From: Holger Klawitter <li...@klawitter.de>
To: Tomcat Users List <to...@jakarta.apache.org>
Sent: Tuesday, June 24, 2003 10:53 AM
Subject: Re: How use an external C program in a Servlet


Am Dienstag, 24. Juni 2003 09:51 schrieb Michel Jubault:
> Hi there !!
>
> I've  a little C program. This computes some variables and return a kind
of
> statistic result. I need it in a servlet. But I don't know how to call it.
> I'm using Tomcat 4.1.24.
> Where this program must be to be launched ?
> How can I pass arguments to C program and use in servlet the return value
?

The normal java contains the solution:

http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Runtime.html#exec(java.lan
g.String[])

However, this imposes a lot of security concerns. You will probably have to
dig into $TOMCAT_HOME/conf/catalina.policy.

Mit freundlichem Gruß / With kind regards
Holger Klawitter
--
lists@klawitter.de


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: How use an external C program in a Servlet

Posted by Holger Klawitter <li...@klawitter.de>.
Am Dienstag, 24. Juni 2003 09:51 schrieb Michel Jubault:
> Hi there !!
>
> I've  a little C program. This computes some variables and return a kind of
> statistic result. I need it in a servlet. But I don't know how to call it.
> I'm using Tomcat 4.1.24.
> Where this program must be to be launched ?
> How can I pass arguments to C program and use in servlet the return value ?

The normal java contains the solution:

http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Runtime.html#exec(java.lang.String[])

However, this imposes a lot of security concerns. You will probably have to 
dig into $TOMCAT_HOME/conf/catalina.policy.

Mit freundlichem Gruß / With kind regards
	Holger Klawitter
--
lists@klawitter.de


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org