Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (5 years ago)
Author:
bruno
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/init/mesg.c

    r2725 r3232  
    88 */
    99
    10 //applet:IF_MESG(APPLET(mesg, _BB_DIR_USR_BIN, _BB_SUID_DROP))
    11 
    12 //kbuild:lib-$(CONFIG_MESG) += mesg.o
    13 
    1410//config:config MESG
    1511//config:   bool "mesg"
     
    1814//config:     Mesg controls access to your terminal by others. It is typically
    1915//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
    2032
    2133//usage:#define mesg_trivial_usage
     
    2840#include "libbb.h"
    2941
    30 #ifdef USE_TTY_GROUP
     42#if ENABLE_FEATURE_MESG_ENABLE_ONLY_GROUP
    3143#define S_IWGRP_OR_S_IWOTH  S_IWGRP
    3244#else
     
    3850{
    3951    struct stat sb;
    40     const char *tty;
     52    mode_t m;
    4153    char c = 0;
    4254
    4355    argv++;
    4456
    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'))
    4759    ) {
    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();
    6461    }
    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;
    6676}
Note: See TracChangeset for help on using the changeset viewer.