Makefile.am | 1
Makefile.in | 1
ldap/admin/src/scripts/template-fixup-memberuid.pl.in | 180 ++++++++++++++++++
3 files changed, 182 insertions(+)
New commits:
commit fba1db19ef8dcea9f41e80edf23ec91442516771
Author: Noriko Hosoi <nhosoi(a)redhat.com>
Date: Wed Jun 11 13:48:09 2014 -0700
Ticket #555 - add fixup-memberuid.pl script
Description: Thanks to Carsten Grzembra for providing us the script
(previous 2 commits -- add fixup-memberuid.pl)
This is an additional patch generated by the autogen.sh.
https://fedorahosted.org/389/ticket/555
diff --git a/Makefile.in b/Makefile.in
index 1d8fa47..3c4f99e 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1846,6 +1846,7 @@ task_SCRIPTS = ldap/admin/src/scripts/template-bak2db \
ldap/admin/src/scripts/template-db2ldif.pl \
ldap/admin/src/scripts/template-fixup-linkedattrs.pl \
ldap/admin/src/scripts/template-fixup-memberof.pl \
+ ldap/admin/src/scripts/template-fixup-memberuid.pl \
ldap/admin/src/scripts/template-cleanallruv.pl \
ldap/admin/src/scripts/template-ldif2db.pl \
ldap/admin/src/scripts/template-ns-accountstatus.pl \
commit e38dc4e8265dd22d4d194dd99b4a5f8f19fc8c7a
Author: Carsten Grzemba <grzemba(a)contac-dt.de>
Date: Fri Jan 11 15:45:00 2013 +0100
Ticket #555 - add fixup-memberuid.pl script
Description: add fixup-memberuid.pl script
https://fedorahosted.org/389/ticket/555
Reviewed by nhosoi(a)redhat.com
diff --git a/ldap/admin/src/scripts/template-fixup-memberuid.pl.in b/ldap/admin/src/scripts/template-fixup-memberuid.pl.in
new file mode 100644
index 0000000..8ac4f86
--- /dev/null
+++ b/ldap/admin/src/scripts/template-fixup-memberuid.pl.in
@@ -0,0 +1,180 @@
+#{{PERL-EXEC}}
+#
+# BEGIN COPYRIGHT BLOCK
+# This Program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; version 2 of the License.
+#
+# This Program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA.
+#
+# In addition, as a special exception, Red Hat, Inc. gives You the additional
+# right to link the code of this Program with code not covered under the GNU
+# General Public License ("Non-GPL Code") and to distribute linked combinations
+# including the two, subject to the limitations in this paragraph. Non-GPL Code
+# permitted under this exception must only link to the code of this Program
+# through those well defined interfaces identified in the file named EXCEPTION
+# found in the source code files (the "Approved Interfaces"). The files of
+# Non-GPL Code may instantiate templates or use macros or inline functions from
+# the Approved Interfaces without causing the resulting work to be covered by
+# the GNU General Public License. Only Red Hat, Inc. may make changes or
+# additions to the list of Approved Interfaces. You must obey the GNU General
+# Public License in all respects for all of the Program code and other code used
+# in conjunction with the Program except the Non-GPL Code covered by this
+# exception. If you modify this file, you may extend this exception to your
+# version of the file, but you are not obligated to do so. If you do not wish to
+# provide this exception without modification, you must delete this exception
+# statement from your version and license this file solely under the GPL without
+# exception.
+#
+#
+# Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
+# Copyright (C) 2014 Red Hat, Inc.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+
+sub usage {
+ print(STDERR "Usage: $0 [-v] -D rootdn { -w password | -w - | -j filename } \n");
+ print(STDERR " -b baseDN [-f filter]\n");
+ print(STDERR " Opts: -D rootdn - Directory Manager\n");
+ print(STDERR " : -w password - Directory Manager's password\n");
+ print(STDERR " : -w - - Prompt for Directory Manager's password\n");
+ print(STDERR " : -j filename - Read Directory Manager's password from file\n");
+ print(STDERR " : -b baseDN - Base DN that contains entries to fix up.\n");
+ print(STDERR " : -f filter - Filter for entries to fix up\n");
+ print(STDERR " If omitted, all entries under the specified\n");
+ print(STDERR " base will have their memberUid attribute\n");
+ print(STDERR " regenerated.\n");
+ print(STDERR " : -v - verbose\n");
+}
+
+$rootdn = "";
+$passwd = "";
+$passwdfile = "";
+$basedn_arg = "";
+$filter_arg = "";
+$filter = "";
+$verbose = 0;
+
+$prefix = "{{DS-ROOT}}";
+
+$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
+
+libpath_add("$prefix@nss_libdir@");
+libpath_add("$prefix/usr/lib");
+libpath_add("@nss_libdir@");
+libpath_add("/usr/lib");
+
+$ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
+
+$i = 0;
+while ($i <= $#ARGV)
+{
+ if ("$ARGV[$i]" eq "-b")
+ {
+ # base DN
+ $i++; $basedn_arg = $ARGV[$i];
+ }
+ elsif ("$ARGV[$i]" eq "-f")
+ {
+ # filter
+ $i++; $filter_arg = $ARGV[$i];
+ }
+ elsif ("$ARGV[$i]" eq "-D")
+ {
+ # Directory Manager
+ $i++; $rootdn = $ARGV[$i];
+ }
+ elsif ("$ARGV[$i]" eq "-w")
+ {
+ # Directory Manager's password
+ $i++; $passwd = $ARGV[$i];
+ }
+ elsif ("$ARGV[$i]" eq "-j")
+ {
+ # Read Directory Manager's password from a file
+ $i++; $passwdfile = $ARGV[$i];
+ }
+ elsif ("$ARGV[$i]" eq "-v")
+ {
+ # verbose
+ $verbose = 1;
+ }
+ else
+ {
+ &usage; exit(1);
+ }
+ $i++;
+}
+
+if ($passwdfile ne ""){
+# Open file and get the password
+ unless (open (RPASS, $passwdfile)) {
+ die "Error, cannot open password file $passwdfile\n";
+ }
+ $passwd = <RPASS>;
+ chomp($passwd);
+ close(RPASS);
+} elsif ($passwd eq "-"){
+# Read the password from terminal
+ print "Bind Password: ";
+ # Disable console echo
+ system("@sttyexec@ -echo") if -t STDIN;
+ # read the answer
+ $passwd = <STDIN>;
+ # Enable console echo
+ system("@sttyexec@ echo") if -t STDIN;
+ print "\n";
+ chop($passwd); # trim trailing newline
+}
+
+if ( $rootdn eq "" || $passwd eq "" || $basedn_arg eq "" )
+{
+ &usage;
+ exit(1);
+}
+
+$vstr = "";
+if ($verbose != 0)
+{
+ $vstr = "-v";
+}
+
+# Use a timestamp as part of the task entry name
+($s, $m, $h, $dy, $mn, $yr, $wdy, $ydy, $r) = localtime(time);
+$mn++; $yr += 1900;
+$taskname = "memberUid_fixup_${yr}_${mn}_${dy}_${h}_${m}_${s}";
+
+# Build the task entry to add
+$dn = "dn: cn=$taskname, cn=memberuid task, cn=tasks, cn=config\n";
+$misc = "changetype: add\nobjectclass: top\nobjectclass: extensibleObject\n";
+$cn = "cn: $taskname\n";
+$basedn = "basedn: $basedn_arg\n";
+
+if ( $filter_arg ne "" )
+{
+ $filter = "filter: $filter_arg\n";
+}
+
+$entry = "${dn}${misc}${cn}${basedn}${filter}";
+open(FOO, "| ldapmodify @ldaptool_opts@ $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -a" );
+print(FOO "$entry");
+close(FOO);
+
+sub libpath_add {
+ my $libpath = shift;
+
+ if ($libpath) {
+ if ($ENV{'LD_LIBRARY_PATH'}) {
+ $ENV{'LD_LIBRARY_PATH'} = "$ENV{'LD_LIBRARY_PATH'}:$libpath";
+ } else {
+ $ENV{'LD_LIBRARY_PATH'} = "$libpath";
+ }
+ }
+}
commit f2d7a71f1644500aed41439a5916889cc65291ac
Author: Carsten Grzemba <grzemba(a)contac-dt.de>
Date: Fri Jan 11 15:52:43 2013 +0100
Ticket #555 - add fixup-memberuid.pl script
Description: add fixup-memberuid.pl to Makefile.am
https://fedorahosted.org/389/ticket/555
Reviewed by nhosoi(a)redhat.com
diff --git a/Makefile.am b/Makefile.am
index 04bada8..a2a1fa1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -435,6 +435,7 @@ task_SCRIPTS = ldap/admin/src/scripts/template-bak2db \
ldap/admin/src/scripts/template-db2ldif.pl \
ldap/admin/src/scripts/template-fixup-linkedattrs.pl \
ldap/admin/src/scripts/template-fixup-memberof.pl \
+ ldap/admin/src/scripts/template-fixup-memberuid.pl \
ldap/admin/src/scripts/template-cleanallruv.pl \
ldap/admin/src/scripts/template-ldif2db.pl \
ldap/admin/src/scripts/template-ns-accountstatus.pl \
ldap/servers/slapd/back-ldbm/ldbm_index_config.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
New commits:
commit 4bccd2b735d1fc6765f37623f8f67d6c2f22226d
Author: Rich Megginson <rmeggins(a)redhat.com>
Date: Wed Jun 25 16:49:50 2014 -0600
Ticket #47831 - server restart wipes out index config if there is a default index
https://fedorahosted.org/389/ticket/47831
Reviewed by: nhosoi (Thanks!)
Branch: 389-ds-base-1.2.11
Fix Description: In ldbm_instance_index_config_enable_index(), only call
the function ldbm_index_parse_entry() if the index does not exist. Instead,
get the name of the index from the "cn" attribute of the entry, and use
ainfo_get() to get the index. If this returns NULL, then call
ldbm_index_parse_entry() to create and parse the index.
Platforms tested: Fedora 20
Flag Day: no
Doc impact: no
(cherry picked from commit 5c5c9603946ecb89fb17df665a95aa3ce75e01de)
(cherry picked from commit 111e11ad2b8ef1f3a1827e0aa833512189424a8b)
(cherry picked from commit 18bc3e82c3919867f14747343e452019630b60d0)
(cherry picked from commit e260d9fd9e680579677007b6466f4e9ad3323eb6)
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_index_config.c b/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
index 2775785..7026a79 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
@@ -341,19 +341,26 @@ int ldbm_instance_config_add_index_entry(
int
ldbm_instance_index_config_enable_index(ldbm_instance *inst, Slapi_Entry* e)
{
- char *index_name;
- int rc;
+ char *index_name = NULL;
+ int rc = LDAP_SUCCESS;
+ struct attrinfo *ai = NULL;
- rc=ldbm_index_parse_entry(inst, e, "from DSE add", &index_name);
+ index_name = slapi_entry_attr_get_charptr(e, "cn");
+ if (index_name) {
+ ainfo_get(inst->inst_be, index_name, &ai);
+ }
+ if (!ai) {
+ rc=ldbm_index_parse_entry(inst, e, "from DSE add", &index_name);
+ }
if (rc == LDAP_SUCCESS) {
/* Assume the caller knows if it is OK to go online immediately */
- struct attrinfo *ai = NULL;
-
- ainfo_get(inst->inst_be, index_name, &ai);
+ if (!ai) {
+ ainfo_get(inst->inst_be, index_name, &ai);
+ }
PR_ASSERT(ai != NULL);
ai->ai_indexmask &= ~INDEX_OFFLINE;
- slapi_ch_free((void **)&index_name);
- }
+ }
+ slapi_ch_free_string(&index_name);
return rc;
}
ldap/servers/slapd/back-ldbm/ldbm_index_config.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
New commits:
commit 5c5c9603946ecb89fb17df665a95aa3ce75e01de
Author: Rich Megginson <rmeggins(a)redhat.com>
Date: Wed Jun 25 16:49:50 2014 -0600
Ticket #47831 - server restart wipes out index config if there is a default index
https://fedorahosted.org/389/ticket/47831
Reviewed by: nhosoi (Thanks!)
Branch: master
Fix Description: In ldbm_instance_index_config_enable_index(), only call
the function ldbm_index_parse_entry() if the index does not exist. Instead,
get the name of the index from the "cn" attribute of the entry, and use
ainfo_get() to get the index. If this returns NULL, then call
ldbm_index_parse_entry() to create and parse the index.
Platforms tested: Fedora 20
Flag Day: no
Doc impact: no
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_index_config.c b/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
index e2bec79..51801f5 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
@@ -347,19 +347,26 @@ int ldbm_instance_config_add_index_entry(
int
ldbm_instance_index_config_enable_index(ldbm_instance *inst, Slapi_Entry* e)
{
- char *index_name;
- int rc;
+ char *index_name = NULL;
+ int rc = LDAP_SUCCESS;
+ struct attrinfo *ai = NULL;
- rc=ldbm_index_parse_entry(inst, e, "from DSE add", &index_name);
+ index_name = slapi_entry_attr_get_charptr(e, "cn");
+ if (index_name) {
+ ainfo_get(inst->inst_be, index_name, &ai);
+ }
+ if (!ai) {
+ rc=ldbm_index_parse_entry(inst, e, "from DSE add", &index_name);
+ }
if (rc == LDAP_SUCCESS) {
/* Assume the caller knows if it is OK to go online immediately */
- struct attrinfo *ai = NULL;
-
- ainfo_get(inst->inst_be, index_name, &ai);
+ if (!ai) {
+ ainfo_get(inst->inst_be, index_name, &ai);
+ }
PR_ASSERT(ai != NULL);
ai->ai_indexmask &= ~INDEX_OFFLINE;
- slapi_ch_free((void **)&index_name);
- }
+ }
+ slapi_ch_free_string(&index_name);
return rc;
}
ldap/servers/slapd/back-ldbm/ldbm_index_config.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
New commits:
commit e260d9fd9e680579677007b6466f4e9ad3323eb6
Author: Rich Megginson <rmeggins(a)redhat.com>
Date: Wed Jun 25 16:49:50 2014 -0600
Ticket #47831 - server restart wipes out index config if there is a default index
https://fedorahosted.org/389/ticket/47831
Reviewed by: nhosoi (Thanks!)
Branch: 389-ds-base-1.3.0
Fix Description: In ldbm_instance_index_config_enable_index(), only call
the function ldbm_index_parse_entry() if the index does not exist. Instead,
get the name of the index from the "cn" attribute of the entry, and use
ainfo_get() to get the index. If this returns NULL, then call
ldbm_index_parse_entry() to create and parse the index.
Platforms tested: Fedora 20
Flag Day: no
Doc impact: no
(cherry picked from commit 5c5c9603946ecb89fb17df665a95aa3ce75e01de)
(cherry picked from commit 111e11ad2b8ef1f3a1827e0aa833512189424a8b)
(cherry picked from commit 18bc3e82c3919867f14747343e452019630b60d0)
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_index_config.c b/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
index e2bec79..51801f5 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
@@ -347,19 +347,26 @@ int ldbm_instance_config_add_index_entry(
int
ldbm_instance_index_config_enable_index(ldbm_instance *inst, Slapi_Entry* e)
{
- char *index_name;
- int rc;
+ char *index_name = NULL;
+ int rc = LDAP_SUCCESS;
+ struct attrinfo *ai = NULL;
- rc=ldbm_index_parse_entry(inst, e, "from DSE add", &index_name);
+ index_name = slapi_entry_attr_get_charptr(e, "cn");
+ if (index_name) {
+ ainfo_get(inst->inst_be, index_name, &ai);
+ }
+ if (!ai) {
+ rc=ldbm_index_parse_entry(inst, e, "from DSE add", &index_name);
+ }
if (rc == LDAP_SUCCESS) {
/* Assume the caller knows if it is OK to go online immediately */
- struct attrinfo *ai = NULL;
-
- ainfo_get(inst->inst_be, index_name, &ai);
+ if (!ai) {
+ ainfo_get(inst->inst_be, index_name, &ai);
+ }
PR_ASSERT(ai != NULL);
ai->ai_indexmask &= ~INDEX_OFFLINE;
- slapi_ch_free((void **)&index_name);
- }
+ }
+ slapi_ch_free_string(&index_name);
return rc;
}
ldap/servers/slapd/back-ldbm/ldbm_index_config.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
New commits:
commit 111e11ad2b8ef1f3a1827e0aa833512189424a8b
Author: Rich Megginson <rmeggins(a)redhat.com>
Date: Wed Jun 25 16:49:50 2014 -0600
Ticket #47831 - server restart wipes out index config if there is a default index
https://fedorahosted.org/389/ticket/47831
Reviewed by: nhosoi (Thanks!)
Branch: 389-ds-base-1.3.2
Fix Description: In ldbm_instance_index_config_enable_index(), only call
the function ldbm_index_parse_entry() if the index does not exist. Instead,
get the name of the index from the "cn" attribute of the entry, and use
ainfo_get() to get the index. If this returns NULL, then call
ldbm_index_parse_entry() to create and parse the index.
Platforms tested: Fedora 20
Flag Day: no
Doc impact: no
(cherry picked from commit 5c5c9603946ecb89fb17df665a95aa3ce75e01de)
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_index_config.c b/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
index e2bec79..51801f5 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
@@ -347,19 +347,26 @@ int ldbm_instance_config_add_index_entry(
int
ldbm_instance_index_config_enable_index(ldbm_instance *inst, Slapi_Entry* e)
{
- char *index_name;
- int rc;
+ char *index_name = NULL;
+ int rc = LDAP_SUCCESS;
+ struct attrinfo *ai = NULL;
- rc=ldbm_index_parse_entry(inst, e, "from DSE add", &index_name);
+ index_name = slapi_entry_attr_get_charptr(e, "cn");
+ if (index_name) {
+ ainfo_get(inst->inst_be, index_name, &ai);
+ }
+ if (!ai) {
+ rc=ldbm_index_parse_entry(inst, e, "from DSE add", &index_name);
+ }
if (rc == LDAP_SUCCESS) {
/* Assume the caller knows if it is OK to go online immediately */
- struct attrinfo *ai = NULL;
-
- ainfo_get(inst->inst_be, index_name, &ai);
+ if (!ai) {
+ ainfo_get(inst->inst_be, index_name, &ai);
+ }
PR_ASSERT(ai != NULL);
ai->ai_indexmask &= ~INDEX_OFFLINE;
- slapi_ch_free((void **)&index_name);
- }
+ }
+ slapi_ch_free_string(&index_name);
return rc;
}
ldap/servers/slapd/back-ldbm/ldbm_index_config.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
New commits:
commit 18bc3e82c3919867f14747343e452019630b60d0
Author: Rich Megginson <rmeggins(a)redhat.com>
Date: Wed Jun 25 16:49:50 2014 -0600
Ticket #47831 - server restart wipes out index config if there is a default index
https://fedorahosted.org/389/ticket/47831
Reviewed by: nhosoi (Thanks!)
Branch: 389-ds-base-1.3.1
Fix Description: In ldbm_instance_index_config_enable_index(), only call
the function ldbm_index_parse_entry() if the index does not exist. Instead,
get the name of the index from the "cn" attribute of the entry, and use
ainfo_get() to get the index. If this returns NULL, then call
ldbm_index_parse_entry() to create and parse the index.
Platforms tested: Fedora 20
Flag Day: no
Doc impact: no
(cherry picked from commit 5c5c9603946ecb89fb17df665a95aa3ce75e01de)
(cherry picked from commit 111e11ad2b8ef1f3a1827e0aa833512189424a8b)
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_index_config.c b/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
index e2bec79..51801f5 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
@@ -347,19 +347,26 @@ int ldbm_instance_config_add_index_entry(
int
ldbm_instance_index_config_enable_index(ldbm_instance *inst, Slapi_Entry* e)
{
- char *index_name;
- int rc;
+ char *index_name = NULL;
+ int rc = LDAP_SUCCESS;
+ struct attrinfo *ai = NULL;
- rc=ldbm_index_parse_entry(inst, e, "from DSE add", &index_name);
+ index_name = slapi_entry_attr_get_charptr(e, "cn");
+ if (index_name) {
+ ainfo_get(inst->inst_be, index_name, &ai);
+ }
+ if (!ai) {
+ rc=ldbm_index_parse_entry(inst, e, "from DSE add", &index_name);
+ }
if (rc == LDAP_SUCCESS) {
/* Assume the caller knows if it is OK to go online immediately */
- struct attrinfo *ai = NULL;
-
- ainfo_get(inst->inst_be, index_name, &ai);
+ if (!ai) {
+ ainfo_get(inst->inst_be, index_name, &ai);
+ }
PR_ASSERT(ai != NULL);
ai->ai_indexmask &= ~INDEX_OFFLINE;
- slapi_ch_free((void **)&index_name);
- }
+ }
+ slapi_ch_free_string(&index_name);
return rc;
}
dirsrvtests/tickets/ticket47815_test.py | 227 ++++++++++++++++++++++++++++++++
1 file changed, 227 insertions(+)
New commits:
commit 2bae66a1bc7b2e211dded44cdede18281632e4bc
Author: Mark Reynolds <mreynolds(a)redhat.com>
Date: Wed Jun 25 16:00:26 2014 -0400
Ticket 47815 - add lib389 test
Description: Add a lib389 test for ticket 47815
https://fedorahosted.org/389/ticket/47815
Reviewed by: nhosoi(Thanks!)
(cherry picked from commit b3aae6b16bb99eec56d2bda84ac8fc9a979b354e)
diff --git a/dirsrvtests/tickets/ticket47815_test.py b/dirsrvtests/tickets/ticket47815_test.py
new file mode 100644
index 0000000..1f2ce33
--- /dev/null
+++ b/dirsrvtests/tickets/ticket47815_test.py
@@ -0,0 +1,227 @@
+import os
+import sys
+import time
+import ldap
+import logging
+import socket
+import pytest
+from lib389 import DirSrv, Entry, tools
+from lib389.tools import DirSrvTools
+from lib389._constants import *
+from lib389.properties import *
+from constants import *
+
+log = logging.getLogger(__name__)
+
+installation_prefix = None
+
+
+class TopologyStandalone(object):
+ def __init__(self, standalone):
+ standalone.open()
+ self.standalone = standalone
+
+
+pytest.fixture(scope="module")
+def topology(request):
+ '''
+ This fixture is used to standalone topology for the 'module'.
+ At the beginning, It may exists a standalone instance.
+ It may also exists a backup for the standalone instance.
+
+ Principle:
+ If standalone instance exists:
+ restart it
+ If backup of standalone exists:
+ create/rebind to standalone
+
+ restore standalone instance from backup
+ else:
+ Cleanup everything
+ remove instance
+ remove backup
+ Create instance
+ Create backup
+ '''
+ global installation_prefix
+
+ if installation_prefix:
+ args_instance[SER_DEPLOYED_DIR] = installation_prefix
+
+ standalone = DirSrv(verbose=False)
+
+ # Args for the standalone instance
+ args_instance[SER_HOST] = HOST_STANDALONE
+ args_instance[SER_PORT] = PORT_STANDALONE
+ args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
+ args_standalone = args_instance.copy()
+ standalone.allocate(args_standalone)
+
+ # Get the status of the backups
+ backup_standalone = standalone.checkBackupFS()
+
+ # Get the status of the instance and restart it if it exists
+ instance_standalone = standalone.exists()
+ if instance_standalone:
+ # assuming the instance is already stopped, just wait 5 sec max
+ standalone.stop(timeout=5)
+ standalone.start(timeout=10)
+
+ if backup_standalone:
+ # The backup exist, assuming it is correct
+ # we just re-init the instance with it
+ if not instance_standalone:
+ standalone.create()
+ # Used to retrieve configuration information (dbdir, confdir...)
+ standalone.open()
+
+ # restore standalone instance from backup
+ standalone.stop(timeout=10)
+ standalone.restoreFS(backup_standalone)
+ standalone.start(timeout=10)
+
+ else:
+ # We should be here only in two conditions
+ # - This is the first time a test involve standalone instance
+ # - Something weird happened (instance/backup destroyed)
+ # so we discard everything and recreate all
+
+ # Remove the backup. So even if we have a specific backup file
+ # (e.g backup_standalone) we clear backup that an instance may have created
+ if backup_standalone:
+ standalone.clearBackupFS()
+
+ # Remove the instance
+ if instance_standalone:
+ standalone.delete()
+
+ # Create the instance
+ standalone.create()
+
+ # Used to retrieve configuration information (dbdir, confdir...)
+ standalone.open()
+
+ # Time to create the backups
+ standalone.stop(timeout=10)
+ standalone.backupfile = standalone.backupFS()
+ standalone.start(timeout=10)
+
+ #
+ # Here we have standalone instance up and running
+ # Either coming from a backup recovery
+ # or from a fresh (re)init
+ # Time to return the topology
+ return TopologyStandalone(standalone)
+
+
+def test_ticket47815(topology):
+ """
+ Test betxn plugins reject an invalid option, and make sure that the rejected entry
+ is not in the entry cache.
+
+ Enable memberOf, automember, and retrocl plugins
+ Add the automember config entry
+ Add the automember group
+ Add a user that will be rejected by a betxn plugin - result error 53
+ Attempt the same add again, and it should result in another error 53 (not error 68)
+ """
+ result = 0
+ result2 = 0
+
+ log.info('Testing Ticket 47815 - Add entries that should be rejected by the betxn plugins, and are not left in the entry cache')
+
+ # Enabled the plugins
+ topology.standalone.plugins.enable(name=PLUGIN_MEMBER_OF)
+ topology.standalone.plugins.enable(name=PLUGIN_AUTOMEMBER)
+ topology.standalone.plugins.enable(name=PLUGIN_RETRO_CHANGELOG)
+
+ # configure automember config entry
+ log.info('Adding automember config')
+ try:
+ topology.standalone.add_s(Entry(('cn=group cfg,cn=Auto Membership Plugin,cn=plugins,cn=config', {
+ 'objectclass': 'top autoMemberDefinition'.split(),
+ 'autoMemberScope': 'dc=example,dc=com',
+ 'autoMemberFilter': 'cn=user',
+ 'autoMemberDefaultGroup': 'cn=group,dc=example,dc=com',
+ 'autoMemberGroupingAttr': 'member:dn',
+ 'cn': 'group cfg'})))
+ except:
+ log.error('Failed to add automember config')
+ exit(1)
+
+ topology.standalone.stop(timeout=120)
+ time.sleep(1)
+ topology.standalone.start(timeout=120)
+ time.sleep(3)
+
+ # need to reopen a connection toward the instance
+ topology.standalone.open()
+
+ # add automember group
+ log.info('Adding automember group')
+ try:
+ topology.standalone.add_s(Entry(('cn=group,dc=example,dc=com', {
+ 'objectclass': 'top groupOfNames'.split(),
+ 'cn': 'group'})))
+ except:
+ log.error('Failed to add automember group')
+ exit(1)
+
+ # add user that should result in an error 53
+ log.info('Adding invalid entry')
+
+ try:
+ topology.standalone.add_s(Entry(('cn=user,dc=example,dc=com', {
+ 'objectclass': 'top person'.split(),
+ 'sn': 'user',
+ 'cn': 'user'})))
+ except ldap.UNWILLING_TO_PERFORM:
+ log.debug('Adding invalid entry failed as expected')
+ result = 53
+ except ldap.LDAPError, e:
+ log.error('Unexpected result ' + e.message['desc'])
+ assert False
+ if result == 0:
+ log.error('Add operation unexpectedly succeeded')
+ assert False
+
+ # Attempt to add user again, should result in error 53 again
+ try:
+ topology.standalone.add_s(Entry(('cn=user,dc=example,dc=com', {
+ 'objectclass': 'top person'.split(),
+ 'sn': 'user',
+ 'cn': 'user'})))
+ except ldap.UNWILLING_TO_PERFORM:
+ log.debug('2nd add of invalid entry failed as expected')
+ result2 = 53
+ except ldap.LDAPError, e:
+ log.error('Unexpected result ' + e.message['desc'])
+ assert False
+ if result2 == 0:
+ log.error('2nd Add operation unexpectedly succeeded')
+ assert False
+
+ # If we got here we passed!
+ log.info('Ticket47815 Test - Passed')
+
+
+def test_ticket47815_final(topology):
+ topology.standalone.stop(timeout=10)
+
+
+def run_isolated():
+ '''
+ run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..)
+ To run isolated without py.test, you need to
+ - edit this file and comment '@pytest.fixture' line before 'topology' function.
+ - set the installation prefix
+ - run this program
+ '''
+ global installation_prefix
+ installation_prefix = None
+
+ topo = topology(True)
+ test_ticket47815(topo)
+
+if __name__ == '__main__':
+ run_isolated()