map.c
来自「ldap服务器源码」· C语言 代码 · 共 805 行 · 第 1/2 页
C
805 行
fstr->bv_len += vtmp.bv_len; fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 ); snprintf( &fstr->bv_val[len - 2], vtmp.bv_len + 3, /* "(attr=" */ "%s*)", vtmp.bv_val ); ber_memfree( vtmp.bv_val ); } if ( f->f_sub_any != NULL ) { for ( i = 0; !BER_BVISNULL( &f->f_sub_any[i] ); i++ ) { len = fstr->bv_len; filter_escape_value( &f->f_sub_any[i], &vtmp ); fstr->bv_len += vtmp.bv_len + 1; fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 ); snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3, /* "(attr=[init]*[any*]" */ "%s*)", vtmp.bv_val ); ber_memfree( vtmp.bv_val ); } } if ( !BER_BVISNULL( &f->f_sub_final ) ) { len = fstr->bv_len; filter_escape_value( &f->f_sub_final, &vtmp ); fstr->bv_len += vtmp.bv_len; fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 ); snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3, /* "(attr=[init*][any*]" */ "%s)", vtmp.bv_val ); ber_memfree( vtmp.bv_val ); } break; case LDAP_FILTER_PRESENT: if ( map_attr_value( dc, f->f_desc, &atmp, NULL, NULL, remap ) ) { goto computed; } fstr->bv_len = atmp.bv_len + ( STRLENOF( "(=*)" ) ); fstr->bv_val = malloc( fstr->bv_len + 1 ); snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)", atmp.bv_val ); break; case LDAP_FILTER_AND: case LDAP_FILTER_OR: case LDAP_FILTER_NOT: fstr->bv_len = STRLENOF( "(%)" ); fstr->bv_val = malloc( fstr->bv_len + 128 ); /* FIXME: why 128? */ snprintf( fstr->bv_val, fstr->bv_len + 1, "(%c)", f->f_choice == LDAP_FILTER_AND ? '&' : f->f_choice == LDAP_FILTER_OR ? '|' : '!' ); for ( p = f->f_list; p != NULL; p = p->f_next ) { int rc; len = fstr->bv_len; rc = ldap_back_int_filter_map_rewrite( dc, p, &vtmp, remap ); if ( rc != LDAP_SUCCESS ) { return rc; } fstr->bv_len += vtmp.bv_len; fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 ); snprintf( &fstr->bv_val[len-1], vtmp.bv_len + 2, /*"("*/ "%s)", vtmp.bv_val ); ch_free( vtmp.bv_val ); } break; case LDAP_FILTER_EXT: if ( f->f_mr_desc ) { if ( map_attr_value( dc, f->f_mr_desc, &atmp, &f->f_mr_value, &vtmp, remap ) ) { goto computed; } } else { BER_BVSTR( &atmp, "" ); filter_escape_value( &f->f_mr_value, &vtmp ); } /* FIXME: cleanup (less ?: operators...) */ fstr->bv_len = atmp.bv_len + ( f->f_mr_dnattrs ? STRLENOF( ":dn" ) : 0 ) + ( !BER_BVISEMPTY( &f->f_mr_rule_text ) ? f->f_mr_rule_text.bv_len + 1 : 0 ) + vtmp.bv_len + ( STRLENOF( "(:=)" ) ); fstr->bv_val = malloc( fstr->bv_len + 1 ); snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s:=%s)", atmp.bv_val, f->f_mr_dnattrs ? ":dn" : "", !BER_BVISEMPTY( &f->f_mr_rule_text ) ? ":" : "", !BER_BVISEMPTY( &f->f_mr_rule_text ) ? f->f_mr_rule_text.bv_val : "", vtmp.bv_val ); ber_memfree( vtmp.bv_val ); break; case SLAPD_FILTER_COMPUTED: switch ( f->f_result ) { case LDAP_COMPARE_FALSE: /* FIXME: treat UNDEFINED as FALSE */ case SLAPD_COMPARE_UNDEFINED:computed:; if ( META_BACK_TGT_T_F( dc->target ) ) { tmp = &ber_bvtf_false; break; } tmp = &ber_bvfalse; break; case LDAP_COMPARE_TRUE: if ( META_BACK_TGT_T_F( dc->target ) ) { tmp = &ber_bvtf_true; break; } tmp = &ber_bvtrue; break; default: tmp = &ber_bverror; break; } ber_dupbv( fstr, tmp ); break; default: ber_dupbv( fstr, &ber_bvunknown ); break; } return 0;}intldap_back_filter_map_rewrite( dncookie *dc, Filter *f, struct berval *fstr, int remap ){ int rc; dncookie fdc; struct berval ftmp; static char *dmy = ""; rc = ldap_back_int_filter_map_rewrite( dc, f, fstr, remap );#ifdef ENABLE_REWRITE if ( rc != LDAP_SUCCESS ) { return rc; } fdc = *dc; ftmp = *fstr; fdc.ctx = "searchFilter"; switch ( rewrite_session( fdc.target->mt_rwmap.rwm_rw, fdc.ctx, ( !BER_BVISEMPTY( &ftmp ) ? ftmp.bv_val : dmy ), fdc.conn, &fstr->bv_val ) ) { case REWRITE_REGEXEC_OK: if ( !BER_BVISNULL( fstr ) ) { fstr->bv_len = strlen( fstr->bv_val ); } else { *fstr = ftmp; } Debug( LDAP_DEBUG_ARGS, "[rw] %s: \"%s\" -> \"%s\"\n", fdc.ctx, BER_BVISNULL( &ftmp ) ? "" : ftmp.bv_val, BER_BVISNULL( fstr ) ? "" : fstr->bv_val ); rc = LDAP_SUCCESS; break; case REWRITE_REGEXEC_UNWILLING: if ( fdc.rs ) { fdc.rs->sr_err = LDAP_UNWILLING_TO_PERFORM; fdc.rs->sr_text = "Operation not allowed"; } rc = LDAP_UNWILLING_TO_PERFORM; break; case REWRITE_REGEXEC_ERR: if ( fdc.rs ) { fdc.rs->sr_err = LDAP_OTHER; fdc.rs->sr_text = "Rewrite error"; } rc = LDAP_OTHER; break; } if ( fstr->bv_val == dmy ) { BER_BVZERO( fstr ); }#endif /* ENABLE_REWRITE */ return rc;}intldap_back_referral_result_rewrite( dncookie *dc, BerVarray a_vals){ int i, last; assert( dc != NULL ); assert( a_vals != NULL ); for ( last = 0; !BER_BVISNULL( &a_vals[ last ] ); last++ ) ; last--; for ( i = 0; !BER_BVISNULL( &a_vals[ i ] ); i++ ) { struct berval dn, olddn = BER_BVNULL; int rc; LDAPURLDesc *ludp; rc = ldap_url_parse( a_vals[ i ].bv_val, &ludp ); if ( rc != LDAP_URL_SUCCESS ) { /* leave attr untouched if massage failed */ continue; } /* FIXME: URLs like "ldap:///dc=suffix" if passed * thru ldap_url_parse() and ldap_url_desc2str() * get rewritten as "ldap:///dc=suffix??base"; * we don't want this to occur... */ if ( ludp->lud_scope == LDAP_SCOPE_BASE ) { ludp->lud_scope = LDAP_SCOPE_DEFAULT; } ber_str2bv( ludp->lud_dn, 0, 0, &olddn ); rc = ldap_back_dn_massage( dc, &olddn, &dn ); switch ( rc ) { case LDAP_UNWILLING_TO_PERFORM: /* * FIXME: need to check if it may be considered * legal to trim values when adding/modifying; * it should be when searching (e.g. ACLs). */ LBER_FREE( a_vals[ i ].bv_val ); if ( last > i ) { a_vals[ i ] = a_vals[ last ]; } BER_BVZERO( &a_vals[ last ] ); last--; i--; break; default: /* leave attr untouched if massage failed */ if ( !BER_BVISNULL( &dn ) && olddn.bv_val != dn.bv_val ) { char *newurl; ludp->lud_dn = dn.bv_val; newurl = ldap_url_desc2str( ludp ); free( dn.bv_val ); if ( newurl == NULL ) { /* FIXME: leave attr untouched * even if ldap_url_desc2str failed... */ break; } LBER_FREE( a_vals[ i ].bv_val ); ber_str2bv( newurl, 0, 1, &a_vals[ i ] ); LDAP_FREE( newurl ); ludp->lud_dn = olddn.bv_val; } break; } ldap_free_urldesc( ludp ); } return 0;}/* * I don't like this much, but we need two different * functions because different heap managers may be * in use in back-ldap/meta to reduce the amount of * calls to malloc routines, and some of the free() * routines may be macros with args */intldap_dnattr_rewrite( dncookie *dc, BerVarray a_vals){ struct berval bv; int i, last; assert( a_vals != NULL ); for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ ) ; last--; for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) { switch ( ldap_back_dn_massage( dc, &a_vals[i], &bv ) ) { case LDAP_UNWILLING_TO_PERFORM: /* * FIXME: need to check if it may be considered * legal to trim values when adding/modifying; * it should be when searching (e.g. ACLs). */ ch_free( a_vals[i].bv_val ); if ( last > i ) { a_vals[i] = a_vals[last]; } BER_BVZERO( &a_vals[last] ); last--; break; default: /* leave attr untouched if massage failed */ if ( !BER_BVISNULL( &bv ) && bv.bv_val != a_vals[i].bv_val ) { ch_free( a_vals[i].bv_val ); a_vals[i] = bv; } break; } } return 0;}intldap_dnattr_result_rewrite( dncookie *dc, BerVarray a_vals){ struct berval bv; int i, last; assert( a_vals != NULL ); for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ ) ; last--; for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) { switch ( ldap_back_dn_massage( dc, &a_vals[i], &bv ) ) { case LDAP_UNWILLING_TO_PERFORM: /* * FIXME: need to check if it may be considered * legal to trim values when adding/modifying; * it should be when searching (e.g. ACLs). */ LBER_FREE( a_vals[i].bv_val ); if ( last > i ) { a_vals[i] = a_vals[last]; } BER_BVZERO( &a_vals[last] ); last--; break; default: /* leave attr untouched if massage failed */ if ( !BER_BVISNULL( &bv ) && a_vals[i].bv_val != bv.bv_val ) { LBER_FREE( a_vals[i].bv_val ); a_vals[i] = bv; } break; } } return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?