Blame sunrpc/pm_getmaps.c

Packit Service 82fcde
/*
Packit Service 82fcde
 * pmap_getmap.c
Packit Service 82fcde
 * Client interface to pmap rpc service.
Packit Service 82fcde
 * contains pmap_getmaps, which is only tcp service involved
Packit Service 82fcde
 *
Packit Service 82fcde
 * Copyright (c) 2010, Oracle America, Inc.
Packit Service 82fcde
 *
Packit Service 82fcde
 * Redistribution and use in source and binary forms, with or without
Packit Service 82fcde
 * modification, are permitted provided that the following conditions are
Packit Service 82fcde
 * met:
Packit Service 82fcde
 *
Packit Service 82fcde
 *     * Redistributions of source code must retain the above copyright
Packit Service 82fcde
 *       notice, this list of conditions and the following disclaimer.
Packit Service 82fcde
 *     * Redistributions in binary form must reproduce the above
Packit Service 82fcde
 *       copyright notice, this list of conditions and the following
Packit Service 82fcde
 *       disclaimer in the documentation and/or other materials
Packit Service 82fcde
 *       provided with the distribution.
Packit Service 82fcde
 *     * Neither the name of the "Oracle America, Inc." nor the names of its
Packit Service 82fcde
 *       contributors may be used to endorse or promote products derived
Packit Service 82fcde
 *       from this software without specific prior written permission.
Packit Service 82fcde
 *
Packit Service 82fcde
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit Service 82fcde
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit Service 82fcde
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
Packit Service 82fcde
 *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
Packit Service 82fcde
 *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
Packit Service 82fcde
 *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit Service 82fcde
 *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
Packit Service 82fcde
 *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit Service 82fcde
 *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Packit Service 82fcde
 *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Packit Service 82fcde
 *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit Service 82fcde
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service 82fcde
 */
Packit Service 82fcde
Packit Service 82fcde
#include <rpc/rpc.h>
Packit Service 82fcde
#include <rpc/pmap_prot.h>
Packit Service 82fcde
#include <rpc/pmap_clnt.h>
Packit Service 82fcde
#include <sys/socket.h>
Packit Service 82fcde
#include <netdb.h>
Packit Service 82fcde
#include <stdbool.h>
Packit Service 82fcde
#include <stdio.h>
Packit Service 82fcde
#include <errno.h>
Packit Service 82fcde
#include <libintl.h>
Packit Service 82fcde
#include <unistd.h>
Packit Service 82fcde
#include <not-cancel.h>
Packit Service 82fcde
#include <shlib-compat.h>
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/*
Packit Service 82fcde
 * Get a copy of the current port maps.
Packit Service 82fcde
 * Calls the pmap service remotely to do get the maps.
Packit Service 82fcde
 */
Packit Service 82fcde
struct pmaplist *
Packit Service 82fcde
pmap_getmaps (struct sockaddr_in *address)
Packit Service 82fcde
{
Packit Service 82fcde
  struct pmaplist *head = (struct pmaplist *) NULL;
Packit Service 82fcde
  struct timeval minutetimeout;
Packit Service 82fcde
  CLIENT *client;
Packit Service 82fcde
  bool closeit = false;
Packit Service 82fcde
Packit Service 82fcde
  minutetimeout.tv_sec = 60;
Packit Service 82fcde
  minutetimeout.tv_usec = 0;
Packit Service 82fcde
  address->sin_port = htons (PMAPPORT);
Packit Service 82fcde
Packit Service 82fcde
  /* Don't need a reserved port to get ports from the portmapper.  */
Packit Service 82fcde
  int socket = __get_socket (address);
Packit Service 82fcde
  if (socket != -1)
Packit Service 82fcde
    closeit = true;
Packit Service 82fcde
Packit Service 82fcde
  client = clnttcp_create (address, PMAPPROG, PMAPVERS, &socket, 50, 500);
Packit Service 82fcde
  if (client != (CLIENT *) NULL)
Packit Service 82fcde
    {
Packit Service 82fcde
      if (CLNT_CALL (client, PMAPPROC_DUMP, (xdrproc_t)xdr_void, NULL,
Packit Service 82fcde
		     (xdrproc_t)xdr_pmaplist, (caddr_t)&head,
Packit Service 82fcde
		     minutetimeout) != RPC_SUCCESS)
Packit Service 82fcde
	{
Packit Service 82fcde
	  clnt_perror (client, _("pmap_getmaps.c: rpc problem"));
Packit Service 82fcde
	}
Packit Service 82fcde
      CLNT_DESTROY (client);
Packit Service 82fcde
    }
Packit Service 82fcde
  /* We only need to close the socket here if we opened  it.  */
Packit Service 82fcde
  if (closeit)
Packit Service 82fcde
    __close_nocancel (socket);
Packit Service 82fcde
  address->sin_port = 0;
Packit Service 82fcde
  return head;
Packit Service 82fcde
}
Packit Service 82fcde
libc_hidden_nolink_sunrpc (pmap_getmaps, GLIBC_2_0)