Merge branch 'master' into config-checks-ipv6
[mono.git] / mono / metadata / mono-security.c
index a1d3c9d0e4fe22e880944a855475c09b7ad09a00..d5b40a927b659b1ea2174ba8127f7ea1e8903d51 100644 (file)
@@ -1,5 +1,6 @@
-/*
- * security.c:  Security internal calls
+/**
+ * \file
+ * Security internal calls
  *
  * Author:
  *     Sebastien Pouliot  <sebastien@ximian.com>
@@ -12,7 +13,7 @@
 #include <config.h>
 #endif
 
-#include <mono/metadata/assembly.h>
+#include <mono/metadata/assembly-internals.h>
 #include <mono/metadata/appdomain.h>
 #include <mono/metadata/image.h>
 #include <mono/metadata/exception.h>
@@ -76,6 +77,8 @@ GetTokenName (uid_t uid)
 {
        gchar *uname = NULL;
 
+#ifdef HAVE_PWD_H
+
 #ifdef HAVE_GETPWUID_R
        struct passwd pwd;
        size_t fbufsize;
@@ -108,9 +111,13 @@ GetTokenName (uid_t uid)
        g_free (fbuf);
 #endif
 
+#endif /* HAVE_PWD_H */
+
        return uname;
 }
 
+#ifdef HAVE_GRP_H
+
 static gboolean
 IsMemberInList (uid_t user, struct group *g) 
 {
@@ -137,9 +144,15 @@ IsMemberInList (uid_t user, struct group *g)
        return result;
 }
 
+#endif /* HAVE_GRP_H */
+
 static gboolean
 IsDefaultGroup (uid_t user, gid_t group)
 {
+       gboolean result = FALSE;
+
+#ifdef HAVE_PWD_H
+
 #ifdef HAVE_GETPWUID_R
        struct passwd pwd;
        size_t fbufsize;
@@ -147,7 +160,6 @@ IsDefaultGroup (uid_t user, gid_t group)
        gint32 retval;
 #endif
        struct passwd *p = NULL;
-       gboolean result;
 
 #ifdef HAVE_GETPWUID_R
 #ifdef _SC_GETPW_R_SIZE_MAX
@@ -173,9 +185,13 @@ IsDefaultGroup (uid_t user, gid_t group)
        g_free (fbuf);
 #endif
 
+#endif /* HAVE_PWD_H */
+
        return result;
 }
 
+#ifdef HAVE_GRP_H
+
 static gboolean
 IsMemberOf (gid_t user, struct group *g) 
 {
@@ -189,6 +205,9 @@ IsMemberOf (gid_t user, struct group *g)
        /* is the user in the group list */
        return IsMemberInList (user, g);
 }
+
+#endif /* HAVE_GRP_H */
+
 #endif /* !HOST_WIN32 */
 
 /* ICALLS */
@@ -226,7 +245,7 @@ ves_icall_System_Security_Principal_WindowsIdentity_GetTokenName (gpointer token
        gunichar2 *uniname = NULL;
        gint32 size = 0;
 
-       mono_error_init (&error);
+       error_init (&error);
 
        size = internal_get_token_name (token, &uniname);
 
@@ -248,13 +267,16 @@ ves_icall_System_Security_Principal_WindowsIdentity_GetTokenName (gpointer token
 gpointer
 ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken (MonoString *username)
 {
+       gpointer token = (gpointer)-2;
+
+#ifdef HAVE_PWD_H
+
 #ifdef HAVE_GETPWNAM_R
        struct passwd pwd;
        size_t fbufsize;
        gchar *fbuf;
        gint32 retval;
 #endif
-       gpointer token = (gpointer) -2;
        struct passwd *p;
        gchar *utf8_name;
        gboolean result;
@@ -286,6 +308,8 @@ ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken (MonoString *us
 #endif
        g_free (utf8_name);
 
+#endif /* HAVE_PWD_H */
+
        return token;
 }
 #endif /* HOST_WIN32 */
@@ -382,6 +406,8 @@ ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupId (gpointer
 {
        gboolean result = FALSE;
 
+#ifdef HAVE_GRP_H
+
 #ifdef HAVE_GETGRGID_R
        struct group grp;
        size_t fbufsize;
@@ -413,6 +439,8 @@ ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupId (gpointer
        g_free (fbuf);
 #endif
 
+#endif /* HAVE_GRP_H */
+
        return result;
 }
 
@@ -420,6 +448,9 @@ gboolean
 ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupName (gpointer user, MonoString *group)
 {
        gboolean result = FALSE;
+
+#ifdef HAVE_GRP_H
+
        gchar *utf8_groupname;
 
        utf8_groupname = mono_unicode_to_external (mono_string_chars (group));
@@ -453,6 +484,8 @@ ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupName (gpoint
                g_free (utf8_groupname);
        }
 
+#endif /* HAVE_GRP_H */
+
        return result;
 }
 #endif /* !HOST_WIN32 */
@@ -551,7 +584,7 @@ ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectUser (MonoString
 MonoBoolean
 ves_icall_System_Security_Policy_Evidence_IsAuthenticodePresent (MonoReflectionAssemblyHandle refass, MonoError *error)
 {
-       mono_error_init (error);
+       error_init (error);
        if (MONO_HANDLE_IS_NULL (refass))
                return FALSE;
        MonoAssembly *assembly = MONO_HANDLE_GETVAL (refass, assembly);
@@ -587,12 +620,12 @@ void invoke_protected_memory_method (MonoArray *data, MonoObject *scope, gboolea
        MonoMethod *method;
        void *params [2];
 
-       mono_error_init (error);
+       error_init (error);
        
        if (system_security_assembly == NULL) {
                system_security_assembly = mono_image_loaded ("System.Security");
                if (!system_security_assembly) {
-                       MonoAssembly *sa = mono_assembly_open ("System.Security.dll", NULL);
+                       MonoAssembly *sa = mono_assembly_open_predicate ("System.Security.dll", FALSE, FALSE, NULL, NULL, NULL);
                        if (!sa)
                                g_assert_not_reached ();
                        system_security_assembly = mono_assembly_get_image (sa);