Fill out AssemblyName.ProcessorArchitecture for assemblies. Fixes #15347.
[mono.git] / mono / metadata / security-core-clr.c
index 2376cdd4c2d17343cfa0ad22f0a01eba7af24476..1be63ffc2240dbfcce52661320765620449a384d 100644 (file)
 
 gboolean mono_security_core_clr_test = FALSE;
 
+static MonoSecurityCoreCLROptions security_core_clr_options = MONO_SECURITY_CORE_CLR_OPTIONS_DEFAULT;
+
+/**
+ * mono_security_core_clr_set_options:
+ * @options: the new options for the coreclr system to use
+ *
+ * By default, the CoreCLRs security model forbids execution trough reflection of methods not visible from the calling code.
+ * Even if the method being called is not in a platform assembly. For non moonlight CoreCLR users this restriction does not
+ * make a lot of sense, since the author could have just changed the non platform assembly to allow the method to be called.
+ * This function allows specific relaxations from the default behaviour to be set.
+ *
+ * Use MONO_SECURITY_CORE_CLR_OPTIONS_DEFAULT for the default coreclr coreclr behaviour as used in Moonlight.
+ *
+ * Use MONO_SECURITY_CORE_CLR_OPTIONS_RELAX_REFLECTION to allow transparent code to execute methods and access 
+ * fields that are not in platformcode, even if those methods and fields are private or otherwise not visible to the calling code.
+ *
+ * Use MONO_SECURITY_CORE_CLR_OPTIONS_RELAX_DELEGATE to allow delegates to be created that point at methods that are not in
+ * platformcode even if those methods and fields are private or otherwise not visible to the calling code.
+ *
+ */
+void
+mono_security_core_clr_set_options (MonoSecurityCoreCLROptions options) {
+       security_core_clr_options = options;
+}
+
+/**
+ * mono_security_core_clr_get_options:
+ *
+ * Retrieves the current options used by the coreclr system.
+ */
+
+MonoSecurityCoreCLROptions
+mono_security_core_clr_get_options ()
+{
+       return security_core_clr_options;
+}
+
+/*
+ * default_platform_check:
+ *
+ *     Default platform check. Always TRUE for current corlib (minimum 
+ *     trust-able subset) otherwise return FALSE. Any real CoreCLR host
+ *     should provide its own callback to define platform code (i.e.
+ *     this default is meant for test only).
+ */
+static gboolean
+default_platform_check (const char *image_name)
+{
+       if (mono_defaults.corlib) {
+               return (strcmp (mono_defaults.corlib->name, image_name) == 0);
+       } else {
+               /* this can get called even before we load corlib (e.g. the EXE itself) */
+               const char *corlib = "mscorlib.dll";
+               int ilen = strlen (image_name);
+               int clen = strlen (corlib);
+               return ((ilen >= clen) && (strcmp ("mscorlib.dll", image_name + ilen - clen) == 0));
+       }
+}
+
+static MonoCoreClrPlatformCB platform_callback = default_platform_check;
+
+/*
+ * mono_security_core_clr_determine_platform_image:
+ *
+ *  Call the supplied callback (from mono_security_set_core_clr_platform_callback) 
+ *  to determine if this image represents platform code.
+ */
+gboolean
+mono_security_core_clr_determine_platform_image (MonoImage *image)
+{
+       return platform_callback (image->name);
+}
+
+/*
+ * mono_security_set_core_clr_platform_callback:
+ *
+ *  Set the callback function that will be used to determine if an image
+ *  is part, or not, of the platform code.
+ */
+void
+mono_security_set_core_clr_platform_callback (MonoCoreClrPlatformCB callback)
+{
+       platform_callback = callback;
+}
+
+/*
+ * mono_security_core_clr_is_platform_image:
+ *
+ *   Return the (cached) boolean value indicating if this image represent platform code
+ */
+gboolean
+mono_security_core_clr_is_platform_image (MonoImage *image)
+{
+       return image->core_clr_platform_code;
+}
+
+/* Note: The above functions are outside this guard so that the public API isn't affected. */
+
+#ifndef DISABLE_SECURITY
+
 static MonoClass*
 security_critical_attribute (void)
 {
@@ -409,29 +509,6 @@ mono_security_core_clr_require_elevated_permissions (void)
 }
 
 
-static MonoSecurityCoreCLROptions security_core_clr_options = MONO_SECURITY_CORE_CLR_OPTIONS_DEFAULT;
-
-/*
- * mono_security_core_clr_set_options
- *
- *      By default, the CoreCLRs security model forbids execution trough reflection of methods not visible from the calling code.
- *      Even if the method being called is not in a platform assembly. For non moonlight CoreCLR users this restriction does not
- *      make a lot of sense, since the author could have just changed the non platform assembly to allow the method to be called.
- *     this function allows specific relaxations from the default behaviour to be set. 
- */
-
-void 
-mono_security_core_clr_set_options (MonoSecurityCoreCLROptions options) {
-       security_core_clr_options = options;
-}
-
-MonoSecurityCoreCLROptions
-mono_security_core_clr_get_options ()
-{
-       return security_core_clr_options;
-}
-
-
 /*
  * check_field_access:
  *
@@ -918,73 +995,90 @@ mono_security_core_clr_method_level (MonoMethod *method, gboolean with_class_lev
 }
 
 /*
- * mono_security_core_clr_is_platform_image:
+ * mono_security_enable_core_clr:
  *
- *   Return the (cached) boolean value indicating if this image represent platform code
+ *   Enable the verifier and the CoreCLR security model
  */
-gboolean
-mono_security_core_clr_is_platform_image (MonoImage *image)
+void
+mono_security_enable_core_clr ()
 {
-       return image->core_clr_platform_code;
+       mono_verifier_set_mode (MONO_VERIFIER_MODE_VERIFIABLE);
+       mono_security_set_mode (MONO_SECURITY_MODE_CORE_CLR);
 }
 
-/*
- * default_platform_check:
- *
- *     Default platform check. Always TRUE for current corlib (minimum 
- *     trust-able subset) otherwise return FALSE. Any real CoreCLR host
- *     should provide its own callback to define platform code (i.e.
- *     this default is meant for test only).
- */
-static gboolean
-default_platform_check (const char *image_name)
+#else
+
+void
+mono_security_core_clr_check_inheritance (MonoClass *class)
 {
-       if (mono_defaults.corlib) {
-               return (strcmp (mono_defaults.corlib->name, image_name) == 0);
-       } else {
-               /* this can get called even before we load corlib (e.g. the EXE itself) */
-               const char *corlib = "mscorlib.dll";
-               int ilen = strlen (image_name);
-               int clen = strlen (corlib);
-               return ((ilen >= clen) && (strcmp ("mscorlib.dll", image_name + ilen - clen) == 0));
-       }
 }
 
-static MonoCoreClrPlatformCB platform_callback = default_platform_check;
+void
+mono_security_core_clr_check_override (MonoClass *class, MonoMethod *override, MonoMethod *base)
+{
+}
 
-/*
- * mono_security_core_clr_determine_platform_image:
- *
- *     Call the supplied callback (from mono_security_set_core_clr_platform_callback) 
- *     to determine if this image represents platform code.
- */
 gboolean
-mono_security_core_clr_determine_platform_image (MonoImage *image)
+mono_security_core_clr_require_elevated_permissions (void)
 {
-       return platform_callback (image->name);
+       return FALSE;
 }
 
-/*
- * mono_security_enable_core_clr:
- *
- *   Enable the verifier and the CoreCLR security model
- */
 void
-mono_security_enable_core_clr ()
+mono_security_core_clr_ensure_reflection_access_field (MonoClassField *field)
 {
-       mono_verifier_set_mode (MONO_VERIFIER_MODE_VERIFIABLE);
-       mono_security_set_mode (MONO_SECURITY_MODE_CORE_CLR);
 }
 
-/*
- * mono_security_set_core_clr_platform_callback:
- *
- *     Set the callback function that will be used to determine if an image
- *     is part, or not, of the platform code.
- */
 void
-mono_security_set_core_clr_platform_callback (MonoCoreClrPlatformCB callback)
+mono_security_core_clr_ensure_reflection_access_method (MonoMethod *method)
+{
+}
+
+gboolean
+mono_security_core_clr_ensure_delegate_creation (MonoMethod *method, gboolean throwOnBindFailure)
+{
+       return TRUE;
+}
+
+MonoException*
+mono_security_core_clr_ensure_dynamic_method_resolved_object (gpointer ref, MonoClass *handle_class)
+{
+       return NULL;
+}
+
+gboolean
+mono_security_core_clr_can_access_internals (MonoImage *accessing, MonoImage* accessed)
+{
+       return TRUE;
+}
+
+MonoException*
+mono_security_core_clr_is_field_access_allowed (MonoMethod *caller, MonoClassField *field)
+{
+       return NULL;
+}
+
+MonoException*
+mono_security_core_clr_is_call_allowed (MonoMethod *caller, MonoMethod *callee)
+{
+       return NULL;
+}
+
+MonoSecurityCoreCLRLevel
+mono_security_core_clr_class_level (MonoClass *class)
+{
+       return MONO_SECURITY_CORE_CLR_TRANSPARENT;
+}
+
+MonoSecurityCoreCLRLevel
+mono_security_core_clr_method_level (MonoMethod *method, gboolean with_class_level)
+{
+       return MONO_SECURITY_CORE_CLR_TRANSPARENT;
+}
+
+void
+mono_security_enable_core_clr ()
 {
-       platform_callback = callback;
 }
 
+#endif /* DISABLE_SECURITY */