~ubuntu-branches/ubuntu/precise/autofs5/precise

« back to all changes in this revision

Viewing changes to lib/rpc_subs.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-05-27 09:21:06 UTC
  • Revision ID: james.westby@ubuntu.com-20110527092106-8f4jioajbyi3bctn
Tags: 5.0.5-0ubuntu7
* Refresh upstream patches.
* Convert to dpkg-source 3.0 quilt format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
/* Get numeric value of the n bits starting at position p */
54
54
#define getbits(x, p, n)      ((x >> (p + 1 - n)) & ~(~0 << n))
55
55
 
 
56
static const rpcvers_t mount_vers[] = {
 
57
        MOUNTVERS_NFSV3,
 
58
        MOUNTVERS_POSIX,
 
59
        MOUNTVERS,
 
60
};
 
61
 
 
62
static int connect_nb(int, struct sockaddr *, socklen_t, struct timeval *);
56
63
inline void dump_core(void);
57
64
 
58
65
static CLIENT *rpc_clntudp_create(struct sockaddr *addr, struct conn_info *info, int *fd)
97
104
        struct sockaddr_in *in4_raddr;
98
105
        struct sockaddr_in6 *in6_raddr;
99
106
        CLIENT *client = NULL;
 
107
        socklen_t slen;
100
108
 
101
109
        switch (addr->sa_family) {
102
110
        case AF_INET:
103
111
                in4_raddr = (struct sockaddr_in *) addr;
104
112
                in4_raddr->sin_port = htons(info->port);
 
113
                slen = sizeof(struct sockaddr_in);
 
114
 
 
115
                if (connect_nb(*fd, addr, slen, &info->timeout) < 0)
 
116
                        break;
 
117
 
105
118
                client = clnttcp_create(in4_raddr,
106
119
                                        info->program, info->version, fd,
107
120
                                        info->send_sz, info->recv_sz);
114
127
#else
115
128
                in6_raddr = (struct sockaddr_in6 *) addr;
116
129
                in6_raddr->sin6_port = htons(info->port);
 
130
                slen = sizeof(struct sockaddr_in6);
 
131
 
 
132
                if (connect_nb(*fd, addr, slen, &info->timeout) < 0)
 
133
                        break;
 
134
 
117
135
                client = clnttcp6_create(in6_raddr,
118
136
                                         info->program, info->version, fd,
119
137
                                         info->send_sz, info->recv_sz);
161
179
        if (ret == 0)
162
180
                goto done;
163
181
 
 
182
        if (timeout != -1) {
 
183
                if (timeout >= (INT_MAX - 1)/1000)
 
184
                        timeout = INT_MAX - 1;
 
185
                else
 
186
                        timeout = timeout * 1000;
 
187
        }
 
188
 
164
189
        pfd[0].fd = fd;
165
190
        pfd[0].events = POLLOUT;
166
191
 
253
278
                return NULL;
254
279
        }
255
280
 
 
281
        if (!info->client) {
 
282
                *fd = open_sock(addr->sa_family, type, proto);
 
283
                if (*fd < 0)
 
284
                        return NULL;
 
285
 
 
286
                if (bind(*fd, laddr, slen) < 0)
 
287
                        return NULL;
 
288
        }
 
289
 
256
290
        switch (info->proto->p_proto) {
257
291
        case IPPROTO_UDP:
258
 
                if (!info->client) {
259
 
                        *fd = open_sock(addr->sa_family, type, proto);
260
 
                        if (*fd < 0)
261
 
                                return NULL;
262
 
 
263
 
                        if (bind(*fd, laddr, slen) < 0) {
264
 
                                close(*fd);
265
 
                                return NULL;
266
 
                        }
267
 
                }
268
292
                client = rpc_clntudp_create(addr, info, fd);
269
293
                break;
270
294
 
271
295
        case IPPROTO_TCP:
272
 
                if (!info->client) {
273
 
                        *fd = open_sock(addr->sa_family, type, proto);
274
 
                        if (*fd < 0)
275
 
                                return NULL;
276
 
 
277
 
                        if (connect_nb(*fd, laddr, slen, &info->timeout) < 0) {
278
 
                                close(*fd);
279
 
                                return NULL;
280
 
                        }
281
 
                }
282
296
                client = rpc_clnttcp_create(addr, info, fd);
283
297
                break;
284
298
 
320
334
                if (client)
321
335
                        goto done;
322
336
 
323
 
                if (!info->client) {
 
337
                if (!info->client && fd != RPC_ANYSOCK) {
324
338
                        close(fd);
325
339
                        fd = RPC_ANYSOCK;
326
340
                }
345
359
                if (client)
346
360
                        break;
347
361
 
348
 
                if (!info->client) {
 
362
                if (!info->client && fd != RPC_ANYSOCK) {
349
363
                        close(fd);
350
364
                        fd = RPC_ANYSOCK;
351
365
                }
470
484
                if (client)
471
485
                        break;
472
486
 
473
 
                if (!info->client) {
 
487
                if (!info->client && fd != RPC_ANYSOCK) {
474
488
                        close(fd);
475
489
                        fd = RPC_ANYSOCK;
476
490
                }
838
852
        enum clnt_stat status;
839
853
        int proto = info->proto->p_proto;
840
854
        unsigned int option = info->close_option;
 
855
        int vers_entry;
841
856
 
842
857
        if (info->proto->p_proto == IPPROTO_UDP) {
843
858
                info->send_sz = UDPMSGSIZE;
854
869
 
855
870
        client->cl_auth = authunix_create_default();
856
871
 
857
 
        status = clnt_call(client, MOUNTPROC_EXPORT,
858
 
                         (xdrproc_t) xdr_void, NULL,
859
 
                         (xdrproc_t) xdr_exports, (caddr_t) exp,
860
 
                         info->timeout);
 
872
        vers_entry = 0;
 
873
        while (1) {
 
874
                status = clnt_call(client, MOUNTPROC_EXPORT,
 
875
                                 (xdrproc_t) xdr_void, NULL,
 
876
                                 (xdrproc_t) xdr_exports, (caddr_t) exp,
 
877
                                 info->timeout);
 
878
                if (status != RPC_PROGVERSMISMATCH)
 
879
                        break;
 
880
                if (++vers_entry > 2)
 
881
                        break;
 
882
                CLNT_CONTROL(client, CLSET_VERS,
 
883
                            (void *) &mount_vers[vers_entry]);
 
884
        }
861
885
 
862
886
        /* Only play with the close options if we think it completed OK */
863
887
        if (proto == IPPROTO_TCP && status == RPC_SUCCESS) {
926
950
        info.addr = NULL;
927
951
        info.addr_len = 0;
928
952
        info.program = MOUNTPROG;
929
 
        info.version = MOUNTVERS;
 
953
        info.version = mount_vers[0];
930
954
        info.send_sz = 0;
931
955
        info.recv_sz = 0;
932
956
        info.timeout.tv_sec = seconds;
975
999
        return exportlist;
976
1000
}
977
1001
 
 
1002
const char *get_addr_string(struct sockaddr *sa, char *name, socklen_t len)
 
1003
{
 
1004
        void *addr;
 
1005
 
 
1006
        if (len < INET6_ADDRSTRLEN)
 
1007
                return NULL;
 
1008
 
 
1009
        if (sa->sa_family == AF_INET) {
 
1010
                struct sockaddr_in *ipv4 = (struct sockaddr_in *) sa;
 
1011
                addr = &(ipv4->sin_addr);
 
1012
        } else if (sa->sa_family == AF_INET6) {
 
1013
                struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *) sa;
 
1014
                addr = &(ipv6->sin6_addr);
 
1015
        } else {
 
1016
                return NULL;
 
1017
        }
 
1018
 
 
1019
        return inet_ntop(sa->sa_family, addr, name, len);
 
1020
}
 
1021
 
978
1022
#if 0
979
1023
#include <stdio.h>
980
1024