Skip to content

Commit

Permalink
Merge pull request #10520: jewel: radosgw-admin: inconsistency in uid…
Browse files Browse the repository at this point in the history
…/email handling

Reviewed-by: Loic Dachary <ldachary@redhat.com>
  • Loading branch information
Loic Dachary committed Aug 8, 2016
2 parents 7a00e9f + 67eb961 commit c83d0e0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/rgw/rgw_user.cc
Expand Up @@ -5,6 +5,7 @@

#include <string>
#include <map>
#include <boost/algorithm/string.hpp>

#include "common/errno.h"
#include "common/Formatter.h"
Expand Down Expand Up @@ -1877,13 +1878,15 @@ int RGWUser::execute_add(RGWUserAdminOpState& op_state, std::string *err_msg)
// fail if the user exists already
if (op_state.has_existing_user()) {
if (!op_state.exclusive &&
(user_email.empty() || old_info.user_email == user_email) &&
(user_email.empty() ||
boost::iequals(user_email, old_info.user_email)) &&
old_info.display_name == display_name) {
return execute_modify(op_state, err_msg);
}

if (op_state.found_by_email) {
set_err_msg(err_msg, "email: " + user_email + " exists");
set_err_msg(err_msg, "email: " + user_email +
" is the email address an existing user");
ret = -ERR_EMAIL_EXIST;
} else if (op_state.found_by_key) {
set_err_msg(err_msg, "duplicate key provided");
Expand Down
25 changes: 25 additions & 0 deletions src/rgw/rgw_user.h
Expand Up @@ -5,6 +5,8 @@
#define CEPH_RGW_USER_H

#include <string>
#include <boost/algorithm/string.hpp>
#include "include/assert.h"

#include "include/types.h"
#include "rgw_common.h"
Expand Down Expand Up @@ -225,6 +227,7 @@ struct RGWUserAdminOpState {
gen_access = false;
key_op = true;
}

void set_secret_key(std::string& secret_key) {
if (secret_key.empty())
return;
Expand All @@ -234,26 +237,32 @@ struct RGWUserAdminOpState {
gen_secret = false;
key_op = true;
}

void set_user_id(rgw_user& id) {
if (id.empty())
return;

user_id = id;
}

void set_user_email(std::string& email) {
if (email.empty())
return;

/* always lowercase email address */
boost::algorithm::to_lower(email);
user_email = email;
user_email_specified = true;
}

void set_display_name(std::string& name) {
if (name.empty())
return;

display_name = name;
display_name_specified = true;
}

void set_subuser(std::string& _subuser) {
if (_subuser.empty())
return;
Expand All @@ -274,70 +283,86 @@ struct RGWUserAdminOpState {

subuser_specified = true;
}

void set_caps(std::string& _caps) {
if (_caps.empty())
return;

caps = _caps;
caps_specified = true;
}

void set_perm(uint32_t perm) {
perm_mask = perm;
perm_specified = true;
}

void set_op_mask(uint32_t mask) {
op_mask = mask;
op_mask_specified = true;
}

void set_temp_url_key(const string& key, int index) {
temp_url_keys[index] = key;
temp_url_key_specified = true;
}

void set_key_type(int32_t type) {
key_type = type;
type_specified = true;
}

void set_suspension(__u8 is_suspended) {
suspended = is_suspended;
suspension_op = true;
}

void set_system(__u8 is_system) {
system = is_system;
system_specified = true;
}

void set_exclusive(__u8 is_exclusive) {
exclusive = is_exclusive;
}

void set_fetch_stats(__u8 is_fetch_stats) {
fetch_stats = is_fetch_stats;
}

void set_user_info(RGWUserInfo& user_info) {
user_id = user_info.user_id;
info = user_info;
}

void set_max_buckets(uint32_t mb) {
max_buckets = mb;
max_buckets_specified = true;
}

void set_gen_access() {
gen_access = true;
key_op = true;
}

void set_gen_secret() {
gen_secret = true;
key_op = true;
}

void set_generate_key() {
if (id.empty())
gen_access = true;
if (key.empty())
gen_secret = true;
key_op = true;
}

void clear_generate_key() {
gen_access = false;
gen_secret = false;
}

void set_purge_keys() {
purge_keys = true;
key_op = true;
Expand Down

0 comments on commit c83d0e0

Please sign in to comment.