コード例 #1
0
ファイル: mono-security.c プロジェクト: LevNNN/mono
gpointer
ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken (MonoString *username)
{
#ifdef HOST_WIN32
    gpointer token = NULL;

    MONO_ARCH_SAVE_REGS;

    /* TODO: MS has something like this working in Windows 2003 (client and
     * server) but works only for domain accounts (so it's quite limiting).
     * http://www.develop.com/kbrown/book/html/howto_logonuser.html
     */
    g_warning ("Unsupported on Win32 (anyway requires W2K3 minimum)");

#else /* HOST_WIN32*/

#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;

    MONO_ARCH_SAVE_REGS;

    utf8_name = mono_unicode_to_external (mono_string_chars (username));

#ifdef HAVE_GETPWNAM_R
#ifdef _SC_GETPW_R_SIZE_MAX
    fbufsize = mono_sysconf (_SC_GETPW_R_SIZE_MAX);
#else
    fbufsize = MONO_SYSCONF_DEFAULT_SIZE;
#endif

    fbuf = g_malloc0 (fbufsize);
    retval = getpwnam_r (utf8_name, &pwd, fbuf, fbufsize, &p);
    result = ((retval == 0) && (p == &pwd));
#else
    /* default to non thread-safe but posix compliant function */
    p = getpwnam (utf8_name);
    result = (p != NULL);
#endif

    if (result) {
        token = GINT_TO_POINTER (p->pw_uid);
    }

#ifdef HAVE_GETPWNAM_R
    g_free (fbuf);
#endif
    g_free (utf8_name);
#endif
    return token;
}
コード例 #2
0
ファイル: mono-security.c プロジェクト: LevNNN/mono
gboolean
ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupName (gpointer user, MonoString *group)
{
    gboolean result = FALSE;

#ifdef HOST_WIN32

    MONO_ARCH_SAVE_REGS;

    /* Windows version use a cache built using WindowsIdentity._GetRoles */
    g_warning ("IsMemberOfGroupName should never be called on Win32");

#else /* HOST_WIN32 */
    gchar *utf8_groupname;

    MONO_ARCH_SAVE_REGS;

    utf8_groupname = mono_unicode_to_external (mono_string_chars (group));
    if (utf8_groupname) {
        struct group *g = NULL;
#ifdef HAVE_GETGRNAM_R
        struct group grp;
        gchar *fbuf;
        gint32 retval;
#ifdef _SC_GETGR_R_SIZE_MAX
        size_t fbufsize = mono_sysconf (_SC_GETGR_R_SIZE_MAX);
#else
        size_t fbufsize = MONO_SYSCONF_DEFAULT_SIZE;
#endif
        fbuf = g_malloc0 (fbufsize);
        retval = getgrnam_r (utf8_groupname, &grp, fbuf, fbufsize, &g);
        result = ((retval == 0) && (g == &grp));
#else
        /* default to non thread-safe but posix compliant function */
        g = getgrnam (utf8_groupname);
        result = (g != NULL);
#endif

        if (result) {
            result = IsMemberOf ((uid_t) GPOINTER_TO_INT (user), g);
        }

#ifdef HAVE_GETGRNAM_R
        g_free (fbuf);
#endif
        g_free (utf8_groupname);
    }
#endif /* HOST_WIN32 */

    return result;
}
コード例 #3
0
ファイル: mono-security.c プロジェクト: LevNNN/mono
static gboolean
IsProtected (MonoString *path, gint32 protection)
{
    gboolean result = FALSE;
    gchar *utf8_name = mono_unicode_to_external (mono_string_chars (path));
    if (utf8_name) {
        struct stat st;
        if (stat (utf8_name, &st) == 0) {
            result = (((st.st_mode & 0777) & protection) == 0);
        }
        g_free (utf8_name);
    }
    return result;
}
コード例 #4
0
ファイル: mono-security.c プロジェクト: LevNNN/mono
static gboolean
Protect (MonoString *path, gint32 file_mode, gint32 add_dir_mode)
{
    gboolean result = FALSE;
    gchar *utf8_name = mono_unicode_to_external (mono_string_chars (path));
    if (utf8_name) {
        struct stat st;
        if (stat (utf8_name, &st) == 0) {
            int mode = file_mode;
            if (st.st_mode & S_IFDIR)
                mode |= add_dir_mode;
            result = (chmod (utf8_name, mode) == 0);
        }
        g_free (utf8_name);
    }
    return result;
}
コード例 #5
0
ファイル: mono-security.c プロジェクト: LogosBible/mono
static gboolean
Protect (const gunichar2 *path, gint32 file_mode, gint32 add_dir_mode)
{
	gboolean result = FALSE;
	gchar *utf8_name = mono_unicode_to_external (path);
	if (utf8_name) {
		struct stat st;
		if (stat (utf8_name, &st) == 0) {
			int mode = file_mode;
			if (st.st_mode & S_IFDIR)
				mode |= add_dir_mode;
#ifdef HAVE_CHMOD
			result = (chmod (utf8_name, mode) == 0);
#else
			result = -1;
#endif
		}
		g_free (utf8_name);
	}
	return result;
}