MXS-1354: Rename user account type enum
Renamed the enum and its values.
This commit is contained in:
parent
6ee7ed6a38
commit
9f81f0775f
@ -74,11 +74,11 @@ typedef struct admin_session
|
||||
|
||||
void admin_users_init();
|
||||
|
||||
const char* admin_enable_linux_account(const char *uname, enum account_type type);
|
||||
const char* admin_enable_linux_account(const char *uname, enum user_account_type type);
|
||||
const char* admin_disable_linux_account(const char *uname);
|
||||
bool admin_linux_account_enabled(const char *uname);
|
||||
|
||||
const char* admin_add_inet_user(const char *uname, const char *password, enum account_type type);
|
||||
const char* admin_add_inet_user(const char *uname, const char *password, enum user_account_type type);
|
||||
const char* admin_remove_inet_user(const char* uname);
|
||||
bool admin_inet_user_exists(const char *uname);
|
||||
bool admin_verify_inet_user(const char *uname, const char *password);
|
||||
|
@ -27,11 +27,11 @@
|
||||
MXS_BEGIN_DECLS
|
||||
|
||||
/** User account types */
|
||||
enum account_type
|
||||
enum user_account_type
|
||||
{
|
||||
ACCOUNT_UNKNOWN,
|
||||
ACCOUNT_BASIC, /**< Allows read-only access */
|
||||
ACCOUNT_ADMIN /**< Allows complete access */
|
||||
USER_ACCOUNT_UNKNOWN,
|
||||
USER_ACCOUNT_BASIC, /**< Allows read-only access */
|
||||
USER_ACCOUNT_ADMIN /**< Allows complete access */
|
||||
};
|
||||
|
||||
/**
|
||||
@ -65,7 +65,7 @@ void users_free(USERS* users);
|
||||
*
|
||||
* @return True if user was added
|
||||
*/
|
||||
bool users_add(USERS *users, const char *user, const char *password, enum account_type type);
|
||||
bool users_add(USERS *users, const char *user, const char *password, enum user_account_type type);
|
||||
|
||||
/**
|
||||
* Delete a user from the user table.
|
||||
@ -186,7 +186,7 @@ json_t* users_diagnostic_json(USERS* users);
|
||||
*
|
||||
* @return String representation of @c type
|
||||
*/
|
||||
const char* account_type_to_str(enum account_type type);
|
||||
const char* account_type_to_str(enum user_account_type type);
|
||||
|
||||
/**
|
||||
* Convert JSON value to account_type value
|
||||
@ -195,6 +195,6 @@ const char* account_type_to_str(enum account_type type);
|
||||
*
|
||||
* @return Enum value of @c json
|
||||
*/
|
||||
enum account_type json_to_account_type(json_t* json);
|
||||
enum user_account_type json_to_account_type(json_t* json);
|
||||
|
||||
MXS_END_DECLS
|
||||
|
@ -80,7 +80,7 @@ static bool admin_dump_users(USERS* users, const char* fname)
|
||||
|
||||
static const char *admin_add_user(USERS** pusers, const char* fname,
|
||||
const char* uname, const char* password,
|
||||
account_type type)
|
||||
user_account_type type)
|
||||
{
|
||||
if (*pusers == NULL)
|
||||
{
|
||||
@ -122,7 +122,8 @@ static const char* admin_remove_user(USERS *users, const char* fname, const char
|
||||
return ADMIN_SUCCESS;
|
||||
}
|
||||
|
||||
static json_t* admin_user_json_data(const char* host, const char* user, enum user_type user_type, enum account_type account)
|
||||
static json_t* admin_user_json_data(const char* host, const char* user, enum user_type user_type,
|
||||
enum user_account_type account)
|
||||
{
|
||||
ss_dassert(user_type != USER_TYPE_ALL);
|
||||
const char* type = user_type == USER_TYPE_INET ? CN_INET : CN_UNIX;
|
||||
@ -151,7 +152,7 @@ static void user_types_to_json(USERS* users, json_t* arr, const char* host, enum
|
||||
json_array_foreach(json, index, value)
|
||||
{
|
||||
const char* user = json_string_value(json_object_get(value, CN_NAME));
|
||||
enum account_type account = json_to_account_type(json_object_get(value, CN_ACCOUNT));
|
||||
enum user_account_type account = json_to_account_type(json_object_get(value, CN_ACCOUNT));
|
||||
json_array_append_new(arr, admin_user_json_data(host, user, type, account));
|
||||
}
|
||||
|
||||
@ -176,7 +177,7 @@ static std::string path_from_type(enum user_type type)
|
||||
|
||||
json_t* admin_user_to_json(const char* host, const char* user, enum user_type type)
|
||||
{
|
||||
account_type account = admin_is_admin_user(user) ? ACCOUNT_ADMIN : ACCOUNT_BASIC;
|
||||
user_account_type account = admin_is_admin_user(user) ? USER_ACCOUNT_ADMIN : USER_ACCOUNT_BASIC;
|
||||
std::string path = path_from_type(type);
|
||||
path += "/";
|
||||
path += user;
|
||||
@ -244,7 +245,7 @@ USERS* load_legacy_users(FILE* fp)
|
||||
password = "";
|
||||
}
|
||||
|
||||
if (users_add(rval, uname, password, ACCOUNT_ADMIN))
|
||||
if (users_add(rval, uname, password, USER_ACCOUNT_ADMIN))
|
||||
{
|
||||
added_users++;
|
||||
}
|
||||
@ -340,7 +341,7 @@ static USERS *load_inet_users()
|
||||
*
|
||||
* @return NULL on success or an error string on failure.
|
||||
*/
|
||||
const char *admin_enable_linux_account(const char *uname, enum account_type type)
|
||||
const char *admin_enable_linux_account(const char *uname, enum user_account_type type)
|
||||
{
|
||||
return admin_add_user(&linux_users, LINUX_USERS_FILE_NAME, uname, NULL, type);
|
||||
}
|
||||
@ -406,7 +407,7 @@ void mxs_crypt(const char* password, const char* salt, char* output)
|
||||
*
|
||||
* @return NULL on success or an error string on failure.
|
||||
*/
|
||||
const char *admin_add_inet_user(const char *uname, const char* password, enum account_type type)
|
||||
const char *admin_add_inet_user(const char *uname, const char* password, enum user_account_type type)
|
||||
{
|
||||
char cpassword[MXS_CRYPT_SIZE];
|
||||
mxs_crypt(password, ADMIN_SALT, cpassword);
|
||||
|
@ -1750,7 +1750,7 @@ bool validate_user_json(json_t* json)
|
||||
{
|
||||
runtime_error("The '%s' field is not a string", MXS_JSON_PTR_ACCOUNT);
|
||||
}
|
||||
else if (json_to_account_type(account) == ACCOUNT_UNKNOWN)
|
||||
else if (json_to_account_type(account) == USER_ACCOUNT_UNKNOWN)
|
||||
{
|
||||
runtime_error("The '%s' field is not a valid account value", MXS_JSON_PTR_ACCOUNT);
|
||||
}
|
||||
@ -1794,7 +1794,7 @@ bool runtime_create_user_from_json(json_t* json)
|
||||
const char* user = json_string_value(mxs_json_pointer(json, MXS_JSON_PTR_ID));
|
||||
const char* password = json_string_value(mxs_json_pointer(json, MXS_JSON_PTR_PASSWORD));
|
||||
string strtype = json_string_value(mxs_json_pointer(json, MXS_JSON_PTR_TYPE));
|
||||
account_type type = json_to_account_type(mxs_json_pointer(json, MXS_JSON_PTR_ACCOUNT));
|
||||
user_account_type type = json_to_account_type(mxs_json_pointer(json, MXS_JSON_PTR_ACCOUNT));
|
||||
const char* err = NULL;
|
||||
|
||||
if (strtype == CN_INET && (err = admin_add_inet_user(user, password, type)) == ADMIN_SUCCESS)
|
||||
|
@ -64,13 +64,13 @@ test2()
|
||||
{
|
||||
const char *err;
|
||||
|
||||
if ((err = admin_enable_linux_account("user0", ACCOUNT_ADMIN)) != NULL)
|
||||
if ((err = admin_enable_linux_account("user0", USER_ACCOUNT_ADMIN)) != NULL)
|
||||
{
|
||||
fprintf(stderr, "admin_add_user: test 2.1 (add user) failed, %s.\n", err);
|
||||
|
||||
return 1;
|
||||
}
|
||||
if (admin_enable_linux_account("user0", ACCOUNT_ADMIN) == NULL)
|
||||
if (admin_enable_linux_account("user0", USER_ACCOUNT_ADMIN) == NULL)
|
||||
{
|
||||
fprintf(stderr, "admin_add_user: test 2.2 (add user) failed, duplicate.\n");
|
||||
|
||||
@ -86,7 +86,7 @@ test2()
|
||||
}
|
||||
|
||||
/* Add the user back, for test5. */
|
||||
if ((err = admin_enable_linux_account("user0", ACCOUNT_ADMIN)) != NULL)
|
||||
if ((err = admin_enable_linux_account("user0", USER_ACCOUNT_ADMIN)) != NULL)
|
||||
{
|
||||
fprintf(stderr, "admin_add_user: test 2.4 (add user) failed, %s.\n", err);
|
||||
|
||||
@ -110,7 +110,7 @@ test3()
|
||||
{
|
||||
const char *err;
|
||||
|
||||
if ((err = admin_enable_linux_account("user1", ACCOUNT_ADMIN)) != NULL)
|
||||
if ((err = admin_enable_linux_account("user1", USER_ACCOUNT_ADMIN)) != NULL)
|
||||
{
|
||||
fprintf(stderr, "admin_add_user: test 3.1 (add user) failed, %s.\n", err);
|
||||
|
||||
@ -168,7 +168,7 @@ test4()
|
||||
for (i = 1; i < n_users; i++)
|
||||
{
|
||||
sprintf(user, "user%d", i);
|
||||
if ((err = admin_enable_linux_account(user, ACCOUNT_ADMIN)) != NULL)
|
||||
if ((err = admin_enable_linux_account(user, USER_ACCOUNT_ADMIN)) != NULL)
|
||||
{
|
||||
fprintf(stderr, "admin_add_user: test 4.1 (add user) failed, %s.\n", err);
|
||||
|
||||
@ -212,7 +212,7 @@ test5()
|
||||
{
|
||||
const char *err;
|
||||
|
||||
if ((err = admin_enable_linux_account("user", ACCOUNT_ADMIN)) != NULL)
|
||||
if ((err = admin_enable_linux_account("user", USER_ACCOUNT_ADMIN)) != NULL)
|
||||
{
|
||||
fprintf(stderr, "admin_add_user: test 5.1 (add user) failed, %s.\n", err);
|
||||
|
||||
|
@ -48,7 +48,7 @@ static int test1()
|
||||
mxs_log_flush_sync();
|
||||
ss_info_dassert(NULL != users, "Allocating user table should not return NULL.");
|
||||
ss_dfprintf(stderr, "\t..done\nAdd a user");
|
||||
rv = users_add(users, "username", "authorisation", ACCOUNT_ADMIN);
|
||||
rv = users_add(users, "username", "authorisation", USER_ACCOUNT_ADMIN);
|
||||
mxs_log_flush_sync();
|
||||
ss_info_dassert(rv, "Should add one user");
|
||||
rv = users_auth(users, "username", "authorisation");
|
||||
@ -59,7 +59,7 @@ static int test1()
|
||||
ss_info_dassert(rv == 0, "Fetch invalid user must return NULL");
|
||||
|
||||
ss_dfprintf(stderr, "\t..done\nAdd another user");
|
||||
rv = users_add(users, "username2", "authorisation2", ACCOUNT_ADMIN);
|
||||
rv = users_add(users, "username2", "authorisation2", USER_ACCOUNT_ADMIN);
|
||||
mxs_log_flush_sync();
|
||||
ss_info_dassert(rv, "Should add one user");
|
||||
ss_dfprintf(stderr, "\t..done\nDelete a user.");
|
||||
|
@ -33,18 +33,18 @@ static const char STR_ADMIN[] = "admin";
|
||||
struct UserInfo
|
||||
{
|
||||
UserInfo():
|
||||
permissions(ACCOUNT_BASIC)
|
||||
permissions(USER_ACCOUNT_BASIC)
|
||||
{
|
||||
}
|
||||
|
||||
UserInfo(std::string pw, account_type perm):
|
||||
UserInfo(std::string pw, user_account_type perm):
|
||||
password(pw),
|
||||
permissions(perm)
|
||||
{
|
||||
}
|
||||
|
||||
std::string password;
|
||||
account_type permissions;
|
||||
std::string password;
|
||||
user_account_type permissions;
|
||||
};
|
||||
|
||||
|
||||
@ -64,7 +64,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
bool add(std::string user, std::string password, account_type perm)
|
||||
bool add(std::string user, std::string password, user_account_type perm)
|
||||
{
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
return m_data.insert(std::make_pair(user, UserInfo(password, perm))).second;
|
||||
@ -109,7 +109,7 @@ public:
|
||||
return std::find_if(m_data.begin(), m_data.end(), is_admin) != m_data.end();
|
||||
}
|
||||
|
||||
bool check_permissions(std::string user, account_type perm) const
|
||||
bool check_permissions(std::string user, user_account_type perm) const
|
||||
{
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
UserMap::const_iterator it = m_data.find(user);
|
||||
@ -123,7 +123,7 @@ public:
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool set_permissions(std::string user, account_type perm)
|
||||
bool set_permissions(std::string user, user_account_type perm)
|
||||
{
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
UserMap::iterator it = m_data.find(user);
|
||||
@ -204,7 +204,7 @@ private:
|
||||
|
||||
static bool is_admin(const UserMap::value_type& value)
|
||||
{
|
||||
return value.second.permissions == ACCOUNT_ADMIN;
|
||||
return value.second.permissions == USER_ACCOUNT_ADMIN;
|
||||
}
|
||||
|
||||
void load_json(json_t* json)
|
||||
@ -222,7 +222,7 @@ private:
|
||||
if (name && json_is_string(name) &&
|
||||
type && json_is_string(type) &&
|
||||
password && json_is_string(password) &&
|
||||
json_to_account_type(type) != ACCOUNT_UNKNOWN)
|
||||
json_to_account_type(type) != USER_ACCOUNT_UNKNOWN)
|
||||
{
|
||||
add(json_string_value(name), json_string_value(password),
|
||||
json_to_account_type(type));
|
||||
@ -253,7 +253,7 @@ void users_free(USERS *users)
|
||||
delete u;
|
||||
}
|
||||
|
||||
bool users_add(USERS *users, const char *user, const char *password, enum account_type type)
|
||||
bool users_add(USERS *users, const char *user, const char *password, enum user_account_type type)
|
||||
{
|
||||
Users* u = reinterpret_cast<Users*>(users);
|
||||
return u->add(user, password, type);
|
||||
@ -299,7 +299,7 @@ bool users_auth(USERS* users, const char* user, const char* password)
|
||||
bool users_is_admin(USERS* users, const char* user)
|
||||
{
|
||||
Users* u = reinterpret_cast<Users*>(users);
|
||||
return u->check_permissions(user, ACCOUNT_ADMIN);
|
||||
return u->check_permissions(user, USER_ACCOUNT_ADMIN);
|
||||
}
|
||||
|
||||
bool users_have_admin(USERS* users)
|
||||
@ -350,14 +350,14 @@ int users_default_loadusers(SERV_LISTENER *port)
|
||||
return MXS_AUTH_LOADUSERS_OK;
|
||||
}
|
||||
|
||||
const char* account_type_to_str(enum account_type type)
|
||||
const char* account_type_to_str(enum user_account_type type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ACCOUNT_BASIC:
|
||||
case USER_ACCOUNT_BASIC:
|
||||
return STR_BASIC;
|
||||
|
||||
case ACCOUNT_ADMIN:
|
||||
case USER_ACCOUNT_ADMIN:
|
||||
return STR_ADMIN;
|
||||
|
||||
default:
|
||||
@ -365,18 +365,18 @@ const char* account_type_to_str(enum account_type type)
|
||||
}
|
||||
}
|
||||
|
||||
enum account_type json_to_account_type(json_t* json)
|
||||
enum user_account_type json_to_account_type(json_t* json)
|
||||
{
|
||||
std::string str = json_string_value(json);
|
||||
|
||||
if (str == STR_BASIC)
|
||||
{
|
||||
return ACCOUNT_BASIC;
|
||||
return USER_ACCOUNT_BASIC;
|
||||
}
|
||||
else if (str == STR_ADMIN)
|
||||
{
|
||||
return ACCOUNT_ADMIN;
|
||||
return USER_ACCOUNT_ADMIN;
|
||||
}
|
||||
|
||||
return ACCOUNT_UNKNOWN;
|
||||
return USER_ACCOUNT_UNKNOWN;
|
||||
}
|
||||
|
@ -460,7 +460,7 @@ cdc_set_service_user(SERV_LISTENER *listener)
|
||||
}
|
||||
|
||||
/* add service user */
|
||||
(void)users_add(listener->users, service->credentials.name, newpasswd, ACCOUNT_ADMIN);
|
||||
(void)users_add(listener->users, service->credentials.name, newpasswd, USER_ACCOUNT_ADMIN);
|
||||
|
||||
MXS_FREE(newpasswd);
|
||||
MXS_FREE(dpwd);
|
||||
@ -510,7 +510,7 @@ cdc_read_users(USERS *users, char *usersfile)
|
||||
}
|
||||
|
||||
/* add user */
|
||||
users_add(users, avro_user, user_passwd, ACCOUNT_ADMIN);
|
||||
users_add(users, avro_user, user_passwd, USER_ACCOUNT_ADMIN);
|
||||
|
||||
loaded++;
|
||||
}
|
||||
|
@ -2258,7 +2258,7 @@ reload_config(DCB *dcb)
|
||||
* @param user The user name
|
||||
* @param user The user password
|
||||
*/
|
||||
static void do_inet_add_user(DCB *dcb, char *user, char *password, enum account_type type)
|
||||
static void do_inet_add_user(DCB *dcb, char *user, char *password, enum user_account_type type)
|
||||
{
|
||||
const char *err;
|
||||
|
||||
@ -2282,7 +2282,7 @@ static void inet_add_user(DCB *dcb, char *user, char *password)
|
||||
{
|
||||
if (admin_have_admin())
|
||||
{
|
||||
do_inet_add_user(dcb, user, password, ACCOUNT_BASIC);
|
||||
do_inet_add_user(dcb, user, password, USER_ACCOUNT_BASIC);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2293,7 +2293,7 @@ static void inet_add_user(DCB *dcb, char *user, char *password)
|
||||
|
||||
static void inet_add_admin_user(DCB *dcb, char *user, char *password)
|
||||
{
|
||||
do_inet_add_user(dcb, user, password, ACCOUNT_ADMIN);
|
||||
do_inet_add_user(dcb, user, password, USER_ACCOUNT_ADMIN);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2583,7 +2583,7 @@ disable_maxlog()
|
||||
* @param dcb The DCB for messages
|
||||
* @param user The Linux user name
|
||||
*/
|
||||
static void do_enable_account(DCB *dcb, char *user, enum account_type type)
|
||||
static void do_enable_account(DCB *dcb, char *user, enum user_account_type type)
|
||||
{
|
||||
const char *err;
|
||||
|
||||
@ -2607,7 +2607,7 @@ static void enable_account(DCB *dcb, char *user)
|
||||
{
|
||||
if (admin_have_admin())
|
||||
{
|
||||
do_enable_account(dcb, user, ACCOUNT_BASIC);
|
||||
do_enable_account(dcb, user, USER_ACCOUNT_BASIC);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2624,7 +2624,7 @@ static void enable_account(DCB *dcb, char *user)
|
||||
*/
|
||||
static void enable_admin_account(DCB *dcb, char *user)
|
||||
{
|
||||
do_enable_account(dcb, user, ACCOUNT_ADMIN);
|
||||
do_enable_account(dcb, user, USER_ACCOUNT_ADMIN);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user