Remove bogus NULL checks from Cache_inode

If someone passes us a NULL pointer when they shouldn't, it's better to
crash than LogDebug.

Signed-off-by: Adam C. Emerson <aemerson@linuxbox.com>
Remove bogus NULL tests from nfs_proto_tools.c

It's better to crash outright than LogDebug in these cases.

Signed-off-by: Adam C. Emerson <aemerson@linuxbox.com>
Remove bogus NULL tests from cidr

We'd much rather crash on pointer errors than LogDebug.

Signed-off-by: Adam C. Emerson <aemerson@linuxbox.com>
Remove NULL checks in Common and ConfigParsing

Signed-off-by: Adam C. Emerson <aemerson@linuxbox.com>
Remove bogus NULL checks from FSAL_VFS

Other FSAL authors should pull any out of their own FSAL.

Signed-off-by: Adam C. Emerson <aemerson@linuxbox.com>
Remove fuse_binding.c

Should have been taken out in the previous FUSE removal.

Signed-off-by: Adam C. Emerson <aemerson@linuxbox.com>
Remove (some) NULL checks from SAL

I was very conservative here, since there are some instances that just
return false or NULL on NULL.  More could probably removed without
breaking legitimate cases but making bugs easier to find.

Signed-off-by: Adam C. Emerson <aemerson@linuxbox.com>
Remove bogus NULL checks from support
Add display.h and safe display buffers

A struct display_buffer describes a string buffer and the current position
within it so that a string can be built of various components. This is
especially useful for nested display functions for data types, where
the top level display function may call display functions for sub-data types.

While building a complex string, users SHOULD check the return value from
each display function and exit if it is <= 0, however, continuing to call
display functions will be totally safe.

The only things that MUST be done if building a new display primitive is
to call display_start at the beginning and display_finish at the end. A
display primitive is a function that uses a non-display function (such as
strcat, memcpy, sprintf) to copy bytes into the buffer. Such primitives must
assure that any such routines do not overflow the buffer, and then the
primitive must manage the b_current. display_finish will handle proper
indication of a full buffer or buffer overflow.

The core routines:

display_start validate and prepare to start appending to the buffer.
display_finish wrap up after appending to the buffer.
display_reset_buffer reset a buffer for re-use to build a new string.
display_printf append to the string using printf formatting
display_opaque_value format an opaque value into the buffer
display_cat append a simple string to the buffer

Additional documentation may be found in the Doxygen comments within
the source.

Ported from 1.5 21956e8e5457441dc7638916820572b35c7dc2bd

Signed-off-by: Frank Filz <ffilzlnx@mindspring.com>
Add simple log macro to log opaque values

Ported from 1.5 e243f94f20b19bbb777b3f1ca2a6548acfab97ff

Signed-off-by: Frank Filz <ffilzlnx@mindspring.com>
Increase number of pseudo fs nodes to 2048 and check limits

Also clean up some dead code.

The limit of 100 pseudo fs nodes is rather insufficient for 1000 exports...

To make it somewhat sane to test, I increased the number of path elements in
a pseudo path to 128.

Moved set up of pseudo fs until after creating root entries. This assures
that the pseudo fs only contains valid exports (previously, an export for
a path that didn't actually exist in the FSAL would be instantiated in the
pseudo fs, and then the export would have been discarded, leaving a dangling
pointer for someone to trip on).

Also improved the logging within the pseudo fs.

Also check pseudofs_id in pseudo fs handle before dereferencing array.

Ported from 1.5: a0de6fb4a764ca4d049436eda750f9f7cce71275

Apparently 2.0 somehow wound up with two calls to nfs4_ExportToPseudoFS.
The 1.5 patch moved the call to later in init, so this patch removes the
earlier call to match the 1.5 code.

Signed-off-by: Frank Filz <ffilzlnx@mindspring.com>
Fix up READDIR in pseudo fs so it handles NFS4ERR_WRONGSEC properly

Allow READDIR with just MOUNTED_ON_FILEID to succeed even if NFS4ERR_WRONGSEC.

Also clean up some out of memory handling for READDIR, don't bother trying
to recover, just LogFatal.

Ported from 1.5: b37c3372278a5c07a4b6192ebdda4d723648d2d4

Signed-off-by: Frank Filz <ffilz@us.ibm.com>
Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Don't check timestamp or length in creds when comparing v4 clientid verifiier

Confirmed ACE's comment. Clients create new creds so timestamp is a problem.

New creds might have a different group list, which changes length of cred, if
we don't care about group list, shouldn't care about cred length either.

Ported from 1.5: 2c309a762a38d58e660783ea7c264de02a3974d7

Signed-off-by: Frank Filz <ffilz@us.ibm.com>
Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Clean up use of NFS4ERR_BADHANDLE vs NFS4ERR_STALE

A handle that COULD be a valid Ganesha handle, that happens to not be
valid currently (for example, exportid doesn't reference a currently
valid export), or a PseudoFS ID that is in range, but not currently
valid should result in NFS4ERR_STALE.

NFS4ERR_BADHANDLE should be reserved for handles that are badly formed
or otherwise could not ever be a valid Ganesha handle. We also more
carefullly check handle validity, and make checks in order such that
there won't be any surprises, like indexing beyond end of provided
handle.

We must also properly validate PseudoFS handles by the same criteria.

NFS v3 and NLM validate handles during nfs_rpc_execute. If the handle
is bad or the exportid is bad, an SVC AUTH error was sent. This is
wrong, we must send NFS3ERR_BADHANDLE for bad handles and
NFS4ERR_STALE for invalid exportid. Because NLM has ASYNC procedures,
we allow a NULL pexport to be passed to NLM procedures that take
handles, and let the procedure handle responding. NFS procedures will
be responded to within nfs_rpc_execute.

Additionally, remove CACHE_INODE_UNAPPROPRIATED_KEY and
STATE_UNAPPROPRIATED_KEY since these errors are never used (and
were translated into NFS4ERR_BADHANDLE which is probably not the right
error if we ever did have that return code.

Several handle validation routines return an NFS4ERR, we now use the
returned value in most cases (except for RESTOREFH which has a specific
error code to report empty SavedFH.

Added nfs4_sanity_check_SavedFH to simplify checking of SavedFH and
remove duplicate code.

Fix PUBFH. We were not setting the length of it, so it was taking
maximum length and this was not equal to ROOTFH. The length of a
PseudoFS handle is also now computed the same way a normal handle
length is computed.

NFS v2/v3 LINK and RENAME operations should properly validate
the destination directory handle and properly report errors.

Clean up how handle errors are logged. LogInfo is used so that
sysadmins can debug handle issues without having to see gory
code internals.

Replace nfs4_sprint_fhandle with sprint_fhandle4 (remove duplicate
code).

Replace print_buff with new routine print_fhandle_fsal for FSAL handles
to be more informative.

Ported from 1.5 95bb50ea9cfe743c312cb325fe5739c67dc44d17

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fix a logging bug in fattr_xdr_result encode_acl when no ACL present

Also fix up a few log messsage components.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Return NFS4ERR_SYMNLINK when trying to open special files

Per this linux-nfs post:

http://marc.info/?l=linux-nfs&m=131342421825436&w=2

NFS4ERR_SYMLINK is required for client to distinguish wrong file type so
it can refresh it's cache and retry with a LOOKUP instead of an OPEN.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Return NFS4ERR_ROFS for NFS v4 open for write on read-only export

Ported from 1.5 3c179ffba7d4c2318cc7540796229edf23ab724b

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Save UDP request remote port number in svc_req, since UDP xprt
is shared among different endpoints of the same host addr.
This port is needed to send data gram response back
to client.

Signed-off-by: Rong Zeng <rongzeng@us.ibm.com>
Signed-off-by: Matt Benjamin <matt@linuxbox.com>
Return NFS4ERR_NOENT instead of NFS4ERR_ACCESS on export client has no access to

If a client doesn't have any access to an EXPORT (is not listed in any
Access list for the EXPORT or covered by any wild card), we already
hide that export in READDIR. We should also return NFS4ERR_NOENT rather
than NFS4ERR_ACCESS to match.

Ported from 1.5 cee1437b2d0890f7da1a107991d6b86a37af57d5

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Make SECINFO not always return NFS4ERR_WRONGSEC

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