]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: head acls target can be quoted
authorYehuda Sadeh <yehuda@inktank.com>
Tue, 11 Jun 2013 04:58:02 +0000 (21:58 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Tue, 11 Jun 2013 04:58:02 +0000 (21:58 -0700)
when passing x-amz-grant-* headers, the target (id, email,
group) may be quoted.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_acl_s3.cc
src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_rest_s3.cc

index 4f26dda7d202d1682f71ac32c34dbfcc320738a7..4c04e8c69e9aeebdf2bf9504c581f46c23893f59 100644 (file)
@@ -280,16 +280,18 @@ static const char *get_acl_header(RGWEnv *env,
 static int parse_grantee_str(RGWRados *store, string& grantee_str,
         const struct s3_acl_header *perm, ACLGrant& grant)
 {
-  string id_type, id_val;
+  string id_type, id_val_quoted;
   int rgw_perm = perm->rgw_perm;
   int ret;
 
   RGWUserInfo info;
 
-  ret = parse_key_value(grantee_str, id_type, id_val);
+  ret = parse_key_value(grantee_str, id_type, id_val_quoted);
   if (ret < 0)
     return ret;
 
+  string id_val = rgw_trim_quotes(id_val_quoted);
+
   if (strcasecmp(id_type.c_str(), "emailAddress") == 0) {
     ret = rgw_get_user_info_by_email(store, id_val, info);
     if (ret < 0)
index efcf4305f00687c3a5ad567745dd65b015a55acc..1a1b974cbec701a85b9ef068d07e5544ea6a7b94 100644 (file)
@@ -667,6 +667,55 @@ bool url_decode(string& src_str, string& dest_str)
   return true;
 }
 
+string rgw_trim_whitespace(const string& src)
+{
+  if (src.empty()) {
+    return string();
+  }
+
+  int start = 0;
+  for (; start != (int)src.size(); start++) {
+    if (!isspace(src[start]))
+      break;
+  }
+
+  int end = src.size() - 1;
+  if (end <= start) {
+    return string();
+  }
+
+  for (; end > start; end--) {
+    if (!isspace(src[end]))
+      break;
+  }
+
+  return src.substr(start, end - start + 1);
+}
+
+string rgw_trim_quotes(const string& val)
+{
+  string s = rgw_trim_whitespace(val);
+  if (s.size() < 2)
+    return s;
+
+  int start = 0;
+  int end = s.size() - 1;
+  int quotes_count = 0;
+
+  if (s[start] == '"') {
+    start++;
+    quotes_count++;
+  }
+  if (s[end] == '"') {
+    end--;
+    quotes_count++;
+  }
+  if (quotes_count == 2) {
+    return s.substr(start, end - start + 1);
+  }
+  return s;
+}
+
 static struct {
   const char *type_name;
   uint32_t perm;
index 219fb504f2c9a82ce83621c797d168c2ac0a046a..d3792060eafdf976cf22d6933b7092493dbe34cf 100644 (file)
@@ -1126,6 +1126,9 @@ extern int parse_time(const char *time_str, time_t *time);
 extern bool parse_rfc2616(const char *s, struct tm *t);
 extern bool parse_iso8601(const char *s, struct tm *t);
 extern int parse_date(const string& date, uint64_t *epoch, string *out_date = NULL, string *out_time = NULL);
+extern string rgw_trim_whitespace(const string& src);
+extern string rgw_trim_quotes(const string& val);
+
 
 /** Check if the req_state's user has the necessary permissions
  * to do the requested action */
index 07cd55718fdba8f2f6bd2d4054c46ca86df9d7f0..831959f25478069ddcc3433c2b93e7a321f5cf3a 100644 (file)
@@ -484,55 +484,6 @@ void RGWPutObj_ObjStore_S3::send_response()
   end_header(s);
 }
 
-string trim_whitespace(const string& src)
-{
-  if (src.empty()) {
-    return string();
-  }
-
-  int start = 0;
-  for (; start != (int)src.size(); start++) {
-    if (!isspace(src[start]))
-      break;
-  }
-
-  int end = src.size() - 1;
-  if (end <= start) {
-    return string();
-  }
-
-  for (; end > start; end--) {
-    if (!isspace(src[end]))
-      break;
-  }
-
-  return src.substr(start, end - start + 1);
-}
-
-string trim_quotes(const string& val)
-{
-  string s = trim_whitespace(val);
-  if (s.size() < 2)
-    return s;
-
-  int start = 0;
-  int end = s.size() - 1;
-  int quotes_count = 0;
-
-  if (s[start] == '"') {
-    start++;
-    quotes_count++;
-  }
-  if (s[end] == '"') {
-    end--;
-    quotes_count++;
-  }
-  if (quotes_count == 2) {
-    return s.substr(start, end - start + 1);
-  }
-  return s;
-}
-
 /*
  * parses params in the format: 'first; param1=foo; param2=bar'
  */
@@ -540,11 +491,11 @@ static void parse_params(const string& params_str, string& first, map<string, st
 {
   int pos = params_str.find(';');
   if (pos < 0) {
-    first = trim_whitespace(params_str);
+    first = rgw_trim_whitespace(params_str);
     return;
   }
 
-  first = trim_whitespace(params_str.substr(0, pos));
+  first = rgw_trim_whitespace(params_str.substr(0, pos));
 
   pos++;
 
@@ -557,11 +508,11 @@ static void parse_params(const string& params_str, string& first, map<string, st
 
     int eqpos = param.find('=');
     if (eqpos > 0) {
-      string param_name = trim_whitespace(param.substr(0, eqpos));
-      string val = trim_quotes(param.substr(eqpos + 1));
+      string param_name = rgw_trim_whitespace(param.substr(0, eqpos));
+      string val = rgw_trim_quotes(param.substr(eqpos + 1));
       params[param_name] = val;
     } else {
-      params[trim_whitespace(param)] = "";
+      params[rgw_trim_whitespace(param)] = "";
     }
 
     pos = end + 1;
@@ -739,7 +690,7 @@ int RGWPostObj_ObjStore_S3::read_form_part_header(struct post_form_part *part,
   /*
    * iterate through fields
    */
-    string line = trim_whitespace(string(bl.c_str(), bl.length()));
+    string line = rgw_trim_whitespace(string(bl.c_str(), bl.length()));
 
     if (line.empty())
       break;
@@ -774,7 +725,7 @@ bool RGWPostObj_ObjStore_S3::part_str(const string& name, string *val)
 
   bufferlist& data = iter->second.data;
   string str = string(data.c_str(), data.length());
-  *val = trim_whitespace(str);
+  *val = rgw_trim_whitespace(str);
   return true;
 }