Annotation of researchv8dc/cmd/upas/send/notify.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     notify user on mail arrival
        !             3:  */
        !             4: #include <stdio.h>
        !             5: #include <sys/types.h>
        !             6: #include <sys/stat.h>
        !             7: #include <utmp.h>
        !             8: #include "string.h"
        !             9: 
        !            10: /* imports */
        !            11: extern char *thissys;
        !            12: extern unsigned int alarm();
        !            13: 
        !            14: extern void
        !            15: setnotify()
        !            16: {
        !            17:        struct stat s;
        !            18:        char *ttyname();
        !            19:        char *p;
        !            20: 
        !            21:        fstat(2, &s);
        !            22:        setgid(getgid());
        !            23:        setuid(getuid());
        !            24:        if ((p = ttyname(2)) && *p)
        !            25:                chmod(p, s.st_mode ^ S_IEXEC);
        !            26: }
        !            27: 
        !            28: 
        !            29: static int
        !            30: blurbtime()
        !            31: {
        !            32: }
        !            33: 
        !            34: static void
        !            35: blurb(tty, sender, maxsize)
        !            36: char *tty, *sender;
        !            37: {
        !            38:        FILE *f = NULL;
        !            39:        struct stat s;
        !            40:        char devtty[32];
        !            41: 
        !            42:        strcpy(devtty, "/dev/");
        !            43:        strncat(devtty, tty, maxsize);
        !            44:        signal(SIGALRM, blurbtime);
        !            45:        alarm(30);
        !            46:        stat(devtty, &s);
        !            47:        if (s.st_mode & S_IEXEC)        /* notify only if enabled */
        !            48:        if ((f = fopen(devtty, "w")) != NULL) {
        !            49:                fprintf(f, "\r\n[%s: mail from %s]\r\n\7", thissys,
        !            50:                  sender);
        !            51:        }
        !            52:        if (f)
        !            53:                fclose(f);
        !            54:        alarm(0);
        !            55: }
        !            56: 
        !            57: extern int
        !            58: notify(name, sender)
        !            59: char *name, *sender;
        !            60: {
        !            61:        struct utmp entry;
        !            62:        FILE *f;
        !            63: 
        !            64:        if ((f = fopen("/etc/utmp", "r")) == NULL)
        !            65:                return;
        !            66:        while (fread((char *)&entry, sizeof(entry), 1, f) == 1) {
        !            67:                if (strncmp(name, entry.ut_name, sizeof(entry.ut_name)) == 0)
        !            68:                        blurb(entry.ut_line, sender, sizeof(entry.ut_line));
        !            69:        }
        !            70:        fclose(f);
        !            71: }

unix.superglobalmegacorp.com

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