]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #include <boost/algorithm/string/predicate.hpp> | |
5 | #include <boost/optional.hpp> | |
6 | #include <boost/utility/in_place_factory.hpp> | |
7 | ||
8 | #include "include/assert.h" | |
9 | #include "ceph_ver.h" | |
10 | ||
11 | #include "common/Formatter.h" | |
12 | #include "common/utf8.h" | |
13 | #include "common/ceph_json.h" | |
14 | ||
15 | #include "rgw_rest_swift.h" | |
16 | #include "rgw_acl_swift.h" | |
17 | #include "rgw_cors_swift.h" | |
18 | #include "rgw_formats.h" | |
19 | #include "rgw_client_io.h" | |
20 | ||
21 | #include "rgw_auth.h" | |
22 | #include "rgw_swift_auth.h" | |
23 | ||
24 | #include "rgw_request.h" | |
25 | #include "rgw_process.h" | |
26 | ||
27 | #include <array> | |
28 | #include <sstream> | |
29 | #include <memory> | |
30 | ||
31 | #include <boost/utility/string_ref.hpp> | |
32 | ||
33 | #define dout_context g_ceph_context | |
34 | #define dout_subsys ceph_subsys_rgw | |
35 | ||
36 | int RGWListBuckets_ObjStore_SWIFT::get_params() | |
37 | { | |
38 | prefix = s->info.args.get("prefix"); | |
39 | marker = s->info.args.get("marker"); | |
40 | end_marker = s->info.args.get("end_marker"); | |
41 | ||
42 | string limit_str = s->info.args.get("limit"); | |
43 | if (!limit_str.empty()) { | |
44 | string err; | |
45 | long l = strict_strtol(limit_str.c_str(), 10, &err); | |
46 | if (!err.empty()) { | |
47 | return -EINVAL; | |
48 | } | |
49 | ||
50 | if (l > (long)limit_max || l < 0) { | |
51 | return -ERR_PRECONDITION_FAILED; | |
52 | } | |
53 | ||
54 | limit = (uint64_t)l; | |
55 | } | |
56 | ||
224ce89b | 57 | if (s->cct->_conf->rgw_swift_need_stats) { |
7c673cae FG |
58 | bool stats, exists; |
59 | int r = s->info.args.get_bool("stats", &stats, &exists); | |
60 | ||
61 | if (r < 0) { | |
62 | return r; | |
63 | } | |
64 | ||
65 | if (exists) { | |
66 | need_stats = stats; | |
67 | } | |
224ce89b WB |
68 | } else { |
69 | need_stats = false; | |
7c673cae FG |
70 | } |
71 | ||
72 | return 0; | |
73 | } | |
74 | ||
75 | static void dump_account_metadata(struct req_state * const s, | |
76 | const uint32_t buckets_count, | |
77 | const uint64_t buckets_object_count, | |
78 | const uint64_t buckets_size, | |
79 | const uint64_t buckets_size_rounded, | |
80 | /* const */map<string, bufferlist>& attrs, | |
81 | const RGWQuotaInfo& quota, | |
82 | const RGWAccessControlPolicy_SWIFTAcct &policy) | |
83 | { | |
84 | /* Adding X-Timestamp to keep align with Swift API */ | |
85 | dump_header(s, "X-Timestamp", ceph_clock_now()); | |
86 | ||
87 | dump_header(s, "X-Account-Container-Count", buckets_count); | |
88 | dump_header(s, "X-Account-Object-Count", buckets_object_count); | |
89 | dump_header(s, "X-Account-Bytes-Used", buckets_size); | |
90 | dump_header(s, "X-Account-Bytes-Used-Actual", buckets_size_rounded); | |
91 | ||
92 | /* Dump TempURL-related stuff */ | |
93 | if (s->perm_mask == RGW_PERM_FULL_CONTROL) { | |
94 | auto iter = s->user->temp_url_keys.find(0); | |
95 | if (iter != std::end(s->user->temp_url_keys) && ! iter->second.empty()) { | |
96 | dump_header(s, "X-Account-Meta-Temp-Url-Key", iter->second); | |
97 | } | |
98 | ||
99 | iter = s->user->temp_url_keys.find(1); | |
100 | if (iter != std::end(s->user->temp_url_keys) && ! iter->second.empty()) { | |
101 | dump_header(s, "X-Account-Meta-Temp-Url-Key-2", iter->second); | |
102 | } | |
103 | } | |
104 | ||
105 | /* Dump quota headers. */ | |
106 | if (quota.enabled) { | |
107 | if (quota.max_size >= 0) { | |
108 | dump_header(s, "X-Account-Meta-Quota-Bytes", quota.max_size); | |
109 | } | |
110 | ||
111 | /* Limit on the number of objects in a given account is a RadosGW's | |
112 | * extension. Swift's account quota WSGI filter doesn't support it. */ | |
113 | if (quota.max_objects >= 0) { | |
114 | dump_header(s, "X-Account-Meta-Quota-Count", quota.max_objects); | |
115 | } | |
116 | } | |
117 | ||
118 | /* Dump user-defined metadata items and generic attrs. */ | |
119 | const size_t PREFIX_LEN = sizeof(RGW_ATTR_META_PREFIX) - 1; | |
120 | map<string, bufferlist>::iterator iter; | |
121 | for (iter = attrs.lower_bound(RGW_ATTR_PREFIX); iter != attrs.end(); ++iter) { | |
122 | const char *name = iter->first.c_str(); | |
123 | map<string, string>::const_iterator geniter = rgw_to_http_attrs.find(name); | |
124 | ||
125 | if (geniter != rgw_to_http_attrs.end()) { | |
126 | dump_header(s, geniter->second, iter->second); | |
127 | } else if (strncmp(name, RGW_ATTR_META_PREFIX, PREFIX_LEN) == 0) { | |
128 | dump_header_prefixed(s, "X-Account-Meta-", | |
129 | camelcase_dash_http_attr(name + PREFIX_LEN), | |
130 | iter->second); | |
131 | } | |
132 | } | |
133 | ||
134 | /* Dump account ACLs */ | |
224ce89b WB |
135 | auto account_acls = policy.to_str(); |
136 | if (account_acls) { | |
137 | dump_header(s, "X-Account-Access-Control", std::move(*account_acls)); | |
7c673cae FG |
138 | } |
139 | } | |
140 | ||
141 | void RGWListBuckets_ObjStore_SWIFT::send_response_begin(bool has_buckets) | |
142 | { | |
143 | if (op_ret) { | |
144 | set_req_state_err(s, op_ret); | |
145 | } else if (!has_buckets && s->format == RGW_FORMAT_PLAIN) { | |
146 | op_ret = STATUS_NO_CONTENT; | |
147 | set_req_state_err(s, op_ret); | |
148 | } | |
149 | ||
150 | if (! s->cct->_conf->rgw_swift_enforce_content_length) { | |
151 | /* Adding account stats in the header to keep align with Swift API */ | |
152 | dump_account_metadata(s, | |
153 | buckets_count, | |
154 | buckets_objcount, | |
155 | buckets_size, | |
156 | buckets_size_rounded, | |
157 | attrs, | |
158 | user_quota, | |
159 | static_cast<RGWAccessControlPolicy_SWIFTAcct&>(*s->user_acl)); | |
160 | dump_errno(s); | |
161 | end_header(s, NULL, NULL, NO_CONTENT_LENGTH, true); | |
162 | } | |
163 | ||
164 | if (! op_ret) { | |
165 | dump_start(s); | |
166 | s->formatter->open_array_section_with_attrs("account", | |
167 | FormatterAttrs("name", s->user->display_name.c_str(), NULL)); | |
168 | ||
169 | sent_data = true; | |
170 | } | |
171 | } | |
172 | ||
173 | void RGWListBuckets_ObjStore_SWIFT::send_response_data(RGWUserBuckets& buckets) | |
174 | { | |
175 | if (! sent_data) { | |
176 | return; | |
177 | } | |
178 | ||
179 | /* Take care of the prefix parameter of Swift API. There is no business | |
180 | * in applying the filter earlier as we really need to go through all | |
181 | * entries regardless of it (the headers like X-Account-Container-Count | |
182 | * aren't affected by specifying prefix). */ | |
183 | const std::map<std::string, RGWBucketEnt>& m = buckets.get_buckets(); | |
184 | for (auto iter = m.lower_bound(prefix); | |
185 | iter != m.end() && boost::algorithm::starts_with(iter->first, prefix); | |
186 | ++iter) { | |
187 | const RGWBucketEnt& obj = iter->second; | |
188 | ||
189 | s->formatter->open_object_section("container"); | |
190 | s->formatter->dump_string("name", obj.bucket.name); | |
191 | if (need_stats) { | |
192 | s->formatter->dump_int("count", obj.count); | |
193 | s->formatter->dump_int("bytes", obj.size); | |
194 | } | |
195 | s->formatter->close_section(); | |
196 | if (! s->cct->_conf->rgw_swift_enforce_content_length) { | |
197 | rgw_flush_formatter(s, s->formatter); | |
198 | } | |
199 | } | |
200 | } | |
201 | ||
202 | void RGWListBuckets_ObjStore_SWIFT::send_response_end() | |
203 | { | |
204 | if (sent_data) { | |
205 | s->formatter->close_section(); | |
206 | } | |
207 | ||
208 | if (s->cct->_conf->rgw_swift_enforce_content_length) { | |
209 | /* Adding account stats in the header to keep align with Swift API */ | |
210 | dump_account_metadata(s, | |
211 | buckets_count, | |
212 | buckets_objcount, | |
213 | buckets_size, | |
214 | buckets_size_rounded, | |
215 | attrs, | |
216 | user_quota, | |
217 | static_cast<RGWAccessControlPolicy_SWIFTAcct&>(*s->user_acl)); | |
218 | dump_errno(s); | |
219 | end_header(s, NULL, NULL, s->formatter->get_len(), true); | |
220 | } | |
221 | ||
222 | if (sent_data || s->cct->_conf->rgw_swift_enforce_content_length) { | |
223 | rgw_flush_formatter_and_reset(s, s->formatter); | |
224 | } | |
225 | } | |
226 | ||
227 | int RGWListBucket_ObjStore_SWIFT::get_params() | |
228 | { | |
229 | prefix = s->info.args.get("prefix"); | |
230 | marker = s->info.args.get("marker"); | |
231 | end_marker = s->info.args.get("end_marker"); | |
232 | max_keys = s->info.args.get("limit"); | |
233 | op_ret = parse_max_keys(); | |
234 | if (op_ret < 0) { | |
235 | return op_ret; | |
236 | } | |
237 | if (max > default_max) | |
238 | return -ERR_PRECONDITION_FAILED; | |
239 | ||
240 | delimiter = s->info.args.get("delimiter"); | |
241 | ||
242 | string path_args; | |
243 | if (s->info.args.exists("path")) { // should handle empty path | |
244 | path_args = s->info.args.get("path"); | |
245 | if (!delimiter.empty() || !prefix.empty()) { | |
246 | return -EINVAL; | |
247 | } | |
248 | prefix = path_args; | |
249 | delimiter="/"; | |
250 | ||
251 | path = prefix; | |
252 | if (path.size() && path[path.size() - 1] != '/') | |
253 | path.append("/"); | |
254 | ||
255 | int len = prefix.size(); | |
256 | int delim_size = delimiter.size(); | |
257 | ||
258 | if (len >= delim_size) { | |
259 | if (prefix.substr(len - delim_size).compare(delimiter) != 0) | |
260 | prefix.append(delimiter); | |
261 | } | |
262 | } | |
263 | ||
264 | return 0; | |
265 | } | |
266 | ||
267 | static void dump_container_metadata(struct req_state *, | |
268 | const RGWBucketEnt&, | |
269 | const RGWQuotaInfo&, | |
270 | const RGWBucketWebsiteConf&); | |
271 | ||
272 | void RGWListBucket_ObjStore_SWIFT::send_response() | |
273 | { | |
274 | vector<rgw_bucket_dir_entry>::iterator iter = objs.begin(); | |
275 | map<string, bool>::iterator pref_iter = common_prefixes.begin(); | |
276 | ||
277 | dump_start(s); | |
278 | dump_container_metadata(s, bucket, bucket_quota, | |
279 | s->bucket_info.website_conf); | |
280 | ||
281 | s->formatter->open_array_section_with_attrs("container", FormatterAttrs("name", s->bucket.name.c_str(), NULL)); | |
282 | ||
283 | while (iter != objs.end() || pref_iter != common_prefixes.end()) { | |
284 | bool do_pref = false; | |
285 | bool do_objs = false; | |
286 | rgw_obj_key key; | |
287 | if (iter != objs.end()) { | |
288 | key = iter->key; | |
289 | } | |
290 | if (pref_iter == common_prefixes.end()) | |
291 | do_objs = true; | |
292 | else if (iter == objs.end()) | |
293 | do_pref = true; | |
294 | else if (!key.empty() && key.name.compare(pref_iter->first) == 0) { | |
295 | do_objs = true; | |
296 | ++pref_iter; | |
297 | } else if (!key.empty() && key.name.compare(pref_iter->first) <= 0) | |
298 | do_objs = true; | |
299 | else | |
300 | do_pref = true; | |
301 | ||
302 | if (do_objs && (marker.empty() || marker < key)) { | |
303 | if (key.name.compare(path) == 0) | |
304 | goto next; | |
305 | ||
306 | s->formatter->open_object_section("object"); | |
307 | s->formatter->dump_string("name", key.name); | |
308 | s->formatter->dump_string("hash", iter->meta.etag); | |
309 | s->formatter->dump_int("bytes", iter->meta.accounted_size); | |
310 | if (!iter->meta.user_data.empty()) | |
311 | s->formatter->dump_string("user_custom_data", iter->meta.user_data); | |
312 | string single_content_type = iter->meta.content_type; | |
313 | if (iter->meta.content_type.size()) { | |
314 | // content type might hold multiple values, just dump the last one | |
315 | ssize_t pos = iter->meta.content_type.rfind(','); | |
316 | if (pos > 0) { | |
317 | ++pos; | |
318 | while (single_content_type[pos] == ' ') | |
319 | ++pos; | |
320 | single_content_type = single_content_type.substr(pos); | |
321 | } | |
322 | s->formatter->dump_string("content_type", single_content_type); | |
323 | } | |
324 | dump_time(s, "last_modified", &iter->meta.mtime); | |
325 | s->formatter->close_section(); | |
326 | } | |
327 | ||
328 | if (do_pref && (marker.empty() || pref_iter->first.compare(marker.name) > 0)) { | |
329 | const string& name = pref_iter->first; | |
330 | if (name.compare(delimiter) == 0) | |
331 | goto next; | |
332 | ||
333 | s->formatter->open_object_section_with_attrs("subdir", FormatterAttrs("name", name.c_str(), NULL)); | |
334 | ||
335 | /* swift is a bit inconsistent here */ | |
336 | switch (s->format) { | |
337 | case RGW_FORMAT_XML: | |
338 | s->formatter->dump_string("name", name); | |
339 | break; | |
340 | default: | |
341 | s->formatter->dump_string("subdir", name); | |
342 | } | |
343 | s->formatter->close_section(); | |
344 | } | |
345 | next: | |
346 | if (do_objs) | |
347 | ++iter; | |
348 | else | |
349 | ++pref_iter; | |
350 | } | |
351 | ||
352 | s->formatter->close_section(); | |
353 | ||
354 | int64_t content_len = 0; | |
355 | if (! op_ret) { | |
356 | content_len = s->formatter->get_len(); | |
357 | if (content_len == 0) { | |
358 | op_ret = STATUS_NO_CONTENT; | |
359 | } | |
360 | } else if (op_ret > 0) { | |
361 | op_ret = 0; | |
362 | } | |
363 | ||
364 | set_req_state_err(s, op_ret); | |
365 | dump_errno(s); | |
366 | end_header(s, this, NULL, content_len); | |
367 | if (op_ret < 0) { | |
368 | return; | |
369 | } | |
370 | ||
371 | rgw_flush_formatter_and_reset(s, s->formatter); | |
372 | } | |
373 | ||
374 | static void dump_container_metadata(struct req_state *s, | |
375 | const RGWBucketEnt& bucket, | |
376 | const RGWQuotaInfo& quota, | |
377 | const RGWBucketWebsiteConf& ws_conf) | |
378 | { | |
379 | /* Adding X-Timestamp to keep align with Swift API */ | |
380 | dump_header(s, "X-Timestamp", utime_t(s->bucket_info.creation_time)); | |
381 | ||
382 | dump_header(s, "X-Container-Object-Count", bucket.count); | |
383 | dump_header(s, "X-Container-Bytes-Used", bucket.size); | |
384 | dump_header(s, "X-Container-Bytes-Used-Actual", bucket.size_rounded); | |
385 | ||
386 | if (s->object.empty()) { | |
387 | auto swift_policy = static_cast<RGWAccessControlPolicy_SWIFT*>(s->bucket_acl); | |
388 | std::string read_acl, write_acl; | |
389 | swift_policy->to_str(read_acl, write_acl); | |
390 | ||
391 | if (read_acl.size()) { | |
392 | dump_header(s, "X-Container-Read", read_acl); | |
393 | } | |
394 | if (write_acl.size()) { | |
395 | dump_header(s, "X-Container-Write", write_acl); | |
396 | } | |
397 | if (!s->bucket_info.placement_rule.empty()) { | |
398 | dump_header(s, "X-Storage-Policy", s->bucket_info.placement_rule); | |
399 | } | |
400 | ||
401 | /* Dump user-defined metadata items and generic attrs. */ | |
402 | const size_t PREFIX_LEN = sizeof(RGW_ATTR_META_PREFIX) - 1; | |
403 | map<string, bufferlist>::iterator iter; | |
404 | for (iter = s->bucket_attrs.lower_bound(RGW_ATTR_PREFIX); | |
405 | iter != s->bucket_attrs.end(); | |
406 | ++iter) { | |
407 | const char *name = iter->first.c_str(); | |
408 | map<string, string>::const_iterator geniter = rgw_to_http_attrs.find(name); | |
409 | ||
410 | if (geniter != rgw_to_http_attrs.end()) { | |
411 | dump_header(s, geniter->second, iter->second); | |
412 | } else if (strncmp(name, RGW_ATTR_META_PREFIX, PREFIX_LEN) == 0) { | |
413 | dump_header_prefixed(s, "X-Container-Meta-", | |
414 | camelcase_dash_http_attr(name + PREFIX_LEN), | |
415 | iter->second); | |
416 | } | |
417 | } | |
418 | } | |
419 | ||
420 | /* Dump container versioning info. */ | |
421 | if (! s->bucket_info.swift_ver_location.empty()) { | |
422 | dump_header(s, "X-Versions-Location", | |
423 | url_encode(s->bucket_info.swift_ver_location)); | |
424 | } | |
425 | ||
426 | /* Dump quota headers. */ | |
427 | if (quota.enabled) { | |
428 | if (quota.max_size >= 0) { | |
429 | dump_header(s, "X-Container-Meta-Quota-Bytes", quota.max_size); | |
430 | } | |
431 | ||
432 | if (quota.max_objects >= 0) { | |
433 | dump_header(s, "X-Container-Meta-Quota-Count", quota.max_objects); | |
434 | } | |
435 | } | |
436 | ||
437 | /* Dump Static Website headers. */ | |
438 | if (! ws_conf.index_doc_suffix.empty()) { | |
439 | dump_header(s, "X-Container-Meta-Web-Index", ws_conf.index_doc_suffix); | |
440 | } | |
441 | ||
442 | if (! ws_conf.error_doc.empty()) { | |
443 | dump_header(s, "X-Container-Meta-Web-Error", ws_conf.error_doc); | |
444 | } | |
445 | ||
446 | if (! ws_conf.subdir_marker.empty()) { | |
447 | dump_header(s, "X-Container-Meta-Web-Directory-Type", | |
448 | ws_conf.subdir_marker); | |
449 | } | |
450 | ||
451 | if (! ws_conf.listing_css_doc.empty()) { | |
452 | dump_header(s, "X-Container-Meta-Web-Listings-CSS", | |
453 | ws_conf.listing_css_doc); | |
454 | } | |
455 | ||
456 | if (ws_conf.listing_enabled) { | |
457 | dump_header(s, "X-Container-Meta-Web-Listings", "true"); | |
458 | } | |
459 | } | |
460 | ||
461 | void RGWStatAccount_ObjStore_SWIFT::execute() | |
462 | { | |
463 | RGWStatAccount_ObjStore::execute(); | |
464 | op_ret = rgw_get_user_attrs_by_uid(store, s->user->user_id, attrs); | |
465 | } | |
466 | ||
467 | void RGWStatAccount_ObjStore_SWIFT::send_response() | |
468 | { | |
469 | if (op_ret >= 0) { | |
470 | op_ret = STATUS_NO_CONTENT; | |
471 | dump_account_metadata(s, | |
472 | buckets_count, | |
473 | buckets_objcount, | |
474 | buckets_size, | |
475 | buckets_size_rounded, | |
476 | attrs, | |
477 | user_quota, | |
478 | static_cast<RGWAccessControlPolicy_SWIFTAcct&>(*s->user_acl)); | |
479 | } | |
480 | ||
481 | set_req_state_err(s, op_ret); | |
482 | dump_errno(s); | |
483 | ||
484 | end_header(s, NULL, NULL, 0, true); | |
485 | ||
486 | dump_start(s); | |
487 | } | |
488 | ||
489 | void RGWStatBucket_ObjStore_SWIFT::send_response() | |
490 | { | |
491 | if (op_ret >= 0) { | |
492 | op_ret = STATUS_NO_CONTENT; | |
493 | dump_container_metadata(s, bucket, bucket_quota, | |
494 | s->bucket_info.website_conf); | |
495 | } | |
496 | ||
497 | set_req_state_err(s, op_ret); | |
498 | dump_errno(s); | |
499 | ||
500 | end_header(s, this, NULL, 0, true); | |
501 | dump_start(s); | |
502 | } | |
503 | ||
504 | static int get_swift_container_settings(req_state * const s, | |
505 | RGWRados * const store, | |
506 | RGWAccessControlPolicy * const policy, | |
507 | bool * const has_policy, | |
508 | uint32_t * rw_mask, | |
509 | RGWCORSConfiguration * const cors_config, | |
510 | bool * const has_cors) | |
511 | { | |
512 | string read_list, write_list; | |
513 | ||
514 | const char * const read_attr = s->info.env->get("HTTP_X_CONTAINER_READ"); | |
515 | if (read_attr) { | |
516 | read_list = read_attr; | |
517 | } | |
518 | const char * const write_attr = s->info.env->get("HTTP_X_CONTAINER_WRITE"); | |
519 | if (write_attr) { | |
520 | write_list = write_attr; | |
521 | } | |
522 | ||
523 | *has_policy = false; | |
524 | ||
525 | if (read_attr || write_attr) { | |
526 | RGWAccessControlPolicy_SWIFT swift_policy(s->cct); | |
527 | const auto r = swift_policy.create(store, | |
528 | s->user->user_id, | |
529 | s->user->display_name, | |
530 | read_list, | |
531 | write_list, | |
532 | *rw_mask); | |
533 | if (r < 0) { | |
534 | return r; | |
535 | } | |
536 | ||
537 | *policy = swift_policy; | |
538 | *has_policy = true; | |
539 | } | |
540 | ||
541 | *has_cors = false; | |
542 | ||
543 | /*Check and update CORS configuration*/ | |
544 | const char *allow_origins = s->info.env->get("HTTP_X_CONTAINER_META_ACCESS_CONTROL_ALLOW_ORIGIN"); | |
545 | const char *allow_headers = s->info.env->get("HTTP_X_CONTAINER_META_ACCESS_CONTROL_ALLOW_HEADERS"); | |
546 | const char *expose_headers = s->info.env->get("HTTP_X_CONTAINER_META_ACCESS_CONTROL_EXPOSE_HEADERS"); | |
547 | const char *max_age = s->info.env->get("HTTP_X_CONTAINER_META_ACCESS_CONTROL_MAX_AGE"); | |
548 | if (allow_origins) { | |
549 | RGWCORSConfiguration_SWIFT *swift_cors = new RGWCORSConfiguration_SWIFT; | |
550 | int r = swift_cors->create_update(allow_origins, allow_headers, expose_headers, max_age); | |
551 | if (r < 0) { | |
552 | dout(0) << "Error creating/updating the cors configuration" << dendl; | |
553 | delete swift_cors; | |
554 | return r; | |
555 | } | |
556 | *has_cors = true; | |
557 | *cors_config = *swift_cors; | |
558 | cors_config->dump(); | |
559 | delete swift_cors; | |
560 | } | |
561 | ||
562 | return 0; | |
563 | } | |
564 | ||
565 | #define ACCT_REMOVE_ATTR_PREFIX "HTTP_X_REMOVE_ACCOUNT_META_" | |
566 | #define ACCT_PUT_ATTR_PREFIX "HTTP_X_ACCOUNT_META_" | |
567 | #define CONT_REMOVE_ATTR_PREFIX "HTTP_X_REMOVE_CONTAINER_META_" | |
568 | #define CONT_PUT_ATTR_PREFIX "HTTP_X_CONTAINER_META_" | |
569 | ||
570 | static void get_rmattrs_from_headers(const req_state * const s, | |
571 | const char * const put_prefix, | |
572 | const char * const del_prefix, | |
573 | set<string>& rmattr_names) | |
574 | { | |
7c673cae FG |
575 | const size_t put_prefix_len = strlen(put_prefix); |
576 | const size_t del_prefix_len = strlen(del_prefix); | |
577 | ||
31f18b77 | 578 | for (const auto& kv : s->info.env->get_map()) { |
7c673cae | 579 | size_t prefix_len = 0; |
31f18b77 | 580 | const char * const p = kv.first.c_str(); |
7c673cae FG |
581 | |
582 | if (strncasecmp(p, del_prefix, del_prefix_len) == 0) { | |
583 | /* Explicitly requested removal. */ | |
584 | prefix_len = del_prefix_len; | |
585 | } else if ((strncasecmp(p, put_prefix, put_prefix_len) == 0) | |
31f18b77 | 586 | && kv.second.empty()) { |
7c673cae FG |
587 | /* Removal requested by putting an empty value. */ |
588 | prefix_len = put_prefix_len; | |
589 | } | |
590 | ||
591 | if (prefix_len > 0) { | |
592 | string name(RGW_ATTR_META_PREFIX); | |
593 | name.append(lowercase_dash_http_attr(p + prefix_len)); | |
594 | rmattr_names.insert(name); | |
595 | } | |
596 | } | |
597 | } | |
598 | ||
599 | static int get_swift_versioning_settings( | |
600 | req_state * const s, | |
601 | boost::optional<std::string>& swift_ver_location) | |
602 | { | |
603 | /* Removing the Swift's versions location has lower priority than setting | |
604 | * a new one. That's the reason why we're handling it first. */ | |
605 | const std::string vlocdel = | |
606 | s->info.env->get("HTTP_X_REMOVE_VERSIONS_LOCATION", ""); | |
607 | if (vlocdel.size()) { | |
608 | swift_ver_location = boost::in_place(std::string()); | |
609 | } | |
610 | ||
611 | if (s->info.env->exists("HTTP_X_VERSIONS_LOCATION")) { | |
612 | /* If the Swift's versioning is globally disabled but someone wants to | |
613 | * enable it for a given container, new version of Swift will generate | |
614 | * the precondition failed error. */ | |
615 | if (! s->cct->_conf->rgw_swift_versioning_enabled) { | |
616 | return -ERR_PRECONDITION_FAILED; | |
617 | } | |
618 | ||
619 | swift_ver_location = s->info.env->get("HTTP_X_VERSIONS_LOCATION", ""); | |
620 | } | |
621 | ||
622 | return 0; | |
623 | } | |
624 | ||
625 | int RGWCreateBucket_ObjStore_SWIFT::get_params() | |
626 | { | |
627 | bool has_policy; | |
628 | uint32_t policy_rw_mask = 0; | |
629 | ||
630 | int r = get_swift_container_settings(s, store, &policy, &has_policy, | |
631 | &policy_rw_mask, &cors_config, &has_cors); | |
632 | if (r < 0) { | |
633 | return r; | |
634 | } | |
635 | ||
636 | if (!has_policy) { | |
637 | policy.create_default(s->user->user_id, s->user->display_name); | |
638 | } | |
639 | ||
640 | location_constraint = store->get_zonegroup().api_name; | |
641 | get_rmattrs_from_headers(s, CONT_PUT_ATTR_PREFIX, | |
642 | CONT_REMOVE_ATTR_PREFIX, rmattr_names); | |
643 | placement_rule = s->info.env->get("HTTP_X_STORAGE_POLICY", ""); | |
644 | ||
645 | return get_swift_versioning_settings(s, swift_ver_location); | |
646 | } | |
647 | ||
648 | void RGWCreateBucket_ObjStore_SWIFT::send_response() | |
649 | { | |
650 | if (! op_ret) | |
651 | op_ret = STATUS_CREATED; | |
652 | else if (op_ret == -ERR_BUCKET_EXISTS) | |
653 | op_ret = STATUS_ACCEPTED; | |
654 | set_req_state_err(s, op_ret); | |
655 | dump_errno(s); | |
656 | /* Propose ending HTTP header with 0 Content-Length header. */ | |
657 | end_header(s, NULL, NULL, 0); | |
658 | rgw_flush_formatter_and_reset(s, s->formatter); | |
659 | } | |
660 | ||
661 | void RGWDeleteBucket_ObjStore_SWIFT::send_response() | |
662 | { | |
663 | int r = op_ret; | |
664 | if (!r) | |
665 | r = STATUS_NO_CONTENT; | |
666 | ||
667 | set_req_state_err(s, r); | |
668 | dump_errno(s); | |
669 | end_header(s, this, NULL, 0); | |
670 | rgw_flush_formatter_and_reset(s, s->formatter); | |
671 | } | |
672 | ||
673 | static int get_delete_at_param(req_state *s, boost::optional<real_time> &delete_at) | |
674 | { | |
675 | /* Handle Swift object expiration. */ | |
676 | real_time delat_proposal; | |
677 | string x_delete = s->info.env->get("HTTP_X_DELETE_AFTER", ""); | |
678 | ||
679 | if (x_delete.empty()) { | |
680 | x_delete = s->info.env->get("HTTP_X_DELETE_AT", ""); | |
681 | } else { | |
682 | /* X-Delete-After HTTP is present. It means we need add its value | |
683 | * to the current time. */ | |
684 | delat_proposal = real_clock::now(); | |
685 | } | |
686 | ||
687 | if (x_delete.empty()) { | |
688 | delete_at = boost::none; | |
689 | if (s->info.env->exists("HTTP_X_REMOVE_DELETE_AT")) { | |
690 | delete_at = boost::in_place(real_time()); | |
691 | } | |
692 | return 0; | |
693 | } | |
694 | string err; | |
695 | long ts = strict_strtoll(x_delete.c_str(), 10, &err); | |
696 | ||
697 | if (!err.empty()) { | |
698 | return -EINVAL; | |
699 | } | |
700 | ||
701 | delat_proposal += make_timespan(ts); | |
702 | if (delat_proposal < real_clock::now()) { | |
703 | return -EINVAL; | |
704 | } | |
705 | ||
706 | delete_at = delat_proposal; | |
707 | ||
708 | return 0; | |
709 | } | |
710 | ||
711 | int RGWPutObj_ObjStore_SWIFT::verify_permission() | |
712 | { | |
713 | op_ret = RGWPutObj_ObjStore::verify_permission(); | |
714 | ||
715 | /* We have to differentiate error codes depending on whether user is | |
716 | * anonymous (401 Unauthorized) or he doesn't have necessary permissions | |
717 | * (403 Forbidden). */ | |
718 | if (s->auth.identity->is_anonymous() && op_ret == -EACCES) { | |
719 | return -EPERM; | |
720 | } else { | |
721 | return op_ret; | |
722 | } | |
723 | } | |
724 | ||
725 | int RGWPutObj_ObjStore_SWIFT::get_params() | |
726 | { | |
727 | if (s->has_bad_meta) { | |
728 | return -EINVAL; | |
729 | } | |
730 | ||
731 | if (!s->length) { | |
732 | const char *encoding = s->info.env->get("HTTP_TRANSFER_ENCODING"); | |
733 | if (!encoding || strcmp(encoding, "chunked") != 0) { | |
734 | ldout(s->cct, 20) << "neither length nor chunked encoding" << dendl; | |
735 | return -ERR_LENGTH_REQUIRED; | |
736 | } | |
737 | ||
738 | chunked_upload = true; | |
739 | } | |
740 | ||
741 | supplied_etag = s->info.env->get("HTTP_ETAG"); | |
742 | ||
743 | if (!s->generic_attrs.count(RGW_ATTR_CONTENT_TYPE)) { | |
744 | ldout(s->cct, 5) << "content type wasn't provided, trying to guess" << dendl; | |
745 | const char *suffix = strrchr(s->object.name.c_str(), '.'); | |
746 | if (suffix) { | |
747 | suffix++; | |
748 | if (*suffix) { | |
749 | string suffix_str(suffix); | |
750 | const char *mime = rgw_find_mime_by_ext(suffix_str); | |
751 | if (mime) { | |
752 | s->generic_attrs[RGW_ATTR_CONTENT_TYPE] = mime; | |
753 | } | |
754 | } | |
755 | } | |
756 | } | |
757 | ||
758 | policy.create_default(s->user->user_id, s->user->display_name); | |
759 | ||
760 | int r = get_delete_at_param(s, delete_at); | |
761 | if (r < 0) { | |
762 | ldout(s->cct, 5) << "ERROR: failed to get Delete-At param" << dendl; | |
763 | return r; | |
764 | } | |
765 | ||
766 | if (!s->cct->_conf->rgw_swift_custom_header.empty()) { | |
767 | string custom_header = s->cct->_conf->rgw_swift_custom_header; | |
768 | if (s->info.env->exists(custom_header.c_str())) { | |
769 | user_data = s->info.env->get(custom_header.c_str()); | |
770 | } | |
771 | } | |
772 | ||
773 | dlo_manifest = s->info.env->get("HTTP_X_OBJECT_MANIFEST"); | |
774 | bool exists; | |
775 | string multipart_manifest = s->info.args.get("multipart-manifest", &exists); | |
776 | if (exists) { | |
777 | if (multipart_manifest != "put") { | |
778 | ldout(s->cct, 5) << "invalid multipart-manifest http param: " << multipart_manifest << dendl; | |
779 | return -EINVAL; | |
780 | } | |
781 | ||
782 | #define MAX_SLO_ENTRY_SIZE (1024 + 128) // 1024 - max obj name, 128 - enough extra for other info | |
783 | uint64_t max_len = s->cct->_conf->rgw_max_slo_entries * MAX_SLO_ENTRY_SIZE; | |
784 | ||
785 | slo_info = new RGWSLOInfo; | |
786 | ||
787 | int r = rgw_rest_get_json_input_keep_data(s->cct, s, slo_info->entries, max_len, &slo_info->raw_data, &slo_info->raw_data_len); | |
788 | if (r < 0) { | |
789 | ldout(s->cct, 5) << "failed to read input for slo r=" << r << dendl; | |
790 | return r; | |
791 | } | |
792 | ||
793 | if ((int64_t)slo_info->entries.size() > s->cct->_conf->rgw_max_slo_entries) { | |
794 | ldout(s->cct, 5) << "too many entries in slo request: " << slo_info->entries.size() << dendl; | |
795 | return -EINVAL; | |
796 | } | |
797 | ||
798 | MD5 etag_sum; | |
799 | uint64_t total_size = 0; | |
800 | for (const auto& entry : slo_info->entries) { | |
801 | etag_sum.Update((const byte *)entry.etag.c_str(), | |
802 | entry.etag.length()); | |
803 | total_size += entry.size_bytes; | |
804 | ||
805 | ldout(s->cct, 20) << "slo_part: " << entry.path | |
806 | << " size=" << entry.size_bytes | |
807 | << " etag=" << entry.etag | |
808 | << dendl; | |
809 | } | |
810 | complete_etag(etag_sum, &lo_etag); | |
811 | slo_info->total_size = total_size; | |
812 | ||
813 | ofs = slo_info->raw_data_len; | |
814 | } | |
815 | ||
816 | return RGWPutObj_ObjStore::get_params(); | |
817 | } | |
818 | ||
819 | void RGWPutObj_ObjStore_SWIFT::send_response() | |
820 | { | |
821 | if (! op_ret) { | |
822 | op_ret = STATUS_CREATED; | |
823 | } | |
824 | ||
825 | if (! lo_etag.empty()) { | |
826 | /* Static Large Object of Swift API has two etags represented by | |
827 | * following members: | |
828 | * - etag - for the manifest itself (it will be stored in xattrs), | |
829 | * - lo_etag - for the content composited from SLO's segments. | |
830 | * The value is calculated basing on segments' etags. | |
831 | * In response for PUT request we have to expose the second one. | |
832 | * The first one may be obtained by GET with "multipart-manifest=get" | |
833 | * in query string on a given SLO. */ | |
834 | dump_etag(s, lo_etag, true /* quoted */); | |
835 | } else { | |
836 | dump_etag(s, etag); | |
837 | } | |
838 | ||
839 | dump_last_modified(s, mtime); | |
840 | set_req_state_err(s, op_ret); | |
841 | dump_errno(s); | |
842 | end_header(s, this); | |
843 | rgw_flush_formatter_and_reset(s, s->formatter); | |
844 | } | |
845 | ||
846 | static int get_swift_account_settings(req_state * const s, | |
847 | RGWRados * const store, | |
848 | RGWAccessControlPolicy_SWIFTAcct * const policy, | |
849 | bool * const has_policy) | |
850 | { | |
851 | *has_policy = false; | |
852 | ||
853 | const char * const acl_attr = s->info.env->get("HTTP_X_ACCOUNT_ACCESS_CONTROL"); | |
854 | if (acl_attr) { | |
855 | RGWAccessControlPolicy_SWIFTAcct swift_acct_policy(s->cct); | |
856 | const bool r = swift_acct_policy.create(store, | |
857 | s->user->user_id, | |
858 | s->user->display_name, | |
859 | string(acl_attr)); | |
860 | if (r != true) { | |
861 | return -EINVAL; | |
862 | } | |
863 | ||
864 | *policy = swift_acct_policy; | |
865 | *has_policy = true; | |
866 | } | |
867 | ||
868 | return 0; | |
869 | } | |
870 | ||
871 | int RGWPutMetadataAccount_ObjStore_SWIFT::get_params() | |
872 | { | |
873 | if (s->has_bad_meta) { | |
874 | return -EINVAL; | |
875 | } | |
876 | ||
877 | int ret = get_swift_account_settings(s, | |
878 | store, | |
879 | // FIXME: we need to carry unique_ptr in generic class | |
880 | // and allocate appropriate ACL class in the ctor | |
881 | static_cast<RGWAccessControlPolicy_SWIFTAcct *>(&policy), | |
882 | &has_policy); | |
883 | if (ret < 0) { | |
884 | return ret; | |
885 | } | |
886 | ||
887 | get_rmattrs_from_headers(s, ACCT_PUT_ATTR_PREFIX, ACCT_REMOVE_ATTR_PREFIX, | |
888 | rmattr_names); | |
889 | return 0; | |
890 | } | |
891 | ||
892 | void RGWPutMetadataAccount_ObjStore_SWIFT::send_response() | |
893 | { | |
894 | if (! op_ret) { | |
895 | op_ret = STATUS_NO_CONTENT; | |
896 | } | |
897 | set_req_state_err(s, op_ret); | |
898 | dump_errno(s); | |
899 | end_header(s, this); | |
900 | rgw_flush_formatter_and_reset(s, s->formatter); | |
901 | } | |
902 | ||
903 | int RGWPutMetadataBucket_ObjStore_SWIFT::get_params() | |
904 | { | |
905 | if (s->has_bad_meta) { | |
906 | return -EINVAL; | |
907 | } | |
908 | ||
909 | int r = get_swift_container_settings(s, store, &policy, &has_policy, | |
910 | &policy_rw_mask, &cors_config, &has_cors); | |
911 | if (r < 0) { | |
912 | return r; | |
913 | } | |
914 | ||
915 | get_rmattrs_from_headers(s, CONT_PUT_ATTR_PREFIX, CONT_REMOVE_ATTR_PREFIX, | |
916 | rmattr_names); | |
917 | placement_rule = s->info.env->get("HTTP_X_STORAGE_POLICY", ""); | |
918 | ||
919 | return get_swift_versioning_settings(s, swift_ver_location); | |
920 | } | |
921 | ||
922 | void RGWPutMetadataBucket_ObjStore_SWIFT::send_response() | |
923 | { | |
924 | if (!op_ret && (op_ret != -EINVAL)) { | |
925 | op_ret = STATUS_NO_CONTENT; | |
926 | } | |
927 | set_req_state_err(s, op_ret); | |
928 | dump_errno(s); | |
929 | end_header(s, this); | |
930 | rgw_flush_formatter_and_reset(s, s->formatter); | |
931 | } | |
932 | ||
933 | int RGWPutMetadataObject_ObjStore_SWIFT::get_params() | |
934 | { | |
935 | if (s->has_bad_meta) { | |
936 | return -EINVAL; | |
937 | } | |
938 | ||
939 | /* Handle Swift object expiration. */ | |
940 | int r = get_delete_at_param(s, delete_at); | |
941 | if (r < 0) { | |
942 | ldout(s->cct, 5) << "ERROR: failed to get Delete-At param" << dendl; | |
943 | return r; | |
944 | } | |
945 | ||
946 | placement_rule = s->info.env->get("HTTP_X_STORAGE_POLICY", ""); | |
947 | dlo_manifest = s->info.env->get("HTTP_X_OBJECT_MANIFEST"); | |
948 | ||
949 | return 0; | |
950 | } | |
951 | ||
952 | void RGWPutMetadataObject_ObjStore_SWIFT::send_response() | |
953 | { | |
954 | if (! op_ret) { | |
955 | op_ret = STATUS_ACCEPTED; | |
956 | } | |
957 | set_req_state_err(s, op_ret); | |
31f18b77 | 958 | if (!s->is_err()) { |
7c673cae FG |
959 | dump_content_length(s, 0); |
960 | } | |
961 | dump_errno(s); | |
962 | end_header(s, this); | |
963 | rgw_flush_formatter_and_reset(s, s->formatter); | |
964 | } | |
965 | ||
966 | static void bulkdelete_respond(const unsigned num_deleted, | |
967 | const unsigned int num_unfound, | |
968 | const std::list<RGWBulkDelete::fail_desc_t>& failures, | |
969 | const int prot_flags, /* in */ | |
970 | ceph::Formatter& formatter) /* out */ | |
971 | { | |
972 | formatter.open_object_section("delete"); | |
973 | ||
974 | string resp_status; | |
975 | string resp_body; | |
976 | ||
977 | if (!failures.empty()) { | |
978 | int reason = ERR_INVALID_REQUEST; | |
979 | for (const auto fail_desc : failures) { | |
980 | if (-ENOENT != fail_desc.err && -EACCES != fail_desc.err) { | |
981 | reason = fail_desc.err; | |
982 | } | |
983 | } | |
7c673cae FG |
984 | rgw_err err; |
985 | set_req_state_err(err, reason, prot_flags); | |
986 | dump_errno(err, resp_status); | |
987 | } else if (0 == num_deleted && 0 == num_unfound) { | |
988 | /* 400 Bad Request */ | |
989 | dump_errno(400, resp_status); | |
990 | resp_body = "Invalid bulk delete."; | |
991 | } else { | |
992 | /* 200 OK */ | |
993 | dump_errno(200, resp_status); | |
994 | } | |
995 | ||
996 | encode_json("Number Deleted", num_deleted, &formatter); | |
997 | encode_json("Number Not Found", num_unfound, &formatter); | |
998 | encode_json("Response Body", resp_body, &formatter); | |
999 | encode_json("Response Status", resp_status, &formatter); | |
1000 | ||
1001 | formatter.open_array_section("Errors"); | |
1002 | for (const auto fail_desc : failures) { | |
1003 | formatter.open_array_section("object"); | |
1004 | ||
1005 | stringstream ss_name; | |
1006 | ss_name << fail_desc.path; | |
1007 | encode_json("Name", ss_name.str(), &formatter); | |
1008 | ||
1009 | rgw_err err; | |
1010 | set_req_state_err(err, fail_desc.err, prot_flags); | |
1011 | string status; | |
1012 | dump_errno(err, status); | |
1013 | encode_json("Status", status, &formatter); | |
1014 | formatter.close_section(); | |
1015 | } | |
1016 | formatter.close_section(); | |
1017 | ||
1018 | formatter.close_section(); | |
1019 | } | |
1020 | ||
1021 | int RGWDeleteObj_ObjStore_SWIFT::verify_permission() | |
1022 | { | |
1023 | op_ret = RGWDeleteObj_ObjStore::verify_permission(); | |
1024 | ||
1025 | /* We have to differentiate error codes depending on whether user is | |
1026 | * anonymous (401 Unauthorized) or he doesn't have necessary permissions | |
1027 | * (403 Forbidden). */ | |
1028 | if (s->auth.identity->is_anonymous() && op_ret == -EACCES) { | |
1029 | return -EPERM; | |
1030 | } else { | |
1031 | return op_ret; | |
1032 | } | |
1033 | } | |
1034 | ||
1035 | int RGWDeleteObj_ObjStore_SWIFT::get_params() | |
1036 | { | |
1037 | const string& mm = s->info.args.get("multipart-manifest"); | |
1038 | multipart_delete = (mm.compare("delete") == 0); | |
1039 | ||
1040 | return RGWDeleteObj_ObjStore::get_params(); | |
1041 | } | |
1042 | ||
1043 | void RGWDeleteObj_ObjStore_SWIFT::send_response() | |
1044 | { | |
1045 | int r = op_ret; | |
1046 | ||
1047 | if (multipart_delete) { | |
1048 | r = 0; | |
1049 | } else if(!r) { | |
1050 | r = STATUS_NO_CONTENT; | |
1051 | } | |
1052 | ||
1053 | set_req_state_err(s, r); | |
1054 | dump_errno(s); | |
1055 | ||
1056 | if (multipart_delete) { | |
1057 | end_header(s, this /* RGWOp */, nullptr /* contype */, | |
1058 | CHUNKED_TRANSFER_ENCODING); | |
1059 | ||
1060 | if (deleter) { | |
1061 | bulkdelete_respond(deleter->get_num_deleted(), | |
1062 | deleter->get_num_unfound(), | |
1063 | deleter->get_failures(), | |
1064 | s->prot_flags, | |
1065 | *s->formatter); | |
1066 | } else if (-ENOENT == op_ret) { | |
1067 | bulkdelete_respond(0, 1, {}, s->prot_flags, *s->formatter); | |
1068 | } else { | |
1069 | RGWBulkDelete::acct_path_t path; | |
1070 | path.bucket_name = s->bucket_name; | |
1071 | path.obj_key = s->object; | |
1072 | ||
1073 | RGWBulkDelete::fail_desc_t fail_desc; | |
1074 | fail_desc.err = op_ret; | |
1075 | fail_desc.path = path; | |
1076 | ||
1077 | bulkdelete_respond(0, 0, { fail_desc }, s->prot_flags, *s->formatter); | |
1078 | } | |
1079 | } else { | |
1080 | end_header(s, this); | |
1081 | } | |
1082 | ||
1083 | rgw_flush_formatter_and_reset(s, s->formatter); | |
1084 | ||
1085 | } | |
1086 | ||
1087 | static void get_contype_from_attrs(map<string, bufferlist>& attrs, | |
1088 | string& content_type) | |
1089 | { | |
1090 | map<string, bufferlist>::iterator iter = attrs.find(RGW_ATTR_CONTENT_TYPE); | |
1091 | if (iter != attrs.end()) { | |
1092 | content_type = iter->second.c_str(); | |
1093 | } | |
1094 | } | |
1095 | ||
1096 | static void dump_object_metadata(struct req_state * const s, | |
1097 | map<string, bufferlist> attrs) | |
1098 | { | |
1099 | map<string, string> response_attrs; | |
1100 | ||
1101 | for (auto kv : attrs) { | |
1102 | const char * name = kv.first.c_str(); | |
1103 | const auto aiter = rgw_to_http_attrs.find(name); | |
1104 | ||
1105 | if (aiter != std::end(rgw_to_http_attrs)) { | |
1106 | response_attrs[aiter->second] = kv.second.c_str(); | |
31f18b77 FG |
1107 | } else if (strcmp(name, RGW_ATTR_SLO_UINDICATOR) == 0) { |
1108 | // this attr has an extra length prefix from ::encode() in prior versions | |
1109 | dump_header(s, "X-Object-Meta-Static-Large-Object", "True"); | |
7c673cae FG |
1110 | } else if (strncmp(name, RGW_ATTR_META_PREFIX, |
1111 | sizeof(RGW_ATTR_META_PREFIX)-1) == 0) { | |
1112 | name += sizeof(RGW_ATTR_META_PREFIX) - 1; | |
1113 | dump_header_prefixed(s, "X-Object-Meta-", | |
1114 | camelcase_dash_http_attr(name), kv.second); | |
1115 | } | |
1116 | } | |
1117 | ||
1118 | /* Handle override and fallback for Content-Disposition HTTP header. | |
1119 | * At the moment this will be used only by TempURL of the Swift API. */ | |
1120 | const auto cditer = rgw_to_http_attrs.find(RGW_ATTR_CONTENT_DISP); | |
1121 | if (cditer != std::end(rgw_to_http_attrs)) { | |
1122 | const auto& name = cditer->second; | |
1123 | ||
1124 | if (!s->content_disp.override.empty()) { | |
1125 | response_attrs[name] = s->content_disp.override; | |
1126 | } else if (!s->content_disp.fallback.empty() | |
1127 | && response_attrs.find(name) == std::end(response_attrs)) { | |
1128 | response_attrs[name] = s->content_disp.fallback; | |
1129 | } | |
1130 | } | |
1131 | ||
1132 | for (const auto kv : response_attrs) { | |
1133 | dump_header(s, kv.first, kv.second); | |
1134 | } | |
1135 | ||
1136 | const auto iter = attrs.find(RGW_ATTR_DELETE_AT); | |
1137 | if (iter != std::end(attrs)) { | |
1138 | utime_t delete_at; | |
1139 | try { | |
1140 | ::decode(delete_at, iter->second); | |
1141 | if (!delete_at.is_zero()) { | |
1142 | dump_header(s, "X-Delete-At", delete_at.sec()); | |
1143 | } | |
1144 | } catch (buffer::error& err) { | |
1145 | ldout(s->cct, 0) << "ERROR: cannot decode object's " RGW_ATTR_DELETE_AT | |
1146 | " attr, ignoring" | |
1147 | << dendl; | |
1148 | } | |
1149 | } | |
1150 | } | |
1151 | ||
1152 | int RGWCopyObj_ObjStore_SWIFT::init_dest_policy() | |
1153 | { | |
1154 | dest_policy.create_default(s->user->user_id, s->user->display_name); | |
1155 | ||
1156 | return 0; | |
1157 | } | |
1158 | ||
1159 | int RGWCopyObj_ObjStore_SWIFT::get_params() | |
1160 | { | |
1161 | if_mod = s->info.env->get("HTTP_IF_MODIFIED_SINCE"); | |
1162 | if_unmod = s->info.env->get("HTTP_IF_UNMODIFIED_SINCE"); | |
1163 | if_match = s->info.env->get("HTTP_COPY_IF_MATCH"); | |
1164 | if_nomatch = s->info.env->get("HTTP_COPY_IF_NONE_MATCH"); | |
1165 | ||
1166 | src_tenant_name = s->src_tenant_name; | |
1167 | src_bucket_name = s->src_bucket_name; | |
1168 | src_object = s->src_object; | |
1169 | dest_tenant_name = s->bucket_tenant; | |
1170 | dest_bucket_name = s->bucket_name; | |
1171 | dest_object = s->object.name; | |
1172 | ||
1173 | const char * const fresh_meta = s->info.env->get("HTTP_X_FRESH_METADATA"); | |
1174 | if (fresh_meta && strcasecmp(fresh_meta, "TRUE") == 0) { | |
1175 | attrs_mod = RGWRados::ATTRSMOD_REPLACE; | |
1176 | } else { | |
1177 | attrs_mod = RGWRados::ATTRSMOD_MERGE; | |
1178 | } | |
1179 | ||
1180 | int r = get_delete_at_param(s, delete_at); | |
1181 | if (r < 0) { | |
1182 | ldout(s->cct, 5) << "ERROR: failed to get Delete-At param" << dendl; | |
1183 | return r; | |
1184 | } | |
1185 | ||
1186 | return 0; | |
1187 | } | |
1188 | ||
1189 | void RGWCopyObj_ObjStore_SWIFT::send_partial_response(off_t ofs) | |
1190 | { | |
1191 | if (! sent_header) { | |
1192 | if (! op_ret) | |
1193 | op_ret = STATUS_CREATED; | |
1194 | set_req_state_err(s, op_ret); | |
1195 | dump_errno(s); | |
1196 | end_header(s, this); | |
1197 | ||
1198 | /* Send progress information. Note that this diverge from the original swift | |
1199 | * spec. We do this in order to keep connection alive. | |
1200 | */ | |
1201 | if (op_ret == 0) { | |
1202 | s->formatter->open_array_section("progress"); | |
1203 | } | |
1204 | sent_header = true; | |
1205 | } else { | |
1206 | s->formatter->dump_int("ofs", (uint64_t)ofs); | |
1207 | } | |
1208 | rgw_flush_formatter(s, s->formatter); | |
1209 | } | |
1210 | ||
1211 | void RGWCopyObj_ObjStore_SWIFT::dump_copy_info() | |
1212 | { | |
1213 | /* Dump X-Copied-From. */ | |
1214 | dump_header(s, "X-Copied-From", url_encode(src_bucket.name) + | |
1215 | "/" + url_encode(src_object.name)); | |
1216 | ||
1217 | /* Dump X-Copied-From-Account. */ | |
1218 | /* XXX tenant */ | |
1219 | dump_header(s, "X-Copied-From-Account", url_encode(s->user->user_id.id)); | |
1220 | ||
1221 | /* Dump X-Copied-From-Last-Modified. */ | |
1222 | dump_time_header(s, "X-Copied-From-Last-Modified", src_mtime); | |
1223 | } | |
1224 | ||
1225 | void RGWCopyObj_ObjStore_SWIFT::send_response() | |
1226 | { | |
1227 | if (! sent_header) { | |
1228 | string content_type; | |
1229 | if (! op_ret) | |
1230 | op_ret = STATUS_CREATED; | |
1231 | set_req_state_err(s, op_ret); | |
1232 | dump_errno(s); | |
1233 | dump_etag(s, etag); | |
1234 | dump_last_modified(s, mtime); | |
1235 | dump_copy_info(); | |
1236 | get_contype_from_attrs(attrs, content_type); | |
1237 | dump_object_metadata(s, attrs); | |
1238 | end_header(s, this, !content_type.empty() ? content_type.c_str() | |
1239 | : "binary/octet-stream"); | |
1240 | } else { | |
1241 | s->formatter->close_section(); | |
1242 | rgw_flush_formatter(s, s->formatter); | |
1243 | } | |
1244 | } | |
1245 | ||
1246 | int RGWGetObj_ObjStore_SWIFT::verify_permission() | |
1247 | { | |
1248 | op_ret = RGWGetObj_ObjStore::verify_permission(); | |
1249 | ||
1250 | /* We have to differentiate error codes depending on whether user is | |
1251 | * anonymous (401 Unauthorized) or he doesn't have necessary permissions | |
1252 | * (403 Forbidden). */ | |
1253 | if (s->auth.identity->is_anonymous() && op_ret == -EACCES) { | |
1254 | return -EPERM; | |
1255 | } else { | |
1256 | return op_ret; | |
1257 | } | |
1258 | } | |
1259 | ||
1260 | int RGWGetObj_ObjStore_SWIFT::get_params() | |
1261 | { | |
1262 | const string& mm = s->info.args.get("multipart-manifest"); | |
1263 | skip_manifest = (mm.compare("get") == 0); | |
1264 | ||
1265 | return RGWGetObj_ObjStore::get_params(); | |
1266 | } | |
1267 | ||
1268 | int RGWGetObj_ObjStore_SWIFT::send_response_data_error() | |
1269 | { | |
1270 | std::string error_content; | |
1271 | op_ret = error_handler(op_ret, &error_content); | |
1272 | if (! op_ret) { | |
1273 | /* The error handler has taken care of the error. */ | |
1274 | return 0; | |
1275 | } | |
1276 | ||
1277 | bufferlist error_bl; | |
1278 | error_bl.append(error_content); | |
1279 | return send_response_data(error_bl, 0, error_bl.length()); | |
1280 | } | |
1281 | ||
1282 | int RGWGetObj_ObjStore_SWIFT::send_response_data(bufferlist& bl, | |
1283 | const off_t bl_ofs, | |
1284 | const off_t bl_len) | |
1285 | { | |
1286 | string content_type; | |
1287 | ||
1288 | if (sent_header) { | |
1289 | goto send_data; | |
1290 | } | |
1291 | ||
1292 | if (custom_http_ret) { | |
1293 | set_req_state_err(s, 0); | |
1294 | dump_errno(s, custom_http_ret); | |
1295 | } else { | |
1296 | set_req_state_err(s, (partial_content && !op_ret) ? STATUS_PARTIAL_CONTENT | |
1297 | : op_ret); | |
1298 | dump_errno(s); | |
1299 | ||
31f18b77 | 1300 | if (s->is_err()) { |
7c673cae FG |
1301 | end_header(s, NULL); |
1302 | return 0; | |
1303 | } | |
1304 | } | |
1305 | ||
1306 | if (range_str) { | |
1307 | dump_range(s, ofs, end, s->obj_size); | |
1308 | } | |
1309 | ||
31f18b77 | 1310 | if (s->is_err()) { |
7c673cae FG |
1311 | end_header(s, NULL); |
1312 | return 0; | |
1313 | } | |
1314 | ||
1315 | dump_content_length(s, total_len); | |
1316 | dump_last_modified(s, lastmod); | |
1317 | dump_header(s, "X-Timestamp", utime_t(lastmod)); | |
1318 | if (is_slo) { | |
1319 | dump_header(s, "X-Static-Large-Object", "True"); | |
1320 | } | |
1321 | ||
1322 | if (! op_ret) { | |
1323 | if (! lo_etag.empty()) { | |
1324 | dump_etag(s, lo_etag, true /* quoted */); | |
1325 | } else { | |
1326 | auto iter = attrs.find(RGW_ATTR_ETAG); | |
1327 | if (iter != attrs.end()) { | |
1328 | dump_etag(s, iter->second); | |
1329 | } | |
1330 | } | |
1331 | ||
1332 | get_contype_from_attrs(attrs, content_type); | |
1333 | dump_object_metadata(s, attrs); | |
1334 | } | |
1335 | ||
1336 | end_header(s, this, !content_type.empty() ? content_type.c_str() | |
1337 | : "binary/octet-stream"); | |
1338 | ||
1339 | sent_header = true; | |
1340 | ||
1341 | send_data: | |
1342 | if (get_data && !op_ret) { | |
1343 | const auto r = dump_body(s, bl.c_str() + bl_ofs, bl_len); | |
1344 | if (r < 0) { | |
1345 | return r; | |
1346 | } | |
1347 | } | |
1348 | rgw_flush_formatter_and_reset(s, s->formatter); | |
1349 | ||
1350 | return 0; | |
1351 | } | |
1352 | ||
1353 | void RGWOptionsCORS_ObjStore_SWIFT::send_response() | |
1354 | { | |
1355 | string hdrs, exp_hdrs; | |
1356 | uint32_t max_age = CORS_MAX_AGE_INVALID; | |
1357 | /*EACCES means, there is no CORS registered yet for the bucket | |
1358 | *ENOENT means, there is no match of the Origin in the list of CORSRule | |
1359 | */ | |
1360 | if (op_ret == -ENOENT) | |
1361 | op_ret = -EACCES; | |
1362 | if (op_ret < 0) { | |
1363 | set_req_state_err(s, op_ret); | |
1364 | dump_errno(s); | |
1365 | end_header(s, NULL); | |
1366 | return; | |
1367 | } | |
1368 | get_response_params(hdrs, exp_hdrs, &max_age); | |
1369 | dump_errno(s); | |
1370 | dump_access_control(s, origin, req_meth, hdrs.c_str(), exp_hdrs.c_str(), | |
1371 | max_age); | |
1372 | end_header(s, NULL); | |
1373 | } | |
1374 | ||
1375 | int RGWBulkDelete_ObjStore_SWIFT::get_data( | |
1376 | list<RGWBulkDelete::acct_path_t>& items, bool * const is_truncated) | |
1377 | { | |
1378 | constexpr size_t MAX_LINE_SIZE = 2048; | |
1379 | ||
1380 | RGWClientIOStreamBuf ciosb(static_cast<RGWRestfulIO&>(*(s->cio)), | |
1381 | size_t(s->cct->_conf->rgw_max_chunk_size)); | |
1382 | istream cioin(&ciosb); | |
1383 | ||
1384 | char buf[MAX_LINE_SIZE]; | |
1385 | while (cioin.getline(buf, sizeof(buf))) { | |
1386 | string path_str(buf); | |
1387 | ||
1388 | ldout(s->cct, 20) << "extracted Bulk Delete entry: " << path_str << dendl; | |
1389 | ||
1390 | RGWBulkDelete::acct_path_t path; | |
1391 | ||
1392 | /* We need to skip all slashes at the beginning in order to preserve | |
1393 | * compliance with Swift. */ | |
1394 | const size_t start_pos = path_str.find_first_not_of('/'); | |
1395 | ||
1396 | if (string::npos != start_pos) { | |
1397 | /* Seperator is the first slash after the leading ones. */ | |
1398 | const size_t sep_pos = path_str.find('/', start_pos); | |
1399 | ||
1400 | if (string::npos != sep_pos) { | |
31f18b77 FG |
1401 | path.bucket_name = url_decode(path_str.substr(start_pos, |
1402 | sep_pos - start_pos)); | |
1403 | path.obj_key = url_decode(path_str.substr(sep_pos + 1)); | |
7c673cae FG |
1404 | } else { |
1405 | /* It's guaranteed here that bucket name is at least one character | |
1406 | * long and is different than slash. */ | |
31f18b77 | 1407 | path.bucket_name = url_decode(path_str.substr(start_pos)); |
7c673cae FG |
1408 | } |
1409 | ||
1410 | items.push_back(path); | |
1411 | } | |
1412 | ||
1413 | if (items.size() == MAX_CHUNK_ENTRIES) { | |
1414 | *is_truncated = true; | |
1415 | return 0; | |
1416 | } | |
1417 | } | |
1418 | ||
1419 | *is_truncated = false; | |
1420 | return 0; | |
1421 | } | |
1422 | ||
1423 | void RGWBulkDelete_ObjStore_SWIFT::send_response() | |
1424 | { | |
1425 | set_req_state_err(s, op_ret); | |
1426 | dump_errno(s); | |
1427 | end_header(s, this /* RGWOp */, nullptr /* contype */, | |
1428 | CHUNKED_TRANSFER_ENCODING); | |
1429 | ||
1430 | bulkdelete_respond(deleter->get_num_deleted(), | |
1431 | deleter->get_num_unfound(), | |
1432 | deleter->get_failures(), | |
1433 | s->prot_flags, | |
1434 | *s->formatter); | |
1435 | rgw_flush_formatter_and_reset(s, s->formatter); | |
1436 | } | |
1437 | ||
1438 | ||
1439 | std::unique_ptr<RGWBulkUploadOp::StreamGetter> | |
1440 | RGWBulkUploadOp_ObjStore_SWIFT::create_stream() | |
1441 | { | |
1442 | class SwiftStreamGetter : public StreamGetter { | |
1443 | const size_t conlen; | |
1444 | size_t curpos; | |
1445 | req_state* const s; | |
1446 | ||
1447 | public: | |
1448 | SwiftStreamGetter(req_state* const s, const size_t conlen) | |
1449 | : conlen(conlen), | |
1450 | curpos(0), | |
1451 | s(s) { | |
1452 | } | |
1453 | ||
1454 | ssize_t get_at_most(size_t want, ceph::bufferlist& dst) override { | |
1455 | /* maximum requested by a caller */ | |
1456 | /* data provided by client */ | |
1457 | /* RadosGW's limit. */ | |
1458 | const size_t max_chunk_size = \ | |
1459 | static_cast<size_t>(s->cct->_conf->rgw_max_chunk_size); | |
1460 | const size_t max_to_read = std::min({ want, conlen - curpos, max_chunk_size }); | |
1461 | ||
1462 | ldout(s->cct, 20) << "bulk_upload: get_at_most max_to_read=" | |
1463 | << max_to_read | |
1464 | << ", dst.c_str()=" << reinterpret_cast<intptr_t>(dst.c_str()) << dendl; | |
1465 | ||
1466 | bufferptr bp(max_to_read); | |
1467 | const auto read_len = recv_body(s, bp.c_str(), max_to_read); | |
1468 | dst.append(bp, 0, read_len); | |
1469 | //const auto read_len = recv_body(s, dst.c_str(), max_to_read); | |
1470 | if (read_len < 0) { | |
1471 | return read_len; | |
1472 | } | |
1473 | ||
1474 | curpos += read_len; | |
1475 | return curpos > s->cct->_conf->rgw_max_put_size ? -ERR_TOO_LARGE | |
1476 | : read_len; | |
1477 | } | |
1478 | ||
1479 | ssize_t get_exactly(size_t want, ceph::bufferlist& dst) override { | |
1480 | ldout(s->cct, 20) << "bulk_upload: get_exactly want=" << want << dendl; | |
1481 | ||
1482 | /* FIXME: do this in a loop. */ | |
1483 | const auto ret = get_at_most(want, dst); | |
1484 | ldout(s->cct, 20) << "bulk_upload: get_exactly ret=" << ret << dendl; | |
1485 | if (ret < 0) { | |
1486 | return ret; | |
1487 | } else if (static_cast<size_t>(ret) != want) { | |
1488 | return -EINVAL; | |
1489 | } else { | |
1490 | return want; | |
1491 | } | |
1492 | } | |
1493 | }; | |
1494 | ||
1495 | if (! s->length) { | |
1496 | op_ret = -EINVAL; | |
1497 | return nullptr; | |
1498 | } else { | |
1499 | ldout(s->cct, 20) << "bulk upload: create_stream for length=" | |
1500 | << s->length << dendl; | |
1501 | ||
1502 | const size_t conlen = atoll(s->length); | |
1503 | return std::unique_ptr<SwiftStreamGetter>(new SwiftStreamGetter(s, conlen)); | |
1504 | } | |
1505 | } | |
1506 | ||
1507 | void RGWBulkUploadOp_ObjStore_SWIFT::send_response() | |
1508 | { | |
1509 | set_req_state_err(s, op_ret); | |
1510 | dump_errno(s); | |
1511 | end_header(s, this /* RGWOp */, nullptr /* contype */, | |
1512 | CHUNKED_TRANSFER_ENCODING); | |
1513 | rgw_flush_formatter_and_reset(s, s->formatter); | |
1514 | ||
1515 | s->formatter->open_object_section("delete"); | |
1516 | ||
1517 | std::string resp_status; | |
1518 | std::string resp_body; | |
1519 | ||
1520 | if (! failures.empty()) { | |
1521 | rgw_err err; | |
1522 | ||
1523 | const auto last_err = { failures.back().err }; | |
1524 | if (boost::algorithm::contains(last_err, terminal_errors)) { | |
1525 | /* The terminal errors are affecting the status of the whole upload. */ | |
1526 | set_req_state_err(err, failures.back().err, s->prot_flags); | |
1527 | } else { | |
1528 | set_req_state_err(err, ERR_INVALID_REQUEST, s->prot_flags); | |
1529 | } | |
1530 | ||
1531 | dump_errno(err, resp_status); | |
1532 | } else if (0 == num_created && failures.empty()) { | |
1533 | /* Nothing created, nothing failed. This means the archive contained no | |
1534 | * entity we could understand (regular file or directory). We need to | |
1535 | * send 400 Bad Request to an HTTP client in the internal status field. */ | |
1536 | dump_errno(400, resp_status); | |
1537 | resp_body = "Invalid Tar File: No Valid Files"; | |
1538 | } else { | |
1539 | /* 200 OK */ | |
1540 | dump_errno(201, resp_status); | |
1541 | } | |
1542 | ||
1543 | encode_json("Number Files Created", num_created, s->formatter); | |
1544 | encode_json("Response Body", resp_body, s->formatter); | |
1545 | encode_json("Response Status", resp_status, s->formatter); | |
1546 | ||
1547 | s->formatter->open_array_section("Errors"); | |
1548 | for (const auto& fail_desc : failures) { | |
1549 | s->formatter->open_array_section("object"); | |
1550 | ||
1551 | encode_json("Name", fail_desc.path, s->formatter); | |
1552 | ||
1553 | rgw_err err; | |
1554 | set_req_state_err(err, fail_desc.err, s->prot_flags); | |
1555 | std::string status; | |
1556 | dump_errno(err, status); | |
1557 | encode_json("Status", status, s->formatter); | |
1558 | ||
1559 | s->formatter->close_section(); | |
1560 | } | |
1561 | s->formatter->close_section(); | |
1562 | ||
1563 | s->formatter->close_section(); | |
1564 | rgw_flush_formatter_and_reset(s, s->formatter); | |
1565 | } | |
1566 | ||
1567 | ||
1568 | void RGWGetCrossDomainPolicy_ObjStore_SWIFT::send_response() | |
1569 | { | |
1570 | set_req_state_err(s, op_ret); | |
1571 | dump_errno(s); | |
1572 | end_header(s, this, "application/xml"); | |
1573 | ||
1574 | std::stringstream ss; | |
1575 | ||
1576 | ss << R"(<?xml version="1.0"?>)" << "\n" | |
1577 | << R"(<!DOCTYPE cross-domain-policy SYSTEM )" | |
1578 | << R"("http://www.adobe.com/xml/dtds/cross-domain-policy.dtd" >)" << "\n" | |
1579 | << R"(<cross-domain-policy>)" << "\n" | |
1580 | << g_conf->rgw_cross_domain_policy << "\n" | |
1581 | << R"(</cross-domain-policy>)"; | |
1582 | ||
1583 | dump_body(s, ss.str()); | |
1584 | } | |
1585 | ||
1586 | void RGWGetHealthCheck_ObjStore_SWIFT::send_response() | |
1587 | { | |
1588 | set_req_state_err(s, op_ret); | |
1589 | dump_errno(s); | |
1590 | end_header(s, this, "application/xml"); | |
1591 | ||
1592 | if (op_ret) { | |
1593 | static constexpr char DISABLED[] = "DISABLED BY FILE"; | |
1594 | dump_body(s, DISABLED, strlen(DISABLED)); | |
1595 | } | |
1596 | } | |
1597 | ||
1598 | const vector<pair<string, RGWInfo_ObjStore_SWIFT::info>> RGWInfo_ObjStore_SWIFT::swift_info = | |
1599 | { | |
1600 | {"bulk_delete", {false, nullptr}}, | |
1601 | {"container_quotas", {false, nullptr}}, | |
1602 | {"swift", {false, RGWInfo_ObjStore_SWIFT::list_swift_data}}, | |
1603 | {"tempurl", { false, RGWInfo_ObjStore_SWIFT::list_tempurl_data}}, | |
1604 | {"slo", {false, RGWInfo_ObjStore_SWIFT::list_slo_data}}, | |
1605 | {"account_quotas", {false, nullptr}}, | |
1606 | {"staticweb", {false, nullptr}}, | |
224ce89b | 1607 | {"tempauth", {false, RGWInfo_ObjStore_SWIFT::list_tempauth_data}}, |
7c673cae FG |
1608 | }; |
1609 | ||
1610 | void RGWInfo_ObjStore_SWIFT::execute() | |
1611 | { | |
1612 | bool is_admin_info_enabled = false; | |
1613 | ||
1614 | const string& swiftinfo_sig = s->info.args.get("swiftinfo_sig"); | |
1615 | const string& swiftinfo_expires = s->info.args.get("swiftinfo_expires"); | |
1616 | ||
1617 | if (!swiftinfo_sig.empty() && | |
1618 | !swiftinfo_expires.empty() && | |
1619 | !is_expired(swiftinfo_expires, s->cct)) { | |
1620 | is_admin_info_enabled = true; | |
1621 | } | |
1622 | ||
1623 | s->formatter->open_object_section("info"); | |
1624 | ||
1625 | for (const auto& pair : swift_info) { | |
1626 | if(!is_admin_info_enabled && pair.second.is_admin_info) | |
1627 | continue; | |
1628 | ||
1629 | if (!pair.second.list_data) { | |
1630 | s->formatter->open_object_section((pair.first).c_str()); | |
1631 | s->formatter->close_section(); | |
1632 | } | |
1633 | else { | |
1634 | pair.second.list_data(*(s->formatter), *(s->cct->_conf), *store); | |
1635 | } | |
1636 | } | |
1637 | ||
1638 | s->formatter->close_section(); | |
1639 | } | |
1640 | ||
1641 | void RGWInfo_ObjStore_SWIFT::send_response() | |
1642 | { | |
1643 | if (op_ret < 0) { | |
1644 | op_ret = STATUS_NO_CONTENT; | |
1645 | } | |
1646 | set_req_state_err(s, op_ret); | |
1647 | dump_errno(s); | |
1648 | end_header(s, this); | |
1649 | rgw_flush_formatter_and_reset(s, s->formatter); | |
1650 | } | |
1651 | ||
1652 | void RGWInfo_ObjStore_SWIFT::list_swift_data(Formatter& formatter, | |
1653 | const md_config_t& config, | |
1654 | RGWRados& store) | |
1655 | { | |
1656 | formatter.open_object_section("swift"); | |
1657 | formatter.dump_int("max_file_size", config.rgw_max_put_size); | |
1658 | formatter.dump_int("container_listing_limit", RGW_LIST_BUCKETS_LIMIT_MAX); | |
1659 | ||
1660 | string ceph_version(CEPH_GIT_NICE_VER); | |
1661 | formatter.dump_string("version", ceph_version); | |
1662 | formatter.dump_int("max_meta_name_length", 81); | |
1663 | ||
1664 | formatter.open_array_section("policies"); | |
1665 | RGWZoneGroup& zonegroup = store.get_zonegroup(); | |
1666 | ||
1667 | for (const auto& placement_targets : zonegroup.placement_targets) { | |
1668 | formatter.open_object_section("policy"); | |
1669 | if (placement_targets.second.name.compare(zonegroup.default_placement) == 0) | |
1670 | formatter.dump_bool("default", true); | |
1671 | formatter.dump_string("name", placement_targets.second.name.c_str()); | |
1672 | formatter.close_section(); | |
1673 | } | |
1674 | formatter.close_section(); | |
1675 | ||
1676 | formatter.dump_int("max_object_name_size", RGWHandler_REST::MAX_OBJ_NAME_LEN); | |
1677 | formatter.dump_bool("strict_cors_mode", true); | |
1678 | formatter.dump_int("max_container_name_length", RGWHandler_REST::MAX_BUCKET_NAME_LEN); | |
1679 | formatter.close_section(); | |
1680 | } | |
1681 | ||
224ce89b WB |
1682 | void RGWInfo_ObjStore_SWIFT::list_tempauth_data(Formatter& formatter, |
1683 | const md_config_t& config, | |
1684 | RGWRados& store) | |
1685 | { | |
1686 | formatter.open_object_section("tempauth"); | |
1687 | formatter.dump_bool("account_acls", true); | |
1688 | formatter.close_section(); | |
1689 | } | |
7c673cae FG |
1690 | void RGWInfo_ObjStore_SWIFT::list_tempurl_data(Formatter& formatter, |
1691 | const md_config_t& config, | |
1692 | RGWRados& store) | |
1693 | { | |
1694 | formatter.open_object_section("tempurl"); | |
1695 | formatter.open_array_section("methods"); | |
1696 | formatter.dump_string("methodname", "GET"); | |
1697 | formatter.dump_string("methodname", "HEAD"); | |
1698 | formatter.dump_string("methodname", "PUT"); | |
1699 | formatter.dump_string("methodname", "POST"); | |
1700 | formatter.dump_string("methodname", "DELETE"); | |
1701 | formatter.close_section(); | |
1702 | formatter.close_section(); | |
1703 | } | |
1704 | ||
1705 | void RGWInfo_ObjStore_SWIFT::list_slo_data(Formatter& formatter, | |
1706 | const md_config_t& config, | |
1707 | RGWRados& store) | |
1708 | { | |
1709 | formatter.open_object_section("slo"); | |
1710 | formatter.dump_int("max_manifest_segments", config.rgw_max_slo_entries); | |
1711 | formatter.close_section(); | |
1712 | } | |
1713 | ||
1714 | bool RGWInfo_ObjStore_SWIFT::is_expired(const std::string& expires, CephContext* cct) | |
1715 | { | |
1716 | string err; | |
1717 | const utime_t now = ceph_clock_now(); | |
1718 | const uint64_t expiration = (uint64_t)strict_strtoll(expires.c_str(), | |
1719 | 10, &err); | |
1720 | if (!err.empty()) { | |
1721 | ldout(cct, 5) << "failed to parse siginfo_expires: " << err << dendl; | |
1722 | return true; | |
1723 | } | |
1724 | ||
1725 | if (expiration <= (uint64_t)now.sec()) { | |
1726 | ldout(cct, 5) << "siginfo expired: " << expiration << " <= " << now.sec() << dendl; | |
1727 | return true; | |
1728 | } | |
1729 | ||
1730 | return false; | |
1731 | } | |
1732 | ||
1733 | ||
1734 | void RGWFormPost::init(RGWRados* const store, | |
1735 | req_state* const s, | |
1736 | RGWHandler* const dialect_handler) | |
1737 | { | |
1738 | prefix = std::move(s->object.name); | |
1739 | s->object = rgw_obj_key(); | |
1740 | ||
1741 | return RGWPostObj_ObjStore::init(store, s, dialect_handler); | |
1742 | } | |
1743 | ||
1744 | std::size_t RGWFormPost::get_max_file_size() /*const*/ | |
1745 | { | |
1746 | std::string max_str = get_part_str(ctrl_parts, "max_file_size", "0"); | |
1747 | ||
1748 | std::string err; | |
1749 | const std::size_t max_file_size = | |
1750 | static_cast<uint64_t>(strict_strtoll(max_str.c_str(), 10, &err)); | |
1751 | ||
1752 | if (! err.empty()) { | |
1753 | ldout(s->cct, 5) << "failed to parse FormPost's max_file_size: " << err | |
1754 | << dendl; | |
1755 | return 0; | |
1756 | } | |
1757 | ||
1758 | return max_file_size; | |
1759 | } | |
1760 | ||
1761 | bool RGWFormPost::is_non_expired() | |
1762 | { | |
1763 | std::string expires = get_part_str(ctrl_parts, "expires", "0"); | |
1764 | ||
1765 | std::string err; | |
1766 | const uint64_t expires_timestamp = | |
1767 | static_cast<uint64_t>(strict_strtoll(expires.c_str(), 10, &err)); | |
1768 | ||
1769 | if (! err.empty()) { | |
1770 | dout(5) << "failed to parse FormPost's expires: " << err << dendl; | |
1771 | return false; | |
1772 | } | |
1773 | ||
1774 | const utime_t now = ceph_clock_now(); | |
1775 | if (expires_timestamp <= static_cast<uint64_t>(now.sec())) { | |
1776 | dout(5) << "FormPost form expired: " | |
1777 | << expires_timestamp << " <= " << now.sec() << dendl; | |
1778 | return false; | |
1779 | } | |
1780 | ||
1781 | return true; | |
1782 | } | |
1783 | ||
1784 | bool RGWFormPost::is_integral() | |
1785 | { | |
1786 | const std::string form_signature = get_part_str(ctrl_parts, "signature"); | |
1787 | ||
31f18b77 FG |
1788 | try { |
1789 | get_owner_info(s, *s->user); | |
1790 | s->auth.identity = rgw::auth::transform_old_authinfo(s); | |
1791 | } catch (...) { | |
1792 | ldout(s->cct, 5) << "cannot get user_info of account's owner" << dendl; | |
1793 | return false; | |
1794 | } | |
1795 | ||
7c673cae FG |
1796 | for (const auto& kv : s->user->temp_url_keys) { |
1797 | const int temp_url_key_num = kv.first; | |
1798 | const string& temp_url_key = kv.second; | |
1799 | ||
1800 | if (temp_url_key.empty()) { | |
1801 | continue; | |
1802 | } | |
1803 | ||
1804 | SignatureHelper sig_helper; | |
1805 | sig_helper.calc(temp_url_key, | |
1806 | s->info.request_uri, | |
1807 | get_part_str(ctrl_parts, "redirect"), | |
1808 | get_part_str(ctrl_parts, "max_file_size", "0"), | |
1809 | get_part_str(ctrl_parts, "max_file_count", "0"), | |
1810 | get_part_str(ctrl_parts, "expires", "0")); | |
1811 | ||
1812 | const auto local_sig = sig_helper.get_signature(); | |
1813 | ||
1814 | ldout(s->cct, 20) << "FormPost signature [" << temp_url_key_num << "]" | |
1815 | << " (calculated): " << local_sig << dendl; | |
1816 | ||
1817 | if (sig_helper.is_equal_to(form_signature)) { | |
1818 | return true; | |
1819 | } else { | |
1820 | ldout(s->cct, 5) << "FormPost's signature mismatch: " | |
1821 | << local_sig << " != " << form_signature << dendl; | |
1822 | } | |
1823 | } | |
1824 | ||
1825 | return false; | |
1826 | } | |
1827 | ||
31f18b77 FG |
1828 | void RGWFormPost::get_owner_info(const req_state* const s, |
1829 | RGWUserInfo& owner_info) const | |
1830 | { | |
1831 | /* We cannot use req_state::bucket_name because it isn't available | |
1832 | * now. It will be initialized in RGWHandler_REST_SWIFT::postauth_init(). */ | |
1833 | const string& bucket_name = s->init_state.url_bucket; | |
1834 | ||
1835 | /* TempURL in Formpost only requires that bucket name is specified. */ | |
1836 | if (bucket_name.empty()) { | |
1837 | throw -EPERM; | |
1838 | } | |
1839 | ||
1840 | string bucket_tenant; | |
1841 | if (!s->account_name.empty()) { | |
1842 | RGWUserInfo uinfo; | |
1843 | bool found = false; | |
1844 | ||
1845 | const rgw_user uid(s->account_name); | |
1846 | if (uid.tenant.empty()) { | |
1847 | const rgw_user tenanted_uid(uid.id, uid.id); | |
1848 | ||
1849 | if (rgw_get_user_info_by_uid(store, tenanted_uid, uinfo) >= 0) { | |
1850 | /* Succeeded. */ | |
1851 | bucket_tenant = uinfo.user_id.tenant; | |
1852 | found = true; | |
1853 | } | |
1854 | } | |
1855 | ||
1856 | if (!found && rgw_get_user_info_by_uid(store, uid, uinfo) < 0) { | |
1857 | throw -EPERM; | |
1858 | } else { | |
1859 | bucket_tenant = uinfo.user_id.tenant; | |
1860 | } | |
1861 | } | |
1862 | ||
1863 | /* Need to get user info of bucket owner. */ | |
1864 | RGWBucketInfo bucket_info; | |
1865 | int ret = store->get_bucket_info(*static_cast<RGWObjectCtx *>(s->obj_ctx), | |
1866 | bucket_tenant, bucket_name, | |
1867 | bucket_info, nullptr); | |
1868 | if (ret < 0) { | |
1869 | throw ret; | |
1870 | } | |
1871 | ||
1872 | ldout(s->cct, 20) << "temp url user (bucket owner): " << bucket_info.owner | |
1873 | << dendl; | |
1874 | ||
1875 | if (rgw_get_user_info_by_uid(store, bucket_info.owner, owner_info) < 0) { | |
1876 | throw -EPERM; | |
1877 | } | |
1878 | } | |
1879 | ||
7c673cae FG |
1880 | int RGWFormPost::get_params() |
1881 | { | |
1882 | /* The parentt class extracts boundary info from the Content-Type. */ | |
1883 | int ret = RGWPostObj_ObjStore::get_params(); | |
1884 | if (ret < 0) { | |
1885 | return ret; | |
1886 | } | |
1887 | ||
1888 | policy.create_default(s->user->user_id, s->user->display_name); | |
1889 | ||
1890 | /* Let's start parsing the HTTP body by parsing each form part step- | |
1891 | * by-step till encountering the first part with file data. */ | |
1892 | do { | |
1893 | struct post_form_part part; | |
1894 | ret = read_form_part_header(&part, stream_done); | |
1895 | if (ret < 0) { | |
1896 | return ret; | |
1897 | } | |
1898 | ||
1899 | if (s->cct->_conf->subsys.should_gather(ceph_subsys_rgw, 20)) { | |
1900 | ldout(s->cct, 20) << "read part header -- part.name=" | |
1901 | << part.name << dendl; | |
1902 | ||
1903 | for (const auto& pair : part.fields) { | |
1904 | ldout(s->cct, 20) << "field.name=" << pair.first << dendl; | |
1905 | ldout(s->cct, 20) << "field.val=" << pair.second.val << dendl; | |
1906 | ldout(s->cct, 20) << "field.params:" << dendl; | |
1907 | ||
1908 | for (const auto& param_pair : pair.second.params) { | |
1909 | ldout(s->cct, 20) << " " << param_pair.first | |
1910 | << " -> " << param_pair.second << dendl; | |
1911 | } | |
1912 | } | |
1913 | } | |
1914 | ||
1915 | if (stream_done) { | |
1916 | /* Unexpected here. */ | |
1917 | err_msg = "Malformed request"; | |
1918 | return -EINVAL; | |
1919 | } | |
1920 | ||
1921 | const auto field_iter = part.fields.find("Content-Disposition"); | |
1922 | if (std::end(part.fields) != field_iter && | |
1923 | std::end(field_iter->second.params) != field_iter->second.params.find("filename")) { | |
1924 | /* First data part ahead. */ | |
1925 | current_data_part = std::move(part); | |
1926 | ||
1927 | /* Stop the iteration. We can assume that all control parts have been | |
1928 | * already parsed. The rest of HTTP body should contain data parts | |
1929 | * only. They will be picked up by ::get_data(). */ | |
1930 | break; | |
1931 | } else { | |
1932 | /* Control part ahead. Receive, parse and store for later usage. */ | |
1933 | bool boundary; | |
1934 | ret = read_data(part.data, s->cct->_conf->rgw_max_chunk_size, | |
1935 | boundary, stream_done); | |
1936 | if (ret < 0) { | |
1937 | return ret; | |
1938 | } else if (! boundary) { | |
1939 | err_msg = "Couldn't find boundary"; | |
1940 | return -EINVAL; | |
1941 | } | |
1942 | ||
1943 | ctrl_parts[part.name] = std::move(part); | |
1944 | } | |
1945 | } while (! stream_done); | |
1946 | ||
1947 | min_len = 0; | |
1948 | max_len = get_max_file_size(); | |
1949 | ||
1950 | if (! current_data_part) { | |
1951 | err_msg = "FormPost: no files to process"; | |
1952 | return -EINVAL; | |
1953 | } | |
1954 | ||
1955 | if (! is_non_expired()) { | |
1956 | err_msg = "FormPost: Form Expired"; | |
1957 | return -EPERM; | |
1958 | } | |
1959 | ||
1960 | if (! is_integral()) { | |
1961 | err_msg = "FormPost: Invalid Signature"; | |
1962 | return -EPERM; | |
1963 | } | |
1964 | ||
1965 | return 0; | |
1966 | } | |
1967 | ||
1968 | std::string RGWFormPost::get_current_filename() const | |
1969 | { | |
1970 | try { | |
1971 | const auto& field = current_data_part->fields.at("Content-Disposition"); | |
1972 | const auto iter = field.params.find("filename"); | |
1973 | ||
1974 | if (std::end(field.params) != iter) { | |
1975 | return prefix + iter->second; | |
1976 | } | |
1977 | } catch (std::out_of_range&) { | |
1978 | /* NOP */; | |
1979 | } | |
1980 | ||
1981 | return prefix; | |
1982 | } | |
1983 | ||
1984 | std::string RGWFormPost::get_current_content_type() const | |
1985 | { | |
1986 | try { | |
1987 | const auto& field = current_data_part->fields.at("Content-Type"); | |
1988 | return field.val; | |
1989 | } catch (std::out_of_range&) { | |
1990 | /* NOP */; | |
1991 | } | |
1992 | ||
1993 | return std::string(); | |
1994 | } | |
1995 | ||
1996 | bool RGWFormPost::is_next_file_to_upload() | |
1997 | { | |
1998 | if (! stream_done) { | |
1999 | /* We have at least one additional part in the body. */ | |
2000 | struct post_form_part part; | |
2001 | int r = read_form_part_header(&part, stream_done); | |
2002 | if (r < 0) { | |
2003 | return false; | |
2004 | } | |
2005 | ||
2006 | const auto field_iter = part.fields.find("Content-Disposition"); | |
2007 | if (std::end(part.fields) != field_iter) { | |
2008 | const auto& params = field_iter->second.params; | |
31f18b77 | 2009 | const auto& filename_iter = params.find("filename"); |
7c673cae | 2010 | |
31f18b77 | 2011 | if (std::end(params) != filename_iter && ! filename_iter->second.empty()) { |
7c673cae FG |
2012 | current_data_part = std::move(part); |
2013 | return true; | |
2014 | } | |
2015 | } | |
2016 | } | |
2017 | ||
2018 | return false; | |
2019 | } | |
2020 | ||
2021 | int RGWFormPost::get_data(ceph::bufferlist& bl, bool& again) | |
2022 | { | |
2023 | bool boundary; | |
2024 | ||
2025 | int r = read_data(bl, s->cct->_conf->rgw_max_chunk_size, | |
2026 | boundary, stream_done); | |
2027 | if (r < 0) { | |
2028 | return r; | |
2029 | } | |
2030 | ||
2031 | /* Tell RGWPostObj::execute() that it has some data to put. */ | |
2032 | again = !boundary; | |
2033 | ||
2034 | return bl.length(); | |
2035 | } | |
2036 | ||
2037 | void RGWFormPost::send_response() | |
2038 | { | |
2039 | std::string redirect = get_part_str(ctrl_parts, "redirect"); | |
2040 | if (! redirect.empty()) { | |
2041 | op_ret = STATUS_REDIRECT; | |
2042 | } | |
2043 | ||
2044 | set_req_state_err(s, op_ret); | |
31f18b77 | 2045 | s->err.err_code = err_msg; |
7c673cae FG |
2046 | dump_errno(s); |
2047 | if (! redirect.empty()) { | |
2048 | dump_redirect(s, redirect); | |
2049 | } | |
2050 | end_header(s, this); | |
2051 | } | |
2052 | ||
2053 | bool RGWFormPost::is_formpost_req(req_state* const s) | |
2054 | { | |
2055 | std::string content_type; | |
2056 | std::map<std::string, std::string> params; | |
2057 | ||
2058 | parse_boundary_params(s->info.env->get("CONTENT_TYPE", ""), | |
2059 | content_type, params); | |
2060 | ||
2061 | return boost::algorithm::iequals(content_type, "multipart/form-data") && | |
2062 | params.count("boundary") > 0; | |
2063 | } | |
2064 | ||
2065 | ||
2066 | RGWOp *RGWHandler_REST_Service_SWIFT::op_get() | |
2067 | { | |
2068 | return new RGWListBuckets_ObjStore_SWIFT; | |
2069 | } | |
2070 | ||
2071 | RGWOp *RGWHandler_REST_Service_SWIFT::op_head() | |
2072 | { | |
2073 | return new RGWStatAccount_ObjStore_SWIFT; | |
2074 | } | |
2075 | ||
2076 | RGWOp *RGWHandler_REST_Service_SWIFT::op_put() | |
2077 | { | |
2078 | if (s->info.args.exists("extract-archive")) { | |
2079 | return new RGWBulkUploadOp_ObjStore_SWIFT; | |
2080 | } | |
2081 | return nullptr; | |
2082 | } | |
2083 | ||
2084 | RGWOp *RGWHandler_REST_Service_SWIFT::op_post() | |
2085 | { | |
2086 | if (s->info.args.exists("bulk-delete")) { | |
2087 | return new RGWBulkDelete_ObjStore_SWIFT; | |
2088 | } | |
2089 | return new RGWPutMetadataAccount_ObjStore_SWIFT; | |
2090 | } | |
2091 | ||
2092 | RGWOp *RGWHandler_REST_Service_SWIFT::op_delete() | |
2093 | { | |
2094 | if (s->info.args.exists("bulk-delete")) { | |
2095 | return new RGWBulkDelete_ObjStore_SWIFT; | |
2096 | } | |
2097 | return NULL; | |
2098 | } | |
2099 | ||
2100 | int RGWSwiftWebsiteHandler::serve_errordoc(const int http_ret, | |
2101 | const std::string error_doc) | |
2102 | { | |
2103 | /* Try to throw it all away. */ | |
2104 | s->formatter->reset(); | |
2105 | ||
2106 | class RGWGetErrorPage : public RGWGetObj_ObjStore_SWIFT { | |
2107 | public: | |
2108 | RGWGetErrorPage(RGWRados* const store, | |
2109 | RGWHandler_REST* const handler, | |
2110 | req_state* const s, | |
2111 | const int http_ret) { | |
2112 | /* Calling a virtual from the base class is safe as the subobject should | |
2113 | * be properly initialized and we haven't overridden the init method. */ | |
2114 | init(store, s, handler); | |
2115 | set_get_data(true); | |
2116 | set_custom_http_response(http_ret); | |
2117 | } | |
2118 | ||
2119 | int error_handler(const int err_no, | |
2120 | std::string* const error_content) override { | |
2121 | /* Enforce that any error generated while getting the error page will | |
2122 | * not be send to a client. This allows us to recover from the double | |
2123 | * fault situation by sending the original message. */ | |
2124 | return 0; | |
2125 | } | |
2126 | } get_errpage_op(store, handler, s, http_ret); | |
2127 | ||
2128 | s->object = std::to_string(http_ret) + error_doc; | |
2129 | ||
2130 | RGWOp* newop = &get_errpage_op; | |
2131 | RGWRequest req(0); | |
2132 | return rgw_process_authenticated(handler, newop, &req, s, true); | |
2133 | } | |
2134 | ||
2135 | int RGWSwiftWebsiteHandler::error_handler(const int err_no, | |
2136 | std::string* const error_content) | |
2137 | { | |
2138 | const auto& ws_conf = s->bucket_info.website_conf; | |
2139 | ||
2140 | if (can_be_website_req() && ! ws_conf.error_doc.empty()) { | |
31f18b77 FG |
2141 | set_req_state_err(s, err_no); |
2142 | return serve_errordoc(s->err.http_ret, ws_conf.error_doc); | |
7c673cae FG |
2143 | } |
2144 | ||
2145 | /* Let's go to the default, no-op handler. */ | |
2146 | return err_no; | |
2147 | } | |
2148 | ||
2149 | bool RGWSwiftWebsiteHandler::is_web_mode() const | |
2150 | { | |
2151 | const boost::string_ref webmode = s->info.env->get("HTTP_X_WEB_MODE", ""); | |
2152 | return boost::algorithm::iequals(webmode, "true"); | |
2153 | } | |
2154 | ||
2155 | bool RGWSwiftWebsiteHandler::can_be_website_req() const | |
2156 | { | |
2157 | /* Static website works only with the GET or HEAD method. Nothing more. */ | |
2158 | static const std::set<boost::string_ref> ws_methods = { "GET", "HEAD" }; | |
2159 | if (ws_methods.count(s->info.method) == 0) { | |
2160 | return false; | |
2161 | } | |
2162 | ||
2163 | /* We also need to handle early failures from the auth system. In such cases | |
2164 | * req_state::auth.identity may be empty. Let's treat that the same way as | |
2165 | * the anonymous access. */ | |
2166 | if (! s->auth.identity) { | |
2167 | return true; | |
2168 | } | |
2169 | ||
2170 | /* Swift serves websites only for anonymous requests unless client explicitly | |
2171 | * requested this behaviour by supplying X-Web-Mode HTTP header set to true. */ | |
2172 | if (s->auth.identity->is_anonymous() || is_web_mode()) { | |
2173 | return true; | |
2174 | } | |
2175 | ||
2176 | return false; | |
2177 | } | |
2178 | ||
2179 | RGWOp* RGWSwiftWebsiteHandler::get_ws_redirect_op() | |
2180 | { | |
2181 | class RGWMovedPermanently: public RGWOp { | |
2182 | const std::string location; | |
2183 | public: | |
2184 | RGWMovedPermanently(const std::string& location) | |
2185 | : location(location) { | |
2186 | } | |
2187 | ||
2188 | int verify_permission() override { | |
2189 | return 0; | |
2190 | } | |
2191 | ||
2192 | void execute() override { | |
2193 | op_ret = -ERR_PERMANENT_REDIRECT; | |
2194 | return; | |
2195 | } | |
2196 | ||
2197 | void send_response() override { | |
2198 | set_req_state_err(s, op_ret); | |
2199 | dump_errno(s); | |
2200 | dump_content_length(s, 0); | |
2201 | dump_redirect(s, location); | |
2202 | end_header(s, this); | |
2203 | } | |
2204 | ||
2205 | const string name() override { | |
2206 | return "RGWMovedPermanently"; | |
2207 | } | |
2208 | }; | |
2209 | ||
2210 | return new RGWMovedPermanently(s->info.request_uri + '/'); | |
2211 | } | |
2212 | ||
2213 | RGWOp* RGWSwiftWebsiteHandler::get_ws_index_op() | |
2214 | { | |
2215 | /* Retarget to get obj on requested index file. */ | |
2216 | if (! s->object.empty()) { | |
2217 | s->object = s->object.name + | |
2218 | s->bucket_info.website_conf.get_index_doc(); | |
2219 | } else { | |
2220 | s->object = s->bucket_info.website_conf.get_index_doc(); | |
2221 | } | |
2222 | ||
2223 | auto getop = new RGWGetObj_ObjStore_SWIFT; | |
2224 | getop->set_get_data(boost::algorithm::equals("GET", s->info.method)); | |
2225 | ||
2226 | return getop; | |
2227 | } | |
2228 | ||
2229 | RGWOp* RGWSwiftWebsiteHandler::get_ws_listing_op() | |
2230 | { | |
2231 | class RGWWebsiteListing : public RGWListBucket_ObjStore_SWIFT { | |
2232 | const std::string prefix_override; | |
2233 | ||
2234 | int get_params() override { | |
2235 | prefix = prefix_override; | |
2236 | max = default_max; | |
2237 | delimiter = "/"; | |
2238 | return 0; | |
2239 | } | |
2240 | ||
2241 | void send_response() override { | |
2242 | /* Generate the header now. */ | |
2243 | set_req_state_err(s, op_ret); | |
2244 | dump_errno(s); | |
2245 | dump_container_metadata(s, bucket, bucket_quota, | |
2246 | s->bucket_info.website_conf); | |
2247 | end_header(s, this, "text/html"); | |
2248 | if (op_ret < 0) { | |
2249 | return; | |
2250 | } | |
2251 | ||
2252 | /* Now it's the time to start generating HTML bucket listing. | |
2253 | * All the crazy stuff with crafting tags will be delegated to | |
2254 | * RGWSwiftWebsiteListingFormatter. */ | |
2255 | std::stringstream ss; | |
2256 | RGWSwiftWebsiteListingFormatter htmler(ss, prefix); | |
2257 | ||
2258 | const auto& ws_conf = s->bucket_info.website_conf; | |
2259 | htmler.generate_header(s->decoded_uri, | |
2260 | ws_conf.listing_css_doc); | |
2261 | ||
2262 | for (const auto& pair : common_prefixes) { | |
2263 | std::string subdir_name = pair.first; | |
2264 | if (! subdir_name.empty()) { | |
2265 | /* To be compliant with Swift we need to remove the trailing | |
2266 | * slash. */ | |
2267 | subdir_name.pop_back(); | |
2268 | } | |
2269 | ||
2270 | htmler.dump_subdir(subdir_name); | |
2271 | } | |
2272 | ||
2273 | for (const rgw_bucket_dir_entry& obj : objs) { | |
2274 | if (! common_prefixes.count(obj.key.name + '/')) { | |
2275 | htmler.dump_object(obj); | |
2276 | } | |
2277 | } | |
2278 | ||
2279 | htmler.generate_footer(); | |
2280 | dump_body(s, ss.str()); | |
2281 | } | |
2282 | public: | |
2283 | /* Taking prefix_override by value to leverage std::string r-value ref | |
2284 | * ctor and thus avoid extra memory copying/increasing ref counter. */ | |
2285 | RGWWebsiteListing(std::string prefix_override) | |
2286 | : prefix_override(std::move(prefix_override)) { | |
2287 | } | |
2288 | }; | |
2289 | ||
2290 | std::string prefix = std::move(s->object.name); | |
2291 | s->object = rgw_obj_key(); | |
2292 | ||
2293 | return new RGWWebsiteListing(std::move(prefix)); | |
2294 | } | |
2295 | ||
2296 | bool RGWSwiftWebsiteHandler::is_web_dir() const | |
2297 | { | |
31f18b77 | 2298 | std::string subdir_name = url_decode(s->object.name); |
7c673cae FG |
2299 | |
2300 | /* Remove character from the subdir name if it is "/". */ | |
2301 | if (subdir_name.empty()) { | |
2302 | return false; | |
2303 | } else if (subdir_name.back() == '/') { | |
2304 | subdir_name.pop_back(); | |
2305 | } | |
2306 | ||
31f18b77 | 2307 | rgw_obj obj(s->bucket, std::move(subdir_name)); |
7c673cae FG |
2308 | |
2309 | /* First, get attrset of the object we'll try to retrieve. */ | |
2310 | RGWObjectCtx& obj_ctx = *static_cast<RGWObjectCtx *>(s->obj_ctx); | |
2311 | obj_ctx.obj.set_atomic(obj); | |
2312 | obj_ctx.obj.set_prefetch_data(obj); | |
2313 | ||
2314 | RGWObjState* state = nullptr; | |
2315 | if (store->get_obj_state(&obj_ctx, s->bucket_info, obj, &state, false) < 0) { | |
2316 | return false; | |
2317 | } | |
2318 | ||
2319 | /* A nonexistent object cannot be a considered as a marker representing | |
2320 | * the emulation of catalog in FS hierarchy. */ | |
2321 | if (! state->exists) { | |
2322 | return false; | |
2323 | } | |
2324 | ||
2325 | /* Decode the content type. */ | |
2326 | std::string content_type; | |
2327 | get_contype_from_attrs(state->attrset, content_type); | |
2328 | ||
2329 | const auto& ws_conf = s->bucket_info.website_conf; | |
2330 | const std::string subdir_marker = ws_conf.subdir_marker.empty() | |
2331 | ? "application/directory" | |
2332 | : ws_conf.subdir_marker; | |
2333 | return subdir_marker == content_type && state->size <= 1; | |
2334 | } | |
2335 | ||
2336 | bool RGWSwiftWebsiteHandler::is_index_present(const std::string& index) | |
2337 | { | |
2338 | rgw_obj obj(s->bucket, index); | |
2339 | ||
2340 | RGWObjectCtx& obj_ctx = *static_cast<RGWObjectCtx *>(s->obj_ctx); | |
2341 | obj_ctx.obj.set_atomic(obj); | |
2342 | obj_ctx.obj.set_prefetch_data(obj); | |
2343 | ||
2344 | RGWObjState* state = nullptr; | |
2345 | if (store->get_obj_state(&obj_ctx, s->bucket_info, obj, &state, false) < 0) { | |
2346 | return false; | |
2347 | } | |
2348 | ||
2349 | /* A nonexistent object cannot be a considered as a viable index. We will | |
2350 | * try to list the bucket or - if this is impossible - return an error. */ | |
2351 | return state->exists; | |
2352 | } | |
2353 | ||
2354 | int RGWSwiftWebsiteHandler::retarget_bucket(RGWOp* op, RGWOp** new_op) | |
2355 | { | |
2356 | ldout(s->cct, 10) << "Starting retarget" << dendl; | |
2357 | RGWOp* op_override = nullptr; | |
2358 | ||
2359 | /* In Swift static web content is served if the request is anonymous or | |
2360 | * has X-Web-Mode HTTP header specified to true. */ | |
2361 | if (can_be_website_req()) { | |
2362 | const auto& ws_conf = s->bucket_info.website_conf; | |
2363 | const auto& index = s->bucket_info.website_conf.get_index_doc(); | |
2364 | ||
2365 | if (s->decoded_uri.back() != '/') { | |
2366 | op_override = get_ws_redirect_op(); | |
2367 | } else if (! index.empty() && is_index_present(index)) { | |
2368 | op_override = get_ws_index_op(); | |
2369 | } else if (ws_conf.listing_enabled) { | |
2370 | op_override = get_ws_listing_op(); | |
2371 | } | |
2372 | } | |
2373 | ||
2374 | if (op_override) { | |
2375 | handler->put_op(op); | |
2376 | op_override->init(store, s, handler); | |
2377 | ||
2378 | *new_op = op_override; | |
2379 | } else { | |
2380 | *new_op = op; | |
2381 | } | |
2382 | ||
2383 | /* Return 404 Not Found is the request has web mode enforced but we static web | |
2384 | * wasn't able to serve it accordingly. */ | |
2385 | return ! op_override && is_web_mode() ? -ENOENT : 0; | |
2386 | } | |
2387 | ||
2388 | int RGWSwiftWebsiteHandler::retarget_object(RGWOp* op, RGWOp** new_op) | |
2389 | { | |
2390 | ldout(s->cct, 10) << "Starting object retarget" << dendl; | |
2391 | RGWOp* op_override = nullptr; | |
2392 | ||
2393 | /* In Swift static web content is served if the request is anonymous or | |
2394 | * has X-Web-Mode HTTP header specified to true. */ | |
2395 | if (can_be_website_req() && is_web_dir()) { | |
2396 | const auto& ws_conf = s->bucket_info.website_conf; | |
2397 | const auto& index = s->bucket_info.website_conf.get_index_doc(); | |
2398 | ||
2399 | if (s->decoded_uri.back() != '/') { | |
2400 | op_override = get_ws_redirect_op(); | |
2401 | } else if (! index.empty() && is_index_present(index)) { | |
2402 | op_override = get_ws_index_op(); | |
2403 | } else if (ws_conf.listing_enabled) { | |
2404 | op_override = get_ws_listing_op(); | |
2405 | } | |
2406 | } else { | |
2407 | /* A regular request or the specified object isn't a subdirectory marker. | |
2408 | * We don't need any re-targeting. Error handling (like sending a custom | |
2409 | * error page) will be performed by error_handler of the actual RGWOp. */ | |
2410 | return 0; | |
2411 | } | |
2412 | ||
2413 | if (op_override) { | |
2414 | handler->put_op(op); | |
2415 | op_override->init(store, s, handler); | |
2416 | ||
2417 | *new_op = op_override; | |
2418 | } else { | |
2419 | *new_op = op; | |
2420 | } | |
2421 | ||
2422 | /* Return 404 Not Found if we aren't able to re-target for subdir marker. */ | |
2423 | return ! op_override ? -ENOENT : 0; | |
2424 | } | |
2425 | ||
2426 | ||
2427 | RGWOp *RGWHandler_REST_Bucket_SWIFT::get_obj_op(bool get_data) | |
2428 | { | |
2429 | if (is_acl_op()) { | |
2430 | return new RGWGetACLs_ObjStore_SWIFT; | |
2431 | } | |
2432 | ||
2433 | if (get_data) | |
2434 | return new RGWListBucket_ObjStore_SWIFT; | |
2435 | else | |
2436 | return new RGWStatBucket_ObjStore_SWIFT; | |
2437 | } | |
2438 | ||
2439 | RGWOp *RGWHandler_REST_Bucket_SWIFT::op_get() | |
2440 | { | |
2441 | return get_obj_op(true); | |
2442 | } | |
2443 | ||
2444 | RGWOp *RGWHandler_REST_Bucket_SWIFT::op_head() | |
2445 | { | |
2446 | return get_obj_op(false); | |
2447 | } | |
2448 | ||
2449 | RGWOp *RGWHandler_REST_Bucket_SWIFT::op_put() | |
2450 | { | |
2451 | if (is_acl_op()) { | |
2452 | return new RGWPutACLs_ObjStore_SWIFT; | |
2453 | } | |
2454 | if(s->info.args.exists("extract-archive")) { | |
2455 | return new RGWBulkUploadOp_ObjStore_SWIFT; | |
2456 | } | |
2457 | return new RGWCreateBucket_ObjStore_SWIFT; | |
2458 | } | |
2459 | ||
2460 | RGWOp *RGWHandler_REST_Bucket_SWIFT::op_delete() | |
2461 | { | |
2462 | return new RGWDeleteBucket_ObjStore_SWIFT; | |
2463 | } | |
2464 | ||
2465 | RGWOp *RGWHandler_REST_Bucket_SWIFT::op_post() | |
2466 | { | |
2467 | if (RGWFormPost::is_formpost_req(s)) { | |
2468 | return new RGWFormPost; | |
2469 | } else { | |
2470 | return new RGWPutMetadataBucket_ObjStore_SWIFT; | |
2471 | } | |
2472 | } | |
2473 | ||
2474 | RGWOp *RGWHandler_REST_Bucket_SWIFT::op_options() | |
2475 | { | |
2476 | return new RGWOptionsCORS_ObjStore_SWIFT; | |
2477 | } | |
2478 | ||
2479 | ||
2480 | RGWOp *RGWHandler_REST_Obj_SWIFT::get_obj_op(bool get_data) | |
2481 | { | |
2482 | if (is_acl_op()) { | |
2483 | return new RGWGetACLs_ObjStore_SWIFT; | |
2484 | } | |
2485 | ||
2486 | RGWGetObj_ObjStore_SWIFT *get_obj_op = new RGWGetObj_ObjStore_SWIFT; | |
2487 | get_obj_op->set_get_data(get_data); | |
2488 | return get_obj_op; | |
2489 | } | |
2490 | ||
2491 | RGWOp *RGWHandler_REST_Obj_SWIFT::op_get() | |
2492 | { | |
2493 | return get_obj_op(true); | |
2494 | } | |
2495 | ||
2496 | RGWOp *RGWHandler_REST_Obj_SWIFT::op_head() | |
2497 | { | |
2498 | return get_obj_op(false); | |
2499 | } | |
2500 | ||
2501 | RGWOp *RGWHandler_REST_Obj_SWIFT::op_put() | |
2502 | { | |
2503 | if (is_acl_op()) { | |
2504 | return new RGWPutACLs_ObjStore_SWIFT; | |
2505 | } | |
2506 | if(s->info.args.exists("extract-archive")) { | |
2507 | return new RGWBulkUploadOp_ObjStore_SWIFT; | |
2508 | } | |
2509 | if (s->init_state.src_bucket.empty()) | |
2510 | return new RGWPutObj_ObjStore_SWIFT; | |
2511 | else | |
2512 | return new RGWCopyObj_ObjStore_SWIFT; | |
2513 | } | |
2514 | ||
2515 | RGWOp *RGWHandler_REST_Obj_SWIFT::op_delete() | |
2516 | { | |
2517 | return new RGWDeleteObj_ObjStore_SWIFT; | |
2518 | } | |
2519 | ||
2520 | RGWOp *RGWHandler_REST_Obj_SWIFT::op_post() | |
2521 | { | |
2522 | if (RGWFormPost::is_formpost_req(s)) { | |
2523 | return new RGWFormPost; | |
2524 | } else { | |
2525 | return new RGWPutMetadataObject_ObjStore_SWIFT; | |
2526 | } | |
2527 | } | |
2528 | ||
2529 | RGWOp *RGWHandler_REST_Obj_SWIFT::op_copy() | |
2530 | { | |
2531 | return new RGWCopyObj_ObjStore_SWIFT; | |
2532 | } | |
2533 | ||
2534 | RGWOp *RGWHandler_REST_Obj_SWIFT::op_options() | |
2535 | { | |
2536 | return new RGWOptionsCORS_ObjStore_SWIFT; | |
2537 | } | |
2538 | ||
2539 | ||
2540 | int RGWHandler_REST_SWIFT::authorize() | |
2541 | { | |
31f18b77 | 2542 | return rgw::auth::Strategy::apply(auth_strategy, s); |
7c673cae FG |
2543 | } |
2544 | ||
2545 | int RGWHandler_REST_SWIFT::postauth_init() | |
2546 | { | |
2547 | struct req_init_state* t = &s->init_state; | |
2548 | ||
2549 | /* XXX Stub this until Swift Auth sets account into URL. */ | |
2550 | s->bucket_tenant = s->user->user_id.tenant; | |
2551 | s->bucket_name = t->url_bucket; | |
2552 | ||
2553 | dout(10) << "s->object=" << | |
2554 | (!s->object.empty() ? s->object : rgw_obj_key("<NULL>")) | |
2555 | << " s->bucket=" | |
2556 | << rgw_make_bucket_entry_name(s->bucket_tenant, s->bucket_name) | |
2557 | << dendl; | |
2558 | ||
2559 | int ret; | |
2560 | ret = validate_tenant_name(s->bucket_tenant); | |
2561 | if (ret) | |
2562 | return ret; | |
2563 | ret = validate_bucket_name(s->bucket_name); | |
2564 | if (ret) | |
2565 | return ret; | |
2566 | ret = validate_object_name(s->object.name); | |
2567 | if (ret) | |
2568 | return ret; | |
2569 | ||
2570 | if (!t->src_bucket.empty()) { | |
2571 | /* | |
2572 | * We don't allow cross-tenant copy at present. It requires account | |
2573 | * names in the URL for Swift. | |
2574 | */ | |
2575 | s->src_tenant_name = s->user->user_id.tenant; | |
2576 | s->src_bucket_name = t->src_bucket; | |
2577 | ||
2578 | ret = validate_bucket_name(s->src_bucket_name); | |
2579 | if (ret < 0) { | |
2580 | return ret; | |
2581 | } | |
2582 | ret = validate_object_name(s->src_object.name); | |
2583 | if (ret < 0) { | |
2584 | return ret; | |
2585 | } | |
2586 | } | |
2587 | ||
2588 | return 0; | |
2589 | } | |
2590 | ||
2591 | int RGWHandler_REST_SWIFT::validate_bucket_name(const string& bucket) | |
2592 | { | |
2593 | int ret = RGWHandler_REST::validate_bucket_name(bucket); | |
2594 | if (ret < 0) | |
2595 | return ret; | |
2596 | ||
2597 | int len = bucket.size(); | |
2598 | ||
2599 | if (len == 0) | |
2600 | return 0; | |
2601 | ||
2602 | if (bucket[0] == '.') | |
2603 | return -ERR_INVALID_BUCKET_NAME; | |
2604 | ||
2605 | if (check_utf8(bucket.c_str(), len)) | |
2606 | return -ERR_INVALID_UTF8; | |
2607 | ||
2608 | const char *s = bucket.c_str(); | |
2609 | ||
2610 | for (int i = 0; i < len; ++i, ++s) { | |
2611 | if (*(unsigned char *)s == 0xff) | |
2612 | return -ERR_INVALID_BUCKET_NAME; | |
2613 | } | |
2614 | ||
2615 | return 0; | |
2616 | } | |
2617 | ||
2618 | static void next_tok(string& str, string& tok, char delim) | |
2619 | { | |
2620 | if (str.size() == 0) { | |
2621 | tok = ""; | |
2622 | return; | |
2623 | } | |
2624 | tok = str; | |
2625 | int pos = str.find(delim); | |
2626 | if (pos > 0) { | |
2627 | tok = str.substr(0, pos); | |
2628 | str = str.substr(pos + 1); | |
2629 | } else { | |
2630 | str = ""; | |
2631 | } | |
2632 | } | |
2633 | ||
2634 | int RGWHandler_REST_SWIFT::init_from_header(struct req_state* const s, | |
2635 | const std::string& frontend_prefix) | |
2636 | { | |
2637 | string req; | |
2638 | string first; | |
2639 | ||
2640 | s->prot_flags |= RGW_REST_SWIFT; | |
2641 | ||
2642 | char reqbuf[frontend_prefix.length() + s->decoded_uri.length() + 1]; | |
2643 | sprintf(reqbuf, "%s%s", frontend_prefix.c_str(), s->decoded_uri.c_str()); | |
2644 | const char *req_name = reqbuf; | |
2645 | ||
2646 | const char *p; | |
2647 | ||
2648 | if (*req_name == '?') { | |
2649 | p = req_name; | |
2650 | } else { | |
2651 | p = s->info.request_params.c_str(); | |
2652 | } | |
2653 | ||
2654 | s->info.args.set(p); | |
2655 | s->info.args.parse(); | |
2656 | ||
2657 | /* Skip the leading slash of URL hierarchy. */ | |
2658 | if (req_name[0] != '/') { | |
2659 | return 0; | |
2660 | } else { | |
2661 | req_name++; | |
2662 | } | |
2663 | ||
2664 | if ('\0' == req_name[0]) { | |
2665 | return g_conf->rgw_swift_url_prefix == "/" ? -ERR_BAD_URL : 0; | |
2666 | } | |
2667 | ||
2668 | req = req_name; | |
2669 | ||
2670 | size_t pos = req.find('/'); | |
2671 | if (std::string::npos != pos && g_conf->rgw_swift_url_prefix != "/") { | |
2672 | bool cut_url = g_conf->rgw_swift_url_prefix.length(); | |
2673 | first = req.substr(0, pos); | |
2674 | ||
2675 | if (first.compare(g_conf->rgw_swift_url_prefix) == 0) { | |
2676 | if (cut_url) { | |
2677 | /* Rewind to the "v1/..." part. */ | |
2678 | next_tok(req, first, '/'); | |
2679 | } | |
2680 | } | |
2681 | } else if (req.compare(g_conf->rgw_swift_url_prefix) == 0) { | |
2682 | s->formatter = new RGWFormatter_Plain; | |
2683 | return -ERR_BAD_URL; | |
2684 | } else { | |
2685 | first = req; | |
2686 | } | |
2687 | ||
2688 | std::string tenant_path; | |
2689 | if (! g_conf->rgw_swift_tenant_name.empty()) { | |
2690 | tenant_path = "/AUTH_"; | |
2691 | tenant_path.append(g_conf->rgw_swift_tenant_name); | |
2692 | } | |
2693 | ||
2694 | /* verify that the request_uri conforms with what's expected */ | |
2695 | char buf[g_conf->rgw_swift_url_prefix.length() + 16 + tenant_path.length()]; | |
2696 | int blen; | |
2697 | if (g_conf->rgw_swift_url_prefix == "/") { | |
2698 | blen = sprintf(buf, "/v1%s", tenant_path.c_str()); | |
2699 | } else { | |
2700 | blen = sprintf(buf, "/%s/v1%s", | |
2701 | g_conf->rgw_swift_url_prefix.c_str(), tenant_path.c_str()); | |
2702 | } | |
2703 | ||
2704 | if (strncmp(reqbuf, buf, blen) != 0) { | |
2705 | return -ENOENT; | |
2706 | } | |
2707 | ||
2708 | int ret = allocate_formatter(s, RGW_FORMAT_PLAIN, true); | |
2709 | if (ret < 0) | |
2710 | return ret; | |
2711 | ||
2712 | string ver; | |
2713 | ||
2714 | next_tok(req, ver, '/'); | |
2715 | ||
2716 | if (!tenant_path.empty() || g_conf->rgw_swift_account_in_url) { | |
2717 | string account_name; | |
2718 | next_tok(req, account_name, '/'); | |
2719 | ||
2720 | /* Erase all pre-defined prefixes like "AUTH_" or "KEY_". */ | |
2721 | const vector<string> skipped_prefixes = { "AUTH_", "KEY_" }; | |
2722 | ||
2723 | for (const auto pfx : skipped_prefixes) { | |
2724 | const size_t comp_len = min(account_name.length(), pfx.length()); | |
2725 | if (account_name.compare(0, comp_len, pfx) == 0) { | |
2726 | /* Prefix is present. Drop it. */ | |
2727 | account_name = account_name.substr(comp_len); | |
2728 | break; | |
2729 | } | |
2730 | } | |
2731 | ||
2732 | if (account_name.empty()) { | |
2733 | return -ERR_PRECONDITION_FAILED; | |
2734 | } else { | |
2735 | s->account_name = account_name; | |
2736 | } | |
2737 | } | |
2738 | ||
2739 | next_tok(req, first, '/'); | |
2740 | ||
2741 | dout(10) << "ver=" << ver << " first=" << first << " req=" << req << dendl; | |
2742 | if (first.size() == 0) | |
2743 | return 0; | |
2744 | ||
2745 | s->info.effective_uri = "/" + first; | |
2746 | ||
2747 | // Save bucket to tide us over until token is parsed. | |
2748 | s->init_state.url_bucket = first; | |
2749 | ||
2750 | if (req.size()) { | |
2751 | s->object = | |
2752 | rgw_obj_key(req, s->info.env->get("HTTP_X_OBJECT_VERSION_ID", "")); /* rgw swift extension */ | |
2753 | s->info.effective_uri.append("/" + s->object.name); | |
2754 | } | |
2755 | ||
2756 | return 0; | |
2757 | } | |
2758 | ||
2759 | int RGWHandler_REST_SWIFT::init(RGWRados* store, struct req_state* s, | |
2760 | rgw::io::BasicClient *cio) | |
2761 | { | |
2762 | struct req_init_state *t = &s->init_state; | |
2763 | ||
2764 | s->dialect = "swift"; | |
2765 | ||
2766 | const char *copy_source = s->info.env->get("HTTP_X_COPY_FROM"); | |
2767 | if (copy_source) { | |
2768 | bool result = RGWCopyObj::parse_copy_location(copy_source, t->src_bucket, | |
2769 | s->src_object); | |
2770 | if (!result) | |
2771 | return -ERR_BAD_URL; | |
2772 | } | |
2773 | ||
2774 | if (s->op == OP_COPY) { | |
2775 | const char *req_dest = s->info.env->get("HTTP_DESTINATION"); | |
2776 | if (!req_dest) | |
2777 | return -ERR_BAD_URL; | |
2778 | ||
2779 | string dest_bucket_name; | |
2780 | rgw_obj_key dest_obj_key; | |
2781 | bool result = | |
2782 | RGWCopyObj::parse_copy_location(req_dest, dest_bucket_name, | |
2783 | dest_obj_key); | |
2784 | if (!result) | |
2785 | return -ERR_BAD_URL; | |
2786 | ||
2787 | string dest_object = dest_obj_key.name; | |
2788 | ||
2789 | /* convert COPY operation into PUT */ | |
2790 | t->src_bucket = t->url_bucket; | |
2791 | s->src_object = s->object; | |
2792 | t->url_bucket = dest_bucket_name; | |
2793 | s->object = rgw_obj_key(dest_object); | |
2794 | s->op = OP_PUT; | |
2795 | } | |
2796 | ||
2797 | return RGWHandler_REST::init(store, s, cio); | |
2798 | } | |
2799 | ||
2800 | RGWHandler_REST* | |
2801 | RGWRESTMgr_SWIFT::get_handler(struct req_state* const s, | |
2802 | const rgw::auth::StrategyRegistry& auth_registry, | |
2803 | const std::string& frontend_prefix) | |
2804 | { | |
2805 | int ret = RGWHandler_REST_SWIFT::init_from_header(s, frontend_prefix); | |
2806 | if (ret < 0) { | |
2807 | ldout(s->cct, 10) << "init_from_header returned err=" << ret << dendl; | |
2808 | return nullptr; | |
2809 | } | |
2810 | ||
2811 | const auto& auth_strategy = auth_registry.get_swift(); | |
2812 | ||
2813 | if (s->init_state.url_bucket.empty()) { | |
2814 | return new RGWHandler_REST_Service_SWIFT(auth_strategy); | |
2815 | } | |
2816 | ||
2817 | if (s->object.empty()) { | |
2818 | return new RGWHandler_REST_Bucket_SWIFT(auth_strategy); | |
2819 | } | |
2820 | ||
2821 | return new RGWHandler_REST_Obj_SWIFT(auth_strategy); | |
2822 | } | |
2823 | ||
2824 | RGWHandler_REST* RGWRESTMgr_SWIFT_Info::get_handler( | |
2825 | struct req_state* const s, | |
2826 | const rgw::auth::StrategyRegistry& auth_registry, | |
2827 | const std::string& frontend_prefix) | |
2828 | { | |
2829 | s->prot_flags |= RGW_REST_SWIFT; | |
2830 | const auto& auth_strategy = auth_registry.get_swift(); | |
2831 | return new RGWHandler_REST_SWIFT_Info(auth_strategy); | |
2832 | } |