From b501e15fe98083a641e4000f8b7bb66a5ce771da Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Mon, 12 Jun 2006 08:30:07 +0000 Subject: prettify dissection of LDAP search filters. svn path=/trunk/; revision=18431 --- asn1/ldap/ldap.cnf | 119 ++++++++++++++++++++++++++++++++++++++- asn1/ldap/packet-ldap-template.c | 28 ++++++--- 2 files changed, 135 insertions(+), 12 deletions(-) (limited to 'asn1/ldap') diff --git a/asn1/ldap/ldap.cnf b/asn1/ldap/ldap.cnf index b35b57ebc5..8059256e42 100644 --- a/asn1/ldap/ldap.cnf +++ b/asn1/ldap/ldap.cnf @@ -248,7 +248,7 @@ ldap_conv_info_t *ldap_info; ldap_do_protocolop(pinfo); if(parameter_tvb) - ldapstring = tvb_get_string(parameter_tvb, 0, tvb_length_remaining(parameter_tvb, 0)); + ldapstring = tvb_get_ephemeral_string(parameter_tvb, 0, tvb_length_remaining(parameter_tvb, 0)); else ldapstring = ""; @@ -271,6 +271,12 @@ ldap_conv_info_t *ldap_info; if(ldm_tree) proto_item_append_text(ldm_tree, " \"%%s\"", ldapstring); + } else if (hf_index == hf_ldap_attributeDesc){ + /* remember the attribute description */ + attributedesc_string=ldapstring; + } else if (hf_index == hf_ldap_present){ + /* remember the present name */ + Filter_string=ldapstring; } else if (hf_index == hf_ldap_type) { /* remember attribute type name */ attr_type = ep_strdup(ldapstring); @@ -290,8 +296,6 @@ ldap_conv_info_t *ldap_info; } - if(parameter_tvb && ldapstring) - g_free(ldapstring); } #.FN_PARS T_scope VAL_PTR = &scope @@ -424,6 +428,115 @@ ldap_conv_info_t *ldap_info; ldap_do_protocolop(pinfo); + + + + +#.FN_HDR SearchRequest/filter + Filter_string=NULL; + +#.FN_FTR SearchRequest/filter + Filter_string=NULL; + and_filter_string=NULL; + +#.FN_FTR Filter/equalityMatch + Filter_string=ep_strdup_printf("(%s==%s)",attributedesc_string,assertionvalue_string); + + +#.FN_FTR Filter/greaterOrEqual + Filter_string=ep_strdup_printf("(%s>=%s)",attributedesc_string,assertionvalue_string); + + +#.FN_FTR Filter/lessOrEqual + Filter_string=ep_strdup_printf("(%s<=%s)",attributedesc_string,assertionvalue_string); + + +#.FN_FTR Filter/approxMatch + Filter_string=ep_strdup_printf("(%s~=%s)",attributedesc_string,assertionvalue_string); + +#.FN_BODY Filter/and/_item + offset=dissect_ldap_Filter(FALSE, tvb, offset, pinfo, tree, hf_ldap_and_item); + + if(and_filter_string){ + and_filter_string=ep_strdup_printf("%%s and %%s",and_filter_string,Filter_string); + } else { + and_filter_string=Filter_string; + } + +#.FN_BODY Filter/and + const ber_sequence_t and_set_of[1] = { { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_and_item }, +}; + proto_tree *tr=NULL; + proto_item *it=NULL; + char *old_and_filter_string=and_filter_string; + + and_filter_string=NULL; + if(tree){ + it=proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset), "and: "); + tr=proto_item_add_subtree(it, ett_ldap_T_and); + } + offset = dissect_ber_set_of(implicit_tag, pinfo, tr, tvb, offset, + and_set_of, -1, ett_ldap_T_and); + + proto_item_append_text(it, " %%s", and_filter_string); + Filter_string=ep_strdup_printf("(%%s)",and_filter_string); + and_filter_string=old_and_filter_string; + +#.FN_BODY Filter/or/_item + offset=dissect_ldap_Filter(FALSE, tvb, offset, pinfo, tree, hf_ldap_or_item); + + if(and_filter_string){ + and_filter_string=ep_strdup_printf("%%s and %%s",and_filter_string,Filter_string); + } else { + and_filter_string=Filter_string; + } + + +#.FN_BODY Filter/or + const ber_sequence_t or_set_of[1] = { { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_or_item }, +}; + proto_tree *tr=NULL; + proto_item *it=NULL; + char *old_and_filter_string=and_filter_string; + + and_filter_string=NULL; + if(tree){ + it=proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset), "or: "); + tr=proto_item_add_subtree(it, ett_ldap_T_or); + } + offset = dissect_ber_set_of(implicit_tag, pinfo, tr, tvb, offset, + or_set_of, -1, ett_ldap_T_or); + + proto_item_append_text(it, " %%s", and_filter_string); + Filter_string=ep_strdup_printf("(%%s)",and_filter_string); + and_filter_string=old_and_filter_string; + +#.FN_FTR Filter/present + Filter_string=ep_strdup_printf("is_present %s",Filter_string); + +#.FN_FTR Filter/not + Filter_string=ep_strdup_printf("not (%s)",Filter_string); + +#.FN_FTR Filter/extensibleMatch + Filter_string=""; + +#.FN_FTR Filter/substrings + Filter_string=""; + +#.FN_BODY Filter + proto_tree *tr=NULL; + proto_item *it=NULL; + + if(tree){ + it=proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset), "Filter: "); + tr=proto_item_add_subtree(it, ett_ldap_Filter); + } + offset = dissect_ber_choice(pinfo, tr, tvb, offset, + Filter_choice, -1, ett_ldap_Filter, + NULL); + + proto_item_append_text(it, "%%s", Filter_string); + #.NO_EMIT AttributeType Attribute diff --git a/asn1/ldap/packet-ldap-template.c b/asn1/ldap/packet-ldap-template.c index e77eac364a..6b2a894807 100644 --- a/asn1/ldap/packet-ldap-template.c +++ b/asn1/ldap/packet-ldap-template.c @@ -246,6 +246,8 @@ ldap_info_equal_unmatched(gconstpointer k1, gconstpointer k2) return key1->messageId==key2->messageId; } +/* This string contains the last AssertionValue that was decoded */ +static char *assertionvalue_string=NULL; /* if the octet string contain all ascii characters then display it as * a string othervise just display it in hex. */ @@ -256,7 +258,7 @@ dissect_ldap_AssertionValue(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset gboolean pc, ind, is_ascii; gint32 tag; guint32 len, i; - char *str, *new_str; + char *str; offset=get_ber_identifier(tvb, offset, &class, &pc, &tag); offset=get_ber_length(NULL, tvb, offset, &len, &ind); @@ -276,26 +278,34 @@ dissect_ldap_AssertionValue(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset /* convert the string into a printable string */ if(is_ascii){ - new_str=ep_alloc(len+1); + assertionvalue_string=ep_alloc(len+1); for(i=0;i