Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove 'using * = Interop.*'
  • Loading branch information
elinor-fung committed Dec 1, 2021
commit c9d6265dd6abff66525cd37885e953cd0988f29d
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System.Runtime.InteropServices;
using System.Security;

using Activeds = Interop.Activeds;

namespace System.DirectoryServices.Interop
{

Expand Down Expand Up @@ -34,7 +32,7 @@ public static int ADsOpenObject(string path, string? userName, string? password,
{
try
{
return Activeds.ADsOpenObject(path, userName, password, flags, ref iid, out ppObject);
return global::Interop.Activeds.ADsOpenObject(path, userName, password, flags, ref iid, out ppObject);
}
catch (EntryPointNotFoundException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using System.Text;
using System.Diagnostics.CodeAnalysis;

using Kernel32 = Interop.Kernel32;

namespace System.DirectoryServices.ActiveDirectory
{
[Flags]
Expand Down Expand Up @@ -1308,7 +1306,7 @@ private void GetDomains()

IntPtr info = (IntPtr)0;
// call DsReplicaSyncAllW
IntPtr functionPtr = Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsListDomainsInSiteW");
IntPtr functionPtr = global::Interop.Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsListDomainsInSiteW");
if (functionPtr == (IntPtr)0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
Expand Down Expand Up @@ -1350,7 +1348,7 @@ private void GetDomains()
finally
{
// call DsFreeNameResultW
functionPtr = Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsFreeNameResultW");
functionPtr = global::Interop.Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsFreeNameResultW");
if (functionPtr == (IntPtr)0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

using Microsoft.Win32.SafeHandles;

using Advapi32 = Interop.Advapi32;
using Kernel32 = Interop.Kernel32;

namespace System.DirectoryServices.ActiveDirectory
{
public enum DirectoryContextType
Expand Down Expand Up @@ -603,7 +600,7 @@ internal static string GetLoggedOnDomain()
{
throw new OutOfMemoryException();
}
else if ((result == 0) && (Advapi32.LsaNtStatusToWinError(protocolStatus) == NativeMethods.ERROR_NO_SUCH_LOGON_SESSION))
else if ((result == 0) && (global::Interop.Advapi32.LsaNtStatusToWinError(protocolStatus) == NativeMethods.ERROR_NO_SUCH_LOGON_SESSION))
{
// If this is a directory user, extract domain info from username
if (!Utils.IsSamUser())
Expand All @@ -617,7 +614,7 @@ internal static string GetLoggedOnDomain()
}
else
{
throw ExceptionHelper.GetExceptionFromErrorCode((int)Advapi32.LsaNtStatusToWinError((result != 0) ? result : protocolStatus));
throw ExceptionHelper.GetExceptionFromErrorCode((int)global::Interop.Advapi32.LsaNtStatusToWinError((result != 0) ? result : protocolStatus));
}
}
}
Expand All @@ -635,7 +632,7 @@ internal static string GetLoggedOnDomain()
}
else
{
throw ExceptionHelper.GetExceptionFromErrorCode((int)Advapi32.LsaNtStatusToWinError(result));
throw ExceptionHelper.GetExceptionFromErrorCode((int)global::Interop.Advapi32.LsaNtStatusToWinError(result));
}

// If we're running as a local user (i.e. NT AUTHORITY\LOCAL SYSTEM, IIS APPPOOL\APPPoolIdentity, etc.),
Expand Down Expand Up @@ -693,7 +690,7 @@ private static void GetLibraryHandle()
{
// first get AD handle
string systemPath = Environment.SystemDirectory;
IntPtr tempHandle = Kernel32.LoadLibrary(systemPath + "\\ntdsapi.dll");
IntPtr tempHandle = global::Interop.Kernel32.LoadLibrary(systemPath + "\\ntdsapi.dll");
if (tempHandle == (IntPtr)0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
Expand All @@ -706,7 +703,7 @@ private static void GetLibraryHandle()
// not get the ADAM handle
// got to the windows\adam directory
DirectoryInfo windowsDirectory = Directory.GetParent(systemPath)!;
tempHandle = Kernel32.LoadLibrary(windowsDirectory.FullName + "\\ADAM\\ntdsapi.dll");
tempHandle = global::Interop.Kernel32.LoadLibrary(windowsDirectory.FullName + "\\ADAM\\ntdsapi.dll");
if (tempHandle == (IntPtr)0)
{
ADAMHandle = ADHandle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

using Microsoft.Win32.SafeHandles;

using Kernel32 = Interop.Kernel32;

namespace System.DirectoryServices.ActiveDirectory
{
public abstract class DirectoryServer : IDisposable
Expand Down Expand Up @@ -298,7 +296,7 @@ internal void CheckIfDisposed()
internal void CheckConsistencyHelper(IntPtr dsHandle, SafeLibraryHandle libHandle)
{
// call DsReplicaConsistencyCheck
IntPtr functionPtr = Kernel32.GetProcAddress(libHandle, "DsReplicaConsistencyCheck");
IntPtr functionPtr = global::Interop.Kernel32.GetProcAddress(libHandle, "DsReplicaConsistencyCheck");
if (functionPtr == (IntPtr)0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
Expand All @@ -320,11 +318,11 @@ internal IntPtr GetReplicationInfoHelper(IntPtr dsHandle, int type, int secondar

// first try to use the DsReplicaGetInfo2W API which does not exist on win2k machine
// call DsReplicaGetInfo2W
functionPtr = Kernel32.GetProcAddress(libHandle, "DsReplicaGetInfo2W");
functionPtr = global::Interop.Kernel32.GetProcAddress(libHandle, "DsReplicaGetInfo2W");
if (functionPtr == (IntPtr)0)
{
// a win2k machine which does not have it.
functionPtr = Kernel32.GetProcAddress(libHandle, "DsReplicaGetInfoW");
functionPtr = global::Interop.Kernel32.GetProcAddress(libHandle, "DsReplicaGetInfoW");
if (functionPtr == (IntPtr)0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
Expand All @@ -344,7 +342,7 @@ internal IntPtr GetReplicationInfoHelper(IntPtr dsHandle, int type, int secondar
if (needToTryAgain && result == DS_REPL_NOTSUPPORTED)
{
// this is the case that client is xp/win2k3, dc is win2k
functionPtr = Kernel32.GetProcAddress(libHandle, "DsReplicaGetInfoW");
functionPtr = global::Interop.Kernel32.GetProcAddress(libHandle, "DsReplicaGetInfoW");
if (functionPtr == (IntPtr)0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
Expand Down Expand Up @@ -645,7 +643,7 @@ internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallb

// we want to return the dn instead of DNS guid
// call DsReplicaSyncAllW
IntPtr functionPtr = Kernel32.GetProcAddress(libHandle, "DsReplicaSyncAllW");
IntPtr functionPtr = global::Interop.Kernel32.GetProcAddress(libHandle, "DsReplicaSyncAllW");
if (functionPtr == (IntPtr)0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
Expand Down Expand Up @@ -676,7 +674,7 @@ internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallb
{
// release the memory
if (errorInfo != (IntPtr)0)
Kernel32.LocalFree(errorInfo);
global::Interop.Kernel32.LocalFree(errorInfo);
}
}

Expand All @@ -685,7 +683,7 @@ private void FreeReplicaInfo(DS_REPL_INFO_TYPE type, IntPtr value, SafeLibraryHa
if (value != (IntPtr)0)
{
// call DsReplicaFreeInfo
IntPtr functionPtr = Kernel32.GetProcAddress(libHandle, "DsReplicaFreeInfo");
IntPtr functionPtr = global::Interop.Kernel32.GetProcAddress(libHandle, "DsReplicaFreeInfo");
if (functionPtr == (IntPtr)0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
Expand Down Expand Up @@ -725,7 +723,7 @@ internal void SyncReplicaHelper(IntPtr dsHandle, bool isADAM, string partition,
}

// call DsReplicaSyncW
IntPtr functionPtr = Kernel32.GetProcAddress(libHandle, "DsReplicaSyncW");
IntPtr functionPtr = global::Interop.Kernel32.GetProcAddress(libHandle, "DsReplicaSyncW");
if (functionPtr == (IntPtr)0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
using System.Runtime.InteropServices;
using System.Diagnostics;

using Kernel32 = Interop.Kernel32;

namespace System.DirectoryServices.ActiveDirectory
{
[Flags]
Expand Down Expand Up @@ -1089,7 +1087,7 @@ private void GetDomainControllerInfo()
GetDSHandle();

// call DsGetDomainControllerInfo
IntPtr functionPtr = Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsGetDomainControllerInfoW");
IntPtr functionPtr = global::Interop.Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsGetDomainControllerInfoW");
if (functionPtr == (IntPtr)0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
Expand Down Expand Up @@ -1166,7 +1164,7 @@ private void GetDomainControllerInfo()
if (dcInfoPtr != IntPtr.Zero)
{
// call DsFreeDomainControllerInfo
functionPtr = Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsFreeDomainControllerInfoW");
functionPtr = global::Interop.Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsFreeDomainControllerInfoW");
if (functionPtr == (IntPtr)0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
Expand Down Expand Up @@ -1251,7 +1249,7 @@ private ArrayList GetRoles()
GetDSHandle();
// Get the roles
// call DsListRoles
IntPtr functionPtr = Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsListRolesW");
IntPtr functionPtr = global::Interop.Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsListRolesW");
if (functionPtr == (IntPtr)0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
Expand Down Expand Up @@ -1291,7 +1289,7 @@ private ArrayList GetRoles()
if (rolesPtr != IntPtr.Zero)
{
// call DsFreeNameResult
functionPtr = Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsFreeNameResultW");
functionPtr = global::Interop.Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsFreeNameResultW");
if (functionPtr == (IntPtr)0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
using System.Runtime.InteropServices;
using System.Diagnostics;

using Kernel32 = Interop.Kernel32;

namespace System.DirectoryServices.ActiveDirectory
{
public enum ForestMode : int
Expand Down Expand Up @@ -886,7 +884,7 @@ private ArrayList GetSites()

// Get the sites within the forest
// call DsListSites
IntPtr functionPtr = Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsListSitesW");
IntPtr functionPtr = global::Interop.Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsListSitesW");
if (functionPtr == (IntPtr)0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
Expand Down Expand Up @@ -923,7 +921,7 @@ private ArrayList GetSites()
if (sitesPtr != IntPtr.Zero)
{
// call DsFreeNameResultW
functionPtr = Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsFreeNameResultW");
functionPtr = global::Interop.Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsFreeNameResultW");
if (functionPtr == (IntPtr)0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
using System.Runtime.InteropServices;
using System.ComponentModel;

using Advapi32 = Interop.Advapi32;
using BOOL = Interop.BOOL;

namespace System.DirectoryServices.ActiveDirectory
{
public enum ForestTrustDomainStatus
Expand All @@ -30,8 +27,8 @@ internal ForestTrustDomainInformation(int flag, LSA_FOREST_TRUST_DOMAIN_INFO dom
NetBiosName = Marshal.PtrToStringUni(domainInfo.NetBIOSNameBuffer, domainInfo.NetBIOSNameLength / 2);

string sidLocal;
BOOL result = Advapi32.ConvertSidToStringSid(domainInfo.sid, out sidLocal);
if (result == BOOL.FALSE)
global::Interop.BOOL result = global::Interop.Advapi32.ConvertSidToStringSid(domainInfo.sid, out sidLocal);
if (result == global::Interop.BOOL.FALSE)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

using Microsoft.Win32.SafeHandles;

using Advapi32 = Interop.Advapi32;
using BOOL = Interop.BOOL;
using Kernel32 = Interop.Kernel32;
using UNICODE_STRING = Interop.UNICODE_STRING;

namespace System.DirectoryServices.ActiveDirectory
{
public class ForestTrustRelationshipInformation : TrustRelationshipInformation
Expand Down Expand Up @@ -192,8 +187,8 @@ public void Save()
ForestTrustDomainInformation tmp = _domainInfo[i];
record.Time = tmp.time;
IntPtr pSid = (IntPtr)0;
BOOL result = Advapi32.ConvertStringSidToSid(tmp.DomainSid, out pSid);
if (result == BOOL.FALSE)
global::Interop.BOOL result = global::Interop.Advapi32.ConvertStringSidToSid(tmp.DomainSid, out pSid);
if (result == global::Interop.BOOL.FALSE)
{
throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
}
Expand Down Expand Up @@ -273,15 +268,15 @@ public void Save()
handle = Utils.GetPolicyHandle(serverName);

// get the target name
UNICODE_STRING trustedDomainName;
global::Interop.UNICODE_STRING trustedDomainName;
target = Marshal.StringToHGlobalUni(TargetName);
UnsafeNativeMethods.RtlInitUnicodeString(out trustedDomainName, target);

// call the unmanaged function
uint error = UnsafeNativeMethods.LsaSetForestTrustInformation(handle, trustedDomainName, forestInfo, 1, out collisionInfo);
if (error != 0)
{
throw ExceptionHelper.GetExceptionFromErrorCode((int)Advapi32.LsaNtStatusToWinError(error), serverName);
throw ExceptionHelper.GetExceptionFromErrorCode((int)global::Interop.Advapi32.LsaNtStatusToWinError(error), serverName);
}

// there is collision, throw proper exception so user can deal with it
Expand Down Expand Up @@ -313,7 +308,7 @@ public void Save()

for (int i = 0; i < sidList.Count; i++)
{
Kernel32.LocalFree((IntPtr)sidList[i]!);
global::Interop.Kernel32.LocalFree((IntPtr)sidList[i]!);
}

if (records != (IntPtr)0)
Expand All @@ -327,7 +322,7 @@ public void Save()
}

if (collisionInfo != (IntPtr)0)
Advapi32.LsaFreeMemory(collisionInfo);
global::Interop.Advapi32.LsaFreeMemory(collisionInfo);

if (target != (IntPtr)0)
Marshal.FreeHGlobal(target);
Expand Down Expand Up @@ -361,7 +356,7 @@ private void GetForestTrustInfoHelper()
try
{
// get the target name
UNICODE_STRING tmpName;
global::Interop.UNICODE_STRING tmpName;
targetPtr = Marshal.StringToHGlobalUni(TargetName);
UnsafeNativeMethods.RtlInitUnicodeString(out tmpName, targetPtr);

Expand All @@ -377,7 +372,7 @@ private void GetForestTrustInfoHelper()
// check the result
if (result != 0)
{
uint win32Error = Advapi32.LsaNtStatusToWinError(result);
uint win32Error = global::Interop.Advapi32.LsaNtStatusToWinError(result);
if (win32Error != 0)
{
throw ExceptionHelper.GetExceptionFromErrorCode((int)win32Error, serverName);
Expand Down Expand Up @@ -441,7 +436,7 @@ private void GetForestTrustInfoHelper()
}
finally
{
Advapi32.LsaFreeMemory(forestTrustInfo);
global::Interop.Advapi32.LsaFreeMemory(forestTrustInfo);
}

_topLevelNames = tmpTLNs;
Expand Down
Loading