Skip to content

Commit

Permalink
Check for user name conflicts with existing groups during validation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
stephdl authored Feb 19, 2025
1 parent 9881067 commit d6b7e81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions imageroot/actions/add-group/01validate_group
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ if proc.returncode == 0:
agent.set_status('validation-failed')
json.dump([{'field':'group', 'parameter':'group','value': group, 'error':'group_already_exists'}], fp=sys.stdout)
sys.exit(2)

# we test if the group does not have the same name than a user
testnameavailable_cmd = ['podman', 'exec', '-i', 'samba-dc', 'samba-tool', 'user', 'show', group]
testnameavailable_proc = subprocess.run(testnameavailable_cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, text=True)
if testnameavailable_proc.returncode == 0:
agent.set_status('validation-failed')
json.dump([{'field':'group', 'parameter':'group','value': group, 'error':'user_with_same_name'}], fp=sys.stdout)
sys.exit(2)
8 changes: 8 additions & 0 deletions imageroot/actions/add-user/01validate_user
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ if proc.returncode == 0:
agent.set_status('validation-failed')
json.dump([{'field':'user', 'parameter':'user','value': user, 'error':'user_already_exists'}], fp=sys.stdout)
sys.exit(2)

# we test if the user does not have the same name than a group
testnameavailable_cmd = ['podman', 'exec', '-i', 'samba-dc', 'samba-tool', 'group', 'show', user]
testnameavailable_proc = subprocess.run(testnameavailable_cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, text=True)
if testnameavailable_proc.returncode == 0:
agent.set_status('validation-failed')
json.dump([{'field':'user', 'parameter':'user','value': user, 'error':'group_with_same_name'}], fp=sys.stdout)
sys.exit(2)

0 comments on commit d6b7e81

Please sign in to comment.