Annotation of 43BSDReno/libexec/bugfiler/bugfiler.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1983, 1986, 1987 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that: (1) source distributions retain this entire copyright
        !             7:  * notice and comment, and (2) distributions including binaries display
        !             8:  * the following acknowledgement:  ``This product includes software
        !             9:  * developed by the University of California, Berkeley and its contributors''
        !            10:  * in the documentation or other materials provided with the distribution
        !            11:  * and in all advertising materials mentioning features or use of this
        !            12:  * software. Neither the name of the University nor the names of its
        !            13:  * contributors may be used to endorse or promote products derived
        !            14:  * from this software without specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #ifndef lint
        !            21: char copyright[] =
        !            22: "@(#) Copyright (c) 1983, 1986, 1987 Regents of the University of California.\n\
        !            23:  All rights reserved.\n";
        !            24: #endif /* not lint */
        !            25: 
        !            26: #ifndef lint
        !            27: static char sccsid[] = "@(#)bugfiler.c 5.15 (Berkeley) 6/1/90";
        !            28: #endif /* not lint */
        !            29: 
        !            30: /*
        !            31:  * Bug report processing program, designed to be invoked
        !            32:  * through aliases(5).
        !            33:  */
        !            34: #include <bug.h>
        !            35: #include <sys/time.h>
        !            36: #include <sys/file.h>
        !            37: #include <pwd.h>
        !            38: #include <stdio.h>
        !            39: 
        !            40: char   bfr[MAXBSIZE],                  /* general I/O buffer */
        !            41:        tmpname[sizeof(TMP_BUG) + 5];   /* temp bug file */
        !            42: 
        !            43: main(argc, argv)
        !            44:        int     argc;
        !            45:        char    **argv;
        !            46: {
        !            47:        extern char     *optarg;        /* getopt arguments */
        !            48:        register struct passwd  *pwd;   /* bugs password entry */
        !            49:        register int    ch;             /* getopts char */
        !            50:        int     do_ack,                 /* acknowledge bug report */
        !            51:                do_redist;              /* redistribut BR */
        !            52:        char    *argversion,            /* folder name provided */
        !            53:                *strcpy();
        !            54:        struct passwd   *getpwnam();
        !            55: 
        !            56:        do_ack = do_redist = YES;
        !            57:        argversion = NULL;
        !            58:        while ((ch = getopt(argc, argv, "av:r")) != EOF)
        !            59:                switch((char)ch) {
        !            60:                case 'a':
        !            61:                        do_ack = NO;
        !            62:                        break;
        !            63:                case 'v':
        !            64:                        argversion = optarg;
        !            65:                        break;
        !            66:                case 'r':
        !            67:                        do_redist = NO;
        !            68:                        break;
        !            69:                case '?':
        !            70:                default:
        !            71:                        fputs("usage: bugfiler [-ar] [-v version]\n", stderr);
        !            72:                        error("usage: bugfiler [-ar] [-v version]", CHN);
        !            73:                }
        !            74: 
        !            75:        if (!(pwd = getpwnam(BUGS_ID)))
        !            76:                error("can't find bugs login.", BUGS_ID);
        !            77: 
        !            78:        if (chdir(pwd->pw_dir))         /* change to bugs home directory */
        !            79:                error("can't chdir to %s.", pwd->pw_dir);
        !            80: 
        !            81:        if (setreuid(0, pwd->pw_uid))
        !            82:                error("can't set id to %s.", BUGS_ID);
        !            83: 
        !            84:        (void)umask(02);                /* everything is 664 */
        !            85:        seterr();                       /* redirect to log file */
        !            86:        logit();                        /* log report arrival */
        !            87:        make_copy();                    /* save copy in case */
        !            88:        gethead(do_redist);
        !            89: 
        !            90:        if (argversion)                 /* specific folder requested */
        !            91:                (void)strcpy(dir, argversion);
        !            92: 
        !            93:        process();
        !            94: 
        !            95:        if (setuid(0, 0))
        !            96:                error("can't set id to root.", CHN);
        !            97:        if (do_ack)
        !            98:                reply();
        !            99:        if (do_redist)
        !           100:                redist();
        !           101:        (void)unlink(tmpname);
        !           102:        exit(OK);
        !           103: }
        !           104: 
        !           105: /*
        !           106:  * make_copy --
        !           107:  *     make a copy of bug report in error folder
        !           108:  */
        !           109: static
        !           110: make_copy()
        !           111: {
        !           112:        register int    cnt,                    /* read return value */
        !           113:                        tfd;                    /* temp file descriptor */
        !           114:        char    *strcpy();
        !           115: 
        !           116:        if (access(TMP_DIR, F_OK)) {
        !           117:                (void)mkdir(TMP_DIR);
        !           118:                (void)chmod(TMP_DIR, 0775);
        !           119:        }
        !           120:        (void)strcpy(tmpname, TMP_BUG);
        !           121:        if (tfd = mkstemp(tmpname)) {
        !           122:                while ((cnt = read(fileno(stdin), bfr, sizeof(bfr))) != ERR && cnt)
        !           123:                        write(tfd, bfr, cnt);
        !           124:                (void)close(tfd);
        !           125:                return;
        !           126:        }
        !           127:        error("can't make copy using %s.", tmpname);
        !           128: }
        !           129: 
        !           130: /*
        !           131:  * logit --
        !           132:  *     log this run of the bugfiler
        !           133:  */
        !           134: static
        !           135: logit()
        !           136: {
        !           137:        struct timeval  tp;
        !           138:        char    *C1, *C2,
        !           139:                *ctime();
        !           140: 
        !           141:        if (gettimeofday(&tp, (struct timezone *)NULL))
        !           142:                error("can't get time of day.", CHN);
        !           143:        for (C1 = C2 = ctime(&tp.tv_sec); *C1 && *C1 != '\n'; ++C1);
        !           144:        *C1 = EOS;
        !           145:        fputs(C2, stderr);
        !           146: }

unix.superglobalmegacorp.com

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