Skip to content

Commit

Permalink
2005-03-10 Sebastien Pouliot <sebastien@ximian.com>
Browse files Browse the repository at this point in the history
	* 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
  • Loading branch information
Sebastien Pouliot committed Mar 10, 2005
1 parent ac4b185 commit 05e532b
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 5 deletions.
14 changes: 14 additions & 0 deletions mono/metadata/ChangeLog
@@ -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
Expand Down
24 changes: 24 additions & 0 deletions mono/metadata/exception.c
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions mono/metadata/exception.h
Expand Up @@ -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_ */
56 changes: 54 additions & 2 deletions mono/metadata/icall.c
Expand Up @@ -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 *
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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},
Expand Down
28 changes: 28 additions & 0 deletions mono/metadata/security-manager.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
5 changes: 2 additions & 3 deletions mono/metadata/security-manager.h
Expand Up @@ -19,6 +19,7 @@
#include "marshal.h"
#include "image.h"
#include "reflection.h"
#include "tabledefs.h"


/* Definitions */
Expand All @@ -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 */
Expand All @@ -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_ */

0 comments on commit 05e532b

Please sign in to comment.