Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
openldap
OpenLDAP
Commits
fffaea79
Commit
fffaea79
authored
Feb 05, 2007
by
Howard Chu
Browse files
Preliminary multi-context support for syncrepl. Passes all single-master
tests, needs multi-master testing.
parent
e0ed944b
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
servers/slapd/bconfig.c
View file @
fffaea79
...
...
@@ -555,7 +555,7 @@ static ConfigTable config_back_cf_table[] = {
"SYNTAX OMsDN )"
,
NULL
,
NULL
},
{
"syncrepl"
,
NULL
,
0
,
0
,
0
,
ARG_DB
|
ARG_MAGIC
,
&
syncrepl_config
,
"( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
"SYNTAX OMsDirectoryString
SINGLE-
VALUE )"
,
NULL
,
NULL
},
"SYNTAX OMsDirectoryString
X-ORDERED '
VALUE
S'
)"
,
NULL
,
NULL
},
{
"threads"
,
"count"
,
2
,
2
,
0
,
#ifdef NO_THREADS
ARG_IGNORED
,
NULL
,
...
...
@@ -760,8 +760,6 @@ typedef struct ServerID {
int
si_num
;
}
ServerID
;
#define SERVERID_MAX 4095
static
ServerID
*
sid_list
;
static
int
...
...
@@ -1574,7 +1572,7 @@ config_generic(ConfigArgs *c) {
ServerID
*
si
,
**
sip
;
LDAPURLDesc
*
lud
;
int
num
=
atoi
(
c
->
argv
[
1
]
);
if
(
num
<
0
||
num
>
S
ERVER
ID_MAX
)
{
if
(
num
<
0
||
num
>
S
LAP_SYNC_S
ID_MAX
)
{
snprintf
(
c
->
msg
,
sizeof
(
c
->
msg
),
"<%s> illegal server ID"
,
c
->
argv
[
0
]
);
Debug
(
LDAP_DEBUG_ANY
,
"%s: %s %s
\n
"
,
...
...
@@ -1636,7 +1634,7 @@ config_generic(ConfigArgs *c) {
for
(
i
=
0
;
l
[
i
];
i
++
)
{
LDAPURLDesc
*
lu2
;
int
isMe
=
0
;
ldap_url_parse
(
&
l
[
i
]
->
sl_url
,
&
lu2
);
ldap_url_parse
(
l
[
i
]
->
sl_url
.
bv_val
,
&
lu2
);
do
{
if
(
strcasecmp
(
lud
->
lud_scheme
,
lu2
->
lud_scheme
))
...
...
servers/slapd/ldapsync.c
View file @
fffaea79
...
...
@@ -34,34 +34,47 @@ void
slap_compose_sync_cookie
(
Operation
*
op
,
struct
berval
*
cookie
,
struct
berval
*
csn
,
BerVarray
csn
,
int
rid
)
{
char
cookiestr
[
LDAP_LUTIL_CSNSTR_BUFSIZE
+
20
];
int
len
;
int
len
,
numcsn
=
0
;
if
(
BER_BVISNULL
(
csn
))
{
if
(
csn
)
{
for
(;
!
BER_BVISEMPTY
(
&
csn
[
numcsn
]
);
numcsn
++
);
}
if
(
numcsn
==
0
||
rid
==
-
1
)
{
char
cookiestr
[
LDAP_LUTIL_CSNSTR_BUFSIZE
+
20
];
if
(
rid
==
-
1
)
{
cookiestr
[
0
]
=
'\0'
;
len
=
0
;
}
else
{
len
=
snprintf
(
cookiestr
,
LDAP_LUTIL_CSNSTR_BUFSIZE
+
20
,
len
=
snprintf
(
cookiestr
,
sizeof
(
cookiestr
)
,
"rid=%03d"
,
rid
);
}
ber_str2bv_x
(
cookiestr
,
len
,
1
,
cookie
,
op
?
op
->
o_tmpmemctx
:
NULL
);
}
else
{
char
*
end
=
cookiestr
+
sizeof
(
cookiestr
);
char
*
ptr
=
lutil_strcopy
(
cookiestr
,
"csn="
);
len
=
csn
->
bv_len
;
if
(
ptr
+
len
>=
end
)
len
=
end
-
ptr
;
ptr
=
lutil_strncopy
(
ptr
,
csn
->
bv_val
,
len
);
if
(
rid
!=
-
1
&&
ptr
<
end
-
STRLENOF
(
",rid=xxx"
)
)
{
ptr
+=
sprintf
(
ptr
,
",rid=%03d"
,
rid
);
char
*
ptr
;
int
i
;
len
=
0
;
for
(
i
=
0
;
i
<
numcsn
;
i
++
)
len
+=
csn
[
i
].
bv_len
+
1
;
len
+=
STRLENOF
(
"rid=123,csn="
);
cookie
->
bv_val
=
slap_sl_malloc
(
len
,
op
?
op
->
o_tmpmemctx
:
NULL
);
len
=
sprintf
(
cookie
->
bv_val
,
"rid=%03d,csn="
,
rid
);
ptr
=
cookie
->
bv_val
+
len
;
for
(
i
=
0
;
i
<
numcsn
;
i
++
)
{
ptr
=
lutil_strncopy
(
ptr
,
csn
->
bv_val
,
csn
->
bv_len
);
*
ptr
++
=
';'
;
}
len
=
ptr
-
cookiestr
;
ptr
--
;
*
ptr
=
'\0'
;
cookie
->
bv_len
=
ptr
-
cookie
->
bv_val
;
}
ber_str2bv_x
(
cookiestr
,
len
,
1
,
cookie
,
op
?
op
->
o_tmpmemctx
:
NULL
);
}
void
...
...
@@ -73,11 +86,16 @@ slap_sync_cookie_free(
if
(
cookie
==
NULL
)
return
;
if
(
!
BER_BVISNULL
(
&
cookie
->
ctxcsn
)
)
{
ch_free
(
cookie
->
ctxcsn
.
bv_val
);
BER_BVZERO
(
&
cookie
->
ctxcsn
)
;
if
(
cookie
->
sids
)
{
ch_free
(
cookie
->
sids
);
cookie
->
sids
=
NULL
;
}
if
(
cookie
->
ctxcsn
)
{
ber_bvarray_free
(
cookie
->
ctxcsn
);
cookie
->
ctxcsn
=
NULL
;
}
cookie
->
numcsns
=
0
;
if
(
!
BER_BVISNULL
(
&
cookie
->
octet_str
))
{
ch_free
(
cookie
->
octet_str
.
bv_val
);
BER_BVZERO
(
&
cookie
->
octet_str
);
...
...
@@ -90,6 +108,37 @@ slap_sync_cookie_free(
return
;
}
int
slap_parse_csn_sid
(
struct
berval
*
csn
)
{
char
*
p
,
*
q
;
int
i
;
p
=
memchr
(
csn
->
bv_val
,
'#'
,
csn
->
bv_len
);
if
(
p
)
p
=
strchr
(
p
+
1
,
'#'
);
if
(
!
p
)
return
-
1
;
p
++
;
i
=
strtoul
(
p
,
&
q
,
10
);
if
(
p
==
q
||
i
>
SLAP_SYNC_SID_MAX
)
i
=
-
1
;
return
i
;
}
int
*
slap_parse_csn_sids
(
BerVarray
csns
,
int
numcsns
)
{
int
i
,
*
ret
;
char
*
p
,
*
q
;
ret
=
ch_malloc
(
numcsns
*
sizeof
(
int
)
);
for
(
i
=
0
;
i
<
numcsns
;
i
++
)
{
ret
[
i
]
=
slap_parse_csn_sid
(
&
csns
[
i
]
);
}
return
ret
;
}
int
slap_parse_sync_cookie
(
struct
sync_cookie
*
cookie
,
...
...
@@ -99,10 +148,10 @@ slap_parse_sync_cookie(
char
*
csn_ptr
;
char
*
csn_str
;
int
csn_str_len
;
int
valid
=
0
;
char
*
rid_ptr
;
char
*
cval
;
char
*
next
;
char
*
next
,
*
end
;
AttributeDescription
*
ad
=
slap_schema
.
si_ad_modifyTimestamp
;
if
(
cookie
==
NULL
)
return
-
1
;
...
...
@@ -111,60 +160,76 @@ slap_parse_sync_cookie(
return
-
1
;
cookie
->
rid
=
-
1
;
/* FIXME: may read past end of cookie->octet_str.bv_val */
rid_ptr
=
strstr
(
cookie
->
octet_str
.
bv_val
,
"rid="
);
if
(
rid_ptr
==
NULL
||
rid_ptr
>
&
cookie
->
octet_str
.
bv_val
[
cookie
->
octet_str
.
bv_len
-
STRLENOF
(
"rid="
)
]
)
{
return
-
1
;
}
if
(
rid_ptr
[
STRLENOF
(
"rid="
)
]
==
'-'
)
{
return
-
1
;
}
cookie
->
rid
=
strtoul
(
&
rid_ptr
[
STRLENOF
(
"rid="
)
],
&
next
,
10
);
if
(
next
==
&
rid_ptr
[
STRLENOF
(
"rid="
)
]
||
(
next
[
0
]
!=
','
&&
next
[
0
]
!=
'\0'
)
)
{
return
-
1
;
}
while
((
csn_ptr
=
strstr
(
cookie
->
octet_str
.
bv_val
,
"csn="
))
!=
NULL
)
{
AttributeDescription
*
ad
=
slap_schema
.
si_ad_modifyTimestamp
;
slap_syntax_validate_func
*
validate
;
struct
berval
stamp
;
/* This only happens when called from main */
if
(
ad
==
NULL
)
break
;
if
(
csn_ptr
>=
&
cookie
->
octet_str
.
bv_val
[
cookie
->
octet_str
.
bv_len
-
STRLENOF
(
"csn="
)
]
)
{
return
-
1
;
cookie
->
ctxcsn
=
NULL
;
cookie
->
sids
=
NULL
;
cookie
->
numcsns
=
0
;
end
=
cookie
->
octet_str
.
bv_val
+
cookie
->
octet_str
.
bv_len
;
for
(
next
=
cookie
->
octet_str
.
bv_val
;
next
<
end
;
)
{
if
(
!
strncmp
(
next
,
"rid="
,
STRLENOF
(
"rid="
)
))
{
rid_ptr
=
next
;
cookie
->
rid
=
strtoul
(
&
rid_ptr
[
STRLENOF
(
"rid="
)
],
&
next
,
10
);
if
(
next
==
rid_ptr
||
next
>
end
||
*
next
!=
','
)
{
return
-
1
;
}
if
(
*
next
==
','
)
{
next
++
;
}
if
(
!
ad
)
{
break
;
}
continue
;
}
csn_str
=
csn_ptr
+
STRLENOF
(
"csn="
);
cval
=
strchr
(
csn_str
,
','
);
if
(
cval
&&
cval
<
&
cookie
->
octet_str
.
bv_val
[
cookie
->
octet_str
.
bv_len
]
)
csn_str_len
=
cval
-
csn_str
;
else
csn_str_len
=
0
;
/* FIXME use csnValidate when it gets implemented */
csn_ptr
=
strchr
(
csn_str
,
'#'
);
if
(
!
csn_ptr
||
csn_str
>=
&
cookie
->
octet_str
.
bv_val
[
cookie
->
octet_str
.
bv_len
]
)
break
;
stamp
.
bv_val
=
csn_str
;
stamp
.
bv_len
=
csn_ptr
-
csn_str
;
validate
=
ad
->
ad_type
->
sat_syntax
->
ssyn_validate
;
if
(
validate
(
ad
->
ad_type
->
sat_syntax
,
&
stamp
)
!=
LDAP_SUCCESS
)
break
;
valid
=
1
;
break
;
if
(
!
strncmp
(
next
,
"csn="
,
STRLENOF
(
"csn="
)
))
{
slap_syntax_validate_func
*
validate
;
struct
berval
stamp
;
csn_str
=
next
+
STRLENOF
(
"csn="
);
while
(
next
<
end
)
{
/* FIXME use csnValidate when it gets implemented */
csn_ptr
=
strchr
(
csn_str
,
'#'
);
if
(
!
csn_ptr
||
csn_ptr
>
end
)
break
;
/* ad will be NULL when called from main. we just
* want to parse the rid then. But we still iterate
* through the string to find the end.
*/
if
(
ad
)
{
stamp
.
bv_val
=
csn_str
;
stamp
.
bv_len
=
csn_ptr
-
csn_str
;
validate
=
ad
->
ad_type
->
sat_syntax
->
ssyn_validate
;
if
(
validate
(
ad
->
ad_type
->
sat_syntax
,
&
stamp
)
!=
LDAP_SUCCESS
)
break
;
}
cval
=
strchr
(
csn_ptr
,
';'
);
if
(
!
cval
)
cval
=
strchr
(
csn_ptr
,
','
);
if
(
cval
)
stamp
.
bv_len
=
cval
-
csn_str
;
else
stamp
.
bv_len
=
end
-
csn_str
;
if
(
ad
)
{
value_add_one
(
&
cookie
->
ctxcsn
,
&
stamp
);
cookie
->
numcsns
++
;
}
if
(
cval
)
{
next
=
cval
+
1
;
if
(
*
cval
!=
';'
)
break
;
}
else
{
next
=
end
;
break
;
}
}
continue
;
}
next
++
;
}
if
(
valid
)
{
ber_str2bv_x
(
csn_str
,
csn_str_len
,
1
,
&
cookie
->
ctxcsn
,
memctx
);
}
else
{
BER_BVZERO
(
&
cookie
->
ctxcsn
);
if
(
cookie
->
numcsns
)
{
cookie
->
sids
=
slap_parse_csn_sids
(
cookie
->
ctxcsn
,
cookie
->
numcsns
);
}
return
0
;
}
...
...
@@ -189,7 +254,9 @@ slap_init_sync_cookie_ctxcsn(
ctxcsn
.
bv_val
=
octet_str
.
bv_val
+
4
;
ctxcsn
.
bv_len
=
octet_str
.
bv_len
-
4
;
ber_dupbv
(
&
cookie
->
ctxcsn
,
&
ctxcsn
);
cookie
->
ctxcsn
=
NULL
;
value_add_one
(
&
cookie
->
ctxcsn
,
&
ctxcsn
);
cookie
->
numcsns
=
1
;
return
0
;
}
...
...
@@ -201,14 +268,16 @@ slap_dup_sync_cookie(
)
{
struct
sync_cookie
*
new
;
int
i
;
if
(
src
==
NULL
)
return
NULL
;
if
(
dst
)
{
ch_free
(
dst
->
ctxcsn
.
bv_val
);
ber_bvarray_free
(
dst
->
ctxcsn
);
dst
->
ctxcsn
=
NULL
;
dst
->
sids
=
NULL
;
ch_free
(
dst
->
octet_str
.
bv_val
);
BER_BVZERO
(
&
dst
->
ctxcsn
);
BER_BVZERO
(
&
dst
->
octet_str
);
new
=
dst
;
}
else
{
...
...
@@ -217,9 +286,18 @@ slap_dup_sync_cookie(
}
new
->
rid
=
src
->
rid
;
if
(
!
BER_BVISNULL
(
&
src
->
ctxcsn
))
{
ber_dupbv
(
&
new
->
ctxcsn
,
&
src
->
ctxcsn
);
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
;
i
<
src
->
numcsns
;
i
++
)
new
->
sids
[
i
]
=
src
->
sids
[
i
];
}
if
(
!
BER_BVISNULL
(
&
src
->
octet_str
))
{
...
...
servers/slapd/overlays/syncprov.c
View file @
fffaea79
This diff is collapsed.
Click to expand it.
servers/slapd/proto-slap.h
View file @
fffaea79
...
...
@@ -1016,9 +1016,13 @@ LDAP_SLAPD_V (char *) slap_known_controls[];
* ldapsync.c
*/
LDAP_SLAPD_F
(
void
)
slap_compose_sync_cookie
LDAP_P
((
Operation
*
,
struct
berval
*
,
struct
berval
*
,
int
));
Operation
*
,
struct
berval
*
,
BerVarray
,
int
));
LDAP_SLAPD_F
(
void
)
slap_sync_cookie_free
LDAP_P
((
struct
sync_cookie
*
,
int
free_cookie
));
LDAP_SLAPD_F
(
int
)
slap_parse_csn_sid
LDAP_P
((
struct
berval
*
));
LDAP_SLAPD_F
(
int
*
)
slap_parse_csn_sids
LDAP_P
((
BerVarray
,
int
));
LDAP_SLAPD_F
(
int
)
slap_parse_sync_cookie
LDAP_P
((
struct
sync_cookie
*
,
void
*
memctx
));
LDAP_SLAPD_F
(
int
)
slap_init_sync_cookie_ctxcsn
LDAP_P
((
...
...
servers/slapd/schema_prep.c
View file @
fffaea79
...
...
@@ -603,7 +603,7 @@ static struct slap_schema_ad_map {
"EQUALITY CSNMatch "
"ORDERING CSNOrderingMatch "
"SYNTAX 1.3.6.1.4.1.4203.666.11.2.1{64} "
"
SINGLE-VALUE
NO-USER-MODIFICATION USAGE dSAOperation )"
,
"NO-USER-MODIFICATION USAGE dSAOperation )"
,
NULL
,
SLAP_AT_HIDE
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
...
...
servers/slapd/slap.h
View file @
fffaea79
...
...
@@ -1650,14 +1650,17 @@ typedef BackendDB Backend;
struct
syncinfo_s
;
#define SLAP_SYNC_RID_SIZE 3
#define SLAP_SYNC_SID_MAX 4095
/* based on liblutil/csn.c field width */
#define SLAP_SYNCUUID_SET_SIZE 256
#define SLAP_SYNC_UPDATE_MSGID 1
struct
sync_cookie
{
struct
berval
ctxcsn
;
struct
berval
*
ctxcsn
;
struct
berval
octet_str
;
long
rid
;
int
rid
;
int
numcsns
;
int
*
sids
;
LDAP_STAILQ_ENTRY
(
sync_cookie
)
sc_next
;
};
...
...
servers/slapd/syncrepl.c
View file @
fffaea79
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment