aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-03-22 06:54:36 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-03-22 06:54:36 +0100
commitbeea5a70c34bdcf2b02c37e6f56d2efcbd90fedb (patch)
tree45947cc3220ee84edcfd9e9dabf0a5cec7e81241
parentb0e8ced3589c601ad5c15e74d6f82b1928e1eb8f (diff)
downloadbusybox-w32-beea5a70c34bdcf2b02c37e6f56d2efcbd90fedb.tar.gz
busybox-w32-beea5a70c34bdcf2b02c37e6f56d2efcbd90fedb.tar.bz2
busybox-w32-beea5a70c34bdcf2b02c37e6f56d2efcbd90fedb.zip
mesg: make group/all writability configurable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--init/mesg.c60
1 files changed, 35 insertions, 25 deletions
diff --git a/init/mesg.c b/init/mesg.c
index 676ca2e24..8489e621c 100644
--- a/init/mesg.c
+++ b/init/mesg.c
@@ -7,16 +7,28 @@
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//applet:IF_MESG(APPLET(mesg, BB_DIR_USR_BIN, BB_SUID_DROP))
11
12//kbuild:lib-$(CONFIG_MESG) += mesg.o
13
14//config:config MESG 10//config:config MESG
15//config: bool "mesg" 11//config: bool "mesg"
16//config: default y 12//config: default y
17//config: help 13//config: help
18//config: Mesg controls access to your terminal by others. It is typically 14//config: Mesg controls access to your terminal by others. It is typically
19//config: used to allow or disallow other users to write to your terminal 15//config: used to allow or disallow other users to write to your terminal
16//config:
17//config:config FEATURE_MESG_ENABLE_ONLY_GROUP
18//config: bool "Enable writing to tty only by group, not by everybody"
19//config: default y
20//config: depends on MESG
21//config: help
22//config: Usually, ttys are owned by group "tty", and "write" tool is
23//config: setgid to this group. This way, "mesg y" only needs to enable
24//config: "write by owning group" bit in tty mode.
25//config:
26//config: If you set this option to N, "mesg y" will enable writing
27//config: by anybody at all. This is not recommended.
28
29//applet:IF_MESG(APPLET(mesg, BB_DIR_USR_BIN, BB_SUID_DROP))
30
31//kbuild:lib-$(CONFIG_MESG) += mesg.o
20 32
21//usage:#define mesg_trivial_usage 33//usage:#define mesg_trivial_usage
22//usage: "[y|n]" 34//usage: "[y|n]"
@@ -27,7 +39,7 @@
27 39
28#include "libbb.h" 40#include "libbb.h"
29 41
30#ifdef USE_TTY_GROUP 42#if ENABLE_FEATURE_MESG_ENABLE_ONLY_GROUP
31#define S_IWGRP_OR_S_IWOTH S_IWGRP 43#define S_IWGRP_OR_S_IWOTH S_IWGRP
32#else 44#else
33#define S_IWGRP_OR_S_IWOTH (S_IWGRP | S_IWOTH) 45#define S_IWGRP_OR_S_IWOTH (S_IWGRP | S_IWOTH)
@@ -37,30 +49,28 @@ int mesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
37int mesg_main(int argc UNUSED_PARAM, char **argv) 49int mesg_main(int argc UNUSED_PARAM, char **argv)
38{ 50{
39 struct stat sb; 51 struct stat sb;
40 const char *tty; 52 mode_t m;
41 char c = 0; 53 char c = 0;
42 54
43 argv++; 55 argv++;
44 56
45 if (!argv[0] 57 if (argv[0]
46 || (!argv[1] && ((c = argv[0][0]) == 'y' || c == 'n')) 58 && (argv[1] || ((c = argv[0][0]) != 'y' && c != 'n'))
47 ) { 59 ) {
48 tty = xmalloc_ttyname(STDERR_FILENO); 60 bb_show_usage();
49 if (tty == NULL) { 61 }
50 tty = "ttyname"; 62
51 } else if (stat(tty, &sb) == 0) { 63 if (!isatty(STDERR_FILENO))
52 mode_t m; 64 bb_error_msg_and_die("not a tty");
53 if (c == 0) { 65
54 puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n"); 66 xfstat(STDERR_FILENO, &sb, "stderr");
55 return EXIT_SUCCESS; 67 if (c == 0) {
56 } 68 puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n");
57 m = (c == 'y') ? sb.st_mode | S_IWGRP_OR_S_IWOTH 69 return EXIT_SUCCESS;
58 : sb.st_mode & ~(S_IWGRP|S_IWOTH);
59 if (chmod(tty, m) == 0) {
60 return EXIT_SUCCESS;
61 }
62 }
63 bb_simple_perror_msg_and_die(tty);
64 } 70 }
65 bb_show_usage(); 71 m = (c == 'y') ? sb.st_mode | S_IWGRP_OR_S_IWOTH
72 : sb.st_mode & ~(S_IWGRP|S_IWOTH);
73 if (fchmod(STDERR_FILENO, m) != 0)
74 bb_perror_nomsg_and_die();
75 return EXIT_SUCCESS;
66} 76}