LDAPControl **ctrls,
int num_ctrls,
int send_cookie,
- struct berval *csn)
+ struct berval *cookie)
{
Attribute* a;
int ret;
}
}
- if ( send_cookie && csn ) {
+ if ( send_cookie && cookie ) {
ber_printf( ber, "{eOON}",
- entry_sync_state, &entryuuid_bv, csn );
+ entry_sync_state, &entryuuid_bv, cookie );
} else {
ber_printf( ber, "{eON}",
entry_sync_state, &entryuuid_bv );
Operation *op,
SlapReply *rs,
LDAPControl **ctrls,
- int num_ctrls,
- int send_cookie,
- struct berval *csn )
+ int num_ctrls,
+ int send_cookie,
+ struct berval *cookie,
+ int refreshDeletes )
{
int ret;
BerElementBuffer berbuf;
ctrls[num_ctrls] = ch_malloc ( sizeof ( LDAPControl ) );
- if ( send_cookie && csn ) {
- ber_printf( ber, "{ON}", csn );
- } else {
- ber_printf( ber, "{N}" );
+ ber_printf( ber, "{" );
+ if ( send_cookie && cookie ) {
+ ber_printf( ber, "O", cookie );
+ }
+ if ( refreshDeletes == LDAP_SYNC_REFRESH_DELETES ) {
+ ber_printf( ber, "b", refreshDeletes );
}
+ ber_printf( ber, "N}" );
ctrls[num_ctrls]->ldctl_oid = LDAP_CONTROL_SYNC_DONE;
ctrls[num_ctrls]->ldctl_iscritical = op->o_sync;
LDAPControl **ctrls,
int num_ctrls,
int send_cookie,
- struct berval *csn)
+ struct berval *cookie)
{
Attribute* a;
int ret;
ber_dupbv( &entryuuid_bv, &slog_e->sl_uuid );
- if ( send_cookie && csn ) {
+ if ( send_cookie && cookie ) {
ber_printf( ber, "{eOON}",
- entry_sync_state, &entryuuid_bv, csn );
+ entry_sync_state, &entryuuid_bv, cookie );
} else {
ber_printf( ber, "{eON}",
entry_sync_state, &entryuuid_bv );
return LDAP_SUCCESS;
}
+int
+slap_send_syncinfo(
+ Operation *op,
+ SlapReply *rs,
+ int type,
+ struct berval *cookie,
+ int refreshDone,
+ BerVarray syncUUIDs,
+ int refreshDeletes )
+{
+ BerElementBuffer berbuf;
+ BerElement *ber = (BerElement *)&berbuf;
+ struct berval rspdata;
+
+ int ret;
+
+ ber_init2( ber, NULL, LBER_USE_DER );
+
+ if ( type ) {
+ switch ( type ) {
+ case LDAP_TAG_SYNC_NEW_COOKIE:
+ ber_printf( ber, "tO", type, cookie );
+ break;
+ case LDAP_TAG_SYNC_REFRESH_DELETE:
+ case LDAP_TAG_SYNC_REFRESH_PRESENT:
+ ber_printf( ber, "t{", type );
+ if ( cookie ) {
+ ber_printf( ber, "O", cookie );
+ }
+ if ( refreshDone == 0 ) {
+ ber_printf( ber, "b", refreshDone );
+ }
+ ber_printf( ber, "N}" );
+ break;
+ case LDAP_TAG_SYNC_ID_SET:
+ ber_printf( ber, "t{", type );
+ if ( cookie ) {
+ ber_printf( ber, "O", cookie );
+ }
+ if ( refreshDeletes == 1 ) {
+ ber_printf( ber, "b", refreshDeletes );
+ }
+ ber_printf( ber, "[W]", syncUUIDs );
+ ber_printf( ber, "N}" );
+ break;
+ default:
+#ifdef NEW_LOGGING
+ LDAP_LOG ( OPERATION, RESULTS,
+ "slap_send_syncinfo: invalid syncinfo type (%d)\n",
+ type, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "slap_send_syncinfo: invalid syncinfo type (%d)\n",
+ type, 0, 0 );
+#endif
+ return LDAP_OTHER;
+ }
+ }
+
+ ret = ber_flatten2( ber, &rspdata, 0 );
+
+ if ( ret < 0 ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG ( OPERATION, RESULTS,
+ "slap_send_syncinfo: ber_flatten2 failed\n",
+ 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "slap_send_syncinfo: ber_flatten2 failed\n",
+ 0, 0, 0 );
+#endif
+ send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
+ return ret;
+ }
+
+ rs->sr_rspdata = &rspdata;
+ send_ldap_intermediate( op, rs );
+ rs->sr_rspdata = NULL;
+ ber_free_buf( ber );
+
+ return LDAP_SUCCESS;
+}
+
void
slap_compose_sync_cookie(
Operation *op,
{
char *csn_ptr;
char *csn_str;
+ int csn_str_len;
char *sid_ptr;
char *sid_str;
char *cval;
return -1;
if (( csn_ptr = strstr( cookie->octet_str[0].bv_val, "csn=" )) != NULL ) {
- csn_str = (char *) strndup( csn_ptr, LDAP_LUTIL_CSNSTR_BUFSIZE );
+ csn_str = (char *) SLAP_STRNDUP( csn_ptr, LDAP_LUTIL_CSNSTR_BUFSIZE );
if ( cval = strchr( csn_str, ',' )) {
*cval = '\0';
+ csn_str_len = cval - csn_str - (sizeof("csn=") - 1);
+ } else {
+ csn_str_len = cookie->octet_str[0].bv_len -
+ (csn_ptr - cookie->octet_str[0].bv_val) -
+ (sizeof("csn=") - 1);
}
- ctxcsn = ber_str2bv( csn_str + 4, strlen(csn_str) - 4, 1, NULL );
+ ctxcsn = ber_str2bv( csn_str + (sizeof("csn=")-1),
+ csn_str_len, 1, NULL );
ch_free( csn_str );
ber_bvarray_add( &cookie->ctxcsn, ctxcsn );
ch_free( ctxcsn );
}
if (( sid_ptr = strstr( cookie->octet_str->bv_val, "sid=" )) != NULL ) {
- sid_str = (char *) strndup( sid_ptr, 7 );
+ sid_str = (char *) SLAP_STRNDUP( sid_ptr,
+ SLAP_SYNC_SID_SIZE + sizeof("sid=") - 1 );
if ( cval = strchr( sid_str, ',' )) {
*cval = '\0';
}
- cookie->sid = atoi( sid_str+4 );
+ cookie->sid = atoi( sid_str + sizeof("sid=") - 1 );
ch_free( sid_str );
} else {
cookie->sid = -1;
return -1;
octet_str.bv_len = snprintf( csnbuf, LDAP_LUTIL_CSNSTR_BUFSIZE + 4,
- "csn=%4d%02d%02d%02d:%02d:%02dZ#0x%04x#%d#%04x",
+ "csn=%4d%02d%02d%02d%02d%02dZ#%06x#%02x#%06x",
1900, 1, 1, 0, 0, 0, 0, 0, 0 );
octet_str.bv_val = csnbuf;
build_new_dn( &slap_syncCookie, &cookie->octet_str[0], &octet_str, NULL );