mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
postinstall: crash early if the username already exists on the system
This commit is contained in:
parent
bcd2550fdd
commit
e87ee09b3e
1 changed files with 7 additions and 0 deletions
|
@ -16,6 +16,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import pwd
|
||||
import re
|
||||
import os
|
||||
import subprocess
|
||||
|
@ -174,6 +175,12 @@ def tools_postinstall(
|
|||
raw_msg=True,
|
||||
)
|
||||
|
||||
# Crash early if the username is already a system user, which is
|
||||
# a common confusion. We don't want to crash later and end up in an half-configured state.
|
||||
all_existing_usernames = {x.pw_name for x in pwd.getpwall()}
|
||||
if username in all_existing_usernames:
|
||||
raise YunohostValidationError("system_username_exists")
|
||||
|
||||
if username in ADMIN_ALIASES:
|
||||
raise YunohostValidationError(
|
||||
f"Unfortunately, {username} cannot be used as a username", raw_msg=True
|
||||
|
|
Loading…
Add table
Reference in a new issue