Annotation of 43BSDReno/contrib/isode-beta/dsap/common/ufn_parse.c, revision 1.1.1.1

1.1       root        1: /* ufn_parse.c - user-friendly name resolution */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/dsap/common/RCS/ufn_parse.c,v 7.1 90/07/09 14:35:20 mrose Exp $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/dsap/common/RCS/ufn_parse.c,v 7.1 90/07/09 14:35:20 mrose Exp $
                      9:  *
                     10:  *
                     11:  * $Log:       ufn_parse.c,v $
                     12:  * Revision 7.1  90/07/09  14:35:20  mrose
                     13:  * sync
                     14:  * 
                     15:  * Revision 7.0  90/06/11  09:59:42  mrose
                     16:  * *** empty log message ***
                     17:  * 
                     18:  */
                     19: 
                     20: /*
                     21:  *                               NOTICE
                     22:  *
                     23:  *    Acquisition, use, and distribution of this module and related
                     24:  *    materials are subject to the restrictions of a license agreement.
                     25:  *    Consult the Preface in the User's Manual for the full terms of
                     26:  *    this agreement.
                     27:  *
                     28:  */
                     29: 
                     30: 
                     31: #include "quipu/ufn.h"
                     32: #include "tailor.h"
                     33: #include "quipu/list.h"
                     34: #include "quipu/ds_search.h"
                     35: #include "quipu/connection.h"  /* ds_search uses di_block - include this for lint !!! */
                     36: #include "quipu/dua.h"
                     37: 
                     38: char ufn_notify = FALSE;
                     39: extern char PY_pepy[];
                     40: #define NOTIFY(x) if (ufn_notify) (void) printf x, (void) putchar('\n'); else ;
                     41: 
                     42: AttributeType at_OrgUnit;
                     43: AttributeType at_Organisation;
                     44: AttributeType at_Locality;
                     45: AttributeType at_CountryName;
                     46: AttributeType at_FriendlyCountryName;
                     47: AttributeType at_CommonName;
                     48: AttributeType at_Surname;
                     49: AttributeType at_Userid;
                     50: 
                     51: AttributeType at_ObjectClass;
                     52: 
                     53: Attr_Sequence ufnas = NULL;
                     54: 
                     55: extern LLog * log_dsap;
                     56: 
                     57: extern Filter strfilter ();
                     58: extern Filter ocfilter ();
                     59: extern Filter joinfilter ();
                     60: 
                     61: DNS DNS_append (a,b)
                     62: DNS a, b;
                     63: {      
                     64: DNS c;
                     65:        if (a == NULLDNS)
                     66:                return b;
                     67: 
                     68:        for (c=a; c->dns_next != NULLDNS; c=c->dns_next)
                     69:                ; /* Nothing */
                     70: 
                     71:        c->dns_next = b;
                     72: 
                     73:        return a;
                     74: }
                     75: 
                     76: static Attr_Sequence read_cache (base)
                     77: DN base;
                     78: {
                     79: Entry ptr;
                     80: 
                     81:        if ((ptr = local_find_entry (base,FALSE)) != NULLENTRY) 
                     82:                return (ptr->e_attributes);
                     83: 
                     84:        (void) printf ("You need the bug fix to libquipu.a !!!\n");
                     85:        return NULLATTR;
                     86: }
                     87: 
                     88: static char exact_match (dn,s) 
                     89: DN dn;
                     90: char * s;
                     91: {
                     92: RDN rdn;
                     93:        for (; dn->dn_parent != NULLDN; dn=dn->dn_parent)
                     94:                ; /* Nothing */
                     95: 
                     96:        for (rdn = dn->dn_rdn; rdn != NULLRDN; rdn=rdn->rdn_next) {
                     97:                if (sub_string (rdn->rdn_av.av_syntax)
                     98:                && (lexequ((char *)rdn->rdn_av.av_struct,s) == 0))
                     99:                        return TRUE;
                    100:        }
                    101:        return FALSE;
                    102: }
                    103: 
                    104: static char good_match (dn,s) 
                    105: DN dn;
                    106: char * s;
                    107: {
                    108: Attr_Sequence as;
                    109: AV_Sequence avs;
                    110: 
                    111:        for (as = read_cache(dn); as != NULLATTR; as=as->attr_link)
                    112:                for (avs=as->attr_value; avs!= NULLAV; avs=avs->avseq_next)
                    113:                        if (sub_string (avs->avseq_av.av_syntax)
                    114:                                && (lexequ((char *)avs->avseq_av.av_struct,s) == 0))
                    115:                                        return TRUE;
                    116:        return FALSE;
                    117: }
                    118: 
                    119: dnSelect (s,dlist,interact,el)
                    120: char * s;
                    121: DNS *dlist;
                    122: DNS (* interact) ();
                    123: DNS el;
                    124: {
                    125: DNS exact = NULLDNS;
                    126: DNS good  = NULLDNS;
                    127: DNS bad   = NULLDNS;
                    128: DNS tmp, next = NULLDNS;
                    129: 
                    130:        if ((dlist == (DNS *)NULL) || (*dlist == NULLDNS))
                    131:                return 2;
                    132: 
                    133:        for (tmp= *dlist; tmp != NULLDNS; tmp=next) {
                    134:                next = tmp->dns_next;
                    135:                if (exact_match(tmp->dns_dn,s)) {
                    136:                        tmp->dns_next = exact;
                    137:                        exact = tmp;
                    138:                } else if (good_match(tmp->dns_dn,s)) {
                    139:                        tmp->dns_next = good;
                    140:                        good = tmp;
                    141:                } else {
                    142:                        tmp->dns_next = bad;
                    143:                        bad = tmp;
                    144:                }
                    145:        }
                    146: 
                    147: 
                    148:        if (exact) {
                    149:                NOTIFY (("Found exact match(es) for '%s'",s));
                    150:                *dlist = exact;
                    151:                dn_seq_free (good);
                    152:                dn_seq_free (bad);
                    153:                return TRUE;
                    154:        }
                    155: 
                    156:        if (good) {
                    157:                NOTIFY (("Found good match(es) for '%s'",s));
                    158:                *dlist = good;
                    159:                dn_seq_free (bad);
                    160:                return TRUE;
                    161:        }
                    162: 
                    163:        good = (*interact)(bad,el->dns_dn,s);
                    164:        *dlist = good;
                    165:        if (good != NULLDNS)
                    166:                return TRUE;
                    167:        else
                    168:                return 2;       /* back track allowed ! */
                    169: 
                    170: }
                    171: 
                    172: ufn_search (base, subtree, filt, res, s, interact, el)
                    173: DN base;
                    174: char subtree;
                    175: Filter filt;
                    176: DNS * res;
                    177: char * s;
                    178: DNS (* interact) ();
                    179: DNS el;
                    180: {
                    181: struct ds_search_arg search_arg;
                    182: static struct ds_search_result result;
                    183: struct DSError err;
                    184: static CommonArgs ca = default_common_args;
                    185: EntryInfo * ptr;
                    186: DNS newdns, r = NULLDNS;
                    187: 
                    188:        search_arg.sra_baseobject = base;
                    189:        search_arg.sra_filter = filt;
                    190:        if (subtree)
                    191:                search_arg.sra_subset = SRA_WHOLESUBTREE;
                    192:        else    
                    193:                search_arg.sra_subset = SRA_ONELEVEL;
                    194:        search_arg.sra_searchaliases = TRUE;
                    195:        search_arg.sra_common = ca; /* struct copy */
                    196:        search_arg.sra_eis.eis_infotypes = TRUE;
                    197:        search_arg.sra_eis.eis_allattributes = FALSE;
                    198:        search_arg.sra_eis.eis_select = ufnas;
                    199: 
                    200: #ifdef DEBUG
                    201:        if (ufn_notify == 2)
                    202:            print_search (base, subtree, filt);
                    203: #endif
                    204:        if (ds_search (&search_arg, &err, &result) != DS_OK) {
                    205:                log_ds_error (&err);
                    206:                NOTIFY (("DAP Search returned an error"))
                    207:                ds_error_free (&err);
                    208:                filter_free (filt);
                    209:                return FALSE;
                    210:        }
                    211: 
                    212:        filter_free (filt);
                    213:        correlate_search_results (&result);
                    214: 
                    215:        if ( (result.CSR_limitproblem != LSR_NOLIMITPROBLEM) || (result.CSR_cr != NULLCONTINUATIONREF)) {
                    216:                if ( ! result.CSR_entries) {
                    217:                        NOTIFY (("Search returned partial results"))
                    218:                        return FALSE;
                    219:                } 
                    220:                NOTIFY (("Continuing with partial results !"));
                    221:        }
                    222: 
                    223:        for (ptr = result.CSR_entries; ptr != NULLENTRYINFO; ptr=ptr->ent_next) {
                    224:                cache_entry (ptr,FALSE,TRUE);
                    225:                newdns = dn_seq_alloc();
                    226:                newdns->dns_next = r;
                    227:                newdns->dns_dn = dn_cpy (ptr->ent_dn);
                    228:                r = newdns;
                    229:        }
                    230: 
                    231:        *res = r;
                    232: 
                    233:        return dnSelect (s,res,interact,el);
                    234: }
                    235: 
                    236: static rootSearch (s,interact,el,result)
                    237: char * s;
                    238: DNS (* interact) ();
                    239: DNS el;
                    240: DNS * result;
                    241: {
                    242: Filter filt, filta, filtb, filtc, filtd, filte, filtf;
                    243: 
                    244:        if (strlen (s) == 2) {
                    245: 
                    246:                filta = strfilter (at_CountryName,s,FILTERITEM_EQUALITY);
                    247:                filtb = strfilter (at_FriendlyCountryName,s,FILTERITEM_EQUALITY);
                    248:                filtc = strfilter (at_Organisation,s,FILTERITEM_EQUALITY);
                    249: 
                    250:                filtb->flt_next = filta;
                    251:                filtc->flt_next = filtb;
                    252: 
                    253:                filt = joinfilter (filtc, FILTER_OR);
                    254: 
                    255:                return ufn_search (NULLDN,FALSE,filt,result,s,interact,el);
                    256: 
                    257:        } else {
                    258: 
                    259:                filta = strfilter (at_FriendlyCountryName,s,FILTERITEM_SUBSTRINGS);
                    260:                filtb = strfilter (at_FriendlyCountryName,s,FILTERITEM_APPROX);
                    261:                filtc = strfilter (at_Organisation,s,FILTERITEM_SUBSTRINGS);
                    262:                filtd = strfilter (at_Organisation,s,FILTERITEM_APPROX);
                    263:                filte = strfilter (at_Locality,s,FILTERITEM_SUBSTRINGS);
                    264:                filtf = strfilter (at_Locality,s,FILTERITEM_APPROX);
                    265: 
                    266:                filtb->flt_next = filta;
                    267:                filtc->flt_next = filtb;
                    268:                filtd->flt_next = filtc;
                    269:                filte->flt_next = filtd;
                    270:                filtf->flt_next = filte;
                    271: 
                    272:                filt = joinfilter (filtf, FILTER_OR);
                    273: 
                    274:                return ufn_search (NULLDN,FALSE,filt,result,s,interact,el);
                    275:        }
                    276: }
                    277: 
                    278: static char present (d,t)
                    279: DN d;
                    280: AttributeType t;
                    281: {
                    282:        for (; d != NULLDN; d=d->dn_parent)
                    283:                if (AttrT_cmp (d->dn_rdn->rdn_at,t) == 0)
                    284:                        return TRUE;
                    285: 
                    286:        return FALSE;   /* More work ... */
                    287: }
                    288: 
                    289: static intSearch (base,s,interact,el,result)
                    290: DN base;
                    291: char * s;
                    292: DNS (* interact) ();
                    293: DNS el;
                    294: DNS * result;
                    295: {
                    296: Filter filt, filta, filtb, filtc, filtd, filte, filtf, filtg, filth;
                    297: 
                    298:        if ( present (base,at_OrgUnit) ) {
                    299: 
                    300:                filta = strfilter (at_OrgUnit,s,FILTERITEM_APPROX);
                    301:                filtb = strfilter (at_OrgUnit,s,FILTERITEM_SUBSTRINGS);
                    302: 
                    303:                filtb->flt_next = filta;
                    304: 
                    305:                filt = joinfilter (filtb, FILTER_OR);
                    306: 
                    307:                if ((filte = ocfilter ("OrganizationalUnit")) == NULLFILTER)
                    308:                        return FALSE;
                    309: 
                    310:                filte->flt_next = filt;
                    311: 
                    312:                filtf = joinfilter (filte, FILTER_AND);
                    313: 
                    314:                return ufn_search (base,FALSE,filtf,result,s,interact,el);
                    315: 
                    316:        } else if ( present (base,at_Organisation) ) {
                    317: 
                    318:                filta = strfilter (at_OrgUnit,s,FILTERITEM_APPROX);
                    319:                filtb = strfilter (at_OrgUnit,s,FILTERITEM_SUBSTRINGS);
                    320:                filtc = strfilter (at_Locality,s,FILTERITEM_APPROX);
                    321:                filtd = strfilter (at_Locality,s,FILTERITEM_SUBSTRINGS);
                    322: 
                    323:                filtb->flt_next = filta;
                    324:                filtc->flt_next = filtb;
                    325:                filtd->flt_next = filtc;
                    326: 
                    327:                filt = joinfilter (filtd, FILTER_OR);
                    328: 
                    329:                if ((filte = ocfilter ("OrganizationalUnit")) == NULLFILTER)
                    330:                        return FALSE;
                    331:                if ((filth = ocfilter ("Locality")) == NULLFILTER)
                    332:                        return FALSE;
                    333: 
                    334:                filth->flt_next = filte;
                    335: 
                    336:                filtg = joinfilter (filth, FILTER_OR);
                    337:                filtg->flt_next = filt;
                    338:                filtf = joinfilter (filtg, FILTER_AND);
                    339: 
                    340:                return ufn_search (base,FALSE,filtf,result,s,interact,el);
                    341: 
                    342:        } else if ( present (base,at_Locality) ) {
                    343: 
                    344:                filta = strfilter (at_Organisation,s,FILTERITEM_APPROX);
                    345:                filtb = strfilter (at_Organisation,s,FILTERITEM_SUBSTRINGS);
                    346: 
                    347:                filtb->flt_next = filta;
                    348: 
                    349:                filt = joinfilter (filtb, FILTER_OR);
                    350: 
                    351:                if ((filte = ocfilter ("Organization")) == NULLFILTER)
                    352:                        return FALSE;
                    353: 
                    354:                filte->flt_next = filt;
                    355: 
                    356:                filtf = joinfilter (filte, FILTER_AND);
                    357: 
                    358:                return ufn_search (base,FALSE,filtf,result,s,interact,el);
                    359:        } else {
                    360:                filta = strfilter (at_Organisation,s,FILTERITEM_APPROX);
                    361:                filtb = strfilter (at_Organisation,s,FILTERITEM_SUBSTRINGS);
                    362:                filtc = strfilter (at_Locality,s,FILTERITEM_APPROX);
                    363:                filtd = strfilter (at_Locality,s,FILTERITEM_SUBSTRINGS);
                    364: 
                    365:                filtb->flt_next = filta;
                    366:                filtc->flt_next = filtb;
                    367:                filtd->flt_next = filtc;
                    368: 
                    369:                filt = joinfilter (filtd, FILTER_OR);
                    370: 
                    371:                if ((filte = ocfilter ("Organization")) == NULLFILTER)
                    372:                        return FALSE;
                    373:                if ((filth = ocfilter ("Locality")) == NULLFILTER)
                    374:                        return FALSE;
                    375: 
                    376:                filth->flt_next = filte;
                    377: 
                    378:                filtg = joinfilter (filth, FILTER_OR);
                    379:                filtg->flt_next = filt;
                    380:                filtf = joinfilter (filtg, FILTER_AND);
                    381: 
                    382:                return ufn_search (base,FALSE,filtf,result,s,interact,el);
                    383:        }
                    384: }
                    385: 
                    386: static leafSearch (base,s,subtree,interact,el,result)
                    387: DN base;
                    388: char * s;
                    389: char subtree;
                    390: DNS (* interact) ();
                    391: DNS el;
                    392: DNS * result;
                    393: {
                    394: Filter filt, filta, filtb, filtc, filtd, filte, filtf;
                    395: 
                    396:        filta = strfilter (at_CommonName,s,FILTERITEM_APPROX);
                    397:        filtb = strfilter (at_CommonName,s,FILTERITEM_SUBSTRINGS);
                    398:        filtc = strfilter (at_Surname,s,FILTERITEM_APPROX);
                    399:        filtd = strfilter (at_Surname,s,FILTERITEM_SUBSTRINGS);
                    400:        filte = strfilter (at_Userid,s,FILTERITEM_APPROX);
                    401:        filtf = strfilter (at_Userid,s,FILTERITEM_SUBSTRINGS);
                    402: 
                    403:        filtb->flt_next = filta;
                    404:        filtc->flt_next = filtb;
                    405:        filtd->flt_next = filtc;
                    406:        filte->flt_next = filtd;
                    407:        filtf->flt_next = filte;
                    408: 
                    409:        filt = joinfilter (filtf, FILTER_OR);
                    410: 
                    411:        return ufn_search (base,subtree,filt,result,s,interact,el);
                    412: }
                    413: 
                    414: static keyedSearch (base,t,v,interact,el,result)
                    415: DN base;
                    416: char * t, *v; 
                    417: DNS (* interact) ();
                    418: DNS el;
                    419: DNS * result;
                    420: {
                    421: Filter filt, filta, filtb;
                    422: AttributeType at;
                    423: 
                    424:        if ((at = AttrT_new (t)) == NULLAttrT) {
                    425:                NOTIFY (("Invalid Key !"));
                    426:                return FALSE;
                    427:        }
                    428:        if ( ! sub_string (at->oa_syntax)) {
                    429:                NOTIFY (("String types only !"));
                    430:                return FALSE;
                    431:        }
                    432: 
                    433:        filta = strfilter (at,v,FILTERITEM_SUBSTRINGS);
                    434:        filtb = strfilter (at,v,FILTERITEM_APPROX);
                    435: 
                    436:        filtb->flt_next = filta;
                    437: 
                    438:        filt = joinfilter (filtb, FILTER_OR);
                    439: 
                    440:        if (base && base->dn_parent)
                    441:                return ufn_search (base,TRUE,filt,result,v,interact,el);
                    442:        else
                    443:                return ufn_search (base,FALSE,filt,result,v,interact,el);
                    444: }
                    445: 
                    446: 
                    447: static purportedMatch(base,c,v,interact,el,result)
                    448: DN base;
                    449: int c;
                    450: char ** v;
                    451: DNS (* interact) ();
                    452: DNS el;
                    453: DNS * result;
                    454: {
                    455: char * s = v[c-1];
                    456: DNS root, x, new = NULLDNS;
                    457: char * ptr;
                    458: int matches;
                    459: 
                    460:        if (c == 1) {
                    461: 
                    462:                if ((ptr = index (s,'=')) != NULLCP) {
                    463:                        *ptr++ = 0;
                    464:                        matches = keyedSearch (base,SkipSpace(s),SkipSpace(ptr),interact,el,result);
                    465:                        *(--ptr) = '=';
                    466:                        return matches;
                    467:                } else if (base == NULLDN) {
                    468:                        matches = rootSearch(s,interact,el,result);
                    469:                        if (*result != NULLDNS)
                    470:                                return matches;
                    471:                        else if (matches == TRUE)
                    472:                                return TRUE;
                    473:                        else
                    474:                                return leafSearch (base,s,FALSE,interact,el,result);
                    475:                } else if (base->dn_parent == NULLDN) {
                    476:                        /* length == 1 */
                    477:                        matches = intSearch (base,s,interact,el,result);
                    478:                        if (*result != NULLDNS)
                    479:                                return matches;
                    480:                        else if (matches == TRUE)
                    481:                                return TRUE;
                    482:                        else
                    483:                                return leafSearch (base,s,FALSE,interact,el,result);
                    484:                } else {
                    485:                        matches = leafSearch (base,s,TRUE,interact,el,result);
                    486:                        if (*result != NULLDNS)
                    487:                                return matches;
                    488:                        else if (matches == TRUE)
                    489:                                return TRUE;
                    490:                        else
                    491:                                return intSearch (base,s,interact,el,result);
                    492:                }
                    493:        }
                    494: 
                    495:        if ((ptr = index (s,'=')) != NULLCP) {
                    496:                *ptr++ = 0;
                    497:                if ( ! (matches = keyedSearch (base,SkipSpace(s),SkipSpace(ptr),interact,el,&root))) {
                    498:                        *(--ptr) = '=';
                    499:                        return FALSE;
                    500:                }
                    501:                *(--ptr) = '=';
                    502:        } else if (base == NULLDN) {
                    503:                if ( ! (matches = rootSearch (s,interact,el,&root)))
                    504:                        return FALSE;
                    505:        } else {
                    506:                if ( ! (matches = intSearch (base,s,interact,el,&root)))
                    507:                        return FALSE;
                    508:        }
                    509: 
                    510:        for (x = root; x != NULLDNS; x = x->dns_next) {
                    511:                if (purportedMatch (x->dns_dn, c-1, v,interact,el,&new)) {
                    512:                        if (new != NULLDNS)
                    513:                                *result = DNS_append (*result,new);
                    514:                } else
                    515:                        return FALSE;
                    516:        }
                    517: 
                    518:        return matches;
                    519: }
                    520: 
                    521: static envMatch (c,v,el,interact,result)
                    522: int c;
                    523: char ** v;
                    524: DNS el;
                    525: DNS (* interact) ();
                    526: DNS * result;
                    527: {
                    528: int res;
                    529: 
                    530:        if (el == NULLDNS)
                    531:                return TRUE;
                    532: 
                    533:        if ( ! ( res = purportedMatch(el->dns_dn,c,v,interact,el,result)))
                    534:                return FALSE;
                    535:        if (*result != NULLDNS) 
                    536:                return res;
                    537:        if (res == TRUE)
                    538:                return TRUE;            
                    539: 
                    540:        return envMatch(c,v,el->dns_next,interact,result);
                    541: 
                    542: }
                    543: 
                    544: static friendlyMatch_aux (c,v,el,interact,result)
                    545: int c;
                    546: char ** v;
                    547: envlist el;
                    548: DNS (* interact) ();
                    549: DNS * result;
                    550: {
                    551:        if (el == NULLEL)
                    552:                return TRUE;
                    553: 
                    554:        if ( ( c <= el->Upper) && (c >= el->Lower) ) 
                    555:                return envMatch (c,v,el->Dns,interact,result);
                    556: 
                    557:        return (friendlyMatch_aux (c,v,el->Next,interact,result));
                    558: 
                    559: }
                    560: 
                    561: envlist read_envlist()
                    562: {
                    563: char * home, *p, *ptr;
                    564: char ufnrc [LINESIZE];
                    565: char * def;
                    566: char buffer [LINESIZE];
                    567: envlist env, top = NULLEL, trail = NULLEL;
                    568: DNS dtail = NULLDNS;
                    569: FILE * file;
                    570: DN dn;
                    571: int i = 0;
                    572: extern char * TidyString ();
                    573: 
                    574:        if (home = getenv ("UFNRC"))
                    575:                (void) strcpy (ufnrc, home);
                    576:        else 
                    577:                if (home = getenv ("HOME"))
                    578:                        (void) sprintf (ufnrc, "%s/.ufnrc", home);
                    579:                else
                    580:                        (void) strcpy (ufnrc, "./.ufnrc");
                    581: 
                    582:        if ((file = fopen (ufnrc,"r")) == 0) {
                    583:                def = isodefile("ufnrc",0);
                    584:                if ((file = fopen(def,"r")) == 0) {
                    585:                        (void) sprintf (PY_pepy,"Can't open '%s' or '%s'",ufnrc,def);
                    586:                        return NULLEL;
                    587:                }
                    588:        }
                    589: 
                    590:        while (fgets (buffer, LINESIZE, file) != 0) {
                    591:                i++;
                    592:                p = buffer;
                    593:                if (( *p == '#') || (*p == '\0') || (*p == '\n'))
                    594:                        continue;       /* ignore comments and blanks */
                    595: 
                    596:                if (isspace (*p)) {
                    597:                        /* part of current environment */
                    598:                        if (!dtail) {
                    599:                                (void) sprintf (PY_pepy, "Unexpected blank at start of line %d",i);
                    600:                                (void) fclose (file);
                    601:                                return NULLEL;
                    602:                        }
                    603:                        p = TidyString(p);
                    604:                        if (*p == '-')
                    605:                                dn = NULLDN;
                    606:                        else if ((dn = str2dn (p)) == NULLDN) {
                    607:                                (void) sprintf (PY_pepy, "Bad DN in environment file line %d",i);
                    608:                                (void) fclose (file);
                    609:                                return NULLEL;
                    610:                        }
                    611:                        dtail->dns_next = dn_seq_alloc();
                    612:                        dtail = dtail->dns_next;
                    613:                        dtail->dns_next = NULLDNS;
                    614:                        dtail->dns_dn   = dn;
                    615:                        continue;
                    616:                }
                    617: 
                    618:                p = TidyString (p);
                    619: 
                    620:                if ((ptr = index (p,':')) == NULLCP) {
                    621:                        (void) sprintf (PY_pepy, "':' missing in environment file line %d",i);
                    622:                        (void) fclose (file);
                    623:                        return NULLEL;
                    624:                }
                    625: 
                    626:                *ptr++ = 0;
                    627:                ptr = SkipSpace (ptr);
                    628: 
                    629:                if (*ptr == '-')
                    630:                        dn = NULLDN;
                    631:                else if ((dn = str2dn (ptr)) == NULLDN) {
                    632:                        (void) sprintf (PY_pepy, "Bad DN in environment file line %d",i);
                    633:                        (void) fclose (file);
                    634:                        return NULLEL;
                    635:                }
                    636: 
                    637:                env = (envlist) smalloc (sizeof (*env));
                    638:                dtail = env->Dns = dn_seq_alloc();
                    639:                dtail->dns_next = NULLDNS;
                    640:                dtail->dns_dn   = dn;
                    641:                env->Next = NULLEL;
                    642:                if (top == NULLEL)
                    643:                        top = env;
                    644:                else 
                    645:                        trail->Next = env;
                    646:                trail = env;
                    647: 
                    648:                if ((ptr = index (p,',')) != NULLCP) {
                    649:                        *ptr++ = 0;
                    650:                        ptr = SkipSpace(ptr);
                    651:                        if (*ptr == '+')
                    652:                                env->Upper = 32767;     /* ~= infinity */
                    653:                        else 
                    654:                                env->Upper = atoi (ptr);        /* how to test error ? */
                    655:                } else
                    656:                        env->Upper = 0;
                    657:                
                    658:                p = SkipSpace(p);
                    659: 
                    660:                env->Lower = atoi (p);          /* how to test error ? */
                    661: 
                    662:                if ( ! env->Upper)
                    663:                        env->Upper = env->Lower;
                    664: 
                    665:        }
                    666: 
                    667:        (void) fclose (file);
                    668: 
                    669:        return top;
                    670: }
                    671: 
                    672: 
                    673: ufn_match (c,v,interact,result,el)
                    674: int c;
                    675: char ** v;
                    676: DNS (* interact) ();
                    677: DNS * result;
                    678: envlist el;
                    679: {
                    680: static int inited = FALSE;
                    681: 
                    682:        if ( (!ufnas) && !(inited = ufn_init()))
                    683:                return inited;
                    684:        
                    685:        PY_pepy[0] = NULL;
                    686:        if (el == NULLEL) {
                    687:                if ((el = read_envlist ()) == NULLEL) {
                    688:                        (void) sprintf (PY_pepy,"Can't read environment");
                    689:                        return 0;
                    690:                }
                    691:        }
                    692: 
                    693:        return (friendlyMatch_aux (c,v,el,interact,result));
                    694: }
                    695: 
                    696: ufn_init ()
                    697: {
                    698: Attr_Sequence as;
                    699: int result = TRUE;
                    700: 
                    701:        if (ufnas)
                    702:            return result;
                    703: 
                    704:        if ((at_ObjectClass = AttrT_new ("ObjectClass")) == NULLAttrT) {
                    705:                result = FALSE;
                    706:                LLOG (log_dsap,LLOG_EXCEPTIONS,("ObjectClass attribute unknown"));
                    707:        }
                    708: 
                    709:        if ((at_OrgUnit = AttrT_new ("ou")) == NULLAttrT) {
                    710:                result = FALSE;
                    711:                LLOG (log_dsap,LLOG_EXCEPTIONS,("ou attribute unknown"));
                    712:        }
                    713:        if ((at_Organisation = AttrT_new ("o")) == NULLAttrT) {
                    714:                result = FALSE;
                    715:                LLOG (log_dsap,LLOG_EXCEPTIONS,("o attribute unknown"));
                    716:        }
                    717:        if ((at_Locality = AttrT_new ("l")) == NULLAttrT) {
                    718:                result = FALSE;
                    719:                LLOG (log_dsap,LLOG_EXCEPTIONS,("l attribute unknown"));
                    720:        }
                    721:        if ((at_CountryName = AttrT_new ("c")) == NULLAttrT) {
                    722:                result = FALSE;
                    723:                LLOG (log_dsap,LLOG_EXCEPTIONS,("c attribute unknown"));
                    724:        }
                    725:        if ((at_FriendlyCountryName = AttrT_new ("FriendlyCountryName")) == NULLAttrT) {
                    726:                result = FALSE;
                    727:                LLOG (log_dsap,LLOG_EXCEPTIONS,("FriendlyCountryName attribute unknown"));
                    728:        }
                    729:        if ((at_CommonName = AttrT_new (CN_OID)) == NULLAttrT) {
                    730:                result = FALSE;
                    731:                LLOG (log_dsap,LLOG_EXCEPTIONS,("cn attribute unknown"));
                    732:        }
                    733:        if ((at_Surname = AttrT_new ("sn")) == NULLAttrT) {
                    734:                result = FALSE;
                    735:                LLOG (log_dsap,LLOG_EXCEPTIONS,("sn attribute unknown"));
                    736:        }
                    737:        if ((at_Userid = AttrT_new ("uid")) == NULLAttrT) {
                    738:                result = FALSE;
                    739:                LLOG (log_dsap,LLOG_EXCEPTIONS,("uid attribute unknown"));
                    740:        }
                    741: 
                    742:        ufnas = as_comp_new (at_OrgUnit,NULLAV,NULLACL_INFO);
                    743:        as = as_comp_new (at_Organisation,NULLAV,NULLACL_INFO);
                    744:        ufnas = as_merge (ufnas,as);
                    745:        as = as_comp_new (at_Locality,NULLAV,NULLACL_INFO);
                    746:        ufnas = as_merge (ufnas,as);
                    747:        as = as_comp_new (at_CountryName,NULLAV,NULLACL_INFO);
                    748:        ufnas = as_merge (ufnas,as);
                    749:        as = as_comp_new (at_FriendlyCountryName,NULLAV,NULLACL_INFO);
                    750:        ufnas = as_merge (ufnas,as);
                    751:        as = as_comp_new (at_CommonName,NULLAV,NULLACL_INFO);
                    752:        ufnas = as_merge (ufnas,as);
                    753:        as = as_comp_new (at_Surname,NULLAV,NULLACL_INFO);
                    754:        ufnas = as_merge (ufnas,as);
                    755:        as = as_comp_new (at_Userid,NULLAV,NULLACL_INFO);
                    756:        ufnas = as_merge (ufnas,as);
                    757: 
                    758:        return result;
                    759: }
                    760: 
                    761: #ifdef DEBUG
                    762: 
                    763: static print_search (dn, subtree, fi)
                    764: DN     dn;
                    765: char   subtree;
                    766: Filter fi;
                    767: {
                    768: static PS      nps = NULLPS;
                    769: 
                    770:     if (nps == NULLPS) {
                    771:        if ((nps = ps_alloc (std_open)) == NULL) {
                    772:            (void) fprintf (stderr, "ps_alloc(std_open): you lose\n");
                    773:            return;
                    774:        }
                    775:        if (std_setup (nps, stdout) == NOTOK) {
                    776:            (void) fprintf (stderr, "std_setup(stdout): you lose\n");
                    777:            ps_free (nps);
                    778:            nps = NULL;
                    779:            return;
                    780:        }
                    781:     }
                    782:     
                    783:     ps_printf (nps, "search starting at @");
                    784:     dn_print (nps, dn, EDBOUT);
                    785:     ps_printf (nps, "(%s) for ", subtree ? "subtree" : "singlelevel");
                    786: 
                    787:     print_filter (nps, fi, 0);
                    788: 
                    789:     ps_print (nps, "\n\n");
                    790:     (void) ps_flush (nps);
                    791: }
                    792: #endif

unix.superglobalmegacorp.com

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