bool arraying = false;
bool objecting = false;
+ bool cond_ifexists = false;
void reset();
}
bool ParseState::key(const char* s, size_t l) {
- auto k = pp->tokens.lookup(s, l);
+ auto token_len = l;
+ bool ifexists = false;
+ if (w->id == TokenID::Condition && w->kind == TokenKind::statement) {
+ static constexpr char IfExists[] = "IfExists";
+ if (boost::algorithm::ends_with(boost::string_view{s, l}, IfExists)) {
+ ifexists = true;
+ token_len -= sizeof(IfExists)-1;
+ }
+ }
+ auto k = pp->tokens.lookup(s, token_len);
if (!k) {
if (w->kind == TokenKind::cond_op) {
auto& t = pp->policy.statements.back();
pp->s.emplace_back(pp, cond_key);
- t.conditions.emplace_back(w->id, s, l);
+ t.conditions.emplace_back(w->id, s, l, cond_ifexists);
return true;
} else {
return false;
} else if ((w->id == TokenID::Condition) &&
(k->kind == TokenKind::cond_op)) {
pp->s.emplace_back(pp, k);
+ pp->s.back().cond_ifexists = ifexists;
return true;
}
return false;
#include "fnmatch.h"
+#include "rgw_acl.h"
#include "rgw_basic_types.h"
#include "rgw_iam_policy_keywords.h"
std::vector<std::string> vals;
Condition() = default;
- Condition(TokenID op, const char* s, std::size_t len) : op(op) {
- static constexpr char ifexistr[] = "IfExists";
- auto l = static_cast<const char*>(memmem(static_cast<const void*>(s), len,
- static_cast<const void*>(ifexistr),
- sizeof(ifexistr) -1));
- if (l && ((l + sizeof(ifexistr) - 1 == (s + len)))) {
- ifexists = true;
- key.assign(s, static_cast<const char*>(l) - s);
- } else {
- key.assign(s, len);
- }
- }
+ Condition(TokenID op, const char* s, std::size_t len, bool ifexists)
+ : op(op), key(s, len), ifexists(ifexists) {}
bool eval(const Environment& e) const;