usr/src/uts/common/fs/zfs/zfs_acl.c
author Albert Lee <trisk@nexenta.com>
Sat, 14 May 2011 00:29:13 -0400
changeset 13370 8c04143bd318
parent 13101 08bbd228b732
child 13980 d7059eb1884c
permissions -rw-r--r--
742 Resurrect the ZFS "aclmode" property 664 Umask masking "deny" ACL entries. 279 Bug in the new ACL (post-PSARC/2010/029) semantics Reviewed by: Aram Hăvărneanu <[email protected]> Reviewed by: Gordon Ross <[email protected]> Reviewed by: Robert Gordon <[email protected]> Reviewed by: [email protected] Approved by: Garrett D'Amore <[email protected]>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    21
/*
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
    22
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
    23
 * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#include <sys/types.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#include <sys/param.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/time.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/systm.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/sysmacros.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/resource.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/vfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/vnode.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    34
#include <sys/sid.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/file.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/kmem.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
#include <sys/cmn_err.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
#include <sys/errno.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
#include <sys/unistd.h>
1576
0364d1928a7f 6380036 zfs does not clear S_ISUID and S_ISGID bits on successful writes
marks
parents: 1544
diff changeset
    41
#include <sys/sdt.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
#include <sys/fs/zfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
#include <sys/mode.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
#include <sys/policy.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
#include <sys/zfs_znode.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    46
#include <sys/zfs_fuid.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
#include <sys/zfs_acl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
#include <sys/zfs_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
#include <sys/zfs_vfsops.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
#include <sys/dmu.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    51
#include <sys/dnode.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
#include <sys/zap.h>
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
    53
#include <sys/sa.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
#include "fs/fs_subr.h"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
#include <acl/acl_common.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
#define	ALLOW	ACE_ACCESS_ALLOWED_ACE_TYPE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
#define	DENY	ACE_ACCESS_DENIED_ACE_TYPE
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    59
#define	MAX_ACE_TYPE	ACE_SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE
7559
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
    60
#define	MIN_ACE_TYPE	ALLOW
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
#define	OWNING_GROUP		(ACE_GROUP|ACE_IDENTIFIER_GROUP)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
#define	EVERYONE_ALLOW_MASK (ACE_READ_ACL|ACE_READ_ATTRIBUTES | \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
    ACE_READ_NAMED_ATTRS|ACE_SYNCHRONIZE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
#define	EVERYONE_DENY_MASK (ACE_WRITE_ACL|ACE_WRITE_OWNER | \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
    ACE_WRITE_ATTRIBUTES|ACE_WRITE_NAMED_ATTRS)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
#define	OWNER_ALLOW_MASK (ACE_WRITE_ACL | ACE_WRITE_OWNER | \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
    ACE_WRITE_ATTRIBUTES|ACE_WRITE_NAMED_ATTRS)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    69
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    70
#define	ZFS_CHECKED_MASKS (ACE_READ_ACL|ACE_READ_ATTRIBUTES|ACE_READ_DATA| \
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    71
    ACE_READ_NAMED_ATTRS|ACE_WRITE_DATA|ACE_WRITE_ATTRIBUTES| \
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    72
    ACE_WRITE_NAMED_ATTRS|ACE_APPEND_DATA|ACE_EXECUTE|ACE_WRITE_OWNER| \
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    73
    ACE_WRITE_ACL|ACE_DELETE|ACE_DELETE_CHILD|ACE_SYNCHRONIZE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    74
8952
c2f95230b0ff 6809529 dirtying snapshot! rears its head again
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8227
diff changeset
    75
#define	WRITE_MASK_DATA (ACE_WRITE_DATA|ACE_APPEND_DATA|ACE_WRITE_NAMED_ATTRS)
c2f95230b0ff 6809529 dirtying snapshot! rears its head again
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8227
diff changeset
    76
#define	WRITE_MASK_ATTRS (ACE_WRITE_ACL|ACE_WRITE_OWNER|ACE_WRITE_ATTRIBUTES| \
c2f95230b0ff 6809529 dirtying snapshot! rears its head again
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8227
diff changeset
    77
    ACE_DELETE|ACE_DELETE_CHILD)
c2f95230b0ff 6809529 dirtying snapshot! rears its head again
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8227
diff changeset
    78
#define	WRITE_MASK (WRITE_MASK_DATA|WRITE_MASK_ATTRS)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
#define	OGE_CLEAR	(ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
    ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_EXECUTE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
#define	OKAY_MASK_BITS (ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
    ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_EXECUTE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
#define	ALL_INHERIT	(ACE_FILE_INHERIT_ACE|ACE_DIRECTORY_INHERIT_ACE | \
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    87
    ACE_NO_PROPAGATE_INHERIT_ACE|ACE_INHERIT_ONLY_ACE|ACE_INHERITED_ACE)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
6385
5437941ec5a1 PSARC/2008/231 New ZFS "passthrough" ACL inheritance rules
marks
parents: 6257
diff changeset
    89
#define	RESTRICTED_CLEAR	(ACE_WRITE_ACL|ACE_WRITE_OWNER)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    91
#define	V4_ACL_WIDE_FLAGS (ZFS_ACL_AUTO_INHERIT|ZFS_ACL_DEFAULTED|\
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    92
    ZFS_ACL_PROTECTED)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    93
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    94
#define	ZFS_ACL_WIDE_FLAGS (V4_ACL_WIDE_FLAGS|ZFS_ACL_TRIVIAL|ZFS_INHERIT_ACE|\
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    95
    ZFS_ACL_OBJ_ACE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    96
10143
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
    97
#define	ALL_MODE_EXECS (S_IXUSR | S_IXGRP | S_IXOTH)
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
    98
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
    99
static uint16_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   100
zfs_ace_v0_get_type(void *acep)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   101
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   102
	return (((zfs_oldace_t *)acep)->z_type);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   103
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   104
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   105
static uint16_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   106
zfs_ace_v0_get_flags(void *acep)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   107
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   108
	return (((zfs_oldace_t *)acep)->z_flags);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   109
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   110
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   111
static uint32_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   112
zfs_ace_v0_get_mask(void *acep)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   113
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   114
	return (((zfs_oldace_t *)acep)->z_access_mask);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   115
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   116
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   117
static uint64_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   118
zfs_ace_v0_get_who(void *acep)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   119
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   120
	return (((zfs_oldace_t *)acep)->z_fuid);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   121
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   122
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   123
static void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   124
zfs_ace_v0_set_type(void *acep, uint16_t type)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   125
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   126
	((zfs_oldace_t *)acep)->z_type = type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   127
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   128
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   129
static void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   130
zfs_ace_v0_set_flags(void *acep, uint16_t flags)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   131
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   132
	((zfs_oldace_t *)acep)->z_flags = flags;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   133
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   134
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   135
static void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   136
zfs_ace_v0_set_mask(void *acep, uint32_t mask)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   137
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   138
	((zfs_oldace_t *)acep)->z_access_mask = mask;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   139
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   140
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   141
static void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   142
zfs_ace_v0_set_who(void *acep, uint64_t who)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   143
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   144
	((zfs_oldace_t *)acep)->z_fuid = who;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   145
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   146
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   147
/*ARGSUSED*/
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   148
static size_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   149
zfs_ace_v0_size(void *acep)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   150
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   151
	return (sizeof (zfs_oldace_t));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   152
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   153
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   154
static size_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   155
zfs_ace_v0_abstract_size(void)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   156
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   157
	return (sizeof (zfs_oldace_t));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   158
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   159
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   160
static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   161
zfs_ace_v0_mask_off(void)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   162
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   163
	return (offsetof(zfs_oldace_t, z_access_mask));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   164
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   165
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   166
/*ARGSUSED*/
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   167
static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   168
zfs_ace_v0_data(void *acep, void **datap)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   169
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   170
	*datap = NULL;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   171
	return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   172
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   173
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   174
static acl_ops_t zfs_acl_v0_ops = {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   175
	zfs_ace_v0_get_mask,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   176
	zfs_ace_v0_set_mask,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   177
	zfs_ace_v0_get_flags,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   178
	zfs_ace_v0_set_flags,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   179
	zfs_ace_v0_get_type,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   180
	zfs_ace_v0_set_type,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   181
	zfs_ace_v0_get_who,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   182
	zfs_ace_v0_set_who,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   183
	zfs_ace_v0_size,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   184
	zfs_ace_v0_abstract_size,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   185
	zfs_ace_v0_mask_off,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   186
	zfs_ace_v0_data
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   187
};
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   188
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   189
static uint16_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   190
zfs_ace_fuid_get_type(void *acep)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   191
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   192
	return (((zfs_ace_hdr_t *)acep)->z_type);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   193
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   194
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   195
static uint16_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   196
zfs_ace_fuid_get_flags(void *acep)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   197
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   198
	return (((zfs_ace_hdr_t *)acep)->z_flags);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   199
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   200
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   201
static uint32_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   202
zfs_ace_fuid_get_mask(void *acep)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   203
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   204
	return (((zfs_ace_hdr_t *)acep)->z_access_mask);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   205
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   206
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   207
static uint64_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   208
zfs_ace_fuid_get_who(void *args)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   209
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   210
	uint16_t entry_type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   211
	zfs_ace_t *acep = args;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   212
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   213
	entry_type = acep->z_hdr.z_flags & ACE_TYPE_FLAGS;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   215
	if (entry_type == ACE_OWNER || entry_type == OWNING_GROUP ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   216
	    entry_type == ACE_EVERYONE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   217
		return (-1);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   218
	return (((zfs_ace_t *)acep)->z_fuid);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   219
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   220
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   221
static void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   222
zfs_ace_fuid_set_type(void *acep, uint16_t type)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   223
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   224
	((zfs_ace_hdr_t *)acep)->z_type = type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   225
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   226
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   227
static void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   228
zfs_ace_fuid_set_flags(void *acep, uint16_t flags)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   229
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   230
	((zfs_ace_hdr_t *)acep)->z_flags = flags;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   231
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   232
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   233
static void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   234
zfs_ace_fuid_set_mask(void *acep, uint32_t mask)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   235
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   236
	((zfs_ace_hdr_t *)acep)->z_access_mask = mask;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   237
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   238
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   239
static void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   240
zfs_ace_fuid_set_who(void *arg, uint64_t who)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   241
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   242
	zfs_ace_t *acep = arg;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   243
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   244
	uint16_t entry_type = acep->z_hdr.z_flags & ACE_TYPE_FLAGS;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   245
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   246
	if (entry_type == ACE_OWNER || entry_type == OWNING_GROUP ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   247
	    entry_type == ACE_EVERYONE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   248
		return;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   249
	acep->z_fuid = who;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   250
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   251
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   252
static size_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   253
zfs_ace_fuid_size(void *acep)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   254
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   255
	zfs_ace_hdr_t *zacep = acep;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   256
	uint16_t entry_type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   257
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   258
	switch (zacep->z_type) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   259
	case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   260
	case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   261
	case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   262
	case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   263
		return (sizeof (zfs_object_ace_t));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   264
	case ALLOW:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   265
	case DENY:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   266
		entry_type =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   267
		    (((zfs_ace_hdr_t *)acep)->z_flags & ACE_TYPE_FLAGS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   268
		if (entry_type == ACE_OWNER ||
7328
6bdcaa4505ac 6736457 dmu_tx_dirty_buf+297 panic while Win2003 is copying i386 folder from win2003 CD-ROM to Nevada
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7294
diff changeset
   269
		    entry_type == OWNING_GROUP ||
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   270
		    entry_type == ACE_EVERYONE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   271
			return (sizeof (zfs_ace_hdr_t));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   272
		/*FALLTHROUGH*/
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   273
	default:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   274
		return (sizeof (zfs_ace_t));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   275
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   276
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   277
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   278
static size_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   279
zfs_ace_fuid_abstract_size(void)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   280
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   281
	return (sizeof (zfs_ace_hdr_t));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   282
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   283
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   284
static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   285
zfs_ace_fuid_mask_off(void)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   286
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   287
	return (offsetof(zfs_ace_hdr_t, z_access_mask));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   288
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   289
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   290
static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   291
zfs_ace_fuid_data(void *acep, void **datap)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   292
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   293
	zfs_ace_t *zacep = acep;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   294
	zfs_object_ace_t *zobjp;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   295
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   296
	switch (zacep->z_hdr.z_type) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   297
	case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   298
	case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   299
	case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   300
	case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   301
		zobjp = acep;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   302
		*datap = (caddr_t)zobjp + sizeof (zfs_ace_t);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   303
		return (sizeof (zfs_object_ace_t) - sizeof (zfs_ace_t));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   304
	default:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   305
		*datap = NULL;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   306
		return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   307
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   308
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   309
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   310
static acl_ops_t zfs_acl_fuid_ops = {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   311
	zfs_ace_fuid_get_mask,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   312
	zfs_ace_fuid_set_mask,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   313
	zfs_ace_fuid_get_flags,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   314
	zfs_ace_fuid_set_flags,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   315
	zfs_ace_fuid_get_type,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   316
	zfs_ace_fuid_set_type,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   317
	zfs_ace_fuid_get_who,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   318
	zfs_ace_fuid_set_who,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   319
	zfs_ace_fuid_size,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   320
	zfs_ace_fuid_abstract_size,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   321
	zfs_ace_fuid_mask_off,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   322
	zfs_ace_fuid_data
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   323
};
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   324
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   325
/*
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   326
 * The following three functions are provided for compatibility with
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   327
 * older ZPL version in order to determine if the file use to have
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   328
 * an external ACL and what version of ACL previously existed on the
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   329
 * file.  Would really be nice to not need this, sigh.
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   330
 */
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   331
uint64_t
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   332
zfs_external_acl(znode_t *zp)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   333
{
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   334
	zfs_acl_phys_t acl_phys;
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   335
	int error;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   336
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   337
	if (zp->z_is_sa)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   338
		return (0);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   339
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   340
	/*
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   341
	 * Need to deal with a potential
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   342
	 * race where zfs_sa_upgrade could cause
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   343
	 * z_isa_sa to change.
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   344
	 *
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   345
	 * If the lookup fails then the state of z_is_sa should have
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   346
	 * changed.
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   347
	 */
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   348
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   349
	if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs),
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   350
	    &acl_phys, sizeof (acl_phys))) == 0)
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   351
		return (acl_phys.z_acl_extern_obj);
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   352
	else {
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   353
		/*
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   354
		 * after upgrade the SA_ZPL_ZNODE_ACL should have been
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   355
		 * removed
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   356
		 */
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   357
		VERIFY(zp->z_is_sa && error == ENOENT);
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   358
		return (0);
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   359
	}
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   360
}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   361
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   362
/*
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   363
 * Determine size of ACL in bytes
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   364
 *
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   365
 * This is more complicated than it should be since we have to deal
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   366
 * with old external ACLs.
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   367
 */
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   368
static int
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   369
zfs_acl_znode_info(znode_t *zp, int *aclsize, int *aclcount,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   370
    zfs_acl_phys_t *aclphys)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   371
{
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   372
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   373
	uint64_t acl_count;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   374
	int size;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   375
	int error;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   376
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   377
	ASSERT(MUTEX_HELD(&zp->z_acl_lock));
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   378
	if (zp->z_is_sa) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   379
		if ((error = sa_size(zp->z_sa_hdl, SA_ZPL_DACL_ACES(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   380
		    &size)) != 0)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   381
			return (error);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   382
		*aclsize = size;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   383
		if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_DACL_COUNT(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   384
		    &acl_count, sizeof (acl_count))) != 0)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   385
			return (error);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   386
		*aclcount = acl_count;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   387
	} else {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   388
		if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   389
		    aclphys, sizeof (*aclphys))) != 0)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   390
			return (error);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   391
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   392
		if (aclphys->z_acl_version == ZFS_ACL_VERSION_INITIAL) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   393
			*aclsize = ZFS_ACL_SIZE(aclphys->z_acl_size);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   394
			*aclcount = aclphys->z_acl_size;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   395
		} else {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   396
			*aclsize = aclphys->z_acl_size;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   397
			*aclcount = aclphys->z_acl_count;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   398
		}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   399
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   400
	return (0);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   401
}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   402
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   403
int
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   404
zfs_znode_acl_version(znode_t *zp)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   405
{
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   406
	zfs_acl_phys_t acl_phys;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   407
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   408
	if (zp->z_is_sa)
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   409
		return (ZFS_ACL_VERSION_FUID);
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   410
	else {
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   411
		int error;
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   412
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   413
		/*
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   414
		 * Need to deal with a potential
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   415
		 * race where zfs_sa_upgrade could cause
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   416
		 * z_isa_sa to change.
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   417
		 *
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   418
		 * If the lookup fails then the state of z_is_sa should have
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   419
		 * changed.
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   420
		 */
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   421
		if ((error = sa_lookup(zp->z_sa_hdl,
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   422
		    SA_ZPL_ZNODE_ACL(zp->z_zfsvfs),
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   423
		    &acl_phys, sizeof (acl_phys))) == 0)
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   424
			return (acl_phys.z_acl_version);
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   425
		else {
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   426
			/*
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   427
			 * After upgrade SA_ZPL_ZNODE_ACL should have
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   428
			 * been removed.
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   429
			 */
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   430
			VERIFY(zp->z_is_sa && error == ENOENT);
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   431
			return (ZFS_ACL_VERSION_FUID);
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
   432
		}
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   433
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   434
}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   435
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   436
static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   437
zfs_acl_version(int version)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   438
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   439
	if (version < ZPL_VERSION_FUID)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   440
		return (ZFS_ACL_VERSION_INITIAL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   441
	else
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   442
		return (ZFS_ACL_VERSION_FUID);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   443
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   444
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   445
static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   446
zfs_acl_version_zp(znode_t *zp)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   447
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   448
	return (zfs_acl_version(zp->z_zfsvfs->z_version));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   449
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   450
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   451
zfs_acl_t *
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   452
zfs_acl_alloc(int vers)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   453
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   454
	zfs_acl_t *aclp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   455
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   456
	aclp = kmem_zalloc(sizeof (zfs_acl_t), KM_SLEEP);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   457
	list_create(&aclp->z_acl, sizeof (zfs_acl_node_t),
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   458
	    offsetof(zfs_acl_node_t, z_next));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   459
	aclp->z_version = vers;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   460
	if (vers == ZFS_ACL_VERSION_FUID)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   461
		aclp->z_ops = zfs_acl_fuid_ops;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   462
	else
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   463
		aclp->z_ops = zfs_acl_v0_ops;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   464
	return (aclp);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   465
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   466
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   467
zfs_acl_node_t *
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   468
zfs_acl_node_alloc(size_t bytes)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   469
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   470
	zfs_acl_node_t *aclnode;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   471
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   472
	aclnode = kmem_zalloc(sizeof (zfs_acl_node_t), KM_SLEEP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   473
	if (bytes) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   474
		aclnode->z_acldata = kmem_alloc(bytes, KM_SLEEP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   475
		aclnode->z_allocdata = aclnode->z_acldata;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   476
		aclnode->z_allocsize = bytes;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   477
		aclnode->z_size = bytes;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   478
	}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   479
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   480
	return (aclnode);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   481
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   482
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   483
static void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   484
zfs_acl_node_free(zfs_acl_node_t *aclnode)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   485
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   486
	if (aclnode->z_allocsize)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   487
		kmem_free(aclnode->z_allocdata, aclnode->z_allocsize);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   488
	kmem_free(aclnode, sizeof (zfs_acl_node_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   489
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   490
5489
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   491
static void
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   492
zfs_acl_release_nodes(zfs_acl_t *aclp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   494
	zfs_acl_node_t *aclnode;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   495
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   496
	while (aclnode = list_head(&aclp->z_acl)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   497
		list_remove(&aclp->z_acl, aclnode);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   498
		zfs_acl_node_free(aclnode);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   499
	}
5489
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   500
	aclp->z_acl_count = 0;
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   501
	aclp->z_acl_bytes = 0;
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   502
}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   503
5489
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   504
void
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   505
zfs_acl_free(zfs_acl_t *aclp)
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   506
{
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   507
	zfs_acl_release_nodes(aclp);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   508
	list_destroy(&aclp->z_acl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
	kmem_free(aclp, sizeof (zfs_acl_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   510
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   511
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   512
static boolean_t
7559
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   513
zfs_acl_valid_ace_type(uint_t type, uint_t flags)
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   514
{
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   515
	uint16_t entry_type;
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   516
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   517
	switch (type) {
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   518
	case ALLOW:
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   519
	case DENY:
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   520
	case ACE_SYSTEM_AUDIT_ACE_TYPE:
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   521
	case ACE_SYSTEM_ALARM_ACE_TYPE:
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   522
		entry_type = flags & ACE_TYPE_FLAGS;
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   523
		return (entry_type == ACE_OWNER ||
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   524
		    entry_type == OWNING_GROUP ||
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   525
		    entry_type == ACE_EVERYONE || entry_type == 0 ||
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   526
		    entry_type == ACE_IDENTIFIER_GROUP);
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   527
	default:
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   528
		if (type >= MIN_ACE_TYPE && type <= MAX_ACE_TYPE)
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   529
			return (B_TRUE);
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   530
	}
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   531
	return (B_FALSE);
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   532
}
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   533
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   534
static boolean_t
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   535
zfs_ace_valid(vtype_t obj_type, zfs_acl_t *aclp, uint16_t type, uint16_t iflags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   537
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   538
	 * first check type of entry
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   539
	 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   540
7559
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   541
	if (!zfs_acl_valid_ace_type(type, iflags))
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   542
		return (B_FALSE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   543
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   544
	switch (type) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   545
	case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   546
	case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   547
	case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   548
	case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   549
		if (aclp->z_version < ZFS_ACL_VERSION_FUID)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   550
			return (B_FALSE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   551
		aclp->z_hints |= ZFS_ACL_OBJ_ACE;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   552
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   553
7559
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   554
	/*
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   555
	 * next check inheritance level flags
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   556
	 */
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   557
7057
d3fa1d6dbef7 PSARC/2008/342 Further SID support
marks
parents: 6385
diff changeset
   558
	if (obj_type == VDIR &&
d3fa1d6dbef7 PSARC/2008/342 Further SID support
marks
parents: 6385
diff changeset
   559
	    (iflags & (ACE_FILE_INHERIT_ACE|ACE_DIRECTORY_INHERIT_ACE)))
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   560
		aclp->z_hints |= ZFS_INHERIT_ACE;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   561
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   562
	if (iflags & (ACE_INHERIT_ONLY_ACE|ACE_NO_PROPAGATE_INHERIT_ACE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   563
		if ((iflags & (ACE_FILE_INHERIT_ACE|
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   564
		    ACE_DIRECTORY_INHERIT_ACE)) == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   565
			return (B_FALSE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   566
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   567
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   568
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   569
	return (B_TRUE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   570
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   571
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   572
static void *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   573
zfs_acl_next_ace(zfs_acl_t *aclp, void *start, uint64_t *who,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   574
    uint32_t *access_mask, uint16_t *iflags, uint16_t *type)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   575
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   576
	zfs_acl_node_t *aclnode;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   577
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   578
	ASSERT(aclp);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   579
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   580
	if (start == NULL) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   581
		aclnode = list_head(&aclp->z_acl);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   582
		if (aclnode == NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   583
			return (NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   584
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   585
		aclp->z_next_ace = aclnode->z_acldata;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   586
		aclp->z_curr_node = aclnode;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   587
		aclnode->z_ace_idx = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   588
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   589
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   590
	aclnode = aclp->z_curr_node;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   591
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   592
	if (aclnode == NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   593
		return (NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   594
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   595
	if (aclnode->z_ace_idx >= aclnode->z_ace_count) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   596
		aclnode = list_next(&aclp->z_acl, aclnode);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   597
		if (aclnode == NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   598
			return (NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   599
		else {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   600
			aclp->z_curr_node = aclnode;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   601
			aclnode->z_ace_idx = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   602
			aclp->z_next_ace = aclnode->z_acldata;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   603
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   604
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   605
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   606
	if (aclnode->z_ace_idx < aclnode->z_ace_count) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   607
		void *acep = aclp->z_next_ace;
7559
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   608
		size_t ace_size;
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   609
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   610
		/*
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   611
		 * Make sure we don't overstep our bounds
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   612
		 */
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   613
		ace_size = aclp->z_ops.ace_size(acep);
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   614
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   615
		if (((caddr_t)acep + ace_size) >
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   616
		    ((caddr_t)aclnode->z_acldata + aclnode->z_size)) {
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   617
			return (NULL);
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   618
		}
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   619
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   620
		*iflags = aclp->z_ops.ace_flags_get(acep);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   621
		*type = aclp->z_ops.ace_type_get(acep);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   622
		*access_mask = aclp->z_ops.ace_mask_get(acep);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   623
		*who = aclp->z_ops.ace_who_get(acep);
7559
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   624
		aclp->z_next_ace = (caddr_t)aclp->z_next_ace + ace_size;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   625
		aclnode->z_ace_idx++;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   626
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   627
		return ((void *)acep);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   628
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   629
	return (NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   630
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   631
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   632
/*ARGSUSED*/
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   633
static uint64_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   634
zfs_ace_walk(void *datap, uint64_t cookie, int aclcnt,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   635
    uint16_t *flags, uint16_t *type, uint32_t *mask)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   636
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   637
	zfs_acl_t *aclp = datap;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   638
	zfs_ace_hdr_t *acep = (zfs_ace_hdr_t *)(uintptr_t)cookie;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   639
	uint64_t who;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   640
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   641
	acep = zfs_acl_next_ace(aclp, acep, &who, mask,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   642
	    flags, type);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   643
	return ((uint64_t)(uintptr_t)acep);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   644
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   645
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   646
static zfs_acl_node_t *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   647
zfs_acl_curr_node(zfs_acl_t *aclp)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   648
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   649
	ASSERT(aclp->z_curr_node);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   650
	return (aclp->z_curr_node);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   651
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   652
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   653
/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   654
 * Copy ACE to internal ZFS format.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   655
 * While processing the ACL each ACE will be validated for correctness.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   656
 * ACE FUIDs will be created later.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   657
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   658
int
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
   659
zfs_copy_ace_2_fuid(zfsvfs_t *zfsvfs, vtype_t obj_type, zfs_acl_t *aclp,
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   660
    void *datap, zfs_ace_t *z_acl, uint64_t aclcnt, size_t *size,
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
   661
    zfs_fuid_info_t **fuidp, cred_t *cr)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   662
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   663
	int i;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   664
	uint16_t entry_type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   665
	zfs_ace_t *aceptr = z_acl;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   666
	ace_t *acep = datap;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   667
	zfs_object_ace_t *zobjacep;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   668
	ace_object_t *aceobjp;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   669
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   670
	for (i = 0; i != aclcnt; i++) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   671
		aceptr->z_hdr.z_access_mask = acep->a_access_mask;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   672
		aceptr->z_hdr.z_flags = acep->a_flags;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   673
		aceptr->z_hdr.z_type = acep->a_type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   674
		entry_type = aceptr->z_hdr.z_flags & ACE_TYPE_FLAGS;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   675
		if (entry_type != ACE_OWNER && entry_type != OWNING_GROUP &&
5824
1d2d522d19b5 6603908 can't change mode if FS/dir is out of quota
marks
parents: 5771
diff changeset
   676
		    entry_type != ACE_EVERYONE) {
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
   677
			aceptr->z_fuid = zfs_fuid_create(zfsvfs, acep->a_who,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
   678
			    cr, (entry_type == 0) ?
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
   679
			    ZFS_ACE_USER : ZFS_ACE_GROUP, fuidp);
5824
1d2d522d19b5 6603908 can't change mode if FS/dir is out of quota
marks
parents: 5771
diff changeset
   680
		}
1d2d522d19b5 6603908 can't change mode if FS/dir is out of quota
marks
parents: 5771
diff changeset
   681
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   682
		/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   683
		 * Make sure ACE is valid
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   684
		 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   685
		if (zfs_ace_valid(obj_type, aclp, aceptr->z_hdr.z_type,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   686
		    aceptr->z_hdr.z_flags) != B_TRUE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   687
			return (EINVAL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   688
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   689
		switch (acep->a_type) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   690
		case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   691
		case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   692
		case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   693
		case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   694
			zobjacep = (zfs_object_ace_t *)aceptr;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   695
			aceobjp = (ace_object_t *)acep;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   696
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   697
			bcopy(aceobjp->a_obj_type, zobjacep->z_object_type,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   698
			    sizeof (aceobjp->a_obj_type));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   699
			bcopy(aceobjp->a_inherit_obj_type,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   700
			    zobjacep->z_inherit_type,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   701
			    sizeof (aceobjp->a_inherit_obj_type));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   702
			acep = (ace_t *)((caddr_t)acep + sizeof (ace_object_t));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   703
			break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   704
		default:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   705
			acep = (ace_t *)((caddr_t)acep + sizeof (ace_t));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   706
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   707
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   708
		aceptr = (zfs_ace_t *)((caddr_t)aceptr +
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   709
		    aclp->z_ops.ace_size(aceptr));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   710
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   711
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   712
	*size = (caddr_t)aceptr - (caddr_t)z_acl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   714
	return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   715
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   716
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   717
/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   718
 * Copy ZFS ACEs to fixed size ace_t layout
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   719
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   720
static void
5771
7ba3a2c57d6a 6552639 Each zone should have it's own idmapd
jp151216
parents: 5762
diff changeset
   721
zfs_copy_fuid_2_ace(zfsvfs_t *zfsvfs, zfs_acl_t *aclp, cred_t *cr,
7ba3a2c57d6a 6552639 Each zone should have it's own idmapd
jp151216
parents: 5762
diff changeset
   722
    void *datap, int filter)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   723
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   724
	uint64_t who;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   725
	uint32_t access_mask;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   726
	uint16_t iflags, type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   727
	zfs_ace_hdr_t *zacep = NULL;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   728
	ace_t *acep = datap;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   729
	ace_object_t *objacep;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   730
	zfs_object_ace_t *zobjacep;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   731
	size_t ace_size;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   732
	uint16_t entry_type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   733
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   734
	while (zacep = zfs_acl_next_ace(aclp, zacep,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   735
	    &who, &access_mask, &iflags, &type)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   736
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   737
		switch (type) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   738
		case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   739
		case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   740
		case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   741
		case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   742
			if (filter) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   743
				continue;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   744
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   745
			zobjacep = (zfs_object_ace_t *)zacep;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   746
			objacep = (ace_object_t *)acep;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   747
			bcopy(zobjacep->z_object_type,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   748
			    objacep->a_obj_type,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   749
			    sizeof (zobjacep->z_object_type));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   750
			bcopy(zobjacep->z_inherit_type,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   751
			    objacep->a_inherit_obj_type,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   752
			    sizeof (zobjacep->z_inherit_type));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   753
			ace_size = sizeof (ace_object_t);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   754
			break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   755
		default:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   756
			ace_size = sizeof (ace_t);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   757
			break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   758
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   759
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   760
		entry_type = (iflags & ACE_TYPE_FLAGS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   761
		if ((entry_type != ACE_OWNER &&
7328
6bdcaa4505ac 6736457 dmu_tx_dirty_buf+297 panic while Win2003 is copying i386 folder from win2003 CD-ROM to Nevada
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7294
diff changeset
   762
		    entry_type != OWNING_GROUP &&
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
   763
		    entry_type != ACE_EVERYONE)) {
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
   764
			acep->a_who = zfs_fuid_map_id(zfsvfs, who,
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
   765
			    cr, (entry_type & ACE_IDENTIFIER_GROUP) ?
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
   766
			    ZFS_ACE_GROUP : ZFS_ACE_USER);
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
   767
		} else {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   768
			acep->a_who = (uid_t)(int64_t)who;
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
   769
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   770
		acep->a_access_mask = access_mask;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   771
		acep->a_flags = iflags;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   772
		acep->a_type = type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   773
		acep = (ace_t *)((caddr_t)acep + ace_size);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   774
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   775
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   776
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   777
static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   778
zfs_copy_ace_2_oldace(vtype_t obj_type, zfs_acl_t *aclp, ace_t *acep,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   779
    zfs_oldace_t *z_acl, int aclcnt, size_t *size)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   780
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   781
	int i;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   782
	zfs_oldace_t *aceptr = z_acl;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   783
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   784
	for (i = 0; i != aclcnt; i++, aceptr++) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   785
		aceptr->z_access_mask = acep[i].a_access_mask;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   786
		aceptr->z_type = acep[i].a_type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   787
		aceptr->z_flags = acep[i].a_flags;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   788
		aceptr->z_fuid = acep[i].a_who;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   789
		/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   790
		 * Make sure ACE is valid
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   791
		 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   792
		if (zfs_ace_valid(obj_type, aclp, aceptr->z_type,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   793
		    aceptr->z_flags) != B_TRUE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   794
			return (EINVAL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   795
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   796
	*size = (caddr_t)aceptr - (caddr_t)z_acl;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   797
	return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   798
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   799
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   800
/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   801
 * convert old ACL format to new
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   802
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   803
void
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
   804
zfs_acl_xform(znode_t *zp, zfs_acl_t *aclp, cred_t *cr)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   805
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   806
	zfs_oldace_t *oldaclp;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   807
	int i;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   808
	uint16_t type, iflags;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   809
	uint32_t access_mask;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   810
	uint64_t who;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   811
	void *cookie = NULL;
5489
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   812
	zfs_acl_node_t *newaclnode;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   813
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   814
	ASSERT(aclp->z_version == ZFS_ACL_VERSION_INITIAL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   815
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   816
	 * First create the ACE in a contiguous piece of memory
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   817
	 * for zfs_copy_ace_2_fuid().
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   818
	 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   819
	 * We only convert an ACL once, so this won't happen
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   820
	 * everytime.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   821
	 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   822
	oldaclp = kmem_alloc(sizeof (zfs_oldace_t) * aclp->z_acl_count,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   823
	    KM_SLEEP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   824
	i = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   825
	while (cookie = zfs_acl_next_ace(aclp, cookie, &who,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   826
	    &access_mask, &iflags, &type)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   827
		oldaclp[i].z_flags = iflags;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   828
		oldaclp[i].z_type = type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   829
		oldaclp[i].z_fuid = who;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   830
		oldaclp[i++].z_access_mask = access_mask;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   831
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   832
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   833
	newaclnode = zfs_acl_node_alloc(aclp->z_acl_count *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   834
	    sizeof (zfs_object_ace_t));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   835
	aclp->z_ops = zfs_acl_fuid_ops;
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
   836
	VERIFY(zfs_copy_ace_2_fuid(zp->z_zfsvfs, ZTOV(zp)->v_type, aclp,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
   837
	    oldaclp, newaclnode->z_acldata, aclp->z_acl_count,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
   838
	    &newaclnode->z_size, NULL, cr) == 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   839
	newaclnode->z_ace_count = aclp->z_acl_count;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   840
	aclp->z_version = ZFS_ACL_VERSION;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   841
	kmem_free(oldaclp, aclp->z_acl_count * sizeof (zfs_oldace_t));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   842
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   843
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   844
	 * Release all previous ACL nodes
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   845
	 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   846
5489
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   847
	zfs_acl_release_nodes(aclp);
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   848
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   849
	list_insert_head(&aclp->z_acl, newaclnode);
5489
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   850
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   851
	aclp->z_acl_bytes = newaclnode->z_size;
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   852
	aclp->z_acl_count = newaclnode->z_ace_count;
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
   853
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   854
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   855
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   856
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   857
 * Convert unix access mask to v4 access mask
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   858
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   859
static uint32_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   860
zfs_unix_to_v4(uint32_t access_mask)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   861
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   862
	uint32_t new_mask = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   863
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   864
	if (access_mask & S_IXOTH)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   865
		new_mask |= ACE_EXECUTE;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   866
	if (access_mask & S_IWOTH)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   867
		new_mask |= ACE_WRITE_DATA;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   868
	if (access_mask & S_IROTH)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   869
		new_mask |= ACE_READ_DATA;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   870
	return (new_mask);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   871
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   872
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   873
static void
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   874
zfs_set_ace(zfs_acl_t *aclp, void *acep, uint32_t access_mask,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   875
    uint16_t access_type, uint64_t fuid, uint16_t entry_type)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   876
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   877
	uint16_t type = entry_type & ACE_TYPE_FLAGS;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   878
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   879
	aclp->z_ops.ace_mask_set(acep, access_mask);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   880
	aclp->z_ops.ace_type_set(acep, access_type);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   881
	aclp->z_ops.ace_flags_set(acep, entry_type);
7328
6bdcaa4505ac 6736457 dmu_tx_dirty_buf+297 panic while Win2003 is copying i386 folder from win2003 CD-ROM to Nevada
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7294
diff changeset
   882
	if ((type != ACE_OWNER && type != OWNING_GROUP &&
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   883
	    type != ACE_EVERYONE))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   884
		aclp->z_ops.ace_who_set(acep, fuid);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   885
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   886
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   887
/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   888
 * Determine mode of file based on ACL.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   889
 * Also, create FUIDs for any User/Group ACEs
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   890
 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   891
uint64_t
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
   892
zfs_mode_compute(uint64_t fmode, zfs_acl_t *aclp,
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
   893
    uint64_t *pflags, uint64_t fuid, uint64_t fgid)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   894
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   895
	int		entry_type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   896
	mode_t		mode;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   897
	mode_t		seen = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   898
	zfs_ace_hdr_t 	*acep = NULL;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   899
	uint64_t	who;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   900
	uint16_t	iflags, type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   901
	uint32_t	access_mask;
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
   902
	boolean_t	an_exec_denied = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   903
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
   904
	mode = (fmode & (S_IFMT | S_ISUID | S_ISGID | S_ISVTX));
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   905
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   906
	while (acep = zfs_acl_next_ace(aclp, acep, &who,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   907
	    &access_mask, &iflags, &type)) {
4869
f123f22fc641 6590376 Fails to chmod on a zfs volume with windows ACL
marks
parents: 4321
diff changeset
   908
7559
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   909
		if (!zfs_acl_valid_ace_type(type, iflags))
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   910
			continue;
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
   911
7328
6bdcaa4505ac 6736457 dmu_tx_dirty_buf+297 panic while Win2003 is copying i386 folder from win2003 CD-ROM to Nevada
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7294
diff changeset
   912
		entry_type = (iflags & ACE_TYPE_FLAGS);
6bdcaa4505ac 6736457 dmu_tx_dirty_buf+297 panic while Win2003 is copying i386 folder from win2003 CD-ROM to Nevada
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7294
diff changeset
   913
4869
f123f22fc641 6590376 Fails to chmod on a zfs volume with windows ACL
marks
parents: 4321
diff changeset
   914
		/*
7328
6bdcaa4505ac 6736457 dmu_tx_dirty_buf+297 panic while Win2003 is copying i386 folder from win2003 CD-ROM to Nevada
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7294
diff changeset
   915
		 * Skip over owner@, group@ or everyone@ inherit only ACEs
4869
f123f22fc641 6590376 Fails to chmod on a zfs volume with windows ACL
marks
parents: 4321
diff changeset
   916
		 */
7328
6bdcaa4505ac 6736457 dmu_tx_dirty_buf+297 panic while Win2003 is copying i386 folder from win2003 CD-ROM to Nevada
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7294
diff changeset
   917
		if ((iflags & ACE_INHERIT_ONLY_ACE) &&
6bdcaa4505ac 6736457 dmu_tx_dirty_buf+297 panic while Win2003 is copying i386 folder from win2003 CD-ROM to Nevada
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7294
diff changeset
   918
		    (entry_type == ACE_OWNER || entry_type == ACE_EVERYONE ||
6bdcaa4505ac 6736457 dmu_tx_dirty_buf+297 panic while Win2003 is copying i386 folder from win2003 CD-ROM to Nevada
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7294
diff changeset
   919
		    entry_type == OWNING_GROUP))
4869
f123f22fc641 6590376 Fails to chmod on a zfs volume with windows ACL
marks
parents: 4321
diff changeset
   920
			continue;
f123f22fc641 6590376 Fails to chmod on a zfs volume with windows ACL
marks
parents: 4321
diff changeset
   921
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
   922
		if (entry_type == ACE_OWNER || (entry_type == 0 &&
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
   923
		    who == fuid)) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   924
			if ((access_mask & ACE_READ_DATA) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   925
			    (!(seen & S_IRUSR))) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   926
				seen |= S_IRUSR;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   927
				if (type == ALLOW) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   928
					mode |= S_IRUSR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   929
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   930
			}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   931
			if ((access_mask & ACE_WRITE_DATA) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   932
			    (!(seen & S_IWUSR))) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   933
				seen |= S_IWUSR;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   934
				if (type == ALLOW) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   935
					mode |= S_IWUSR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   936
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   937
			}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   938
			if ((access_mask & ACE_EXECUTE) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   939
			    (!(seen & S_IXUSR))) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   940
				seen |= S_IXUSR;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   941
				if (type == ALLOW) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   942
					mode |= S_IXUSR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   943
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   944
			}
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
   945
		} else if (entry_type == OWNING_GROUP ||
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
   946
		    (entry_type == ACE_IDENTIFIER_GROUP && who == fgid)) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   947
			if ((access_mask & ACE_READ_DATA) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   948
			    (!(seen & S_IRGRP))) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   949
				seen |= S_IRGRP;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   950
				if (type == ALLOW) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   951
					mode |= S_IRGRP;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   952
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   953
			}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   954
			if ((access_mask & ACE_WRITE_DATA) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   955
			    (!(seen & S_IWGRP))) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   956
				seen |= S_IWGRP;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   957
				if (type == ALLOW) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   958
					mode |= S_IWGRP;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   959
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   960
			}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   961
			if ((access_mask & ACE_EXECUTE) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   962
			    (!(seen & S_IXGRP))) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   963
				seen |= S_IXGRP;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   964
				if (type == ALLOW) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   965
					mode |= S_IXGRP;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   967
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   968
		} else if (entry_type == ACE_EVERYONE) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   969
			if ((access_mask & ACE_READ_DATA)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   970
				if (!(seen & S_IRUSR)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   971
					seen |= S_IRUSR;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   972
					if (type == ALLOW) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   973
						mode |= S_IRUSR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   974
					}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   975
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   976
				if (!(seen & S_IRGRP)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   977
					seen |= S_IRGRP;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   978
					if (type == ALLOW) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   979
						mode |= S_IRGRP;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   980
					}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   981
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   982
				if (!(seen & S_IROTH)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   983
					seen |= S_IROTH;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   984
					if (type == ALLOW) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
						mode |= S_IROTH;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
					}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   988
			}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   989
			if ((access_mask & ACE_WRITE_DATA)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   990
				if (!(seen & S_IWUSR)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   991
					seen |= S_IWUSR;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   992
					if (type == ALLOW) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   993
						mode |= S_IWUSR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   994
					}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   995
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   996
				if (!(seen & S_IWGRP)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   997
					seen |= S_IWGRP;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
   998
					if (type == ALLOW) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   999
						mode |= S_IWGRP;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1000
					}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1001
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1002
				if (!(seen & S_IWOTH)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1003
					seen |= S_IWOTH;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1004
					if (type == ALLOW) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1005
						mode |= S_IWOTH;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1006
					}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1007
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1008
			}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1009
			if ((access_mask & ACE_EXECUTE)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1010
				if (!(seen & S_IXUSR)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1011
					seen |= S_IXUSR;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1012
					if (type == ALLOW) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1013
						mode |= S_IXUSR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1014
					}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1015
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1016
				if (!(seen & S_IXGRP)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1017
					seen |= S_IXGRP;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1018
					if (type == ALLOW) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1019
						mode |= S_IXGRP;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1020
					}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1021
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1022
				if (!(seen & S_IXOTH)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1023
					seen |= S_IXOTH;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1024
					if (type == ALLOW) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1025
						mode |= S_IXOTH;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1026
					}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1027
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1028
			}
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1029
		} else {
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1030
			/*
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1031
			 * Only care if this IDENTIFIER_GROUP or
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1032
			 * USER ACE denies execute access to someone,
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1033
			 * mode is not affected
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1034
			 */
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1035
			if ((access_mask & ACE_EXECUTE) && type == DENY)
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1036
				an_exec_denied = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1037
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1038
	}
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1039
10143
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1040
	/*
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1041
	 * Failure to allow is effectively a deny, so execute permission
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1042
	 * is denied if it was never mentioned or if we explicitly
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1043
	 * weren't allowed it.
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1044
	 */
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1045
	if (!an_exec_denied &&
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1046
	    ((seen & ALL_MODE_EXECS) != ALL_MODE_EXECS ||
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1047
	    (mode & ALL_MODE_EXECS) != ALL_MODE_EXECS))
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1048
		an_exec_denied = B_TRUE;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1049
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1050
	if (an_exec_denied)
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1051
		*pflags &= ~ZFS_NO_EXECS_DENIED;
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1052
	else
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1053
		*pflags |= ZFS_NO_EXECS_DENIED;
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1054
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1055
	return (mode);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1056
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1057
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1058
/*
10143
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1059
 * Read an external acl object.  If the intent is to modify, always
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1060
 * create a new acl and leave any cached acl in place.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1061
 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
  1062
static int
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1063
zfs_acl_node_read(znode_t *zp, boolean_t have_lock, zfs_acl_t **aclpp,
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1064
    boolean_t will_modify)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1065
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1066
	zfs_acl_t	*aclp;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1067
	int		aclsize;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1068
	int		acl_count;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1069
	zfs_acl_node_t	*aclnode;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1070
	zfs_acl_phys_t	znode_acl;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1071
	int		version;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1072
	int		error;
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1073
	boolean_t	drop_lock = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1074
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1075
	ASSERT(MUTEX_HELD(&zp->z_acl_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1076
10143
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1077
	if (zp->z_acl_cached && !will_modify) {
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1078
		*aclpp = zp->z_acl_cached;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1079
		return (0);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1080
	}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1081
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1082
	/*
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1083
	 * close race where znode could be upgrade while trying to
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1084
	 * read the znode attributes.
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1085
	 *
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1086
	 * But this could only happen if the file isn't already an SA
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1087
	 * znode
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1088
	 */
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1089
	if (!zp->z_is_sa && !have_lock) {
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1090
		mutex_enter(&zp->z_lock);
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1091
		drop_lock = B_TRUE;
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1092
	}
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1093
	version = zfs_znode_acl_version(zp);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1094
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1095
	if ((error = zfs_acl_znode_info(zp, &aclsize,
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1096
	    &acl_count, &znode_acl)) != 0) {
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1097
		goto done;
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1098
	}
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1099
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1100
	aclp = zfs_acl_alloc(version);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1101
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1102
	aclp->z_acl_count = acl_count;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1103
	aclp->z_acl_bytes = aclsize;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1104
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1105
	aclnode = zfs_acl_node_alloc(aclsize);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1106
	aclnode->z_ace_count = aclp->z_acl_count;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1107
	aclnode->z_size = aclsize;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1108
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1109
	if (!zp->z_is_sa) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1110
		if (znode_acl.z_acl_extern_obj) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1111
			error = dmu_read(zp->z_zfsvfs->z_os,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1112
			    znode_acl.z_acl_extern_obj, 0, aclnode->z_size,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1113
			    aclnode->z_acldata, DMU_READ_PREFETCH);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1114
		} else {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1115
			bcopy(znode_acl.z_ace_data, aclnode->z_acldata,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1116
			    aclnode->z_size);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1117
		}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1118
	} else {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1119
		error = sa_lookup(zp->z_sa_hdl, SA_ZPL_DACL_ACES(zp->z_zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1120
		    aclnode->z_acldata, aclnode->z_size);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1121
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1122
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
  1123
	if (error != 0) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
  1124
		zfs_acl_free(aclp);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1125
		zfs_acl_node_free(aclnode);
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7163
diff changeset
  1126
		/* convert checksum errors into IO errors */
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7163
diff changeset
  1127
		if (error == ECKSUM)
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7163
diff changeset
  1128
			error = EIO;
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1129
		goto done;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
  1130
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1131
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1132
	list_insert_head(&aclp->z_acl, aclnode);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1133
10143
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1134
	*aclpp = aclp;
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1135
	if (!will_modify)
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1136
		zp->z_acl_cached = aclp;
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1137
done:
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1138
	if (drop_lock)
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1139
		mutex_exit(&zp->z_lock);
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1140
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1141
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1142
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1143
/*ARGSUSED*/
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1144
void
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1145
zfs_acl_data_locator(void **dataptr, uint32_t *length, uint32_t buflen,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1146
    boolean_t start, void *userdata)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1147
{
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1148
	zfs_acl_locator_cb_t *cb = (zfs_acl_locator_cb_t *)userdata;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1149
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1150
	if (start) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1151
		cb->cb_acl_node = list_head(&cb->cb_aclp->z_acl);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1152
	} else {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1153
		cb->cb_acl_node = list_next(&cb->cb_aclp->z_acl,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1154
		    cb->cb_acl_node);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1155
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1156
	*dataptr = cb->cb_acl_node->z_acldata;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1157
	*length = cb->cb_acl_node->z_size;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1158
}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1159
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1160
int
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1161
zfs_acl_chown_setattr(znode_t *zp)
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1162
{
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1163
	int error;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1164
	zfs_acl_t *aclp;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1165
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1166
	ASSERT(MUTEX_HELD(&zp->z_lock));
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1167
	ASSERT(MUTEX_HELD(&zp->z_acl_lock));
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1168
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1169
	if ((error = zfs_acl_node_read(zp, B_TRUE, &aclp, B_FALSE)) == 0)
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1170
		zp->z_mode = zfs_mode_compute(zp->z_mode, aclp,
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  1171
		    &zp->z_pflags, zp->z_uid, zp->z_gid);
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1172
	return (error);
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1173
}
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1174
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1175
/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1176
 * common code for setting ACLs.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1177
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1178
 * This function is called from zfs_mode_update, zfs_perm_init, and zfs_setacl.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1179
 * zfs_setacl passes a non-NULL inherit pointer (ihp) to indicate that it's
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1180
 * already checked the acl and knows whether to inherit.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1181
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1182
int
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1183
zfs_aclset_common(znode_t *zp, zfs_acl_t *aclp, cred_t *cr, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1184
{
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1185
	int			error;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1186
	zfsvfs_t		*zfsvfs = zp->z_zfsvfs;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1187
	dmu_object_type_t	otype;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1188
	zfs_acl_locator_cb_t	locate = { 0 };
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1189
	uint64_t		mode;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1190
	sa_bulk_attr_t		bulk[5];
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1191
	uint64_t		ctime[2];
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1192
	int			count = 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1193
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1194
	mode = zp->z_mode;
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1195
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  1196
	mode = zfs_mode_compute(mode, aclp, &zp->z_pflags,
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  1197
	    zp->z_uid, zp->z_gid);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1198
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1199
	zp->z_mode = mode;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1200
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs), NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1201
	    &mode, sizeof (mode));
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1202
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1203
	    &zp->z_pflags, sizeof (zp->z_pflags));
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1204
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1205
	    &ctime, sizeof (ctime));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1206
10143
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1207
	if (zp->z_acl_cached) {
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1208
		zfs_acl_free(zp->z_acl_cached);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1209
		zp->z_acl_cached = NULL;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1210
	}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  1211
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1212
	/*
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1213
	 * Upgrade needed?
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1214
	 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1215
	if (!zfsvfs->z_use_fuids) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1216
		otype = DMU_OT_OLDACL;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1217
	} else {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1218
		if ((aclp->z_version == ZFS_ACL_VERSION_INITIAL) &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1219
		    (zfsvfs->z_version >= ZPL_VERSION_FUID))
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1220
			zfs_acl_xform(zp, aclp, cr);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1221
		ASSERT(aclp->z_version >= ZFS_ACL_VERSION_FUID);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1222
		otype = DMU_OT_ACL;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1223
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1224
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1225
	/*
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1226
	 * Arrgh, we have to handle old on disk format
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1227
	 * as well as newer (preferred) SA format.
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1228
	 */
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1229
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1230
	if (zp->z_is_sa) { /* the easy case, just update the ACL attribute */
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1231
		locate.cb_aclp = aclp;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1232
		SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_DACL_ACES(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1233
		    zfs_acl_data_locator, &locate, aclp->z_acl_bytes);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1234
		SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_DACL_COUNT(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1235
		    NULL, &aclp->z_acl_count, sizeof (uint64_t));
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1236
	} else { /* Painful legacy way */
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1237
		zfs_acl_node_t *aclnode;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1238
		uint64_t off = 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1239
		zfs_acl_phys_t acl_phys;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1240
		uint64_t aoid;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1241
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1242
		if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1243
		    &acl_phys, sizeof (acl_phys))) != 0)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1244
			return (error);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1245
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1246
		aoid = acl_phys.z_acl_extern_obj;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1247
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1248
		if (aclp->z_acl_bytes > ZFS_ACE_SPACE) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1249
			/*
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1250
			 * If ACL was previously external and we are now
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1251
			 * converting to new ACL format then release old
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1252
			 * ACL object and create a new one.
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1253
			 */
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1254
			if (aoid &&
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1255
			    aclp->z_version != acl_phys.z_acl_version) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1256
				error = dmu_object_free(zfsvfs->z_os, aoid, tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1257
				if (error)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1258
					return (error);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1259
				aoid = 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1260
			}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1261
			if (aoid == 0) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1262
				aoid = dmu_object_alloc(zfsvfs->z_os,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1263
				    otype, aclp->z_acl_bytes,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1264
				    otype == DMU_OT_ACL ?
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1265
				    DMU_OT_SYSACL : DMU_OT_NONE,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1266
				    otype == DMU_OT_ACL ?
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1267
				    DN_MAX_BONUSLEN : 0, tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1268
			} else {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1269
				(void) dmu_object_set_blocksize(zfsvfs->z_os,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1270
				    aoid, aclp->z_acl_bytes, 0, tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1271
			}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1272
			acl_phys.z_acl_extern_obj = aoid;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1273
			for (aclnode = list_head(&aclp->z_acl); aclnode;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1274
			    aclnode = list_next(&aclp->z_acl, aclnode)) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1275
				if (aclnode->z_ace_count == 0)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1276
					continue;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1277
				dmu_write(zfsvfs->z_os, aoid, off,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1278
				    aclnode->z_size, aclnode->z_acldata, tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1279
				off += aclnode->z_size;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1280
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1281
		} else {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1282
			void *start = acl_phys.z_ace_data;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1283
			/*
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1284
			 * Migrating back embedded?
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1285
			 */
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1286
			if (acl_phys.z_acl_extern_obj) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1287
				error = dmu_object_free(zfsvfs->z_os,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1288
				    acl_phys.z_acl_extern_obj, tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1289
				if (error)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1290
					return (error);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1291
				acl_phys.z_acl_extern_obj = 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1292
			}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1293
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1294
			for (aclnode = list_head(&aclp->z_acl); aclnode;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1295
			    aclnode = list_next(&aclp->z_acl, aclnode)) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1296
				if (aclnode->z_ace_count == 0)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1297
					continue;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1298
				bcopy(aclnode->z_acldata, start,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1299
				    aclnode->z_size);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1300
				start = (caddr_t)start + aclnode->z_size;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1301
			}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1302
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1303
		/*
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1304
		 * If Old version then swap count/bytes to match old
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1305
		 * layout of znode_acl_phys_t.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1306
		 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1307
		if (aclp->z_version == ZFS_ACL_VERSION_INITIAL) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1308
			acl_phys.z_acl_size = aclp->z_acl_count;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1309
			acl_phys.z_acl_count = aclp->z_acl_bytes;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1310
		} else {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1311
			acl_phys.z_acl_size = aclp->z_acl_bytes;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1312
			acl_phys.z_acl_count = aclp->z_acl_count;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1313
		}
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1314
		acl_phys.z_acl_version = aclp->z_version;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1315
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1316
		SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ZNODE_ACL(zfsvfs), NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1317
		    &acl_phys, sizeof (acl_phys));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1318
	}
905
920e9b2e0899 6347134 zfs_zaccess() is killing ZFS stat() performance
marks
parents: 865
diff changeset
  1319
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1320
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1321
	 * Replace ACL wide bits, but first clear them.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1322
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1323
	zp->z_pflags &= ~ZFS_ACL_WIDE_FLAGS;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1324
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1325
	zp->z_pflags |= aclp->z_hints;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1326
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1327
	if (ace_trivial_common(aclp, 0, zfs_ace_walk) == 0)
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1328
		zp->z_pflags |= ZFS_ACL_TRIVIAL;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1329
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1330
	zfs_tstamp_update_setup(zp, STATE_CHANGED, NULL, ctime, B_TRUE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1331
	return (sa_bulk_update(zp->z_sa_hdl, bulk, count, tx));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1332
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1333
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1334
static void
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1335
zfs_acl_chmod(vtype_t vtype, uint64_t mode, boolean_t trim, zfs_acl_t *aclp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1336
{
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1337
	void		*acep = NULL;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1338
	uint64_t	who;
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1339
	int		new_count, new_bytes;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1340
	int		ace_size;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1341
	int 		entry_type;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1342
	uint16_t	iflags, type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1343
	uint32_t	access_mask;
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1344
	zfs_acl_node_t	*newnode;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1345
	size_t 		abstract_size = aclp->z_ops.ace_abstract_size();
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1346
	void 		*zacep;
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1347
	boolean_t	isdir;
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1348
	trivial_acl_t	masks;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1349
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1350
	new_count = new_bytes = 0;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1351
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1352
	isdir = (vtype == VDIR);
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1353
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1354
	acl_trivial_access_masks((mode_t)mode, isdir, &masks);
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1355
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1356
	newnode = zfs_acl_node_alloc((abstract_size * 6) + aclp->z_acl_bytes);
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1357
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1358
	zacep = newnode->z_acldata;
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1359
	if (masks.allow0) {
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1360
		zfs_set_ace(aclp, zacep, masks.allow0, ALLOW, -1, ACE_OWNER);
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1361
		zacep = (void *)((uintptr_t)zacep + abstract_size);
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1362
		new_count++;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1363
		new_bytes += abstract_size;
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1364
	} if (masks.deny1) {
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1365
		zfs_set_ace(aclp, zacep, masks.deny1, DENY, -1, ACE_OWNER);
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1366
		zacep = (void *)((uintptr_t)zacep + abstract_size);
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1367
		new_count++;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1368
		new_bytes += abstract_size;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1369
	}
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1370
	if (masks.deny2) {
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1371
		zfs_set_ace(aclp, zacep, masks.deny2, DENY, -1, OWNING_GROUP);
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1372
		zacep = (void *)((uintptr_t)zacep + abstract_size);
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1373
		new_count++;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1374
		new_bytes += abstract_size;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1375
	}
5489
25bfaf065197 6601830 mismatch between zfs_mount() behavior and comment
marks
parents: 5435
diff changeset
  1376
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1377
	while (acep = zfs_acl_next_ace(aclp, acep, &who, &access_mask,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1378
	    &iflags, &type)) {
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1379
		uint16_t inherit_flags;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1380
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1381
		entry_type = (iflags & ACE_TYPE_FLAGS);
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1382
		inherit_flags = (iflags & ALL_INHERIT);
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1383
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1384
		if ((entry_type == ACE_OWNER || entry_type == ACE_EVERYONE ||
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1385
		    (entry_type == OWNING_GROUP)) &&
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1386
		    ((inherit_flags & ACE_INHERIT_ONLY_ACE) == 0)) {
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1387
			continue;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1388
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1389
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1390
		/*
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1391
		 * If this ACL has any inheritable ACEs, mark that in
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1392
		 * the hints (which are later masked into the pflags)
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1393
		 * so create knows to do inheritance.
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1394
		 */
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1395
		if (isdir && (inherit_flags &
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1396
		    (ACE_FILE_INHERIT_ACE|ACE_DIRECTORY_INHERIT_ACE)))
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1397
			aclp->z_hints |= ZFS_INHERIT_ACE;
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1398
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1399
		if ((type != ALLOW && type != DENY) ||
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1400
		    (inherit_flags & ACE_INHERIT_ONLY_ACE)) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1401
			switch (type) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1402
			case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1403
			case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1404
			case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1405
			case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1406
				aclp->z_hints |= ZFS_ACL_OBJ_ACE;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1407
				break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1408
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1409
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1410
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1411
			/*
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1412
			 * Limit permissions to be no greater than
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1413
			 * group permissions.
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1414
			 * The "aclinherit" and "aclmode" properties
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1415
			 * affect policy for create and chmod(2),
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1416
			 * respectively.
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1417
			 */
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1418
			if ((type == ALLOW) && trim)
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1419
				access_mask &= masks.group;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1420
		}
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1421
		zfs_set_ace(aclp, zacep, access_mask, type, who, iflags);
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1422
		ace_size = aclp->z_ops.ace_size(acep);
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1423
		zacep = (void *)((uintptr_t)zacep + ace_size);
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1424
		new_count++;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1425
		new_bytes += ace_size;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1426
	}
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1427
	zfs_set_ace(aclp, zacep, masks.owner, 0, -1, ACE_OWNER);
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1428
	zacep = (void *)((uintptr_t)zacep + abstract_size);
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1429
	zfs_set_ace(aclp, zacep, masks.group, 0, -1, OWNING_GROUP);
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1430
	zacep = (void *)((uintptr_t)zacep + abstract_size);
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1431
	zfs_set_ace(aclp, zacep, masks.everyone, 0, -1, ACE_EVERYONE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1432
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1433
	new_count += 3;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1434
	new_bytes += abstract_size * 3;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1435
	zfs_acl_release_nodes(aclp);
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1436
	aclp->z_acl_count = new_count;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1437
	aclp->z_acl_bytes = new_bytes;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1438
	newnode->z_ace_count = new_count;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1439
	newnode->z_size = new_bytes;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1440
	list_insert_tail(&aclp->z_acl, newnode);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1441
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1442
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1443
int
5824
1d2d522d19b5 6603908 can't change mode if FS/dir is out of quota
marks
parents: 5771
diff changeset
  1444
zfs_acl_chmod_setattr(znode_t *zp, zfs_acl_t **aclp, uint64_t mode)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1445
{
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1446
	int error = 0;
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1447
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1448
	mutex_enter(&zp->z_acl_lock);
5824
1d2d522d19b5 6603908 can't change mode if FS/dir is out of quota
marks
parents: 5771
diff changeset
  1449
	mutex_enter(&zp->z_lock);
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1450
	if (zp->z_zfsvfs->z_acl_mode == ZFS_ACL_DISCARD)
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1451
		*aclp = zfs_acl_alloc(zfs_acl_version_zp(zp));
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1452
	else
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1453
		error = zfs_acl_node_read(zp, B_TRUE, aclp, B_TRUE);
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1454
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1455
	if (error == 0) {
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1456
		(*aclp)->z_hints = zp->z_pflags & V4_ACL_WIDE_FLAGS;
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1457
		zfs_acl_chmod(ZTOV(zp)->v_type, mode,
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1458
		    (zp->z_zfsvfs->z_acl_mode == ZFS_ACL_GROUPMASK), *aclp);
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1459
	}
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1460
	mutex_exit(&zp->z_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1461
	mutex_exit(&zp->z_acl_lock);
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1462
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1463
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1464
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1465
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1466
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1467
 * strip off write_owner and write_acl
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1468
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1469
static void
6385
5437941ec5a1 PSARC/2008/231 New ZFS "passthrough" ACL inheritance rules
marks
parents: 6257
diff changeset
  1470
zfs_restricted_update(zfsvfs_t *zfsvfs, zfs_acl_t *aclp, void *acep)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1471
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1472
	uint32_t mask = aclp->z_ops.ace_mask_get(acep);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1473
6385
5437941ec5a1 PSARC/2008/231 New ZFS "passthrough" ACL inheritance rules
marks
parents: 6257
diff changeset
  1474
	if ((zfsvfs->z_acl_inherit == ZFS_ACL_RESTRICTED) &&
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1475
	    (aclp->z_ops.ace_type_get(acep) == ALLOW)) {
6385
5437941ec5a1 PSARC/2008/231 New ZFS "passthrough" ACL inheritance rules
marks
parents: 6257
diff changeset
  1476
		mask &= ~RESTRICTED_CLEAR;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1477
		aclp->z_ops.ace_mask_set(acep, mask);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1478
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1479
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1480
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1481
/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1482
 * Should ACE be inherited?
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1483
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1484
static int
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1485
zfs_ace_can_use(vtype_t vtype, uint16_t acep_flags)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1486
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1487
	int	iflags = (acep_flags & 0xf);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1488
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1489
	if ((vtype == VDIR) && (iflags & ACE_DIRECTORY_INHERIT_ACE))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1490
		return (1);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1491
	else if (iflags & ACE_FILE_INHERIT_ACE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1492
		return (!((vtype == VDIR) &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1493
		    (iflags & ACE_NO_PROPAGATE_INHERIT_ACE)));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1494
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1495
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1496
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1498
 * inherit inheritable ACEs from parent
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1499
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1500
static zfs_acl_t *
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1501
zfs_acl_inherit(zfsvfs_t *zfsvfs, vtype_t vtype, zfs_acl_t *paclp,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1502
    uint64_t mode, boolean_t *need_chmod)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1503
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1504
	void		*pacep;
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1505
	void		*acep;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1506
	zfs_acl_node_t  *aclnode;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1507
	zfs_acl_t	*aclp = NULL;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1508
	uint64_t	who;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1509
	uint32_t	access_mask;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1510
	uint16_t	iflags, newflags, type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1511
	size_t		ace_size;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1512
	void		*data1, *data2;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1513
	size_t		data1sz, data2sz;
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1514
	boolean_t	vdir = vtype == VDIR;
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1515
	boolean_t	vreg = vtype == VREG;
8053
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1516
	boolean_t	passthrough, passthrough_x, noallow;
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1517
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1518
	passthrough_x =
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1519
	    zfsvfs->z_acl_inherit == ZFS_ACL_PASSTHROUGH_X;
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1520
	passthrough = passthrough_x ||
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1521
	    zfsvfs->z_acl_inherit == ZFS_ACL_PASSTHROUGH;
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1522
	noallow =
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1523
	    zfsvfs->z_acl_inherit == ZFS_ACL_NOALLOW;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1524
6385
5437941ec5a1 PSARC/2008/231 New ZFS "passthrough" ACL inheritance rules
marks
parents: 6257
diff changeset
  1525
	*need_chmod = B_TRUE;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1526
	pacep = NULL;
7559
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
  1527
	aclp = zfs_acl_alloc(paclp->z_version);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1528
	if (zfsvfs->z_acl_inherit == ZFS_ACL_DISCARD || vtype == VLNK)
8053
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1529
		return (aclp);
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1530
	while (pacep = zfs_acl_next_ace(paclp, pacep, &who,
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1531
	    &access_mask, &iflags, &type)) {
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1532
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1533
		/*
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1534
		 * don't inherit bogus ACEs
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1535
		 */
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1536
		if (!zfs_acl_valid_ace_type(type, iflags))
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1537
			continue;
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1538
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1539
		if (noallow && type == ALLOW)
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1540
			continue;
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1541
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1542
		ace_size = aclp->z_ops.ace_size(pacep);
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1543
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1544
		if (!zfs_ace_can_use(vtype, iflags))
8053
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1545
			continue;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1546
8053
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1547
		/*
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1548
		 * If owner@, group@, or everyone@ inheritable
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1549
		 * then zfs_acl_chmod() isn't needed.
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1550
		 */
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1551
		if (passthrough &&
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1552
		    ((iflags & (ACE_OWNER|ACE_EVERYONE)) ||
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1553
		    ((iflags & OWNING_GROUP) ==
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1554
		    OWNING_GROUP)) && (vreg || (vdir && (iflags &
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1555
		    ACE_DIRECTORY_INHERIT_ACE)))) {
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1556
			*need_chmod = B_FALSE;
11969
cdd98a239cd1 PSARC/2010/009 Modified ZFS passthrough-x ACL inheritance
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1557
		}
cdd98a239cd1 PSARC/2010/009 Modified ZFS passthrough-x ACL inheritance
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1558
cdd98a239cd1 PSARC/2010/009 Modified ZFS passthrough-x ACL inheritance
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1559
		if (!vdir && passthrough_x &&
cdd98a239cd1 PSARC/2010/009 Modified ZFS passthrough-x ACL inheritance
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1560
		    ((mode & (S_IXUSR | S_IXGRP | S_IXOTH)) == 0)) {
cdd98a239cd1 PSARC/2010/009 Modified ZFS passthrough-x ACL inheritance
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1561
			access_mask &= ~ACE_EXECUTE;
8053
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1562
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1563
8053
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1564
		aclnode = zfs_acl_node_alloc(ace_size);
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1565
		list_insert_tail(&aclp->z_acl, aclnode);
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1566
		acep = aclnode->z_acldata;
6385
5437941ec5a1 PSARC/2008/231 New ZFS "passthrough" ACL inheritance rules
marks
parents: 6257
diff changeset
  1567
8053
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1568
		zfs_set_ace(aclp, acep, access_mask, type,
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1569
		    who, iflags|ACE_INHERITED_ACE);
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1570
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1571
		/*
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1572
		 * Copy special opaque data if any
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1573
		 */
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1574
		if ((data1sz = paclp->z_ops.ace_data(pacep, &data1)) != 0) {
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1575
			VERIFY((data2sz = aclp->z_ops.ace_data(acep,
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1576
			    &data2)) == data1sz);
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1577
			bcopy(data1, data2, data2sz);
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1578
		}
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1579
8053
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1580
		aclp->z_acl_count++;
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1581
		aclnode->z_ace_count++;
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1582
		aclp->z_acl_bytes += aclnode->z_size;
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1583
		newflags = aclp->z_ops.ace_flags_get(acep);
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1584
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1585
		if (vdir)
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1586
			aclp->z_hints |= ZFS_INHERIT_ACE;
6385
5437941ec5a1 PSARC/2008/231 New ZFS "passthrough" ACL inheritance rules
marks
parents: 6257
diff changeset
  1587
8053
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1588
		if ((iflags & ACE_NO_PROPAGATE_INHERIT_ACE) || !vdir) {
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1589
			newflags &= ~ALL_INHERIT;
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1590
			aclp->z_ops.ace_flags_set(acep,
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1591
			    newflags|ACE_INHERITED_ACE);
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1592
			zfs_restricted_update(zfsvfs, aclp, acep);
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1593
			continue;
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1594
		}
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1595
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1596
		ASSERT(vdir);
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1597
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1598
		/*
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1599
		 * If only FILE_INHERIT is set then turn on
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1600
		 * inherit_only
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1601
		 */
8053
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1602
		if ((iflags & (ACE_FILE_INHERIT_ACE |
12322
2d0b03fa06b5 6947609 not inheriting inherit_only directories correctly
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12273
diff changeset
  1603
		    ACE_DIRECTORY_INHERIT_ACE)) == ACE_FILE_INHERIT_ACE) {
8053
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1604
			newflags |= ACE_INHERIT_ONLY_ACE;
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1605
			aclp->z_ops.ace_flags_set(acep,
271f44d3de11 PSARC/2008/659 New ZFS "passthrough-x" ACL inheritance rules
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7624
diff changeset
  1606
			    newflags|ACE_INHERITED_ACE);
12322
2d0b03fa06b5 6947609 not inheriting inherit_only directories correctly
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12273
diff changeset
  1607
		} else {
2d0b03fa06b5 6947609 not inheriting inherit_only directories correctly
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12273
diff changeset
  1608
			newflags &= ~ACE_INHERIT_ONLY_ACE;
2d0b03fa06b5 6947609 not inheriting inherit_only directories correctly
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12273
diff changeset
  1609
			aclp->z_ops.ace_flags_set(acep,
2d0b03fa06b5 6947609 not inheriting inherit_only directories correctly
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12273
diff changeset
  1610
			    newflags|ACE_INHERITED_ACE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1611
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1612
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1613
	return (aclp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1614
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1615
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1616
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1617
 * Create file system object initial permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1618
 * including inheritable ACEs.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1619
 */
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1620
int
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1621
zfs_acl_ids_create(znode_t *dzp, int flag, vattr_t *vap, cred_t *cr,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1622
    vsecattr_t *vsecp, zfs_acl_ids_t *acl_ids)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1623
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1624
	int		error;
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1625
	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1626
	zfs_acl_t	*paclp;
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
  1627
	gid_t		gid;
6385
5437941ec5a1 PSARC/2008/231 New ZFS "passthrough" ACL inheritance rules
marks
parents: 6257
diff changeset
  1628
	boolean_t	need_chmod = B_TRUE;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1629
	boolean_t	inherited = B_FALSE;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1630
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1631
	bzero(acl_ids, sizeof (zfs_acl_ids_t));
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1632
	acl_ids->z_mode = MAKEIMODE(vap->va_type, vap->va_mode);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1633
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1634
	if (vsecp)
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1635
		if ((error = zfs_vsec_2_aclp(zfsvfs, vap->va_type, vsecp, cr,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1636
		    &acl_ids->z_fuidp, &acl_ids->z_aclp)) != 0)
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1637
			return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1638
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1639
	 * Determine uid and gid.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1640
	 */
11249
6c30f7dfc97b 6906110 bad trap panic in zil_replay_log_record
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10295
diff changeset
  1641
	if ((flag & IS_ROOT_NODE) || zfsvfs->z_replay ||
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1642
	    ((flag & IS_XATTR) && (vap->va_type == VDIR))) {
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1643
		acl_ids->z_fuid = zfs_fuid_create(zfsvfs,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1644
		    (uint64_t)vap->va_uid, cr,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1645
		    ZFS_OWNER, &acl_ids->z_fuidp);
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1646
		acl_ids->z_fgid = zfs_fuid_create(zfsvfs,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1647
		    (uint64_t)vap->va_gid, cr,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1648
		    ZFS_GROUP, &acl_ids->z_fuidp);
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
  1649
		gid = vap->va_gid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1650
	} else {
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1651
		acl_ids->z_fuid = zfs_fuid_create_cred(zfsvfs, ZFS_OWNER,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1652
		    cr, &acl_ids->z_fuidp);
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1653
		acl_ids->z_fgid = 0;
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
  1654
		if (vap->va_mask & AT_GID)  {
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1655
			acl_ids->z_fgid = zfs_fuid_create(zfsvfs,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1656
			    (uint64_t)vap->va_gid,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1657
			    cr, ZFS_GROUP, &acl_ids->z_fuidp);
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
  1658
			gid = vap->va_gid;
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  1659
			if (acl_ids->z_fgid != dzp->z_gid &&
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
  1660
			    !groupmember(vap->va_gid, cr) &&
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
  1661
			    secpolicy_vnode_create_gid(cr) != 0)
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1662
				acl_ids->z_fgid = 0;
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
  1663
		}
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1664
		if (acl_ids->z_fgid == 0) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1665
			if (dzp->z_mode & S_ISGID) {
11574
42fda5f95dac 6901694 Panic attempting to write zfs credentials
John Harres <John.Harres@Sun.COM>
parents: 11249
diff changeset
  1666
				char		*domain;
42fda5f95dac 6901694 Panic attempting to write zfs credentials
John Harres <John.Harres@Sun.COM>
parents: 11249
diff changeset
  1667
				uint32_t	rid;
42fda5f95dac 6901694 Panic attempting to write zfs credentials
John Harres <John.Harres@Sun.COM>
parents: 11249
diff changeset
  1668
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  1669
				acl_ids->z_fgid = dzp->z_gid;
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1670
				gid = zfs_fuid_map_id(zfsvfs, acl_ids->z_fgid,
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
  1671
				    cr, ZFS_GROUP);
11574
42fda5f95dac 6901694 Panic attempting to write zfs credentials
John Harres <John.Harres@Sun.COM>
parents: 11249
diff changeset
  1672
42fda5f95dac 6901694 Panic attempting to write zfs credentials
John Harres <John.Harres@Sun.COM>
parents: 11249
diff changeset
  1673
				if (zfsvfs->z_use_fuids &&
42fda5f95dac 6901694 Panic attempting to write zfs credentials
John Harres <John.Harres@Sun.COM>
parents: 11249
diff changeset
  1674
				    IS_EPHEMERAL(acl_ids->z_fgid)) {
42fda5f95dac 6901694 Panic attempting to write zfs credentials
John Harres <John.Harres@Sun.COM>
parents: 11249
diff changeset
  1675
					domain = zfs_fuid_idx_domain(
42fda5f95dac 6901694 Panic attempting to write zfs credentials
John Harres <John.Harres@Sun.COM>
parents: 11249
diff changeset
  1676
					    &zfsvfs->z_fuid_idx,
42fda5f95dac 6901694 Panic attempting to write zfs credentials
John Harres <John.Harres@Sun.COM>
parents: 11249
diff changeset
  1677
					    FUID_INDEX(acl_ids->z_fgid));
42fda5f95dac 6901694 Panic attempting to write zfs credentials
John Harres <John.Harres@Sun.COM>
parents: 11249
diff changeset
  1678
					rid = FUID_RID(acl_ids->z_fgid);
42fda5f95dac 6901694 Panic attempting to write zfs credentials
John Harres <John.Harres@Sun.COM>
parents: 11249
diff changeset
  1679
					zfs_fuid_node_add(&acl_ids->z_fuidp,
42fda5f95dac 6901694 Panic attempting to write zfs credentials
John Harres <John.Harres@Sun.COM>
parents: 11249
diff changeset
  1680
					    domain, rid,
42fda5f95dac 6901694 Panic attempting to write zfs credentials
John Harres <John.Harres@Sun.COM>
parents: 11249
diff changeset
  1681
					    FUID_INDEX(acl_ids->z_fgid),
42fda5f95dac 6901694 Panic attempting to write zfs credentials
John Harres <John.Harres@Sun.COM>
parents: 11249
diff changeset
  1682
					    acl_ids->z_fgid, ZFS_GROUP);
42fda5f95dac 6901694 Panic attempting to write zfs credentials
John Harres <John.Harres@Sun.COM>
parents: 11249
diff changeset
  1683
				}
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
  1684
			} else {
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1685
				acl_ids->z_fgid = zfs_fuid_create_cred(zfsvfs,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1686
				    ZFS_GROUP, cr, &acl_ids->z_fuidp);
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
  1687
				gid = crgetgid(cr);
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
  1688
			}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1689
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1690
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1691
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1692
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1693
	 * If we're creating a directory, and the parent directory has the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1694
	 * set-GID bit set, set in on the new directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1695
	 * Otherwise, if the user is neither privileged nor a member of the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1696
	 * file's new group, clear the file's set-GID bit.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1697
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1698
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1699
	if (!(flag & IS_ROOT_NODE) && (dzp->z_mode & S_ISGID) &&
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1700
	    (vap->va_type == VDIR)) {
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1701
		acl_ids->z_mode |= S_ISGID;
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
  1702
	} else {
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1703
		if ((acl_ids->z_mode & S_ISGID) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1704
		    secpolicy_vnode_setids_setgids(cr, gid) != 0)
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1705
			acl_ids->z_mode &= ~S_ISGID;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1706
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1707
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1708
	if (acl_ids->z_aclp == NULL) {
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1709
		mutex_enter(&dzp->z_acl_lock);
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1710
		mutex_enter(&dzp->z_lock);
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1711
		if (!(flag & IS_ROOT_NODE) &&
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1712
		    (dzp->z_pflags & ZFS_INHERIT_ACE) &&
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1713
		    !(dzp->z_pflags & ZFS_XATTR)) {
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1714
			VERIFY(0 == zfs_acl_node_read(dzp, B_TRUE,
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1715
			    &paclp, B_FALSE));
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1716
			acl_ids->z_aclp = zfs_acl_inherit(zfsvfs,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1717
			    vap->va_type, paclp, acl_ids->z_mode, &need_chmod);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1718
			inherited = B_TRUE;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1719
		} else {
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1720
			acl_ids->z_aclp =
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1721
			    zfs_acl_alloc(zfs_acl_version_zp(dzp));
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1722
			acl_ids->z_aclp->z_hints |= ZFS_ACL_TRIVIAL;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1723
		}
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1724
		mutex_exit(&dzp->z_lock);
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1725
		mutex_exit(&dzp->z_acl_lock);
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1726
		if (need_chmod) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1727
			acl_ids->z_aclp->z_hints |= (vap->va_type == VDIR) ?
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1728
			    ZFS_ACL_AUTO_INHERIT : 0;
13370
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1729
			zfs_acl_chmod(vap->va_type, acl_ids->z_mode,
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1730
			    (zfsvfs->z_acl_inherit == ZFS_ACL_RESTRICTED),
8c04143bd318 742 Resurrect the ZFS "aclmode" property
Albert Lee <trisk@nexenta.com>
parents: 13101
diff changeset
  1731
			    acl_ids->z_aclp);
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1732
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1733
	}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1734
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1735
	if (inherited || vsecp) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1736
		acl_ids->z_mode = zfs_mode_compute(acl_ids->z_mode,
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1737
		    acl_ids->z_aclp, &acl_ids->z_aclp->z_hints,
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11969
diff changeset
  1738
		    acl_ids->z_fuid, acl_ids->z_fgid);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1739
		if (ace_trivial_common(acl_ids->z_aclp, 0, zfs_ace_walk) == 0)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1740
			acl_ids->z_aclp->z_hints |= ZFS_ACL_TRIVIAL;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1741
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1742
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1743
	return (0);
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1744
}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1745
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1746
/*
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1747
 * Free ACL and fuid_infop, but not the acl_ids structure
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1748
 */
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1749
void
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1750
zfs_acl_ids_free(zfs_acl_ids_t *acl_ids)
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1751
{
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1752
	if (acl_ids->z_aclp)
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1753
		zfs_acl_free(acl_ids->z_aclp);
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1754
	if (acl_ids->z_fuidp)
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1755
		zfs_fuid_info_free(acl_ids->z_fuidp);
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1756
	acl_ids->z_aclp = NULL;
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1757
	acl_ids->z_fuidp = NULL;
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1758
}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1759
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1760
boolean_t
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1761
zfs_acl_ids_overquota(zfsvfs_t *zfsvfs, zfs_acl_ids_t *acl_ids)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1762
{
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1763
	return (zfs_fuid_overquota(zfsvfs, B_FALSE, acl_ids->z_fuid) ||
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1764
	    zfs_fuid_overquota(zfsvfs, B_TRUE, acl_ids->z_fgid));
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1765
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1766
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1767
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1768
 * Retrieve a files ACL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1769
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1770
int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1771
zfs_getacl(znode_t *zp, vsecattr_t *vsecp, boolean_t skipaclchk, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1772
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1773
	zfs_acl_t	*aclp;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1774
	ulong_t		mask;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1775
	int		error;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1776
	int 		count = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1777
	int		largeace = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1778
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1779
	mask = vsecp->vsa_mask & (VSA_ACE | VSA_ACECNT |
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1780
	    VSA_ACE_ACLFLAGS | VSA_ACE_ALLTYPES);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1781
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1782
	if (mask == 0)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1783
		return (ENOSYS);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1784
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1785
	if (error = zfs_zaccess(zp, ACE_READ_ACL, 0, skipaclchk, cr))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1786
		return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1787
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1788
	mutex_enter(&zp->z_acl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1789
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1790
	error = zfs_acl_node_read(zp, B_FALSE, &aclp, B_FALSE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
  1791
	if (error != 0) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
  1792
		mutex_exit(&zp->z_acl_lock);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
  1793
		return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
  1794
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
  1795
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1796
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1797
	 * Scan ACL to determine number of ACEs
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1798
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1799
	if ((zp->z_pflags & ZFS_ACL_OBJ_ACE) && !(mask & VSA_ACE_ALLTYPES)) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1800
		void *zacep = NULL;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1801
		uint64_t who;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1802
		uint32_t access_mask;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1803
		uint16_t type, iflags;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1804
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1805
		while (zacep = zfs_acl_next_ace(aclp, zacep,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1806
		    &who, &access_mask, &iflags, &type)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1807
			switch (type) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1808
			case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1809
			case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1810
			case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1811
			case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1812
				largeace++;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1813
				continue;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1814
			default:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1815
				count++;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1816
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1817
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1818
		vsecp->vsa_aclcnt = count;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1819
	} else
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1820
		count = (int)aclp->z_acl_count;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1821
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1822
	if (mask & VSA_ACECNT) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1823
		vsecp->vsa_aclcnt = count;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1824
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1825
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1826
	if (mask & VSA_ACE) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1827
		size_t aclsz;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1828
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1829
		aclsz = count * sizeof (ace_t) +
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1830
		    sizeof (ace_object_t) * largeace;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1831
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1832
		vsecp->vsa_aclentp = kmem_alloc(aclsz, KM_SLEEP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1833
		vsecp->vsa_aclentsz = aclsz;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1834
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1835
		if (aclp->z_version == ZFS_ACL_VERSION_FUID)
5771
7ba3a2c57d6a 6552639 Each zone should have it's own idmapd
jp151216
parents: 5762
diff changeset
  1836
			zfs_copy_fuid_2_ace(zp->z_zfsvfs, aclp, cr,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1837
			    vsecp->vsa_aclentp, !(mask & VSA_ACE_ALLTYPES));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1838
		else {
10295
f7a18a1e9610 6870564 panic in zfs_getsecattr
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10232
diff changeset
  1839
			zfs_acl_node_t *aclnode;
f7a18a1e9610 6870564 panic in zfs_getsecattr
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10232
diff changeset
  1840
			void *start = vsecp->vsa_aclentp;
f7a18a1e9610 6870564 panic in zfs_getsecattr
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10232
diff changeset
  1841
f7a18a1e9610 6870564 panic in zfs_getsecattr
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10232
diff changeset
  1842
			for (aclnode = list_head(&aclp->z_acl); aclnode;
f7a18a1e9610 6870564 panic in zfs_getsecattr
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10232
diff changeset
  1843
			    aclnode = list_next(&aclp->z_acl, aclnode)) {
f7a18a1e9610 6870564 panic in zfs_getsecattr
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10232
diff changeset
  1844
				bcopy(aclnode->z_acldata, start,
f7a18a1e9610 6870564 panic in zfs_getsecattr
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10232
diff changeset
  1845
				    aclnode->z_size);
f7a18a1e9610 6870564 panic in zfs_getsecattr
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10232
diff changeset
  1846
				start = (caddr_t)start + aclnode->z_size;
f7a18a1e9610 6870564 panic in zfs_getsecattr
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10232
diff changeset
  1847
			}
f7a18a1e9610 6870564 panic in zfs_getsecattr
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10232
diff changeset
  1848
			ASSERT((caddr_t)start - (caddr_t)vsecp->vsa_aclentp ==
f7a18a1e9610 6870564 panic in zfs_getsecattr
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10232
diff changeset
  1849
			    aclp->z_acl_bytes);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1850
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1851
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1852
	if (mask & VSA_ACE_ACLFLAGS) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1853
		vsecp->vsa_aclflags = 0;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1854
		if (zp->z_pflags & ZFS_ACL_DEFAULTED)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1855
			vsecp->vsa_aclflags |= ACL_DEFAULTED;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1856
		if (zp->z_pflags & ZFS_ACL_PROTECTED)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1857
			vsecp->vsa_aclflags |= ACL_PROTECTED;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1858
		if (zp->z_pflags & ZFS_ACL_AUTO_INHERIT)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1859
			vsecp->vsa_aclflags |= ACL_AUTO_INHERIT;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1860
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1861
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1862
	mutex_exit(&zp->z_acl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1863
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1864
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1865
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1866
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1867
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1868
zfs_vsec_2_aclp(zfsvfs_t *zfsvfs, vtype_t obj_type,
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1869
    vsecattr_t *vsecp, cred_t *cr, zfs_fuid_info_t **fuidp, zfs_acl_t **zaclp)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1870
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1871
	zfs_acl_t *aclp;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1872
	zfs_acl_node_t *aclnode;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1873
	int aclcnt = vsecp->vsa_aclcnt;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1874
	int error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1875
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1876
	if (vsecp->vsa_aclcnt > MAX_ACL_ENTRIES || vsecp->vsa_aclcnt <= 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1877
		return (EINVAL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1878
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1879
	aclp = zfs_acl_alloc(zfs_acl_version(zfsvfs->z_version));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1880
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1881
	aclp->z_hints = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1882
	aclnode = zfs_acl_node_alloc(aclcnt * sizeof (zfs_object_ace_t));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1883
	if (aclp->z_version == ZFS_ACL_VERSION_INITIAL) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1884
		if ((error = zfs_copy_ace_2_oldace(obj_type, aclp,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1885
		    (ace_t *)vsecp->vsa_aclentp, aclnode->z_acldata,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1886
		    aclcnt, &aclnode->z_size)) != 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1887
			zfs_acl_free(aclp);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1888
			zfs_acl_node_free(aclnode);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1889
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1890
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1891
	} else {
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1892
		if ((error = zfs_copy_ace_2_fuid(zfsvfs, obj_type, aclp,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1893
		    vsecp->vsa_aclentp, aclnode->z_acldata, aclcnt,
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1894
		    &aclnode->z_size, fuidp, cr)) != 0) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1895
			zfs_acl_free(aclp);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1896
			zfs_acl_node_free(aclnode);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1897
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1898
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1899
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1900
	aclp->z_acl_bytes = aclnode->z_size;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1901
	aclnode->z_ace_count = aclcnt;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1902
	aclp->z_acl_count = aclcnt;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1903
	list_insert_head(&aclp->z_acl, aclnode);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1904
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1905
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1906
	 * If flags are being set then add them to z_hints
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1907
	 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1908
	if (vsecp->vsa_mask & VSA_ACE_ACLFLAGS) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1909
		if (vsecp->vsa_aclflags & ACL_PROTECTED)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1910
			aclp->z_hints |= ZFS_ACL_PROTECTED;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1911
		if (vsecp->vsa_aclflags & ACL_DEFAULTED)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1912
			aclp->z_hints |= ZFS_ACL_DEFAULTED;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1913
		if (vsecp->vsa_aclflags & ACL_AUTO_INHERIT)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1914
			aclp->z_hints |= ZFS_ACL_AUTO_INHERIT;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1915
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1916
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1917
	*zaclp = aclp;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1918
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1919
	return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1920
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1921
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1922
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1923
 * Set a files ACL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1924
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1925
int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1926
zfs_setacl(znode_t *zp, vsecattr_t *vsecp, boolean_t skipaclchk, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1927
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1928
	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1929
	zilog_t		*zilog = zfsvfs->z_log;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1930
	ulong_t		mask = vsecp->vsa_mask & (VSA_ACE | VSA_ACECNT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1931
	dmu_tx_t	*tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1932
	int		error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1933
	zfs_acl_t	*aclp;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1934
	zfs_fuid_info_t	*fuidp = NULL;
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1935
	boolean_t	fuid_dirtied;
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1936
	uint64_t	acl_obj;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1937
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1938
	if (mask == 0)
4300
d74de773d6e6 6528189 cp -p invalid argument issue on Redhat linux AS 3.0 NFS client against ZFS NFS directory
marks
parents: 2676
diff changeset
  1939
		return (ENOSYS);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1940
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1941
	if (zp->z_pflags & ZFS_IMMUTABLE)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1942
		return (EPERM);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1943
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1944
	if (error = zfs_zaccess(zp, ACE_WRITE_ACL, 0, skipaclchk, cr))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1945
		return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1946
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1947
	error = zfs_vsec_2_aclp(zfsvfs, ZTOV(zp)->v_type, vsecp, cr, &fuidp,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1948
	    &aclp);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1949
	if (error)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1950
		return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1951
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1952
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1953
	 * If ACL wide flags aren't being set then preserve any
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1954
	 * existing flags.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1955
	 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1956
	if (!(vsecp->vsa_mask & VSA_ACE_ACLFLAGS)) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1957
		aclp->z_hints |=
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1958
		    (zp->z_pflags & V4_ACL_WIDE_FLAGS);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  1959
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1960
top:
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1961
	mutex_enter(&zp->z_acl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1962
	mutex_enter(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1963
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1964
	tx = dmu_tx_create(zfsvfs->z_os);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1965
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1966
	dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1967
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  1968
	fuid_dirtied = zfsvfs->z_fuid_dirty;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1969
	if (fuid_dirtied)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1970
		zfs_fuid_txhold(zfsvfs, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1971
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1972
	/*
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1973
	 * If old version and ACL won't fit in bonus and we aren't
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1974
	 * upgrading then take out necessary DMU holds
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1975
	 */
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1976
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1977
	if ((acl_obj = zfs_external_acl(zp)) != 0) {
13058
f653a0d643ec 6973827 ACL upgrade from zpl version 2 -> 4 don't grab all the necessary tx holds.
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12620
diff changeset
  1978
		if (zfsvfs->z_version >= ZPL_VERSION_FUID &&
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1979
		    zfs_znode_acl_version(zp) <= ZFS_ACL_VERSION_INITIAL) {
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1980
			dmu_tx_hold_free(tx, acl_obj, 0,
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1981
			    DMU_OBJECT_END);
13058
f653a0d643ec 6973827 ACL upgrade from zpl version 2 -> 4 don't grab all the necessary tx holds.
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12620
diff changeset
  1982
			dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
f653a0d643ec 6973827 ACL upgrade from zpl version 2 -> 4 don't grab all the necessary tx holds.
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12620
diff changeset
  1983
			    aclp->z_acl_bytes);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1984
		} else {
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  1985
			dmu_tx_hold_write(tx, acl_obj, 0, aclp->z_acl_bytes);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1986
		}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1987
	} else if (!zp->z_is_sa && aclp->z_acl_bytes > ZFS_ACE_SPACE) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1988
		dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, aclp->z_acl_bytes);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1989
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1990
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  1991
	zfs_sa_upgrade_txholds(tx, zp);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8053
diff changeset
  1992
	error = dmu_tx_assign(tx, TXG_NOWAIT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1993
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1994
		mutex_exit(&zp->z_acl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1995
		mutex_exit(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1996
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8053
diff changeset
  1997
		if (error == ERESTART) {
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 2058
diff changeset
  1998
			dmu_tx_wait(tx);
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 2058
diff changeset
  1999
			dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2000
			goto top;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2001
		}
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 2058
diff changeset
  2002
		dmu_tx_abort(tx);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2003
		zfs_acl_free(aclp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2004
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2005
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2006
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  2007
	error = zfs_aclset_common(zp, aclp, cr, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2008
	ASSERT(error == 0);
13101
08bbd228b732 6975482 assertion failed: error == 0 (0x2 == 0x0), file: ../../common/fs/zfs/zfs_vnops.c, line: 1630
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13081
diff changeset
  2009
	ASSERT(zp->z_acl_cached == NULL);
10143
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  2010
	zp->z_acl_cached = aclp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2011
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  2012
	if (fuid_dirtied)
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  2013
		zfs_fuid_sync(zfsvfs, tx);
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8952
diff changeset
  2014
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2015
	zfs_log_acl(zilog, tx, zp, vsecp, fuidp);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2016
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2017
	if (fuidp)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2018
		zfs_fuid_info_free(fuidp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2019
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2020
done:
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  2021
	mutex_exit(&zp->z_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2022
	mutex_exit(&zp->z_acl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2023
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2024
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2025
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2026
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2027
/*
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2028
 * Check accesses of interest (AoI) against attributes of the dataset
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2029
 * such as read-only.  Returns zero if no AoI conflict with dataset
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2030
 * attributes, otherwise an appropriate errno is returned.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2031
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2032
static int
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2033
zfs_zaccess_dataset_check(znode_t *zp, uint32_t v4_mode)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2034
{
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2035
	if ((v4_mode & WRITE_MASK) &&
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2036
	    (zp->z_zfsvfs->z_vfs->vfs_flag & VFS_RDONLY) &&
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2037
	    (!IS_DEVVP(ZTOV(zp)) ||
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2038
	    (IS_DEVVP(ZTOV(zp)) && (v4_mode & WRITE_MASK_ATTRS)))) {
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2039
		return (EROFS);
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2040
	}
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2041
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2042
	/*
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2043
	 * Only check for READONLY on non-directories.
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2044
	 */
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2045
	if ((v4_mode & WRITE_MASK_DATA) &&
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2046
	    (((ZTOV(zp)->v_type != VDIR) &&
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2047
	    (zp->z_pflags & (ZFS_READONLY | ZFS_IMMUTABLE))) ||
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2048
	    (ZTOV(zp)->v_type == VDIR &&
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2049
	    (zp->z_pflags & ZFS_IMMUTABLE)))) {
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2050
		return (EPERM);
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2051
	}
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2052
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2053
	if ((v4_mode & (ACE_DELETE | ACE_DELETE_CHILD)) &&
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2054
	    (zp->z_pflags & ZFS_NOUNLINK)) {
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2055
		return (EPERM);
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2056
	}
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2057
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2058
	if (((v4_mode & (ACE_READ_DATA|ACE_EXECUTE)) &&
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2059
	    (zp->z_pflags & ZFS_AV_QUARANTINED))) {
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2060
		return (EACCES);
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2061
	}
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2062
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2063
	return (0);
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2064
}
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2065
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2066
/*
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2067
 * The primary usage of this function is to loop through all of the
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2068
 * ACEs in the znode, determining what accesses of interest (AoI) to
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2069
 * the caller are allowed or denied.  The AoI are expressed as bits in
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2070
 * the working_mode parameter.  As each ACE is processed, bits covered
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2071
 * by that ACE are removed from the working_mode.  This removal
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2072
 * facilitates two things.  The first is that when the working mode is
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2073
 * empty (= 0), we know we've looked at all the AoI. The second is
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2074
 * that the ACE interpretation rules don't allow a later ACE to undo
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2075
 * something granted or denied by an earlier ACE.  Removing the
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2076
 * discovered access or denial enforces this rule.  At the end of
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2077
 * processing the ACEs, all AoI that were found to be denied are
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2078
 * placed into the working_mode, giving the caller a mask of denied
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2079
 * accesses.  Returns:
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2080
 *	0		if all AoI granted
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2081
 *	EACCESS 	if the denied mask is non-zero
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2082
 *	other error	if abnormal failure (e.g., IO error)
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2083
 *
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2084
 * A secondary usage of the function is to determine if any of the
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2085
 * AoI are granted.  If an ACE grants any access in
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2086
 * the working_mode, we immediately short circuit out of the function.
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2087
 * This mode is chosen by setting anyaccess to B_TRUE.  The
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2088
 * working_mode is not a denied access mask upon exit if the function
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2089
 * is used in this manner.
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2090
 */
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2091
static int
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2092
zfs_zaccess_aces_check(znode_t *zp, uint32_t *working_mode,
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2093
    boolean_t anyaccess, cred_t *cr)
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2094
{
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2095
	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2096
	zfs_acl_t	*aclp;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
  2097
	int		error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2098
	uid_t		uid = crgetuid(cr);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2099
	uint64_t 	who;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2100
	uint16_t	type, iflags;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2101
	uint16_t	entry_type;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2102
	uint32_t	access_mask;
6056
37f30782c577 6664536 zfs O_RDWR access check more stringent than tmpfs or ufs
marks
parents: 5959
diff changeset
  2103
	uint32_t	deny_mask = 0;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2104
	zfs_ace_hdr_t	*acep = NULL;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2105
	boolean_t	checkit;
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2106
	uid_t		gowner;
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2107
	uid_t		fowner;
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2108
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2109
	zfs_fuid_map_ids(zp, cr, &fowner, &gowner);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2110
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2111
	mutex_enter(&zp->z_acl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2112
12620
12fcd99a642d 6957974 assertion failed: 0 == sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs)
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12322
diff changeset
  2113
	error = zfs_acl_node_read(zp, B_FALSE, &aclp, B_FALSE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
  2114
	if (error != 0) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
  2115
		mutex_exit(&zp->z_acl_lock);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
  2116
		return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
  2117
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1308
diff changeset
  2118
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2119
	ASSERT(zp->z_acl_cached);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2120
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2121
	while (acep = zfs_acl_next_ace(aclp, acep, &who, &access_mask,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2122
	    &iflags, &type)) {
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2123
		uint32_t mask_matched;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2124
7559
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
  2125
		if (!zfs_acl_valid_ace_type(type, iflags))
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
  2126
			continue;
a2e9a3201169 6746456 ZFS doesn't inherit old ACLs correctly on upgraded file system
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7328
diff changeset
  2127
7057
d3fa1d6dbef7 PSARC/2008/342 Further SID support
marks
parents: 6385
diff changeset
  2128
		if (ZTOV(zp)->v_type == VDIR && (iflags & ACE_INHERIT_ONLY_ACE))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2129
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2130
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2131
		/* Skip ACE if it does not affect any AoI */
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2132
		mask_matched = (access_mask & *working_mode);
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2133
		if (!mask_matched)
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2134
			continue;
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2135
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2136
		entry_type = (iflags & ACE_TYPE_FLAGS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2137
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2138
		checkit = B_FALSE;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2139
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2140
		switch (entry_type) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2141
		case ACE_OWNER:
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2142
			if (uid == fowner)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2143
				checkit = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2144
			break;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2145
		case OWNING_GROUP:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2146
			who = gowner;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2147
			/*FALLTHROUGH*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2148
		case ACE_IDENTIFIER_GROUP:
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2149
			checkit = zfs_groupmember(zfsvfs, who, cr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2150
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2151
		case ACE_EVERYONE:
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2152
			checkit = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2153
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2154
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2155
		/* USER Entry */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2156
		default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2157
			if (entry_type == 0) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2158
				uid_t newid;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2159
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
  2160
				newid = zfs_fuid_map_id(zfsvfs, who, cr,
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
  2161
				    ZFS_ACE_USER);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2162
				if (newid != IDMAP_WK_CREATOR_OWNER_UID &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2163
				    uid == newid)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2164
					checkit = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2165
				break;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2166
			} else {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2167
				mutex_exit(&zp->z_acl_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2168
				return (EIO);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2169
			}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2170
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2171
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2172
		if (checkit) {
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2173
			if (type == DENY) {
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2174
				DTRACE_PROBE3(zfs__ace__denies,
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2175
				    znode_t *, zp,
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2176
				    zfs_ace_hdr_t *, acep,
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2177
				    uint32_t, mask_matched);
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2178
				deny_mask |= mask_matched;
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2179
			} else {
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2180
				DTRACE_PROBE3(zfs__ace__allows,
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2181
				    znode_t *, zp,
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2182
				    zfs_ace_hdr_t *, acep,
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2183
				    uint32_t, mask_matched);
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2184
				if (anyaccess) {
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2185
					mutex_exit(&zp->z_acl_lock);
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2186
					return (0);
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2187
				}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2188
			}
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2189
			*working_mode &= ~mask_matched;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2190
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2191
6056
37f30782c577 6664536 zfs O_RDWR access check more stringent than tmpfs or ufs
marks
parents: 5959
diff changeset
  2192
		/* Are we done? */
37f30782c577 6664536 zfs O_RDWR access check more stringent than tmpfs or ufs
marks
parents: 5959
diff changeset
  2193
		if (*working_mode == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2194
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2195
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2196
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2197
	mutex_exit(&zp->z_acl_lock);
6056
37f30782c577 6664536 zfs O_RDWR access check more stringent than tmpfs or ufs
marks
parents: 5959
diff changeset
  2198
37f30782c577 6664536 zfs O_RDWR access check more stringent than tmpfs or ufs
marks
parents: 5959
diff changeset
  2199
	/* Put the found 'denies' back on the working mode */
7163
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2200
	if (deny_mask) {
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2201
		*working_mode |= deny_mask;
6056
37f30782c577 6664536 zfs O_RDWR access check more stringent than tmpfs or ufs
marks
parents: 5959
diff changeset
  2202
		return (EACCES);
7163
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2203
	} else if (*working_mode) {
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2204
		return (-1);
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2205
	}
6056
37f30782c577 6664536 zfs O_RDWR access check more stringent than tmpfs or ufs
marks
parents: 5959
diff changeset
  2206
37f30782c577 6664536 zfs O_RDWR access check more stringent than tmpfs or ufs
marks
parents: 5959
diff changeset
  2207
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2208
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2209
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2210
/*
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2211
 * Return true if any access whatsoever granted, we don't actually
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2212
 * care what access is granted.
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2213
 */
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2214
boolean_t
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2215
zfs_has_access(znode_t *zp, cred_t *cr)
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2216
{
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2217
	uint32_t have = ACE_ALL_PERMS;
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2218
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2219
	if (zfs_zaccess_aces_check(zp, &have, B_TRUE, cr) != 0) {
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2220
		uid_t owner;
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2221
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2222
		owner = zfs_fuid_map_id(zp->z_zfsvfs, zp->z_uid, cr, ZFS_OWNER);
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2223
		return (secpolicy_vnode_any_access(cr, ZTOV(zp), owner) == 0);
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2224
	}
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2225
	return (B_TRUE);
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2226
}
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2227
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2228
static int
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2229
zfs_zaccess_common(znode_t *zp, uint32_t v4_mode, uint32_t *working_mode,
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2230
    boolean_t *check_privs, boolean_t skipaclchk, cred_t *cr)
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2231
{
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2232
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2233
	int err;
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2234
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2235
	*working_mode = v4_mode;
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2236
	*check_privs = B_TRUE;
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2237
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2238
	/*
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2239
	 * Short circuit empty requests
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2240
	 */
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2241
	if (v4_mode == 0 || zfsvfs->z_replay) {
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2242
		*working_mode = 0;
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2243
		return (0);
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2244
	}
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2245
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2246
	if ((err = zfs_zaccess_dataset_check(zp, v4_mode)) != 0) {
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2247
		*check_privs = B_FALSE;
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2248
		return (err);
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2249
	}
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2250
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2251
	/*
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2252
	 * The caller requested that the ACL check be skipped.  This
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2253
	 * would only happen if the caller checked VOP_ACCESS() with a
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2254
	 * 32 bit ACE mask and already had the appropriate permissions.
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2255
	 */
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2256
	if (skipaclchk) {
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2257
		*working_mode = 0;
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2258
		return (0);
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2259
	}
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2260
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2261
	return (zfs_zaccess_aces_check(zp, working_mode, B_FALSE, cr));
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2262
}
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2263
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2264
static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2265
zfs_zaccess_append(znode_t *zp, uint32_t *working_mode, boolean_t *check_privs,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2266
    cred_t *cr)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2267
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2268
	if (*working_mode != ACE_WRITE_DATA)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2269
		return (EACCES);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2270
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2271
	return (zfs_zaccess_common(zp, ACE_APPEND_DATA, working_mode,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2272
	    check_privs, B_FALSE, cr));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2273
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2274
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2275
int
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2276
zfs_fastaccesschk_execute(znode_t *zdp, cred_t *cr)
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2277
{
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2278
	boolean_t owner = B_FALSE;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2279
	boolean_t groupmbr = B_FALSE;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2280
	boolean_t is_attr;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2281
	uid_t uid = crgetuid(cr);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2282
	int error;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2283
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2284
	if (zdp->z_pflags & ZFS_AV_QUARANTINED)
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2285
		return (EACCES);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2286
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2287
	is_attr = ((zdp->z_pflags & ZFS_XATTR) &&
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2288
	    (ZTOV(zdp)->v_type == VDIR));
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2289
	if (is_attr)
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2290
		goto slow;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2291
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2292
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2293
	mutex_enter(&zdp->z_acl_lock);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2294
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2295
	if (zdp->z_pflags & ZFS_NO_EXECS_DENIED) {
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2296
		mutex_exit(&zdp->z_acl_lock);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2297
		return (0);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2298
	}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2299
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2300
	if (FUID_INDEX(zdp->z_uid) != 0 || FUID_INDEX(zdp->z_gid) != 0) {
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2301
		mutex_exit(&zdp->z_acl_lock);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2302
		goto slow;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2303
	}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2304
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2305
	if (uid == zdp->z_uid) {
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2306
		owner = B_TRUE;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2307
		if (zdp->z_mode & S_IXUSR) {
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2308
			mutex_exit(&zdp->z_acl_lock);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2309
			return (0);
10232
f37b85f7e03e 6865875 zfs sometimes incorrectly giving search access to a dir
Tim Haley <Tim.Haley@Sun.COM>
parents: 10143
diff changeset
  2310
		} else {
f37b85f7e03e 6865875 zfs sometimes incorrectly giving search access to a dir
Tim Haley <Tim.Haley@Sun.COM>
parents: 10143
diff changeset
  2311
			mutex_exit(&zdp->z_acl_lock);
f37b85f7e03e 6865875 zfs sometimes incorrectly giving search access to a dir
Tim Haley <Tim.Haley@Sun.COM>
parents: 10143
diff changeset
  2312
			goto slow;
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2313
		}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2314
	}
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2315
	if (groupmember(zdp->z_gid, cr)) {
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2316
		groupmbr = B_TRUE;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2317
		if (zdp->z_mode & S_IXGRP) {
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2318
			mutex_exit(&zdp->z_acl_lock);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2319
			return (0);
10232
f37b85f7e03e 6865875 zfs sometimes incorrectly giving search access to a dir
Tim Haley <Tim.Haley@Sun.COM>
parents: 10143
diff changeset
  2320
		} else {
f37b85f7e03e 6865875 zfs sometimes incorrectly giving search access to a dir
Tim Haley <Tim.Haley@Sun.COM>
parents: 10143
diff changeset
  2321
			mutex_exit(&zdp->z_acl_lock);
f37b85f7e03e 6865875 zfs sometimes incorrectly giving search access to a dir
Tim Haley <Tim.Haley@Sun.COM>
parents: 10143
diff changeset
  2322
			goto slow;
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2323
		}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2324
	}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2325
	if (!owner && !groupmbr) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2326
		if (zdp->z_mode & S_IXOTH) {
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2327
			mutex_exit(&zdp->z_acl_lock);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2328
			return (0);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2329
		}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2330
	}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2331
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2332
	mutex_exit(&zdp->z_acl_lock);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2333
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2334
slow:
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2335
	DTRACE_PROBE(zfs__fastpath__execute__access__miss);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2336
	ZFS_ENTER(zdp->z_zfsvfs);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2337
	error = zfs_zaccess(zdp, ACE_EXECUTE, 0, B_FALSE, cr);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2338
	ZFS_EXIT(zdp->z_zfsvfs);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2339
	return (error);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2340
}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9866
diff changeset
  2341
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2342
/*
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2343
 * Determine whether Access should be granted/denied.
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2344
 * The least priv subsytem is always consulted as a basic privilege
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2345
 * can define any form of access.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2346
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2347
int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2348
zfs_zaccess(znode_t *zp, int mode, int flags, boolean_t skipaclchk, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2349
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2350
	uint32_t	working_mode;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2351
	int		error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2352
	int		is_attr;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2353
	boolean_t 	check_privs;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2354
	znode_t		*xzp;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2355
	znode_t 	*check_zp = zp;
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2356
	mode_t		needed_bits;
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2357
	uid_t		owner;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2358
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2359
	is_attr = ((zp->z_pflags & ZFS_XATTR) && (ZTOV(zp)->v_type == VDIR));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2360
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2361
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2362
	 * If attribute then validate against base file
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2363
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2364
	if (is_attr) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2365
		uint64_t	parent;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2366
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2367
		if ((error = sa_lookup(zp->z_sa_hdl,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2368
		    SA_ZPL_PARENT(zp->z_zfsvfs), &parent,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2369
		    sizeof (parent))) != 0)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2370
			return (error);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2371
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2372
		if ((error = zfs_zget(zp->z_zfsvfs,
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2373
		    parent, &xzp)) != 0)	{
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2374
			return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2375
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2376
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2377
		check_zp = xzp;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2378
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2379
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2380
		 * fixup mode to map to xattr perms
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2381
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2382
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2383
		if (mode & (ACE_WRITE_DATA|ACE_APPEND_DATA)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2384
			mode &= ~(ACE_WRITE_DATA|ACE_APPEND_DATA);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2385
			mode |= ACE_WRITE_NAMED_ATTRS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2386
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2387
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2388
		if (mode & (ACE_READ_DATA|ACE_EXECUTE)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2389
			mode &= ~(ACE_READ_DATA|ACE_EXECUTE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2390
			mode |= ACE_READ_NAMED_ATTRS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2391
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2392
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2393
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2394
	owner = zfs_fuid_map_id(zp->z_zfsvfs, zp->z_uid, cr, ZFS_OWNER);
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2395
	/*
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2396
	 * Map the bits required to the standard vnode flags VREAD|VWRITE|VEXEC
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2397
	 * in needed_bits.  Map the bits mapped by working_mode (currently
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2398
	 * missing) in missing_bits.
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2399
	 * Call secpolicy_vnode_access2() with (needed_bits & ~checkmode),
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2400
	 * needed_bits.
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2401
	 */
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2402
	needed_bits = 0;
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2403
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2404
	working_mode = mode;
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2405
	if ((working_mode & (ACE_READ_ACL|ACE_READ_ATTRIBUTES)) &&
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2406
	    owner == crgetuid(cr))
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2407
		working_mode &= ~(ACE_READ_ACL|ACE_READ_ATTRIBUTES);
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2408
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2409
	if (working_mode & (ACE_READ_DATA|ACE_READ_NAMED_ATTRS|
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2410
	    ACE_READ_ACL|ACE_READ_ATTRIBUTES|ACE_SYNCHRONIZE))
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2411
		needed_bits |= VREAD;
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2412
	if (working_mode & (ACE_WRITE_DATA|ACE_WRITE_NAMED_ATTRS|
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2413
	    ACE_APPEND_DATA|ACE_WRITE_ATTRIBUTES|ACE_SYNCHRONIZE))
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2414
		needed_bits |= VWRITE;
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2415
	if (working_mode & ACE_EXECUTE)
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2416
		needed_bits |= VEXEC;
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2417
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2418
	if ((error = zfs_zaccess_common(check_zp, mode, &working_mode,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2419
	    &check_privs, skipaclchk, cr)) == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2420
		if (is_attr)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2421
			VN_RELE(ZTOV(xzp));
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2422
		return (secpolicy_vnode_access2(cr, ZTOV(zp), owner,
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2423
		    needed_bits, needed_bits));
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2424
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2425
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5824
diff changeset
  2426
	if (error && !check_privs) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2427
		if (is_attr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2428
			VN_RELE(ZTOV(xzp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2429
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2430
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2431
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2432
	if (error && (flags & V_APPEND)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2433
		error = zfs_zaccess_append(zp, &working_mode, &check_privs, cr);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2434
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2435
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2436
	if (error && check_privs) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2437
		mode_t		checkmode = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2438
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2439
		/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2440
		 * First check for implicit owner permission on
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2441
		 * read_acl/read_attributes
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2442
		 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2443
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2444
		error = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2445
		ASSERT(working_mode != 0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2446
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2447
		if ((working_mode & (ACE_READ_ACL|ACE_READ_ATTRIBUTES) &&
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2448
		    owner == crgetuid(cr)))
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2449
			working_mode &= ~(ACE_READ_ACL|ACE_READ_ATTRIBUTES);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2450
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2451
		if (working_mode & (ACE_READ_DATA|ACE_READ_NAMED_ATTRS|
7624
0a59f685e81b 6744510 Should not allow to rename a file/folder when a user does not have permission
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7559
diff changeset
  2452
		    ACE_READ_ACL|ACE_READ_ATTRIBUTES|ACE_SYNCHRONIZE))
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2453
			checkmode |= VREAD;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2454
		if (working_mode & (ACE_WRITE_DATA|ACE_WRITE_NAMED_ATTRS|
7624
0a59f685e81b 6744510 Should not allow to rename a file/folder when a user does not have permission
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7559
diff changeset
  2455
		    ACE_APPEND_DATA|ACE_WRITE_ATTRIBUTES|ACE_SYNCHRONIZE))
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2456
			checkmode |= VWRITE;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2457
		if (working_mode & ACE_EXECUTE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2458
			checkmode |= VEXEC;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2459
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2460
		error = secpolicy_vnode_access2(cr, ZTOV(check_zp), owner,
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2461
		    needed_bits & ~checkmode, needed_bits);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2462
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2463
		if (error == 0 && (working_mode & ACE_WRITE_OWNER))
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2464
			error = secpolicy_vnode_chown(cr, owner);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2465
		if (error == 0 && (working_mode & ACE_WRITE_ACL))
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2466
			error = secpolicy_vnode_setdac(cr, owner);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2467
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2468
		if (error == 0 && (working_mode &
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2469
		    (ACE_DELETE|ACE_DELETE_CHILD)))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2470
			error = secpolicy_vnode_remove(cr);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2471
7624
0a59f685e81b 6744510 Should not allow to rename a file/folder when a user does not have permission
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7559
diff changeset
  2472
		if (error == 0 && (working_mode & ACE_SYNCHRONIZE)) {
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2473
			error = secpolicy_vnode_chown(cr, owner);
7624
0a59f685e81b 6744510 Should not allow to rename a file/folder when a user does not have permission
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7559
diff changeset
  2474
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2475
		if (error == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2476
			/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2477
			 * See if any bits other than those already checked
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2478
			 * for are still present.  If so then return EACCES
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2479
			 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2480
			if (working_mode & ~(ZFS_CHECKED_MASKS)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2481
				error = EACCES;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2482
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2483
		}
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2484
	} else if (error == 0) {
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2485
		error = secpolicy_vnode_access2(cr, ZTOV(zp), owner,
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2486
		    needed_bits, needed_bits);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2487
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2488
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2489
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2490
	if (is_attr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2491
		VN_RELE(ZTOV(xzp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2492
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2493
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2494
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2495
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2496
/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2497
 * Translate traditional unix VREAD/VWRITE/VEXEC mode into
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2498
 * native ACL format and call zfs_zaccess()
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2499
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2500
int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2501
zfs_zaccess_rwx(znode_t *zp, mode_t mode, int flags, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2502
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2503
	return (zfs_zaccess(zp, zfs_unix_to_v4(mode >> 6), flags, B_FALSE, cr));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2504
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2505
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2506
/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2507
 * Access function for secpolicy_vnode_setattr
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2508
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2509
int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2510
zfs_zaccess_unix(znode_t *zp, mode_t mode, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2511
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2512
	int v4_mode = zfs_unix_to_v4(mode >> 6);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2513
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2514
	return (zfs_zaccess(zp, v4_mode, 0, B_FALSE, cr));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2515
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2516
2604
b2fb13f56fe7 6461609 zfs delete permissions are not working correctly
marks
parents: 2113
diff changeset
  2517
static int
6257
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2518
zfs_delete_final_check(znode_t *zp, znode_t *dzp,
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2519
    mode_t available_perms, cred_t *cr)
2604
b2fb13f56fe7 6461609 zfs delete permissions are not working correctly
marks
parents: 2113
diff changeset
  2520
{
b2fb13f56fe7 6461609 zfs delete permissions are not working correctly
marks
parents: 2113
diff changeset
  2521
	int error;
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2522
	uid_t downer;
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2523
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2524
	downer = zfs_fuid_map_id(dzp->z_zfsvfs, dzp->z_uid, cr, ZFS_OWNER);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2525
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2526
	error = secpolicy_vnode_access2(cr, ZTOV(dzp),
13081
79b387e27d99 6971929 Unable to add/remove ACE after doing idmap flush -a
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 13058
diff changeset
  2527
	    downer, available_perms, VWRITE|VEXEC);
2604
b2fb13f56fe7 6461609 zfs delete permissions are not working correctly
marks
parents: 2113
diff changeset
  2528
b2fb13f56fe7 6461609 zfs delete permissions are not working correctly
marks
parents: 2113
diff changeset
  2529
	if (error == 0)
b2fb13f56fe7 6461609 zfs delete permissions are not working correctly
marks
parents: 2113
diff changeset
  2530
		error = zfs_sticky_remove_access(dzp, zp, cr);
b2fb13f56fe7 6461609 zfs delete permissions are not working correctly
marks
parents: 2113
diff changeset
  2531
b2fb13f56fe7 6461609 zfs delete permissions are not working correctly
marks
parents: 2113
diff changeset
  2532
	return (error);
b2fb13f56fe7 6461609 zfs delete permissions are not working correctly
marks
parents: 2113
diff changeset
  2533
}
b2fb13f56fe7 6461609 zfs delete permissions are not working correctly
marks
parents: 2113
diff changeset
  2534
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2535
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2536
 * Determine whether Access should be granted/deny, without
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2537
 * consulting least priv subsystem.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2538
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2539
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2540
 * The following chart is the recommended NFSv4 enforcement for
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2541
 * ability to delete an object.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2542
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2543
 *      -------------------------------------------------------
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2544
 *      |   Parent Dir  |           Target Object Permissions |
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2545
 *      |  permissions  |                                     |
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2546
 *      -------------------------------------------------------
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2547
 *      |               | ACL Allows | ACL Denies| Delete     |
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2548
 *      |               |  Delete    |  Delete   | unspecified|
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2549
 *      -------------------------------------------------------
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2550
 *      |  ACL Allows   | Permit     | Permit    | Permit     |
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2551
 *      |  DELETE_CHILD |                                     |
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2552
 *      -------------------------------------------------------
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2553
 *      |  ACL Denies   | Permit     | Deny      | Deny       |
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2554
 *      |  DELETE_CHILD |            |           |            |
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2555
 *      -------------------------------------------------------
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2556
 *      | ACL specifies |            |           |            |
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2557
 *      | only allow    | Permit     | Permit    | Permit     |
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2558
 *      | write and     |            |           |            |
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2559
 *      | execute       |            |           |            |
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2560
 *      -------------------------------------------------------
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2561
 *      | ACL denies    |            |           |            |
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2562
 *      | write and     | Permit     | Deny      | Deny       |
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2563
 *      | execute       |            |           |            |
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2564
 *      -------------------------------------------------------
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2565
 *         ^
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2566
 *         |
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2567
 *         No search privilege, can't even look up file?
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2568
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2569
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2570
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2571
zfs_zaccess_delete(znode_t *dzp, znode_t *zp, cred_t *cr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2572
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2573
	uint32_t dzp_working_mode = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2574
	uint32_t zp_working_mode = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2575
	int dzp_error, zp_error;
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2576
	mode_t available_perms;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2577
	boolean_t dzpcheck_privs = B_TRUE;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2578
	boolean_t zpcheck_privs = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2579
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2580
	/*
6257
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2581
	 * We want specific DELETE permissions to
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2582
	 * take precedence over WRITE/EXECUTE.  We don't
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2583
	 * want an ACL such as this to mess us up.
2604
b2fb13f56fe7 6461609 zfs delete permissions are not working correctly
marks
parents: 2113
diff changeset
  2584
	 * user:joe:write_data:deny,user:joe:delete:allow
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2585
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2586
	 * However, deny permissions may ultimately be overridden
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2587
	 * by secpolicy_vnode_access().
6257
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2588
	 *
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2589
	 * We will ask for all of the necessary permissions and then
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2590
	 * look at the working modes from the directory and target object
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2591
	 * to determine what was found.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2592
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2593
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2594
	if (zp->z_pflags & (ZFS_IMMUTABLE | ZFS_NOUNLINK))
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2595
		return (EPERM);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2596
6257
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2597
	/*
7163
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2598
	 * First row
6257
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2599
	 * If the directory permissions allow the delete, we are done.
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2600
	 */
7163
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2601
	if ((dzp_error = zfs_zaccess_common(dzp, ACE_DELETE_CHILD,
6257
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2602
	    &dzp_working_mode, &dzpcheck_privs, B_FALSE, cr)) == 0)
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2603
		return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2604
6257
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2605
	/*
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2606
	 * If target object has delete permission then we are done
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2607
	 */
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2608
	if ((zp_error = zfs_zaccess_common(zp, ACE_DELETE, &zp_working_mode,
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2609
	    &zpcheck_privs, B_FALSE, cr)) == 0)
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2610
		return (0);
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2611
7163
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2612
	ASSERT(dzp_error && zp_error);
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2613
6257
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2614
	if (!dzpcheck_privs)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2615
		return (dzp_error);
7163
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2616
	if (!zpcheck_privs)
6257
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2617
		return (zp_error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2618
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2619
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2620
	 * Second row
7163
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2621
	 *
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2622
	 * If directory returns EACCES then delete_child was denied
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2623
	 * due to deny delete_child.  In this case send the request through
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2624
	 * secpolicy_vnode_remove().  We don't use zfs_delete_final_check()
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2625
	 * since that *could* allow the delete based on write/execute permission
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2626
	 * and we want delete permissions to override write/execute.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2627
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2628
2604
b2fb13f56fe7 6461609 zfs delete permissions are not working correctly
marks
parents: 2113
diff changeset
  2629
	if (dzp_error == EACCES)
7163
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2630
		return (secpolicy_vnode_remove(cr));
2604
b2fb13f56fe7 6461609 zfs delete permissions are not working correctly
marks
parents: 2113
diff changeset
  2631
b2fb13f56fe7 6461609 zfs delete permissions are not working correctly
marks
parents: 2113
diff changeset
  2632
	/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2633
	 * Third Row
6257
0c7475fa4852 6674548 zfs_delete_final_check calls secpolicy_vnode_access on wrong vnode
marks
parents: 6056
diff changeset
  2634
	 * only need to see if we have write/execute on directory.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2635
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2636
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2637
	dzp_error = zfs_zaccess_common(dzp, ACE_EXECUTE|ACE_WRITE_DATA,
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2638
	    &dzp_working_mode, &dzpcheck_privs, B_FALSE, cr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2639
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2640
	if (dzp_error != 0 && !dzpcheck_privs)
7163
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2641
		return (dzp_error);
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2642
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2643
	/*
7163
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2644
	 * Fourth row
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2645
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2646
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2647
	available_perms = (dzp_working_mode & ACE_WRITE_DATA) ? 0 : VWRITE;
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2648
	available_perms |= (dzp_working_mode & ACE_EXECUTE) ? 0 : VEXEC;
7163
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2649
12273
63678502e95e PSARC 2009/377 In-kernel pfexec implementation.
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 12218
diff changeset
  2650
	return (zfs_delete_final_check(zp, dzp, available_perms, cr));
7163
b0960f193b35 6723181 delete deny permissions broken
marks
parents: 7057
diff changeset
  2651
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2652
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2653
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2654
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2655
zfs_zaccess_rename(znode_t *sdzp, znode_t *szp, znode_t *tdzp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2656
    znode_t *tzp, cred_t *cr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2657
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2658
	int add_perm;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2659
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2660
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11574
diff changeset
  2661
	if (szp->z_pflags & ZFS_AV_QUARANTINED)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2662
		return (EACCES);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2663
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2664
	add_perm = (ZTOV(szp)->v_type == VDIR) ?
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2665
	    ACE_ADD_SUBDIRECTORY : ACE_ADD_FILE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2666
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2667
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2668
	 * Rename permissions are combination of delete permission +
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2669
	 * add file/subdir permission.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2670
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2671
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2672
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2673
	 * first make sure we do the delete portion.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2674
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2675
	 * If that succeeds then check for add_file/add_subdir permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2676
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2677
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2678
	if (error = zfs_zaccess_delete(sdzp, szp, cr))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2679
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2680
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2681
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2682
	 * If we have a tzp, see if we can delete it?
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2683
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2684
	if (tzp) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2685
		if (error = zfs_zaccess_delete(tdzp, tzp, cr))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2686
			return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2687
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2688
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2689
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2690
	 * Now check for add permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2691
	 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4869
diff changeset
  2692
	error = zfs_zaccess(tdzp, add_perm, 0, B_FALSE, cr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2693
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2694
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2695
}