LinuxQuestions.org
Help answer threads with 0 replies.
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 10-19-2005, 01:08 PM   #1
dimsh
Member
 
Registered: Aug 2005
Distribution: Debian, Ubuntu, Fedora
Posts: 74

Rep: Reputation: 15
popen output not appear


Hi,

I am running my box on Linux FC4, and using Tomcat as my Web Server.
There is a user called utomcat who own the files/directories related to Tomcat and who own its process.

I am writing a binary file using C language and gcc compiler to allow web user (utomcat) to call (execute) a binary which can only be executed by root, those binaries are:
/home/vpopmail/bin/vadduser
/home/vpopmail/bin/vuserinfo

My problem is in the output that those binaries offer as a response to the acton they did.

I used "popen" in my program as following:
Code:
//### C Code ###
#include "stdio.h"
int main (int args, char *argv[]) {
	int result = 1;
	char *command = "/home/vpopmail/bin/vuserinfo user1@domain.com";
	FILE *output = popen(command , "r");

	while(result != EOF)	printf("%c" , result = fgetc(output));
	pclose(output);
};
//##############
The program compiled with no errors nor warnings and I named it "uinfo.exec", and chmod to 755.
I have set the "setuid" and "setgid" flags to the file "uinfo.exec" which is owned by root:root .

When I run the binary as root user , I get the output as supposed on the console terminal and every thing is fine

But
when su-ing to another user and running it (utomcat user for example) I see no output at all.

I need the output be visible to any user who call my binary.

Any solutions?

Thanks

Last edited by dimsh; 10-19-2005 at 01:11 PM.
 
Old 10-19-2005, 02:03 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
I tried your code, with only the command changed to "ls /tmp" and it worked as expected. So I guess "vuserinfo" writes to stderr instead of stdin.

What happens when you try with "ls /tmp"?

I also wonder why you need this extra program. Doesn't java/tomcat has its own popen()-like functionality?
 
Old 10-20-2005, 06:45 AM   #3
dimsh
Member
 
Registered: Aug 2005
Distribution: Debian, Ubuntu, Fedora
Posts: 74

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by Hko
I tried your code, with only the command changed to "ls /tmp" and it worked as expected. So I guess "vuserinfo" writes to stderr instead of stdin.

What happens when you try with "ls /tmp"?
"ls /tmp" command works fine for both users.
What can I do if "vuserinfo" writes to stderr ? why i can get the user info using my binary if i am root and can not if other user ?

Quote:
I also wonder why you need this extra program. Doesn't java/tomcat has its own popen()-like functionality?
Also "vuserinfo" can only be executed by root , that is why i write this binary to be able to set its setuid flag (chmod 4755) and execute the "vuserinfo" command by any user (utomcat)

I do not know about java ability to popen because i am not java programmer , I need to allow java programmers to get user's mail information, via setuid ability, all they need to do is to call my binary from the java page , the script then will set UID to root , bring the user infor and they can read the binary output through java.

I think the problem is in stderr as you say , but how to work around it ?

Last edited by dimsh; 10-20-2005 at 07:00 AM.
 
Old 10-20-2005, 04:39 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally posted by dimsh
I think the problem is in stderr as you say , but how to work around it ?
Instead of:
Code:
"/home/vpopmail/bin/vuserinfo user1@domain.com"
Try:
Code:
"/home/vpopmail/bin/vuserinfo user1@domain.com 2>&1"
If stderr is the problem, adding "2&>1" after the command should solve it.

Last edited by Hko; 10-20-2005 at 04:41 PM.
 
Old 10-22-2005, 02:56 AM   #5
dimsh
Member
 
Registered: Aug 2005
Distribution: Debian, Ubuntu, Fedora
Posts: 74

Original Poster
Rep: Reputation: 15
Thanks Hko for your help, redirecting using 2>&1 did not solve the problem.

I have posted this on experts-exchange also, the guys there says to use setuid() function and it works just fine.

if you like to see the solution there here is the link:
http://www.experts-exchange.com/Prog..._21600661.html

Thanks again for your efforts, Regards.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
popen for windows csfalcon Programming 6 11-30-2005 08:21 AM
where do i get a bidirectional popen pipe? Thinking Programming 9 10-21-2005 07:42 AM
Help needed with system() and popen! twirl Programming 4 09-14-2005 09:22 AM
Multithreading and os.popen in wxPython wapcaplet Programming 0 12-29-2004 07:58 PM
C Popen gold5angel Programming 2 04-17-2004 07:07 PM

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

All times are GMT -5. The time now is 07:19 AM.

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