From: "Anthony Brock" <brocka@sterlingcgi.com>
To: user-mode-linux-devel@lists.sourceforge.net
Subject: RE: [uml-devel] Re: pcap cross-linking [PATCH]
Date: Thu, 22 Dec 2005 09:57:35 -0800 [thread overview]
Message-ID: <CGEGKKNGBDKPCKOKKGFEIEBACDAA.brocka@sterlingcgi.com> (raw)
In-Reply-To: <200512211913.18433.blaisorblade@yahoo.it>
[-- Attachment #1: Type: text/plain, Size: 1637 bytes --]
I don't think the attachment made it into the email. However, I am attaching
one that we've used with good success. It allows us to also specify a "nice"
level for the UML kernel in addition to the chroot-setuid.
Tony
> -----Original Message-----
> From: user-mode-linux-devel-admin@lists.sourceforge.net
> [mailto:user-mode-linux-devel-admin@lists.sourceforge.net]On Behalf Of
> Blaisorblade
> Sent: Wednesday, December 21, 2005 10:13 AM
> To: user-mode-linux-devel@lists.sourceforge.net
> Cc: Rob Landley; Antoine Martin
> Subject: Re: [uml-devel] Re: pcap cross-linking [PATCH]
>
>
> Forgot to say one thing - the attachment is a minimal
> chroot-setuid C program
> written by Jeff Dike for his book - it's minimal and trivial to verify.
>
> --
> Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
> Paolo Giarrusso, aka Blaisorblade (Skype ID "PaoloGiarrusso", ICQ
> 215621894)
> http://www.user-mode-linux.org/~blaisorblade
>
>
> ___________________________________
> Yahoo! Messenger: chiamate gratuite in tutto il mondo
> http://it.messenger.yahoo.com
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep
> through log files
> for problems? Stop! Download the new AJAX search engine that makes
> searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> User-mode-linux-devel mailing list
> User-mode-linux-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
>
[-- Attachment #2: chrootuidgid.c --]
[-- Type: application/octet-stream, Size: 3560 bytes --]
#include <unistd.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/param.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#define TMP_PATH "/dev/shm"
#define PATH "PATH"
int main(int ac, char **av)
{
char *param[ac+1];
char *uname = NULL;
char *chroot_dir = NULL;
char *path = NULL;
struct passwd *userinfo;
int c, i;
int nice_val = 0;
uid_t uid = 0;
gid_t gid = 0;
opterr = 0;
while ((c = getopt(ac, av, "+u:n:p:")) != -1)
switch (c)
{
case 'u':
uname = optarg;
break;
case 'n':
nice_val = atoi(optarg);
break;
case 'p':
chroot_dir = optarg;
break;
case '?':
if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr,
"Unknown option character `\\x%x'.\n",
optopt);
return 1;
default:
abort();
}
if ((uname != NULL) && (chroot_dir != NULL))
{
if ((userinfo = getpwnam(uname)) != NULL)
{
uid = userinfo->pw_uid;
gid = userinfo->pw_gid;
// Adjust the process priority by the requested "nice" value
if(nice(nice_val) == -1)
{
fprintf(stderr, "error changing 'nice' value to %i: %s\n", nice_val, strerror(errno));
return 1;
}
// Abort if we were passed user "root"
if (uid == 0)
{
fprintf (stderr, "Specified account must NOT be root!\n");
return 1;
}
// Clear any existing environment
path = getenv(PATH);
if (clearenv())
{
fprintf(stderr, "WARNING: unable to clear environment!\n");
}
// Setup the command environment
setenv("HOME", userinfo->pw_dir, 1);
setenv(PATH, path, 1);
setenv("TMP", TMP_PATH, 1);
setenv("USER", userinfo->pw_name, 1);
// Our first parameter should be the command we're to execute
// Therefore, we assign this to element '0' of our parameters to pass
for (i = 0, c = optind; c < ac; i++, c++)
{
param[i] = av[c];
}
// Abort if we have not other parameters
if (i == 0)
{
fprintf (stderr, "You must specify a command to execute!\n");
return 1;
}
// The final element in the array MUST be a NULL pointer
param[i] = NULL;
// First, we need to CHDIR to the CHROOT directory
if(chdir(chroot_dir) == -1)
{
fprintf(stderr, "chdir to '%s' failed: %s\n", chroot_dir, strerror(errno));
return 3;
}
// Next, we need to CHROOT ourselves (while we're still root)
if(chroot(chroot_dir) == -1)
{
fprintf(stderr, "chroot to '%s' failed: %s\n", chroot_dir, strerror(errno));
return 3;
}
// Now CHDIR to the accounts home directory. This is a non-fatal error.
if(chdir(userinfo->pw_dir) == -1)
{
fprintf(stderr, "WARNING: chdir to home directory '%s' failed: %s\n", userinfo->pw_dir, strerror(errno));
}
if(setregid(gid, gid) == -1)
{
fprintf(stderr, "setregid to gid %i failed: %s\n", gid, strerror(errno));
return 3;
}
if(setreuid(uid, uid) == -1)
{
fprintf(stderr, "setreuid to uid %i failed: %s\n", uid, strerror(errno));
return 3;
}
if(execvp(param[0], param) == -1)
{
fprintf(stderr, "exec for '%s' failed: %s\n", param[0], strerror(errno));
return 4;
}
}
else
{
fprintf(stderr, "User '%s' not found\n", uname);
return 2;
}
}
else
{
fprintf(stderr, "You must specify a valid account with the '-u' option and a valid chroot path with the '-p' option!\n");
return 1;
}
}
next prev parent reply other threads:[~2005-12-22 17:57 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-18 19:03 [uml-devel] pcap cross-linking Antoine Martin
2005-12-19 16:16 ` [uml-devel] " Blaisorblade
2005-12-19 18:33 ` [uml-devel] Re: pcap cross-linking [PATCH] Antoine Martin
2005-12-19 19:27 ` Blaisorblade
2005-12-19 21:47 ` Antoine Martin
2005-12-20 14:23 ` Blaisorblade
2005-12-20 16:25 ` Antoine Martin
2005-12-20 19:24 ` Blaisorblade
2005-12-20 20:01 ` Rob Landley
2005-12-20 20:24 ` Antoine Martin
2005-12-20 20:43 ` Blaisorblade
2005-12-21 18:13 ` Blaisorblade
2005-12-22 17:57 ` Anthony Brock [this message]
2005-12-23 16:11 ` Blaisorblade
2005-12-26 7:47 ` Anthony Brock
2005-12-29 20:12 ` Rob Landley
2006-01-01 18:51 ` Blaisorblade
2006-01-01 21:01 ` Rob Landley
2006-01-02 20:10 ` Blaisorblade
2005-12-19 18:39 ` [uml-devel] Re: pcap cross-linking Blaisorblade
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CGEGKKNGBDKPCKOKKGFEIEBACDAA.brocka@sterlingcgi.com \
--to=brocka@sterlingcgi.com \
--cc=user-mode-linux-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox