summaryrefslogtreecommitdiff
path: root/applets/applets.c
diff options
context:
space:
mode:
authorDenis Vlasenko2007-04-14 13:22:09 +0000
committerDenis Vlasenko2007-04-14 13:22:09 +0000
commit5f9468e99649c0daa5cacfe180fbd0e061df6fc3 (patch)
tree61ab361ce2e76c19f9c3d3661c9fd8d3e0eae6cf /applets/applets.c
parent8a28e620ce6017fd184c26a7ce25f5e167a90fe7 (diff)
downloadbusybox-5f9468e99649c0daa5cacfe180fbd0e061df6fc3.zip
busybox-5f9468e99649c0daa5cacfe180fbd0e061df6fc3.tar.gz
lineedit: nuke two unused variables and code which sets them
applets: do not even try to read config if run by real root msh: use named constants (O_RDONLY etc) in open() instead of magic numbers, other minor code size reduction.
Diffstat (limited to 'applets/applets.c')
-rw-r--r--applets/applets.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/applets/applets.c b/applets/applets.c
index fb37fbe..13b406a 100644
--- a/applets/applets.c
+++ b/applets/applets.c
@@ -48,14 +48,15 @@ static const char usage_messages[] = ""
/* 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
@@ -143,6 +144,10 @@ static void parse_config_file(void)
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? */
@@ -324,15 +329,21 @@ static void parse_config_file(void)
}
}
#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) {
@@ -387,7 +398,7 @@ static void check_suid(const struct bb_applet *applet)
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);
}
}
@@ -636,8 +647,7 @@ int main(int argc, char **argv)
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)