From b81122d441ea16d534d4195d342ba681519cf901 Mon Sep 17 00:00:00 2001 From: Jong Hyuk Choi Date: Wed, 21 Aug 2002 00:11:32 +0000 Subject: [PATCH] Slapadd is changed to include Operational Attributes (entryUUID, entryCSN, creatorsName, modifiersName, createTimestamp, modifyTimestamp) when it adds from ldif file. Month field in time format in entryCSN is changed to 1~12. --- libraries/liblutil/csn.c | 2 +- servers/slapd/tools/slapadd.c | 61 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/libraries/liblutil/csn.c b/libraries/liblutil/csn.c index 33907102e1..0a18918b3b 100644 --- a/libraries/liblutil/csn.c +++ b/libraries/liblutil/csn.c @@ -54,7 +54,7 @@ lutil_csnstr(char *buf, size_t len, unsigned int replica, unsigned int mod) ltm = gmtime( &t ); n = snprintf( buf, len, "%4d%02d%02d%02d:%02d:%02dZ#0x%04x#%d#%04x", - ltm->tm_year + 1900, ltm->tm_mon, ltm->tm_mday, ltm->tm_hour, + ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday, ltm->tm_hour, ltm->tm_min, ltm->tm_sec, op, replica, mod ); if( n < 0 ) return 0; diff --git a/servers/slapd/tools/slapadd.c b/servers/slapd/tools/slapadd.c index 7710127740..3c71859e83 100644 --- a/servers/slapd/tools/slapadd.c +++ b/servers/slapd/tools/slapadd.c @@ -31,6 +31,10 @@ 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 @@ -137,6 +141,27 @@ main( int argc, char **argv ) } } + if ( SLAP_LASTMOD(be) ) { + struct tm *ltm; + time_t now = slap_get_time(); + + ltm = gmtime(&now); + lutil_gentime( timebuf, sizeof(timebuf), ltm ); + + csn.bv_len = lutil_csnstr( csnbuf, sizeof( csnbuf ), 0, 0 ); + csn.bv_val = csnbuf; + + timestamp.bv_val = timebuf; + timestamp.bv_len = strlen(timebuf); + + if ( be->be_rootndn.bv_len == 0 ) { + name.bv_val = SLAPD_ANONYMOUS; + name.bv_len = sizeof(SLAPD_ANONYMOUS) - 1; + } else { + name = be->be_rootndn; + } + } + if( global_schemacheck ) { /* check schema */ @@ -152,6 +177,42 @@ main( int argc, char **argv ) } } + 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], ×tamp ); + vals[1].bv_len = 0; + vals[1].bv_val = NULL; + attr_merge( e, slap_schema.si_ad_createTimestamp, vals ); + + ber_dupbv( &vals[0], ×tamp ); + 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 (!dryrun) { ID id = be->be_entry_put( be, e, &bvtext ); if( id == NOID ) { -- 2.39.5