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) 2019 Red Hat, Inc.
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
16 /* N.B., this header defines fundamental serialized types. Do not
17 * introduce changes or include files which can only be compiled in
18 * radosgw or OSD contexts (e.g., rgw_sal.h, rgw_common.h)
25 #include <fmt/format.h>
27 #include "include/types.h"
28 #include "common/Formatter.h"
30 #define RGW_PERM_NONE 0x00
31 #define RGW_PERM_READ 0x01
32 #define RGW_PERM_WRITE 0x02
33 #define RGW_PERM_READ_ACP 0x04
34 #define RGW_PERM_WRITE_ACP 0x08
35 #define RGW_PERM_READ_OBJS 0x10
36 #define RGW_PERM_WRITE_OBJS 0x20
37 #define RGW_PERM_FULL_CONTROL ( RGW_PERM_READ | RGW_PERM_WRITE | \
38 RGW_PERM_READ_ACP | RGW_PERM_WRITE_ACP )
39 #define RGW_PERM_ALL_S3 RGW_PERM_FULL_CONTROL
40 #define RGW_PERM_INVALID 0xFF00
42 static constexpr char RGW_REFERER_WILDCARD
[] = "*";
45 std::string id
; // AccessKey
46 std::string key
; // SecretKey
50 RGWAccessKey(std::string _id
, std::string _key
)
51 : id(std::move(_id
)), key(std::move(_key
)) {}
53 void encode(bufferlist
& bl
) const {
54 ENCODE_START(2, 2, bl
);
61 void decode(bufferlist::const_iterator
& bl
) {
62 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
68 void dump(Formatter
*f
) const;
69 void dump_plain(Formatter
*f
) const;
70 void dump(Formatter
*f
, const std::string
& user
, bool swift
) const;
71 static void generate_test_instances(std::list
<RGWAccessKey
*>& o
);
73 void decode_json(JSONObj
*obj
);
74 void decode_json(JSONObj
*obj
, bool swift
);
76 WRITE_CLASS_ENCODER(RGWAccessKey
)
82 RGWSubUser() : perm_mask(0) {}
83 void encode(bufferlist
& bl
) const {
84 ENCODE_START(2, 2, bl
);
86 encode(perm_mask
, bl
);
90 void decode(bufferlist::const_iterator
& bl
) {
91 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
93 decode(perm_mask
, bl
);
96 void dump(Formatter
*f
) const;
97 void dump(Formatter
*f
, const std::string
& user
) const;
98 static void generate_test_instances(std::list
<RGWSubUser
*>& o
);
100 void decode_json(JSONObj
*obj
);
102 WRITE_CLASS_ENCODER(RGWSubUser
)
106 std::map
<std::string
, uint32_t> caps
;
108 int get_cap(const std::string
& cap
, std::string
& type
, uint32_t *perm
);
109 int add_cap(const std::string
& cap
);
110 int remove_cap(const std::string
& cap
);
112 static int parse_cap_perm(const std::string
& str
, uint32_t *perm
);
113 int add_from_string(const std::string
& str
);
114 int remove_from_string(const std::string
& str
);
116 void encode(bufferlist
& bl
) const {
117 ENCODE_START(1, 1, bl
);
121 void decode(bufferlist::const_iterator
& bl
) {
126 int check_cap(const std::string
& cap
, uint32_t perm
) const;
127 bool is_valid_cap_type(const std::string
& tp
);
128 void dump(Formatter
*f
) const;
129 void dump(Formatter
*f
, const char *name
) const;
131 void decode_json(JSONObj
*obj
);
133 WRITE_CLASS_ENCODER(RGWUserCaps
)
135 enum ACLGranteeTypeEnum
{
136 /* numbers are encoded, should not change */
137 ACL_TYPE_CANON_USER
= 0,
138 ACL_TYPE_EMAIL_USER
= 1,
140 ACL_TYPE_UNKNOWN
= 3,
141 ACL_TYPE_REFERER
= 4,
144 enum ACLGroupTypeEnum
{
145 /* numbers are encoded should not change */
147 ACL_GROUP_ALL_USERS
= 1,
148 ACL_GROUP_AUTHENTICATED_USERS
= 2,
156 ACLPermission() : flags(0) {}
158 uint32_t get_permissions() const { return flags
; }
159 void set_permissions(uint32_t perm
) { flags
= perm
; }
161 void encode(bufferlist
& bl
) const {
162 ENCODE_START(2, 2, bl
);
166 void decode(bufferlist::const_iterator
& bl
) {
167 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl
);
171 void dump(Formatter
*f
) const;
172 static void generate_test_instances(std::list
<ACLPermission
*>& o
);
174 friend bool operator==(const ACLPermission
& lhs
, const ACLPermission
& rhs
);
175 friend bool operator!=(const ACLPermission
& lhs
, const ACLPermission
& rhs
);
177 WRITE_CLASS_ENCODER(ACLPermission
)
184 ACLGranteeType() : type(ACL_TYPE_UNKNOWN
) {}
185 virtual ~ACLGranteeType() {}
186 // virtual const char *to_string() = 0;
187 ACLGranteeTypeEnum
get_type() const { return (ACLGranteeTypeEnum
)type
; }
188 void set(ACLGranteeTypeEnum t
) { type
= t
; }
189 // virtual void set(const char *s) = 0;
190 void encode(bufferlist
& bl
) const {
191 ENCODE_START(2, 2, bl
);
195 void decode(bufferlist::const_iterator
& bl
) {
196 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl
);
200 void dump(Formatter
*f
) const;
201 static void generate_test_instances(std::list
<ACLGranteeType
*>& o
);
203 friend bool operator==(const ACLGranteeType
& lhs
, const ACLGranteeType
& rhs
);
204 friend bool operator!=(const ACLGranteeType
& lhs
, const ACLGranteeType
& rhs
);
206 WRITE_CLASS_ENCODER(ACLGranteeType
)