2006-10-09 15:13:49 +04:00
/*
Unix SMB / CIFS implementation .
POSIX NTVFS backend - NT ACLs in xattrs
Copyright ( C ) Andrew Tridgell 2006
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2006-10-09 15:13:49 +04:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2006-10-09 15:13:49 +04:00
*/
# include "includes.h"
# include "vfs_posix.h"
2008-10-11 23:31:42 +04:00
# include "../lib/util/unix_privs.h"
2006-10-09 15:13:49 +04:00
# include "librpc/gen_ndr/ndr_xattr.h"
2017-04-20 22:24:43 +03:00
NTSTATUS pvfs_acl_xattr_init ( TALLOC_CTX * ) ;
2011-03-19 02:43:05 +03:00
2006-10-09 15:13:49 +04:00
/*
load the current ACL from extended attributes
*/
static NTSTATUS pvfs_acl_load_xattr ( struct pvfs_state * pvfs , struct pvfs_filename * name , int fd ,
TALLOC_CTX * mem_ctx ,
struct security_descriptor * * sd )
{
NTSTATUS status ;
struct xattr_NTACL * acl ;
if ( ! ( pvfs - > flags & PVFS_FLAG_XATTR_ENABLE ) ) {
return NT_STATUS_NOT_FOUND ;
}
acl = talloc_zero ( mem_ctx , struct xattr_NTACL ) ;
NT_STATUS_HAVE_NO_MEMORY ( acl ) ;
status = pvfs_xattr_ndr_load ( pvfs , mem_ctx , name - > full_name , fd ,
XATTR_NTACL_NAME ,
2010-08-27 00:35:09 +04:00
acl , ( void * ) ndr_pull_xattr_NTACL ) ;
2006-10-09 15:13:49 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
talloc_free ( acl ) ;
return status ;
}
if ( acl - > version ! = 1 ) {
talloc_free ( acl ) ;
return NT_STATUS_INVALID_ACL ;
}
* sd = talloc_steal ( mem_ctx , acl - > info . sd ) ;
return NT_STATUS_OK ;
}
/*
save the acl for a file into filesystem xattr
*/
static NTSTATUS pvfs_acl_save_xattr ( struct pvfs_state * pvfs , struct pvfs_filename * name , int fd ,
struct security_descriptor * sd )
{
NTSTATUS status ;
void * privs ;
struct xattr_NTACL acl ;
if ( ! ( pvfs - > flags & PVFS_FLAG_XATTR_ENABLE ) ) {
return NT_STATUS_OK ;
}
acl . version = 1 ;
acl . info . sd = sd ;
/* this xattr is in the "system" namespace, so we need
admin privileges to set it */
privs = root_privileges ( ) ;
status = pvfs_xattr_ndr_save ( pvfs , name - > full_name , fd ,
XATTR_NTACL_NAME ,
2010-08-27 00:35:09 +04:00
& acl , ( void * ) ndr_push_xattr_NTACL ) ;
2006-10-09 15:13:49 +04:00
talloc_free ( privs ) ;
return status ;
}
/*
initialise pvfs acl xattr backend
*/
2017-04-20 22:24:43 +03:00
NTSTATUS pvfs_acl_xattr_init ( TALLOC_CTX * ctx )
2006-10-09 15:13:49 +04:00
{
struct pvfs_acl_ops ops = {
. name = " xattr " ,
. acl_load = pvfs_acl_load_xattr ,
. acl_save = pvfs_acl_save_xattr
} ;
2017-05-12 01:45:57 +03:00
return pvfs_acl_register ( ctx , & ops ) ;
2006-10-09 15:13:49 +04:00
}