791e76c2f8ea7a210de4e5e203c7956bc9307244
[mono.git] / mono / metadata / mono-security-windows-uwp.c
1 /*
2  * mono-security-windows-uwp.c: UWP security support for Mono.
3  *
4  * Copyright 2016 Microsoft
5  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
6 */
7 #include <config.h>
8 #include <glib.h>
9
10 #if G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT)
11 #include <Windows.h>
12 #include "mono/metadata/mono-security-windows-internals.h"
13
14 gpointer
15 ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken (void)
16 {
17         MonoError mono_error;
18         mono_error_init (&mono_error);
19
20         g_unsupported_api ("OpenThreadToken, OpenProcessToken");
21
22         mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, "OpenThreadToken, OpenProcessToken");
23         mono_error_set_pending_exception (&mono_error);
24
25         SetLastError (ERROR_NOT_SUPPORTED);
26
27         return NULL;
28 }
29
30 MonoArray*
31 ves_icall_System_Security_Principal_WindowsIdentity_GetRoles (gpointer token)
32 {
33         MonoError mono_error;
34         mono_error_init (&mono_error);
35
36         g_unsupported_api ("GetTokenInformation");
37
38         mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, "GetTokenInformation");
39         mono_error_set_pending_exception (&mono_error);
40
41         SetLastError (ERROR_NOT_SUPPORTED);
42
43         return NULL;
44 }
45
46 gpointer
47 ves_icall_System_Security_Principal_WindowsImpersonationContext_DuplicateToken (gpointer token)
48 {
49         MonoError mono_error;
50         mono_error_init (&mono_error);
51
52         g_unsupported_api ("DuplicateToken");
53
54         mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, "DuplicateToken");
55         mono_error_set_pending_exception (&mono_error);
56
57         SetLastError (ERROR_NOT_SUPPORTED);
58
59         return NULL;
60 }
61
62 gboolean
63 ves_icall_System_Security_Principal_WindowsImpersonationContext_SetCurrentToken (gpointer token)
64 {
65         MonoError mono_error;
66         mono_error_init (&mono_error);
67
68         g_unsupported_api ("ImpersonateLoggedOnUser");
69
70         mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, "ImpersonateLoggedOnUser");
71         mono_error_set_pending_exception (&mono_error);
72
73         SetLastError (ERROR_NOT_SUPPORTED);
74
75         return FALSE;
76 }
77
78 gboolean
79 ves_icall_System_Security_Principal_WindowsImpersonationContext_RevertToSelf (void)
80 {
81         MonoError mono_error;
82         mono_error_init (&mono_error);
83
84         g_unsupported_api ("RevertToSelf");
85
86         mono_error_set_not_supported(&mono_error, G_UNSUPPORTED_API, "RevertToSelf");
87         mono_error_set_pending_exception (&mono_error);
88
89         SetLastError (ERROR_NOT_SUPPORTED);
90
91         return FALSE;
92 }
93
94 gint32
95 mono_security_win_get_token_name (gpointer token, gunichar2 ** uniname)
96 {
97         MonoError mono_error;
98         mono_error_init (&mono_error);
99
100         g_unsupported_api ("GetTokenInformation");
101
102         mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, "GetTokenInformation");
103         mono_error_set_pending_exception (&mono_error);
104
105         SetLastError (ERROR_NOT_SUPPORTED);
106
107         return 0;
108 }
109
110 gboolean
111 mono_security_win_is_machine_protected (gunichar2 *path)
112 {
113         MonoError mono_error;
114         mono_error_init (&mono_error);
115
116         g_unsupported_api ("GetNamedSecurityInfo, LocalFree");
117
118         mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, "GetNamedSecurityInfo, LocalFree");
119         mono_error_set_pending_exception (&mono_error);
120
121         SetLastError (ERROR_NOT_SUPPORTED);
122
123         return FALSE;
124 }
125
126 gboolean
127 mono_security_win_is_user_protected (gunichar2 *path)
128 {
129         MonoError mono_error;
130         mono_error_init (&mono_error);
131
132         g_unsupported_api ("GetNamedSecurityInfo, LocalFree");
133
134         mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, "GetNamedSecurityInfo, LocalFree");
135         mono_error_set_pending_exception (&mono_error);
136
137         SetLastError (ERROR_NOT_SUPPORTED);
138
139         return FALSE;
140 }
141
142 gboolean
143 mono_security_win_protect_machine (gunichar2 *path)
144 {
145         MonoError mono_error;
146         mono_error_init (&mono_error);
147
148         g_unsupported_api ("BuildTrusteeWithSid, SetEntriesInAcl, SetNamedSecurityInfo, LocalFree, FreeSid");
149
150         mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, "BuildTrusteeWithSid, SetEntriesInAcl, SetNamedSecurityInfo, LocalFree, FreeSid");
151         mono_error_set_pending_exception (&mono_error);
152
153         SetLastError (ERROR_NOT_SUPPORTED);
154
155         return FALSE;
156 }
157
158 gboolean
159 mono_security_win_protect_user (gunichar2 *path)
160 {
161         MonoError mono_error;
162         mono_error_init (&mono_error);
163
164         g_unsupported_api ("BuildTrusteeWithSid, SetEntriesInAcl, SetNamedSecurityInfo, LocalFree");
165
166         mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, "BuildTrusteeWithSid, SetEntriesInAcl, SetNamedSecurityInfo, LocalFree");
167         mono_error_set_pending_exception (&mono_error);
168
169         SetLastError (ERROR_NOT_SUPPORTED);
170
171         return FALSE;
172 }
173 #else /* G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) */
174
175 #ifdef _MSC_VER
176 // Quiet Visual Studio linker warning, LNK4221, in cases when this source file intentional ends up empty.
177 void __mono_win32_mono_security_windows_uwp_quiet_lnk4221(void) {}
178 #endif
179 #endif /* G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) */