X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fmount%2Fconfigfile.c;h=6f2ee75f11c9c159124f2127914c819f12c9bacf;hp=e347b0ebcaf3fed77f86b873c25a3e77b6bd5ec7;hb=9a5293a10551c03b4fb976503dd24da569fcadb3;hpb=8414d150cee62ba0554cfd645956a88dba02a7eb diff --git a/utils/mount/configfile.c b/utils/mount/configfile.c index e347b0e..6f2ee75 100644 --- a/utils/mount/configfile.c +++ b/utils/mount/configfile.c @@ -20,13 +20,19 @@ #include #endif #include +#include +#include #include #include #include #include +#include #include "xlog.h" +#include "mount.h" +#include "parse_opt.h" +#include "network.h" #include "conffile.h" #define KBYTES(x) ((x) * (1024)) @@ -185,6 +191,87 @@ void free_all(void) free(entry); } } +static char *versions[] = {"v2", "v3", "v4", "vers", "nfsvers", NULL}; +static int +check_vers(char *mopt, char *field) +{ + int i, found=0; + + /* + * First check to see if the config setting is one + * of the many version settings + */ + for (i=0; versions[i]; i++) { + if (strcasestr(field, versions[i]) != NULL) { + found++; + break; + } + } + if (!found) + return 0; + /* + * It appears the version is being set, now see + * if the version appears on the command + */ + for (i=0; versions[i]; i++) { + if (strcasestr(mopt, versions[i]) != NULL) + return 1; + } + + return 0; +} + +unsigned long config_default_vers; +unsigned long config_default_proto; +extern sa_family_t config_default_family; + +/* + * Check to see if a default value is being set. + * If so, set the appropriate global value which will + * be used as the initial value in the server negation. + */ +static int +default_value(char *mopt) +{ + struct mount_options *options = NULL; + int dftlen = strlen("default"); + char *field; + + if (strncasecmp(mopt, "default", dftlen) != 0) + return 0; + + field = mopt + dftlen; + if (strncasecmp(field, "proto", strlen("proto")) == 0) { + if ((options = po_split(field)) != NULL) { + if (!nfs_nfs_protocol(options, &config_default_proto)) { + xlog_warn("Unable to set default protocol : %s", + strerror(errno)); + } + if (!nfs_nfs_proto_family(options, &config_default_family)) { + xlog_warn("Unable to set default family : %s", + strerror(errno)); + } + } else { + xlog_warn("Unable to alloc memory for default protocol"); + } + } else if (strncasecmp(field, "vers", strlen("vers")) == 0) { + if ((options = po_split(field)) != NULL) { + if (!nfs_nfs_version(options, &config_default_vers)) { + xlog_warn("Unable to set default version: %s", + strerror(errno)); + + } + } else { + xlog_warn("Unable to alloc memory for default version"); + } + } else + xlog_warn("Invalid default setting: '%s'", mopt); + + if (options) + po_destroy(options); + + return 1; +} /* * Parse the given section of the configuration * file to if there are any mount options set. @@ -207,6 +294,12 @@ conf_parse_mntopts(char *section, char *arg, char *opts) snprintf(buf, BUFSIZ, "%s=", node->field); if (opts && strcasestr(opts, buf) != NULL) continue; + /* + * Protocol verions can be set in a number of ways + */ + if (opts && check_vers(opts, node->field)) + continue; + if (lookup_entry(node->field) != NULL) continue; buf[0] = '\0'; @@ -302,15 +395,19 @@ char *conf_get_mntopts(char *spec, char *mount_point, free_all(); return mount_opts; } + if (mount_opts) { strcpy(config_opts, mount_opts); strcat(config_opts, ","); } SLIST_FOREACH(entry, &head, entries) { + if (default_value(entry->opt)) + continue; strcat(config_opts, entry->opt); strcat(config_opts, ","); } - *(strrchr(config_opts, ',')) = '\0'; + if ((ptr = strrchr(config_opts, ',')) != NULL) + *ptr = '\0'; free_all(); if (mount_opts)