📄 rwm.c
字号:
bva = ch_malloc( (num+1) * sizeof( struct berval )); for (i=0; i<num; i++) ber_dupbv( &bva[i], &ml->sml_nvalues[i] ); BER_BVZERO( &bva[i] ); ml->sml_nvalues = bva; } if ( is_oc ) { int last, j; last = num-1; for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ ) { struct ldapmapping *oc_mapping = NULL; ( void )rwm_mapping( &rwmap->rwm_oc, &ml->sml_values[ j ], &oc_mapping, RWM_MAP ); if ( oc_mapping == NULL ) { if ( rwmap->rwm_at.drop_missing ) { /* FIXME: we allow to remove objectClasses as well; * if the resulting entry is inconsistent, that's * the relayed database's business... */ if ( last > j ) { ch_free( ml->sml_values[ j ].bv_val ); ml->sml_values[ j ] = ml->sml_values[ last ]; } BER_BVZERO( &ml->sml_values[ last ] ); last--; j--; } } else { ch_free( ml->sml_values[ j ].bv_val ); ber_dupbv( &ml->sml_values[ j ], &oc_mapping->m_dst ); } } } else { if ( ml->sml_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) ) {#ifdef ENABLE_REWRITE rc = rwm_dnattr_rewrite( op, rs, "modifyAttrDN", ml->sml_values, ml->sml_nvalues ? &ml->sml_nvalues : NULL );#else /* ! ENABLE_REWRITE */ rc = 1; rc = rwm_dnattr_rewrite( op, rs, &rc, ml->sml_values, ml->sml_nvalues ? &ml->sml_nvalues : NULL );#endif /* ! ENABLE_REWRITE */ } else if ( ml->sml_desc == slap_schema.si_ad_ref ) {#ifdef ENABLE_REWRITE rc = rwm_referral_rewrite( op, rs, "referralAttrDN", ml->sml_values, ml->sml_nvalues ? &ml->sml_nvalues : NULL );#else /* ! ENABLE_REWRITE */ rc = 1; rc = rwm_referral_rewrite( op, rs, &rc, ml->sml_values, ml->sml_nvalues ? &ml->sml_nvalues : NULL );#endif /* ! ENABLE_REWRITE */ if ( rc != LDAP_SUCCESS ) { goto cleanup_mod; } } if ( rc != LDAP_SUCCESS ) { goto cleanup_mod; } } }next_mod:; if ( mapping != NULL ) { /* use new attribute description */ assert( mapping->m_dst_ad != NULL ); ml->sml_desc = mapping->m_dst_ad; } mlp = &ml->sml_next; continue;cleanup_mod:; ml = *mlp; *mlp = (*mlp)->sml_next; slap_mod_free( &ml->sml_mod, 0 ); free( ml ); } op->o_callback = &roc->cb; return SLAP_CB_CONTINUE;}static intrwm_op_modrdn( Operation *op, SlapReply *rs ){ slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; struct ldaprwmap *rwmap = (struct ldaprwmap *)on->on_bi.bi_private; int rc; rwm_op_cb *roc = rwm_callback_get( op, rs ); if ( op->orr_newSup ) { dncookie dc; struct berval nnewSup = BER_BVNULL; struct berval newSup = BER_BVNULL; /* * Rewrite the new superior, if defined and required */ dc.rwmap = rwmap;#ifdef ENABLE_REWRITE dc.conn = op->o_conn; dc.rs = rs; dc.ctx = "newSuperiorDN";#else /* ! ENABLE_REWRITE */ dc.tofrom = 0; dc.normalized = 0;#endif /* ! ENABLE_REWRITE */ newSup = *op->orr_newSup; nnewSup = *op->orr_nnewSup; rc = rwm_dn_massage_pretty_normalize( &dc, op->orr_newSup, &newSup, &nnewSup ); if ( rc != LDAP_SUCCESS ) { op->o_bd->bd_info = (BackendInfo *)on->on_info; send_ldap_error( op, rs, rc, "newSuperiorDN massage error" ); return -1; } if ( op->orr_newSup->bv_val != newSup.bv_val ) { op->orr_newSup = op->o_tmpalloc( sizeof( struct berval ), op->o_tmpmemctx ); op->orr_nnewSup = op->o_tmpalloc( sizeof( struct berval ), op->o_tmpmemctx ); *op->orr_newSup = newSup; *op->orr_nnewSup = nnewSup; } } /* * Rewrite the dn, if needed */#ifdef ENABLE_REWRITE rc = rwm_op_dn_massage( op, rs, "renameDN", &roc->ros );#else /* ! ENABLE_REWRITE */ rc = 1; rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );#endif /* ! ENABLE_REWRITE */ if ( rc != LDAP_SUCCESS ) { op->o_bd->bd_info = (BackendInfo *)on->on_info; send_ldap_error( op, rs, rc, "renameDN massage error" ); if ( op->orr_newSup != roc->ros.orr_newSup ) { ch_free( op->orr_newSup->bv_val ); ch_free( op->orr_nnewSup->bv_val ); op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx ); op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx ); op->orr_newSup = roc->ros.orr_newSup; op->orr_nnewSup = roc->ros.orr_nnewSup; } return -1; } /* TODO: rewrite newRDN, attribute types, * values of DN-valued attributes ... */ op->o_callback = &roc->cb; return SLAP_CB_CONTINUE;}static intrwm_swap_attrs( Operation *op, SlapReply *rs ){ slap_callback *cb = op->o_callback; rwm_op_state *ros = cb->sc_private; rs->sr_attrs = ros->ors_attrs; return SLAP_CB_CONTINUE;}static intrwm_op_search( Operation *op, SlapReply *rs ){ slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; struct ldaprwmap *rwmap = (struct ldaprwmap *)on->on_bi.bi_private; int rc; dncookie dc; struct berval fstr = BER_BVNULL; Filter *f = NULL; AttributeName *an = NULL; char *text = NULL; rwm_op_cb *roc = rwm_callback_get( op, rs );#ifdef ENABLE_REWRITE rc = rewrite_session_var_set( rwmap->rwm_rw, op->o_conn, "searchFilter", op->ors_filterstr.bv_val ); if ( rc == LDAP_SUCCESS ) rc = rwm_op_dn_massage( op, rs, "searchDN", &roc->ros );#else /* ! ENABLE_REWRITE */ rc = 1; rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );#endif /* ! ENABLE_REWRITE */ if ( rc != LDAP_SUCCESS ) { text = "searchDN massage error"; goto error_return; } /* * Rewrite the dn if needed */ dc.rwmap = rwmap;#ifdef ENABLE_REWRITE dc.conn = op->o_conn; dc.rs = rs; dc.ctx = "searchFilterAttrDN";#else /* ! ENABLE_REWRITE */ dc.tofrom = 0; dc.normalized = 0;#endif /* ! ENABLE_REWRITE */ rc = rwm_filter_map_rewrite( op, &dc, op->ors_filter, &fstr ); if ( rc != LDAP_SUCCESS ) { text = "searchFilter/searchFilterAttrDN massage error"; goto error_return; } f = str2filter_x( op, fstr.bv_val ); if ( f == NULL ) { text = "massaged filter parse error"; goto error_return; } op->ors_filter = f; op->ors_filterstr = fstr; rc = rwm_map_attrnames( &rwmap->rwm_at, &rwmap->rwm_oc, op->ors_attrs, &an, RWM_MAP ); if ( rc != LDAP_SUCCESS ) { text = "attribute list mapping error"; goto error_return; } op->ors_attrs = an; roc->cb.sc_response = rwm_swap_attrs; op->o_callback = &roc->cb; return SLAP_CB_CONTINUE;error_return:; if ( an != NULL ) { ch_free( an ); } if ( f != NULL ) { filter_free_x( op, f ); } if ( !BER_BVISNULL( &fstr ) ) { ch_free( fstr.bv_val ); } op->oq_search = roc->ros.oq_search; op->o_bd->bd_info = (BackendInfo *)on->on_info; send_ldap_error( op, rs, rc, text ); return -1;}static intrwm_exop_passwd( Operation *op, SlapReply *rs ){ slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; int rc; rwm_op_cb *roc; struct berval id = BER_BVNULL, pwold = BER_BVNULL, pwnew = BER_BVNULL; BerElement *ber = NULL; if ( !BER_BVISNULL( &op->o_req_ndn ) ) { return LDAP_SUCCESS; } if ( !SLAP_ISGLOBALOVERLAY( op->o_bd ) ) { rs->sr_err = LDAP_OTHER; return rs->sr_err; } rs->sr_err = slap_passwd_parse( op->ore_reqdata, &id, &pwold, &pwnew, &rs->sr_text ); if ( rs->sr_err != LDAP_SUCCESS ) { return rs->sr_err; } if ( !BER_BVISNULL( &id ) ) { rs->sr_err = dnPrettyNormal( NULL, &id, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx ); if ( rs->sr_err != LDAP_SUCCESS ) { rs->sr_text = "Invalid DN"; return rs->sr_err; } } else { ber_dupbv_x( &op->o_req_dn, &op->o_dn, op->o_tmpmemctx ); ber_dupbv_x( &op->o_req_ndn, &op->o_ndn, op->o_tmpmemctx ); } roc = rwm_callback_get( op, rs );#ifdef ENABLE_REWRITE rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros );#else /* ! ENABLE_REWRITE */ rc = 1; rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );#endif /* ! ENABLE_REWRITE */ if ( rc != LDAP_SUCCESS ) { op->o_bd->bd_info = (BackendInfo *)on->on_info; send_ldap_error( op, rs, rc, "extendedDN massage error" ); return -1; } ber = ber_alloc_t( LBER_USE_DER ); if ( !ber ) { rs->sr_err = LDAP_OTHER; rs->sr_text = "No memory"; return rs->sr_err; } ber_printf( ber, "{" ); if ( !BER_BVISNULL( &id )) { ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_ID, &op->o_req_dn ); } if ( !BER_BVISNULL( &pwold )) { ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_OLD, &pwold ); } if ( !BER_BVISNULL( &pwnew )) { ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, &pwnew ); } ber_printf( ber, "N}" ); ber_flatten( ber, &op->ore_reqdata ); ber_free( ber, 1 ); op->o_callback = &roc->cb; return SLAP_CB_CONTINUE;}static struct exop { struct berval oid; BI_op_extended *extended;} exop_table[] = { { BER_BVC(LDAP_EXOP_MODIFY_PASSWD), rwm_exop_passwd }, { BER_BVNULL, NULL }};static intrwm_extended( Operation *op, SlapReply *rs ){ slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; int rc; rwm_op_cb *roc; int i; for ( i = 0; exop_table[i].extended != NULL; i++ ) { if ( bvmatch( &exop_table[i].oid, &op->oq_extended.rs_reqoid ) ) { rc = exop_table[i].extended( op, rs ); switch ( rc ) { case LDAP_SUCCESS: break; case SLAP_CB_CONTINUE: case SLAPD_ABANDON: return rc; default: send_ldap_result( op, rs ); return rc; } break; } } roc = rwm_callback_get( op, rs );#ifdef ENABLE_REWRITE rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros );#else /* ! ENABLE_REWRITE */ rc = 1; rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );#endif /* ! ENABLE_REWRITE */ if ( rc != LDAP_SUCCESS ) { op->o_bd->bd_info = (BackendInfo *)on->on_info; send_ldap_error( op, rs, rc, "extendedDN massage error" ); return -1; } /* TODO: rewrite/map extended data ? ... */ op->o_callback = &roc->cb; return SLAP_CB_CONTINUE;}static intrwm_matched( Operation *op, SlapReply *rs ){ slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; struct ldaprwmap *rwmap = (struct ldaprwmap *)on->on_bi.bi_private; struct berval dn, mdn; dncookie dc; int rc; if ( rs->sr_matched == NULL ) { return SLAP_CB_CONTINUE; } dc.rwmap = rwmap;#ifdef ENABLE_REWRITE dc.conn = op->o_conn; dc.rs = rs; dc.ctx = "matchedDN";#else /* ! ENABLE_REWRITE */ dc.tofrom = 0; dc.normalized = 0;#endif /* ! ENABLE_REWRITE */ ber_str2bv( rs->sr_matched, 0, 0, &dn ); mdn = dn; rc = rwm_dn_massage_pretty( &dc, &dn, &mdn ); if ( rc != LDAP_SUCCESS ) { rs->sr_err = rc; rs->sr_text = "Rewrite error"; return 1; } if ( mdn.bv_val != dn.bv_val ) { if ( rs->sr_flags & REP_MATCHED_MUSTBEFREED ) { ch_free( (void *)rs->sr_matched ); } else { rs->sr_flags |= REP_MATCHED_MUSTBEFREED; } rs->sr_matched = mdn.bv_val; } return SLAP_CB_CONTINUE;}static intrwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN ){ slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; struct ldaprwmap *rwmap = (struct ldaprwmap *)on->on_bi.bi_private; dncookie dc; int rc; Attribute **ap; int isupdate; /* * Rewrite the dn attrs, if needed */ dc.rwmap = rwmap;#ifdef ENABLE_REWRITE dc.conn = op->o_conn; dc.rs = NULL; #else /* ! ENABLE_REWRITE */ dc.tofrom = 0; dc.normalized = 0;#endif /* ! ENABLE_REWRITE */ /* FIXME: the entries are in the remote mapping form; * so we need to select those attributes we are willing * to return, and remap them accordingly */ /* FIXME: in principle, one could map an attribute * on top of another, which already exists. * As such, in the end there might exist more than * one instance of an attribute. * We should at least check if this occurs, and issue * an error (because multiple instances of attrs in * response are not valid), or merge the values (what * about duplicate values?) */ isupdate = be_shadow_update( op ); for ( ap = a_first; *ap; ) { struct ldapmapping *mapping = NULL; int drop_missing; int last; Attribute *a; if ( SLAP_OPATTRS( rs->sr_attr_flags ) && is_at_operational( (*ap)->a_desc->ad_type ) ) { /* go on */ ; } else { if ( op->ors_attrs != NULL && !SLAP_USERATTRS( rs->sr_attr_flags ) && !ad_inlist( (*ap)->a_desc, op->ors_attrs ) ) { goto cleanup_attr; } drop_missing = rwm_mapping( &rwmap->rwm_at, &(*ap)->a_desc->ad_cname, &mapping, RWM_REMAP ); if ( drop_missing || ( mapping != NULL && BER_BVISEMPTY( &mapping->m_dst ) ) ) { goto cleanup_attr; } if ( mapping != NULL ) { (*ap)->a_desc = mapping->m_dst_ad; } } if ( (*ap)->a_desc == slap_schema.si_ad_entryDN ) { if ( stripEntryDN ) { /* will be generated by frontend */ goto cleanup_attr; } } else if ( !isupdate && !get_manageDIT( op ) && (*ap)->a_desc->ad_type->sat_no_user_mod && (*ap)->a_desc->ad_type != slap_schema.si_at_undefined ) { goto next_attr; } for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ ) /* just count */ ; if ( last == 0 ) { /* empty? leave it in place because of attrsonly and vlv */ goto next_attr; } last--; if ( (*ap)->a_desc == slap_schema.si_ad_objectClass || (*ap)->a_desc == slap_schema.si_ad_structuralObjectClass ) { struct berval *bv; for ( bv = (*ap)->a_vals; !BER_BVISNULL( bv ); bv++ ) { struct berval mapped; rwm_map( &rwmap->rwm_oc, &bv[0], &mapped, RWM_REMAP ); if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) { ch_free( bv[0].bv_val ); BER_BVZERO( &bv[0] ); if ( &(*ap)->a_vals[last] > &bv[0] ) { bv[0] = (*ap)->a_vals[last]; BER_BVZERO( &(*ap)->a_vals[last] ); } last--; bv--; } else if ( mapped.bv_val != bv[0].bv_val ) { /* * FIXME: after LBER_FREEing * the value is replaced by * ch_alloc'ed memory */ ber_bvreplace( &bv[0], &mapped ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -