~ubuntu-branches/debian/stretch/nfs-utils/stretch

« back to all changes in this revision

Viewing changes to utils/mount/network.c

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar, Anibal Monsalve Salazar, Ben Hutchings
  • Date: 2010-04-06 16:11:22 UTC
  • mfrom: (1.2.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20100406161122-x7erw0q8xiitoyp6
Tags: 1:1.2.2-1
[ Anibal Monsalve Salazar ]
* New upstream release 
  Build depend on libcap-dev
  Set configure option --enable-nfsv41
* X-ref nfsd({7,8})
  02-524255-manpages.patch by Cyril Brulebois
  Closes: 524255

[ Ben Hutchings ]
* Change maintainer to Debian kernel team; move Aníbal to uploaders and
  add myself to uploaders
* Check for nfsd in /proc/filesystems rather than looking for signs of it in
  /proc/kallsyms (Closes: #563104, #572736)
* Document the -n option to svcgssd, thanks to Alberto Gonzalez Iniesta
  (Closes: #451402, #550270)
* Replace upstream reference in package descriptions with Homepage fields,
  and do not refer to the obsolete CVS repository
* Update policy version to 3.8.4; no changes required
* Override lintian error 'init.d-script-missing-dependency-on-remote_fs';
  the init script does work without /usr mounted

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include <sys/types.h>
38
38
#include <sys/socket.h>
39
39
#include <sys/wait.h>
 
40
#include <sys/stat.h>
40
41
#include <netinet/in.h>
41
42
#include <rpc/rpc.h>
42
43
#include <rpc/pmap_prot.h>
43
44
#include <rpc/pmap_clnt.h>
44
45
 
 
46
#include "sockaddr.h"
45
47
#include "xcommon.h"
46
48
#include "mount.h"
47
49
#include "nls.h"
56
58
#define CONNECT_TIMEOUT (20)
57
59
#define MOUNT_TIMEOUT   (30)
58
60
 
59
 
#if SIZEOF_SOCKLEN_T - 0 == 0
60
 
#define socklen_t unsigned int
61
 
#endif
62
 
 
63
61
extern int nfs_mount_data_version;
64
62
extern char *progname;
65
63
extern int verbose;
193
191
}
194
192
#endif /* MOUNT_CONFIG */
195
193
 
196
 
static int nfs_lookup(const char *hostname, const sa_family_t family,
197
 
                      struct sockaddr *sap, socklen_t *salen)
 
194
/**
 
195
 * nfs_lookup - resolve hostname to an IPv4 or IPv6 socket address
 
196
 * @hostname: pointer to C string containing DNS hostname to resolve
 
197
 * @family: address family hint
 
198
 * @sap: pointer to buffer to fill with socket address
 
199
 * @len: IN: size of buffer to fill; OUT: size of socket address
 
200
 *
 
201
 * Returns 1 and places a socket address at @sap if successful;
 
202
 * otherwise zero.
 
203
 */
 
204
int nfs_lookup(const char *hostname, const sa_family_t family,
 
205
                struct sockaddr *sap, socklen_t *salen)
198
206
{
199
207
        struct addrinfo *gai_results;
200
208
        struct addrinfo gai_hint = {
243
251
}
244
252
 
245
253
/**
246
 
 * nfs_name_to_address - resolve hostname to an IPv4 or IPv6 socket address
247
 
 * @hostname: pointer to C string containing DNS hostname to resolve
248
 
 * @sap: pointer to buffer to fill with socket address
249
 
 * @len: IN: size of buffer to fill; OUT: size of socket address
250
 
 *
251
 
 * Returns 1 and places a socket address at @sap if successful;
252
 
 * otherwise zero.
253
 
 */
254
 
int nfs_name_to_address(const char *hostname,
255
 
                        struct sockaddr *sap, socklen_t *salen)
256
 
{
257
 
#ifdef IPV6_SUPPORTED
258
 
        return nfs_lookup(hostname, AF_UNSPEC, sap, salen);
259
 
#else   /* !IPV6_SUPPORTED */
260
 
        return nfs_lookup(hostname, AF_INET, sap, salen);
261
 
#endif  /* !IPV6_SUPPORTED */
262
 
}
263
 
 
264
 
/**
265
254
 * nfs_gethostbyname - resolve a hostname to an IPv4 address
266
255
 * @hostname: pointer to a C string containing a DNS hostname
267
256
 * @sin: returns an IPv4 address 
283
272
 *              OUT: length of converted socket address
284
273
 *
285
274
 * Convert a presentation format address string to a socket address.
286
 
 * Similar to nfs_name_to_address(), but the DNS query is squelched,
287
 
 * and won't make any noise if the getaddrinfo() call fails.
 
275
 * Similar to nfs_lookup(), but the DNS query is squelched, and it
 
276
 * won't make any noise if the getaddrinfo() call fails.
288
277
 *
289
278
 * Returns 1 and fills in @sap and @salen if successful; otherwise zero.
290
279
 *
549
538
                          struct pmap *pmap, const unsigned long *versions,
550
539
                          const unsigned int *protos)
551
540
{
552
 
        struct sockaddr_storage address;
553
 
        struct sockaddr *saddr = (struct sockaddr *)&address;
 
541
        union nfs_sockaddr address;
 
542
        struct sockaddr *saddr = &address.sa;
554
543
        const unsigned long prog = pmap->pm_prog, *p_vers;
555
544
        const unsigned int prot = (u_int)pmap->pm_prot, *p_prot;
556
545
        const u_short port = (u_short) pmap->pm_port;
840
829
int nfs_advise_umount(const struct sockaddr *sap, const socklen_t salen,
841
830
                      const struct pmap *pmap, const dirpath *argp)
842
831
{
843
 
        struct sockaddr_storage address;
844
 
        struct sockaddr *saddr = (struct sockaddr *)&address;
 
832
        union nfs_sockaddr address;
 
833
        struct sockaddr *saddr = &address.sa;
845
834
        struct pmap mnt_pmap = *pmap;
846
835
        struct timeval timeout = {
847
836
                .tv_sec         = MOUNT_TIMEOUT >> 3,
1284
1273
 
1285
1274
/*
1286
1275
 * Returns TRUE if @protocol contains a valid value for this option,
1287
 
 * or FALSE if the option was specified with an invalid value.
 
1276
 * or FALSE if the option was specified with an invalid value. On
 
1277
 * error, errno is set.
1288
1278
 */
1289
1279
int
1290
1280
nfs_nfs_protocol(struct mount_options *options, unsigned long *protocol)
1291
1281
{
 
1282
        sa_family_t family;
1292
1283
        char *option;
1293
1284
 
1294
1285
        switch (po_rightmost(options, nfs_transport_opttbl)) {
1300
1291
                return 1;
1301
1292
        case 2: /* proto */
1302
1293
                option = po_get(options, "proto");
1303
 
                if (option) {
1304
 
                        if (strcmp(option, "tcp") == 0) {
1305
 
                                *protocol = IPPROTO_TCP;
1306
 
                                return 1;
1307
 
                        }
1308
 
                        if (strcmp(option, "udp") == 0) {
1309
 
                                *protocol = IPPROTO_UDP;
1310
 
                                return 1;
1311
 
                        }
1312
 
                        return 0;
 
1294
                if (option != NULL) {
 
1295
                        if (!nfs_get_proto(option, &family, protocol)) {
 
1296
                                errno = EPROTONOSUPPORT;
 
1297
                                return 0;
 
1298
                        }
 
1299
                        return 1;
1313
1300
                }
1314
1301
        }
1315
1302
 
1351
1338
        return 1;
1352
1339
}
1353
1340
 
 
1341
#ifdef IPV6_SUPPORTED
 
1342
sa_family_t     config_default_family = AF_UNSPEC;
 
1343
 
 
1344
static int
 
1345
nfs_verify_family(sa_family_t family)
 
1346
{
 
1347
        return 1;
 
1348
}
 
1349
#else /* IPV6_SUPPORTED */
 
1350
sa_family_t     config_default_family = AF_INET;
 
1351
 
 
1352
static int
 
1353
nfs_verify_family(sa_family_t family)
 
1354
{
 
1355
        if (family != AF_INET)
 
1356
                return 0;
 
1357
 
 
1358
        return 1;
 
1359
}
 
1360
#endif /* IPV6_SUPPORTED */
 
1361
 
 
1362
/*
 
1363
 * Returns TRUE and fills in @family if a valid NFS protocol option
 
1364
 * is found, or FALSE if the option was specified with an invalid value
 
1365
 * or if the protocol family isn't supported. On error, errno is set.
 
1366
 */
 
1367
int nfs_nfs_proto_family(struct mount_options *options,
 
1368
                                sa_family_t *family)
 
1369
{
 
1370
        unsigned long protocol;
 
1371
        char *option;
 
1372
        sa_family_t tmp_family = config_default_family;
 
1373
 
 
1374
        switch (po_rightmost(options, nfs_transport_opttbl)) {
 
1375
        case 0: /* udp */
 
1376
        case 1: /* tcp */
 
1377
                /* for compatibility; these are always AF_INET */
 
1378
                *family = AF_INET;
 
1379
                return 1;
 
1380
        case 2: /* proto */
 
1381
                option = po_get(options, "proto");
 
1382
                if (option != NULL &&
 
1383
                    !nfs_get_proto(option, &tmp_family, &protocol))
 
1384
                        goto out_err;
 
1385
        }
 
1386
 
 
1387
        if (!nfs_verify_family(tmp_family))
 
1388
                goto out_err;
 
1389
        *family = tmp_family;
 
1390
        return 1;
 
1391
out_err:
 
1392
        errno = EAFNOSUPPORT;
 
1393
        return 0;
 
1394
}
 
1395
 
1354
1396
/*
1355
1397
 * "mountprog" is supported only by the legacy mount command.  The
1356
1398
 * kernel mount client does not support this option.
1414
1456
 
1415
1457
/*
1416
1458
 * Returns TRUE if @protocol contains a valid value for this option,
1417
 
 * or FALSE if the option was specified with an invalid value.
 
1459
 * or FALSE if the option was specified with an invalid value. On
 
1460
 * error, errno is set.
1418
1461
 */
1419
1462
static int
1420
1463
nfs_mount_protocol(struct mount_options *options, unsigned long *protocol)
1421
1464
{
 
1465
        sa_family_t family;
1422
1466
        char *option;
1423
1467
 
1424
1468
        option = po_get(options, "mountproto");
1425
 
        if (option) {
1426
 
                if (strcmp(option, "tcp") == 0) {
1427
 
                        *protocol = IPPROTO_TCP;
1428
 
                        return 1;
1429
 
                }
1430
 
                if (strcmp(option, "udp") == 0) {
1431
 
                        *protocol = IPPROTO_UDP;
1432
 
                        return 1;
1433
 
                }
1434
 
                return 0;
 
1469
        if (option != NULL) {
 
1470
                if (!nfs_get_proto(option, &family, protocol)) {
 
1471
                        errno = EPROTONOSUPPORT;
 
1472
                        return 0;
 
1473
                }
 
1474
                return 1;
1435
1475
        }
1436
1476
 
1437
1477
        /*
1472
1512
        return 1;
1473
1513
}
1474
1514
 
 
1515
/*
 
1516
 * Returns TRUE and fills in @family if a valid MNT protocol option
 
1517
 * is found, or FALSE if the option was specified with an invalid value
 
1518
 * or if the protocol family isn't supported. On error, errno is set.
 
1519
 */
 
1520
int nfs_mount_proto_family(struct mount_options *options,
 
1521
                                sa_family_t *family)
 
1522
{
 
1523
        unsigned long protocol;
 
1524
        char *option;
 
1525
        sa_family_t tmp_family = config_default_family;
 
1526
 
 
1527
        option = po_get(options, "mountproto");
 
1528
        if (option != NULL) {
 
1529
                if (!nfs_get_proto(option, &tmp_family, &protocol))
 
1530
                        goto out_err;
 
1531
                if (!nfs_verify_family(tmp_family))
 
1532
                        goto out_err;
 
1533
                *family = tmp_family;
 
1534
                return 1;
 
1535
        }
 
1536
 
 
1537
        /*
 
1538
         * MNT transport protocol wasn't specified.  If the NFS
 
1539
         * transport protocol was specified, derive the family
 
1540
         * from that; otherwise, return the default family for
 
1541
         * NFS.
 
1542
         */
 
1543
        return nfs_nfs_proto_family(options, family);
 
1544
out_err:
 
1545
        errno = EAFNOSUPPORT;
 
1546
        return 0;
 
1547
}
 
1548
 
1475
1549
/**
1476
1550
 * nfs_options2pmap - set up pmap structs based on mount options
1477
1551
 * @options: pointer to mount options