Reindent server/core/adminusers.c
This commit is contained in:
@ -70,7 +70,10 @@ static void
|
||||
initialise()
|
||||
{
|
||||
if (admin_init)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
admin_init = 1;
|
||||
users = loadUsers();
|
||||
}
|
||||
@ -91,15 +94,21 @@ char *pw;
|
||||
if (users == NULL)
|
||||
{
|
||||
if (strcmp(username, "admin") == 0 && strcmp(password, "mariadb") == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pw = users_fetch(users, username)) == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(pw, crypt(password, ADMIN_SALT)) == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -121,7 +130,9 @@ char uname[80], passwd[80];
|
||||
snprintf(fname,1023, "%s/passwd", get_datadir());
|
||||
fname[1023] = '\0';
|
||||
if ((fp = fopen(fname, "r")) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if ((rval = users_alloc()) == NULL)
|
||||
{
|
||||
fclose(fp);
|
||||
@ -152,8 +163,12 @@ char fname[1024], *home, *cpasswd;
|
||||
initialise();
|
||||
|
||||
if (access(get_datadir(), F_OK) != 0)
|
||||
{
|
||||
if (mkdir(get_datadir(), S_IRWXU) != 0 && errno != EEXIST)
|
||||
{
|
||||
return ADMIN_ERR_PWDFILEOPEN;
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(fname,1023, "%s/passwd", get_datadir());
|
||||
fname[1023] = '\0';
|
||||
@ -162,7 +177,9 @@ char fname[1024], *home, *cpasswd;
|
||||
MXS_NOTICE("Create initial password file.");
|
||||
|
||||
if ((users = users_alloc()) == NULL)
|
||||
{
|
||||
return ADMIN_ERR_NOMEM;
|
||||
}
|
||||
if ((fp = fopen(fname, "w")) == NULL)
|
||||
{
|
||||
MXS_ERROR("Unable to create password file %s.", fname);
|
||||
@ -209,12 +226,14 @@ char* admin_remove_user(
|
||||
fpos_t rpos;
|
||||
int n_deleted;
|
||||
|
||||
if (!admin_search_user(uname)) {
|
||||
if (!admin_search_user(uname))
|
||||
{
|
||||
MXS_ERROR("Couldn't find user %s. Removing user failed.", uname);
|
||||
return ADMIN_ERR_USERNOTFOUND;
|
||||
}
|
||||
|
||||
if (admin_verify(uname, passwd) == 0) {
|
||||
if (admin_verify(uname, passwd) == 0)
|
||||
{
|
||||
MXS_ERROR("Authentication failed, wrong user/password "
|
||||
"combination. Removing user failed.");
|
||||
return ADMIN_ERR_AUTHENTICATION;
|
||||
@ -224,7 +243,8 @@ char* admin_remove_user(
|
||||
/** Remove user from in-memory structure */
|
||||
n_deleted = users_delete(users, uname);
|
||||
|
||||
if (n_deleted == 0) {
|
||||
if (n_deleted == 0)
|
||||
{
|
||||
MXS_ERROR("Deleting the only user is forbidden. Add new "
|
||||
"user before deleting the one.");
|
||||
return ADMIN_ERR_DELLASTUSER;
|
||||
@ -267,7 +287,8 @@ char* admin_remove_user(
|
||||
/**
|
||||
* Scan passwd and copy all but matching lines to temp file.
|
||||
*/
|
||||
if (fgetpos(fp, &rpos) != 0) {
|
||||
if (fgetpos(fp, &rpos) != 0)
|
||||
{
|
||||
int err = errno;
|
||||
MXS_ERROR("Unable to process passwd file %s : errno %d.\n"
|
||||
"Removing user from file failed, and must be done "
|
||||
@ -286,15 +307,18 @@ char* admin_remove_user(
|
||||
* Compare username what was found from passwd file.
|
||||
* Unmatching lines are copied to tmp file.
|
||||
*/
|
||||
if (strncmp(uname, fusr, strlen(uname)+1) != 0) {
|
||||
if(fsetpos(fp, &rpos) != 0){ /** one step back */
|
||||
if (strncmp(uname, fusr, strlen(uname)+1) != 0)
|
||||
{
|
||||
if(fsetpos(fp, &rpos) != 0)
|
||||
{ /** one step back */
|
||||
MXS_ERROR("Unable to set stream position. ");
|
||||
}
|
||||
fgets(line, LINELEN, fp);
|
||||
fputs(line, fp_tmp);
|
||||
}
|
||||
|
||||
if (fgetpos(fp, &rpos) != 0) {
|
||||
if (fgetpos(fp, &rpos) != 0)
|
||||
{
|
||||
int err = errno;
|
||||
MXS_ERROR("Unable to process passwd file %s : "
|
||||
"errno %d.\n"
|
||||
@ -312,7 +336,8 @@ char* admin_remove_user(
|
||||
/**
|
||||
* Replace original passwd file with new.
|
||||
*/
|
||||
if (rename(fname_tmp, fname)) {
|
||||
if (rename(fname_tmp, fname))
|
||||
{
|
||||
int err = errno;
|
||||
MXS_ERROR("Unable to rename new passwd file %s : errno "
|
||||
"%d.\n"
|
||||
@ -341,7 +366,9 @@ admin_search_user(char *user)
|
||||
{
|
||||
initialise();
|
||||
if (users == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return users_fetch(users, user) != NULL;
|
||||
}
|
||||
|
||||
@ -354,7 +381,11 @@ void
|
||||
dcb_PrintAdminUsers(DCB *dcb)
|
||||
{
|
||||
if (users)
|
||||
{
|
||||
dcb_usersPrint(dcb, users);
|
||||
}
|
||||
else
|
||||
{
|
||||
dcb_printf(dcb, "No administration users have been defined.\n");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user