summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2012-10-10 16:16:01 -0700
committerYehuda Sadeh <yehuda@inktank.com>2012-10-23 10:43:09 -0700
commit846bb34335f2069eaf911609399ffbd4f5c5d97b (patch)
tree5166226bda0dcb57a7bb931d4a44d7b5b7f39034
parent391775b78e5c5e6ab6262a0ac0765160189c246b (diff)
downloadceph-846bb34335f2069eaf911609399ffbd4f5c5d97b.tar.gz
rgw: handle policy as case insensitive where required
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r--src/Makefile.am1
-rw-r--r--src/rgw/rgw_policy_s3.cc15
-rw-r--r--src/rgw/rgw_policy_s3.h10
-rw-r--r--src/rgw/rgw_rest_s3.cc2
-rw-r--r--src/rgw/rgw_rest_s3.h8
-rw-r--r--src/rgw/rgw_string.h27
6 files changed, 42 insertions, 21 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 5754c94da0f..58ca3ffbb66 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1758,6 +1758,7 @@ noinst_HEADERS = \
rgw/rgw_json.h\
rgw/rgw_cache.h\
rgw/rgw_common.h\
+ rgw/rgw_string.h\
rgw/rgw_formats.h\
rgw/rgw_html_errors.h\
rgw/rgw_log.h\
diff --git a/src/rgw/rgw_policy_s3.cc b/src/rgw/rgw_policy_s3.cc
index 05cb3469f01..b0fc78524b2 100644
--- a/src/rgw/rgw_policy_s3.cc
+++ b/src/rgw/rgw_policy_s3.cc
@@ -3,7 +3,6 @@
#include "rgw_policy_s3.h"
#include "rgw_json.h"
-
#include "rgw_common.h"
@@ -25,7 +24,7 @@ public:
v2 = _v2;
}
- bool check(RGWPolicyEnv *env, map<string, bool>& checked_vars) {
+ bool check(RGWPolicyEnv *env, map<string, bool, ltstr_nocase>& checked_vars) {
string first, second;
env->get_value(v1, first, checked_vars);
env->get_value(v2, second, checked_vars);
@@ -58,7 +57,7 @@ void RGWPolicyEnv::add_var(const string& name, const string& value)
bool RGWPolicyEnv::get_var(const string& name, string& val)
{
- map<string, string>::iterator iter = vars.find(name);
+ map<string, string, ltstr_nocase>::iterator iter = vars.find(name);
if (iter == vars.end())
return false;
@@ -67,7 +66,7 @@ bool RGWPolicyEnv::get_var(const string& name, string& val)
return true;
}
-bool RGWPolicyEnv::get_value(const string& s, string& val, map<string, bool>& checked_vars)
+bool RGWPolicyEnv::get_value(const string& s, string& val, map<string, bool, ltstr_nocase>& checked_vars)
{
if (s.empty() || s[0] != '$') {
val = s;
@@ -81,9 +80,9 @@ bool RGWPolicyEnv::get_value(const string& s, string& val, map<string, bool>& ch
}
-bool RGWPolicyEnv::match_policy_vars(map<string, bool>& policy_vars)
+bool RGWPolicyEnv::match_policy_vars(map<string, bool, ltstr_nocase>& policy_vars)
{
- map<string, string>::iterator iter;
+ map<string, string, ltstr_nocase>::iterator iter;
string ignore_prefix = "x-ignore-";
for (iter = vars.begin(); iter != vars.end(); ++iter) {
const string& var = iter->first;
@@ -109,9 +108,9 @@ RGWPolicy::~RGWPolicy()
int RGWPolicy::add_condition(const string& op, const string& first, const string& second)
{
RGWPolicyCondition *cond = NULL;
- if (op.compare("eq") == 0)
+ if (stringcasecmp(op, "eq") == 0)
cond = new RGWPolicyCondition_StrEqual;
- else if (op.compare("starts-with") == 0)
+ else if (stringcasecmp(op, "starts-with") == 0)
cond = new RGWPolicyCondition_StrStartsWith;
if (!cond)
diff --git a/src/rgw/rgw_policy_s3.h b/src/rgw/rgw_policy_s3.h
index 2a8e75407e3..97cb3ed6a61 100644
--- a/src/rgw/rgw_policy_s3.h
+++ b/src/rgw/rgw_policy_s3.h
@@ -7,15 +7,17 @@
#include "include/utime.h"
+#include "rgw_string.h"
+
class RGWPolicyEnv {
- std::map<std::string, std::string> vars;
+ std::map<std::string, std::string, ltstr_nocase> vars;
public:
void add_var(const string& name, const string& value);
bool get_var(const string& name, string& val);
- bool get_value(const string& s, string& val, std::map<std::string, bool>& checked_vars);
- bool match_policy_vars(map<string, bool>& policy_vars);
+ bool get_value(const string& s, string& val, std::map<std::string, bool, ltstr_nocase>& checked_vars);
+ bool match_policy_vars(map<string, bool, ltstr_nocase>& policy_vars);
};
class RGWPolicyCondition;
@@ -25,7 +27,7 @@ class RGWPolicy {
utime_t expires;
std::list<RGWPolicyCondition *> conditions;
std::list<pair<std::string, std::string> > var_checks;
- std::map<std::string, bool> checked_vars;
+ std::map<std::string, bool, ltstr_nocase> checked_vars;
public:
RGWPolicy() {}
diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc
index ec8b711c87d..5e8ed449fed 100644
--- a/src/rgw/rgw_rest_s3.cc
+++ b/src/rgw/rgw_rest_s3.cc
@@ -738,7 +738,7 @@ int RGWPostObj_ObjStore_S3::get_params()
if (done) /* unexpected here */
return -EINVAL;
- if (part.name.compare("file") == 0) { /* beginning of data transfer */
+ if (stringcasecmp(part.name, "file") == 0) { /* beginning of data transfer */
parts[part.name] = part;
data_pending = true;
break;
diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h
index 6839c8928cc..c6cb3a4766f 100644
--- a/src/rgw/rgw_rest_s3.h
+++ b/src/rgw/rgw_rest_s3.h
@@ -94,14 +94,6 @@ struct post_form_part {
bufferlist data;
};
-struct ltstr_nocase
-{
- bool operator()(const string& s1, const string& s2)
- {
- return strcasecmp(s1.c_str(), s2.c_str()) < 0;
- }
-};
-
class RGWPostObj_ObjStore_S3 : public RGWPostObj_ObjStore {
string boundary;
bufferlist in_data;
diff --git a/src/rgw/rgw_string.h b/src/rgw/rgw_string.h
new file mode 100644
index 00000000000..bbd2c67b6c9
--- /dev/null
+++ b/src/rgw/rgw_string.h
@@ -0,0 +1,27 @@
+#ifndef CEPH_RGW_STRING_H
+#define CEPH_RGW_STRING_H
+
+struct ltstr_nocase
+{
+ bool operator()(const string& s1, const string& s2) const
+ {
+ return strcasecmp(s1.c_str(), s2.c_str()) < 0;
+ }
+};
+
+static inline int stringcasecmp(const string& s1, const string& s2)
+{
+ return strcasecmp(s1.c_str(), s2.c_str());
+}
+
+static inline int stringcasecmp(const string& s1, const char *s2)
+{
+ return strcasecmp(s1.c_str(), s2);
+}
+
+static inline int stringcasecmp(const string& s1, int ofs, int size, const string& s2)
+{
+ return strncasecmp(s1.c_str() + ofs, s2.c_str(), size);
+}
+
+#endif