Creating home directories with permissions in ActiveDirectory using COM

Posted & filed under active directory, ADSI, C++, com, GADfly, integration.

Creating users in ActiveDirectory is pretty straightforward. You connect to the domain controller:

ADsOpenObject(m_connectionString,
             (LPCWSTR)m_username, (LPCWSTR)m_password,
             ADS_SECURE_AUTHENTICATION,
             IID_IADsContainer,
             (void**)&m_pContainer);

create the user, getting an IDispatch interface back:

m_pContainer->Create(CComBSTR("user"), CComBSTR(wcCN), &pDispatch);

query the IDispatch interface to get the IADsUser interface:

pDispatch->QueryInterface(IID_IADsUser, (void**)&pUser);

and use it to set the various properties of the new user object:

BSTR prop = SysAllocString(L"samAccountName");
var.vt = VT_BSTR;
var.bstrVal = SysAllocString(pUserDetails->GetUsername());
m_hr = pUser->Put(prop, var);
SysFreeString(prop);
VariantClear(&var);
if (!SUCCEEDED(m_hr)) {
  pUser->Release();
  return false;
} (more...)

Active Directory, ADSI, COM and C++

Posted & filed under active directory, ADSI, com, GADfly.

Well here I am, back in my Alma Mater, Windows, working on user account creation for Active Directory. The project I’ve called GADfly (Groupwise Active Directory on the fly). GADfly requires developing on Windows. Well it does and it doesn’t. I’ve already written a couple of Java creators to compare direct LDAPS and TLS which can run from any OS but I’ll need to create home directories and assign correct permissions, which requires ADSI, which is C++ and COM, which is Windows only. (more…)