1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2009 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
15 #include <mono/metadata/appdomain.h>
16 #include <mono/metadata/assembly.h>
18 #if MONO_ENABLE_CORECLR_SECURITY
20 static struct stat platform_stat
;
22 static struct stat platform_a11y_stat
;
25 a11y_stat_init (char *platform_dir
)
27 //please keep this lookup pattern in sync with the one in A11yHelper.cs (Initiailize() method)
28 const char* moonlight_at_novell
= g_strrstr (platform_dir
, "moonlight@novell.com");
29 if (moonlight_at_novell
!= NULL
) {
30 const char* after
= g_strdup ("moonlight-a11y@novell.com/components");
31 const char* before
= g_strndup (platform_dir
,
32 strlen (platform_dir
) - strlen (moonlight_at_novell
));
33 const char* platform_a11y_dir
= g_strconcat (before
, after
, NULL
);
35 memset (&platform_a11y_stat
, 0, sizeof (platform_a11y_stat
));
36 stat (platform_a11y_dir
, &platform_a11y_stat
);
37 g_free (platform_a11y_dir
);
40 moonlight_at_novell
= NULL
;
45 const static char* platform_code_assemblies
[] = {
50 "System.Runtime.Serialization.dll",
51 "System.ServiceModel.dll",
52 "System.ServiceModel.Web.dll",
54 "System.Windows.Browser.dll",
55 // right now there are no [SecurityCritical] nor [SecuritySafeCritical] code inside the next two assemblies
56 // so we'll treat them (at runtime) just like "application code" to reduce our attack surface
58 // "Microsoft.VisualBasic.dll",
65 determine_platform_image (const char *image_name
)
70 struct stat the_platform_stat
= platform_stat
;
71 gboolean a11y
= FALSE
;
76 /* all platform code resides in the same directory */
77 dir
= g_path_get_dirname (image_name
);
78 if (!dir
|| stat (dir
, &info
) != 0) {
83 name
= g_path_get_basename (image_name
);
89 if (g_ascii_strcasecmp (name
, "MoonAtkBridge.dll") == 0) {
90 the_platform_stat
= platform_a11y_stat
;
94 /* we avoid comparing strings, e.g. /opt/mono/lib/moon versus /opt/mono//lib/moon */
95 if ((the_platform_stat
.st_mode
!= info
.st_mode
) ||
96 (the_platform_stat
.st_ino
!= info
.st_ino
) ||
97 (the_platform_stat
.st_dev
!= info
.st_dev
)) {
109 /* we know the names of every platform assembly, because we ship them */
110 for (i
= 0; i
< G_N_ELEMENTS (platform_code_assemblies
); i
++) {
111 if (g_ascii_strcasecmp (name
, platform_code_assemblies
[i
]) == 0) {
120 #define DISABLE_SECURITY "MOON_DISABLE_SECURITY_PREVIEW_" PREVIEW_VERSION
123 security_enable_coreclr (const char *platform_dir
)
125 if (g_getenv (DISABLE_SECURITY
) != NULL
) {
126 g_warning ("CORECLR was DISABLED using %s override", DISABLE_SECURITY
);
127 g_warning ("this disables both code verification and metadata verification on code\n"
128 "downloaded from untrusted sources, and therefore opens up your machine\n"
129 "to a wide variety of attack vectors. Don't do this unless you know what\n"
131 } else if (g_path_is_absolute (platform_dir
)) {
132 memset (&platform_stat
, 0, sizeof (platform_stat
));
134 if (stat (platform_dir
, &platform_stat
) == 0) {
136 a11y_stat_init (platform_dir
);
138 mono_security_enable_core_clr ();
139 mono_security_set_core_clr_platform_callback (determine_platform_image
);
142 g_warning ("CORECLR was DISABLED due to invalid, non-absolute, platform directory");
145 mono_assembly_setrootdir (platform_dir
);
151 security_enable_coreclr (const char *platform_dir
)