summaryrefslogtreecommitdiffstats
path: root/src/portmap.c
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2009-02-11 18:20:18 -0500
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2009-02-11 18:20:18 -0500
commit4118a0c053531ed45299318a5fcececcab94a314 (patch)
tree31404e85a01469c959e4a28f0395aee0f227d756 /src/portmap.c
parent6b5ca0df76e9a76059e549f710e58589026ffe83 (diff)
downloadslapi-nis-4118a0c053531ed45299318a5fcececcab94a314.tar.gz
slapi-nis-4118a0c053531ed45299318a5fcececcab94a314.tar.xz
slapi-nis-4118a0c053531ed45299318a5fcececcab94a314.zip
- 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
Diffstat (limited to 'src/portmap.c')
-rw-r--r--src/portmap.c36
1 files changed, 25 insertions, 11 deletions
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 <slapi-plugin.h>
#endif
+#include <rpcsvc/yp_prot.h>
#include <rpc/xdr.h>
+#ifdef HAVE_LIBTIRPC
+#include <rpc/rpcb_prot.h>
+#else
#include <rpc/pmap_prot.h>
-#include <rpcsvc/yp_prot.h>
+#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);
}