Exemplo n.º 1
0
static void remove_item(Prioq *q, struct prioq_item *i) {
        struct prioq_item *l;

        assert(q);
        assert(i);

        l = q->items + q->n_items - 1;

        if (i == l)
                /* Last entry, let's just remove it */
                q->n_items--;
        else {
                unsigned k;

                /* Not last entry, let's replace the last entry with
                 * this one, and reshuffle */

                k = i - q->items;

                i->data = l->data;
                i->idx = l->idx;
                if (i->idx)
                        *i->idx = k;
                q->n_items--;

                k = shuffle_down(q, k);
                shuffle_up(q, k);
        }
}
Exemplo n.º 2
0
int prioq_put(Prioq *q, void *data, unsigned *idx) {
        struct prioq_item *i;
        unsigned k;

        assert(q);

        if (q->n_items >= q->n_allocated) {
                unsigned n;
                struct prioq_item *j;

                n = MAX((q->n_items+1) * 2, 16u);
                j = realloc(q->items, sizeof(struct prioq_item) * n);
                if (!j)
                        return -ENOMEM;

                q->items = j;
                q->n_allocated = n;
        }

        k = q->n_items++;
        i = q->items + k;
        i->data = data;
        i->idx = idx;

        if (idx)
                *idx = k;

        shuffle_up(q, k);

        return 0;
}
Exemplo n.º 3
0
void pa_prioq_reshuffle(pa_prioq *q, pa_prioq_item *i) {
    pa_assert(q);
    pa_assert(i);

    /* This will move the entry down as far as necessary */
    shuffle_down(q, i->idx);

    /* And this will move the entry up as far as necessary */
    shuffle_up(q, i);
}
Exemplo n.º 4
0
int 
osisecinit (int *argc, char ***argv, int fn)
{
	char   *ap;
	char  **argptr;
	static char   *args[10];
	static int     argp;
	int	       narg;

	if(fn == 0) {
		argp = 0;
		narg = 1;
		args[argp++] = (*argv)[0];
		for (argptr = *argv, argptr++; ap = *argptr ; argptr++, narg++) {
			if (*ap == '-')
				switch (*++ap) {
				case 'A':
					if ((ap = *++argptr) == NULL || *ap == '-')
						break;
					shuffle_up ((*argc)--, *argv, narg);
					shuffle_up ((*argc)--, *argv, narg);
					args[argp++] = "-A";
					args[argp++] = ap;
					break;

				default:
					continue;
				}

			break;
		}
		args[argp] = NULLCP;
	}

#ifdef OSISEC

	else
		osisec_init (&argp, (argptr = args, &argptr));

#endif

}
Exemplo n.º 5
0
int prioq_reshuffle(Prioq *q, void *data, unsigned *idx) {
        struct prioq_item *i;
        unsigned k;

        assert(q);

        i = find_item(q, data, idx);
        if (!i)
                return 0;

        k = i - q->items;
        k = shuffle_down(q, k);
        shuffle_up(q, k);
        return 1;
}
Exemplo n.º 6
0
pa_prioq_item* pa_prioq_put(pa_prioq *q, void *p) {
    pa_prioq_item *i;

    pa_assert(q);

    if (q->n_items >= q->n_allocated) {
        q->n_allocated = PA_MAX(q->n_items+1, q->n_allocated)*2;
        q->items = pa_xrealloc(q->items, sizeof(pa_prioq_item*) * q->n_allocated);
    }

    if (!(i = pa_flist_pop(PA_STATIC_FLIST_GET(items))))
        i = pa_xnew(pa_prioq_item, 1);

    i->value = p;
    i->idx = q->n_items++;

    shuffle_up(q, i);

    return i;
}
Exemplo n.º 7
0
int 
call_moveto (int argc, char **argv)
{
	char pwd_flag = FALSE;
	char check_move = TRUE;
	int x;

	if (argc == 1) {
		Usage (argv[0]);
		return;
	}

	move_flag = FALSE;

	for (x = 1; x < argc; x++) {
		if (test_arg (argv[x],"-pwd",1))
			pwd_flag = TRUE;
		else if (test_arg (argv[x],"-nopwd",3))
			pwd_flag = FALSE;
		else if (test_arg (argv[x],"-check",1))
			check_move = TRUE;
		else if (test_arg (argv[x],"-nocheck",3))
			check_move = FALSE;
		else if (test_arg (argv[x], "-sequence",3)) {
			if (x + 1 == argc) {
				ps_printf (OPT, "We need a sequence name.\n");
				return;
			} else {
				shuffle_up (argc--, argv, x);
				set_sequence (argv[x]);
			}
		} else if (move (argv[x]) == OK) {
			if (move_flag == TRUE) {
				ps_print (RPS,"Too many parameters !\n");
				Usage (argv[0]);
				return;
			}
			move_flag = TRUE;
		} else {
			move_flag = FALSE;
			if (*argv[x] != '-')
				ps_printf (OPT,"Unknown entity '%s'\n",argv[x]);
			else
				Usage (argv[0]);
			return;
		}
	}

	if (check_move)
		if (test_move_dn() != TRUE) {
			move_flag = FALSE;
			return;
		}

	if (move_flag == TRUE)
		consolidate_move ();

	if (pwd_flag) {
		dn_print (RPS, fixed_pos, EDBOUT);
		ps_print (RPS, "\n");
	}

}
Exemplo n.º 8
0
int 
call_showentry (int argc, char **argv)
{
	Attr_Sequence   eptr;
	char           *vect[2];
	int             x;
	extern char	name_flag;
	extern char	all_flag;
	extern Attr_Sequence as_flag;
	extern char	flag_show;
	char            full_edb_flag;
	char            *temp_file_name;
	extern int      mod_template();

	vect[0] = "showentry";

	move_flag = FALSE;
	fred_flag = FALSE;
	fred_expand = FALSE;
	fred_list = FALSE;
	fred_long = 2;
	fred_phone = FALSE;
	fred_photo = FALSE;
	fred_sequence = TRUE;
	fred_subdisplay = FALSE;
	name_flag = FALSE;
	full_edb_flag = FALSE;

	for (x=1; x<argc; x++) {
		if (test_arg (argv[x], "-move",2))
			move_flag = TRUE;
		else if (test_arg (argv[x], "-nomove",3))
			move_flag = FALSE;
		else if (test_arg (argv[x], "-fred",4))
			fred_flag = TRUE;
		else if (test_arg (argv[x], "-expand",4))
			fred_expand = TRUE;
		else if (test_arg (argv[x], "-fredlist",8))
			fred_list = TRUE;
		else if (test_arg (argv[x], "-full",4))
			fred_long = TRUE;
		else if (test_arg (argv[x], "-summary",7))
			fred_long = FALSE;
		else if (test_arg (argv[x], "-phone",5))
			fred_phone = TRUE;
		else if (test_arg (argv[x], "-fredphoto",9))
			fred_photo = dad_flag;
		else if (test_arg (argv[x], "-nofredseq",9))
			fred_sequence = FALSE;
		else if (test_arg (argv[x], "-subdisplay",10))
			fred_subdisplay = TRUE;
		else if (test_arg (argv[x], "-fedb",4)) {
			if (x + 1 == argc) {
				ps_printf (opt, "We need a filename for the full edb entry.\n");
				return;
			} else {
				shuffle_up (argc, argv, x);
				argc--;
				if (*(temp_file_name = argv[x]) != '/') {
					ps_printf (opt, "We need a real file spec for the file name.\n");
					return;
				}
			}
			full_edb_flag = TRUE;
		} else
			continue;
		shuffle_up (argc--,argv,x--);

	}
	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 (current_entry == NULLENTRY) {
		ps_print (OPT,"Specify an entry \n");
		/* this CAN happen - when the entry is not cache, but -noread */
		return;
	}
	if (full_edb_flag) {
		 mod_template(temp_file_name,0);
		return;
	}

	if (fred_flag) {
		if (fred_long == 2)
			if ((fred_subdisplay && fred_expand)
					|| (!fred_subdisplay && !fred_expand))
				fred_long = TRUE;
			else
				fred_long = fred_expand;
		if (fred_expand)
			fred_long = fred_subdisplay = TRUE;

		if (fred_list
				&& frompipe
				&& rps -> ps_byteno == 0
				&& opt -> ps_byteno == 0) {
			DN	new_dn = dn_cpy (current_dn);

			showfredDNs (new_dn, fred_long);
			dn_free (new_dn);
		}

		 showfred (current_dn, fred_long, fred_subdisplay);
	} else {
		if (name_flag) {
			dn_print (RPS,dn,EDBOUT);
			ps_print (RPS,"\n");
		}

		if (all_flag)
			eptr = current_entry->e_attributes;
		else
			eptr = as_flag;

		if (flag_show)
			for (; eptr != NULLATTR; eptr = eptr->attr_link)
				showattribute (eptr->attr_type);
	}

	consolidate_move();
}
Exemplo n.º 9
0
int 
call_modify (int argc, char **argv)
{
	struct ds_modifyentry_arg mod_arg;

	struct DSError  error;
	struct entrymod *emnew, *ems_append(), *modify_avs();
	Attr_Sequence   as,
#ifdef TURBO_DISK
					fget_attributes (),
#else
					get_attributes (),
#endif
					temp,
					trail = NULLATTR;
	AV_Sequence     avst = NULLAV;
	extern AttributeType at_objectclass;
	extern int	parse_status;
	Entry           entry_ptr;
	FILE           *fd;
	char            draft_flag = FALSE;
	char		noedit_flag = FALSE;
	int 		x;
	DN		moddn;
	char	       *home;
	RDN		new_rdn;

	struct  list_element   *start = 0 ;
	struct  list_element   *last ;
	struct  list_element   *l_temp ;

	/*	char	add = FALSE ;
		char	rem = FALSE ;
	 */
	if ((argc = service_control (OPT, argc, argv, &mod_arg.mea_common)) == -1)
		return;

	mod_arg.mea_changes = NULLMOD;
	new_draft = FALSE;

	if (home = getenv ("DISHDRAFT"))
		 strcpy (fname, home);
	else if (dad_flag) {
		 strcpy (fname, "/tmp/dishXXXXXX");
		 unlink (mktemp (fname));
	} else if (home = getenv ("HOME"))
		 sprintf (fname, "%s/.dishdraft", home);
	else
		 strcpy (fname, "./.dishdraft");

	for (x=1; x<argc; x++) {
		if (test_arg (argv[x], "-draft",1)) {
			draft_flag = 1;
			shuffle_up (argc--,argv,x);
			if (x == argc) {
				ps_printf (OPT, "Draft file name missing\n");
				Usage (argv[0]);
				return;
			}
			 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 if (test_arg(argv[x], "-remove", 3)) {
			shuffle_up (argc--, argv, x);
			if (x == argc) {
				ps_printf(OPT, "Attribute to remove missing\n") ;
				Usage(argv[0]) ;
				return ;
			}
			l_temp = (struct list_element *) malloc (sizeof(struct list_element)) ;
			l_temp->mod = (char *) malloc ((unsigned)(strlen(argv[x]) + 1));
			 strcpy (l_temp->mod, argv[x]) ;
			l_temp->add = 0 ;
			l_temp->next = 0 ;
			if (start == 0) {
				start = last = l_temp ;
			} else {
				last->next = l_temp ;
				last = l_temp ;
			}
			shuffle_up (argc--,argv,x--);
		} else if (test_arg(argv[x], "-add", 2)) {
			shuffle_up (argc--, argv, x);
			if (x == argc) {
				ps_printf(OPT, "Attribute to insert missing\n") ;
				Usage(argv[0]) ;
				return ;
			}
			l_temp = (struct list_element *) malloc (sizeof(struct list_element)) ;
			l_temp->mod = (char *) malloc ((unsigned)(strlen(argv[x]) + 1));
			 strcpy (l_temp->mod, argv[x]) ;
			l_temp->add = 1 ;
			l_temp->next = 0 ;
			if (start == 0) {
				start = last = l_temp ;
			} else {
				last->next = l_temp ;
				last = l_temp ;
			}
			shuffle_up (argc--,argv,x--);
		}
	}

	if (dad_flag && (draft_flag || noedit_flag)) {
		ps_printf (OPT,
				   "operation not allowed when using directory assistance server!\n");
		return;
	}

	/* read attributes we want to modify */
	if ((argc = read_cache_aux (argc, argv, FALSE, &mod_arg.mea_common)) <0 )
		return;

	if (argc != 1) {
		ps_printf (OPT,"Unknown option %s\n",argv[1]);
		Usage (argv[0]);
		return;
	}

	if (start != 0) {
		if (build_modify(start, &mod_arg) == NOTOK) {
			return ;
		}

		while (ds_modifyentry (&mod_arg, &error) != DS_OK) {
			if (dish_error (OPT, &error) == 0) {
				return ;
			}
			mod_arg.mea_object = error.ERR_REFERRAL.DSE_ref_candidates->cr_name ;
		}
		ps_print (RPS, "Modified ");
		dn_print (RPS, dn, EDBOUT);
		ps_print (RPS, "\n");
		delete_cache (dn);  /* re-cache when next read */
		return ;
	}

	if (!draft_flag) {
		if (mod_template (fname,noedit_flag) != OK)
			return;
		noedit_flag = FALSE;
	} else {
		new_draft = TRUE;	/* Ugh ! */
		 mod_template ("/dev/null",TRUE);
	}

	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);
#ifdef TURBO_DISK
	entry_ptr->e_attributes = fget_attributes (fd);
#else
	entry_ptr->e_attributes = get_attributes (fd);
#endif

	 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 */
	for (new_rdn = entry_ptr->e_name; new_rdn != NULLRDN; new_rdn = new_rdn->rdn_next) {
		avst = avs_comp_new (AttrV_cpy (&new_rdn->rdn_av));
		temp = as_comp_new (AttrT_cpy (new_rdn->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) {
		emnew = NULLMOD;
		trail = as->attr_link;
		as->attr_link = NULLATTR;

		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)
					emnew = modify_avs (as->attr_value, temp->attr_value,as->attr_type);
				break;
			}

		if (temp == NULLATTR) {
			emnew = em_alloc ();
			emnew->em_type = EM_ADDATTRIBUTE;
			emnew->em_what = as_cpy(as);
			emnew->em_next = NULLMOD;
		}

		if (emnew != NULLMOD)
			mod_arg.mea_changes = ems_append (mod_arg.mea_changes,emnew);

		as->attr_link = trail;
	}

	/* remove attribute missing in new entry */
	for (as = current_entry->e_attributes; as != NULLATTR; as = as->attr_link) {
		emnew = NULLMOD;

		temp = entry_ptr->e_attributes;
		for (; temp != NULLATTR; temp = temp->attr_link)
			if (AttrT_cmp (as->attr_type, temp->attr_type) == 0)
				break;

		if (temp == NULLATTR) {
			emnew = em_alloc ();
			emnew->em_type = EM_REMOVEATTRIBUTE;
			emnew->em_what = as_comp_new(as->attr_type,NULLAV,NULLACL_INFO);
			emnew->em_next = NULLMOD;
		}

		if (emnew != NULLMOD)
			mod_arg.mea_changes = ems_append (mod_arg.mea_changes,emnew);
	}


	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 this operation is time-stamped, it may have expired while the user
	 * was editing the entry. Re-calculate the time-stamp. Modify is the only
	 * dish command where this needs to be done.
	 */

	if ((mod_arg.mea_common.ca_security != (struct security_parms *) 0)
			&& (mod_arg.mea_common.ca_security->sp_time != NULLCP)) {
		char *new_version();

		free(mod_arg.mea_common.ca_security->sp_time);
		mod_arg.mea_common.ca_security->sp_time = new_version();
	}

	/* If security parameters are present, take this to mean that strong
	 * authentication is required. This disallows 'parms + no signature'
	 * (pointless) and 'signature + no parms' (security risk).
	 */
	if (mod_arg.mea_common.ca_security != (struct security_parms *) 0) {
		extern struct SecurityServices *dsap_security;

		mod_arg.mea_common.ca_sig =
			(dsap_security->serv_sign)((caddr_t)&mod_arg,
									   _ZModifyEntryArgumentDataDAS, &_ZDAS_mod);
	}

	while (ds_modifyentry (&mod_arg, &error) != DS_OK) {
		if (dish_error (OPT, &error) == 0) {
			entry_free (entry_ptr);
			return;
		}
		mod_arg.mea_object = error.ERR_REFERRAL.DSE_ref_candidates->cr_name;
	}
	ps_print (RPS, "Modified ");
	dn_print (RPS, dn, EDBOUT);
	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);
}