#include <map>
#include "include/types.h"
+#include "common/split.h"
#include "rgw_acl_s3.h"
#include "rgw_user.h"
const char *http_header;
};
-static const char *get_acl_header(const RGWEnv *env,
- const struct s3_acl_header *perm)
-{
- const char *header = perm->http_header;
-
- return env->get(header, NULL);
-}
-
-static int parse_grantee_str(const DoutPrefixProvider *dpp, rgw::sal::Driver* driver, string& grantee_str,
- const struct s3_acl_header *perm, ACLGrant& grant)
+static int parse_grantee_str(const DoutPrefixProvider* dpp,
+ rgw::sal::Driver* driver,
+ const std::string& grantee_str,
+ const s3_acl_header* perm,
+ ACLGrant& grant)
{
string id_type, id_val_quoted;
int rgw_perm = perm->rgw_perm;
return 0;
}
-static int parse_acl_header(const DoutPrefixProvider *dpp, rgw::sal::Driver* driver,
- const RGWEnv *env, const struct s3_acl_header *perm,
- std::list<ACLGrant>& _grants)
+static int parse_acl_header(const DoutPrefixProvider* dpp, rgw::sal::Driver* driver,
+ const RGWEnv& env, const s3_acl_header* perm,
+ RGWAccessControlList& acl)
{
- std::list<string> grantees;
- std::string hacl_str;
-
- const char *hacl = get_acl_header(env, perm);
- if (hacl == NULL)
+ const char* hacl = env.get(perm->http_header, nullptr);
+ if (hacl == nullptr) {
return 0;
+ }
- hacl_str = hacl;
- get_str_list(hacl_str, ",", grantees);
-
- for (list<string>::iterator it = grantees.begin(); it != grantees.end(); ++it) {
+ for (std::string_view grantee : ceph::split(hacl, ",")) {
ACLGrant grant;
- int ret = parse_grantee_str(dpp, driver, *it, perm, grant);
+ int ret = parse_grantee_str(dpp, driver, std::string{grantee}, perm, grant);
if (ret < 0)
return ret;
- _grants.push_back(grant);
+ acl.add_grant(grant);
}
return 0;
return 0;
}
-int RGWAccessControlList_S3::create_from_grants(std::list<ACLGrant>& grants)
-{
- if (grants.empty())
- return -EINVAL;
-
- acl_user_map.clear();
- grant_map.clear();
-
- for (const auto& g : grants) {
- add_grant(g);
- }
-
- return 0;
-}
-
bool RGWAccessControlPolicy_S3::xml_end(const char *el) {
RGWAccessControlList_S3 *s3acl =
static_cast<RGWAccessControlList_S3 *>(find_first("AccessControlList"));
{0, NULL}
};
-int RGWAccessControlPolicy_S3::create_from_headers(const DoutPrefixProvider *dpp,
- rgw::sal::Driver* driver,
- const RGWEnv *env, ACLOwner& _owner)
-{
- std::list<ACLGrant> grants;
- int r = 0;
-
- for (const struct s3_acl_header *p = acl_header_perms; p->rgw_perm; p++) {
- r = parse_acl_header(dpp, driver, env, p, grants);
- if (r < 0) {
- return r;
- }
- }
-
- RGWAccessControlList_S3& _acl = static_cast<RGWAccessControlList_S3 &>(acl);
- r = _acl.create_from_grants(grants);
-
- owner = _owner;
-
- return r;
-}
-
/*
can only be called on object that was parsed
*/
return create_canned(owner, bucket_owner, canned_acl, policy.get_acl());
}
+int create_policy_from_headers(const DoutPrefixProvider* dpp,
+ rgw::sal::Driver* driver,
+ const ACLOwner& owner,
+ const RGWEnv& env,
+ RGWAccessControlPolicy& policy)
+{
+ policy.set_owner(owner);
+ auto& acl = policy.get_acl();
+
+ for (const s3_acl_header* p = acl_header_perms; p->rgw_perm; p++) {
+ int r = parse_acl_header(dpp, driver, env, p, acl);
+ if (r < 0) {
+ return r;
+ }
+ }
+
+ return 0;
+}
+
} // namespace rgw::s3
public:
bool xml_end(const char *el) override;
void to_xml(const DoutPrefixProvider* dpp, std::ostream& out);
-
- int create_from_grants(std::list<ACLGrant>& grants);
};
class ACLOwner_S3 : public ACLOwner, public XMLObj
void to_xml(const DoutPrefixProvider* dpp, std::ostream& out);
int rebuild(const DoutPrefixProvider *dpp, rgw::sal::Driver* driver, ACLOwner *owner,
RGWAccessControlPolicy& dest, std::string &err_msg);
-
- int create_from_headers(const DoutPrefixProvider *dpp, rgw::sal::Driver* driver,
- const RGWEnv *env, ACLOwner& _owner);
};
/**
const std::string& canned_acl,
RGWAccessControlPolicy& policy);
+/// Construct a policy from x-amz-grant-* request headers.
+int create_policy_from_headers(const DoutPrefixProvider* dpp,
+ rgw::sal::Driver* driver,
+ const ACLOwner& owner,
+ const RGWEnv& env,
+ RGWAccessControlPolicy& policy);
+
} // namespace rgw::s3
extern std::string rgw_string_unquote(const std::string& s);
extern void parse_csv_string(const std::string& ival, std::vector<std::string>& ovals);
-extern int parse_key_value(std::string& in_str, std::string& key, std::string& val);
-extern int parse_key_value(std::string& in_str, const char *delim, std::string& key, std::string& val);
+extern int parse_key_value(const std::string& in_str, std::string& key, std::string& val);
+extern int parse_key_value(const std::string& in_str, const char *delim, std::string& key, std::string& val);
extern boost::optional<std::pair<std::string_view,std::string_view>>
parse_key_value(const std::string_view& in_str,