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