从 MAPI 检索用户条目 ID

发布于 2024-09-24 00:44:30 字数 1949 浏览 7 评论 0原文

我使用接口 IExchangeModifyTable 扩展了 win32comext MAPI,以通过 MAPI 编辑 ACL。我可以修改现有的 ACL 条目,但我坚持添加新条目。我需要用户条目 ID 来添加它,根据此 C 示例

(来自 MSDN 的示例源

STDMETHODIMP AddUserPermission(
   LPSTR szUserAlias, 
   LPMAPISESSION lpSession,
   LPEXCHANGEMODIFYTABLE lpExchModTbl, 
   ACLRIGHTS frights)
{
 HRESULT     hr = S_OK;
 LPADRBOOK   lpAdrBook;  
 ULONG       cbEid;
 LPENTRYID   lpEid = NULL;
 SPropValue  prop[2] = {0};
 ROWLIST     rowList  = {0};

 char szExName[MAX_PATH]; 
 // Replace with "/o=OrganizationName/ou=SiteName/cn=Recipients/cn="
 char* szServerDN = "/o=org/ou=site/cn=Recipients/cn=";

 strcpy(szExName, szServerDN);
 strcat(szExName, szUserAlias);

 // Open the address book.
 hr = lpSession->OpenAddressBook(0,
                                 0, 
                                 MAPI_ACCESS_MODIFY, 
                                 &lpAdrBook );
 if ( FAILED( hr ) ) goto cleanup;

 // Obtain the entry ID for the recipient.
 hr = HrCreateDirEntryIdEx(lpAdrBook, 
                           szExName, 
                           &cbEid, 
                           &lpEid);
 if ( FAILED( hr ) ) goto cleanup;

 prop[0].ulPropTag  = PR_MEMBER_ENTRYID;
 prop[0].Value.bin.cb = cbEid;
 prop[0].Value.bin.lpb = (BYTE*)lpEid;
 prop[1].ulPropTag  = PR_MEMBER_RIGHTS;
 prop[1].Value.l   = frights;

 rowList.cEntries = 1;
 rowList.aEntries->ulRowFlags = ROW_ADD;
 rowList.aEntries->cValues  = 2;
 rowList.aEntries->rgPropVals = &prop[0]; 

 hr = lpExchModTbl->ModifyTable(0, &rowList);
 if(FAILED(hr)) goto cleanup;
 printf("Added user permission. \n");

cleanup:
 if (lpAdrBook)
  lpAdrBook->Release();
 return hr;
}

我可以打开地址簿,但 pywin32 mapi 中未提供 HrCreateDirEntryIdEx。我在交换扩展中找到了它,它在我的系统上无法编译,缺少库问题。您有办法检索用户条目 ID 吗?

感谢。

  • 帕特里克

I extended the win32comext MAPI with the Interface IExchangeModifyTable to edit ACLs via the MAPI. I can modify existing ACL entries, but I stuck in adding new entries. I need the users entry ID to add it, according this C example

(Example Source from MSDN)

STDMETHODIMP AddUserPermission(
   LPSTR szUserAlias, 
   LPMAPISESSION lpSession,
   LPEXCHANGEMODIFYTABLE lpExchModTbl, 
   ACLRIGHTS frights)
{
 HRESULT     hr = S_OK;
 LPADRBOOK   lpAdrBook;  
 ULONG       cbEid;
 LPENTRYID   lpEid = NULL;
 SPropValue  prop[2] = {0};
 ROWLIST     rowList  = {0};

 char szExName[MAX_PATH]; 
 // Replace with "/o=OrganizationName/ou=SiteName/cn=Recipients/cn="
 char* szServerDN = "/o=org/ou=site/cn=Recipients/cn=";

 strcpy(szExName, szServerDN);
 strcat(szExName, szUserAlias);

 // Open the address book.
 hr = lpSession->OpenAddressBook(0,
                                 0, 
                                 MAPI_ACCESS_MODIFY, 
                                 &lpAdrBook );
 if ( FAILED( hr ) ) goto cleanup;

 // Obtain the entry ID for the recipient.
 hr = HrCreateDirEntryIdEx(lpAdrBook, 
                           szExName, 
                           &cbEid, 
                           &lpEid);
 if ( FAILED( hr ) ) goto cleanup;

 prop[0].ulPropTag  = PR_MEMBER_ENTRYID;
 prop[0].Value.bin.cb = cbEid;
 prop[0].Value.bin.lpb = (BYTE*)lpEid;
 prop[1].ulPropTag  = PR_MEMBER_RIGHTS;
 prop[1].Value.l   = frights;

 rowList.cEntries = 1;
 rowList.aEntries->ulRowFlags = ROW_ADD;
 rowList.aEntries->cValues  = 2;
 rowList.aEntries->rgPropVals = &prop[0]; 

 hr = lpExchModTbl->ModifyTable(0, &rowList);
 if(FAILED(hr)) goto cleanup;
 printf("Added user permission. \n");

cleanup:
 if (lpAdrBook)
  lpAdrBook->Release();
 return hr;
}

I can open the Address Book, but HrCreateDirEntryIdEx is not provided in the pywin32 mapi. I found it in the exchange extension, which does not compile on my system, the missing library problem. Do you have any idea to retrieve the users entry ID?

Thank.

  • Patrick

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

机场等船 2024-10-01 00:44:30

我得到了这段代码并且运行良好

from binascii import b2a_hex, a2b_hex
import active_directory as ad


# entry_type, see http://msdn.microsoft.com/en-us/library/cc840018.aspx
#  + AB_DT_CONTAINER     0x000000100
#  + AB_DT_TEMPLATE      0x000000101
#  + AB_DT_OOUSER        0x000000102
#  + AB_DT_SEARCH        0x000000200
# ab_flags, maybe see here: https://svn.openchange.org/openchange/trunk/libmapi/mapidefs.h

def gen_exchange_entry_id(user_id, ab_flags=0, entry_type = 0):
    muidEMSAB = "DCA740C8C042101AB4B908002B2FE182"
    version = 1

    # Find user and bail out if it's not there
    ad_obj = ad.find_user(user_id)
    if not ad_obj:
        return None

    return "%08X%s%08X%08X%s00" % (
        ab_flags,
        muidEMSAB,
        version,
        entry_type,
        b2a_hex(ad_obj.legacyExchangeDN.upper()).upper(),
    )

data = gen_exchange_entry_id("myusername")
print data 
print len(a2b_hex(data))

I got this piece of code and it works fine

from binascii import b2a_hex, a2b_hex
import active_directory as ad


# entry_type, see http://msdn.microsoft.com/en-us/library/cc840018.aspx
#  + AB_DT_CONTAINER     0x000000100
#  + AB_DT_TEMPLATE      0x000000101
#  + AB_DT_OOUSER        0x000000102
#  + AB_DT_SEARCH        0x000000200
# ab_flags, maybe see here: https://svn.openchange.org/openchange/trunk/libmapi/mapidefs.h

def gen_exchange_entry_id(user_id, ab_flags=0, entry_type = 0):
    muidEMSAB = "DCA740C8C042101AB4B908002B2FE182"
    version = 1

    # Find user and bail out if it's not there
    ad_obj = ad.find_user(user_id)
    if not ad_obj:
        return None

    return "%08X%s%08X%08X%s00" % (
        ab_flags,
        muidEMSAB,
        version,
        entry_type,
        b2a_hex(ad_obj.legacyExchangeDN.upper()).upper(),
    )

data = gen_exchange_entry_id("myusername")
print data 
print len(a2b_hex(data))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文