[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: what is the pretty function and the validate function in OpenLDAP?



> Hi, all,
>
> I'm trying to understand the internal workflow of the attribute type
> checking and syntax validation in OpenLDAP. For example, if I use an
> attribute whose syntax is not implemented like "presentationAddress", the
> log message "no validator for syntax" will occur.
>
> I trace this message in the source code and find this's done by checking
> "pretty" and "validate", as follows:
>
> -------------------------------------servers/slapd/modify.c--------------------------------
>
> slap_syntax_validate_func *validate
> = ad->ad_type->sat_syntax->ssyn_validate;
> slap_syntax_transform_func *pretty = ad->ad_type->sat_syntax->ssyn_pretty;
>
> if( !pretty && !validate ) {
>      *text = "no validator for syntax";
>      snprintf( textbuf, textlen,
>                   "%s: no validator for syntax %s",
>                   ml->sml_type.bv_val,
>                   ad->ad_type->sat_syntax->ssyn_oid );
>      *text = textbuf;
>      return LDAP_INVALID_SYNTAX;
> }
>
> -----------------------------------------------------------------------------------------------------
>
> Moreover, the pretty function and validate function are treat differently
> in the latter code like:
>
> if ( pretty ) {
>      rc = ordered_value_pretty( ad, &ml->sml_values[nvals], &pval, ctx );
> // wrapper for pretty function
> } else {
>      rc = ordered_value_validate( ad, &ml->sml_values[nvals], ml->sml_op
> );
> // wrapper for validate function
> }
>
> I'm very confused on the "pretty" function and the "validate" function. I
> tried to google but no related results.
>
> Could anyone tell me WHAT is the pretty function and what is the validate
> function? And HOW can OpenLDAP knows which function is pretty and which is
> validate?

"validate" simply checks that a value conforms to the syntax.  "pretty"
modifies the value, if needed, to turn it into a normal form for that
syntax.  For example, the "validate" of UUID simply checks its value; the
"pretty" of UUID turns all hexadecimal digits 'A' to 'F' into the lower
form 'a' to 'f'.  "pretty" should not be confused with a normalization. 
Functions belonging to a specific syntax are hardcoded in Syntax
structures.  You can find examples of run-time registration of new
syntaxes for example in slapd/aci.c

p.