Use fsal_set_credentials in GPFSFSAL_unlink, GPFSFSAL_rename, and GPFSFSAL_link

Due to atomicity problems, GPFS needs to do the permission checking for
directory mutating operations, so set the thread credentials to allow that and
strip the old explicit permission checking.

Ported from 1.5 93ed49514aa8984b7c7aa1c197e18cfdda912ab1

This is a slightly different set of routines, but the net effect is the same.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Add fsal_set_credentials to fsal_symlink for FSAL_GPFS

Use fsal_set_credentials to avoid needing to chown the symlink.

Ported from 1.5 902b5c14982ca2dfcf0378a9ae61ef38b255ce15

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Only get current attr in GPFSFSAL_setattrs when FSAL is at NIV_DEBUG

Also, if we fail to get the attributes, don't return the error, just
zero out the attributes (but log a message).

Ported from 1.5 4f6c07b552c1bb3ce3ff08a97dee0a7f420799b8

In 2.0, we have the attributes in the FSAL handle, so we just use
those instead of getting attributes from disk.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Handle EROFS in GPFS by converting to ERR_FSAL_ROFS

Ported from 1.5 55e8daa111086b7cee7f592e1ed40cca245546b1

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fixup cache_inode_create in light of permissions work

Permission checking for create will be accomplished by the FSAL.

It SHOULD be accomplished by passing the user creds to the kernel or
whatever ultimately does the operation.

However we need to properly update parent directory attributes.

Ported from 1.5 d25a34770a0bdc7f6fdd609cd8b8990015722834

Note that in 2.0, permission checking had been moved into cache_inode_create
so this patch also removes that check.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Strip permission check cache_inode_link

Permission checking for link will be accomplished by the FSAL.

It SHOULD be accomplished by passing the user creds to the kernel or
whatever ultimately does the operation.

Ported from 1.5 8079744b4f3f8916862f05957431bb6664c3c46f

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Properly permission check cache_inode_rdwr

Permission checking will actually be done at protocol layer.

For NFS v4, we do permission checking on OPEN and on READ and WRITE
operations that use a special stateid.

NFS v3 operations as well as NFS v4 operations performed with a special
stateid will bypass permission checking if the user is the owner of the
file. This is in order to support client side POSIX behavior where a
file may be opened and then the permissions changed without affecting
the open (open(O_CREAT) may have the same effect). Since we don't have
a protocol open, we can not assume the file permissions have not
changed. The client will make an ACCESS call in conjunction with any
open system call that will verify if the open is allowed.

This "owner bypass" check must be done by the protocol layer and not
in the access check code. If done in the access check code, it would
confuse the ACCRESS operation.

NFS v4 OPEN will also result in read, write, or read/write permission
checking based on the type of open.

In all cases, a READ operation, or open for read only is also allowed
if the user has execute permission but not read permission. This is to
allow the client to read executables that do not allow read permission.
The client also has responsibility to make this work. If the client
makes an ACCESS call, read will be denied if the file is execute only.
Not all clients handle this condition properly, or do not handle it
properly for all types of executables.

Ported from 1.5 9f63050211c228540a256f03900e8dc6b906db69

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Strip permission checking from cache_inode_remove

Permission checking will be done by underlying filesystem under FSAL.

Ported from 1.5 856797abfe57c43c8191de8b7ba6bba0c644a3a4

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Simplify use of cache_inode_rename and Fix directory cache in cache_inode_rename

Callers should let cache_inode_rename, and ultimately FSAL_rename do the
checking of various things. This allows checks for things like empty
directories before overwrite to be done by the actual atomic operation
and not dependent on our cache.

Trim down when cache_inode_rename holds content_lock.

Also, for NFS v3, we do the get post op attr in the operation rather than
burdening cache_inode_rename with it.

All callers of cache_inode_lookup_impl needed to take content_lock around
the call. Instead of making callers do it, push the lock/unlock into
cache_inode_lookup_impl.

If todir/newname exists, we handle removing the cache entry AFTER the
FSAL_rename code, rather than using cache_inode_remove. This makes the
operation more atomic.

Ported from 1.5 bbd4e091611255a1917160ca2e762699970207cd

Make sure errors in adjusting directory cache don't cause us to skip
adjusting the other directory entries.

Ported from 1.5 a3842e78dfbaef1a87ed2f59011159749526247a

For 2.0 we also have to remove permission checking.

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

With directory permissions now being handled underneath Ganesha, Ganesha
no longer has to have special dealings with the sticky bit.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fix directory fd leak.

Ported from 1.5 1e5797b82602a3d0009a71e4099f271b669d109a

Signed-off-by: Venkateswararao Jujjuri "<jvrao@linux.vnet.ibm.com>
Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fix typos in FSAL/access_check.c

Ported from 1.5 165fefa72c5f8c6d08a9f011f8722c82b830e1ef

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Make debugging permission checking easier.

Using COMPONENT_NFS_V4_ACL will allow tracing permission checking at
all layers. If it is not turned on, some log messages will go to
COMPONENT_CACHE_INODE or COMPONENT_NFSPROTO.

Ported from 1.5 5a5083110558a9be904c2aa23c11e4eca2a08b7e

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Add some debug for cache_inode_rename and cache_inode_remove

Ported from 1.5 6c99fdb2ba2c67a7614c7ff59dcefbbe8466e45a

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Return EPERM instead of EACCESS for ACL when appropriate

EPERM is expected when ACE4_WRITE_ATTR, ACE4_WRITE_ACL, or
ACE4_WRITE_OWNER are required and either not granted or
explicitly denied.

Ported from 1.5 411d8fc3674fe9382b51013f73c1855c108df1a7

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fix a couple exit conditions in cache_inode_readdir
Set process umask from config

If process umask isn't set from config, then files created may not get
the expected mode.

Ported from 1.5 ef55ba81482cff171c9b9e574a2ab38fe621571f

Well, not really, just call umask(0000);

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Some miscellaneous log changes that seemed valuable from 1.5

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fixup cache inode hash functions in shell

The shell was using different cache inode hash functions than
Ganesha. Use the same ones and get rid of the crufty ones.:wq

Ported from 1.5 1de053896a256d4b8312a12e8b5b77c826b2aec8

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Remove use of log_snprintf and log_fprintf from shell and Log/test_liblog_functions.c

NOTE: shell/commands_Cache_inode.c depends on long deprecated special
Ganesha formatting codes. These fprintf will not work...

Since Ganesha no longer has it's own snprintf implementation
for logging, there is no need to test it.

Ported from 1.5 15001e6a9fea5c4934a41d0628df7f23ae0101a6

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