Annotation of coherent/d/bin/mesg.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Permit or deny messages (e.g. write, msg, etc.)
        !             3:  * to be sent to the user's terminal.
        !             4:  * As these commands are setuid, execute permission
        !             5:  * may be used to control use of the terminal without
        !             6:  * allowing indiscriminate use by other users of the
        !             7:  * terminal.
        !             8:  *
        !             9:  * NOTE: the terminal is assumed to be stderr.
        !            10:  */
        !            11: 
        !            12: #include <stdio.h>
        !            13: #include <sys/stat.h>
        !            14: 
        !            15: main(argc, argv)
        !            16: char *argv[];
        !            17: {
        !            18:        struct stat sb;
        !            19:        char type = 'c';
        !            20:        char *tty;
        !            21:        char *ttyname();
        !            22: 
        !            23:        if (argc == 2) {
        !            24:                if (argv[1][1]=='\0' && (*argv[1]=='y' || *argv[1]=='n'))
        !            25:                        type = *argv[1];
        !            26:                else if (strcmp(argv[1], "no")==0 || strcmp(argv[1], "yes")==0)
        !            27:                        type = *argv[1];
        !            28:                else
        !            29:                        usage();
        !            30:        } else if (argc != 1)
        !            31:                usage();
        !            32:        tty = ttyname(fileno(stderr));
        !            33:        if (tty==NULL || stat(tty, &sb)<0) {
        !            34:                fprintf(stderr, "Standard error not a tty\n");
        !            35:                exit(2);
        !            36:        }
        !            37:        if (argc > 1) {
        !            38:                if (type == 'n')
        !            39:                        sb.st_mode &= ~S_IEXEC;
        !            40:                else if (type == 'y')
        !            41:                        sb.st_mode |= S_IEXEC;
        !            42:                chmod(tty, sb.st_mode);
        !            43:        } else
        !            44:                printf("%s\n", sb.st_mode&S_IEXEC ? "yes" : "no");
        !            45:        exit (sb.st_mode&S_IEXEC ? 0 : 1);
        !            46: }
        !            47: 
        !            48: usage()
        !            49: {
        !            50:        fprintf(stderr, "Usage: mesg [n] [y]\n");
        !            51:        exit(2);
        !            52: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.