remove genxs2 (no 2.0 profile assembly is built)
[mono-project/dkf.git] / mono / metadata / security-core-clr.c
blobfa34ec2f1886d6475a5fc4ec7bcfa37b28b5631b
1 /*
2 * security-core-clr.c: CoreCLR security
4 * Author:
5 * Mark Probst <mark.probst@gmail.com>
7 * Copyright 2007-2009 Novell, Inc (http://www.novell.com)
8 */
10 #include <mono/metadata/class-internals.h>
11 #include <mono/metadata/security-manager.h>
12 #include <mono/metadata/assembly.h>
14 #include "security-core-clr.h"
16 gboolean mono_security_core_clr_test = FALSE;
18 static MonoClass*
19 security_critical_attribute (void)
21 static MonoClass *class = NULL;
23 if (!class) {
24 class = mono_class_from_name (mono_defaults.corlib, "System.Security",
25 "SecurityCriticalAttribute");
27 g_assert (class);
28 return class;
31 static MonoClass*
32 security_safe_critical_attribute (void)
34 static MonoClass *class = NULL;
36 if (!class) {
37 class = mono_class_from_name (mono_defaults.corlib, "System.Security",
38 "SecuritySafeCriticalAttribute");
40 g_assert (class);
41 return class;
44 MonoSecurityCoreCLRLevel
45 mono_security_core_clr_level_from_cinfo (MonoCustomAttrInfo *cinfo, MonoImage *image)
47 int level = MONO_SECURITY_CORE_CLR_TRANSPARENT;
49 if (!mono_security_core_clr_test && !mono_security_core_clr_is_platform_image (image))
50 return level;
52 if (cinfo && mono_custom_attrs_has_attr (cinfo, security_safe_critical_attribute ()))
53 level = MONO_SECURITY_CORE_CLR_SAFE_CRITICAL;
54 if (cinfo && mono_custom_attrs_has_attr (cinfo, security_critical_attribute ()))
55 level = MONO_SECURITY_CORE_CLR_CRITICAL;
57 return level;
60 MonoSecurityCoreCLRLevel
61 mono_security_core_clr_class_level (MonoClass *class)
63 MonoCustomAttrInfo *cinfo = mono_custom_attrs_from_class (class);
64 MonoSecurityCoreCLRLevel lvl = mono_security_core_clr_level_from_cinfo (cinfo, class->image);
66 if (cinfo)
67 mono_custom_attrs_free (cinfo);
69 if (lvl == MONO_SECURITY_CORE_CLR_TRANSPARENT && class->nested_in)
70 return mono_security_core_clr_class_level (class->nested_in);
71 else
72 return lvl;
75 MonoSecurityCoreCLRLevel
76 mono_security_core_clr_method_level (MonoMethod *method, gboolean with_class_level)
78 MonoCustomAttrInfo *cinfo = mono_custom_attrs_from_method (method);
79 MonoSecurityCoreCLRLevel level = mono_security_core_clr_level_from_cinfo (cinfo, method->klass->image);
81 if (with_class_level && level == MONO_SECURITY_CORE_CLR_TRANSPARENT)
82 level = mono_security_core_clr_class_level (method->klass);
84 if (cinfo)
85 mono_custom_attrs_free (cinfo);
87 return level;
90 gboolean
91 mono_security_core_clr_is_platform_image (MonoImage *image)
93 const char *prefix = mono_assembly_getrootdir ();
94 int prefix_len = strlen (prefix);
95 static const char subprefix[] = "/mono/2.1/";
96 int subprefix_len = strlen (subprefix);
98 if (!image->name)
99 return FALSE;
100 if (strncmp (prefix, image->name, prefix_len) != 0)
101 return FALSE;
102 if (strncmp (subprefix, image->name + prefix_len, subprefix_len) != 0)
103 return FALSE;
104 if (strchr (image->name + prefix_len + subprefix_len, '/'))
105 return FALSE;
106 return TRUE;