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

1.1       root        1: /* aetufn.c - UFN-based DSE */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/dsap/common/RCS/aetufn.c,v 7.1 90/07/09 14:33:49 mrose Exp $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/dsap/common/RCS/aetufn.c,v 7.1 90/07/09 14:33:49 mrose Exp $
                      9:  *
                     10:  *
                     11:  * $Log:       aetufn.c,v $
                     12:  * Revision 7.1  90/07/09  14:33:49  mrose
                     13:  * sync
                     14:  * 
                     15:  * Revision 7.0  90/07/06  23:18:10  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: /* LINTLIBRARY */
                     32: 
                     33: #include "quipu/ufn.h"
                     34: #include "quipu/util.h"
                     35: #include "quipu/read.h"
                     36: #include "quipu/dua.h"
                     37: #include "quipu/bind.h"
                     38: #include "tailor.h"
                     39: 
                     40: extern LLog * addr_log;
                     41: 
                     42: extern char * dn2str();
                     43: extern char * dn2ufn();
                     44: extern struct dn_seq *dn_seq_push ();
                     45: 
                     46: 
                     47: /* ARGSUSED */
                     48: static DNS ufn_interact (dns,dn,s)
                     49: DNS dns;
                     50: DN dn;
                     51: char * s;
                     52: {
                     53: char    buf[LINESIZE];
                     54: DNS result = NULLDNS;
                     55: DNS newdns;
                     56: 
                     57:        if (dns == NULLDNS)
                     58:                return NULLDNS;
                     59: 
                     60:        (void) printf ("Please select from the following (matching '%s'):\n",s);
                     61:        while (dns != NULLDNS) {
                     62:                (void) printf ("  %s [y/n] ? ",dn2ufn(dns->dns_dn,FALSE));
                     63:                (void) fflush (stdout);
                     64: again:;
                     65:                if (gets (buf) == NULL) {
                     66:                        clearerr (stdin);
                     67:                        (void) printf ("\n");
                     68:                        return result;
                     69:                }
                     70: 
                     71:                if ((buf[0] == NULL) 
                     72:                        || (strlen(buf) != 1)
                     73:                        || ((buf[0] != 'y') && (buf[0] != 'n'))) {
                     74:                                (void) printf ("Please type 'y' or 'n': ");
                     75:                                (void) fflush (stdout);
                     76:                                goto again;
                     77:                        }
                     78: 
                     79:                if (buf[0] == 'y') {
                     80:                        newdns = dn_seq_alloc();
                     81:                        newdns->dns_next = result;
                     82:                        newdns->dns_dn = dn_cpy (dns->dns_dn);
                     83:                        result = newdns;
                     84:                        dns = dns->dns_next;
                     85:                } else {
                     86:                        DNS tmp;
                     87:                        tmp = dns;
                     88:                        dns = dns->dns_next;
                     89:                        tmp->dns_next = NULLDNS;
                     90:                        dn_seq_free (tmp);
                     91:                }
                     92:        }
                     93:        return result;
                     94: }
                     95: 
                     96: /* ARGSUSED */
                     97: 
                     98: static DNS just_say_no (dns,dn,s)
                     99: DNS dns;
                    100: DN dn;
                    101: char * s;
                    102: {
                    103:        /* we only want good hits ! */
                    104: 
                    105:        dn_seq_free (dns);
                    106:        SLOG (addr_log, LLOG_NOTICE, NULLCP,
                    107:              ("UFN asked for interactive response -- auto reply of NO"));
                    108:        return NULLDNS;
                    109: }
                    110: 
                    111: static bind_to_dsa ()
                    112: {
                    113:   struct ds_bind_arg bindarg;
                    114:   struct ds_bind_arg bindresult;
                    115:   struct ds_bind_error binderr;
                    116: 
                    117:   bindarg.dba_version = DBA_VERSION_V1988;
                    118: 
                    119:   bindarg.dba_passwd_len = 0;
                    120:   bindarg.dba_passwd [0] = '\0';
                    121:   bindarg.dba_dn = NULLDN;
                    122: 
                    123:   if (ds_bind (&bindarg,&binderr,&bindresult) != DS_OK)
                    124:        return FALSE;
                    125:   else
                    126:        return TRUE;
                    127: }
                    128: 
                    129: static PE name2psap (dn)
                    130: DN dn;
                    131: {
                    132: AttributeType at;
                    133: extern PE grab_pe();
                    134: PE res_pe;
                    135: static struct ds_read_arg read_arg = 
                    136:        {
                    137:                default_common_args,
                    138:                NULLDN,   /* read_arg DN */
                    139:                {       /* entry info selection */
                    140:                        FALSE,
                    141:                        NULLATTR,
                    142:                        EIS_ATTRIBUTESANDVALUES
                    143:                }
                    144:        };
                    145: struct DSError  error;
                    146: struct ds_read_result result;
                    147: 
                    148: 
                    149:        if ( (at = AttrT_new (DSAADDRESS_OID)) == NULLAttrT) {
                    150:                PY_advise (NULLCP, "build of attribute failed: %s",
                    151:                           DSAADDRESS_OID);
                    152: out: ;
                    153:                SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("%s", PY_pepy));
                    154:                return NULLPE;
                    155:        }
                    156: 
                    157:        read_arg.rda_common.ca_servicecontrol.svc_prio = SVC_PRIO_HIGH;
                    158:        read_arg.rda_object = dn;
                    159:        read_arg.rda_eis.eis_select = as_comp_new (AttrT_cpy (at), NULLAV, NULLACL_INFO);
                    160: 
                    161:        if (ds_read (&read_arg,&error,&result) != DS_OK) {
                    162:                PY_advise (NULLCP, "DAP lookup failed: %s",dn2str(dn));
                    163:                log_ds_error (&error);
                    164:                ds_error_free (&error);
                    165:                AttrT_free (at);
                    166:                as_free (read_arg.rda_eis.eis_select);
                    167:                goto out;
                    168:        } else {
                    169:                if (result.rdr_entry.ent_attr == NULLATTR) {
                    170:                        PY_advise (NULLCP, "No '%s' attribute in entry '%s'",
                    171:                                   DSAADDRESS_OID,dn2str(dn));
                    172:                        AttrT_free (at);
                    173:                        as_free (read_arg.rda_eis.eis_select);
                    174:                        goto out;
                    175:                }
                    176:                AttrT_free (at);
                    177:                as_free (read_arg.rda_eis.eis_select);
                    178:                res_pe = grab_pe(&result.rdr_entry.ent_attr->attr_value->avseq_av);
                    179:                as_free (result.rdr_entry.ent_attr);
                    180:                return (res_pe);
                    181:        }
                    182: }
                    183: 
                    184: static char bound = FALSE;
                    185: static char unbind = FALSE;
                    186: static envlist el = NULLEL;
                    187: 
                    188: /* ARGSUSED */
                    189: 
                    190: static PE  name2value_ufn (name, qualifier, context, ontty, real_name)
                    191: char   *name,
                    192:        *qualifier,
                    193:        *context;
                    194: int    ontty;
                    195: PE     *real_name;
                    196: {
                    197: int n;
                    198: char * v[20],buffer[LINESIZE];
                    199: DNS dns = NULLDNS;
                    200: DN *dn;
                    201: PE addr;
                    202: 
                    203:        *real_name = NULLPE;
                    204: 
                    205:        if (el == NULLEL)
                    206:            set_el ();
                    207: 
                    208:        (void) strcpy (buffer, name);
                    209:        if ((n = sstr2arg (buffer,20,v,",")) == NOTOK) {
                    210:            PY_advise (NULLCP, "invalid name");
                    211: out: ;
                    212:            SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("%s", PY_pepy));
                    213:            return NULLPE;
                    214:        }
                    215: 
                    216:        if (! bound) {
                    217:            if (! bind_to_dsa()) {
                    218:                PY_advise (NULLCP, "bind to directory failed");
                    219:                goto out;
                    220:            }
                    221:            bound = TRUE;
                    222:        }
                    223: 
                    224:        PY_pepy[0] = NULL;
                    225:        if ( ! aet_match (n, v, ontty ? ufn_interact : just_say_no, &dns, el,
                    226:                          context)) {
                    227:            if (PY_pepy[0] == NULL) {
                    228:                PY_advise (NULLCP, "unable to resolve name");
                    229:                goto out;
                    230:            }
                    231:            return NULLPE;
                    232:        }
                    233: 
                    234:        if (dns == NULLDNS) {
                    235:            PY_advise (NULLCP, "search failed to find anything");
                    236:            goto out;
                    237:        }
                    238:        dn = NULL;
                    239: 
                    240: 
                    241:        addr = NULLPE;
                    242:        if (dns->dns_next == NULLDNS) {
                    243:                dn = &dns -> dns_dn;
                    244:                addr = name2psap (*dn);
                    245:        }
                    246:        else {
                    247:                /* Multiple hits */
                    248:                /* Continue until one works */
                    249:                if ( ontty ) 
                    250:                        (void) dnSelect (name,&dns,ufn_interact,el->Dns);
                    251: 
                    252:                for (; dns!= NULLDNS; dns=dns->dns_next) {
                    253:                        dn = &dns -> dns_dn;
                    254:                        if (addr = name2psap (*dn))
                    255:                                break;
                    256:                }
                    257:        }
                    258: 
                    259:        if (*dn) {
                    260:            (void) encode_IF_DistinguishedName (real_name, 1, 0, NULLCP, *dn);
                    261:            *dn = NULLDN;
                    262:        }
                    263:        dn_seq_free (dns);
                    264: 
                    265:        if (unbind) {
                    266:            bound = FALSE;
                    267:            ds_unbind ();
                    268:        }
                    269: 
                    270:        return addr;
                    271: }
                    272: 
                    273: 
                    274: static set_el ()
                    275: {
                    276:     register envlist  en,
                    277:                     *ep;
                    278:     DN     local_dn,
                    279:            c_dn;
                    280:     static int  inited = FALSE;
                    281:     extern char *local_dit;
                    282: 
                    283:     if (!inited) {
                    284:        quipu_syntaxes ();
                    285:        dsap_init ((int *)0,(char ***)0);
                    286:        inited = TRUE;
                    287:     }
                    288:     if (el = read_envlist ())
                    289:        return;
                    290: 
                    291:     if (local_dn = str2dn (local_dit)) {
                    292:        DN      dn = local_dn -> dn_parent;
                    293: 
                    294:        local_dn -> dn_parent = NULLDN;
                    295:        c_dn = dn_cpy (local_dn);
                    296:        local_dn -> dn_parent = dn;
                    297:     }
                    298: 
                    299:     ep = ⪙
                    300: 
                    301:     if ((en = (envlist) calloc (1, sizeof **ep)) == NULL) {
                    302: no_mem: ;
                    303:        SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("out of memory"));
                    304:        if (el) {
                    305:            for (; el; el = en) {
                    306:                en = el -> Next;
                    307: 
                    308:                dn_seq_free (el -> Dns);
                    309:                free ((char *) el);
                    310:            }
                    311: 
                    312:            el = NULLEL;
                    313:        }
                    314:        goto done;
                    315:     }
                    316:     *ep = en, ep = &en -> Next;
                    317:     en -> Dns =
                    318:        dn_seq_push (local_dn,
                    319:                     dn_seq_push (c_dn, dn_seq_push (NULLDN, NULLDNSEQ)));
                    320:     en -> Upper = en -> Lower = 1;
                    321: 
                    322:     if ((en = (envlist) calloc (1, sizeof **ep)) == NULL)
                    323:        goto no_mem;
                    324:     *ep = en, ep = &en -> Next;
                    325:     en -> Dns =
                    326:        dn_seq_push (c_dn,
                    327:                     dn_seq_push (local_dn, dn_seq_push (NULLDN, NULLDNSEQ)));
                    328:     en -> Upper = en -> Lower = 2;
                    329: 
                    330:     if ((en = (envlist) calloc (1, sizeof **ep)) == NULL)
                    331:        goto no_mem;
                    332:     *ep = en, ep = &en -> Next;
                    333:     en -> Dns =
                    334:        dn_seq_push (NULLDN,
                    335:                     dn_seq_push (c_dn, dn_seq_push (local_dn, NULLDNSEQ)));
                    336:     en -> Upper = 32767, en -> Lower = 3;
                    337: 
                    338: done: ;
                    339:     dn_free (local_dn);
                    340:     dn_free (c_dn);
                    341: }
                    342: 
                    343: set_lookup_ufn (flag)
                    344: char   flag;   /* if TRUE always unbind */
                    345: {
                    346:     unbind = flag;
                    347: 
                    348:     acsap_lookup = name2value_ufn;
                    349: 
                    350:     if (el == NULLEL)
                    351:        set_el ();
                    352: }
                    353: 
                    354: 
                    355: #ifdef STANDALONE_AET_TEST
                    356: 
                    357: main (argc,argv)
                    358: int argc;
                    359: char ** argv;
                    360: {
                    361: char buffer [1024];
                    362: int ontty, n;
                    363: PE title, paddr;
                    364: 
                    365:        buffer[0] = NULL;
                    366: 
                    367:        ontty = isatty (fileno (stdin));
                    368:        for (n=1; n<argc; n++) {
                    369:                (void) strcat (buffer," ");
                    370:                (void) strcat (buffer, argv[n]);
                    371:        }
                    372: 
                    373:        isodetailor ("ufn_aet",1);
                    374: 
                    375:        quipu_syntaxes ();
                    376:        dsap_init ((int *)0,(char ***)0);
                    377: 
                    378:        addr_log -> ll_events |= LLOG_ALL, addr_log -> ll_stat |= LLOGTTY;
                    379: 
                    380:        if (pe = name2value_ufn (buffer, "iso ftam", ontty, &title)) {
                    381:            struct PSAPaddr pas;
                    382: 
                    383:            if (parse_DSE_PSAPaddr (pe, 1, NULLIP, NULLVP, (char *) &pas)
                    384:                    == NOTOK)
                    385:                fprintf (stderr, "parse of presentation address failed: %s",
                    386:                         PY_pepy);
                    387:            else
                    388:                printf ("%s\n", paddr2str (&pas));
                    389:        }
                    390:        else
                    391:            fprintf (stderr, "directory returns no value");
                    392: 
                    393:        if (title) {
                    394:            printf ("AETitle\n");
                    395:            vunknown (title);
                    396:        }
                    397: 
                    398:        exit (0);
                    399: }
                    400: 
                    401: advise ()
                    402: {
                    403: ;
                    404: }
                    405: 
                    406: #endif

unix.superglobalmegacorp.com

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