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 m

⟦edbce74ee⟧ TextFile

    Length: 8408 (0x20d8)
    Types: TextFile
    Names: »modify.c«

Derivation

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

TextFile

#include "quipu/util.h"
#include "quipu/modify.h"
#include "quipu/entry.h"
#include "quipu/dua.h"

extern DN       dn;
extern PS       opt,
                rps;
extern Entry    current_entry;
extern LLog    *log_dua;
static char     new_draft;

call_modify (argc, argv)
int             argc;
char          **argv;
{
	struct ds_modifyentry_arg mod_arg;

	struct DSError  error;
	struct entrymod *em = NULLMOD,
	               *emnew;
	Attr_Sequence   as,
			get_attributes (),
	                temp,
	                trail = NULLATTR;
	AV_Sequence     avs,
	                avst = NULLAV;
	extern AttributeType at_objectclass;
	int             change;
	extern char     fname[];
	extern int	parse_status;
	Entry           entry_ptr;
	FILE           *fd;
	char            draft_flag = FALSE;
	char		noedit_flag = FALSE;
	int 		x;
	DN		moddn;

	if ((argc = service_control (opt, argc, argv, &mod_arg.mea_common)) == -1)
		return;

	mod_arg.mea_changes = NULLMOD;
	new_draft = FALSE;

	(void) sprintf (fname, "%s/.dishdraft", getenv ("HOME"));
	
	for (x=1; x<argc; x++) {
		if (test_arg (argv[x], "-draft",1)) {
			draft_flag = 1;
			DLOG (log_dua, LLOG_TRACE, ("We have a -draft flag.\n"));
			shuffle_up (argc--,argv,x);
			if (x == argc) {
				ps_printf (opt, "Draft file name missing\n");
				Usage (argv[0]);
				return;
			}
			(void) strcpy (fname, argv[x]);
			shuffle_up (argc--,argv,x--);
		} else if (test_arg (argv[x], "-newdraft",2)) {
			new_draft = TRUE;
			shuffle_up (argc--,argv,x--);			
		} else if (test_arg (argv[x], "-noedit",3)) {
			noedit_flag = TRUE;
			shuffle_up (argc--,argv,x--);			
		} else if (move (argv[x]) == OK) 
			shuffle_up (argc--,argv,x--);			
		else {
			Usage (argv[0]);
			return;
		}
	}

	/* read attributes we want to modify */
	if ((argc = read_cache (argc, argv)) <0 )
		return;

	if (argc != 1) {
		ps_printf (opt,"Unknown option %s\n",argv[1]);
		Usage (argv[0]);
		return;
	}
	
	if (!draft_flag) {
		if (mod_template (fname) != OK)
			return;
		noedit_flag = FALSE;
	}

	if (! noedit_flag)
		if (editentry (1, argv) != OK) {
			make_old (fname,draft_flag);
			return;
		}

	/* now parse the files */

	if ((fd = fopen (fname, "r")) == (FILE *) NULL) {
		ps_printf (opt, "Can't open draft entry %s\n", fname);
		return;
	}

	entry_ptr = get_default_entry (NULLENTRY);
	entry_ptr->e_attributes = get_attributes (fd);

	(void) fclose (fd);
	if (parse_status != 0)
		return;

	mod_arg.mea_object = dn;
	for (moddn = dn ; moddn->dn_parent != NULLDN; moddn=moddn->dn_parent)
		;
	entry_ptr->e_name = rdn_cpy (moddn->dn_rdn);
	
	/* add rdn as attribute */
	avst = avs_comp_new (AttrV_cpy (entry_ptr->e_name->rdn_av));
	temp = as_comp_new (AttrT_cpy (entry_ptr->e_name->rdn_at), avst, NULLACL_INFO);
	entry_ptr->e_attributes = as_merge (entry_ptr->e_attributes, temp);

	for (as = entry_ptr->e_attributes; as != NULLATTR; as = as->attr_link) {
		change = TRUE;
		if (trail != NULLATTR)
			trail->attr_link = NULLATTR;	/* break list */

		/* search read result for this attribute, if found */
		/* it must be removed before added */
		temp = current_entry->e_attributes;
		for (; temp != NULLATTR; temp = temp->attr_link) {
			if (AttrT_cmp (as->attr_type, temp->attr_type) == 0) {

				/* found it - does it need changing ? */
				if (avs_cmp (as->attr_value, temp->attr_value) != 0) {

					if (AttrT_cmp (as->attr_type, current_entry->e_name->rdn_at) == 0) {
						/* this is the rdn */
						/* add *new* value, can't delete old one !!! */
						/* also can't send old one ->X500 error */
						for (avs = as->attr_value; avs != NULLAV; avst = avs, avs = avs->avseq_next)
							if (AttrV_cmp (avs->avseq_av, entry_ptr->e_name->rdn_av,&error) == 0)
								if (avst == NULLAV)
									as->attr_value = avs->avseq_next;
								else
									avst->avseq_next = avs->avseq_next;
						if (as->attr_value != NULLAV) {
							emnew = em_alloc ();
							emnew->em_type = EM_ADDVALUES;
							emnew->em_what = as;
							emnew->em_next = NULLMOD;
							if (em == NULLMOD)
								mod_arg.mea_changes = emnew;
							else
								em->em_next = emnew;
							em = emnew;
						}
						change = FALSE;
					} else {
						emnew = em_alloc ();
						emnew->em_type = EM_REMOVEATTRIBUTE;
						emnew->em_what = as;
						emnew->em_next = NULLMOD;
						if (em == NULLMOD)
							mod_arg.mea_changes = emnew;
						else
							em->em_next = emnew;
						em = emnew;
					}
				} else
					change = FALSE;

				break;
			}
		}
		if (change) {
			emnew = em_alloc ();
			emnew->em_type = EM_ADDATTRIBUTE;
			emnew->em_what = as;
			emnew->em_next = NULLMOD;
			if (em == NULLMOD)
				mod_arg.mea_changes = emnew;
			else
				em->em_next = emnew;
			em = emnew;

			trail = as;
		}
	}

	if (mod_arg.mea_changes == NULLMOD) {
		ps_print (rps, "The draft entry and the entry for ");
		dn_print (rps, dn, EDBOUT);
		ps_print (rps, "\nare exactly the same - no change made!!!\n");
		entry_free (entry_ptr);
		make_old (fname,draft_flag);
		return;
	}

	if (rebind () != OK) {
		entry_free (entry_ptr);
		return;
	}

	if (ds_modifyentry (&mod_arg, &error) != DS_OK) {
		ds_error (opt, &error);
		ps_print (opt, "\n");
		entry_free (entry_ptr);
		return;
	}
	ps_print (rps, "Modified  ");
	dn_print (rps, dn, READOUT);
	ps_print (rps, "\n");
	delete_cache (dn);	/* re-cache when next read */
	
	entry_free (entry_ptr);
	ems_part_free (mod_arg.mea_changes);

	make_old (fname,draft_flag);

}

ems_part_free(emp)
struct entrymod *emp;
{
	if(emp == NULLMOD)
		return;
	ems_part_free(emp->em_next);
	free((char *)emp);
}

dsa_control (argc, argv)
int             argc;
char          **argv;
{
	static struct entrymod mod = {
				      EM_ADDATTRIBUTE,
				      NULLATTR,
				      NULLMOD
	};

	static struct ds_modifyentry_arg mod_arg =
	{
	 default_common_args,
	 NULLDN,
	 &mod
	};

	struct DSError  error;
	char            buffer[100];

	if (test_arg (argv[1], "-lock",1))
		(void) sprintf (buffer, " ,1%s", argv[2]);
	else if (test_arg (argv[1], "-unlock",1))
		(void) sprintf (buffer, "u %s", argv[2]);
	else if (test_arg (argv[1], "-dump",1))
		(void) sprintf (buffer, "d %s", argv[2]);
	else if (test_arg (argv[1], "-tailor",1))
		(void) sprintf (buffer, "t %s", argv[2]);
	else if (test_arg (argv[1], "-slave",1)) {
		buffer[0] = 's';
		argc++;		/* to get through if (argc != 3) */
	} else if (test_arg (argv[1], "-abort",1)) {
		buffer[0] = 'a';
		argc++;		/* to get through if (argc != 3) */
	} else if (test_arg (argv[1], "-refresh",3))
		(void) sprintf (buffer, "r %s", argv[2]);
	else if (test_arg (argv[1], "-resync",2))
		(void) sprintf (buffer, "f %s", argv[2]);
	else
		argc = 1;	/* to force error */

	if (argc != 3) {
		Usage (argv[0]);
		return;
	}
	mod_arg.mea_object = dn;
	mod_arg.mea_changes->em_what = as_comp_new (AttrT_new ("control"), avs_comp_new (str2AttrV (buffer, AV_CASEIGNORESTRING)), NULLACL_INFO);

	if (ds_modifyentry (&mod_arg, &error) != DS_OK) {
		/* deal with error */
		ds_error (opt, &error);
	} else {
		ps_print (rps, "Done\n");
		return;
	}
	/* as_free (mod_arg.mea_changes->em_what); */
}

mod_template (name)
char           *name;
{
	FILE           *fptr;
	PS              ps;
	extern oid_table_attr * tab_objectclass;
	Attr_Sequence   as, trail = NULLATTR;
	Attr_Sequence   nas, tas, make_template_as ();
	int		um;

	if (! new_draft)
		if ((fptr = fopen (name, "r")) != NULL) {
			(void) fclose (fptr);
			return (OK);	/* template already exists ! */
		}

	um = umask (0177);
	if ((fptr = fopen (name, "w")) == NULL) {
		ps_printf (opt, "Can't open template entry %s\n", name);
		return (-1);
	}
	(void) umask (um);

	if ((ps = ps_alloc (std_open)) == NULLPS) {
		return (-1);
	}
	if (std_setup (ps, fptr) == NOTOK) {
		return (-1);
	}
	as_decode (current_entry->e_attributes);

	for (as = current_entry->e_attributes; as != NULLATTR; as = as->attr_link) 
		if (as->attr_type->at_table == tab_objectclass)
			break;

	tas = make_template_as (as->attr_value);
	nas = as_cpy(current_entry->e_attributes);
	
	for (as = nas; as != NULLATTR; as = as->attr_link) {
		/* remove photo attribute for now !!! */
		if (as->attr_value->avseq_av->av_syntax == AV_PHOTO) {
			if (trail == NULLATTR)
				nas = as->attr_link;
			else
				trail->attr_link = as->attr_link;
			as_comp_free (as);
			break; 
		}
		trail = as;
	}

	tas = as_merge (tas,nas);

	as_print (ps,tas,EDBOUT);

	as_free (tas);
	ps_free (ps);
	(void) fclose (fptr);

	return (OK);
}