方法: 明示的な所有者権限の追加How-to: add explicit owner rights

アプリケーションでは、IpcCreateLicenseFromScratch を使って最初からライセンスを作成するときに、"所有者" 権限を明示的に追加する必要があります。Your application should explicitly add "Owner" rights when creating a license from scratch using IpcCreateLicenseFromScratch.

必須コンポーネントPrerequisites

アプリケーションで IpcCreateLicenseFromScratch を使ってライセンス ハンドルを作成するときは、所有者に完全な権限 (アクセス許可) も明示的に付与する必要があります。When your application is creating a license handle using IpcCreateLicenseFromScratch, it must also grant the owner full rights (permissions) explicitly.

注意

IpcSetLicensePropertyIPC_LI_OWNER プロパティを使ってユーザーを "所有者" として設定しても、所有者に完全なアクセス許可は付与されません。Setting a user as "owner" using IpcSetLicenseProperty with the IPC_LI_OWNER property does not grant the owner full permissions.

次のコード例には、特定の権限を作成して特定のライセンスに割り当てるための手順のみが示されています。The following example code only represents the steps involved in creating and adding the specific rights to a given license.

手順Instructions

手順 1:シナリオ例Step 1: Example scenario

この例では、IpcCreateLicenseFromScratch を使って作成したライセンスに必要な権限を追加しています。In this example, needed rights are added to a license created with IpcCreateLicenseFromScratch. この例は、権限の作成のほか、権限リストを使用したライセンスへの権限の割り当てを示しています。The example shows the creation and assignment of the rights to the license through a rights list.

次の 2 つの権限が次のユーザーに追加されます。The following two rights are added to these users:

  • 読み取りアクセス許可が joe@contoso.com に割り当てられます。Read permissions assigned to joe@contoso.com

  • 完全なアクセス許可が mary_kay@contoso.com に割り当てられます。Full permissions assigned to 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
    }