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
,
547 /*OIDC provider specific*/
548 RGW_OP_CREATE_OIDC_PROVIDER
,
549 RGW_OP_DELETE_OIDC_PROVIDER
,
550 RGW_OP_GET_OIDC_PROVIDER
,
551 RGW_OP_LIST_OIDC_PROVIDERS
,
554 class RGWAccessControlPolicy
;
557 struct RGWAccessKey
{
558 string id
; // AccessKey
559 string key
; // SecretKey
563 RGWAccessKey(std::string _id
, std::string _key
)
564 : id(std::move(_id
)), key(std::move(_key
)) {}
566 void encode(bufferlist
& bl
) const {
567 ENCODE_START(2, 2, bl
);
574 void decode(bufferlist::const_iterator
& bl
) {
575 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
581 void dump(Formatter
*f
) const;
582 void dump_plain(Formatter
*f
) const;
583 void dump(Formatter
*f
, const string
& user
, bool swift
) const;
584 static void generate_test_instances(list
<RGWAccessKey
*>& o
);
586 void decode_json(JSONObj
*obj
);
587 void decode_json(JSONObj
*obj
, bool swift
);
589 WRITE_CLASS_ENCODER(RGWAccessKey
)
595 RGWSubUser() : perm_mask(0) {}
596 void encode(bufferlist
& bl
) const {
597 ENCODE_START(2, 2, bl
);
599 encode(perm_mask
, bl
);
603 void decode(bufferlist::const_iterator
& bl
) {
604 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
606 decode(perm_mask
, bl
);
609 void dump(Formatter
*f
) const;
610 void dump(Formatter
*f
, const string
& user
) const;
611 static void generate_test_instances(list
<RGWSubUser
*>& o
);
613 void decode_json(JSONObj
*obj
);
615 WRITE_CLASS_ENCODER(RGWSubUser
)
619 map
<string
, uint32_t> caps
;
621 int get_cap(const string
& cap
, string
& type
, uint32_t *perm
);
622 int add_cap(const string
& cap
);
623 int remove_cap(const string
& cap
);
625 static int parse_cap_perm(const string
& str
, uint32_t *perm
);
626 int add_from_string(const string
& str
);
627 int remove_from_string(const string
& str
);
629 void encode(bufferlist
& bl
) const {
630 ENCODE_START(1, 1, bl
);
634 void decode(bufferlist::const_iterator
& bl
) {
639 int check_cap(const string
& cap
, uint32_t perm
) const;
640 bool is_valid_cap_type(const string
& tp
);
641 void dump(Formatter
*f
) const;
642 void dump(Formatter
*f
, const char *name
) const;
644 void decode_json(JSONObj
*obj
);
646 WRITE_CLASS_ENCODER(RGWUserCaps
)
648 void encode_json(const char *name
, const obj_version
& v
, Formatter
*f
);
649 void encode_json(const char *name
, const RGWUserCaps
& val
, Formatter
*f
);
651 void decode_json_obj(obj_version
& v
, JSONObj
*obj
);
665 static string RGW_STORAGE_CLASS_STANDARD
= "STANDARD";
667 struct rgw_placement_rule
{
669 std::string storage_class
;
671 rgw_placement_rule() {}
672 rgw_placement_rule(const string
& _n
, const string
& _sc
) : name(_n
), storage_class(_sc
) {}
673 rgw_placement_rule(const rgw_placement_rule
& _r
, const string
& _sc
) : name(_r
.name
) {
677 storage_class
= _r
.storage_class
;
682 return name
.empty() && storage_class
.empty();
685 void inherit_from(const rgw_placement_rule
& r
) {
689 if (storage_class
.empty()) {
690 storage_class
= r
.storage_class
;
696 storage_class
.clear();
699 void init(const string
& n
, const string
& c
) {
704 static const string
& get_canonical_storage_class(const string
& storage_class
) {
705 if (storage_class
.empty()) {
706 return RGW_STORAGE_CLASS_STANDARD
;
708 return storage_class
;
711 const string
& get_storage_class() const {
712 return get_canonical_storage_class(storage_class
);
715 int compare(const rgw_placement_rule
& r
) const {
716 int c
= name
.compare(r
.name
);
720 return get_storage_class().compare(r
.get_storage_class());
723 bool operator==(const rgw_placement_rule
& r
) const {
724 return (name
== r
.name
&&
725 get_storage_class() == r
.get_storage_class());
728 bool operator!=(const rgw_placement_rule
& r
) const {
729 return !(*this == r
);
732 void encode(bufferlist
& bl
) const {
733 /* no ENCODE_START/END due to backward compatibility */
734 std::string s
= to_str();
738 void decode(bufferlist::const_iterator
& bl
) {
744 std::string
to_str() const {
745 if (standard_storage_class()) {
748 return to_str_explicit();
751 std::string
to_str_explicit() const {
752 return name
+ "/" + storage_class
;
755 void from_str(const std::string
& s
) {
756 size_t pos
= s
.find("/");
757 if (pos
== std::string::npos
) {
759 storage_class
.clear();
762 name
= s
.substr(0, pos
);
763 storage_class
= s
.substr(pos
+ 1);
766 bool standard_storage_class() const {
767 return storage_class
.empty() || storage_class
== RGW_STORAGE_CLASS_STANDARD
;
770 WRITE_CLASS_ENCODER(rgw_placement_rule
)
772 void encode_json(const char *name
, const rgw_placement_rule
& val
, ceph::Formatter
*f
);
773 void decode_json_obj(rgw_placement_rule
& v
, JSONObj
*obj
);
775 inline ostream
& operator<<(ostream
& out
, const rgw_placement_rule
& rule
) {
776 return out
<< rule
.to_str();
783 map
<string
, RGWAccessKey
> access_keys
;
784 map
<string
, RGWAccessKey
> swift_keys
;
785 map
<string
, RGWSubUser
> subusers
;
792 rgw_placement_rule default_placement
;
793 list
<string
> placement_tags
;
794 RGWQuotaInfo bucket_quota
;
795 map
<int, string
> temp_url_keys
;
796 RGWQuotaInfo user_quota
;
799 string assumed_role_arn
;
803 max_buckets(RGW_DEFAULT_MAX_BUCKETS
),
804 op_mask(RGW_OP_TYPE_ALL
),
810 RGWAccessKey
* get_key(const string
& access_key
) {
811 if (access_keys
.empty())
814 auto k
= access_keys
.find(access_key
);
815 if (k
== access_keys
.end())
821 void encode(bufferlist
& bl
) const {
822 ENCODE_START(21, 9, bl
);
823 encode((uint64_t)0, bl
); // old auid
826 if (!access_keys
.empty()) {
827 map
<string
, RGWAccessKey
>::const_iterator iter
= access_keys
.begin();
828 const RGWAccessKey
& k
= iter
->second
;
832 encode(access_key
, bl
);
833 encode(secret_key
, bl
);
834 encode(display_name
, bl
);
835 encode(user_email
, bl
);
838 if (!swift_keys
.empty()) {
839 map
<string
, RGWAccessKey
>::const_iterator iter
= swift_keys
.begin();
840 const RGWAccessKey
& k
= iter
->second
;
844 encode(swift_name
, bl
);
845 encode(swift_key
, bl
);
846 encode(user_id
.id
, bl
);
847 encode(access_keys
, bl
);
848 encode(subusers
, bl
);
849 encode(suspended
, bl
);
850 encode(swift_keys
, bl
);
851 encode(max_buckets
, bl
);
855 encode(default_placement
, bl
);
856 encode(placement_tags
, bl
);
857 encode(bucket_quota
, bl
);
858 encode(temp_url_keys
, bl
);
859 encode(user_quota
, bl
);
860 encode(user_id
.tenant
, bl
);
864 encode(assumed_role_arn
, bl
);
867 void decode(bufferlist::const_iterator
& bl
) {
868 DECODE_START_LEGACY_COMPAT_LEN_32(21, 9, 9, bl
);
871 decode(old_auid
, bl
);
875 decode(access_key
, bl
);
876 decode(secret_key
, bl
);
881 access_keys
[access_key
] = k
;
883 decode(display_name
, bl
);
884 decode(user_email
, bl
);
885 /* We populate swift_keys map later nowadays, but we have to decode. */
888 if (struct_v
>= 3) decode(swift_name
, bl
);
889 if (struct_v
>= 4) decode(swift_key
, bl
);
891 decode(user_id
.id
, bl
);
893 user_id
.id
= access_key
;
895 decode(access_keys
, bl
);
896 decode(subusers
, bl
);
900 decode(suspended
, bl
);
903 decode(swift_keys
, bl
);
905 if (struct_v
>= 10) {
906 decode(max_buckets
, bl
);
908 max_buckets
= RGW_DEFAULT_MAX_BUCKETS
;
910 if (struct_v
>= 11) {
913 if (struct_v
>= 12) {
916 op_mask
= RGW_OP_TYPE_ALL
;
918 if (struct_v
>= 13) {
920 decode(default_placement
, bl
);
921 decode(placement_tags
, bl
); /* tags of allowed placement rules */
923 if (struct_v
>= 14) {
924 decode(bucket_quota
, bl
);
926 if (struct_v
>= 15) {
927 decode(temp_url_keys
, bl
);
929 if (struct_v
>= 16) {
930 decode(user_quota
, bl
);
932 if (struct_v
>= 17) {
933 decode(user_id
.tenant
, bl
);
935 user_id
.tenant
.clear();
937 if (struct_v
>= 18) {
940 if (struct_v
>= 19) {
943 if (struct_v
>= 20) {
946 if (struct_v
>= 21) {
947 decode(assumed_role_arn
, bl
);
951 void dump(Formatter
*f
) const;
952 static void generate_test_instances(list
<RGWUserInfo
*>& o
);
954 void decode_json(JSONObj
*obj
);
956 WRITE_CLASS_ENCODER(RGWUserInfo
)
964 rgw_raw_obj(const rgw_pool
& _pool
, const std::string
& _oid
) {
967 rgw_raw_obj(const rgw_pool
& _pool
, const std::string
& _oid
, const string
& _loc
) : loc(_loc
) {
971 void init(const rgw_pool
& _pool
, const std::string
& _oid
) {
980 void encode(bufferlist
& bl
) const {
981 ENCODE_START(6, 6, bl
);
988 void decode_from_rgw_obj(bufferlist::const_iterator
& bl
);
990 void decode(bufferlist::const_iterator
& bl
) {
991 unsigned ofs
= bl
.get_off();
995 * this object was encoded as rgw_obj, prior to rgw_raw_obj been split out of it,
996 * let's decode it as rgw_obj and convert it
999 decode_from_rgw_obj(bl
);
1008 bool operator<(const rgw_raw_obj
& o
) const {
1009 int r
= pool
.compare(o
.pool
);
1011 r
= oid
.compare(o
.oid
);
1013 r
= loc
.compare(o
.loc
);
1019 bool operator==(const rgw_raw_obj
& o
) const {
1020 return (pool
== o
.pool
&& oid
== o
.oid
&& loc
== o
.loc
);
1023 void dump(Formatter
*f
) const;
1024 void decode_json(JSONObj
*obj
);
1026 WRITE_CLASS_ENCODER(rgw_raw_obj
)
1028 inline ostream
& operator<<(ostream
& out
, const rgw_raw_obj
& o
) {
1029 out
<< o
.pool
<< ":" << o
.oid
;
1033 struct rgw_bucket_placement
{
1034 rgw_placement_rule placement_rule
;
1037 void dump(Formatter
*f
) const;
1040 struct RGWObjVersionTracker
{
1041 obj_version read_version
;
1042 obj_version write_version
;
1044 obj_version
*version_for_read() {
1045 return &read_version
;
1048 obj_version
*version_for_write() {
1049 if (write_version
.ver
== 0)
1052 return &write_version
;
1055 obj_version
*version_for_check() {
1056 if (read_version
.ver
== 0)
1059 return &read_version
;
1062 void prepare_op_for_read(librados::ObjectReadOperation
*op
);
1063 void prepare_op_for_write(librados::ObjectWriteOperation
*op
);
1068 read_version
= obj_version();
1069 write_version
= obj_version();
1072 void generate_new_write_ver(CephContext
*cct
);
1075 inline ostream
& operator<<(ostream
& out
, const obj_version
&v
)
1077 out
<< v
.tag
<< ":" << v
.ver
;
1081 inline ostream
& operator<<(ostream
& out
, const RGWObjVersionTracker
&ot
)
1083 out
<< "{r=" << ot
.read_version
<< ",w=" << ot
.write_version
<< "}";
1087 enum RGWBucketFlags
{
1088 BUCKET_SUSPENDED
= 0x1,
1089 BUCKET_VERSIONED
= 0x2,
1090 BUCKET_VERSIONS_SUSPENDED
= 0x4,
1091 BUCKET_DATASYNC_DISABLED
= 0X8,
1092 BUCKET_MFA_ENABLED
= 0X10,
1093 BUCKET_OBJ_LOCK_ENABLED
= 0X20,
1096 enum RGWBucketIndexType
{
1097 RGWBIType_Normal
= 0,
1098 RGWBIType_Indexless
= 1,
1101 inline ostream
& operator<<(ostream
& out
, const RGWBucketIndexType
&index_type
)
1103 switch (index_type
) {
1104 case RGWBIType_Normal
:
1105 return out
<< "Normal";
1106 case RGWBIType_Indexless
:
1107 return out
<< "Indexless";
1109 return out
<< "Unknown";
1115 struct RGWBucketInfo
{
1116 enum BIShardsHashType
{
1124 ceph::real_time creation_time
;
1125 rgw_placement_rule placement_rule
;
1126 bool has_instance_obj
{false};
1127 RGWObjVersionTracker objv_tracker
; /* we don't need to serialize this, for runtime tracking */
1130 // Represents the number of bucket index object shards:
1131 // - value of 0 indicates there is no sharding (this is by default
1132 // before this feature is implemented).
1133 // - value of UINT32_T::MAX indicates this is a blind bucket.
1134 uint32_t num_shards
{0};
1136 // Represents the bucket index shard hash type.
1137 uint8_t bucket_index_shard_hash_type
{MOD
};
1139 // Represents the shard number for blind bucket.
1140 const static uint32_t NUM_SHARDS_BLIND_BUCKET
;
1142 bool requester_pays
{false};
1144 bool has_website
{false};
1145 RGWBucketWebsiteConf website_conf
;
1147 RGWBucketIndexType index_type
= RGWBIType_Normal
;
1149 bool swift_versioning
{false};
1150 string swift_ver_location
;
1152 map
<string
, uint32_t> mdsearch_config
;
1155 cls_rgw_reshard_status reshard_status
{cls_rgw_reshard_status::NOT_RESHARDING
};
1156 string new_bucket_instance_id
;
1158 RGWObjectLock obj_lock
;
1160 std::optional
<rgw_sync_policy_info
> sync_policy
;
1162 void encode(bufferlist
& bl
) const;
1163 void decode(bufferlist::const_iterator
& bl
);
1165 void dump(Formatter
*f
) const;
1166 static void generate_test_instances(list
<RGWBucketInfo
*>& o
);
1168 void decode_json(JSONObj
*obj
);
1170 bool versioned() const { return (flags
& BUCKET_VERSIONED
) != 0; }
1171 int versioning_status() const { return flags
& (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
| BUCKET_MFA_ENABLED
); }
1172 bool versioning_enabled() const { return (versioning_status() & (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
)) == BUCKET_VERSIONED
; }
1173 bool mfa_enabled() const { return (versioning_status() & BUCKET_MFA_ENABLED
) != 0; }
1174 bool datasync_flag_enabled() const { return (flags
& BUCKET_DATASYNC_DISABLED
) == 0; }
1175 bool obj_lock_enabled() const { return (flags
& BUCKET_OBJ_LOCK_ENABLED
) != 0; }
1177 bool has_swift_versioning() const {
1178 /* A bucket may be versioned through one mechanism only. */
1179 return swift_versioning
&& !versioned();
1182 void set_sync_policy(rgw_sync_policy_info
&& policy
);
1184 bool empty_sync_policy() const;
1189 WRITE_CLASS_ENCODER(RGWBucketInfo
)
1191 struct RGWBucketEntryPoint
1195 ceph::real_time creation_time
;
1198 bool has_bucket_info
;
1199 RGWBucketInfo old_bucket_info
;
1201 RGWBucketEntryPoint() : linked(false), has_bucket_info(false) {}
1203 void encode(bufferlist
& bl
) const {
1204 ENCODE_START(10, 8, bl
);
1206 encode(owner
.id
, bl
);
1208 uint64_t ctime
= (uint64_t)real_clock::to_time_t(creation_time
);
1211 encode(creation_time
, bl
);
1214 void decode(bufferlist::const_iterator
& bl
) {
1215 auto orig_iter
= bl
;
1216 DECODE_START_LEGACY_COMPAT_LEN_32(10, 4, 4, bl
);
1218 /* ouch, old entry, contains the bucket info itself */
1219 old_bucket_info
.decode(orig_iter
);
1220 has_bucket_info
= true;
1223 has_bucket_info
= false;
1225 decode(owner
.id
, bl
);
1229 if (struct_v
< 10) {
1230 creation_time
= real_clock::from_time_t((time_t)ctime
);
1232 if (struct_v
>= 9) {
1235 if (struct_v
>= 10) {
1236 decode(creation_time
, bl
);
1241 void dump(Formatter
*f
) const;
1242 void decode_json(JSONObj
*obj
);
1243 static void generate_test_instances(list
<RGWBucketEntryPoint
*>& o
);
1245 WRITE_CLASS_ENCODER(RGWBucketEntryPoint
)
1247 struct RGWStorageStats
1249 RGWObjCategory category
;
1251 uint64_t size_rounded
;
1252 uint64_t size_utilized
{0}; //< size after compression, encryption
1253 uint64_t num_objects
;
1256 : category(RGWObjCategory::None
),
1261 void dump(Formatter
*f
) const;
1266 /* Namespaced forward declarations. */
1270 class AWSBrowserUploadAbstractor
;
1280 using meta_map_t
= boost::container::flat_map
<std::string
, std::string
>;
1285 meta_map_t x_meta_map
;
1291 string request_uri_aws4
;
1292 string effective_uri
;
1293 string request_params
;
1295 string storage_class
;
1297 req_info(CephContext
*cct
, const RGWEnv
*env
);
1298 void rebuild_from(req_info
& src
);
1299 void init_meta_info(bool *found_bad_meta
);
1302 typedef cls_rgw_obj_key rgw_obj_index_key
;
1304 struct rgw_obj_key
{
1310 // cppcheck-suppress noExplicitConstructor
1311 rgw_obj_key(const string
& n
) : name(n
) {}
1312 rgw_obj_key(const string
& n
, const string
& i
) : name(n
), instance(i
) {}
1313 rgw_obj_key(const string
& n
, const string
& i
, const string
& _ns
) : name(n
), instance(i
), ns(_ns
) {}
1315 rgw_obj_key(const rgw_obj_index_key
& k
) {
1316 parse_index_key(k
.name
, &name
, &ns
);
1317 instance
= k
.instance
;
1320 static void parse_index_key(const string
& key
, string
*name
, string
*ns
) {
1321 if (key
[0] != '_') {
1326 if (key
[1] == '_') {
1327 *name
= key
.substr(1);
1331 ssize_t pos
= key
.find('_', 1);
1333 /* shouldn't happen, just use key */
1339 *name
= key
.substr(pos
+ 1);
1340 *ns
= key
.substr(1, pos
-1);
1343 void set(const string
& n
) {
1349 void set(const string
& n
, const string
& i
) {
1355 void set(const string
& n
, const string
& i
, const string
& _ns
) {
1361 bool set(const rgw_obj_index_key
& index_key
) {
1362 if (!parse_raw_oid(index_key
.name
, this)) {
1365 instance
= index_key
.instance
;
1369 void set_instance(const string
& i
) {
1373 const string
& get_instance() const {
1377 void set_ns(const std::string
& _ns
) {
1381 const std::string
& get_ns() const {
1385 string
get_index_key_name() const {
1387 if (name
.size() < 1 || name
[0] != '_') {
1390 return string("_") + name
;
1393 char buf
[ns
.size() + 16];
1394 snprintf(buf
, sizeof(buf
), "_%s_", ns
.c_str());
1395 return string(buf
) + name
;
1398 void get_index_key(rgw_obj_index_key
*key
) const {
1399 key
->name
= get_index_key_name();
1400 key
->instance
= instance
;
1403 string
get_loc() const {
1405 * For backward compatibility. Older versions used to have object locator on all objects,
1406 * however, the name was the effective object locator. This had the same effect as not
1407 * having object locator at all for most objects but the ones that started with underscore as
1408 * these were escaped.
1410 if (name
[0] == '_' && ns
.empty()) {
1417 bool empty() const {
1418 return name
.empty();
1421 bool have_null_instance() const {
1422 return instance
== "null";
1425 bool have_instance() const {
1426 return !instance
.empty();
1429 bool need_to_encode_instance() const {
1430 return have_instance() && !have_null_instance();
1433 string
get_oid() const {
1434 if (ns
.empty() && !need_to_encode_instance()) {
1435 if (name
.size() < 1 || name
[0] != '_') {
1438 return string("_") + name
;
1443 if (need_to_encode_instance()) {
1444 oid
.append(string(":") + instance
);
1451 bool operator==(const rgw_obj_key
& k
) const {
1452 return (name
.compare(k
.name
) == 0) &&
1453 (instance
.compare(k
.instance
) == 0);
1456 bool operator<(const rgw_obj_key
& k
) const {
1457 int r
= name
.compare(k
.name
);
1459 r
= instance
.compare(k
.instance
);
1464 bool operator<=(const rgw_obj_key
& k
) const {
1465 return !(k
< *this);
1468 static void parse_ns_field(string
& ns
, string
& instance
) {
1469 int pos
= ns
.find(':');
1471 instance
= ns
.substr(pos
+ 1);
1472 ns
= ns
.substr(0, pos
);
1478 // takes an oid and parses out the namespace (ns), name, and
1480 static bool parse_raw_oid(const string
& oid
, rgw_obj_key
*key
) {
1481 key
->instance
.clear();
1483 if (oid
[0] != '_') {
1488 if (oid
.size() >= 2 && oid
[1] == '_') {
1489 key
->name
= oid
.substr(1);
1493 if (oid
.size() < 3) // for namespace, min size would be 3: _x_
1496 size_t pos
= oid
.find('_', 2); // oid must match ^_[^_].+$
1497 if (pos
== string::npos
)
1500 key
->ns
= oid
.substr(1, pos
- 1);
1501 parse_ns_field(key
->ns
, key
->instance
);
1503 key
->name
= oid
.substr(pos
+ 1);
1508 * Translate a namespace-mangled object name to the user-facing name
1509 * existing in the given namespace.
1511 * If the object is part of the given namespace, it returns true
1512 * and cuts down the name to the unmangled version. If it is not
1513 * part of the given namespace, it returns false.
1515 static bool oid_to_key_in_ns(const string
& oid
, rgw_obj_key
*key
, const string
& ns
) {
1516 bool ret
= parse_raw_oid(oid
, key
);
1521 return (ns
== key
->ns
);
1525 * Given a mangled object name and an empty namespace string, this
1526 * function extracts the namespace into the string and sets the object
1527 * name to be the unmangled version.
1529 * It returns true after successfully doing so, or
1530 * false if it fails.
1532 static bool strip_namespace_from_name(string
& name
, string
& ns
, string
& instance
) {
1535 if (name
[0] != '_') {
1539 size_t pos
= name
.find('_', 1);
1540 if (pos
== string::npos
) {
1544 if (name
[1] == '_') {
1545 name
= name
.substr(1);
1549 size_t period_pos
= name
.find('.');
1550 if (period_pos
< pos
) {
1554 ns
= name
.substr(1, pos
-1);
1555 name
= name
.substr(pos
+1, string::npos
);
1557 parse_ns_field(ns
, instance
);
1561 void encode(bufferlist
& bl
) const {
1562 ENCODE_START(2, 1, bl
);
1564 encode(instance
, bl
);
1568 void decode(bufferlist::const_iterator
& bl
) {
1569 DECODE_START(2, bl
);
1571 decode(instance
, bl
);
1572 if (struct_v
>= 2) {
1577 void dump(Formatter
*f
) const;
1578 void decode_json(JSONObj
*obj
);
1580 string
to_str() const {
1581 if (instance
.empty()) {
1584 char buf
[name
.size() + instance
.size() + 16];
1585 snprintf(buf
, sizeof(buf
), "%s[%s]", name
.c_str(), instance
.c_str());
1589 WRITE_CLASS_ENCODER(rgw_obj_key
)
1591 inline ostream
& operator<<(ostream
& out
, const rgw_obj_key
&o
) {
1592 return out
<< o
.to_str();
1595 inline ostream
& operator<<(ostream
& out
, const rgw_obj_index_key
&o
) {
1596 if (o
.instance
.empty()) {
1597 return out
<< o
.name
;
1599 return out
<< o
.name
<< "[" << o
.instance
<< "]";
1603 struct req_init_state
{
1604 /* Keeps [[tenant]:]bucket until we parse the token. */
1609 #include "rgw_auth.h"
1612 class RGWSysObjectCtx
;
1614 /** Store all the state necessary to complete and respond to an HTTP request*/
1615 struct req_state
: DoutPrefixProvider
{
1617 rgw::io::BasicClient
*cio
{nullptr};
1618 http_op op
{OP_UNKNOWN
};
1619 RGWOpType op_type
{};
1620 bool content_started
{false};
1622 ceph::Formatter
*formatter
{nullptr};
1624 string relative_uri
;
1625 const char *length
{nullptr};
1626 int64_t content_length
{0};
1627 map
<string
, string
> generic_attrs
;
1629 bool expect_cont
{false};
1630 uint64_t obj_size
{0};
1631 bool enable_ops_log
;
1632 bool enable_usage_log
;
1633 uint8_t defer_to_bucket_acls
;
1634 uint32_t perm_mask
{0};
1636 /* Set once when url_bucket is parsed and not violated thereafter. */
1637 string account_name
;
1639 string bucket_tenant
;
1644 string src_tenant_name
;
1645 string src_bucket_name
;
1646 rgw_obj_key src_object
;
1647 ACLOwner bucket_owner
;
1650 string zonegroup_name
;
1651 string zonegroup_endpoint
;
1652 string bucket_instance_id
;
1653 int bucket_instance_shard_id
{-1};
1654 string redirect_zone_endpoint
;
1658 RGWBucketInfo bucket_info
;
1659 obj_version bucket_ep_objv
;
1660 real_time bucket_mtime
;
1661 std::map
<std::string
, ceph::bufferlist
> bucket_attrs
;
1662 bool bucket_exists
{false};
1663 rgw_placement_rule dest_placement
;
1665 bool has_bad_meta
{false};
1667 rgw::sal::RGWUser
*user
;
1670 /* TODO(rzarzynski): switch out to the static_ptr for both members. */
1672 /* Object having the knowledge about an authenticated identity and allowing
1673 * to apply it during the authorization phase (verify_permission() methods
1674 * of a given RGWOp). Thus, it bounds authentication and authorization steps
1675 * through a well-defined interface. For more details, see rgw_auth.h. */
1676 std::unique_ptr
<rgw::auth::Identity
> identity
;
1678 std::shared_ptr
<rgw::auth::Completer
> completer
;
1680 /* A container for credentials of the S3's browser upload. It's necessary
1681 * because: 1) the ::authenticate() method of auth engines and strategies
1682 * take req_state only; 2) auth strategies live much longer than RGWOps -
1683 * there is no way to pass additional data dependencies through ctors. */
1686 friend class RGWPostObj_ObjStore_S3
;
1688 friend class rgw::auth::s3::AWSBrowserUploadAbstractor
;
1689 friend class rgw::auth::s3::STSEngine
;
1691 std::string access_key
;
1692 std::string signature
;
1693 std::string x_amz_algorithm
;
1694 std::string x_amz_credential
;
1695 std::string x_amz_date
;
1696 std::string x_amz_security_token
;
1697 ceph::bufferlist encoded_policy
;
1701 std::unique_ptr
<RGWAccessControlPolicy
> user_acl
;
1702 std::unique_ptr
<RGWAccessControlPolicy
> bucket_acl
;
1703 std::unique_ptr
<RGWAccessControlPolicy
> object_acl
;
1705 rgw::IAM::Environment env
;
1706 boost::optional
<rgw::IAM::Policy
> iam_policy
;
1707 boost::optional
<PublicAccessBlockConfiguration
> bucket_access_conf
;
1708 vector
<rgw::IAM::Policy
> iam_user_policies
;
1710 /* Is the request made by an user marked as a system one?
1711 * Being system user means we also have the admin status. */
1712 bool system_request
{false};
1715 bool has_acl_header
{false};
1716 bool local_source
{false}; /* source is local */
1720 /* Content-Disposition override for TempURL of Swift API. */
1729 req_init_state init_state
;
1731 using Clock
= ceph::coarse_real_clock
;
1732 Clock::time_point time
;
1734 Clock::duration
time_elapsed() const { return Clock::now() - time
; }
1736 RGWObjectCtx
*obj_ctx
{nullptr};
1737 RGWSysObjectCtx
*sysobj_ctx
{nullptr};
1745 bool mfa_verified
{false};
1747 /// optional coroutine context
1748 optional_yield yield
{null_yield
};
1750 req_state(CephContext
* _cct
, RGWEnv
* e
, rgw::sal::RGWUser
* u
, uint64_t id
);
1753 bool is_err() const { return err
.is_err(); }
1755 // implements DoutPrefixProvider
1756 std::ostream
& gen_prefix(std::ostream
& out
) const override
;
1757 CephContext
* get_cct() const override
{ return cct
; }
1758 unsigned get_subsys() const override
{ return ceph_subsys_rgw
; }
1761 void set_req_state_err(struct req_state
*, int);
1762 void set_req_state_err(struct req_state
*, int, const string
&);
1763 void set_req_state_err(struct rgw_err
&, int, const int);
1764 void dump(struct req_state
*);
1766 /** Store basic data on bucket */
1767 struct RGWBucketEnt
{
1770 size_t size_rounded
;
1771 ceph::real_time creation_time
;
1774 /* The placement_rule is necessary to calculate per-storage-policy statics
1775 * of the Swift API. Although the info available in RGWBucketInfo, we need
1776 * to duplicate it here to not affect the performance of buckets listing. */
1777 rgw_placement_rule placement_rule
;
1784 RGWBucketEnt(const RGWBucketEnt
&) = default;
1785 RGWBucketEnt(RGWBucketEnt
&&) = default;
1786 explicit RGWBucketEnt(const rgw_user
& u
, cls_user_bucket_entry
&& e
)
1787 : bucket(u
, std::move(e
.bucket
)),
1789 size_rounded(e
.size_rounded
),
1790 creation_time(e
.creation_time
),
1794 RGWBucketEnt
& operator=(const RGWBucketEnt
&) = default;
1796 void convert(cls_user_bucket_entry
*b
) const {
1797 bucket
.convert(&b
->bucket
);
1799 b
->size_rounded
= size_rounded
;
1800 b
->creation_time
= creation_time
;
1804 void encode(bufferlist
& bl
) const {
1805 ENCODE_START(7, 5, bl
);
1807 __u32 mt
= ceph::real_clock::to_time_t(creation_time
);
1808 string empty_str
; // originally had the bucket name here, but we encode bucket later
1809 encode(empty_str
, bl
);
1816 encode(creation_time
, bl
);
1817 encode(placement_rule
, bl
);
1820 void decode(bufferlist::const_iterator
& bl
) {
1821 DECODE_START_LEGACY_COMPAT_LEN(7, 5, 5, bl
);
1824 string empty_str
; // backward compatibility
1825 decode(empty_str
, bl
);
1830 creation_time
= ceph::real_clock::from_time_t(mt
);
1840 decode(creation_time
, bl
);
1842 decode(placement_rule
, bl
);
1845 void dump(Formatter
*f
) const;
1846 static void generate_test_instances(list
<RGWBucketEnt
*>& o
);
1848 WRITE_CLASS_ENCODER(RGWBucketEnt
)
1854 bool in_extra_data
{false}; /* in-memory only member, does not serialize */
1856 // Represents the hash index source for this object once it is set (non-empty)
1857 std::string index_hash_source
;
1860 rgw_obj(const rgw_bucket
& b
, const std::string
& name
) : bucket(b
), key(name
) {}
1861 rgw_obj(const rgw_bucket
& b
, const rgw_obj_key
& k
) : bucket(b
), key(k
) {}
1862 rgw_obj(const rgw_bucket
& b
, const rgw_obj_index_key
& k
) : bucket(b
), key(k
) {}
1864 void init(const rgw_bucket
& b
, const std::string
& name
) {
1868 void init(const rgw_bucket
& b
, const std::string
& name
, const string
& i
, const string
& n
) {
1870 key
.set(name
, i
, n
);
1872 void init_ns(const rgw_bucket
& b
, const std::string
& name
, const string
& n
) {
1875 key
.instance
.clear();
1879 bool empty() const {
1883 void set_key(const rgw_obj_key
& k
) {
1887 string
get_oid() const {
1888 return key
.get_oid();
1891 const string
& get_hash_object() const {
1892 return index_hash_source
.empty() ? key
.name
: index_hash_source
;
1895 void set_in_extra_data(bool val
) {
1896 in_extra_data
= val
;
1899 bool is_in_extra_data() const {
1900 return in_extra_data
;
1903 void encode(bufferlist
& bl
) const {
1904 ENCODE_START(6, 6, bl
);
1907 encode(key
.name
, bl
);
1908 encode(key
.instance
, bl
);
1909 // encode(placement_id, bl);
1912 void decode(bufferlist::const_iterator
& bl
) {
1913 DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, bl
);
1916 decode(bucket
.name
, bl
); /* bucket.name */
1917 decode(s
, bl
); /* loc */
1919 decode(key
.name
, bl
);
1923 decode(key
.instance
, bl
);
1924 if (key
.ns
.empty() && key
.instance
.empty()) {
1925 if (key
.name
[0] == '_') {
1926 key
.name
= key
.name
.substr(1);
1929 if (struct_v
>= 5) {
1930 decode(key
.name
, bl
);
1932 ssize_t pos
= key
.name
.find('_', 1);
1934 throw buffer::error();
1936 key
.name
= key
.name
.substr(pos
+ 1);
1942 decode(key
.name
, bl
);
1943 decode(key
.instance
, bl
);
1944 // decode(placement_id, bl);
1948 void dump(Formatter
*f
) const;
1949 static void generate_test_instances(list
<rgw_obj
*>& o
);
1951 bool operator==(const rgw_obj
& o
) const {
1952 return (key
== o
.key
) &&
1953 (bucket
== o
.bucket
);
1955 bool operator<(const rgw_obj
& o
) const {
1956 int r
= key
.name
.compare(o
.key
.name
);
1958 r
= bucket
.bucket_id
.compare(o
.bucket
.bucket_id
); /* not comparing bucket.name, if bucket_id is equal so will be bucket.name */
1960 r
= key
.ns
.compare(o
.key
.ns
);
1962 r
= key
.instance
.compare(o
.key
.instance
);
1970 const rgw_pool
& get_explicit_data_pool() {
1971 if (!in_extra_data
|| bucket
.explicit_placement
.data_extra_pool
.empty()) {
1972 return bucket
.explicit_placement
.data_pool
;
1974 return bucket
.explicit_placement
.data_extra_pool
;
1977 WRITE_CLASS_ENCODER(rgw_obj
)
1979 struct rgw_cache_entry_info
{
1980 string cache_locator
;
1983 rgw_cache_entry_info() : gen(0) {}
1986 inline ostream
& operator<<(ostream
& out
, const rgw_obj
&o
) {
1987 return out
<< o
.bucket
.name
<< ":" << o
.get_oid();
1990 static inline void buf_to_hex(const unsigned char* const buf
,
1995 for (size_t i
= 0; i
< len
; i
++) {
1996 ::sprintf(&str
[i
*2], "%02x", static_cast<int>(buf
[i
]));
2000 template<size_t N
> static inline std::array
<char, N
* 2 + 1>
2001 buf_to_hex(const std::array
<unsigned char, N
>& buf
)
2003 static_assert(N
> 0, "The input array must be at least one element long");
2005 std::array
<char, N
* 2 + 1> hex_dest
;
2006 buf_to_hex(buf
.data(), N
, hex_dest
.data());
2010 static inline int hexdigit(char c
)
2012 if (c
>= '0' && c
<= '9')
2015 if (c
>= 'A' && c
<= 'F')
2016 return c
- 'A' + 0xa;
2020 static inline int hex_to_buf(const char *hex
, char *buf
, int len
)
2023 const char *p
= hex
;
2028 int d
= hexdigit(*p
);
2045 static inline int rgw_str_to_bool(const char *s
, int def_val
)
2050 return (strcasecmp(s
, "true") == 0 ||
2051 strcasecmp(s
, "on") == 0 ||
2052 strcasecmp(s
, "yes") == 0 ||
2053 strcasecmp(s
, "1") == 0);
2056 static inline void append_rand_alpha(CephContext
*cct
, const string
& src
, string
& dest
, int len
)
2060 gen_rand_alphanumeric(cct
, buf
, len
);
2065 static inline const char *rgw_obj_category_name(RGWObjCategory category
)
2068 case RGWObjCategory::None
:
2070 case RGWObjCategory::Main
:
2072 case RGWObjCategory::Shadow
:
2073 return "rgw.shadow";
2074 case RGWObjCategory::MultiMeta
:
2075 return "rgw.multimeta";
2081 static inline uint64_t rgw_rounded_kb(uint64_t bytes
)
2083 return (bytes
+ 1023) / 1024;
2086 static inline uint64_t rgw_rounded_objsize(uint64_t bytes
)
2088 return ((bytes
+ 4095) & ~4095);
2091 static inline uint64_t rgw_rounded_objsize_kb(uint64_t bytes
)
2093 return ((bytes
+ 4095) & ~4095) / 1024;
2096 /* implement combining step, S3 header canonicalization; k is a
2097 * valid header and in lc form */
2098 void rgw_add_amz_meta_header(
2099 meta_map_t
& x_meta_map
,
2100 const std::string
& k
,
2101 const std::string
& v
);
2103 extern string
rgw_string_unquote(const string
& s
);
2104 extern void parse_csv_string(const string
& ival
, vector
<string
>& ovals
);
2105 extern int parse_key_value(string
& in_str
, string
& key
, string
& val
);
2106 extern int parse_key_value(string
& in_str
, const char *delim
, string
& key
, string
& val
);
2108 extern boost::optional
<std::pair
<boost::string_view
, boost::string_view
>>
2109 parse_key_value(const boost::string_view
& in_str
,
2110 const boost::string_view
& delim
);
2111 extern boost::optional
<std::pair
<boost::string_view
, boost::string_view
>>
2112 parse_key_value(const boost::string_view
& in_str
);
2116 extern int parse_time(const char *time_str
, real_time
*time
);
2117 extern bool parse_rfc2616(const char *s
, struct tm
*t
);
2118 extern bool parse_iso8601(const char *s
, struct tm
*t
, uint32_t *pns
= NULL
, bool extended_format
= true);
2119 extern string
rgw_trim_whitespace(const string
& src
);
2120 extern boost::string_view
rgw_trim_whitespace(const boost::string_view
& src
);
2121 extern string
rgw_trim_quotes(const string
& val
);
2123 extern void rgw_to_iso8601(const real_time
& t
, char *dest
, int buf_size
);
2124 extern void rgw_to_iso8601(const real_time
& t
, string
*dest
);
2125 extern std::string
rgw_to_asctime(const utime_t
& t
);
2127 struct perm_state_base
{
2129 const rgw::IAM::Environment
& env
;
2130 rgw::auth::Identity
*identity
;
2131 const RGWBucketInfo
& bucket_info
;
2133 bool defer_to_bucket_acls
;
2134 boost::optional
<PublicAccessBlockConfiguration
> bucket_access_conf
;
2136 perm_state_base(CephContext
*_cct
,
2137 const rgw::IAM::Environment
& _env
,
2138 rgw::auth::Identity
*_identity
,
2139 const RGWBucketInfo
& _bucket_info
,
2141 bool _defer_to_bucket_acls
,
2142 boost::optional
<PublicAccessBlockConfiguration
> _bucket_acess_conf
= boost::none
) :
2145 identity(_identity
),
2146 bucket_info(_bucket_info
),
2147 perm_mask(_perm_mask
),
2148 defer_to_bucket_acls(_defer_to_bucket_acls
),
2149 bucket_access_conf(_bucket_acess_conf
)
2152 virtual ~perm_state_base() {}
2154 virtual const char *get_referer() const = 0;
2155 virtual std::optional
<bool> get_request_payer() const = 0; /*
2156 * empty state means that request_payer param was not passed in
2161 struct perm_state
: public perm_state_base
{
2162 const char *referer
;
2165 perm_state(CephContext
*_cct
,
2166 const rgw::IAM::Environment
& _env
,
2167 rgw::auth::Identity
*_identity
,
2168 const RGWBucketInfo
& _bucket_info
,
2170 bool _defer_to_bucket_acls
,
2171 const char *_referer
,
2172 bool _request_payer
) : perm_state_base(_cct
,
2177 _defer_to_bucket_acls
),
2179 request_payer(_request_payer
) {}
2181 const char *get_referer() const override
{
2185 std::optional
<bool> get_request_payer() const override
{
2186 return request_payer
;
2190 /** Check if the req_state's user has the necessary permissions
2191 * to do the requested action */
2192 bool verify_bucket_permission_no_policy(
2193 const DoutPrefixProvider
* dpp
,
2194 struct perm_state_base
* const s
,
2195 RGWAccessControlPolicy
* const user_acl
,
2196 RGWAccessControlPolicy
* const bucket_acl
,
2199 bool verify_user_permission_no_policy(const DoutPrefixProvider
* dpp
,
2200 struct perm_state_base
* const s
,
2201 RGWAccessControlPolicy
* const user_acl
,
2204 bool verify_object_permission_no_policy(const DoutPrefixProvider
* dpp
,
2205 struct perm_state_base
* const s
,
2206 RGWAccessControlPolicy
* const user_acl
,
2207 RGWAccessControlPolicy
* const bucket_acl
,
2208 RGWAccessControlPolicy
* const object_acl
,
2211 /** Check if the req_state's user has the necessary permissions
2212 * to do the requested action */
2213 rgw::IAM::Effect
eval_user_policies(const vector
<rgw::IAM::Policy
>& user_policies
,
2214 const rgw::IAM::Environment
& env
,
2215 boost::optional
<const rgw::auth::Identity
&> id
,
2217 const rgw::ARN
& arn
);
2218 bool verify_user_permission(const DoutPrefixProvider
* dpp
,
2219 struct req_state
* const s
,
2220 RGWAccessControlPolicy
* const user_acl
,
2221 const vector
<rgw::IAM::Policy
>& user_policies
,
2222 const rgw::ARN
& res
,
2224 bool verify_user_permission_no_policy(const DoutPrefixProvider
* dpp
,
2225 struct req_state
* const s
,
2226 RGWAccessControlPolicy
* const user_acl
,
2228 bool verify_user_permission(const DoutPrefixProvider
* dpp
,
2229 struct req_state
* const s
,
2230 const rgw::ARN
& res
,
2232 bool verify_user_permission_no_policy(const DoutPrefixProvider
* dpp
,
2233 struct req_state
* const s
,
2235 bool verify_bucket_permission(
2236 const DoutPrefixProvider
* dpp
,
2237 struct req_state
* const s
,
2238 const rgw_bucket
& bucket
,
2239 RGWAccessControlPolicy
* const user_acl
,
2240 RGWAccessControlPolicy
* const bucket_acl
,
2241 const boost::optional
<rgw::IAM::Policy
>& bucket_policy
,
2242 const vector
<rgw::IAM::Policy
>& user_policies
,
2244 bool verify_bucket_permission(const DoutPrefixProvider
* dpp
, struct req_state
* const s
, const uint64_t op
);
2245 bool verify_bucket_permission_no_policy(
2246 const DoutPrefixProvider
* dpp
,
2247 struct req_state
* const s
,
2248 RGWAccessControlPolicy
* const user_acl
,
2249 RGWAccessControlPolicy
* const bucket_acl
,
2251 bool verify_bucket_permission_no_policy(const DoutPrefixProvider
* dpp
,
2252 struct req_state
* const s
,
2254 int verify_bucket_owner_or_policy(struct req_state
* const s
,
2256 extern bool verify_object_permission(
2257 const DoutPrefixProvider
* dpp
,
2258 struct req_state
* const s
,
2260 RGWAccessControlPolicy
* const user_acl
,
2261 RGWAccessControlPolicy
* const bucket_acl
,
2262 RGWAccessControlPolicy
* const object_acl
,
2263 const boost::optional
<rgw::IAM::Policy
>& bucket_policy
,
2264 const vector
<rgw::IAM::Policy
>& user_policies
,
2266 extern bool verify_object_permission(const DoutPrefixProvider
* dpp
, struct req_state
*s
, uint64_t op
);
2267 extern bool verify_object_permission_no_policy(
2268 const DoutPrefixProvider
* dpp
,
2269 struct req_state
* const s
,
2270 RGWAccessControlPolicy
* const user_acl
,
2271 RGWAccessControlPolicy
* const bucket_acl
,
2272 RGWAccessControlPolicy
* const object_acl
,
2274 extern bool verify_object_permission_no_policy(const DoutPrefixProvider
* dpp
, struct req_state
*s
,
2276 /** Convert an input URL into a sane object name
2277 * by converting %-escaped strings into characters, etc*/
2278 extern void rgw_uri_escape_char(char c
, string
& dst
);
2279 extern std::string
url_decode(const boost::string_view
& src_str
,
2280 bool in_query
= false);
2281 extern void url_encode(const std::string
& src
, string
& dst
,
2282 bool encode_slash
= true);
2283 extern std::string
url_encode(const std::string
& src
, bool encode_slash
= true);
2284 extern std::string
url_remove_prefix(const std::string
& url
); // Removes hhtp, https and www from url
2285 /* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */
2286 extern void calc_hmac_sha1(const char *key
, int key_len
,
2287 const char *msg
, int msg_len
, char *dest
);
2289 static inline sha1_digest_t
2290 calc_hmac_sha1(const boost::string_view
& key
, const boost::string_view
& msg
) {
2292 calc_hmac_sha1(key
.data(), key
.size(), msg
.data(), msg
.size(),
2293 reinterpret_cast<char*>(dest
.v
));
2297 /* destination should be CEPH_CRYPTO_HMACSHA256_DIGESTSIZE bytes long */
2298 extern void calc_hmac_sha256(const char *key
, int key_len
,
2299 const char *msg
, int msg_len
,
2302 static inline sha256_digest_t
2303 calc_hmac_sha256(const char *key
, const int key_len
,
2304 const char *msg
, const int msg_len
) {
2305 sha256_digest_t dest
;
2306 calc_hmac_sha256(key
, key_len
, msg
, msg_len
,
2307 reinterpret_cast<char*>(dest
.v
));
2311 static inline sha256_digest_t
2312 calc_hmac_sha256(const boost::string_view
& key
, const boost::string_view
& msg
) {
2313 sha256_digest_t dest
;
2314 calc_hmac_sha256(key
.data(), key
.size(),
2315 msg
.data(), msg
.size(),
2316 reinterpret_cast<char*>(dest
.v
));
2320 static inline sha256_digest_t
2321 calc_hmac_sha256(const sha256_digest_t
&key
,
2322 const boost::string_view
& msg
) {
2323 sha256_digest_t dest
;
2324 calc_hmac_sha256(reinterpret_cast<const char*>(key
.v
), sha256_digest_t::SIZE
,
2325 msg
.data(), msg
.size(),
2326 reinterpret_cast<char*>(dest
.v
));
2330 static inline sha256_digest_t
2331 calc_hmac_sha256(const std::vector
<unsigned char>& key
,
2332 const boost::string_view
& msg
) {
2333 sha256_digest_t dest
;
2334 calc_hmac_sha256(reinterpret_cast<const char*>(key
.data()), key
.size(),
2335 msg
.data(), msg
.size(),
2336 reinterpret_cast<char*>(dest
.v
));
2340 template<size_t KeyLenN
>
2341 static inline sha256_digest_t
2342 calc_hmac_sha256(const std::array
<unsigned char, KeyLenN
>& key
,
2343 const boost::string_view
& msg
) {
2344 sha256_digest_t dest
;
2345 calc_hmac_sha256(reinterpret_cast<const char*>(key
.data()), key
.size(),
2346 msg
.data(), msg
.size(),
2347 reinterpret_cast<char*>(dest
.v
));
2351 extern sha256_digest_t
calc_hash_sha256(const boost::string_view
& msg
);
2353 extern ceph::crypto::SHA256
* calc_hash_sha256_open_stream();
2354 extern void calc_hash_sha256_update_stream(ceph::crypto::SHA256
* hash
,
2357 extern std::string
calc_hash_sha256_close_stream(ceph::crypto::SHA256
** phash
);
2358 extern std::string
calc_hash_sha256_restart_stream(ceph::crypto::SHA256
** phash
);
2360 extern int rgw_parse_op_type_list(const string
& str
, uint32_t *perm
);
2362 static constexpr uint32_t MATCH_POLICY_ACTION
= 0x01;
2363 static constexpr uint32_t MATCH_POLICY_RESOURCE
= 0x02;
2364 static constexpr uint32_t MATCH_POLICY_ARN
= 0x04;
2365 static constexpr uint32_t MATCH_POLICY_STRING
= 0x08;
2367 extern bool match_policy(boost::string_view pattern
, boost::string_view input
,
2370 extern string
camelcase_dash_http_attr(const string
& orig
);
2371 extern string
lowercase_dash_http_attr(const string
& orig
);
2373 void rgw_setup_saved_curl_handles();
2374 void rgw_release_all_curl_handles();
2376 static inline void rgw_escape_str(const string
& s
, char esc_char
,
2377 char special_char
, string
*dest
)
2379 const char *src
= s
.c_str();
2380 char dest_buf
[s
.size() * 2 + 1];
2381 char *destp
= dest_buf
;
2383 for (size_t i
= 0; i
< s
.size(); i
++) {
2385 if (c
== esc_char
|| c
== special_char
) {
2386 *destp
++ = esc_char
;
2394 static inline ssize_t
rgw_unescape_str(const string
& s
, ssize_t ofs
,
2395 char esc_char
, char special_char
,
2398 const char *src
= s
.c_str();
2399 char dest_buf
[s
.size() + 1];
2400 char *destp
= dest_buf
;
2405 for (size_t i
= ofs
; i
< s
.size(); i
++) {
2407 if (!esc
&& c
== esc_char
) {
2411 if (!esc
&& c
== special_char
) {
2414 return (ssize_t
)i
+ 1;
2421 return string::npos
;
2424 static inline string
rgw_bl_str(ceph::buffer::list
& raw
)
2426 size_t len
= raw
.length();
2427 string
s(raw
.c_str(), len
);
2428 while (len
&& !s
[len
- 1]) {
2435 template <typename T
>
2436 int decode_bl(bufferlist
& bl
, T
& t
)
2438 auto iter
= bl
.cbegin();
2441 } catch (buffer::error
& err
) {