📄 retcode.c
字号:
memset( cb, 0, sizeof( slap_callback ) ); cb->sc_cleanup = retcode_cleanup_cb; op->o_callback = cb; break; default: send_ldap_result( op, rs ); if ( rs->sr_ref != NULL ) { ber_bvarray_free( rs->sr_ref ); rs->sr_ref = NULL; } rs->sr_matched = NULL; rs->sr_text = NULL; break; } return rs->sr_err;}static intretcode_op2str( ber_tag_t op, struct berval *bv ){ switch ( op ) { case LDAP_REQ_BIND: BER_BVSTR( bv, "bind" ); return 0; case LDAP_REQ_ADD: BER_BVSTR( bv, "add" ); return 0; case LDAP_REQ_DELETE: BER_BVSTR( bv, "delete" ); return 0; case LDAP_REQ_MODRDN: BER_BVSTR( bv, "modrdn" ); return 0; case LDAP_REQ_MODIFY: BER_BVSTR( bv, "modify" ); return 0; case LDAP_REQ_COMPARE: BER_BVSTR( bv, "compare" ); return 0; case LDAP_REQ_SEARCH: BER_BVSTR( bv, "search" ); return 0; case LDAP_REQ_EXTENDED: BER_BVSTR( bv, "extended" ); return 0; } return -1;}static intretcode_entry_response( Operation *op, SlapReply *rs, BackendInfo *bi, Entry *e ){ Attribute *a; int err; char *next; if ( get_manageDSAit( op ) ) { return SLAP_CB_CONTINUE; } if ( !is_entry_objectclass_or_sub( e, oc_errAbsObject ) ) { return SLAP_CB_CONTINUE; } /* operation */ a = attr_find( e->e_attrs, ad_errOp ); if ( a != NULL ) { int i, gotit = 0; struct berval bv = BER_BVNULL; (void)retcode_op2str( op->o_tag, &bv ); if ( BER_BVISNULL( &bv ) ) { return SLAP_CB_CONTINUE; } for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) { if ( bvmatch( &a->a_nvals[ i ], &bv ) ) { gotit = 1; break; } } if ( !gotit ) { return SLAP_CB_CONTINUE; } } /* error code */ a = attr_find( e->e_attrs, ad_errCode ); if ( a == NULL ) { return SLAP_CB_CONTINUE; } err = strtol( a->a_nvals[ 0 ].bv_val, &next, 0 ); if ( next == a->a_nvals[ 0 ].bv_val || next[ 0 ] != '\0' ) { return SLAP_CB_CONTINUE; } rs->sr_err = err; /* sleep time */ a = attr_find( e->e_attrs, ad_errSleepTime ); if ( a != NULL && a->a_nvals[ 0 ].bv_val[ 0 ] != '-' ) { int sleepTime; sleepTime = strtoul( a->a_nvals[ 0 ].bv_val, &next, 0 ); if ( next != a->a_nvals[ 0 ].bv_val && next[ 0 ] == '\0' ) { sleep( sleepTime ); } } if ( rs->sr_err != LDAP_SUCCESS ) { BackendDB db = *op->o_bd, *o_bd = op->o_bd; void *o_callback = op->o_callback; /* message text */ a = attr_find( e->e_attrs, ad_errText ); if ( a != NULL ) { rs->sr_text = a->a_vals[ 0 ].bv_val; } /* matched DN */ a = attr_find( e->e_attrs, ad_errMatchedDN ); if ( a != NULL ) { rs->sr_matched = a->a_vals[ 0 ].bv_val; } if ( bi == NULL ) { slap_overinst *on = (slap_overinst *)op->o_bd->bd_info; bi = on->on_info->oi_orig; } db.bd_info = bi; op->o_bd = &db; op->o_callback = NULL; /* referral */ if ( rs->sr_err == LDAP_REFERRAL ) { BerVarray refs = default_referral; a = attr_find( e->e_attrs, slap_schema.si_ad_ref ); if ( a != NULL ) { refs = a->a_vals; } rs->sr_ref = referral_rewrite( refs, NULL, &op->o_req_dn, op->oq_search.rs_scope ); send_search_reference( op, rs ); ber_bvarray_free( rs->sr_ref ); rs->sr_ref = NULL; } else { send_ldap_result( op, rs ); } rs->sr_text = NULL; rs->sr_matched = NULL; op->o_bd = o_bd; op->o_callback = o_callback; } if ( rs->sr_err != LDAP_SUCCESS ) { op->o_abandon = 1; return rs->sr_err; } return SLAP_CB_CONTINUE;}static intretcode_response( Operation *op, SlapReply *rs ){ slap_overinst *on = (slap_overinst *)op->o_bd->bd_info; retcode_t *rd = (retcode_t *)on->on_bi.bi_private; if ( rs->sr_type != REP_SEARCH || !RETCODE_INDIR( rd ) ) { return SLAP_CB_CONTINUE; } return retcode_entry_response( op, rs, NULL, rs->sr_entry );}static intretcode_db_init( BackendDB *be ){ slap_overinst *on = (slap_overinst *)be->bd_info; retcode_t *rd; rd = (retcode_t *)ch_malloc( sizeof( retcode_t ) ); memset( rd, 0, sizeof( retcode_t ) ); on->on_bi.bi_private = (void *)rd; return 0;}static intretcode_db_config( BackendDB *be, const char *fname, int lineno, int argc, char **argv ){ slap_overinst *on = (slap_overinst *)be->bd_info; retcode_t *rd = (retcode_t *)on->on_bi.bi_private; char *argv0 = argv[ 0 ] + STRLENOF( "retcode-" ); if ( strncasecmp( argv[ 0 ], "retcode-", STRLENOF( "retcode-" ) ) != 0 ) { return SLAP_CONF_UNKNOWN; } if ( strcasecmp( argv0, "parent" ) == 0 ) { struct berval dn; int rc; if ( argc != 2 ) { fprintf( stderr, "%s: line %d: retcode: " "\"retcode-parent <DN>\": missing <DN>\n", fname, lineno ); return 1; } if ( !BER_BVISNULL( &rd->rd_pdn ) ) { fprintf( stderr, "%s: line %d: retcode: " "parent already defined.\n", fname, lineno ); return 1; } ber_str2bv( argv[ 1 ], 0, 0, &dn ); rc = dnPrettyNormal( NULL, &dn, &rd->rd_pdn, &rd->rd_npdn, NULL ); if ( rc != LDAP_SUCCESS ) { fprintf( stderr, "%s: line %d: retcode: " "unable to normalize parent DN \"%s\": %d\n", fname, lineno, argv[ 1 ], rc ); return 1; } } else if ( strcasecmp( argv0, "item" ) == 0 ) { retcode_item_t rdi = { BER_BVNULL }, **rdip; struct berval bv, rdn, nrdn; int rc; char *next = NULL; if ( argc < 3 ) { fprintf( stderr, "%s: line %d: retcode: " "\"retcode-item <RDN> <retcode> [<text>]\": " "missing args\n", fname, lineno ); return 1; } ber_str2bv( argv[ 1 ], 0, 0, &bv ); rc = dnPrettyNormal( NULL, &bv, &rdn, &nrdn, NULL ); if ( rc != LDAP_SUCCESS ) { fprintf( stderr, "%s: line %d: retcode: " "unable to normalize RDN \"%s\": %d\n", fname, lineno, argv[ 1 ], rc ); return 1; } if ( !dnIsOneLevelRDN( &nrdn ) ) { fprintf( stderr, "%s: line %d: retcode: " "value \"%s\" is not a RDN\n", fname, lineno, argv[ 1 ] ); return 1; } if ( BER_BVISNULL( &rd->rd_npdn ) ) { /* FIXME: we use the database suffix */ if ( be->be_nsuffix == NULL ) { fprintf( stderr, "%s: line %d: retcode: " "either \"retcode-parent\" " "or \"suffix\" must be defined.\n", fname, lineno ); return 1; } ber_dupbv( &rd->rd_pdn, &be->be_suffix[ 0 ] ); ber_dupbv( &rd->rd_npdn, &be->be_nsuffix[ 0 ] ); } build_new_dn( &rdi.rdi_dn, &rd->rd_pdn, &rdn, NULL ); build_new_dn( &rdi.rdi_ndn, &rd->rd_npdn, &nrdn, NULL ); ch_free( rdn.bv_val ); ch_free( nrdn.bv_val ); rdi.rdi_err = strtol( argv[ 2 ], &next, 0 ); if ( next == argv[ 2 ] || next[ 0 ] != '\0' ) { fprintf( stderr, "%s: line %d: retcode: " "unable to parse return code \"%s\"\n", fname, lineno, argv[ 2 ] ); return 1; } rdi.rdi_mask = SN_DG_OP_ALL; if ( argc > 3 ) { int i; for ( i = 3; i < argc; i++ ) { if ( strncasecmp( argv[ i ], "op=", STRLENOF( "op=" ) ) == 0 ) { char **ops; int j; ops = ldap_str2charray( &argv[ i ][ STRLENOF( "op=" ) ], "," ); assert( ops != NULL ); rdi.rdi_mask = SN_DG_OP_NONE; for ( j = 0; ops[ j ] != NULL; j++ ) { if ( strcasecmp( ops[ j ], "add" ) == 0 ) { rdi.rdi_mask |= SN_DG_OP_ADD; } else if ( strcasecmp( ops[ j ], "bind" ) == 0 ) { rdi.rdi_mask |= SN_DG_OP_BIND; } else if ( strcasecmp( ops[ j ], "compare" ) == 0 ) { rdi.rdi_mask |= SN_DG_OP_COMPARE; } else if ( strcasecmp( ops[ j ], "delete" ) == 0 ) { rdi.rdi_mask |= SN_DG_OP_DELETE; } else if ( strcasecmp( ops[ j ], "modify" ) == 0 ) { rdi.rdi_mask |= SN_DG_OP_MODIFY; } else if ( strcasecmp( ops[ j ], "rename" ) == 0 || strcasecmp( ops[ j ], "modrdn" ) == 0 ) { rdi.rdi_mask |= SN_DG_OP_RENAME; } else if ( strcasecmp( ops[ j ], "search" ) == 0 ) { rdi.rdi_mask |= SN_DG_OP_SEARCH; } else if ( strcasecmp( ops[ j ], "extended" ) == 0 ) { rdi.rdi_mask |= SN_DG_EXTENDED; } else if ( strcasecmp( ops[ j ], "auth" ) == 0 ) { rdi.rdi_mask |= SN_DG_OP_AUTH; } else if ( strcasecmp( ops[ j ], "read" ) == 0 ) { rdi.rdi_mask |= SN_DG_OP_READ; } else if ( strcasecmp( ops[ j ], "write" ) == 0 ) { rdi.rdi_mask |= SN_DG_OP_WRITE; } else if ( strcasecmp( ops[ j ], "all" ) == 0 ) { rdi.rdi_mask |= SN_DG_OP_ALL; } else { fprintf( stderr, "retcode: unknown op \"%s\"\n", ops[ j ] ); return 1; } } ldap_charray_free( ops ); } else if ( strncasecmp( argv[ i ], "text=", STRLENOF( "text=" ) ) == 0 ) { if ( !BER_BVISNULL( &rdi.rdi_text ) ) { fprintf( stderr, "%s: line %d: retcode: " "\"text\" already provided.\n", fname, lineno ); return 1; } ber_str2bv( &argv[ i ][ STRLENOF( "text=" ) ], 0, 1, &rdi.rdi_text ); } else if ( strncasecmp( argv[ i ], "matched=", STRLENOF( "matched=" ) ) == 0 ) { struct berval dn; if ( !BER_BVISNULL( &rdi.rdi_matched ) ) { fprintf( stderr, "%s: line %d: retcode: " "\"matched\" already provided.\n", fname, lineno ); return 1; } ber_str2bv( &argv[ i ][ STRLENOF( "matched=" ) ], 0, 0, &dn ); if ( dnPretty( NULL, &dn, &rdi.rdi_matched, NULL ) != LDAP_SUCCESS ) { fprintf( stderr, "%s: line %d: retcode: " "unable to prettify matched DN \"%s\".\n", fname, lineno, &argv[ i ][ STRLENOF( "matched=" ) ] ); return 1; } } else if ( strncasecmp( argv[ i ], "ref=", STRLENOF( "ref=" ) ) == 0 ) { char **refs; int j; if ( rdi.rdi_ref != NULL ) { fprintf( stderr, "%s: line %d: retcode: " "\"ref\" already provided.\n", fname, lineno ); return 1; } if ( rdi.rdi_err != LDAP_REFERRAL ) { fprintf( stderr, "%s: line %d: retcode: " "providing \"ref\"\n" "\talong with a non-referral " "resultCode may cause slapd failures\n" "\trelated to internal checks.\n", fname, lineno ); } refs = ldap_str2charray( &argv[ i ][ STRLENOF( "ref=" ) ], " " ); assert( refs != NULL ); for ( j = 0; refs[ j ] != NULL; j++ ) { struct berval bv; ber_str2bv( refs[ j ], 0, 1, &bv ); ber_bvarray_add( &rdi.rdi_ref, &bv ); } ldap_charray_free( refs ); } else if ( strncasecmp( argv[ i ], "sleeptime=", STRLENOF( "sleeptime=" ) ) == 0 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -