int dnPretty( Syntax *syntax, struct berval *val, struct berval *out, void *ctx) { assert( val != NULL ); assert( out != NULL ); Debug( LDAP_DEBUG_TRACE, ">>> dnPretty: <%s>\n", val->bv_val ? val->bv_val : "", 0, 0 ); if ( val->bv_len == 0 ) { ber_dupbv_x( out, val, ctx ); } else if ( val->bv_len > SLAP_LDAPDN_MAXLEN ) { return LDAP_INVALID_SYNTAX; } else { LDAPDN dn = NULL; int rc; /* FIXME: should be liberal in what we accept */ rc = ldap_bv2dn_x( val, &dn, LDAP_DN_FORMAT_LDAP, ctx ); if ( rc != LDAP_SUCCESS ) { return LDAP_INVALID_SYNTAX; } assert( strlen( val->bv_val ) == val->bv_len ); /* * Schema-aware rewrite */ if ( LDAPDN_rewrite( dn, SLAP_LDAPDN_PRETTY, ctx ) != LDAP_SUCCESS ) { ldap_dnfree_x( dn, ctx ); return LDAP_INVALID_SYNTAX; } /* FIXME: not sure why the default isn't pretty */ /* RE: the default is the form that is used as * an internal representation; the pretty form * is a variant */ rc = ldap_dn2bv_x( dn, out, LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY, ctx ); ldap_dnfree_x( dn, ctx ); if ( rc != LDAP_SUCCESS ) { return LDAP_INVALID_SYNTAX; } } Debug( LDAP_DEBUG_TRACE, "<<< dnPretty: <%s>\n", out->bv_val ? out->bv_val : "", 0, 0 ); return LDAP_SUCCESS; }
int dnNormalize( slap_mask_t use, Syntax *syntax, MatchingRule *mr, struct berval *val, struct berval *out, void *ctx) { assert( val != NULL ); assert( out != NULL ); Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: <%s>\n", val->bv_val ? val->bv_val : "", 0, 0 ); if ( val->bv_len != 0 ) { LDAPDN dn = NULL; int rc; /* * Go to structural representation */ rc = ldap_bv2dn_x( val, &dn, LDAP_DN_FORMAT_LDAP, ctx ); if ( rc != LDAP_SUCCESS ) { return LDAP_INVALID_SYNTAX; } assert( strlen( val->bv_val ) == val->bv_len ); /* * Schema-aware rewrite */ if ( LDAPDN_rewrite( dn, 0, ctx ) != LDAP_SUCCESS ) { ldap_dnfree_x( dn, ctx ); return LDAP_INVALID_SYNTAX; } /* * Back to string representation */ rc = ldap_dn2bv_x( dn, out, LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY, ctx ); ldap_dnfree_x( dn, ctx ); if ( rc != LDAP_SUCCESS ) { return LDAP_INVALID_SYNTAX; } } else { ber_dupbv_x( out, val, ctx ); } Debug( LDAP_DEBUG_TRACE, "<<< dnNormalize: <%s>\n", out->bv_val ? out->bv_val : "", 0, 0 ); return LDAP_SUCCESS; }
/* Rewrite an LDAP DN in DER form * Input must be valid DN, therefore no error checking is done here. */ static int autoca_dnbv2der( Operation *op, struct berval *bv, struct berval *der ) { BerElementBuffer berbuf; BerElement *ber = (BerElement *)&berbuf; LDAPDN dn; LDAPRDN rdn; LDAPAVA *ava; AttributeDescription *ad; int irdn, iava; ldap_bv2dn_x( bv, &dn, LDAP_DN_FORMAT_LDAP, op->o_tmpmemctx ); ber_init2( ber, NULL, LBER_USE_DER ); ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx ); /* count RDNs, we need them in reverse order */ for (irdn = 0; dn[irdn]; irdn++); irdn--; /* DN is a SEQuence of RDNs */ ber_start_seq( ber, LBER_SEQUENCE ); for (; irdn >=0; irdn--) { /* RDN is a SET of AVAs */ ber_start_set( ber, LBER_SET ); rdn = dn[irdn]; for (iava = 0; rdn[iava]; iava++) { const char *text; char oid[1024]; struct berval bvo = { sizeof(oid), oid }; struct berval bva; /* AVA is a SEQuence of attr and value */ ber_start_seq( ber, LBER_SEQUENCE ); ava = rdn[iava]; ad = NULL; slap_bv2ad( &ava->la_attr, &ad, &text ); ber_str2bv( ad->ad_type->sat_oid, 0, 0, &bva ); ber_encode_oid( &bva, &bvo ); ber_put_berval( ber, &bvo, LBER_TAG_OID ); ber_put_berval( ber, &ava->la_value, LBER_TAG_UTF8 ); ber_put_seq( ber ); } ber_put_set( ber ); } ber_put_seq( ber ); ber_flatten2( ber, der, 0 ); ldap_dnfree_x( dn, op->o_tmpmemctx ); return 0; }
int dnPrettyNormalDN( Syntax *syntax, struct berval *val, LDAPDN *dn, int flags, void *ctx ) { assert( val != NULL ); assert( dn != NULL ); Debug( LDAP_DEBUG_TRACE, ">>> dn%sDN: <%s>\n", flags == SLAP_LDAPDN_PRETTY ? "Pretty" : "Normal", val->bv_val ? val->bv_val : "", 0 ); if ( val->bv_len == 0 ) { return LDAP_SUCCESS; } else if ( val->bv_len > SLAP_LDAPDN_MAXLEN ) { return LDAP_INVALID_SYNTAX; } else { int rc; /* FIXME: should be liberal in what we accept */ rc = ldap_bv2dn_x( val, dn, LDAP_DN_FORMAT_LDAP, ctx ); if ( rc != LDAP_SUCCESS ) { return LDAP_INVALID_SYNTAX; } assert( strlen( val->bv_val ) == val->bv_len ); /* * Schema-aware rewrite */ if ( LDAPDN_rewrite( *dn, flags, ctx ) != LDAP_SUCCESS ) { ldap_dnfree_x( *dn, ctx ); *dn = NULL; return LDAP_INVALID_SYNTAX; } } Debug( LDAP_DEBUG_TRACE, "<<< dn%sDN\n", flags == SLAP_LDAPDN_PRETTY ? "Pretty" : "Normal", 0, 0 ); return LDAP_SUCCESS; }
/* * Combination of both dnPretty and dnNormalize */ int dnPrettyNormal( Syntax *syntax, struct berval *val, struct berval *pretty, struct berval *normal, void *ctx) { assert( val != NULL ); assert( pretty != NULL ); assert( normal != NULL ); Debug( LDAP_DEBUG_TRACE, ">>> dnPrettyNormal: <%s>\n", val->bv_val ? val->bv_val : "", 0, 0 ); if ( val->bv_len == 0 ) { ber_dupbv_x( pretty, val, ctx ); ber_dupbv_x( normal, val, ctx ); } else if ( val->bv_len > SLAP_LDAPDN_MAXLEN ) { /* too big */ return LDAP_INVALID_SYNTAX; } else { LDAPDN dn = NULL; int rc; pretty->bv_val = NULL; normal->bv_val = NULL; pretty->bv_len = 0; normal->bv_len = 0; /* FIXME: should be liberal in what we accept */ rc = ldap_bv2dn_x( val, &dn, LDAP_DN_FORMAT_LDAP, ctx ); if ( rc != LDAP_SUCCESS ) { return LDAP_INVALID_SYNTAX; } assert( strlen( val->bv_val ) == val->bv_len ); /* * Schema-aware rewrite */ if ( LDAPDN_rewrite( dn, SLAP_LDAPDN_PRETTY, ctx ) != LDAP_SUCCESS ) { ldap_dnfree_x( dn, ctx ); return LDAP_INVALID_SYNTAX; } rc = ldap_dn2bv_x( dn, pretty, LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY, ctx ); if ( rc != LDAP_SUCCESS ) { ldap_dnfree_x( dn, ctx ); return LDAP_INVALID_SYNTAX; } if ( LDAPDN_rewrite( dn, 0, ctx ) != LDAP_SUCCESS ) { ldap_dnfree_x( dn, ctx ); ber_memfree_x( pretty->bv_val, ctx ); pretty->bv_val = NULL; pretty->bv_len = 0; return LDAP_INVALID_SYNTAX; } rc = ldap_dn2bv_x( dn, normal, LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY, ctx ); ldap_dnfree_x( dn, ctx ); if ( rc != LDAP_SUCCESS ) { ber_memfree_x( pretty->bv_val, ctx ); pretty->bv_val = NULL; pretty->bv_len = 0; return LDAP_INVALID_SYNTAX; } } Debug( LDAP_DEBUG_TRACE, "<<< dnPrettyNormal: <%s>, <%s>\n", pretty->bv_val ? pretty->bv_val : "", normal->bv_val ? normal->bv_val : "", 0 ); return LDAP_SUCCESS; }