File:  [CSRG BSD Unix] / 43BSDReno / contrib / isode-beta / quipu / attribute.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:56 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD43reno
BSD 4.3reno

/* attribute.c - */

#ifndef lint
static char *rcsid = "$Header: /var/lib/cvsd/repos/CSRG/43BSDReno/contrib/isode-beta/quipu/attribute.c,v 1.1.1.1 2018/04/24 16:12:56 root Exp $";
#endif

/*
 * $Header: /var/lib/cvsd/repos/CSRG/43BSDReno/contrib/isode-beta/quipu/attribute.c,v 1.1.1.1 2018/04/24 16:12:56 root Exp $
 *
 *
 * $Log: attribute.c,v $
 * Revision 1.1.1.1  2018/04/24 16:12:56  root
 * BSD 4.3reno
 *
 * Revision 7.3  90/04/18  08:49:44  mrose
 * 6.2
 * 
 * Revision 7.2  90/01/11  23:55:49  mrose
 * lint
 * 
 * Revision 7.1  90/01/11  18:37:17  mrose
 * real-sync
 * 
 * Revision 7.0  89/11/23  22:16:38  mrose
 * Release 6.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 "quipu/util.h"
#include "quipu/entry.h"
#include "quipu/ds_error.h"
#include "quipu/oid.h"
#include "quipu/malloc.h"

AttributeType at_certificate;
AttributeType at_p_password;
AttributeType at_password;
AttributeType at_acl;
AttributeType at_control;
AttributeType at_schema;
AttributeType at_applctx;
oid_table_attr * tab_applctx;
oid_table_attr * tab_password;
oid_table_attr * tab_acl;
oid_table_attr * tab_schema;
oid_table_attr * tab_edbinfo;
oid_table_attr * tab_masterdsa;
oid_table_attr * tab_slavedsa;
oid_table_attr * tab_dsaaddress;
oid_table_attr * tab_version;
OID alias_oc;
OID quipu_dsa_oid;

extern oid_table_attr * tab_objectclass;
extern oid_table_attr * tab_alias;
extern LLog * log_dsap;

check_dsa_known_oids ()
{
	/* for efficiency yacc has knowledge of certain oid built in
		   check these are in current table  */

	check_known_oids ();

	at_password = AttrT_new (PASSWORD_OID);
	if (at_password == NULLAttrT)
		fatal (-21,"userPassword attribute type missing - check oidtables");
	tab_password = at_password;

	at_control = AttrT_new (CONTROL_OID);
	if (at_control == NULLAttrT)
		fatal (-22,"control attribute type missing - check oidtables");

	at_acl = AttrT_new (ACL_OID);
	if ( at_acl == NULLAttrT)
		fatal (-23,"acl attribute type missing - check oidtables");
	tab_acl = at_acl;

	at_applctx = AttrT_new (APPLCTX_OID);
	if ( at_applctx == NULLAttrT)
		fatal (-23,"supported application context attribute type missing - check oidtables");

	at_schema = AttrT_new (SCHEMA_OID);
	if ( at_schema == NULLAttrT)
		fatal (-24,"treeStructure attribute type missing - check oidtables");
	tab_schema = at_schema;

	if ( (tab_edbinfo = name2attr (EDBINFO_OID)) == NULLTABLE_ATTR)
		fatal (-25,"edbinfo attribute type missing - check oidtables");

	if ( (tab_masterdsa = name2attr (MASTERDSA_OID)) == NULLTABLE_ATTR)
		fatal (-26,"masterDSA attribute type missing - check oidtables");

	if ( (tab_slavedsa = name2attr (SLAVEDSA_OID)) == NULLTABLE_ATTR)
		fatal (-27,"slaveDSA attribute type missing - check oidtables");

	if ( (tab_dsaaddress = name2attr (DSAADDRESS_OID)) == NULLTABLE_ATTR)
		fatal (-28,"dsaAddress attribute type missing - check oidtables");

	if ( (tab_version = name2attr (VERSION_OID)) == NULLTABLE_ATTR)
		fatal (-31,"version attribute type missing - check oidtables");

	if ( ( alias_oc = str2oid (ALIAS_OC)) == NULLOID)
		fatal (-32, "alias objectclass missing");

	alias_oc = oid_cpy (alias_oc);
	quipu_dsa_oid = oid_cpy (str2oid(QUIPU_DSA));

	if ( (at_p_password = AttrT_new(PROTECTED_OID)) == NULLAttrT)
		fatal (-33, "protectedPassword attribute type missing - check oidtables");

	if ( (at_certificate = AttrT_new(CERTIFICATE_OID)) == NULLAttrT)
		fatal (-34, "userCertificate attribute type missing - check oidtables");
}

real_unravel_attribute (eptr,error)
Entry eptr;
struct DSError * error;
{
register Attr_Sequence as;
RDN new_rdn, rdn_test;
AttributeType at;
AV_Sequence   avs;
struct acl * acl = (struct acl *) NULL;
extern oid_cmp ();
char * dsa_version = NULLCP;
char oc_found = FALSE;
int rdn_print();

	DLOG (log_dsap,LLOG_TRACE,("unravel_attributes"));

	/* take rdn's and make sure an attribute, if not add it in */
    for (new_rdn = eptr->e_name; new_rdn != NULLRDN; new_rdn = new_rdn->rdn_next) {
	if (new_rdn->rdn_at != NULLTABLE_ATTR)
		new_rdn->rdn_av.av_syntax = new_rdn->rdn_at->oa_syntax;

	if (new_rdn->rdn_av.av_syntax == 0) {
		/* Check we know about local RDNs syntax */
		if (eptr->e_data == E_DATA_MASTER) {
			LLOG (log_dsap, LLOG_EXCEPTIONS, ("RDN of unknown attribute type"));
			error->dse_type = DSE_UPDATEERROR;
			error->ERR_UPDATE.DSE_up_problem = DSE_UP_NAMINGVIOLATION;
			return NOTOK;
		}
	}

	for (rdn_test = eptr->e_name; rdn_test != new_rdn; rdn_test = rdn_test->rdn_next)
		/* check for repeated attribute in RDN */
		if (AttrT_cmp (new_rdn->rdn_at, rdn_test->rdn_at) == 0) {
			LLOG (log_dsap, LLOG_EXCEPTIONS, ("RDN with two AVAs of same attribute type"));
			error->dse_type = DSE_UPDATEERROR;
			error->ERR_UPDATE.DSE_up_problem = DSE_UP_NAMINGVIOLATION;
			return NOTOK;
		}
			
	if ((as = as_find_type (eptr->e_attributes,new_rdn->rdn_at)) == NULLATTR) {
		SET_HEAP (new_rdn->rdn_at);
		at  = AttrT_cpy (new_rdn->rdn_at);
		avs = avs_comp_new (AttrV_cpy(&new_rdn->rdn_av));
		as  = as_comp_new (at, avs, NULLACL_INFO);
		eptr->e_attributes = as_merge (eptr->e_attributes,as);
		RESTORE_HEAP;
	} else {
		for (avs=as->attr_value; avs!=NULLAV; avs=avs->avseq_next) 
			if (AttrV_cmp (&new_rdn->rdn_av,&avs->avseq_av) == 0)
				break;
		if (avs == NULLAV) {
			SET_HEAP (new_rdn->rdn_at);
			avs = avs_comp_new (AttrV_cpy(&new_rdn->rdn_av));
			as->attr_value = avs_merge (as->attr_value,avs);
			RESTORE_HEAP;
		}
	}
    }

	/* now get special attributes into structure */
	/* first reset pointerss - incase deleted. */

	eptr->e_alias = NULLDN;
	eptr->e_dsainfo = NULLDSA;
	eptr->e_master = NULLAV;
	eptr->e_slave = NULLAV;

	for ( as = eptr->e_attributes; as != NULLATTR; as = as->attr_link) {
		if (as->attr_type == NULLTABLE_ATTR) {
			error->dse_type = DSE_ATTRIBUTEERROR;
			error->ERR_ATTRIBUTE.DSE_at_name = get_copy_dn (eptr);
			error->ERR_ATTRIBUTE.DSE_at_plist.DSE_at_what = DSE_AT_UNDEFINEDATTRIBUTETYPE;
			error->ERR_ATTRIBUTE.DSE_at_plist.DSE_at_type = NULLAttrT;
			error->ERR_ATTRIBUTE.DSE_at_plist.DSE_at_value = NULLAttrV;
			error->ERR_ATTRIBUTE.DSE_at_plist.dse_at_next = DSE_AT_NOPROBLEM;
			return (NOTOK);
		}
		
		if (as->attr_type == tab_acl) {
			eptr->e_acl = (struct acl *) as->attr_value->avseq_av.av_struct;
			acl = eptr->e_acl;
			if (acl->ac_child == NULLACL_INFO)
				acl->ac_child = acl_default ();
			if (acl->ac_entry == NULLACL_INFO)
				acl->ac_entry = acl_default ();
			if (acl->ac_default == NULLACL_INFO)
				acl->ac_default = acl_default ();
		}

		else if (as->attr_type == tab_edbinfo) {
			if (eptr->e_dsainfo == NULLDSA) {
				eptr->e_dsainfo = (struct dsa_info *) smalloc (sizeof (struct dsa_info));
				bzero ((char *)eptr->e_dsainfo,sizeof (struct dsa_info));
			}
			eptr->e_dsainfo->dsa_attr = as->attr_value;
		}

		else if (as->attr_type == tab_masterdsa) {
			eptr->e_master = as->attr_value;
			eptr->e_leaf = FALSE;
		}

		else if (as->attr_type == tab_slavedsa) {
			eptr->e_slave = as->attr_value;
			eptr->e_leaf = FALSE;
		}

		else if (as->attr_type == tab_dsaaddress) {
			if (eptr->e_dsainfo == NULLDSA) {
				eptr->e_dsainfo = (struct dsa_info *) smalloc (sizeof (struct dsa_info));
				bzero ((char *)eptr->e_dsainfo,sizeof (struct dsa_info));
			}
			eptr->e_dsainfo->dsa_addr = (struct PSAPaddr *) as->attr_value->avseq_av.av_struct;
		}

		else if (as->attr_type == tab_alias)
			eptr->e_alias = (DN) as->attr_value->avseq_av.av_struct;

		else if (as->attr_type == tab_version)
			dsa_version = (char *) as->attr_value->avseq_av.av_struct;

		else if (as->attr_type == tab_objectclass) 
			oc_found = TRUE;

	}

	if ((eptr->e_master == NULLAV) && (eptr->e_slave == NULLAV))
		/* May need a stronger test here */
		eptr->e_leaf = TRUE;

	if (eptr->e_dsainfo != NULLDSA) /* set version number */
		eptr->e_dsainfo->dsa_version = dsa_version;

	if (oc_found != TRUE) {
		LLOG (log_dsap, LLOG_EXCEPTIONS, ("Object class attribute missing"));
		error->dse_type = DSE_UPDATEERROR;
		error->ERR_UPDATE.DSE_up_problem = DSE_UP_OBJECTCLASSVIOLATION;
		return (NOTOK);
	}
	/* Make sure acl attribute exists */
	if (eptr->e_acl == (struct acl *) NULL) {
		Attr_Sequence as1;
		AV_Sequence avs1;
		AttributeValue av;

		SET_HEAP (at_acl);

		acl = acl_alloc();
		eptr->e_acl = acl;
		acl->ac_child = acl_default ();
		acl->ac_entry = acl_default ();
		acl->ac_default = acl_default ();
		acl->ac_attributes = NULLACL_ATTR;
		av = AttrV_alloc();
		av->av_syntax = str2syntax ("acl");
		av->av_struct = (caddr_t) acl;
		avs1 = avs_comp_new (av);
		as1 = as_comp_new (AttrT_cpy(at_acl),avs1,NULLACL_INFO);
		eptr->e_attributes = as_merge(eptr->e_attributes,as1);

		RESTORE_HEAP;
	}

	/* now do the attribute acl */
	/* first of all create and oid_seq of all attribute, and point them to */
	/* the default.  */
	if (acl->ac_attributes == NULLACL_ATTR) {
		/* the easy case !!! - set every attribute to ac_default */
		for ( as = eptr->e_attributes; as != NULLATTR; as = as->attr_link) 
			as->attr_acl = acl->ac_default;
	} else {
		register struct acl_attr * aa;
		struct acl_attr * found_aa;
		register struct oid_seq * oidptr;
		char once;

		/* The following is probably in efficient */
		/* There must be a better way of setting these pointers */
		for ( as = eptr->e_attributes; as != NULLATTR; as = as->attr_link) {
			found_aa = NULLACL_ATTR;
			once = FALSE;

			for ( aa = acl->ac_attributes; aa!=NULLACL_ATTR; aa=aa->aa_next) {
				for ( oidptr=aa->aa_types;oidptr != NULLOIDSEQ; oidptr=oidptr->oid_next) {
					if (oid_cmp (oidptr->oid_oid,grab_oid(as->attr_type)) == 0) {
						if (once == TRUE)
							pslog (log_dsap,LLOG_EXCEPTIONS,
								"WARNING Inconsistent ACL in entry",
								rdn_print,
							        (caddr_t)eptr->e_name);
						else
							once = TRUE;
						found_aa = aa;
					}
				}
			}

			if (found_aa != NULLACL_ATTR) 
				/* found the apprioriate acl - add oid to it */
				as->attr_acl = found_aa->aa_acl;
			else
				as->attr_acl = acl->ac_default;
		}
	}
	return (OK);
}

unix.superglobalmegacorp.com

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