From bf333d8e432d9bfac61a2c5f5dfd4341aee4ca8e Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Tue, 2 Oct 2012 14:17:13 -0700 Subject: [PATCH] OSDCap: allow runs of spaces anywhere I couldn't find a way to do this with skip parsers, so these are explicitly included in the grammar. Signed-off-by: Josh Durgin --- src/osd/OSDCap.cc | 25 ++++++++++++++++--------- src/test/osd/osdcap.cc | 11 ++++++----- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/osd/OSDCap.cc b/src/osd/OSDCap.cc index e47effc99d890..0831e85b52f07 100644 --- a/src/osd/OSDCap.cc +++ b/src/osd/OSDCap.cc @@ -145,18 +145,22 @@ struct OSDCapParser : qi::grammar unquoted_word %= +(alnum | '_' | '-'); str %= quoted_string | unquoted_word; + spaces = +lit(' '); + // match := [pool[=] | auid <123>] [object_prefix ] - pool_name %= -(lit(" pool") >> (lit('=') | lit(' ')) >> str); - object_prefix %= -(lit(" object_prefix ") >> str); - match = ( (lit(" auid ") >> int_ >> object_prefix)[_val = phoenix::construct(_1, _2)] | + pool_name %= -(spaces >> lit("pool") >> (lit('=') | spaces) >> str); + auid %= (spaces >> lit("auid") >> spaces >> int_); + object_prefix %= -(spaces >> lit("object_prefix") >> spaces >> str); + + match = ( (auid >> object_prefix) [_val = phoenix::construct(_1, _2)] | (pool_name >> object_prefix) [_val = phoenix::construct(_1, _2)]); // rwxa := * | [r][w][x] rwxa = - lit(" *")[_val = OSD_CAP_ANY] | + (spaces >> lit("*")[_val = OSD_CAP_ANY]) | ( eps[_val = 0] >> ( - lit(' ') >> + spaces >> ( lit('r')[_val |= OSD_CAP_R] || lit('w')[_val |= OSD_CAP_W] || lit('x')[_val |= OSD_CAP_X] ))); @@ -164,21 +168,24 @@ struct OSDCapParser : qi::grammar // capspec := * | rwx | class [classcap] capspec = rwxa [_val = phoenix::construct(_1)] | - ( lit(" class ") >> ((str >> lit(' ') >> str) [_val = phoenix::construct(_1, _2)] | + ( spaces >> lit("class") >> spaces >> ((str >> spaces >> str) [_val = phoenix::construct(_1, _2)] | str [_val = phoenix::construct(_1, string())] )); // grant := allow match capspec - grant = lit("allow") >> ((capspec >> match) [_val = phoenix::construct(_2, _1)] | - (match >> capspec) [_val = phoenix::construct(_1, _2)]); - + grant = (*lit(' ') >> lit("allow") >> + ((capspec >> match) [_val = phoenix::construct(_2, _1)] | + (match >> capspec) [_val = phoenix::construct(_1, _2)]) >> + *lit(' ')); // osdcap := grant [grant ...] grants %= (grant % (*lit(' ') >> (lit(';') | lit(',')) >> *lit(' '))); osdcap = grants [_val = phoenix::construct(_1)]; } + qi::rule spaces; qi::rule rwxa; qi::rule quoted_string; qi::rule unquoted_word; qi::rule str; + qi::rule auid; qi::rule capspec; qi::rule pool_name; qi::rule object_prefix; diff --git a/src/test/osd/osdcap.cc b/src/test/osd/osdcap.cc index 3088e05952e46..ad2f6a3997995 100644 --- a/src/test/osd/osdcap.cc +++ b/src/test/osd/osdcap.cc @@ -47,6 +47,12 @@ const char *parse_good[] = { "allow pool data rw, allow pool rbd rwx, allow pool images class rbd foo", "allow class foo", "allow class clsname \"clsthingidon'tunderstand\"", + " allow rwx pool foo; allow r pool bar ", + " allow rwx pool foo; allow r pool bar ", + " allow pool foo rwx; allow pool bar r ", + " allow pool foo rwx; allow pool bar r ", + " allow wx pool taco", + "allow r pool foo object_prefix blah ; allow w auid 5", 0 }; @@ -60,11 +66,6 @@ TEST(OSDCap, ParseGood) { } const char *parse_bad[] = { - " allow rwx pool foo; allow r pool bar ", - " allow rwx pool foo; allow r pool bar ", - " allow pool foo rwx; allow pool bar r ", - " allow pool foo rwx; allow pool bar r ", - " allow wx pool taco", "allow r poolfoo", "allow r w", "ALLOW r", -- 2.39.5