示例#1
0
文件: idtest.c 项目: 1ack/Impala
int
main( int argc, char **argv )
{
#ifdef HAVE_PSAP_H
	PE	pe;
	PS	psin, psout, pserr;

	/* read the pe from standard in */
	if ( (psin = ps_alloc( std_open )) == NULLPS ) {
		perror( "ps_alloc" );
		exit( EXIT_FAILURE );
	}
	if ( std_setup( psin, stdin ) == NOTOK ) {
		perror( "std_setup" );
		exit( EXIT_FAILURE );
	}
	/* write the pe to standard out */
	if ( (psout = ps_alloc( std_open )) == NULLPS ) {
		perror( "ps_alloc" );
		exit( EXIT_FAILURE );
	}
	if ( std_setup( psout, stdout ) == NOTOK ) {
		perror( "std_setup" );
		exit( EXIT_FAILURE );
	}
	/* pretty print it to standard error */
	if ( (pserr = ps_alloc( std_open )) == NULLPS ) {
		perror( "ps_alloc" );
		exit( EXIT_FAILURE );
	}
	if ( std_setup( pserr, stderr ) == NOTOK ) {
		perror( "std_setup" );
		exit( EXIT_FAILURE );
	}

	while ( (pe = ps2pe( psin )) != NULLPE ) {
		pe2pl( pserr, pe );
		pe2ps( psout, pe );
	}

	exit( EXIT_SUCCESS );
#else
	fprintf(stderr, "requires ISODE X.500 distribution.\n");
	return( EXIT_FAILURE );
#endif
}
示例#2
0
static DNS 
dase_interact (DNS dns, DN dn, char *s)
{
	int i;
	struct type_DASE_Callback__REQ *req = NULL;
	struct element_DASE_3 **dp;
	struct type_DASE_Callback__RSP *rsp = NULL;
	struct type_DASE_Callback__RSP *rp;
	DNS	    ds,
			*dq;
	PE	    pe = NULLPE;

	if (dns == NULLDNS)
		return NULL;

	i = 0;
	for (ds = dns; ds; ds = ds -> dns_next)
		i++;

	if (i > 1) {
		struct dn_seq **base,
				**bp,
				**ep;

		if (base = (struct dn_seq **) malloc ((unsigned) (i * sizeof *base))) {
			ep = base;
			for (ds = dns; ds; ds = ds -> dns_next)
				*ep++ = ds;

			qsort ((char *) base, i, sizeof *base, dns_compar);

			bp = base;
			ds = dns = *bp++;
			while (bp < ep) {
				ds -> dns_next = *bp;
				ds = *bp++;
			}
			ds -> dns_next = NULL;

			free ((char *) base);
		}
	}

	if ((req = (struct type_DASE_Callback__REQ *) calloc (1, sizeof *req))
			== NULL) {
no_mem:
		;
		advise (LLOG_EXCEPTIONS, NULLCP, "out of memory");
out:
		;
		if (req)
			free_DASE_Callback__REQ (req);
		if (rsp)
			free_DASE_Callback__RSP (rsp);
		if (pe)
			pe_free (pe);

		dn_seq_free (dns);
		return NULL;
	}
	if ((req -> string = str2qb (s, strlen (s), 1)) == NULL)
		goto no_mem;

	dp = &req -> choices;
	for (; dns; dns = ds) {
		struct element_DASE_3 *d3;
		struct type_DASE_Pair *pair;

		if ((d3 = (struct element_DASE_3 *) calloc (1, sizeof *d3)) == NULL)
			goto no_mem;
		*dp = d3, dp = &d3 -> next;

		if ((pair = (struct type_DASE_Pair *) calloc (1, sizeof *pair))
				== NULL)
			goto no_mem;
		d3 -> Pair = pair;

		dn_print (nps, dns -> dns_dn, EDBOUT);
		ps_print (nps, " ");
		*--nps -> ps_ptr = NULL, nps -> ps_cnt++;

		pair -> complete = str2qb (nps -> ps_base, strlen (nps -> ps_base), 1);

		nps -> ps_ptr = nps -> ps_base, nps -> ps_cnt = nps -> ps_bufsiz;

		ufn_dn_print_aux (nps, dns -> dns_dn, dn, 0);
		ps_print (nps, " ");
		*--nps -> ps_ptr = NULL, nps -> ps_cnt++;

		pair -> friendly = str2qb (nps -> ps_base, strlen (nps -> ps_base), 1);

		nps -> ps_ptr = nps -> ps_base, nps -> ps_cnt = nps -> ps_bufsiz;

		if (pair -> complete == NULL || pair -> friendly == NULL)
			goto no_mem;

		ds = dns -> dns_next;

		dn_free (dns -> dns_dn);
		free ((char *) dns);
	}

	dns = NULL;

	if (encode_DASE_Callback__REQ (&pe, 1, NULL, NULLCP, req) == NOTOK) {
		advise (LLOG_EXCEPTIONS, NULLCP, "encode_DASE_Callback__REQ: %s",
				PY_pepy);
		goto out;
	}
	if (pe2ps (ps, pe) == NOTOK)
		adios (NULLCP, "pe2ps: %s", ps_error (ps -> ps_errno));
	PLOGP (pgm_log,DASE_Message, pe, "message", 0);

	free_DASE_Callback__REQ (req);
	req = NULL;
	pe_free (pe);

	if ((pe = ps2pe (ps)) == NULLPE)
		adios (NULLCP, "ps2pe: %s", ps_error (ps -> ps_errno));

	if (decode_DASE_Callback__RSP (pe, 1, NULLIP, NULLVP, &rsp) == NOTOK) {
		advise (LLOG_EXCEPTIONS, NULLCP, "decode_DASE_Callback__RSP: %s",
				PY_pepy);
		goto out;
	}
	PLOGP (pgm_log,DASE_Message, pe, "message", 1);

	dq = &dns;
	for (rp = rsp; rp; rp = rp -> next) {
		char   *cp;

		if ((ds = (struct dn_seq *) calloc (1, sizeof *ds)) == NULL)
			goto no_mem;
		*dq = ds, dq = &ds -> dns_next;

		if ((cp = qb2str (rp -> IA5String)) == NULL)
			goto no_mem;
		ds -> dns_dn = str2dn (cp);
		free (cp);
	}

	free_DASE_Callback__RSP (rsp);
	pe_free (pe);

	return dns;
}
示例#3
0
static 
dase_aux (struct type_DASE_Query__REQ *req)
{
	int    i;
	int	    vecp;
	char **vp;
	char   *context,
		   **vec;
	struct type_DASE_Query__RSP *rsp;
	struct element_DASE_0 *d0;
	struct element_DASE_1 *d1;
	envlist el;
	envlist  en,
			 *ep;
	DN	   *dn;
	DNS	    dns;
	PE	    pe;

	if ((rsp = (struct type_DASE_Query__RSP *) calloc (1, sizeof *rsp))
			== NULL) {
no_mem:
		;
		adios (NULLCP, "out of memory");
	}

	vec = NULL, el = NULL, context = NULL, dns = NULL;

	i = 1;
	for (d0 = req -> name; d0; d0 = d0 -> next)
		i++;
	if ((vec = (char **) calloc ((unsigned) i, sizeof *vec)) == NULL)
		goto no_mem;
	for (vp = vec, d0 = req -> name; d0; vp++, d0 = d0 -> next)
		if ((*vp = qb2str (d0 -> IA5String)) == NULL)
			goto no_mem;
#ifdef	STATS
		else
			advise (LLOG_NOTICE, NULLCP, "lookup: %s", *vp);
#endif
	vecp = i - 1;

	el = NULL, ep = &el;
	for (d1 = req -> envlist; d1; d1 = d1 -> next) {
		struct type_DASE_Environment *ev = d1 -> Environment;
		struct element_DASE_2 *d2;
		struct dn_seq **dp;

		if ((en = (envlist) calloc (1, sizeof *en)) == NULL)
			goto no_mem;
		*ep = en, ep = &en -> Next;

		en -> Upper = ev -> upper;
		en -> Lower = ev -> lower;

		dp = &en -> Dns;
		for (d2 = ev -> path; d2; d2 = d2 -> next) {
			char   *cp;
			struct dn_seq *ds;

			if ((ds = (struct dn_seq *) calloc (1, sizeof *ds)) == NULL)
				goto no_mem;
			*dp = ds, dp = &ds -> dns_next;

			if ((cp = qb2str (d2 -> IA5String)) == NULL)
				goto no_mem;
			if (*cp != '-')
				ds -> dns_dn = str2dn (cp);
			free (cp);

			if (*cp != '-' && ds -> dns_dn == NULLDN) {
				PY_advise (NULLCP, "bad DN in environment (%s)", cp);
				goto send_rsp;
			}
		}
	}

	if ((context = qb2str (req -> context)) == NULL)
		goto no_mem;
#ifdef	STATS
	advise (LLOG_NOTICE, NULLCP, "context: %s", context);
#endif

	if (req -> userdn) {
		int	changed = 0;
		char   *cp;
		DN	newdn;

		if ((cp = qb2str (req -> userdn)) == NULL)
			goto no_mem;
#ifdef	STATS
		advise (LLOG_NOTICE, NULLCP, "userdn: %s", cp);
#endif
		if ((newdn = str2dn (*cp != '@' ? cp : cp + 1)) == NULLDN) {
			PY_advise (NULLCP, "bad DN for userdn (%s)", cp);
			free (cp);
			goto send_rsp;
		}
		if (!userdn || dn_cmp (userdn, newdn))
			changed++;
		if (userdn)
			dn_free (userdn);
		userdn = newdn;
		free (cp);

		if (req -> passwd) {
			if ((cp = qb2str (req -> passwd)) == NULL)
				goto no_mem;
			if (strcmp (passwd, cp))
				changed++;
			 strcpy (passwd, cp);
			free (cp);
		} else {
			if (passwd[0])
				changed++;
			passwd[0] = NULL;
		}

		if (isbound && changed) {
			 ds_unbind ();
			isbound = 0;
		}
	}

	if (!isbound && bind_to_dsa () == NOTOK)
		goto send_rsp;

	PY_pepy[0] = NULL;
	pe = NULLPE;
	if (vecp == 1 && *vec[0] == '@') {
		static DN dnstat;

		if ((dnstat = str2dn (vec[0])) == NULLDN) {
			PY_advise (NULLCP, "invalid name");
			goto send_rsp;
		}

		rsp -> value = name2psap (*(dn = &dnstat));
		goto all_done;
	}

	if (!aet_match (vecp, vec, req -> interactive ? dase_interact
					: just_say_no,
					&dns, el, context)) {
		if (PY_pepy[0] == NULL)
			PY_advise (NULLCP, "unable to resolve name");
		goto send_rsp;
	}

	if (dns == NULL) {
		PY_advise (NULLCP, "search failed to find anything");
		goto send_rsp;
	}
	dn = NULL;

	if (dns -> dns_next) {
		if (req -> interactive)
			 dnSelect (vec[0], &dns, dase_interact, el -> Dns);

		for (; dns; dns = dns -> dns_next) {
			dn = &dns -> dns_dn;
			if (rsp -> value = name2psap (*dn))
				break;
		}
	} else {
		dn = &dns -> dns_dn;
		rsp -> value = name2psap (*dn);
	}

all_done:
	;
	if (dn) {
		 encode_IF_DistinguishedName (&rsp -> name, 1, NULL, NULLCP,*dn);
#ifdef	STATS
		advise (LLOG_NOTICE, NULLCP, "answer: %s", dn2str (*dn));
#endif

		ufn_dn_print_aux (nps, *dn, NULLDN, 0);
		ps_print (nps, " ");
		*--nps -> ps_ptr = NULL, nps -> ps_cnt++;

		rsp -> friendly = str2qb (nps -> ps_base, strlen (nps -> ps_base), 1);

		nps -> ps_ptr = nps -> ps_base, nps -> ps_cnt = nps -> ps_bufsiz;

		dn_free (*dn);
		*dn = NULLDN;
	}

send_rsp:
	;
	if (PY_pepy[0]) {
		advise (LLOG_NOTICE, NULLCP, "diagnostic: %s", PY_pepy);

		if ((rsp -> diagnostic = str2qb (PY_pepy, strlen (PY_pepy), 1))
				== NULL)
			goto no_mem;
	}

	if (encode_DASE_Query__RSP (&pe, 1, NULL, NULLCP, rsp) == NOTOK)
		adios (NULLCP, "encode_DASE_Query__RSP: %s", PY_pepy);
	if (pe2ps (ps, pe) == NOTOK)
		adios (NULLCP, "pe2ps: %s", ps_error (ps -> ps_errno));
	PLOGP (pgm_log,DASE_Message, pe, "message", 0);

	free_DASE_Query__RSP (rsp);
	pe_free (pe);

	if (vec) {
		for (vp = vec; *vp; vp++)
			free (*vp);
		free ((char *) vec);
	}

	for (; el; el = en) {
		en = el -> Next;

		dn_seq_free (el -> Dns);
		free ((char *) el);
	}

	if (context)
		free (context);

	if (dns)
		dn_seq_free (dns);
}