From 86f79b85d85941b0f473ea44ef18774a4f946e01 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Wed, 5 Dec 2001 07:25:25 +0000 Subject: [PATCH] Add experimental UUID/CSN support (needed for LCUP). --- libraries/liblutil/csn.c | 4 ++-- libraries/liblutil/uuid.c | 11 ++++++---- servers/slapd/modify.c | 37 +++++++++++++++++++++++++++++--- servers/slapd/schema/core.schema | 16 ++++++++++++++ servers/slapd/schema_prep.c | 4 ++++ servers/slapd/slap.h | 4 ++-- 6 files changed, 65 insertions(+), 11 deletions(-) diff --git a/libraries/liblutil/csn.c b/libraries/liblutil/csn.c index 104ad5cd4d..9c92737724 100644 --- a/libraries/liblutil/csn.c +++ b/libraries/liblutil/csn.c @@ -32,7 +32,7 @@ #include #include -int +size_t lutil_csnstr(char *buf, size_t len, unsigned int replica, unsigned int mod) { static time_t csntime; @@ -55,7 +55,7 @@ lutil_csnstr(char *buf, size_t len, unsigned int replica, unsigned int mod) ltm->tm_year + 1900, ltm->tm_mon, ltm->tm_mday, ltm->tm_hour, ltm->tm_min, ltm->tm_sec, op, replica, mod ); - return ( n < len ) ? 1 : 0; + return ( n < len ) ? n : 0; } #ifdef TEST diff --git a/libraries/liblutil/uuid.c b/libraries/liblutil/uuid.c index 9800cc9cad..8f741a607e 100644 --- a/libraries/liblutil/uuid.c +++ b/libraries/liblutil/uuid.c @@ -182,6 +182,7 @@ lutil_uuidstr( char *buf, size_t len ) uuid_t uu = {0}; unsigned rc; char *s; + size_t l; uuid_create( &uu, &rc ); if ( rc != uuid_s_ok ) { @@ -192,15 +193,17 @@ lutil_uuidstr( char *buf, size_t len ) if ( rc != uuid_s_ok ) { return 0; } - if ( strlen( s ) >= len ) { + + l = strlen( s ); + if ( l >= len ) { free( s ); return 0; } - strncpy( buf, s, len ); + strncpy( buf, s, l ); free( s ); - return 1; + return l; #else struct timeval tv; @@ -243,7 +246,7 @@ lutil_uuidstr( char *buf, size_t len ) (unsigned) nl[2], (unsigned) nl[3], (unsigned) nl[4], (unsigned) nl[5] ); - return (t1 < len) ? 1 : 0; + return (t1 < len) ? t1 : 0; #endif } diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index c8a616d5e7..4bc3b0c41e 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -549,9 +549,10 @@ int slap_mods_opattrs( Modifications **modtail, const char **text ) { - struct berval name, timestamp; + struct berval name, timestamp, csn; time_t now = slap_get_time(); char timebuf[22]; + char csnbuf[128]; struct tm *ltm; Modifications *mod; @@ -564,7 +565,11 @@ int slap_mods_opattrs( ldap_pvt_thread_mutex_lock( &gmtime_mutex ); ltm = gmtime( &now ); strftime( timebuf, sizeof(timebuf), "%Y%m%d%H%M%SZ", ltm ); + + csn.bv_len = lutil_csnstr( csnbuf, sizeof( csnbuf ), 0, 0 ); ldap_pvt_thread_mutex_unlock( &gmtime_mutex ); + csn.bv_val = csnbuf; + timestamp.bv_val = timebuf; timestamp.bv_len = strlen(timebuf); @@ -577,6 +582,22 @@ int slap_mods_opattrs( } if( op->o_tag == LDAP_REQ_ADD ) { + struct berval uuid; + char uuidbuf[64]; + + uuid.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) ); + uuid.bv_val = uuidbuf; + + mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ) ); + mod->sml_op = mop; + mod->sml_desc = slap_schema.si_ad_entryUUID; + mod->sml_bvalues = (struct berval **) malloc( 2 * sizeof( struct berval * ) ); + mod->sml_bvalues[0] = ber_bvdup( &uuid ); + mod->sml_bvalues[1] = NULL; + assert( mod->sml_bvalues[0] ); + *modtail = mod; + modtail = &mod->sml_next; + mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ) ); mod->sml_op = mop; mod->sml_desc = slap_schema.si_ad_creatorsName; @@ -598,10 +619,20 @@ int slap_mods_opattrs( modtail = &mod->sml_next; } + mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ) ); + mod->sml_op = mop; + mod->sml_desc = slap_schema.si_ad_entryCSN; + mod->sml_bvalues = (struct berval **) malloc( 2 * sizeof(struct berval *) ); + mod->sml_bvalues[0] = ber_bvdup( &csn ); + mod->sml_bvalues[1] = NULL; + assert( mod->sml_bvalues[0] ); + *modtail = mod; + modtail = &mod->sml_next; + mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ) ); mod->sml_op = mop; mod->sml_desc = slap_schema.si_ad_modifiersName; - mod->sml_bvalues = (struct berval **) malloc( 2 * sizeof( struct berval * ) ); + mod->sml_bvalues = (struct berval **) malloc( 2 * sizeof(struct berval *) ); mod->sml_bvalues[0] = ber_bvdup( &name ); mod->sml_bvalues[1] = NULL; assert( mod->sml_bvalues[0] ); @@ -611,7 +642,7 @@ int slap_mods_opattrs( mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ) ); mod->sml_op = mop; mod->sml_desc = slap_schema.si_ad_modifyTimestamp; - mod->sml_bvalues = (struct berval **) malloc( 2 * sizeof( struct berval * ) ); + mod->sml_bvalues = (struct berval **) malloc( 2 * sizeof(struct berval *) ); mod->sml_bvalues[0] = ber_bvdup( ×tamp ); mod->sml_bvalues[1] = NULL; assert( mod->sml_bvalues[0] ); diff --git a/servers/slapd/schema/core.schema b/servers/slapd/schema/core.schema index f7a577a47b..c93fb23dbb 100644 --- a/servers/slapd/schema/core.schema +++ b/servers/slapd/schema/core.schema @@ -763,6 +763,22 @@ objectclass ( 1.3.6.1.4.1.4203.1.4.7 MAY authPassword AUXILIARY ) +# +# LDUP/LCUP attributes +# Experimental! +# +attributetype ( 1.3.6.1.4.1.4203.666.1.6 NAME 'entryUUID' + DESC 'LCUP/LDUP: universally unique identifier' + EQUALITY octetStringMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64} + SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation ) + +attributetype ( 1.3.6.1.4.1.4203.666.1.7 NAME 'entryCSN' + DESC 'LCUP/LDUP: change sequence number' + EQUALITY octetStringMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64} + SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation ) + # # OpenLDAP specific schema items # diff --git a/servers/slapd/schema_prep.c b/servers/slapd/schema_prep.c index e34914c15b..f713d5e18e 100644 --- a/servers/slapd/schema_prep.c +++ b/servers/slapd/schema_prep.c @@ -153,6 +153,10 @@ struct slap_schema_ad_map { offsetof(struct slap_internal_schema, si_ad_structuralObjectClass) }, /* user entry operational attributes */ + { "entryUUID", NULL, NULL, NULL, + offsetof(struct slap_internal_schema, si_ad_entryUUID) }, + { "entryCSN", NULL, NULL, NULL, + offsetof(struct slap_internal_schema, si_ad_entryCSN) }, { "creatorsName", NULL, NULL, NULL, offsetof(struct slap_internal_schema, si_ad_creatorsName) }, { "createTimestamp", NULL, NULL, NULL, diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 27098ebe1f..8994f3be6a 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -473,6 +473,8 @@ struct slap_internal_schema { /* operational attribute descriptions */ AttributeDescription *si_ad_structuralObjectClass; + AttributeDescription *si_ad_entryUUID; + AttributeDescription *si_ad_entryCSN; AttributeDescription *si_ad_creatorsName; AttributeDescription *si_ad_createTimestamp; AttributeDescription *si_ad_modifiersName; @@ -544,7 +546,6 @@ typedef struct slap_mr_assertion { struct berval *ma_value; /* required */ } MatchingRuleAssertion; - /* * represents a search filter */ @@ -554,7 +555,6 @@ typedef struct slap_filter { #define SLAPD_FILTER_DN_ONE ((ber_tag_t) -2) #define SLAPD_FILTER_DN_SUBTREE ((ber_tag_t) -3) - union f_un_u { /* precomputed result */ ber_int_t f_un_result; -- 2.39.5