|
Lines 43-56
Link Here
|
| 43 |
} while (0) |
43 |
} while (0) |
| 44 |
#endif |
44 |
#endif |
| 45 |
|
45 |
|
| 46 |
#ifdef WITH_LIBTIRPC |
|
|
| 47 |
const rpcprog_t rpcb_prog = RPCBPROG; |
| 48 |
const rpcvers_t rpcb_version = RPCBVERS; |
| 49 |
#else |
| 50 |
const rpcprog_t rpcb_prog = PMAPPROG; |
| 51 |
const rpcvers_t rpcb_version = PMAPVERS; |
| 52 |
#endif |
| 53 |
|
| 54 |
#include "mount.h" |
46 |
#include "mount.h" |
| 55 |
#include "rpc_subs.h" |
47 |
#include "rpc_subs.h" |
| 56 |
#include "automount.h" |
48 |
#include "automount.h" |
|
Lines 267-275
static int rpc_do_create_client(struct sockaddr *addr, struct conn_info *info, i
Link Here
|
| 267 |
laddr = (struct sockaddr *) &in4_laddr; |
259 |
laddr = (struct sockaddr *) &in4_laddr; |
| 268 |
in4_raddr->sin_port = htons(info->port); |
260 |
in4_raddr->sin_port = htons(info->port); |
| 269 |
slen = sizeof(struct sockaddr_in); |
261 |
slen = sizeof(struct sockaddr_in); |
| 270 |
/* Use rpcbind v2 for AF_INET */ |
|
|
| 271 |
if (info->program == rpcb_prog) |
| 272 |
info->version = PMAPVERS; |
| 273 |
} else if (addr->sa_family == AF_INET6) { |
262 |
} else if (addr->sa_family == AF_INET6) { |
| 274 |
struct sockaddr_in6 *in6_raddr = (struct sockaddr_in6 *) addr; |
263 |
struct sockaddr_in6 *in6_raddr = (struct sockaddr_in6 *) addr; |
| 275 |
in6_laddr.sin6_family = AF_INET6; |
264 |
in6_laddr.sin6_family = AF_INET6; |
|
Lines 326-388
static int rpc_do_create_client(struct sockaddr *addr, struct conn_info *info, i
Link Here
|
| 326 |
} |
315 |
} |
| 327 |
#endif |
316 |
#endif |
| 328 |
|
317 |
|
| 329 |
#if defined(HAVE_GETRPCBYNAME) || defined(HAVE_GETSERVBYNAME) |
|
|
| 330 |
static pthread_mutex_t rpcb_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 331 |
#endif |
| 332 |
|
| 333 |
static rpcprog_t rpc_getrpcbyname(const rpcprog_t program) |
| 334 |
{ |
| 335 |
#ifdef HAVE_GETRPCBYNAME |
| 336 |
static const char *rpcb_pgmtbl[] = { |
| 337 |
"rpcbind", "portmap", "portmapper", "sunrpc", NULL, |
| 338 |
}; |
| 339 |
struct rpcent *entry; |
| 340 |
rpcprog_t prog_number; |
| 341 |
unsigned int i; |
| 342 |
|
| 343 |
pthread_mutex_lock(&rpcb_mutex); |
| 344 |
for (i = 0; rpcb_pgmtbl[i] != NULL; i++) { |
| 345 |
entry = getrpcbyname(rpcb_pgmtbl[i]); |
| 346 |
if (entry) { |
| 347 |
prog_number = entry->r_number; |
| 348 |
pthread_mutex_unlock(&rpcb_mutex); |
| 349 |
return prog_number; |
| 350 |
} |
| 351 |
} |
| 352 |
pthread_mutex_unlock(&rpcb_mutex); |
| 353 |
#endif |
| 354 |
return program; |
| 355 |
} |
| 356 |
|
| 357 |
static unsigned short rpc_getrpcbport(const int proto) |
| 358 |
{ |
| 359 |
#ifdef HAVE_GETSERVBYNAME |
| 360 |
static const char *rpcb_netnametbl[] = { |
| 361 |
"rpcbind", "portmapper", "sunrpc", NULL, |
| 362 |
}; |
| 363 |
struct servent *entry; |
| 364 |
struct protoent *p_ent; |
| 365 |
unsigned short port; |
| 366 |
unsigned int i; |
| 367 |
|
| 368 |
pthread_mutex_lock(&rpcb_mutex); |
| 369 |
p_ent = getprotobynumber(proto); |
| 370 |
if (!p_ent) |
| 371 |
goto done; |
| 372 |
for (i = 0; rpcb_netnametbl[i] != NULL; i++) { |
| 373 |
entry = getservbyname(rpcb_netnametbl[i], p_ent->p_name); |
| 374 |
if (entry) { |
| 375 |
port = entry->s_port; |
| 376 |
pthread_mutex_unlock(&rpcb_mutex); |
| 377 |
return port; |
| 378 |
} |
| 379 |
} |
| 380 |
done: |
| 381 |
pthread_mutex_unlock(&rpcb_mutex); |
| 382 |
#endif |
| 383 |
return (unsigned short) PMAPPORT; |
| 384 |
} |
| 385 |
|
| 386 |
/* |
318 |
/* |
| 387 |
* Create an RPC client |
319 |
* Create an RPC client |
| 388 |
*/ |
320 |
*/ |
|
Lines 578-592
int rpc_portmap_getclient(struct conn_info *info,
Link Here
|
| 578 |
info->host = host; |
510 |
info->host = host; |
| 579 |
info->addr = addr; |
511 |
info->addr = addr; |
| 580 |
info->addr_len = addr_len; |
512 |
info->addr_len = addr_len; |
| 581 |
info->program = rpc_getrpcbyname(rpcb_prog); |
513 |
info->program = PMAPPROG; |
| 582 |
info->port = ntohs(rpc_getrpcbport(proto)); |
514 |
info->port = PMAPPORT; |
| 583 |
/* |
515 |
info->version = PMAPVERS; |
| 584 |
* When using libtirpc we might need to change the rpcbind version |
|
|
| 585 |
* to qurey AF_INET addresses. Since we might not have an address |
| 586 |
* yet set AF_INET rpcbind version in rpc_do_create_client() when |
| 587 |
* we always have an address. |
| 588 |
*/ |
| 589 |
info->version = rpcb_version; |
| 590 |
info->proto = proto; |
516 |
info->proto = proto; |
| 591 |
info->send_sz = RPCSMALLMSGSIZE; |
517 |
info->send_sz = RPCSMALLMSGSIZE; |
| 592 |
info->recv_sz = RPCSMALLMSGSIZE; |
518 |
info->recv_sz = RPCSMALLMSGSIZE; |
|
Lines 629-643
int rpc_portmap_getport(struct conn_info *info,
Link Here
|
| 629 |
pmap_info.host = info->host; |
555 |
pmap_info.host = info->host; |
| 630 |
pmap_info.addr = info->addr; |
556 |
pmap_info.addr = info->addr; |
| 631 |
pmap_info.addr_len = info->addr_len; |
557 |
pmap_info.addr_len = info->addr_len; |
| 632 |
pmap_info.port = ntohs(rpc_getrpcbport(info->proto)); |
558 |
pmap_info.port = PMAPPORT; |
| 633 |
pmap_info.program = rpc_getrpcbyname(rpcb_prog); |
559 |
pmap_info.program = PMAPPROG; |
| 634 |
/* |
560 |
pmap_info.version = PMAPVERS; |
| 635 |
* When using libtirpc we might need to change the rpcbind |
|
|
| 636 |
* version to qurey AF_INET addresses. Since we might not |
| 637 |
* have an address yet set AF_INET rpcbind version in |
| 638 |
* rpc_do_create_client() when we always have an address. |
| 639 |
*/ |
| 640 |
pmap_info.version = rpcb_version; |
| 641 |
pmap_info.proto = info->proto; |
561 |
pmap_info.proto = info->proto; |
| 642 |
pmap_info.send_sz = RPCSMALLMSGSIZE; |
562 |
pmap_info.send_sz = RPCSMALLMSGSIZE; |
| 643 |
pmap_info.recv_sz = RPCSMALLMSGSIZE; |
563 |
pmap_info.recv_sz = RPCSMALLMSGSIZE; |