rpcb_clnt.c (258581) | rpcb_clnt.c (287341) |
---|---|
1/* $NetBSD: rpcb_clnt.c,v 1.6 2000/07/16 06:41:43 itojun Exp $ */ 2 3/*- 4 * Copyright (c) 2010, Oracle America, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are met: --- 21 unchanged lines hidden (view full) --- 30 31/* #ident "@(#)rpcb_clnt.c 1.27 94/04/24 SMI" */ 32 33 34#if defined(LIBC_SCCS) && !defined(lint) 35static char sccsid[] = "@(#)rpcb_clnt.c 1.30 89/06/21 Copyr 1988 Sun Micro"; 36#endif 37#include <sys/cdefs.h> | 1/* $NetBSD: rpcb_clnt.c,v 1.6 2000/07/16 06:41:43 itojun Exp $ */ 2 3/*- 4 * Copyright (c) 2010, Oracle America, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are met: --- 21 unchanged lines hidden (view full) --- 30 31/* #ident "@(#)rpcb_clnt.c 1.27 94/04/24 SMI" */ 32 33 34#if defined(LIBC_SCCS) && !defined(lint) 35static char sccsid[] = "@(#)rpcb_clnt.c 1.30 89/06/21 Copyr 1988 Sun Micro"; 36#endif 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: head/lib/libc/rpc/rpcb_clnt.c 258581 2013-11-25 19:08:38Z hrs $"); | 38__FBSDID("$FreeBSD: head/lib/libc/rpc/rpcb_clnt.c 287341 2015-09-01 02:39:07Z rodrigc $"); |
39 40/* 41 * rpcb_clnt.c 42 * interface to rpcbind rpc service. 43 */ 44 45#include "namespace.h" 46#include "reentrant.h" --- 57 unchanged lines hidden (view full) --- 104 105/* 106 * This routine adjusts the timeout used for calls to the remote rpcbind. 107 * Also, this routine can be used to set the use of portmapper version 2 108 * only when doing rpc_broadcasts 109 * These are private routines that may not be provided in future releases. 110 */ 111bool_t | 39 40/* 41 * rpcb_clnt.c 42 * interface to rpcbind rpc service. 43 */ 44 45#include "namespace.h" 46#include "reentrant.h" --- 57 unchanged lines hidden (view full) --- 104 105/* 106 * This routine adjusts the timeout used for calls to the remote rpcbind. 107 * Also, this routine can be used to set the use of portmapper version 2 108 * only when doing rpc_broadcasts 109 * These are private routines that may not be provided in future releases. 110 */ 111bool_t |
112__rpc_control(request, info) 113 int request; 114 void *info; | 112__rpc_control(int request, void *info) |
115{ 116 switch (request) { 117 case CLCR_GET_RPCB_TIMEOUT: 118 *(struct timeval *)info = tottimeout; 119 break; 120 case CLCR_SET_RPCB_TIMEOUT: 121 tottimeout = *(struct timeval *)info; 122 break; --- 22 unchanged lines hidden (view full) --- 145 */ 146 147/* 148 * The routines check_cache(), add_cache(), delete_cache() manage the 149 * cache of rpcbind addresses for (host, netid). 150 */ 151 152static struct address_cache * | 113{ 114 switch (request) { 115 case CLCR_GET_RPCB_TIMEOUT: 116 *(struct timeval *)info = tottimeout; 117 break; 118 case CLCR_SET_RPCB_TIMEOUT: 119 tottimeout = *(struct timeval *)info; 120 break; --- 22 unchanged lines hidden (view full) --- 143 */ 144 145/* 146 * The routines check_cache(), add_cache(), delete_cache() manage the 147 * cache of rpcbind addresses for (host, netid). 148 */ 149 150static struct address_cache * |
153check_cache(host, netid) 154 const char *host, *netid; | 151check_cache(const char *host, const char *netid) |
155{ 156 struct address_cache *cptr; 157 158 /* READ LOCK HELD ON ENTRY: rpcbaddr_cache_lock */ 159 160 for (cptr = front; cptr != NULL; cptr = cptr->ac_next) { 161 if (!strcmp(cptr->ac_host, host) && 162 !strcmp(cptr->ac_netid, netid)) { 163#ifdef ND_DEBUG 164 fprintf(stderr, "Found cache entry for %s: %s\n", 165 host, netid); 166#endif 167 return (cptr); 168 } 169 } 170 return ((struct address_cache *) NULL); 171} 172 173static void | 152{ 153 struct address_cache *cptr; 154 155 /* READ LOCK HELD ON ENTRY: rpcbaddr_cache_lock */ 156 157 for (cptr = front; cptr != NULL; cptr = cptr->ac_next) { 158 if (!strcmp(cptr->ac_host, host) && 159 !strcmp(cptr->ac_netid, netid)) { 160#ifdef ND_DEBUG 161 fprintf(stderr, "Found cache entry for %s: %s\n", 162 host, netid); 163#endif 164 return (cptr); 165 } 166 } 167 return ((struct address_cache *) NULL); 168} 169 170static void |
174delete_cache(addr) 175 struct netbuf *addr; | 171delete_cache(struct netbuf *addr) |
176{ 177 struct address_cache *cptr, *prevptr = NULL; 178 179 /* WRITE LOCK HELD ON ENTRY: rpcbaddr_cache_lock */ 180 for (cptr = front; cptr != NULL; cptr = cptr->ac_next) { 181 if (!memcmp(cptr->ac_taddr->buf, addr->buf, addr->len)) { 182 free(cptr->ac_host); 183 free(cptr->ac_netid); --- 97 unchanged lines hidden (view full) --- 281/* 282 * This routine will return a client handle that is connected to the 283 * rpcbind. If targaddr is non-NULL, the "universal address" of the 284 * host will be stored in *targaddr; the caller is responsible for 285 * freeing this string. 286 * On error, returns NULL and free's everything. 287 */ 288static CLIENT * | 172{ 173 struct address_cache *cptr, *prevptr = NULL; 174 175 /* WRITE LOCK HELD ON ENTRY: rpcbaddr_cache_lock */ 176 for (cptr = front; cptr != NULL; cptr = cptr->ac_next) { 177 if (!memcmp(cptr->ac_taddr->buf, addr->buf, addr->len)) { 178 free(cptr->ac_host); 179 free(cptr->ac_netid); --- 97 unchanged lines hidden (view full) --- 277/* 278 * This routine will return a client handle that is connected to the 279 * rpcbind. If targaddr is non-NULL, the "universal address" of the 280 * host will be stored in *targaddr; the caller is responsible for 281 * freeing this string. 282 * On error, returns NULL and free's everything. 283 */ 284static CLIENT * |
289getclnthandle(host, nconf, targaddr) 290 const char *host; 291 const struct netconfig *nconf; 292 char **targaddr; | 285getclnthandle(const char *host, const struct netconfig *nconf, char **targaddr) |
293{ 294 CLIENT *client; 295 struct netbuf *addr, taddr; 296 struct netbuf addr_to_delete; 297 struct __rpc_sockinfo si; 298 struct addrinfo hints, *res, *tres; 299 struct address_cache *ad_cache; 300 char *tmpaddr; --- 225 unchanged lines hidden (view full) --- 526 mutex_unlock(&loopnconf_lock); 527 client = getclnthandle(hostname, loopnconf, NULL); 528 return (client); 529} 530 531/* 532 * Set a mapping between program, version and address. 533 * Calls the rpcbind service to do the mapping. | 286{ 287 CLIENT *client; 288 struct netbuf *addr, taddr; 289 struct netbuf addr_to_delete; 290 struct __rpc_sockinfo si; 291 struct addrinfo hints, *res, *tres; 292 struct address_cache *ad_cache; 293 char *tmpaddr; --- 225 unchanged lines hidden (view full) --- 519 mutex_unlock(&loopnconf_lock); 520 client = getclnthandle(hostname, loopnconf, NULL); 521 return (client); 522} 523 524/* 525 * Set a mapping between program, version and address. 526 * Calls the rpcbind service to do the mapping. |
527 * 528 * nconf - Network structure of transport 529 * address - Services netconfig address |
|
534 */ 535bool_t | 530 */ 531bool_t |
536rpcb_set(program, version, nconf, address) 537 rpcprog_t program; 538 rpcvers_t version; 539 const struct netconfig *nconf; /* Network structure of transport */ 540 const struct netbuf *address; /* Services netconfig address */ | 532rpcb_set(rpcprog_t program, rpcvers_t version, const struct netconfig *nconf, 533 const struct netbuf *address) |
541{ 542 CLIENT *client; 543 bool_t rslt = FALSE; 544 RPCB parms; 545 char uidbuf[32]; 546 547 /* parameter checking */ 548 if (nconf == NULL) { --- 40 unchanged lines hidden (view full) --- 589 590/* 591 * Remove the mapping between program, version and netbuf address. 592 * Calls the rpcbind service to do the un-mapping. 593 * If netbuf is NULL, unset for all the transports, otherwise unset 594 * only for the given transport. 595 */ 596bool_t | 534{ 535 CLIENT *client; 536 bool_t rslt = FALSE; 537 RPCB parms; 538 char uidbuf[32]; 539 540 /* parameter checking */ 541 if (nconf == NULL) { --- 40 unchanged lines hidden (view full) --- 582 583/* 584 * Remove the mapping between program, version and netbuf address. 585 * Calls the rpcbind service to do the un-mapping. 586 * If netbuf is NULL, unset for all the transports, otherwise unset 587 * only for the given transport. 588 */ 589bool_t |
597rpcb_unset(program, version, nconf) 598 rpcprog_t program; 599 rpcvers_t version; 600 const struct netconfig *nconf; | 590rpcb_unset(rpcprog_t program, rpcvers_t version, const struct netconfig *nconf) |
601{ 602 CLIENT *client; 603 bool_t rslt = FALSE; 604 RPCB parms; 605 char uidbuf[32]; 606 607 client = local_rpcb(); 608 if (! client) { --- 20 unchanged lines hidden (view full) --- 629 CLNT_DESTROY(client); 630 return (rslt); 631} 632 633/* 634 * From the merged list, find the appropriate entry 635 */ 636static struct netbuf * | 591{ 592 CLIENT *client; 593 bool_t rslt = FALSE; 594 RPCB parms; 595 char uidbuf[32]; 596 597 client = local_rpcb(); 598 if (! client) { --- 20 unchanged lines hidden (view full) --- 619 CLNT_DESTROY(client); 620 return (rslt); 621} 622 623/* 624 * From the merged list, find the appropriate entry 625 */ 626static struct netbuf * |
637got_entry(relp, nconf) 638 rpcb_entry_list_ptr relp; 639 const struct netconfig *nconf; | 627got_entry(rpcb_entry_list_ptr relp, const struct netconfig *nconf) |
640{ 641 struct netbuf *na = NULL; 642 rpcb_entry_list_ptr sp; 643 rpcb_entry *rmap; 644 645 for (sp = relp; sp != NULL; sp = sp->rpcb_entry_next) { 646 rmap = &sp->rpcb_entry_map; 647 if ((strcmp(nconf->nc_proto, rmap->r_nc_proto) == 0) && --- 69 unchanged lines hidden (view full) --- 717 * For all other transports, the algorithm remains as 4 and then 3. 718 * 719 * XXX: Due to some problems with t_connect(), we do not reuse the same client 720 * handle for COTS cases and hence in these cases we do not return the 721 * client handle. This code will change if t_connect() ever 722 * starts working properly. Also look under clnt_vc.c. 723 */ 724struct netbuf * | 628{ 629 struct netbuf *na = NULL; 630 rpcb_entry_list_ptr sp; 631 rpcb_entry *rmap; 632 633 for (sp = relp; sp != NULL; sp = sp->rpcb_entry_next) { 634 rmap = &sp->rpcb_entry_map; 635 if ((strcmp(nconf->nc_proto, rmap->r_nc_proto) == 0) && --- 69 unchanged lines hidden (view full) --- 705 * For all other transports, the algorithm remains as 4 and then 3. 706 * 707 * XXX: Due to some problems with t_connect(), we do not reuse the same client 708 * handle for COTS cases and hence in these cases we do not return the 709 * client handle. This code will change if t_connect() ever 710 * starts working properly. Also look under clnt_vc.c. 711 */ 712struct netbuf * |
725__rpcb_findaddr_timed(program, version, nconf, host, clpp, tp) 726 rpcprog_t program; 727 rpcvers_t version; 728 const struct netconfig *nconf; 729 const char *host; 730 CLIENT **clpp; 731 struct timeval *tp; | 713__rpcb_findaddr_timed(rpcprog_t program, rpcvers_t version, 714 const struct netconfig *nconf, const char *host, 715 CLIENT **clpp, struct timeval *tp) |
732{ 733 static bool_t check_rpcbind = TRUE; 734 CLIENT *client = NULL; 735 RPCB parms; 736 enum clnt_stat clnt_st; 737 char *ua = NULL; 738 rpcvers_t vers; 739 struct netbuf *address = NULL; --- 292 unchanged lines hidden (view full) --- 1032 * Find the mapped address for program, version. 1033 * Calls the rpcbind service remotely to do the lookup. 1034 * Uses the transport specified in nconf. 1035 * Returns FALSE (0) if no map exists, else returns 1. 1036 * 1037 * Assuming that the address is all properly allocated 1038 */ 1039int | 716{ 717 static bool_t check_rpcbind = TRUE; 718 CLIENT *client = NULL; 719 RPCB parms; 720 enum clnt_stat clnt_st; 721 char *ua = NULL; 722 rpcvers_t vers; 723 struct netbuf *address = NULL; --- 292 unchanged lines hidden (view full) --- 1016 * Find the mapped address for program, version. 1017 * Calls the rpcbind service remotely to do the lookup. 1018 * Uses the transport specified in nconf. 1019 * Returns FALSE (0) if no map exists, else returns 1. 1020 * 1021 * Assuming that the address is all properly allocated 1022 */ 1023int |
1040rpcb_getaddr(program, version, nconf, address, host) 1041 rpcprog_t program; 1042 rpcvers_t version; 1043 const struct netconfig *nconf; 1044 struct netbuf *address; 1045 const char *host; | 1024rpcb_getaddr(rpcprog_t program, rpcvers_t version, const struct netconfig *nconf, 1025 struct netbuf *address, const char *host) |
1046{ 1047 struct netbuf *na; 1048 1049 if ((na = __rpcb_findaddr_timed(program, version, 1050 (struct netconfig *) nconf, (char *) host, 1051 (CLIENT **) NULL, (struct timeval *) NULL)) == NULL) 1052 return (FALSE); 1053 --- 14 unchanged lines hidden (view full) --- 1068/* 1069 * Get a copy of the current maps. 1070 * Calls the rpcbind service remotely to get the maps. 1071 * 1072 * It returns only a list of the services 1073 * It returns NULL on failure. 1074 */ 1075rpcblist * | 1026{ 1027 struct netbuf *na; 1028 1029 if ((na = __rpcb_findaddr_timed(program, version, 1030 (struct netconfig *) nconf, (char *) host, 1031 (CLIENT **) NULL, (struct timeval *) NULL)) == NULL) 1032 return (FALSE); 1033 --- 14 unchanged lines hidden (view full) --- 1048/* 1049 * Get a copy of the current maps. 1050 * Calls the rpcbind service remotely to get the maps. 1051 * 1052 * It returns only a list of the services 1053 * It returns NULL on failure. 1054 */ 1055rpcblist * |
1076rpcb_getmaps(nconf, host) 1077 const struct netconfig *nconf; 1078 const char *host; | 1056rpcb_getmaps(const struct netconfig *nconf, const char *host) |
1079{ 1080 rpcblist_ptr head = NULL; 1081 CLIENT *client; 1082 enum clnt_stat clnt_st; 1083 rpcvers_t vers = 0; 1084 1085 client = getclnthandle(host, nconf, NULL); 1086 if (client == NULL) { --- 114 unchanged lines hidden (view full) --- 1201 return (stat); 1202} 1203 1204/* 1205 * Gets the time on the remote host. 1206 * Returns 1 if succeeds else 0. 1207 */ 1208bool_t | 1057{ 1058 rpcblist_ptr head = NULL; 1059 CLIENT *client; 1060 enum clnt_stat clnt_st; 1061 rpcvers_t vers = 0; 1062 1063 client = getclnthandle(host, nconf, NULL); 1064 if (client == NULL) { --- 114 unchanged lines hidden (view full) --- 1179 return (stat); 1180} 1181 1182/* 1183 * Gets the time on the remote host. 1184 * Returns 1 if succeeds else 0. 1185 */ 1186bool_t |
1209rpcb_gettime(host, timep) 1210 const char *host; 1211 time_t *timep; | 1187rpcb_gettime(const char *host, time_t *timep) |
1212{ 1213 CLIENT *client = NULL; 1214 void *handle; 1215 struct netconfig *nconf; 1216 rpcvers_t vers; 1217 enum clnt_stat st; 1218 1219 --- 42 unchanged lines hidden (view full) --- 1262 return (st == RPC_SUCCESS? TRUE: FALSE); 1263} 1264 1265/* 1266 * Converts taddr to universal address. This routine should never 1267 * really be called because local n2a libraries are always provided. 1268 */ 1269char * | 1188{ 1189 CLIENT *client = NULL; 1190 void *handle; 1191 struct netconfig *nconf; 1192 rpcvers_t vers; 1193 enum clnt_stat st; 1194 1195 --- 42 unchanged lines hidden (view full) --- 1238 return (st == RPC_SUCCESS? TRUE: FALSE); 1239} 1240 1241/* 1242 * Converts taddr to universal address. This routine should never 1243 * really be called because local n2a libraries are always provided. 1244 */ 1245char * |
1270rpcb_taddr2uaddr(nconf, taddr) 1271 struct netconfig *nconf; 1272 struct netbuf *taddr; | 1246rpcb_taddr2uaddr(struct netconfig *nconf, struct netbuf *taddr) |
1273{ 1274 CLIENT *client; 1275 char *uaddr = NULL; 1276 1277 1278 /* parameter checking */ 1279 if (nconf == NULL) { 1280 rpc_createerr.cf_stat = RPC_UNKNOWNPROTO; --- 15 unchanged lines hidden (view full) --- 1296 return (uaddr); 1297} 1298 1299/* 1300 * Converts universal address to netbuf. This routine should never 1301 * really be called because local n2a libraries are always provided. 1302 */ 1303struct netbuf * | 1247{ 1248 CLIENT *client; 1249 char *uaddr = NULL; 1250 1251 1252 /* parameter checking */ 1253 if (nconf == NULL) { 1254 rpc_createerr.cf_stat = RPC_UNKNOWNPROTO; --- 15 unchanged lines hidden (view full) --- 1270 return (uaddr); 1271} 1272 1273/* 1274 * Converts universal address to netbuf. This routine should never 1275 * really be called because local n2a libraries are always provided. 1276 */ 1277struct netbuf * |
1304rpcb_uaddr2taddr(nconf, uaddr) 1305 struct netconfig *nconf; 1306 char *uaddr; | 1278rpcb_uaddr2taddr(struct netconfig *nconf, char *uaddr) |
1307{ 1308 CLIENT *client; 1309 struct netbuf *taddr; 1310 1311 1312 /* parameter checking */ 1313 if (nconf == NULL) { 1314 rpc_createerr.cf_stat = RPC_UNKNOWNPROTO; --- 26 unchanged lines hidden --- | 1279{ 1280 CLIENT *client; 1281 struct netbuf *taddr; 1282 1283 1284 /* parameter checking */ 1285 if (nconf == NULL) { 1286 rpc_createerr.cf_stat = RPC_UNKNOWNPROTO; --- 26 unchanged lines hidden --- |