ldap remove some unneeded checks

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ldap remove some unneeded checks

Martijn van Duren-5
I found two minor issues and a nuisance with ldap(1).
Issues:
1) When searching a tree the DN that equals the searchdn is not shown,  
   resulting in weird (and incorrect) output. According to RFC2849 the
   DN must always be shown.
2) If we can't print a single element node we still print the version
   line. According to RFC2849 there needs to be at least one
   ldif-attrval-record to be valid.

The nuisance, even though correct (and what got me here in the first
place):
When running a search query with attribute 1.1 we don't print anything,
because every ldif-attrval-record requires one or more attrval-spec,
but with a filter of "1.1" we force ldapsearch to skip all attributes.
Since openldap and (from what I gather from the documentation)
idsldapsearch[0] support this behaviour I reckon we could also
implement this.

OK?

martijn@

[0] https://www.ibm.com/support/knowledgecenter/en/SSVJJU_6.4.0/com.ibm.IBMDS.doc_6.4/r_cr_ldapsearch.html

Index: ldapclient.c
===================================================================
RCS file: /cvs/src/usr.bin/ldap/ldapclient.c,v
retrieving revision 1.12
diff -u -p -r1.12 ldapclient.c
--- ldapclient.c 26 Jan 2019 10:58:54 -0000 1.12
+++ ldapclient.c 13 Feb 2019 13:33:33 -0000
@@ -296,14 +296,12 @@ ldapc_search(struct ldapc *ldap, struct
  struct aldap_page_control *pg = NULL;
  struct aldap_message *m;
  const char *errstr;
- const char *searchdn, *dn = NULL;
+ const char *searchdn;
  char *outkey;
  struct aldap_stringset *outvalues;
- int ret, code, fail = 0;
+ int ret, code, fail = 0, first = 1;
  size_t i;
 
- if (ldap->ldap_flags & F_LDIF)
- printf("version: 1\n");
  do {
  if (aldap_search(ldap->ldap_al, ls->ls_basedn, ls->ls_scope,
     ls->ls_filter, ls->ls_attr, 0, ls->ls_sizelimit,
@@ -343,20 +341,15 @@ ldapc_search(struct ldapc *ldap, struct
  goto fail;
  }
 
- if (aldap_count_attrs(m) < 1) {
- aldap_freemsg(m);
- continue;
- }
-
  if ((searchdn = aldap_get_dn(m)) == NULL)
  goto fail;
 
- if (dn != NULL)
- printf("\n");
- else
- dn = ls->ls_basedn;
- if (strcmp(dn, searchdn) != 0)
- printf("dn: %s\n", searchdn);
+ if (first) {
+ if (ldap->ldap_flags & F_LDIF)
+ printf("version: 1");
+ first = 0;
+ }
+ printf("\ndn: %s\n", searchdn);
 
  for (ret = aldap_first_attr(m, &outkey, &outvalues);
     ret != -1;