From d08ef701e1b6af148c47b60dd2ab6b15692eeba5 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Fri, 2 Apr 2010 16:25:00 -0700 Subject: [PATCH] rgw: radosgw_admin can delete users from the system --- src/rgw/rgw_admin.cc | 13 +++++++++++-- src/rgw/rgw_rados.cc | 2 +- src/rgw/rgw_user.cc | 22 ++++++++++++++++++++++ src/rgw/rgw_user.h | 5 ++++- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index fd29c02a1a0f0..fc092563e14e5 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -75,6 +75,9 @@ int gen_rand_alphanumeric(char *dest, int size) /* size should be the required s return 0; } + + + int main(int argc, char **argv) { DEFINE_CONF_VARS(usage); @@ -93,6 +96,7 @@ int main(int argc, char **argv) bool mod_user = false; bool read_policy = false; bool list_buckets = false; + bool delete_user = false; int actions = 0 ; __u64 auid = 0; RGWUserInfo info; @@ -123,6 +127,8 @@ int main(int argc, char **argv) CONF_SAFE_SET_ARG_VAL(&object, OPT_STR); } else if (CONF_ARG_EQ("auth_uid", 'a')) { CONF_SAFE_SET_ARG_VAL(&auid, OPT_LONGLONG); + } else if (CONF_ARG_EQ("delete_user", 'd')) { + delete_user = true; } else { cerr << "unrecognized arg " << args[i] << std::endl; ARGS_USAGE(); @@ -256,10 +262,13 @@ int main(int argc, char **argv) } } + if (delete_user) { + ++actions; + rgw_delete_user(info); + } + if (!actions) ARGS_USAGE(); return 0; } - - diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index a49f40cdd1585..fb62e6b83bb7e 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -16,7 +16,7 @@ using namespace std; static Rados *rados = NULL; -#define ROOT_BUCKET ".rgw" +#define ROOT_BUCKET ".rgw" //keep this synced to rgw_user.cc::root_bucket! static string root_bucket(ROOT_BUCKET); static rados_pool_t root_pool; diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index 6723b517dcc5c..6d7000c41c52e 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -13,6 +13,7 @@ using namespace std; static string ui_bucket = USER_INFO_BUCKET_NAME; static string ui_email_bucket = USER_INFO_EMAIL_BUCKET_NAME; +static string root_bucket = ".rgw"; //keep this synced to rgw_rados.cc::ROOT_BUCKET! /** * Get the info for a user out of storage. @@ -148,3 +149,24 @@ int rgw_put_user_buckets(string user_id, RGWUserBuckets& buckets) return ret; } + +/** + * delete a user's presence from the RGW system. + * First remove their bucket ACLs, then delete them + * from the user and user email pools. This leaves the pools + * themselves alone, as well as any ACLs embedded in object xattrs. + */ +int rgw_delete_user(RGWUserInfo& info) { + RGWUserBuckets user_buckets; + rgw_get_user_buckets(info.user_id, user_buckets); + map& buckets = user_buckets.get_buckets(); + for (map::iterator i = buckets.begin(); + i != buckets.end(); + ++i) { + string bucket_name = i->first; + rgwstore->delete_obj(info.user_id, root_bucket, bucket_name); + } + rgwstore->delete_obj(info.user_id, ui_bucket, info.user_id); + rgwstore->delete_obj(info.user_id, ui_email_bucket, info.user_email); + return 0; +} diff --git a/src/rgw/rgw_user.h b/src/rgw/rgw_user.h index 86bd762d1dd32..98ce1bdac2e77 100644 --- a/src/rgw/rgw_user.h +++ b/src/rgw/rgw_user.h @@ -47,7 +47,10 @@ extern int rgw_store_user_info(RGWUserInfo& info); * returns: 0 on success, -ERR# on failure (including nonexistence) */ extern int rgw_get_uid_by_email(string& email, string& user_id); - +/** + * Given an RGWUserInfo, deletes the user and its bucket ACLs. + */ +extern int rgw_delete_user(RGWUserInfo& user); /** * Store a list of the user's buckets, with associated functinos. */ -- 2.47.3