17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 53582b7c1Sgt29601 * Common Development and Distribution License (the "License"). 63582b7c1Sgt29601 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 223582b7c1Sgt29601 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 25*8f6d9daeSMarcel Telka /* 26*8f6d9daeSMarcel Telka * Copyright 2013 Nexenta Systems, Inc. All rights reserved. 27*8f6d9daeSMarcel Telka */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * rpcb_svc_4.c 317c478bd9Sstevel@tonic-gate * The server procedure for the version 4 rpcbind. 327c478bd9Sstevel@tonic-gate * 337c478bd9Sstevel@tonic-gate */ 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include <stdio.h> 367c478bd9Sstevel@tonic-gate #include <sys/types.h> 377c478bd9Sstevel@tonic-gate #include <sys/stat.h> 387c478bd9Sstevel@tonic-gate #include <unistd.h> 397c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 407c478bd9Sstevel@tonic-gate #include <netconfig.h> 417c478bd9Sstevel@tonic-gate #include <syslog.h> 427c478bd9Sstevel@tonic-gate #include <netdir.h> 437c478bd9Sstevel@tonic-gate #include <string.h> 447c478bd9Sstevel@tonic-gate #include <stdlib.h> 457c478bd9Sstevel@tonic-gate #include "rpcbind.h" 467c478bd9Sstevel@tonic-gate 47*8f6d9daeSMarcel Telka static void free_rpcb_entry_list(rpcb_entry_list_ptr); 48*8f6d9daeSMarcel Telka static bool_t xdr_rpcb_entry_list_ptr_wrap(XDR *, rpcb_entry_list_ptr *); 49*8f6d9daeSMarcel Telka static bool_t rpcbproc_getaddrlist(rpcb *, rpcb_entry_list_ptr *, 50*8f6d9daeSMarcel Telka struct svc_req *); 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* 537c478bd9Sstevel@tonic-gate * Called by svc_getreqset. There is a separate server handle for 547c478bd9Sstevel@tonic-gate * every transport that it waits on. 557c478bd9Sstevel@tonic-gate */ 567c478bd9Sstevel@tonic-gate void 57*8f6d9daeSMarcel Telka rpcb_service_4(struct svc_req *rqstp, SVCXPRT *transp) 587c478bd9Sstevel@tonic-gate { 597c478bd9Sstevel@tonic-gate union { 607c478bd9Sstevel@tonic-gate rpcb rpcbproc_set_4_arg; 617c478bd9Sstevel@tonic-gate rpcb rpcbproc_unset_4_arg; 627c478bd9Sstevel@tonic-gate rpcb rpcbproc_getaddr_4_arg; 637c478bd9Sstevel@tonic-gate char *rpcbproc_uaddr2taddr_4_arg; 647c478bd9Sstevel@tonic-gate struct netbuf rpcbproc_taddr2uaddr_4_arg; 65*8f6d9daeSMarcel Telka rpcb rpcbproc_getversaddr_4_arg; 66*8f6d9daeSMarcel Telka rpcb rpcbproc_getaddrlist_4_arg; 677c478bd9Sstevel@tonic-gate } argument; 68*8f6d9daeSMarcel Telka union { 69*8f6d9daeSMarcel Telka bool_t rpcbproc_set_4_res; 70*8f6d9daeSMarcel Telka bool_t rpcbproc_unset_4_res; 71*8f6d9daeSMarcel Telka char *rpcbproc_getaddr_4_res; 72*8f6d9daeSMarcel Telka rpcblist_ptr *rpcbproc_dump_4_res; 73*8f6d9daeSMarcel Telka ulong_t rpcbproc_gettime_4_res; 74*8f6d9daeSMarcel Telka struct netbuf rpcbproc_uaddr2taddr_4_res; 75*8f6d9daeSMarcel Telka char *rpcbproc_taddr2uaddr_4_res; 76*8f6d9daeSMarcel Telka char *rpcbproc_getversaddr_4_res; 77*8f6d9daeSMarcel Telka rpcb_entry_list_ptr rpcbproc_getaddrlist_4_res; 78*8f6d9daeSMarcel Telka rpcb_stat_byvers *rpcbproc_getstat_4_res; 79*8f6d9daeSMarcel Telka } result; 80*8f6d9daeSMarcel Telka bool_t retval; 81*8f6d9daeSMarcel Telka xdrproc_t xdr_argument, xdr_result; 82*8f6d9daeSMarcel Telka bool_t (*local)(); 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate rpcbs_procinfo(RPCBVERS_4_STAT, rqstp->rq_proc); 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate RPCB_CHECK(transp, rqstp->rq_proc); 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate switch (rqstp->rq_proc) { 897c478bd9Sstevel@tonic-gate case NULLPROC: 907c478bd9Sstevel@tonic-gate /* 917c478bd9Sstevel@tonic-gate * Null proc call 927c478bd9Sstevel@tonic-gate */ 93*8f6d9daeSMarcel Telka (void) svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL); 947c478bd9Sstevel@tonic-gate return; 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate case RPCBPROC_SET: 977c478bd9Sstevel@tonic-gate /* 987c478bd9Sstevel@tonic-gate * Check to see whether the message came from 997c478bd9Sstevel@tonic-gate * loopback transports (for security reasons) 1007c478bd9Sstevel@tonic-gate */ 1017c478bd9Sstevel@tonic-gate if (strcasecmp(transp->xp_netid, loopback_dg) && 1027c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc) && 1037c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc_ord)) { 1047c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "non-local attempt to set"); 1057c478bd9Sstevel@tonic-gate svcerr_weakauth(transp); 1067c478bd9Sstevel@tonic-gate return; 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate xdr_argument = xdr_rpcb; 1097c478bd9Sstevel@tonic-gate xdr_result = xdr_bool; 110*8f6d9daeSMarcel Telka local = (bool_t (*)()) rpcbproc_set_com; 1117c478bd9Sstevel@tonic-gate break; 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate case RPCBPROC_UNSET: 1147c478bd9Sstevel@tonic-gate /* 1157c478bd9Sstevel@tonic-gate * Check to see whether the message came from 1167c478bd9Sstevel@tonic-gate * loopback transports (for security reasons) 1177c478bd9Sstevel@tonic-gate */ 1187c478bd9Sstevel@tonic-gate if (strcasecmp(transp->xp_netid, loopback_dg) && 1197c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc) && 1207c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc_ord)) { 1217c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "non-local attempt to unset"); 1227c478bd9Sstevel@tonic-gate svcerr_weakauth(transp); 1237c478bd9Sstevel@tonic-gate return; 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate xdr_argument = xdr_rpcb; 1267c478bd9Sstevel@tonic-gate xdr_result = xdr_bool; 127*8f6d9daeSMarcel Telka local = (bool_t (*)()) rpcbproc_unset_com; 1287c478bd9Sstevel@tonic-gate break; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate case RPCBPROC_GETADDR: 1317c478bd9Sstevel@tonic-gate xdr_argument = xdr_rpcb; 1327c478bd9Sstevel@tonic-gate xdr_result = xdr_wrapstring; 133*8f6d9daeSMarcel Telka local = (bool_t (*)()) rpcbproc_getaddr_com; 1347c478bd9Sstevel@tonic-gate break; 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate case RPCBPROC_DUMP: 1377c478bd9Sstevel@tonic-gate xdr_argument = xdr_void; 138*8f6d9daeSMarcel Telka xdr_result = xdr_rpcblist_ptr_ptr; 139*8f6d9daeSMarcel Telka local = (bool_t (*)()) rpcbproc_dump_com; 1407c478bd9Sstevel@tonic-gate break; 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate case RPCBPROC_BCAST: 1437c478bd9Sstevel@tonic-gate rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS4); 1447c478bd9Sstevel@tonic-gate return; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate case RPCBPROC_GETTIME: 1477c478bd9Sstevel@tonic-gate xdr_argument = xdr_void; 1487c478bd9Sstevel@tonic-gate xdr_result = xdr_u_long; 149*8f6d9daeSMarcel Telka local = (bool_t (*)()) rpcbproc_gettime_com; 1507c478bd9Sstevel@tonic-gate break; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate case RPCBPROC_UADDR2TADDR: 1537c478bd9Sstevel@tonic-gate xdr_argument = xdr_wrapstring; 1547c478bd9Sstevel@tonic-gate xdr_result = xdr_netbuf; 155*8f6d9daeSMarcel Telka local = (bool_t (*)()) rpcbproc_uaddr2taddr_com; 1567c478bd9Sstevel@tonic-gate break; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate case RPCBPROC_TADDR2UADDR: 1597c478bd9Sstevel@tonic-gate xdr_argument = xdr_netbuf; 1607c478bd9Sstevel@tonic-gate xdr_result = xdr_wrapstring; 161*8f6d9daeSMarcel Telka local = (bool_t (*)()) rpcbproc_taddr2uaddr_com; 1627c478bd9Sstevel@tonic-gate break; 1637c478bd9Sstevel@tonic-gate 164*8f6d9daeSMarcel Telka case RPCBPROC_GETVERSADDR: 1657c478bd9Sstevel@tonic-gate xdr_argument = xdr_rpcb; 166*8f6d9daeSMarcel Telka xdr_result = xdr_wrapstring; 167*8f6d9daeSMarcel Telka local = (bool_t (*)()) rpcbproc_getaddr_com; 168*8f6d9daeSMarcel Telka break; 169*8f6d9daeSMarcel Telka 170*8f6d9daeSMarcel Telka case RPCBPROC_INDIRECT: 171*8f6d9daeSMarcel Telka rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS4); 172*8f6d9daeSMarcel Telka return; 173*8f6d9daeSMarcel Telka 174*8f6d9daeSMarcel Telka case RPCBPROC_GETADDRLIST: 175*8f6d9daeSMarcel Telka xdr_argument = xdr_rpcb; 176*8f6d9daeSMarcel Telka xdr_result = xdr_rpcb_entry_list_ptr_wrap; 177*8f6d9daeSMarcel Telka local = (bool_t (*)()) rpcbproc_getaddrlist; 1787c478bd9Sstevel@tonic-gate break; 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate case RPCBPROC_GETSTAT: 1817c478bd9Sstevel@tonic-gate xdr_argument = xdr_void; 182*8f6d9daeSMarcel Telka xdr_result = xdr_rpcb_stat_byvers_ptr; 183*8f6d9daeSMarcel Telka local = (bool_t (*)()) rpcbproc_getstat; 1847c478bd9Sstevel@tonic-gate break; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate default: 1877c478bd9Sstevel@tonic-gate svcerr_noproc(transp); 1887c478bd9Sstevel@tonic-gate return; 1897c478bd9Sstevel@tonic-gate } 190*8f6d9daeSMarcel Telka (void) memset((char *)&argument, 0, sizeof (argument)); 191*8f6d9daeSMarcel Telka if (!svc_getargs(transp, xdr_argument, (char *)&argument)) { 1927c478bd9Sstevel@tonic-gate svcerr_decode(transp); 1937c478bd9Sstevel@tonic-gate if (debugging) 1947c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "rpcbind: could not decode\n"); 1957c478bd9Sstevel@tonic-gate return; 1967c478bd9Sstevel@tonic-gate } 197*8f6d9daeSMarcel Telka retval = (*local)(&argument, &result, rqstp, RPCBVERS4); 198*8f6d9daeSMarcel Telka if (retval > 0 && !svc_sendreply(transp, xdr_result, (char *)&result)) { 1997c478bd9Sstevel@tonic-gate svcerr_systemerr(transp); 2007c478bd9Sstevel@tonic-gate if (debugging) { 2017c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "rpcbind: svc_sendreply\n"); 2027c478bd9Sstevel@tonic-gate if (doabort) { 2037c478bd9Sstevel@tonic-gate rpcbind_abort(); 2047c478bd9Sstevel@tonic-gate } 2057c478bd9Sstevel@tonic-gate } 2067c478bd9Sstevel@tonic-gate } 207*8f6d9daeSMarcel Telka if (!svc_freeargs(transp, xdr_argument, (char *)&argument)) { 2087c478bd9Sstevel@tonic-gate if (debugging) { 2097c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "unable to free arguments\n"); 2107c478bd9Sstevel@tonic-gate if (doabort) { 2117c478bd9Sstevel@tonic-gate rpcbind_abort(); 2127c478bd9Sstevel@tonic-gate } 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate 216*8f6d9daeSMarcel Telka xdr_free(xdr_result, (char *)&result); 2177c478bd9Sstevel@tonic-gate } 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate /* 2207c478bd9Sstevel@tonic-gate * Lookup the mapping for a program, version and return the 2217c478bd9Sstevel@tonic-gate * addresses for all transports in the current transport family. 2227c478bd9Sstevel@tonic-gate * We return a merged address. 2237c478bd9Sstevel@tonic-gate */ 224*8f6d9daeSMarcel Telka static bool_t 225*8f6d9daeSMarcel Telka rpcbproc_getaddrlist(rpcb *regp, rpcb_entry_list_ptr *result, 226*8f6d9daeSMarcel Telka struct svc_req *rqstp) 2277c478bd9Sstevel@tonic-gate { 228*8f6d9daeSMarcel Telka rpcb_entry_list_ptr rlist = *result = NULL; 2293582b7c1Sgt29601 rpcblist_ptr rbl, next, prev; 230*8f6d9daeSMarcel Telka rpcb_entry_list_ptr rp, tail = NULL; 2317c478bd9Sstevel@tonic-gate ulong_t prog, vers; 2327c478bd9Sstevel@tonic-gate rpcb_entry *a; 2337c478bd9Sstevel@tonic-gate struct netconfig *nconf; 2347c478bd9Sstevel@tonic-gate struct netconfig *reg_nconf; 2357c478bd9Sstevel@tonic-gate char *saddr, *maddr = NULL; 2367c478bd9Sstevel@tonic-gate struct netconfig *trans_conf; /* transport netconfig */ 237*8f6d9daeSMarcel Telka SVCXPRT *transp = rqstp->rq_xprt; 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate /* 2407c478bd9Sstevel@tonic-gate * Deal with a possible window during which we could return an IPv6 2417c478bd9Sstevel@tonic-gate * address when the caller wanted IPv4. See the comments in 2427c478bd9Sstevel@tonic-gate * rpcbproc_getaddr_com() for more details. 2437c478bd9Sstevel@tonic-gate */ 2447c478bd9Sstevel@tonic-gate trans_conf = rpcbind_get_conf(transp->xp_netid); 2457c478bd9Sstevel@tonic-gate if (strcmp(trans_conf->nc_protofmly, NC_INET6) == 0) { 2467c478bd9Sstevel@tonic-gate struct sockaddr_in6 *rmtaddr; 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate rmtaddr = (struct sockaddr_in6 *)transp->xp_rtaddr.buf; 2497c478bd9Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&rmtaddr->sin6_addr)) { 2507c478bd9Sstevel@tonic-gate syslog(LOG_DEBUG, 2517c478bd9Sstevel@tonic-gate "IPv4 GETADDRLIST request mapped " 2527c478bd9Sstevel@tonic-gate "to IPv6: ignoring"); 253*8f6d9daeSMarcel Telka return (FALSE); 2547c478bd9Sstevel@tonic-gate } 2557c478bd9Sstevel@tonic-gate } 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate prog = regp->r_prog; 2587c478bd9Sstevel@tonic-gate vers = regp->r_vers; 2597c478bd9Sstevel@tonic-gate reg_nconf = rpcbind_get_conf(transp->xp_netid); 2607c478bd9Sstevel@tonic-gate if (reg_nconf == NULL) 261*8f6d9daeSMarcel Telka return (FALSE); 2627c478bd9Sstevel@tonic-gate if (*(regp->r_addr) != '\0') { 2637c478bd9Sstevel@tonic-gate saddr = regp->r_addr; 2647c478bd9Sstevel@tonic-gate } else { 2657c478bd9Sstevel@tonic-gate saddr = NULL; 2667c478bd9Sstevel@tonic-gate } 267*8f6d9daeSMarcel Telka 2683582b7c1Sgt29601 prev = NULL; 269*8f6d9daeSMarcel Telka (void) rw_wrlock(&list_rbl_lock); 2703582b7c1Sgt29601 for (rbl = list_rbl; rbl != NULL; rbl = next) { 2713582b7c1Sgt29601 next = rbl->rpcb_next; 2727c478bd9Sstevel@tonic-gate if ((rbl->rpcb_map.r_prog == prog) && 2737c478bd9Sstevel@tonic-gate (rbl->rpcb_map.r_vers == vers)) { 2747c478bd9Sstevel@tonic-gate nconf = rpcbind_get_conf(rbl->rpcb_map.r_netid); 275*8f6d9daeSMarcel Telka if (nconf == NULL) { 276*8f6d9daeSMarcel Telka (void) rw_unlock(&list_rbl_lock); 2777c478bd9Sstevel@tonic-gate goto fail; 278*8f6d9daeSMarcel Telka } 2797c478bd9Sstevel@tonic-gate if (strcmp(nconf->nc_protofmly, reg_nconf->nc_protofmly) 2807c478bd9Sstevel@tonic-gate != 0) { 2813582b7c1Sgt29601 prev = rbl; 2827c478bd9Sstevel@tonic-gate continue; /* not same proto family */ 2837c478bd9Sstevel@tonic-gate } 2847c478bd9Sstevel@tonic-gate if ((maddr = mergeaddr(transp, rbl->rpcb_map.r_netid, 2857c478bd9Sstevel@tonic-gate rbl->rpcb_map.r_addr, saddr)) == NULL) { 2863582b7c1Sgt29601 prev = rbl; 2877c478bd9Sstevel@tonic-gate continue; 2887c478bd9Sstevel@tonic-gate } else if (!maddr[0]) { 2893582b7c1Sgt29601 /* 290*8f6d9daeSMarcel Telka * The server died, remove this rpcb_map element 291*8f6d9daeSMarcel Telka * from the list and free it. 2923582b7c1Sgt29601 */ 2933582b7c1Sgt29601 #ifdef PORTMAP 294*8f6d9daeSMarcel Telka (void) rw_wrlock(&list_pml_lock); 2953582b7c1Sgt29601 (void) del_pmaplist(&rbl->rpcb_map); 296*8f6d9daeSMarcel Telka (void) rw_unlock(&list_pml_lock); 2973582b7c1Sgt29601 #endif 2983582b7c1Sgt29601 (void) delete_rbl(rbl); 2993582b7c1Sgt29601 3003582b7c1Sgt29601 if (prev == NULL) 3013582b7c1Sgt29601 list_rbl = next; 3023582b7c1Sgt29601 else 3033582b7c1Sgt29601 prev->rpcb_next = next; 3047c478bd9Sstevel@tonic-gate continue; 3057c478bd9Sstevel@tonic-gate } 3067c478bd9Sstevel@tonic-gate /* 3077c478bd9Sstevel@tonic-gate * Add it to rlist. 3087c478bd9Sstevel@tonic-gate */ 3097c478bd9Sstevel@tonic-gate rp = (rpcb_entry_list_ptr) 3107c478bd9Sstevel@tonic-gate malloc((uint_t)sizeof (rpcb_entry_list)); 311*8f6d9daeSMarcel Telka if (rp == NULL) { 312*8f6d9daeSMarcel Telka (void) rw_unlock(&list_rbl_lock); 3137c478bd9Sstevel@tonic-gate goto fail; 314*8f6d9daeSMarcel Telka } 3157c478bd9Sstevel@tonic-gate a = &rp->rpcb_entry_map; 3167c478bd9Sstevel@tonic-gate a->r_maddr = maddr; 3177c478bd9Sstevel@tonic-gate a->r_nc_netid = nconf->nc_netid; 3187c478bd9Sstevel@tonic-gate a->r_nc_semantics = nconf->nc_semantics; 3197c478bd9Sstevel@tonic-gate a->r_nc_protofmly = nconf->nc_protofmly; 3207c478bd9Sstevel@tonic-gate a->r_nc_proto = nconf->nc_proto; 3217c478bd9Sstevel@tonic-gate rp->rpcb_entry_next = NULL; 3227c478bd9Sstevel@tonic-gate if (rlist == NULL) { 3237c478bd9Sstevel@tonic-gate rlist = rp; 3247c478bd9Sstevel@tonic-gate tail = rp; 3257c478bd9Sstevel@tonic-gate } else { 3267c478bd9Sstevel@tonic-gate tail->rpcb_entry_next = rp; 3277c478bd9Sstevel@tonic-gate tail = rp; 3287c478bd9Sstevel@tonic-gate } 3297c478bd9Sstevel@tonic-gate rp = NULL; 3307c478bd9Sstevel@tonic-gate } 3313582b7c1Sgt29601 prev = rbl; 3327c478bd9Sstevel@tonic-gate } 333*8f6d9daeSMarcel Telka (void) rw_unlock(&list_rbl_lock); 334*8f6d9daeSMarcel Telka 3357c478bd9Sstevel@tonic-gate /* 3367c478bd9Sstevel@tonic-gate * XXX: getaddrlist info is also being stuffed into getaddr. 3377c478bd9Sstevel@tonic-gate * Perhaps wrong, but better than it not getting counted at all. 3387c478bd9Sstevel@tonic-gate */ 339*8f6d9daeSMarcel Telka rpcbs_getaddr(RPCBVERS_4_STAT, prog, vers, transp->xp_netid, maddr); 3407c478bd9Sstevel@tonic-gate 341*8f6d9daeSMarcel Telka *result = rlist; 342*8f6d9daeSMarcel Telka return (TRUE); 343*8f6d9daeSMarcel Telka 344*8f6d9daeSMarcel Telka fail: 345*8f6d9daeSMarcel Telka free_rpcb_entry_list(rlist); 346*8f6d9daeSMarcel Telka return (FALSE); 3477c478bd9Sstevel@tonic-gate } 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate /* 3507c478bd9Sstevel@tonic-gate * Free only the allocated structure, rest is all a pointer to some 3517c478bd9Sstevel@tonic-gate * other data somewhere else. 3527c478bd9Sstevel@tonic-gate */ 353*8f6d9daeSMarcel Telka static void 354*8f6d9daeSMarcel Telka free_rpcb_entry_list(rpcb_entry_list_ptr rlist) 3557c478bd9Sstevel@tonic-gate { 356*8f6d9daeSMarcel Telka while (rlist != NULL) { 357*8f6d9daeSMarcel Telka rpcb_entry_list_ptr tmp = rlist; 358*8f6d9daeSMarcel Telka rlist = rlist->rpcb_entry_next; 359*8f6d9daeSMarcel Telka free(tmp->rpcb_entry_map.r_maddr); 360*8f6d9daeSMarcel Telka free(tmp); 3617c478bd9Sstevel@tonic-gate } 3627c478bd9Sstevel@tonic-gate } 3637c478bd9Sstevel@tonic-gate 364*8f6d9daeSMarcel Telka static bool_t 365*8f6d9daeSMarcel Telka xdr_rpcb_entry_list_ptr_wrap(XDR *xdrs, rpcb_entry_list_ptr *rp) 3667c478bd9Sstevel@tonic-gate { 367*8f6d9daeSMarcel Telka if (xdrs->x_op == XDR_FREE) { 368*8f6d9daeSMarcel Telka free_rpcb_entry_list(*rp); 369*8f6d9daeSMarcel Telka return (TRUE); 370*8f6d9daeSMarcel Telka } 371*8f6d9daeSMarcel Telka 372*8f6d9daeSMarcel Telka return (xdr_rpcb_entry_list_ptr(xdrs, rp)); 3737c478bd9Sstevel@tonic-gate } 374