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:
--
[email protected] mailing list