]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/tools/slapadd.c
Don't reeval expression
[openldap] / servers / slapd / tools / slapadd.c
index 91fb15c3822c863933894db3fc882f80ed919f2d..1f31d57735385f4f5b0195d30c424622e6c173b9 100644 (file)
@@ -32,10 +32,6 @@ main( int argc, char **argv )
        char textbuf[SLAP_TEXT_BUFLEN] = { '\0' };
        size_t textlen = sizeof textbuf;
 
-       struct berval name, timestamp, csn;
-       char timebuf[22];
-       char csnbuf[64];
-
 #ifdef NEW_LOGGING
        lutil_log_initialize(argc, argv );
 #endif
@@ -63,8 +59,12 @@ main( int argc, char **argv )
                Entry *e = str2entry( buf );
                struct berval bvtext;
 
+               /*
+                * Initialize text buffer
+                */
                bvtext.bv_len = textlen;
                bvtext.bv_val = textbuf;
+               bvtext.bv_val[0] = '\0';
 
                if( e == NULL ) {
                        fprintf( stderr, "%s: could not parse entry (line=%d)\n",
@@ -104,7 +104,7 @@ main( int argc, char **argv )
                        break;
                }
 
-               {
+               if( global_schemacheck ) {
                        Attribute *sc = attr_find( e->e_attrs,
                                slap_schema.si_ad_structuralObjectClass );
                        Attribute *oc = attr_find( e->e_attrs,
@@ -123,13 +123,12 @@ main( int argc, char **argv )
                        if( sc == NULL ) {
                                struct berval vals[2];
 
-                               /* int ret = */ 
-                                       structural_class( oc->a_vals, vals,
+                               rc = structural_class( oc->a_vals, vals,
                                        NULL, &text, textbuf, textlen );
 
-                               if( vals[0].bv_len == 0 ) {
-                                       fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
-                                       progname, e->e_dn, lineno, text );
+                               if( rc != LDAP_SUCCESS ) {
+                                       fprintf( stderr, "%s: dn=\"%s\" (line=%d): (%d) %s\n",
+                                               progname, e->e_dn, lineno, rc, text );
                                        rc = EXIT_FAILURE;
                                        entry_free( e );
                                        if( continuemode ) continue;
@@ -140,11 +139,29 @@ main( int argc, char **argv )
                                attr_merge( e, slap_schema.si_ad_structuralObjectClass,
                                        vals );
                        }
+
+                       /* check schema */
+                       rc = entry_schema_check( be, e, NULL, &text, textbuf, textlen );
+
+                       if( rc != LDAP_SUCCESS ) {
+                               fprintf( stderr, "%s: dn=\"%s\" (line=%d): (%d) %s\n",
+                                       progname, e->e_dn, lineno, rc, text );
+                               rc = EXIT_FAILURE;
+                               entry_free( e );
+                               if( continuemode ) continue;
+                               break;
+                       }
                }
 
                if ( SLAP_LASTMOD(be) ) {
                        struct tm *ltm;
                        time_t now = slap_get_time();
+                       char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
+                       struct berval vals[ 2 ];
+
+                       struct berval name, timestamp, csn;
+                       char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
+                       char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
 
                        ltm = gmtime(&now);
                        lutil_gentime( timebuf, sizeof(timebuf), ltm );
@@ -161,57 +178,61 @@ main( int argc, char **argv )
                        } else {
                                name = be->be_rootndn;
                        }
-               }
 
-               if( global_schemacheck ) {
-                       /* check schema */
+                       if( attr_find( e->e_attrs, slap_schema.si_ad_entryUUID )
+                               == NULL )
+                       {
+                               vals[0].bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
+                               vals[0].bv_val = uuidbuf;
+                               vals[1].bv_len = 0;
+                               vals[1].bv_val = NULL;
+                               attr_merge( e, slap_schema.si_ad_entryUUID, vals );
+                       }
 
-                       rc = entry_schema_check( be, e, NULL, &text, textbuf, textlen );
+                       if( attr_find( e->e_attrs, slap_schema.si_ad_creatorsName )
+                               == NULL )
+                       {
+                               vals[0] = name;
+                               vals[1].bv_len = 0;
+                               vals[1].bv_val = NULL;
+                               attr_merge( e, slap_schema.si_ad_creatorsName, vals);
+                       }
 
-                       if( rc != LDAP_SUCCESS ) {
-                               fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
-                                       progname, e->e_dn, lineno, text );
-                               rc = EXIT_FAILURE;
-                               entry_free( e );
-                               if( continuemode ) continue;
-                               break;
+                       if( attr_find( e->e_attrs, slap_schema.si_ad_modifiersName )
+                               == NULL )
+                       {
+                               vals[0] = name;
+                               vals[1].bv_len = 0;
+                               vals[1].bv_val = NULL;
+                               attr_merge( e, slap_schema.si_ad_modifiersName, vals);
                        }
-               }
 
-               if ( SLAP_LASTMOD(be) ) {
-                       char uuidbuf[40];
-                       struct berval vals[2];
-
-                       vals[0].bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
-                       vals[0].bv_val = uuidbuf;
-                       vals[1].bv_len = 0;
-                       vals[1].bv_val = NULL;
-                       attr_merge( e, slap_schema.si_ad_entryUUID, vals );
-
-                       ber_dupbv( &vals[0], &name );
-                       vals[1].bv_len = 0;
-                       vals[1].bv_val = NULL;
-                       attr_merge( e, slap_schema.si_ad_creatorsName, vals);
-
-                       ber_dupbv( &vals[0], &name );
-                       vals[1].bv_len = 0;
-                       vals[1].bv_val = NULL;
-                       attr_merge( e, slap_schema.si_ad_modifiersName, vals);
-
-                       ber_dupbv( &vals[0], &timestamp );
-                       vals[1].bv_len = 0;
-                       vals[1].bv_val = NULL;
-                       attr_merge( e, slap_schema.si_ad_createTimestamp, vals );
-
-                       ber_dupbv( &vals[0], &timestamp );
-                       vals[1].bv_len = 0;
-                       vals[1].bv_val = NULL;
-                       attr_merge( e, slap_schema.si_ad_modifyTimestamp, vals );
-
-                       ber_dupbv( &vals[0], &csn );
-                       vals[1].bv_len = 0;
-                       vals[1].bv_val = NULL;
-                       attr_merge( e, slap_schema.si_ad_entryCSN, vals );
+                       if( attr_find( e->e_attrs, slap_schema.si_ad_createTimestamp )
+                               == NULL )
+                       {
+                               vals[0] = timestamp;
+                               vals[1].bv_len = 0;
+                               vals[1].bv_val = NULL;
+                               attr_merge( e, slap_schema.si_ad_createTimestamp, vals );
+                       }
+
+                       if( attr_find( e->e_attrs, slap_schema.si_ad_modifyTimestamp )
+                               == NULL )
+                       {
+                               vals[0] = timestamp;
+                               vals[1].bv_len = 0;
+                               vals[1].bv_val = NULL;
+                               attr_merge( e, slap_schema.si_ad_modifyTimestamp, vals );
+                       }
+
+                       if( attr_find( e->e_attrs, slap_schema.si_ad_entryCSN )
+                               == NULL )
+                       {
+                               vals[0] = csn;
+                               vals[1].bv_len = 0;
+                               vals[1].bv_val = NULL;
+                               attr_merge( e, slap_schema.si_ad_entryCSN, vals );
+                       }
                }
 
                if (!dryrun) {