Comment : ajouter des droits de propriétaire explicitesHow-to: add explicit owner rights

Votre application doit ajouter explicitement les droits « Owner » lors de la création d’une licence à partir de rien (à l’aide de IpcCreateLicenseFromScratch).Your application should explicitly add "Owner" rights when creating a license from scratch using IpcCreateLicenseFromScratch.

Conditions préalablesPrerequisites

Quand votre application crée un handle de licence en utilisant IpcCreateLicenseFromScratch, elle doit également accorder explicitement les droits (autorisations) complets de propriétaire.When your application is creating a license handle using IpcCreateLicenseFromScratch, it must also grant the owner full rights (permissions) explicitly.

Note

La définition d’un utilisateur comme « Owner » en utilisant IpcSetLicenseProperty avec la propriété IPC_LI_OWNER n’accorde pas toutes les autorisations de propriétaire.Setting a user as "owner" using IpcSetLicenseProperty with the IPC_LI_OWNER property does not grant the owner full permissions.

L’exemple de code suivant représente uniquement les étapes de création et d’ajout des droits spécifiques à une licence donnée.The following example code only represents the steps involved in creating and adding the specific rights to a given license.

InstructionsInstructions

Étape 1 : Exemple de scénarioStep 1: Example scenario

Dans cet exemple, les droits nécessaires sont ajoutés à une licence créée avec IpcCreateLicenseFromScratch.In this example, needed rights are added to a license created with IpcCreateLicenseFromScratch. L’exemple montre la création et l’attribution des droits à la licence via une liste de droits.The example shows the creation and assignment of the rights to the license through a rights list.

Les deux droits suivants sont ajoutés à ces utilisateurs :The following two rights are added to these users:

  • Autorisations de Lecture affectées à joe@contoso.comRead permissions assigned to joe@contoso.com
  • Autorisations Complètes affectées à mary_kay@contoso.comFull 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
    }
    

Rubriques connexesRelated topics

CommentairesComments

Avant de transmettre vos commentaires, nous vous demandons de consulter notre règlement interne.Before commenting, we ask that you review our House rules.