aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2014-01-02 10:25:11 +0000
committerRon Yorston <rmy@pobox.com>2014-01-02 10:25:11 +0000
commitb8f278ee745778806118f57fb7884d205eba05ad (patch)
treefef237f6dd302c59918cf389a60c120e58d3e086 /miscutils
parent3fd34651ea72ea1c335d3170f234cb0517fd897f (diff)
parent57434022cefde87133b8ad39fb3b79c1274e7684 (diff)
downloadbusybox-w32-b8f278ee745778806118f57fb7884d205eba05ad.tar.gz
busybox-w32-b8f278ee745778806118f57fb7884d205eba05ad.tar.bz2
busybox-w32-b8f278ee745778806118f57fb7884d205eba05ad.zip
Merge branch 'busybox' into merge
Conflicts: archival/Config.src shell/ash.c
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/Config.src19
-rw-r--r--miscutils/Kbuild.src2
-rw-r--r--miscutils/chat.c2
-rw-r--r--miscutils/crontab.c27
-rw-r--r--miscutils/devfsd.c20
-rw-r--r--miscutils/hdparm.c8
-rw-r--r--miscutils/rfkill.c17
-rw-r--r--miscutils/wall.c21
8 files changed, 54 insertions, 62 deletions
diff --git a/miscutils/Config.src b/miscutils/Config.src
index b9fc196d8..1da9800bd 100644
--- a/miscutils/Config.src
+++ b/miscutils/Config.src
@@ -503,18 +503,6 @@ config READAHEAD
503 As readahead(2) blocks until each file has been read, it is best to 503 As readahead(2) blocks until each file has been read, it is best to
504 run this applet as a background job. 504 run this applet as a background job.
505 505
506config RFKILL
507 bool "rfkill"
508 default n # doesn't build on Ubuntu 9.04
509 select PLATFORM_LINUX
510 help
511 Enable/disable wireless devices.
512
513 rfkill list : list all wireless devices
514 rfkill list bluetooth : list all bluetooth devices
515 rfkill list 1 : list device corresponding to the given index
516 rfkill block|unblock wlan : block/unblock all wlan(wifi) devices
517
518config RUNLEVEL 506config RUNLEVEL
519 bool "runlevel" 507 bool "runlevel"
520 default y 508 default y
@@ -591,13 +579,6 @@ config VOLNAME
591 help 579 help
592 Prints a CD-ROM volume name. 580 Prints a CD-ROM volume name.
593 581
594config WALL
595 bool "wall"
596 default y
597 depends on FEATURE_UTMP
598 help
599 Write a message to all users that are logged in.
600
601config WATCHDOG 582config WATCHDOG
602 bool "watchdog" 583 bool "watchdog"
603 default y 584 default y
diff --git a/miscutils/Kbuild.src b/miscutils/Kbuild.src
index 8c498643b..9e164f16e 100644
--- a/miscutils/Kbuild.src
+++ b/miscutils/Kbuild.src
@@ -36,7 +36,6 @@ lib-$(CONFIG_MOUNTPOINT) += mountpoint.o
36lib-$(CONFIG_MT) += mt.o 36lib-$(CONFIG_MT) += mt.o
37lib-$(CONFIG_RAIDAUTORUN) += raidautorun.o 37lib-$(CONFIG_RAIDAUTORUN) += raidautorun.o
38lib-$(CONFIG_READAHEAD) += readahead.o 38lib-$(CONFIG_READAHEAD) += readahead.o
39lib-$(CONFIG_RFKILL) += rfkill.o
40lib-$(CONFIG_RUNLEVEL) += runlevel.o 39lib-$(CONFIG_RUNLEVEL) += runlevel.o
41lib-$(CONFIG_RX) += rx.o 40lib-$(CONFIG_RX) += rx.o
42lib-$(CONFIG_SETSID) += setsid.o 41lib-$(CONFIG_SETSID) += setsid.o
@@ -46,5 +45,4 @@ lib-$(CONFIG_TIME) += time.o
46lib-$(CONFIG_TIMEOUT) += timeout.o 45lib-$(CONFIG_TIMEOUT) += timeout.o
47lib-$(CONFIG_TTYSIZE) += ttysize.o 46lib-$(CONFIG_TTYSIZE) += ttysize.o
48lib-$(CONFIG_VOLNAME) += volname.o 47lib-$(CONFIG_VOLNAME) += volname.o
49lib-$(CONFIG_WALL) += wall.o
50lib-$(CONFIG_WATCHDOG) += watchdog.o 48lib-$(CONFIG_WATCHDOG) += watchdog.o
diff --git a/miscutils/chat.c b/miscutils/chat.c
index ce994f870..bd2abc24a 100644
--- a/miscutils/chat.c
+++ b/miscutils/chat.c
@@ -296,7 +296,7 @@ int chat_main(int argc UNUSED_PARAM, char **argv)
296 full_write(record_fd, buf+buf_len, 1); 296 full_write(record_fd, buf+buf_len, 1);
297 } 297 }
298 // dump device input if ECHO ON 298 // dump device input if ECHO ON
299 if (echo > 0) { 299 if (echo) {
300// if (buf[buf_len] < ' ') { 300// if (buf[buf_len] < ' ') {
301// full_write(STDERR_FILENO, "^", 1); 301// full_write(STDERR_FILENO, "^", 1);
302// buf[buf_len] += '@'; 302// buf[buf_len] += '@';
diff --git a/miscutils/crontab.c b/miscutils/crontab.c
index 4731d8da6..aad242fd8 100644
--- a/miscutils/crontab.c
+++ b/miscutils/crontab.c
@@ -55,28 +55,6 @@ static void edit_file(const struct passwd *pas, const char *file)
55 bb_perror_msg_and_die("can't execute '%s'", ptr); 55 bb_perror_msg_and_die("can't execute '%s'", ptr);
56} 56}
57 57
58static int open_as_user(const struct passwd *pas, const char *file)
59{
60 pid_t pid;
61 char c;
62
63 pid = xvfork();
64 if (pid) { /* PARENT */
65 if (wait4pid(pid) == 0) {
66 /* exitcode 0: child says it can read */
67 return open(file, O_RDONLY);
68 }
69 return -1;
70 }
71
72 /* CHILD */
73 /* initgroups, setgid, setuid */
74 change_identity(pas);
75 /* We just try to read one byte. If it works, file is readable
76 * under this user. We signal that by exiting with 0. */
77 _exit(safe_read(xopen(file, O_RDONLY), &c, 1) < 0);
78}
79
80int crontab_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 58int crontab_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
81int crontab_main(int argc UNUSED_PARAM, char **argv) 59int crontab_main(int argc UNUSED_PARAM, char **argv)
82{ 60{
@@ -137,10 +115,7 @@ int crontab_main(int argc UNUSED_PARAM, char **argv)
137 if (!argv[0]) 115 if (!argv[0])
138 bb_show_usage(); 116 bb_show_usage();
139 if (NOT_LONE_DASH(argv[0])) { 117 if (NOT_LONE_DASH(argv[0])) {
140 src_fd = open_as_user(pas, argv[0]); 118 src_fd = xopen_as_uid_gid(argv[0], O_RDONLY, pas->pw_uid, pas->pw_gid);
141 if (src_fd < 0)
142 bb_error_msg_and_die("user %s cannot read %s",
143 pas->pw_name, argv[0]);
144 } 119 }
145 } 120 }
146 121
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c
index 24c953bac..96ffe0738 100644
--- a/miscutils/devfsd.c
+++ b/miscutils/devfsd.c
@@ -1083,21 +1083,23 @@ static int get_uid_gid(int flag, const char *string)
1083{ 1083{
1084 struct passwd *pw_ent; 1084 struct passwd *pw_ent;
1085 struct group *grp_ent; 1085 struct group *grp_ent;
1086 static const char *msg; 1086 const char *msg;
1087 1087
1088 if (ENABLE_DEVFSD_VERBOSE) 1088 if (isdigit(string[0]) || ((string[0] == '-') && isdigit(string[1])))
1089 msg = "user";
1090
1091 if (isdigit(string[0]) ||((string[0] == '-') && isdigit(string[1])))
1092 return atoi(string); 1089 return atoi(string);
1093 1090
1094 if (flag == UID && (pw_ent = getpwnam(string)) != NULL) 1091 if (flag == UID && (pw_ent = getpwnam(string)) != NULL)
1095 return pw_ent->pw_uid; 1092 return pw_ent->pw_uid;
1096 1093
1097 if (flag == GID && (grp_ent = getgrnam(string)) != NULL) 1094 if (ENABLE_DEVFSD_VERBOSE)
1098 return grp_ent->gr_gid; 1095 msg = "user";
1099 else if (ENABLE_DEVFSD_VERBOSE) 1096
1100 msg = "group"; 1097 if (flag == GID) {
1098 if ((grp_ent = getgrnam(string)) != NULL)
1099 return grp_ent->gr_gid;
1100 if (ENABLE_DEVFSD_VERBOSE)
1101 msg = "group";
1102 }
1101 1103
1102 if (ENABLE_DEVFSD_VERBOSE) 1104 if (ENABLE_DEVFSD_VERBOSE)
1103 msg_logger(LOG_ERR, "unknown %s: %s, defaulting to %cid=0", msg, string, msg[0]); 1105 msg_logger(LOG_ERR, "unknown %s: %s, defaulting to %cid=0", msg, string, msg[0]);
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c
index 69726ae72..f0e9c9d75 100644
--- a/miscutils/hdparm.c
+++ b/miscutils/hdparm.c
@@ -465,14 +465,14 @@ static void on_off(int value)
465static void print_flag_on_off(int get_arg, const char *s, unsigned long arg) 465static void print_flag_on_off(int get_arg, const char *s, unsigned long arg)
466{ 466{
467 if (get_arg) { 467 if (get_arg) {
468 printf(" setting %s to %ld", s, arg); 468 printf(" setting %s to %lu", s, arg);
469 on_off(arg); 469 on_off(arg);
470 } 470 }
471} 471}
472 472
473static void print_value_on_off(const char *str, unsigned long argp) 473static void print_value_on_off(const char *str, unsigned long argp)
474{ 474{
475 printf(" %s\t= %2ld", str, argp); 475 printf(" %s\t= %2lu", str, argp);
476 on_off(argp != 0); 476 on_off(argp != 0);
477} 477}
478 478
@@ -1509,7 +1509,7 @@ static void bus_state_value(unsigned value)
1509 else if (value == BUSSTATE_TRISTATE) 1509 else if (value == BUSSTATE_TRISTATE)
1510 printf(" (tristate)\n"); 1510 printf(" (tristate)\n");
1511 else 1511 else
1512 printf(" (unknown: %d)\n", value); 1512 printf(" (unknown: %u)\n", value);
1513} 1513}
1514#endif 1514#endif
1515 1515
@@ -1589,7 +1589,7 @@ static void interpret_xfermode(unsigned xfermode)
1589static void print_flag(int flag, const char *s, unsigned long value) 1589static void print_flag(int flag, const char *s, unsigned long value)
1590{ 1590{
1591 if (flag) 1591 if (flag)
1592 printf(" setting %s to %ld\n", s, value); 1592 printf(" setting %s to %lu\n", s, value);
1593} 1593}
1594 1594
1595static void process_dev(char *devname) 1595static void process_dev(char *devname)
diff --git a/miscutils/rfkill.c b/miscutils/rfkill.c
index 467197371..7411b6fc3 100644
--- a/miscutils/rfkill.c
+++ b/miscutils/rfkill.c
@@ -7,6 +7,23 @@
7* Licensed under GPLv2 or later, see file LICENSE in this source tree. 7* Licensed under GPLv2 or later, see file LICENSE in this source tree.
8*/ 8*/
9 9
10//config:config RFKILL
11//config: bool "rfkill"
12//config: default n # doesn't build on Ubuntu 9.04
13//config: select PLATFORM_LINUX
14//config: help
15//config: Enable/disable wireless devices.
16//config:
17//config: rfkill list : list all wireless devices
18//config: rfkill list bluetooth : list all bluetooth devices
19//config: rfkill list 1 : list device corresponding to the given index
20//config: rfkill block|unblock wlan : block/unblock all wlan(wifi) devices
21//config:
22
23//applet:IF_RFKILL(APPLET(rfkill, BB_DIR_USR_SBIN, BB_SUID_DROP))
24
25//kbuild:lib-$(CONFIG_RFKILL) += rfkill.o
26
10//usage:#define rfkill_trivial_usage 27//usage:#define rfkill_trivial_usage
11//usage: "COMMAND [INDEX|TYPE]" 28//usage: "COMMAND [INDEX|TYPE]"
12//usage:#define rfkill_full_usage "\n\n" 29//usage:#define rfkill_full_usage "\n\n"
diff --git a/miscutils/wall.c b/miscutils/wall.c
index 762f53b72..bb709ee39 100644
--- a/miscutils/wall.c
+++ b/miscutils/wall.c
@@ -6,6 +6,18 @@
6 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 6 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
7 */ 7 */
8 8
9//config:config WALL
10//config: bool "wall"
11//config: default y
12//config: depends on FEATURE_UTMP
13//config: help
14//config: Write a message to all users that are logged in.
15
16/* Needs to be run by root or be suid root - needs to write to /dev/TTY: */
17//applet:IF_WALL(APPLET(wall, BB_DIR_USR_BIN, BB_SUID_REQUIRE))
18
19//kbuild:lib-$(CONFIG_WALL) += wall.o
20
9//usage:#define wall_trivial_usage 21//usage:#define wall_trivial_usage
10//usage: "[FILE]" 22//usage: "[FILE]"
11//usage:#define wall_full_usage "\n\n" 23//usage:#define wall_full_usage "\n\n"
@@ -22,8 +34,15 @@ int wall_main(int argc UNUSED_PARAM, char **argv)
22{ 34{
23 struct utmp *ut; 35 struct utmp *ut;
24 char *msg; 36 char *msg;
25 int fd = argv[1] ? xopen(argv[1], O_RDONLY) : STDIN_FILENO; 37 int fd;
26 38
39 fd = STDIN_FILENO;
40 if (argv[1]) {
41 /* The applet is setuid.
42 * Access to the file must be under user's uid/gid.
43 */
44 fd = xopen_as_uid_gid(argv[1], O_RDONLY, getuid(), getgid());
45 }
27 msg = xmalloc_read(fd, NULL); 46 msg = xmalloc_read(fd, NULL);
28 if (ENABLE_FEATURE_CLEAN_UP && argv[1]) 47 if (ENABLE_FEATURE_CLEAN_UP && argv[1])
29 close(fd); 48 close(fd);