1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2009 Sage Weil <sage@newdream.net>
7 * Copyright (C) 2015 Yehuda Sadeh <yehuda@redhat.com>
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
16 #ifndef CEPH_RGW_COMMON_H
17 #define CEPH_RGW_COMMON_H
21 #include <boost/utility/string_view.hpp>
23 #include "common/ceph_crypto.h"
24 #include "common/perf_counters.h"
28 #include "rgw_iam_policy.h"
29 #include "rgw_quota.h"
30 #include "rgw_string.h"
31 #include "rgw_website.h"
32 #include "cls/version/cls_version_types.h"
33 #include "cls/user/cls_user_types.h"
34 #include "cls/rgw/cls_rgw_types.h"
35 #include "include/rados/librados.hpp"
41 using ceph::crypto::MD5
;
44 #define RGW_ATTR_PREFIX "user.rgw."
46 #define RGW_HTTP_RGWX_ATTR_PREFIX "RGWX_ATTR_"
47 #define RGW_HTTP_RGWX_ATTR_PREFIX_OUT "Rgwx-Attr-"
49 #define RGW_AMZ_PREFIX "x-amz-"
50 #define RGW_AMZ_META_PREFIX RGW_AMZ_PREFIX "meta-"
51 #define RGW_AMZ_WEBSITE_REDIRECT_LOCATION RGW_AMZ_PREFIX "website-redirect-location"
53 #define RGW_SYS_PARAM_PREFIX "rgwx-"
55 #define RGW_ATTR_ACL RGW_ATTR_PREFIX "acl"
56 #define RGW_ATTR_LC RGW_ATTR_PREFIX "lc"
57 #define RGW_ATTR_CORS RGW_ATTR_PREFIX "cors"
58 #define RGW_ATTR_ETAG RGW_ATTR_PREFIX "etag"
59 #define RGW_ATTR_BUCKETS RGW_ATTR_PREFIX "buckets"
60 #define RGW_ATTR_META_PREFIX RGW_ATTR_PREFIX RGW_AMZ_META_PREFIX
61 #define RGW_ATTR_CONTENT_TYPE RGW_ATTR_PREFIX "content_type"
62 #define RGW_ATTR_CACHE_CONTROL RGW_ATTR_PREFIX "cache_control"
63 #define RGW_ATTR_CONTENT_DISP RGW_ATTR_PREFIX "content_disposition"
64 #define RGW_ATTR_CONTENT_ENC RGW_ATTR_PREFIX "content_encoding"
65 #define RGW_ATTR_CONTENT_LANG RGW_ATTR_PREFIX "content_language"
66 #define RGW_ATTR_EXPIRES RGW_ATTR_PREFIX "expires"
67 #define RGW_ATTR_DELETE_AT RGW_ATTR_PREFIX "delete_at"
68 #define RGW_ATTR_ID_TAG RGW_ATTR_PREFIX "idtag"
69 #define RGW_ATTR_SHADOW_OBJ RGW_ATTR_PREFIX "shadow_name"
70 #define RGW_ATTR_MANIFEST RGW_ATTR_PREFIX "manifest"
71 #define RGW_ATTR_USER_MANIFEST RGW_ATTR_PREFIX "user_manifest"
72 #define RGW_ATTR_AMZ_WEBSITE_REDIRECT_LOCATION RGW_ATTR_PREFIX RGW_AMZ_WEBSITE_REDIRECT_LOCATION
73 #define RGW_ATTR_SLO_MANIFEST RGW_ATTR_PREFIX "slo_manifest"
74 /* Information whether an object is SLO or not must be exposed to
75 * user through custom HTTP header named X-Static-Large-Object. */
76 #define RGW_ATTR_SLO_UINDICATOR RGW_ATTR_META_PREFIX "static-large-object"
77 #define RGW_ATTR_X_ROBOTS_TAG RGW_ATTR_PREFIX "x-robots-tag"
79 #define RGW_ATTR_PG_VER RGW_ATTR_PREFIX "pg_ver"
80 #define RGW_ATTR_SOURCE_ZONE RGW_ATTR_PREFIX "source_zone"
82 #define RGW_ATTR_TEMPURL_KEY1 RGW_ATTR_META_PREFIX "temp-url-key"
83 #define RGW_ATTR_TEMPURL_KEY2 RGW_ATTR_META_PREFIX "temp-url-key-2"
85 /* Account/container quota of the Swift API. */
86 #define RGW_ATTR_QUOTA_NOBJS RGW_ATTR_META_PREFIX "quota-count"
87 #define RGW_ATTR_QUOTA_MSIZE RGW_ATTR_META_PREFIX "quota-bytes"
89 /* Static Web Site of Swift API. */
90 #define RGW_ATTR_WEB_INDEX RGW_ATTR_META_PREFIX "web-index"
91 #define RGW_ATTR_WEB_ERROR RGW_ATTR_META_PREFIX "web-error"
92 #define RGW_ATTR_WEB_LISTINGS RGW_ATTR_META_PREFIX "web-listings"
93 #define RGW_ATTR_WEB_LIST_CSS RGW_ATTR_META_PREFIX "web-listings-css"
94 #define RGW_ATTR_SUBDIR_MARKER RGW_ATTR_META_PREFIX "web-directory-type"
96 #define RGW_ATTR_OLH_PREFIX RGW_ATTR_PREFIX "olh."
98 #define RGW_ATTR_OLH_INFO RGW_ATTR_OLH_PREFIX "info"
99 #define RGW_ATTR_OLH_VER RGW_ATTR_OLH_PREFIX "ver"
100 #define RGW_ATTR_OLH_ID_TAG RGW_ATTR_OLH_PREFIX "idtag"
101 #define RGW_ATTR_OLH_PENDING_PREFIX RGW_ATTR_OLH_PREFIX "pending."
103 #define RGW_ATTR_COMPRESSION RGW_ATTR_PREFIX "compression"
106 #define RGW_ATTR_IAM_POLICY RGW_ATTR_PREFIX "iam-policy"
109 /* RGW File Attributes */
110 #define RGW_ATTR_UNIX_KEY1 RGW_ATTR_PREFIX "unix-key1"
111 #define RGW_ATTR_UNIX1 RGW_ATTR_PREFIX "unix1"
113 #define RGW_ATTR_CRYPT_PREFIX RGW_ATTR_PREFIX "crypt."
114 #define RGW_ATTR_CRYPT_MODE RGW_ATTR_CRYPT_PREFIX "mode"
115 #define RGW_ATTR_CRYPT_KEYMD5 RGW_ATTR_CRYPT_PREFIX "keymd5"
116 #define RGW_ATTR_CRYPT_KEYID RGW_ATTR_CRYPT_PREFIX "keyid"
117 #define RGW_ATTR_CRYPT_KEYSEL RGW_ATTR_CRYPT_PREFIX "keysel"
119 #define RGW_BUCKETS_OBJ_SUFFIX ".buckets"
121 #define RGW_FORMAT_PLAIN 0
122 #define RGW_FORMAT_XML 1
123 #define RGW_FORMAT_JSON 2
124 #define RGW_FORMAT_HTML 3
126 #define RGW_CAP_READ 0x1
127 #define RGW_CAP_WRITE 0x2
128 #define RGW_CAP_ALL (RGW_CAP_READ | RGW_CAP_WRITE)
130 #define RGW_REST_SWIFT 0x1
131 #define RGW_REST_SWIFT_AUTH 0x2
132 #define RGW_REST_S3 0x4
133 #define RGW_REST_WEBSITE 0x8
135 #define RGW_SUSPENDED_USER_AUID (uint64_t)-2
137 #define RGW_OP_TYPE_READ 0x01
138 #define RGW_OP_TYPE_WRITE 0x02
139 #define RGW_OP_TYPE_DELETE 0x04
141 #define RGW_OP_TYPE_MODIFY (RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE)
142 #define RGW_OP_TYPE_ALL (RGW_OP_TYPE_READ | RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE)
144 #define RGW_DEFAULT_MAX_BUCKETS 1000
146 #define RGW_DEFER_TO_BUCKET_ACLS_RECURSE 1
147 #define RGW_DEFER_TO_BUCKET_ACLS_FULL_CONTROL 2
149 #define STATUS_CREATED 1900
150 #define STATUS_ACCEPTED 1901
151 #define STATUS_NO_CONTENT 1902
152 #define STATUS_PARTIAL_CONTENT 1903
153 #define STATUS_REDIRECT 1904
154 #define STATUS_NO_APPLY 1905
155 #define STATUS_APPLIED 1906
157 #define ERR_INVALID_BUCKET_NAME 2000
158 #define ERR_INVALID_OBJECT_NAME 2001
159 #define ERR_NO_SUCH_BUCKET 2002
160 #define ERR_METHOD_NOT_ALLOWED 2003
161 #define ERR_INVALID_DIGEST 2004
162 #define ERR_BAD_DIGEST 2005
163 #define ERR_UNRESOLVABLE_EMAIL 2006
164 #define ERR_INVALID_PART 2007
165 #define ERR_INVALID_PART_ORDER 2008
166 #define ERR_NO_SUCH_UPLOAD 2009
167 #define ERR_REQUEST_TIMEOUT 2010
168 #define ERR_LENGTH_REQUIRED 2011
169 #define ERR_REQUEST_TIME_SKEWED 2012
170 #define ERR_BUCKET_EXISTS 2013
171 #define ERR_BAD_URL 2014
172 #define ERR_PRECONDITION_FAILED 2015
173 #define ERR_NOT_MODIFIED 2016
174 #define ERR_INVALID_UTF8 2017
175 #define ERR_UNPROCESSABLE_ENTITY 2018
176 #define ERR_TOO_LARGE 2019
177 #define ERR_TOO_MANY_BUCKETS 2020
178 #define ERR_INVALID_REQUEST 2021
179 #define ERR_TOO_SMALL 2022
180 #define ERR_NOT_FOUND 2023
181 #define ERR_PERMANENT_REDIRECT 2024
182 #define ERR_LOCKED 2025
183 #define ERR_QUOTA_EXCEEDED 2026
184 #define ERR_SIGNATURE_NO_MATCH 2027
185 #define ERR_INVALID_ACCESS_KEY 2028
186 #define ERR_MALFORMED_XML 2029
187 #define ERR_USER_EXIST 2030
188 #define ERR_NOT_SLO_MANIFEST 2031
189 #define ERR_EMAIL_EXIST 2032
190 #define ERR_KEY_EXIST 2033
191 #define ERR_INVALID_SECRET_KEY 2034
192 #define ERR_INVALID_KEY_TYPE 2035
193 #define ERR_INVALID_CAP 2036
194 #define ERR_INVALID_TENANT_NAME 2037
195 #define ERR_WEBSITE_REDIRECT 2038
196 #define ERR_NO_SUCH_WEBSITE_CONFIGURATION 2039
197 #define ERR_AMZ_CONTENT_SHA256_MISMATCH 2040
198 #define ERR_NO_SUCH_LC 2041
199 #define ERR_USER_SUSPENDED 2100
200 #define ERR_INTERNAL_ERROR 2200
201 #define ERR_NOT_IMPLEMENTED 2201
202 #define ERR_SERVICE_UNAVAILABLE 2202
203 #define ERR_ROLE_EXISTS 2203
204 #define ERR_MALFORMED_DOC 2204
205 #define ERR_NO_ROLE_FOUND 2205
206 #define ERR_DELETE_CONFLICT 2206
207 #define ERR_NO_SUCH_BUCKET_POLICY 2207
208 #define ERR_INVALID_LOCATION_CONSTRAINT 2208
210 #define ERR_BUSY_RESHARDING 2300
213 #define UINT32_MAX (0xffffffffu)
218 typedef void *RGWAccessHandle
;
223 extern PerfCounters
*perfcounter
;
225 extern int rgw_perf_start(CephContext
*cct
);
226 extern void rgw_perf_stop(CephContext
*cct
);
247 l_rgw_keystone_token_cache_hit
,
248 l_rgw_keystone_token_cache_miss
,
254 /* size should be the required string size + 1 */
255 extern int gen_rand_base64(CephContext
*cct
, char *dest
, int size
);
256 extern int gen_rand_alphanumeric(CephContext
*cct
, char *dest
, int size
);
257 extern int gen_rand_alphanumeric_lower(CephContext
*cct
, char *dest
, int size
);
258 extern int gen_rand_alphanumeric_upper(CephContext
*cct
, char *dest
, int size
);
259 extern int gen_rand_alphanumeric_no_underscore(CephContext
*cct
, char *dest
, int size
);
260 extern int gen_rand_alphanumeric_plain(CephContext
*cct
, char *dest
, int size
);
262 extern int gen_rand_alphanumeric_lower(CephContext
*cct
, string
*str
, int length
);
264 enum RGWIntentEvent
{
269 enum RGWObjCategory
{
270 RGW_OBJ_CATEGORY_NONE
= 0,
271 RGW_OBJ_CATEGORY_MAIN
= 1,
272 RGW_OBJ_CATEGORY_SHADOW
= 2,
273 RGW_OBJ_CATEGORY_MULTIMETA
= 3,
276 /** Store error returns for output at a different point in the program */
280 bool is_clear() const;
282 friend std::ostream
& operator<<(std::ostream
& oss
, const rgw_err
&err
);
286 std::string err_code
;
292 /* Helper class used for RGWHTTPArgs parsing */
299 explicit NameVal(string nv
) : str(nv
) {}
303 string
& get_name() { return name
; }
304 string
& get_val() { return val
; }
307 /** Stores the XML arguments associated with the HTTP request in req_state*/
310 string str
, empty_str
;
311 map
<string
, string
> val_map
;
312 map
<string
, string
> sys_val_map
;
313 map
<string
, string
> sub_resources
;
314 bool has_resp_modifier
;
315 bool admin_subresource_added
;
317 RGWHTTPArgs() : has_resp_modifier(false), admin_subresource_added(false) {}
319 /** Set the arguments; as received */
321 has_resp_modifier
= false;
323 sub_resources
.clear();
326 /** parse the received arguments */
328 void append(const string
& name
, const string
& val
);
329 /** Get the value for a specific argument parameter */
330 const string
& get(const string
& name
, bool *exists
= NULL
) const;
331 int get_bool(const string
& name
, bool *val
, bool *exists
);
332 int get_bool(const char *name
, bool *val
, bool *exists
);
333 void get_bool(const char *name
, bool *val
, bool def_val
);
335 /** Get the value for specific system argument parameter */
336 std::string
sys_get(const string
& name
, bool *exists
= nullptr) const;
338 /** see if a parameter is contained in this RGWHTTPArgs */
339 bool exists(const char *name
) const {
340 return (val_map
.find(name
) != std::end(val_map
));
342 bool sub_resource_exists(const char *name
) const {
343 return (sub_resources
.find(name
) != std::end(sub_resources
));
345 map
<string
, string
>& get_params() {
348 const std::map
<std::string
, std::string
>& get_sub_resources() const {
349 return sub_resources
;
351 unsigned get_num_params() const {
352 return val_map
.size();
354 bool has_response_modifier() const {
355 return has_resp_modifier
;
357 void set_system() { /* make all system params visible */
358 map
<string
, string
>::iterator iter
;
359 for (iter
= sys_val_map
.begin(); iter
!= sys_val_map
.end(); ++iter
) {
360 val_map
[iter
->first
] = iter
->second
;
363 const string
& get_str() {
368 const char *rgw_conf_get(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, const char *def_val
);
369 int rgw_conf_get_int(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, int def_val
);
370 bool rgw_conf_get_bool(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, bool def_val
);
377 void init(CephContext
*cct
, RGWEnv
* env
);
382 defer_to_bucket_acls(0) {
386 int enable_usage_log
;
387 uint8_t defer_to_bucket_acls
;
391 std::map
<string
, string
, ltstr_nocase
> env_map
;
395 void init(CephContext
*cct
);
396 void init(CephContext
*cct
, char **envp
);
397 void set(const boost::string_ref
& name
, const boost::string_ref
& val
);
398 const char *get(const char *name
, const char *def_val
= nullptr) const;
399 int get_int(const char *name
, int def_val
= 0) const;
400 bool get_bool(const char *name
, bool def_val
= 0);
401 size_t get_size(const char *name
, size_t def_val
= 0) const;
402 bool exists(const char *name
) const;
403 bool exists_prefix(const char *prefix
) const;
405 void remove(const char *name
);
407 const std::map
<string
, string
, ltstr_nocase
>& get_map() const { return env_map
; }
427 RGW_OP_GET_BUCKET_LOGGING
,
428 RGW_OP_GET_BUCKET_VERSIONING
,
429 RGW_OP_SET_BUCKET_VERSIONING
,
430 RGW_OP_GET_BUCKET_WEBSITE
,
431 RGW_OP_SET_BUCKET_WEBSITE
,
433 RGW_OP_CREATE_BUCKET
,
434 RGW_OP_DELETE_BUCKET
,
438 RGW_OP_PUT_METADATA_ACCOUNT
,
439 RGW_OP_PUT_METADATA_BUCKET
,
440 RGW_OP_PUT_METADATA_OBJECT
,
450 RGW_OP_GET_REQUEST_PAYMENT
,
451 RGW_OP_SET_REQUEST_PAYMENT
,
452 RGW_OP_INIT_MULTIPART
,
453 RGW_OP_COMPLETE_MULTIPART
,
454 RGW_OP_ABORT_MULTIPART
,
455 RGW_OP_LIST_MULTIPART
,
456 RGW_OP_LIST_BUCKET_MULTIPARTS
,
457 RGW_OP_DELETE_MULTI_OBJ
,
460 RGW_OP_GET_CROSS_DOMAIN_POLICY
,
461 RGW_OP_GET_HEALTH_CHECK
,
468 RGW_OP_PUT_ROLE_POLICY
,
469 RGW_OP_GET_ROLE_POLICY
,
470 RGW_OP_LIST_ROLE_POLICIES
,
471 RGW_OP_DELETE_ROLE_POLICY
,
472 RGW_OP_PUT_BUCKET_POLICY
,
473 RGW_OP_GET_BUCKET_POLICY
,
474 RGW_OP_DELETE_BUCKET_POLICY
,
477 RGW_OP_ADMIN_SET_METADATA
,
478 RGW_OP_GET_OBJ_LAYOUT
,
480 RGW_OP_METADATA_SEARCH
,
481 RGW_OP_CONFIG_BUCKET_META_SEARCH
,
482 RGW_OP_GET_BUCKET_META_SEARCH
,
483 RGW_OP_DEL_BUCKET_META_SEARCH
,
486 class RGWAccessControlPolicy
;
489 struct RGWAccessKey
{
490 string id
; // AccessKey
491 string key
; // SecretKey
495 RGWAccessKey(std::string _id
, std::string _key
)
496 : id(std::move(_id
)), key(std::move(_key
)) {}
498 void encode(bufferlist
& bl
) const {
499 ENCODE_START(2, 2, bl
);
502 ::encode(subuser
, bl
);
506 void decode(bufferlist::iterator
& bl
) {
507 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
510 ::decode(subuser
, bl
);
513 void dump(Formatter
*f
) const;
514 void dump_plain(Formatter
*f
) const;
515 void dump(Formatter
*f
, const string
& user
, bool swift
) const;
516 static void generate_test_instances(list
<RGWAccessKey
*>& o
);
518 void decode_json(JSONObj
*obj
);
519 void decode_json(JSONObj
*obj
, bool swift
);
521 WRITE_CLASS_ENCODER(RGWAccessKey
)
527 RGWSubUser() : perm_mask(0) {}
528 void encode(bufferlist
& bl
) const {
529 ENCODE_START(2, 2, bl
);
531 ::encode(perm_mask
, bl
);
535 void decode(bufferlist::iterator
& bl
) {
536 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
538 ::decode(perm_mask
, bl
);
541 void dump(Formatter
*f
) const;
542 void dump(Formatter
*f
, const string
& user
) const;
543 static void generate_test_instances(list
<RGWSubUser
*>& o
);
545 void decode_json(JSONObj
*obj
);
547 WRITE_CLASS_ENCODER(RGWSubUser
)
551 map
<string
, uint32_t> caps
;
553 int get_cap(const string
& cap
, string
& type
, uint32_t *perm
);
554 int add_cap(const string
& cap
);
555 int remove_cap(const string
& cap
);
557 static int parse_cap_perm(const string
& str
, uint32_t *perm
);
558 int add_from_string(const string
& str
);
559 int remove_from_string(const string
& str
);
561 void encode(bufferlist
& bl
) const {
562 ENCODE_START(1, 1, bl
);
566 void decode(bufferlist::iterator
& bl
) {
571 int check_cap(const string
& cap
, uint32_t perm
);
572 bool is_valid_cap_type(const string
& tp
);
573 void dump(Formatter
*f
) const;
574 void dump(Formatter
*f
, const char *name
) const;
576 void decode_json(JSONObj
*obj
);
578 WRITE_CLASS_ENCODER(RGWUserCaps
)
580 void encode_json(const char *name
, const obj_version
& v
, Formatter
*f
);
581 void encode_json(const char *name
, const RGWUserCaps
& val
, Formatter
*f
);
583 void decode_json_obj(obj_version
& v
, JSONObj
*obj
);
585 enum RGWUserSourceType
599 map
<string
, RGWAccessKey
> access_keys
;
600 map
<string
, RGWAccessKey
> swift_keys
;
601 map
<string
, RGWSubUser
> subusers
;
608 string default_placement
;
609 list
<string
> placement_tags
;
610 RGWQuotaInfo bucket_quota
;
611 map
<int, string
> temp_url_keys
;
612 RGWQuotaInfo user_quota
;
618 max_buckets(RGW_DEFAULT_MAX_BUCKETS
),
619 op_mask(RGW_OP_TYPE_ALL
),
625 RGWAccessKey
* get_key0() {
626 if (access_keys
.empty())
629 return &(access_keys
.begin()->second
);
632 void encode(bufferlist
& bl
) const {
633 ENCODE_START(19, 9, bl
);
637 if (!access_keys
.empty()) {
638 map
<string
, RGWAccessKey
>::const_iterator iter
= access_keys
.begin();
639 const RGWAccessKey
& k
= iter
->second
;
643 ::encode(access_key
, bl
);
644 ::encode(secret_key
, bl
);
645 ::encode(display_name
, bl
);
646 ::encode(user_email
, bl
);
649 if (!swift_keys
.empty()) {
650 map
<string
, RGWAccessKey
>::const_iterator iter
= swift_keys
.begin();
651 const RGWAccessKey
& k
= iter
->second
;
655 ::encode(swift_name
, bl
);
656 ::encode(swift_key
, bl
);
657 ::encode(user_id
.id
, bl
);
658 ::encode(access_keys
, bl
);
659 ::encode(subusers
, bl
);
660 ::encode(suspended
, bl
);
661 ::encode(swift_keys
, bl
);
662 ::encode(max_buckets
, bl
);
664 ::encode(op_mask
, bl
);
665 ::encode(system
, bl
);
666 ::encode(default_placement
, bl
);
667 ::encode(placement_tags
, bl
);
668 ::encode(bucket_quota
, bl
);
669 ::encode(temp_url_keys
, bl
);
670 ::encode(user_quota
, bl
);
671 ::encode(user_id
.tenant
, bl
);
676 void decode(bufferlist::iterator
& bl
) {
677 DECODE_START_LEGACY_COMPAT_LEN_32(19, 9, 9, bl
);
678 if (struct_v
>= 2) ::decode(auid
, bl
);
679 else auid
= CEPH_AUTH_UID_DEFAULT
;
682 ::decode(access_key
, bl
);
683 ::decode(secret_key
, bl
);
688 access_keys
[access_key
] = k
;
690 ::decode(display_name
, bl
);
691 ::decode(user_email
, bl
);
692 /* We populate swift_keys map later nowadays, but we have to decode. */
695 if (struct_v
>= 3) ::decode(swift_name
, bl
);
696 if (struct_v
>= 4) ::decode(swift_key
, bl
);
698 ::decode(user_id
.id
, bl
);
700 user_id
.id
= access_key
;
702 ::decode(access_keys
, bl
);
703 ::decode(subusers
, bl
);
707 ::decode(suspended
, bl
);
710 ::decode(swift_keys
, bl
);
712 if (struct_v
>= 10) {
713 ::decode(max_buckets
, bl
);
715 max_buckets
= RGW_DEFAULT_MAX_BUCKETS
;
717 if (struct_v
>= 11) {
720 if (struct_v
>= 12) {
721 ::decode(op_mask
, bl
);
723 op_mask
= RGW_OP_TYPE_ALL
;
725 if (struct_v
>= 13) {
726 ::decode(system
, bl
);
727 ::decode(default_placement
, bl
);
728 ::decode(placement_tags
, bl
); /* tags of allowed placement rules */
730 if (struct_v
>= 14) {
731 ::decode(bucket_quota
, bl
);
733 if (struct_v
>= 15) {
734 ::decode(temp_url_keys
, bl
);
736 if (struct_v
>= 16) {
737 ::decode(user_quota
, bl
);
739 if (struct_v
>= 17) {
740 ::decode(user_id
.tenant
, bl
);
742 user_id
.tenant
.clear();
744 if (struct_v
>= 18) {
747 if (struct_v
>= 19) {
752 void dump(Formatter
*f
) const;
753 static void generate_test_instances(list
<RGWUserInfo
*>& o
);
755 void decode_json(JSONObj
*obj
);
757 WRITE_CLASS_ENCODER(RGWUserInfo
)
764 rgw_pool(const rgw_pool
& _p
) : name(_p
.name
), ns(_p
.ns
) {}
765 rgw_pool(const string
& _s
) {
768 rgw_pool(const string
& _name
, const string
& _ns
) : name(_name
), ns(_ns
) {}
770 string
to_str() const;
771 void from_str(const string
& s
);
773 void init(const string
& _s
) {
781 int compare(const rgw_pool
& p
) const {
782 int r
= name
.compare(p
.name
);
786 return ns
.compare(p
.ns
);
789 void encode(bufferlist
& bl
) const {
790 ENCODE_START(10, 10, bl
);
796 void decode_from_bucket(bufferlist::iterator
& bl
);
798 void decode(bufferlist::iterator
& bl
) {
799 DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl
);
806 * note that rgw_pool can be used where rgw_bucket was used before
807 * therefore we inherit rgw_bucket's old versions. However, we only
808 * need the first field from rgw_bucket. unless we add more fields
809 * in which case we'll need to look at struct_v, and check the actual
810 * version. Anything older than 10 needs to be treated as old rgw_bucket
820 bool operator==(const rgw_pool
& p
) const {
821 return (compare(p
) == 0);
823 bool operator!=(const rgw_pool
& p
) const {
824 return !(*this == p
);
826 bool operator<(const rgw_pool
& p
) const {
827 int r
= name
.compare(p
.name
);
829 return (ns
.compare(p
.ns
) < 0);
834 WRITE_CLASS_ENCODER(rgw_pool
)
836 struct rgw_data_placement_target
{
838 rgw_pool data_extra_pool
;
841 rgw_data_placement_target() {}
843 rgw_data_placement_target(const rgw_pool
& _data_pool
, const rgw_pool
& _data_extra_pool
, const rgw_pool
& _index_pool
)
844 : data_pool(_data_pool
), data_extra_pool(_data_extra_pool
), index_pool(_index_pool
) {}
846 const rgw_pool
& get_data_extra_pool() const {
847 if (data_extra_pool
.empty()) {
850 return data_extra_pool
;
853 int compare(const rgw_data_placement_target
& t
) {
854 int c
= data_pool
.compare(t
.data_pool
);
858 c
= data_extra_pool
.compare(t
.data_extra_pool
);
862 return index_pool
.compare(t
.index_pool
);
865 void dump(Formatter
*f
) const;
866 void decode_json(JSONObj
*obj
);
869 inline ostream
& operator<<(ostream
& out
, const rgw_pool
& p
) {
880 rgw_raw_obj(const rgw_pool
& _pool
, const std::string
& _oid
) {
883 rgw_raw_obj(const rgw_pool
& _pool
, const std::string
& _oid
, const string
& _loc
) : loc(_loc
) {
887 void init(const rgw_pool
& _pool
, const std::string
& _oid
) {
896 void encode(bufferlist
& bl
) const {
897 ENCODE_START(6, 6, bl
);
904 void decode_from_rgw_obj(bufferlist::iterator
& bl
);
906 void decode(bufferlist::iterator
& bl
) {
907 unsigned ofs
= bl
.get_off();
911 * this object was encoded as rgw_obj, prior to rgw_raw_obj been split out of it,
912 * let's decode it as rgw_obj and convert it
915 decode_from_rgw_obj(bl
);
924 bool operator<(const rgw_raw_obj
& o
) const {
925 int r
= pool
.compare(o
.pool
);
927 r
= oid
.compare(o
.oid
);
929 r
= loc
.compare(o
.loc
);
935 bool operator==(const rgw_raw_obj
& o
) const {
936 return (pool
== o
.pool
&& oid
== o
.oid
&& loc
== o
.loc
);
939 void dump(Formatter
*f
) const;
940 void decode_json(JSONObj
*obj
);
942 WRITE_CLASS_ENCODER(rgw_raw_obj
)
944 inline ostream
& operator<<(ostream
& out
, const rgw_raw_obj
& o
) {
945 out
<< o
.pool
<< ":" << o
.oid
;
953 std::string bucket_id
;
954 rgw_data_placement_target explicit_placement
;
957 * runtime in-memory only info. If not empty, points to the bucket instance object
961 // cppcheck-suppress noExplicitConstructor
962 explicit rgw_bucket(const rgw_user
& u
, const cls_user_bucket
& b
) :
966 bucket_id(b
.bucket_id
),
967 explicit_placement(b
.explicit_placement
.data_pool
,
968 b
.explicit_placement
.data_extra_pool
,
969 b
.explicit_placement
.index_pool
) {}
971 void convert(cls_user_bucket
*b
) const {
974 b
->bucket_id
= bucket_id
;
975 b
->explicit_placement
.data_pool
= explicit_placement
.data_pool
.to_str();
976 b
->explicit_placement
.data_extra_pool
= explicit_placement
.data_extra_pool
.to_str();
977 b
->explicit_placement
.index_pool
= explicit_placement
.index_pool
.to_str();
980 void encode(bufferlist
& bl
) const {
981 ENCODE_START(10, 10, bl
);
983 ::encode(marker
, bl
);
984 ::encode(bucket_id
, bl
);
985 ::encode(tenant
, bl
);
986 bool encode_explicit
= !explicit_placement
.data_pool
.empty();
987 ::encode(encode_explicit
, bl
);
988 if (encode_explicit
) {
989 ::encode(explicit_placement
.data_pool
, bl
);
990 ::encode(explicit_placement
.data_extra_pool
, bl
);
991 ::encode(explicit_placement
.index_pool
, bl
);
995 void decode(bufferlist::iterator
& bl
) {
996 DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl
);
999 ::decode(explicit_placement
.data_pool
.name
, bl
);
1001 if (struct_v
>= 2) {
1002 ::decode(marker
, bl
);
1003 if (struct_v
<= 3) {
1007 snprintf(buf
, sizeof(buf
), "%llu", (long long)id
);
1010 ::decode(bucket_id
, bl
);
1013 if (struct_v
< 10) {
1014 if (struct_v
>= 5) {
1015 ::decode(explicit_placement
.index_pool
.name
, bl
);
1017 explicit_placement
.index_pool
= explicit_placement
.data_pool
;
1019 if (struct_v
>= 7) {
1020 ::decode(explicit_placement
.data_extra_pool
.name
, bl
);
1023 if (struct_v
>= 8) {
1024 ::decode(tenant
, bl
);
1026 if (struct_v
>= 10) {
1027 bool decode_explicit
= !explicit_placement
.data_pool
.empty();
1028 ::decode(decode_explicit
, bl
);
1029 if (decode_explicit
) {
1030 ::decode(explicit_placement
.data_pool
, bl
);
1031 ::decode(explicit_placement
.data_extra_pool
, bl
);
1032 ::decode(explicit_placement
.index_pool
, bl
);
1038 void update_bucket_id(const string
& new_bucket_id
) {
1039 bucket_id
= new_bucket_id
;
1043 // format a key for the bucket/instance. pass delim=0 to skip a field
1044 std::string
get_key(char tenant_delim
= '/',
1045 char id_delim
= ':') const;
1047 const rgw_pool
& get_data_extra_pool() const {
1048 return explicit_placement
.get_data_extra_pool();
1051 void dump(Formatter
*f
) const;
1052 void decode_json(JSONObj
*obj
);
1053 static void generate_test_instances(list
<rgw_bucket
*>& o
);
1055 bool operator<(const rgw_bucket
& b
) const {
1056 return name
.compare(b
.name
) < 0;
1058 bool operator==(const rgw_bucket
& b
) const {
1059 return (name
== b
.name
) && (bucket_id
== b
.bucket_id
);
1062 WRITE_CLASS_ENCODER(rgw_bucket
)
1064 inline ostream
& operator<<(ostream
& out
, const rgw_bucket
&b
) {
1065 out
<< b
.name
<< "[" << b
.marker
<< "])";
1069 struct rgw_bucket_shard
{
1073 rgw_bucket_shard() : shard_id(-1) {}
1074 rgw_bucket_shard(const rgw_bucket
& _b
, int _sid
) : bucket(_b
), shard_id(_sid
) {}
1076 std::string
get_key(char tenant_delim
= '/', char id_delim
= ':',
1077 char shard_delim
= ':') const;
1079 bool operator<(const rgw_bucket_shard
& b
) const {
1080 if (bucket
< b
.bucket
) {
1083 if (b
.bucket
< bucket
) {
1086 return shard_id
< b
.shard_id
;
1091 struct RGWObjVersionTracker
{
1092 obj_version read_version
;
1093 obj_version write_version
;
1095 obj_version
*version_for_read() {
1096 return &read_version
;
1099 obj_version
*version_for_write() {
1100 if (write_version
.ver
== 0)
1103 return &write_version
;
1106 obj_version
*version_for_check() {
1107 if (read_version
.ver
== 0)
1110 return &read_version
;
1113 void prepare_op_for_read(librados::ObjectReadOperation
*op
);
1114 void prepare_op_for_write(librados::ObjectWriteOperation
*op
);
1116 void apply_write() {
1117 read_version
= write_version
;
1118 write_version
= obj_version();
1122 read_version
= obj_version();
1123 write_version
= obj_version();
1126 void generate_new_write_ver(CephContext
*cct
);
1129 enum RGWBucketFlags
{
1130 BUCKET_SUSPENDED
= 0x1,
1131 BUCKET_VERSIONED
= 0x2,
1132 BUCKET_VERSIONS_SUSPENDED
= 0x4,
1135 enum RGWBucketIndexType
{
1136 RGWBIType_Normal
= 0,
1137 RGWBIType_Indexless
= 1,
1140 inline ostream
& operator<<(ostream
& out
, const RGWBucketIndexType
&index_type
)
1142 switch (index_type
) {
1143 case RGWBIType_Normal
:
1144 return out
<< "Normal";
1145 case RGWBIType_Indexless
:
1146 return out
<< "Indexless";
1148 return out
<< "Unknown";
1152 struct RGWBucketInfo
1154 enum BIShardsHashType
{
1162 ceph::real_time creation_time
;
1163 string placement_rule
;
1164 bool has_instance_obj
;
1165 RGWObjVersionTracker objv_tracker
; /* we don't need to serialize this, for runtime tracking */
1166 obj_version ep_objv
; /* entry point object version, for runtime tracking only */
1169 // Represents the number of bucket index object shards:
1170 // - value of 0 indicates there is no sharding (this is by default before this
1171 // feature is implemented).
1172 // - value of UINT32_T::MAX indicates this is a blind bucket.
1173 uint32_t num_shards
;
1175 // Represents the bucket index shard hash type.
1176 uint8_t bucket_index_shard_hash_type
;
1178 // Represents the shard number for blind bucket.
1179 const static uint32_t NUM_SHARDS_BLIND_BUCKET
;
1181 bool requester_pays
;
1184 RGWBucketWebsiteConf website_conf
;
1186 RGWBucketIndexType index_type
;
1188 bool swift_versioning
;
1189 string swift_ver_location
;
1191 map
<string
, uint32_t> mdsearch_config
;
1194 uint8_t reshard_status
;
1195 string new_bucket_instance_id
;
1197 void encode(bufferlist
& bl
) const {
1198 ENCODE_START(19, 4, bl
);
1199 ::encode(bucket
, bl
);
1200 ::encode(owner
.id
, bl
);
1201 ::encode(flags
, bl
);
1202 ::encode(zonegroup
, bl
);
1203 uint64_t ct
= real_clock::to_time_t(creation_time
);
1205 ::encode(placement_rule
, bl
);
1206 ::encode(has_instance_obj
, bl
);
1207 ::encode(quota
, bl
);
1208 ::encode(num_shards
, bl
);
1209 ::encode(bucket_index_shard_hash_type
, bl
);
1210 ::encode(requester_pays
, bl
);
1211 ::encode(owner
.tenant
, bl
);
1212 ::encode(has_website
, bl
);
1214 ::encode(website_conf
, bl
);
1216 ::encode((uint32_t)index_type
, bl
);
1217 ::encode(swift_versioning
, bl
);
1218 if (swift_versioning
) {
1219 ::encode(swift_ver_location
, bl
);
1221 ::encode(creation_time
, bl
);
1222 ::encode(mdsearch_config
, bl
);
1223 ::encode(reshard_status
, bl
);
1224 ::encode(new_bucket_instance_id
, bl
);
1227 void decode(bufferlist::iterator
& bl
) {
1228 DECODE_START_LEGACY_COMPAT_LEN_32(19, 4, 4, bl
);
1229 ::decode(bucket
, bl
);
1230 if (struct_v
>= 2) {
1236 ::decode(flags
, bl
);
1238 ::decode(zonegroup
, bl
);
1239 if (struct_v
>= 6) {
1243 creation_time
= ceph::real_clock::from_time_t((time_t)ct
);
1246 ::decode(placement_rule
, bl
);
1248 ::decode(has_instance_obj
, bl
);
1250 ::decode(quota
, bl
);
1252 ::decode(num_shards
, bl
);
1254 ::decode(bucket_index_shard_hash_type
, bl
);
1256 ::decode(requester_pays
, bl
);
1258 ::decode(owner
.tenant
, bl
);
1259 if (struct_v
>= 14) {
1260 ::decode(has_website
, bl
);
1262 ::decode(website_conf
, bl
);
1264 website_conf
= RGWBucketWebsiteConf();
1267 if (struct_v
>= 15) {
1270 index_type
= (RGWBucketIndexType
)it
;
1272 index_type
= RGWBIType_Normal
;
1274 swift_versioning
= false;
1275 swift_ver_location
.clear();
1276 if (struct_v
>= 16) {
1277 ::decode(swift_versioning
, bl
);
1278 if (swift_versioning
) {
1279 ::decode(swift_ver_location
, bl
);
1282 if (struct_v
>= 17) {
1283 ::decode(creation_time
, bl
);
1285 if (struct_v
>= 18) {
1286 ::decode(mdsearch_config
, bl
);
1288 if (struct_v
>= 19) {
1289 ::decode(reshard_status
, bl
);
1290 ::decode(new_bucket_instance_id
, bl
);
1294 void dump(Formatter
*f
) const;
1295 static void generate_test_instances(list
<RGWBucketInfo
*>& o
);
1297 void decode_json(JSONObj
*obj
);
1299 bool versioned() const { return (flags
& BUCKET_VERSIONED
) != 0; }
1300 int versioning_status() { return flags
& (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
); }
1301 bool versioning_enabled() { return versioning_status() == BUCKET_VERSIONED
; }
1303 bool has_swift_versioning() const {
1304 /* A bucket may be versioned through one mechanism only. */
1305 return swift_versioning
&& !versioned();
1308 RGWBucketInfo() : flags(0), has_instance_obj(false), num_shards(0), bucket_index_shard_hash_type(MOD
), requester_pays(false),
1309 has_website(false), swift_versioning(false), reshard_status(0) {}
1311 WRITE_CLASS_ENCODER(RGWBucketInfo
)
1313 struct RGWBucketEntryPoint
1317 ceph::real_time creation_time
;
1320 bool has_bucket_info
;
1321 RGWBucketInfo old_bucket_info
;
1323 RGWBucketEntryPoint() : linked(false), has_bucket_info(false) {}
1325 void encode(bufferlist
& bl
) const {
1326 ENCODE_START(10, 8, bl
);
1327 ::encode(bucket
, bl
);
1328 ::encode(owner
.id
, bl
);
1329 ::encode(linked
, bl
);
1330 uint64_t ctime
= (uint64_t)real_clock::to_time_t(creation_time
);
1331 ::encode(ctime
, bl
);
1332 ::encode(owner
, bl
);
1333 ::encode(creation_time
, bl
);
1336 void decode(bufferlist::iterator
& bl
) {
1337 bufferlist::iterator orig_iter
= bl
;
1338 DECODE_START_LEGACY_COMPAT_LEN_32(10, 4, 4, bl
);
1340 /* ouch, old entry, contains the bucket info itself */
1341 old_bucket_info
.decode(orig_iter
);
1342 has_bucket_info
= true;
1345 has_bucket_info
= false;
1346 ::decode(bucket
, bl
);
1347 ::decode(owner
.id
, bl
);
1348 ::decode(linked
, bl
);
1350 ::decode(ctime
, bl
);
1351 if (struct_v
< 10) {
1352 creation_time
= real_clock::from_time_t((time_t)ctime
);
1354 if (struct_v
>= 9) {
1355 ::decode(owner
, bl
);
1357 if (struct_v
>= 10) {
1358 ::decode(creation_time
, bl
);
1363 void dump(Formatter
*f
) const;
1364 void decode_json(JSONObj
*obj
);
1366 WRITE_CLASS_ENCODER(RGWBucketEntryPoint
)
1368 struct RGWStorageStats
1370 RGWObjCategory category
;
1372 uint64_t size_rounded
;
1373 uint64_t size_utilized
{0}; //< size after compression, encryption
1374 uint64_t num_objects
;
1377 : category(RGW_OBJ_CATEGORY_NONE
),
1382 void dump(Formatter
*f
) const;
1387 /* Namespaced forward declarations. */
1391 class AWSBrowserUploadAbstractor
;
1404 map
<string
, string
> x_meta_map
;
1410 string request_uri_aws4
;
1411 string effective_uri
;
1412 string request_params
;
1415 req_info(CephContext
*cct
, const RGWEnv
*env
);
1416 void rebuild_from(req_info
& src
);
1417 void init_meta_info(bool *found_bad_meta
);
1420 typedef cls_rgw_obj_key rgw_obj_index_key
;
1422 struct rgw_obj_key
{
1428 // cppcheck-suppress noExplicitConstructor
1429 rgw_obj_key(const string
& n
) : name(n
) {}
1430 rgw_obj_key(const string
& n
, const string
& i
) : name(n
), instance(i
) {}
1431 rgw_obj_key(const string
& n
, const string
& i
, const string
& _ns
) : name(n
), instance(i
), ns(_ns
) {}
1433 rgw_obj_key(const rgw_obj_index_key
& k
) {
1434 parse_index_key(k
.name
, &name
, &ns
);
1435 instance
= k
.instance
;
1438 static void parse_index_key(const string
& key
, string
*name
, string
*ns
) {
1439 if (key
[0] != '_') {
1444 if (key
[1] == '_') {
1445 *name
= key
.substr(1);
1449 ssize_t pos
= key
.find('_', 1);
1451 /* shouldn't happen, just use key */
1457 *name
= key
.substr(pos
+ 1);
1458 *ns
= key
.substr(1, pos
-1);
1461 void set(const string
& n
) {
1467 void set(const string
& n
, const string
& i
) {
1473 void set(const string
& n
, const string
& i
, const string
& _ns
) {
1479 bool set(const rgw_obj_index_key
& index_key
) {
1480 if (!parse_raw_oid(index_key
.name
, this)) {
1483 instance
= index_key
.instance
;
1487 void set_instance(const string
& i
) {
1491 string
get_index_key_name() const {
1493 if (name
.size() < 1 || name
[0] != '_') {
1496 return string("_") + name
;
1499 char buf
[ns
.size() + 16];
1500 snprintf(buf
, sizeof(buf
), "_%s_", ns
.c_str());
1501 return string(buf
) + name
;
1504 void get_index_key(rgw_obj_index_key
*key
) const {
1505 key
->name
= get_index_key_name();
1506 key
->instance
= instance
;
1509 string
get_loc() const {
1511 * For backward compatibility. Older versions used to have object locator on all objects,
1512 * however, the name was the effective object locator. This had the same effect as not
1513 * having object locator at all for most objects but the ones that started with underscore as
1514 * these were escaped.
1516 if (name
[0] == '_' && ns
.empty()) {
1523 bool empty() const {
1524 return name
.empty();
1527 bool have_null_instance() const {
1528 return instance
== "null";
1531 bool have_instance() const {
1532 return !instance
.empty();
1535 bool need_to_encode_instance() const {
1536 return have_instance() && !have_null_instance();
1539 string
get_oid() const {
1540 if (ns
.empty() && !need_to_encode_instance()) {
1541 if (name
.size() < 1 || name
[0] != '_') {
1544 return string("_") + name
;
1549 if (need_to_encode_instance()) {
1550 oid
.append(string(":") + instance
);
1557 bool operator==(const rgw_obj_key
& k
) const {
1558 return (name
.compare(k
.name
) == 0) &&
1559 (instance
.compare(k
.instance
) == 0);
1562 bool operator<(const rgw_obj_key
& k
) const {
1563 int r
= name
.compare(k
.name
);
1565 r
= instance
.compare(k
.instance
);
1570 bool operator<=(const rgw_obj_key
& k
) const {
1571 return !(k
< *this);
1574 static void parse_ns_field(string
& ns
, string
& instance
) {
1575 int pos
= ns
.find(':');
1577 instance
= ns
.substr(pos
+ 1);
1578 ns
= ns
.substr(0, pos
);
1584 static bool parse_raw_oid(const string
& oid
, rgw_obj_key
*key
) {
1585 key
->instance
.clear();
1587 if (oid
[0] != '_') {
1592 if (oid
.size() >= 2 && oid
[1] == '_') {
1593 key
->name
= oid
.substr(1);
1597 if (oid
[0] != '_' || oid
.size() < 3) // for namespace, min size would be 3: _x_
1600 int pos
= oid
.find('_', 1);
1601 if (pos
<= 1) // if it starts with __, it's not in our namespace
1604 key
->ns
= oid
.substr(1, pos
- 1);
1605 parse_ns_field(key
->ns
, key
->instance
);
1607 key
->name
= oid
.substr(pos
+ 1);
1612 * Translate a namespace-mangled object name to the user-facing name
1613 * existing in the given namespace.
1615 * If the object is part of the given namespace, it returns true
1616 * and cuts down the name to the unmangled version. If it is not
1617 * part of the given namespace, it returns false.
1619 static bool oid_to_key_in_ns(const string
& oid
, rgw_obj_key
*key
, const string
& ns
) {
1621 bool ret
= parse_raw_oid(oid
, key
);
1626 return (ns
== key
->ns
);
1630 * Given a mangled object name and an empty namespace string, this
1631 * function extracts the namespace into the string and sets the object
1632 * name to be the unmangled version.
1634 * It returns true after successfully doing so, or
1635 * false if it fails.
1637 static bool strip_namespace_from_name(string
& name
, string
& ns
, string
& instance
) {
1640 if (name
[0] != '_') {
1644 size_t pos
= name
.find('_', 1);
1645 if (pos
== string::npos
) {
1649 if (name
[1] == '_') {
1650 name
= name
.substr(1);
1654 size_t period_pos
= name
.find('.');
1655 if (period_pos
< pos
) {
1659 ns
= name
.substr(1, pos
-1);
1660 name
= name
.substr(pos
+1, string::npos
);
1662 parse_ns_field(ns
, instance
);
1666 void encode(bufferlist
& bl
) const {
1667 ENCODE_START(2, 1, bl
);
1669 ::encode(instance
, bl
);
1673 void decode(bufferlist::iterator
& bl
) {
1674 DECODE_START(2, bl
);
1676 ::decode(instance
, bl
);
1677 if (struct_v
>= 2) {
1682 void dump(Formatter
*f
) const;
1684 WRITE_CLASS_ENCODER(rgw_obj_key
)
1686 inline ostream
& operator<<(ostream
& out
, const rgw_obj_key
&o
) {
1687 if (o
.instance
.empty()) {
1688 return out
<< o
.name
;
1690 return out
<< o
.name
<< "[" << o
.instance
<< "]";
1694 inline ostream
& operator<<(ostream
& out
, const rgw_obj_index_key
&o
) {
1695 if (o
.instance
.empty()) {
1696 return out
<< o
.name
;
1698 return out
<< o
.name
<< "[" << o
.instance
<< "]";
1702 struct req_init_state
{
1703 /* Keeps [[tenant]:]bucket until we parse the token. */
1708 /* XXX why don't RGWRequest (or descendants) hold this state? */
1711 #include "rgw_auth.h"
1713 /** Store all the state necessary to complete and respond to an HTTP request*/
1716 rgw::io::BasicClient
*cio
;
1717 RGWRequest
*req
; /// XXX: re-remove??
1720 bool content_started
;
1722 ceph::Formatter
*formatter
;
1724 string relative_uri
;
1726 int64_t content_length
;
1727 map
<string
, string
> generic_attrs
;
1731 bool enable_ops_log
;
1732 bool enable_usage_log
;
1733 uint8_t defer_to_bucket_acls
;
1736 /* Set once when url_bucket is parsed and not violated thereafter. */
1737 string account_name
;
1739 string bucket_tenant
;
1744 string src_tenant_name
;
1745 string src_bucket_name
;
1746 rgw_obj_key src_object
;
1747 ACLOwner bucket_owner
;
1750 string zonegroup_name
;
1751 string zonegroup_endpoint
;
1752 string bucket_instance_id
;
1753 int bucket_instance_shard_id
;
1757 RGWBucketInfo bucket_info
;
1758 map
<string
, bufferlist
> bucket_attrs
;
1766 /* TODO(rzarzynski): switch out to the static_ptr for both members. */
1768 /* Object having the knowledge about an authenticated identity and allowing
1769 * to apply it during the authorization phase (verify_permission() methods
1770 * of a given RGWOp). Thus, it bounds authentication and authorization steps
1771 * through a well-defined interface. For more details, see rgw_auth.h. */
1772 std::unique_ptr
<rgw::auth::Identity
> identity
;
1774 std::shared_ptr
<rgw::auth::Completer
> completer
;
1776 /* A container for credentials of the S3's browser upload. It's necessary
1777 * because: 1) the ::authenticate() method of auth engines and strategies
1778 * take req_state only; 2) auth strategies live much longer than RGWOps -
1779 * there is no way to pass additional data dependencies through ctors. */
1782 friend class RGWPostObj_ObjStore_S3
;
1784 friend class rgw::auth::s3::AWSBrowserUploadAbstractor
;
1786 std::string access_key
;
1787 std::string signature
;
1788 std::string x_amz_algorithm
;
1789 std::string x_amz_credential
;
1790 std::string x_amz_date
;
1791 ceph::bufferlist encoded_policy
;
1795 std::unique_ptr
<RGWAccessControlPolicy
> user_acl
;
1796 RGWAccessControlPolicy
*bucket_acl
;
1797 RGWAccessControlPolicy
*object_acl
;
1799 rgw::IAM::Environment env
;
1800 boost::optional
<rgw::IAM::Policy
> iam_policy
;
1802 /* Is the request made by an user marked as a system one?
1803 * Being system user means we also have the admin status. */
1804 bool system_request
;
1807 bool has_acl_header
;
1808 bool local_source
; /* source is local */
1812 /* Content-Disposition override for TempURL of Swift API. */
1821 req_init_state init_state
;
1829 req_state(CephContext
* _cct
, RGWEnv
* e
, RGWUserInfo
* u
);
1832 bool is_err() const { return err
.is_err(); }
1835 void set_req_state_err(struct req_state
*, int);
1836 void set_req_state_err(struct req_state
*, int, const string
&);
1837 void set_req_state_err(struct rgw_err
&, int, const int);
1838 void dump(struct req_state
*);
1840 /** Store basic data on bucket */
1841 struct RGWBucketEnt
{
1844 size_t size_rounded
;
1845 real_time creation_time
;
1848 RGWBucketEnt() : size(0), size_rounded(0), count(0) {}
1850 explicit RGWBucketEnt(const rgw_user
& u
, const cls_user_bucket_entry
& e
)
1851 : bucket(u
, e
.bucket
),
1853 size_rounded(e
.size_rounded
),
1854 creation_time(e
.creation_time
),
1858 void convert(cls_user_bucket_entry
*b
) const {
1859 bucket
.convert(&b
->bucket
);
1861 b
->size_rounded
= size_rounded
;
1862 b
->creation_time
= creation_time
;
1866 void encode(bufferlist
& bl
) const {
1867 ENCODE_START(6, 5, bl
);
1869 __u32 mt
= ceph::real_clock::to_time_t(creation_time
);
1870 string empty_str
; // originally had the bucket name here, but we encode bucket later
1871 ::encode(empty_str
, bl
);
1874 ::encode(count
, bl
);
1875 ::encode(bucket
, bl
);
1878 ::encode(creation_time
, bl
);
1881 void decode(bufferlist::iterator
& bl
) {
1882 DECODE_START_LEGACY_COMPAT_LEN(6, 5, 5, bl
);
1885 string empty_str
; // backward compatibility
1886 ::decode(empty_str
, bl
);
1891 creation_time
= ceph::real_clock::from_time_t(mt
);
1894 ::decode(count
, bl
);
1896 ::decode(bucket
, bl
);
1901 ::decode(creation_time
, bl
);
1904 void dump(Formatter
*f
) const;
1905 static void generate_test_instances(list
<RGWBucketEnt
*>& o
);
1907 WRITE_CLASS_ENCODER(RGWBucketEnt
)
1913 bool in_extra_data
{false}; /* in-memory only member, does not serialize */
1915 // Represents the hash index source for this object once it is set (non-empty)
1916 std::string index_hash_source
;
1919 rgw_obj(const rgw_bucket
& b
, const std::string
& name
) : bucket(b
), key(name
) {}
1920 rgw_obj(const rgw_bucket
& b
, const rgw_obj_key
& k
) : bucket(b
), key(k
) {}
1921 rgw_obj(const rgw_bucket
& b
, const rgw_obj_index_key
& k
) : bucket(b
), key(k
) {}
1923 void init(const rgw_bucket
& b
, const std::string
& name
) {
1927 void init(const rgw_bucket
& b
, const std::string
& name
, const string
& i
, const string
& n
) {
1929 key
.set(name
, i
, n
);
1931 void init_ns(const rgw_bucket
& b
, const std::string
& name
, const string
& n
) {
1934 key
.instance
.clear();
1938 bool empty() const {
1942 void set_key(const rgw_obj_key
& k
) {
1946 string
get_oid() const {
1947 return key
.get_oid();
1950 const string
& get_hash_object() const {
1951 return index_hash_source
.empty() ? key
.name
: index_hash_source
;
1954 void set_in_extra_data(bool val
) {
1955 in_extra_data
= val
;
1958 bool is_in_extra_data() const {
1959 return in_extra_data
;
1962 void encode(bufferlist
& bl
) const {
1963 ENCODE_START(6, 6, bl
);
1964 ::encode(bucket
, bl
);
1965 ::encode(key
.ns
, bl
);
1966 ::encode(key
.name
, bl
);
1967 ::encode(key
.instance
, bl
);
1968 // ::encode(placement_id, bl);
1971 void decode(bufferlist::iterator
& bl
) {
1972 DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, bl
);
1975 ::decode(bucket
.name
, bl
); /* bucket.name */
1976 ::decode(s
, bl
); /* loc */
1977 ::decode(key
.ns
, bl
);
1978 ::decode(key
.name
, bl
);
1980 ::decode(bucket
, bl
);
1982 ::decode(key
.instance
, bl
);
1983 if (key
.ns
.empty() && key
.instance
.empty()) {
1984 if (key
.name
[0] == '_') {
1985 key
.name
= key
.name
.substr(1);
1988 if (struct_v
>= 5) {
1989 ::decode(key
.name
, bl
);
1991 ssize_t pos
= key
.name
.find('_', 1);
1993 throw buffer::error();
1995 key
.name
= key
.name
.substr(pos
);
1999 ::decode(bucket
, bl
);
2000 ::decode(key
.ns
, bl
);
2001 ::decode(key
.name
, bl
);
2002 ::decode(key
.instance
, bl
);
2003 // ::decode(placement_id, bl);
2007 void dump(Formatter
*f
) const;
2008 static void generate_test_instances(list
<rgw_obj
*>& o
);
2010 bool operator==(const rgw_obj
& o
) const {
2011 return (key
== o
.key
) &&
2012 (bucket
== o
.bucket
);
2014 bool operator<(const rgw_obj
& o
) const {
2015 int r
= key
.name
.compare(o
.key
.name
);
2017 r
= bucket
.bucket_id
.compare(o
.bucket
.bucket_id
); /* not comparing bucket.name, if bucket_id is equal so will be bucket.name */
2019 r
= key
.ns
.compare(o
.key
.ns
);
2021 r
= key
.instance
.compare(o
.key
.instance
);
2029 const rgw_pool
& get_explicit_data_pool() {
2030 if (!in_extra_data
|| bucket
.explicit_placement
.data_extra_pool
.empty()) {
2031 return bucket
.explicit_placement
.data_pool
;
2033 return bucket
.explicit_placement
.data_extra_pool
;
2036 WRITE_CLASS_ENCODER(rgw_obj
)
2038 struct rgw_cache_entry_info
{
2039 string cache_locator
;
2042 rgw_cache_entry_info() : gen(0) {}
2045 inline ostream
& operator<<(ostream
& out
, const rgw_obj
&o
) {
2046 return out
<< o
.bucket
.name
<< ":" << o
.get_oid();
2049 static inline void buf_to_hex(const unsigned char* const buf
,
2054 for (size_t i
= 0; i
< len
; i
++) {
2055 ::sprintf(&str
[i
*2], "%02x", static_cast<int>(buf
[i
]));
2059 template<size_t N
> static inline std::array
<char, N
* 2 + 1>
2060 buf_to_hex(const std::array
<unsigned char, N
>& buf
)
2062 static_assert(N
> 0, "The input array must be at least one element long");
2064 std::array
<char, N
* 2 + 1> hex_dest
;
2065 buf_to_hex(buf
.data(), N
, hex_dest
.data());
2069 static inline int hexdigit(char c
)
2071 if (c
>= '0' && c
<= '9')
2074 if (c
>= 'A' && c
<= 'F')
2075 return c
- 'A' + 0xa;
2079 static inline int hex_to_buf(const char *hex
, char *buf
, int len
)
2082 const char *p
= hex
;
2087 int d
= hexdigit(*p
);
2104 static inline int rgw_str_to_bool(const char *s
, int def_val
)
2109 return (strcasecmp(s
, "on") == 0 ||
2110 strcasecmp(s
, "yes") == 0 ||
2111 strcasecmp(s
, "1") == 0);
2114 static inline void append_rand_alpha(CephContext
*cct
, const string
& src
, string
& dest
, int len
)
2118 gen_rand_alphanumeric(cct
, buf
, len
);
2123 static inline const char *rgw_obj_category_name(RGWObjCategory category
)
2126 case RGW_OBJ_CATEGORY_NONE
:
2128 case RGW_OBJ_CATEGORY_MAIN
:
2130 case RGW_OBJ_CATEGORY_SHADOW
:
2131 return "rgw.shadow";
2132 case RGW_OBJ_CATEGORY_MULTIMETA
:
2133 return "rgw.multimeta";
2139 static inline uint64_t rgw_rounded_kb(uint64_t bytes
)
2141 return (bytes
+ 1023) / 1024;
2144 static inline uint64_t rgw_rounded_objsize(uint64_t bytes
)
2146 return ((bytes
+ 4095) & ~4095);
2149 static inline uint64_t rgw_rounded_objsize_kb(uint64_t bytes
)
2151 return ((bytes
+ 4095) & ~4095) / 1024;
2154 extern string
rgw_string_unquote(const string
& s
);
2155 extern void parse_csv_string(const string
& ival
, vector
<string
>& ovals
);
2156 extern int parse_key_value(string
& in_str
, string
& key
, string
& val
);
2157 extern int parse_key_value(string
& in_str
, const char *delim
, string
& key
, string
& val
);
2159 extern boost::optional
<std::pair
<boost::string_view
, boost::string_view
>>
2160 parse_key_value(const boost::string_view
& in_str
,
2161 const boost::string_view
& delim
);
2162 extern boost::optional
<std::pair
<boost::string_view
, boost::string_view
>>
2163 parse_key_value(const boost::string_view
& in_str
);
2167 extern int parse_time(const char *time_str
, real_time
*time
);
2168 extern bool parse_rfc2616(const char *s
, struct tm
*t
);
2169 extern bool parse_iso8601(const char *s
, struct tm
*t
, uint32_t *pns
= NULL
, bool extended_format
= true);
2170 extern string
rgw_trim_whitespace(const string
& src
);
2171 extern boost::string_view
rgw_trim_whitespace(const boost::string_view
& src
);
2172 extern string
rgw_trim_quotes(const string
& val
);
2174 extern void rgw_to_iso8601(const real_time
& t
, char *dest
, int buf_size
);
2175 extern void rgw_to_iso8601(const real_time
& t
, string
*dest
);
2177 /** Check if the req_state's user has the necessary permissions
2178 * to do the requested action */
2179 bool verify_user_permission(struct req_state
* const s
,
2180 RGWAccessControlPolicy
* const user_acl
,
2182 bool verify_user_permission(struct req_state
* const s
,
2184 bool verify_bucket_permission(
2185 struct req_state
* const s
,
2186 const rgw_bucket
& bucket
,
2187 RGWAccessControlPolicy
* const user_acl
,
2188 RGWAccessControlPolicy
* const bucket_acl
,
2189 const boost::optional
<rgw::IAM::Policy
>& bucket_policy
,
2191 bool verify_bucket_permission(struct req_state
* const s
, const uint64_t op
);
2192 bool verify_bucket_permission_no_policy(
2193 struct req_state
* const s
,
2194 RGWAccessControlPolicy
* const user_acl
,
2195 RGWAccessControlPolicy
* const bucket_acl
,
2197 bool verify_bucket_permission_no_policy(struct req_state
* const s
,
2199 extern bool verify_object_permission(
2200 struct req_state
* const s
,
2202 RGWAccessControlPolicy
* const user_acl
,
2203 RGWAccessControlPolicy
* const bucket_acl
,
2204 RGWAccessControlPolicy
* const object_acl
,
2205 const boost::optional
<rgw::IAM::Policy
>& bucket_policy
,
2207 extern bool verify_object_permission(struct req_state
*s
, uint64_t op
);
2208 extern bool verify_object_permission_no_policy(
2209 struct req_state
* const s
,
2210 RGWAccessControlPolicy
* const user_acl
,
2211 RGWAccessControlPolicy
* const bucket_acl
,
2212 RGWAccessControlPolicy
* const object_acl
,
2214 extern bool verify_object_permission_no_policy(struct req_state
*s
,
2216 /** Convert an input URL into a sane object name
2217 * by converting %-escaped strings into characters, etc*/
2218 extern void rgw_uri_escape_char(char c
, string
& dst
);
2219 extern std::string
url_decode(const boost::string_view
& src_str
,
2220 bool in_query
= false);
2221 extern void url_encode(const std::string
& src
,
2223 extern std::string
url_encode(const std::string
& src
);
2225 /* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */
2226 extern void calc_hmac_sha1(const char *key
, int key_len
,
2227 const char *msg
, int msg_len
, char *dest
);
2229 using sha1_digest_t
= \
2230 std::array
<char, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE
>;
2232 static inline sha1_digest_t
2233 calc_hmac_sha1(const boost::string_view
& key
, const boost::string_view
& msg
) {
2235 calc_hmac_sha1(key
.data(), key
.size(), msg
.data(), msg
.size(), dest
.data());
2239 /* destination should be CEPH_CRYPTO_HMACSHA256_DIGESTSIZE bytes long */
2240 extern void calc_hmac_sha256(const char *key
, int key_len
,
2241 const char *msg
, int msg_len
,
2244 using sha256_digest_t
= \
2245 std::array
<unsigned char, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
>;
2247 static inline sha256_digest_t
2248 calc_hmac_sha256(const char *key
, const int key_len
,
2249 const char *msg
, const int msg_len
) {
2250 std::array
<unsigned char, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
> dest
;
2251 calc_hmac_sha256(key
, key_len
, msg
, msg_len
,
2252 reinterpret_cast<char*>(dest
.data()));
2256 static inline sha256_digest_t
2257 calc_hmac_sha256(const boost::string_view
& key
, const boost::string_view
& msg
) {
2258 std::array
<unsigned char, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
> dest
;
2259 calc_hmac_sha256(key
.data(), key
.size(),
2260 msg
.data(), msg
.size(),
2261 reinterpret_cast<char*>(dest
.data()));
2265 static inline sha256_digest_t
2266 calc_hmac_sha256(const std::vector
<unsigned char>& key
,
2267 const boost::string_view
& msg
) {
2268 std::array
<unsigned char, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
> dest
;
2269 calc_hmac_sha256(reinterpret_cast<const char*>(key
.data()), key
.size(),
2270 msg
.data(), msg
.size(),
2271 reinterpret_cast<char*>(dest
.data()));
2275 template<size_t KeyLenN
>
2276 static inline sha256_digest_t
2277 calc_hmac_sha256(const std::array
<unsigned char, KeyLenN
>& key
,
2278 const boost::string_view
& msg
) {
2279 std::array
<unsigned char, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
> dest
;
2280 calc_hmac_sha256(reinterpret_cast<const char*>(key
.data()), key
.size(),
2281 msg
.data(), msg
.size(),
2282 reinterpret_cast<char*>(dest
.data()));
2286 extern sha256_digest_t
calc_hash_sha256(const boost::string_view
& msg
);
2288 extern ceph::crypto::SHA256
* calc_hash_sha256_open_stream();
2289 extern void calc_hash_sha256_update_stream(ceph::crypto::SHA256
* hash
,
2292 extern std::string
calc_hash_sha256_close_stream(ceph::crypto::SHA256
** phash
);
2293 extern std::string
calc_hash_sha256_restart_stream(ceph::crypto::SHA256
** phash
);
2295 extern int rgw_parse_op_type_list(const string
& str
, uint32_t *perm
);
2298 constexpr uint32_t MATCH_POLICY_ACTION
= 0x01;
2299 constexpr uint32_t MATCH_POLICY_RESOURCE
= 0x02;
2300 constexpr uint32_t MATCH_POLICY_ARN
= 0x04;
2301 constexpr uint32_t MATCH_POLICY_STRING
= 0x08;
2304 int match(const std::string
& pattern
, const std::string
& input
, uint32_t flag
);