[BusyBox] Improving Our Development Process
Tomi Ollila
Tomi.Ollila at sonera.com
Thu Jan 25 07:12:50 UTC 2001
Wednesday Jan 24 21:24:37 +0300 2001 Vladimir N. Oleynik <dzo at simtreas.ru> wrote:
> Matt Kraai wrote:
>
> >> To not litter, look:
> > I did see this earlier but it must have slipped my mind.
>
> ftp://ftp.simtreas.ru/pub/my/bb/new/suid_wrapper.c
>
> New version.
> The new version. Check is not obligatory.
> Rewriting argv [0] is obligatory.
Suggestion:
Make one suid-wrapper able to run all setuid busybox applets, thus saving
inode and some file space.
In order to do this, again, an alphabetical list of allowed commands needs
to be generated (at programming time), basename of the command needs to be
taken (at run time), search for match for this command in the list and if
one found, set argv[0] accordingly and execv the cmd line. An example:
--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--
#include <unistd.h>
//#define TEST
#ifdef TEST
#define BB_PLACE "./busybox"
#else
#define BB_PLACE "/bin/busybox"
#endif
void exit(int code) { _exit(code); }
char * suid_applets[] = {
"mount"
"ping"
"su"
"umount"
};
#define SIZE_APPLETS (sizeof suid_applets / sizeof suid_applets[0])
int main(int argc, char **argv)
{
int lower = 0, upper = SIZE_APPLETS - 1
char * cmdname;
char * p;
p = cmdname = argv[0];
/* basename argv[0] */
while (*p)
{
if (*p++ == '/')
cmdname = p;
}
while (lower <= upper)
{
char * q = cmdname;
int res;
p = suid_applets[lower + upper / 2];
/* strcmp */
while (*q)
{
if (*p++ != *q++)
break;
}
res = *q - *p;
if (res < 0) lower = middle + 1;
else if (res > 0) upper = middle - 1;
else {
argv[0] = cmdname;
execv(BB_PLACE, argv);
write(2, "Can`t start busybox!\n", 21);
}
}
/* not found (or execv failed) */
return -1;
}
--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--
I'd estimate this example compiles just under 1000 bytes?
>
>
> --w
> vodz
Tomi
More information about the busybox
mailing list