/// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception> public override void Decode(NdrBuffer src) { src.Align(4); Count = src.Dec_ndr_long(); int arrayp = src.Dec_ndr_long(); if (arrayp != 0) { src = src.Deferred; int arrays = src.Dec_ndr_long(); int arrayi = src.Index; src.Advance(12 * arrays); if (Array == null) { if (arrays < 0 || arrays > unchecked (0xFFFF)) { throw new NdrException(NdrException.InvalidConformance); } Array = new ShareInfo1[arrays]; } src = src.Derive(arrayi); for (int i = 0; i < arrays; i++) { if (Array[i] == null) { Array[i] = new ShareInfo1(); } Array[i].Decode(src); } } }
/// <summary> /// Enumerates the shares on Windows NT. /// </summary> /// <param name="server">The server name.</param> /// <returns>Collection of shares of the given <paramref name="server"/>.</returns> protected static ICollection <Share> EnumerateSharesNT(string server) { ICollection <Share> result = new List <Share>(); int level = 2; int hResume = 0; IntPtr pBuffer = IntPtr.Zero; try { int entriesRead; int totalEntries; int nRet = NetShareEnum(server, level, out pBuffer, -1, out entriesRead, out totalEntries, ref hResume); if (ERROR_ACCESS_DENIED == nRet) { //Need admin for level 2, drop to level 1 level = 1; nRet = NetShareEnum(server, level, out pBuffer, -1, out entriesRead, out totalEntries, ref hResume); } if (NO_ERROR == nRet && entriesRead > 0) { Type t = (2 == level) ? typeof(ShareInfo2) : typeof(ShareInfo1); int offset = Marshal.SizeOf(t); for (int i = 0, lpItem = pBuffer.ToInt32(); i < entriesRead; i++, lpItem += offset) { IntPtr pItem = new IntPtr(lpItem); if (1 == level) { ShareInfo1 si = (ShareInfo1)Marshal.PtrToStructure(pItem, t); result.Add(new Share(server, si.NetName, string.Empty, si.ShareType, si.Remark)); } else { ShareInfo2 si = (ShareInfo2)Marshal.PtrToStructure(pItem, t); result.Add(new Share(server, si.NetName, si.Path, si.ShareType, si.Remark)); } } } } finally { // Clean up buffer allocated by system if (IntPtr.Zero != pBuffer) { NetApiBufferFree(pBuffer); } } return(result); }
// ReSharper disable InconsistentNaming static void EnumerateSharesNT(string server, ShareCollection shares) // ReSharper restore InconsistentNaming { int level = 2; int hResume = 0; IntPtr pBuffer = IntPtr.Zero; try { int entriesRead; int totalEntries; int nRet = NetShareEnum(server, level, out pBuffer, -1, out entriesRead, out totalEntries, ref hResume); if (ErrorAccessDenied == nRet) { level = 1; nRet = NetShareEnum(server, level, out pBuffer, -1, out entriesRead, out totalEntries, ref hResume); } if (NoError == nRet && entriesRead > 0) { Type t = 2 == level ? typeof(ShareInfo2) : typeof(ShareInfo1); int offset = Marshal.SizeOf(t); for (int i = 0, lpItem = pBuffer.ToInt32(); i < entriesRead; i++, lpItem += offset) { IntPtr pItem = new IntPtr(lpItem); if (1 == level) { ShareInfo1 si = (ShareInfo1)Marshal.PtrToStructure(pItem, t); shares.Add(si.NetName, string.Empty, si.ShareType, si.Remark); } else { ShareInfo2 si = (ShareInfo2)Marshal.PtrToStructure(pItem, t); shares.Add(si.NetName, si.Path, si.ShareType, si.Remark); } } } } finally { if (IntPtr.Zero != pBuffer) { NetApiBufferFree(pBuffer); } } }
/// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception> public override void Decode(NdrBuffer src) { src.Align(4); Count = src.Dec_ndr_long(); int arrayp = src.Dec_ndr_long(); if (arrayp != 0) { src = src.Deferred; int arrays = src.Dec_ndr_long(); int arrayi = src.Index; src.Advance(12 * arrays); if (Array == null) { if (arrays < 0 || arrays > unchecked(0xFFFF)) { throw new NdrException(NdrException.InvalidConformance); } Array = new ShareInfo1[arrays]; } src = src.Derive(arrayi); for (int i = 0; i < arrays; i++) { if (Array[i] == null) { Array[i] = new ShareInfo1(); } Array[i].Decode(src); } } }