Issue 5198 - wrong SQL-Statements in Back-SQL
Summary: wrong SQL-Statements in Back-SQL
Status: VERIFIED SUSPENDED
Alias: None
Product: OpenLDAP
Classification: Unclassified
Component: slapd (show other issues)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: OpenLDAP project
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-23 14:21 UTC by peter.gietz@daasi.de
Modified: 2020-06-26 15:05 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description peter.gietz@daasi.de 2007-10-23 14:21:11 UTC
Full_Name: Peter Gietz
Version: 2.3.38
OS: Linux
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (84.154.95.209)


This bug report was given to me at the OpenLDAP booth on the Systems in Munich.

SQL search-statements are wrong because of a strange OR condition: 
"(2=2 OR (ldap_entries.id=ldap_entry_objclasses.entry_id AND
ldap_entry_objclasses.oc_name='"

So instead of a subset, all data are included in the response. Thats what the
guy, who was too lazy to make the bug report himself told me. He also told me
that he patched his code (by deleting the condition (2=2)  and is happy for
now.

If you think this is a bug, please repair.

I found this in the source code (.../slapd/back-sql/search.c (lines 780-805): 
(not sure if this is the only occurance)


			/*
			 * "structural" objectClass inheritance:
			 * - a search for "person" will also return 
			 *   "inetOrgPerson"
			 * - a search for "top" will return everything
			 */
 			if ( is_object_subclass( oc, bsi->bsi_oc->bom_oc ) ) {
				static struct berval ldap_entry_objclasses = BER_BVC(
"ldap_entry_objclasses" );

				backsql_merge_from_tbls( bsi, &ldap_entry_objclasses );

				backsql_strfcat_x( &bsi->bsi_flt_where,
						bsi->bsi_op->o_tmpmemctx,
						"lbl",
						(ber_len_t)STRLENOF( "(2=2 OR
(ldap_entries.id=ldap_entry_objclasses.entry_id AND
ldap_entry_objclasses.oc_name='" /* ')) */ ),
							"(2=2 OR (ldap_entries.id=ldap_entry_objclasses.entry_id AND
ldap_entry_objclasses.oc_name='" /* ')) */,
						&bsi->bsi_oc->bom_oc->soc_cname,
						(ber_len_t)STRLENOF( /* ((' */ "'))" ),
							/* ((' */ "'))" );
				bsi->bsi_status = LDAP_SUCCESS;
				rc = 1;
				goto done;
			}

			break;
		}



Comment 1 ando@openldap.org 2007-10-24 08:15:33 UTC
changed notes
changed state Open to Suspended
moved from Incoming to Software Enhancements
Comment 2 ando@openldap.org 2007-10-24 08:18:12 UTC
peter.gietz@daasi.de wrote:

> This bug report was given to me at the OpenLDAP booth on the Systems in Munich.
> 
> SQL search-statements are wrong because of a strange OR condition: 
> "(2=2 OR (ldap_entries.id=ldap_entry_objclasses.entry_id AND
> ldap_entry_objclasses.oc_name='"
> 
> So instead of a subset, all data are included in the response.

It is not a bug, but rather an easy means to indicate that the whole
data should be returned to the frontend in order to filter it the LDAP
way, since sub-classing might be involved.  If that user doesn't want
searches for (objectClass=person) to return objects with
objectClass=inetOrgPerson, then he shouldn't be using LDAP.

> Thats what the
> guy, who was too lazy to make the bug report himself told me. He also told me
> that he patched his code (by deleting the condition (2=2)  and is happy for
> now.

Well, you see: open source software makes people happy.

As a side note, usually, well-designed RDBMSes understand that 2=2 is
always true and do not proceed any further in evaluating other clauses
in the OR.  For those RDBMSes this causes a performance degradation
(and, I insist, it would be the RDBMS' fault) the only **improvement**
to OpenLDAP's back-sql (no bug) could consist in detecting that
condition ourselves and omit that part of the WHERE clause entirely.
But this would probably require to rewrite the filter translation layer,
and it's not something I plan to do any soon (unless rewarded enough to
distract me from other issues, I mean).

p.



Ing. Pierangelo Masarati
OpenLDAP Core Team

SysNet s.r.l.
via Dossi, 8 - 27100 Pavia - ITALIA
http://www.sys-net.it
---------------------------------------
Office:  +39 02 23998309
Mobile:  +39 333 4963172
Email:   pierangelo.masarati@sys-net.it
---------------------------------------


Comment 3 OpenLDAP project 2014-08-01 21:04:53 UTC
not a bug
needed by sub-classing
room for performance improvements