Esempio n. 1
0
/* http://www.dotnet247.com/247reference/msgs/39/195403.aspx
// internal static string[] WindowsIdentity._GetRoles (IntPtr token)
*/
MonoArray*
ves_icall_System_Security_Principal_WindowsIdentity_GetRoles (gpointer token) 
{
	MonoError error;
	MonoArray *array = NULL;
	MonoDomain *domain = mono_domain_get (); 
#ifdef HOST_WIN32
	gint32 size = 0;

	GetTokenInformation (token, TokenGroups, NULL, size, (PDWORD)&size);
	if (size > 0) {
		TOKEN_GROUPS *tg = g_malloc0 (size);
		if (GetTokenInformation (token, TokenGroups, tg, size, (PDWORD)&size)) {
			int i=0;
			int num = tg->GroupCount;

			array = mono_array_new_checked (domain, mono_get_string_class (), num, &error);
			if (mono_error_set_pending_exception (&error)) {
				g_free (tg);
				return NULL;
			}

			for (i=0; i < num; i++) {
				gint32 size = 0;
				gunichar2 *uniname = GetSidName (NULL, tg->Groups [i].Sid, &size);

				if (uniname) {
					MonoString *str = mono_string_new_utf16_checked (domain, uniname, size, &error);
					if (!is_ok (&error)) {
						g_free (uniname);
						g_free (tg);
						mono_error_set_pending_exception (&error);
						return NULL;
					}
					mono_array_setref (array, i, str);
					g_free (uniname);
				}
			}
		}
		g_free (tg);
	}
#else
	/* POSIX-compliant systems should use IsMemberOfGroupId or IsMemberOfGroupName */
	g_warning ("WindowsIdentity._GetRoles should never be called on POSIX");
#endif
	if (!array) {
		/* return empty array of string, i.e. string [0] */
		array = mono_array_new_checked (domain, mono_get_string_class (), 0, &error);
		mono_error_set_pending_exception (&error);
	}
	return array;
}
Esempio n. 2
0
MonoString*
ves_icall_System_Security_Principal_WindowsIdentity_GetTokenName (gpointer token)
{
    MonoString *result = NULL;
    gunichar2 *uniname = NULL;
    gint32 size = 0;

#ifdef HOST_WIN32
    MONO_ARCH_SAVE_REGS;

    GetTokenInformation (token, TokenUser, NULL, size, (PDWORD)&size);
    if (size > 0) {
        TOKEN_USER *tu = g_malloc0 (size);
        if (GetTokenInformation (token, TokenUser, tu, size, (PDWORD)&size)) {
            uniname = GetSidName (NULL, tu->User.Sid, &size);
        }
        g_free (tu);
    }
#else
    gchar *uname = GetTokenName ((uid_t) GPOINTER_TO_INT (token));

    MONO_ARCH_SAVE_REGS;

    if (uname) {
        size = strlen (uname);
        uniname = g_utf8_to_utf16 (uname, size, NULL, NULL, NULL);
        g_free (uname);
    }
#endif /* HOST_WIN32 */

    if (size > 0) {
        result = mono_string_new_utf16 (mono_domain_get (), uniname, size);
    }
    else
        result = mono_string_new (mono_domain_get (), "");

    if (uniname)
        g_free (uniname);

    return result;
}