e.g. ldapi:// (and eventually IPSEC). It is not normally used.
.TP
.B serverID <integer> [<URL>]
-Specify an integer ID from 0 to 4095 for this server. These IDs are
+Specify an integer ID from 0 to 4095 for this server (limited
+to 3 hexadecimal digits).
+These IDs are
required when using multimaster replication and each master must have a
unique ID. If the URL is provided, this directive may be specified
multiple times, providing a complete list of participating servers
identifies the current
.B syncrepl
directive within the replication consumer site.
-It is a non-negative integer having no more than three digits.
+It is a non-negative integer not greater than 4095 (limited
+to three hexadecimal digits).
.B provider
specifies the replication provider site containing the master content
struct berval bv;
for ( si = sid_list; si; si=si->si_next ) {
+ assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
if ( !BER_BVISEMPTY( &si->si_url )) {
bv.bv_len = si->si_url.bv_len + 6;
bv.bv_val = ch_malloc( bv.bv_len );
{
ServerID *si, **sip;
LDAPURLDesc *lud;
- int num = atoi( c->argv[1] );
- if ( num < 0 || num > SLAP_SYNC_SID_MAX ) {
+ int num;
+ if ( lutil_atoi( &num, c->argv[1] ) ||
+ num < 0 || num > SLAP_SYNC_SID_MAX )
+ {
snprintf( c->cr_msg, sizeof( c->cr_msg ),
"<%s> illegal server ID", c->argv[0] );
Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
}
int
-slap_parse_csn_sid( struct berval *csn )
+slap_parse_csn_sid( struct berval *csnp )
{
char *p, *q;
+ struct berval csn = *csnp;
int i;
- p = memchr( csn->bv_val, '#', csn->bv_len );
- if ( p )
- p = strchr( p+1, '#' );
+ p = ber_bvchr( &csn, '#' );
if ( !p )
return -1;
p++;
- i = strtoul( p, &q, 10 );
- if ( p == q || i > SLAP_SYNC_SID_MAX )
+ csn.bv_len -= p - csn.bv_val;
+ csn.bv_val = p;
+
+ p = ber_bvchr( &csn, '#' );
+ if ( !p )
+ return -1;
+ p++;
+ csn.bv_len -= p - csn.bv_val;
+ csn.bv_val = p;
+
+ q = ber_bvchr( &csn, '#' );
+ if ( !q )
+ return -1;
+
+ csn.bv_len = q - p;
+
+ i = (int)strtoul( p, &q, 16 );
+ if ( p == q || q != p + csn.bv_len || i > SLAP_SYNC_SID_MAX ) {
i = -1;
+ }
+
return i;
}
struct berval csn;
struct berval maxcsn[ SLAP_SYNC_SID_MAX + 1 ];
- MatchingRule *mr_csnsid;
unsigned long sid;
struct berval bvtext;
Attribute *attr;
}
if ( update_ctxcsn ) {
- mr_csnsid = mr_find( "CSNSIDMatch" );
- assert( mr_csnsid != NULL );
maxcsn[ 0 ].bv_val = maxcsnbuf;
for ( sid = 1; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
maxcsn[ sid ].bv_val = maxcsn[ sid - 1 ].bv_val + LDAP_LUTIL_CSNSTR_BUFSIZE;
}
if ( update_ctxcsn ) {
- struct berval nsid;
+ int rc_sid;
attr = attr_find( e->e_attrs, slap_schema.si_ad_entryCSN );
assert( attr != NULL );
-
- rc = mr_csnsid->smr_normalize( SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
- NULL, NULL, &attr->a_nvals[ 0 ], &nsid, NULL );
- assert( rc == LDAP_SUCCESS );
- rc = lutil_atoulx( &sid, nsid.bv_val, 16 );
- ber_memfree( nsid.bv_val );
- if ( rc ) {
+
+ rc_sid = slap_parse_csn_sid( &attr->a_nvals[ 0 ] );
+ if ( rc_sid < 0 ) {
Debug( LDAP_DEBUG_ANY, "%s: could not "
"extract SID from entryCSN=%s\n",
progname, attr->a_nvals[ 0 ].bv_val, 0 );
} else {
- assert( sid <= SLAP_SYNC_SID_MAX );
+ assert( rc_sid <= SLAP_SYNC_SID_MAX );
+ sid = (unsigned)rc_sid;
if ( maxcsn[ sid ].bv_len != 0 ) {
match = 0;
value_match( &match, slap_schema.si_ad_entryCSN,
int i;
for ( i = 0; !BER_BVISNULL( &attr->a_vals[ i ] ); i++ ) {
- struct berval nsid;
-
- rc = mr_csnsid->smr_normalize( SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
- NULL, NULL, &attr->a_nvals[ i ], &nsid, NULL );
-
- /* must succeed, since it passed
- * validation/normalization */
- assert( rc == LDAP_SUCCESS );
+ int rc_sid;
- rc = lutil_atoulx( &sid, nsid.bv_val, 16 );
- ber_memfree( nsid.bv_val );
-
- if ( rc ) {
+ rc_sid = slap_parse_csn_sid( &attr->a_nvals[ i ] );
+ if ( rc_sid < 0 ) {
Debug( LDAP_DEBUG_ANY,
"%s: unable to extract SID "
"from #%d contextCSN=%s\n",
continue;
}
+ assert( rc_sid <= SLAP_SYNC_SID_MAX );
+
+ sid = (unsigned)rc_sid;
+
if ( maxcsn[ sid ].bv_len == 0 ) {
match = -1;
BackendDB *si_wbe;
struct re_s *si_re;
int si_rid;
- char si_ridtxt[8];
+ char si_ridtxt[ STRLENOF("rid=4095") + 1 ];
slap_bindconf si_bindconf;
struct berval si_base;
struct berval si_logbase;
Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
return -1;
}
- if ( tmp >= 1000 || tmp < 0 ) {
+ if ( tmp > SLAP_SYNC_SID_MAX || tmp < 0 ) {
snprintf( c->cr_msg, sizeof( c->cr_msg ),
"Error: parse_syncrepl_line: "
- "syncrepl id %d is out of range [0..999]", tmp );
+ "syncrepl id %d is out of range [0..4095]", tmp );
Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
return -1;
}
si->si_rid = tmp;
- sprintf( si->si_ridtxt, IDSTR "=%03d", si->si_rid );
+ sprintf( si->si_ridtxt, IDSTR "=%d", si->si_rid );
gots |= GOT_ID;
} else if ( !strncasecmp( c->argv[ i ], PROVIDERSTR "=",
STRLENOF( PROVIDERSTR "=" ) ) )
si->si_bindconf.sb_version = LDAP_VERSION3;
ptr = buf;
- ptr += snprintf( ptr, WHATSLEFT, IDSTR "=%03d " PROVIDERSTR "=%s",
+ assert( si->si_rid >= 0 && si->si_rid <= SLAP_SYNC_SID_MAX );
+ ptr += snprintf( ptr, WHATSLEFT, IDSTR "=%d " PROVIDERSTR "=%s",
si->si_rid, si->si_bindconf.sb_uri.bv_val );
if ( ptr - buf >= sizeof( buf ) ) return;
if ( !BER_BVISNULL( &bc ) ) {