Am working with windows server I want to create active directory lightweight service user by c ie, By c using ldap connection. My server runs in virtual box and i set the network adapter to be bridged network and it connects to the network just fine. Now when i used the code from microsoft documentation the ldap bind is not connecting .The error am getting is an operation error occured.
#include "atlbase.h"
#include "activeds.h"
int main(int argc, char* argv[])
{
HRESULT hr;
IADsContainer* pCont;
IDispatch* pDisp = NULL;
IADs* pUser;
// Initialize COM before calling any ADSI functions or interfaces.
CoInitialize(NULL);
hr = ADsGetObject(L"LDAP://ABC.local",
IID_IADsContainer,
(void**)&pCont);
if (!SUCCEEDED(hr))
{
return 0;
}
//-----------------
// Create a user
//-----------------
hr = pCont->Create(CComBSTR("user"), CComBSTR("cn=jeffsmith"), &pDisp);
// Release the container object.
pCont->Release();
if (!SUCCEEDED(hr))
{
return 0;
}
hr = pDisp->QueryInterface(IID_IADs, (void**)&pUser);
// Release the dispatch interface.
pDisp->Release();
if (!SUCCEEDED(hr))
{
return 0;
}
// Commit the object data to the directory.
pUser->SetInfo();
// Release the object.
pUser->Release();
CoUninitialize();
}
This is the code am using to check for successful connection. Any help will be really useful thank you.
CodePudding user response:
You're asking for a container (IID_IADsContainer
), but the path you give it is to the root of the domain (LDAP://ABC.local
). Try specifying the distinguished name of the OU you want to put the user in. For example, if you want to put the user in the Users
OU, which is at the root of the domain, it would look like this:
hr = ADsGetObject(L"LDAP://ABC.local/OU=Users,DC=ABC,DC=local",
IID_IADsContainer,
(void**)&pCont);
You can read more about the format of the LDAP path here: LDAP ADsPath