Skip to content

Commit

Permalink
renamed check_options to Nfs::Options::validate
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Dec 17, 2012
1 parent 2a4e799 commit 3354f0c
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 86 deletions.
13 changes: 12 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ myinclude_DATA = \
module_DATA = \
modules/Nfs.ycp

nfs_moduledir = @moduledir@/Nfs
nfs_module_DATA = \
modules/Nfs/Options.ycp

nfs_modulebindir = $(nfs_moduledir)
nfs_modulebin_DATA = $(patsubst %.ycp,%.ybc,$(nfs_module_DATA))

# .dep does not work with subdirs
modules/Nfs.ybc: modules/Nfs/Options.ybc

desktop_DATA = nfs.desktop

rncdir = $(schemadir)/autoyast/rnc
rnc_DATA = nfs.rnc

EXTRA_DIST = $(client_DATA) $(myinclude_DATA) $(module_DATA) $(desktop_DATA) $(rnc_DATA)
EXTRA_DIST = $(client_DATA) $(myinclude_DATA) $(module_DATA) $(nfs_module_DATA) $(desktop_DATA) $(rnc_DATA)

include $(top_srcdir)/Makefile.am.common
ybcfiles += $(filter %.ybc,$(nfs_modulebin_DATA))
5 changes: 3 additions & 2 deletions src/clients/nfs.ycp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ y2milestone ("----------------------------------------");
y2milestone ("NFS module started");

import "Nfs";
import "Nfs::Options";
import "Progress";
import "Report";
import "String";
Expand Down Expand Up @@ -86,7 +87,7 @@ boolean NfsAddHandler (map options) {
if (! haskey (options, "mntops"))
options["mntops"] = "defaults";

string options_error = check_options (options["mntops"]:"");
string options_error = Nfs::Options::validate (options["mntops"]:"");
if (size (options_error) > 0)
{
Report::Error (options_error);
Expand Down Expand Up @@ -184,7 +185,7 @@ boolean NfsEditHandler (map options) {
!CheckPath (mount) || IsMpInFstab (existing, mount))
return false;

string options_error = check_options (entry["mntops"]:"");
string options_error = Nfs::Options::validate (entry["mntops"]:"");
if (size (options_error) > 0)
{
Report::Error (options_error);
Expand Down
58 changes: 0 additions & 58 deletions src/include/nfs/routines.ycp
Original file line number Diff line number Diff line change
Expand Up @@ -149,64 +149,6 @@ and it must begin with a slash (/).")));
return false;
};

/**
* Checks the nfs options for /etc/fstab:
* nonempty, comma separated list of foo,nofoo,bar=baz (see nfs(5))
* @param options options
* @return a translated string with error message, emtpy string if ok
*/
define string check_options (string options) ``{

// To translators: error popup
if (size (options) == 0) return _("Empty option strings are not allowed.");
if (options == "defaults") return "";


list<string> option_list = splitstring (options, ",");

//the options must be easy to sync with mount.c and nfsmount.c

// these can be negated by "no"
list<string> non_value = ["bg", "fg", "soft", "hard", "intr", "posix", "cto", "ac", "acl",
"lock", "tcp", "udp", "rdirplus",
// these are common for all fs types
"atime", "auto", "dev", "exec", "group", "owner",
"suid", "user", "users"];
// these cannot be negated
// they are not nfs specific BTW
list non_value1 = ["defaults", "async", "sync", "dirsync", "ro", "rw",
"remount", "bind", "rbind", "_netdev", ];
list with_value = ["rsize", "wsize", "timeo", "retrans", "acregmin", "acregmax",
"acdirmin", "acdirmin", "acdirmax", "actimeo", "retry", "namlen",
"port", "proto", "clientaddr", "mountport", "mounthost",
"mountprog", "mountvers", "nfsprog", "nfsvers", "vers", "sec" ];
integer i = 0;
string current_option = "";

// first fiter out non value options and its nooptions forms (see nfs(5))
option_list = filter (string e, option_list, ``(!contains (non_value, e)));
non_value = maplist (string e, non_value, ``(sformat ("no%1", e)));
option_list = filter (string e, option_list, ``(!contains (non_value, e)));
option_list = filter (string e, option_list, ``(!contains (non_value1, e)));

while (i < size (option_list))
{
string opt = option_list[i]:"";
list<string> value = splitstring (opt, "=");
string v0 = value[0]:"";
string v1 = value[1]:"";
// FIXME: this also triggers for "intr=bogus"
// To translators: error popup
if (!contains (with_value, v0)) return sformat (_("Unknown option: %1"), v0);
// To translators: error popup
if (size (value) != 2) return sformat (_("Invalid option: %1"), opt);
// To translators: error popup
if (v1 == "") return sformat (_("Empty value for option: %1"), v0);
i = i + 1;
}

return "";
}

/**
* Strips a superfluous slash off the end of a pathname.
Expand Down
3 changes: 2 additions & 1 deletion src/include/nfs/ui.ycp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import "FileUtils";
import "Label";
import "Nfs";
import "Nfs::Options";
import "Popup";
import "SuSEFirewall";
import "Wizard";
Expand Down Expand Up @@ -376,7 +377,7 @@ which probably blocks the network scanning.");
options = deletechars ((string) UI::QueryWidget(`id(`optionsent), `Value), " ");

ret = nil;
string options_error = check_options (options);
string options_error = Nfs::Options::validate (options);
if (!CheckHostName (server))
{
UI::SetFocus (`id (`serverent));
Expand Down
3 changes: 2 additions & 1 deletion src/modules/Nfs.ycp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import "FileUtils";
import "Mode";
import "Nfs::Options";
import "Report";
import "Service";
import "Summary";
Expand Down Expand Up @@ -477,7 +478,7 @@ the NFS client configuration.\n"));
// check if options are valid
if (size(options) > 0)
{
if (check_options(options) != "")
if (Nfs::Options::validate(options) != "")
{
y2warning("invalid mount options: %1", options);
return nil;
Expand Down
66 changes: 66 additions & 0 deletions src/modules/Nfs/Options.ycp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{

module "Nfs::Options";
textdomain "nfs";

/**
* Checks the nfs options for /etc/fstab:
* nonempty, comma separated list of foo,nofoo,bar=baz (see nfs(5))
* @param options options
* @return a translated string with error message, emtpy string if ok
*/
global define string validate (string options) {
// To translators: error popup
if (size (options) == 0) return _("Empty option strings are not allowed.");
if (options == "defaults") return "";


list<string> option_list = splitstring (options, ",");

//the options must be easy to sync with mount.c and nfsmount.c

// these can be negated by "no"
list<string> non_value = ["bg", "fg", "soft", "hard", "intr", "posix", "cto", "ac", "acl",
"lock", "tcp", "udp", "rdirplus",
// these are common for all fs types
"atime", "auto", "dev", "exec", "group", "owner",
"suid", "user", "users"];
// these cannot be negated
// they are not nfs specific BTW
list non_value1 = ["defaults", "async", "sync", "dirsync", "ro", "rw",
"remount", "bind", "rbind", "_netdev", ];
list with_value = ["rsize", "wsize", "timeo", "retrans", "acregmin", "acregmax",
"acdirmin", "acdirmin", "acdirmax", "actimeo", "retry", "namlen",
"port", "proto", "clientaddr", "mountport", "mounthost",
"mountprog", "mountvers", "nfsprog", "nfsvers", "vers",
"sec" ];
integer i = 0;
string current_option = "";

// first fiter out non value options and its nooptions forms (see nfs(5))
option_list = filter (string e, option_list, ``(!contains (non_value, e)));
non_value = maplist (string e, non_value, ``(sformat ("no%1", e)));
option_list = filter (string e, option_list, ``(!contains (non_value, e)));
option_list = filter (string e, option_list, ``(!contains (non_value1, e)));

while (i < size (option_list))
{
string opt = option_list[i]:"";
list<string> value = splitstring (opt, "=");
string v0 = value[0]:"";
string v1 = value[1]:"";
// FIXME: this also triggers for "intr=bogus"
// To translators: error popup
if (!contains (with_value, v0)) return sformat (_("Unknown option: %1"), v0);
// To translators: error popup
if (size (value) != 2) return sformat (_("Invalid option: %1"), opt);
// To translators: error popup
if (v1 == "") return sformat (_("Empty value for option: %1"), v0);
i = i + 1;
}

return "";
}

/*EOF*/
}
Empty file added testsuite/tests/nfs-options.err
Empty file.
11 changes: 11 additions & 0 deletions testsuite/tests/nfs-options.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Dump Nfs::Options::validate
Return Empty option strings are not allowed.
Return
Return
Return
Return
Return Unknown option: bg
Return Unknown option: unknownoption
Return Unknown option: unknownassignment
Return Empty value for option: rsize
Return Unknown option: two
16 changes: 16 additions & 0 deletions testsuite/tests/nfs-options.ycp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
include "testsuite.ycp";
import "Nfs::Options";

DUMP ("Nfs::Options::validate");
TEST (``(Nfs::Options::validate ("")), [], nil);
TEST (``(Nfs::Options::validate ("defaults")), [], nil);
TEST (``(Nfs::Options::validate ("nolock,bg")), [], nil);
TEST (``(Nfs::Options::validate ("nolock,nobg")), [], nil);
TEST (``(Nfs::Options::validate ("nolock,rsize=8192")), [], nil);
TEST (``(Nfs::Options::validate ("nolock, bg")), [], nil);
TEST (``(Nfs::Options::validate ("nolock,unknownoption")), [], nil);
TEST (``(Nfs::Options::validate ("nolock,unknownassignment=true")), [], nil);
TEST (``(Nfs::Options::validate ("nolock,rsize=")), [], nil);
TEST (``(Nfs::Options::validate ("nolock,two=equal=signs")), [], nil);
}
11 changes: 0 additions & 11 deletions testsuite/tests/r-check.out
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
Dump check_options
Return Empty option strings are not allowed.
Return
Return
Return
Return
Return Unknown option: bg
Return Unknown option: unknownoption
Return Unknown option: unknownassignment
Return Empty value for option: rsize
Return Unknown option: two
Dump CheckHostName
Return true
Return false
Expand Down
12 changes: 0 additions & 12 deletions testsuite/tests/r-check.ycp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@
string IPv6_link_local_ib = "[fe80::3%eth0]";
string IPv6_link_local_invalid = "[fe80::3%]";

DUMP ("check_options");
TEST (``(check_options ("")), [], nil);
TEST (``(check_options ("defaults")), [], nil);
TEST (``(check_options ("nolock,bg")), [], nil);
TEST (``(check_options ("nolock,nobg")), [], nil);
TEST (``(check_options ("nolock,rsize=8192")), [], nil);
TEST (``(check_options ("nolock, bg")), [], nil);
TEST (``(check_options ("nolock,unknownoption")), [], nil);
TEST (``(check_options ("nolock,unknownassignment=true")), [], nil);
TEST (``(check_options ("nolock,rsize=")), [], nil);
TEST (``(check_options ("nolock,two=equal=signs")), [], nil);

DUMP ("CheckHostName");
TEST (``(CheckHostName (OK_Name)), [], nil);
TEST (``(CheckHostName (TooLongName)), [], nil);
Expand Down
3 changes: 3 additions & 0 deletions yast2-nfs-client.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Summary: Configuration of nfs
%dir @moduledir@
@moduledir@/Nfs.ycp
@moduledir@/Nfs.ybc
%dir @moduledir@/Nfs
@moduledir@/Nfs/Options.ycp
@moduledir@/Nfs/Options.ybc
%dir @desktopdir@
@desktopdir@/nfs.desktop
%doc @docdir@
Expand Down

0 comments on commit 3354f0c

Please sign in to comment.