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.
16 #if MONO_ENABLE_CORECLR_SECURITY
18 static struct stat platform_stat
;
20 #if MOON_A11Y_INTERNAL_HACK_ENABLED
21 static struct stat platform_a11y_stat
;
24 a11y_stat_init (char *platform_dir
)
26 //please keep this lookup pattern in sync with the one in A11yHelper.cs (Initiailize() method)
27 const char* moonlight_at_novell
= g_strrstr (platform_dir
, "moonlight@novell.com");
28 if (moonlight_at_novell
!= NULL
) {
29 const char* after
= g_strdup ("moonlight-a11y@novell.com/components");
30 const char* before
= g_strndup (platform_dir
,
31 strlen (platform_dir
) - strlen (moonlight_at_novell
));
32 const char* platform_a11y_dir
= g_strconcat (before
, after
, NULL
);
34 memset (&platform_a11y_stat
, 0, sizeof (platform_a11y_stat
));
35 stat (platform_a11y_dir
, &platform_a11y_stat
);
36 g_free (platform_a11y_dir
);
39 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",
56 "Microsoft.VisualBasic.dll",
63 determine_platform_image (const char *image_name
)
68 struct stat the_platform_stat
= platform_stat
;
69 gboolean a11y
= FALSE
;
74 /* all platform code resides in the same directory */
75 dir
= g_path_get_dirname (image_name
);
76 if (!dir
|| stat (dir
, &info
) != 0) {
81 name
= g_path_get_basename (image_name
);
87 #if MOON_A11Y_INTERNAL_HACK_ENABLED
88 if (g_ascii_strcasecmp (name
, "MoonAtkBridge.dll") == 0) {
89 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 #if MOON_A11Y_INTERNAL_HACK_ENABLED
137 a11y_stat_init (platform_dir
);
140 mono_security_enable_core_clr ();
141 mono_security_set_core_clr_platform_callback (determine_platform_image
);
144 g_warning ("CORECLR was DISABLED due to invalid, non-absolute, platform directory");
147 mono_assembly_setrootdir (platform_dir
);
153 security_enable_coreclr (const char *platform_dir
)