LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Closed Thread
  Search this Thread
Old 10-30-2009, 05:33 AM   #1
narendra1310
Member
 
Registered: May 2008
Posts: 41

Rep: Reputation: 15
Question Limit non-jail running of jailed binaries ????


I constructed newroot directory and run this command [ /usr/sbin/chroot /path-to-newroot/ apache/bin/httpd -k start] as root user and it was working fine.

But
I want to run my apache-server inside chrootJail as a non-root user for security reasons.

Here is the link I followed steps to do :

http://unixwiz.net/techtips/chroot-practices.html

* Run in the jail as a non-root user
* Limit non-jail running of jailed binaries

For systems that do not have a command-line option for running chroot, the only alternative is to create a wrapper program. This wrapper will perform the key chroot operation, give up root permission, and then execute the jailed binary.

The wrapper must be run as root (only chroot can perform this operation), but the wrapper itself must not be found in the jail.

++++++++++++++++++++
My Wrapper program.
++++++++++++++++++++
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <pwd.h>

int showList(const char *path)
{
DIR *dir;
struct dirent *ent;
dir = opendir(path);
if (dir != NULL)
{
printf ("#####Sub-Directories And Files Under newroot#####///\n");
while ((ent = readdir (dir)) != NULL)
{
printf ("%s ", ent->d_name);
}
printf ("\n");
closedir(dir);
}
else
{
printf ("ERROR open with dir \n");
perror ("dir");
}
}

int main()
{
char *path;
path = (char *)malloc(100);

printf("parent process\n");

/*change directory to newroot*/
printf("chdir=%d\n",chdir("/home/test/builds/server/sgchroot"));

/*chrooting the newroot*/
printf("chrt=%d\n",chroot("/home/test/builds/server/sgchroot"));

/*setting uid of the test [non-root user] with its uid=500 */
setuid(500);

if(!fork())
{
printf("\nchild process\n");

/*setting uid of the test [non-root user] with its uid=500 */
setuid(500);

/*Get uid's status of a child process*/
printf("uid :: %d\teuid :: %d\n",getuid(),geteuid());

/*get current working directory i.e. newroot as "/"*/
memset(path,0,100);
getcwd(path,100);
path[strlen(path)]='\0';
printf("cwd :: %s\n",path);

/*show the list of derectories under newroot "/"*/
showList(path);

/* Executing the binary as test [non-root user]*/
printf("system() :: %d\n",system("./apache/bin/httpd -k start"));
}
}

+++++++
Result:
+++++++
parent process
chdir :: 0
chrt :: 0

child process
uid :: 500 euid :: 500
cwd :: /
#####Sub-Directories And Files Under newroot#####///
dev usr data php etc tmp .odbc.ini htmlgui .. apache . lib readme.html .createsgchroot.sh gd
system() :: 32512

?????????????????????????????????????????????????????????????????

But still I am unable to start apache inside the chrootJail. syscall system() throws some numeric value. what is this value.

Is there any changes need to be done to my wrapper program to work in order to execute jailed apache binary as a non-root user OR the way i done it was wrong ?.

"""""""" Please suggest me with some good solution """"""

Thanks in Advance
 
Old 10-30-2009, 09:02 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.
 
  


Closed Thread



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
Running libc5 binaries sreyesp Slackware 5 04-22-2007 02:11 AM
Perl not running backticks within chroot jail Consul Linux - Security 2 08-02-2005 05:36 PM
Installing a 64 bit Linux and running 32 binaries? hal9000hal Linux - General 1 01-31-2005 02:41 PM
Running FreeBSD binaries on Linux? koyi Linux - General 6 12-25-2004 10:16 PM
Running linux binaries on windows alitrix Linux - Software 2 09-13-2004 08:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:35 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