1 diff -ur rpcbind-0.2.3.orig/src/rpcbind.c rpcbind-0.2.3/src/rpcbind.c
2 --- rpcbind-0.2.3.orig/src/rpcbind.c 2015-04-27 16:07:43.000000000 +0200
3 +++ rpcbind-0.2.3/src/rpcbind.c 2016-09-04 11:30:23.340410259 +0200
5 int status; /* bound checking ? */
12 struct sockaddr *sa = NULL;
14 hints.ai_family = si.si_af;
15 hints.ai_socktype = si.si_socktype;
16 hints.ai_protocol = si.si_proto;
18 - if (nconf->nc_semantics == NC_TPI_CLTS) {
20 * If no hosts were specified, just bind to INADDR_ANY. Otherwise
21 * make sure 127.0.0.1 is added to the list.
28 - * Bind to specific IPs if asked to
31 - while (nhostsbak > 0) {
34 - * XXX - using RPC library internal functions.
36 - if ((fd = __rpc_nconf2fd(nconf)) < 0) {
37 - syslog(LOG_ERR, "cannot create socket for %s",
43 + * Bind to specific IPs if asked to
46 + while (nhostsbak > 0) {
48 + if ((strcmp(nconf->nc_netid, "local") != 0) &&
49 + (strcmp(nconf->nc_netid, "unix") != 0)) {
51 hints.ai_flags &= ~AI_NUMERICHOST;
52 switch (hints.ai_family) {
62 @@ -541,103 +533,37 @@
64 addrlen = res->ai_addrlen;
65 sa = (struct sockaddr *)res->ai_addr;
66 - oldmask = umask(S_IXUSR|S_IXGRP|S_IXOTH);
67 - if (bind(fd, sa, addrlen) != 0) {
68 - syslog(LOG_ERR, "cannot bind %s on %s: %m",
69 - (hosts[nhostsbak] == NULL) ? "*" :
70 - hosts[nhostsbak], nconf->nc_netid);
76 - (void) umask(oldmask);
78 - /* Copy the address */
79 - taddr.addr.maxlen = taddr.addr.len = addrlen;
80 - taddr.addr.buf = malloc(addrlen);
81 - if (taddr.addr.buf == NULL) {
83 - "cannot allocate memory for %s address",
89 - memcpy(taddr.addr.buf, sa, addrlen);
93 - * for debugging print out our universal
101 - switch( sa->sa_family){
103 - sa_size = sizeof (struct sockaddr_in);
106 - sa_size = sizeof (struct sockaddr_in6);
109 - nb.len = nb.maxlen = sa_size;
110 - uaddr = taddr2uaddr(nconf, &nb);
111 - (void) xlog(LOG_DEBUG,
112 - "rpcbind : my address is %s\n", uaddr);
113 - (void) free(uaddr);
116 - my_xprt = (SVCXPRT *)svc_tli_create(fd, nconf, &taddr,
117 - RPC_MAXDATASIZE, RPC_MAXDATASIZE);
118 - if (my_xprt == (SVCXPRT *)NULL) {
119 - syslog(LOG_ERR, "%s: could not create service",
126 - } else { /* NC_TPI_COTS */
129 + * XXX - using RPC library internal functions.
131 if ((fd = __rpc_nconf2fd(nconf)) < 0) {
132 syslog(LOG_ERR, "cannot create socket for %s",
137 - if ((strcmp(nconf->nc_netid, "local") != 0) &&
138 - (strcmp(nconf->nc_netid, "unix") != 0)) {
139 - if ((aicode = getaddrinfo(NULL, servname, &hints, &res))!= 0) {
140 - if ((aicode = getaddrinfo(NULL, "portmapper", &hints, &res))!= 0) {
141 - printf("cannot get local address for %s: %s", nconf->nc_netid, gai_strerror(aicode));
143 - "cannot get local address for %s: %s",
144 - nconf->nc_netid, gai_strerror(aicode));
148 - addrlen = res->ai_addrlen;
149 - sa = (struct sockaddr *)res->ai_addr;
152 oldmask = umask(S_IXUSR|S_IXGRP|S_IXOTH);
153 - __rpc_fd2sockinfo(fd, &si);
154 - if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on,
155 - sizeof(on)) != 0) {
156 - syslog(LOG_ERR, "cannot set SO_REUSEADDR on %s",
161 + if (nconf->nc_semantics != NC_TPI_CLTS) {
162 + __rpc_fd2sockinfo(fd, &si);
163 + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on,
164 + sizeof(on)) != 0) {
165 + syslog(LOG_ERR, "cannot set SO_REUSEADDR on %s",
172 if (bind(fd, sa, addrlen) < 0) {
173 - syslog(LOG_ERR, "cannot bind %s: %m", nconf->nc_netid);
174 + syslog(LOG_ERR, "cannot bind %s on %s: %m",
175 + (hosts && hosts[nhostsbak]) ? hosts[nhostsbak] : "*",
184 (void) umask(oldmask);
186 /* Copy the address */
188 /* for debugging print out our universal address */
195 switch( sa->sa_family){
200 - listen(fd, SOMAXCONN);
201 + if (nconf->nc_semantics != NC_TPI_CLTS)
202 + listen(fd, SOMAXCONN);
204 my_xprt = (SVCXPRT *)svc_tli_create(fd, nconf, &taddr, RPC_MAXDATASIZE, RPC_MAXDATASIZE);
205 if (my_xprt == (SVCXPRT *)NULL) {
207 /* Also add version 2 stuff to rpcbind list */
208 rbllist_add(PMAPPROG, PMAPVERS, nconf, &taddr.addr);
213 /* We need to support portmap over IPv4. It makes sense to
214 * support it over AF_LOCAL as well, because that allows