Restructure cache_inode_readdir callback to be made from cache_inode_getattr

For the subsequent patch to fix mounted_on_fileid, we will need to use
cache_inode_getattr from readdir, so we will utilize its callback
mechanism to make the callback to the protocol readdir handlers.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fix MOUNTED_ON_FILEID, setting from export if entry is export root

This is a complete rework of 1.5 patch
6aa4a7800602b2f89a129986b5795bc47c05c8a8

Added mounted_on_fileid parameter to cache_inode_getattr callback.

cache_inode_getattr handles selecting the correct value for
mounted_on_fileid based on the req_ctx and the inode entry.

Call cache_inode_getattr from cache_inode_readdir instead of calling
cache_inode_lock_trust_attrs directly. cache_inode_readdir now does not
have it's own callback, the callback for each entry will come from
cache_inode_getattr. To accomplish this, the readdir callers pass a
common structure to cache_inode_readdir, which will fill in the readdir
entry parameters, and then call cache_inode_getattr. The callback
function will then have both the directory entry items and the
correct attributes with a correct mounted_on_fileid having been passed.

Remove mounted_on_fileid from struct attrlist. Since mounted_on_fileid
is an NFS server attribute and is not at all an underlying filesystem
attribute, it is not appropriate for this attribute to be part of the
FSAL attrlist.

Add mounted_on_fileid to xdr_attrs_args so that it is available to
encode_mounted_on_fileid. nfs4_PseudoToFattr sets this from the
pseudo_id for PsuedoFS READDIR of a non-junction PseudoFS inode.
cache_entry_To_Fattr accomplishes thsi via Fattr_filler which is a
getattr callback function for GETATTR and PseudoFS READDIR of a
junction. nfs4_readdir_callback accomplishes this for all other
READDIR calls.

Note that a PseudoFS junction which resutls in an NFS4ERR_WRONGSEC for
the client attempting to cross, for which the client was just requesting
FATTR4_MOUNTED_ON_FILEID via READDIR of the PseudoFS directory, will
get mounted_on_fileid via nfs4_PseudoToFattr using the "trick" that
the mounted_on_fileid for the junction node is the same as it's fileid.
This is code that will be obsoleted in the future when FSAL_PSEUDO is
introduced as a first class FSAL and junctions are fully supported (in
that case, all junctions will be handled by cache_inode_readdir which
will then have to handle the NFS4ERR_WRONGSEC case - probably by
calling cache_inode_getattr anyway).

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>

Conflicts:
	src/Protocols/9P/9p_readdir.c
	src/Protocols/NFS/nfs4_op_readdir.c
Perform owner override check in protocol routines (read and write)

This is an important patch, owner override MUST be determined at the
protocol layer so that only the appropriate operations are affected.

Ported from 1.5 6cc0225700a966ac6356f54dd784931593adcaa2

Did NOT port to setattr since that will be handled later.

Also remove attempted owner override check from fsal_check_access_no_acl.
This is not an appropriate check because ACCESS calls must not be
treated with owner override. Also, owner override applies to NFS v4
(and probably 9p also).

Signed-off-by: Srikrishan Malik <srimalik@in.ibm.com>
Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Don't check for write access for OPEN share deny write

AIX clients among others expect to OPEN access read/share deny write
when executing a file.

Ported from 1.5 9c10fac86847c8eeafaa3d7e8f6f6d312c304dad

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Add is_open_write parm to cache_inode_setattr

A SETATTR(size) is allowed to anyone who has the file open for write.

Ported from 1.5 00253a3c9aed27dffb735a090c3f9654961994a0

Also removed a redundant is owner check from cache_inode_check_setattr_perms.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Allow root execute permission if someone is allowed execute

Root is only allowed to execute a file if at least one user is allowed
to execute the file.

For mode check, test is simple.

For ACL check, if we are looking for execute permission for root,
we walk the ACL, and consider ANY ACE as applicable, however, we
then ignore a DENY ACE.

Ported from 1.5 70deb145fe500d6321b3028001451a874b43f1ae
and 8b51c085b9f0c46af24f560d8d6d022197899ef9

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fix hardcoded NFS4ERR_ACCESS return code in nfs4_op_open/nfs41_op_open.

Ported from 1.5 6bc05881fe1c00b3bbe864afd4374a0eb9415d78

Signed-off-by: rong zeng <rongzeng@us.ibm.com>
Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Make generic ACL code and GPFS ACL code same so GPFS can use generic

Partial port of 1.5 faf921bab385c6a0a07e8748f84a38d381c8e588

Ported the changes to how ACLs are printed to be the same as GPFS.

The actual changes for GPFS to use the common routines are left for
a member of the FSAL_GPFS team.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Use display buffer for FSAL ACL checks

Ported from 1.5 e9b1ca9c6567e4cd9b89aecd907042937c139871

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fixes in cache_inode_readdir

cache_inode_operate_cached_dirent is ok if dirent doesn't exist
and request was CACHE_INODE_DIRENT_OP_REMOVE.

In cache_inode_readdir, while looping, must always go to next
dirent.

Also, make temp copy of name before calling cache_inode_lookup_impl.

Ported from 1.5 a0aee730daeaaffc1b62bcc5cb770accd225c5e8

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Remove unused FSAL_OWNER_OK flag

This flag was originally implemented to allow permission checking to evaluate
the conditions where the file owner is allowed access despite the mode or ACL.
This condition is now evaluated directly for I/O operations.

Ported from 1.5 2db00a02809e39a18b8ce22d890ea4339b40b8c8

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Remove unused FSAL_F_OK flag

Ported from 1.5 0ea39d03f2d57c07474470ba44bb7ad8336fa498

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Add some debug to cache_inode_access

Ported from 1.5 68b85a3307ef082d250dcf6b29adc4d164069d9c

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Make cache_inode_access_sw wrappers static inline

Ported from 1.5 17fd7b6f87e6661d939b5045acf0f482f1015444

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Add allowed and denied parms to access check routines

Affects:

fsal_test_access
fsal_check_access
cache_inode_access_sw

These parms allow access check to return the specific access mask bits
that were allowed and denied if the caller desires.

These will be used by high level permission checking to make some
more complex decisions, also, it will allow the protocol ACCESS routines
to make a single access check and be able to identify which bits should
be returned to the client.

Also, a flag is added to allow ACL interpretation to not stop at first
applicable DENY ACE. This will be used by NFS v3 and v4 ACCESS ops to
determine access in a single pass.

Ported from 1.5 c322e1b753befb0614318b0b49cbcbbca5b02f36

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Add a LogFullDebug of file type to nfs4_op_putfh

Borrowed from 1.5 989c2a846991daf34c15dde005c496ea12e980b0

The rest of that patch was irrelevant, but this debug seems useful.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fixup some error translations

New error: CACHE_INODE_BADNAME

ERR_FSAL_ISDIR -> CACHE_INODE_IS_A_DIRECTORY
ERR_FSAL_ISDIR -> STATE_IS_A_DIRECTORY

CACHE_INODE_BADNAME -> STATE_INVALID_ARGUMENT
CACHE_INODE_BADNAME -> NFS4ERR_BADNAME
CACHE_INODE_BADNAME -> NFS3ERR_INVAL (v3 doesn't have BADNAME)
CACHE_INODE_BADNAME -> NFSERR_IO (v2 doesn't even have INVAL)

In nfs4_sanity_check_FH, if required_type is DIRECTORY, return
NFS4ERR_SYMLINK or NFS4ERR_NOTDIR as appropriate.

Ported from 1.5 5cc398a1ab074772d4e875d910c3d96fa8faa3fe

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Have cache_inode_get_changeid4 check trust of attrs

This makes changeid more resilient to attr changes outside Ganesha.

Ported from 1.5 1219cc9bea64a3d34fd8b876174ea99c3930f684

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Use allowed/denied return from cache_inode_access_sw to simplify v3/4 ACCESS

By using the ability of cache_inode_access_sw to return the set of
allowed bits combined with the ability to ask for ACL evaluation to not
terminate on an applicable DENY ACE, we can make the access determination
for ACCESS with a single permission evaluation.

Also, provide a shared routine for performing the ACCESS logic.

Ported from 1.5 9d65778036b6466ffece9fbee7a6b40c35085214

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Add ATTRS_NFS3 to cover all attrs in fattr3 structure

In some cases we need to make sure we get all the FSAL attr flags
corresponding to the attributes present in NFS v3 fattr3 structure.

Ported from 1.5 3954450c52b8310184da2323b56de4d6de9a727d

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>