Return cache_entry refs in dirent populate callback.

The dirent populate callback routine leaked cache entry
references, which are returned indirectly from
cache_inode_new_entry.

The desired behavior is to return each reference immediately.
The LRU mechanism and policies will take care of its lifetime
in the entry cache.

For improved readability, rename the callback from "populate"
to "populate_dirent."  Simplify error handling, just return
false at the error point, since the error label did no work.
Use STYLE(9) return.

Thanks to Dominique Martinet <dominique.martinet@cea.fr> for
finding and reporting this.

Signed-off-by: Matt Benjamin <matt@linuxbox.com>
Avoid overrunning buffer strcaller if getpeername fails.

Typo.

Signed-off-by: Matt Benjamin <matt@linuxbox.com>
Initialize grp_tail proc_export (werror).

The surrounding code must assure that grp_tail actually
has a value in all cases, I've not attempted to verify
this.

Signed-off-by: Matt Benjamin <matt@linuxbox.com>
Assign RES_READDIR3_OK invariantly (werror).

GCC decided that RES_READDIR3 might be used uninitialized.
Just do so in the prologue.

Signed-off-by: Matt Benjamin <matt@linuxbox.com>
Break out cast pointing into sockaddr_in6.s6_addr (strict aliasing).

It is not clear to me that the flagged code was incorrect, or that
it presented a real aliasing problem, but gcc 4.7.2 seems to think
so, perhaps due to the nested casts.

Signed-off-by: Matt Benjamin <matt@linuxbox.com>
Break out cast pointing into sockaddr_in6.s6_addr (strict aliasing).

It is not clear to me that the flagged code was incorrect, or that
it presented a real aliasing problem, but gcc 4.7.2 seems to think
so, perhaps due to the nested casts.

Signed-off-by: Matt Benjamin <matt@linuxbox.com>
Make some cosmetic changes to readdir to make porting easier

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
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>