Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/init/mesg.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/init/mesg.c
r2725 r3232 8 8 */ 9 9 10 //applet:IF_MESG(APPLET(mesg, _BB_DIR_USR_BIN, _BB_SUID_DROP))11 12 //kbuild:lib-$(CONFIG_MESG) += mesg.o13 14 10 //config:config MESG 15 11 //config: bool "mesg" … … 18 14 //config: Mesg controls access to your terminal by others. It is typically 19 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 33 //usage:#define mesg_trivial_usage … … 28 40 #include "libbb.h" 29 41 30 #if def USE_TTY_GROUP42 #if ENABLE_FEATURE_MESG_ENABLE_ONLY_GROUP 31 43 #define S_IWGRP_OR_S_IWOTH S_IWGRP 32 44 #else … … 38 50 { 39 51 struct stat sb; 40 const char *tty;52 mode_t m; 41 53 char c = 0; 42 54 43 55 argv++; 44 56 45 if ( !argv[0]46 || (!argv[1] && ((c = argv[0][0]) == 'y' || c == 'n'))57 if (argv[0] 58 && (argv[1] || ((c = argv[0][0]) != 'y' && c != 'n')) 47 59 ) { 48 tty = xmalloc_ttyname(STDERR_FILENO); 49 if (tty == NULL) { 50 tty = "ttyname"; 51 } else if (stat(tty, &sb) == 0) { 52 mode_t m; 53 if (c == 0) { 54 puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n"); 55 return EXIT_SUCCESS; 56 } 57 m = (c == 'y') ? sb.st_mode | S_IWGRP_OR_S_IWOTH 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); 60 bb_show_usage(); 64 61 } 65 bb_show_usage(); 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; 66 76 }
Note:
See TracChangeset
for help on using the changeset viewer.