summaryrefslogtreecommitdiffstats
path: root/support
Commit message (Collapse)AuthorAgeFilesLines
...
* nfs-utils: Fix C aliasing rules violation in nfs_getrpccaller()Chuck Lever2010-07-191-2/+2
| | | | | | | | | | | | | | | Squelch compiler warnings reported with -Wextra: In file included from statd.c:24: ../../support/include/rpcmisc.h: In function nfs_getrpccaller_in: ../../support/include/rpcmisc.h:58: warning: dereferencing type-punned pointer might break strict-aliasing rules ../../support/include/rpcmisc.h: In function nfs_getrpccaller: ../../support/include/rpcmisc.h:63: warning: dereferencing type-punned pointer might break strict-aliasing rules Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Remove unused hostent-based DNS helper functionsChuck Lever2010-06-222-310/+16
| | | | | | | | | | | Clean up: Get rid of hostent-based DNS helper functions in libexport.a that have been replaced by addrinfo-based DNS helpers. None of the original code remains, so replace the copyright notice as well. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Replace matchhostname()Chuck Lever2010-06-221-2/+0
| | | | | | | | | | | | | | | | | So that exportfs can eventually support IPv6 addresses, copy statd's getaddrinfo(3)-based matchhostname to exportfs, with adjustments for dealing with export wildcards and netgroups. Until exportfs has full IPv6 support, however, we want to ensure that IPv6 addresses continue to remain blocked in the address comparison code used by exportfs. At a later point we'll replace much of this with the generic functions in sockaddr.h. Since it contains special logic for handling wildcard and netgroups, this function is specialized for exportfs, and does not belong in one of the shared libraries. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Add documenting commentsChuck Lever2010-06-222-9/+39
| | | | | | | | Clean up. Add a few additional documenting comments for globally visible functions. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Make export_add() staticChuck Lever2010-06-222-5/+2
| | | | | | | | Clean up: export_add() is not called from outside of export.c, so make it a static helper. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Make export_read() return voidChuck Lever2010-06-222-3/+7
| | | | | | | | Clean up: export_read()'s return value is always zero, and its only caller never checks it. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* mountd: Replace "struct hostent" with "struct addrinfo"Chuck Lever2010-06-224-138/+181
| | | | | | | | | | | | | | | | | | | struct hostent can store either IPv4 or IPv6 addresses, but it can't store both address families concurrently for the same host. Neither can hostent deal with parts of socket addresses that are outside of the sin{,6}_addr field. Replace the use of "struct hostent" everywhere in libexport.a, mountd, and exportfs with "struct addrinfo". This is a large change, but there are so many strong dependencies on struct hostent that this can't easily be broken into smaller pieces. One benefit of this change is that hostent_dup() is no longer required, since the results of getaddrinfo(3) are already dynamically allocated. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Add helpers to manage DNS lookupsChuck Lever2010-06-223-1/+365
| | | | | | | | | | | | | | | Introduce DNS query helpers based on getaddrinfo(3) and getnameinfo(3). These will eventually replace the existing hostent-based functions in support/export/hostname.c. Put some of these new helpers to immediate use, where convenient. As they are part of libexport.a, I've added the forward declarations for these new functions in exportfs.h rather than misc.h, where the hostent-based forward declarations are currently. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* mountd: Convert colons in IPv6 presentation addresses tosemicolonsChuck Lever2010-05-241-3/+39
| | | | | | | | | | | | | | The /var/lib/nfs/rmtab file delineates fields in each of its lines with a ":". The first field contains the IP address of a client, in presentation format. IPv6 presentation format addresses contain colons, which screws up the field delineation of rmtab. Use a simple simple scheme to convert the colons in incoming client names to some other character, and then convert them back when the rmtab file is read. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Refactor rmtab_read()Chuck Lever2010-05-241-23/+41
| | | | | | | | Clean up: Make it easier to add IPv6 support by refactoring part of rmtab_read() into a helper function. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* mountd/exportfs: Make m_addrlist field a nfs_sockaddrChuck Lever2010-05-053-15/+90
| | | | | | | | | | | | | | | | | | | | | | | | To store non-AF_INET addresses in the nfs_client structure, we need to use more than in_addr for the m_addrlist field. Make m_addrlist larger, then add a few helper functions to handle type casting and array indexing cleanly. We could treat the nfs_client address list as if all the addresses in the list were the same family. This might work for MCL_SUBNETWORK type nfs_clients. However, during the transition to IPv6, most hosts will have at least one IPv4 and one IPv6 address. For MCL_FQDN, I think we need to have the ability to store addresses from both families in one nfs_client. Additionally, IPv6 scope IDs are not part of struct sin6_addr. To support link-local IPv6 addresses and the like, a scope ID must be stored. Thus, each slot in the address list needs to be capable of storing an entire socket address, and not simply the network address part. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Clean up client_add()Chuck Lever2010-05-052-15/+12
| | | | | | | | | | | Clean up: client_add()'s current callers never set unknown m_type values, so the m_type check is unnecessary. All of client_add()'s callers are in the same source file where it is defined, so make it a static helper function. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Refactor client_init()Chuck Lever2010-05-051-43/+56
| | | | | | | | | | Clean up: Move subnet hostname parsing logic out of client_init() to make it simpler to introduce IPv6 support. Make client_init() a helper, since it's already static. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* Make capabilities support optionalMike Frysinger2010-04-231-0/+4
| | | | | | | | | | The new code using libcap is quite minor, so rather than always reqiure libcap support, make it a normal --enable type flag. Current default behavior is retained -- if libcap is found, it is enabled, else it is disabled like every nfs-utils version in the past. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Allow malloc(3) failures in client_lookup() and friendsChuck Lever2010-04-231-6/+9
| | | | | | | | | | | | | Clean up: Use malloc(3) instead of xmalloc() in client_lookup() and client_dup(), ensuring that a failed memory allocation here doesn't cause our process to exit suddenly. Allocation of nfs_client records and the m_hostname string are now consistently handled with malloc(3), calloc(3), strdup(3), and free(3). Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Allow m_hostname allocation to fail instead of exitChuck Lever2010-04-231-6/+4
| | | | | | | | | | | | Clean up: Replace xstrdup() with strdup(3) in client_init(), to prevent the process from exiting if the memory allocation fails. Note that both of client_init()'s callers set m_hostname equal to NULL before calling, thus the extra free(3) at the top of client_init() is unneeded. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Allow client_init() to fail instead of exitChuck Lever2010-04-231-7/+17
| | | | | | | | | client_init()'s current callers can now deal correctly with a failure. Get rid of code that can cause our process to exit in client_init(), if address mask parsing or memory allocation fails. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Add client_free()Chuck Lever2010-04-231-2/+8
| | | | | | | Clean up: Introduce a helper to free a nfs_client record. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: export_find() should handle address parsing errorsChuck Lever2010-04-161-0/+4
| | | | | | | | | | | | | | | An address mask parsing error can cause client_init(), and therefore client_dup(), to make our process exit suddenly. Soon we want to add more complex address parsing in client_init(), so we need this interface to be a little more robust. Since export_find() can return NULL in some cases, it can handle NULL returns from its subroutines if an address parsing error occurs, or if memory is exhausted. Allow for client_dup() to return NULL instead of exiting sideways. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Add export_free()Chuck Lever2010-04-161-10/+17
| | | | | | | Clean up: Introduce a helper to free an nfs_export record. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Add helper for populating m_addrlist[]Chuck Lever2010-04-151-18/+20
| | | | | | | | | Clean up: Move common code that populates an nfs_client record's m_addrlist to a helper function. This eliminates a little code duplication, and makes it simpler to add IPv6 support later. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Reduce code duplication in client_init()Chuck Lever2010-04-151-4/+5
| | | | | | | | | Clean up: Most cases in client_init() set clp->m_naddr to zero. Move it to the common part of the function, and simplify the logic. This will make adding IPv6 support here more straightforward. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: replace xlog(L_FATAL) in client_check()Chuck Lever2010-04-081-4/+9
| | | | | | | | | | | Clean up: Prevent the process from exiting in client_check(). Report bad m_type values, but return 0. This removes another site where a mountd or exportfs process can exit sideways. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Refactor wildcard checking in client_check()Chuck Lever2010-04-081-12/+26
| | | | | | | | | | Clean up: refactor wildcard logic out of client_check() to make it easier to introduce IPv6 support. Match the style used for client_check_{fqdn,subnetwork,netgroup}. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Refactor netgroup checking in client_check()Chuck Lever2010-04-081-40/+57
| | | | | | | | | | | | | | | | | | Clean up: refactor netgroup logic out of client_check() to make it easier to introduce IPv6 support. + Use preferred style of keeping #ifdef out of the middle of function definitions. Squelch compiler warnings for "#ifndef HAVE_INNETGR" by using __attribute__((unused)). + Use preferred style of not using curly braces around switch cases. + Match style used for check_{fqdn,subnetwork}. + Clarify comment documenting use of h_aliases Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Remove unused function client_checkaddr()Chuck Lever2010-04-081-7/+0
| | | | | | | Clean up. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Factor SUBNETWORK checking out of check_client()Chuck Lever2010-04-081-10/+22
| | | | | | | | | | | | | | | | | | | | Clean up: Factor the MCL_SUBNETWORK case out of check_client() and client_checkaddr(). This will make it easier to add IPv6 support eventually. The logic in the new helper function will get a little more tangled once IPv6 support is introduced. Each slot in the clp address list eventually may contain an address from either address family. Note that the switch statement in client_checkaddr() is redundant, since clp->cl_mtype is loop invariant. This change makes SUBNETWORK client checking more computationally efficient, at the cost of a few extra lines of code. This commit should not change code behavior in any way. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Factor FQDN checking out of check_client()Chuck Lever2010-04-081-8/+23
| | | | | | | | | | | | | | | | | | | | Clean up: Factor the MCL_FQDN case out of check_client() and client_checkaddr(). This will make it easier to add IPv6 support eventually. The logic in the new helper function will get a little more tangled once IPv6 support is introduced. Each slot in the clp address list eventually may contain an address from either address family. Note that the switch statement in client_checkaddr() is redundant, since clp->cl_mtype is loop invariant. This change makes FQDN client checking more computationally efficient, at the cost of a few extra lines of code. This commit should not change code behavior in any way. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* Remove some warnings that were introduced by commit 6ca440cSteve Dickson2010-04-082-1/+3
| | | | Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: e_fslocdata should be freed with free(3)Chuck Lever2010-03-221-1/+1
| | | | | | | | Clean up: Since e_fslocdata is allocated with strdup(3), and not xstrdup(), it should be freed with free(3), and not xfree(). Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Fix whitespace damage in support/export/export.cChuck Lever2010-03-221-5/+6
| | | | | | | Clean up whitespace damage introduced by commit 4cacc965. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Clean up client_compose() and client_member()Chuck Lever2010-03-222-17/+29
| | | | | | | | Clean up: Replace outdated comments, and fix some function declarations. Use proper type for a couple of automatic variables. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libexport.a: Remove dead codeChuck Lever2010-03-222-24/+0
| | | | | | | | Clean up: I can't find any call sites for client_find() or client_match(). Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* mountd: fix --manage-gids hang due to int/uint bugSteve Dickson2010-03-081-0/+19
| | | | | | | | | | | | | A uid or gid should be represented as unsigned, not signed. The conversion to signed here could cause a hang on access by an unknown user to a server running mountd with --manage-gids; such a user is likely to be mapped to 232-1, which may be converted to 231-1 when represented as an int, resulting in a downcall for uid 231-1, hence the original rpc hanging forever waiting for a cache downcall for 232-1. Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu> Signed-off-by: Steve Dickson <steved@redhat.com>
* Use authunix_create() instead of authsys_create() to fix regression.Steve Dickson2010-03-081-1/+1
| | | | | | | | | | | | | Commit 409b8 introduced a regression when the --disable-tirpc configuration flag is set. The authsys_create() interface, which was introduced, does not exist in the legacy glibc library. Since the authsys_create() interface is a redefined of the authunix_create() interface, which is defined in glibc, using authunix_create() resolves the regression, Acked-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* nfs-utils: add and use nfs_authsys_createJeff Layton2010-03-012-0/+24
| | | | | | | | | | | | | | | | | | The current mount, umount and showmount code uses authunix_create_default to get an auth handle. The one provided by glibc returned a truncated list of groups when there were more than 16 groups. libtirpc however currently does an abort() in this case, which causes the program to crash and dump core. nfs-utils just uses these auth handles for the MNT protocol, so the group list doesn't make a lot of difference here. Add a new function that creates an auth handle with a supplemental gids list that consists only of the primary gid. Have nfs-utils use that function anywhere that it currently uses authunix_create_default. Also, have the caller properly check for a NULL return from that function. Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* nfsd: Disble NFS 4.1 functionality by defaultSteve Dickson2010-02-171-0/+6
| | | | | | | | | | | | Due to the fact the current kernel code do not completely conform to the NFS 4.1 RFC, this patch disable the 4.1 support on the server. To control this 41 functionality, the NFS41_SUPPORTED configuration variable now exist that will allow us to re enable the functionality without any code changes. Signed-off-by: Steve Dickson <steved@redhat.com>
* nfs-utils: don't fdatasync the rmtabBen Myers2010-02-122-8/+20
| | | | | | | If we're using the new caching interface the rmtab will be ignored by exportfs so there is no need to fdatasync. This improves mountd performance. Signed-off-by: Steve Dickson <steved@redhat.com>
* nfs-utils: remove xflock timeoutBen Myers2010-02-121-17/+1
| | | | | | | Remove this 10 second timeout which can cause unexpected behavior and corruption in the rmtab when hit. Signed-off-by: Steve Dickson <steved@redhat.com>
* Teach nfs_compare_sockaddr() to handle NULL arguments.Steve Dickson2010-01-251-0/+4
| | | | | Reviewed-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* tcpwrapper: Add support for IPv6Chuck Lever2010-01-172-37/+81
| | | | | | | | | | Assuming the tcp_wrappers library can actually support IPv6 addresses, here's a crack at IPv6 support in nfs-utils' TCP wrapper shim. Some reorganization is done to limit the number of times that @sap is converted to a presentation address string. Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
* tcpwrapper: Eliminated shadowed declaration warningsChuck Lever2010-01-172-19/+16
| | | | | | | | | | | | | | | | | | | | | | Clean up: the use of identifiers called "access" and "daemon" shadow function declarations in unistd.h. Seen with "-Wextra -pedantic". tcpwrapper.c: In function haccess_add: tcpwrapper.c:112: warning: declaration of access shadows a global declaration /usr/include/unistd.h:288: warning: shadowed declaration is here tcpwrapper.c: In function good_client: tcpwrapper.c:161: warning: declaration of daemon shadows a global declaration /usr/include/unistd.h:953: warning: shadowed declaration is here tcpwrapper.c: In function check_default: tcpwrapper.c:212: warning: declaration of daemon shadows a global declaration /usr/include/unistd.h:953: warning: shadowed declaration is here good_client() is used only in support/misc/tcpwrapper.c, so make it static (and update its prototype to c99 standard form). Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* tcpwrapper: Fix signage problems in the tcp_wrappers hash functionChuck Lever2010-01-171-14/+20
| | | | | | | | | | | | | | | | | | | | Eliminate the following compiler warnings: tcpwrapper.c:78: warning: no previous prototype for strtoint tcpwrapper.c: In function strtoint tcpwrapper.c:81: warning: conversion to int size_t may change the sign of the result tcpwrapper.c:85: warning: conversion to unsigned int from int may change the sign of the result tcpwrapper.c: In function hashint: tcpwrapper.c:91: warning: conversion to int from unsigned int may change the sign of the result The hash value is probably computed consistently even with unexpected sign inversions. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* tcp_wrapper: Clean up logit()Chuck Lever2010-01-172-39/+25
| | | | | | | | | | | | | | | | | | | | | | | | | Eliminate these compiler warnings: tcpwrapper.c: In function logit tcpwrapper.c:225: warning: unused parameter procnum tcpwrapper.c:225: warning: unused parameter prognum Actually, @procnum is not used anywhere in our tcpwrapper.c, so let's just get rid of it. Since there is only one logit() call site in tcpwrapper.c, the macro wrapper just adds needless clutter. Let's get rid of that too. Finally, both mountd and statd now use xlog(), which adds an appropriate program name prefix to every message. Replace the open-coded syslog(2) call with an xlog() call in order to consistently identify the RPC service reporting the intrusion. Since logit() no longer references "deny_severity" and no nfs-utils caller sets either allow_severity or deny_severity, we remove them. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* tcp_wrappers: Use getifaddrs(3) if it is availableChuck Lever2010-01-173-9/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After glibc 2.3.3, getifaddrs(3) can return AF_INET6 addresses for local network interfaces. Using the library call is easier than trying to update the open code in from_local(), and means we have less to maintain in nfs-utils going forward. And, since from_local() can now support IPv6, change its synopsis to take a "struct sockaddr *" . Note that the original code discovers local addresses once. These days, with wifi, DHCP, and NetworkManager, the local network configuration can change dynamically over time. So, call getifaddrs() more often to ensure from_local() has up-to-date network configuration information. This implementation refreshes the list if from_local() has not been called in the last second. This is actually not terribly honerous. check_default() invokes from_local() only when the remote host is not in its access cache, or the access/deny files have changed. So new hosts will cause a refresh, but previously seen hosts (including localhost) should not. On the other hand, it still may not be often enough. After the first call, if only previously seen hosts attempt to access our daemons, from_local() would never be called, and the local list would never be updated. This might be possible during steady-state operation with a small number of servers and clients. It would also be nice if we could free the local interface address list at shutdown time, but that would be a lot of trouble for little gain. Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
* tcpwrappers: Use xlog() instead of perror(3) and syslog(2)Chuck Lever2010-01-171-12/+13
| | | | | | | | | | | | Clean up: Replace calls to syslog(2) and perror(3) in from_local.c with calls to xlog(). The problems displayed by the perror(3) calls especially should be reported. Currently they are never seen in the system log. As part of a build test, I defined TEST, and found a couple of problems with main(), which are also addressed in this patch. Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
* Tone down a number xlog messages in svc_create_bindaddr()Steve Dickson2010-01-151-11/+5
| | | | Signed-off-by: Steve Dickson <steved@redhat.com>
* statd: Support TI-RPC statd listenerChuck Lever2010-01-153-2/+260
| | | | | | | | | | | | | | | | | | | | If TI-RPC is available, use it to create statd's svc listener. If not, use the old function, rpc_init(), to create statd's listener. IPv6 can be supported if TI-RPC is available. In this case, /etc/netconfig is searched to determine which transports to advertise. Add the new listener creation API in libnfs.a since other components of nfs-utils (such as rpc.mountd) will eventually want to share it. A little re-arrangement of when the statd listener is created is done to make unregistration of the statd service more reliable. As it is now, the statd service is never unregistered when it exits. After it is gone, other programs usually hang when trying to access statd or see if it's running, since the registration is still there but statd itself does not respond. Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
* libnsm.a: retain CAP_NET_BIND when dropping privilegesChuck Lever2010-01-151-1/+40
| | | | | | | | | | | | | | | | | I'm about to switch the order of listener creation and dropping root privileges. rpc.statd will drop privileges first, then create its listeners. The reason for the new ordering is explained in a subsequent patch. However, for non-TI-RPC builds, rpc_init() needs to use a privileged port to do pmap registrations. For both TI-RPC and non-TI-RPC builds, CAP_NET_BIND is required in case the admin requests a privileged listener port on the statd command line. So that these requirements are met, nsm_drop_privileges() will now retain CAP_NET_BIND while dropping root. Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
* libnsm.a: Add support for multiple lines in monitor record filesChuck Lever2010-01-152-12/+155
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To support IPv6, statd must support multi-homed remote peers. For our purposes, "multi-homed peer" means that more than one unique IP address maps to the one canonical host name for that peer. An SM_MON request from the local lockd has a "mon_name" argument that statd reverse maps to a canonical hostname (ie the A record for that host). statd assumes the canonical hostname is unique enough that it stores the callback data for this mon_name in a file named after that canonical hostname. Because lockd can't distinguish between two unique IP addresses that may be from the same physical host, the kernel can hand statd a mon_name that maps to the same canonical hostname as some previous mon_name. So that the kernel can keep this instance of the mon_name unique, it creates a fresh priv cookie for each new address. Note that a mon_name can be a presentation address string, or the caller_name string sent in each NLMPROC_LOCK request. There's nothing that requires the caller_name to be a fully-qualified hostname, thus it's uniqueness is not guaranteed. The current design of statd assumes that canonical hostnames will be unique enough. When a mon_name for a fresh SM_MON request maps to the same canonical hostname as an existing monitored peer, but the priv cookie is new, statd will try to write the information for the fresh request into an existing monitor record file, wiping out the contents of the file. This is because the mon_name/cookie combination won't match any record statd already has. Currently, statd doesn't check if a record file already exists before writing into it. statd's logic assumes that the svc routine has already checked that no matching record exists in the in-core monitor list. And, it doesn't use O_EXCL when opening the record file. Not only is the old data in that file wiped out, but statd's in-core monitor list will no longer match what's in the on-disk monitor list. Note that IPv6 isn't needed to exercise multi-homed peer support. Any IPv4 peer that has multiple addresses that map to its canonical hostname will trigger this behavior. However, this scenario will become quite common when all hosts on a network automatically get both an IPv4 address and an IPv6 address. I can think of a few ways to address this: 1. Replace the current on-disk format with a database that has a uniqueness constraint on the monitor records 2. Create a new file naming scheme; eg. one that uses a truly unique name such as a hash generated from the mon_name, my_name, and priv cookie 3. Support multiple lines in each monitor record file Since statd's on-disk format constitutes a formal API, options 1 and 2 are right out. This patch implements option 3. There are two parts: adding a new line to an existing file; and deleting a line from a file with more than one line. Interestingly, the existing code already supports reading more than one line from these files, so we don't need to add extra code here to do that. One file may contain a line for every unique mon_name / priv cookie where the mon_name reverse maps to the same canonical hostname. We use the atomic write facility added by a previous patch to ensure the on-disk monitor record list is updated atomically. Signed-off-by: Chuck Lever <chuck.lever@oracle.com>