]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: fix the bug of rgw not doing necessary checking to website configuration
authorEnming Zhang <enming.zhang@umcloud.com>
Fri, 5 Jul 2019 15:09:22 +0000 (08:09 -0700)
committerEnming Zhang <enming.zhang@umcloud.com>
Fri, 5 Jul 2019 15:22:44 +0000 (08:22 -0700)
Fixes: http://tracker.ceph.com/issues/40678
Signed-off-by: Enming Zhang <enming.zhang@umcloud.com>
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_website.h
src/rgw/rgw_xml_enc.cc

index bce2ca9457698f0c394b48799762129508b84328..42983890eab2f6a8cad56398ab8031caf70ca128 100644 (file)
@@ -1400,6 +1400,21 @@ int RGWSetBucketWebsite_ObjStore_S3::get_params()
     return -EINVAL;
   }
 
+  if (website_conf.is_redirect_all && website_conf.redirect_all.hostname.empty()) {
+    s->err.message = "A host name must be provided to redirect all requests (e.g. \"example.com\").";
+    ldout(s->cct, 5) << s->err.message << dendl;
+    return -EINVAL;
+  } else if (!website_conf.is_redirect_all && !website_conf.is_set_index_doc) {
+    s->err.message = "A value for IndexDocument Suffix must be provided if RedirectAllRequestsTo is empty";
+    ldout(s->cct, 5) << s->err.message << dendl;
+    return -EINVAL;
+  } else if (!website_conf.is_redirect_all && website_conf.is_set_index_doc &&
+             website_conf.index_doc_suffix.empty()) {
+    s->err.message = "The IndexDocument Suffix is not well formed";
+    ldout(s->cct, 5) << s->err.message << dendl;
+    return -EINVAL;
+  }
+
 #define WEBSITE_ROUTING_RULES_MAX_NUM      50
   int max_num = s->cct->_conf->rgw_website_routing_rules_max_num;
   if (max_num < 0) {
index fb6a2d4d9468a0c5176927323f4bfe9abb2adc5e..b423b630c34ef7f52e4e5835e68ee492c612b7ae 100644 (file)
@@ -182,10 +182,14 @@ struct RGWBucketWebsiteConf
   std::string subdir_marker;
   std::string listing_css_doc;
   bool listing_enabled;
+  bool is_redirect_all;
+  bool is_set_index_doc;
   RGWBWRoutingRules routing_rules;
 
   RGWBucketWebsiteConf()
     : listing_enabled(false) {
+    is_redirect_all = false;
+    is_set_index_doc = false;
   }
 
   void encode(bufferlist& bl) const {
index 44a9364b8028b027afeb3c8136683c42de34284e..1b9d250a7a6ccde07132a40d91e52b37cc4dfd60 100644 (file)
@@ -116,11 +116,13 @@ void decode_xml_obj(list<RGWBWRoutingRule>& l, XMLObj *obj)
 void RGWBucketWebsiteConf::decode_xml(XMLObj *obj) {
   XMLObj *o = obj->find_first("RedirectAllRequestsTo");
   if (o) {
+    is_redirect_all = true;
     RGWXMLDecoder::decode_xml("HostName", redirect_all.hostname, o, true);
     RGWXMLDecoder::decode_xml("Protocol", redirect_all.protocol, o);
   } else {
     o = obj->find_first("IndexDocument");
     if (o) {
+      is_set_index_doc = true;
       RGWXMLDecoder::decode_xml("Suffix", index_doc_suffix, o);
     }
     o = obj->find_first("ErrorDocument");