如何:新增明確的擁有者權限
重要
2020 年 3 月之前發行的 Microsoft Rights Management Service SDK 版本已被取代;使用舊版的應用程式必須更新為使用 2020 年 3 月版本。 如需完整詳細資料,請參閱 淘汰通知。
Microsoft Rights Management Service SDK 沒有進一步的增強功能。 我們強烈建議採用Microsoft 資訊保護 SDK來分類、標記和保護服務。
您的應用程式在使用 IpcCreateLicenseFromScratch從頭開始建立授權時,應該明確新增「擁有者」許可權。
必要條件
當您的應用程式正在使用 IpcCreateLicenseFromScratch 建立授權控制代碼時,它也必須明確授與擁有者完整權限 (權限)。
注意
使用 IpcSetLicenseProperty 搭配 IPC_LI_OWNER 屬性將 使用者設定為「擁有者」,並不會授與擁有者完整許可權。
下列範例程式碼僅代表涉及建立特定權限並將其加入指定授權中的步驟。
指示
步驟 1:範例案例
此範例中,會在以 IpcCreateLicenseFromScratch 建立的授權中加入需要的權限。 此範例顯示透過權限清單建立權限並指派給授權。
下列兩個權限會新增給這些使用者︰
- 指派給 joe@contoso.com 的「讀取」權限
- 指派給的完整許可權mary_kay@contoso.com
// Create User Rights structure
IPC_USER_RIGHTS ownerRightForOwner = {0};
// Create rights
LPCWSTR rgwszOwnerRights[1] = {IPC_GENERIC_ALL};
// Assign values to members of Rights structure
ownerRightForOwner.User.dwType = IPC_USER_TYPE_IPC;
ownerRightForOwner.User.wszID = IPC_USER_ID_OWNER;
ownerRightForOwner.rgwszRights = rgwszOwnerRights;
ownerRightForOwner.cRights = 1;
// Create User Rights structure for Joe with Read permissions
IPC_USER_RIGHTS joeReadRight = {0};
LPCWSTR rgwszReadRights[1] = {IPC_GENERIC_READ};
// Assign values to members of Rights structure for Joe
joeReadRight.User.dwType = IPC_USER_TYPE_EMAIL;
joeReadRight.User.wszID = "joe@contoso.com";
joeReadRight.rgwszRights = rgwszReadRights;
joeReadRight.cRights = 1;
// Create User Rights structure for Mary Kay with Full permissions
IPC_USER_RIGHTS mary_kayFullRight = {0};
LPCWSTR rgwszFullRights[1] = {IPC_GENERIC_ALL};
// Assign values to members of Rights structure for Mary Kay
mary_kayFullRight.User.dwType = IPC_USER_TYPE_EMAIL;
mary_kayFullRight.User.wszID = L"mary_kay@contoso.com";
mary_kayFullRight.rgwszRights = rgwszFullRights;
mary_kayFullRight.cRights = 1;
// Create User Rights List and assign the above rights
size_t uNoOfUserRights = 3;
PIPC_USER_RIGHTS_LIST pUserRightsList = NULL;
pUserRightsList = reinterpret_cast<PIPC_USER_RIGHTS_LIST>
(new BYTE[ sizeof(IPC_USER_RIGHTS_LIST) + uNoOfUserRights * sizeof(IPC_USER_RIGHTS)]);
if(pUserRightsList == NULL)
{
// Handle error
}
// Assign values to members of Rights List structure for Joe and Mary Kay
(*pUserRightsList).cbSize = sizeof(IPC_USER_RIGHTS_LIST);
(*pUserRightsList).cUserRights = uNoOfUserRights;
(*pUserRightsList).rgUserRights[0] = ownerRightForOwner;
(*pUserRightsList).rgUserRights[1] = joeReadRight;
(*pUserRightsList).rgUserRights[2] = mary_kayFullRight;
// Set the Rights List property on the license via its handle
// hLicense is a license handle created with IpcCreateLicenseFromScratch
hr = IpcSetLicenseProperty(hLicense, FALSE, IPC_LI_USER_RIGHTS_LIST, pUserRightsList);
if(FAILED(hr))
{
// Handle the error
}