From: Billy Holmes <billy@gonoph.net>
To: gentoo-amd64@lists.gentoo.org
Subject: Re: [gentoo-amd64] Re: Installing into a 32-bit chroot?
Date: Wed, 07 Sep 2005 10:09:40 -0400 [thread overview]
Message-ID: <431EF4A4.505@gonoph.net> (raw)
In-Reply-To: <1126037681.10070.47.camel@thor.tres.org>
Tres Melton wrote:
> the /tmp dirs and other things and I do this at boot. Further I have
> written a program that will allow any user (approved by the sudoers file
> in the chroot and the regular root) to run any program from wherever
> they are without the headache of becoming root, etc.. Here ya go:
I actually did the same thing, but I'm combined some code from chroot
and linux32 and made my own "l32".
install as:
# install -o root -g root -m 4555 l32 $BIN_DIR
invoke as:
$ l32 $PROGRAM
If it can't change into the CWD from the chroot (I use mount --bind for
/home and /tmp), then it changes in to the chroot's "/" directory.
Change "LOWDIR" to point to your own 32-bit chroot.
---[snip]---
#include <linux/personality.h>
#undef personality
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
/* Make --3gb the default for buggy Java */
#define STUPID_DEFAULT 1
#define PER_LINUX32_3GB (PER_LINUX32 | ADDR_LIMIT_32BIT)
#ifdef STUPID_DEFAULT
#define DFL_PER PER_LINUX32_3GB
#else
#define DFL_PER PER_LINUX32
#endif
const char *LOWDIR="/home/32-bit";
#define malloc_Add 64
#define malloc_Max INT_MAX>>12 // If it's over 512 kb, then path is too big
int main(int argc,char **argv,char **envp)
{
int per=DFL_PER;
char *PWD;
size_t PWD_size=malloc_Add;
if (personality(per) < 0)
{
fprintf(stderr,"Can't set personality %x : %s\n",per,strerror(errno));
exit(-1);
}
if (argc<2)
{
fprintf(stderr,"Usage: %s program (arg1 arg2 arg3 ...)\n",argv[0]);
exit(-1);
}
PWD=malloc(PWD_size);
while (NULL==getcwd(PWD,PWD_size))
{
if (errno==ERANGE)
{
if (PWD_size+malloc_Add>malloc_Max)
{
fprintf(stderr,"Path is too long: greater than %lu bytes\n",PWD_size);
exit(-1);
}
PWD_size+=malloc_Add;
PWD=realloc(PWD,PWD_size);
} else {
fprintf(stderr,"Unable to determine current working directory:
%s\n",strerror(errno));
exit(-1);
}
}
if (chroot(LOWDIR) < 0)
{
fprintf(stderr,"Unable to chroot(%s): %s\n",LOWDIR,strerror(errno));
exit(-1);
}
if (seteuid(getuid()) < 0)
{
fprintf(stderr,"Unable to suid(%d): %s\n",getuid(),strerror(errno));
exit(-1);
}
// now change into current working dir with no root privs
if (chdir(PWD) && chdir("/"))
{
fprintf(stderr,"Unable to set working directory:
%s\n",strerror(errno));
exit(-1);
}
free(PWD);
execvp(argv[1],argv+1);
exit(-1);
}
// vim: sw=2:cindent:
--
gentoo-amd64@gentoo.org mailing list
next prev parent reply other threads:[~2005-09-07 14:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-04 16:02 [gentoo-amd64] Installing into a 32-bit chroot? Peter Humphrey
2005-09-04 21:14 ` [gentoo-amd64] " Duncan
2005-09-06 20:14 ` Tres Melton
2005-09-07 8:00 ` Peter Humphrey
2005-09-07 14:09 ` Billy Holmes [this message]
2005-09-05 1:56 ` [gentoo-amd64] " David Fellows
2005-09-05 3:08 ` Barry.SCHWARTZ
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=431EF4A4.505@gonoph.net \
--to=billy@gonoph.net \
--cc=gentoo-amd64@lists.gentoo.org \
/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