Make Users const correct
This commit is contained in:
@ -61,16 +61,16 @@ typedef struct users
|
|||||||
unsigned char cksum[SHA_DIGEST_LENGTH]; /**< The users' table ckecksum */
|
unsigned char cksum[SHA_DIGEST_LENGTH]; /**< The users' table ckecksum */
|
||||||
} USERS;
|
} USERS;
|
||||||
|
|
||||||
extern USERS *users_alloc(); /**< Allocate a users table */
|
extern USERS *users_alloc(); /**< Allocate a users table */
|
||||||
extern void users_free(USERS *); /**< Free a users table */
|
extern void users_free(USERS *); /**< Free a users table */
|
||||||
extern int users_add(USERS *, char *, char *); /**< Add a user to the users table */
|
extern int users_add(USERS *, const char *, const char *); /**< Add a user to the users table */
|
||||||
extern int users_delete(USERS *, char *); /**< Delete a user from the users table */
|
extern int users_delete(USERS *, const char *); /**< Delete a user from the users table */
|
||||||
extern char *users_fetch(USERS *, char *); /**< Fetch the authentication data for a user */
|
extern const char *users_fetch(USERS *, const char *); /**< Fetch the authentication data for a user*/
|
||||||
extern int users_update(USERS *, char *, char *); /**< Change the password data for a user in
|
extern int users_update(USERS *, const char *, const char *); /**< Change the password data for a user in
|
||||||
the users table */
|
the users table */
|
||||||
extern int users_default_loadusers(SERV_LISTENER *port); /**< A generic implementation of the authenticator
|
extern int users_default_loadusers(SERV_LISTENER *port); /**< A generic implementation of the
|
||||||
* loadusers entry point */
|
authenticator loadusers entry point */
|
||||||
extern void usersPrint(USERS *); /**< Print data about the users loaded */
|
extern void usersPrint(const USERS *); /**< Print data about the users loaded */
|
||||||
extern void dcb_usersPrint(DCB *, USERS *); /**< Print data about the users loaded */
|
extern void dcb_usersPrint(DCB *, const USERS *); /**< Print data about the users loaded */
|
||||||
|
|
||||||
MXS_END_DECLS
|
MXS_END_DECLS
|
||||||
|
@ -45,9 +45,9 @@
|
|||||||
static int
|
static int
|
||||||
test1()
|
test1()
|
||||||
{
|
{
|
||||||
USERS *users;
|
USERS *users;
|
||||||
char *authdata;
|
const char *authdata;
|
||||||
int result, count;
|
int result, count;
|
||||||
|
|
||||||
/* Poll tests */
|
/* Poll tests */
|
||||||
ss_dfprintf(stderr,
|
ss_dfprintf(stderr,
|
||||||
|
@ -87,12 +87,12 @@ users_free(USERS *users)
|
|||||||
* @return The number of users added to the table
|
* @return The number of users added to the table
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
users_add(USERS *users, char *user, char *auth)
|
users_add(USERS *users, const char *user, const char *auth)
|
||||||
{
|
{
|
||||||
int add;
|
int add;
|
||||||
|
|
||||||
atomic_add(&users->stats.n_adds, 1);
|
atomic_add(&users->stats.n_adds, 1);
|
||||||
add = hashtable_add(users->data, user, auth);
|
add = hashtable_add(users->data, (char*)user, (char*)auth);
|
||||||
atomic_add(&users->stats.n_entries, add);
|
atomic_add(&users->stats.n_entries, add);
|
||||||
return add;
|
return add;
|
||||||
}
|
}
|
||||||
@ -105,12 +105,12 @@ users_add(USERS *users, char *user, char *auth)
|
|||||||
* @return The number of users deleted from the table
|
* @return The number of users deleted from the table
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
users_delete(USERS *users, char *user)
|
users_delete(USERS *users, const char *user)
|
||||||
{
|
{
|
||||||
int del;
|
int del;
|
||||||
|
|
||||||
atomic_add(&users->stats.n_deletes, 1);
|
atomic_add(&users->stats.n_deletes, 1);
|
||||||
del = hashtable_delete(users->data, user);
|
del = hashtable_delete(users->data, (char*)user);
|
||||||
atomic_add(&users->stats.n_entries, -del);
|
atomic_add(&users->stats.n_entries, -del);
|
||||||
return del;
|
return del;
|
||||||
}
|
}
|
||||||
@ -122,11 +122,12 @@ users_delete(USERS *users, char *user)
|
|||||||
* @param user The user name
|
* @param user The user name
|
||||||
* @return The authentication data or NULL on error
|
* @return The authentication data or NULL on error
|
||||||
*/
|
*/
|
||||||
char
|
const char
|
||||||
*users_fetch(USERS *users, char *user)
|
*users_fetch(USERS *users, const char *user)
|
||||||
{
|
{
|
||||||
atomic_add(&users->stats.n_fetches, 1);
|
atomic_add(&users->stats.n_fetches, 1);
|
||||||
return hashtable_fetch(users->data, user);
|
// TODO: Returning data from the hashtable is not threadsafe.
|
||||||
|
return hashtable_fetch(users->data, (char*)user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,13 +140,13 @@ char
|
|||||||
* @return Number of users updated
|
* @return Number of users updated
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
users_update(USERS *users, char *user, char *auth)
|
users_update(USERS *users, const char *user, const char *auth)
|
||||||
{
|
{
|
||||||
if (hashtable_delete(users->data, user) == 0)
|
if (hashtable_delete(users->data, (char*)user) == 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return hashtable_add(users->data, user, auth);
|
return hashtable_add(users->data, (char*)user, (char*)auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -154,7 +155,7 @@ users_update(USERS *users, char *user, char *auth)
|
|||||||
* @param users The users table
|
* @param users The users table
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
usersPrint(USERS *users)
|
usersPrint(const USERS *users)
|
||||||
{
|
{
|
||||||
printf("Users table data\n");
|
printf("Users table data\n");
|
||||||
hashtable_stats(users->data);
|
hashtable_stats(users->data);
|
||||||
@ -167,7 +168,7 @@ usersPrint(USERS *users)
|
|||||||
* @param users The users table
|
* @param users The users table
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
dcb_usersPrint(DCB *dcb, USERS *users)
|
dcb_usersPrint(DCB *dcb, const USERS *users)
|
||||||
{
|
{
|
||||||
if (users == NULL || users->data == NULL)
|
if (users == NULL || users->data == NULL)
|
||||||
{
|
{
|
||||||
|
@ -139,7 +139,7 @@ static int cdc_auth_check(DCB *dcb, CDC_protocol *protocol, char *username, uint
|
|||||||
{
|
{
|
||||||
if (dcb->listener->users)
|
if (dcb->listener->users)
|
||||||
{
|
{
|
||||||
char *user_password = users_fetch(dcb->listener->users, username);
|
const char *user_password = users_fetch(dcb->listener->users, username);
|
||||||
|
|
||||||
if (user_password)
|
if (user_password)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user