]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ldap: fix `Curl_ldap_version()` for IBMi/OS400
authorAndrew <akirillo@uk.ibm.com>
Mon, 5 Jan 2026 18:00:20 +0000 (18:00 +0000)
committerViktor Szakats <commit@vsz.me>
Mon, 5 Jan 2026 22:10:47 +0000 (23:10 +0100)
- `LDAP_OPT_SUCCESS` (== 0) is missing from some LDAP implementations
  and documented to use `LDAP_SUCCESS` (== 0) instead. Use literal zero
  to avoid macro name differences.

- fix freeing `LDAP_OPT_API_INFO` buffers:
  - docs suggest `ldapai_vendor_name` on IBMi is `const char *`.
    Nothing in docs says it need to be freed.
  - `ldapai_extensions` need to be freed, according to docs.
    However, on IBMi there is `ldap_value_free()` function for it.
  Ref: https://www.ibm.com/docs/en/svd/10.0.3?topic=settings-ldap-opt-api-info

Fixing, on OS400 (V7R4M0):
```
CZM1003:  LDAP__819.c, 1028.56: CZM0045(30) Undeclared identifier LDAP_OPT_SUCCESS.
CZM1003:  LDAP__819.c, 1036.21: CZM0280(30) Function argument assignment between types "char*" and "const char*" is not allowed.
CZM1001:  LDAP__819.c, 1037.5: CZM0304(10) No function prototype given for "ber_memvfree".
...
CZS0601:  Module LDAP is not created because statement errors occurred.
```

Follow-up to 859ce48de12986f5bf846c2800dacab893ff12c1 #19832
Fixes #20188
Closes #20189

lib/ldap.c

index 71871fc742b19025c6ccd7d96f6257b8f0f030dd..55f39e147c97999c88476d7f1f0e34b3737008b6 100644 (file)
@@ -1022,7 +1022,9 @@ void Curl_ldap_version(char *buf, size_t bufsz)
   LDAPAPIInfo api;
   api.ldapai_info_version = LDAP_API_INFO_VERSION;
 
-  if(ldap_get_option(NULL, LDAP_OPT_API_INFO, &api) == LDAP_OPT_SUCCESS) {
+  /* Comparing against 0, as different platforms
+     disagree on the success define name */
+  if(ldap_get_option(NULL, LDAP_OPT_API_INFO, &api) == 0) {
     unsigned int patch = (unsigned int)(api.ldapai_vendor_version % 100);
     unsigned int major = (unsigned int)(api.ldapai_vendor_version / 10000);
     unsigned int minor =
@@ -1030,8 +1032,12 @@ void Curl_ldap_version(char *buf, size_t bufsz)
        - patch) / 100;
     curl_msnprintf(buf, bufsz, "%s/%u.%u.%u%s",
                    api.ldapai_vendor_name, major, minor, patch, flavor);
+#ifdef __OS400__
+    ldap_value_free(api.ldapai_extensions);
+#else
     ldap_memfree(api.ldapai_vendor_name);
     ber_memvfree((void **)api.ldapai_extensions);
+#endif
   }
   else
     curl_msnprintf(buf, bufsz, "LDAP/1");