⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modify.c

📁 ldap服务器源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* modify.c - bdb backend modify routine *//* $OpenLDAP: pkg/ldap/servers/slapd/back-bdb/modify.c,v 1.124.2.16 2007/01/02 21:44:00 kurt Exp $ *//* This work is part of OpenLDAP Software <http://www.openldap.org/>. * * Copyright 2000-2007 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted only as authorized by the OpenLDAP * Public License. * * A copy of this license is available in the file LICENSE in the * top-level directory of the distribution or, alternatively, at * <http://www.OpenLDAP.org/license.html>. */#include "portable.h"#include <stdio.h>#include <ac/string.h>#include <ac/time.h>#include "back-bdb.h"static struct berval scbva[] = {	BER_BVC("glue"),	BER_BVNULL};int bdb_modify_internal(	Operation *op,	DB_TXN *tid,	Modifications *modlist,	Entry *e,	const char **text,	char *textbuf,	size_t textlen ){	int rc, err;	Modification	*mod;	Modifications	*ml;	Attribute	*save_attrs;	Attribute 	*ap;	int			glue_attr_delete = 0;	Debug( LDAP_DEBUG_TRACE, "bdb_modify_internal: 0x%08lx: %s\n",		e->e_id, e->e_dn, 0);	if ( !acl_check_modlist( op, e, modlist )) {		return LDAP_INSUFFICIENT_ACCESS;	}	/* save_attrs will be disposed of by bdb_cache_modify */	save_attrs = e->e_attrs;	e->e_attrs = attrs_dup( e->e_attrs );	for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {		int match;		mod = &ml->sml_mod;		switch( mod->sm_op ) {		case LDAP_MOD_ADD:		case LDAP_MOD_REPLACE:			if ( mod->sm_desc == slap_schema.si_ad_structuralObjectClass ) {				value_match( &match, slap_schema.si_ad_structuralObjectClass,					slap_schema.si_ad_structuralObjectClass->						ad_type->sat_equality,					SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,					&mod->sm_values[0], &scbva[0], text );				if ( !match ) glue_attr_delete = 1;			}		}		if ( glue_attr_delete )			break;	}	if ( glue_attr_delete ) {		Attribute	**app = &e->e_attrs;		while ( *app != NULL ) {			if ( !is_at_operational( (*app)->a_desc->ad_type )) {				Attribute *save = *app;				*app = (*app)->a_next;				attr_free( save );				continue;			}			app = &(*app)->a_next;		}	}	for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {		mod = &ml->sml_mod;		switch ( mod->sm_op ) {		case LDAP_MOD_ADD:			Debug(LDAP_DEBUG_ARGS,				"bdb_modify_internal: add %s\n",				mod->sm_desc->ad_cname.bv_val, 0, 0);			err = modify_add_values( e, mod, get_permissiveModify(op),				text, textbuf, textlen );			if( err != LDAP_SUCCESS ) {				Debug(LDAP_DEBUG_ARGS, "bdb_modify_internal: %d %s\n",					err, *text, 0);			}			break;		case LDAP_MOD_DELETE:			if ( glue_attr_delete ) {				err = LDAP_SUCCESS;				break;			}			Debug(LDAP_DEBUG_ARGS,				"bdb_modify_internal: delete %s\n",				mod->sm_desc->ad_cname.bv_val, 0, 0);			err = modify_delete_values( e, mod, get_permissiveModify(op),				text, textbuf, textlen );			assert( err != LDAP_TYPE_OR_VALUE_EXISTS );			if( err != LDAP_SUCCESS ) {				Debug(LDAP_DEBUG_ARGS, "bdb_modify_internal: %d %s\n",					err, *text, 0);			}			break;		case LDAP_MOD_REPLACE:			Debug(LDAP_DEBUG_ARGS,				"bdb_modify_internal: replace %s\n",				mod->sm_desc->ad_cname.bv_val, 0, 0);			err = modify_replace_values( e, mod, get_permissiveModify(op),				text, textbuf, textlen );			if( err != LDAP_SUCCESS ) {				Debug(LDAP_DEBUG_ARGS, "bdb_modify_internal: %d %s\n",					err, *text, 0);			}			break;		case LDAP_MOD_INCREMENT:			Debug(LDAP_DEBUG_ARGS,				"bdb_modify_internal: increment %s\n",				mod->sm_desc->ad_cname.bv_val, 0, 0);			err = modify_increment_values( e, mod, get_permissiveModify(op),				text, textbuf, textlen );			if( err != LDAP_SUCCESS ) {				Debug(LDAP_DEBUG_ARGS,					"bdb_modify_internal: %d %s\n",					err, *text, 0);			}			break;		case SLAP_MOD_SOFTADD:			Debug(LDAP_DEBUG_ARGS,				"bdb_modify_internal: softadd %s\n",				mod->sm_desc->ad_cname.bv_val, 0, 0); 			/* Avoid problems in index_add_mods() 			 * We need to add index if necessary. 			 */ 			mod->sm_op = LDAP_MOD_ADD;			err = modify_add_values( e, mod, get_permissiveModify(op),				text, textbuf, textlen ); 			mod->sm_op = SLAP_MOD_SOFTADD; 			if ( err == LDAP_TYPE_OR_VALUE_EXISTS ) { 				err = LDAP_SUCCESS; 			}			if( err != LDAP_SUCCESS ) {				Debug(LDAP_DEBUG_ARGS, "bdb_modify_internal: %d %s\n",					err, *text, 0);			} 			break;		default:			Debug(LDAP_DEBUG_ANY, "bdb_modify_internal: invalid op %d\n",				mod->sm_op, 0, 0);			*text = "Invalid modify operation";			err = LDAP_OTHER;			Debug(LDAP_DEBUG_ARGS, "bdb_modify_internal: %d %s\n",				err, *text, 0);		}		if ( err != LDAP_SUCCESS ) {			attrs_free( e->e_attrs );			e->e_attrs = save_attrs;			/* unlock entry, delete from cache */			return err; 		}		/* If objectClass was modified, reset the flags */		if ( mod->sm_desc == slap_schema.si_ad_objectClass ) {			e->e_ocflags = 0;		}		if ( glue_attr_delete ) e->e_ocflags = 0;		/* check if modified attribute was indexed		 * but not in case of NOOP... */		err = bdb_index_is_indexed( op->o_bd, mod->sm_desc );		if ( err == LDAP_SUCCESS && !op->o_noop ) {			ap = attr_find( save_attrs, mod->sm_desc );			if ( ap ) ap->a_flags |= SLAP_ATTR_IXDEL;			ap = attr_find( e->e_attrs, mod->sm_desc );			if ( ap ) ap->a_flags |= SLAP_ATTR_IXADD;		}	}	/* check that the entry still obeys the schema */	rc = entry_schema_check( op, e, save_attrs, get_manageDIT(op),		text, textbuf, textlen );	if ( rc != LDAP_SUCCESS || op->o_noop ) {		attrs_free( e->e_attrs );		/* clear the indexing flags */		for ( ap = save_attrs; ap != NULL; ap = ap->a_next ) {			ap->a_flags = 0;		}		e->e_attrs = save_attrs;		if ( rc != LDAP_SUCCESS ) {			Debug( LDAP_DEBUG_ANY,				"entry failed schema check: %s\n",				*text, 0, 0 );		}		/* if NOOP then silently revert to saved attrs */		return rc;	}	/* update the indices of the modified attributes */	/* start with deleting the old index entries */	for ( ap = save_attrs; ap != NULL; ap = ap->a_next ) {		if ( ap->a_flags & SLAP_ATTR_IXDEL ) {			rc = bdb_index_values( op, tid, ap->a_desc,				ap->a_nvals,				e->e_id, SLAP_INDEX_DELETE_OP );			if ( rc != LDAP_SUCCESS ) {				attrs_free( e->e_attrs );				e->e_attrs = save_attrs;				Debug( LDAP_DEBUG_ANY,				       "Attribute index delete failure",				       0, 0, 0 );				return rc;			}			ap->a_flags &= ~SLAP_ATTR_IXDEL;		}	}	/* add the new index entries */	for ( ap = e->e_attrs; ap != NULL; ap = ap->a_next ) {		if (ap->a_flags & SLAP_ATTR_IXADD) {			rc = bdb_index_values( op, tid, ap->a_desc,				ap->a_nvals,				e->e_id, SLAP_INDEX_ADD_OP );			if ( rc != LDAP_SUCCESS ) {				attrs_free( e->e_attrs );				e->e_attrs = save_attrs;				Debug( LDAP_DEBUG_ANY,				       "Attribute index add failure",				       0, 0, 0 );				return rc;			}			ap->a_flags &= ~SLAP_ATTR_IXADD;		}	}	return rc;}intbdb_modify( Operation *op, SlapReply *rs ){	struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;	Entry		*e = NULL;	EntryInfo	*ei = NULL;	int		manageDSAit = get_manageDSAit( op );	char textbuf[SLAP_TEXT_BUFLEN];	size_t textlen = sizeof textbuf;	DB_TXN	*ltid = NULL, *lt2;	struct bdb_op_info opinfo = {0};	Entry		dummy = {0};	int			fakeroot = 0;	u_int32_t	locker = 0;	DB_LOCK		lock;	int		num_retries = 0;	LDAPControl **preread_ctrl = NULL;	LDAPControl **postread_ctrl = NULL;	LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];	int num_ctrls = 0;	int rc;	Debug( LDAP_DEBUG_ARGS, LDAP_XSTRING(bdb_modify) ": %s\n",		op->o_req_dn.bv_val, 0, 0 );	ctrls[num_ctrls] = NULL;	slap_mods_opattrs( op, &op->orm_modlist, 1 );	if( 0 ) {retry:	/* transaction retry */		if ( dummy.e_attrs ) {			attrs_free( dummy.e_attrs );			dummy.e_attrs = NULL;		}		if( e != NULL ) {			bdb_unlocked_cache_return_entry_w(&bdb->bi_cache, e);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -