Home | History | Annotate | Line # | Download | only in rpc
pmap_clnt.c revision 1.18.62.1
      1  1.18.62.1       tls /*	$NetBSD: pmap_clnt.c,v 1.18.62.1 2013/06/23 06:21:05 tls Exp $	*/
      2        1.2       cgd 
      3        1.1       cgd /*
      4  1.18.62.1       tls  * Copyright (c) 2010, Oracle America, Inc.
      5  1.18.62.1       tls  *
      6  1.18.62.1       tls  * Redistribution and use in source and binary forms, with or without
      7  1.18.62.1       tls  * modification, are permitted provided that the following conditions are
      8  1.18.62.1       tls  * met:
      9  1.18.62.1       tls  *
     10  1.18.62.1       tls  *     * Redistributions of source code must retain the above copyright
     11  1.18.62.1       tls  *       notice, this list of conditions and the following disclaimer.
     12  1.18.62.1       tls  *     * Redistributions in binary form must reproduce the above
     13  1.18.62.1       tls  *       copyright notice, this list of conditions and the following
     14  1.18.62.1       tls  *       disclaimer in the documentation and/or other materials
     15  1.18.62.1       tls  *       provided with the distribution.
     16  1.18.62.1       tls  *     * Neither the name of the "Oracle America, Inc." nor the names of its
     17  1.18.62.1       tls  *       contributors may be used to endorse or promote products derived
     18  1.18.62.1       tls  *       from this software without specific prior written permission.
     19  1.18.62.1       tls  *
     20  1.18.62.1       tls  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     21  1.18.62.1       tls  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     22  1.18.62.1       tls  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     23  1.18.62.1       tls  *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     24  1.18.62.1       tls  *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     25  1.18.62.1       tls  *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.18.62.1       tls  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     27  1.18.62.1       tls  *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  1.18.62.1       tls  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29  1.18.62.1       tls  *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     30  1.18.62.1       tls  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     31  1.18.62.1       tls  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32        1.1       cgd  */
     33        1.1       cgd 
     34        1.4  christos #include <sys/cdefs.h>
     35        1.1       cgd #if defined(LIBC_SCCS) && !defined(lint)
     36        1.4  christos #if 0
     37        1.4  christos static char *sccsid = "@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";
     38        1.4  christos static char *sccsid = "@(#)pmap_clnt.c	2.2 88/08/01 4.0 RPCSRC";
     39        1.4  christos #else
     40  1.18.62.1       tls __RCSID("$NetBSD: pmap_clnt.c,v 1.18.62.1 2013/06/23 06:21:05 tls Exp $");
     41        1.4  christos #endif
     42        1.1       cgd #endif
     43        1.1       cgd 
     44        1.1       cgd /*
     45        1.1       cgd  * pmap_clnt.c
     46        1.1       cgd  * Client interface to pmap rpc service.
     47        1.1       cgd  *
     48        1.1       cgd  * Copyright (C) 1984, Sun Microsystems, Inc.
     49        1.1       cgd  */
     50        1.1       cgd 
     51        1.5       jtc #include "namespace.h"
     52        1.8     lukem 
     53        1.8     lukem #include <unistd.h>
     54        1.8     lukem 
     55        1.1       cgd #include <rpc/rpc.h>
     56        1.1       cgd #include <rpc/pmap_prot.h>
     57        1.1       cgd #include <rpc/pmap_clnt.h>
     58       1.16  christos #include <rpc/nettype.h>
     59        1.5       jtc 
     60       1.15      fvdl #include <stdio.h>
     61       1.15      fvdl #include <stdlib.h>
     62       1.15      fvdl 
     63       1.17      fvdl #include "rpc_internal.h"
     64       1.15      fvdl 
     65        1.5       jtc #ifdef __weak_alias
     66       1.14   mycroft __weak_alias(pmap_set,_pmap_set)
     67       1.14   mycroft __weak_alias(pmap_unset,_pmap_unset)
     68        1.5       jtc #endif
     69        1.1       cgd 
     70        1.1       cgd bool_t
     71       1.15      fvdl pmap_set(u_long program, u_long version, int protocol, int port)
     72        1.1       cgd {
     73        1.1       cgd 	bool_t rslt;
     74       1.15      fvdl 	struct netbuf *na;
     75       1.15      fvdl 	struct netconfig *nconf;
     76       1.15      fvdl 	char buf[32];
     77        1.1       cgd 
     78       1.15      fvdl 	if ((protocol != IPPROTO_UDP) && (protocol != IPPROTO_TCP)) {
     79        1.3        pk 		return (FALSE);
     80       1.15      fvdl 	}
     81       1.15      fvdl 	nconf = __rpc_getconfip(protocol == IPPROTO_UDP ? "udp" : "tcp");
     82       1.15      fvdl 	if (nconf == NULL) {
     83       1.15      fvdl 		return (FALSE);
     84       1.15      fvdl 	}
     85       1.16  christos 	snprintf(buf, sizeof buf, "0.0.0.0.%d.%d",
     86       1.16  christos 	    (((u_int32_t)port) >> 8) & 0xff, port & 0xff);
     87       1.15      fvdl 	na = uaddr2taddr(nconf, buf);
     88       1.15      fvdl 	if (na == NULL) {
     89       1.15      fvdl 		freenetconfigent(nconf);
     90        1.1       cgd 		return (FALSE);
     91        1.1       cgd 	}
     92       1.16  christos 	rslt = rpcb_set((rpcprog_t)program, (rpcvers_t)version, nconf, na);
     93       1.15      fvdl 	free(na);
     94       1.15      fvdl 	freenetconfigent(nconf);
     95        1.1       cgd 	return (rslt);
     96        1.1       cgd }
     97        1.1       cgd 
     98        1.1       cgd /*
     99       1.15      fvdl  * Remove the mapping between program, version and port.
    100        1.1       cgd  * Calls the pmap service remotely to do the un-mapping.
    101        1.1       cgd  */
    102        1.1       cgd bool_t
    103       1.15      fvdl pmap_unset(u_long program, u_long version)
    104        1.1       cgd {
    105       1.15      fvdl 	struct netconfig *nconf;
    106       1.15      fvdl 	bool_t udp_rslt = FALSE;
    107       1.15      fvdl 	bool_t tcp_rslt = FALSE;
    108       1.15      fvdl 
    109       1.15      fvdl 	nconf = __rpc_getconfip("udp");
    110       1.15      fvdl 	if (nconf != NULL) {
    111       1.16  christos 		udp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version,
    112       1.16  christos 		    nconf);
    113       1.15      fvdl 		freenetconfigent(nconf);
    114       1.15      fvdl 	}
    115       1.15      fvdl 	nconf = __rpc_getconfip("tcp");
    116       1.15      fvdl 	if (nconf != NULL) {
    117       1.16  christos 		tcp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version,
    118       1.16  christos 		    nconf);
    119       1.15      fvdl 		freenetconfigent(nconf);
    120       1.15      fvdl 	}
    121       1.15      fvdl 	/*
    122       1.15      fvdl 	 * XXX: The call may still succeed even if only one of the
    123       1.15      fvdl 	 * calls succeeded.  This was the best that could be
    124       1.15      fvdl 	 * done for backward compatibility.
    125       1.15      fvdl 	 */
    126       1.15      fvdl 	return (tcp_rslt || udp_rslt);
    127        1.1       cgd }
    128