Permissions des dossiers partagés
Bonjourà tous, dans le cadre de mon TFE, je dois recuperer l'ensemble des users,groupes et shares d'un AD (Active Directory).
Recuperer les listes n'a pas été trop difficile, cependant je bloque au moment, ou je dois recuperer les permissions des differents utilisateurs sur les dossiers partagés.
Je précises, que je ne cherche pas à avoir les permissions NTFS mais les permissions de partage (Allow - Deny -> FullControl,Read, Modify)
J'ai exploré la voie des api avec netsharegetinfo
http://msdn.microsoft.com/en-us/libr...88(VS.85).aspx
Cependant la permission retourné est tout le temps égale à 0, mais de toute manière, un "masque" ne pourrait pas me dire les droits en fonction des utilisateurs :|
Voici le code de cette partie :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
const int ERROR_ACCESS_DENIED = 5;
const int ERROR_INVALID_LEVEL = 124; // unimplemented level for info
const int ERROR_INVALID_PARAMETER = 87;
const int ERROR_MORE_DATA = 234;
const int ERROR_NOT_ENOUGH_MEMORY = 8;
const int NERR_BufTooSmall = 2123; // The API return buffer is too small.
const int NERR_NetNameNotFound = 2310; // This shared resource does not exist.
const int NERR_Success = 0;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
struct SHARE_INFO_2
{
[MarshalAs(UnmanagedType.LPWStr)]
public string shi2_netname;
public uint shi2_type;
[MarshalAs(UnmanagedType.LPWStr)]
public string shi2_remark;
public uint shi2_permissions;
public uint shi2_max_uses;
public uint shi2_current_uses;
[MarshalAs(UnmanagedType.LPWStr)]
public string shi2_path;
[MarshalAs(UnmanagedType.LPWStr)]
public string shi2_passwd;
}
static string FormatMessage(int errCode)
{
switch (errCode)
{
case ERROR_ACCESS_DENIED: return "The user does not have access to the requested information.";
case ERROR_INVALID_LEVEL: return "The value specified for the level parameter is invalid.";
case ERROR_INVALID_PARAMETER: return "The specified parameter is invalid.";
case ERROR_MORE_DATA: return "More entries are available. Specify a large enough buffer to receive all entries.";
case ERROR_NOT_ENOUGH_MEMORY: return "Insufficient memory is available.";
case NERR_BufTooSmall: return "The supplied buffer is too small.";
case NERR_NetNameNotFound: return "The share name does not exist.";
};
return null;
}
[DllImport("Netapi32", CharSet = CharSet.Auto)]
static extern int NetApiBufferFree(IntPtr Buffer);
[DllImport("Netapi32", CharSet = CharSet.Auto)]
static extern int NetShareGetInfo([MarshalAs(UnmanagedType.LPWStr)] string servername,
[MarshalAs(UnmanagedType.LPWStr)] string netname, int level, ref IntPtr bufptr);
/// <summary>
/// Retrieves the local path for the given server and share name.
/// </summary>
/// <remarks>serverName must start with \\</remarks>
static string NetShareGetPath(string serverName, string netName)
{
string path = null;
IntPtr ptr = IntPtr.Zero;
int errCode = NetShareGetInfo(serverName, netName, 2, ref ptr);
if (errCode == NERR_Success)
{
SHARE_INFO_2 shareInfo = (SHARE_INFO_2)
Marshal.PtrToStructure(ptr, typeof(SHARE_INFO_2));
path = shareInfo.shi2_path;
NetApiBufferFree(ptr);
}
else
Console.WriteLine(FormatMessage(errCode));
return path;
}
static string NetShareGetPermissions(string serverName, string netName)
{
string path = null;
IntPtr ptr = IntPtr.Zero;
int errCode = NetShareGetInfo(serverName, netName, 2, ref ptr);
if (errCode == NERR_Success)
{
SHARE_INFO_2 shareInfo = (SHARE_INFO_2)
Marshal.PtrToStructure(ptr, typeof(SHARE_INFO_2));
path = shareInfo.shi2_permissions.ToString();
NetApiBufferFree(ptr);
}
else
Console.WriteLine(FormatMessage(errCode));
return path;
} |
Donc en faisant appel a la methode netsharegetpermission comme ceci par exemple :
String Res = NetShareGetPath("srv2", "TFEs");
Res est tout le temps égale à 0 ...
Ce n'est pas un problème de drois étant donné que j'utilises l impersonation dans ette partie.
Quun a t-il déjà vu comment obtenir ces informations ?
Merci d'avance.