浏览代码

[System.Data] use PAL_gssapi.c for SSPI (#9922)

PAL_gssapi.c was converted to C recently in corefx but since our fork is not up to date I copied `PAL_gssapi.c` and `PAL_gssapi.h` into mono/metadata (I guess I should just cherry-pick those files to our fork).
For System.Data it will allow users to connect to sql servers using SSPI (Security Support Provider Interface).
See https://github.com/mono/mono/issues/9028 and https://github.com/mono/mono/issues/9751
on macOS (and iOS) it uses built-in GSS.framework.
on Linux it requires an additional package (`krb`) to be installed (see .NET Core prerequisites, e.g. https://docs.microsoft.com/en-us/dotnet/core/linux-prerequisites?tabs=netcore2x#ubuntu). 
Unfortunately it's not installed on our CI yet.
Egor Bogatov 7 年之前
父节点
当前提交
e162fdaede

+ 43 - 0
configure.ac

@@ -1775,6 +1775,49 @@ if test x$platform_android = xyes; then
 	AC_DEFINE(HAVE_SIGNAL,1)
 fi
 
+dnl ***********************************
+dnl *** Checks for availability of GSS dependencies (krb5, gss.framework, etc)
+dnl ***********************************
+enable_gss=no;
+AC_MSG_CHECKING(for GSS/GSS.h)
+AC_TRY_COMPILE([
+    #include <GSS/GSS.h>
+], [
+],[
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(HAVE_GSSFW_HEADERS, 1, [GSS/GSS.h])
+    AC_DEFINE(HAVE_GSS_SPNEGO_MECHANISM, 1, [GSS_SPNEGO_MECHANISM])
+    enable_gss=yes
+], [
+    AC_MSG_RESULT(no)
+])
+
+AC_MSG_CHECKING(for gssapi/gssapi_ext.h)
+AC_TRY_COMPILE([
+    #include <gssapi/gssapi_ext.h>
+], [
+],[
+    AC_MSG_RESULT(yes)
+    enable_gss=yes
+], [
+    AC_MSG_RESULT(no)
+])
+
+AC_MSG_CHECKING(for GSS_SPNEGO_MECHANISM)
+AC_TRY_COMPILE([
+    #include <gssapi/gssapi_ext.h>
+    #include <gssapi/gssapi_krb5.h>
+    gss_OID_set_desc gss_mech_spnego_OID_set_desc = {.count = 1, .elements = GSS_SPNEGO_MECHANISM};
+], [
+],[
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(HAVE_GSS_SPNEGO_MECHANISM, 1, [GSS_SPNEGO_MECHANISM])
+], [
+    AC_MSG_RESULT(no)
+])
+
+AM_CONDITIONAL(ENABLE_GSS, test x$enable_gss = xyes)
+
 if test x$host_win32 = xno; then
 	dnl *************************************
 	dnl *** Checks for time capabilities ***

+ 1 - 0
data/config.in

@@ -12,6 +12,7 @@
 	<dllmap dll="db2cli" target="libdb2_36@libsuffix@" os="!windows"/>
 	<dllmap dll="MonoPosixHelper" target="$mono_libdir/libMonoPosixHelper@libsuffix@" os="!windows" />
 	<dllmap dll="System.Native" target="$mono_libdir/libmono-system-native@libsuffix@" os="!windows" />
+	<dllmap dll="System.Net.Security.Native" target="$mono_libdir/libmono-system-net-security-native@libsuffix@" os="!windows" />
 	<dllmap dll="libmono-btls-shared" target="$mono_libdir/libmono-btls-shared@libsuffix@" os="!windows" />
 	<dllmap dll="i:msvcrt" target="@LIBC@" os="!windows"/>
 	<dllmap dll="i:msvcrt.dll" target="@LIBC@" os="!windows"/>

+ 1 - 0
mcs/build/profiles/monotouch_runtime.make

@@ -39,3 +39,4 @@ NO_CONSOLE = yes
 PROFILE_DISABLE_BTLS=1
 MONO_FEATURE_APPLETLS=1
 ONLY_APPLETLS=1
+ENABLE_GSS=1

+ 1 - 0
mcs/build/profiles/net_4_x.make

@@ -23,4 +23,5 @@ ENFORCE_LIBRARY_WARN_AS_ERROR = yes
 
 ifdef PLATFORM_MACOS
 MONO_FEATURE_APPLETLS=1
+ENABLE_GSS=1
 endif

+ 1 - 0
mcs/build/profiles/xammac.make

@@ -35,6 +35,7 @@ MOBILE_DYNAMIC = yes
 MOBILE_PROFILE = yes
 NO_CONSOLE = yes
 
+ENABLE_GSS=1
 PROFILE_DISABLE_BTLS=1
 MONO_FEATURE_APPLETLS=1
 ONLY_APPLETLS=1

+ 1 - 0
mcs/build/profiles/xammac_net_4_5.make

@@ -23,3 +23,4 @@ NO_SYSTEM_DIRECTORY_SERVICES_DEPENDENCY=1
 PROFILE_DISABLE_BTLS=1
 MONO_FEATURE_APPLETLS=1
 ONLY_APPLETLS=1
+ENABLE_GSS=1

+ 4 - 0
mcs/class/System.Data/Makefile

@@ -25,6 +25,10 @@ ifdef MONO_FEATURE_APPLETLS
 LIB_MCS_FLAGS += -d:MONO_FEATURE_APPLETLS
 endif
 
+ifdef ENABLE_GSS
+LIB_MCS_FLAGS += -d:ENABLE_GSS
+endif
+
 ifndef PROFILE_DISABLE_BTLS
 ifdef HAVE_BTLS
 LIB_MCS_FLAGS += -d:MONO_FEATURE_BTLS

+ 29 - 29
mcs/class/System.Data/System.Data.csproj

@@ -39,17 +39,17 @@
   <PropertyGroup Condition=" '$(Platform)' == 'monotouch' ">
     <OutputPath>./../../class/lib/monotouch</OutputPath>
     <IntermediateOutputPath>./../../class/obj/$(AssemblyName)-monotouch</IntermediateOutputPath>
-    <DefineConstants>NET_1_1;NET_2_0;NET_2_1;NET_3_5;NET_4_0;NET_4_5;MOBILE;MOBILE_LEGACY;MONO;MONOTOUCH;DISABLE_REMOTING;DISABLE_COM;FEATURE_INTERCEPTABLE_THREADPOOL_CALLBACK;FULL_AOT_RUNTIME;COREFX;PLATFORM_UNIX;USEOFFSET;MONO_PARTIAL_DATA_IMPORT;NO_CODEDOM;NO_OLEDB;NO_ODBC;NO_CONFIGURATION;MONO_FEATURE_APPLETLS</DefineConstants>
+    <DefineConstants>NET_1_1;NET_2_0;NET_2_1;NET_3_5;NET_4_0;NET_4_5;MOBILE;MOBILE_LEGACY;MONO;MONOTOUCH;DISABLE_REMOTING;DISABLE_COM;FEATURE_INTERCEPTABLE_THREADPOOL_CALLBACK;FULL_AOT_RUNTIME;COREFX;PLATFORM_UNIX;USEOFFSET;MONO_PARTIAL_DATA_IMPORT;NO_CODEDOM;NO_OLEDB;NO_ODBC;NO_CONFIGURATION;MONO_FEATURE_APPLETLS;ENABLE_GSS</DefineConstants>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Platform)' == 'monotouch_watch' ">
     <OutputPath>./../../class/lib/monotouch_watch</OutputPath>
     <IntermediateOutputPath>./../../class/obj/$(AssemblyName)-monotouch_watch</IntermediateOutputPath>
-    <DefineConstants>NET_1_1;NET_2_0;NET_2_1;NET_3_5;NET_4_0;NET_4_5;MOBILE;MOBILE_LEGACY;MONO;MONOTOUCH;DISABLE_REMOTING;DISABLE_COM;FEATURE_INTERCEPTABLE_THREADPOOL_CALLBACK;FULL_AOT_RUNTIME;FEATURE_NO_BSD_SOCKETS;MONOTOUCH_WATCH;COREFX;PLATFORM_UNIX;USEOFFSET;MONO_PARTIAL_DATA_IMPORT;NO_CODEDOM;NO_OLEDB;NO_ODBC;NO_CONFIGURATION</DefineConstants>
+    <DefineConstants>NET_1_1;NET_2_0;NET_2_1;NET_3_5;NET_4_0;NET_4_5;MOBILE;MOBILE_LEGACY;MONO;MONOTOUCH;DISABLE_REMOTING;DISABLE_COM;FEATURE_INTERCEPTABLE_THREADPOOL_CALLBACK;FULL_AOT_RUNTIME;FEATURE_NO_BSD_SOCKETS;MONOTOUCH_WATCH;COREFX;PLATFORM_UNIX;USEOFFSET;MONO_PARTIAL_DATA_IMPORT;NO_CODEDOM;NO_OLEDB;NO_ODBC;NO_CONFIGURATION;ENABLE_GSS</DefineConstants>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Platform)' == 'monotouch_tv' ">
     <OutputPath>./../../class/lib/monotouch_tv</OutputPath>
     <IntermediateOutputPath>./../../class/obj/$(AssemblyName)-monotouch_tv</IntermediateOutputPath>
-    <DefineConstants>NET_1_1;NET_2_0;NET_2_1;NET_3_5;NET_4_0;NET_4_5;MOBILE;MOBILE_LEGACY;MONO;MONOTOUCH;DISABLE_REMOTING;DISABLE_COM;FEATURE_INTERCEPTABLE_THREADPOOL_CALLBACK;FULL_AOT_RUNTIME;MONOTOUCH_TV;COREFX;PLATFORM_UNIX;USEOFFSET;MONO_PARTIAL_DATA_IMPORT;NO_CODEDOM;NO_OLEDB;NO_ODBC;NO_CONFIGURATION;MONO_FEATURE_APPLETLS</DefineConstants>
+    <DefineConstants>NET_1_1;NET_2_0;NET_2_1;NET_3_5;NET_4_0;NET_4_5;MOBILE;MOBILE_LEGACY;MONO;MONOTOUCH;DISABLE_REMOTING;DISABLE_COM;FEATURE_INTERCEPTABLE_THREADPOOL_CALLBACK;FULL_AOT_RUNTIME;MONOTOUCH_TV;COREFX;PLATFORM_UNIX;USEOFFSET;MONO_PARTIAL_DATA_IMPORT;NO_CODEDOM;NO_OLEDB;NO_ODBC;NO_CONFIGURATION;MONO_FEATURE_APPLETLS;ENABLE_GSS</DefineConstants>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Platform)' == 'testing_aot_hybrid' ">
     <OutputPath>./../../class/lib/testing_aot_hybrid</OutputPath>
@@ -69,12 +69,12 @@
   <PropertyGroup Condition=" '$(Platform)' == 'xammac' ">
     <OutputPath>./../../class/lib/xammac</OutputPath>
     <IntermediateOutputPath>./../../class/obj/$(AssemblyName)-xammac</IntermediateOutputPath>
-    <DefineConstants>NET_1_1;NET_2_0;NET_2_1;NET_3_5;NET_4_0;NET_4_5;MONO;MOBILE;MOBILE_DYNAMIC;XAMMAC;FEATURE_INTERCEPTABLE_THREADPOOL_CALLBACK;XAMARIN_MODERN;COREFX;PLATFORM_UNIX;USEOFFSET;MONO_PARTIAL_DATA_IMPORT;NO_CODEDOM;NO_OLEDB;NO_ODBC;NO_CONFIGURATION;MONO_FEATURE_APPLETLS</DefineConstants>
+    <DefineConstants>NET_1_1;NET_2_0;NET_2_1;NET_3_5;NET_4_0;NET_4_5;MONO;MOBILE;MOBILE_DYNAMIC;XAMMAC;FEATURE_INTERCEPTABLE_THREADPOOL_CALLBACK;XAMARIN_MODERN;COREFX;PLATFORM_UNIX;USEOFFSET;MONO_PARTIAL_DATA_IMPORT;NO_CODEDOM;NO_OLEDB;NO_ODBC;NO_CONFIGURATION;MONO_FEATURE_APPLETLS;ENABLE_GSS</DefineConstants>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Platform)' == 'xammac_net_4_5' ">
     <OutputPath>./../../class/lib/xammac_net_4_5</OutputPath>
     <IntermediateOutputPath>./../../class/obj/$(AssemblyName)-xammac_net_4_5</IntermediateOutputPath>
-    <DefineConstants>NET_4_0;NET_4_5;NET_4_6;MONO;FEATURE_INTERCEPTABLE_THREADPOOL_CALLBACK;NO_SYSTEM_DRAWING_DEPENDENCY;NO_WINFORMS_DEPENDENCY;NO_SYSTEM_WEB_DEPENDENCY;XAMMAC_4_5;XAMARIN_MODERN;COREFX;PLATFORM_UNIX;USEOFFSET;MONO_PARTIAL_DATA_IMPORT;MONO_FEATURE_APPLETLS</DefineConstants>
+    <DefineConstants>NET_4_0;NET_4_5;NET_4_6;MONO;FEATURE_INTERCEPTABLE_THREADPOOL_CALLBACK;NO_SYSTEM_DRAWING_DEPENDENCY;NO_WINFORMS_DEPENDENCY;NO_SYSTEM_WEB_DEPENDENCY;XAMMAC_4_5;XAMARIN_MODERN;COREFX;PLATFORM_UNIX;USEOFFSET;MONO_PARTIAL_DATA_IMPORT;MONO_FEATURE_APPLETLS;ENABLE_GSS</DefineConstants>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Platform)' == 'orbis' ">
     <OutputPath>./../../class/lib/orbis</OutputPath>
@@ -550,9 +550,9 @@
   <Choose>
     <When Condition="'$(Platform)' == 'xammac'">
       <ItemGroup>
-        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\Interop.Libraries.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssApiException.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssBuffer.cs" />
+        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.NetSecurityNative.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Microsoft\Win32\SafeHandles\GssSafeHandles.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\ContextFlagsAdapterPal.Unix.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\Security\NegotiateStreamPal.Unix.cs" />
@@ -577,16 +577,16 @@
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlParameterHelper.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlTransaction.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\TdsParser.Unix.cs" />
-        <Compile Include="corefx\Interop.NetSecurityNative.cs" />
+        <Compile Include="corefx\Interop.Libraries.cs" />
         <Compile Include="corefx\SqlCommand.cs" />
         <Compile Include="corefx\SqlException.cs" />
       </ItemGroup>
     </When>
     <When Condition="'$(Platform)' == 'winaot'">
       <ItemGroup>
-        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\Interop.Libraries.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssApiException.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssBuffer.cs" />
+        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.NetSecurityNative.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Microsoft\Win32\SafeHandles\GssSafeHandles.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\ContextFlagsAdapterPal.Unix.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\Security\NegotiateStreamPal.Unix.cs" />
@@ -611,16 +611,16 @@
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlParameterHelper.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlTransaction.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\TdsParser.Unix.cs" />
-        <Compile Include="corefx\Interop.NetSecurityNative.cs" />
+        <Compile Include="corefx\Interop.Libraries.cs" />
         <Compile Include="corefx\SqlCommand.cs" />
         <Compile Include="corefx\SqlException.cs" />
       </ItemGroup>
     </When>
     <When Condition="'$(Platform)' == 'wasm'">
       <ItemGroup>
-        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\Interop.Libraries.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssApiException.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssBuffer.cs" />
+        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.NetSecurityNative.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Microsoft\Win32\SafeHandles\GssSafeHandles.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\ContextFlagsAdapterPal.Unix.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\Security\NegotiateStreamPal.Unix.cs" />
@@ -645,16 +645,16 @@
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlParameterHelper.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlTransaction.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\TdsParser.Unix.cs" />
-        <Compile Include="corefx\Interop.NetSecurityNative.cs" />
+        <Compile Include="corefx\Interop.Libraries.cs" />
         <Compile Include="corefx\SqlCommand.cs" />
         <Compile Include="corefx\SqlException.cs" />
       </ItemGroup>
     </When>
     <When Condition="'$(Platform)' == 'unreal'">
       <ItemGroup>
-        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\Interop.Libraries.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssApiException.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssBuffer.cs" />
+        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.NetSecurityNative.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Microsoft\Win32\SafeHandles\GssSafeHandles.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\ContextFlagsAdapterPal.Unix.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\Security\NegotiateStreamPal.Unix.cs" />
@@ -679,16 +679,16 @@
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlParameterHelper.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlTransaction.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\TdsParser.Unix.cs" />
-        <Compile Include="corefx\Interop.NetSecurityNative.cs" />
+        <Compile Include="corefx\Interop.Libraries.cs" />
         <Compile Include="corefx\SqlCommand.cs" />
         <Compile Include="corefx\SqlException.cs" />
       </ItemGroup>
     </When>
     <When Condition="'$(Platform)' == 'orbis'">
       <ItemGroup>
-        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\Interop.Libraries.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssApiException.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssBuffer.cs" />
+        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.NetSecurityNative.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Microsoft\Win32\SafeHandles\GssSafeHandles.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\ContextFlagsAdapterPal.Unix.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\Security\NegotiateStreamPal.Unix.cs" />
@@ -713,7 +713,7 @@
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlParameterHelper.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlTransaction.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\TdsParser.Unix.cs" />
-        <Compile Include="corefx\Interop.NetSecurityNative.cs" />
+        <Compile Include="corefx\Interop.Libraries.cs" />
         <Compile Include="corefx\SqlCommand.cs" />
         <Compile Include="corefx\SqlException.cs" />
       </ItemGroup>
@@ -836,9 +836,9 @@
           <ItemGroup>
             <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Interop.Odbc.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Linux\Interop.Libraries.cs" />
-            <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\Interop.Libraries.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssApiException.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssBuffer.cs" />
+            <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.NetSecurityNative.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\Microsoft\Win32\SafeHandles\GssSafeHandles.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\ContextFlagsAdapterPal.Unix.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\Security\NegotiateStreamPal.Unix.cs" />
@@ -910,7 +910,7 @@
             <Compile Include="..\referencesource\System.Data\System\Data\SQLTypes\SqlTypesSchemaImporter.cs" />
             <Compile Include="Microsoft.SqlServer.Server\SqlContext.cs" />
             <Compile Include="Microsoft.SqlServer.Server\SqlPipe.cs" />
-            <Compile Include="corefx\Interop.NetSecurityNative.cs" />
+            <Compile Include="corefx\Interop.Libraries.cs" />
             <Compile Include="corefx\Odbc\DbConnectionStringCommon.cs" />
             <Compile Include="corefx\Odbc\OdbcFactory.cs" />
             <Compile Include="corefx\OleDbStubs.cs" />
@@ -922,9 +922,9 @@
           <ItemGroup>
             <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Interop.Odbc.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\OSX\Interop.Libraries.cs" />
-            <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\Interop.Libraries.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssApiException.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssBuffer.cs" />
+            <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.NetSecurityNative.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\Microsoft\Win32\SafeHandles\GssSafeHandles.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\ContextFlagsAdapterPal.Unix.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\Security\NegotiateStreamPal.Unix.cs" />
@@ -996,7 +996,7 @@
             <Compile Include="..\referencesource\System.Data\System\Data\SQLTypes\SqlTypesSchemaImporter.cs" />
             <Compile Include="Microsoft.SqlServer.Server\SqlContext.cs" />
             <Compile Include="Microsoft.SqlServer.Server\SqlPipe.cs" />
-            <Compile Include="corefx\Interop.NetSecurityNative.cs" />
+            <Compile Include="corefx\Interop.Libraries.cs" />
             <Compile Include="corefx\Odbc\DbConnectionStringCommon.cs" />
             <Compile Include="corefx\Odbc\OdbcFactory.cs" />
             <Compile Include="corefx\OleDbStubs.cs" />
@@ -1008,9 +1008,9 @@
           <ItemGroup>
             <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Interop.Odbc.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Linux\Interop.Libraries.cs" />
-            <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\Interop.Libraries.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssApiException.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssBuffer.cs" />
+            <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.NetSecurityNative.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\Microsoft\Win32\SafeHandles\GssSafeHandles.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\ContextFlagsAdapterPal.Unix.cs" />
             <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\Security\NegotiateStreamPal.Unix.cs" />
@@ -1082,7 +1082,7 @@
             <Compile Include="..\referencesource\System.Data\System\Data\SQLTypes\SqlTypesSchemaImporter.cs" />
             <Compile Include="Microsoft.SqlServer.Server\SqlContext.cs" />
             <Compile Include="Microsoft.SqlServer.Server\SqlPipe.cs" />
-            <Compile Include="corefx\Interop.NetSecurityNative.cs" />
+            <Compile Include="corefx\Interop.Libraries.cs" />
             <Compile Include="corefx\Odbc\DbConnectionStringCommon.cs" />
             <Compile Include="corefx\Odbc\OdbcFactory.cs" />
             <Compile Include="corefx\OleDbStubs.cs" />
@@ -1095,9 +1095,9 @@
     </When>
     <When Condition="'$(Platform)' == 'monotouch_watch'">
       <ItemGroup>
-        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\Interop.Libraries.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssApiException.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssBuffer.cs" />
+        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.NetSecurityNative.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Microsoft\Win32\SafeHandles\GssSafeHandles.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\ContextFlagsAdapterPal.Unix.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\Security\NegotiateStreamPal.Unix.cs" />
@@ -1119,14 +1119,14 @@
         <Compile Include="System.Data.SqlClient\SqlParameter.platformnotsupported.cs" />
         <Compile Include="System.Data.SqlClient\SqlParameterCollection.platformnotsupported.cs" />
         <Compile Include="System.Data.SqlClient\SqlTransaction.platformnotsupported.cs" />
-        <Compile Include="corefx\Interop.NetSecurityNative.cs" />
+        <Compile Include="corefx\Interop.Libraries.cs" />
       </ItemGroup>
     </When>
     <When Condition="'$(Platform)' == 'monotouch_tv'">
       <ItemGroup>
-        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\Interop.Libraries.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssApiException.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssBuffer.cs" />
+        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.NetSecurityNative.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Microsoft\Win32\SafeHandles\GssSafeHandles.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\ContextFlagsAdapterPal.Unix.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\Security\NegotiateStreamPal.Unix.cs" />
@@ -1151,16 +1151,16 @@
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlParameterHelper.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlTransaction.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\TdsParser.Unix.cs" />
-        <Compile Include="corefx\Interop.NetSecurityNative.cs" />
+        <Compile Include="corefx\Interop.Libraries.cs" />
         <Compile Include="corefx\SqlCommand.cs" />
         <Compile Include="corefx\SqlException.cs" />
       </ItemGroup>
     </When>
     <When Condition="'$(Platform)' == 'monotouch'">
       <ItemGroup>
-        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\Interop.Libraries.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssApiException.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssBuffer.cs" />
+        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.NetSecurityNative.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Microsoft\Win32\SafeHandles\GssSafeHandles.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\ContextFlagsAdapterPal.Unix.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\Security\NegotiateStreamPal.Unix.cs" />
@@ -1185,16 +1185,16 @@
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlParameterHelper.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlTransaction.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\TdsParser.Unix.cs" />
-        <Compile Include="corefx\Interop.NetSecurityNative.cs" />
+        <Compile Include="corefx\Interop.Libraries.cs" />
         <Compile Include="corefx\SqlCommand.cs" />
         <Compile Include="corefx\SqlException.cs" />
       </ItemGroup>
     </When>
     <When Condition="'$(Platform)' == 'monodroid'">
       <ItemGroup>
-        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\Interop.Libraries.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssApiException.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.GssBuffer.cs" />
+        <Compile Include="..\..\..\external\corefx\src\Common\src\Interop\Unix\System.Net.Security.Native\Interop.NetSecurityNative.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\Microsoft\Win32\SafeHandles\GssSafeHandles.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\ContextFlagsAdapterPal.Unix.cs" />
         <Compile Include="..\..\..\external\corefx\src\Common\src\System\Net\Security\NegotiateStreamPal.Unix.cs" />
@@ -1219,7 +1219,7 @@
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlParameterHelper.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlTransaction.cs" />
         <Compile Include="..\..\..\external\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\TdsParser.Unix.cs" />
-        <Compile Include="corefx\Interop.NetSecurityNative.cs" />
+        <Compile Include="corefx\Interop.Libraries.cs" />
         <Compile Include="corefx\SqlCommand.cs" />
         <Compile Include="corefx\SqlException.cs" />
       </ItemGroup>

+ 2 - 3
mcs/class/System.Data/corefx.unix.sources

@@ -4,10 +4,9 @@
 ../../../external/corefx/src/Common/src/System/Net/Security/Unix/SafeDeleteContext.cs
 ../../../external/corefx/src/Common/src/System/Net/Security/Unix/SafeFreeCredentials.cs
 ../../../external/corefx/src/Common/src/Microsoft/Win32/SafeHandles/GssSafeHandles.cs
-corefx/Interop.NetSecurityNative.cs
-#../../../external/corefx/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.NetSecurityNative.cs
+../../../external/corefx/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.NetSecurityNative.cs
 ../../../external/corefx/src/Common/src/System/Net/Security/Unix/SafeFreeNegoCredentials.cs
-../../../external/corefx/src/Common/src/Interop/Unix/Interop.Libraries.cs
+corefx/Interop.Libraries.cs
 ../../../external/corefx/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssBuffer.cs
 ../../../external/corefx/src/Common/src/System/Net/Security/Unix/SafeDeleteNegoContext.cs
 ../../../external/corefx/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssApiException.cs

+ 11 - 0
mcs/class/System.Data/corefx/Interop.Libraries.cs

@@ -0,0 +1,11 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+internal static partial class Interop
+{
+    internal static partial class Libraries
+    {
+        internal const string NetSecurityNative = "System.Net.Security.Native";
+    }
+}

+ 0 - 147
mcs/class/System.Data/corefx/Interop.NetSecurityNative.cs

@@ -1,147 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Text;
-using Microsoft.Win32.SafeHandles;
-
-// stubs for external/corefx/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.NetSecurityNative.cs
-// needed for https://github.com/mono/mono/issues/6766
-// or can be implemented via pal_gssapi (see https://github.com/mono/mono/pull/6806)
-static partial class Interop
-{
-    static partial class NetSecurityNative
-    {
-        internal static void ReleaseGssBuffer (
-            IntPtr bufferPtr,
-            UInt64 length) => throw new NotSupportedException ();
-
-        internal static Status DisplayMinorStatus (
-            out Status minorStatus,
-            Status statusValue,
-            ref GssBuffer buffer) => throw new NotSupportedException ();
-
-        internal static Status DisplayMajorStatus (
-            out Status minorStatus,
-            Status statusValue,
-            ref GssBuffer buffer) => throw new NotSupportedException ();
-
-        internal static Status ImportUserName (
-            out Status minorStatus,
-            string inputName,
-            int inputNameByteCount,
-            out SafeGssNameHandle outputName) => throw new NotSupportedException ();
-
-        internal static Status ImportPrincipalName (
-            out Status minorStatus,
-            string inputName,
-            int inputNameByteCount,
-            out SafeGssNameHandle outputName) => throw new NotSupportedException ();
-
-        internal static Status ReleaseName (
-            out Status minorStatus,
-            ref IntPtr inputName) => throw new NotSupportedException ();
-
-        internal static Status InitiateCredSpNego (
-            out Status minorStatus,
-            SafeGssNameHandle desiredName,
-            out SafeGssCredHandle outputCredHandle) => throw new NotSupportedException ();
-
-        internal static Status InitiateCredWithPassword (
-            out Status minorStatus,
-            bool isNtlm,
-            SafeGssNameHandle desiredName,
-            string password,
-            int passwordLen,
-            out SafeGssCredHandle outputCredHandle) => throw new NotSupportedException ();
-
-        internal static Status ReleaseCred (
-            out Status minorStatus,
-            ref IntPtr credHandle) => throw new NotSupportedException ();
-
-        internal static Status InitSecContext (
-            out Status minorStatus,
-            SafeGssCredHandle initiatorCredHandle,
-            ref SafeGssContextHandle contextHandle,
-            bool isNtlmOnly,
-            SafeGssNameHandle targetName,
-            uint reqFlags,
-            byte[] inputBytes,
-            int inputLength,
-            ref GssBuffer token,
-            out uint retFlags,
-            out int isNtlmUsed) => throw new NotSupportedException ();
-
-        internal static Status AcceptSecContext (
-            out Status minorStatus,
-            ref SafeGssContextHandle acceptContextHandle,
-            byte[] inputBytes,
-            int inputLength,
-            ref GssBuffer token) => throw new NotSupportedException ();
-
-        internal static Status DeleteSecContext (
-            out Status minorStatus,
-            ref IntPtr contextHandle) => throw new NotSupportedException ();
-
-        static Status Wrap(
-            out Status minorStatus,
-            SafeGssContextHandle contextHandle,
-            bool isEncrypt,
-            byte[] inputBytes,
-            int offset,
-            int count,
-            ref GssBuffer outBuffer) => throw new NotSupportedException ();
-
-        static Status Unwrap (
-            out Status minorStatus,
-            SafeGssContextHandle contextHandle,
-            byte[] inputBytes,
-            int offset,
-            int count,
-            ref GssBuffer outBuffer) => throw new NotSupportedException ();
-
-        internal static Status WrapBuffer (
-            out Status minorStatus,
-            SafeGssContextHandle contextHandle,
-            bool isEncrypt,
-            byte[] inputBytes,
-            int offset,
-            int count,
-            ref GssBuffer outBuffer) => throw new NotSupportedException ();
-
-        internal static Status UnwrapBuffer (
-            out Status minorStatus,
-            SafeGssContextHandle contextHandle,
-            byte[] inputBytes,
-            int offset,
-            int count,
-            ref GssBuffer outBuffer) => throw new NotSupportedException ();
-
-        internal enum Status : uint
-        {
-            GSS_S_COMPLETE = 0,
-            GSS_S_CONTINUE_NEEDED = 1
-        }
-
-        [Flags]
-        internal enum GssFlags : uint
-        {
-            GSS_C_DELEG_FLAG = 0x1,
-            GSS_C_MUTUAL_FLAG = 0x2,
-            GSS_C_REPLAY_FLAG = 0x4,
-            GSS_C_SEQUENCE_FLAG = 0x8,
-            GSS_C_CONF_FLAG = 0x10,
-            GSS_C_INTEG_FLAG = 0x20,
-            GSS_C_ANON_FLAG = 0x40,
-            GSS_C_PROT_READY_FLAG = 0x80,
-            GSS_C_TRANS_FLAG = 0x100,
-            GSS_C_DCE_STYLE = 0x1000,
-            GSS_C_IDENTIFY_FLAG = 0x2000,
-            GSS_C_EXTENDED_ERROR_FLAG = 0x4000,
-            GSS_C_DELEG_POLICY_FLAG = 0x8000
-        }
-    }
-}

+ 13 - 0
mono/metadata/Makefile.am

@@ -163,6 +163,16 @@ system_native_common_sources = \
 	../../external/corefx/src/Native/Unix/System.Native/pal_memory.c \
 	../../external/corefx/src/Native/Unix/System.Native/pal_memory.h
 
+if ENABLE_GSS
+libmono_system_net_security_native_la_SOURCES = \
+	pal_config.h \
+	../../external/corefx/src/Native/Unix/Common/pal_compiler.h \
+	../../external/corefx/src/Native/Unix/Common/pal_types.h \
+	../../external/corefx/src/Native/Unix/Common/pal_utilities.h \
+	../../external/corefx/src/Native/Unix/System.Net.Security.Native/pal_gssapi.c \
+	../../external/corefx/src/Native/Unix/System.Net.Security.Native/pal_gssapi.h
+endif
+
 system_native_full_sources = \
 	../../external/corefx/src/Native/Unix/System.Native/pal_io.c \
 	../../external/corefx/src/Native/Unix/System.Native/pal_io.h \
@@ -186,6 +196,7 @@ system_native_android_sources = \
 if !HOST_WIN32
 if !HOST_WASM
 lib_LTLIBRARIES += libmono-system-native.la
+lib_LTLIBRARIES += libmono-system-net-security-native.la
 libmono_system_native_la_SOURCES = $(system_native_common_sources)
 if TARGET_OSX
 libmono_system_native_la_SOURCES += $(system_native_full_sources)
@@ -206,6 +217,8 @@ endif
 # Add back CXX_REMOVE_CFLAGS to keep this as C until/unless https://github.com/dotnet/corefx/pull/31342.
 libmono_system_native_la_CFLAGS = -I$(abs_top_srcdir)/external/corefx/src/Native/Unix/Common -I$(abs_top_srcdir)/external/corefx/src/Native/Unix/System.Native -Wno-typedef-redefinition @CXX_REMOVE_CFLAGS@
 libmono_system_native_la_LDFLAGS = $(libmonoldflags)
+libmono_system_net_security_native_la_CFLAGS = $(libmono_system_native_la_CFLAGS)
+libmono_system_net_security_native_la_LDFLAGS = $(libmono_system_native_la_LDFLAGS)
 
 CLEANFILES = mono-bundle.stamp
 

+ 7 - 0
runtime/Makefile.am

@@ -207,6 +207,13 @@ etc/mono/config: ../data/config Makefile $(symlinks)
 	else \
 		echo "Unknown directory '$(abs_top_builddir)/mono/metadata'" && false; \
 	fi
+	if test -d "$(abs_top_builddir)/mono/metadata"; then \
+		sed 's,target="$$mono_libdir/libmono-system-net-security-native$(libsuffix)",target="$(abs_top_builddir)/mono/metadata/libmono-system-net-security-native.la",' $@ > [email protected] \
+		 && mv [email protected] $@ \
+		 ; \
+	else \
+		echo "Unknown directory '$(abs_top_builddir)/mono/metadata'" && false; \
+	fi
 	if test -d "$(abs_top_builddir)/mono/btls/build-shared"; then \
 		sed 's,target="$$mono_libdir/libmono-btls-shared$(libsuffix)",target="$(abs_top_builddir)/mono/btls/build-shared/libmono-btls-shared$(libsuffix)",' $@ > [email protected] \
 		 && mv [email protected] $@ \