aboutsummaryrefslogtreecommitdiff
path: root/util-linux/mesg.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2017-05-29 14:20:10 +0100
committerRon Yorston <rmy@pobox.com>2017-05-29 14:34:28 +0100
commitda4f331955bed8afda670afcd58d524a04a0faa9 (patch)
treef6a3879aefdd714240f8c022375f687b512d2238 /util-linux/mesg.c
parent74163a535fd21f5fcca4c052d2e7c192d3e264fa (diff)
parent6683d1cbb44859f549f87f882545b84b9369585c (diff)
downloadbusybox-w32-da4f331955bed8afda670afcd58d524a04a0faa9.tar.gz
busybox-w32-da4f331955bed8afda670afcd58d524a04a0faa9.tar.bz2
busybox-w32-da4f331955bed8afda670afcd58d524a04a0faa9.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'util-linux/mesg.c')
-rw-r--r--util-linux/mesg.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/util-linux/mesg.c b/util-linux/mesg.c
new file mode 100644
index 000000000..45c13b8e0
--- /dev/null
+++ b/util-linux/mesg.c
@@ -0,0 +1,76 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * mesg implementation for busybox
4 *
5 * Copyright (c) 2002 Manuel Novoa III <mjn3@codepoet.org>
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */
9
10//config:config MESG
11//config: bool "mesg"
12//config: default y
13//config: help
14//config: Mesg controls access to your terminal by others. It is typically
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
32
33//usage:#define mesg_trivial_usage
34//usage: "[y|n]"
35//usage:#define mesg_full_usage "\n\n"
36//usage: "Control write access to your terminal\n"
37//usage: " y Allow write access to your terminal\n"
38//usage: " n Disallow write access to your terminal"
39
40#include "libbb.h"
41
42#if ENABLE_FEATURE_MESG_ENABLE_ONLY_GROUP
43#define S_IWGRP_OR_S_IWOTH S_IWGRP
44#else
45#define S_IWGRP_OR_S_IWOTH (S_IWGRP | S_IWOTH)
46#endif
47
48int mesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
49int mesg_main(int argc UNUSED_PARAM, char **argv)
50{
51 struct stat sb;
52 mode_t m;
53 char c = 0;
54
55 argv++;
56
57 if (argv[0]
58 && (argv[1] || ((c = argv[0][0]) != 'y' && c != 'n'))
59 ) {
60 bb_show_usage();
61 }
62
63 if (!isatty(STDIN_FILENO))
64 bb_error_msg_and_die("not a tty");
65
66 xfstat(STDIN_FILENO, &sb, "stderr");
67 if (c == 0) {
68 puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n");
69 return EXIT_SUCCESS;
70 }
71 m = (c == 'y') ? sb.st_mode | S_IWGRP_OR_S_IWOTH
72 : sb.st_mode & ~(S_IWGRP|S_IWOTH);
73 if (fchmod(STDIN_FILENO, m) != 0)
74 bb_perror_nomsg_and_die();
75 return EXIT_SUCCESS;
76}