2005-03-10 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Thu, 10 Mar 2005 13:25:35 +0000 (13:25 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Thu, 10 Mar 2005 13:25:35 +0000 (13:25 -0000)
* exception.c|h: Added mono_get_exception_reflection_type_load to
create a ReflectionTypeLoadException object.
* icall.c: Updated ves_icall_System_Reflection_Assembly_InternalGetType
to return NULL is a InheritanceDemand fails during reflection. Updated
ves_icall_System_Reflection_Assembly_GetTypes to throw a
ReflectionTypeLoadException if an InheritanceDemand fails during
reflection. Added icall mapping for GetLinkDemandSecurity.
* security-manager.c|h: Added ves_icall_System_Security_
SecurityManager_GetLinkDemandSecurity internal call to return the
class and methods permissions set for a LinkDemand. Removed unused
fields in MonoSecurityManager.

svn path=/trunk/mono/; revision=41645

mono/metadata/ChangeLog
mono/metadata/exception.c
mono/metadata/exception.h
mono/metadata/icall.c
mono/metadata/security-manager.c
mono/metadata/security-manager.h

index fae09cb504fff7dcd67f6961a406df61522a6695..b1921da14a523b876ae927c97d409dad7b776323 100644 (file)
@@ -1,3 +1,17 @@
+2005-03-10  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * exception.c|h: Added mono_get_exception_reflection_type_load to
+       create a ReflectionTypeLoadException object.
+       * icall.c: Updated ves_icall_System_Reflection_Assembly_InternalGetType
+       to return NULL is a InheritanceDemand fails during reflection. Updated
+       ves_icall_System_Reflection_Assembly_GetTypes to throw a 
+       ReflectionTypeLoadException if an InheritanceDemand fails during 
+       reflection. Added icall mapping for GetLinkDemandSecurity.
+       * security-manager.c|h: Added ves_icall_System_Security_
+       SecurityManager_GetLinkDemandSecurity internal call to return the
+       class and methods permissions set for a LinkDemand. Removed unused
+       fields in MonoSecurityManager.
+
 2005-03-10  Martin Baulig  <martin@ximian.com>
 
        * class.c (mono_bounded_array_class_get): Initialize `eclass' if
index a2d34fe6f74012d8c2fc4026e6b58cec082cbc9f..5212e34461889ad7de8d72a86951027f3da3c145 100644 (file)
@@ -410,3 +410,27 @@ mono_get_exception_stack_overflow (void)
 {
        return mono_exception_from_name (mono_get_corlib (), "System", "StackOverflowException");       
 }
+
+MonoException *
+mono_get_exception_reflection_type_load (MonoArray *types, MonoArray *exceptions)
+{
+       MonoClass *klass;
+       gpointer args [2];
+       MonoObject *exc;
+       MonoMethod *method;
+
+       klass = mono_class_from_name (mono_get_corlib (), "System.Reflection", "ReflectionTypeLoadException");
+       g_assert (klass);
+       mono_class_init (klass);
+
+       method = mono_class_get_method_from_name (klass, ".ctor", 2);
+       g_assert (method);
+
+       args [0] = types;
+       args [1] = exceptions;
+
+       exc = mono_object_new (mono_domain_get (), klass);
+       mono_runtime_invoke (method, exc, args, NULL);
+
+       return (MonoException *) exc;
+}
index ded278098bde12df73349bd5450690760c967407..47285ee2d252aa751818154b8c80522b857ef1a6 100644 (file)
@@ -112,4 +112,7 @@ mono_get_exception_bad_image_format (const guchar *msg);
 MonoException *
 mono_get_exception_stack_overflow (void);
 
+MonoException *
+mono_get_exception_reflection_type_load (MonoArray *types, MonoArray *exceptions);
+
 #endif /* _MONO_METADATA_EXCEPTION_H_ */
index 39add280bad84c56fa21cccc1806a04057d55c21..b2b0fec442240db01fba9fc77e6975a611cbde03 100644 (file)
@@ -3325,9 +3325,21 @@ ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *as
                /* g_print ("failed find\n"); */
                return NULL;
        }
+
+       if (type->type == MONO_TYPE_CLASS) {
+               MonoClass *klass = mono_type_get_class (type);
+               /* need to report exceptions ? */
+               if (throwOnError && klass->exception_type) {
+                       /* report SecurityException (or others) that occured when loading the assembly */
+                       MonoException *exc = mono_class_get_exception_for_failure (klass);
+                       mono_raise_exception (exc);
+               } else if (klass->exception_type == MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND) {
+                       return NULL;
+               }
+       }
+
        /* g_print ("got it\n"); */
        return mono_type_get_object (mono_object_domain (assembly), type);
-
 }
 
 static MonoString *
@@ -4179,7 +4191,46 @@ ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly,
                                }
                        }
                }
-       }               
+       }
+
+       if (mono_is_security_manager_active ()) {
+               /* the ReflectionTypeLoadException must have all the types (Types property), 
+                * NULL replacing types which throws an exception. The LoaderException must
+                * contains all exceptions for NULL items.
+                */
+
+               guint32 len = mono_array_length (res);
+               GList *list = NULL;
+
+               for (i = 0; i < len; i++) {
+                       MonoReflectionType *t = mono_array_get (res, gpointer, i);
+                       MonoClass *klass = mono_type_get_class (t->type);
+                       if ((klass != NULL) && klass->exception_type) {
+                               /* keep the class in the list */
+                               list = g_list_append (list, klass);
+                               /* and replace Type with NULL */
+                               mono_array_set (res, gpointer, i, NULL);
+                       }
+               }
+
+               if (list) {
+                       GList *tmp = NULL;
+                       MonoException *exc = NULL;
+                       int length = g_list_length (list);
+
+                       MonoArray *exl = mono_array_new (domain, mono_defaults.exception_class, length);
+                       for (i = 0, tmp = list; i < length; i++, tmp = tmp->next) {
+                               MonoException *exc = mono_class_get_exception_for_failure (tmp->data);
+                               mono_array_set (exl, gpointer, i, exc);
+                       }
+                       g_list_free (list);
+                       list = NULL;
+
+                       exc = mono_get_exception_reflection_type_load (res, exl);
+                       mono_raise_exception (exc);
+               }
+       }
+               
        return res;
 }
 
@@ -6620,6 +6671,7 @@ static const IcallEntry evidence_icalls [] = {
 };
 
 static const IcallEntry securitymanager_icalls [] = {
+       {"GetLinkDemandSecurity", ves_icall_System_Security_SecurityManager_GetLinkDemandSecurity},
        {"get_CheckExecutionRights", ves_icall_System_Security_SecurityManager_get_CheckExecutionRights},
        {"get_SecurityEnabled", ves_icall_System_Security_SecurityManager_get_SecurityEnabled},
        {"set_CheckExecutionRights", ves_icall_System_Security_SecurityManager_set_CheckExecutionRights},
index ba29325cb3eda50d5b8aded4a85c452d17644a00..f5d9eacdbe16e1aba2eebaf7f4dec4dc53e66460 100644 (file)
@@ -38,6 +38,10 @@ mono_security_manager_get_methods (void)
                "InternalDemand", 2);   
        g_assert (secman.demand);
 
+       secman.demandchoice = mono_class_get_method_from_name (secman.securitymanager,
+               "InternalDemandChoice", 2);     
+       g_assert (secman.demandchoice);
+
        secman.inheritancedemand = mono_class_get_method_from_name (secman.securitymanager,
                "InheritanceDemand", 2);        
        g_assert (secman.inheritancedemand);
@@ -167,6 +171,8 @@ mono_is_ecma_key (const char *publickey, int size)
        return TRUE;
 }
 
+/* System.Security icalls */
+
 MonoBoolean
 ves_icall_System_Security_SecurityManager_get_SecurityEnabled (void)
 {
@@ -200,3 +206,25 @@ ves_icall_System_Security_SecurityManager_set_CheckExecutionRights (MonoBoolean
                mono_security_manager_execution = value;
        }
 }
+
+MonoBoolean
+ves_icall_System_Security_SecurityManager_GetLinkDemandSecurity (MonoReflectionMethod *m, MonoDeclSecurityActions *kactions, MonoDeclSecurityActions *mactions)
+{
+       MonoMethod *method = m->method;
+       /* we want the original as the wrapper is "free" of the security informations */
+       if (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) {
+               method = mono_marshal_method_from_wrapper (method);
+       }
+
+       mono_class_init (method->klass);
+
+       /* if either the method or it's class has security (any type) */
+       if ((method->flags & METHOD_ATTRIBUTE_HAS_SECURITY) || (method->klass->flags & TYPE_ATTRIBUTE_HAS_SECURITY)) {
+               memset (kactions, 0, sizeof (MonoDeclSecurityActions));
+               memset (mactions, 0, sizeof (MonoDeclSecurityActions));
+
+               /* get any linkdemand (either on the method or it's class) */
+               return mono_declsec_get_linkdemands (method, kactions, mactions);
+       }
+       return FALSE;
+}
index 9ebb558ece6f5ea7ad447d63db3ad180d643f408..ef89fb7ff8cf708d6c187d8b9bf5c20acec2681f 100644 (file)
@@ -19,6 +19,7 @@
 #include "marshal.h"
 #include "image.h"
 #include "reflection.h"
+#include "tabledefs.h"
 
 
 /* Definitions */
@@ -38,9 +39,6 @@ typedef struct {
        MonoClass *securitymanager;             /* System.Security.SecurityManager */
        MonoMethod *demand;                     /* SecurityManager.InternalDemand */
        MonoMethod *demandchoice;               /* SecurityManager.InternalDemandChoice */
-       MonoMethod *assert;                     /* SecurityManager.InternalAssert */
-       MonoMethod *deny;                       /* SecurityManager.InternalDeny */
-       MonoMethod *permitonly;                 /* SecurityManager.InternalPermitOnly */
        MonoMethod *inheritancedemand;          /* SecurityManager.InheritanceDemand */
        MonoMethod *inheritsecurityexception;   /* SecurityManager.InheritanceDemandSecurityException */
        MonoMethod *linkdemand;                 /* SecurityManager.LinkDemand */
@@ -66,6 +64,7 @@ MonoBoolean ves_icall_System_Security_SecurityManager_get_SecurityEnabled (void)
 void ves_icall_System_Security_SecurityManager_set_SecurityEnabled (MonoBoolean value);
 MonoBoolean ves_icall_System_Security_SecurityManager_get_CheckExecutionRights (void);
 void ves_icall_System_Security_SecurityManager_set_CheckExecutionRights (MonoBoolean value);
+MonoBoolean ves_icall_System_Security_SecurityManager_GetLinkDemandSecurity (MonoReflectionMethod *m, MonoDeclSecurityActions *kactions, MonoDeclSecurityActions *mactions);
 
 
 #endif /* _MONO_METADATA_SECURITY_MANAGER_H_ */