Ticket 47369  version2 - provide default syntax plugin

Bug Description:  syntax plugins are laoded during bootstrapping, but
			in that phase already attributes are handled
			eg in dse.ldif and schema files and no proper way
			to normalize or comare values is provided.
			This became visible with teh fix for ticket #346
			where large attribute sets will be sorted

Fix Description:   when the first attribute syntax init is done, create a plugin
			for directory string syntax and register it with a dummy
			attribute name. if for any attribute the syntax lookup fails
			fall back to using this plugin.
			It will only be used until the syntax plugins are loaded
			and in the startup phase it is acceptable to use directory
			string.
			The impelemenation of the default plugin is reduce to the
			necessary minimum not to duplicate the code of the syntax
			plugins.

			A more rigorus solution would be to refactor the code and
			and move the common code from the syntax plugin to the
			slapd level and reuse it in the default plugin.
			But this would be a major change and should only be done
			with a review of the syntax plugin code, whic could probabyly
			be optimized.

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

Reviewed by: RichM
Fix compiler warning
Ticket #47384 - Plugin library path validation

Description: commit a4b81c0ae59a4246d2d44790efea093a62fc972c
only checks the invalid plugin path when the value is modified.
This patch adds the check when a plugin entry is added.
Ticket #47431 - Duplicate values for the attribute nsslapd-pluginarg are not handled correctly

Fix description: Added the attributes nsslapd-pluginarg0 to
nsslapd-pluginarg15 in the schema file with the condition that
they must be singlevalued. This solves the issue of incorrect
handling of duplicate and multiple values of these attributes.
This fix also solves the problem of non-continuous numbers in
the nsslapd-pluginarg attributes and makes them continuous if
they are not.

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

Reviewed by nhosoi.
Ticket #47370 - DS crashes with some 7-bit check plugin configurations

Bug description: DS crashed when some nsslapd-pluginarg were
missing. The crash was resolved with the fix to #47340 but
the correct error messages were not logged in some cases

Fix description: This patch ensures that correct error messages
are logged in the server error log

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

Reviewed by nhosoi.
Ticket 346 - version 4 Slow ldapmodify operation time
	for large quantities of multi-valued attribute values

Bug Description:  The reason for the performance degradation is that for
		operations like add and delete of values and for updating the index for
		each values a check has tobe done if it exists in the current attribute.
		if the number of values grows the seaqrch time increases

Fix Description:  Keep a secondary array of the indexes of the valuearray which is sorted.
		To locate a value, a binary search can be used.
		A design doc is available at: http://port389.org/wiki/Static_group_performance

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

Reviewed by: RichM
fix compiler warnings
Ticket 47416 - SASL encrypted packet length exceeds maximum allowed limit

Bug Description:  If an error occurs while establishing the secure layer during
                  a bind operation, the client will send an unbind request that
                  is not encrypted.  The sasl code expects encrypted values
                  and it incorrectly parses the message for its length, but since
                  it's not encrypted the length is wrong, and exceeds the saslio limit.

Fix Description:  Check if there is data in the encrypted buffer before the secure
                  layer is established.  Check if the first byte in the buffer is an
                  LDAP_TAG_MESSAGE.  Then we get the legnth of the LDAP message, and compare
                  it to maxbersize.  Then attmept to read in the rest of the
                  packet(if necessary).  If we fail to read in the LDAP msg length,
                  then return PR_WOULD_BLOCK_ERROR.  Otherwise parse the berElement, and
                  check if it is an UNBIND operation.  If it is then copy it to the socket
                  buffer, and let the server process the operation.  Any other valid
                  LDAP operation is still treated as an error.

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

Reviewed by: richm (Thanks!!!)
Ticket 47421 - memory leaks in set_krb5_creds

Bug Description:  Valgrind shows memory leaks in set_krb5_creds()

Fix description:  krb5_unparse_name() allocates/returns the principle name.
                  But we can call this function twice without freeing the first
                  returned value.

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

Reviewed by: richm(Thanks!)
Ticket #47367 - (phase 1) ldapdelete returns non-leaf entry error while trying to remove a leaf entry

Bug description: Replication conflict confuses the numsubordinate count,
which leaves an entry that cannot be deleted even its subordinate entries
are all removed.

Fix description:
[urp.c] 1) get_dn_plus_uniqueid: a logic to create a conflict DN had a bug.
  It used to call slapi_sdn_get_rdn to get the rdn.  The function slapi_sdn_
  get_rdn blindly returned the "dn" field without checking whether the field
  is NULL or not.  Instead, this patch changes the interface of the helper
  function get_dn_plus_uniqueid and use the original Slapi_DN with slapi_sdn_
  get_dn, then generates the conflict DN "nsuniqueid=...+ <RDN>,<PARENT>".
  2) The urp calling timing was moved from SLAPI_PLUGIN_BE_TXN_PRE_* to
  SLAPI_PLUGIN_BE_PRE_*.  (Note: SLAPI_PLUGIN_BE_PRE_* is also in the
  backend transaction.)  This is necessary since urp needs to be done
  prior to parent checking.
[ldbm_add.c] Moved SLAPI_PLUGIN_BE_PRE_ADD_FN inside of the transaction.
  Other operations are already calling SLAPI_PLUGIN_BE_PRE function at the
  timing.
[ldbm_delete.c] There is a case a parent of a delete-candidate entry runs
  into a conflict and multiple parent entries exist.  Once it occurs, a
  parent entry found by the parent dn string may not be the entry which
  manages the numsubordinate count the delete-candidate entry belonging to.
  It confuses the numsubordinate counts and leaves an entry which cannot be
  deleted due to the numsubordinate count mismatch. This patch retrieves
  parent entry by parent id if it is available.
[ldbm_entryrdn.c] When traversing the DIT, a special treatment is needed
  for a tombstone entry. I.e, 2 RDNs (nsuniqueid=..., <RDN>) is treated as
  one RDN.  It should decrement the index (rdnidx) one more to point to the
  right position of the RDN array in Slapi_RDN.
[ldbm_search.c] When checking the scope of an entry in ldbm_back_next_
  search_entry_ext, a tombstone entry was not properly examined. This patch
  introduces a new slapi api slapi_sdn_scope_test_ext.
[dn.c] In slapi_sdn_get_rdn, use slapi_sdn_get_dn to get the dn value of
  Slapi_DN.  It was one cause of the problem in get_dn_plus_uniqueid (urp.c).
  This patch adds slapi_sdn_scope_test_ext, which takes flags to indicates
  the first argument dn is a tombstone sdn.  Also, this patch replaces
  "malloc + strcpy + strcat" with slapi_ch_smprintf to improve the
  readability of the code.
[rdn.c] This patch replaces "malloc + strcpy + strcat" with slapi_create_
  dn_string to normalize the newly added rdn and improve the readability of
  the code.

Reviewed by Rich (Thanks!!)

https://fedorahosted.org/389/ticket/47367
Ticket #47367 - (phase 2) ldapdelete returns non-leaf entry error while trying to remove a leaf entry

Fix description:
1) Make sure add/modify/modrdn/delete plug-in callbacks return
SLAPI_PLUGIN_SUCCESS (==0) on SUCCESS and SLAPI_PLUGIN_FAILURE
(==-1) on FAILURE.  And set error code to SLAPI_RESULT_CODE in
pblock, if any.
2) replication: eliminated multimaster_betxnpreop_* which were
used for calling urp.  Urp needs to be processed at bepreop
timing.

Reviewed by Rich (Thank you!!)

https://fedorahosted.org/389/ticket/47367
Ticket #47435 - Very large entryusn values after enabling the USN plugin and the lastusn value is negative.

1. Bug description: The initial value of lastusn is -1, but since
the entryusn has the unsigned long long integer type, the server
returns 18446744073709551615 == 0XFFFFFFFFFFFFFFFF.

Fix description: The initial value "-1" is returned as it is.

2. Bug description: Entryusn syntax is defined as an integer in
the schema.  If negative values are accidentally stored in the
entryusn value in the database, it was casted to the unsigned
integer in the entryusn initialization code (usn_get_last_usn).

Fix description: When an entryusn value is retrieved from the
database, it's checked as a singed integer once and if it is
negative, it's replaced with the initial value "-1".

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

Reviewed by Mark and Rich (Thank you!!)