1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
5 * Ceph - scalable distributed file system
7 * Copyright (C) 2004-2009 Sage Weil <sage@newdream.net>
8 * Copyright (C) 2015 Yehuda Sadeh <yehuda@redhat.com>
10 * This is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License version 2.1, as published by the Free Software
13 * Foundation. See file COPYING.
17 #ifndef CEPH_RGW_COMMON_H
18 #define CEPH_RGW_COMMON_H
22 #include <boost/utility/string_view.hpp>
24 #include "common/ceph_crypto.h"
25 #include "common/random_string.h"
28 #include "rgw_iam_policy.h"
29 #include "rgw_quota.h"
30 #include "rgw_string.h"
31 #include "common/async/yield_context.h"
32 #include "rgw_website.h"
33 #include "rgw_object_lock.h"
35 #include "rgw_sync_policy.h"
36 #include "cls/version/cls_version_types.h"
37 #include "cls/user/cls_user_types.h"
38 #include "cls/rgw/cls_rgw_types.h"
39 #include "include/rados/librados.hpp"
40 #include "rgw_public_access.h"
50 using ceph::crypto::MD5
;
52 #define RGW_ATTR_PREFIX "user.rgw."
54 #define RGW_HTTP_RGWX_ATTR_PREFIX "RGWX_ATTR_"
55 #define RGW_HTTP_RGWX_ATTR_PREFIX_OUT "Rgwx-Attr-"
57 #define RGW_AMZ_PREFIX "x-amz-"
58 #define RGW_AMZ_META_PREFIX RGW_AMZ_PREFIX "meta-"
59 #define RGW_AMZ_WEBSITE_REDIRECT_LOCATION RGW_AMZ_PREFIX "website-redirect-location"
60 #define RGW_AMZ_TAG_COUNT RGW_AMZ_PREFIX "tagging-count"
62 #define RGW_SYS_PARAM_PREFIX "rgwx-"
64 #define RGW_ATTR_ACL RGW_ATTR_PREFIX "acl"
65 #define RGW_ATTR_LC RGW_ATTR_PREFIX "lc"
66 #define RGW_ATTR_CORS RGW_ATTR_PREFIX "cors"
67 #define RGW_ATTR_ETAG RGW_ATTR_PREFIX "etag"
68 #define RGW_ATTR_BUCKETS RGW_ATTR_PREFIX "buckets"
69 #define RGW_ATTR_META_PREFIX RGW_ATTR_PREFIX RGW_AMZ_META_PREFIX
70 #define RGW_ATTR_CONTENT_TYPE RGW_ATTR_PREFIX "content_type"
71 #define RGW_ATTR_CACHE_CONTROL RGW_ATTR_PREFIX "cache_control"
72 #define RGW_ATTR_CONTENT_DISP RGW_ATTR_PREFIX "content_disposition"
73 #define RGW_ATTR_CONTENT_ENC RGW_ATTR_PREFIX "content_encoding"
74 #define RGW_ATTR_CONTENT_LANG RGW_ATTR_PREFIX "content_language"
75 #define RGW_ATTR_EXPIRES RGW_ATTR_PREFIX "expires"
76 #define RGW_ATTR_DELETE_AT RGW_ATTR_PREFIX "delete_at"
77 #define RGW_ATTR_ID_TAG RGW_ATTR_PREFIX "idtag"
78 #define RGW_ATTR_TAIL_TAG RGW_ATTR_PREFIX "tail_tag"
79 #define RGW_ATTR_SHADOW_OBJ RGW_ATTR_PREFIX "shadow_name"
80 #define RGW_ATTR_MANIFEST RGW_ATTR_PREFIX "manifest"
81 #define RGW_ATTR_USER_MANIFEST RGW_ATTR_PREFIX "user_manifest"
82 #define RGW_ATTR_AMZ_WEBSITE_REDIRECT_LOCATION RGW_ATTR_PREFIX RGW_AMZ_WEBSITE_REDIRECT_LOCATION
83 #define RGW_ATTR_SLO_MANIFEST RGW_ATTR_PREFIX "slo_manifest"
84 /* Information whether an object is SLO or not must be exposed to
85 * user through custom HTTP header named X-Static-Large-Object. */
86 #define RGW_ATTR_SLO_UINDICATOR RGW_ATTR_META_PREFIX "static-large-object"
87 #define RGW_ATTR_X_ROBOTS_TAG RGW_ATTR_PREFIX "x-robots-tag"
88 #define RGW_ATTR_STORAGE_CLASS RGW_ATTR_PREFIX "storage_class"
91 #define RGW_ATTR_OBJECT_LOCK RGW_ATTR_PREFIX "object-lock"
92 #define RGW_ATTR_OBJECT_RETENTION RGW_ATTR_PREFIX "object-retention"
93 #define RGW_ATTR_OBJECT_LEGAL_HOLD RGW_ATTR_PREFIX "object-legal-hold"
96 #define RGW_ATTR_PG_VER RGW_ATTR_PREFIX "pg_ver"
97 #define RGW_ATTR_SOURCE_ZONE RGW_ATTR_PREFIX "source_zone"
98 #define RGW_ATTR_TAGS RGW_ATTR_PREFIX RGW_AMZ_PREFIX "tagging"
100 #define RGW_ATTR_TEMPURL_KEY1 RGW_ATTR_META_PREFIX "temp-url-key"
101 #define RGW_ATTR_TEMPURL_KEY2 RGW_ATTR_META_PREFIX "temp-url-key-2"
103 /* Account/container quota of the Swift API. */
104 #define RGW_ATTR_QUOTA_NOBJS RGW_ATTR_META_PREFIX "quota-count"
105 #define RGW_ATTR_QUOTA_MSIZE RGW_ATTR_META_PREFIX "quota-bytes"
107 /* Static Web Site of Swift API. */
108 #define RGW_ATTR_WEB_INDEX RGW_ATTR_META_PREFIX "web-index"
109 #define RGW_ATTR_WEB_ERROR RGW_ATTR_META_PREFIX "web-error"
110 #define RGW_ATTR_WEB_LISTINGS RGW_ATTR_META_PREFIX "web-listings"
111 #define RGW_ATTR_WEB_LIST_CSS RGW_ATTR_META_PREFIX "web-listings-css"
112 #define RGW_ATTR_SUBDIR_MARKER RGW_ATTR_META_PREFIX "web-directory-type"
114 #define RGW_ATTR_OLH_PREFIX RGW_ATTR_PREFIX "olh."
116 #define RGW_ATTR_OLH_INFO RGW_ATTR_OLH_PREFIX "info"
117 #define RGW_ATTR_OLH_VER RGW_ATTR_OLH_PREFIX "ver"
118 #define RGW_ATTR_OLH_ID_TAG RGW_ATTR_OLH_PREFIX "idtag"
119 #define RGW_ATTR_OLH_PENDING_PREFIX RGW_ATTR_OLH_PREFIX "pending."
121 #define RGW_ATTR_COMPRESSION RGW_ATTR_PREFIX "compression"
123 #define RGW_ATTR_APPEND_PART_NUM RGW_ATTR_PREFIX "append_part_num"
126 #define RGW_ATTR_IAM_POLICY RGW_ATTR_PREFIX "iam-policy"
127 #define RGW_ATTR_USER_POLICY RGW_ATTR_PREFIX "user-policy"
128 #define RGW_ATTR_PUBLIC_ACCESS RGW_ATTR_PREFIX "public-access"
130 /* RGW File Attributes */
131 #define RGW_ATTR_UNIX_KEY1 RGW_ATTR_PREFIX "unix-key1"
132 #define RGW_ATTR_UNIX1 RGW_ATTR_PREFIX "unix1"
134 #define RGW_ATTR_CRYPT_PREFIX RGW_ATTR_PREFIX "crypt."
135 #define RGW_ATTR_CRYPT_MODE RGW_ATTR_CRYPT_PREFIX "mode"
136 #define RGW_ATTR_CRYPT_KEYMD5 RGW_ATTR_CRYPT_PREFIX "keymd5"
137 #define RGW_ATTR_CRYPT_KEYID RGW_ATTR_CRYPT_PREFIX "keyid"
138 #define RGW_ATTR_CRYPT_KEYSEL RGW_ATTR_CRYPT_PREFIX "keysel"
141 #define RGW_FORMAT_PLAIN 0
142 #define RGW_FORMAT_XML 1
143 #define RGW_FORMAT_JSON 2
144 #define RGW_FORMAT_HTML 3
146 #define RGW_CAP_READ 0x1
147 #define RGW_CAP_WRITE 0x2
148 #define RGW_CAP_ALL (RGW_CAP_READ | RGW_CAP_WRITE)
150 #define RGW_REST_SWIFT 0x1
151 #define RGW_REST_SWIFT_AUTH 0x2
152 #define RGW_REST_S3 0x4
153 #define RGW_REST_WEBSITE 0x8
154 #define RGW_REST_STS 0x10
155 #define RGW_REST_IAM 0x20
157 #define RGW_SUSPENDED_USER_AUID (uint64_t)-2
159 #define RGW_OP_TYPE_READ 0x01
160 #define RGW_OP_TYPE_WRITE 0x02
161 #define RGW_OP_TYPE_DELETE 0x04
163 #define RGW_OP_TYPE_MODIFY (RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE)
164 #define RGW_OP_TYPE_ALL (RGW_OP_TYPE_READ | RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE)
166 #define RGW_DEFAULT_MAX_BUCKETS 1000
168 #define RGW_DEFER_TO_BUCKET_ACLS_RECURSE 1
169 #define RGW_DEFER_TO_BUCKET_ACLS_FULL_CONTROL 2
171 #define STATUS_CREATED 1900
172 #define STATUS_ACCEPTED 1901
173 #define STATUS_NO_CONTENT 1902
174 #define STATUS_PARTIAL_CONTENT 1903
175 #define STATUS_REDIRECT 1904
176 #define STATUS_NO_APPLY 1905
177 #define STATUS_APPLIED 1906
179 #define ERR_INVALID_BUCKET_NAME 2000
180 #define ERR_INVALID_OBJECT_NAME 2001
181 #define ERR_NO_SUCH_BUCKET 2002
182 #define ERR_METHOD_NOT_ALLOWED 2003
183 #define ERR_INVALID_DIGEST 2004
184 #define ERR_BAD_DIGEST 2005
185 #define ERR_UNRESOLVABLE_EMAIL 2006
186 #define ERR_INVALID_PART 2007
187 #define ERR_INVALID_PART_ORDER 2008
188 #define ERR_NO_SUCH_UPLOAD 2009
189 #define ERR_REQUEST_TIMEOUT 2010
190 #define ERR_LENGTH_REQUIRED 2011
191 #define ERR_REQUEST_TIME_SKEWED 2012
192 #define ERR_BUCKET_EXISTS 2013
193 #define ERR_BAD_URL 2014
194 #define ERR_PRECONDITION_FAILED 2015
195 #define ERR_NOT_MODIFIED 2016
196 #define ERR_INVALID_UTF8 2017
197 #define ERR_UNPROCESSABLE_ENTITY 2018
198 #define ERR_TOO_LARGE 2019
199 #define ERR_TOO_MANY_BUCKETS 2020
200 #define ERR_INVALID_REQUEST 2021
201 #define ERR_TOO_SMALL 2022
202 #define ERR_NOT_FOUND 2023
203 #define ERR_PERMANENT_REDIRECT 2024
204 #define ERR_LOCKED 2025
205 #define ERR_QUOTA_EXCEEDED 2026
206 #define ERR_SIGNATURE_NO_MATCH 2027
207 #define ERR_INVALID_ACCESS_KEY 2028
208 #define ERR_MALFORMED_XML 2029
209 #define ERR_USER_EXIST 2030
210 #define ERR_NOT_SLO_MANIFEST 2031
211 #define ERR_EMAIL_EXIST 2032
212 #define ERR_KEY_EXIST 2033
213 #define ERR_INVALID_SECRET_KEY 2034
214 #define ERR_INVALID_KEY_TYPE 2035
215 #define ERR_INVALID_CAP 2036
216 #define ERR_INVALID_TENANT_NAME 2037
217 #define ERR_WEBSITE_REDIRECT 2038
218 #define ERR_NO_SUCH_WEBSITE_CONFIGURATION 2039
219 #define ERR_AMZ_CONTENT_SHA256_MISMATCH 2040
220 #define ERR_NO_SUCH_LC 2041
221 #define ERR_NO_SUCH_USER 2042
222 #define ERR_NO_SUCH_SUBUSER 2043
223 #define ERR_MFA_REQUIRED 2044
224 #define ERR_NO_SUCH_CORS_CONFIGURATION 2045
225 #define ERR_NO_SUCH_OBJECT_LOCK_CONFIGURATION 2046
226 #define ERR_INVALID_RETENTION_PERIOD 2047
227 #define ERR_USER_SUSPENDED 2100
228 #define ERR_INTERNAL_ERROR 2200
229 #define ERR_NOT_IMPLEMENTED 2201
230 #define ERR_SERVICE_UNAVAILABLE 2202
231 #define ERR_ROLE_EXISTS 2203
232 #define ERR_MALFORMED_DOC 2204
233 #define ERR_NO_ROLE_FOUND 2205
234 #define ERR_DELETE_CONFLICT 2206
235 #define ERR_NO_SUCH_BUCKET_POLICY 2207
236 #define ERR_INVALID_LOCATION_CONSTRAINT 2208
237 #define ERR_TAG_CONFLICT 2209
238 #define ERR_INVALID_TAG 2210
239 #define ERR_ZERO_IN_URL 2211
240 #define ERR_MALFORMED_ACL_ERROR 2212
241 #define ERR_ZONEGROUP_DEFAULT_PLACEMENT_MISCONFIGURATION 2213
242 #define ERR_INVALID_ENCRYPTION_ALGORITHM 2214
243 #define ERR_INVALID_CORS_RULES_ERROR 2215
244 #define ERR_NO_CORS_FOUND 2216
245 #define ERR_INVALID_WEBSITE_ROUTING_RULES_ERROR 2217
246 #define ERR_RATE_LIMITED 2218
247 #define ERR_POSITION_NOT_EQUAL_TO_LENGTH 2219
248 #define ERR_OBJECT_NOT_APPENDABLE 2220
249 #define ERR_INVALID_BUCKET_STATE 2221
251 #define ERR_BUSY_RESHARDING 2300
252 #define ERR_NO_SUCH_ENTITY 2301
253 #define ERR_LIMIT_EXCEEDED 2302
256 #define ERR_PACKED_POLICY_TOO_LARGE 2400
257 #define ERR_INVALID_IDENTITY_TOKEN 2401
259 #define ERR_NO_SUCH_TAG_SET 2402
262 #define UINT32_MAX (0xffffffffu)
267 typedef void *RGWAccessHandle
;
269 enum RGWIntentEvent
{
279 /** Store error returns for output at a different point in the program */
283 bool is_clear() const;
285 friend std::ostream
& operator<<(std::ostream
& oss
, const rgw_err
&err
);
289 std::string err_code
;
293 /* Helper class used for RGWHTTPArgs parsing */
296 const std::string str
;
300 explicit NameVal(const std::string
& nv
) : str(nv
) {}
304 std::string
& get_name() { return name
; }
305 std::string
& get_val() { return val
; }
308 /** Stores the XML arguments associated with the HTTP request in req_state*/
310 std::string str
, empty_str
;
311 std::map
<std::string
, std::string
> val_map
;
312 std::map
<std::string
, std::string
> sys_val_map
;
313 std::map
<std::string
, std::string
> sub_resources
;
314 bool has_resp_modifier
= false;
315 bool admin_subresource_added
= false;
317 RGWHTTPArgs() = default;
318 explicit RGWHTTPArgs(const std::string
& s
) {
323 /** Set the arguments; as received */
324 void set(const std::string
& s
) {
325 has_resp_modifier
= false;
327 sub_resources
.clear();
330 /** parse the received arguments */
332 void append(const std::string
& name
, const string
& val
);
333 /** Get the value for a specific argument parameter */
334 const string
& get(const std::string
& name
, bool *exists
= NULL
) const;
335 boost::optional
<const std::string
&>
336 get_optional(const std::string
& name
) const;
337 int get_bool(const std::string
& name
, bool *val
, bool *exists
);
338 int get_bool(const char *name
, bool *val
, bool *exists
);
339 void get_bool(const char *name
, bool *val
, bool def_val
);
340 int get_int(const char *name
, int *val
, int def_val
);
342 /** Get the value for specific system argument parameter */
343 std::string
sys_get(const std::string
& name
, bool *exists
= nullptr) const;
345 /** see if a parameter is contained in this RGWHTTPArgs */
346 bool exists(const char *name
) const {
347 return (val_map
.find(name
) != std::end(val_map
));
349 bool sub_resource_exists(const char *name
) const {
350 return (sub_resources
.find(name
) != std::end(sub_resources
));
352 std::map
<std::string
, std::string
>& get_params() {
355 const std::map
<std::string
, std::string
>& get_sub_resources() const {
356 return sub_resources
;
358 unsigned get_num_params() const {
359 return val_map
.size();
361 bool has_response_modifier() const {
362 return has_resp_modifier
;
364 void set_system() { /* make all system params visible */
365 std::map
<std::string
, std::string
>::iterator iter
;
366 for (iter
= sys_val_map
.begin(); iter
!= sys_val_map
.end(); ++iter
) {
367 val_map
[iter
->first
] = iter
->second
;
370 const std::string
& get_str() {
375 const char *rgw_conf_get(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, const char *def_val
);
376 int rgw_conf_get_int(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, int def_val
);
377 bool rgw_conf_get_bool(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, bool def_val
);
384 int enable_usage_log
;
385 uint8_t defer_to_bucket_acls
;
386 void init(CephContext
*cct
);
391 defer_to_bucket_acls(0) {
396 std::map
<string
, string
, ltstr_nocase
> env_map
;
399 void init(CephContext
*cct
);
400 void init(CephContext
*cct
, char **envp
);
401 void set(std::string name
, std::string val
);
402 const char *get(const char *name
, const char *def_val
= nullptr) const;
403 int get_int(const char *name
, int def_val
= 0) const;
404 bool get_bool(const char *name
, bool def_val
= 0);
405 size_t get_size(const char *name
, size_t def_val
= 0) const;
406 bool exists(const char *name
) const;
407 bool exists_prefix(const char *prefix
) const;
408 void remove(const char *name
);
409 const std::map
<string
, string
, ltstr_nocase
>& get_map() const { return env_map
; }
410 int get_enable_ops_log() const {
411 return conf
.enable_ops_log
;
414 int get_enable_usage_log() const {
415 return conf
.enable_usage_log
;
418 int get_defer_to_bucket_acls() const {
419 return conf
.defer_to_bucket_acls
;
423 // return true if the connection is secure. this either means that the
424 // connection arrived via ssl, or was forwarded as https by a trusted proxy
425 bool rgw_transport_is_secure(CephContext
*cct
, const RGWEnv
& env
);
444 RGW_OP_GET_BUCKET_LOGGING
,
445 RGW_OP_GET_BUCKET_LOCATION
,
446 RGW_OP_GET_BUCKET_VERSIONING
,
447 RGW_OP_SET_BUCKET_VERSIONING
,
448 RGW_OP_GET_BUCKET_WEBSITE
,
449 RGW_OP_SET_BUCKET_WEBSITE
,
451 RGW_OP_CREATE_BUCKET
,
452 RGW_OP_DELETE_BUCKET
,
456 RGW_OP_PUT_METADATA_ACCOUNT
,
457 RGW_OP_PUT_METADATA_BUCKET
,
458 RGW_OP_PUT_METADATA_OBJECT
,
468 RGW_OP_GET_REQUEST_PAYMENT
,
469 RGW_OP_SET_REQUEST_PAYMENT
,
470 RGW_OP_INIT_MULTIPART
,
471 RGW_OP_COMPLETE_MULTIPART
,
472 RGW_OP_ABORT_MULTIPART
,
473 RGW_OP_LIST_MULTIPART
,
474 RGW_OP_LIST_BUCKET_MULTIPARTS
,
475 RGW_OP_DELETE_MULTI_OBJ
,
478 RGW_OP_GET_CROSS_DOMAIN_POLICY
,
479 RGW_OP_GET_HEALTH_CHECK
,
486 RGW_OP_PUT_ROLE_POLICY
,
487 RGW_OP_GET_ROLE_POLICY
,
488 RGW_OP_LIST_ROLE_POLICIES
,
489 RGW_OP_DELETE_ROLE_POLICY
,
490 RGW_OP_PUT_BUCKET_POLICY
,
491 RGW_OP_GET_BUCKET_POLICY
,
492 RGW_OP_DELETE_BUCKET_POLICY
,
493 RGW_OP_PUT_OBJ_TAGGING
,
494 RGW_OP_GET_OBJ_TAGGING
,
495 RGW_OP_DELETE_OBJ_TAGGING
,
499 RGW_OP_PUT_USER_POLICY
,
500 RGW_OP_GET_USER_POLICY
,
501 RGW_OP_LIST_USER_POLICIES
,
502 RGW_OP_DELETE_USER_POLICY
,
503 RGW_OP_PUT_BUCKET_OBJ_LOCK
,
504 RGW_OP_GET_BUCKET_OBJ_LOCK
,
505 RGW_OP_PUT_OBJ_RETENTION
,
506 RGW_OP_GET_OBJ_RETENTION
,
507 RGW_OP_PUT_OBJ_LEGAL_HOLD
,
508 RGW_OP_GET_OBJ_LEGAL_HOLD
,
510 RGW_OP_ADMIN_SET_METADATA
,
511 RGW_OP_GET_OBJ_LAYOUT
,
513 RGW_OP_METADATA_SEARCH
,
514 RGW_OP_CONFIG_BUCKET_META_SEARCH
,
515 RGW_OP_GET_BUCKET_META_SEARCH
,
516 RGW_OP_DEL_BUCKET_META_SEARCH
,
519 RGW_STS_GET_SESSION_TOKEN
,
520 RGW_STS_ASSUME_ROLE_WEB_IDENTITY
,
522 RGW_OP_PUBSUB_TOPIC_CREATE
,
523 RGW_OP_PUBSUB_TOPICS_LIST
,
524 RGW_OP_PUBSUB_TOPIC_GET
,
525 RGW_OP_PUBSUB_TOPIC_DELETE
,
526 RGW_OP_PUBSUB_SUB_CREATE
,
527 RGW_OP_PUBSUB_SUB_GET
,
528 RGW_OP_PUBSUB_SUB_DELETE
,
529 RGW_OP_PUBSUB_SUB_PULL
,
530 RGW_OP_PUBSUB_SUB_ACK
,
531 RGW_OP_PUBSUB_NOTIF_CREATE
,
532 RGW_OP_PUBSUB_NOTIF_DELETE
,
533 RGW_OP_PUBSUB_NOTIF_LIST
,
534 RGW_OP_GET_BUCKET_TAGGING
,
535 RGW_OP_PUT_BUCKET_TAGGING
,
536 RGW_OP_DELETE_BUCKET_TAGGING
,
537 RGW_OP_GET_BUCKET_REPLICATION
,
538 RGW_OP_PUT_BUCKET_REPLICATION
,
539 RGW_OP_DELETE_BUCKET_REPLICATION
,
542 RGW_OP_GET_BUCKET_POLICY_STATUS
,
543 RGW_OP_PUT_BUCKET_PUBLIC_ACCESS_BLOCK
,
544 RGW_OP_GET_BUCKET_PUBLIC_ACCESS_BLOCK
,
545 RGW_OP_DELETE_BUCKET_PUBLIC_ACCESS_BLOCK
,
548 class RGWAccessControlPolicy
;
551 struct RGWAccessKey
{
552 string id
; // AccessKey
553 string key
; // SecretKey
557 RGWAccessKey(std::string _id
, std::string _key
)
558 : id(std::move(_id
)), key(std::move(_key
)) {}
560 void encode(bufferlist
& bl
) const {
561 ENCODE_START(2, 2, bl
);
568 void decode(bufferlist::const_iterator
& bl
) {
569 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
575 void dump(Formatter
*f
) const;
576 void dump_plain(Formatter
*f
) const;
577 void dump(Formatter
*f
, const string
& user
, bool swift
) const;
578 static void generate_test_instances(list
<RGWAccessKey
*>& o
);
580 void decode_json(JSONObj
*obj
);
581 void decode_json(JSONObj
*obj
, bool swift
);
583 WRITE_CLASS_ENCODER(RGWAccessKey
)
589 RGWSubUser() : perm_mask(0) {}
590 void encode(bufferlist
& bl
) const {
591 ENCODE_START(2, 2, bl
);
593 encode(perm_mask
, bl
);
597 void decode(bufferlist::const_iterator
& bl
) {
598 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
600 decode(perm_mask
, bl
);
603 void dump(Formatter
*f
) const;
604 void dump(Formatter
*f
, const string
& user
) const;
605 static void generate_test_instances(list
<RGWSubUser
*>& o
);
607 void decode_json(JSONObj
*obj
);
609 WRITE_CLASS_ENCODER(RGWSubUser
)
613 map
<string
, uint32_t> caps
;
615 int get_cap(const string
& cap
, string
& type
, uint32_t *perm
);
616 int add_cap(const string
& cap
);
617 int remove_cap(const string
& cap
);
619 static int parse_cap_perm(const string
& str
, uint32_t *perm
);
620 int add_from_string(const string
& str
);
621 int remove_from_string(const string
& str
);
623 void encode(bufferlist
& bl
) const {
624 ENCODE_START(1, 1, bl
);
628 void decode(bufferlist::const_iterator
& bl
) {
633 int check_cap(const string
& cap
, uint32_t perm
) const;
634 bool is_valid_cap_type(const string
& tp
);
635 void dump(Formatter
*f
) const;
636 void dump(Formatter
*f
, const char *name
) const;
638 void decode_json(JSONObj
*obj
);
640 WRITE_CLASS_ENCODER(RGWUserCaps
)
642 void encode_json(const char *name
, const obj_version
& v
, Formatter
*f
);
643 void encode_json(const char *name
, const RGWUserCaps
& val
, Formatter
*f
);
645 void decode_json_obj(obj_version
& v
, JSONObj
*obj
);
659 static string RGW_STORAGE_CLASS_STANDARD
= "STANDARD";
661 struct rgw_placement_rule
{
663 std::string storage_class
;
665 rgw_placement_rule() {}
666 rgw_placement_rule(const string
& _n
, const string
& _sc
) : name(_n
), storage_class(_sc
) {}
667 rgw_placement_rule(const rgw_placement_rule
& _r
, const string
& _sc
) : name(_r
.name
) {
671 storage_class
= _r
.storage_class
;
676 return name
.empty() && storage_class
.empty();
679 void inherit_from(const rgw_placement_rule
& r
) {
683 if (storage_class
.empty()) {
684 storage_class
= r
.storage_class
;
690 storage_class
.clear();
693 void init(const string
& n
, const string
& c
) {
698 static const string
& get_canonical_storage_class(const string
& storage_class
) {
699 if (storage_class
.empty()) {
700 return RGW_STORAGE_CLASS_STANDARD
;
702 return storage_class
;
705 const string
& get_storage_class() const {
706 return get_canonical_storage_class(storage_class
);
709 int compare(const rgw_placement_rule
& r
) const {
710 int c
= name
.compare(r
.name
);
714 return get_storage_class().compare(r
.get_storage_class());
717 bool operator==(const rgw_placement_rule
& r
) const {
718 return (name
== r
.name
&&
719 get_storage_class() == r
.get_storage_class());
722 bool operator!=(const rgw_placement_rule
& r
) const {
723 return !(*this == r
);
726 void encode(bufferlist
& bl
) const {
727 /* no ENCODE_START/END due to backward compatibility */
728 std::string s
= to_str();
732 void decode(bufferlist::const_iterator
& bl
) {
738 std::string
to_str() const {
739 if (standard_storage_class()) {
742 return to_str_explicit();
745 std::string
to_str_explicit() const {
746 return name
+ "/" + storage_class
;
749 void from_str(const std::string
& s
) {
750 size_t pos
= s
.find("/");
751 if (pos
== std::string::npos
) {
753 storage_class
.clear();
756 name
= s
.substr(0, pos
);
757 storage_class
= s
.substr(pos
+ 1);
760 bool standard_storage_class() const {
761 return storage_class
.empty() || storage_class
== RGW_STORAGE_CLASS_STANDARD
;
764 WRITE_CLASS_ENCODER(rgw_placement_rule
)
766 void encode_json(const char *name
, const rgw_placement_rule
& val
, ceph::Formatter
*f
);
767 void decode_json_obj(rgw_placement_rule
& v
, JSONObj
*obj
);
769 inline ostream
& operator<<(ostream
& out
, const rgw_placement_rule
& rule
) {
770 return out
<< rule
.to_str();
777 map
<string
, RGWAccessKey
> access_keys
;
778 map
<string
, RGWAccessKey
> swift_keys
;
779 map
<string
, RGWSubUser
> subusers
;
786 rgw_placement_rule default_placement
;
787 list
<string
> placement_tags
;
788 RGWQuotaInfo bucket_quota
;
789 map
<int, string
> temp_url_keys
;
790 RGWQuotaInfo user_quota
;
793 string assumed_role_arn
;
797 max_buckets(RGW_DEFAULT_MAX_BUCKETS
),
798 op_mask(RGW_OP_TYPE_ALL
),
804 RGWAccessKey
* get_key(const string
& access_key
) {
805 if (access_keys
.empty())
808 auto k
= access_keys
.find(access_key
);
809 if (k
== access_keys
.end())
815 void encode(bufferlist
& bl
) const {
816 ENCODE_START(21, 9, bl
);
817 encode((uint64_t)0, bl
); // old auid
820 if (!access_keys
.empty()) {
821 map
<string
, RGWAccessKey
>::const_iterator iter
= access_keys
.begin();
822 const RGWAccessKey
& k
= iter
->second
;
826 encode(access_key
, bl
);
827 encode(secret_key
, bl
);
828 encode(display_name
, bl
);
829 encode(user_email
, bl
);
832 if (!swift_keys
.empty()) {
833 map
<string
, RGWAccessKey
>::const_iterator iter
= swift_keys
.begin();
834 const RGWAccessKey
& k
= iter
->second
;
838 encode(swift_name
, bl
);
839 encode(swift_key
, bl
);
840 encode(user_id
.id
, bl
);
841 encode(access_keys
, bl
);
842 encode(subusers
, bl
);
843 encode(suspended
, bl
);
844 encode(swift_keys
, bl
);
845 encode(max_buckets
, bl
);
849 encode(default_placement
, bl
);
850 encode(placement_tags
, bl
);
851 encode(bucket_quota
, bl
);
852 encode(temp_url_keys
, bl
);
853 encode(user_quota
, bl
);
854 encode(user_id
.tenant
, bl
);
858 encode(assumed_role_arn
, bl
);
861 void decode(bufferlist::const_iterator
& bl
) {
862 DECODE_START_LEGACY_COMPAT_LEN_32(21, 9, 9, bl
);
865 decode(old_auid
, bl
);
869 decode(access_key
, bl
);
870 decode(secret_key
, bl
);
875 access_keys
[access_key
] = k
;
877 decode(display_name
, bl
);
878 decode(user_email
, bl
);
879 /* We populate swift_keys map later nowadays, but we have to decode. */
882 if (struct_v
>= 3) decode(swift_name
, bl
);
883 if (struct_v
>= 4) decode(swift_key
, bl
);
885 decode(user_id
.id
, bl
);
887 user_id
.id
= access_key
;
889 decode(access_keys
, bl
);
890 decode(subusers
, bl
);
894 decode(suspended
, bl
);
897 decode(swift_keys
, bl
);
899 if (struct_v
>= 10) {
900 decode(max_buckets
, bl
);
902 max_buckets
= RGW_DEFAULT_MAX_BUCKETS
;
904 if (struct_v
>= 11) {
907 if (struct_v
>= 12) {
910 op_mask
= RGW_OP_TYPE_ALL
;
912 if (struct_v
>= 13) {
914 decode(default_placement
, bl
);
915 decode(placement_tags
, bl
); /* tags of allowed placement rules */
917 if (struct_v
>= 14) {
918 decode(bucket_quota
, bl
);
920 if (struct_v
>= 15) {
921 decode(temp_url_keys
, bl
);
923 if (struct_v
>= 16) {
924 decode(user_quota
, bl
);
926 if (struct_v
>= 17) {
927 decode(user_id
.tenant
, bl
);
929 user_id
.tenant
.clear();
931 if (struct_v
>= 18) {
934 if (struct_v
>= 19) {
937 if (struct_v
>= 20) {
940 if (struct_v
>= 21) {
941 decode(assumed_role_arn
, bl
);
945 void dump(Formatter
*f
) const;
946 static void generate_test_instances(list
<RGWUserInfo
*>& o
);
948 void decode_json(JSONObj
*obj
);
950 WRITE_CLASS_ENCODER(RGWUserInfo
)
958 rgw_raw_obj(const rgw_pool
& _pool
, const std::string
& _oid
) {
961 rgw_raw_obj(const rgw_pool
& _pool
, const std::string
& _oid
, const string
& _loc
) : loc(_loc
) {
965 void init(const rgw_pool
& _pool
, const std::string
& _oid
) {
974 void encode(bufferlist
& bl
) const {
975 ENCODE_START(6, 6, bl
);
982 void decode_from_rgw_obj(bufferlist::const_iterator
& bl
);
984 void decode(bufferlist::const_iterator
& bl
) {
985 unsigned ofs
= bl
.get_off();
989 * this object was encoded as rgw_obj, prior to rgw_raw_obj been split out of it,
990 * let's decode it as rgw_obj and convert it
993 decode_from_rgw_obj(bl
);
1002 bool operator<(const rgw_raw_obj
& o
) const {
1003 int r
= pool
.compare(o
.pool
);
1005 r
= oid
.compare(o
.oid
);
1007 r
= loc
.compare(o
.loc
);
1013 bool operator==(const rgw_raw_obj
& o
) const {
1014 return (pool
== o
.pool
&& oid
== o
.oid
&& loc
== o
.loc
);
1017 void dump(Formatter
*f
) const;
1018 void decode_json(JSONObj
*obj
);
1020 WRITE_CLASS_ENCODER(rgw_raw_obj
)
1022 inline ostream
& operator<<(ostream
& out
, const rgw_raw_obj
& o
) {
1023 out
<< o
.pool
<< ":" << o
.oid
;
1027 struct rgw_bucket_placement
{
1028 rgw_placement_rule placement_rule
;
1031 void dump(Formatter
*f
) const;
1034 struct RGWObjVersionTracker
{
1035 obj_version read_version
;
1036 obj_version write_version
;
1038 obj_version
*version_for_read() {
1039 return &read_version
;
1042 obj_version
*version_for_write() {
1043 if (write_version
.ver
== 0)
1046 return &write_version
;
1049 obj_version
*version_for_check() {
1050 if (read_version
.ver
== 0)
1053 return &read_version
;
1056 void prepare_op_for_read(librados::ObjectReadOperation
*op
);
1057 void prepare_op_for_write(librados::ObjectWriteOperation
*op
);
1059 void apply_write() {
1060 read_version
= write_version
;
1061 write_version
= obj_version();
1065 read_version
= obj_version();
1066 write_version
= obj_version();
1069 void generate_new_write_ver(CephContext
*cct
);
1072 inline ostream
& operator<<(ostream
& out
, const obj_version
&v
)
1074 out
<< v
.tag
<< ":" << v
.ver
;
1078 inline ostream
& operator<<(ostream
& out
, const RGWObjVersionTracker
&ot
)
1080 out
<< "{r=" << ot
.read_version
<< ",w=" << ot
.write_version
<< "}";
1084 enum RGWBucketFlags
{
1085 BUCKET_SUSPENDED
= 0x1,
1086 BUCKET_VERSIONED
= 0x2,
1087 BUCKET_VERSIONS_SUSPENDED
= 0x4,
1088 BUCKET_DATASYNC_DISABLED
= 0X8,
1089 BUCKET_MFA_ENABLED
= 0X10,
1090 BUCKET_OBJ_LOCK_ENABLED
= 0X20,
1093 enum RGWBucketIndexType
{
1094 RGWBIType_Normal
= 0,
1095 RGWBIType_Indexless
= 1,
1098 inline ostream
& operator<<(ostream
& out
, const RGWBucketIndexType
&index_type
)
1100 switch (index_type
) {
1101 case RGWBIType_Normal
:
1102 return out
<< "Normal";
1103 case RGWBIType_Indexless
:
1104 return out
<< "Indexless";
1106 return out
<< "Unknown";
1112 struct RGWBucketInfo
{
1113 enum BIShardsHashType
{
1121 ceph::real_time creation_time
;
1122 rgw_placement_rule placement_rule
;
1123 bool has_instance_obj
{false};
1124 RGWObjVersionTracker objv_tracker
; /* we don't need to serialize this, for runtime tracking */
1127 // Represents the number of bucket index object shards:
1128 // - value of 0 indicates there is no sharding (this is by default
1129 // before this feature is implemented).
1130 // - value of UINT32_T::MAX indicates this is a blind bucket.
1131 uint32_t num_shards
{0};
1133 // Represents the bucket index shard hash type.
1134 uint8_t bucket_index_shard_hash_type
{MOD
};
1136 // Represents the shard number for blind bucket.
1137 const static uint32_t NUM_SHARDS_BLIND_BUCKET
;
1139 bool requester_pays
{false};
1141 bool has_website
{false};
1142 RGWBucketWebsiteConf website_conf
;
1144 RGWBucketIndexType index_type
= RGWBIType_Normal
;
1146 bool swift_versioning
{false};
1147 string swift_ver_location
;
1149 map
<string
, uint32_t> mdsearch_config
;
1152 cls_rgw_reshard_status reshard_status
{cls_rgw_reshard_status::NOT_RESHARDING
};
1153 string new_bucket_instance_id
;
1155 RGWObjectLock obj_lock
;
1157 std::optional
<rgw_sync_policy_info
> sync_policy
;
1159 void encode(bufferlist
& bl
) const;
1160 void decode(bufferlist::const_iterator
& bl
);
1162 void dump(Formatter
*f
) const;
1163 static void generate_test_instances(list
<RGWBucketInfo
*>& o
);
1165 void decode_json(JSONObj
*obj
);
1167 bool versioned() const { return (flags
& BUCKET_VERSIONED
) != 0; }
1168 int versioning_status() const { return flags
& (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
| BUCKET_MFA_ENABLED
); }
1169 bool versioning_enabled() const { return (versioning_status() & (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
)) == BUCKET_VERSIONED
; }
1170 bool mfa_enabled() const { return (versioning_status() & BUCKET_MFA_ENABLED
) != 0; }
1171 bool datasync_flag_enabled() const { return (flags
& BUCKET_DATASYNC_DISABLED
) == 0; }
1172 bool obj_lock_enabled() const { return (flags
& BUCKET_OBJ_LOCK_ENABLED
) != 0; }
1174 bool has_swift_versioning() const {
1175 /* A bucket may be versioned through one mechanism only. */
1176 return swift_versioning
&& !versioned();
1179 void set_sync_policy(rgw_sync_policy_info
&& policy
);
1181 bool empty_sync_policy() const;
1186 WRITE_CLASS_ENCODER(RGWBucketInfo
)
1188 struct RGWBucketEntryPoint
1192 ceph::real_time creation_time
;
1195 bool has_bucket_info
;
1196 RGWBucketInfo old_bucket_info
;
1198 RGWBucketEntryPoint() : linked(false), has_bucket_info(false) {}
1200 void encode(bufferlist
& bl
) const {
1201 ENCODE_START(10, 8, bl
);
1203 encode(owner
.id
, bl
);
1205 uint64_t ctime
= (uint64_t)real_clock::to_time_t(creation_time
);
1208 encode(creation_time
, bl
);
1211 void decode(bufferlist::const_iterator
& bl
) {
1212 auto orig_iter
= bl
;
1213 DECODE_START_LEGACY_COMPAT_LEN_32(10, 4, 4, bl
);
1215 /* ouch, old entry, contains the bucket info itself */
1216 old_bucket_info
.decode(orig_iter
);
1217 has_bucket_info
= true;
1220 has_bucket_info
= false;
1222 decode(owner
.id
, bl
);
1226 if (struct_v
< 10) {
1227 creation_time
= real_clock::from_time_t((time_t)ctime
);
1229 if (struct_v
>= 9) {
1232 if (struct_v
>= 10) {
1233 decode(creation_time
, bl
);
1238 void dump(Formatter
*f
) const;
1239 void decode_json(JSONObj
*obj
);
1240 static void generate_test_instances(list
<RGWBucketEntryPoint
*>& o
);
1242 WRITE_CLASS_ENCODER(RGWBucketEntryPoint
)
1244 struct RGWStorageStats
1246 RGWObjCategory category
;
1248 uint64_t size_rounded
;
1249 uint64_t size_utilized
{0}; //< size after compression, encryption
1250 uint64_t num_objects
;
1253 : category(RGWObjCategory::None
),
1258 void dump(Formatter
*f
) const;
1263 /* Namespaced forward declarations. */
1267 class AWSBrowserUploadAbstractor
;
1277 using meta_map_t
= boost::container::flat_map
<std::string
, std::string
>;
1282 meta_map_t x_meta_map
;
1288 string request_uri_aws4
;
1289 string effective_uri
;
1290 string request_params
;
1292 string storage_class
;
1294 req_info(CephContext
*cct
, const RGWEnv
*env
);
1295 void rebuild_from(req_info
& src
);
1296 void init_meta_info(bool *found_bad_meta
);
1299 typedef cls_rgw_obj_key rgw_obj_index_key
;
1301 struct rgw_obj_key
{
1307 // cppcheck-suppress noExplicitConstructor
1308 rgw_obj_key(const string
& n
) : name(n
) {}
1309 rgw_obj_key(const string
& n
, const string
& i
) : name(n
), instance(i
) {}
1310 rgw_obj_key(const string
& n
, const string
& i
, const string
& _ns
) : name(n
), instance(i
), ns(_ns
) {}
1312 rgw_obj_key(const rgw_obj_index_key
& k
) {
1313 parse_index_key(k
.name
, &name
, &ns
);
1314 instance
= k
.instance
;
1317 static void parse_index_key(const string
& key
, string
*name
, string
*ns
) {
1318 if (key
[0] != '_') {
1323 if (key
[1] == '_') {
1324 *name
= key
.substr(1);
1328 ssize_t pos
= key
.find('_', 1);
1330 /* shouldn't happen, just use key */
1336 *name
= key
.substr(pos
+ 1);
1337 *ns
= key
.substr(1, pos
-1);
1340 void set(const string
& n
) {
1346 void set(const string
& n
, const string
& i
) {
1352 void set(const string
& n
, const string
& i
, const string
& _ns
) {
1358 bool set(const rgw_obj_index_key
& index_key
) {
1359 if (!parse_raw_oid(index_key
.name
, this)) {
1362 instance
= index_key
.instance
;
1366 void set_instance(const string
& i
) {
1370 const string
& get_instance() const {
1374 void set_ns(const std::string
& _ns
) {
1378 const std::string
& get_ns() const {
1382 string
get_index_key_name() const {
1384 if (name
.size() < 1 || name
[0] != '_') {
1387 return string("_") + name
;
1390 char buf
[ns
.size() + 16];
1391 snprintf(buf
, sizeof(buf
), "_%s_", ns
.c_str());
1392 return string(buf
) + name
;
1395 void get_index_key(rgw_obj_index_key
*key
) const {
1396 key
->name
= get_index_key_name();
1397 key
->instance
= instance
;
1400 string
get_loc() const {
1402 * For backward compatibility. Older versions used to have object locator on all objects,
1403 * however, the name was the effective object locator. This had the same effect as not
1404 * having object locator at all for most objects but the ones that started with underscore as
1405 * these were escaped.
1407 if (name
[0] == '_' && ns
.empty()) {
1414 bool empty() const {
1415 return name
.empty();
1418 bool have_null_instance() const {
1419 return instance
== "null";
1422 bool have_instance() const {
1423 return !instance
.empty();
1426 bool need_to_encode_instance() const {
1427 return have_instance() && !have_null_instance();
1430 string
get_oid() const {
1431 if (ns
.empty() && !need_to_encode_instance()) {
1432 if (name
.size() < 1 || name
[0] != '_') {
1435 return string("_") + name
;
1440 if (need_to_encode_instance()) {
1441 oid
.append(string(":") + instance
);
1448 bool operator==(const rgw_obj_key
& k
) const {
1449 return (name
.compare(k
.name
) == 0) &&
1450 (instance
.compare(k
.instance
) == 0);
1453 bool operator<(const rgw_obj_key
& k
) const {
1454 int r
= name
.compare(k
.name
);
1456 r
= instance
.compare(k
.instance
);
1461 bool operator<=(const rgw_obj_key
& k
) const {
1462 return !(k
< *this);
1465 static void parse_ns_field(string
& ns
, string
& instance
) {
1466 int pos
= ns
.find(':');
1468 instance
= ns
.substr(pos
+ 1);
1469 ns
= ns
.substr(0, pos
);
1475 // takes an oid and parses out the namespace (ns), name, and
1477 static bool parse_raw_oid(const string
& oid
, rgw_obj_key
*key
) {
1478 key
->instance
.clear();
1480 if (oid
[0] != '_') {
1485 if (oid
.size() >= 2 && oid
[1] == '_') {
1486 key
->name
= oid
.substr(1);
1490 if (oid
.size() < 3) // for namespace, min size would be 3: _x_
1493 size_t pos
= oid
.find('_', 2); // oid must match ^_[^_].+$
1494 if (pos
== string::npos
)
1497 key
->ns
= oid
.substr(1, pos
- 1);
1498 parse_ns_field(key
->ns
, key
->instance
);
1500 key
->name
= oid
.substr(pos
+ 1);
1505 * Translate a namespace-mangled object name to the user-facing name
1506 * existing in the given namespace.
1508 * If the object is part of the given namespace, it returns true
1509 * and cuts down the name to the unmangled version. If it is not
1510 * part of the given namespace, it returns false.
1512 static bool oid_to_key_in_ns(const string
& oid
, rgw_obj_key
*key
, const string
& ns
) {
1513 bool ret
= parse_raw_oid(oid
, key
);
1518 return (ns
== key
->ns
);
1522 * Given a mangled object name and an empty namespace string, this
1523 * function extracts the namespace into the string and sets the object
1524 * name to be the unmangled version.
1526 * It returns true after successfully doing so, or
1527 * false if it fails.
1529 static bool strip_namespace_from_name(string
& name
, string
& ns
, string
& instance
) {
1532 if (name
[0] != '_') {
1536 size_t pos
= name
.find('_', 1);
1537 if (pos
== string::npos
) {
1541 if (name
[1] == '_') {
1542 name
= name
.substr(1);
1546 size_t period_pos
= name
.find('.');
1547 if (period_pos
< pos
) {
1551 ns
= name
.substr(1, pos
-1);
1552 name
= name
.substr(pos
+1, string::npos
);
1554 parse_ns_field(ns
, instance
);
1558 void encode(bufferlist
& bl
) const {
1559 ENCODE_START(2, 1, bl
);
1561 encode(instance
, bl
);
1565 void decode(bufferlist::const_iterator
& bl
) {
1566 DECODE_START(2, bl
);
1568 decode(instance
, bl
);
1569 if (struct_v
>= 2) {
1574 void dump(Formatter
*f
) const;
1575 void decode_json(JSONObj
*obj
);
1577 string
to_str() const {
1578 if (instance
.empty()) {
1581 char buf
[name
.size() + instance
.size() + 16];
1582 snprintf(buf
, sizeof(buf
), "%s[%s]", name
.c_str(), instance
.c_str());
1586 WRITE_CLASS_ENCODER(rgw_obj_key
)
1588 inline ostream
& operator<<(ostream
& out
, const rgw_obj_key
&o
) {
1589 return out
<< o
.to_str();
1592 inline ostream
& operator<<(ostream
& out
, const rgw_obj_index_key
&o
) {
1593 if (o
.instance
.empty()) {
1594 return out
<< o
.name
;
1596 return out
<< o
.name
<< "[" << o
.instance
<< "]";
1600 struct req_init_state
{
1601 /* Keeps [[tenant]:]bucket until we parse the token. */
1606 #include "rgw_auth.h"
1609 class RGWSysObjectCtx
;
1611 /** Store all the state necessary to complete and respond to an HTTP request*/
1612 struct req_state
: DoutPrefixProvider
{
1614 rgw::io::BasicClient
*cio
{nullptr};
1615 http_op op
{OP_UNKNOWN
};
1616 RGWOpType op_type
{};
1617 bool content_started
{false};
1619 ceph::Formatter
*formatter
{nullptr};
1621 string relative_uri
;
1622 const char *length
{nullptr};
1623 int64_t content_length
{0};
1624 map
<string
, string
> generic_attrs
;
1626 bool expect_cont
{false};
1627 uint64_t obj_size
{0};
1628 bool enable_ops_log
;
1629 bool enable_usage_log
;
1630 uint8_t defer_to_bucket_acls
;
1631 uint32_t perm_mask
{0};
1633 /* Set once when url_bucket is parsed and not violated thereafter. */
1634 string account_name
;
1636 string bucket_tenant
;
1641 string src_tenant_name
;
1642 string src_bucket_name
;
1643 rgw_obj_key src_object
;
1644 ACLOwner bucket_owner
;
1647 string zonegroup_name
;
1648 string zonegroup_endpoint
;
1649 string bucket_instance_id
;
1650 int bucket_instance_shard_id
{-1};
1651 string redirect_zone_endpoint
;
1655 RGWBucketInfo bucket_info
;
1656 obj_version bucket_ep_objv
;
1657 real_time bucket_mtime
;
1658 std::map
<std::string
, ceph::bufferlist
> bucket_attrs
;
1659 bool bucket_exists
{false};
1660 rgw_placement_rule dest_placement
;
1662 bool has_bad_meta
{false};
1664 rgw::sal::RGWUser
*user
;
1667 /* TODO(rzarzynski): switch out to the static_ptr for both members. */
1669 /* Object having the knowledge about an authenticated identity and allowing
1670 * to apply it during the authorization phase (verify_permission() methods
1671 * of a given RGWOp). Thus, it bounds authentication and authorization steps
1672 * through a well-defined interface. For more details, see rgw_auth.h. */
1673 std::unique_ptr
<rgw::auth::Identity
> identity
;
1675 std::shared_ptr
<rgw::auth::Completer
> completer
;
1677 /* A container for credentials of the S3's browser upload. It's necessary
1678 * because: 1) the ::authenticate() method of auth engines and strategies
1679 * take req_state only; 2) auth strategies live much longer than RGWOps -
1680 * there is no way to pass additional data dependencies through ctors. */
1683 friend class RGWPostObj_ObjStore_S3
;
1685 friend class rgw::auth::s3::AWSBrowserUploadAbstractor
;
1686 friend class rgw::auth::s3::STSEngine
;
1688 std::string access_key
;
1689 std::string signature
;
1690 std::string x_amz_algorithm
;
1691 std::string x_amz_credential
;
1692 std::string x_amz_date
;
1693 std::string x_amz_security_token
;
1694 ceph::bufferlist encoded_policy
;
1698 std::unique_ptr
<RGWAccessControlPolicy
> user_acl
;
1699 std::unique_ptr
<RGWAccessControlPolicy
> bucket_acl
;
1700 std::unique_ptr
<RGWAccessControlPolicy
> object_acl
;
1702 rgw::IAM::Environment env
;
1703 boost::optional
<rgw::IAM::Policy
> iam_policy
;
1704 boost::optional
<PublicAccessBlockConfiguration
> bucket_access_conf
;
1705 vector
<rgw::IAM::Policy
> iam_user_policies
;
1707 /* Is the request made by an user marked as a system one?
1708 * Being system user means we also have the admin status. */
1709 bool system_request
{false};
1712 bool has_acl_header
{false};
1713 bool local_source
{false}; /* source is local */
1717 /* Content-Disposition override for TempURL of Swift API. */
1726 req_init_state init_state
;
1728 using Clock
= ceph::coarse_real_clock
;
1729 Clock::time_point time
;
1731 Clock::duration
time_elapsed() const { return Clock::now() - time
; }
1733 RGWObjectCtx
*obj_ctx
{nullptr};
1734 RGWSysObjectCtx
*sysobj_ctx
{nullptr};
1742 bool mfa_verified
{false};
1744 /// optional coroutine context
1745 optional_yield yield
{null_yield
};
1747 req_state(CephContext
* _cct
, RGWEnv
* e
, rgw::sal::RGWUser
* u
, uint64_t id
);
1750 bool is_err() const { return err
.is_err(); }
1752 // implements DoutPrefixProvider
1753 std::ostream
& gen_prefix(std::ostream
& out
) const override
;
1754 CephContext
* get_cct() const override
{ return cct
; }
1755 unsigned get_subsys() const override
{ return ceph_subsys_rgw
; }
1758 void set_req_state_err(struct req_state
*, int);
1759 void set_req_state_err(struct req_state
*, int, const string
&);
1760 void set_req_state_err(struct rgw_err
&, int, const int);
1761 void dump(struct req_state
*);
1763 /** Store basic data on bucket */
1764 struct RGWBucketEnt
{
1767 size_t size_rounded
;
1768 ceph::real_time creation_time
;
1771 /* The placement_rule is necessary to calculate per-storage-policy statics
1772 * of the Swift API. Although the info available in RGWBucketInfo, we need
1773 * to duplicate it here to not affect the performance of buckets listing. */
1774 rgw_placement_rule placement_rule
;
1781 RGWBucketEnt(const RGWBucketEnt
&) = default;
1782 RGWBucketEnt(RGWBucketEnt
&&) = default;
1783 explicit RGWBucketEnt(const rgw_user
& u
, cls_user_bucket_entry
&& e
)
1784 : bucket(u
, std::move(e
.bucket
)),
1786 size_rounded(e
.size_rounded
),
1787 creation_time(e
.creation_time
),
1791 RGWBucketEnt
& operator=(const RGWBucketEnt
&) = default;
1793 void convert(cls_user_bucket_entry
*b
) const {
1794 bucket
.convert(&b
->bucket
);
1796 b
->size_rounded
= size_rounded
;
1797 b
->creation_time
= creation_time
;
1801 void encode(bufferlist
& bl
) const {
1802 ENCODE_START(7, 5, bl
);
1804 __u32 mt
= ceph::real_clock::to_time_t(creation_time
);
1805 string empty_str
; // originally had the bucket name here, but we encode bucket later
1806 encode(empty_str
, bl
);
1813 encode(creation_time
, bl
);
1814 encode(placement_rule
, bl
);
1817 void decode(bufferlist::const_iterator
& bl
) {
1818 DECODE_START_LEGACY_COMPAT_LEN(7, 5, 5, bl
);
1821 string empty_str
; // backward compatibility
1822 decode(empty_str
, bl
);
1827 creation_time
= ceph::real_clock::from_time_t(mt
);
1837 decode(creation_time
, bl
);
1839 decode(placement_rule
, bl
);
1842 void dump(Formatter
*f
) const;
1843 static void generate_test_instances(list
<RGWBucketEnt
*>& o
);
1845 WRITE_CLASS_ENCODER(RGWBucketEnt
)
1851 bool in_extra_data
{false}; /* in-memory only member, does not serialize */
1853 // Represents the hash index source for this object once it is set (non-empty)
1854 std::string index_hash_source
;
1857 rgw_obj(const rgw_bucket
& b
, const std::string
& name
) : bucket(b
), key(name
) {}
1858 rgw_obj(const rgw_bucket
& b
, const rgw_obj_key
& k
) : bucket(b
), key(k
) {}
1859 rgw_obj(const rgw_bucket
& b
, const rgw_obj_index_key
& k
) : bucket(b
), key(k
) {}
1861 void init(const rgw_bucket
& b
, const std::string
& name
) {
1865 void init(const rgw_bucket
& b
, const std::string
& name
, const string
& i
, const string
& n
) {
1867 key
.set(name
, i
, n
);
1869 void init_ns(const rgw_bucket
& b
, const std::string
& name
, const string
& n
) {
1872 key
.instance
.clear();
1876 bool empty() const {
1880 void set_key(const rgw_obj_key
& k
) {
1884 string
get_oid() const {
1885 return key
.get_oid();
1888 const string
& get_hash_object() const {
1889 return index_hash_source
.empty() ? key
.name
: index_hash_source
;
1892 void set_in_extra_data(bool val
) {
1893 in_extra_data
= val
;
1896 bool is_in_extra_data() const {
1897 return in_extra_data
;
1900 void encode(bufferlist
& bl
) const {
1901 ENCODE_START(6, 6, bl
);
1904 encode(key
.name
, bl
);
1905 encode(key
.instance
, bl
);
1906 // encode(placement_id, bl);
1909 void decode(bufferlist::const_iterator
& bl
) {
1910 DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, bl
);
1913 decode(bucket
.name
, bl
); /* bucket.name */
1914 decode(s
, bl
); /* loc */
1916 decode(key
.name
, bl
);
1920 decode(key
.instance
, bl
);
1921 if (key
.ns
.empty() && key
.instance
.empty()) {
1922 if (key
.name
[0] == '_') {
1923 key
.name
= key
.name
.substr(1);
1926 if (struct_v
>= 5) {
1927 decode(key
.name
, bl
);
1929 ssize_t pos
= key
.name
.find('_', 1);
1931 throw buffer::error();
1933 key
.name
= key
.name
.substr(pos
+ 1);
1939 decode(key
.name
, bl
);
1940 decode(key
.instance
, bl
);
1941 // decode(placement_id, bl);
1945 void dump(Formatter
*f
) const;
1946 static void generate_test_instances(list
<rgw_obj
*>& o
);
1948 bool operator==(const rgw_obj
& o
) const {
1949 return (key
== o
.key
) &&
1950 (bucket
== o
.bucket
);
1952 bool operator<(const rgw_obj
& o
) const {
1953 int r
= key
.name
.compare(o
.key
.name
);
1955 r
= bucket
.bucket_id
.compare(o
.bucket
.bucket_id
); /* not comparing bucket.name, if bucket_id is equal so will be bucket.name */
1957 r
= key
.ns
.compare(o
.key
.ns
);
1959 r
= key
.instance
.compare(o
.key
.instance
);
1967 const rgw_pool
& get_explicit_data_pool() {
1968 if (!in_extra_data
|| bucket
.explicit_placement
.data_extra_pool
.empty()) {
1969 return bucket
.explicit_placement
.data_pool
;
1971 return bucket
.explicit_placement
.data_extra_pool
;
1974 WRITE_CLASS_ENCODER(rgw_obj
)
1976 struct rgw_cache_entry_info
{
1977 string cache_locator
;
1980 rgw_cache_entry_info() : gen(0) {}
1983 inline ostream
& operator<<(ostream
& out
, const rgw_obj
&o
) {
1984 return out
<< o
.bucket
.name
<< ":" << o
.get_oid();
1987 static inline void buf_to_hex(const unsigned char* const buf
,
1992 for (size_t i
= 0; i
< len
; i
++) {
1993 ::sprintf(&str
[i
*2], "%02x", static_cast<int>(buf
[i
]));
1997 template<size_t N
> static inline std::array
<char, N
* 2 + 1>
1998 buf_to_hex(const std::array
<unsigned char, N
>& buf
)
2000 static_assert(N
> 0, "The input array must be at least one element long");
2002 std::array
<char, N
* 2 + 1> hex_dest
;
2003 buf_to_hex(buf
.data(), N
, hex_dest
.data());
2007 static inline int hexdigit(char c
)
2009 if (c
>= '0' && c
<= '9')
2012 if (c
>= 'A' && c
<= 'F')
2013 return c
- 'A' + 0xa;
2017 static inline int hex_to_buf(const char *hex
, char *buf
, int len
)
2020 const char *p
= hex
;
2025 int d
= hexdigit(*p
);
2042 static inline int rgw_str_to_bool(const char *s
, int def_val
)
2047 return (strcasecmp(s
, "true") == 0 ||
2048 strcasecmp(s
, "on") == 0 ||
2049 strcasecmp(s
, "yes") == 0 ||
2050 strcasecmp(s
, "1") == 0);
2053 static inline void append_rand_alpha(CephContext
*cct
, const string
& src
, string
& dest
, int len
)
2057 gen_rand_alphanumeric(cct
, buf
, len
);
2062 static inline const char *rgw_obj_category_name(RGWObjCategory category
)
2065 case RGWObjCategory::None
:
2067 case RGWObjCategory::Main
:
2069 case RGWObjCategory::Shadow
:
2070 return "rgw.shadow";
2071 case RGWObjCategory::MultiMeta
:
2072 return "rgw.multimeta";
2078 static inline uint64_t rgw_rounded_kb(uint64_t bytes
)
2080 return (bytes
+ 1023) / 1024;
2083 static inline uint64_t rgw_rounded_objsize(uint64_t bytes
)
2085 return ((bytes
+ 4095) & ~4095);
2088 static inline uint64_t rgw_rounded_objsize_kb(uint64_t bytes
)
2090 return ((bytes
+ 4095) & ~4095) / 1024;
2093 /* implement combining step, S3 header canonicalization; k is a
2094 * valid header and in lc form */
2095 void rgw_add_amz_meta_header(
2096 meta_map_t
& x_meta_map
,
2097 const std::string
& k
,
2098 const std::string
& v
);
2100 extern string
rgw_string_unquote(const string
& s
);
2101 extern void parse_csv_string(const string
& ival
, vector
<string
>& ovals
);
2102 extern int parse_key_value(string
& in_str
, string
& key
, string
& val
);
2103 extern int parse_key_value(string
& in_str
, const char *delim
, string
& key
, string
& val
);
2105 extern boost::optional
<std::pair
<boost::string_view
, boost::string_view
>>
2106 parse_key_value(const boost::string_view
& in_str
,
2107 const boost::string_view
& delim
);
2108 extern boost::optional
<std::pair
<boost::string_view
, boost::string_view
>>
2109 parse_key_value(const boost::string_view
& in_str
);
2113 extern int parse_time(const char *time_str
, real_time
*time
);
2114 extern bool parse_rfc2616(const char *s
, struct tm
*t
);
2115 extern bool parse_iso8601(const char *s
, struct tm
*t
, uint32_t *pns
= NULL
, bool extended_format
= true);
2116 extern string
rgw_trim_whitespace(const string
& src
);
2117 extern boost::string_view
rgw_trim_whitespace(const boost::string_view
& src
);
2118 extern string
rgw_trim_quotes(const string
& val
);
2120 extern void rgw_to_iso8601(const real_time
& t
, char *dest
, int buf_size
);
2121 extern void rgw_to_iso8601(const real_time
& t
, string
*dest
);
2122 extern std::string
rgw_to_asctime(const utime_t
& t
);
2124 struct perm_state_base
{
2126 const rgw::IAM::Environment
& env
;
2127 rgw::auth::Identity
*identity
;
2128 const RGWBucketInfo
& bucket_info
;
2130 bool defer_to_bucket_acls
;
2131 boost::optional
<PublicAccessBlockConfiguration
> bucket_access_conf
;
2133 perm_state_base(CephContext
*_cct
,
2134 const rgw::IAM::Environment
& _env
,
2135 rgw::auth::Identity
*_identity
,
2136 const RGWBucketInfo
& _bucket_info
,
2138 bool _defer_to_bucket_acls
,
2139 boost::optional
<PublicAccessBlockConfiguration
> _bucket_acess_conf
= boost::none
) :
2142 identity(_identity
),
2143 bucket_info(_bucket_info
),
2144 perm_mask(_perm_mask
),
2145 defer_to_bucket_acls(_defer_to_bucket_acls
),
2146 bucket_access_conf(_bucket_acess_conf
)
2149 virtual ~perm_state_base() {}
2151 virtual const char *get_referer() const = 0;
2152 virtual std::optional
<bool> get_request_payer() const = 0; /*
2153 * empty state means that request_payer param was not passed in
2158 struct perm_state
: public perm_state_base
{
2159 const char *referer
;
2162 perm_state(CephContext
*_cct
,
2163 const rgw::IAM::Environment
& _env
,
2164 rgw::auth::Identity
*_identity
,
2165 const RGWBucketInfo
& _bucket_info
,
2167 bool _defer_to_bucket_acls
,
2168 const char *_referer
,
2169 bool _request_payer
) : perm_state_base(_cct
,
2174 _defer_to_bucket_acls
),
2176 request_payer(_request_payer
) {}
2178 const char *get_referer() const override
{
2182 std::optional
<bool> get_request_payer() const override
{
2183 return request_payer
;
2187 /** Check if the req_state's user has the necessary permissions
2188 * to do the requested action */
2189 bool verify_bucket_permission_no_policy(
2190 const DoutPrefixProvider
* dpp
,
2191 struct perm_state_base
* const s
,
2192 RGWAccessControlPolicy
* const user_acl
,
2193 RGWAccessControlPolicy
* const bucket_acl
,
2196 bool verify_user_permission_no_policy(const DoutPrefixProvider
* dpp
,
2197 struct perm_state_base
* const s
,
2198 RGWAccessControlPolicy
* const user_acl
,
2201 bool verify_object_permission_no_policy(const DoutPrefixProvider
* dpp
,
2202 struct perm_state_base
* const s
,
2203 RGWAccessControlPolicy
* const user_acl
,
2204 RGWAccessControlPolicy
* const bucket_acl
,
2205 RGWAccessControlPolicy
* const object_acl
,
2208 /** Check if the req_state's user has the necessary permissions
2209 * to do the requested action */
2210 rgw::IAM::Effect
eval_user_policies(const vector
<rgw::IAM::Policy
>& user_policies
,
2211 const rgw::IAM::Environment
& env
,
2212 boost::optional
<const rgw::auth::Identity
&> id
,
2214 const rgw::ARN
& arn
);
2215 bool verify_user_permission(const DoutPrefixProvider
* dpp
,
2216 struct req_state
* const s
,
2217 RGWAccessControlPolicy
* const user_acl
,
2218 const vector
<rgw::IAM::Policy
>& user_policies
,
2219 const rgw::ARN
& res
,
2221 bool verify_user_permission_no_policy(const DoutPrefixProvider
* dpp
,
2222 struct req_state
* const s
,
2223 RGWAccessControlPolicy
* const user_acl
,
2225 bool verify_user_permission(const DoutPrefixProvider
* dpp
,
2226 struct req_state
* const s
,
2227 const rgw::ARN
& res
,
2229 bool verify_user_permission_no_policy(const DoutPrefixProvider
* dpp
,
2230 struct req_state
* const s
,
2232 bool verify_bucket_permission(
2233 const DoutPrefixProvider
* dpp
,
2234 struct req_state
* const s
,
2235 const rgw_bucket
& bucket
,
2236 RGWAccessControlPolicy
* const user_acl
,
2237 RGWAccessControlPolicy
* const bucket_acl
,
2238 const boost::optional
<rgw::IAM::Policy
>& bucket_policy
,
2239 const vector
<rgw::IAM::Policy
>& user_policies
,
2241 bool verify_bucket_permission(const DoutPrefixProvider
* dpp
, struct req_state
* const s
, const uint64_t op
);
2242 bool verify_bucket_permission_no_policy(
2243 const DoutPrefixProvider
* dpp
,
2244 struct req_state
* const s
,
2245 RGWAccessControlPolicy
* const user_acl
,
2246 RGWAccessControlPolicy
* const bucket_acl
,
2248 bool verify_bucket_permission_no_policy(const DoutPrefixProvider
* dpp
,
2249 struct req_state
* const s
,
2251 int verify_bucket_owner_or_policy(struct req_state
* const s
,
2253 extern bool verify_object_permission(
2254 const DoutPrefixProvider
* dpp
,
2255 struct req_state
* const s
,
2257 RGWAccessControlPolicy
* const user_acl
,
2258 RGWAccessControlPolicy
* const bucket_acl
,
2259 RGWAccessControlPolicy
* const object_acl
,
2260 const boost::optional
<rgw::IAM::Policy
>& bucket_policy
,
2261 const vector
<rgw::IAM::Policy
>& user_policies
,
2263 extern bool verify_object_permission(const DoutPrefixProvider
* dpp
, struct req_state
*s
, uint64_t op
);
2264 extern bool verify_object_permission_no_policy(
2265 const DoutPrefixProvider
* dpp
,
2266 struct req_state
* const s
,
2267 RGWAccessControlPolicy
* const user_acl
,
2268 RGWAccessControlPolicy
* const bucket_acl
,
2269 RGWAccessControlPolicy
* const object_acl
,
2271 extern bool verify_object_permission_no_policy(const DoutPrefixProvider
* dpp
, struct req_state
*s
,
2273 /** Convert an input URL into a sane object name
2274 * by converting %-escaped strings into characters, etc*/
2275 extern void rgw_uri_escape_char(char c
, string
& dst
);
2276 extern std::string
url_decode(const boost::string_view
& src_str
,
2277 bool in_query
= false);
2278 extern void url_encode(const std::string
& src
, string
& dst
,
2279 bool encode_slash
= true);
2280 extern std::string
url_encode(const std::string
& src
, bool encode_slash
= true);
2281 /* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */
2282 extern void calc_hmac_sha1(const char *key
, int key_len
,
2283 const char *msg
, int msg_len
, char *dest
);
2285 static inline sha1_digest_t
2286 calc_hmac_sha1(const boost::string_view
& key
, const boost::string_view
& msg
) {
2288 calc_hmac_sha1(key
.data(), key
.size(), msg
.data(), msg
.size(),
2289 reinterpret_cast<char*>(dest
.v
));
2293 /* destination should be CEPH_CRYPTO_HMACSHA256_DIGESTSIZE bytes long */
2294 extern void calc_hmac_sha256(const char *key
, int key_len
,
2295 const char *msg
, int msg_len
,
2298 static inline sha256_digest_t
2299 calc_hmac_sha256(const char *key
, const int key_len
,
2300 const char *msg
, const int msg_len
) {
2301 sha256_digest_t dest
;
2302 calc_hmac_sha256(key
, key_len
, msg
, msg_len
,
2303 reinterpret_cast<char*>(dest
.v
));
2307 static inline sha256_digest_t
2308 calc_hmac_sha256(const boost::string_view
& key
, const boost::string_view
& msg
) {
2309 sha256_digest_t dest
;
2310 calc_hmac_sha256(key
.data(), key
.size(),
2311 msg
.data(), msg
.size(),
2312 reinterpret_cast<char*>(dest
.v
));
2316 static inline sha256_digest_t
2317 calc_hmac_sha256(const sha256_digest_t
&key
,
2318 const boost::string_view
& msg
) {
2319 sha256_digest_t dest
;
2320 calc_hmac_sha256(reinterpret_cast<const char*>(key
.v
), sha256_digest_t::SIZE
,
2321 msg
.data(), msg
.size(),
2322 reinterpret_cast<char*>(dest
.v
));
2326 static inline sha256_digest_t
2327 calc_hmac_sha256(const std::vector
<unsigned char>& key
,
2328 const boost::string_view
& msg
) {
2329 sha256_digest_t dest
;
2330 calc_hmac_sha256(reinterpret_cast<const char*>(key
.data()), key
.size(),
2331 msg
.data(), msg
.size(),
2332 reinterpret_cast<char*>(dest
.v
));
2336 template<size_t KeyLenN
>
2337 static inline sha256_digest_t
2338 calc_hmac_sha256(const std::array
<unsigned char, KeyLenN
>& key
,
2339 const boost::string_view
& msg
) {
2340 sha256_digest_t dest
;
2341 calc_hmac_sha256(reinterpret_cast<const char*>(key
.data()), key
.size(),
2342 msg
.data(), msg
.size(),
2343 reinterpret_cast<char*>(dest
.v
));
2347 extern sha256_digest_t
calc_hash_sha256(const boost::string_view
& msg
);
2349 extern ceph::crypto::SHA256
* calc_hash_sha256_open_stream();
2350 extern void calc_hash_sha256_update_stream(ceph::crypto::SHA256
* hash
,
2353 extern std::string
calc_hash_sha256_close_stream(ceph::crypto::SHA256
** phash
);
2354 extern std::string
calc_hash_sha256_restart_stream(ceph::crypto::SHA256
** phash
);
2356 extern int rgw_parse_op_type_list(const string
& str
, uint32_t *perm
);
2358 static constexpr uint32_t MATCH_POLICY_ACTION
= 0x01;
2359 static constexpr uint32_t MATCH_POLICY_RESOURCE
= 0x02;
2360 static constexpr uint32_t MATCH_POLICY_ARN
= 0x04;
2361 static constexpr uint32_t MATCH_POLICY_STRING
= 0x08;
2363 extern bool match_policy(boost::string_view pattern
, boost::string_view input
,
2366 extern string
camelcase_dash_http_attr(const string
& orig
);
2367 extern string
lowercase_dash_http_attr(const string
& orig
);
2369 void rgw_setup_saved_curl_handles();
2370 void rgw_release_all_curl_handles();
2372 static inline void rgw_escape_str(const string
& s
, char esc_char
,
2373 char special_char
, string
*dest
)
2375 const char *src
= s
.c_str();
2376 char dest_buf
[s
.size() * 2 + 1];
2377 char *destp
= dest_buf
;
2379 for (size_t i
= 0; i
< s
.size(); i
++) {
2381 if (c
== esc_char
|| c
== special_char
) {
2382 *destp
++ = esc_char
;
2390 static inline ssize_t
rgw_unescape_str(const string
& s
, ssize_t ofs
,
2391 char esc_char
, char special_char
,
2394 const char *src
= s
.c_str();
2395 char dest_buf
[s
.size() + 1];
2396 char *destp
= dest_buf
;
2401 for (size_t i
= ofs
; i
< s
.size(); i
++) {
2403 if (!esc
&& c
== esc_char
) {
2407 if (!esc
&& c
== special_char
) {
2410 return (ssize_t
)i
+ 1;
2417 return string::npos
;
2420 static inline string
rgw_bl_str(ceph::buffer::list
& raw
)
2422 size_t len
= raw
.length();
2423 string
s(raw
.c_str(), len
);
2424 while (len
&& !s
[len
- 1]) {
2431 template <typename T
>
2432 int decode_bl(bufferlist
& bl
, T
& t
)
2434 auto iter
= bl
.cbegin();
2437 } catch (buffer::error
& err
) {