X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fmount%2Fstropts.c;h=627031215a9c286ab76c0ff245722ea5f8105bd8;hp=e3a3ac941d322c55950f7347a0b3f26154d71941;hb=ba0c5b3b8a635ce671778b630787bce857ee81c7;hpb=8034455d1fc4e315b54d100fd8138ce4c5c08471 diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c index e3a3ac9..6270312 100644 --- a/utils/mount/stropts.c +++ b/utils/mount/stropts.c @@ -190,6 +190,53 @@ static int append_clientaddr_option(struct sockaddr_in *saddr, return 0; } +/* + * Resolve the 'mounthost=' hostname and append a new option using + * the resulting IPv4 address. + */ +static int fix_mounthost_option(struct mount_options *options) +{ + struct sockaddr_in maddr; + char *mounthost, new_option[32]; + + mounthost = po_get(options, "mounthost"); + if (!mounthost) + return 1; + + if (!fill_ipv4_sockaddr(mounthost, &maddr)) + return 0; + + snprintf(new_option, sizeof(new_option) - 1, + "mountaddr=%s", inet_ntoa(maddr.sin_addr)); + + if (po_append(options, new_option) == PO_SUCCEEDED) + return 1; + return 0; +} + +/* + * Set up mandatory mount options. + * + * Returns 1 if successful; otherwise zero. + */ +static int set_mandatory_options(const char *type, + struct sockaddr_in *saddr, + struct mount_options *options) +{ + if (!append_addr_option(saddr, options)) + return 0; + + if (strncmp(type, "nfs4", 4) == 0) { + if (!append_clientaddr_option(saddr, options)) + return 0; + } else { + if (!fix_mounthost_option(options)) + return 0; + } + + return 1; +} + /* * nfsmount_s - Mount an NFSv2 or v3 file system using C string options * @@ -227,6 +274,9 @@ int nfsmount_s(const char *spec, const char *node, int flags, if (!append_addr_option(&saddr, options)) goto out; + if (!fix_mounthost_option(options)) + goto out; + if (po_join(options, extra_opts) == PO_FAILED) { nfs_error(_("%s: internal option parsing error"), progname); goto out;