[io-layer] Extract error (#4279)
[mono.git] / mono / metadata / mono-security.c
index 09b8cd44abe6deaba2428602aa257022dbf21a88..a1d3c9d0e4fe22e880944a855475c09b7ad09a00 100644 (file)
@@ -19,7 +19,6 @@
 #include <mono/metadata/object-internals.h>
 #include <mono/metadata/metadata-internals.h>
 #include <mono/metadata/security.h>
-#include <mono/io-layer/io-layer.h>
 #include <mono/utils/strenc.h>
 
 #ifndef HOST_WIN32
@@ -337,15 +336,41 @@ ves_icall_System_Security_Principal_WindowsImpersonationContext_DuplicateToken (
 gboolean
 ves_icall_System_Security_Principal_WindowsImpersonationContext_SetCurrentToken (gpointer token)
 {
-       /* Posix version implemented in /mono/mono/io-layer/security.c */
+#ifdef HOST_WIN32
        return (ImpersonateLoggedOnUser (token) != 0);
+#else
+       uid_t itoken = (uid_t) GPOINTER_TO_INT (token);
+#ifdef HAVE_SETRESUID
+       if (setresuid (-1, itoken, getuid ()) < 0)
+               return FALSE;
+#endif
+       return geteuid () == itoken;
+#endif
 }
 
 gboolean
 ves_icall_System_Security_Principal_WindowsImpersonationContext_RevertToSelf (void)
 {
-       /* Posix version implemented in /mono/mono/io-layer/security.c */
+#ifdef HOST_WIN32
        return (RevertToSelf () != 0);
+#else
+#ifdef HAVE_GETRESUID
+       uid_t ruid, euid;
+#endif
+       uid_t suid = -1;
+
+#ifdef HAVE_GETRESUID
+       if (getresuid (&ruid, &euid, &suid) < 0)
+               return FALSE;
+#endif
+#ifdef HAVE_SETRESUID
+       if (setresuid (-1, suid, -1) < 0)
+               return FALSE;
+#else
+       return TRUE;
+#endif
+       return geteuid () == suid;
+#endif
 }
 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
 
@@ -524,10 +549,14 @@ ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectUser (MonoString
  * Note: Neither the structure nor the signature is verified by this function.
  */
 MonoBoolean
-ves_icall_System_Security_Policy_Evidence_IsAuthenticodePresent (MonoReflectionAssembly *refass)
+ves_icall_System_Security_Policy_Evidence_IsAuthenticodePresent (MonoReflectionAssemblyHandle refass, MonoError *error)
 {
-       if (refass && refass->assembly && refass->assembly->image) {
-               return (MonoBoolean)mono_image_has_authenticode_entry (refass->assembly->image);
+       mono_error_init (error);
+       if (MONO_HANDLE_IS_NULL (refass))
+               return FALSE;
+       MonoAssembly *assembly = MONO_HANDLE_GETVAL (refass, assembly);
+       if (assembly && assembly->image) {
+               return (MonoBoolean)mono_image_has_authenticode_entry (assembly->image);
        }
        return FALSE;
 }