Annotation of researchv10no/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)
        !            33:                return(FAIL);
        !            34:        if (fgets(wkdir, MAXFULLNAME, fp) == NULL) {
        !            35:                (void) pclose(fp);
        !            36:                return(FAIL);
        !            37:        }
        !            38:        if (wkdir[strlen(wkdir)-1] == '\n')
        !            39:                wkdir[strlen(wkdir)-1] = '\0';
        !            40:        (void) pclose(fp);
        !            41:        return(0);
        !            42: }
        !            43: 
        !            44: 
        !            45: /*
        !            46:  * uidstat(file, &statbuf)
        !            47:  * This is a stat call with the uid set from Euid to Uid.
        !            48:  * Used from uucp.c and uux.c to permit file copies
        !            49:  * from directories that may not be searchable by other.
        !            50:  * return:
        !            51:  *     same as stat()
        !            52:  */
        !            53: 
        !            54: #ifndef uidstat
        !            55: 
        !            56: int
        !            57: uidstat(file, buf)
        !            58: char *file;
        !            59: struct stat *buf;
        !            60: {
        !            61: #ifndef V7
        !            62:        register ret;
        !            63: 
        !            64:        (void) setuid(Uid);
        !            65:        ret = stat(file, buf);
        !            66:        (void) setuid(Euid);
        !            67:        return(ret);
        !            68: #else
        !            69:        int     ret;
        !            70:        register pid, rpid;
        !            71: 
        !            72:        if ((pid = vfork()) == 0) {
        !            73:                (void) setuid(Uid);
        !            74:                _exit(stat(file, buf));
        !            75:        }
        !            76:        ret = 1;
        !            77:        while ((rpid = wait(&ret)) != pid && rpid != -1)
        !            78:                ;
        !            79:        return (rpid == -1 ? 1 : ret);
        !            80: #endif
        !            81: }
        !            82: #endif

unix.superglobalmegacorp.com

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