A small code snippet for client authorization using LDAP (verified with very exotic ActiveDirectory configuration where SynApse don't work, also with OpenLDAP). Consider client pass password in base64
LDAP connection string stored in config, example: aLDAPCfg.URL = 'ldaps://mydomain.com:636/DC=mydomain,DC=com?cn?sub?(sAMAccountName=%)'
curlHandle := curl.easy_init;
curlLdapURL := FormatUTF8(aLDAPCfg.URL, [aUserWODomain]);
curl.easy_setopt(curlHandle,coURL,pointer(curlLdapURL));
pwd := UTF8ToString(Base64ToBin(aPassWord));
if (pwd = '') then begin
Result := false;
errReason := FormatUTF8('LDAP anonymous logon attempt for %', [aUserName]);
end else begin
curlUserPwd := FormatUTF8('%:%', [aUserName, pwd]);
curl.easy_setopt(curlHandle, coUserPwd, pointer(curlUserPwd));
if (aLDAPCfg.ignoreSSLCertificateErrors) then begin
curl.easy_setopt(curlHandle, coSSLVerifyPeer, 0);
curl.easy_setopt(curlHandle, coSSLVerifyHost, 0);
end else if (aLDAPCfg.CAPath <> '') then
curl.easy_setopt(curlHandle, coCAPath, pointer(aLDAPCfg.CAPath));
curl.easy_setopt(curlHandle, coWriteFunction, @CurlWriteRawByteString);
curl.easy_setopt(curlHandle, coFile, @curlRespBody);
res := curl.easy_perform(curlHandle);
Result := (res = crOK);
if not Result then begin
Result := false;
errReason := FormatUTF8('LDAP libCurl error #%: %', [ord(res), curl.easy_strerror(res)]);
end;
end;
curl.easy_cleanup(curlHandle);
The ability to use CURL separately is a big feature.
]]>Please check https://synopse.info/fossil/info/0a257a244c
]]> /// low-level libcurl library file name, depending on the running OS
LIBCURL_DLL = {$ifdef Darwin} 'libcurl.dylib' {$else}
{$ifdef Linux} 'libcurl.so' {$else} 'libcurl-x64.dll' {$endif}{$endif};
What about Win32 platform? Is it no longer supported?
]]>Tested on both Windows & Linux with FPC compiler.
We switch to libcurl for accessing LDAP catalogues (instead of synApse 4) - in some catalogue configurations synapse does not work. Now I want to use libclurl for IMAP/POP/SMPT also
]]>The idea of creating a unit separates is great.
The implementation of Curl in Mormot is the best that exists for delphi / Lazarus. It deserves a specific unit.
]]>Perhaps a separated SynLibCurl or SynCurl unit will be made available.
]]>:-)
]]>Are any way to access internal record curl.easy_setopt... ?
I need this to set additional configuration to curl.
Perhaps by putting types and variables (TCurlOption, TCurlResult, curl, ...) in global scope.
]]>