summaryrefslogtreecommitdiff
path: root/src/rpcb_clnt.c
Commit message (Collapse)AuthorAgeFilesLines
* portmapper: allow TCP-only portmapperHEADlibtirpc-1-3-4-rc1masterDan Hork2023-04-211-6/+3
| | | | | | | | | | | | | | | Code that works in GLIBC's runrpc implementation fails with libtirpc. libtirpc forces the RPC library to talk to the portmapper via UDP, even when the client specifies TCP. This breaks existing code which expect the protocol specified to be honored, even when talking to portmapper. This is upstreaming of an old patch by Rob Riggs reported in Fedora. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1725329 Signed-off-by: Rob Riggs <rob+redhat@pangalactic.org> Signed-off-by: Dan Hork <dan@danny.cz> Signed-off-by: Steve Dickson <steved@redhat.com>
* Removed a warning:Steve Dickson2022-08-021-1/+2
| | | | | | | rpcb_clnt.c:224:21: error: argument 'netid' doesn't match prototype const char *host, *netid; Signed-off-by: Steve Dickson <steved@redhat.com>
* SUNRPC: MT-safe overhaul of address cache management in rpcb_clnt.clibtirpc-1-3-3-rc5Attila Kovacs2022-08-011-63/+129
| | | | | | | | | | | | | | | | | | | | | | | rpcb_clnt.c was using a read/write lock mechanism to manage the address cache. This was wrong, because the wrote locked deletion of a cached entry did not prevent concurrent access by other calls that required a read lock (e.g. by check_cache()). Thus, the cache could get corrupted. Instead of a RW locking mechanist, the cache (a linkedf list) need a simple mutex to grant access. To avoid deadlocks while accessing a cache from functions that may recurse, the mutexed part of the cache access should be isolated more to only the code areas necessary. Also, cache lookup should return an independent deep copy of the matching cached element, rather than a pointer to the element in the cache, for operations that can (and should be) performed outside of the mutexed areas for cache access. With the changes, the code is more MT-dafe, more robust, and also simpler to follow. Signed-off-by: Steve Dickson <steved@redhat.com>
* rpcb_clnt.c add mechanism to try v2 protocol firstlibtirpc-1-3-3-rc3Roberto Bergantinos Corpas2022-07-161-4/+26
| | | | | | | | | | | | | | | | | | | | There have been previous attempts to revert protocol tryout algorithm from v4,v3,v2 to previous v2,v4,v3 : https://www.spinics.net/lists/linux-nfs/msg89228.html Apart from GETADDR/NAT issue originating that proposed change, its possible that some legacy custom applications still use v2 of protocol with libtirpc. The change proposed here, introduces an environment variable "RPCB_V2FIRST" so that, if defined, old behaviour is used. This is more flexible and allow us to selectively pick what application reverts to old behaviour instead of a system-wide change. Signed-off-by: Roberto Bergantinos Corpas <rbergant@redhat.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* Fix potential memory leak of parms.r_addrAli Abdallah2022-07-161-0/+8
| | | | | | | | | | | | | | | During some valgrind test, the following is observed ==11391== 64 bytes in 4 blocks are definitely lost in loss record 11 of 16 ==11391== at 0x4C2A2AF: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==11391== by 0x50ECED9: strdup (in /lib64/libc-2.22.so) ==11391== by 0x4E4AFBF: getclnthandle (in /lib64/libtirpc.so.3.0.0) ==11391== by 0x4E4BD8A: __rpcb_findaddr_timed (in /lib64/libtirpc.so.3.0.0) ==11391== by 0x4E443AF: clnt_tp_create_timed (in /lib64/libtirpc.so.3.0.0) ==11391== by 0x4E44580: clnt_create_timed (in /lib64/libtirpc.so.3.0.0) ==11391== by 0x400755: main (in /local/02/xdtadti/tirpc-test/client) Signed-off-by: Steve Dickson <steved@redhat.com>
* rpcb_clnt.c: resource_leakSteve Dickson2018-09-111-0/+1
| | | | | | Variable "nc_handle" going out of scope leaks the storage it points to. Signed-off-by: Steve Dickson <steved@redhat.com>
* rpcb_clnt.c: pass the version argument to __try_protocol_version_2Thomas Blume2018-07-181-1/+1
| | | | | | | | Fixes: 5e7b57bc20bd ("rpcinfo: change order of version to be tried to 4, 3, 2") Reviewed-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Thomas Blume <Thomas.Blume@suse.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* Handle GARBAGE_ARGS response in rpcbind queryChuck Lever2018-07-101-4/+9
| | | | | | | | | | | | | | | | | | | We have a report that some commercial NFS file servers still do not support rpcbind v4 correctly. They return GARBAGE_ARGS instead of PROG_MISMATCH or PROG_UNAVAIL, so our rpcbind client now errors out immediately instead of trying a lower rpcbind version. To address this, convert the "if () else if () else if ()" to a switch statement to make it straightforward to add new status codes to the error processing logic. Then, add a case for RPC_CANTDECODEARGS (the API status code used when the remote responds with GARBAGE_ARGS). Reported-by: Yuan-Yao Sung <yysung@cs.nctu.edu.tw> Fixes: 5e7b57bc20bd ("rpcinfo: change order of version to be ... ") Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Tested-by: Yuan-Yao Sung <yysung@cs.nctu.edu.tw> Signed-off-by: Steve Dickson <steved@redhat.com>
* Fix regression introduced by change rpc version order patchlibtirpc-1-0-4-rc1Thomas Blume2018-04-181-4/+14
| | | | | | | | | | | Fix a socket leak introduced by commit 5e7b57bc20bd9cadff (rpcinfo: change order of version to be tried to 4, 3, 2) The new function __try_protocol_version_2 doesn't return the client, so it can't be closed via CLNT_DESTROY in the calling function. Signed-off-by: Thomas Blume <Thomas.Blume@suse.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* rpcinfo: change order of version to be tried to 4, 3, 2libtirpc-1-0-3-rc3Thomas Blume2018-03-141-68/+80
| | | | | | | | | | | | | | | | | | | | | | When specifying TCP as transport on rpcinfo getport command (-T tcp), the initial RPC getport packet is still sent as a UDP packet. This is due to rpc protocol version 2 is tried first and function getpmaphandle() states: /* * Try UDP only - there are some portmappers out * there that use UDP only. */ Even on systems with newer rpc versions, this will hang when the UDP port is blocked. That is a quite artifical limitation, because UDP only portmappert should be really rare by now. The attached code changes the order of versions to be tried to 4, then 3 and use version 2 only as fallback. Reviewed-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Thomas Blume <Thomas.Blume@suse.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libtirpc: missing NULL pointer checksThorsten Kukuk2015-04-231-5/+21
| | | | | | | This patch fixes various unexpected segfaults caused by invoking rpcb_* functions with NULL arguments. Signed-off-by: Steve Dickson <steved@redhat.com>
* Introduce new helper function getpmaphandleOlaf Kirch2014-12-161-19/+43
| | | | | | | | This moves some code for creation of PMAP handles out of the getaddr code and into a function of its own. Signed-off-by: Olaf Kirch <okir@suse.de> Signed-off-by: Steve Dickson <steved@redhat.com>
* rpcb_clnt: Convert fprintf calls to LIBTIRPC_DEBUG() callsSteve Dickson2014-08-071-44/+21
| | | | Signed-off-by: Steve Dickson <steved@redhat.com>
* Clean up src/rpcb_clnt.cChuck Lever2013-12-091-1/+2
| | | | | | | Remove some unused code. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* Relicense these SISSL files to 3 clause BSDTom \'spot\' Callaway2010-08-301-20/+2
| | | | | | | This is a patch which takes out the SISSL license entries and replaces them with 3-clause BSD, as specified by Oracle America, Inc. Signed-off-by: Steve Dickson <steved@redhat.com>
* Add back SISSL license attribution.libtirpc-0-2-2-rc3Tom "spot" Callaway2010-07-161-0/+13
| | | | Signed-off-by: Steve Dickson <steved@redhat.com>
* Fix memory leak in rpcb_clnt.c:add_cache()Chuck Lever2010-03-251-6/+12
| | | | | | | | | Ensure memory is freed if an error occurs. Memory allocation errors are rare, so probably not a big deal. But worth tidying. Reported-by: Jens-Uwe Mozdzen <jmozdzen@nde.ag> Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* Fix memory leak in getclnthandle()Chuck Lever2010-03-251-3/+11
| | | | | | | | | | | getclnthandle() can return a NULL RPC client, but sometimes it does this without ensuring that *targaddr is freed. Even though the documenting comment claims that callers must free *targaddr, callers don't check the value of *targaddr if getclnthandle() returns NULL. Reported-by: Jens-Uwe Mozdzen <jmozdzen@nde.ag> Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* rpcb_getaddr: Handle only "udp" and "tcp" netids when using PMAP_GETPORTChuck Lever2009-11-301-2/+3
| | | | | | | | | | The PORTMAP logic in __rpcb_findaddr_timed() already prevents its use if the protocol family is not PF_INET. In addition, ensure that the rpcbind v2 logic in __rpcb_findaddr_timed() is executed only if the requested transport protocol name is "tcp" or "udp". Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* rpcb_getaddr: Always do PMAP_GETPORT first for NC_INET transportsChuck Lever2009-11-301-80/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For PF_INET transports, use PMAP_GETPORT. This is what network captures show that Solaris user space does, what the Linux mount.nfs command does, and what the Linux kernel rpcbind client does. It's more efficient when querying legacy hosts, of which there are still many. An additional benefit of this change is that since libtirpc uses only UDP for PMAP_GETPORT requests, and it now tries PMAP_GETPORT first, the creation of a TCP socket in a very common case is now avoided. This reduces the consumption of ephemeral ports that can be left in TIME_WAIT after a request. It appears that the order in which __rpcb_findaddr_timed() tries the rpcbind protocol versions was changed in the FreeBSD port of libtirpc. The documenting comment that appears before __rpcb_findaddr_timed() was never updated. This patch restores the original behavior, which is "try v2 first if the remote is a PF_INET; then try v4, then v3." The FreeBSD change introduced two bugs: one serious, the other harmless but wasteful. The PORTMAP logic overwrites the pointer in "client" instead of invoking CLNT_DESTROY(). Since the portmap code was originally executed first, it had no need to invoke CLNT_DESTROY(). This orphans the RPC client previously created for the v3/v4 query. If a connection-oriented socket was used during the v3/v4 query, this socket is left connected to the remote portmapper, resulting in an inadvertant denial of service attack on the remote. For short-lived programs, this bug is hidden, because a program exit causes all sockets to be closed automatically. Long-running programs leave these sockets connected indefinitely. The harmless bug is that even though a portmapper replies to a v4 RPCB_GETADDR request with "version 4 not supported; use only version 2", libtirpc tries again with a v3 RPCB_GETADDR anyway. Though harmless, this is obviously a wasted round trip. Perform these requests in the original order (v2, then v4, then v3), then the original code makes sense, and the extra v3 round trip is avoided. Reverting the FreeBSD change fixes both problems. Reported-by: Jens-Uwe Mozdzen <jmozdzen@nde.ag>. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* rpcb_clnt: RPC_PROGNOTREGISTERED is a permanent errorlibtirpc-0-2-1-rc2Chuck Lever2009-06-291-1/+1
| | | | | | | | | | | rpcbind returns RPC_PROGNOTREGISTERED if it knows for certain that an RPC program is not supported for a given transport. This is a permanent and authoritative error, so the library's rpcbind query API should never retry the query -- it will only get the same answer. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* Replace the Sun RPC license with the BSD license, with the explicitTom "spot" Callaway2009-05-281-41/+23
| | | | | | | permission of Sun Microsystems Signed-off-by: Tom "spot" Callaway <tcallawa@redhat.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* Added the RPCB_OWNER_STRING define which is definedJeff Layton2009-05-281-3/+6
| | | | | | | as the "libtirpc" constant string Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* libtirpc: set r_netid and r_owner in __rpcb_findaddr_timedJeff Layton2009-03-131-0/+7
| | | | | | | | | | | | | | | These fields in the rpcbind GETADDR call are being passed uninitialized to CLNT_CALL. In the case of x86_64 at least, this usually leads to a segfault. On x86, it sometimes causes segfaults and other times causes garbage to be sent on the wire. rpcbind generally ignores the r_owner field for calls that come in over the wire, so it really doesn't matter what we send in that slot. We just need to send something. The reference implementation from Sun seems to send a blank string. Have ours follow suit. Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve Dickson <steved@redhat.com>
* - Fixed version-info in src/Makefile.am to reflect the correct versionSteve Dickson2008-09-161-1/+6
| | | | | | | | | - Fixed some of warnings in: src/auth_time.c, src/clnt_dg.c and src/clnt_raw.c - Added some #ifdef NOTUSED around some code in src/rpbc_clnt.c that was not being used... Signed-off-by: Steve Dickson <steved@redhat.com>
* Initial commit of libtirpc 0.1.7Steve Dickson2007-04-201-0/+1237
Signed-off-by: Steve Dickson <steved@redhat.com>