do_add( Connection *conn, Operation *op )
{
BerElement *ber = op->o_ber;
- char *dn, *ndn, *last;
+ char *dn, *last;
ber_len_t len;
ber_tag_t tag;
Entry *e;
if ( ber_scanf( ber, "{a", /*}*/ &dn ) == LBER_ERROR ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
- "do_add: conn %d ber_scanf failed\n", conn->c_connid ));
+ "do_add: conn %d ber_scanf failed\n", conn->c_connid ));
#else
Debug( LDAP_DEBUG_ANY, "do_add: ber_scanf failed\n", 0, 0, 0 );
#endif
return -1;
}
- ndn = ch_strdup( dn );
+ e = (Entry *) ch_calloc( 1, sizeof(Entry) );
- if ( dn_normalize( ndn ) == NULL ) {
+ e->e_dn = dn_pretty( dn );
+ e->e_ndn = dn_normalize( dn );
+ e->e_attrs = NULL;
+ e->e_private = NULL;
+
+ if ( e->e_ndn == NULL ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
- "do_add: conn %d invalid dn (%s)\n", conn->c_connid, dn ));
+ "do_add: conn %d invalid dn (%s)\n", conn->c_connid, dn ));
#else
Debug( LDAP_DEBUG_ANY, "do_add: invalid dn (%s)\n", dn, 0, 0 );
#endif
- send_ldap_result( conn, op, LDAP_INVALID_DN_SYNTAX, NULL,
+ send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
"invalid DN", NULL, NULL );
- free( dn );
- free( ndn );
- return LDAP_INVALID_DN_SYNTAX;
+ goto done;
}
- e = (Entry *) ch_calloc( 1, sizeof(Entry) );
-
- e->e_dn = dn;
- e->e_ndn = ndn;
- e->e_attrs = NULL;
- e->e_private = NULL;
-
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
- "do_add: conn %d ndn (%s)\n", conn->c_connid, e->e_ndn ));
+ "do_add: conn %d ndn (%s)\n", conn->c_connid, e->e_ndn ));
#else
Debug( LDAP_DEBUG_ARGS, "do_add: ndn (%s)\n", e->e_ndn, 0, 0 );
#endif
goto done;
#if defined( SLAPD_SCHEMA_DN )
- } else if ( strcasecmp( ndn, SLAPD_SCHEMA_DN ) == 0 ) {
+ } else if ( strcasecmp( e->e_ndn, SLAPD_SCHEMA_DN ) == 0 ) {
/* protocolError may be a more appropriate error */
send_ldap_result( conn, op, rc = LDAP_ALREADY_EXISTS,
NULL, "subschema subentry already exists",
#define INQUOTEDVALUE 7
#define B4SEPARATOR 8
+/*
+ * dn_pretty - "pretty" the DN
+ */
+char *dn_pretty( const char *dn_in )
+{
+ /*
+ * dn_validate based implementation (for now)
+ * likely better just to zap this, dn_validate, dn_normalize
+ */
+ char *dn, *dn_out;
+
+ dn = ch_strdup( dn_in );
+ dn_out = dn_validate( dn );
+ if( dn_out == NULL ) free( dn );
+ return dn_out;
+}
+
/*
* dn_validate - validate and compress dn. the dn is
* compressed in place are returned if valid.
char *
dn_parent(
Backend *be,
- const char *dn
-)
+ const char *dn )
{
const char *s;
int inquote;
}
/* generate normalized dn */
- e->e_ndn = ch_strdup( e->e_dn );
+ e->e_ndn = e->e_dn;
+ e->e_dn = dn_pretty( e->e_dn );
+
+ if( e->e_dn == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
+ "str2entry: entry %ld has invalid dn: %s\n",
+ (long) e->e_id, e->e_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "str2entry: entry %ld has invalid dn: %s\n",
+ (long) e->e_id, e->e_ndn, 0 );
+#endif
+ entry_free( e );
+ return( NULL );
+ }
+
(void) dn_normalize( e->e_ndn );
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_DETAIL2,
- "str2entry(%s) -> 0x%lx\n", e->e_dn, (unsigned long)e ));
+ "str2entry(%s) -> 0x%lx\n", e->e_dn, (unsigned long)e ));
#else
Debug(LDAP_DEBUG_TRACE, "<= str2entry(%s) -> 0x%lx\n",
e->e_dn, (unsigned long) e, 0 );