gssd: select non-conventional principal

This enable kerberized NFS mounts to succeed even if the
principal is not <HOSTNAME>$.

It works by reading another principal name from the [appdefaults]
section of krb5.conf:

[appdefaults]
nfs = {
    ad_principal_name = 129.125.39.115$
}

Signed-off-by: Jurjen Bokma <j.bokma@rug.nl>
Signed-off-by: Steve Dickson <steved@redhat.com>
start-statd: clean up output when systemd is not installed

If you don't have systemd, then this script dumps:
/usr/sbin/start-statd: line 8: systemctl: command not found

This isn't terribly useful since we ultimately fall back to running
the daemon ourselves, so probe for systemd's existence before we try
to use it.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Steve Dickson <steved@redhat.com>
nfs-utils: Allow turning off nfsv3 readdir_plus

One of our customer's application only needs file names, not file
attributes. With directories having 10K+ inodes (assuming buffer cache
has directory blocks cached having file names, but inode cache is
limited and hence need eviction of older cached inodes), older inodes
are evicted periodically. So if they keep on doing readdir(2) from NSF
client on multiple directories, some directory's files are periodically
removed from inode cache and hence new readdir(2) on same directory
requires disk access to bring back inodes again to inode cache.

As READDIRPLUS request fetches attributes also, doing getattr on each
file on server, it causes unnecessary disk accesses. If READDIRPLUS on
NFS client is returned with -ENOTSUPP, NFS client uses READDIR request
which just gets the names of the files in a directory, not attributes,
hence avoiding disk accesses on server.

There's already a corresponding client-side mount option, but an export
option reduces the need for configuration across multiple clients.

This flag affects NFSv3 only.  If it turns out it's needed for NFSv4 as
well then we may have to figure out how to extend the behavior to NFSv4,
but it's not currently obvious how to do that.

Signed-off-by: Rajesh Ghanekar <rajesh_ghanekar@symantec.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
exportfs: taught exportfs -v about the nordirplus option

Signed-off-by: Steve Dickson <steved@redhat.com>
conffile: use standard uint*_t and unsigned char

Use the standard integer types. This fixes compiling errors with musl libc.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Steve Dickson <steved@redhat.com>
Fix header include for definition of NULL

NULL is defined in stdlib.h so we need to include that.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Steve Dickson <steved@redhat.com>
configure.ac: enable GNU_SOURCE for stat64/statfs64

Use AC_USE_SYSTEM_EXTENSIONS to enable GNU_SOURCE, which is needed
for:
 - stat64 in utils/exportfs/exportfs.c
 - statfs64 in utils/mountd/cache.c

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Steve Dickson <steved@redhat.com>
replace __attribute_malloc__ with the more portable __attribute__((__malloc__))

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Steve Dickson <steved@redhat.com>
mountd: use standard dev_t instead of glibc internals

The __dev_t is a GNU libc internal. Use the standard dev_t instead,
which is specified in POSIX.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Steve Dickson <steved@redhat.com>
nfsstat: replace the legacy SA_ONESHOT with standard SA_RESETHAND

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Steve Dickson <steved@redhat.com>
Allow usage of getrpcbynumber() when getrpcbynumber_r() is unavailable

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Steve Dickson <steved@redhat.com>
mountd: Only work around glibc bugs on glibc

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Steve Dickson <steved@redhat.com>
Include libgen.h for basename

According POSIX basename(3) should have an #include <libgen.h>

There are a different GNU implementation too, that can be used with
_GNU_SOURCE, but the POSIX version is good enough and more portable.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Steve Dickson <steved@redhat.com>
exportfs: fix test of NULL pointer in host_pton()

This fixes the problem reported in:
    https://bugzilla.redhat.com/show_bug.cgi?id=1083018

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Steve Dickson <steved@redhat.com>
gssd: ensure that preferred_realm is non-NULL before passing it to strcmp

It's possible for "preferred_realm" to be NULL, in which case we
don't want to pass it to strcmp. Other places that use this variable
test whether it's NULL first -- we need to do the same here.

This should fix the gssd crash reported here:

    https://bugzilla.redhat.com/show_bug.cgi?id=1108615

Reported-by: Brian J. Murrell <brian@interlinx.bc.ca>
Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
nfs_get_tcpclient/nfs_get_udpclient - make bind(2) implicit

When attempting to establish a local ephemeral endpoint for a TCP or UDP
socket, do not explicitly call bind(2), instead let it happen implicilty
when the socket is first used.

The main motivating factor for this change is when TCP runs out of unique
ephemeral ports (i.e. cannot find any ephemeral ports which are not a
part of *any* TCP connection).  In this situation if you explicitly call
bind(2), then the call will fail with EADDRINUSE.  However, if you allow the
allocation of an ephemeral port to happen implicitly as part of connect(2)
(or other functions), then ephemeral ports can be reused, so long as
the combination of (local_ip, local_port, remote_ip, remote_port)
is unique for TCP sockets on the system.

This doesn't matter for UDP sockets, but it seemed easiest to treat TCP
and UDP sockets the same.

This can allow mount.nfs(8) to continue to function successfully, even
in the face of misbehaving applications which are creating a large number of
TCP connections.

Signed-off-by: Chris Perl <chris.perl@gmail.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
Fixed typo in nfsstat -sv output

Signed-off-by: Steve Dickson <steved@redhat.com>
exportfs: Properly parse IPv6 literal strings with null termination

The original implementation was using strncpy() with a truncation
length to an uninitialized stack buffer, leaving a string that
was only null terminated by luck.

While here, change to use no-copy semantics (no extra buffer) to
avoid buffer overflows altogether. exportfs already modifies argv
contents elsewhere, so this doesn't break anything anew.

Fixes: 4663c648 (exportfs: Support raw IPv6 addresses with
"client:/path")

Signed-off-by: Todd Vierling <todd.vierling@oracle.com>
Reviewed-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
nfsdcltrack: fix some minor nits in the manpage

nfsdcltrack isn't a daemon, and we should make mention of the section
in RFC5661.

Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
sm-notify: inform the kernel if there were no hosts to notify

In the event that there no hosts to be notified after a reboot, there's
no real reason to force lockd to wait the entire grace period before
handing out locks. We're not expecting any reclaim requests to come in
that situation.

Have sm-notify do a write to /proc/fs/lockd/nlm_end_grace if that file
is present. That informs the kernel that it's OK to go ahead and lift
lockd's grace period early.

Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Signed-off-by: Steve Dickson <steved@redhat.com>