wheelybird / ldap-user-manager

A PHP web-based interface for LDAP user account management and self-service password change.
MIT License
480 stars 106 forks source link

Use special characters / template parameters / escape sequences in default values of custom attribute #227

Open marcel-sachtleben opened 1 week ago

marcel-sachtleben commented 1 week ago

Version Latest Docker Image (Container SHA: sha256:5987992f57267ae4360b82caa40b2eb90598560e51f6826926f8f385cbcec52b)

Describe the bug When I use default attributes with labels, values and defaults, I am neither able to use pre-defined variables like {first_name} or {last_name} nor can I use special characters like ":" since it is already the delimiter of the triplet "attribute:label:default"

How can I escape special characters and make default template substitution work?

Example 1: LDAP_ACCOUNT_ADDITIONAL_ATTRIBUTES: "mailHomeDirectory:Mail Home Directory:/var/mail/alpha-architect.com/{first_name}.{last_name}"

If I use e.g. First Name = Marcel Last Name = Sachtleben

it will still fill the value "var/mail/alpha-architect.com/{first_name}.{last_name}" without replacing the template parameters.

I have tried escaping "{" and "}" with backslash \ and I have also tried adding a "$" in front of the curly braces with no success.

Example 2: LDAP_ACCOUNT_ADDITIONAL_ATTRIBUTES: "mailStorageDirectory:Mail Storage Directory:maildir:~/mail"

Problem here is that the default value "maildir:~/mail" contains a colon ":" which I have no idea, how to escape. Backslash is treated as normal character.

Meaning, the value is set to "maildir" because it cuts the last part with ":~/mail". Probably the code is splitting by ":" and uses the first 3 parts, ignoring the 4th part in this case.

Can you please give me a solution to be able to use default template variables and special characters in custom attributes default values?

wheelybird commented 8 hours ago

Hi. The additional attributes can only take literal strings, so it's not possible to use the template macro names for that. Only specific LDAP attributes are able to use the USERNAME_FORMAT template. You're right that the code splits the additional attributes using the colon, and so anything past the third colon will be ignored. I'll update the code to allow for escaping colons.