Annotation of 43BSDReno/contrib/isode-beta/quipu/dish/search.c, revision 1.1

1.1     ! root        1: /* search.c - */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/quipu/dish/RCS/search.c,v 7.6 90/07/09 14:47:23 mrose Exp $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/quipu/dish/RCS/search.c,v 7.6 90/07/09 14:47:23 mrose Exp $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       search.c,v $
        !            12:  * Revision 7.6  90/07/09  14:47:23  mrose
        !            13:  * sync
        !            14:  * 
        !            15:  * Revision 7.5  90/03/15  11:18:31  mrose
        !            16:  * quipu-sync
        !            17:  * 
        !            18:  * Revision 7.4  90/01/11  18:37:44  mrose
        !            19:  * real-sync
        !            20:  * 
        !            21:  * Revision 7.3  89/11/26  14:43:00  mrose
        !            22:  * sync
        !            23:  * 
        !            24:  * Revision 7.2  89/11/26  14:27:15  mrose
        !            25:  * sync
        !            26:  * 
        !            27:  * Revision 7.1  89/11/26  14:25:45  mrose
        !            28:  * sync
        !            29:  * 
        !            30:  * Revision 7.0  89/11/23  22:20:20  mrose
        !            31:  * Release 6.0
        !            32:  * 
        !            33:  */
        !            34: 
        !            35: /*
        !            36:  *                               NOTICE
        !            37:  *
        !            38:  *    Acquisition, use, and distribution of this module and related
        !            39:  *    materials are subject to the restrictions of a license agreement.
        !            40:  *    Consult the Preface in the User's Manual for the full terms of
        !            41:  *    this agreement.
        !            42:  *
        !            43:  */
        !            44: 
        !            45: 
        !            46: #include "quipu/util.h"
        !            47: #include "quipu/ds_search.h"
        !            48: #include "quipu/list.h"
        !            49: #include "quipu/entry.h"
        !            50: #include "quipu/sequence.h"
        !            51: 
        !            52: extern DN       dn,
        !            53:                current_dn;
        !            54: 
        !            55: #define        OPT     (!frompipe || rps -> ps_byteno == 0 ? opt : rps)
        !            56: #define        RPS     (!frompipe || opt -> ps_byteno == 0 ? rps : opt)
        !            57: extern char    frompipe;
        !            58: extern PS      opt, rps;
        !            59: 
        !            60: extern Entry   current_entry;
        !            61: extern char     flag_show;
        !            62: DN             rel_dn = NULLDN;
        !            63: 
        !            64: extern char    fred_flag;
        !            65: extern char    fred_expand;
        !            66: extern char    fred_long;
        !            67: extern char    fred_phone;
        !            68: extern char    fred_sequence;
        !            69: extern char    fred_subdisplay;
        !            70: 
        !            71: Filter          get_filter ();
        !            72: char           *TidyString ();
        !            73: char           allow_move = TRUE;
        !            74: 
        !            75: int            csr_compar ();
        !            76: 
        !            77: call_search (argc, argv)
        !            78: int             argc;
        !            79: char          **argv;
        !            80: {
        !            81:        PS      aps;
        !            82:        struct ds_search_arg search_arg;
        !            83:        struct DSError  error;
        !            84:        struct ds_search_result result;
        !            85:        DN              save_dn;
        !            86:        extern int      sizelimit;
        !            87:        int             x;
        !            88:        Entry           save_entry;
        !            89:        char            rel_flag = TRUE;
        !            90:        char            part_flag = TRUE;
        !            91:        char           *save_arg = NULLCP;
        !            92:        extern  char     value_flag ;
        !            93:        extern  char    all_flag;
        !            94:        extern  char    key_flag;
        !            95:        extern  char    name_flag;
        !            96:        extern  char    doneget;
        !            97:        extern  char * result_sequence;
        !            98:        static  char    *nvec[2] = {"search"};
        !            99:        extern  Attr_Sequence as_flag;
        !           100:        int             seqno;
        !           101:        Attr_Sequence   eptr;
        !           102:        char            hit_one = FALSE;
        !           103:        extern  char    search_result;
        !           104: 
        !           105:        search_result = OK;
        !           106: 
        !           107:        value_flag = TRUE;
        !           108:        all_flag = FALSE;
        !           109:        name_flag = TRUE;
        !           110:        if (as_flag != NULLATTR) {
        !           111:                as_free (as_flag);
        !           112:                as_flag = NULLATTR;
        !           113:        }
        !           114:        flag_show = FALSE;
        !           115:        key_flag = TRUE;
        !           116: 
        !           117:        search_arg.sra_filter = NULLFILTER;
        !           118:        search_arg.sra_subset = SRA_ONELEVEL;
        !           119:        search_arg.sra_common.ca_servicecontrol.svc_sizelimit = sizelimit;
        !           120:        search_arg.sra_searchaliases = FALSE;
        !           121:        
        !           122:        if ((argc = service_control (OPT, argc, argv, &search_arg.sra_common)) == -1)
        !           123:                return;
        !           124: 
        !           125:        allow_move = FALSE;
        !           126:        if ( (argc = set_read_flags (argc,argv)) == -1) {
        !           127:                allow_move = TRUE;
        !           128:                return;
        !           129:        }
        !           130:        allow_move = TRUE;
        !           131:        fred_flag = FALSE;
        !           132:        fred_expand = FALSE;
        !           133:        fred_long = 2;
        !           134:        fred_phone = FALSE;
        !           135:        fred_sequence = TRUE;
        !           136:        fred_subdisplay = FALSE;
        !           137: 
        !           138:        for (x = 1; x < argc; x++) {
        !           139:                if (test_arg (argv[x], "-baseobject",1))
        !           140:                        search_arg.sra_subset = SRA_BASEOBJECT;
        !           141:                else if (test_arg (argv[x], "-singlelevel",2))
        !           142:                        search_arg.sra_subset = SRA_ONELEVEL;
        !           143:                else if (test_arg (argv[x], "-subtree",2))
        !           144:                        search_arg.sra_subset = SRA_WHOLESUBTREE;
        !           145:                else if (test_arg (argv[x], "-relative",3)) 
        !           146:                        rel_flag = TRUE;
        !           147:                else if (test_arg (argv[x], "-norelative",5)) 
        !           148:                        rel_flag = FALSE;
        !           149:                else if (test_arg (argv[x], "-partial",2))
        !           150:                        part_flag = TRUE;
        !           151:                else if (test_arg (argv[x], "-nopartial",4))
        !           152:                        part_flag = FALSE;
        !           153:                else if (test_arg (argv[x], "-hitone",3))
        !           154:                        hit_one = TRUE;
        !           155:                else if (test_arg (argv[x], "-searchaliases",3)) 
        !           156:                        search_arg.sra_searchaliases = TRUE;
        !           157:                else if (test_arg (argv[x], "-nosearchaliases",5)) 
        !           158:                        search_arg.sra_searchaliases = FALSE;
        !           159:                else if (test_arg (argv[x], "-filter",1)) {
        !           160:                        if (x+1 == argc) {
        !           161:                                ps_printf (OPT,"Filter missing\n");
        !           162:                                Usage (argv[0]);
        !           163:                                return;
        !           164:                        }
        !           165:                        if ((search_arg.sra_filter = get_filter (argv[++x])) == NULLFILTER) {
        !           166:                                ps_printf (OPT,"Invalid filter %s\n",argv[x]);
        !           167:                                Usage (argv[0]);
        !           168:                                return;
        !           169:                        }
        !           170:                        shuffle_up (argc--,argv,x--);
        !           171:                } else if (test_arg (argv[x], "-object",1)) {
        !           172:                        if (move (argv[++x]) != OK) {
        !           173:                                ps_printf (OPT,"Invalid move object %s\n",argv[x]);
        !           174:                                Usage (argv[0]);
        !           175:                                return;
        !           176:                        }
        !           177:                        shuffle_up (argc--,argv,x--);
        !           178:                } else if (*argv[x] != '-') {
        !           179:                        if (save_arg != NULLCP) {
        !           180:                                ps_printf (OPT,"Need flags to parse argument '%s'!\n",argv[x]);
        !           181:                                Usage (argv[0]);
        !           182:                                return;
        !           183:                        } else 
        !           184:                                save_arg = argv[x];
        !           185:                }
        !           186:                else if (test_arg (argv[x], "-fred",4))
        !           187:                        fred_flag = TRUE;
        !           188:                else if (test_arg (argv[x], "-expand",4))
        !           189:                        fred_expand = TRUE;
        !           190:                else if (test_arg (argv[x], "-full",4))
        !           191:                        fred_long = TRUE;
        !           192:                else if (test_arg (argv[x], "-summary",7))
        !           193:                        fred_long = FALSE;
        !           194:                else if (test_arg (argv[x], "-phone",5))
        !           195:                        fred_phone = TRUE;
        !           196:                else if (test_arg (argv[x], "-nofredseq",9))
        !           197:                        fred_sequence = FALSE;
        !           198:                else if (test_arg (argv[x], "-subdisplay",10))
        !           199:                        fred_subdisplay = TRUE;
        !           200:                else
        !           201:                        continue;  /* a read type flag !!! */
        !           202:                        
        !           203:                shuffle_up (argc--,argv,x--);
        !           204:        }
        !           205: 
        !           206:        if (fred_flag && fred_long != TRUE && fred_expand != TRUE) {
        !           207:            AttributeType at;
        !           208: 
        !           209:            if (at = AttrT_new ("rfc822Mailbox"))
        !           210:                as_flag = as_merge (as_flag,
        !           211:                                    as_comp_new (AttrT_cpy (at), NULLAV,
        !           212:                                                 NULLACL_INFO));
        !           213:            if (at = AttrT_new ("telephoneNumber"))
        !           214:                as_flag = as_merge (as_flag,
        !           215:                                    as_comp_new (AttrT_cpy (at), NULLAV,
        !           216:                                                 NULLACL_INFO));
        !           217:        }
        !           218: 
        !           219:        if (flag_show && (as_flag == NULLATTR))
        !           220:                all_flag = TRUE;
        !           221: 
        !           222:        if (save_arg != NULLCP) {
        !           223:                /* There is an unflagged argument */
        !           224:                if (search_arg.sra_filter == NULLFILTER) {
        !           225:                        if ((search_arg.sra_filter = get_filter (save_arg)) == NULLFILTER) {
        !           226:                                ps_printf (OPT,"Invalid filter %s\n",save_arg);
        !           227:                                Usage (argv[0]);
        !           228:                                return;
        !           229:                        }
        !           230:                } else if (move (save_arg) != OK) {
        !           231:                        ps_printf (OPT,"Invalid move object %s\n",save_arg);
        !           232:                        Usage (argv[0]);
        !           233:                        return;
        !           234:                }
        !           235:        }
        !           236:        
        !           237:        if (search_arg.sra_filter == NULLFILTER) {
        !           238:                /* set default */
        !           239:                search_arg.sra_filter = filter_alloc ();
        !           240:                search_arg.sra_filter->flt_next = NULLFILTER;
        !           241:                search_arg.sra_filter->flt_type = FILTER_AND;
        !           242:                search_arg.sra_filter->FUFILT = NULLFILTER;
        !           243:        }
        !           244: 
        !           245:        if (argc != 1) {
        !           246:                Usage (argv[0]);
        !           247:                return;
        !           248:        }
        !           249: 
        !           250:        if (fred_flag
        !           251:                && (save_entry = local_find_entry (dn, FALSE))
        !           252:                && save_entry -> e_alias)
        !           253:            dn = dn_cpy (save_entry -> e_alias);
        !           254:        search_arg.sra_eis.eis_infotypes = value_flag;
        !           255:        search_arg.sra_eis.eis_allattributes = all_flag;
        !           256:        search_arg.sra_eis.eis_select = as_flag;
        !           257:        search_arg.sra_baseobject = dn;
        !           258: 
        !           259:        if (rebind () != OK)
        !           260:                return;
        !           261: 
        !           262:        /* Strong authentication */
        !           263:        if (search_arg.sra_common.ca_security != (struct security_parms *) 0)
        !           264:        {
        !           265:        struct signature *sign_operation();
        !           266:        int encode_DAS_SearchArgumentData();
        !           267: 
        !           268:        search_arg.sra_common.ca_sig =
        !           269:                sign_operation((caddr_t)&search_arg, encode_DAS_SearchArgumentData);
        !           270:        }
        !           271: 
        !           272:        while (ds_search (&search_arg, &error, &result) != DS_OK) {
        !           273:                if (dish_error (OPT, &error) == 0)
        !           274:                        return;
        !           275:                search_arg.sra_baseobject = error.ERR_REFERRAL.DSE_ref_candidates->cr_name;
        !           276:        }
        !           277: 
        !           278:        correlate_search_results (&result);
        !           279:                        
        !           280:        if (result_sequence)
        !           281:                set_sequence (result_sequence);
        !           282: 
        !           283:        if (result.CSR_entries == NULLENTRYINFO) 
        !           284:                ps_printf (aps = OPT, "Search failed to find anything.\n");
        !           285:        else {
        !           286:                EntryInfo      *ptr;
        !           287: 
        !           288:                ptr = result.CSR_entries;
        !           289:                if (hit_one && result.CSR_entries->ent_next != NULLENTRYINFO) {
        !           290:                        ps_printf (OPT,"Multiple hits...\n");
        !           291:                        if (frompipe)                   
        !           292:                                search_result = NOTOK;  
        !           293:                }
        !           294: 
        !           295:                aps = RPS;
        !           296:                save_dn = dn_cpy(current_dn);
        !           297:                save_entry = current_entry;
        !           298:                doneget = TRUE;
        !           299:                if (rel_flag)
        !           300:                        rel_dn = dn_cpy(dn);
        !           301: 
        !           302:                if (fred_flag) {
        !           303:                    int     i,
        !           304:                            didecode = 0,
        !           305:                            nchild = 0;
        !           306: 
        !           307:                    i = 0;
        !           308:                    for (ptr = result.CSR_entries;
        !           309:                             ptr;
        !           310:                             ptr = ptr -> ent_next)
        !           311:                            i++;
        !           312:                    if (fred_long == 2)
        !           313:                        if ((fred_subdisplay && fred_expand)
        !           314:                                || (!fred_subdisplay && !fred_expand))
        !           315:                            fred_long = i == 1;
        !           316:                        else
        !           317:                            fred_long = fred_expand;
        !           318: 
        !           319:                    if (i > 1) {
        !           320:                        EntryInfo **base,
        !           321:                                  **bp,
        !           322:                                  **ep;
        !           323: 
        !           324:                        ps_printf (RPS, "%d matches found.\n", i);
        !           325:                        (void) ps_flush (RPS);
        !           326: 
        !           327:                        if (base = (EntryInfo **) malloc ((unsigned)
        !           328:                                                          (i * sizeof *base))){
        !           329:                            ep = base;
        !           330: 
        !           331:                            qsort ((char *) base, i, sizeof *base, csr_compar);
        !           332: 
        !           333:                            bp = base;
        !           334:                            ptr = result.CSR_entries = *bp++;
        !           335:                            while (bp < ep) {
        !           336:                                ptr -> ent_next = *bp;
        !           337:                                ptr = *bp++;
        !           338:                            }
        !           339:                            ptr -> ent_next = NULL;
        !           340: 
        !           341:                            free ((char *) base);
        !           342:                            didecode = 1;
        !           343:                        }
        !           344:                    }
        !           345: 
        !           346:                    if (fred_expand)
        !           347:                        fred_long = fred_subdisplay = TRUE;
        !           348:                    for (ptr = result.CSR_entries;
        !           349:                             ptr;
        !           350:                             ptr = ptr -> ent_next) {
        !           351:                        if (!didecode)
        !           352: /* not really necessary...
        !           353:                        normalize_dn (&ptr -> ent_dn);
        !           354:  */
        !           355:                        (void) add_sequence (ptr -> ent_dn);
        !           356:                    }
        !           357:                    set_sequence ("default");
        !           358:                    for (i = 0, ptr = result.CSR_entries;
        !           359:                             ptr;
        !           360:                             ptr = ptr -> ent_next, i++) {
        !           361:                        if (i > 0) {
        !           362:                            if (fred_expand)
        !           363:                                ps_print (RPS, "-------\n");
        !           364:                            else
        !           365:                                if (nchild)
        !           366:                                    ps_print (RPS, "\n");
        !           367:                            (void) ps_flush (RPS);
        !           368:                        }
        !           369: 
        !           370:                        cache_entry (ptr, all_flag, value_flag);
        !           371: 
        !           372:                        nchild = showfred (ptr -> ent_dn, fred_long,
        !           373:                                           fred_subdisplay);
        !           374:                    }
        !           375:                } 
        !           376:                else
        !           377:                for (ptr = result.CSR_entries; ptr != NULLENTRYINFO; ptr = ptr->ent_next) {
        !           378:                                /* decode it immediately so we only
        !           379:                                   have to do it once. */
        !           380:                        cache_entry (ptr, all_flag, value_flag);
        !           381:                        seqno = add_sequence (ptr->ent_dn);
        !           382:                        if (seqno != 0)
        !           383:                                ps_printf (RPS,"%-3d ",seqno);
        !           384:                        nvec[1] = "-compact";
        !           385: 
        !           386:                        if (name_flag)
        !           387:                                call_showname (2, nvec);
        !           388:                        else if (seqno != 0)
        !           389:                                ps_print (RPS,"\n");
        !           390: 
        !           391:                        if (flag_show) {
        !           392:                                eptr = ptr->ent_attr;
        !           393:                                for (; eptr != NULLATTR; eptr = eptr->attr_link)
        !           394:                                        showattribute (eptr->attr_type);
        !           395:                        } 
        !           396:                }
        !           397:                if (rel_dn != NULLDN) {
        !           398:                        dn_free (rel_dn);
        !           399:                        rel_dn = NULLDN;
        !           400:                }
        !           401:                dn_free (current_dn);
        !           402:                current_dn = save_dn;
        !           403:                current_entry = save_entry;
        !           404:                entryinfo_free (result.CSR_entries,0);
        !           405:        }
        !           406: 
        !           407:        handle_problems (aps,result.CSR_cr,result.CSR_limitproblem,part_flag);
        !           408:        
        !           409:        filter_free (search_arg.sra_filter);
        !           410: }
        !           411: 
        !           412: static int  csr_compar (a, b)
        !           413: EntryInfo **a,
        !           414:           **b;
        !           415: {
        !           416:     int            i;
        !           417:     DN     adn,
        !           418:            bdn;
        !           419: 
        !           420:     for (adn = (*a) -> ent_dn; adn -> dn_parent; adn = adn -> dn_parent)
        !           421:        continue;
        !           422:     for (bdn = (*b) -> ent_dn; bdn -> dn_parent; bdn = bdn -> dn_parent)
        !           423:        continue;
        !           424: 
        !           425:     i = rdn_cmp (adn -> dn_rdn, bdn -> dn_rdn);
        !           426:     return (i == (-1) || i == 1 ? i : 0);
        !           427: }
        !           428: 
        !           429: handle_problems (aps,cr,limit,proceed)
        !           430: PS aps;
        !           431: ContinuationRef cr;
        !           432: int limit;
        !           433: {
        !           434:        if (! proceed)
        !           435:                return;
        !           436: 
        !           437:        if (limit != LSR_NOLIMITPROBLEM) {
        !           438:                ps_print (aps, "(");
        !           439:                switch (limit) {
        !           440:                case LSR_TIMELIMITEXCEEDED:
        !           441:                        ps_print (aps, flag_show
        !           442:                              ? "Time limit exceeded"
        !           443:                              : "Partial results only--time limit exceeded");
        !           444:                        break;
        !           445:                case LSR_SIZELIMITEXCEEDED:
        !           446:                        ps_print (aps, flag_show
        !           447:                              ? "Size limit exceeded"
        !           448:                              : "Partial results only--size limit exceeded");
        !           449:                        break;
        !           450:                default: /* admin limit */
        !           451:                        ps_print (aps, flag_show
        !           452:                              ? "Admin limit exceeded"
        !           453:                              : "Partial results only--admin limit exceeded");
        !           454:                        break;
        !           455:                }
        !           456:                ps_print (aps, ")\n");
        !           457:                if (! flag_show)
        !           458:                        return;
        !           459:        }
        !           460: 
        !           461:        if (cr != NULLCONTINUATIONREF) {
        !           462:                ContinuationRef crptr;
        !           463:                if (!flag_show) {
        !           464:                        ps_print (aps,"(Partial results only--not all DSAs could be reached)\n");
        !           465:                        return;
        !           466:                }
        !           467:                ps_print (aps, "NOTE partial results only:- could not contact following DSA(s):-\n");
        !           468:                for (crptr=cr; crptr != NULLCONTINUATIONREF; crptr=crptr->cr_next) {
        !           469:                        ps_print (aps,"   ");
        !           470:                        dn_print (aps,crptr->cr_accesspoints->ap_name,EDBOUT);
        !           471:                        ps_print (aps," (holding ");
        !           472:                        dn_print (aps,crptr->cr_name,EDBOUT);
        !           473:                        ps_print (aps,")\n");
        !           474:                }
        !           475:        }
        !           476:                        
        !           477: }

unix.superglobalmegacorp.com

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