From c2ab7d72c21d0afa2421c5a1d09c6f56c9ddf3fc Mon Sep 17 00:00:00 2001 From: Louis Abel Date: Wed, 31 Jul 2024 07:20:07 -0700 Subject: [PATCH] add group query --- mangle/ipa/ipaauditor.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/mangle/ipa/ipaauditor.py b/mangle/ipa/ipaauditor.py index 7b95c2a..0b99510 100644 --- a/mangle/ipa/ipaauditor.py +++ b/mangle/ipa/ipaauditor.py @@ -447,7 +447,6 @@ class IPAQuery: """ 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': @@ -456,7 +455,7 @@ class IPAQuery: @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] @@ -486,13 +485,37 @@ memberOf:{groups} """ print(outter) - @staticmethod def group_pull(api, name, deep): """ - Gets requested rbac info + Gets requested group info """ - print() + 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):