/* The -1 arises because of the {0,NULL,0,-1} entry. */
const unsigned short NUM_APPLETS = sizeof(applets) / sizeof(applets[0]) - 1;
-
const struct bb_applet *current_applet;
const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
#if !BB_MMU
bool re_execed;
#endif
-
+#if ENABLE_FEATURE_SUID
+static uid_t ruid; /* real uid */
+#endif
#if ENABLE_FEATURE_SUID_CONFIG
assert(!suid_config); /* Should be set to NULL by bss init. */
+ ruid = getuid();
+ if (ruid == 0) /* run by root - don't need to even read config file */
+ return;
+
if ((stat(config_file, &st) != 0) /* No config file? */
|| !S_ISREG(st.st_mode) /* Not a regular file? */
|| (st.st_uid != 0) /* Not owned by root? */
}
}
#else
-#define parse_config_file() ((void)0)
+static inline void parse_config_file(void)
+{
+ ruid = getuid();
+}
#endif /* FEATURE_SUID_CONFIG */
#if ENABLE_FEATURE_SUID
static void check_suid(const struct bb_applet *applet)
{
- uid_t ruid = getuid(); /* real [ug]id */
- uid_t rgid = getgid();
+ uid_t rgid; /* real gid */
+
+ if (ruid == 0) /* set by parse_config_file() */
+ return; /* run by root - no need to check more */
+ rgid = getgid();
#if ENABLE_FEATURE_SUID_CONFIG
if (suid_cfg_readable) {
if (geteuid())
bb_error_msg_and_die("applet requires root privileges!");
} else if (applet->need_suid == _BB_SUID_NEVER) {
- xsetgid(rgid); /* drop all privileges */
+ xsetgid(rgid); /* drop all privileges */
xsetuid(ruid);
}
}
if (s)
applet_name = s + 1;
- if (ENABLE_FEATURE_SUID_CONFIG)
- parse_config_file();
+ parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */
/* Set locale for everybody except 'init' */
if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
/*
* values returned by wait
*/
-#define WAITSIG(s) ((s)&0177)
-#define WAITVAL(s) (((s)>>8)&0377)
-#define WAITCORE(s) (((s)&0200)!=0)
+#define WAITSIG(s) ((s) & 0177)
+#define WAITVAL(s) (((s) >> 8) & 0377)
+#define WAITCORE(s) (((s) & 0200) != 0)
/*
* library and system definitions
*/
typedef void xint; /* base type of jmp_buf, for not broken compilers */
-
/*
* shell components
*/
#define NOWORDS ((char **)NULL)
#define NOPIPE ((int *)NULL)
-
/*
* redirection
*/
/*
* actions determining the environment of a process
*/
-#define BIT(i) (1<<(i))
-#define FEXEC BIT(0) /* execute without forking */
+#define FEXEC 1 /* execute without forking */
-#define AREASIZE (90000)
+#define AREASIZE (90000)
/*
* flags to control evaluation of words
*/
-#define DOSUB 1 /* interpret $, `, and quotes */
-#define DOBLANK 2 /* perform blank interpretation */
-#define DOGLOB 4 /* interpret [?* */
-#define DOKEY 8 /* move words with `=' to 2nd arg. list */
-#define DOTRIM 16 /* trim resulting string */
+#define DOSUB 1 /* interpret $, `, and quotes */
+#define DOBLANK 2 /* perform blank interpretation */
+#define DOGLOB 4 /* interpret [?* */
+#define DOKEY 8 /* move words with `=' to 2nd arg. list */
+#define DOTRIM 16 /* trim resulting string */
-#define DOALL (DOSUB|DOBLANK|DOGLOB|DOKEY|DOTRIM)
+#define DOALL (DOSUB|DOBLANK|DOGLOB|DOKEY|DOTRIM)
/* PROTOTYPES */
/* -------- area stuff -------- */
-#define REGSIZE sizeof(struct region)
-#define GROWBY (256)
-/* #define SHRINKBY (64) */
-#undef SHRINKBY
-#define FREE (32767)
-#define BUSY (0)
-#define ALIGN (sizeof(int)-1)
+#define REGSIZE sizeof(struct region)
+#define GROWBY (256)
+/* #define SHRINKBY (64) */
+#undef SHRINKBY
+#define FREE (32767)
+#define BUSY (0)
+#define ALIGN (sizeof(int)-1)
struct region {
f = 0;
if (NOT_LONE_DASH(s)) {
DBGPRINTF(("NEWFILE: s is %s\n", s));
- f = open(s, 0);
+ f = open(s, O_RDONLY);
if (f < 0) {
prs(s);
err(": cannot open");
interactive = 0;
if (pin == NULL) {
close(0);
- open(bb_dev_null, 0);
+ open(bb_dev_null, O_RDONLY);
}
_exit(execute(t->left, pin, pout, FEXEC));
}
resetsig = 0;
rv = -1; /* system-detected error */
if (t->type == TCOM) {
- while (*wp++ != NULL);
+ while (*wp++ != NULL)
+ continue;
cp = *wp;
/* strip all initial assignments */
if (cp == NULL && t->ioact == NULL) {
while ((cp = *owp++) != NULL && assign(cp, COPYV))
- /**/;
+ continue;
DBGPRINTF(("FORKEXEC: returning setstatus()\n"));
return setstatus(0);
}
}
switch (iop->io_flag) {
case IOREAD:
- u = open(cp, 0);
+ u = open(cp, O_RDONLY);
break;
case IOHERE:
break;
case IOWRITE | IOCAT:
- u = open(cp, 1);
+ u = open(cp, O_WRONLY);
if (u >= 0) {
lseek(u, (long) 0, SEEK_END);
break;
for (i = 0; (*tp++ = cp[i++]) != '\0';);
/* Original code */
- i = open(e.linep, 0);
+ i = open(e.linep, O_RDONLY);
if (i >= 0) {
exstat = 0;
maltmp = remap(i);
DBGPRINTF7(("HEREIN: hname is %s, xdoll=%d\n", hname, xdoll));
- hf = open(hname, 0);
+ hf = open(hname, O_RDONLY);
if (hf < 0)
return -1;
} else
unlink(tname);
close(tf);
- tf = open(tname, 0);
+ tf = open(tname, O_RDONLY);
unlink(tname);
return tf;
}
path = lookup("PATH");
if (path->value == null) {
+ /* Can be merged with same string elsewhere in bbox */
if (geteuid() == 0)
- setval(path, "/sbin:/bin:/usr/sbin:/usr/bin");
+ setval(path, "/sbin:/usr/sbin:/bin:/usr/bin");
else
- setval(path, "/bin:/usr/bin");
+ setval(path, "/sbin:/usr/sbin:/bin:/usr/bin" + sizeof("/sbin:/usr/sbin"));
}
export(path);
signal(SIGQUIT, qflag);
if (name && name[0] == '-') {
interactive++;
- f = open(".profile", 0);
+ f = open(".profile", O_RDONLY);
if (f >= 0)
next(remap(f));
- f = open("/etc/profile", 0);
+ f = open("/etc/profile", O_RDONLY);
if (f >= 0)
next(remap(f));
}