Restrict removal of last admin user

- Don't allow disabling the only available admin account.
- Don't allow deletion of the only available admin account.
- Don't allow removing admin privileges of the only available admin account.

Signed-off-by: Hemanth Kumar Veeranki <hems.india1997@gmail.com>
Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
Hemanth Kumar Veeranki authored and Joseph Nuthalapati committed 2018-06-21 20:09:02 +05:30
1 parent b605c9da8a
commit b9963a45cd
6 files changed
+91 -7

No files matched your search

+15
View File
@@ -86,6 +86,11 @@ def parse_arguments():
subparser.add_argument('groupname',
help='LDAP group to remove the user from')
help_get_admin_user = 'Get the list of all users in an LDAP group'
subparser = subparsers.add_parser('get-group-users', help=help_get_admin_user)
subparser.add_argument('groupname', help='name of the LDAP group to get the '
'list of users')
subparsers.required = True
return parser.parse_args()
@@ -345,6 +350,16 @@ def subcommand_remove_user_from_group(arguments):
flush_cache()
def subcommand_get_group_users(arguments):
""" Get the list of admin users """
process = _run(['ldapgid', arguments.groupname], stdout=subprocess.PIPE)
output = str(process.stdout).split()
users_info = output[1].split('=')[1].strip('\\n').split(',')
for user_info in users_info:
user_name = user_info.split('(')[1].split(')')[0]
print(user_name)
def flush_cache():
"""Flush nscd cache."""
_run(['nscd', '--invalidate=passwd'])