Friday, May 16, 2014

[389-commits] Branch '389-ds-base-1.3.2' - ldap/servers

ldap/servers/slapd/back-ldbm/dbhelp.c | 6 ++
ldap/servers/slapd/back-ldbm/dblayer.c | 60 ++++++++++++-------------
ldap/servers/slapd/back-ldbm/proto-back-ldbm.h | 4 -
3 files changed, 39 insertions(+), 31 deletions(-)

New commits:
commit 072b9fe660c35cf71c9df678c96bf39e61b47687
Author: Noriko Hosoi <nhosoi@redhat.com>
Date: Thu May 15 18:57:21 2014 -0700

Ticket #47804 - db2bak.pl error with changelogdb

Bug description: Backup utility db2bak[.pl] copies not just backend
db files but also changelog db files, which is not associated with
the backend instance, but the backup code blindly expected it.

Fix description: If the copying directory is a changelog db dir,
skip retrieving the backend instance info and just copy the files
underneath.

https://fedorahosted.org/389/ticket/47804

Reviewed by rmeggins@redhat.com (Thank you, Rich!!)

Signed-off-by: Noriko Hosoi <nhosoi@redhat.com>

diff --git a/ldap/servers/slapd/back-ldbm/dbhelp.c b/ldap/servers/slapd/back-ldbm/dbhelp.c
index 29c0247..40966ac 100644
--- a/ldap/servers/slapd/back-ldbm/dbhelp.c
+++ b/ldap/servers/slapd/back-ldbm/dbhelp.c
@@ -139,6 +139,12 @@ dblayer_copy_file_keybykey(DB_ENV *env,
(*(p + sizeof(LDBM_ENTRYRDN_STR) - 1) == '.')) {
/* entryrdn.db */
struct attrinfo *ai = NULL;
+ if (NULL == inst) {
+ LDAPDebug0Args(LDAP_DEBUG_ANY,
+ "dblayer_copy_file_keybykey(entryrdn), "
+ "dup_cmp_fn cannot be retrieved since inst is NULL.\n");
+ goto error;
+ }
ainfo_get(inst->inst_be, LDBM_ENTRYRDN_STR, &ai);
if (ai->ai_dup_cmp_fn) {
/* If set, use the special dup compare callback */
diff --git a/ldap/servers/slapd/back-ldbm/dblayer.c b/ldap/servers/slapd/back-ldbm/dblayer.c
index 6582c7a..6f3d258 100644
--- a/ldap/servers/slapd/back-ldbm/dblayer.c
+++ b/ldap/servers/slapd/back-ldbm/dblayer.c
@@ -5918,17 +5918,15 @@ dblayer_copy_directory(struct ldbminfo *li,
char *dest_dir,
int restore,
int *cnt,
- int instance_dir_flag,
int indexonly,
- int resetlsns)
+ int resetlsns,
+ int is_changelog)
{
dblayer_private *priv = NULL;
char *new_src_dir = NULL;
char *new_dest_dir = NULL;
PRDir *dirhandle = NULL;
PRDirEntry *direntry = NULL;
- size_t filename_length = 0;
- size_t offset = 0;
char *compare_piece = NULL;
char *filename1;
char *filename2;
@@ -5937,8 +5935,8 @@ dblayer_copy_directory(struct ldbminfo *li,
char *inst_dirp = NULL;
char inst_dir[MAXPATHLEN];
char sep;
- int suffix_len = 0;
- ldbm_instance *inst = NULL;
+ int src_is_fullpath = 0;
+ ldbm_instance *inst = NULL;

if (!src_dir || '\0' == *src_dir)
{
@@ -5962,20 +5960,28 @@ dblayer_copy_directory(struct ldbminfo *li,
else
relative_instance_name++;

- inst = ldbm_instance_find_by_name(li, relative_instance_name);
- if (NULL == inst) {
- LDAPDebug(LDAP_DEBUG_ANY, "Backend instance \"%s\" does not exist; "
- "Instance path %s could be invalid.\n",
- relative_instance_name, src_dir, 0);
- return return_value;
+ if (is_fullpath(src_dir)) {
+ src_is_fullpath = 1;
+ }
+ if (is_changelog) {
+ if (!src_is_fullpath) {
+ LDAPDebug1Arg(LDAP_DEBUG_ANY, "Changelogdir \"%s\" is not full path; "
+ "Skipping it.\n", src_dir);
+ return 0;
+ }
+ } else {
+ inst = ldbm_instance_find_by_name(li, relative_instance_name);
+ if (NULL == inst) {
+ LDAPDebug(LDAP_DEBUG_ANY, "Backend instance \"%s\" does not exist; "
+ "Instance path %s could be invalid.\n",
+ relative_instance_name, src_dir, 0);
+ return return_value;
+ }
}

- if (is_fullpath(src_dir))
- {
+ if (src_is_fullpath) {
new_src_dir = src_dir;
- }
- else
- {
+ } else {
int len;

inst_dirp = dblayer_get_full_inst_dir(inst->inst_li, inst,
@@ -6002,7 +6008,6 @@ dblayer_copy_directory(struct ldbminfo *li,
return return_value;
}

- suffix_len = sizeof(LDBM_SUFFIX) - 1;
while (NULL != (direntry =
PR_ReadDir(dirhandle, PR_SKIP_DOT | PR_SKIP_DOT_DOT)))
{
@@ -6016,15 +6021,10 @@ dblayer_copy_directory(struct ldbminfo *li,
continue;
}

- /* Look at the last three characters in the filename */
- filename_length = strlen(direntry->name);
- if (filename_length > suffix_len) {
- offset = filename_length - suffix_len;
- } else {
- offset = 0;
+ compare_piece = PL_strrchr((char *)direntry->name, '.');
+ if (NULL == compare_piece) {
+ compare_piece = (char *)direntry->name;
}
- compare_piece = (char *)direntry->name + offset;
-
/* rename .db3 -> .db4 or .db4 -> .db */
if (0 == strcmp(compare_piece, LDBM_FILENAME_SUFFIX) ||
0 == strcmp(compare_piece, LDBM_SUFFIX_OLD) ||
@@ -6124,6 +6124,7 @@ out:
/*
* Get changelogdir from cn=changelog5,cn=config
* The value does not have trailing spaces nor slashes.
+ * The changelogdir value must be a fullpath.
*/
static int
_dblayer_get_changelogdir(struct ldbminfo *li, char **changelogdir)
@@ -6339,7 +6340,7 @@ dblayer_backup(struct ldbminfo *li, char *dest_dir, Slapi_Task *task)
return_value = dblayer_copy_directory(li, task, changelogdir,
changelog_destdir,
0 /* backup */,
- &cnt, 0, 0, 0);
+ &cnt, 0, 0, 1);
if (return_value) {
LDAPDebug(LDAP_DEBUG_ANY,
"Backup: error in copying directory "
@@ -7012,7 +7013,8 @@ int dblayer_restore(struct ldbminfo *li, char *src_dir, Slapi_Task *task, char *
/* Get the parent dir of changelogdir */
*cldirname = '\0';
return_value = dblayer_copy_directory(li, task, filename1,
- changelogdir, 1 /* restore */, &cnt, 0, 0, 0);
+ changelogdir, 1 /* restore */,
+ &cnt, 0, 0, 1);
*cldirname = '/';
if (return_value) {
LDAPDebug1Arg(LDAP_DEBUG_ANY,
@@ -7044,7 +7046,7 @@ int dblayer_restore(struct ldbminfo *li, char *src_dir, Slapi_Task *task, char *
restore_dir = inst->inst_parent_dir_name;
/* If we're doing a partial restore, we need to reset the LSNs on the data files */
if (dblayer_copy_directory(li, task, filename1,
- restore_dir, 1 /* restore */, &cnt, 0, 0, (bename) ? 1 : 0) == 0)
+ restore_dir, 1 /* restore */, &cnt, 0, (bename) ? 1 : 0, 0) == 0)
continue;
else
{
diff --git a/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h b/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h
index 0022bfd..0fc8025 100644
--- a/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h
+++ b/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h
@@ -143,8 +143,8 @@ int dblayer_backup(struct ldbminfo *li, char *destination_directory,
int dblayer_restore(struct ldbminfo *li, char* source_directory, Slapi_Task *task, char *bename);
int dblayer_copy_directory(struct ldbminfo *li, Slapi_Task *task,
char *instance_dir, char *destination_dir,
- int restore, int *cnt, int instance_dir_flag,
- int indexonly, int resetlsns);
+ int restore, int *cnt, int indexonly,
+ int resetlsns, int is_changelog);
int dblayer_copyfile(char* source, char * destination, int overwrite, int mode);
int dblayer_delete_instance_dir(backend *be);
int dblayer_delete_database(struct ldbminfo *li);


--
389 commits mailing list
389-commits@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/389-commits

No comments:

Post a Comment