Classify NTFS paths via DFS metadata
This commit is contained in:
@@ -101,6 +101,35 @@ namespace C4IT_IAM
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetDfsEntryPath(string dfsEntryPath, out string entryPath)
|
||||
{
|
||||
entryPath = string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(dfsEntryPath))
|
||||
return false;
|
||||
|
||||
IntPtr buffer = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
int result = NetDfsGetInfo(dfsEntryPath, null, null, 1, ref buffer);
|
||||
if (result != NERR_Success || buffer == IntPtr.Zero)
|
||||
return false;
|
||||
|
||||
DFS_INFO_1 info = (DFS_INFO_1)Marshal.PtrToStructure(buffer, typeof(DFS_INFO_1));
|
||||
entryPath = info.EntryPath ?? dfsEntryPath;
|
||||
return !string.IsNullOrWhiteSpace(entryPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DefaultLogger.LogException(ex);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (buffer != IntPtr.Zero)
|
||||
NetApiBufferFree(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("mpr.dll")]
|
||||
private static extern int WNetAddConnection2(NetResource netResource,
|
||||
string password, string username, int flags);
|
||||
@@ -123,6 +152,15 @@ namespace C4IT_IAM
|
||||
ref int resume_handle
|
||||
);
|
||||
|
||||
[DllImport("Netapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private static extern int NetDfsGetInfo(
|
||||
string DfsEntryPath,
|
||||
string ServerName,
|
||||
string ShareName,
|
||||
int Level,
|
||||
ref IntPtr Buffer
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
@@ -205,4 +243,10 @@ namespace C4IT_IAM
|
||||
return shi1_netname;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
public struct DFS_INFO_1
|
||||
{
|
||||
public string EntryPath;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user