SamAccountName = MYDOMAIN \ UserName, dc = MYDOMAIN, DC = local
This username format is incorrect. You do not need to specify sAMAccountName
in your username and you do not need to specify dc
if you are not using Distinguished Name
. You have few username options.
CN = Jeff Smith, OU = Sales, DC = Fabrikam, DC = Com
- sAMaccountName
Jsmith
- User path from previous version of Windows
"Fabrikam \ jeffsmith".
- Username (UPN)
jeffsmith@Fabrikam.com
Having said that, Iām not sure that the username is the only problem you have encountered. I do not run your code locally.
Although this answer cannot directly answer your question, since I have not tested this code on a Linux machine, it can give you an idea or put you in the right direction. I would not be surprised if this method is only for Windows.
According to MSDN, there are several methods
that you can use to authenticate a user.
The ADsOpenObject function is bound to an ADSI object using explicit username and password credentials.
This method takes the following parameters:
HRESULT ADsOpenObject( _In_ LPCWSTR lpszPathName, _In_ LPCWSTR lpszUserName, _In_ LPCWSTR lpszPassword, _In_ DWORD dwReserved, _In_ REFIID riid, _Out_ VOID **ppObject );
Using this method, you can bind to an object in Active Directory by specifying username
and password
.
If the binding is successful, the return code is S_OK
, otherwise you will receive different error messages.
I do not write programs in C++
on a daily basis. I usually work with Active Directory
and Active Directory Lightweight Services
in the C#
world. But this sample code that I wrote shows you how to call the ADsOpenObject
method to bind to an ADSI object using the specified credentials. In your case, just authenticate
.
#include <iostream> #include "activeds.h" using namespace std; int main(int argc, char* argv[]) { HRESULT hr; IADsContainer *pCont; IDispatch *pDisp = NULL; IADs *pUser; CoInitialize(NULL); hr = ADsOpenObject( L"LDAP://yourserver", L"username", L"password", ADS_FAST_BIND, //authentication option IID_IADs, (void**) &pUser); if (SUCCEEDED(hr)) { cout << "Successfully authenticated"; } else cout << "Incorrect username or password"; return hr; }
Depending on your setup, you may need to configure ADS_AUTHENTICATION_ENUM
. I suggest installing an SSL certificate and using the ADS_USE_SSL
binding. Working with non-SSL passwords in AD can be a nightmare.