本文整理汇总了C++中zimbra::util::ScopedInterface::Add方法的典型用法代码示例。如果您正苦于以下问题:C++ ScopedInterface::Add方法的具体用法?C++ ScopedInterface::Add怎么用?C++ ScopedInterface::Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zimbra::util::ScopedInterface
的用法示例。
在下文中一共展示了ScopedInterface::Add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateExchangeMailBox
HRESULT ExchangeAdmin::CreateExchangeMailBox(LPCWSTR lpwstrNewUser, LPCWSTR lpwstrNewUserPwd,
LPCWSTR lpwstrlogonuser, LPCWSTR lpwstrLogonUsrPwd)
{
HRESULT hr = S_OK;
// Get Logon user DN
wstring LogonUserDN;
wstring legacyName;
wstring msExchHomeSvrName;
Zimbra::MAPI::Util::GetUserDNAndLegacyName(m_strServer.c_str(), lpwstrlogonuser,
lpwstrLogonUsrPwd, LogonUserDN, legacyName);
Zimbra::MAPI::Util::GetmsExchHomeServerName(m_strServer.c_str(), lpwstrlogonuser,
lpwstrLogonUsrPwd, msExchHomeSvrName);
Zimbra::Util::ScopedInterface<IDirectoryObject> pLogonContainer;
Zimbra::Util::ScopedInterface<IADsUser> pIAdUser;
Zimbra::Util::ScopedInterface<IADs> pIAds;
wstring strContainer = L"LDAP://";
strContainer += LogonUserDN.c_str();
dloge("strContainer %S msExchHomeSvrName: %S", strContainer.c_str(), msExchHomeSvrName.c_str());
// Get loggedin user container
hr = ADsOpenObject(strContainer.c_str(), NULL, NULL, ADS_SECURE_AUTHENTICATION,
IID_IDirectoryObject, (void **)pLogonContainer.getptr());
if (FAILED(hr))
{
if (hr == 0x8007052e) // credentials are not valid
{
hr = ADsOpenObject((LPTSTR)strContainer.c_str(), lpwstrlogonuser, lpwstrLogonUsrPwd,
ADS_SECURE_AUTHENTICATION, IID_IDirectoryObject, (void **)pLogonContainer.getptr());
if (FAILED(hr)||(pLogonContainer.get()==NULL))
throw ExchangeAdminException(hr,L"CreateExchangeMailBox(): ADsOpenObject Failed.",
ERR_ADOBJECT_OPEN, __LINE__, __FILE__);
}
else
{
throw ExchangeAdminException(hr, L"CreateExchangeMailBox(): ADsOpenObject Failed.",
ERR_ADOBJECT_OPEN, __LINE__, __FILE__);
}
}
ADS_ATTR_INFO *pAttrInfo = NULL;
DWORD dwReturn;
LPWSTR pAttrNames[] = { L"mail", L"homeMDB", L"homeMTA" };
DWORD dwNumAttr = sizeof (pAttrNames) / sizeof (LPWSTR);
wstring strLogonHomeMDB;
wstring strLogonHomeMTA;
wstring strLogonMail;
// Get attribute values requested. Its not necessary the order is same as requested.
if (FAILED(hr = pLogonContainer->GetObjectAttributes(pAttrNames, dwNumAttr, &pAttrInfo,
&dwReturn)))
throw ExchangeAdminException(hr,L"CreateExchangeMailBox(): GetObjectAttributes Failed.",
ERR_CREATE_EXCHMBX, __LINE__, __FILE__);
for (DWORD idx = 0; idx < dwReturn; idx++)
{
if (_wcsicmp(pAttrInfo[idx].pszAttrName, L"mail") == 0)
strLogonMail = pAttrInfo[idx].pADsValues->Email.Address;
else if (_wcsicmp(pAttrInfo[idx].pszAttrName, L"homeMTA") == 0)
strLogonHomeMTA = pAttrInfo[idx].pADsValues->DNString;
else if (_wcsicmp(pAttrInfo[idx].pszAttrName, L"homeMDB") == 0)
strLogonHomeMDB = pAttrInfo[idx].pADsValues->DNString;
}
// Use FreeADsMem for all memory obtained from the ADSI call.
FreeADsMem(pAttrInfo);
wstring twtsrlogonuserDN = LogonUserDN;
size_t nPos = twtsrlogonuserDN.find(_T("DC="), 0);
wstring wstrServerDN = twtsrlogonuserDN.substr(nPos);
wstring wstrADSPath = _T("LDAP://CN=Users,") + wstrServerDN;
ADSVALUE cnValue;
ADSVALUE classValue;
ADSVALUE sAMValue;
ADSVALUE uPNValue;
ADSVALUE controlValue;
ADS_ATTR_INFO attrInfo[] = {
{ L"objectClass", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, &classValue, 1 },
{ L"cn", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, &cnValue, 1 },
{ L"sAMAccountName", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, &sAMValue, 1 },
{ L"userPrincipalName", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, &uPNValue, 1 },
{L"userAccountControl", ADS_ATTR_UPDATE, ADSTYPE_INTEGER,&controlValue, 1},
};
DWORD dwAttrs = sizeof (attrInfo) / sizeof (ADS_ATTR_INFO);
classValue.dwType = ADSTYPE_CASE_IGNORE_STRING;
classValue.CaseIgnoreString = L"user";
//int UF_ACCOUNTDISABLE = 0x0002;
int UF_PASSWD_NOTREQD = 0x0020;
//int UF_PASSWD_CANT_CHANGE = 0x0040;
int UF_NORMAL_ACCOUNT = 0x0200;
int UF_DONT_EXPIRE_PASSWD = 0x10000;
//int UF_PASSWORD_EXPIRED = 0x800000;
controlValue.dwType = ADSTYPE_INTEGER;
controlValue.Integer=UF_NORMAL_ACCOUNT | UF_PASSWD_NOTREQD |UF_DONT_EXPIRE_PASSWD;
cnValue.dwType = ADSTYPE_CASE_IGNORE_STRING;
//.........这里部分代码省略.........