Annotation of researchv10no/ipc/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=newre(fields[0]))==NULL
        !            46:        || (mp->from=newre(fields[1]))==NULL
        !            47:        || (mp->user=newre(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", mp->serv->re, mp->from->re,
        !            55:                 mp->user->re, mp->luser);
        !            56:        return mp;
        !            57: }
        !            58: 
        !            59: freemap(mp)
        !            60:        Mapping *mp;
        !            61: {
        !            62:        if(mp==NULL)
        !            63:                return;
        !            64:        if(mp->from)
        !            65:                freere(mp->from);
        !            66:        if(mp->serv)
        !            67:                freere(mp->serv);
        !            68:        if(mp->user)
        !            69:                freere(mp->user);
        !            70:        if(mp->luser)
        !            71:                free(mp->luser);
        !            72: }
        !            73: 
        !            74: /*
        !            75:  *  add a map entry
        !            76:  */
        !            77: addmap(mp)
        !            78:        Mapping *mp;
        !            79: {
        !            80:        mp->next = NULL;
        !            81:        if(maphead==NULL)
        !            82:                maphead = mp;
        !            83:        else
        !            84:                maptail->next = mp;
        !            85:        maptail = mp;
        !            86: }
        !            87: 
        !            88: /*
        !            89:  *  free all map entries
        !            90:  */
        !            91: resetmaps()
        !            92: {
        !            93:        Mapping *mp, *nxt;
        !            94: 
        !            95:        logevent("resetmaps()\n");
        !            96:        for(mp=maphead; mp; mp=nxt) {
        !            97:                nxt = mp->next;
        !            98:                freemap(mp);
        !            99:        }
        !           100:        maphead = maptail = NULL;
        !           101: }
        !           102: 
        !           103: /*
        !           104:  *  return a new user id for call
        !           105:  */
        !           106: char *
        !           107: mapuser(service, source, user)
        !           108:        char *service;
        !           109:        char *source;
        !           110:        char *user;
        !           111: {
        !           112:        Mapping *mp;
        !           113:        regsubexp sub[10];
        !           114:        static char luser[ARB];
        !           115: 
        !           116:        for(mp=maphead; mp; mp=mp->next) {
        !           117:                if(!execre(mp->serv, service, (regsubexp *)0, 0))
        !           118:                        continue;
        !           119:                if(!execre(mp->from, source, (regsubexp *)0, 0))
        !           120:                        continue;
        !           121:                if(!execre(mp->user, user, sub, 10))
        !           122:                        continue;
        !           123:                regsub(mp->luser, luser, sub, 10);
        !           124:                return luser;
        !           125:        }
        !           126:        return NULL;
        !           127: }

unix.superglobalmegacorp.com

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