Annotation of researchv8dc/cmd/uucp/gwd.c, revision 1.1

1.1     ! root        1: /*     /sccs/src/cmd/uucp/s.gwd.c
        !             2:        gwd.c   1.3     8/30/84 17:37:28
        !             3: */
        !             4: #include "uucp.h"
        !             5: VERSION(@(#)gwd.c      1.3);
        !             6: 
        !             7: /*
        !             8:  *     gwd - get working directory
        !             9:  *     Uid and Euid are global
        !            10:  *     return
        !            11:  *             0 - ok
        !            12:  *             FAIL - failed
        !            13:  */
        !            14: 
        !            15: gwd(wkdir)
        !            16: char *wkdir;
        !            17: {
        !            18:        FILE *fp;
        !            19:        char cmd[BUFSIZ];
        !            20: 
        !            21:        *wkdir = '\0';
        !            22:        (void) sprintf(cmd, "%s pwd 2>&-", PATH);
        !            23: 
        !            24: #ifndef V7
        !            25:        (void) setuid(Uid);
        !            26:        fp = popen(cmd, "r");
        !            27:        (void) setuid(Euid);
        !            28: #else
        !            29:        fp = popen(cmd, "r");
        !            30: #endif
        !            31: 
        !            32:        if (fp == NULL || fgets(wkdir, MAXFULLNAME, fp) == NULL) {
        !            33:                (void) pclose(fp);
        !            34:                return(FAIL);
        !            35:        }
        !            36:        if (wkdir[strlen(wkdir)-1] == '\n')
        !            37:                wkdir[strlen(wkdir)-1] = '\0';
        !            38:        (void) pclose(fp);
        !            39:        return(0);
        !            40: }
        !            41: 
        !            42: 
        !            43: /*
        !            44:  * uidstat(file, &statbuf)
        !            45:  * This is a stat call with the uid set from Euid to Uid.
        !            46:  * Used from uucp.c and uux.c to permit file copies
        !            47:  * from directories that may not be searchable by other.
        !            48:  * return:
        !            49:  *     same as stat()
        !            50:  */
        !            51: 
        !            52: int
        !            53: uidstat(file, buf)
        !            54: char *file;
        !            55: struct stat *buf;
        !            56: {
        !            57: #ifndef V7
        !            58:        register ret;
        !            59: 
        !            60:        (void) setuid(Uid);
        !            61:        ret = stat(file, buf);
        !            62:        (void) setuid(Euid);
        !            63:        return(ret);
        !            64: #else V7
        !            65:        int     ret;
        !            66: 
        !            67:        if (vfork() == 0) {
        !            68:                (void) setuid(Uid);
        !            69:                _exit(stat(file, buf));
        !            70:        }
        !            71:        wait(&ret);
        !            72:        return(ret);
        !            73: #endif V7
        !            74: }

unix.superglobalmegacorp.com

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