Vodz, last_path_87, formatiing changes

This commit is contained in:
Glenn L McGrath 2003-05-26 14:09:12 +00:00
parent 393183dccc
commit 2faee7b1ed

View File

@ -60,7 +60,8 @@ static int config_ok;
#define CONFIG_FILE "/etc/busybox.conf"
/* applets [] is const, so we have to define this "override" structure */
struct BB_suid_config {
struct BB_suid_config
{
struct BB_applet *m_applet;
uid_t m_uid;
@ -78,7 +79,8 @@ static struct BB_suid_config *suid_config;
extern void bb_show_usage(void)
extern void
bb_show_usage (void)
{
const char *format_string;
const char *usage_string = usage_messages;
@ -93,12 +95,14 @@ extern void bb_show_usage(void)
format_string = "%s\n\nUsage: %s %s\n\n";
if (*usage_string == '\b')
format_string = "%s\n\nNo help available.\n\n";
fprintf(stderr, format_string, bb_msg_full_version, applet_using->name, usage_string);
fprintf (stderr, format_string, bb_msg_full_version, applet_using->name,
usage_string);
exit (EXIT_FAILURE);
}
static int applet_name_compare(const void *x, const void *y)
static int
applet_name_compare (const void *x, const void *y)
{
const char *name = x;
const struct BB_applet *applet = y;
@ -108,13 +112,15 @@ static int applet_name_compare(const void *x, const void *y)
extern const size_t NUM_APPLETS;
struct BB_applet *find_applet_by_name(const char *name)
struct BB_applet *
find_applet_by_name (const char *name)
{
return bsearch (name, applets, NUM_APPLETS, sizeof (struct BB_applet),
applet_name_compare);
}
void run_applet_by_name(const char *name, int argc, char **argv)
void
run_applet_by_name (const char *name, int argc, char **argv)
{
static int recurse_level = 0;
extern int been_there_done_that; /* From busybox.c */
@ -159,7 +165,8 @@ void run_applet_by_name(const char *name, int argc, char **argv)
#ifdef CONFIG_FEATURE_SUID_CONFIG
/* check if u is member of group g */
static int ingroup ( uid_t u, gid_t g )
static int
ingroup (uid_t u, gid_t g)
{
struct group *grp = getgrgid (g);
@ -179,7 +186,8 @@ static int ingroup ( uid_t u, gid_t g )
#endif
void check_suid ( struct BB_applet *applet )
void
check_suid (struct BB_applet *applet)
{
uid_t ruid = getuid (); /* real [ug]id */
uid_t rgid = getgid ();
@ -205,25 +213,24 @@ void check_suid ( struct BB_applet *applet )
if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) { /* *both* have to be set for sgid */
if (setegid (sct->m_gid))
bb_error_msg_and_die ( "BusyBox binary has insufficient rights to set proper GID for applet!" );
}
else
bb_error_msg_and_die
("BusyBox binary has insufficient rights to set proper GID for applet!");
} else
setgid (rgid); /* no sgid -> drop */
if (sct->m_mode & S_ISUID) {
if (seteuid (sct->m_uid))
bb_error_msg_and_die ( "BusyBox binary has insufficient rights to set proper UID for applet!" );
}
else
bb_error_msg_and_die
("BusyBox binary has insufficient rights to set proper UID for applet!");
} else
setuid (ruid); /* no suid -> drop */
}
else { /* default: drop all priviledges */
} else {
/* default: drop all priviledges */
setgid (rgid);
setuid (ruid);
}
return;
}
else {
} else {
#ifndef CONFIG_FEATURE_SUID_CONFIG_QUIET
static int onetime = 0;
@ -238,8 +245,7 @@ void check_suid ( struct BB_applet *applet )
if (applet->need_suid == _BB_SUID_ALWAYS) {
if (geteuid () != 0)
bb_error_msg_and_die ("This applet requires root priviledges!");
}
else if ( applet-> need_suid == _BB_SUID_NEVER ) {
} else if (applet->need_suid == _BB_SUID_NEVER) {
setgid (rgid); /* drop all priviledges */
setuid (ruid);
}
@ -251,7 +257,8 @@ void check_suid ( struct BB_applet *applet )
#define parse_error(x) { err=x; goto pe_label; }
int parse_config_file ( void )
int
parse_config_file (void)
{
struct stat st;
char *err = 0;
@ -263,7 +270,8 @@ int parse_config_file ( void )
/* is there a config file ? */
if (stat (CONFIG_FILE, &st) == 0) {
/* is it owned by root with no write perm. for group and others ? */
if ( S_ISREG( st. st_mode ) && ( st. st_uid == 0 ) && (!( st. st_mode & ( S_IWGRP | S_IWOTH )))) {
if (S_ISREG (st.st_mode) && (st.st_uid == 0)
&& (!(st.st_mode & (S_IWGRP | S_IWOTH)))) {
/* that's ok .. then try to open it */
f = fopen (CONFIG_FILE, "r");
@ -299,8 +307,7 @@ int parse_config_file ( void )
section = 1;
else
section = -1; /* unknown section - just skip */
}
else if ( section ) {
} else if (section) {
switch (section) {
case 1:{ /* SUID */
int l;
@ -312,53 +319,78 @@ int parse_config_file ( void )
parse_error ("malformed keyword");
l = p - buffer;
while ( isspace ( buffer [--l] )) { } /* skip whitespace */
while (isspace (buffer[--l])) {
/* skip whitespace */
}
buffer[l + 1] = 0;
if ((applet = find_applet_by_name (buffer))) {
struct BB_suid_config *sct = xmalloc ( sizeof( struct BB_suid_config ));
struct BB_suid_config *sct =
xmalloc (sizeof (struct BB_suid_config));
sct->m_applet = applet;
sct->m_next = suid_config;
suid_config = sct;
while ( isspace ( *++p )) { } /* skip whitespace */
while (isspace (*++p)) {
/* skip whitespace */
}
sct->m_mode = 0;
switch (*p++) {
case 'S': sct-> m_mode |= S_ISUID; break;
case 's': sct-> m_mode |= S_ISUID; /* no break */
case 'x': sct-> m_mode |= S_IXUSR; break;
case '-': break;
default : parse_error ( "invalid user mode" );
case 'S':
sct->m_mode |= S_ISUID;
break;
case 's':
sct->m_mode |= S_ISUID;
/* no break */
case 'x':
sct->m_mode |= S_IXUSR;
break;
case '-':
break;
default:
parse_error ("invalid user mode");
}
switch (*p++) {
case 's': sct-> m_mode |= S_ISGID; /* no break */
case 'x': sct-> m_mode |= S_IXGRP; break;
case 'S': break;
case '-': break;
default : parse_error ( "invalid group mode" );
case 's':
sct->m_mode |= S_ISGID;
/* no break */
case 'x':
sct->m_mode |= S_IXGRP;
break;
case 'S':
break;
case '-':
break;
default:
parse_error ("invalid group mode");
}
switch (*p) {
case 't':
case 'x': sct-> m_mode |= S_IXOTH; break;
case 'x':
sct->m_mode |= S_IXOTH;
break;
case 'T':
case '-': break;
default : parse_error ( "invalid other mode" );
case '-':
break;
default:
parse_error ("invalid other mode");
}
while ( isspace ( *++p )) { } /* skip whitespace */
while (isspace (*++p)) {
/* skip whitespace */
}
if (isdigit (*p)) {
sct->m_uid = strtol (p, &p, 10);
if (*p++ != '.')
parse_error ("parsing <uid>.<gid>");
}
else {
} else {
struct passwd *pwd;
char *p2 = strchr (p, '.');
@ -390,8 +422,7 @@ int parse_config_file ( void )
default: /* unknown - skip */
break;
}
}
else
} else
parse_error ("keyword not within section");
}
fclose (f);