mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
fixes #3217 by checking for existing pihole group
Signed-off-by: pvogt09 <50047961+pvogt09@users.noreply.github.com>
This commit is contained in:
parent
7b8611ced0
commit
a993b8b34d
2 changed files with 77 additions and 5 deletions
|
@ -1770,18 +1770,49 @@ create_pihole_user() {
|
||||||
printf " %b %s..." "${INFO}" "${str}"
|
printf " %b %s..." "${INFO}" "${str}"
|
||||||
# If the user pihole exists,
|
# If the user pihole exists,
|
||||||
if id -u pihole &> /dev/null; then
|
if id -u pihole &> /dev/null; then
|
||||||
# just show a success
|
# if group exists
|
||||||
printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}"
|
if getent group pihole; then
|
||||||
|
# just show a success
|
||||||
|
printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}"
|
||||||
|
else
|
||||||
|
local str="Checking for group 'pihole'"
|
||||||
|
printf " %b %s..." "${INFO}" "${str}"
|
||||||
|
local str="Creating group 'pihole'"
|
||||||
|
# if group can be created
|
||||||
|
if groupadd pihole; then
|
||||||
|
printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}"
|
||||||
|
local str="Adding user 'pihole' to group 'pihole'"
|
||||||
|
printf " %b %s..." "${INFO}" "${str}"
|
||||||
|
# if pihole user can be added to group pihole
|
||||||
|
if usermod -g pihole pihole; then
|
||||||
|
printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}"
|
||||||
|
else
|
||||||
|
printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
# Otherwise,
|
# Otherwise,
|
||||||
else
|
else
|
||||||
printf "%b %b %s" "${OVER}" "${CROSS}" "${str}"
|
printf "%b %b %s" "${OVER}" "${CROSS}" "${str}"
|
||||||
local str="Creating user 'pihole'"
|
local str="Creating user 'pihole'"
|
||||||
printf "%b %b %s..." "${OVER}" "${INFO}" "${str}"
|
printf "%b %b %s..." "${OVER}" "${INFO}" "${str}"
|
||||||
# create her with the useradd command
|
# create her with the useradd command
|
||||||
if useradd -r -s /usr/sbin/nologin pihole; then
|
if getent group pihole; then
|
||||||
printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}"
|
# add primary group pihole as it already exists
|
||||||
|
if useradd -r --no-user-group -g pihole -s /usr/sbin/nologin pihole; then
|
||||||
|
printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}"
|
||||||
|
else
|
||||||
|
printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}"
|
# add user pihole with default group settings
|
||||||
|
if useradd -r -s /usr/sbin/nologin pihole; then
|
||||||
|
printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}"
|
||||||
|
else
|
||||||
|
printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,47 @@ def test_setupVars_saved_to_file(Pihole):
|
||||||
assert "{}={}".format(k, v) in output
|
assert "{}={}".format(k, v) in output
|
||||||
|
|
||||||
|
|
||||||
|
def test_pihole_user_group_creation(Pihole):
|
||||||
|
'''
|
||||||
|
check user creation works if user or group already exist
|
||||||
|
'''
|
||||||
|
# normal situation where neither user or group exist
|
||||||
|
user_create = Pihole.run('''
|
||||||
|
source /opt/pihole/basic-install.sh
|
||||||
|
create_pihole_user
|
||||||
|
''')
|
||||||
|
expected_stdout = tick_box + ' Creating user \'pihole\''
|
||||||
|
assert expected_stdout in user_create.stdout
|
||||||
|
# situation where both user and group already exist
|
||||||
|
user_create = Pihole.run('''
|
||||||
|
source /opt/pihole/basic-install.sh
|
||||||
|
create_pihole_user
|
||||||
|
''')
|
||||||
|
expected_stdout = tick_box + ' Checking for user \'pihole\''
|
||||||
|
assert expected_stdout in user_create.stdout
|
||||||
|
# situation where only group and no user exists
|
||||||
|
Pihole.run('su --shell /bin/bash --command "userdel -r pihole" -p root')
|
||||||
|
user_create = Pihole.run('''
|
||||||
|
source /opt/pihole/basic-install.sh
|
||||||
|
create_pihole_user
|
||||||
|
''')
|
||||||
|
expected_stdout = tick_box + ' Creating user \'pihole\''
|
||||||
|
assert expected_stdout in user_create.stdout
|
||||||
|
# situation where only user and no group exists
|
||||||
|
Pihole.run('su --shell /bin/bash --command "userdel -r pihole" -p root')
|
||||||
|
Pihole.run('su --shell /bin/bash --command "groupdel pihole" -p root')
|
||||||
|
Pihole.run('su --shell /bin/bash --command "groupadd pihole_dummy" -p root')
|
||||||
|
Pihole.run('su --shell /bin/bash --command "useradd -r --no-user-group -g pihole_dummy -s /usr/sbin/nologin pihole" -p root')
|
||||||
|
user_create = Pihole.run('''
|
||||||
|
source /opt/pihole/basic-install.sh
|
||||||
|
create_pihole_user
|
||||||
|
''')
|
||||||
|
expected_stdout = tick_box + ' Creating group \'pihole\''
|
||||||
|
assert expected_stdout in user_create.stdout
|
||||||
|
expected_stdout = tick_box + ' Adding user \'pihole\' to group \'pihole\''
|
||||||
|
assert expected_stdout in user_create.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_configureFirewall_firewalld_running_no_errors(Pihole):
|
def test_configureFirewall_firewalld_running_no_errors(Pihole):
|
||||||
'''
|
'''
|
||||||
confirms firewalld rules are applied when firewallD is running
|
confirms firewalld rules are applied when firewallD is running
|
||||||
|
|
Loading…
Reference in a new issue