开发者

Retrieve User Entry IDs from MAPI

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 开发者_JAVA技巧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


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))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜