Annotation of researchv10no/netfs/libnetb/setupmap.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * make userid and groupid maps
        !             3:  * combine the client ids sent by setup
        !             4:  * with the server ids left around by the user code
        !             5:  */
        !             6: 
        !             7: #include <ctype.h>
        !             8: #include "rf.h"
        !             9: #include "perm.h"
        !            10: 
        !            11: #define        NULL    0
        !            12: 
        !            13: Idmap *rfuidmap, *rfgidmap;
        !            14: 
        !            15: char *defaultuser = 0;
        !            16: char *defaultgroup = 0;
        !            17: 
        !            18: int defaultuid = RFNOID;
        !            19: int defaultgid = RFNOID;
        !            20: 
        !            21: static int mapbuild();
        !            22: static char *getpair();
        !            23: 
        !            24: extern char *malloc(), *realloc();
        !            25: 
        !            26: _rfmapuid(rbuf)
        !            27: char *rbuf;
        !            28: {
        !            29:        static int nuids;
        !            30: 
        !            31:        if (defaultuser)
        !            32:                defaultuid = _rflookid(rfuidmap, defaultuser);
        !            33:        if (mapbuild(rbuf, rfuidmap, &_rfuids, &nuids, defaultuser) == 0)
        !            34:                return (0);
        !            35:        _rfmkhash(_rfuids, nuids, &_rfuhp, &_rfcu, &_rfsu);
        !            36:        return (1);
        !            37: }
        !            38: 
        !            39: _rfmapgid(rbuf)
        !            40: char *rbuf;
        !            41: {
        !            42:        static int ngids;
        !            43: 
        !            44:        if (defaultgroup)
        !            45:                defaultgid = _rflookid(rfgidmap, defaultgroup);
        !            46:        if (mapbuild(rbuf, rfgidmap, &_rfgids, &ngids, defaultgroup) == 0)
        !            47:                return (0);
        !            48:        _rfmkhash(_rfgids, ngids, &_rfghp, &_rfcg, &_rfsg);
        !            49:        return (1);
        !            50: }
        !            51: 
        !            52: /*
        !            53:  * combine server names and ids (locmap)
        !            54:  * with client names and ids (rdata)
        !            55:  * to make an id-id map (returned, length in *lsize)
        !            56:  * return nonzero if this was the last buffer,
        !            57:  * zero if more data are expected.  If the remote name
        !            58:  * doesn't map to a local name, and defaultlocal is non-zero,
        !            59:  * map it to the defaultlocal name.
        !            60:  */
        !            61: static int
        !            62: mapbuild(rdata, locmap, lmap, lsize, defaultlocal)
        !            63: char *rdata;
        !            64: Idmap *locmap;
        !            65: Tuid **lmap;
        !            66: int *lsize;
        !            67: char *defaultlocal;
        !            68: {
        !            69:        char *cname;
        !            70:        char *p;
        !            71:        int cid, sid;
        !            72:        Tuid *map;
        !            73:        register Tuid *cur, *last;
        !            74:        int size;
        !            75:        int curoff;
        !            76:        Idmap nilmap;
        !            77:        int done;
        !            78: 
        !            79:        if (locmap == NULL) {
        !            80:                locmap = &nilmap;
        !            81:                nilmap.name[0] = 0;
        !            82:        }
        !            83:        if ((size = *lsize) != 0) {     /* already started */
        !            84:                map = *lmap;
        !            85:                cur = &map[size];
        !            86:                while (--cur >= map && cur->sid == RFNOID)
        !            87:                        ;
        !            88:                cur++;          /* point to first unused slot */
        !            89:        } else {
        !            90:                size = 100;     /* too big for groups, but too bad */
        !            91:                if ((map = (Tuid *)malloc(size * sizeof(Tuid))) == NULL)
        !            92:                        rfpanic("out of memory making id map\n");
        !            93:                cur = map;
        !            94:        }
        !            95:        last = &map[size-1];
        !            96:        p = rdata;
        !            97:        done = 1;               /* assume we'll get whole buffer */
        !            98:        while ((p = getpair(p, &cname, &cid)) != NULL) {
        !            99:                if (cname[0] == 0 || cid == RFNOID)
        !           100:                        continue;
        !           101:                if (cname[0] == ':' && cname[1] == 0) { /* continuation mark */
        !           102:                        done = 0;
        !           103:                        break;
        !           104:                }
        !           105:                if ((sid = _rflookid(locmap, cname)) == RFNOID)
        !           106: #ifdef notdef
        !           107:                        if (defaultlocal == 0 ||
        !           108:                           (sid = _rflookid(locmap, defaultlocal)) == RFNOID)
        !           109: #endif
        !           110:                                continue;
        !           111:                if (cur >= last) {
        !           112:                        curoff = cur - map;
        !           113:                        size += 100;
        !           114:                        if ((map = (Tuid *)realloc((char *)map, size*sizeof(Tuid))) == NULL)
        !           115:                                rfpanic("out of memory making id map\n");
        !           116:                        last = &map[size-1];
        !           117:                        cur = &map[curoff];
        !           118:                }
        !           119:                cur->sid = sid;
        !           120:                cur->cid = cid;
        !           121:                cur++;
        !           122:        }
        !           123:        cur->sid = cur->cid = RFNOID;   /* end marker */
        !           124:        if (done == 0) {        /* i don't especially like this */
        !           125:                for (cur++; cur <= last; cur++)
        !           126:                        cur->sid = RFNOID;
        !           127:                /* now (cur-map) == size == allocated size */
        !           128:        }
        !           129:        *lsize = cur - map;
        !           130:        *lmap = map;
        !           131:        return (done);
        !           132: }
        !           133: 
        !           134: static char *
        !           135: getpair(line, pname, pnum)
        !           136: char *line;
        !           137: char **pname;
        !           138: int *pnum;
        !           139: {
        !           140:        register char *p;
        !           141: 
        !           142:        p = line;
        !           143:        while (isspace(*p))
        !           144:                p++;
        !           145:        *pname = p;
        !           146:        while (!isspace(*p)) {
        !           147:                if (*p == '\n' || *p == 0)
        !           148:                        return (NULL);
        !           149:                p++;
        !           150:        }
        !           151:        while (isspace(*p))
        !           152:                *p++ = 0;
        !           153:        *pnum = atoi(p);
        !           154:        if (*p == '-' || *p == '+')     /* well ... */
        !           155:                p++;
        !           156:        while (isdigit(*p))
        !           157:                p++;
        !           158:        if (*p != '\n')
        !           159:                return (NULL);
        !           160:        return (p+1);
        !           161: }

unix.superglobalmegacorp.com

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