DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T n

⟦adbe11c21⟧ TextFile

    Length: 9078 (0x2376)
    Types: TextFile
    Names: »nsa.c«

Derivation

└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
    └─⟦eba4602b1⟧ »./isode-5.0.tar.Z« 
        └─⟦d3ac74d73⟧ 
            └─⟦this⟧ »isode-5.0/quipu/nsa.c« 

TextFile

/* nsa.c - Name server access to the directory */

#ifndef	lint
static char *rcsid = "$Header: /f/osi/quipu/RCS/nsa.c,v 6.0 89/03/18 23:41:44 mrose Rel $";
#endif

/* 
 * $Header: /f/osi/quipu/RCS/nsa.c,v 6.0 89/03/18 23:41:44 mrose Rel $
 *
 *
 * $Log:	nsa.c,v $
 * Revision 6.0  89/03/18  23:41:44  mrose
 * Release 5.0
 * 
 */

/*
 *				  NOTICE
 *
 *    Acquisition, use, and distribution of this module and related
 *    materials are subject to the restrictions of a license agreement.
 *    Consult the Preface in the User's Manual for the full terms of
 *    this agreement.
 *
 */


#include <signal.h>
#include <stdio.h>
#include <varargs.h>
#include "psap.h"
#include "rosap.h"
#include "isoaddrs.h"
#include "internet.h"
#include "logger.h"
#include "tailor.h"
#include "quipu/util.h"
#include "quipu/read.h"
#include "quipu/dua.h"
#include "quipu/connection.h"
#include "quipu/entry.h"
#include <sys/ioctl.h>
#ifdef	BSD42
#include <sys/file.h>
#endif
#ifdef	SYS5
#include <fcntl.h>
#endif

#ifdef DSAP

#ifndef NO_STATS
LLog    *log_stat;
#endif

#define	DSA_WAIT	30

/* \f

   DATA */

extern	LLog   *log_dsap;
extern	int	dn_print();

DN	str2dn ();
void	advise (), adios();
static PE remote_resolve ();

extern int    dsap_ad;

int	nfds,
	nameservice;
fd_set	ifds,
	rfds;

/* \f

 */

ns_init ()
{
    int	    i;

    register struct NSAPaddr *na;
    register struct PSAPaddr *pa;
    struct sockaddr_in	in_socket;
    register struct sockaddr_in *isock = &in_socket;
    register struct hostent *hp;

    if ((pa = str2paddr (ns_address)) == NULL)
	adios (NULLCP, "unable to parse resolver address \"%s\"", ns_address);
    if ((i = pa -> pa_addr.sa_addr.ta_naddr) == 0)
	adios (NULLCP, "no network addresses present in \"%s\"", ns_address);
    for (na = pa -> pa_addr.sa_addr.ta_addrs; i-- > 0; na++)
	if (na -> na_type == NA_TCP)
	    break;
    if (i < 0)
	adios (NULLCP, "no TCP-based network addresses present in \"%s\"",
	       ns_address);
    if (na -> na_domain[0]) {
	if ((hp = gethostbystring (na -> na_domain)) == NULL)
	    adios (NULLCP, "%s: unknown host", na -> na_domain);
    }
    else
	hp = NULL;
    if (na -> na_port == 0)
	adios (NULLCP, "UDP port not specified");

    bzero ((char *) isock, sizeof *isock);
    isock -> sin_family = hp ? hp -> h_addrtype : AF_INET;
    isock -> sin_port = na -> na_port;
    if (hp)
	inaddr_copy (hp, isock);

    if ((nameservice = start_udp_server (isock, 0, 0, 0)) == NOTOK)
	adios ("failed", "start_udp_server");

    if (nameservice >= id_st.nads)
	id_st.nads = nameservice + 1;
    FD_SET (nameservice,&id_st.iads);

}

/* \f

 */

ns_process (ud)
int	ud;
{
    int	    fd;
    struct sockaddr_in   out_socket;
    register struct sockaddr_in *osock = &out_socket;
    struct ns_query nss;
    register struct ns_query *ns = &nss;
    PE	    pe;
    PS	    ps;

    if ((fd = join_udp_client (ud, osock)) == NOTOK) {
	advise (LLOG_EXCEPTIONS, "failed", "join_udp_client");
	return;
    }

    pe = NULLPE;
    bzero ((char *) ns, sizeof *ns);
    if ((ps = ps_alloc (dg_open)) == NULLPS
	    || dg_setup (ps, fd, MAXUDP, read_udp_socket, write_udp_socket)
		    == NOTOK) {
	advise (LLOG_EXCEPTIONS, NULLCP, "%s failed", ps ? "dg_setup" : "ps_alloc");
	goto out;
    }

    if ((pe = ps2pe (ps)) == NULLPE) {
	advise (LLOG_NOTICE, NULLCP, "unable to read query: %s",
		ps_error (ps -> ps_errno));
	goto out;
    }

    if (parse_NS_Query (pe, 1, NULLIP, NULLVP, (char *) ns) == NOTOK) {
	advise (LLOG_NOTICE, NULLCP, "parse of Query failed: %s", PY_pepy);
	goto out;
    }

    PLOG (log_dsap, print_NS_Message, pe, "message", 1);

    resolve (ps, ns -> ns_id, ns -> ns_name, ns -> ns_attribute);

out: ;
    if (ns -> ns_name)
	free (ns -> ns_name);
    if (ns -> ns_attribute)
	free (ns -> ns_attribute);
    if (pe)
	pe_free (pe);
    if (ps)
	ps_free (ps);

    (void) close_udp_socket (fd);
}

/* \f

 */

static	resolve (ps, id, name, attribute)
register PS	ps;
int	id;
char   *name,
       *attribute;
{
    static struct ds_read_arg read_arg = {
	default_common_args,
	NULLDN, /* supplied */
	{ FALSE, NULLATTR, EIS_ATTRIBUTESANDVALUES }
    };
    struct ds_read_result result;
    struct DSError error;
    
    int	    i;
    DN     dn;
    struct ns_response nss;
    register struct ns_response *ns = &nss;
    PE     pe;
    PE     grab_pe();
    AttributeType myattr;
    Attr_Sequence ap;

    bzero ((char *) ns, sizeof *ns);
    ns -> ns_id = id;

    if ((dn = str2dn (name)) == NULLDN) {
	advise (LLOG_EXCEPTIONS, NULLCP, "str2dn of \"%s\" failed", name);
	goto out1;
    }
    
    read_arg.rda_common.ca_requestor = NULLDN;
    read_arg.rda_object = dn;

    if ((myattr = AttrT_new (attribute)) == NULLAttrT) {
	advise (LLOG_EXCEPTIONS, NULLCP, "attribute \"%s\" unknown",
		attribute);

	goto out1;
    }

    read_arg.rda_eis.eis_select = as_comp_new (myattr, NULLAV, NULLACL_INFO);

#ifndef NO_STATS
	LLOG (log_stat,LLOG_NOTICE,("Name server access..."));
#endif

    if ((i = do_ds_read (&read_arg, &error, &result, NULLDN, NULLDN)) != DS_OK) {
	if (error.dse_type != DSE_REFERRAL) {
		advise (LLOG_EXCEPTIONS, NULLCP, "ds_read for \"%s\" failed: %d",name, i);
		goto out1;
	}
	if ((ns->ns_value = remote_resolve (dn,myattr,
			&(error.ERR_REFERRAL.DSE_ref_candidates->cr_accesspoints.ap_address),&result )) == NULLPE) {
		advise (LLOG_EXCEPTIONS, NULLCP, "remote ds_read for \"%s\" failed: %d",name, i);
		goto out1;
	}
	if (encode_IF_Name (&ns -> ns_name, 0, 0, NULLCP, result.rdr_entry.ent_dn) == NOTOK) {
		advise (LLOG_EXCEPTIONS, NULLCP,
			"encoding of remote Distinguished Name failed; %s", PY_pepy);
		goto out1;
    	}
	goto remote_out;
    }

#ifdef	DEBUG
    if (result.rdr_entry.ent_next != NULL)
	DLOG (log_dsap, LLOG_EXCEPTIONS, ("multiple entries returned in read"));
#endif

    if (encode_IF_Name (&ns -> ns_name, 0, 0, NULLCP, result.rdr_entry.ent_dn) == NOTOK) {
	advise (LLOG_EXCEPTIONS, NULLCP,
		"encoding of Distinguished Name failed; %s", PY_pepy);
	goto out1;
    }

    if ((ap = as_find_type (result.rdr_entry.ent_attr, myattr)) == NULLATTR) {
	advise (LLOG_EXCEPTIONS, NULLCP, "no \"%s\" attribute in result",
		attribute);
	
        entryinfo_comp_free (&result.rdr_entry, 1);
	goto out2;
    }

    ns->ns_value = grab_pe (ap->attr_value->avseq_av);

    if (ap -> attr_link != NULL)
	advise (LLOG_NOTICE, NULLCP, "multiple values for \"%s\" attribute",
		attribute);

        entryinfo_comp_free (&result.rdr_entry, 1);
    	goto out2;

    
out1: ;
    /* fill in original dn in result - can cope with possible aliases */

    if (encode_IF_Name (&ns -> ns_name, 0, 0, NULLCP, dn) == NOTOK) {
	advise (LLOG_EXCEPTIONS, NULLCP,
		"encoding of Distinguished Name failed; %s", PY_pepy);
    }
    
out2: ;

    if (dn)
	dn_free (dn);
    if  (read_arg.rda_eis.eis_select)
	as_free (read_arg.rda_eis.eis_select);

remote_out: ;
    pe = NULLPE;
    if (build_NS_Response (&pe, 1, NULL, NULLCP, (char *) ns) == NOTOK) {
	advise (LLOG_EXCEPTIONS, NULLCP, "build of Response failed: %s", PY_pepy);
	goto out;
    }

    PLOG (log_dsap, print_NS_Message, pe, "message", 0);

    if (pe2ps (ps, pe) == NOTOK)
    	advise (LLOG_EXCEPTIONS, NULLCP, "unable to write Response: %s",
		ps_error (ps -> ps_errno));

out: ;
    if (pe)
	pe_free (pe);
    if (ns -> ns_name)
	pe_free (ns -> ns_name);
    if (ns -> ns_value)
	pe_free (ns -> ns_value);
}


static PE remote_resolve (dn,at,addr,result)
DN dn;
AttributeType at;
struct PSAPaddr * addr;
struct ds_read_result *result;
{
static struct ds_read_arg read_arg =
	{
		default_common_args,
		NULLDN,
		{       /* entry info selection */
			TRUE,
			NULLATTR,
			EIS_ATTRIBUTESANDVALUES
		}
	};
struct DSError error;
extern Entry current_entry;
static struct ds_bind_arg bindarg;
static struct ds_bind_arg bindresult;
static struct ds_bind_error binderr;
Attr_Sequence as;
int ad;

	/* read from of remote DSA */
	/* Do synchronus read for now */
	/* Async read eventually */

#ifndef NO_STATS
	dn_decode (dn);
	pslog (log_stat,LLOG_NOTICE,"remote ns lookup",dn_print,(caddr_t)dn);
#endif

	make_dsa_bind_arg (&bindarg);

	if (dap_bind (&ad, &bindarg, &binderr, &bindresult,addr) != OK) {
		advise (LLOG_EXCEPTIONS, NULLCP, "Remote bind failure (NS)");
		return (NULLPE);
	} 

	read_arg.rda_object = dn;

	if (dap_read (ad,1,&read_arg, &error, result) != DS_OK) {
		log_ds_error (&error);
		ds_error_free (&error);
		advise (LLOG_NOTICE, NULLCP, "Remote read failure (NS)");
		(void) dap_unbind (ad);
		return (NULLPE);
	}

	(void) dap_unbind (ad);

	cache_entry (&(result->rdr_entry), TRUE, EIS_ATTRIBUTESANDVALUES);

	if (unravel_attribute (current_entry,&error,TRUE) != OK) {
		log_ds_error (&error);
		ds_error_free (&error);
		advise (LLOG_EXCEPTIONS, NULLCP, "Unravel failure (NS)");
		return (NULLPE);
	}


	if ((as = as_find_type (current_entry->e_attributes,at)) == NULLATTR) {
		advise (LLOG_NOTICE, NULLCP, "No attribute (NS)");
		return (NULLPE);
	}

	return (grab_pe (as->attr_value->avseq_av));
}

#else

/* Dummy routine to prevent errors when DSAP is not defined */

ns_init ()
{
;
}

#endif