2006-01-16 09:50:04 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
|
2006-05-18 12:09:15 -07:00
|
|
|
* Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
|
2006-01-16 09:50:04 -07:00
|
|
|
*
|
|
|
|
* This copyrighted material is made available to anyone wishing to use,
|
|
|
|
* modify, copy, or redistribute it subject to the terms and conditions
|
2006-09-01 08:05:15 -07:00
|
|
|
* of the GNU General Public License version 2.
|
2006-01-16 09:50:04 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/buffer_head.h>
|
2007-07-15 23:40:39 -07:00
|
|
|
#include <linux/capability.h>
|
2006-01-16 09:50:04 -07:00
|
|
|
#include <linux/xattr.h>
|
2006-02-27 15:23:27 -07:00
|
|
|
#include <linux/gfs2_ondisk.h>
|
2006-01-16 09:50:04 -07:00
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
|
|
|
#include "gfs2.h"
|
2006-02-27 15:23:27 -07:00
|
|
|
#include "incore.h"
|
2006-01-16 09:50:04 -07:00
|
|
|
#include "acl.h"
|
|
|
|
#include "eaops.h"
|
|
|
|
#include "eattr.h"
|
2006-02-27 15:23:27 -07:00
|
|
|
#include "util.h"
|
2006-01-16 09:50:04 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gfs2_ea_name2type - get the type of the ea, and truncate type from the name
|
|
|
|
* @namep: ea name, possibly with type appended
|
|
|
|
*
|
|
|
|
* Returns: GFS2_EATYPE_XXX
|
|
|
|
*/
|
|
|
|
|
2006-09-05 10:15:18 -07:00
|
|
|
unsigned int gfs2_ea_name2type(const char *name, const char **truncated_name)
|
2006-01-16 09:50:04 -07:00
|
|
|
{
|
|
|
|
unsigned int type;
|
|
|
|
|
|
|
|
if (strncmp(name, "system.", 7) == 0) {
|
|
|
|
type = GFS2_EATYPE_SYS;
|
|
|
|
if (truncated_name)
|
2006-09-05 10:15:18 -07:00
|
|
|
*truncated_name = name + sizeof("system.") - 1;
|
2006-01-16 09:50:04 -07:00
|
|
|
} else if (strncmp(name, "user.", 5) == 0) {
|
|
|
|
type = GFS2_EATYPE_USR;
|
|
|
|
if (truncated_name)
|
2006-09-05 10:15:18 -07:00
|
|
|
*truncated_name = name + sizeof("user.") - 1;
|
2006-05-22 07:08:35 -07:00
|
|
|
} else if (strncmp(name, "security.", 9) == 0) {
|
|
|
|
type = GFS2_EATYPE_SECURITY;
|
|
|
|
if (truncated_name)
|
2006-09-05 10:15:18 -07:00
|
|
|
*truncated_name = name + sizeof("security.") - 1;
|
2006-01-16 09:50:04 -07:00
|
|
|
} else {
|
|
|
|
type = GFS2_EATYPE_UNUSED;
|
|
|
|
if (truncated_name)
|
|
|
|
*truncated_name = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int system_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
|
|
|
|
{
|
|
|
|
if (!GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) &&
|
|
|
|
!GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len) &&
|
|
|
|
!capable(CAP_SYS_ADMIN))
|
|
|
|
return -EPERM;
|
|
|
|
|
2006-06-14 12:32:57 -07:00
|
|
|
if (GFS2_SB(&ip->i_inode)->sd_args.ar_posix_acl == 0 &&
|
2006-01-16 09:50:04 -07:00
|
|
|
(GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) ||
|
|
|
|
GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
return gfs2_ea_get_i(ip, er);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int system_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
|
|
|
|
{
|
|
|
|
int remove = 0;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len)) {
|
|
|
|
if (!(er->er_flags & GFS2_ERF_MODE)) {
|
2006-11-01 10:22:46 -07:00
|
|
|
er->er_mode = ip->i_inode.i_mode;
|
2006-01-16 09:50:04 -07:00
|
|
|
er->er_flags |= GFS2_ERF_MODE;
|
|
|
|
}
|
|
|
|
error = gfs2_acl_validate_set(ip, 1, er,
|
|
|
|
&remove, &er->er_mode);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = gfs2_ea_set_i(ip, er);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
if (remove)
|
|
|
|
gfs2_ea_remove_i(ip, er);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
} else if (GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)) {
|
|
|
|
error = gfs2_acl_validate_set(ip, 0, er,
|
|
|
|
&remove, NULL);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
if (!remove)
|
|
|
|
error = gfs2_ea_set_i(ip, er);
|
|
|
|
else {
|
|
|
|
error = gfs2_ea_remove_i(ip, er);
|
|
|
|
if (error == -ENODATA)
|
|
|
|
error = 0;
|
|
|
|
}
|
2006-09-25 06:26:04 -07:00
|
|
|
return error;
|
2006-01-16 09:50:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int system_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
|
|
|
|
{
|
|
|
|
if (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len)) {
|
|
|
|
int error = gfs2_acl_validate_remove(ip, 1);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
} else if (GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)) {
|
|
|
|
int error = gfs2_acl_validate_remove(ip, 0);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
} else
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
return gfs2_ea_remove_i(ip, er);
|
|
|
|
}
|
|
|
|
|
2007-07-31 03:31:11 -07:00
|
|
|
static const struct gfs2_eattr_operations gfs2_user_eaops = {
|
2007-11-28 08:22:09 -07:00
|
|
|
.eo_get = gfs2_ea_get_i,
|
|
|
|
.eo_set = gfs2_ea_set_i,
|
|
|
|
.eo_remove = gfs2_ea_remove_i,
|
2006-01-16 09:50:04 -07:00
|
|
|
.eo_name = "user",
|
|
|
|
};
|
|
|
|
|
2007-07-31 03:31:11 -07:00
|
|
|
const struct gfs2_eattr_operations gfs2_system_eaops = {
|
2006-01-16 09:50:04 -07:00
|
|
|
.eo_get = system_eo_get,
|
|
|
|
.eo_set = system_eo_set,
|
|
|
|
.eo_remove = system_eo_remove,
|
|
|
|
.eo_name = "system",
|
|
|
|
};
|
|
|
|
|
2007-07-31 03:31:11 -07:00
|
|
|
static const struct gfs2_eattr_operations gfs2_security_eaops = {
|
2007-11-28 08:22:09 -07:00
|
|
|
.eo_get = gfs2_ea_get_i,
|
|
|
|
.eo_set = gfs2_ea_set_i,
|
|
|
|
.eo_remove = gfs2_ea_remove_i,
|
2006-05-22 07:08:35 -07:00
|
|
|
.eo_name = "security",
|
|
|
|
};
|
|
|
|
|
2007-07-31 03:31:11 -07:00
|
|
|
const struct gfs2_eattr_operations *gfs2_ea_ops[] = {
|
2006-01-16 09:50:04 -07:00
|
|
|
NULL,
|
|
|
|
&gfs2_user_eaops,
|
|
|
|
&gfs2_system_eaops,
|
2006-05-25 14:36:15 -07:00
|
|
|
&gfs2_security_eaops,
|
2006-01-16 09:50:04 -07:00
|
|
|
};
|
|
|
|
|