OVH Cloud OVH Cloud

Erreur 5 sur Mailslot

2 réponses
Avatar
Christian
Bonjour

J'ai un problème de droits d'accès sur un Mailslot. (Windows 2000 serveur,
tests ci desous, serveur et client sur la même machine)

- un process serveur Mailsolt, droit administrateur (CreateMailslot,
ReadFile)
- un process client du Mailslot, droit Utilisateur, reçoit une erreur 5
(accès refusé) au CreateFile sur le MailSlot. Si le MailSlot est créé aussi
en Utilisateur par contre ça passe. J'aimerais éviter ça en donnant les
droits non limités d'accès au Mailslot. (si c'est le problème).

J'ai essayé de nombreuses combinaisons avec les ACL créé avec
AllocateAndInitializeSid() avec SECURITY_WORLD_RID (EveryOne) etc... sur le
HANDLE du Mailslot, sans plus de succès. Le SECURITY_ATTRIBUTES du
CreateMailslot ne prenant pas en compte le "lpSecurityDescriptor" je suis
passé par SetSecurityInfo. Je ne sais pas trop si c'est le bon procécé.

Je précise que j'ai des services en LocalSystem qui accèdent sans erreur au
Mailslot.

Merci d'avance de toute suggestion.

2 réponses

Avatar
Olivier Huet
Christian a écrit :

J'ai essayé de nombreuses combinaisons avec les ACL créé avec
AllocateAndInitializeSid() avec SECURITY_WORLD_RID (EveryOne) etc... sur le
HANDLE du Mailslot, sans plus de succès. Le SECURITY_ATTRIBUTES du
CreateMailslot ne prenant pas en compte le "lpSecurityDescriptor" je suis
passé par SetSecurityInfo. Je ne sais pas trop si c'est le bon procécé.



J'ai piqué un bout de code - qui demanderait d'être retouché pour être
plus beau - dans un bouquin.

En tout les cas, je viens de faire un test sur un 2003, et ça marche
(alors que çà ne marche pas en mettant NULL) :

#include <iostream>

#include <tchar.h>
#include <windows.h>
#include <aclapi.h>


DWORD TestACL()
{
DWORD dwError = S_OK;
PSID pEveryoneSID = NULL;
PACL pACL = NULL;
PSECURITY_DESCRIPTOR pSD = NULL;

try {
const int NUM_ACES = 1;
EXPLICIT_ACCESS ea[NUM_ACES];
ZeroMemory(&ea, NUM_ACES * sizeof(EXPLICIT_ACCESS)) ;

//Create a well-known SID for the Everyone group.
SID_IDENTIFIER_AUTHORITY SIDAuthWorld SECURITY_WORLD_SID_AUTHORITY;
if (!AllocateAndInitializeSid(&SIDAuthWorld, 1,
SECURITY_WORLD_RID,
0, 0, 0, 0, 0, 0, 0,
&pEveryoneSID) )
{
throw GetLastError();
}

ea[0].grfAccessPermissions = GENERIC_ALL;
ea[0].grfAccessMode = SET_ACCESS;
ea[0].grfInheritance= NO_INHERITANCE;
ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
ea[0].Trustee.ptstrName = (LPTSTR) pEveryoneSID;

//Create a new ACL with the three ACEs.
if (ERROR_SUCCESS != SetEntriesInAcl(NUM_ACES,
ea,
NULL,
&pACL))
{
throw GetLastError();
}

//Initialize a security descriptor.
pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR,
SECURITY_DESCRIPTOR_MIN_LENGTH);
if (pSD == NULL)
{
throw GetLastError();
}

if (!InitializeSecurityDescriptor(pSD,
SECURITY_DESCRIPTOR_REVISION))
{
throw GetLastError();
}

//Add the ACL to the security descriptor.
if (!SetSecurityDescriptorDacl(pSD,
TRUE, //fDaclPresent flag
pACL,
FALSE))
{
throw GetLastError();
}
else
{
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = FALSE;
sa.lpSecurityDescriptor = pSD;

HANDLE handle = CreateMailslot(
_T("\.mailslottestMailSlot"),
1000,
MAILSLOT_WAIT_FOREVER,
&sa);
if (handle == INVALID_HANDLE_VALUE)
{
throw GetLastError();
}
}
} catch(DWORD dwLastError) {
dwError = dwLastError;
}

if (pSD)
LocalFree(pSD);

if (pACL)
LocalFree(pACL);

//Call FreeSID for each SID allocated by AllocateAndInit ializeSID.
if (pEveryoneSID)
FreeSid(pEveryoneSID);

return dwError;
}

void main()
{
int toto;
std::cout <<"retour : " << TestACL();
std::cin >>toto;
}


--
Olivier Huet
Avatar
Christian
Merci olivier, ça marche, les process de tous comptes accèdent à l'objet.

J'ai simplifié SetSecurityDescriptorDacl car un DACL NULL donne tous les
accès. Donc pas la peine d'en créer un.

PSECURITY_DESCRIPTOR pSD= (PSECURITY_DESCRIPTOR)LocalAlloc(LPTR,
SECURITY_DESCRIPTOR_MIN_LENGTH);

InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION);

SetSecurityDescriptorDacl(pSD,
true,
NULL, // NULL = tous les accès pACL,
false);

SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof (SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = false;

HANDLE hMailSlot= CreateMailslot (
NameMailSlotLog, // mailslot name
0, // maximum message size
MAILSLOT_WAIT_FOREVER, // read time-out interval
&sa // inheritance option
);