diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-14 13:22:09 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-14 13:22:09 +0000 |
commit | 5f9468e99649c0daa5cacfe180fbd0e061df6fc3 (patch) | |
tree | 61ab361ce2e76c19f9c3d3661c9fd8d3e0eae6cf | |
parent | 8a28e620ce6017fd184c26a7ce25f5e167a90fe7 (diff) | |
download | busybox-w32-5f9468e99649c0daa5cacfe180fbd0e061df6fc3.tar.gz busybox-w32-5f9468e99649c0daa5cacfe180fbd0e061df6fc3.tar.bz2 busybox-w32-5f9468e99649c0daa5cacfe180fbd0e061df6fc3.zip |
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.
-rw-r--r-- | applets/applets.c | 26 | ||||
-rw-r--r-- | libbb/lineedit.c | 9 | ||||
-rw-r--r-- | shell/msh.c | 67 |
3 files changed, 51 insertions, 51 deletions
diff --git a/applets/applets.c b/applets/applets.c index fb37fbea5..13b406ae5 100644 --- a/applets/applets.c +++ b/applets/applets.c | |||
@@ -48,14 +48,15 @@ static const char usage_messages[] = "" | |||
48 | /* The -1 arises because of the {0,NULL,0,-1} entry. */ | 48 | /* The -1 arises because of the {0,NULL,0,-1} entry. */ |
49 | const unsigned short NUM_APPLETS = sizeof(applets) / sizeof(applets[0]) - 1; | 49 | const unsigned short NUM_APPLETS = sizeof(applets) / sizeof(applets[0]) - 1; |
50 | 50 | ||
51 | |||
52 | const struct bb_applet *current_applet; | 51 | const struct bb_applet *current_applet; |
53 | const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE; | 52 | const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE; |
54 | #if !BB_MMU | 53 | #if !BB_MMU |
55 | bool re_execed; | 54 | bool re_execed; |
56 | #endif | 55 | #endif |
57 | 56 | ||
58 | 57 | #if ENABLE_FEATURE_SUID | |
58 | static uid_t ruid; /* real uid */ | ||
59 | #endif | ||
59 | 60 | ||
60 | #if ENABLE_FEATURE_SUID_CONFIG | 61 | #if ENABLE_FEATURE_SUID_CONFIG |
61 | 62 | ||
@@ -143,6 +144,10 @@ static void parse_config_file(void) | |||
143 | 144 | ||
144 | assert(!suid_config); /* Should be set to NULL by bss init. */ | 145 | assert(!suid_config); /* Should be set to NULL by bss init. */ |
145 | 146 | ||
147 | ruid = getuid(); | ||
148 | if (ruid == 0) /* run by root - don't need to even read config file */ | ||
149 | return; | ||
150 | |||
146 | if ((stat(config_file, &st) != 0) /* No config file? */ | 151 | if ((stat(config_file, &st) != 0) /* No config file? */ |
147 | || !S_ISREG(st.st_mode) /* Not a regular file? */ | 152 | || !S_ISREG(st.st_mode) /* Not a regular file? */ |
148 | || (st.st_uid != 0) /* Not owned by root? */ | 153 | || (st.st_uid != 0) /* Not owned by root? */ |
@@ -324,15 +329,21 @@ static void parse_config_file(void) | |||
324 | } | 329 | } |
325 | } | 330 | } |
326 | #else | 331 | #else |
327 | #define parse_config_file() ((void)0) | 332 | static inline void parse_config_file(void) |
333 | { | ||
334 | ruid = getuid(); | ||
335 | } | ||
328 | #endif /* FEATURE_SUID_CONFIG */ | 336 | #endif /* FEATURE_SUID_CONFIG */ |
329 | 337 | ||
330 | 338 | ||
331 | #if ENABLE_FEATURE_SUID | 339 | #if ENABLE_FEATURE_SUID |
332 | static void check_suid(const struct bb_applet *applet) | 340 | static void check_suid(const struct bb_applet *applet) |
333 | { | 341 | { |
334 | uid_t ruid = getuid(); /* real [ug]id */ | 342 | uid_t rgid; /* real gid */ |
335 | uid_t rgid = getgid(); | 343 | |
344 | if (ruid == 0) /* set by parse_config_file() */ | ||
345 | return; /* run by root - no need to check more */ | ||
346 | rgid = getgid(); | ||
336 | 347 | ||
337 | #if ENABLE_FEATURE_SUID_CONFIG | 348 | #if ENABLE_FEATURE_SUID_CONFIG |
338 | if (suid_cfg_readable) { | 349 | if (suid_cfg_readable) { |
@@ -387,7 +398,7 @@ static void check_suid(const struct bb_applet *applet) | |||
387 | if (geteuid()) | 398 | if (geteuid()) |
388 | bb_error_msg_and_die("applet requires root privileges!"); | 399 | bb_error_msg_and_die("applet requires root privileges!"); |
389 | } else if (applet->need_suid == _BB_SUID_NEVER) { | 400 | } else if (applet->need_suid == _BB_SUID_NEVER) { |
390 | xsetgid(rgid); /* drop all privileges */ | 401 | xsetgid(rgid); /* drop all privileges */ |
391 | xsetuid(ruid); | 402 | xsetuid(ruid); |
392 | } | 403 | } |
393 | } | 404 | } |
@@ -636,8 +647,7 @@ int main(int argc, char **argv) | |||
636 | if (s) | 647 | if (s) |
637 | applet_name = s + 1; | 648 | applet_name = s + 1; |
638 | 649 | ||
639 | if (ENABLE_FEATURE_SUID_CONFIG) | 650 | parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ |
640 | parse_config_file(); | ||
641 | 651 | ||
642 | /* Set locale for everybody except 'init' */ | 652 | /* Set locale for everybody except 'init' */ |
643 | if (ENABLE_LOCALE_SUPPORT && getpid() != 1) | 653 | if (ENABLE_LOCALE_SUPPORT && getpid() != 1) |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 59baf23a8..4fc5e7a61 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -85,11 +85,6 @@ static char *user_buf = (char*)""; | |||
85 | static char *home_pwd_buf = (char*)""; | 85 | static char *home_pwd_buf = (char*)""; |
86 | #endif | 86 | #endif |
87 | 87 | ||
88 | #if ENABLE_FEATURE_TAB_COMPLETION | ||
89 | static int my_uid; | ||
90 | static int my_gid; | ||
91 | #endif | ||
92 | |||
93 | /* Put 'command_ps[cursor]', cursor++. | 88 | /* Put 'command_ps[cursor]', cursor++. |
94 | * Advance cursor on screen. If we reached right margin, scroll text up | 89 | * Advance cursor on screen. If we reached right margin, scroll text up |
95 | * and remove terminal margin effect by printing 'next_char' */ | 90 | * and remove terminal margin effect by printing 'next_char' */ |
@@ -1312,10 +1307,6 @@ int read_line_input(const char* prompt, char* command, int maxsize, line_input_t | |||
1312 | } | 1307 | } |
1313 | } | 1308 | } |
1314 | #endif | 1309 | #endif |
1315 | #if ENABLE_FEATURE_TAB_COMPLETION | ||
1316 | my_uid = getuid(); | ||
1317 | my_gid = getgid(); | ||
1318 | #endif | ||
1319 | /* Print out the command prompt */ | 1310 | /* Print out the command prompt */ |
1320 | parse_prompt(prompt); | 1311 | parse_prompt(prompt); |
1321 | 1312 | ||
diff --git a/shell/msh.c b/shell/msh.c index 861abe234..ae18061d6 100644 --- a/shell/msh.c +++ b/shell/msh.c | |||
@@ -152,16 +152,15 @@ int mshdbg_rc = 0; | |||
152 | /* | 152 | /* |
153 | * values returned by wait | 153 | * values returned by wait |
154 | */ | 154 | */ |
155 | #define WAITSIG(s) ((s)&0177) | 155 | #define WAITSIG(s) ((s) & 0177) |
156 | #define WAITVAL(s) (((s)>>8)&0377) | 156 | #define WAITVAL(s) (((s) >> 8) & 0377) |
157 | #define WAITCORE(s) (((s)&0200)!=0) | 157 | #define WAITCORE(s) (((s) & 0200) != 0) |
158 | 158 | ||
159 | /* | 159 | /* |
160 | * library and system definitions | 160 | * library and system definitions |
161 | */ | 161 | */ |
162 | typedef void xint; /* base type of jmp_buf, for not broken compilers */ | 162 | typedef void xint; /* base type of jmp_buf, for not broken compilers */ |
163 | 163 | ||
164 | |||
165 | /* | 164 | /* |
166 | * shell components | 165 | * shell components |
167 | */ | 166 | */ |
@@ -170,7 +169,6 @@ typedef void xint; /* base type of jmp_buf, for not broken compilers */ | |||
170 | #define NOWORDS ((char **)NULL) | 169 | #define NOWORDS ((char **)NULL) |
171 | #define NOPIPE ((int *)NULL) | 170 | #define NOPIPE ((int *)NULL) |
172 | 171 | ||
173 | |||
174 | /* | 172 | /* |
175 | * redirection | 173 | * redirection |
176 | */ | 174 | */ |
@@ -250,21 +248,20 @@ static const char *const T_CMD_NAMES[] = { | |||
250 | /* | 248 | /* |
251 | * actions determining the environment of a process | 249 | * actions determining the environment of a process |
252 | */ | 250 | */ |
253 | #define BIT(i) (1<<(i)) | 251 | #define FEXEC 1 /* execute without forking */ |
254 | #define FEXEC BIT(0) /* execute without forking */ | ||
255 | 252 | ||
256 | #define AREASIZE (90000) | 253 | #define AREASIZE (90000) |
257 | 254 | ||
258 | /* | 255 | /* |
259 | * flags to control evaluation of words | 256 | * flags to control evaluation of words |
260 | */ | 257 | */ |
261 | #define DOSUB 1 /* interpret $, `, and quotes */ | 258 | #define DOSUB 1 /* interpret $, `, and quotes */ |
262 | #define DOBLANK 2 /* perform blank interpretation */ | 259 | #define DOBLANK 2 /* perform blank interpretation */ |
263 | #define DOGLOB 4 /* interpret [?* */ | 260 | #define DOGLOB 4 /* interpret [?* */ |
264 | #define DOKEY 8 /* move words with `=' to 2nd arg. list */ | 261 | #define DOKEY 8 /* move words with `=' to 2nd arg. list */ |
265 | #define DOTRIM 16 /* trim resulting string */ | 262 | #define DOTRIM 16 /* trim resulting string */ |
266 | 263 | ||
267 | #define DOALL (DOSUB|DOBLANK|DOGLOB|DOKEY|DOTRIM) | 264 | #define DOALL (DOSUB|DOBLANK|DOGLOB|DOKEY|DOTRIM) |
268 | 265 | ||
269 | 266 | ||
270 | /* PROTOTYPES */ | 267 | /* PROTOTYPES */ |
@@ -333,13 +330,13 @@ static void runtrap(int i); | |||
333 | 330 | ||
334 | /* -------- area stuff -------- */ | 331 | /* -------- area stuff -------- */ |
335 | 332 | ||
336 | #define REGSIZE sizeof(struct region) | 333 | #define REGSIZE sizeof(struct region) |
337 | #define GROWBY (256) | 334 | #define GROWBY (256) |
338 | /* #define SHRINKBY (64) */ | 335 | /* #define SHRINKBY (64) */ |
339 | #undef SHRINKBY | 336 | #undef SHRINKBY |
340 | #define FREE (32767) | 337 | #define FREE (32767) |
341 | #define BUSY (0) | 338 | #define BUSY (0) |
342 | #define ALIGN (sizeof(int)-1) | 339 | #define ALIGN (sizeof(int)-1) |
343 | 340 | ||
344 | 341 | ||
345 | struct region { | 342 | struct region { |
@@ -1313,7 +1310,7 @@ static int newfile(char *s) | |||
1313 | f = 0; | 1310 | f = 0; |
1314 | if (NOT_LONE_DASH(s)) { | 1311 | if (NOT_LONE_DASH(s)) { |
1315 | DBGPRINTF(("NEWFILE: s is %s\n", s)); | 1312 | DBGPRINTF(("NEWFILE: s is %s\n", s)); |
1316 | f = open(s, 0); | 1313 | f = open(s, O_RDONLY); |
1317 | if (f < 0) { | 1314 | if (f < 0) { |
1318 | prs(s); | 1315 | prs(s); |
1319 | err(": cannot open"); | 1316 | err(": cannot open"); |
@@ -2554,7 +2551,7 @@ static int execute(struct op *t, int *pin, int *pout, int act) | |||
2554 | interactive = 0; | 2551 | interactive = 0; |
2555 | if (pin == NULL) { | 2552 | if (pin == NULL) { |
2556 | close(0); | 2553 | close(0); |
2557 | open(bb_dev_null, 0); | 2554 | open(bb_dev_null, O_RDONLY); |
2558 | } | 2555 | } |
2559 | _exit(execute(t->left, pin, pout, FEXEC)); | 2556 | _exit(execute(t->left, pin, pout, FEXEC)); |
2560 | } | 2557 | } |
@@ -2734,7 +2731,8 @@ static int forkexec(struct op *t, int *pin, int *pout, int act, char **wp) | |||
2734 | resetsig = 0; | 2731 | resetsig = 0; |
2735 | rv = -1; /* system-detected error */ | 2732 | rv = -1; /* system-detected error */ |
2736 | if (t->type == TCOM) { | 2733 | if (t->type == TCOM) { |
2737 | while (*wp++ != NULL); | 2734 | while (*wp++ != NULL) |
2735 | continue; | ||
2738 | cp = *wp; | 2736 | cp = *wp; |
2739 | 2737 | ||
2740 | /* strip all initial assignments */ | 2738 | /* strip all initial assignments */ |
@@ -2747,7 +2745,7 @@ static int forkexec(struct op *t, int *pin, int *pout, int act, char **wp) | |||
2747 | 2745 | ||
2748 | if (cp == NULL && t->ioact == NULL) { | 2746 | if (cp == NULL && t->ioact == NULL) { |
2749 | while ((cp = *owp++) != NULL && assign(cp, COPYV)) | 2747 | while ((cp = *owp++) != NULL && assign(cp, COPYV)) |
2750 | /**/; | 2748 | continue; |
2751 | DBGPRINTF(("FORKEXEC: returning setstatus()\n")); | 2749 | DBGPRINTF(("FORKEXEC: returning setstatus()\n")); |
2752 | return setstatus(0); | 2750 | return setstatus(0); |
2753 | } | 2751 | } |
@@ -2932,7 +2930,7 @@ static int iosetup(struct ioword *iop, int pipein, int pipeout) | |||
2932 | } | 2930 | } |
2933 | switch (iop->io_flag) { | 2931 | switch (iop->io_flag) { |
2934 | case IOREAD: | 2932 | case IOREAD: |
2935 | u = open(cp, 0); | 2933 | u = open(cp, O_RDONLY); |
2936 | break; | 2934 | break; |
2937 | 2935 | ||
2938 | case IOHERE: | 2936 | case IOHERE: |
@@ -2942,7 +2940,7 @@ static int iosetup(struct ioword *iop, int pipein, int pipeout) | |||
2942 | break; | 2940 | break; |
2943 | 2941 | ||
2944 | case IOWRITE | IOCAT: | 2942 | case IOWRITE | IOCAT: |
2945 | u = open(cp, 1); | 2943 | u = open(cp, O_WRONLY); |
2946 | if (u >= 0) { | 2944 | if (u >= 0) { |
2947 | lseek(u, (long) 0, SEEK_END); | 2945 | lseek(u, (long) 0, SEEK_END); |
2948 | break; | 2946 | break; |
@@ -3346,7 +3344,7 @@ static int dodot(struct op *t) | |||
3346 | for (i = 0; (*tp++ = cp[i++]) != '\0';); | 3344 | for (i = 0; (*tp++ = cp[i++]) != '\0';); |
3347 | 3345 | ||
3348 | /* Original code */ | 3346 | /* Original code */ |
3349 | i = open(e.linep, 0); | 3347 | i = open(e.linep, O_RDONLY); |
3350 | if (i >= 0) { | 3348 | if (i >= 0) { |
3351 | exstat = 0; | 3349 | exstat = 0; |
3352 | maltmp = remap(i); | 3350 | maltmp = remap(i); |
@@ -5098,7 +5096,7 @@ static int herein(char *hname, int xdoll) | |||
5098 | 5096 | ||
5099 | DBGPRINTF7(("HEREIN: hname is %s, xdoll=%d\n", hname, xdoll)); | 5097 | DBGPRINTF7(("HEREIN: hname is %s, xdoll=%d\n", hname, xdoll)); |
5100 | 5098 | ||
5101 | hf = open(hname, 0); | 5099 | hf = open(hname, O_RDONLY); |
5102 | if (hf < 0) | 5100 | if (hf < 0) |
5103 | return -1; | 5101 | return -1; |
5104 | 5102 | ||
@@ -5122,7 +5120,7 @@ static int herein(char *hname, int xdoll) | |||
5122 | } else | 5120 | } else |
5123 | unlink(tname); | 5121 | unlink(tname); |
5124 | close(tf); | 5122 | close(tf); |
5125 | tf = open(tname, 0); | 5123 | tf = open(tname, O_RDONLY); |
5126 | unlink(tname); | 5124 | unlink(tname); |
5127 | return tf; | 5125 | return tf; |
5128 | } | 5126 | } |
@@ -5214,10 +5212,11 @@ int msh_main(int argc, char **argv) | |||
5214 | 5212 | ||
5215 | path = lookup("PATH"); | 5213 | path = lookup("PATH"); |
5216 | if (path->value == null) { | 5214 | if (path->value == null) { |
5215 | /* Can be merged with same string elsewhere in bbox */ | ||
5217 | if (geteuid() == 0) | 5216 | if (geteuid() == 0) |
5218 | setval(path, "/sbin:/bin:/usr/sbin:/usr/bin"); | 5217 | setval(path, "/sbin:/usr/sbin:/bin:/usr/bin"); |
5219 | else | 5218 | else |
5220 | setval(path, "/bin:/usr/bin"); | 5219 | setval(path, "/sbin:/usr/sbin:/bin:/usr/bin" + sizeof("/sbin:/usr/sbin")); |
5221 | } | 5220 | } |
5222 | export(path); | 5221 | export(path); |
5223 | 5222 | ||
@@ -5329,10 +5328,10 @@ int msh_main(int argc, char **argv) | |||
5329 | signal(SIGQUIT, qflag); | 5328 | signal(SIGQUIT, qflag); |
5330 | if (name && name[0] == '-') { | 5329 | if (name && name[0] == '-') { |
5331 | interactive++; | 5330 | interactive++; |
5332 | f = open(".profile", 0); | 5331 | f = open(".profile", O_RDONLY); |
5333 | if (f >= 0) | 5332 | if (f >= 0) |
5334 | next(remap(f)); | 5333 | next(remap(f)); |
5335 | f = open("/etc/profile", 0); | 5334 | f = open("/etc/profile", O_RDONLY); |
5336 | if (f >= 0) | 5335 | if (f >= 0) |
5337 | next(remap(f)); | 5336 | next(remap(f)); |
5338 | } | 5337 | } |