LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-07-2013, 04:19 PM   #1
HIDS2013
LQ Newbie
 
Registered: Jul 2013
Posts: 3

Rep: Reputation: Disabled
How to execute system calls in php via browser?


I have a C program that makes a system call (centOS 6.0) to encrypt a file, my code is:

#include <stdlib.h>
int main () {
system ("gpg -c --batch --passphrase mypass file.txt");
return 0;
}
The executable object is called encrypt_file
When I run ./encrypt_file directly through CLI it runs perfectly I obtain my file.txt.gpg, but when I try to execute it via browser when I get no response. Code in php: shell_exec("./encrypt_file");

I already changed permissions to apache user by issuing the following:
chown apache.apache /var/www/html/
And added the next line in /etc/sudoers:
apache ALL=(ALL) NOPASSWD:ALL

NOTE: The only command I have issues is gpg, I can make a system call with any other command that I needed to use, I can even run python scripts, and other C programs that doesn't contain anything related to gpg.

Where can I change the PATH variable that is in use with the apache webserver???

I hope a fast reply! I need to use a lot this encrypt_file!
 
Old 07-08-2013, 04:05 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
1. You better give the shell_exec the full path to the file that is to be executed.

2. The apache web user is probably not "apache" but instead "wwwrun" or "nobody", depending on apache config. (regarding the sudoers)

I think you better do not allow the web user to execute everything on your box as sudo without password, if I don't get you wrong...

Hope this helps,
j

Last edited by j-ray; 07-08-2013 at 04:12 AM.
 
Old 07-08-2013, 10:34 AM   #3
HIDS2013
LQ Newbie
 
Registered: Jul 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
I already added the full PATH, still no response.
But checking the error_log in /var/log/httpd/error_log I saw this line:

gpg: Fatal: can't create directory `/var/www/.gnupg': Permission denied

It's a permission problem obviously but I'm not sure where...

Thanks!
 
Old 07-08-2013, 11:27 AM   #4
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
Can't you manually create this directory as root and grant write access to it to the web user? /var/www/is probably the basic document root and writable for root only...

sudo mkdir /var/www/.gnupg

And if the user needs writing access to it you may
chown wwwrun:users /var/www/.gnupg

Last edited by j-ray; 07-08-2013 at 11:30 AM.
 
1 members found this post helpful.
Old 07-08-2013, 12:53 PM   #5
HIDS2013
LQ Newbie
 
Registered: Jul 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks! Problem solved...

I found a solution at this site -> http://gnupg.10057.n7.nabble.com/Exi...pt-td7342.html

I added that --homedir with the PATH that I found in the error.log of apache, and it works perfectly!

I will try your solution that seems more elegant! Thanks a lot for your help!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
*** glibc detected *** php: free(): invalid pointer: 0x03376f50 *** when execute PHP troya Linux - Server 3 01-07-2015 06:16 AM
how does java calls the system calls which are written in c babu198649 Linux - General 3 12-05-2011 03:40 AM
[SOLVED] PHP System calls using a link d072330 Programming 4 10-10-2011 03:58 PM
LXer: amon.so: Hijacking System Calls For Hardening PHP - Debian Lenny And Squeeze LXer Syndicated Linux News 0 04-11-2011 02:30 PM
System calls/functions to execute a file within a program psandeepnair1985 Programming 1 05-02-2007 02:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration