-/*
-** Escape a string with special LDAP characters. Returns NULL if the original
-** string does not have any special LDAP characters (so we don't allocate
-** memory unless absolutely necessary).
-*/
-
-static char *escape_str(const char *user)
-{
- int i;
- const char *p;
- char *q, *r;
-
- for (i=0, p=user; *p; p++)
- if (strchr("*()\\", *p))
- ++i;
-
- if (i == 0)
- return NULL; /* No need to escape anything */
-
- q=malloc(strlen(user)+i+1);
-
- if (!q)
- {
- perror("malloc");
- exit(1);
- }
-
- for (r=q, p=user; *p; p++)
- {
- if (strchr("*()\\", *p))
- *r++= '\\';
- *r++ = *p;
- }
- *r=0;
- return (q);
-}
-