Ticket #47773 - mem leak in do_bind when there is an error

https://fedorahosted.org/389/ticket/47773
Reviewed by: nhosoi (Thanks!)
Branch: 389-ds-base-1.2.11
Fix Description: Do not get the SLAPI_BIND_TARGET_SDN from the pblock and
free it in the clean up code if it was never set in the pblock - just free
the local variable sdn in this case.
Platforms tested: RHEL6 x86_64
Flag Day: no
Doc impact: no
(cherry picked from commit 2a57b521b86b24c0f0a8ddfbea4169c71ee4e896)
(cherry picked from commit c0606d45b91e87e4d0d90dec0812d20a0b23f545)
(cherry picked from commit 39eab765d9c6552c246bed13903807eca4c96887)
(cherry picked from commit 0911134c2c6d97243a7f6652a9a861bf7e28d91b)
Ticket #47774 mem leak in do_search - rawbase not freed upon certain errors

https://fedorahosted.org/389/ticket/47774
Reviewed by: nhosoi (Thanks!)
Branch: 389-ds-base-1.2.11
Fix Description: Free the local rawbase variable if it was not set in the
pblock.
Platforms tested: RHEL6 x86_64
Flag Day: no
Doc impact: no
(cherry picked from commit 1d5c6d6ca300a45305dba631a334ae9a1857d4cb)
(cherry picked from commit b065515935daa8fffe7a8eef3a66621cc8702018)
(cherry picked from commit 97f58ff4787ecb87780fde7245e354ec75e73125)
(cherry picked from commit 33bf4d42727804f5c10ce30834a2340c99cad459)
Ticket #47772 empty modify returns LDAP_INVALID_DN_SYNTAX

https://fedorahosted.org/389/ticket/47772
Reviewed by: mreynolds (Thanks!)
Branch: 389-ds-base-1.2.11
Fix Description: Do not call normalize_mods2bvals if mods is NULL - just allow
the empty modify op to proceed.  Since normalize_mods2bvals only cares about
DN syntax attributes, it is appropriate to return LDAP_INVALID_DN_SYNTAX if
normalize_mods2bvals returns NULL.
Since this fix allows NULL mods to proceed throughout the code, I checked for
all places that SLAPI_MODIFY_MODS was used, to make sure we don't try to
dereference NULL mods, and to make sure the NULL mods were handled correctly
otherwise.
Platforms tested: RHEL6 x86_64
Flag Day: no
Doc impact: no
(cherry-picked with conflicts from f5730129dfbc4ef3808735051b12cbfda518f4fb)
(cherry picked from commit 469c9b9c68806e46b14595da5aec49517af60028)
(cherry picked from commit 60c36f1c6aea1913bd7f719b9efb892092317917)
(cherry picked from commit 1a39cf36137d522f81bc003d07c21da53371a69d)
Ticket 47736 - Import incorrectly updates numsubordinates for tombstone entries

Bug Description:  Imports incorrectly updates numsubordinates when processing
                  tombstone entries.

Fix Description:  Fix the logic in the condition test for updating parentid.

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

Reviewed by: rmeggins & nhosoi(Thanks!!)
Ticket #47772 empty modify returns LDAP_INVALID_DN_SYNTAX

https://fedorahosted.org/389/ticket/47772
Reviewed by: tbordaz, mreynolds (Thanks!)
Branch: 389-ds-base-1.2.11
Fix Description: tbordaz pointed out a couple of other places where the
pblock modify_mods structure is being referenced directly, and needs to be
checked for NULL.
Platforms tested: RHEL6 x86_64
Flag Day: no
Doc impact: no
(cherry picked from commit 2d25bb4dd39d09d8b5fc5b69702d6e1cccc2c65f)
(cherry picked from commit ba5938bfa94d906c2189ebc6579057b2779ee68d)
(cherry picked from commit 1f3d9f685f2adbb4dc0ebcec3def4ecf68a87013)
Ticket 47782 - Parent numbordinate count can be incorrectly updated if an error occurs

Bug Description:  When adding and deleting entries there is a small chance that the modified
                  parent entry(numbsubordinates) could be replaced in the entry cache, even
                  if the operation fails.

Fix Description:  For deletes we can simply move the cache entry switching to a safe location,
                  but for adds we need to unswitch the parent's entry in the cache.

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

Reviewed by: nhosoi(Thanks!)
Ticket #346 - Slow ldapmodify operation time for large quantities of multi-valued attribute values

Description: slapi_entry_add_value is used to add values for sorting,
which did not pass the attribute syntax info and the fallback compare
algorithm was used.  It sometimes different from the attribute syntax
based sorting and failed to find out an attribute.  This patch passes
an attribute syntax info for sorting.

Plus, featuring slapi_berval_cmp for the fallback compare algorithm.
It is closer to the syntax based sorting.

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

Reviewed by rmeggins@redhat.com (Thank you, Rich!)
(cherry picked from commit 136fa64f95263ffcaca5e855b771b5d377e3de52)
(cherry picked from commit 821297df835b7d5235d66b592613c89d991d4049)
(cherry picked from commit e97f2b8f2a42d4ceca4020614fd7388e4e319bab)
Ticket 47771 - Cherry pick issue parentsdn freed twice

Called slapi_sdn_done twice for the same local variable.

https://fedorahosted.org/389/ticket/47771
Ticket 47771 - Move parentsdn initialization to avoid crash

    Bug Description:  It's possible to call slapi_sdn_done() before parentsdn is
                      initialized - which will crash the server.

    Fix Description:  Initialize parentsdn at the top of the function.

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

    Reviewed by: nhosoi(Thanks!)
Ticket #47707 - 389 DS Server crashes and dies while handles paged searches from clients

Bug Description: If a simple paged search request was sent to the server
and the request was abandoned, the paged result slot in the connection
table was not properly released by setting NULL to pr_current_be.  Since
the slot did not look available for the next request even though it was,
the next request failed to get the valid slot number, and the initial slot
number -1 failed to be replaced with the real slot number.  Until the fix
for "Ticket #47623 fix memleak caused by 47347" was made, it overrode the
allocated array's [-1] location, which usually stores the meta data of the
allocated memory.  That crashed the server in the next realloc since the
corrupted memory was passed to the function.

Fix Description: This patch cleans up the abandoned/cleaned up slot for
reuse.  Also, more check not to break the meta data is added.

Special thanks to German Parente (gparente@redhat.com) for providing the
reproducer and analysing the crash.

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

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

(cherry picked from commit 087356f7eaff2dff3c0c4f7dfcaa6aacc9979224)
(cherry picked from commit 2132875746ed9e1fc7c9c53450241c91d0c5ae55)
(cherry picked from commit 40e86e74fb4ecc0fc5a1027d8241945d9b2564e0)