Annotation of researchv9/ipc/src/mgrs/svcmgr/mapping.c, revision 1.1

1.1     ! root        1: #include "mgr.h"
        !             2: 
        !             3: Mapping *maphead;              
        !             4: Mapping *maptail;
        !             5: 
        !             6: /*
        !             7:  *  Create a new mapping from a string.  The mapping is of the form:
        !             8:  *  `service-re source-re olduser-re newuser-exp'
        !             9:  */
        !            10: Mapping *
        !            11: newmap(cp)
        !            12:        char *cp;
        !            13: {
        !            14:        Mapping *mp = (Mapping *)malloc(sizeof(Mapping));
        !            15: #      define FIELDS 4
        !            16:        char *fields[FIELDS];
        !            17:        int n;
        !            18: 
        !            19:        if(mp==NULL) {
        !            20:                logevent("out of memory allocating mapping\n");
        !            21:                return NULL;
        !            22:        }
        !            23:        mp->user = mp->from = mp->serv = NULL;
        !            24:        mp->luser = NULL;
        !            25:        setfields(" \t");
        !            26:        n = getmfields(cp, fields, FIELDS);
        !            27:        switch(n) {
        !            28:        case 0:
        !            29:                freemap(mp);
        !            30:                return NULL;
        !            31:        case 1:
        !            32:                fields[1] = "";
        !            33:        case 2:
        !            34:                fields[2] = ".*";
        !            35:        case 3:
        !            36:                fields[3] = "&";
        !            37:                break;
        !            38:        case 4:
        !            39:                break;
        !            40:        default:
        !            41:                logevent("incorrect number of fields in mapping %s\n", fields[0]);
        !            42:                freemap(mp);
        !            43:                return NULL;
        !            44:        }
        !            45:        if((mp->serv=nregcomp(fields[0]))==NULL
        !            46:        || (mp->from=nregcomp(fields[1]))==NULL
        !            47:        || (mp->user=nregcomp(fields[2]))==NULL) {
        !            48:                logevent("illegal reg exp in mapping `%s %s %s %s'\n", fields[0],
        !            49:                        fields[1], fields[2], fields[3]);
        !            50:                freemap(mp);
        !            51:                return NULL;
        !            52:        }
        !            53:        mp->luser = strdup(fields[3]);
        !            54:        logevent("newmap(%s %s %s %s)\n", fields[0], fields[1], fields[2], fields[3]);
        !            55:        return mp;
        !            56: }
        !            57: 
        !            58: freemap(mp)
        !            59:        Mapping *mp;
        !            60: {
        !            61:        if(mp==NULL)
        !            62:                return;
        !            63:        if(mp->from)
        !            64:                free((char *)mp->from);
        !            65:        if(mp->serv)
        !            66:                free((char *)mp->serv);
        !            67:        if(mp->user)
        !            68:                free((char *)mp->user);
        !            69:        if(mp->luser)
        !            70:                free(mp->luser);
        !            71: }
        !            72: 
        !            73: /*
        !            74:  *  add a map entry
        !            75:  */
        !            76: addmap(mp)
        !            77:        Mapping *mp;
        !            78: {
        !            79:        mp->next = NULL;
        !            80:        if(maphead==NULL)
        !            81:                maphead = mp;
        !            82:        else
        !            83:                maptail->next = mp;
        !            84:        maptail = mp;
        !            85: }
        !            86: 
        !            87: /*
        !            88:  *  free all map entries
        !            89:  */
        !            90: resetmaps()
        !            91: {
        !            92:        Mapping *mp, *nxt;
        !            93: 
        !            94:        logevent("resetmaps()\n");
        !            95:        for(mp=maphead; mp; mp=nxt) {
        !            96:                nxt = mp->next;
        !            97:                freemap(mp);
        !            98:        }
        !            99:        maphead = maptail = NULL;
        !           100: }
        !           101: 
        !           102: /*
        !           103:  *  return a new user id for call
        !           104:  */
        !           105: char *
        !           106: mapuser(service, source, user)
        !           107:        char *service;
        !           108:        char *source;
        !           109:        char *user;
        !           110: {
        !           111:        Mapping *mp;
        !           112:        regsubexp sub[10];
        !           113:        static char luser[ARB];
        !           114: 
        !           115:        for(mp=maphead; mp; mp=mp->next) {
        !           116:                if(!regexec(mp->serv, service, 0, 0))
        !           117:                        continue;
        !           118:                if(!regexec(mp->from, source, 0, 0))
        !           119:                        continue;
        !           120:                if(!regexec(mp->user, user, sub, 10))
        !           121:                        continue;
        !           122:                regsub(mp->luser, luser, sub, 10);
        !           123:                return luser;
        !           124:        }
        !           125:        return NULL;
        !           126: }

unix.superglobalmegacorp.com

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