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

📄 lastmod.c

📁 ldap服务器源码
💻 C
📖 第 1 页 / 共 2 页
字号:
					ber_dupbv( &bv_nmodifyTimestamp, &ml->sml_nvalues[0] );				} else {					ber_dupbv( &bv_nmodifyTimestamp, &ml->sml_values[0] );				}				rc --;				if ( !rc ) {					break;				}			}		}		/* if rooted at global overlay, opattrs are not yet in place */		if ( BER_BVISNULL( &bv_modifiersName ) ) {			best_guess( op, NULL, NULL, NULL, NULL, &bv_modifiersName, &bv_nmodifiersName );		}		if ( BER_BVISNULL( &bv_entryCSN ) ) {			best_guess( op, &bv_entryCSN, &bv_nentryCSN, NULL, NULL, NULL, NULL );		}		if ( BER_BVISNULL( &bv_modifyTimestamp ) ) {			best_guess( op, NULL, NULL, &bv_modifyTimestamp, &bv_nmodifyTimestamp, NULL, NULL );		}		ber_dupbv( &bv_name, &op->o_req_dn );		ber_dupbv( &bv_nname, &op->o_req_ndn );		break;	case LDAP_REQ_MODRDN:		lmt = LASTMOD_MODRDN;		e = NULL;		if ( op->orr_newSup && !BER_BVISNULL( op->orr_newSup ) ) {			build_new_dn( &bv_name, op->orr_newSup, &op->orr_newrdn, NULL );			build_new_dn( &bv_nname, op->orr_nnewSup, &op->orr_nnewrdn, NULL );		} else {			struct berval	pdn;			dnParent( &op->o_req_dn, &pdn );			build_new_dn( &bv_name, &pdn, &op->orr_newrdn, NULL );			dnParent( &op->o_req_ndn, &pdn );			build_new_dn( &bv_nname, &pdn, &op->orr_nnewrdn, NULL );		}		if ( on->on_info->oi_orig->bi_entry_get_rw ) {			BackendInfo	*bi = op->o_bd->bd_info;			int		rc;			op->o_bd->bd_info = (BackendInfo *)on->on_info->oi_orig;			rc = (*op->o_bd->bd_info->bi_entry_get_rw)( op, &bv_name, NULL, NULL, 0, &e );			if ( rc == LDAP_SUCCESS ) {				a = attr_find( e->e_attrs, slap_schema.si_ad_modifiersName );				if ( a != NULL ) {					ber_dupbv( &bv_modifiersName, &a->a_vals[0] );					ber_dupbv( &bv_nmodifiersName, &a->a_nvals[0] );				}				a = attr_find( e->e_attrs, slap_schema.si_ad_entryCSN );				if ( a != NULL ) {					ber_dupbv( &bv_entryCSN, &a->a_vals[0] );					if ( a->a_nvals && !BER_BVISNULL( &a->a_nvals[0] ) ) {						ber_dupbv( &bv_nentryCSN, &a->a_nvals[0] );					} else {						ber_dupbv( &bv_nentryCSN, &a->a_vals[0] );					}				}				a = attr_find( e->e_attrs, slap_schema.si_ad_modifyTimestamp );				if ( a != NULL ) {					ber_dupbv( &bv_modifyTimestamp, &a->a_vals[0] );					if ( a->a_nvals && !BER_BVISNULL( &a->a_nvals[0] ) ) {						ber_dupbv( &bv_nmodifyTimestamp, &a->a_nvals[0] );					} else {						ber_dupbv( &bv_nmodifyTimestamp, &a->a_vals[0] );					}				}				assert( dn_match( &bv_name, &e->e_name ) );				assert( dn_match( &bv_nname, &e->e_nname ) );				(*op->o_bd->bd_info->bi_entry_release_rw)( op, e, 0 );			}			op->o_bd->bd_info = bi;		}		/* if !bi_entry_get_rw || bi_entry_get_rw failed for any reason... */		if ( e == NULL ) {			best_guess( op, &bv_entryCSN, &bv_nentryCSN,					&bv_modifyTimestamp, &bv_nmodifyTimestamp,					&bv_modifiersName, &bv_nmodifiersName );		}		break;	default:		return -1;	}		ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );#if 0	fprintf( stderr, "### lastmodDN: %s %s\n", bv_name.bv_val, bv_nname.bv_val );#endif	a = attr_find( lmi->lmi_e->e_attrs, lastmod_schema.lms_ad_lastmodDN );	if ( a == NULL ) {		goto error_return;	}	ch_free( a->a_vals[0].bv_val );	a->a_vals[0] = bv_name;	ch_free( a->a_nvals[0].bv_val );	a->a_nvals[0] = bv_nname;#if 0	fprintf( stderr, "### lastmodType: %s %s\n", lastmodType[ lmt ].bv_val, lastmodType[ lmt ].bv_val );#endif	a = attr_find( lmi->lmi_e->e_attrs, lastmod_schema.lms_ad_lastmodType );	if ( a == NULL ) {		goto error_return;	} 	ch_free( a->a_vals[0].bv_val );	ber_dupbv( &a->a_vals[0], &lastmodType[ lmt ] );	ch_free( a->a_nvals[0].bv_val );	ber_dupbv( &a->a_nvals[0], &lastmodType[ lmt ] );#if 0	fprintf( stderr, "### modifiersName: %s %s\n", bv_modifiersName.bv_val, bv_nmodifiersName.bv_val );#endif	a = attr_find( lmi->lmi_e->e_attrs, slap_schema.si_ad_modifiersName );	if ( a == NULL ) {		goto error_return;	} 	ch_free( a->a_vals[0].bv_val );	a->a_vals[0] = bv_modifiersName;	ch_free( a->a_nvals[0].bv_val );	a->a_nvals[0] = bv_nmodifiersName;#if 0	fprintf( stderr, "### modifyTimestamp: %s %s\n", bv_nmodifyTimestamp.bv_val, bv_modifyTimestamp.bv_val );#endif	a = attr_find( lmi->lmi_e->e_attrs, slap_schema.si_ad_modifyTimestamp );	if ( a == NULL ) {		goto error_return;	} 	ch_free( a->a_vals[0].bv_val );	a->a_vals[0] = bv_modifyTimestamp;	ch_free( a->a_nvals[0].bv_val );	a->a_nvals[0] = bv_nmodifyTimestamp;#if 0	fprintf( stderr, "### entryCSN: %s %s\n", bv_nentryCSN.bv_val, bv_entryCSN.bv_val );#endif	a = attr_find( lmi->lmi_e->e_attrs, slap_schema.si_ad_entryCSN );	if ( a == NULL ) {		goto error_return;	} 	ch_free( a->a_vals[0].bv_val );	a->a_vals[0] = bv_entryCSN;	ch_free( a->a_nvals[0].bv_val );	a->a_nvals[0] = bv_nentryCSN;	rc = 0;error_return:;	ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );		return rc;}static intlastmod_response( Operation *op, SlapReply *rs ){	slap_overinst		*on = (slap_overinst *)op->o_bd->bd_info;	lastmod_info_t		*lmi = (lastmod_info_t *)on->on_bi.bi_private;	/* don't record failed operations */	switch ( rs->sr_err ) {	case LDAP_SUCCESS:		/* FIXME: other cases? */		break;	default:		return SLAP_CB_CONTINUE;	}	/* record only write operations */	switch ( op->o_tag ) {	case LDAP_REQ_ADD:	case LDAP_REQ_MODIFY:	case LDAP_REQ_MODRDN:	case LDAP_REQ_DELETE:		break;	case LDAP_REQ_EXTENDED:		/* if write, process */		if ( exop_is_write( op ))			break;		/* fall thru */	default:		return SLAP_CB_CONTINUE;	}	/* skip if disabled */	ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );	if ( !lmi->lmi_enabled ) {		ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );		return SLAP_CB_CONTINUE;	}	ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );	(void)lastmod_update( op, rs );	return SLAP_CB_CONTINUE;}static intlastmod_db_init(	BackendDB *be){	slap_overinst		*on = (slap_overinst *)be->bd_info;	lastmod_info_t		*lmi;	if ( lastmod_schema.lms_oc_lastmod == NULL ) {		int		i;		const char 	*text;		/* schema integration */		for ( i = 0; mat[i].name; i++ ) {			LDAPAttributeType	*at;			int			code;			const char		*err;			AttributeDescription	**ad;				at = ldap_str2attributetype( mat[i].schema, &code,				&err, LDAP_SCHEMA_ALLOW_ALL );			if ( !at ) {				Debug( LDAP_DEBUG_ANY, "lastmod_init: "					"in AttributeType '%s' %s before %s\n",					mat[i].name, ldap_scherr2str(code), err );				return -1;			}				if ( at->at_oid == NULL ) {				Debug( LDAP_DEBUG_ANY, "lastmod_init: "					"null OID for attributeType '%s'\n",					mat[i].name, 0, 0 );				return -1;			}				code = at_add(at, 0, NULL, &err);			if ( code ) {				Debug( LDAP_DEBUG_ANY, "lastmod_init: "					"%s in attributeType '%s'\n",					scherr2str(code), mat[i].name, 0 );				return -1;			}			ldap_memfree(at);				ad = ((AttributeDescription **)&(((char *)&lastmod_schema)[mat[i].offset]));			ad[0] = NULL;			if ( slap_str2ad( mat[i].name, ad, &text ) ) {				Debug( LDAP_DEBUG_ANY,					"lastmod_init: %s\n", text, 0, 0 );				return -1;			}				(*ad)->ad_type->sat_flags |= mat[i].flags;		}		for ( i = 0; moc[i].name; i++ ) {			LDAPObjectClass		*oc;			int			code;			const char		*err;			ObjectClass		*Oc;				oc = ldap_str2objectclass(moc[i].schema, &code, &err,					LDAP_SCHEMA_ALLOW_ALL );			if ( !oc ) {				Debug( LDAP_DEBUG_ANY,					"unable to parse lastmod objectClass '%s': "					"%s before %s\n" , moc[i].name,					ldap_scherr2str(code), err );				return -1;			}			if ( oc->oc_oid == NULL ) {				Debug( LDAP_DEBUG_ANY,					"objectClass '%s' has no OID\n" ,					moc[i].name, 0, 0 );				return -1;			}			code = oc_add(oc, 0, NULL, &err);			if ( code ) {				Debug( LDAP_DEBUG_ANY,					"objectClass '%s': %s \"%s\"\n" ,					moc[i].name, scherr2str(code), err );				return -1;			}				ldap_memfree(oc);				Oc = oc_find( moc[i].name );			if ( Oc == NULL ) {				Debug( LDAP_DEBUG_ANY, "lastmod_init: "						"unable to find objectClass %s "						"(just added)\n", moc[i].name, 0, 0 );				return -1;			}			Oc->soc_flags |= moc[i].flags;			((ObjectClass **)&(((char *)&lastmod_schema)[moc[i].offset]))[0] = Oc;		}	}	lmi = (lastmod_info_t *)ch_malloc( sizeof( lastmod_info_t ) );	memset( lmi, 0, sizeof( lastmod_info_t ) );	lmi->lmi_enabled = 1;		on->on_bi.bi_private = lmi;	return 0;}static intlastmod_db_config(	BackendDB	*be,	const char	*fname,	int		lineno,	int		argc,	char	**argv){	slap_overinst		*on = (slap_overinst *)be->bd_info;	lastmod_info_t		*lmi = (lastmod_info_t *)on->on_bi.bi_private;	if ( strcasecmp( argv[ 0 ], "lastmod-rdnvalue" ) == 0 ) {		if ( lmi->lmi_rdnvalue.bv_val ) {			/* already defined! */			ch_free( lmi->lmi_rdnvalue.bv_val );		}		ber_str2bv( argv[ 1 ], 0, 1, &lmi->lmi_rdnvalue );	} else if ( strcasecmp( argv[ 0 ], "lastmod-enabled" ) == 0 ) {		if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {			lmi->lmi_enabled = 1;		} else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {			lmi->lmi_enabled = 0;		} else {			return -1;		}	} else {		return SLAP_CONF_UNKNOWN;	}	return 0;}static intlastmod_db_open(	BackendDB *be){	slap_overinst	*on = (slap_overinst *) be->bd_info;	lastmod_info_t	*lmi = (lastmod_info_t *)on->on_bi.bi_private;	char		buf[ 8192 ];	static char		tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];	char			csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];	struct berval		entryCSN;	struct berval timestamp;	if ( !SLAP_LASTMOD( be ) ) {		fprintf( stderr, "set \"lastmod on\" to make this overlay effective\n" );		return -1;	}	/*	 * Start	 */	timestamp.bv_val = tmbuf;	timestamp.bv_len = sizeof(tmbuf);	slap_timestamp( &starttime, &timestamp );	entryCSN.bv_val = csnbuf;	entryCSN.bv_len = sizeof( csnbuf );	slap_get_csn( NULL, &entryCSN, 0 );	if ( BER_BVISNULL( &lmi->lmi_rdnvalue ) ) {		ber_str2bv( "Lastmod", 0, 1, &lmi->lmi_rdnvalue );	}	snprintf( buf, sizeof( buf ),			"dn: cn=%s%s%s\n"			"objectClass: %s\n"			"structuralObjectClass: %s\n"			"cn: %s\n"			"description: This object contains the last modification to this database\n"			"%s: cn=%s%s%s\n"			"%s: %s\n"			"%s: %s\n"			"createTimestamp: %s\n"			"creatorsName: %s\n"			"entryCSN: %s\n"			"modifyTimestamp: %s\n"			"modifiersName: %s\n"			"hasSubordinates: FALSE\n",			lmi->lmi_rdnvalue.bv_val, BER_BVISEMPTY( &be->be_suffix[ 0 ] ) ? "" : ",", be->be_suffix[ 0 ].bv_val,			lastmod_schema.lms_oc_lastmod->soc_cname.bv_val,			lastmod_schema.lms_oc_lastmod->soc_cname.bv_val,			lmi->lmi_rdnvalue.bv_val,			lastmod_schema.lms_ad_lastmodDN->ad_cname.bv_val,				lmi->lmi_rdnvalue.bv_val, BER_BVISEMPTY( &be->be_suffix[ 0 ] ) ? "" : ",", be->be_suffix[ 0 ].bv_val,			lastmod_schema.lms_ad_lastmodType->ad_cname.bv_val, lastmodType[ LASTMOD_ADD ].bv_val,			lastmod_schema.lms_ad_lastmodEnabled->ad_cname.bv_val, lmi->lmi_enabled ? "TRUE" : "FALSE",			tmbuf,			BER_BVISNULL( &be->be_rootdn ) ? SLAPD_ANONYMOUS : be->be_rootdn.bv_val,			entryCSN.bv_val,			tmbuf,			BER_BVISNULL( &be->be_rootdn ) ? SLAPD_ANONYMOUS : be->be_rootdn.bv_val );#if 0	fprintf( stderr, "# entry:\n%s\n", buf );#endif	lmi->lmi_e = str2entry( buf );	if ( lmi->lmi_e == NULL ) {		return -1;	}	ldap_pvt_thread_mutex_init( &lmi->lmi_entry_mutex );	return 0;}static intlastmod_db_destroy(	BackendDB *be){	slap_overinst	*on = (slap_overinst *)be->bd_info;	lastmod_info_t	*lmi = (lastmod_info_t *)on->on_bi.bi_private;	if ( lmi ) {		if ( !BER_BVISNULL( &lmi->lmi_rdnvalue ) ) {			ch_free( lmi->lmi_rdnvalue.bv_val );		}		if ( lmi->lmi_e ) {			entry_free( lmi->lmi_e );			ldap_pvt_thread_mutex_destroy( &lmi->lmi_entry_mutex );		}		ch_free( lmi );	}	return 0;}/* This overlay is set up for dynamic loading via moduleload. For static * configuration, you'll need to arrange for the slap_overinst to be * initialized and registered by some other function inside slapd. */static slap_overinst 		lastmod;intlastmod_initialize(){	lastmod.on_bi.bi_type = "lastmod";	lastmod.on_bi.bi_db_init = lastmod_db_init;	lastmod.on_bi.bi_db_config = lastmod_db_config;	lastmod.on_bi.bi_db_destroy = lastmod_db_destroy;	lastmod.on_bi.bi_db_open = lastmod_db_open;	lastmod.on_bi.bi_op_add = lastmod_op_func;	lastmod.on_bi.bi_op_compare = lastmod_op_func;	lastmod.on_bi.bi_op_delete = lastmod_op_func;	lastmod.on_bi.bi_op_modify = lastmod_op_func;	lastmod.on_bi.bi_op_modrdn = lastmod_op_func;	lastmod.on_bi.bi_op_search = lastmod_op_func;	lastmod.on_bi.bi_extended = lastmod_op_func;	lastmod.on_response = lastmod_response;	return overlay_register( &lastmod );}#if SLAPD_OVER_LASTMOD == SLAPD_MOD_DYNAMICintinit_module( int argc, char *argv[] ){	return lastmod_initialize();}#endif /* SLAPD_OVER_LASTMOD == SLAPD_MOD_DYNAMIC */#endif /* defined(SLAPD_OVER_LASTMOD) */

⌨️ 快捷键说明

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