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

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

unix.superglobalmegacorp.com

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