From 4118a0c053531ed45299318a5fcececcab94a314 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Wed, 11 Feb 2009 18:20:18 -0500 Subject: - use our own bind-reserve-port helper, which should work with either ipv4 or ipv6 sockets - make portmap_register()/portmap_unregister() require the address family --- src/portmap.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'src/portmap.c') diff --git a/src/portmap.c b/src/portmap.c index 8963bbf..bb5051f 100644 --- a/src/portmap.c +++ b/src/portmap.c @@ -37,9 +37,13 @@ #include #endif +#include #include +#ifdef HAVE_LIBTIRPC +#include +#else #include -#include +#endif #include "portmap.h" @@ -67,8 +71,8 @@ main(int argc, char **argv) printf("error binding to reserved port\n"); } setreuid(2510, 2510); - portmap_unregister("portmap", s, YPPROG, YPVERS); - portmap_register("portmap", s, YPPROG, YPVERS, IPPROTO_UDP, + portmap_unregister("portmap", s, YPPROG, YPVERS, AF_INET); + portmap_register("portmap", s, YPPROG, YPVERS, AF_INET, IPPROTO_UDP, ntohs(sin.sin_port)); return 0; } @@ -76,7 +80,8 @@ main(int argc, char **argv) static bool_t portmap_register_work(const char *module, int resv_sock, - int program, int version, int protocol, int port, + int program, int version, + int family, int protocol, int port, int proc) { char portmap_buf[4000], auth_buf[4000], reply_buf[8000], *log_id; @@ -138,7 +143,13 @@ portmap_register_work(const char *module, int resv_sock, addr4.sin_family = AF_INET; addr4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr4.sin_port = htons(PMAPPORT); - connect(resv_sock, (struct sockaddr*) &addr4, sizeof(addr4)); + i = connect(resv_sock, (struct sockaddr*) &addr4, sizeof(addr4)); + if (i != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, log_id, + "error targeting portmap with sock %d: %s\n", + resv_sock, strerror(errno)); + return FALSE; + } /* Transmit our request. Retry a few times if it doesn't go through. */ for (i = 1; i < 32; i *= 2) { @@ -170,8 +181,10 @@ portmap_register_work(const char *module, int resv_sock, xdrmem_create(&portmap_xdrs, reply_buf, reply_length, XDR_DECODE); - msg.rm_reply.rp_acpt.ar_results.where = (caddr_t) &ret; - msg.rm_reply.rp_acpt.ar_results.proc = (xdrproc_t) xdr_bool; + msg.rm_reply.rp_acpt.ar_results.where = + (caddr_t) &ret; + msg.rm_reply.rp_acpt.ar_results.proc = + (xdrproc_t) xdr_bool; if (xdr_replymsg(&portmap_xdrs, &msg)) { if ((msg.rm_direction == REPLY) && (msg.rm_xid == xid)) { @@ -278,15 +291,16 @@ portmap_register_work(const char *module, int resv_sock, bool_t portmap_register(const char *log_id, int resv_sock, - int program, int version, int protocol, int port) + int program, int version, int family, int protocol, int port) { return portmap_register_work(log_id, resv_sock, program, version, - protocol, port, PMAPPROC_SET); + family, protocol, port, PMAPPROC_SET); } bool_t -portmap_unregister(const char *log_id, int resv_sock, int program, int version) +portmap_unregister(const char *log_id, int resv_sock, + int program, int version, int family) { return portmap_register_work(log_id, resv_sock, program, version, - 0, 0, PMAPPROC_UNSET); + family, 0, 0, PMAPPROC_UNSET); } -- cgit