Example #1
0
File: urp.c Project: ohamada/389ds
static int
mod_namingconflict_attr (const char *uniqueid, const Slapi_DN *entrysdn,
                         const Slapi_DN *conflictsdn, CSN *opcsn)
{
	Slapi_Mods smods;
	char buf[BUFSIZ];
	int op_result;

	PR_snprintf (buf, sizeof(buf), "%s %s",
	             REASON_ANNOTATE_DN, slapi_sdn_get_dn(conflictsdn));
	slapi_mods_init (&smods, 2);
	if ( strncmp (slapi_sdn_get_dn(entrysdn), SLAPI_ATTR_UNIQUEID,
	     strlen(SLAPI_ATTR_UNIQUEID)) != 0 )
	{
		slapi_mods_add (&smods, LDAP_MOD_ADD, ATTR_NSDS5_REPLCONFLICT, strlen(buf), buf);
	}
	else
	{
		/*
		 * If the existing entry is already a naming conflict loser,
		 * the following replace operation should result in the
		 * replace of the ATTR_NSDS5_REPLCONFLICT index as well.
		 */
		slapi_mods_add (&smods, LDAP_MOD_REPLACE, ATTR_NSDS5_REPLCONFLICT, strlen(buf), buf);
	}
	op_result = urp_fixup_modify_entry (uniqueid, entrysdn, opcsn, &smods, 0);
	slapi_mods_done (&smods);
	return op_result;
}
Example #2
0
static int upgrade_db_3x_40(backend *be)
{
    struct ldbminfo *li = (struct ldbminfo *) be->be_database->plg_private;
    int ret = 0;
    back_txn        txn;

    static char* indexes_modified[] = {"parentid", "numsubordinates", NULL};

    LDAPDebug( LDAP_DEBUG_ANY, "WARNING: Detected a database older than this server, upgrading data...\n",0,0,0);

    dblayer_txn_init(li,&txn);
    ret = dblayer_txn_begin(li,NULL,&txn);
    if (0 != ret) {
        ldbm_nasty(filename,69,ret);
        goto error;
    }
    ret = indexfile_delete_all_keys(be,"parentid",&txn);
    if (0 != ret) {
        ldbm_nasty(filename,70,ret);
        goto error;
    }

    {
        Slapi_Mods smods;
           slapi_mods_init(&smods,1);
        /* Mods are to remove the hassubordinates attribute */
        slapi_mods_add(&smods, LDAP_MOD_DELETE, "hassubordinates", 0, NULL);
        /* This function takes care of generating the subordinatecount attribute and indexing it */
        ret = indexfile_primary_modifyall(be,slapi_mods_get_ldapmods_byref(&smods),indexes_modified,&txn);
        slapi_mods_done(&smods);
    }

    if (0 != ret) {
        ldbm_nasty(filename,61,ret);
    }

error:
    if (0 != ret ) {
        dblayer_txn_abort(li,&txn);
    } else {
        ret = dblayer_txn_commit(li,&txn);
        if (0 != ret) {
            ldbm_nasty(filename,60,ret);
        } else {
            /* Now update DBVERSION file */
        }
    }
    if (0 == ret) {
        LDAPDebug( LDAP_DEBUG_ANY, "...upgrade complete.\n",0,0,0);
    } else {
        LDAPDebug( LDAP_DEBUG_ANY, "ERROR: Attempt to upgrade the older database FAILED.\n",0,0,0);
    }
    return ret;
}
Example #3
0
static 
Slapi_Mods *windows_private_get_cookie_mod(Dirsync_Private *dp, int modtype)
{
	Slapi_Mods *smods = NULL;
	smods = slapi_mods_new();

	slapi_mods_add( smods, modtype,
	 "nsds7DirsyncCookie", dp->dirsync_cookie_len , dp->dirsync_cookie);	

	return smods;

}
Example #4
0
File: urp.c Project: ohamada/389ds
static int
del_replconflict_attr (const Slapi_Entry *entry, CSN *opcsn, int opflags)
{
	Slapi_Attr *attr;
	int op_result = 0;

	if (slapi_entry_attr_find (entry, ATTR_NSDS5_REPLCONFLICT, &attr) == 0)
	{
		Slapi_Mods smods;
		const char *uniqueid;
		const Slapi_DN *entrysdn;

		uniqueid = slapi_entry_get_uniqueid (entry);
		entrysdn = slapi_entry_get_sdn_const (entry);
		slapi_mods_init (&smods, 2);
		slapi_mods_add (&smods, LDAP_MOD_DELETE, ATTR_NSDS5_REPLCONFLICT, 0, NULL);
		op_result = urp_fixup_modify_entry (uniqueid, entrysdn, opcsn, &smods, opflags);
		slapi_mods_done (&smods);
	}
	return op_result;
}
Example #5
0
int
parent_update_on_childchange(modify_context *mc,int op, size_t *new_sub_count )
{
	int ret = 0;
	int mod_op = 0;
	Slapi_Attr	*read_attr = NULL;
	size_t current_sub_count = 0;
	int already_present = 0;
	int repl_op = 0;
	Slapi_Mods *smods = NULL;
	char value_buffer[20]; /* enough digits for 2^64 children */

	if (new_sub_count)
		*new_sub_count = 0;

	repl_op = PARENTUPDATE_TOMBSTONE_MASK & op;
	op &= PARENTUPDATE_MASK;

	/* Check nobody is trying to use op == 3, it's not implemented yet */
	PR_ASSERT( (op == PARENTUPDATE_ADD) || (op == PARENTUPDATE_DEL));

	/* We want to invent a mods set to be passed to modify_apply_mods() */

	/* For now, we're only interested in subordinatecount. 
	   We first examine the present value for the attribute. 
	   If it isn't present and we're adding, we assign value 1 to the attribute and add it.
	   If it is present, we increment or decrement depending upon whether we're adding or deleting.
	   If the value after decrementing is zero, we remove it.
	*/

	smods = slapi_mods_new();

	/* Get the present value of the subcount attr, or 0 if not present */
	ret = slapi_entry_attr_find(mc->old_entry->ep_entry,numsubordinates,&read_attr);
	if (0 == ret) {
		/* decode the value */
		Slapi_Value *sval;
		slapi_attr_first_value( read_attr, &sval );
		if (sval!=NULL) {
			const struct berval *bval = slapi_value_get_berval(sval);
			if(NULL != bval) {
			    already_present = 1;
			    current_sub_count = atol(bval->bv_val);
			}
		}
	}

	if (PARENTUPDATE_DELETE_TOMBSTONE != repl_op) {
		/* are we adding ? */
		if ( (PARENTUPDATE_ADD == op) && !already_present) {
			/* If so, and the parent entry does not already have a subcount 
			 * attribute, we need to add it */
			mod_op = LDAP_MOD_ADD;
		} else  if (PARENTUPDATE_DEL == op) {
			if (!already_present) {
				/* This means that something is wrong---deleting a child but no subcount present on parent */
				LDAPDebug0Args( LDAP_DEBUG_ANY,
				                "numsubordinates assertion failure\n" );
				slapi_mods_free(&smods);
				return -1;
			} else {
				if (current_sub_count == 1) {
					mod_op = LDAP_MOD_DELETE;
				} else {
					mod_op = LDAP_MOD_REPLACE;
				}
			}
		} else {
			/* (PARENTUPDATE_ADD == op) && already_present */
			mod_op = LDAP_MOD_REPLACE;
		}

		/* Now compute the new value */
		if (PARENTUPDATE_ADD == op) {
			current_sub_count++;
		} else {
			current_sub_count--;
		}

		if (mod_op == LDAP_MOD_DELETE) {
			slapi_mods_add(smods, mod_op | LDAP_MOD_BVALUES,
			               numsubordinates, 0, NULL);
		} else {
			sprintf(value_buffer,"%lu", current_sub_count);
			slapi_mods_add(smods, mod_op | LDAP_MOD_BVALUES, 
			               numsubordinates, strlen(value_buffer), value_buffer);
		}
		if (new_sub_count) {
			*new_sub_count = current_sub_count;
		}
	}

	/* tombstoneNumSubordinates is needed only when this is repl op
	 * and a child is being deleted */
	if (repl_op && (PARENTUPDATE_DEL == op)) {
		current_sub_count = LDAP_MAXINT;
		ret = slapi_entry_attr_find(mc->old_entry->ep_entry,
		                            tombstone_numsubordinates, &read_attr);
		if (0 == ret) {
			/* decode the value */
			Slapi_Value *sval;
			slapi_attr_first_value( read_attr, &sval );
			if (sval!=NULL) {
				const struct berval *bval = slapi_value_get_berval(sval);
				if(NULL != bval) {
					current_sub_count = atol(bval->bv_val);
				}
			}
		}

		if (PARENTUPDATE_DELETE_TOMBSTONE == repl_op) {
			/* deleting a tombstone entry: 
			 * reaping or manually deleting it */
			if ((current_sub_count != LDAP_MAXINT) && 
			    (current_sub_count > 0)) {
				current_sub_count--;
				mod_op = LDAP_MOD_REPLACE;
				sprintf(value_buffer,"%lu", current_sub_count);
				slapi_mods_add(smods, mod_op | LDAP_MOD_BVALUES, 
				               tombstone_numsubordinates,
				               strlen(value_buffer), value_buffer);
			}
		}

		if (PARENTUPDATE_CREATE_TOMBSTONE == repl_op) {
			/* creating a tombstone entry */
			if (current_sub_count != LDAP_MAXINT) {
				current_sub_count++;
			} else { /* tombstonenumsubordinates does not exist */
				current_sub_count = 1;
			}
			mod_op = LDAP_MOD_REPLACE;
			sprintf(value_buffer,"%lu", current_sub_count);
			slapi_mods_add(smods, mod_op | LDAP_MOD_BVALUES,
			               tombstone_numsubordinates, 
			               strlen(value_buffer), value_buffer);
		}
	}

	ret = modify_apply_mods(mc, smods); /* smods passed in */
	return ret;
}