- PLD merge, updated to 0.2.4
[packages/rpcbind.git] / rpcbind-tcp-addrs.patch
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
4 @@ -340,7 +340,7 @@
5         int status;     /* bound checking ? */
6         int aicode;
7         int addrlen = 0;
8 -       int nhostsbak;
9 +       int nhostsbak = 1;
10         int checkbind;
11         int on = 1;
12         struct sockaddr *sa = NULL;
13 @@ -456,8 +456,6 @@
14                 hints.ai_family = si.si_af;
15                 hints.ai_socktype = si.si_socktype;
16                 hints.ai_protocol = si.si_proto;
17 -       }
18 -       if (nconf->nc_semantics == NC_TPI_CLTS) {
19                 /*
20                  * If no hosts were specified, just bind to INADDR_ANY.  Otherwise
21                  * make sure 127.0.0.1 is added to the list.
22 @@ -475,21 +473,15 @@
23                         } else
24                                 return 1;
25                 }
26 -
27 -              /*
28 -               * Bind to specific IPs if asked to
29 -               */
30 -               checkbind = 0;
31 -               while (nhostsbak > 0) {
32 -                       --nhostsbak;
33 -                       /*
34 -                        * XXX - using RPC library internal functions.
35 -                        */
36 -                       if ((fd = __rpc_nconf2fd(nconf)) < 0) {
37 -                               syslog(LOG_ERR, "cannot create socket for %s",
38 -                                   nconf->nc_netid);
39 -                               return (1);
40 -                       }
41 +       }
42 +       /*
43 +       * Bind to specific IPs if asked to
44 +       */
45 +       checkbind = 0;
46 +       while (nhostsbak > 0) {
47 +               --nhostsbak;
48 +               if ((strcmp(nconf->nc_netid, "local") != 0) &&
49 +                   (strcmp(nconf->nc_netid, "unix") != 0)) {
50  
51                         hints.ai_flags &= ~AI_NUMERICHOST;
52                         switch (hints.ai_family) {
53 @@ -518,7 +510,7 @@
54                                             host_addr) == 1)
55                                                 continue;
56                                 }
57 -                               break;
58 +                               break;
59                         default:
60                                 break;
61                         }
62 @@ -541,103 +533,37 @@
63                         }
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);
71 -                               if (res != NULL)
72 -                                       freeaddrinfo(res);
73 -                               continue;
74 -                       } else
75 -                               checkbind++;
76 -                       (void) umask(oldmask);
77 -
78 -                       /* Copy the address */
79 -                       taddr.addr.maxlen = taddr.addr.len = addrlen;
80 -                       taddr.addr.buf = malloc(addrlen);
81 -                       if (taddr.addr.buf == NULL) {
82 -                               syslog(LOG_ERR,
83 -                                   "cannot allocate memory for %s address",
84 -                                   nconf->nc_netid);
85 -                               if (res != NULL)
86 -                                       freeaddrinfo(res);
87 -                               return 1;
88 -                       }
89 -                       memcpy(taddr.addr.buf, sa, addrlen);
90 -#ifdef RPCBIND_DEBUG
91 -                       if (debugging) {
92 -                               /*
93 -                                * for debugging print out our universal
94 -                                * address
95 -                                */
96 -                               char *uaddr;
97 -                               struct netbuf nb;
98 -                               int sa_size = 0;
99 -
100 -                               nb.buf = sa;
101 -                               switch( sa->sa_family){
102 -                               case AF_INET:
103 -                                 sa_size = sizeof (struct sockaddr_in);
104 -                                 break;
105 -                               case AF_INET6:
106 -                                 sa_size = sizeof (struct sockaddr_in6);                                
107 -                                 break;
108 -                               }
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);
114 -                       }
115 -#endif
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", 
120 -                                        nconf->nc_netid);
121 -                               goto error;
122 -                       }
123                 }
124 -               if (!checkbind)
125 -                       return 1;
126 -       } else {        /* NC_TPI_COTS */
127 +
128 +               /*
129 +                * XXX - using RPC library internal functions.
130 +                */
131                 if ((fd = __rpc_nconf2fd(nconf)) < 0) {
132                         syslog(LOG_ERR, "cannot create socket for %s",
133                             nconf->nc_netid);
134 -                       return (1);
135 -               }
136 -
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));
142 -                         syslog(LOG_ERR,
143 -                                   "cannot get local address for %s: %s",
144 -                                   nconf->nc_netid, gai_strerror(aicode));
145 -                               return 1;
146 -                         }
147 -                       }
148 -                       addrlen = res->ai_addrlen;
149 -                       sa = (struct sockaddr *)res->ai_addr;
150 +                       continue;
151                 }
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",
157 -                               nconf->nc_netid);
158 -                       if (res != NULL)
159 -                               freeaddrinfo(res);
160 -                       return 1;
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",
166 +                                       nconf->nc_netid);
167 +                               if (res != NULL)
168 +                                       freeaddrinfo(res);
169 +                               continue;
170 +                       }
171                 }
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] : "*",
176 +                               nconf->nc_netid);
177                         if (res != NULL)
178                                 freeaddrinfo(res);
179 -                       return 1;
180 -               }
181 +                       continue;
182 +               } else
183 +                       checkbind++;
184                 (void) umask(oldmask);
185  
186                 /* Copy the address */
187 @@ -656,7 +582,7 @@
188                         /* for debugging print out our universal address */
189                         char *uaddr;
190                         struct netbuf nb;
191 -                       int sa_size2 = 0;
192 +                       int sa_size2 = 0;
193  
194                         nb.buf = sa;
195                         switch( sa->sa_family){
196 @@ -675,7 +601,8 @@
197                 }
198  #endif
199  
200 -               listen(fd, SOMAXCONN);
201 +               if (nconf->nc_semantics != NC_TPI_CLTS)
202 +                       listen(fd, SOMAXCONN);
203  
204                 my_xprt = (SVCXPRT *)svc_tli_create(fd, nconf, &taddr, RPC_MAXDATASIZE, RPC_MAXDATASIZE);
205                 if (my_xprt == (SVCXPRT *)NULL) {
206 @@ -740,6 +667,8 @@
207                 /* Also add version 2 stuff to rpcbind list */
208                 rbllist_add(PMAPPROG, PMAPVERS, nconf, &taddr.addr);
209         }
210 +       if (!checkbind)
211 +               return 1;
212  
213         /* We need to support portmap over IPv4. It makes sense to
214          * support it over AF_LOCAL as well, because that allows