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