[security] Use coop handles for ves_icall_System_Security_Principal_WindowsIdentity_G...
authorAleksey Kliger <aleksey@xamarin.com>
Wed, 3 May 2017 19:17:35 +0000 (15:17 -0400)
committerAleksey Kliger <aleksey@xamarin.com>
Wed, 10 May 2017 15:14:00 +0000 (11:14 -0400)
Refactor it into mono_security_principal_windows_identity_get_current_token ()
and then call that from ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken ()

mono/metadata/icall-def.h
mono/metadata/mono-security-windows-uwp.c
mono/metadata/mono-security-windows.c
mono/metadata/mono-security.c
mono/metadata/security.h

index a9214eb86c55d83132b6222ebd45f44c3c1bc7a8..c4de45f4970eb9505253deb4c16688ca1c313575 100644 (file)
@@ -830,7 +830,7 @@ ICALL_TYPE(EVID, "System.Security.Policy.Evidence", EVID_1)
 HANDLES(ICALL(EVID_1, "IsAuthenticodePresent", ves_icall_System_Security_Policy_Evidence_IsAuthenticodePresent))
 
 ICALL_TYPE(WINID, "System.Security.Principal.WindowsIdentity", WINID_1)
-ICALL(WINID_1, "GetCurrentToken", ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken)
+HANDLES(ICALL(WINID_1, "GetCurrentToken", ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken))
 ICALL(WINID_2, "GetTokenName", ves_icall_System_Security_Principal_WindowsIdentity_GetTokenName)
 ICALL(WINID_3, "GetUserToken", ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken)
 ICALL(WINID_4, "_GetRoles", ves_icall_System_Security_Principal_WindowsIdentity_GetRoles)
index 42f5297aaa627c0373e4ca254d44a1ee78bb3743..72989994c1397eb9c775eb5a6aca8e909b5087c2 100644 (file)
 #include "mono/metadata/mono-security-windows-internals.h"
 
 gpointer
-ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken (void)
+mono_security_principal_windows_identity_get_current_token ()
 {
-       MonoError mono_error;
-       error_init (&mono_error);
-
        g_unsupported_api ("OpenThreadToken, OpenProcessToken");
 
-       mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, "OpenThreadToken, OpenProcessToken");
-       mono_error_set_pending_exception (&mono_error);
-
        SetLastError (ERROR_NOT_SUPPORTED);
-
        return NULL;
 }
 
+gpointer
+ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken (MonoError *error)
+{
+       error_init (error);
+
+       mono_error_set_not_supported (error, G_UNSUPPORTED_API, "OpenThreadToken, OpenProcessToken");
+       return mono_security_principal_windows_identity_get_current_token ();
+}
+
 MonoArray*
 ves_icall_System_Security_Principal_WindowsIdentity_GetRoles (gpointer token)
 {
index 7a34c8a1a6186206251169b4a6e0602a3dfa0c98..fbc9545c96f3646d92c01553ae92da0e6f627a9c 100644 (file)
@@ -69,7 +69,7 @@ GetSidName (gunichar2 *server, PSID sid, gint32 *size)
 }
 
 gpointer
-ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken (void)
+mono_security_principal_windows_identity_get_current_token (void)
 {
        gpointer token = NULL;
 
@@ -86,6 +86,13 @@ ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken (void)
        return token;
 }
 
+gpointer
+ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken (MonoError *error)
+{
+       error_init (error);
+       return mono_security_principal_windows_identity_get_current_token ();
+}
+
 gint32
 mono_security_win_get_token_name (gpointer token, gunichar2 ** uniname)
 {
@@ -264,7 +271,7 @@ GetCurrentUserSid (void)
 {
        PSID sid = NULL;
        guint32 size = 0;
-       gpointer token = ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken ();
+       gpointer token = mono_security_principal_windows_identity_get_current_token ();
 
        GetTokenInformation (token, TokenUser, NULL, size, (PDWORD)&size);
        if (size > 0) {
index fe043d0a6bfaa861dc0b37a0ac307dd1bc19381d..a57cb0fadf3b80ee91734d642cd0eeb08a80b8e9 100644 (file)
@@ -216,11 +216,18 @@ IsMemberOf (gid_t user, struct group *g)
 
 #ifndef HOST_WIN32
 gpointer
-ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken (void)
+mono_security_principal_windows_identity_get_current_token ()
 {
        return GINT_TO_POINTER (geteuid ());
 }
 
+gpointer
+ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken (MonoError *error)
+{
+       error_init (error);
+       return mono_security_principal_windows_identity_get_current_token ();
+}
+
 static gint32
 internal_get_token_name (gpointer token, gunichar2 ** uniname)
 {
index 44e4b4ea4c1617bfb6763b10c06d931a30e5bbce..b3fa721bef4d9785c2e8628d2334bf450f0579b8 100644 (file)
@@ -26,8 +26,9 @@ extern MonoStringHandle ves_icall_System_Environment_get_UserName (MonoError *er
 
 
 /* System.Security.Principal.WindowsIdentity */
+gpointer mono_security_principal_windows_identity_get_current_token (void);
 extern MonoArray* ves_icall_System_Security_Principal_WindowsIdentity_GetRoles (gpointer token);
-extern gpointer ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken (void);
+extern gpointer ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken (MonoError *error);
 extern MonoString* ves_icall_System_Security_Principal_WindowsIdentity_GetTokenName (gpointer token);
 extern gpointer ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken (MonoString *username);