begin process at 2012 02 09 07:39:18
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Système

 > LISTER LES USERS ET LES PERMISSIONS DES DOSSIERS PARTAGÉS D'UN ORDI RÉSEAU (OU PAS : ))

LISTER LES USERS ET LES PERMISSIONS DES DOSSIERS PARTAGÉS D'UN ORDI RÉSEAU (OU PAS : ))


 Information sur la source

Note :
Aucune note
Catégorie :Système Niveau :Initié Date de création :15/12/2003 Vu / téléchargé :5 109 / 302

Auteur : radada

Ecrire un message privé
Site perso
Commentaire sur cette source (3)
Ajouter un commentaire et/ou une note

 Description

N'ayant pas eu de réponse suite à une question sur le forum sur comment lister les permissions de tous les users des dossiers partagés d'un ordi, il a bien fallu que je démerde +/- tout seul. Voici donc la solution. Vraiment pas super facile, merci Microsoft, comme d'hab : (((

Source

  • #define _WIN32_WINNT 0x0500
  • #include <windows.h>
  • #include <stdio.h>
  • #include <aclapi.h>
  • #include <lmshare.h>
  • #include <Lm.h>
  • #include "NetEnum.h"
  • /***************************************/
  • /***************************************/
  • /* CountNetShareEnum */
  • /***************************************/
  • /***************************************/
  • DWORD CountNetShareEnum
  • (
  • const char* p_pcServerName,
  • int* p_TotalOfShareRessource
  • )
  • {
  • PSHARE_INFO_502 l_PShareInfo, l_BufPShareInfo;
  • NET_API_STATUS l_nStatus;
  • DWORD l_dwErr=0,l_dwTr=0,l_dwResume=0, i;
  • LPWSTR l_pwUnicodeServerName = NULL;
  • int l_iSize;
  • try
  • {
  • // si on entre un nom de PC, on transforme le nom AINSI en UNICODE
  • if (p_pcServerName != NULL)
  • {
  • l_iSize = strlen (p_pcServerName) + 1;
  • l_pwUnicodeServerName = new WORD [l_iSize];
  • l_pwUnicodeServerName[0] = 0;
  • MultiByteToWideChar (CP_ACP, 0, p_pcServerName, -1, l_pwUnicodeServerName, l_iSize);
  • }
  • do // begin do
  • {
  • // on liste tout ou partie des dossiers partagés de p_pcServerName
  • l_nStatus = NetShareEnum (l_pwUnicodeServerName, 502, (LPBYTE *) &l_BufPShareInfo, -1, &l_dwErr, &l_dwTr, &l_dwResume);
  • if(l_nStatus != ERROR_SUCCESS && l_nStatus != ERROR_MORE_DATA)
  • throw l_nStatus;
  • // on fait pointer l_PShareInfo sur les données trouvées
  • l_PShareInfo=l_BufPShareInfo;
  • // pour chaque entrée trouvée (jusqu'à dwErr) on incrémente
  • for(i=1;i<=l_dwErr;i++)
  • {
  • l_PShareInfo++;
  • (*p_TotalOfShareRessource) ++;
  • }
  • // on libère le buffer
  • NetApiBufferFree(l_BufPShareInfo);
  • }
  • while (l_nStatus==ERROR_MORE_DATA);
  • }
  • catch (DWORD)
  • {
  • }
  • return l_nStatus;
  • }
  • /***************************************/
  • /***************************************/
  • /* CountNetShareEnum */
  • /***************************************/
  • /***************************************/
  • DWORD RetrieveNetShareEnum
  • (
  • const char* p_pcServerName,
  • const int p_TotalOfShareRessource,
  • int* p_piCurrentIndex,
  • STL_SHARE_INFO* p_ShareInfoArray
  • )
  • {
  • PSHARE_INFO_502 l_PShareInfo, l_BufPShareInfo;
  • NET_API_STATUS l_nStatus;
  • DWORD l_dwCount=0,l_dwTr=0,l_dwResume=0, i;
  • DWORD l_dwRetVal;
  • LPWSTR l_pwUnicodeServerName = NULL;
  • LPWSTR l_pwUnicodeRemark = NULL;
  • LPWSTR l_pwUnicodePath = NULL;
  • LPWSTR l_pwUnicodePassword = NULL;
  • BOOL l_bRetVal;
  • PACL l_Dacl;
  • int l_iSize, l_iTotalEntriesIndex;
  • unsigned long l_ulNbOfEntries = 0;
  • PEXPLICIT_ACCESS l_oAccessArray = NULL;
  • try
  • {
  • // si on entre un nom de PC, on transforme le nom AINSI en UNICODE
  • if (p_pcServerName != NULL)
  • {
  • l_iSize = strlen (p_pcServerName) + 1;
  • l_pwUnicodeServerName = new WORD [l_iSize];
  • l_pwUnicodeServerName[0] = 0;
  • MultiByteToWideChar (CP_ACP, 0, p_pcServerName, -1, l_pwUnicodeServerName, l_iSize);
  • }
  • // on mets le compteur à 0
  • *p_piCurrentIndex = 0;
  • do // begin do
  • {
  • // on récupère une partie des dossiers réseaux
  • l_nStatus = NetShareEnum (l_pwUnicodeServerName, 502, (LPBYTE *) &l_BufPShareInfo, -1, &l_dwCount, &l_dwTr, &l_dwResume);
  • if(l_nStatus != ERROR_SUCCESS && l_nStatus != ERROR_MORE_DATA)
  • throw l_nStatus;
  • l_PShareInfo=l_BufPShareInfo;
  • // pour tous les dossiers trouvés, on va recopier les infos pertinentes dans notre structure STL_SHARE_INFO
  • for(i=1;i<=l_dwCount;i++)
  • {
  • // on convertit du unicode en char pour récupérer le netname
  • l_dwRetVal = WideCharToMultiByte ( CP_ACP,
  • WC_NO_BEST_FIT_CHARS,
  • l_PShareInfo->shi502_netname,
  • -1,
  • p_ShareInfoArray[*p_piCurrentIndex].cNetname,
  • _MAX_PATH,
  • NULL,
  • NULL);
  • if (l_dwRetVal == 0)
  • throw (DWORD) "STL_UNICODE_TO_AINSI_ERROR";
  • // on teste la validité du SID afin de ne pas lister des infos inexistantes (et faire tout exploser)
  • // si le SID est invalide (NULL notamment)
  • l_bRetVal = IsValidSecurityDescriptor(l_PShareInfo->shi502_security_descriptor);
  • // si le SID est valide, on liste les infos
  • if (l_bRetVal != 0)
  • {
  • int size = strlen (p_ShareInfoArray[*p_piCurrentIndex].cNetname) - 1;
  • if (p_ShareInfoArray[*p_piCurrentIndex].cNetname[size] != '$')
  • {
  • // comme ce sont les values DWORD, on fait une copie brute de fonte
  • p_ShareInfoArray[*p_piCurrentIndex].dwType = l_PShareInfo->shi502_type;
  • p_ShareInfoArray[*p_piCurrentIndex].dwPermissions = l_PShareInfo->shi502_permissions;
  • p_ShareInfoArray[*p_piCurrentIndex].dwMax_uses = l_PShareInfo->shi502_max_uses;
  • p_ShareInfoArray[*p_piCurrentIndex].dwCurrent_uses = l_PShareInfo->shi502_current_uses;
  • p_ShareInfoArray[*p_piCurrentIndex].dwReserved = l_PShareInfo->shi502_reserved;
  • // pour les vlaues en unicode, on fait la transformation en AINSI
  • l_dwRetVal = WideCharToMultiByte ( CP_ACP,
  • WC_NO_BEST_FIT_CHARS,
  • l_PShareInfo->shi502_remark,
  • -1,
  • p_ShareInfoArray[*p_piCurrentIndex].cRemark,
  • _MAX_PATH,
  • NULL,
  • NULL);
  • if (l_dwRetVal == 0)
  • throw (DWORD) "STL_UNICODE_TO_AINSI_ERROR";
  • l_dwRetVal = WideCharToMultiByte ( CP_ACP,
  • WC_NO_BEST_FIT_CHARS,
  • l_PShareInfo->shi502_path,
  • -1,
  • p_ShareInfoArray[*p_piCurrentIndex].cPath,
  • _MAX_PATH,
  • NULL,
  • NULL);
  • if (l_dwRetVal == 0)
  • throw (DWORD) "STL_UNICODE_TO_AINSI_ERROR";
  • BOOL l_bDaclPresent, l_bDaclDefault;
  • /******************************************************************************************/
  • /* A cet endroit, si le l_PShareInfo->shi502_security_descriptor est NULL (ou le */
  • /* l_PShareInfo->shi502_reserved est = 0 (ils semblent marcher ensemble...) cela crash le */
  • /* le systeme completement. Ceci peut être bypassé en délétant le rep à pb et en le */
  • /* recréant... Bizarre, vous avez dit bizarre :D:D:D */
  • /******************************************************************************************/
  • // on récupère le Dacl lié au SID? C'est dans ce Dacl que l'on va trouver les infos de partage et de persmissions....
  • l_bRetVal = GetSecurityDescriptorDacl(l_PShareInfo->shi502_security_descriptor, &l_bDaclPresent, &l_Dacl, &l_bDaclDefault);
  • if (l_bRetVal == 0)
  • throw (DWORD) "STL_DACL_ERROR";
  • // on liste de façon explicite les permissions et users. La fonction renvoie un tableau de ExplicitEntries
  • l_dwRetVal = GetExplicitEntriesFromAcl ( l_Dacl,
  • &l_ulNbOfEntries,
  • &l_oAccessArray);
  • if (l_dwRetVal != 0)
  • throw l_dwRetVal;
  • // pour chaque entrée dans le tableau de EXPLICIT_ACCESS, on regarde si le trustee est identifié par un username, et si oui, on récupère le username et les droits d'accès
  • for (l_iTotalEntriesIndex = 0; l_iTotalEntriesIndex < (int) l_ulNbOfEntries; l_iTotalEntriesIndex ++)
  • {
  • // on copie le
  • p_ShareInfoArray[*p_piCurrentIndex].aEnumUserRights[l_iTotalEntriesIndex].AccessRights = l_oAccessArray[l_iTotalEntriesIndex].grfAccessPermissions;
  • if (l_oAccessArray[l_iTotalEntriesIndex].Trustee.TrusteeForm == TRUSTEE_IS_NAME)
  • {
  • // on copie les droits (sous forme de MASK DWORD)
  • strcpy(p_ShareInfoArray[*p_piCurrentIndex].aEnumUserRights[l_iTotalEntriesIndex].cUserName, l_oAccessArray[l_iTotalEntriesIndex].Trustee.ptstrName);
  • }
  • else
  • {
  • char l_cDomainName[_MAX_FNAME];
  • unsigned long l_ulDomSize = _MAX_FNAME;
  • unsigned long l_ulBufSize = _MAX_FNAME;
  • SID_NAME_USE l_oSIDNameUse;
  • DWORD l_dwErr;
  • // pour chaque entrée du tableau, on va récupérer le Nom du user depuis le SID associé
  • l_bRetVal = LookupAccountSid ( p_pcServerName,
  • l_oAccessArray[l_iTotalEntriesIndex].Trustee.ptstrName,
  • p_ShareInfoArray[*p_piCurrentIndex].aEnumUserRights[l_iTotalEntriesIndex].cUserName,
  • &l_ulBufSize,
  • l_cDomainName,
  • &l_ulBufSize,
  • &l_oSIDNameUse);
  • if (l_bRetVal == 0)
  • {
  • l_dwErr = GetLastError();
  • throw l_dwErr;
  • }
  • switch (l_oSIDNameUse)
  • {
  • case SidTypeUser :
  • p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeUser;
  • break;
  • case SidTypeGroup :
  • p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeGroup;
  • break;
  • case SidTypeDomain :
  • p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeDomain;
  • break;
  • case SidTypeAlias :
  • p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeAlias;
  • break;
  • case SidTypeWellKnownGroup :
  • p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeWellKnownGroup;
  • break;
  • case SidTypeDeletedAccount :
  • p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeDeletedAccount;
  • break;
  • case SidTypeInvalid :
  • p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeInvalid;
  • break;
  • default :
  • p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeUnknown;
  • break;
  • }//end switch
  • }
  • }// end for
  • p_ShareInfoArray[*p_piCurrentIndex].iTotalUserRights = l_iTotalEntriesIndex;
  • LocalFree (l_oAccessArray);
  • (*p_piCurrentIndex) ++;
  • }
  • }
  • else // si pb avec le SID
  • {
  • sprintf(p_ShareInfoArray[(*p_piCurrentIndex)++].cRemark, "ERREUR AVEC LE SID DE CE DOSSIER");
  • }
  • l_PShareInfo++;
  • } // end for
  • NetApiBufferFree(l_BufPShareInfo);
  • l_BufPShareInfo = NULL;
  • }
  • while (l_nStatus==ERROR_MORE_DATA);
  • }
  • catch (DWORD dwErr)
  • {
  • l_nStatus = dwErr;
  • }
  • // on delete les pointeurs si OK
  • if (l_BufPShareInfo != NULL)
  • NetApiBufferFree(l_BufPShareInfo);
  • return l_nStatus;
  • }
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <stdio.h>
#include <aclapi.h>
#include <lmshare.h>
#include <Lm.h>
#include "NetEnum.h"


                              /***************************************/
                              /***************************************/
                              /*          CountNetShareEnum          */
                              /***************************************/
                              /***************************************/

DWORD CountNetShareEnum
(
   const char*       p_pcServerName,
   int*              p_TotalOfShareRessource
)
{
   PSHARE_INFO_502               l_PShareInfo, l_BufPShareInfo;
   NET_API_STATUS                l_nStatus;
   DWORD                         l_dwErr=0,l_dwTr=0,l_dwResume=0, i;
   LPWSTR                        l_pwUnicodeServerName = NULL;
   int                           l_iSize;
   try
   {   
      // si on entre un nom de PC, on transforme le nom AINSI en UNICODE
      if (p_pcServerName != NULL)
      {
         l_iSize = strlen (p_pcServerName) + 1;
         l_pwUnicodeServerName = new WORD [l_iSize];
         l_pwUnicodeServerName[0] = 0;
	      MultiByteToWideChar (CP_ACP, 0, p_pcServerName, -1, l_pwUnicodeServerName, l_iSize);
      }

      do // begin do
      {
         // on liste tout ou partie des dossiers partagés de p_pcServerName
         l_nStatus = NetShareEnum (l_pwUnicodeServerName, 502, (LPBYTE *) &l_BufPShareInfo, -1, &l_dwErr, &l_dwTr, &l_dwResume);
         
         if(l_nStatus != ERROR_SUCCESS && l_nStatus != ERROR_MORE_DATA)
            throw l_nStatus;

         // on fait pointer l_PShareInfo sur les données trouvées
         l_PShareInfo=l_BufPShareInfo;

         // pour chaque entrée trouvée (jusqu'à dwErr) on incrémente
         for(i=1;i<=l_dwErr;i++)
         {
            l_PShareInfo++;
            (*p_TotalOfShareRessource) ++;
         }
         
         // on libère le buffer
         NetApiBufferFree(l_BufPShareInfo);
      }
      while (l_nStatus==ERROR_MORE_DATA);
   }
   catch (DWORD)
   {
   }
   return l_nStatus;
}



                              /***************************************/
                              /***************************************/
                              /*          CountNetShareEnum          */
                              /***************************************/
                              /***************************************/

DWORD RetrieveNetShareEnum
(
   const char*       p_pcServerName,
   const int         p_TotalOfShareRessource,
   int*              p_piCurrentIndex,
   STL_SHARE_INFO*   p_ShareInfoArray
)
{
   PSHARE_INFO_502               l_PShareInfo, l_BufPShareInfo;
   NET_API_STATUS                l_nStatus;
   DWORD                         l_dwCount=0,l_dwTr=0,l_dwResume=0, i;
   DWORD                         l_dwRetVal;
   LPWSTR                        l_pwUnicodeServerName = NULL;
   LPWSTR                        l_pwUnicodeRemark = NULL;
   LPWSTR                        l_pwUnicodePath = NULL;
   LPWSTR                        l_pwUnicodePassword = NULL;
   BOOL                          l_bRetVal;
   PACL                          l_Dacl;
   int                           l_iSize, l_iTotalEntriesIndex;
   unsigned long                 l_ulNbOfEntries = 0;
   PEXPLICIT_ACCESS              l_oAccessArray = NULL;

   try
   {        
      // si on entre un nom de PC, on transforme le nom AINSI en UNICODE 
      if (p_pcServerName != NULL)
      {
         l_iSize = strlen (p_pcServerName) + 1;
         l_pwUnicodeServerName = new WORD [l_iSize];
         l_pwUnicodeServerName[0] = 0;
	      MultiByteToWideChar (CP_ACP, 0, p_pcServerName, -1, l_pwUnicodeServerName, l_iSize);
      }
      
      // on mets le compteur à 0
      *p_piCurrentIndex = 0;

      do // begin do
      {
         // on récupère une partie des dossiers réseaux
         l_nStatus = NetShareEnum (l_pwUnicodeServerName, 502, (LPBYTE *) &l_BufPShareInfo, -1, &l_dwCount, &l_dwTr, &l_dwResume);
         
         if(l_nStatus != ERROR_SUCCESS && l_nStatus != ERROR_MORE_DATA)
            throw l_nStatus;

         l_PShareInfo=l_BufPShareInfo;

         // pour tous les dossiers trouvés, on va recopier les infos pertinentes dans notre structure STL_SHARE_INFO
         for(i=1;i<=l_dwCount;i++)
         {
             // on convertit du unicode en char pour récupérer le netname
            l_dwRetVal = WideCharToMultiByte (  CP_ACP, 
                                                WC_NO_BEST_FIT_CHARS, 
                                                l_PShareInfo->shi502_netname, 
                                                -1, 
                                                p_ShareInfoArray[*p_piCurrentIndex].cNetname, 
                                                _MAX_PATH, 
                                                NULL, 
                                                NULL);

            if (l_dwRetVal == 0)
               throw (DWORD) "STL_UNICODE_TO_AINSI_ERROR";

            // on teste la validité du SID afin de ne pas lister des infos inexistantes (et faire tout exploser)
            // si le SID est invalide (NULL notamment)
            l_bRetVal = IsValidSecurityDescriptor(l_PShareInfo->shi502_security_descriptor);

            // si le SID est valide, on liste les infos
            if (l_bRetVal != 0)
            {
               int size = strlen (p_ShareInfoArray[*p_piCurrentIndex].cNetname) - 1;

               if (p_ShareInfoArray[*p_piCurrentIndex].cNetname[size] != '$')
               {
                  // comme ce sont les values DWORD, on fait une copie brute de fonte
                  p_ShareInfoArray[*p_piCurrentIndex].dwType = l_PShareInfo->shi502_type;
                  p_ShareInfoArray[*p_piCurrentIndex].dwPermissions = l_PShareInfo->shi502_permissions;
                  p_ShareInfoArray[*p_piCurrentIndex].dwMax_uses = l_PShareInfo->shi502_max_uses;
                  p_ShareInfoArray[*p_piCurrentIndex].dwCurrent_uses = l_PShareInfo->shi502_current_uses;
                  p_ShareInfoArray[*p_piCurrentIndex].dwReserved = l_PShareInfo->shi502_reserved;

                  // pour les vlaues en unicode, on fait la transformation en AINSI
                  l_dwRetVal = WideCharToMultiByte (  CP_ACP, 
                                                      WC_NO_BEST_FIT_CHARS, 
                                                      l_PShareInfo->shi502_remark, 
                                                      -1, 
                                                      p_ShareInfoArray[*p_piCurrentIndex].cRemark, 
                                                      _MAX_PATH, 
                                                      NULL, 
                                                      NULL);
                  if (l_dwRetVal == 0)
                     throw (DWORD) "STL_UNICODE_TO_AINSI_ERROR";

                  l_dwRetVal = WideCharToMultiByte (  CP_ACP, 
                                                      WC_NO_BEST_FIT_CHARS, 
                                                      l_PShareInfo->shi502_path, 
                                                      -1, 
                                                      p_ShareInfoArray[*p_piCurrentIndex].cPath, 
                                                      _MAX_PATH, 
                                                      NULL, 
                                                      NULL);
                  if (l_dwRetVal == 0)
                     throw (DWORD) "STL_UNICODE_TO_AINSI_ERROR";

                  BOOL  l_bDaclPresent, l_bDaclDefault;
                  /******************************************************************************************/
                  /* A cet endroit, si le l_PShareInfo->shi502_security_descriptor est NULL (ou le          */
                  /* l_PShareInfo->shi502_reserved est = 0 (ils semblent marcher ensemble...) cela crash le */
                  /* le systeme completement. Ceci peut être bypassé en délétant le rep à pb et en le       */
                  /* recréant... Bizarre, vous avez dit bizarre :D:D:D                                      */
                  /******************************************************************************************/
                   
                  // on récupère le Dacl lié au SID? C'est dans ce Dacl que l'on va trouver les infos de partage et de persmissions....
                  l_bRetVal = GetSecurityDescriptorDacl(l_PShareInfo->shi502_security_descriptor, &l_bDaclPresent, &l_Dacl, &l_bDaclDefault);

                  if (l_bRetVal == 0)
                     throw (DWORD) "STL_DACL_ERROR";

                  // on liste de façon explicite les permissions et users. La fonction renvoie un tableau de ExplicitEntries
                  l_dwRetVal = GetExplicitEntriesFromAcl (  l_Dacl,
                                                            &l_ulNbOfEntries,
                                                            &l_oAccessArray);

                  if (l_dwRetVal != 0)
                     throw l_dwRetVal;

                  // pour chaque entrée dans le tableau de EXPLICIT_ACCESS, on regarde si le trustee est identifié par un username, et si oui, on récupère le username et les droits d'accès
                  for (l_iTotalEntriesIndex = 0; l_iTotalEntriesIndex < (int) l_ulNbOfEntries; l_iTotalEntriesIndex ++)
                  {
                     // on copie le 
                     p_ShareInfoArray[*p_piCurrentIndex].aEnumUserRights[l_iTotalEntriesIndex].AccessRights = l_oAccessArray[l_iTotalEntriesIndex].grfAccessPermissions;

                     if (l_oAccessArray[l_iTotalEntriesIndex].Trustee.TrusteeForm == TRUSTEE_IS_NAME)
                     {
                        // on copie les droits (sous forme de MASK DWORD)
                        strcpy(p_ShareInfoArray[*p_piCurrentIndex].aEnumUserRights[l_iTotalEntriesIndex].cUserName, l_oAccessArray[l_iTotalEntriesIndex].Trustee.ptstrName);
                     }
                     else
                     {
                        char     l_cDomainName[_MAX_FNAME];
                        unsigned long  l_ulDomSize = _MAX_FNAME;
                        unsigned long  l_ulBufSize = _MAX_FNAME;
                        SID_NAME_USE   l_oSIDNameUse;
                        DWORD l_dwErr;
                        
                        // pour chaque entrée du tableau, on va récupérer le Nom du user depuis le SID associé
                        l_bRetVal = LookupAccountSid (   p_pcServerName,
                                                         l_oAccessArray[l_iTotalEntriesIndex].Trustee.ptstrName,
                                                         p_ShareInfoArray[*p_piCurrentIndex].aEnumUserRights[l_iTotalEntriesIndex].cUserName,
                                                         &l_ulBufSize,
                                                         l_cDomainName,
                                                         &l_ulBufSize,
                                                         &l_oSIDNameUse);
                        if (l_bRetVal == 0)
                        {
                           l_dwErr = GetLastError();
                           throw l_dwErr;
                        }

                        switch (l_oSIDNameUse)
                        {
                           case SidTypeUser :
                              p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeUser;
                              break;
                           case SidTypeGroup :
                              p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeGroup;
                              break;
                           case SidTypeDomain :
                              p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeDomain;
                              break;
                           case SidTypeAlias :
                              p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeAlias;
                              break;
                           case SidTypeWellKnownGroup :
                              p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeWellKnownGroup;
                              break;
                           case SidTypeDeletedAccount :
                              p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeDeletedAccount;
                              break;
                           case SidTypeInvalid :
                              p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeInvalid;
                              break;
                           default :
                              p_ShareInfoArray[*p_piCurrentIndex].l_oAccountType = STL_SidTypeUnknown;
                              break;
                        }//end switch
                     }

                  }// end for
                  p_ShareInfoArray[*p_piCurrentIndex].iTotalUserRights = l_iTotalEntriesIndex;
                     LocalFree (l_oAccessArray);
                  (*p_piCurrentIndex) ++;  
               }
            }
            else // si pb avec le SID
            {
               sprintf(p_ShareInfoArray[(*p_piCurrentIndex)++].cRemark, "ERREUR AVEC LE SID DE CE DOSSIER");
            }

            l_PShareInfo++;
         } // end for

         NetApiBufferFree(l_BufPShareInfo);
         l_BufPShareInfo = NULL;
      }
      while (l_nStatus==ERROR_MORE_DATA);
   }
   catch (DWORD dwErr)
   {
      l_nStatus = dwErr;
   }
   // on delete les pointeurs si OK
   if (l_BufPShareInfo !=  NULL)
      NetApiBufferFree(l_BufPShareInfo);

   return l_nStatus;
}

 Conclusion

Ne pas oublier de linker les lib advapi32.lib, mpr.lib et netapi32.lib.
Voila, cela peut peut être servir....

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip RÉCUPÉRER LES INFOS D'UNE DLL, EXE, ETC.

 Sources de la même categorie

Source avec Zip Source avec une capture UNE LISTE HÉTÉROGÈNE DOUBLEMENT CHAINÉE par pgl10
Source avec Zip Source avec une capture POUR AFFICHER LES CARACTÈRES ACCENTUÉS SOUS WINDOWS EN MODE ... par pgl10
Source avec Zip PETITE CLASSE DE GESTION DES PROCESSUS SOUS WINDOWS par wisar
Source avec Zip KEYLOGGER AVEC NOM DU PROCESSUS ET DE LA FENETRE QUI A LE FO... par wisar
Source avec Zip LINUX USB BOOT LEGER par patatalo

Commentaires et avis

Commentaire de radada le 15/12/2003 11:30:03

J'ai oublie... Voici un exple pour l'utiliser avec les &lt;&gt; valeurs du ACCESS_MASK

// ajouter une list avec variable -&gt; m_oListInfo et un bouton Perm

void CTestSystemToolsDlg::Display (CString p_oError)
{
   m_oListInfo.AddString    (p_oError);
   m_oListInfo.SetTopIndex  (m_oListInfo.GetCount() - 10);
   m_oListInfo.UpdateWindow ();
}

void CTestSystemToolsDlg::OnBTNPerm()
{
   DWORD Res;
   CString           l_oStr;
   STL_SHARE_INFO  l_oArray[30];
   int i=0, Index = 0, Entries, maxEntries;
   char  Sep[20] = "___________________";


   Res = RetrieveNetShareEnum (NULL, 30, &Index, l_oArray);
   for (i=0; i&lt;Index; i++)
   {
      l_oStr.Format("Folder : %s", l_oArray[i].cNetname);
      Display(l_oStr);
      l_oStr.Format("Path : %s", l_oArray[i].cPath);
      Display(l_oStr);
      l_oStr.Format("**** REMARQUES **** : %s", l_oArray[i].cRemark);
      Display(l_oStr);
      maxEntries = l_oArray[i].iTotalUserRights;
      for (Entries = 0; Entries &lt; maxEntries; Entries ++)
      {
         l_oStr.Format("   User : %s", l_oArray[i].aEnumUserRights[Entries].cUserName);
         Display(l_oStr);
         l_oStr.Format("   AccessMask : %lx", l_oArray[i].aEnumUserRights[Entries].AccessRights);
         Display(l_oStr);
        

         if (l_oArray[i].aEnumUserRights[Entries].AccessRights & SPECIFIC_RIGHTS_ALL)
         {
            l_oStr.Format("      %s", "SPECIFIC_RIGHTS_ALL");
            Display(l_oStr);
         }
         if (l_oArray[i].aEnumUserRights[Entries].AccessRights & STANDARD_RIGHTS_REQUIRED)
         {
            l_oStr.Format("      %s", "STANDARD_RIGHTS_REQUIRED");
            Display(l_oStr);
         }
         if (l_oArray[i].aEnumUserRights[Entries].AccessRights & STANDARD_RIGHTS_ALL)
         {
            l_oStr.Format("      %s", "STANDARD_RIGHTS_ALL");
            Display(l_oStr);
         }
         if (l_oArray[i].aEnumUserRights[Entries].AccessRights & DELETE )
         {
            l_oStr.Format("      %s", "DELETE ");
            Display(l_oStr);
         }
         if (l_oArray[i].aEnumUserRights[Entries].AccessRights & READ_CONTROL )
         {
            l_oStr.Format("      %s", "READ_CONTROL ");
            Display(l_oStr);
         }
         if (l_oArray[i].aEnumUserRights[Entries].AccessRights & WRITE_DAC)
         {
            l_oStr.Format("      %s", "WRITE_DAC");
            Display(l_oStr);
         }
         if (l_oArray[i].aEnumUserRights[Entries].AccessRights & WRITE_OWNER)
         {
            l_oStr.Format("      %s", "WRITE_OWNER");
            Display(l_oStr);
         }
      /****************************/
         if (l_oArray[i].aEnumUserRights[Entries].AccessRights & SYNCHRONIZE)
         {
            l_oStr.Format("      %s", "SYNCHRONIZE");
            Display(l_oStr);
         }
         if (l_oArray[i].aEnumUserRights[Entries].AccessRights & ACCESS_SYSTEM_SECURITY)
         {
            l_oStr.Format("      %s", "ACCESS_SYSTEM_SECURITY");
            Display(l_oStr);
         }
         if (l_oArray[i].aEnumUserRights[Entries].AccessRights & MAXIMUM_ALLOWED)
         {
            l_oStr.Format("      %s", "MAXIMUM_ALLOWED");
            Display(l_oStr);
         }
         if (l_oArray[i].aEnumUserRights[Entries].AccessRights & GENERIC_ALL )
         {
            l_oStr.Format("      %s", "GENERIC_ALL ");
            Display(l_oStr);
         }
         if (l_oArray[i].aEnumUserRights[Entries].AccessRights & GENERIC_EXECUTE )
         {
            l_oStr.Format("      %s", "GENERIC_EXECUTE ");
            Display(l_oStr);
         }
         if (l_oArray[i].aEnumUserRights[Entries].AccessRights & GENERIC_WRITE)
         {
            l_oStr.Format("      %s", "GENERIC_WRITE");
            Display(l_oStr);
         }
         if (l_oArray[i].aEnumUserRights[Entries].AccessRights & GENERIC_READ)
         {
            l_oStr.Format("      %s", "GENERIC_READ");
            Display(l_oStr);
         }
      }
      l_oStr.Format("%s%s%s", Sep, Sep, Sep);
      Display(l_oStr);

   }


}

Commentaire de freax le 28/12/2003 03:05:37

bhen la aussi ;=)

Commentaire de radada le 28/12/2003 21:13:18

??? Pas compris????

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,562 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales