@@ -274,9 +274,42 @@ def entry(api, control, name, deep):
274274 @staticmethod
275275 def user_pull (api , name , deep ):
276276 """
277- Gets requested rbac info
277+ Gets requested user info
278278 """
279- print ()
279+ try :
280+ user_results = IPAQuery .user_data (api , name )
281+ except :
282+ print (f'Could not find { name } ' , sys .stderr )
283+ sys .exit (1 )
284+
285+ user_first = '' if not user_results .get ('givenname' , None ) else user_results ['givenname' ][0 ]
286+ user_last = '' if not user_results .get ('sn' , None ) else user_results ['sn' ][0 ]
287+ user_uid = '' if not user_results .get ('uid' , None ) else user_results ['uid' ][0 ]
288+ user_uidnum = '' if not user_results .get ('uidnumber' , None ) else user_results ['uidnumber' ][0 ]
289+ user_gidnum = '' if not user_results .get ('gidnumber' , None ) else user_results ['gidnumber' ][0 ]
290+ user_groups = '' if not user_results .get ('memberof_group' , None ) else '\n ' .join (user_results ['memberof_group' ])
291+ user_hbachosts = '' if not user_results .get ('memberof_hbacrule' , None ) else '\n ' .join (user_results ['memberof_hbacrule' ])
292+ user_indhbachosts = '' if not user_results .get ('memberofindirect_hbacrule' , None ) else '\n ' .join (user_results ['memberofindirect_hbacrule' ])
293+
294+ starter_user = {
295+ 'User name' : user_uid ,
296+ 'First name' : user_first ,
297+ 'Last name' : user_last ,
298+ 'UID' : user_uidnum ,
299+ 'GID' : user_gidnum ,
300+ 'Groups' : user_groups ,
301+ }
302+
303+ print ('User Information' )
304+ print ('----------------------------------------' )
305+ for key , value in starter_user .items ():
306+ if len (value ) > 0 :
307+ print (f'{ key : <16} { value } ' )
308+ print ('' )
309+
310+ if deep :
311+ group_list = [] if not user_results .get ('memberof_group' , None ) else user_results ['memberof_group' ]
312+ IPAAudit .user_deep_list (api , name , group_list )
280313
281314 @staticmethod
282315 def group_pull (api , name , deep ):
@@ -369,7 +402,7 @@ def role_deep_list(api, users, groups, privs):
369402 if perm not in starting_perms :
370403 starting_perms .append (perm )
371404
372- print (f 'Permissions Applied to this Role' )
405+ print ('Permissions Applied to this Role' )
373406 print ('----------------------------------------' )
374407 for item in starting_perms :
375408 print (item )
@@ -427,10 +460,42 @@ def role_deep_list(api, users, groups, privs):
427460 print (f'{ key : <24} { value } ' )
428461
429462 @staticmethod
430- def user_deep_list (api , user ):
463+ def user_deep_list (api , user , groups ):
431464 """
432465 Does a recursive dig on a user
433466 """
467+ hbac_rule_list = []
468+ host_list = []
469+ hostgroup_list = []
470+ for group in groups :
471+ group_results = IPAQuery .group_data (api , group )
472+ hbac_list = [] if not group_results .get ('memberof_hbacrule' , None ) else group_results ['memberof_hbacrule' ]
473+ hbacind_list = [] if not group_results .get ('memberofindirect_hbacrule' , None ) else group_results ['memberofindirect_hbacrule' ]
474+ hbac_rule_list .extend (hbac_list )
475+ hbac_rule_list .extend (hbacind_list )
476+
477+ # TODO: Add HBAC list (including services)
478+ # TODO: Add RBAC list
479+
480+ hbac_hosts = []
481+ for hbac in hbac_rule_list :
482+ hbac_results = IPAQuery .hbac_data (api , hbac )
483+ hbac_host_list = [] if not hbac_results .get ('memberhost_host' , None ) else hbac_results ['memberhost_host' ]
484+ hbac_hostgroup_list = [] if not hbac_results .get ('memberhost_hostgroup' , None ) else hbac_results ['memberhost_hostgroup' ]
485+
486+ for host in hbac_host_list :
487+ hbac_hosts .append (host )
488+
489+ for hostgroup in hbac_hostgroup_list :
490+ hostgroup_data = IPAQuery .hostgroup_data (api , hostgroup )
491+ host_list = [] if not hostgroup_data .get ('member_host' , None ) else hostgroup_data ['member_host' ]
492+ hbac_hosts .extend (host_list )
493+
494+ new_hbac_hosts = sorted (set (hbac_hosts ))
495+ print ('User Has Access To These Hosts' )
496+ print ('----------------------------------------' )
497+ for hhost in new_hbac_hosts :
498+ print (hhost )
434499
435500 @staticmethod
436501 def group_deep_list (api , group ):
0 commit comments