Added check if the last admin user is to be deleted, and if that's the case, prevent it and return with error message.
This commit is contained in:
@ -55,6 +55,8 @@ static char *ADMIN_ERR_FILEAPPEND = "Unable to append to password file";
|
|||||||
static char *ADMIN_ERR_PWDFILEOPEN = "Failed to open password file";
|
static char *ADMIN_ERR_PWDFILEOPEN = "Failed to open password file";
|
||||||
static char *ADMIN_ERR_TMPFILEOPEN = "Failed to open temporary password file";
|
static char *ADMIN_ERR_TMPFILEOPEN = "Failed to open temporary password file";
|
||||||
static char *ADMIN_ERR_PWDFILEACCESS = "Failed to access password file";
|
static char *ADMIN_ERR_PWDFILEACCESS = "Failed to access password file";
|
||||||
|
static char *ADMIN_ERR_DELLASTUSER = "Deleting user failed, deleting the "
|
||||||
|
"last user is forbidden";
|
||||||
static char *ADMIN_SUCCESS = NULL;
|
static char *ADMIN_SUCCESS = NULL;
|
||||||
|
|
||||||
static const int LINELEN=80;
|
static const int LINELEN=80;
|
||||||
@ -193,15 +195,16 @@ char* admin_remove_user(
|
|||||||
char* uname,
|
char* uname,
|
||||||
char* passwd)
|
char* passwd)
|
||||||
{
|
{
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
FILE* fp_tmp;
|
FILE* fp_tmp;
|
||||||
char fname[1024];
|
char fname[1024];
|
||||||
char fname_tmp[1024];
|
char fname_tmp[1024];
|
||||||
char* home;
|
char* home;
|
||||||
char fusr[LINELEN];
|
char fusr[LINELEN];
|
||||||
char fpwd[LINELEN];
|
char fpwd[LINELEN];
|
||||||
char line[LINELEN];
|
char line[LINELEN];
|
||||||
fpos_t rpos;
|
fpos_t rpos;
|
||||||
|
int n_deleted;
|
||||||
|
|
||||||
if (!admin_search_user(uname)) {
|
if (!admin_search_user(uname)) {
|
||||||
skygw_log_write(NULL,
|
skygw_log_write(NULL,
|
||||||
@ -218,9 +221,17 @@ char* admin_remove_user(
|
|||||||
return ADMIN_ERR_AUTHENTICATION;
|
return ADMIN_ERR_AUTHENTICATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Remove user from in-memory structure */
|
/** Remove user from in-memory structure */
|
||||||
users_delete(users, uname);
|
n_deleted = users_delete(users, uname);
|
||||||
|
|
||||||
|
if (n_deleted == 0) {
|
||||||
|
skygw_log_write(NULL,
|
||||||
|
LOGFILE_MESSAGE,
|
||||||
|
"Deleting the only user is forbidden. add new user "
|
||||||
|
"before deleting the old one.\n");
|
||||||
|
return ADMIN_ERR_DELLASTUSER;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Open passwd file and remove user from the file.
|
* Open passwd file and remove user from the file.
|
||||||
*/
|
*/
|
||||||
|
@ -113,6 +113,10 @@ users_delete(USERS *users, char *user)
|
|||||||
int del;
|
int del;
|
||||||
|
|
||||||
atomic_add(&users->stats.n_deletes, 1);
|
atomic_add(&users->stats.n_deletes, 1);
|
||||||
|
if (users->stats.n_entries == 1) {
|
||||||
|
atomic_add(&users->stats.n_entries, del * -1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
del = hashtable_delete(users->data, user);
|
del = hashtable_delete(users->data, user);
|
||||||
atomic_add(&users->stats.n_entries, del * -1);
|
atomic_add(&users->stats.n_entries, del * -1);
|
||||||
return del;
|
return del;
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
extern int admin_verify(char *, char *);
|
extern int admin_verify(char *, char *);
|
||||||
extern char *admin_add_user(char *, char *);
|
extern char *admin_add_user(char *, char *);
|
||||||
extern int admin_test_user(char *);
|
extern int admin_search_user(char *);
|
||||||
extern void dcb_PrintAdminUsers(DCB *dcb);
|
extern void dcb_PrintAdminUsers(DCB *dcb);
|
||||||
|
|
||||||
char* admin_remove_user(char* uname, char* passwd);
|
char* admin_remove_user(char* uname, char* passwd);
|
||||||
|
Reference in New Issue
Block a user