Annotation of 43BSDReno/contrib/isode-beta/acsap/dased.c, revision 1.1

1.1     ! root        1: /* dased.c - stand-alone DASE */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/acsap/RCS/dased.c,v 7.2 90/07/27 08:41:41 mrose Exp $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/acsap/RCS/dased.c,v 7.2 90/07/27 08:41:41 mrose Exp $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       dased.c,v $
        !            12:  * Revision 7.2  90/07/27  08:41:41  mrose
        !            13:  * update
        !            14:  * 
        !            15:  * Revision 7.1  90/07/09  14:30:57  mrose
        !            16:  * sync
        !            17:  * 
        !            18:  * Revision 7.0  90/07/07  16:11:31  mrose
        !            19:  * *** empty log message ***
        !            20:  * 
        !            21:  */
        !            22: 
        !            23: /*
        !            24:  *                               NOTICE
        !            25:  *
        !            26:  *    Acquisition, use, and distribution of this module and related
        !            27:  *    materials are subject to the restrictions of a license agreement.
        !            28:  *    Consult the Preface in the User's Manual for the full terms of
        !            29:  *    this agreement.
        !            30:  *
        !            31:  */
        !            32: 
        !            33: 
        !            34: #include <signal.h>
        !            35: #include <stdio.h>
        !            36: #include <varargs.h>
        !            37: #include "manifest.h"
        !            38: #include <sys/ioctl.h>
        !            39: #ifdef BSD42
        !            40: #include <sys/file.h>
        !            41: #endif
        !            42: #ifdef SYS5
        !            43: #include <fcntl.h>
        !            44: #endif
        !            45: #include "DASE-types.h"
        !            46: #include "psap.h"
        !            47: #include "tsap.h"
        !            48: #include "dgram.h"
        !            49: #include "tailor.h"
        !            50: 
        !            51: #include "quipu/ufn.h"
        !            52: #include "quipu/util.h"
        !            53: #include "quipu/read.h"
        !            54: #include "quipu/dua.h"
        !            55: #include "quipu/bind.h"
        !            56: 
        !            57: /*  */
        !            58: 
        !            59: static int debug = 0;
        !            60: static int nbits = FD_SETSIZE;
        !            61: 
        !            62: static LLog _pgm_log = {
        !            63:        "dased.log", NULLCP,    NULLCP,
        !            64:        LLOG_FATAL | LLOG_EXCEPTIONS | LLOG_NOTICE, LLOG_FATAL,
        !            65:        -1, LLOGCLS | LLOGCRT | LLOGZER, NOTOK
        !            66: };
        !            67: 
        !            68: static LLog    *pgm_log = &_pgm_log;
        !            69: 
        !            70: static char    *myname = "dased";
        !            71: 
        !            72: static struct TSAPaddr tas;
        !            73: 
        !            74: static int     isbound = 0;
        !            75: extern int     dsap_ad;
        !            76: static PS      ps;
        !            77: static PS      nps;
        !            78: 
        !            79: 
        !            80: int    dns_compar ();
        !            81: DNS    dase_interact (), just_say_no ();
        !            82: PE     name2psap ();
        !            83: 
        !            84: void   adios (), advise (), ts_adios (), ts_advise ();
        !            85: 
        !            86: 
        !            87: char   *dn2str ();
        !            88: PE     grab_pe ();
        !            89: 
        !            90: /*  */
        !            91: 
        !            92: /* ARGSUSED */
        !            93: 
        !            94: main (argc, argv, envp)
        !            95: int    argc;
        !            96: char   **argv,
        !            97:         **envp;
        !            98: {
        !            99:     int            vecp;
        !           100:     char   *vec[4];
        !           101:     struct TSAPdisconnect   tds;
        !           102:     register struct TSAPdisconnect  *td = &tds;
        !           103: 
        !           104:     arginit (argv);
        !           105:     envinit ();
        !           106: 
        !           107:     advise (LLOG_NOTICE, NULLCP, "listening on %s", taddr2str (&tas));
        !           108:     if (TNetListen (&tas, td) == NOTOK)
        !           109:        ts_adios (td, "TNetListen failed");
        !           110: 
        !           111:     for (;;) {
        !           112:        int     nfds,
        !           113:                secs;
        !           114:        fd_set  ifds,
        !           115:               *rfds;
        !           116: 
        !           117:        if (!isbound)
        !           118:            (void) bind_to_dsa ();
        !           119: 
        !           120:        if (isbound) {
        !           121:            rfds = &ifds;
        !           122: 
        !           123:            nfds = dsap_ad + 1;
        !           124:            
        !           125:            FD_ZERO (rfds);
        !           126:            FD_SET (dsap_ad, rfds);
        !           127: 
        !           128:            secs = NOTOK;
        !           129:        }
        !           130:        else
        !           131:            nfds = 0, rfds = NULLFD, secs = 5 * 60L;
        !           132: 
        !           133:        if (TNetAcceptAux (&vecp, vec, NULLIP, NULLTA, nfds, rfds, NULLFD,
        !           134:                           NULLFD, secs, td) == NOTOK) {
        !           135:            ts_advise (td, LLOG_EXCEPTIONS, "TNetAccept failed");
        !           136:            continue;
        !           137:        }
        !           138: 
        !           139:        if (rfds && FD_ISSET (dsap_ad, rfds)) { /* DSA timed us out... */
        !           140:            if (debug)
        !           141:                advise (LLOG_DEBUG, NULLCP, "unbound from directory");
        !           142: 
        !           143:            (void) ds_unbind ();
        !           144:            isbound = 0;
        !           145:        }
        !           146: 
        !           147:        if (vecp <= 0)
        !           148:            continue;
        !           149: 
        !           150:        switch (TNetFork (vecp, vec, td)) {
        !           151:            case OK:
        !           152:                ll_hdinit (pgm_log, myname);
        !           153:                dased (vecp, vec);
        !           154:                exit (1);
        !           155:                /* NOTREACHED */
        !           156: 
        !           157:            case NOTOK:
        !           158:                ts_advise (td, LLOG_EXCEPTIONS, "TNetFork failed");
        !           159:                break;
        !           160: 
        !           161:            default:
        !           162:                if (isbound) {
        !           163:                    if (dsap_ad != NOTOK)
        !           164:                        (void) close (dsap_ad);
        !           165:                    isbound = 0;
        !           166:                }
        !           167:                break;
        !           168:        }
        !           169:     }
        !           170: }
        !           171: 
        !           172: /*    DASE */
        !           173: 
        !           174: static dased (vecp, vec)
        !           175: int    vecp;
        !           176: char  **vec;
        !           177: {
        !           178:     int            sd;
        !           179:     struct TSAPstart tss;
        !           180:     register struct TSAPstart *ts = &tss;
        !           181:     struct TSAPdisconnect   tds;
        !           182:     register struct TSAPdisconnect  *td = &tds;
        !           183: 
        !           184:     if (TInit (vecp, vec, ts, td) == NOTOK)
        !           185:        ts_adios (td, "T-CONNECT.INDICATION failed");
        !           186: 
        !           187:     sd = ts -> ts_sd;
        !           188:     advise (LLOG_NOTICE, NULLCP, "T-CONNECT.INDICATION: <%d, %s, %s, %d, %d>",
        !           189:            ts -> ts_sd, taddr2str (&ts -> ts_calling),
        !           190:            taddr2str (&ts -> ts_called), ts -> ts_expedited,
        !           191:            ts -> ts_tsdusize);
        !           192: 
        !           193:     if (TConnResponse (sd, NULLTA, 0, NULLCP, 0, NULLQOS, td) == NOTOK)
        !           194:        ts_adios (td, "T-CONNECT.RESPONSE failed");
        !           195: 
        !           196:     if ((ps = ps_alloc (dg_open)) == NULLPS)
        !           197:        adios (NULLCP, "ps_alloc: out of memory");
        !           198:     if (dg_setup (ps, sd, MAXDGRAM, ts_read, ts_write) == NOTOK)
        !           199:        adios (NULLCP, "dg_setup: %s", ps_error (ps -> ps_errno));
        !           200: 
        !           201:     for (;;) {
        !           202:        struct type_DASE_Query__REQ *req;
        !           203:        PE      pe;
        !           204: 
        !           205:        if (!isbound)
        !           206:            (void) bind_to_dsa ();
        !           207:     
        !           208:        if ((pe = ps2pe (ps)) == NULLPE) {
        !           209:            if (ps -> ps_errno == PS_ERR_NONE) {
        !           210:                advise (LLOG_NOTICE, NULLCP, "T-DISCONNECT.INDICATION");
        !           211:                break;
        !           212:            }
        !           213:            else
        !           214:                adios (NULLCP, "ps2pe: %s", ps_error (ps -> ps_errno));
        !           215:        }
        !           216: 
        !           217:        if (decode_DASE_Query__REQ (pe, 1, NULLIP, NULLVP, &req) == NOTOK)
        !           218:            adios (NULLCP, "decode_DASE_Query__REQ: %s", PY_pepy);
        !           219:        PLOGP (pgm_log,DASE_Message, pe, "message", 1);
        !           220: 
        !           221:        dase_aux (req);
        !           222: 
        !           223:        free_DASE_Query__REQ (req);
        !           224:        pe_free (pe);
        !           225:     }
        !           226: 
        !           227:     if (isbound) {
        !           228:        if (debug)
        !           229:            advise (LLOG_DEBUG, NULLCP, "unbound from directory");
        !           230: 
        !           231:        (void) ds_unbind ();
        !           232:     }
        !           233: 
        !           234:     exit (0);
        !           235: }
        !           236: 
        !           237: /*  */
        !           238: 
        !           239: static dase_aux (req)
        !           240: register struct type_DASE_Query__REQ *req;
        !           241: {
        !           242:     register int    i;
        !           243:     int            vecp;
        !           244:     register char **vp;
        !           245:     char   *context,
        !           246:          **vec;
        !           247:     register struct type_DASE_Query__RSP *rsp;
        !           248:     register struct element_DASE_0 *d0;
        !           249:     register struct element_DASE_1 *d1;
        !           250:     envlist el;
        !           251:     register envlist  en,
        !           252:                     *ep;
        !           253:     DN    *dn;
        !           254:     DNS            dns;
        !           255:     PE     pe;
        !           256: 
        !           257:     if ((rsp = (struct type_DASE_Query__RSP *) calloc (1, sizeof *rsp))
        !           258:            == NULL) {
        !           259: no_mem: ;
        !           260:        adios (NULLCP, "out of memory");
        !           261:     }
        !           262: 
        !           263:     vec = NULL, el = NULL, context = NULL, dns = NULL;
        !           264:     if (!isbound)
        !           265:        goto send_rsp;
        !           266: 
        !           267:     i = 1;
        !           268:     for (d0 = req -> name; d0; d0 = d0 -> next)
        !           269:        i++;
        !           270:     if ((vec = (char **) calloc ((unsigned) i, sizeof *vec)) == NULL)
        !           271:        goto no_mem;
        !           272:     for (vp = vec, d0 = req -> name; d0; vp++, d0 = d0 -> next)
        !           273:        if ((*vp = qb2str (d0 -> IA5String)) == NULL)
        !           274:            goto no_mem;
        !           275:     vecp = i - 1;
        !           276: 
        !           277:     el = NULL, ep = &el;
        !           278:     for (d1 = req -> envlist; d1; d1 = d1 -> next) {
        !           279:        struct type_DASE_Environment *ev = d1 -> Environment;
        !           280:        register struct element_DASE_2 *d2;
        !           281:        register struct dn_seq **dp;
        !           282: 
        !           283:        if ((en = (envlist) calloc (1, sizeof *en)) == NULL)
        !           284:            goto no_mem;
        !           285:        *ep = en, ep = &en -> Next;
        !           286: 
        !           287:        en -> Upper = ev -> upper;
        !           288:        en -> Lower = ev -> lower;
        !           289: 
        !           290:        dp = &en -> Dns;
        !           291:        for (d2 = ev -> path; d2; d2 = d2 -> next) {
        !           292:            char   *cp;
        !           293:            register struct dn_seq *ds;
        !           294: 
        !           295:            if ((ds = (struct dn_seq *) calloc (1, sizeof *ds)) == NULL)
        !           296:                goto no_mem;
        !           297:            *dp = ds, dp = &ds -> dns_next;
        !           298: 
        !           299:            if ((cp = qb2str (d2 -> IA5String)) == NULL)
        !           300:                goto no_mem;
        !           301:            if (*cp != '-')
        !           302:                ds -> dns_dn = str2dn (cp);
        !           303:            free (cp);
        !           304: 
        !           305:            if (*cp != '-' && ds -> dns_dn == NULLDN) {
        !           306:                PY_advise (NULLCP, "bad DN in environment: %s", cp);
        !           307:                goto send_rsp;
        !           308:            }
        !           309:        }
        !           310:     }
        !           311: 
        !           312:     if ((context = qb2str (req -> context)) == NULL)
        !           313:        goto no_mem;
        !           314: 
        !           315:     PY_pepy[0] = NULL;
        !           316:     if (!aet_match (vecp, vec, req -> interactive ? dase_interact
        !           317:                                                  : just_say_no,
        !           318:                    &dns, el, context)) {
        !           319:        if (PY_pepy[0] == NULL)
        !           320:            PY_advise (NULLCP, "unable to resolve name");
        !           321:        goto send_rsp;
        !           322:     }
        !           323: 
        !           324:     if (dns == NULL) {
        !           325:        PY_advise (NULLCP, "search failed to find anything");
        !           326:        goto send_rsp;
        !           327:     }
        !           328:     dn = NULL;
        !           329: 
        !           330:     pe = NULLPE;
        !           331:     if (dns -> dns_next) {
        !           332:        if (req -> interactive)
        !           333:            (void) dnSelect (vec[0], &dns, dase_interact, el -> Dns);
        !           334: 
        !           335:        for (; dns; dns = dns -> dns_next) {
        !           336:            dn = &dns -> dns_dn;
        !           337:            if (rsp -> value = name2psap (*dn))
        !           338:                break;
        !           339:        }
        !           340:     }
        !           341:     else {
        !           342:        dn = &dns -> dns_dn;
        !           343:        rsp -> value = name2psap (*dn);
        !           344:     }
        !           345: 
        !           346:     if (*dn) {
        !           347:        (void) encode_IF_DistinguishedName (&rsp -> name, 1, NULL, NULLCP,*dn);
        !           348: 
        !           349:        ufn_dn_print_aux (nps, *dn, NULLDN, 0);
        !           350:        ps_print (nps, " ");
        !           351:        *--nps -> ps_ptr = NULL, nps -> ps_cnt++;
        !           352: 
        !           353:        rsp -> friendly = str2qb (nps -> ps_base, strlen (nps -> ps_base), 1);
        !           354: 
        !           355:        nps -> ps_ptr = nps -> ps_base, nps -> ps_cnt = nps -> ps_bufsiz;
        !           356: 
        !           357:        *dn = NULLDN;
        !           358:     }
        !           359: 
        !           360: send_rsp: ;
        !           361:     if (PY_pepy[0]) {
        !           362:        advise (LLOG_NOTICE, NULLCP, "diagnostic: %s", PY_pepy);
        !           363: 
        !           364:        if ((rsp -> diagnostic = str2qb (PY_pepy, strlen (PY_pepy), 1))
        !           365:                == NULL)
        !           366:            goto no_mem;
        !           367:     }
        !           368: 
        !           369:     if (encode_DASE_Query__RSP (&pe, 1, NULL, NULLCP, rsp) == NOTOK)
        !           370:        adios (NULLCP, "encode_DASE_Query__RSP: %s", PY_pepy);
        !           371:     if (pe2ps (ps, pe) == NOTOK)
        !           372:        adios (NULLCP, "pe2ps: %s", ps_error (ps -> ps_errno));
        !           373:     PLOGP (pgm_log,DASE_Message, pe, "message", 0);
        !           374: 
        !           375:     free_DASE_Query__RSP (rsp);
        !           376:     pe_free (pe);
        !           377: 
        !           378:     if (vec) {
        !           379:        for (vp = vec; *vp; vp++)
        !           380:            free (*vp);
        !           381:        free ((char *) vec);
        !           382:     }
        !           383: 
        !           384:     for (; el; el = en) {
        !           385:        en = el -> Next;
        !           386: 
        !           387:        dn_seq_free (el -> Dns);
        !           388:        free ((char *) el);
        !           389:     }
        !           390: 
        !           391:     if (context)
        !           392:        free (context);
        !           393: 
        !           394:     if (dns)
        !           395:        dn_seq_free (dns);
        !           396: }
        !           397: 
        !           398: /*  */
        !           399: 
        !           400: static bind_to_dsa ()
        !           401: {
        !           402:     struct ds_bind_arg ba;
        !           403:     struct ds_bind_arg br;
        !           404:     struct ds_bind_error be;
        !           405:     static int inited = FALSE;
        !           406: 
        !           407:     if (!inited) {
        !           408:        quipu_syntaxes ();
        !           409:        dsap_init ((int *) 0, (char ***) 0);
        !           410:        inited = TRUE;
        !           411:     }
        !           412: 
        !           413:     bzero ((char *) &ba, sizeof ba);
        !           414: 
        !           415:     isbound = 1;
        !           416:     if (ds_bind (&ba, &be, &br) == DS_OK) {
        !           417:        if (debug)
        !           418:            advise (LLOG_DEBUG, NULLCP, "bound to directory");
        !           419: 
        !           420:        return OK;
        !           421:     }
        !           422: 
        !           423:     PY_advise (NULLCP, "unable to bind to directory: %s",
        !           424:               be.dbe_type == DBE_TYPE_SECURITY ? "security error"
        !           425:                                                : "DSA unavailable");
        !           426:     advise (LLOG_EXCEPTIONS, NULLCP, "%s", PY_pepy);
        !           427: 
        !           428:     isbound = 0;
        !           429: 
        !           430:     return NOTOK;
        !           431: }
        !           432: 
        !           433: /*  */
        !           434: 
        !           435: static DNS  dase_interact (dns, dn, s)
        !           436: DNS    dns;
        !           437: DN     dn;
        !           438: char   *s;
        !           439: {
        !           440:     register int i;
        !           441:     register struct type_DASE_Callback__REQ *req = NULL;
        !           442:     register struct element_DASE_3 **dp;
        !           443:     struct type_DASE_Callback__RSP *rsp = NULL;
        !           444:     register struct type_DASE_Callback__RSP *rp;
        !           445:     DNS            ds,
        !           446:           *dq;
        !           447:     PE     pe = NULLPE;
        !           448: 
        !           449:     if (dns == NULLDNS)
        !           450:        return NULL;
        !           451: 
        !           452:     i = 0;
        !           453:     for (ds = dns; ds; ds = ds -> dns_next)
        !           454:        i++;
        !           455: 
        !           456:     if (i > 1) {
        !           457:        struct dn_seq **base,
        !           458:                      **bp,
        !           459:                      **ep;
        !           460: 
        !           461:        if (base = (struct dn_seq **) malloc ((unsigned) (i * sizeof *base))) {
        !           462:            ep = base;
        !           463:            for (ds = dns; ds; ds = ds -> dns_next)
        !           464:                *ep++ = ds;
        !           465: 
        !           466:            qsort ((char *) base, i, sizeof *base, dns_compar);
        !           467: 
        !           468:            bp = base;
        !           469:            ds = dns = *bp++;
        !           470:            while (bp < ep) {
        !           471:                ds -> dns_next = *bp;
        !           472:                ds = *bp++;
        !           473:            }
        !           474:            ds -> dns_next = NULL;
        !           475: 
        !           476:            free ((char *) base);
        !           477:        }
        !           478:     }
        !           479: 
        !           480:     if ((req = (struct type_DASE_Callback__REQ *) calloc (1, sizeof *req))
        !           481:            == NULL) {
        !           482: no_mem: ;
        !           483:         advise (LLOG_EXCEPTIONS, NULLCP, "out of memory");
        !           484: out: ;
        !           485:        if (req)
        !           486:            free_DASE_Callback__REQ (req);
        !           487:        if (rsp)
        !           488:            free_DASE_Callback__RSP (rsp);
        !           489:        if (pe)
        !           490:            pe_free (pe);
        !           491: 
        !           492:        dn_seq_free (dns);
        !           493:        return NULL;
        !           494:     }
        !           495:     if ((req -> string = str2qb (s, strlen (s), 1)) == NULL)
        !           496:        goto no_mem;
        !           497:     
        !           498:     dp = &req -> choices;
        !           499:     for (; dns; dns = ds) {
        !           500:        register struct element_DASE_3 *d3;
        !           501:        register struct type_DASE_Pair *pair;
        !           502: 
        !           503:        if ((d3 = (struct element_DASE_3 *) calloc (1, sizeof *d3)) == NULL)
        !           504:            goto no_mem;
        !           505:        *dp = d3, dp = &d3 -> next;
        !           506: 
        !           507:        if ((pair = (struct type_DASE_Pair *) calloc (1, sizeof *pair))
        !           508:                == NULL)
        !           509:            goto no_mem;
        !           510:        d3 -> Pair = pair;
        !           511: 
        !           512:        dn_print (nps, dns -> dns_dn, EDBOUT);
        !           513:        ps_print (nps, " ");
        !           514:        *--nps -> ps_ptr = NULL, nps -> ps_cnt++;
        !           515: 
        !           516:        pair -> complete = str2qb (nps -> ps_base, strlen (nps -> ps_base), 1);
        !           517:        
        !           518:        nps -> ps_ptr = nps -> ps_base, nps -> ps_cnt = nps -> ps_bufsiz;
        !           519:        
        !           520:        ufn_dn_print_aux (nps, dns -> dns_dn, dn, 0);
        !           521:        ps_print (nps, " ");
        !           522:        *--nps -> ps_ptr = NULL, nps -> ps_cnt++;
        !           523: 
        !           524:        pair -> friendly = str2qb (nps -> ps_base, strlen (nps -> ps_base), 1);
        !           525: 
        !           526:        nps -> ps_ptr = nps -> ps_base, nps -> ps_cnt = nps -> ps_bufsiz;
        !           527:        
        !           528:        if (pair -> complete == NULL || pair -> friendly == NULL)
        !           529:            goto no_mem;
        !           530: 
        !           531:        ds = dns -> dns_next;
        !           532: 
        !           533:        dn_free (dns -> dns_dn);
        !           534:        free ((char *) dns);
        !           535:     }
        !           536: 
        !           537:     dns = NULL;
        !           538: 
        !           539:     if (encode_DASE_Callback__REQ (&pe, 1, NULL, NULLCP, req) == NOTOK) {
        !           540:        advise (LLOG_EXCEPTIONS, NULLCP, "encode_DASE_Callback__REQ: %s",
        !           541:                PY_pepy);
        !           542:        goto out;
        !           543:     }
        !           544:     if (pe2ps (ps, pe) == NOTOK)
        !           545:        adios (NULLCP, "pe2ps: %s", ps_error (ps -> ps_errno));
        !           546:     PLOGP (pgm_log,DASE_Message, pe, "message", 0);
        !           547: 
        !           548:     free_DASE_Callback__REQ (req);
        !           549:     req = NULL;
        !           550:     pe_free (pe);
        !           551: 
        !           552:     if ((pe = ps2pe (ps)) == NULLPE)
        !           553:        adios (NULLCP, "ps2pe: %s", ps_error (ps -> ps_errno));
        !           554: 
        !           555:     if (decode_DASE_Callback__RSP (pe, 1, NULLIP, NULLVP, &rsp) == NOTOK) {
        !           556:        advise (LLOG_EXCEPTIONS, NULLCP, "decode_DASE_Callback__RSP: %s",
        !           557:                PY_pepy);
        !           558:        goto out;
        !           559:     }
        !           560:     PLOGP (pgm_log,DASE_Message, pe, "message", 1);
        !           561: 
        !           562:     dq = &dns;
        !           563:     for (rp = rsp; rp; rp = rp -> next) {
        !           564:        char   *cp;
        !           565: 
        !           566:        if ((ds = (struct dn_seq *) calloc (1, sizeof *ds)) == NULL)
        !           567:            goto no_mem;
        !           568:        *dq = ds, dq = &ds -> dns_next;
        !           569: 
        !           570:        if ((cp = qb2str (rp -> IA5String)) == NULL)
        !           571:            goto no_mem;
        !           572:        ds -> dns_dn = str2dn (cp);
        !           573:        free (cp);
        !           574:     }
        !           575: 
        !           576:     free_DASE_Callback__RSP (rsp);
        !           577:     pe_free (pe);
        !           578: 
        !           579:     return dns;
        !           580: }
        !           581: 
        !           582: /*  */
        !           583: 
        !           584: static int     dns_compar (a, b)
        !           585: struct dn_seq **a,
        !           586:              **b;
        !           587: {
        !           588:     int            i;
        !           589:     DN     adn,
        !           590:            bdn;
        !           591: 
        !           592:     for (adn = (*a) -> dns_dn; adn -> dn_parent; adn = adn -> dn_parent)
        !           593:        continue;
        !           594:     for (bdn = (*b) -> dns_dn; bdn -> dn_parent; bdn = bdn -> dn_parent)
        !           595:        continue;
        !           596: 
        !           597:     i = rdn_cmp (adn -> dn_rdn, bdn -> dn_rdn);
        !           598:     return (i == (-1) || i == 1 ? i : 0);
        !           599: }
        !           600: 
        !           601: /*  */
        !           602: 
        !           603: /* ARGSUSED */
        !           604: 
        !           605: static DNS  just_say_no (dns, dn, s)
        !           606: DNS    dns;
        !           607: DN     dn;
        !           608: char   *s;
        !           609: {
        !           610:     dn_seq_free (dns);
        !           611: 
        !           612:     return NULL;
        !           613: }
        !           614: 
        !           615: /*  */
        !           616: 
        !           617: static PE  name2psap (dn)
        !           618: DN     dn;
        !           619: {
        !           620:     int            i;
        !           621:     AttributeType at;
        !           622:     PE     pe;
        !           623: static struct ds_read_arg read_arg = 
        !           624:        {
        !           625:                default_common_args,
        !           626:                NULLDN,   /* read_arg DN */
        !           627:                {       /* entry info selection */
        !           628:                        FALSE,
        !           629:                        NULLATTR,
        !           630:                        EIS_ATTRIBUTESANDVALUES
        !           631:                }
        !           632:        };
        !           633:     struct DSError  error;
        !           634:     struct ds_read_result result;
        !           635: 
        !           636:     if ((at = AttrT_new (DSAADDRESS_OID)) == NULLAttrT) {
        !           637:        PY_advise (NULLCP, "build of attribute failed: %s", DSAADDRESS_OID);
        !           638:        return NULLPE;
        !           639:     }
        !           640: 
        !           641:     read_arg.rda_common.ca_servicecontrol.svc_prio = SVC_PRIO_HIGH;
        !           642:     read_arg.rda_object = dn;
        !           643:     read_arg.rda_eis.eis_select = as_comp_new (AttrT_cpy (at), NULLAV,
        !           644:                                               NULLACL_INFO);
        !           645: 
        !           646:     i = ds_read (&read_arg, &error, &result);
        !           647: 
        !           648:     AttrT_free (at);
        !           649:     as_free (read_arg.rda_eis.eis_select);
        !           650: 
        !           651:     if (i != DS_OK) {
        !           652:        PY_advise (NULLCP, "DAP lookup failed: %s", dn2str (dn));
        !           653:        return NULLPE;
        !           654:     }
        !           655: 
        !           656:     if (result.rdr_entry.ent_attr == NULLATTR) {
        !           657:        PY_advise (NULLCP, "no '%s' attribute in entry '%s'",
        !           658:                   DSAADDRESS_OID, dn2str (dn));
        !           659:        return NULLPE;
        !           660:     }
        !           661: 
        !           662:     pe = grab_pe (&result.rdr_entry.ent_attr -> attr_value -> avseq_av);
        !           663:     as_free (result.rdr_entry.ent_attr);
        !           664:     return pe;
        !           665: }
        !           666: 
        !           667: /*    INIT */
        !           668: 
        !           669: static arginit (vec)
        !           670: char   **vec;
        !           671: {
        !           672:     register char   *ap;
        !           673:     register struct TSAPaddr *ta = NULL;
        !           674: 
        !           675:     if (myname = rindex (*vec, '/'))
        !           676:        myname++;
        !           677:     if (myname == NULL || *myname == NULL)
        !           678:        myname = *vec;
        !           679: 
        !           680:     isodetailor (myname, 0);
        !           681:     ll_hdinit (pgm_log, myname);
        !           682: 
        !           683:     for (vec++; ap = *vec; vec++) {
        !           684:        if (*ap == '-')
        !           685:            switch (*++ap) {
        !           686:                case 'a':
        !           687:                    if ((ap = *++vec) == NULL || *ap == '-')
        !           688:                        adios (NULLCP, "usage: %s -a address", myname);
        !           689:                    if ((ta = str2taddr (ap)) == NULLTA)
        !           690:                        adios (NULLCP, "basd address \"%s\"", ap);
        !           691:                    continue;
        !           692: 
        !           693:                case 'd':
        !           694:                    debug++;
        !           695:                    continue;
        !           696: 
        !           697:                default:
        !           698:                    adios (NULLCP, "unknown switch -%s", ap);
        !           699:            }
        !           700: 
        !           701:        adios (NULLCP, "usage: %s [switches]", myname);
        !           702:     }
        !           703: 
        !           704:     if (ta == NULL && (ta = str2taddr (ns_address)) == NULLTA)
        !           705:        adios (NULLCP, "bad default address \"%s\"", ns_address);
        !           706:     tas = *ta;         /* struct copy */
        !           707: 
        !           708:     if ((nps = ps_alloc (str_open)) == NULLPS)
        !           709:        adios (NULLCP, "ps_alloc: out of memory");
        !           710:     if (str_setup (nps, NULLCP, 0, 0) == NOTOK)
        !           711:        adios (NULLCP, "str_setup: %s", ps_error (ps -> ps_errno));
        !           712: }
        !           713: 
        !           714: /*  */
        !           715: 
        !           716: static envinit () {
        !           717:     int     i,
        !           718:            sd;
        !           719: 
        !           720:     nbits = getdtablesize ();
        !           721: 
        !           722:     if (debug == 0 && !(debug = isatty (2))) {
        !           723:        for (i = 0; i < 5; i++) {
        !           724:            switch (fork ()) {
        !           725:                case NOTOK:
        !           726:                    sleep (5);
        !           727:                    continue;
        !           728:                
        !           729:                case OK:
        !           730:                    break;
        !           731: 
        !           732:                default:
        !           733:                    _exit (0);
        !           734:                }
        !           735:            break;
        !           736:        }
        !           737: 
        !           738:        (void) chdir ("/");
        !           739: 
        !           740:        if ((sd = open ("/dev/null", O_RDWR)) == NOTOK)
        !           741:            adios ("/dev/null", "unable to read");
        !           742:        if (sd != 0)
        !           743:            (void) dup2 (sd, 0), (void) close (sd);
        !           744:        (void) dup2 (0, 1);
        !           745:        (void) dup2 (0, 2);
        !           746: 
        !           747: #ifdef SETSID
        !           748:        if (setsid () == NOTOK)
        !           749:            advise (LLOG_EXCEPTIONS, "failed", "setsid");
        !           750: #endif
        !           751: #ifdef  TIOCNOTTY
        !           752:        if ((sd = open ("/dev/tty", O_RDWR)) != NOTOK) {
        !           753:            (void) ioctl (sd, TIOCNOTTY, NULLCP);
        !           754:            (void) close (sd);
        !           755:        }
        !           756: #else
        !           757: #ifdef  SYS5
        !           758:        (void) setpgrp ();
        !           759:        (void) signal (SIGINT, SIG_IGN);
        !           760:        (void) signal (SIGQUIT, SIG_IGN);
        !           761: #endif
        !           762: #endif
        !           763:     }
        !           764:     else
        !           765:        ll_dbinit (pgm_log, myname);
        !           766: 
        !           767: #ifndef sun                    /* damn YP... */
        !           768:     for (sd = 3; sd < nbits; sd++)
        !           769:        if (pgm_log -> ll_fd != sd)
        !           770:            (void) close (sd);
        !           771: #endif
        !           772: 
        !           773:     (void) signal (SIGPIPE, SIG_IGN);
        !           774: 
        !           775:     ll_hdinit (pgm_log, myname);
        !           776:     advise (LLOG_NOTICE, NULLCP, "starting");
        !           777: }
        !           778: 
        !           779: /*    ERRORS */
        !           780: 
        !           781: #ifndef lint
        !           782: static void    adios (va_alist)
        !           783: va_dcl
        !           784: {
        !           785:     va_list ap;
        !           786: 
        !           787:     va_start (ap);
        !           788: 
        !           789:     _ll_log (pgm_log, LLOG_FATAL, ap);
        !           790: 
        !           791:     va_end (ap);
        !           792: 
        !           793:     _exit (1);
        !           794: }
        !           795: #else
        !           796: /* VARARGS */
        !           797: 
        !           798: static void    adios (what, fmt)
        !           799: char   *what,
        !           800:        *fmt;
        !           801: {
        !           802:     adios (what, fmt);
        !           803: }
        !           804: #endif
        !           805: 
        !           806: 
        !           807: #ifndef lint
        !           808: static void    advise (va_alist)
        !           809: va_dcl
        !           810: {
        !           811:     int     code;
        !           812:     va_list ap;
        !           813: 
        !           814:     va_start (ap);
        !           815: 
        !           816:     code = va_arg (ap, int);
        !           817: 
        !           818:     _ll_log (pgm_log, code, ap);
        !           819: 
        !           820:     va_end (ap);
        !           821: }
        !           822: #else
        !           823: /* VARARGS */
        !           824: 
        !           825: static void    advise (code, what, fmt)
        !           826: char   *what,
        !           827:        *fmt;
        !           828: int     code;
        !           829: {
        !           830:     advise (code, what, fmt);
        !           831: }
        !           832: #endif
        !           833: 
        !           834: /*  */
        !           835: 
        !           836: static void  ts_adios (td, event)
        !           837: register struct TSAPdisconnect *td;
        !           838: char   *event;
        !           839: {
        !           840:     ts_advise (td, LLOG_EXCEPTIONS, event);
        !           841: 
        !           842:     exit (1);
        !           843: }
        !           844: 
        !           845: /*  */
        !           846: 
        !           847: static void  ts_advise (td, code, event)
        !           848: register struct TSAPdisconnect *td;
        !           849: int     code;
        !           850: char   *event;
        !           851: {
        !           852:     char    buffer[BUFSIZ];
        !           853: 
        !           854:     if (td -> td_cc > 0)
        !           855:        (void) sprintf (buffer, "[%s] %*.*s",
        !           856:                        TErrString (td -> td_reason),
        !           857:                        td -> td_cc, td -> td_cc, td -> td_data);
        !           858:     else
        !           859:        (void) sprintf (buffer, "[%s]", TErrString (td -> td_reason));
        !           860: 
        !           861:     advise (code, NULLCP, "%s: %s", event, buffer);
        !           862: }

unix.superglobalmegacorp.com

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