* ldapServiceLookup * * Search the LDAP URL passed as first argument, treat the result as a * string of connection options that are parsed and added to the array of * options passed as second argument. * * LDAP URLs must conform to RFC 1959 without escape sequences. * ldap://host:port/dn?attributes?scope?filter?extensions * * Returns * 0 if the lookup was successful, * 1 if the connect
| 4864 | * An error message is appended to *errorMessage for return codes 1 and 3. |
| 4865 | */ |
| 4866 | static int |
| 4867 | ldapServiceLookup(const char *purl, PQconninfoOption *options, |
| 4868 | PQExpBuffer errorMessage) |
| 4869 | { |
| 4870 | int port = LDAP_DEF_PORT, |
| 4871 | scope, |
| 4872 | rc, |
| 4873 | size, |
| 4874 | state, |
| 4875 | oldstate, |
| 4876 | i; |
| 4877 | #ifndef WIN32 |
| 4878 | int msgid; |
| 4879 | #endif |
| 4880 | bool found_keyword; |
| 4881 | char *url, |
| 4882 | *hostname, |
| 4883 | *portstr, |
| 4884 | *endptr, |
| 4885 | *dn, |
| 4886 | *scopestr, |
| 4887 | *filter, |
| 4888 | *result, |
| 4889 | *p, |
| 4890 | *p1 = NULL, |
| 4891 | *optname = NULL, |
| 4892 | *optval = NULL; |
| 4893 | char *attrs[2] = {NULL, NULL}; |
| 4894 | LDAP *ld = NULL; |
| 4895 | LDAPMessage *res, |
| 4896 | *entry; |
| 4897 | struct berval **values; |
| 4898 | LDAP_TIMEVAL time = {PGLDAP_TIMEOUT, 0}; |
| 4899 | |
| 4900 | if ((url = strdup(purl)) == NULL) |
| 4901 | { |
| 4902 | appendPQExpBufferStr(errorMessage, libpq_gettext("out of memory\n")); |
| 4903 | return 3; |
| 4904 | } |
| 4905 | |
| 4906 | /* |
| 4907 | * Parse URL components, check for correctness. Basically, url has '\0' |
| 4908 | * placed at component boundaries and variables are pointed at each |
| 4909 | * component. |
| 4910 | */ |
| 4911 | |
| 4912 | if (pg_strncasecmp(url, LDAP_URL, strlen(LDAP_URL)) != 0) |
| 4913 | { |
| 4914 | appendPQExpBuffer(errorMessage, |
| 4915 | libpq_gettext("invalid LDAP URL \"%s\": scheme must be ldap://\n"), purl); |
| 4916 | free(url); |
| 4917 | return 3; |
| 4918 | } |
| 4919 | |
| 4920 | /* hostname */ |
| 4921 | hostname = url + strlen(LDAP_URL); |
| 4922 | if (*hostname == '/') /* no hostname? */ |
| 4923 | hostname = DefaultHost; /* the default */ |
no test coverage detected