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 o

⟦e88d435d0⟧ TextFile

    Length: 5944 (0x1738)
    Types: TextFile
    Names: »or_or2rbits.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« 
        └─⟦e5a54fb17⟧ 
            └─⟦this⟧ »pp-5.0/Lib/or/or_or2rbits.c« 

TextFile

/* or_or2rbits.c: break or into bits */

# ifndef lint
static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Lib/or/RCS/or_or2rbits.c,v 5.0 90/09/20 16:08:22 pp Exp Locker: pp $";
# endif

/*
 * $Header: /cs/research/pp/hubris/pp-beta/Lib/or/RCS/or_or2rbits.c,v 5.0 90/09/20 16:08:22 pp Exp Locker: pp $
 *
 * $Log:	or_or2rbits.c,v $
 * Revision 5.0  90/09/20  16:08:22  pp
 * rcsforce : 5.0 public release
 * 
 */



#include "or.h"
#include "util.h"
#include "table.h"

extern char     *loc_dom_site;
extern char     or_error[];
extern char     *or2rfc_tbl;
static Table    *tb_or2rfc;


/* --- definitions --- */
#define NO_MATCH		0
#define OU_O_MATCH		1
#define PRMD_ADMD_C_MATCH	2


/* -- local routines -- */
int		or_or2rbits();
static		get_psORasc();




/* ---------------------  Begin  Routines  -------------------------------- */




/* --- Get local + domain from or --- */

int or_or2rbits (or, local, domain)
OR_ptr  or;
char    *local;
char    *domain;
{
	OR_ptr          ptr,
			dptr,
			tptr;
	char            buf[LINESIZE],
			tbuf[LINESIZE],
			loc_ps[LINESIZE], /* --- Printable String --- */
			dom_ps[LINESIZE], /* --- Printable String --- */
			*indptr;
	int		match_found;


	PP_DBG (("Lib/or_or2rbits()"));

	if (tb_or2rfc == NULLTBL)
		if ((tb_or2rfc = tb_nm2struct (or2rfc_tbl)) == NULLTBL) {
			PP_LOG (LLOG_EXCEPTIONS,
			       ("Lib/or_or2rbits : or2rfc table not found!"));
			sprintf (or_error, "No or2rfc table!");
			return NOTOK;
		}


	if (or_add_atsigns (&or) == NOTOK)
		return NOTOK;


	/* --- See how much we can domain check against --- */

	for (ptr = or; ptr -> or_next != NULLOR; ptr = ptr -> or_next)
		if (ptr -> or_type > OR_OU)
			break;


	/* --- pointing to the first non-dom compt --- */

	if (ptr != or) {
		ptr = ptr -> or_prev;
		dptr = ptr;

		/* --- move until we find a match --- */

		for (; ptr != NULLOR; ptr = ptr->or_prev) {
			or_or2dmn (NULLOR, ptr, buf);

			if (tb_k2val (tb_or2rfc, buf, tbuf) != OK)
				continue;

			match_found = or_or2rbits_atsigns (ptr);

			switch (match_found) {
			case NO_MATCH: 
				break;
			case PRMD_ADMD_C_MATCH:
				goto doexplicit;
			case OU_O_MATCH:	
				dptr = ptr;
				break;
			}


			/* --- check that tbuf is a valid domain syntax --- */
			if (or_or2rbits_ckdmn (tbuf) == NOTOK)
				goto doexplicit;


			/* --- get local and domain parts --- */	
			if (match_found == NO_MATCH)
				if (or_or2rbits_match (ptr, tptr, &dptr) == NOTOK)
					goto doexplicit;


			dom_ps[0] ='\0';

			for (tptr = dptr; tptr != ptr; tptr = tptr->or_prev)
				if (lexequ (tptr -> or_value, "@") == 0)
					dptr = tptr -> or_prev;


			for (tptr = dptr; tptr != ptr; tptr = tptr->or_prev) {
				(void) strcat (dom_ps, tptr -> or_value);
				(void) strcat (dom_ps, ".");
			}

			(void) strcat (dom_ps, tbuf);
			get_psORasc (dom_ps, domain);

			tptr = dptr -> or_next;
			if (or_delete_atsigns (&tptr) == NOTOK)
				return NOTOK;
			tptr -> or_prev = NULLOR;

			or_or2std (tptr, loc_ps, TRUE);
			if (loc_ps[strlen (loc_ps) - 1]  == '/')
				or_or2std (tptr, loc_ps, FALSE);

			get_psORasc (loc_ps, local);

			tptr -> or_prev = dptr;

			PP_DBG ((
			"Lib/or_or2rbits DMN encoded local='%s', dmn='%s'",
			local, domain
			));

			if (or_delete_atsigns (&or) == NOTOK)
				return NOTOK;

			return OK;

		}   /* end of for */

	}  /* end of if */


doexplicit:
	/* --- Do full LHS encoding --- */
	if (or_delete_atsigns (&or) == NOTOK)
		return NOTOK;

	(void) strcpy (domain, loc_dom_site);
	or_or2std (or, loc_ps, FALSE);
	get_psORasc (loc_ps, local);	

	PP_DBG (("Lib/or_or2rbits/Default setting local='%s' domain='%s'",
		local, domain));

	return OK;
}




/* --------------------------  Static  Routines  ---------------------------- */




static int or_or2rbits_ckdmn (dmn)
char	*dmn; 
{
	char	buf[LINESIZE];
	char	*ptr = dmn;

	PP_DBG (("Lib/or_or2rbits_ckdmn (%s)", dmn));

	buf[0] = '\0'; 

	while (or_gettoken (&ptr, '.', buf) == OK)
		if (!or_isdomsyntax (buf)) {
			PP_LOG (LLOG_EXCEPTIONS, ("%s '%s'",
				"Lib/or_or2rbits: Bad style X400 addr", dmn));
			sprintf (or_error,
				"Bad style X400 address '%s'", dmn);
			return NOTOK;
		}

	return OK;
} 




static int or_or2rbits_match (start, curr, dmn)
OR_ptr  start;
OR_ptr  curr;
OR_ptr  *dmn;
{
	char	buf[LINESIZE];


	/* --- *** ---
	Build domain - match. If attribute value does not hold a valid domain 
	syntax, then move that part to the local part. This is only done if 
	no mapping for that attribute has been specified in the or2rfc table.
	Example:
		'/s=user/ou=org unit/prmd=valid/admd=gold 400/c=gb/'
	will be RFC987 mapped to:
		'"/s=user/ou=org unit/"@valid.gold-400.gb'
	--- *** --- */

	for (curr = *dmn; curr != start; curr = curr -> or_prev) {
		get_psORasc (curr -> or_value, buf);

		if ((!or_isdomsyntax (buf)) && (lexequ (buf, "@") != 0)) {
			if (curr -> or_prev)
				*dmn = curr -> or_prev;
			else {
				PP_LOG (LLOG_EXCEPTIONS,("%s '%s'",
					"Lib/or_or2rbits/No OR prev",
					curr -> or_value));

				sprintf (or_error, "No OR prev '%s'",
					curr->or_value);

				return NOTOK;
			}
		}
	}

	return OK;
}




/* --- match for "@" signs in the or2rfc table --- */

static int or_or2rbits_atsigns (or)
OR_ptr	or;
{
	OR_ptr	next = or -> or_next;	/* save the value */
	int	type = or -> or_type;
	OR_ptr	at;
	char	key[LINESIZE], value[LINESIZE]; 
	int	retval;


	if (type < OR_OU)
		type++;
	else
		return NO_MATCH;

	at = or_new (type, NULLCP, "@");

	at -> or_prev = or;
	at -> or_next = NULLOR;
	or -> or_next = at;	


	or_or2dmn (NULLOR, at, key);	

	retval = tb_k2val (tb_or2rfc, key, value);

	or -> or_next = next;

	at -> or_prev = at -> or_next = NULLOR;
	or_free (at);

	if (retval != OK)
		return NO_MATCH;

	if (type < OR_O)
		return PRMD_ADMD_C_MATCH;

	return OU_O_MATCH;
}




static get_psORasc (value, buf)
char	*value;
char	*buf;
{

#ifndef STRICT_1148
	(void) or_ps2asc (value, buf);
#else
	(void) strcpy (buf, value);
#endif
}