From 5ea77a75dd2d2158401331879f3c8f47940a732c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 18:35:32 +0200 Subject: Adding upstream version 2.5.13+dfsg. Signed-off-by: Daniel Baumann --- servers/slapd/ldapsync.c | 525 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 525 insertions(+) create mode 100644 servers/slapd/ldapsync.c (limited to 'servers/slapd/ldapsync.c') diff --git a/servers/slapd/ldapsync.c b/servers/slapd/ldapsync.c new file mode 100644 index 0000000..f922cd5 --- /dev/null +++ b/servers/slapd/ldapsync.c @@ -0,0 +1,525 @@ +/* ldapsync.c -- LDAP Content Sync Routines */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 2003-2022 The OpenLDAP Foundation. + * Portions Copyright 2003 IBM Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ + +#include "portable.h" + +#include + +#include +#include + +#include "lutil.h" +#include "slap.h" +#include "../../libraries/liblber/lber-int.h" /* get ber_strndup() */ +#include "lutil_ldap.h" + +struct slap_sync_cookie_s slap_sync_cookie = + LDAP_STAILQ_HEAD_INITIALIZER( slap_sync_cookie ); + +void +slap_compose_sync_cookie( + Operation *op, + struct berval *cookie, + BerVarray csn, + int rid, + int sid, + struct berval *delcsn ) +{ + int len, numcsn = 0; + + if ( csn ) { + for (; !BER_BVISNULL( &csn[numcsn] ); numcsn++); + } + + if ( numcsn == 0 || rid == -1 ) { + char cookiestr[ LDAP_PVT_CSNSTR_BUFSIZE + 20 ]; + if ( rid == -1 ) { + cookiestr[0] = '\0'; + len = 0; + } else { + len = snprintf( cookiestr, sizeof( cookiestr ), + "rid=%03d", rid ); + if ( sid >= 0 ) { + len += sprintf( cookiestr+len, ",sid=%03x", sid ); + } + } + ber_str2bv_x( cookiestr, len, 1, cookie, + op ? op->o_tmpmemctx : NULL ); + } else { + char *ptr; + int i; + + len = 0; + for ( i=0; ibv_len; + + len += STRLENOF("rid=123,csn="); + if ( sid >= 0 ) + len += STRLENOF("sid=xxx,"); + + cookie->bv_val = slap_sl_malloc( len, op ? op->o_tmpmemctx : NULL ); + + len = sprintf( cookie->bv_val, "rid=%03d,", rid ); + ptr = cookie->bv_val + len; + if ( sid >= 0 ) { + ptr += sprintf( ptr, "sid=%03x,", sid ); + } + ptr = lutil_strcopy( ptr, "csn=" ); + for ( i=0; ioctet_str.bv_val ); + ber_dupbv( &cookie->octet_str, &octet_str ); + + ctxcsn.bv_val = octet_str.bv_val + 4; + ctxcsn.bv_len = octet_str.bv_len - 4; + cookie->ctxcsn = NULL; + value_add_one( &cookie->ctxcsn, &ctxcsn ); + cookie->numcsns = 1; + cookie->sid = -1; + BER_BVZERO( &cookie->delcsn ); + + return 0; +} + +struct sync_cookie * +slap_dup_sync_cookie( + struct sync_cookie *dst, + struct sync_cookie *src +) +{ + struct sync_cookie *new; + int i; + + if ( src == NULL ) + return NULL; + + if ( dst ) { + ber_bvarray_free( dst->ctxcsn ); + dst->ctxcsn = NULL; + dst->sids = NULL; + ch_free( dst->octet_str.bv_val ); + BER_BVZERO( &dst->octet_str ); + new = dst; + } else { + new = ( struct sync_cookie * ) + ch_calloc( 1, sizeof( struct sync_cookie )); + } + + new->rid = src->rid; + new->sid = src->sid; + new->numcsns = src->numcsns; + + if ( src->numcsns ) { + if ( ber_bvarray_dup_x( &new->ctxcsn, src->ctxcsn, NULL )) { + if ( !dst ) { + ch_free( new ); + } + return NULL; + } + new->sids = ch_malloc( src->numcsns * sizeof(int) ); + for (i=0; inumcsns; i++) + new->sids[i] = src->sids[i]; + } + + if ( !BER_BVISNULL( &src->delcsn )) { + ber_dupbv( &new->delcsn, &src->delcsn ); + } + + if ( !BER_BVISNULL( &src->octet_str )) { + ber_dupbv( &new->octet_str, &src->octet_str ); + } + + return new; +} + -- cgit v1.2.3