Skip to content

Commit

Permalink
add group query
Browse files Browse the repository at this point in the history
  • Loading branch information
nazunalika committed Jul 31, 2024
1 parent 04d1ec6 commit c2ab7d7
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions mangle/ipa/ipaauditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ def entry(api, control, name, deep):
"""
Gets us started on the query
"""
#user_data = IPAQuery.user_data(api, name)
if control == 'user':
IPAQuery.user_pull(api, name, deep)
if control == 'group':
Expand All @@ -456,7 +455,7 @@ def entry(api, control, name, deep):
@staticmethod
def user_pull(api, name, deep):
"""
Gets requested rbac info
Gets requested user info
"""
user_results = IPAQuery.user_data(api, name)
uid = user_results['uid'][0]
Expand Down Expand Up @@ -486,13 +485,37 @@ def user_pull(api, name, deep):
"""
print(outter)


@staticmethod
def group_pull(api, name, deep):
"""
Gets requested rbac info
"""
print()
Gets requested group info
"""
group_results = IPAQuery.group_data(api, name)
gid = group_results['cn'][0]
gid_number = group_results['gidnumber'][0]
description = group_results['description'][0]
users_list = list(group_results['member_user'])
users_indirect = []
if 'memberindirect_user' in group_results:
users_indirect = list(group_results['memberindirect_user'])

users_list = users_list + users_indirect
users_list_names = []
for x in users_list:
user_results = IPAQuery.user_data(api, x)
first_name = ''
if 'givenname' in user_results:
first_name = user_results['givenname'][0]
last_name = user_results['sn'][0]
full_name = f'{first_name} {last_name}'
users_list_names.append(full_name)
users = ','.join(users_list)
users_names = "\n".join(users_list_names)
getent_string = f'{gid}:x:{gid_number}:{users}'
if not deep:
print(getent_string)
else:
print(users_names)

@staticmethod
def user_data(api, user):
Expand Down

0 comments on commit c2ab7d7

Please sign in to comment.